Token creation - Build the payment form

Learn how to seamlessly integrate Klarna into your payment process using our SDK for a seamless, high-conversion checkout. This guide covers everything from SDK setup to custom payment form creation.

Integration overview

With this integration path, Partners are presenting a payment form generated by the Acquiring Partners:

  • Customers are either redirected to a hosted checkout page or a checkout element embedded in the Partner website via a JavaScript library.
  • Acquiring Partners must use Klarna's SDK to dynamically retrieve payment presentation assets (headers, icons, subheaders, button and instructions) and build the payment form.
  • Klarna’s SDK keeps all elements up-to-date and optimized for the best conversion.

The following diagram gives an overview of the customer journey and the Acquiring Partner workflow:

On a high level, building the payment form requires the following actions:

  • Accept klarna_network_session_token in your checkout session API and JavaScript library.
  • Accept klarna_network_data in your checkout session API (server-side only).
  • Forward both Klarna Network data points to Klarna exactly as received — do not modify.
  • If klarna_network_session_token is provided, exchange it server-side for an sdk_token.
  • Load the Klarna SDK from the official URL — never bundle or self-host.
  • Initialize the SDK with clientId, partnerAccountId, sdkToken, products and locale.
  • Use Klarna.Payment.presentation() SDK method to dynamically retrieve personalized assets to build the payment selector
  • Never hardcode Klarna logos, texts, or layout — always render via SDK components.
  • Always follow the returned instruction (e.g., show, preselect Klarna).
  • Mount the Payment Button only after Klarna is selected or preselected.

Integration details

Step 1: Gather and forward payment context data

Before calling the Payment Authorization APIAPI, update the Partner-facing API to collect Klarna-specific context provided by the Partner. This data preserves session continuity, enables interoperability across Klarna Network features and improves risk assessment.

Interoperability parameters

  • klarna_network_session_token

    • Encodes Klarna session context, such as payment option preselection, prequalification results, or payment approval
    • May be present on the initial authorization request
    • Required when finalizing authorization after a step-up flow
  • klarna_network_data

    • Encodes additional Klarna Network context supplied by the Partner, including supplementary purchase data
    • Must not be parsed, enriched, or transformed

Below is an example of how Acquiring Partners can accept the Klarna Network parameters in their Partner-facing APIs.

JSON
{
  "currency": "USD",
  "amount": 17800,
  "payment_method_options": {
    "klarna": {
      "klarna_network_session_token": "eyJhbGciOiJ...",
      "klarna_network_data": "{\"content_type\":\"application/vnd.klarna.interoperability-data.v2+json\",\"content\":{\"payment_request\":{...}}}"
    }
  }
}

Requirements

  • Accept the Klarna Network parameters in the Partner-facing APIs.
  • Use the field names klarna_network_session_token/klarna_network_data, ensuring that it’s easy for any Partner to identify and use.
  • Validation should be implemented, but it must not be more restrictive than what is specified in Klarna’s Payment Authorize APIAPI.
  • All printable UTF-8 characters must be supported
  • Forward the Klarna Network parameters unmodified to Klarna.

Supplementary purchase data

Supplementary purchase data improves Klarna’s ability to assess risk, optimize approval rates, and deliver a more personalized checkout experience. It includes structured information such as line items, L2/L3 data for Card Network optimization and other transaction context. Acquiring Partners may receive this data from the Partner in two ways:

  1. 1.
    Embedded in klarna_network_data
    • 1.1.
      No parsing needed. Just forward it as-is.
  2. 2.
    As individual fields in the Acquiring Partner’s API

Acquiring Partner must collect and forward data that aligns with Klarna’s Supplementary Purchase Data package by utilizing their existing schema. Acquiring Partner should not add additional fields of the supplementary purchase data in their APIs to support Klarna. Instead, they must ensure that the klarna_network_dataAPI and its required structure are properly implemented.

In both cases, the Acquiring Partner is responsible for ensuring that the data provided by the Partner is accurately forwarded to Klarna. Partners should not be asked to resubmit the same information through multiple mechanisms.

Read more about Supplementary Purchase Data here.

Tokenization-specific supplementary purchase data

Step 2: Fast track Klarna payment when applicable

Before presenting the payment form, if an klarna_network_session_token was shared by the Partner, the Acquiring Partner must check if Klarna payment should be fast-tracked. This typically happens when the Partner implements Klarna boost features such as Klarna Express Checkout and the customer has given the approval for payment.

Payment presentation request

Sample request
BASH
curl -G 'https://api-global.test.klarna.com/v2/accounts/{partner_account_id}/payment/presentation' \
     --header 'Authorization: Basic <API key>' \
     --header 'Klarna-Network-Session-Token: eyJhbGciOiJIU...' \
     --data-urlencode 'locale=en-US' \
     --data-urlencode 'amount=11836' \
     --data-urlencode 'currency=USD' \
     --data-urlencode 'intents[]=SUBSCRIBE'

Payment presentation response

The PaymentPresentation interface provides the full Klarna branding package and instructions tailored to the customer's purchase. However, at this step, the only relevant information is payment_status.

Payment statusDescription
REQUIRES_CUSTOMER_ACTIONFurther customer interaction is required, the payment selector should be displayed.
PENDING_PARTNER_AUTHORIZATIONThe customer has approved the payment, the Acquiring Partner should proceed with payment authorization immediately – jump to the Authorize the payment section. If the authorization is successful, return to the merchant confirmation page, else continue to display the payment form.
Sample response
JSON
{
    ...
    "payment_status": "PENDING_PARTNER_AUTHORIZATION",
    ...
}

Step 3: Initialize the Klarna Web SDK

Using Klarna Web SDK, you can:

  • Display Klarna dynamically alongside other payment options in your payment form.
  • Embed Klarna’s UI elements directly in your frontend for a consistent and responsive design.
  • Manage the interaction flow while offloading the rendering and logic to Klarna’s SDK.
Exchange the customer_token and/or interoperability_token for an sdk_token

This step is only applicable if the Partner has shared an klarna_network_session_token or if the customer_token has been acquired through the tokenization process.

The Acquiring Partner must exchange the acquired customer_token for a short-lived sdk_token using the Generate SDK TokenAPI API endpoint. If an klarna_network_session_token was passed by the Partner in the charge call, both tokens should be used for the exchange.

The sdk_token is a single-use, browser-bound credential that restores the customer’s checkout context when Klarna’s Web SDK is loaded. This token should be exchanged server-side before initializing the SDK and displaying the checkout page to the customer.

Initialize the 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:

ParameterDescription
clientIdA credential that identifies the Acquiring Partner (obtained via Klarna’s Credentials API). It is shared across all integrated Partners. To ensure the credential functions properly, make sure to register all domains where the Web SDK will be used.
productsAn array used to specify which products should be loaded to optimize performance by limiting the amount of data downloaded. If the PAYMENT product is included, only the Klarna.Payment package will be loaded. If the products array is omitted, all available packages will be loaded by default.
partnerAccountIdA unique identifier for the specific Partner onboarding under the Acquiring Partner.
sdkTokenThe short-lived token exchanged from the klarna_network_session_token. Enables restoring the customer's session state securely on the client.
localeOptional, 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

JAVASCRIPT
<script type="module">
  const { KlarnaSDK } = await import("https://js.klarna.com/web-sdk/v2/klarna.mjs")

  const klarna = await KlarnaSDK({
    clientId: "klarna_test_client_***",
    products: ["PAYMENT"],
    partnerAccountId: "krn:partner:global:account:***",
    sdkToken: "rxvqGi07j...", // retrieved from server
    locale: "en-US" // optional but recommended
  });

  // sdkToken can also be set after SDK initiation

If the domain is not registered, subsequent method calls will result in an error.

Do
  • Load the Web SDK from https://js.klarna.com/web-sdk/v2/klarna.mjs to remain compliant.

  • Keep the SDK in the top‑level (1st‑party) browsing context.

  • Specify products for performance.

  • Disclose Web SDK tracking in your site’s notices. Learn more here.

Don't
  • Don’t include the Web SDK in a bundle or host it yourself.

  • Don't load the Web SDK inside an iframe.

  • Don't omit products.

  • Don't use the Web SDK without disclosing tracking technologies.

Step 4: Present Klarna in the payment form

Presenting Klarna in the payment form involves retrieving the visual assets, localized text, and display instructions required to correctly render Klarna as a payment option and display the payment button. This dynamic presentation ensures a consistent customer experience, accurate localization, and optimized conversion performance, while adapting seamlessly to different checkout states.

On a high level, the process involves:

  1. 1.
    Initialize Klarna Web SDK in your checkout experience.
  2. 2.
    Request Klarna’s payment presentation for the current payment context.
  3. 3.
    Render Klarna payment option(s) dynamically in the payment form according to the instructions.
  4. 4.
    Allow the customer to select and deselect a Klarna payment option.
  5. 5.
    Display the Klarna button and start the payment process when clicked.

The expected outcomes are as follows:

undefined
undefined
Initial presentationWhen Klarna is selected

Klarna's payment presentation best practice To ensure the best user experience and optimal conversion rates when presenting Klarna as a payment option, please apply the following recommendations:

  • Display Klarna descriptor dynamically alongside other payment options in your payment form.
  • Embed Klarna’s UI elements directly in your frontend for a consistent and responsive design.

The next sections in this guideline will walk through how this can be achieved using Klarna Web SDK.

Klarna payment presentation request

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:

ParameterPresenceDescription
amountconditionalThe transaction amount in minor units following ISO 4217 exponents (e.g., $118.00 = 11800, ¥1400 = 1400). This field is required if any of the intents include PAY, SUBSCRIBE, or DONATE; otherwise, it is optional.
currencyrequiredThree-letter ISO 4217 currency code (e.g., USD, EUR).
localeoptionalLocale 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.
intentsoptionalSpecify the intent of the checkout flow: PAY, SUBSCRIBE, SIGNUP, SIGNIN, DONATE, ADD_TO_WALLET. If omitted, intents defaults to ["PAY"].

For the full API specifications, refer to Klarna Web SDK.

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.

Sample code

JSON
{
  "amount": 11800, // subscription billing amount.
  "currency": "USD",
  "locale": "en-US",
  "intents": ["SUBSCRIBE"],
  "subscription_billing_interval": "MONTH",
  "subscription_billing_interval_frequency": 1
}
Klarna payment presentation response

The PaymentPresentation interface provides the full Klarna branding package and instructions tailored to the customer's purchase:

AttributePresencePurpose
instructionrequiredSpecifies how Klarna as a payment option(s) 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.
paymentOptionoptionalDefines the default payment option applicable to all purchase types. This object includes the visual elements required to represent Klarna during checkout.

The paymentOption object structure is as follows:

AttributePresencePurpose
paymentOptionIdrequiredThe identifier of the payment option. The value is required to be sent to the Payment Authorize API or the Payment Request API when initiating the payment.
iconrequiredKlarna badge/logo suitable for checkout forms.
headerrequiredThe main descriptor that introduces Klarna in the payment form. The value will be dynamically adjusted based on the locale provided.
subheaderrequiredThe 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.
messageoptionalEnriched tailored description with link.
badgeoptionalBadge used for saved options or promotions.
termsoptionalDefines terms/disclosures potentially with links.
paymentButtonrequiredPayment button that starts the Klarna purchase journey.

For the full API specifications, refer to Klarna Web SDK.

Follow Klarna payment presentation instruction

This section describes how to apply Klarna’s payment presentation instructions, which define how Klarna should appear in your checkout. Following these instructions ensures a consistent experience across payment states and is required for features like Klarna Express Checkout and Sign in with Klarna.

The instruction attribute has the following values:

InstructionDescription
SHOW_KLARNAShow Klarna alongside other payment methods.
PRESELECT_KLARNAShow Klarna pre-selected but still alongside others. This is returned when using the customer_token issued from the Sign in with Klarna feature or the tokenization flow.
SHOW_ONLY_KLARNAShow Klarna as the only payment method. This is returned when the customer has finished the first step of Klarna Express Checkout multistep.
HIDE_KLARNAHide Klarna from the list of payment methods. This is returned when the Partner has been identified as fraudulent and terminated, meaning the Partner no longer has access to Klarna functionality.

For the full API specifications, refer to Klarna Web SDK.

Here are example outcomes illustrating how Klarna should be displayed for each instruction:

undefined
undefined
undefined
undefined
Show KlarnaPreselect KlarnaShow only KlarnaHide Klarna

The presentation instructions are derived from possible customer purchase journeys described in the following article.

Sample code:

JAVASCRIPT
function renderKlarna(paymentPresentation) {
  if (!paymentPresentation) return;

  const root = qs("#klarna-payment-method");
  if (!root) {
    console.error("Missing #klarna-payment-method container.");
    return;
  }

  root.innerHTML = `<div id="klarna-option-default" class="klarna-option default" style="display:none;">
</div>
`;
Mount Klarna payment option components

Once an instance of PaymentPresentation is created, the Klarna payment option(s) must be rendered dynamically in the payment selector according to Klarna’s presentation guidelines. The following diagram displays different visual components and how they are rendered in different selection states:

  1. 1.
    Icon
  2. 2.
    Badge
  3. 3.
    Header
  4. 4.
    Subheader
  5. 5.
    Message
  6. 6.
    Terms
  7. 7.
    Button

Mount the Klarna payment option components within your designated Klarna payment method to render them dynamically in the payment form. When defining the layout, allocate sufficient space for all components and choose the appropriate variants to match your payment form structure. The message component must always occupy a full row to ensure legibility, positioned directly beneath the header, sub-header, and logo, as illustrated above.

Ensure that all components—including those not immediately visible—are mounted during initialization, and manage their visibility through your own logic or UI controls.

JAVASCRIPT
function renderKlarnaOption(containerId, option) {
  const container = qs(`#${containerId}`);
  if (!container) {
    console.error(`Missing #${containerId} container.`);
    return;
  }

  const ids = {
    icon:    `${containerId}-icon`,
    header:  `${containerId}-header`,
    subhdr:  `${containerId}-subheader`,
    badge:   `${containerId}-badge`,
Handle Klarna payment option selection and deselection

When a Klarna payment option is selected/deselected, ensure the additional visual components are shown/hidden properly.

JS
/**
 * Toggle the Klarna payment option selected state.
 * Use for both SDK preselection (PRESELECT_KLARNA) and user interactions.
 */
function toggleKlarnaPaymentOptionSelection(containerId, isSelected) {
  const container = qs(`#${containerId}`);
  if (!container) {
    console.error(`Missing container #${containerId}.`);
    return;
  }

  const display = isSelected ? "block" : "none";
Handle Klarna payment button styling and initiate callback

The payment presentation instance allows you to mount the prebuilt button component. 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.

Configure Klarna payment button

The paymentButton.component() can be configured with the following set of parameters:

ParameterDescription
idSets a custom DOM ID on the rendered button. Useful for testing or styling.
shapeDefines the button’s shape. Possible values are:default, pill, rect
themeSets the visual theme of the button. Possible values are: default, light, dark, outlined
localeSets 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.
disabledDisables the button when set to true. Useful during form validation or async operations.
loadingForces the button into a loading state. Useful when awaiting async setup or validation.
intentsSets the purpose of the payment. Used to personalize the button and flow if not set when creating the PaymentPresentation instance.
initiateFunction that returns a Promise resolving to either a PaymentRequestData, a paymentRequestId, or a returnUrl. This will be handled differently depending on the integration path.
initiationModeDefines how Klarna launches the purchase journey.

For the full API specifications, refer to Klarna Web SDK.

Sample code

JAVASCRIPT
option
  .paymentButton
  .component({
    id: "klarna-payment-button",  // optional test hook
    shape: "pill",                // "default" | "pill" | "rect"
    theme: "default",             // "default" | "light" | "dark" | "outlined"
    intents: ["PAY"],
    initiationMode: "DEVICE_BEST", // "DEVICE_BEST" | "ON_PAGE" | "REDIRECT"
    initiate: (klarnaNetworkSesionToken, paymentOptionId) => initiateKlarnaPayment(klarnaNetworkSesionToken, paymentOptionId)
  })
  .mount(`#${containerId}-payment-button`);

The button will automatically handle customer interaction and trigger the Klarna purchase flow via the initiate function.

Related articles

Sharing Supplementary Purchase Data

Authorize the payment

Terms Of Service

Enabling the Perfect Customer Journey

Checkout Styling

API & SDK references

API