Handle token order failures effectively by initiating a new Klarna session without the token, allowing customers to restart the purchase journey and complete the transaction.
This article explains the recovery process to handle failures when placing an order using a customer token in Klarna’s tokenized payment setup.
This recovery flow is designed for when the customer is present as this flow requires customer interaction to be successful.
If a create order attempt using a customer token fails, Klarna returns an error informing that the customer token can’t be used to complete the transaction.
In case of a customer being present in the session, the partner should fallback to creating a new payment session. This allows the customer to enter the purchase flow and correct the issue(s) causing the token charge to fail.
If the recovery order is successful, the customer token will be updated with the chosen payment option for future purchases.
flowchart TD
A[Token-based purchase attempt fails on-session] -->B[Klarna returns error response with failure session]
B --> C[Does the response contain the step-up trigger?]
C -->|No| D[Handle error normally or retry token flow]
C -->|Yes| E[Create new Klarna Payments session]
E --> F{Integration type}
F -->|SDK| G[Use client_token to init Klarna Payments SDK]
F -->|HPP| H[Create HPP session using KP session_id]
G --> I[Call authorize to render Klarna widget]
H --> J[Redirect customer to Klarna using redirect_url]
I --> K[Customer completed authorization]
J --> K[Customer completed authorization]
K --> L[Use authorization_token to create order server-side]
Monitor Klarna responses to the create order from a customer token API call. It is always recommended to attempt a fallback purchase flow if you receive an error code in the response and the customer is present.
Consult this page for a complete list of validations during the payment process.
Klarna can be integrated into your website in two different ways, depending on your setup and preferred level of customization. Each option has its own implementation steps and requirements:
Use Klarna’s create order using customer token endpoint to charge an already generated customer token. The step_up should be set to SUPPORTED in case of customer being present and recovery flow can be triggered. step_up would default to NOT_SUPPORTED in case of missing. When step_up is set to SUPPORTED and the create order being rejected, a step_up_id will be returned in the response and should be provided in the following step-up session.
Use Klarna’s create session endpoint to create a new session. The intent should reflect the intent provided in original session created. The customer_token from the failed charge must be provided as part of the customer object. The step_up_id from the failed charge must be provided for Klarna to later update the stored payment option on the customer_token.
Using the client_token from the session response and initialize the Klarna modal. You can immediately trigger the Klarna Purchase Flow by calling authorize() via the JavaScript SDK.
Once a purchase is successfully created, it will be automatically linked to the existing customer token, and the same token can then used to charge future purchases.
Use Klarna’s create order using customer token endpoint to charge an already generated customer token. The step_up should be set to SUPPORTED in case of customer being present and recovery flow can be triggered. step_up would default to NOT_SUPPORTED in case of missing. When step_up is set to SUPPORTED and the create order being rejected, a step_up_id will be returned in the response and should be provided in the following step-up session.
Use Klarna’s create session endpoint to create a new one-time-buy session. The intent should reflect intent provided in initial created session. The customer_token from the failed charge must be provided as part of the customer. The step_up_id from the failed charge must be provided for Klarna to later update the stored payment option on the customer_token.
Associate the Klarna Payments session_id from the session response with the Hosted Payment Page session by including it in the payment_session_url when creating the HPP session.
Redirect the customer to the Hosted Payment Page using the [redirect_url](https://docs.klarna.com/api/hpp-merchant/#operation/createHppSession!c=201&path=redirect_url&t=response) provided in the session creation response. You may optionally display a prompt or call-to-action before initiating the redirect.
To track the session status, either:
Poll Klarna’s API to retrieve the result of the session.
Refer to the HPP session lifecycle for a detailed explanation of how the session progresses and how to handle its different states.
If the payment is declined, redirect the customer back to checkout so they can choose another payment method.
If the HPP session was created using PLACE_ORDER and CAPTURE_ORDER modes, Klarna handles the order creation, and an order_id is returned, no further action is needed.
When the session was created using place_order_mode: NONE, Klarna does not create the order automatically.
Use the returned authorization_token returned upon successful authorization to create the order:
Once a purchase is successfully created, it will be automatically linked to the existing customer token, and the same token can then used to charge future purchases.