Learn how to integrate the one-step Express checkout for a fast and simple shopping journey.
Follow the web integration guide to add the one-step Express checkout to your website.
Not sure if the one-step 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 one-step Express checkout consists of three 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 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.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. authorize()
callback that you receive in on_click
. The order payload object can contain all information allowed in the Klarna payments API, for example, merchant references, merchant URLs, and 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 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 customer clicks the Express button. In one-step Express checkout, set auto_finalize to true . Otherwise, the purchase won’t be authorized automatically.The default value is true . If you omit this attribute, the order will be authorized automatically. |
If the authorization is successful, you will receive the authorization_token
from the client-side authorize()
response, in the authorization callback, or by getting the payment details from Klarna payments API.
Here’s an example of a response from the client-side authorize()
call.
This example shows a response from the authorization callback.
Once you have the authorization_token
, create an order. When creating the order, make sure the shipping address provided in the API request matches the collected shipping address returned alongside the authorization_token
.