Skip to content

Klarna

Last updated: 6th July 2022

Start accepting payments using Klarna, a favorite payment method in Europe.

We offer Klarna's Pay in 30 days and Pay in installments payment methods, allowing your customers to either pay up to 30 days later via an invoice, or split the payment into three equal installments.

To start accepting Klarna payments, please contact your Customer Success Manager.

Model

GW only

Payment flow

Redirect

Payment method type

BNPL, Online banking

One-step payment

Authorization

Capture

Immediate capture of full amount by Checkout; future partial captures by Klarna

Refund

Partial refund

Chargeback

Recurring payment


Overview

To integrate Klarna into your checkout process and start accepting payments, follow these five steps:

  1. Create a session. When the customer reaches your checkout page, create a session with Klarna.
  2. Display widget. Initialize and load the Klarna widget to present your customer with the payment methods.
  3. Authorize. When the customer presses the buy/review order button on your page, make an authorization request.
  4. Place the order. After the order has been authorized, place the order by using the authorization token generated in step three.
  5. Capture the payment. Finally, once you've shipped the order or made it available to the customer, you can capture the payment.

Create a session

First, you need to create a Klarna session for your customer.

You should provide all known order details at this stage to enable pre-assessment and to personalize the experience for your customer.

If, however, your checkout process is designed in a way that you don't have all the customer's details at this point, you can add them later on when you load the Klarna widget or when you come to authorize the payment.

When you create a session, you will receive the available payment_method_categories, a session_id and a client_token. You can use the session_id to update the session using our API, and the client_token should be passed to the browser. A session is valid for 48 hours.

    post

    https://api.checkout.com/apms/klarna/credit-sessions

    Header parameters

    HeaderValue

    Authorization

    required

    secret key

    Use the valid secret key of your Checkout.com account. You can find this in the Hub.

    Content-Type

    required

    application/json

    Body parameters

    Field nameDescription

    purchase_country

    required
    string

    The country in which the purchase is being made (two-letter ISO 3166 code).

    currency

    required
    string

    The currency in which the payment is being made (three-letter ISO 4217 code).

    locale

    required
    string

    The customer's locale (RFC 1766 code).

    amount

    required
    integer

    The total amount of the order, including tax and any discounts.

    tax_amount

    required
    integer

    The total tax amount of the order.

    products

    required
    array

    The order details.

    This object is passed directly to Klarna as order_lines. See Klarna's documentation for more information.

    purchase_country and locale will affect the Klarna widget's validation rules. For example, when your customer is prompted for their address, the widget's postal code field will validate against available post codes in the country specified in purchase_country.

    Request example

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    {
    "purchase_country": "GB",
    "currency": "GBP",
    "locale": "en-GB",
    "amount": 1000,
    "tax_amount": 1,
    "products": [
    {
    "name": "Brown leather belt",
    "quantity": 1,
    "unit_price": 1000,
    "tax_rate": 0,
    "total_amount": 1000,
    "total_tax_amount": 0
    }
    ]
    }

    Response examples

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      {
      "session_id": "kcs_55xomnyd3ftujckeoyuvtkx2ue",
      "client_token": "eyJhbGciOiJub25lIn0.ewogICJzZXNzaW9uX2lkIiA6ICI1MGEzYTNiOS02NGE5LTYwNjMtODNmNC1hMzRlM2Q4MjRiNGIiLAogICJiYXNlX3VybCIgOiAiaHR0cHM6Ly9rbGFybmEtcGF5bWVudHMtZXUucGxheWdyb3VuZC5rbGFybmEuY29tIiwKICAiZGVzaWduIiA6ICJrbGFybmEiLAogICJsYW5ndWFnZSIgOiAiZW4iLAogICJwdXJjaGFzZV9jb3VudHJ5IiA6ICJHQiIsCiAgImFuYWx5dGljc19wcm9wZXJ0eV9pZCIgOiAiVUEtMzYwNTMxMzctMTEiLAogICJ0cmFjZV9mbG93IiA6IGZhbHNlLAogICJlbnZpcm9ubWVudCIgOiAicGxheWdyb3VuZCIsCiAgIm1lcmNoYW50X25hbWUiIDogIlBsYXlncm91bmQgRGVtbyBNZXJjaGFudCIsCiAgInNlc3Npb25fdHlwZSIgOiAiUEFZTUVOVFMiLAogICJjbGllbnRfZXZlbnRfYmFzZV91cmwiIDogImh0dHBzOi8vZXZ0LnBsYXlncm91bmQua2xhcm5hLmNvbSIKfQ.",
      "payment_method_categories": [
      {
      "asset_urls": {
      "descriptive": "https://cdn.klarna.com/1.0/shared/image/generic/badge/en_gb/slice_it/descriptive/pink.svg",
      "standard": "https://cdn.klarna.com/1.0/shared/image/generic/badge/en_gb/slice_it/standard/pink.svg"
      },
      "identifier": "pay_over_time",
      "name": "Pay in installments"
      },
      {
      "asset_urls": {
      "descriptive": "https://cdn.klarna.com/1.0/shared/image/generic/badge/en_gb/pay_later/descriptive/pink.svg",
      "standard": "https://cdn.klarna.com/1.0/shared/image/generic/badge/en_gb/pay_later/standard/pink.svg"
      },
      "identifier": "pay_later",
      "name": "Pay in 30 days"
      }
      ],
      "_links": {
      "self": {
      "href": "http://localhost:5100/credit-sessions/kcs_55xomnyd3ftujckeoyuvtkx2ue"
      }
      }
      }

      If something goes wrong, you may get a 400 Bad request or 401 Unauthorized to access this resource error.


      Display widget

      Next, load the widget on your page so your customer can choose one of the Klarna payment methods.

      Add the JavaScript SDK to your page

      To do so, you first need to insert the below code into your page to load the Klarna Payments Library in your client.

      1
      2
      3
      4
      5
      6
      7
      //<![CDATA[
      window.klarnaAsyncCallback = function () {
      // This is where you start calling Klarna's JS SDK functions
      //
      // Klarna.Payments.init({ ... })
      };
      //]]>

      Initialize the SDK

      Then initialize the Klarna Payments Library. To do this, call init and pass the client_token that you got in the response when you created the session in the first step.

      1
      2
      3
      4
      5
      6
      7
      8
      9
      try {
      Klarna.Payments.init(
      {
      client_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.dtxWM6MIcgoeMgH87tGvsNDY6cH"
      }
      );
      } catch (e) {
      // Handle error
      }

      Add a container to your page

      Next, specify where you want the widget by adding a container to your checkout page with the following snippet.

      1
      <div id="klarna_container"></div>

      The Klarna Payments iframe requires a minimum width of 280px.

      Display available payment methods

      To show your customers the Klarna payment options open to them (i.e. Pay in 30 days and Pay in installments), use the following payment_method_categories array, which you'll find in the response you received when you created the session in step one.

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      {
      // ...
      "payment_method_categories": [
      {
      "asset_urls": {
      "descriptive": "https://cdn.klarna.com/1.0/shared/image/generic/badge/en_gb/slice_it/descriptive/pink.svg",
      "standard": "https://cdn.klarna.com/1.0/shared/image/generic/badge/en_gb/slice_it/standard/pink.svg"
      },
      "identifier": "pay_over_time",
      "name": "Pay in installments"
      },
      {
      "asset_urls": {
      "descriptive": "https://cdn.klarna.com/1.0/shared/image/generic/badge/en_gb/pay_later/descriptive/pink.svg",
      "standard": "https://cdn.klarna.com/1.0/shared/image/generic/badge/en_gb/pay_later/standard/pink.svg"
      },
      "identifier": "pay_later",
      "name": "Pay in 30 days"
      }
      ]
      // ...
      }

      Load the Klarna widget

      When that's done, present the Klarna widget to your customer by calling load, passing the ID of the container you added earlier and specifying the payment_method_categories.

      If your customer has changed, say, their order or billing details since the session was created, you can also use load to pass these updates to the session by adding the relevant information to the data object.

      Field nameDescription

      options

      required
      object

      Use this to contain the container ID, payment_method_categories, and instance_id.

      options.container

      required
      string

      The ID you specified for the Klarna container above.

      options.payment_method_categories

      required
      array

      The identifiers of the payment_method_categories you want to present to the customer. (i.e. pay_later and/or pay_over_time)

      options.instance_id

      required
      string

      The ID you'll use to identify this instance of the Klarna Payments client.

      You should include this same instance_id for subsequent actions, like authorize, to indicate which instance the action applies to.

      data

      optional
      object

      If the customer has changed any of their order or billing information, this can be used to update the session.

      data.purchase_country

      optional
      string

      The country in which the purchase is being made (two-letter ISO 3166 code).

      data.purchase_currency

      optional
      string

      The currency in which the payment is being made (three-letter ISO 4217 code).

      data.locale

      optional
      string

      The customer's locale (RFC 1766 code).

      data.billing_address

      optional
      object

      Details about the customer's billing address.

      data.shipping_address

      optional
      object

      Details about the customer's shipping address.

      data.order_amount

      optional
      integer

      The total amount of the order, including tax and any discounts.

      data.order_tax_amount

      optional
      integer

      Total tax amount of the order.

      data.order_lines

      optional
      array

      Details about the order.

      This object is passed directly to Klarna as order_lines. See Klarna's documentation for more information.

      data.customer

      optional
      object

      Details about the customer.

      callback

      required
      function

      Catches the response from Klarna.Payments.load() for further processing.

      We recommend passing the data object with every call to load, to ensure that the session reflects any changes the customer might have made to their order or billing information.

      Example

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      try {
      Klarna.Payments.load(
      // options
      {
      container: "#klarna_container",
      payment_method_categories: ["pay_later", "pay_over_time"],
      instance_id: "klarna-payments-instance"
      },
      // data
      {
      purchase_country: "GB",
      purchase_currency: "GBP",
      locale: "en-GB",
      billing_address: {
      given_name: "John",
      family_name: "Doe",
      email: "johndoe@email.com",
      title: "Mr",
      street_address: "13 New Burlington St",
      street_address2: "Apt 214",
      postal_code: "W13 3BG",
      city: "London",
      region: "",
      phone: "01895808221",
      country: "GB"
      },
      shipping_address: {
      given_name: "John",
      family_name: "Doe",
      email: "johndoe@email.com",
      title: "Mr",
      street_address: "13 New Burlington St",
      street_address2: "Apt 214",
      postal_code: "W13 3BG",
      city: "London",
      region: "",
      phone: "01895808221",
      country: "GB"
      },
      order_amount: 10,
      order_tax_amount: 0,
      order_lines: [
      {
      type: "physical",
      reference: "19-402",
      name: "Battery Power Pack",
      quantity: 1,
      unit_price: 1000,
      tax_rate: 0,
      total_amount: 1000,
      total_discount_amount: 0,
      total_tax_amount: 0,
      product_url: "https://www.estore.com/products/f2a8d7e34",
      image_url: "https://www.exampleobjects.com/logo.png"
      }
      ],
      customer: {
      date_of_birth: "1970-01-01",
      gender: "male"
      }
      },
      // callback
      function (response) {
      // ...
      }
      );
      } catch (e) {
      // Handle error. The load~callback will have been called
      // with "{ show_form: false }" at this point.
      }

      Response examples

        1
        2
        3
        {
        show_form: true
        }

        Authorize the order

        When your customer presses the buy now button, you can authorize the order. In return, you'll receive an authorization token, which you'll then use to complete the payment.

        The authorize call may require the customer to provide more details, meaning that the response could be instant, could take a very long time (i.e. the time it takes the customer to complete the form), or might not happen (if the customer drops out). The integration, therefore, should not rely on an immediate response and should not implement timeouts on the merchant side, but, rather, wait for the callback function to be called.

        Field nameDescription

        options

        required
        object

        Use this to pass the instance_id.

        options.instance_id

        required
        string

        The ID of the Klarna Payments instance you want to authorize.

        You should use the instance_id from the load call above.

        data

        optional
        object

        Use this to provide any order or billing details that the customer has changed.

        callback

        required
        function

        Catches the response from Klarna.Payments.authorize() for further processing.

        Example

        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        try {
        Klarna.Payments.authorize(
        // options
        {
        instance_id: "klarna-payments-instance" // Same as instance_id set in Klarna.Payments.load().
        },
        // data
        {
        billing_address: {
        // ...
        }
        },
        // callback
        function (response) {
        // ...
        }
        );
        } catch (e) {
        // Handle error. The authorize~callback will have been called
        // with "{ show_form: false, approved: false }" at this point.
        }

        Response examples

          1
          2
          3
          4
          5
          {
          authorization_token: "b4bd3423-24e3",
          approved: true,
          show_form: true
          }

          Place the order

          If the authorization was successful, you will have received an authorization_token, which you can now use to place the customer's order.

          Do not auto-capture the payment!

          When you're processing a transaction via Klarna, you must only capture the payment once the goods have been shipped to the customer, unless you are selling an online service that the customer may use immediately.

          Endpoints

          You can find the full list, as well as complete request and response examples, in our API reference.

            post

            https://api.checkout.com/payments

            Request example

            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            30
            31
            32
            33
            34
            35
            36
            37
            38
            {
            "amount": 1000,
            "currency": "GBP",
            "capture": false,
            "source": {
            "type": "klarna",
            "authorization_token": "b4bd3423-24e3",
            "locale": "en-GB",
            "purchase_country": "GB",
            "tax_amount": 0,
            "billing_address": {
            "given_name": "John",
            "family_name": "Doe",
            "email": "johndoe@email.com",
            "title": "Mr",
            "street_address": "13 New Burlington St",
            "street_address2": "Apt 214",
            "postal_code": "W13 3BG",
            "city": "London",
            "phone": "01895808221",
            "country": "GB"
            },
            "customer": {
            "date_of_birth": "1970-01-01",
            "gender": "male"
            },
            "products": [
            {
            "name": "Battery Power Pack",
            "quantity": 1,
            "unit_price": 1000,
            "tax_rate": 0,
            "total_amount": 1000,
            "total_tax_amount": 0
            }
            ]
            }
            }

            Response example

            Unlike the other payment method supports, Klarna is always synchronous. The redirect links contained in the response set Klarna-specific cookies, so that the customer is recognized in future payment requests.

            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            30
            31
            32
            33
            34
            35
            {
            "id": "pay_y3oqhf46pyzuxjbcn2giaqnb44",
            "action_id": "act_y3oqhf46pyzuxjbcn2giaqnb44",
            "amount": 1000,
            "currency": "GBP",
            "approved": true,
            "status": "Authorized",
            "response_code": "10000",
            "response_summary": "Approved",
            "source": {
            "type": "klarna",
            "order_id": "5ca8d9ed-d327-61a8-a8f7-c947073142ee",
            "fraud_status": "ACCEPTED"
            },
            "customer": {
            "date_of_birth": "1970-01-01",
            "gender": "male"
            },
            "processed_on": "2019-01-15T10:59:51Z",
            "reference": "ORD-5023-4E89",
            "_links": {
            "self": {
            "href": "https://api.checkout.com/payments/pay_y3oqhf46pyzuxjbcn2giaqnb44"
            },
            "actions": {
            "href": "https://api.checkout.com/payments/pay_y3oqhf46pyzuxjbcn2giaqnb44/actions"
            },
            "klarna:payment-capture": {
            "href": "https://api.checkout.com/klarna/orders/pay_jfcxs5vllp5ufden4lhe2wy4b4/captures/"
            },
            "klarna:payment-void": {
            "href": "https://api.checkout.com/klarna/orders/pay_jfcxs5vllp5ufden4lhe2wy4b4/voids/"
            }
            }
            }

            The 202 response with an approved: true flag confirms that Klarna will process your payout as soon as you capture the payment in the next step.


            Capture the payment

            Capture physical products after shipping

            Klarna requires you to ship the product before capturing the payment. If, however, you provide the customer with immediate access to your product (e.g., you provide them with an online service), you can capture the payment as soon as the order is placed.

            If you're shipping goods, it's a good idea to include the shipping_info for transparency as Klarna will include it in the correspondence with your customer.

            Be careful not to capture payments on Klarna's Back Office.

              post

              https://api.checkout.com/klarna/orders/{payment_id}/captures

              Header and path parameters

              HeaderValue

              Authorization

              required

              secret key

              Use the valid secret key of your Checkout.com account. You can find this in the Hub.

              Content-Type

              required

              application/json

              PathValue

              payment_id

              required

              The payment ID you received in the response when you placed the order.

              Body parameters

              Field nameDescription

              amount

              optional
              integer

              The amount you wish to capture. If you don't specify, you will capture the full payment amount.

              reference

              optional
              string

              A reference, such as an order number, you can later use to identify this payment.

              metadata

              optional
              object

              A set of key-value pairs that you can attach to a payment. You can use this to store additional information in a structured format.

              type

              optional
              string

              Type which can be used as a discriminator for a more generic capture endpoint with property bags.

              klarna

              required
              object

              Contains the order and shipping information.

              klarna.description

              optional
              string

              A description of the order shown to the customer.

              Up to 255 characters.

              klarna.products

              optional
              array

              The order details.

              This object is passed directly to Klarna as order_lines. See Klarna's documentation for more information.

              klarna.shipping_info

              optional
              array

              The shipping information for the order.

              klarna.shipping_delay

              optional
              integer

              The delay before the order is shipped. This field is currently not returned when reading the order.

              If you want to submit a value greater than 0, this needs to be enabled in your account. Please contact Klarna for further information.

              Request example

              1
              2
              3
              4
              5
              6
              7
              8
              9
              10
              11
              12
              13
              14
              15
              16
              17
              18
              19
              20
              21
              22
              23
              24
              25
              26
              27
              28
              29
              30
              31
              {
              "amount": 1000,
              "reference": "ORD-5023-4E89",
              "metadata": {},
              "type": "klarna",
              "klarna": {
              "description": "Your order with Checkout.com",
              "products":[
              {
              "name": "Battery Power Pack",
              "quantity": 1,
              "unit_price": 1000,
              "tax_rate": 0,
              "total_amount": 1000,
              "total_tax_amount": 0
              }
              ],
              "shipping_info": [
              {
              "shipping_company": "DHL US",
              "shipping_method": "PickUpStore",
              "tracking_number": "63456415674545679874",
              "tracking_uri": "http://shipping.example/findmypackage?63456415674545679874",
              "return_shipping_company": "DHL US",
              "return_tracking_number": "93456415674545679888",
              "return_tracking_uri": "http://shipping.example/findmypackage?93456415674545679888"
              }
              ],
              "shipping_delay": 0
              }
              }

              Response examples

                1
                2
                3
                {
                "action_id": "act_4sz4seltcrzuvcgaetumnlamq4"
                }

                If unsuccessful, you may receive a 403 Capture not allowed or 404 Payment not found error.

                Refund a payment

                Klarna supports both partial and full refunds. You can refund a payment through the hub or using the refund API.

                Void a payment

                  post

                  https://api.checkout.com/klarna/orders/{payment_id}/voids

                  Header and path parameters

                  HeaderValue

                  Authorization

                  required

                  secret key

                  Use the valid secret key of your Checkout.com account. You can find this in the Hub.

                  Content-Type

                  required

                  application/json

                  PathValue

                  payment_id

                  required

                  The payment ID (prefixed with pay_) you received in the response when you placed the order.

                  Body parameters

                  Field nameDescription

                  reference

                  optional
                  string

                  A reference, such as an order number, you can later use to identify this payment.

                  metadata

                  optional
                  object

                  A set of key-value pairs that you can attach to a payment. You can use this to store additional information in a structured format.

                  Request example

                  1
                  2
                  3
                  4
                  {
                  "reference": "ORD-5023-4E89",
                  "metadata": {}
                  }

                  Response examples

                    1
                    2
                    3
                    {
                    "action_id": "act_v6572a7elpuupbaljmoi4tk3ma"
                    }

                    If unsuccessful, you may get a 403 Void not allowed or 404 Payment not found error.

                    Testing Klarna

                    To start testing, you'll need to:

                    • create a test account, and
                    • contact your Customer Success Manager or Integrations engineer to activate Klarna payments in the sandbox environment.
                    1. Follow the steps above to display the Klarna widget ready for payment.
                    2. Select the desired payment method and pay.

                    When testing, you may be asked to verify your details. If so, follow Klarna’s testing guide.