Buy now, pay later
Accept Klarna, Afterpay, and Affirm payments using a popup-based approval flow.
PaymentKit.js supports three buy now, pay later (BNPL) payment methods: Klarna, Afterpay, and Affirm. All three share the same flow — there are no input elements to mount. When you submit, PaymentKit.js opens a secure popup where the customer completes approval with the BNPL provider, then polls for the result and resolves your onSuccess or onError callback.
Setup
Register only the BNPL methods you plan to offer — each one is independent.
CDN
NPM/ES Modules
Submit payment
Like PayPal, BNPL methods don’t need input elements. Submit directly when the customer clicks your Klarna, Afterpay, or Affirm button, passing the matching paymentMethod name — 'klarna', 'afterpay', or 'affirm':
PaymentKit.js opens the provider’s approval page in a 600×700 popup window and polls the payment status every 2 seconds. If the customer closes the popup without completing approval, the submission fails with a “popup closed by user” error after a short grace period.
The popup must be triggered by a direct user action (button click) to avoid being blocked by popup blockers.
Options
Saving Klarna for future payments
Klarna supports saving the payment method during checkout for future off-session charges (for example, subscriptions). Pass setupFutureUsage: true in the submit options:
setupFutureUsage is only supported by Klarna. Afterpay and Affirm do not support saving the payment method — their TypeScript submit option types omit the field, and the SDK never sends it for those methods.
Error handling
Each BNPL method returns its errors under its own key — errors.klarna, errors.afterpay, or errors.affirm — as descriptive strings. Validation errors use errors.processor_id and errors.customer_name:
The table below uses Klarna as the example; for Afterpay and Affirm the error field is afterpay / affirm and the provider name in the message changes accordingly: