Integrate Klarna’s Web SDK to deliver a seamless, optimized checkout experience on your site. Initialize the SDK, present Klarna in the payment selector, and finalize the flow with Klarna’s payment button.
Before you integrate, check that you meet the following prerequisites:
payment.request.state-change.completed
events following Webhooks guidelines.Subscribing to webhooks in the Klarna Portal will be available in a future release.
Here's an overview of all the steps to display Klarna via the WebSDK:
payment_request_id
is used to initiate the purchase flow with Klarna’s WebSDK.interoperability_token
via webhook.This guideline describes how Klarna should be presented in the payment form initially as well as when it's selected by the customer. The expected outcomes are as followed:
![]() | ![]() |
Initial presentation | When Klarna is selected |
It's crucial that Klarna payment presentation is dynamic and not hardcoded on your server to deliver the best conversion outcome.
Klarna's best practice
To ensure the best user experience and optimal conversion rates when presenting Klarna as a payment option, please apply the following recommendations:
The next sections in this guideline will walk through how this can be achieved using Klarna Web SDK.
The Klarna Web SDK (klarna.mjs) follows the JavaScript module approach and should be included in places where you need to have a reference to the SDK such as while rendering any components or initiating a payment flow. Here are the initialization parameters:
Parameter | Presence | Description |
---|---|---|
| required | A credential that identifies the Partner (obtained via Klarna Portal). |
| optional | Array to specify which products to load for optimal performance. This reduces the amount of data needed to download. For example, only loading PAYMENT will exclude the CUSTOMER product. |
| optional | Language and region code (e.g., en-US ). If omitted, Klarna may default based on the customer’s browser settings. |
For the full API specifications, refer to Klarna Web SDK.
SDK initialization sample
<script type="module">
const { KlarnaSDK } = await import("https://js.klarna.com/web-sdk/v2/klarna.mjs")
const Klarna = await KlarnaSDK({
clientId: "[client-id]",
products: ["PAYMENT"],
locale: "en-US", // optional
})
// Klarna SDK ready to be utilized
Use PAYMENT
product for all interactions with Klarna.Payment
.
Important implementation details
Legal notice
When using the Klarna Web SDK, you are responsible for informing your users about the tracking technologies it uses. Learn more about how to disclose this on your site.
Klarna payment presentation provides all the visual assets, localized texts, and instructions needed to correctly display Klarna in your checkout form.
Use the initialized SDK instance to call the Klarna.Payment.presentation() method.
Basic checkout context parameters must be provided:
Parameter | Presence | Description |
---|---|---|
| required | The transaction amount in minor units (e.g., $118.00 = 11800 ). |
| required | Three-letter ISO 4217 currency code (e.g., USD , EUR ). |
| optional | Locale code to localize texts and formats (e.g., en-US , de-DE ). If you don’t set this, it will automatically use the value chosen when you first set up the Web SDK. If that’s not available, it will use your browser’s settings instead. |
| optional | Specify the intent of the checkout flow: PAY , SUBSCRIBE , SIGNUP , SIGNIN , DONATE .Default value is PAY . |
For the full API specifications, refer to Klarna Web SDK.
Sample code
var paymentPresentation = await klarna.Payment.presentation({
amount: 11800,
currency: "USD",
locale: "en-US",
intents: ["PAY"], // optional, other values: "SUBSCRIBE" ||"SIGNUP" || "SIGNIN" || "DONATE"
});
Performance optimization
It is important to ensure that Klarna is displayed at roughly the same time as other payment methods, with an acceptable delay of less than 100 ms. To achieve this, begin initializing the Klarna Web SDK and invoke the payment presentation method concurrently while loading the list of all enabled payment methods from your server.
The PaymentPresentation
interface provides the full Klarna branding package and instructions tailored to the customer's purchase:
Attribute | Purpose |
---|---|
| Specifies how Klarna as a payment method should be displayed (e.g., whether to show, preselect, or display as show-only). Adhering to these payment presentation instructions ensures customers have the best possible experience and optimizes conversion rates. |
| Klarna badge/logo suitable for checkout forms. |
| The main descriptor that introduces Klarna in the payment form. The value will be dynamically adjusted based on the locale provided. |
| The descriptor subheader which must be loaded inline below the main descriptor header. Short and enriched descriptive texts. Provides transparency on available options like installments, pay later, etc. |
| Enriched tailored description with link |
| Payment button for the customer to start the Klarna purchase Journey |
For the full API specifications, refer to Klarna Web SDK.
Skip this section if you don't use any Conversion Boost features from Klarna such as Klarna Express Checkout, Sign-in with Klarna, Klarna Messaging or Klarna Prequalification.
Klarna’s payment presentation instructions indicate whether a customer is ready to check out with a prepared payment via Klarna—for example, when Klarna Express Checkout or other Conversion Boost features are integrated. Partners are required to adhere to Klarna’s payment presentation instruction to achieve the best-in-class user experience.
The instruction
attribute has the following values:
Instruction | Description |
---|---|
| Show Klarna alongside other payment methods. |
| Show Klarna pre-selected but still alongside others. This is returned when the customer has logged in using the Sign in with Klarna feature. |
| Display Klarna as the only payment method. This is returned when the customer has finished the first step of Klarna Express Checkout multistep. |
For the full API specifications, refer to Klarna Web SDK.
Here are the expected outcomes of the payment selector depending on the value of the payment presentation instruction:
![]() | ![]() | ![]() |
Show Klarna | Preselect Klarna | Show only Klarna |
The presentation instructions are derived from possible customer purchase journeys described in the following article.
Sample code:
if (paymentPresentation) {
switch (paymentPresentation.instruction) {
case "SHOW_KLARNA":
console.log("Showing Klarna alongside other payment methods.");
renderKlarnaOption(paymentPresentation);
break;
case "PRESELECT_KLARNA":
console.log("Showing Klarna preselected alongside other payment methods.");
renderKlarnaOption(paymentPresentation);
break;
Once an instance of PaymentPresentation
is created, the Partner must dynamically render Klarna payment option in the payment selector according to Klarna’s presentation guidelines.
The following attributes from PaymentPresentation
instance will be used when loading the payment selector initially:
Mount Klarna payment presentation icon, header and subheader to your Klarna payment method container to render the elements dynamically in your payment form.
function renderKlarnaOption(paymentPresentation) {
const klarnaContainer = document.getElementById("klarna-option");
if (!klarnaContainer) {
console.error("Klarna container missing.");
return;
}
// Clear the container first
klarnaContainer.innerHTML = `
After the customer selects Klarna in the payment selector (or if Klarna was pre-selected according to presentation instructions), the next step is to show:
This step finalizes the presentation of Klarna's payment method before the customer proceeds to payment authorization.
Display additional messaging
paymentPresentation
.message
.component()
.mount("#klarna-message-container");
Display Klarna payment button
The payment presentation instance allows you to either mount the prebuilt button component or retrieve the button text asset. The Klarna Payment Button is context-aware and dynamically adapts to your configuration.
Klarna payment button variants
Choose the theme and shape of the payment button to best fit into your online store in a way that complements your brand and encourages user engagement. More details on the button styling can be found here.
Mount Klarna payment button
The paymentButton.component()
can be configured with the following set of parameters:
Parameter | Description |
---|---|
| Sets a custom DOM ID on the rendered button. Useful for testing or styling. |
| Defines the button’s shape. Possible values are:default , pill , rect |
| Sets the visual theme of the button. Possible values are: default , light , dark , outlined |
| Sets the language and region (e.g., en-US ). If you don’t set this, it will automatically use the value chosen when you first set up the Web SDK. If that’s not available, it will use your browser’s settings instead. |
| Disables the button when set to true . Useful during form validation or async operations. |
| Forces the button into a loading state. Useful when awaiting async setup or validation. |
| Sets the purpose of the payment. Used to personalize the button and flow if not set when creating the PaymentPresentation instance. |
| Function that returns a Promise resolving to either a PaymentRequestData , a paymentRequestId , or a returnUrl . This will be handled differently depending on the integration path. |
| Defines how Klarna launches the purchase journey. |
For the full API specifications, refer to Klarna Web SDK.
Sample code
paymentPresentation
.paymentButton
.component({
id: "klarna-payment-button", // unique button/component ID
shape: "pill", // "pill", "default", or "rect"
theme: "default", // "default", "dark", "light", or "outlined"
intents: ["PAY"], // defines payment intent, e.g., "PAY"
initiationMode: "DEVICE_BEST", // "DEVICE_BEST", "ON_PAGE", or "REDIRECT"
initiate: () => {
/**
The button will automatically handle customer interaction and trigger the Klarna purchase flow via the initiate
function.
In order to launch the purchase flow, you need to implement the initiate
callback on the Klarna payment button interface. The initiate
callback is triggered when the customer clicks on the Klarna payment button, upon which, the payment request data such as amount and currency must be submitted to Klarna server.
Parameter | Presence |
---|---|
| required Currency in ISO 4217 format. Supported currencies: AUD, EUR, CAD, CZK, DKK, HUF, MXN, NZD, NOK, PLN, RON, SEK, CHF, GBP, USD. |
| required Total amount of a one-off purchase, including tax and any available discounts. The value should be in non-negative minor units. Eg: 25 Dollars should be 2500. This is the amount that Klarna will charge the customer for a one-off purchase. Should not include any amounts for subscriptions. |
| optional Additional details about the transaction can help reduce the risk of fraud and enhance transparency.
|
For the full API specifications, refer to the API referenceAPI.
Create Klarna payment request on the server side and initiate the purchase flow using Klarna Web SDK
Create a payment request on the server side is the recommended approach to create the payment request, then share the payment request ID as response to the initiate
callback.
Client code
const klarnaPaymentButton = klarna.Payment.button({
initiate: async () => {
const resp = await fetch('/create-klarna-payment-request', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ /* Your data here */ })
});
const data = await resp.json();
return { paymentRequestId: data.paymentRequestId };
}
For the full API specifications, refer to Klarna Web SDK.
Server code
// Server.js
// Simplified backend example for creating a Klarna payment request
const axios = require('axios');
// Klarna credentials and base URL (replace with your keys and consider loading from environment variables)
const KLARNA_API_KEY = 'YOUR_API_KEY';
const KLARNA_BASE_URL = 'https://global-api.klarna.com'; // According to docs
// Function to create a Klarna payment request
For the full API specifications, refer to the API referenceAPI.
Create a new payment request on every button click instead of reusing payment requests.
Once the customer approves the request, the payment request will enter the COMPLETED
state and you’ll receive an interoperability_token
which can be used to authorize the payment and complete the process. There are different ways to obtain the interoperability_token
. The recommended approach is to listen to Klarna Webhook payment.request.state-change.completed
events.
Subscribing to webhooks in the Klarna Portal will be available in a future release.
The field stateContext
in the webhook payload will be available in a future release.
Webhook payload sample
{
"metadata": {
"event_type": "payment.request.state-change.completed",
"event_id": "d9f9b1a0-5b1a-4b0e-9b0a-9e9b1a0d5b1a",
"event_version": "v2",
"occurred_at": "2024-01-01T12:00:00Z",
"correlation_id": "2d1557e8-17c3-466c-924a-bbc3e91c2a02",
"subject_account_id": "krn:partner:global:account:live:HGBY07TR",
"recipient_account_id": "krn:partner:global:account:live:LWT2XJSE",
"product_instance_id": "krn:partner:product:payment:ad71bc48-8a07-4919-a2c1-103dba3fc918",
Make sure to add the interoperability_token
received via the webhook and the purchase details within the call to your Acquiring Partner. If everything is implemented correctly, Klarna will approve the payment transaction.
curl -X POST https://api.acquiring-partner.com/payment \
-H "Content-Type: application/json" \
-d '{
"amount": 1000,
"currency": "USD",
"payment_methods": {
"klarna": {
"klarna_interoperability_token": ""
}
}
In rare cases where there's discrepancy between the amount and purchase details submitted in the original payment request and the information submitted to the Acquiring Partner, Klarna may reject and ask the customer to approve the purchase again.