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.
val bnpl = checkout.primaryMethods.firstOrNull { it.simulable } ?: return
val product = LoanProduct(checkout.remainingAmountToPay.value, checkout.currency)
val schedule = checkout.simulateLoan(bnpl, product) // suspend, runs on Dispatchers.IO
// schedule.installmentCount, initialInstallmentAmount, installmentAmount, finalInstallmentAmount,
// totalCost (price of the credit), totalAmount (everything paid), aprc, legalText
val all = checkout.simulateLoans(bnpl, product) // every schedule the partner offers (3×, 4×, …)
installmentCount includes the first and the last instalment: a 4× plan renders 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.
| Exception | Code | Meaning |
|---|---|---|
LoanSimulationFailed | INVALID_LOAN_SIMULATION | The partner refused the amount or returned no schedule |
MethodNotSimulable | METHOD_IS_NOT_SIMULABLE | Called on a method without the simulable flag |
The sample app's SimulationPreview.kt 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.