Skip to main content

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.

ExceptionCodeMeaning
LoanSimulationFailedINVALID_LOAN_SIMULATIONThe partner refused the amount or returned no schedule
MethodNotSimulableMETHOD_IS_NOT_SIMULABLECalled 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.