Klarna Docs - Create a payment request in Klarna Network
Create a payment request in Klarna Network

This step will be carried out in two different ways depending on your type of integration:

Klarna requires the payment request be initiated using the Klarna payment button wherever possible. This allows for a simple client-side integration with proactively maintained messaging.

If this is not possible, an alternate flow is described in Klarna payment button cannot be initiated.

null

We recommend Partners to change their payment button to Klarna’s payment button when a customer selects Klarna, using the theme most appropriate to the Partner page.

JAVASCRIPT
<div id="#button-container">

</div>

JAVASCRIPT
var klarnaPaymentButton = klarna.Payment.button({
  id: "klarna-payment-button",
  shape: "pill",
  label: "Pay",
  theme: "dark"
});

klarnaPaymentButton.mount('#button-container'); 

Configure the InteractionMode

The payment request options allows you to specify the interactionMode parameter which controls how the Klarna purchase flow is launched (redirect / modal window) on different devices (mobile/desktop/native):

interactionModeDefinition
DEVICE_BESTThis is the default value and recommended. Klarna automatically selects the best flow depending on the device:
  • Mobile: REDIRECT
  • Desktop: Modal window if possible, fallback to REDIRECT.
  • Native webview (mobile app) - REDIRECT
Note: a config.redirectUrl is required in the payment request for this interaction mode
ON_PAGEThis value should be used only if redirection is not possible.
The transaction happens on the same page by using a modal window if possible, if not then it will fallback to fullscreen iframe.
REDIRECTOnly redirect flow.
Note: a config.redirectUrl is required in the payment request for this interaction mode

Generate a Redirect URL

The redirectUrl guides the customer back to your online store after a completed or canceled payment request. By embedding placeholders in the URL, Klarna can dynamically insert pertinent transaction information, ensuring the URL is comprehensive for transaction processing.

To ensure security and integrity, the server-side confirmation payment request call is required to complete a payment. Klarna recommends all partners verify data received via redirect against that received via webhooks to prevent token misuse. Tokens passed via the redirect_url are only valid for the account that completes the payment, preventing hijacking.

For mobile integrations, ensure the redirectUrl is a deep link.

Redirect URL example

JAVASCRIPT
config: {
  redirectUrl:
"https://partner.example/klarna-redirect?confirmation_token={klarna.payment_request.payment_confirmation_token}&request_id={klarna.payment_request.id}&state={klarna.payment_request.state}&reference={klarna.payment_request.payment_reference}"
}

These placeholders enable the redirect URL to dynamically incorporate all necessary transaction details. Klarna replaces these placeholders with actual values prior to redirection, facilitating a smooth redirection process for partners and ensuring that all critical information is accessible for processing the transaction. Details about the available placeholders are provided below:

PlaceholderDescriptionExample
{klarna.payment_request.payment_confirmation_token}The confirmation token, available when a transaction is successfully completed, and used to confirm the transaction.krn:payment:eu1:confirmation-token:51bbf3db-940e-5cb3-9003-381f0cd731b7
{klarna.payment_request.id}Klarna Payment Request identifier. Used in management of a Payment Request.bebeabea-5651-67a4-a843-106cc3c9616a
{klarna.payment_request.state}State of the payment request - may be used as a hint.CONFIRMED
{klarna.payment_request.payment_reference}The provided reference to the payment request.partner-payment-reference-12345

Payment request updates

A payment request can be initiated either directly by the Klarna Partner, using the Klarna Payment Services, or implicitly through the Klarna payment button interface:

  • Once the Web SDK is loaded and a payment request is created, that same it is used throughout the entire session.
  • The payment request cannot be retrieved server-side if it is shared with Klarna when the initiate() method is called.
  • When using the Klarna payment button, the initial payment request is passed in the click handler. The click handler allows you to modify the payment request data and choose if you want to initiate the payment.

Both the request() and initiate() methods share the same set of input parameters.

  • request(paymentRequestData?, options?): Request
  • initiate(paymentRequestData?, options?): Promise<void>

The payment request data allows the Klarna Partner to provide properties for the ongoing purchase.

ParameterDefinition
paymentAmountTotal payment amount
currency3-letter ISO 4217 currency code
config (optional)Configuration object for the payment request, in which the redirectUrl? properties can be provided.
config.paymentOptionIdThe identifier returned by Klarna’s messaging API or Web SDK to support the preselection of payment options within the Klarna payment flow. This identifier is required if Klarna is presented as more than one payment option.
config.shoppingSessionIdThe identifier returned by Klarna’s Web SDK which ties a customer's activities together across multiple features.
If Klarna’s Web SDK is integrated by the partner, this identifier must be mapped to the shoppingSessionId returned by Klarna. Klarna Partners must make this value available to Partners, and allow them to pass this through to Klarna at all interactions.
supplementaryPurchaseData (optional)An object encapsulating additional information related to a purchase transaction, providing comprehensive details to support and enhance the core purchase data.
supplementaryPurchaseData.purchaseReference (optional)Used for storing the customer-facing transaction number. It will be displayed to customers on the Klarna app and other communications. It will also be included in settlement reports for the purpose of reconciliation.
supplementaryPurchaseData.customer (optional)This represents who the customer is according to the Partner. These data points may be used by Klarna to simplify sign-up and during fraud assessment, they will not be used for underwriting and will not be persisted on created Payment Authorizations
supplementaryPurchaseData.shipping (optional)Shipping information for the purchase. This data is used for fraud detection and customer communication.
If the purchase contains multiple shipments with different recipients, you must provide one shipping object per shipment.
supplementaryPurchaseData.lineItems (optional)Detailed line item information of the purchase. This data is used for fraud detection and improving the customer experience in the Klana app. T​​he total sum of the line items must match the payment amount.
Line items stand at the crossroads of Klarna's operations, improving our fraud detection and underwriting capabilities, enhancing the consumer's post-purchase experience through streamlined disputes, returns and more. By dissecting transactions into individual units of purchase, we provide a detailed map of the consumer's buying behavior, facilitating a more personalized and efficient service in the Klarna app.

Consult the SDK reference for a complete description of the request body parameters.SDK reference for a complete description of the request body parameters.

When using the Klarna payment button, the initial payment request is passed in the click handler, where you can modify the request and initiate it. Configurations available for the request are detailed below.
<div style="flex: 1; padding: 10px;">

JAVASCRIPT
klarnaPaymentButton.on("click", async (paymentRequest) => {
  paymentRequest.initiate(
    {
      paymentAmount: 9999,
      currency: "EUR",
      config: {
      redirectUrl:      "https://example.com?id={klarna.payment_request.id}andtoken={klarna.payment_request.payment_confirmation_token}"
      }
    },
    {

</div>

Upon being redirected, the customer will enter Klarna's payment flow, where they can select their payment method and provide any required information. This process may also involve signing into their Klarna account to continue with the payment.

Be mindful when sharing customer data:

  • The Partner is required to, while respecting the privacy of their customers, send all applicable customer data points when initiating the payment request which is then prefilled in the funnel.
  • The Partner is responsible for disclosing how and when personal information is shared with their partners
  • Returning customers checking out from a device where they are logged-in would skip the authentication step in the funnel.

To start the purchase flow a payment request must be created. This request ensures that all necessary information is provided for a successful transaction. To start the process send a POST request to /v2/accounts/{account_id}/payment/requests.

The following data points are required for a successful request:

ParameterDefinitionExample
currencyThe currency in which the transaction is made.EUR
payment_amountThe total amount to be charged, matching the sum of all line item amounts if any are provided.1000
config.payment_option_idSpecifies a payment option to be pre-selected in the purchase flow.czxsa4324132dsaddsxcxzzxs
interoperability.interoperability_tokenUnique identifier for a shopping  session.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzaG9wcGluZ19zZXNzaW9uX2lkIjoia3JuOnNob3BwaW5nOmV1MTpz
config.redirect_urlThe URL provided by the integrator where the customer will be redirected after a successful purchase.https://klarna.com?authorization_token={klarna.payment_request.payment_confirmation_token}andpayment_request_state={klarna.payment_request.state}

Consult the API reference for a complete description of the request body parameters.API reference for a complete description of the request body parameters.

When the payment request has been successfully created, Klarna will return an HTTP 201 CreatedHTTP 201 Created. The response body will contain the payment_request_id as well as the state_context.distribution.url to which the customer should be redirected to.

If the payment request ends up at SUBMITTED, the Partner should redirect the customer to the start link provided in the response. This link is located at state_context.payment_distribution.url in the response of the  Step 2: Create a payment request server-side

Shopping journey

Upon being redirected, the customer will enter Klarna's payment flow. This flow allows the customer to choose their payment method and input any necessary information. The process also requires the customer to log in to their Klarna account, if needed, to proceed with the payment.

After completing these steps, the customer is redirected to the URL specified in the config.redirect_url. This URL is provided in the initial payment request and ensures the customer returns to the Partner's site after a successful transaction.
<div style="flex: 1; padding: 10px;">

JSON
"config": {
   "redirect_url": "https://merchant.com?authorization_token={klarna.payment_request.payment_confirmation_token}"
}

</div>