Create order

The first step is to create an order using the create_order API call with the correct authentication and endpoint (URL), to which Klarna responds with an HTML snippet that allows the merchant to render the Checkout iframe.

This step should be done after the consumer selects their product(s) and proceeds to Checkout.

Authentication

You probably have your test credentials already, otherwise you can get them here .

Klarna uses HTTP Basic Auth for authentication. Use the API credentials provided to you to authenticate with Klarna. The credentials consists of two elements:

  • Username: a username linked to your Merchant ID at Klarna
  • Password: a unique password that is associated with the username Authentication: Base64(username:password)

Never share your test or live credentials.

Endpoints (URLs)

Klarna’s European and North American environments have different endpoints (URLs) for testing and for live purchases. All requests to Klarna go through HTTPS. Read more here

Create order request

To create an order you will use our REST API and make a HTTP POST request towards the right test endpoint + /checkout/v3/orders with the header content-type: application/json.

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
{
  "purchase_country": "GB",
  "purchase_currency": "GBP",
  "locale": "en-GB",
  "order_amount": 50000,
  "order_tax_amount": 4545,
  "order_lines": [
      {
          "type": "physical",
          "reference": "19-402-USA",
          "name": "Red T-Shirt",
          "quantity": 5,
          "quantity_unit": "pcs",
          "unit_price": 10000,
          "tax_rate": 1000,
          "total_amount": 50000,
          "total_discount_amount": 0,
          "total_tax_amount": 4545
      }
    ],
  "merchant_urls": {
    "terms": "https://www.example.com/terms.html",
    "checkout": "https://www.example.com/checkout.html?order_id={checkout.order.id}",
    "confirmation": "https://www.example.com/confirmation.html?order_id={checkout.order.id}",
    "push": "https://www.example.com/api/push?order_id={checkout.order.id}"
  },
}

The example above is configured for UK(GB) and contains the minimum amount of data that is needed to create an order with mock URLs. Please see popular use cases , in-depth knowledge and our API reference for more details on how to configure an order for your specific needs.

Create order response

To read about all of the data fields in the response see our api reference for now we will highlight:

  • order_id a unique ID generated by Klarna which you need to keep track of since it is a reference to the order you created.
  • html_snippet a string that you need to include on your page to render the checkout. We will do that in the next step of this guide.
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
{
  "order_id": "8cf27b55-53e8-6aba-9fb4-7c692e56ddee",
  "status": "checkout_incomplete",
  "purchase_country": "gb",
  "purchase_currency": "GBP",
  "locale": "en-GB",
  "billing_address": {
    "country": "gb"
  },
  "customer": {},
  "shipping_address": {
    "country": "gb"
  },
  "order_amount": 50000,
  "order_tax_amount": 4545,
  "order_lines": [
    {
      "type": "physical",
      "reference": "19-402-USA",
      "name": "Red T-Shirt",
      "quantity": 5,
      "quantity_unit": "pcs",
      "unit_price": 10000,
      "tax_rate": 1000,
      "total_amount": 50000,
      "total_discount_amount": 0,
      "total_tax_amount": 4545
    }
  ],
  "merchant_urls": {
    "terms": "https://www.example.com/terms.html",
    "checkout": "https://www.example.com/checkout.html?order_id={checkout.order.id}",
    "confirmation": "https://www.example.com/confirmation.html?order_id={checkout.order.id}",
    "push": "https://www.example.com/api/push?order_id={checkout.order.id}"
  },
  "html_snippet": "<div id=\"klarna-checkout-container\".................",
  "started_at": "2020-03-05T10:41:58Z",
  "last_modified_at": "2020-03-05T10:41:58Z",
  "options": {
    "allow_separate_shipping_address": false,
    "date_of_birth_mandatory": false,
    "require_validate_callback_success": false
  },
  "external_payment_methods": [],
  "external_checkouts": []
}

What’s next?

It’s time to render checkout on your website! Continue to render Checkout snippet