Instalment simulation
A primary method flagged simulable (Klarna, and any BNPL partner configured for simulation in your dashboard) can show the shopper the schedule before they choose it.
let bnpl = checkout.paymentMethods.compactMap { item -> PrimaryMethod? in
guard case let .primaryMethod(method) = item, method.simulable else { return nil }
return method
}.first
guard let bnpl else { return }
let product = LoanProduct(amount: checkout.remainingAmountToPay, currencyCode: checkout.currency)
let schedule = try await checkout.simulateLoan(bnpl, product: product)
// schedule.installmentCount, initialInstallmentAmount, installmentAmount, finalInstallmentAmount,
// totalCost (price of the credit), totalAmount (everything paid), aprc, legalText
let all = try await checkout.simulateLoans(bnpl, product: product) // every schedule the partner offers (3×, 4×, …)
The SDK returns numbers, never a view: rendering the schedule is yours. installmentCount includes the first and the last instalment, so a 4× plan draws four lines: initialInstallmentAmount, then installmentAmount twice, then finalInstallmentAmount. Show legalText next to the schedule where the partner requires it.
Simulate again when remainingAmountToPay changes: a gift card applied after the simulation changes the amount the partner would finance. In SwiftUI, .task(id: checkout.remainingAmountToPay) is enough.
| Error | Code | Meaning |
|---|---|---|
PurseCheckoutError.loanSimulationFailed | INVALID_LOAN_SIMULATION | The partner refused the amount or returned no schedule |
PurseCheckoutError.methodNotSimulable | METHOD_IS_NOT_SIMULABLE | Called on a method without the simulable label |
The demo app's SimulationPreview.swift is a complete rendering (Run the sample app). The schedule is a preview: paying with the method is the Klarna guide or, for other providers, the redirection guide.