Learn how to integrate the multistep Express checkout to support more robust checkout options.
Follow the web integration guide to add the multistep Express checkout to your website.
Not sure if the multistep checkout is the best option for your store? Refer to the Before you start article to make sure you offer your customers the best checkout experience.
The process of creating a multistep Express checkout consists of six main steps:
Load the Klarna payments JavaScript library when the cart page or a product detail page is loaded. Ensure the library is included only once to prevent conflicts.
Then, implement the klarnaAsyncCallback
function where you initialize the Express checkout. Implement the klarnaAsyncCallback
before importing the library. This way you ensure it will be invoked when the library is loaded. Within klarnaAsyncCallback
, include the logic to:
client_id
, get your client_id
from the Merchant portal. Refer to the Before you start article for instructions on how to generate your client_id . load()
function. To help debug any issues that occur when loading the button, implement the load()
callback.on_click
event, in which you start the payment authorization process by calling the authorize()
function. Keep the following best practices in mind:orderPayload
is the same as the body of the request to create a Klarna payments session. The orderPayload
object can contain all information allowed in the Klarna payments API, for example, merchant references, merchant URLs, or extra merchant data.
Here’s an example of code that initializes the Klarna JavaScript library and renders the Express checkout button on a cart or a product detail page:
The table below lists the attributes of the load()
function’s configuration object.
Attribute | Required | Description |
---|---|---|
container | Yes | container represents the location where you want the Express checkout button to be displayed.In this attribute, you can specify either:
|
on_click | Yes | The function passed in this attribute will be executed when the Express checkout button is clicked. It will receive the authorize() function, which has to be invoked to start the Express checkout flow. The authorize() function acts similarly to authorize() in a standard Klarna payments integration. |
theme | No | The color theme of the button. The possible values are default , light , and dark . If the value isn't specified, default is used. |
shape | No | The shape[[#button-shape]] of the button. The possible values are default , rect , and pill . If the value isn't specified, default is used. |
locale | No | The language of the button text. If not specified, the browser's language will be used. |
The value of locale passed in the authorize()
function’s configuration object defines the language of the button text. On the other hand, the value of locale passed to authorize()
inside the orderPayload
defines the language of the purchase flow. Learn more about locale formats in Klarna APIs.
The table below lists the attributes for the authorize()
function’s configuration object.
Attribute | Required | Description |
---|---|---|
collect_shipping_address | Yes | Informs Express checkout whether you need the customer's shipping address from Klarna. The default value is false . |
auto_finalize | No | Allows you to specify whether the authorization should automatically be finalized when the user clicks the Express button. In multistep Express checkout, make sure to always set auto_finalize to false to keep the authorization process open until the purchase is finalized. The default value is true . |
In the multistep checkout, after the customer completes the first step, you’ll receive the authorize()
call response with the finalize_required
flag set to true
and the client_token
necessary to resume the authorization at checkout.
Redirect the customer to the checkout and pre-fill all necessary fields with the customer data returned in the authorize() response call.
When the customer navigates to another page or reloads the current one, you need to initialize the Klarna payments library with the client_token
you got from the authorization response. This will keep the authorized session open.
To authorize the purchase, you need the authorization_token
. To get the authorization_token
, call the Klarna.Payments.finalize()
function during the final purchase step.
If changes were made in the order payload, for example, to the order amount or shipping address, you have to submit them when calling Klarna.Payments.finalize()
.
If the purchase is authorized successfully, you’ll receive the authorization_token
in the client-side finalize()
response, the authorization callback, or by getting the payment details from Klarna payments API. You need the authorization_token
to create an order in the final step.
Here’s an example of a response from the client-side authorize()
function:
Here’s an example of a response from the authorization callback:
Once you have the authorization_token
, create the order. When creating the order, make sure the order payload is the same as the one sent in the finalize()
call.