klarna_network_session_token, and finalizing authorization. See Authorize a customer-initiated payment (Web SDK).klarna.mjs) follows the JavaScript module approach and should be included where a reference to the SDK is needed, such as while rendering components or initiating a payment flow.| Parameter | Presence | Description |
|---|---|---|
clientId | required | A credential used to identify the Partner, obtained from the Klarna Partner Portal. Register all domains where the Web SDK will be used. |
products | optional | An array used to specify which products should be loaded to optimize performance by limiting the amount of data downloaded. When the PAYMENT product is included, only the klarna.Payment package is loaded. When the products array is omitted, all available packages are loaded by default. |
locale | optional | Language and region code (for example, en-US). When omitted, Klarna may default based on the customer's browser settings. |
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",
});
// Klarna SDK ready to be used:
// klarna.Payment.presentation({ ... });| Do | Don't |
|---|---|
Load the Web SDK from https://js.klarna.com/web-sdk/v2/klarna.mjs to remain compliant. | Bundle the Web SDK or self-host it. |
Keep the SDK in the top-level (1st-party) browsing context. | Load the Web SDK inside an iframe. |
Specify products to optimize loading. | Omit the products array. |
Disclose Web SDK tracking in the site's notices. See the Klarna Web SDK terms. | Use the Web SDK without disclosing tracking technologies. |
klarna.Payment.presentation() method.| Parameter | Presence | Description |
|---|---|---|
amount | conditional | The transaction amount in minor units following ISO 4217 exponents (for example, $118.00 = 11800, ¥1400 = 1400). Required when the intent is PAY or SUBSCRIBE; otherwise optional. |
currency | required | Three-letter ISO 4217 currency code (for example, USD, EUR). |
locale | optional | Locale code to localize texts and formats (for example, en-US, de-DE). When unset, the value chosen at Web SDK setup time is used automatically. When that is not available, the browser's settings are used instead. |
intent | optional | Specify the intent of the checkout flow: PAY, SUBSCRIBE, ADD_TO_WALLET. When omitted, intent defaults to PAY. |
klarna.Payment.presentation() (instalment amounts, messaging, and links) are tied to the amount passed in the call. If the customer changes the basket or final amount after Klarna is already displayed, call klarna.Payment.presentation() again with the updated amount and re-render Klarna with the new response. Displaying presentation from an older total can show incorrect instalment amounts and mislead customers.const paymentPresentation = await klarna.Payment.presentation({
amount: 11800,
currency: "USD",
locale: "en-US",
intent: "PAY"
});PaymentPresentation interface provides the full Klarna branding package and instructions tailored to the customer's purchase:| Attribute | Presence | Purpose |
|---|---|---|
instruction | required | Specifies how Klarna should be displayed in the payment selector (show, preselect, show only, or hide). Adhering to these instructions ensures customers have the best possible experience and optimizes conversion rates. |
paymentOption | optional | Defines the default Klarna payment option applicable to all purchase types. Includes the visual elements required to represent Klarna during checkout. |
savedPaymentOption | optional | Defines the customer's saved payment option, available when the customer has authenticated with a Customer Token. The structure mirrors paymentOption. When present, prioritize savedPaymentOption over paymentOption to provide the best experience for returning customers. |
paymentOption and savedPaymentOption share the same object structure:| Attribute | Presence | Purpose |
|---|---|---|
paymentOptionId | required | The identifier of the payment option. The value is required when later sending the Payment Authorize API or the Payment Request API call to initiate the payment. |
icon | required | Klarna badge/logo suitable for checkout forms. |
header | required | The main descriptor that introduces Klarna in the payment form. The value is dynamically adjusted based on the locale provided. |
subheader | required | The descriptor subheader, loaded inline below the main descriptor header. Short and enriched descriptive texts. Provides transparency on available options like instalments, pay later, and so on. |
message | optional | Enriched tailored description with link. |
badge | optional | Badge used for saved options or promotions. |
terms | optional | Defines terms or disclosures, potentially with links. |
paymentButton | required | Payment button that starts the Klarna Purchase Journey. |
customer_token directly to the Web SDK. When the klarna_network_session_token issued by Klarna for the session is bound to a known customer (for example, after Sign in with Klarna or a previous tokenization), the SDK automatically surfaces the customer's saved payment option in the presentation() response — the response includes savedPaymentOption and the instruction is PRESELECT_KLARNA. To authorize a payment with a stored customer_token server-side without going through the Web SDK, see the Customer Token resource.instruction attribute has the following values:| Instruction | Description |
|---|---|
SHOW_KLARNA | Show Klarna alongside other payment methods. |
PRESELECT_KLARNA | Show Klarna pre-selected but still alongside others. Returned when using a customer_token issued from the Sign in with Klarna feature or the tokenization flow. |
SHOW_ONLY_KLARNA | Show Klarna as the only payment method. Returned when the customer has finished the first step of Klarna Express Checkout multistep. |
HIDE_KLARNA | Hide Klarna from the payment methods. Returned when Klarna is unavailable in the customer's context (for example, when access has been revoked) and the Partner should not offer Klarna for this checkout. |
paymentOption (default) and savedPaymentOption (customer-specific). Prioritize savedPaymentOption when both are present.function renderKlarna(paymentPresentation) {
if (!paymentPresentation) return;
const root = qs("#klarna-payment-method");
if (!root) {
console.error("Missing #klarna-payment-method container.");
return;
}
root.innerHTML = `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 the visual components and how they are rendered in different selection states:
function renderKlarnaOption(containerId, option) {
const container = qs(`#${containerId}`);
if (!container) {
console.error(`Missing #${containerId} container.`);
return;
}
const ids = {
icon: `${containerId}-icon`,
header: `${containerId}-header`,/**
* Toggle the Klarna payment option selected state.
* Use for both SDK preselection (PRESELECT_KLARNA) and customer interactions.
*/
function toggleKlarnaPaymentOptionSelection(containerId, isSelected) {
const container = qs(`#${containerId}`);
if (!container) {
console.error(`Missing container #${containerId}.`);
return;
}
paymentButton.component() can be configured with the following parameters:| Parameter | Presence | Description |
|---|---|---|
id | optional | Sets a custom DOM ID on the rendered button. Useful for testing or styling. |
shape | optional | Defines the button's shape. Possible values: default, pill, rect. |
theme | optional | Sets the visual theme of the button. Possible values: default, light, dark, outlined. |
locale | optional | Sets the language and region (for example, en-US). When unset, the value chosen at Web SDK setup time is used automatically. When that is not available, the browser's settings are used instead. |
disabled | optional | Disables the button when set to true. Useful during form validation or async operations. |
loading | optional | Forces the button into a loading state. Useful when awaiting async setup or validation. |
intent | optional | Sets the purpose of the payment (PAY, SUBSCRIBE, ADD_TO_WALLET). Used to personalize the button and flow when not set when creating the PaymentPresentation instance. |
initiate | required | Function that returns a Promise resolving to either a PaymentRequestData, a paymentRequestUrl, or a returnUrl. This is handled differently depending on the integration path. |
initiationMode | optional | Defines how Klarna launches the Klarna Purchase Journey. |
option.paymentButton.component({
id: "klarna-payment-button", // optional test hook
shape: "pill", // "default" | "pill" | "rect"
theme: "default", // "default" | "light" | "dark" | "outlined"
intent: "PAY",
initiationMode: "DEVICE_BEST", // "DEVICE_BEST" | "ON_PAGE" | "REDIRECT"
initiate: async ({ klarnaNetworkSessionToken, paymentOptionId }) =>
initiateKlarnaPayment(klarnaNetworkSessionToken, paymentOptionId),
}).mount(`#${containerId}-payment-button`);initiate function. Implement the initiate callback as documented in Authorize a customer-initiated payment (Web SDK).klarna_network_session_token, and authorizing the payment.