Introduction

The Klarna Checkout REST API is the underlying interface for all our available client libraries.
This reference guide was created for those who are developing for platforms currently not supported by our client libraries, or those who are interested in diving into the details of our API.

Entry points

The Klarna Checkout API can be accessed from the following entry points, depending on the environment you are working in:

HTTPS vs HTTP

To help ensure data security, only HTTPS is allowed. HTTP is not supported.

JSON, Unicode

JSON is used across all communications as the syntax of the media-types. Only JSON's default UTF-8 encoding is supported.

 

https://checkout.klarna.com/checkout/orders - For transactions in the live environment

https://checkout.testdrive.klarna.com/checkout/orders - For test transactions in Klarna's testing environment.

Authorization

Every API request has to be authenticated by using the Authentication HTTP request header. Only a proprietary Klarna authentication scheme is supported, in the format of Klarna authorization header.

The authorization header is calculated for each request using these steps of this formula: base64 (sha256 (request_payload + shared_secret)), where

  • request_payload is the payload of the request, or an empty string for GET requests
  • shared_secret is the secret key assigned to your EID by Klarna

 

Authorization: Klarna pwhcueUff0MmwLShJiBE9JHA==

Resource structure

Legend

O, optional

M, mandatory

R, read only

 

  checkout_complete / created    
  checkout_incomplete    
       
Name Description    
id Unique identifier of the Klarna Checkout Order R R
merchant_reference Container for merchant reference. Currently supported keys are orderid1 and orderid2 O O
purchase_country Country in which the purchase is done (ISO-3166-alpha2) M R
purchase_currency Currency in which the purchase is done (ISO-4217) M R
locale Locale indicative for language & other location-specific details (RFC1766) M R
status Status. `checkout_incomplete` by default, alternatively `checkout_complete`, `created` R O
reference End-consumer friendly reference R R
reservation Reservation number to be used in the XML-RPC API R R
started_at Timestamp of when the Checkout started (ISO-8601) R R
completed_at Timestamp of when the Checkout was completed (ISO-8601) R R
created_at Timestamp of when the Order was created (ISO-8601) R R
last_modified_at Timestamp of when the Checkout was last modified (ISO-8601) R R
expires_at Timestamp of when the Checkout will expire (ISO-8601) R R
billing_address Billing address
billing_address.given_name Given name R R
billing_address.family_name Family name R R
billing_address.care_of c/o R R
billing_address.street_address Only in Sweden, Norway and Finland: Street address (street name, street number, street extension) R R
billing_address.street_name Only in Germany: Street name R R
billing_address.street_number Only in Germany: Street number R R
billing_address.postal_code Postal code R R
billing_address.city City R R
billing_address.country Country (ISO-3166 alpha) R R
billing_address.email E-mail address R R
billing_address.phone Phone number R R
billing_address.title Only in Germany: The customer's title, possible values are "Herr" and "Frau" R R
shipping_address Shipping address
shipping_address.given_name Given name O R
shipping_address.family_name Family name O R
shipping_address.care_of c/o O R
shipping_address.street_address Only in Sweden, Norway and Finland: Street address (street name, street number, street extension) O R
shipping_address.street_name Only in Germany: Street name O R
shipping_address.street_number Only in Germany: Street number O R
shipping_address.postal_code Postal code O R
shipping_address.city City O R
shipping_address.country Country (ISO-3166 alpha) O R
shipping_address.email E-mail address O R
shipping_address.phone Phone number O R
shipping_address.title Only in Germany: The customer's title, possible values are "Herr" and "Frau" O R
cart Cart
cart.total_price_excluding_tax Total price (excluding tax) in cents R R
cart.total_tax_amount Total tax amount in cents R R
cart.total_price_including_tax Total price (including tax) in cents R R
cart.items List of cart items
cart.items[0].type Type. `physical` by default, alternatively `discount`, `shipping_fee` O R
cart.items[0].ean The item's International Article Number. Please note this property is currently not returned when fetching the full order resource. O R
cart.items[0].reference Reference, usually the article number M R
cart.items[0].name Name, usually a short description M R
cart.items[0].uri Item product page URI. Please note this property is currently not returned when fetching the full order resource. O R
cart.items[0].image_uri Item image URI. Please note this property is currently not returned when fetching the full order resource. O R
cart.items[0].quantity Quantity M R
cart.items[0].unit_price Unit price in cents, including tax M R
cart.items[0].total_price_excluding_tax Total price (excluding tax) in cents R R
cart.items[0].total_tax_amount Total tax amount, in cents R R
cart.items[0].total_price_including_tax Total price (including tax) in cents R R
cart.items[0].discount_rate Percentage of discount, multiplied by 100 and provided as an integer. i.e. 9.57% should be sent as 957 O R
cart.items[0].tax_rate Percentage of tax rate, multiplied by 100 and provided as an integer. i.e. 13.57% should be sent as 1357 M R
customer Customer
customer.date_of_birth If provided by customer, or retrieved from national ID. The customer's birthdate (YYYY-MM-DD) O R
customer.gender Retrieved from national ID or billing_address.title in Germany. 'female' or 'male' O R
customer.type Type. Currently the only supported value is 'person' R R
gui GUI
gui.layout Layout. `desktop` by default, alternatively `mobile` O R
gui.options An array of options to define the checkout behaviour. Supported options `disable_autofocus`. O R
gui.snippet HTML snippet R R
merchant Merchant
merchant.id Unique identifier (EID) M R
merchant.terms_uri URI of your terms and conditions M R
merchant.checkout_uri URI of your checkout page M R
merchant.confirmation_uri URI of your confirmation page M R
merchant.push_uri URI of your push-notification page M R
merchant.validation_uri URI of your validation page, see validate a checkout order. O R
attachment Additional purchase information required for some industries, see here.
attachment.content_type String. O R
attachment.body String. O R

Errors

klarna uses conventional HTTP response codes to indicate success or failure of an API call. 

 

Status code Description
200 OK The request was successful.
201 Created The request was successful and created a new resource at the URI described by the `Content-Location` response header
400 Bad Request The request did not pass validation due to syntax or semantic errors. Error message should indicate the error.
401 Unauthorized Authentication failed due to an invalid or missing `Authentication` request header.
403 Forbidden The server refused to fulfil it.
404 Not Found There is no resource matching the request URI.
405 Method Not Allowed The resource did not expected the request method.
406 Not Acceptable The server cannot fulfil the `Accept` request header.
415 Media Type Not Supported The server does not support the media-type specified by the `Content-Type` request header.

 

Versioning

The Klarna Checkout API is versioned through custom media types. When we make changes to the API which are not backwards compatible, we will increment the version number in the media type.

 

 

Current version: application/vnd.klarna.checkout.aggregated-order-v2+json

Supported locales

The locale configuration in Klarna Checkout affects the iframe language and all further communication made between Klarna and the consumer.

This table specfies the supported combinations of country, currently and locale. 

 

Country Language purchase_country purchase_currency locale
Sweden Swedish SE SEK sv-se
Finland Finnish FI EUR fi-fi
Finland Swedish FI EUR sv-fi
Norway Norwegian NO NOK nb-no
 
Germany German DE EUR de-de

 

Create order

Overview

  • Description: Create a new Checkout Order resource
     
  • Request
    • Method: POST
    • URI: https://checkout.testdrive.klarna.com/checkout/orders
    • Accept: application/vnd.klarna.checkout.aggregated-order-v2+json
    • Content-Type: application/vnd.klarna.checkout.aggregated-order-v2+json
    • Body: ...
       
  • Response
    • Location: URI of the new Checkout Order resource

Examples

Once the order is created, the order will contain a HTML snippet that needs to be embedded on your Checkout page.

 

require_once 'src/Klarna/Checkout.php';

$eid = '0';
$sharedSecret = 'sharedSecret';

Klarna_Checkout_Order::$baseUri = 'https://checkout.testdrive.klarna.com/checkout/orders';
Klarna_Checkout_Order::$contentType
    = "application/vnd.klarna.checkout.aggregated-order-v2+json";

$connector = Klarna_Checkout_Connector::create($sharedSecret);
$order = new Klarna_Checkout_Order($connector);

// Array containing the cart items
$cart = array(
    array(
        'reference' => '123456789',
        'name' => 'Klarna t-shirt',
        'quantity' => 2,
        'unit_price' => 12300,
        'discount_rate' => 1000,
        'tax_rate' => 2500
    ),
    array(
        'type' => 'shipping_fee',
        'reference' => 'SHIPPING',
        'name' => 'Shipping Fee',
        'quantity' => 1,
        'unit_price' => 4900,
        'tax_rate' => 2500
    )
);

$create['purchase_country'] = 'SE';
$create['purchase_currency'] = 'SEK';
$create['locale'] = 'sv-se';
$create['merchant']['id'] = $eid;
$create['merchant']['terms_uri'] = 'http://example.com/terms.php';
$create['merchant']['checkout_uri'] = 'https://example.com/checkout.php';
$create['merchant']['confirmation_uri']
    = 'https://example.com/thankyou.php?sid=123&klarna_order={checkout.order.uri}';
$create['merchant']['push_uri'] = 'https://example.com/push.php?sid=123&klarna_order={checkout.order.uri}';

foreach ($cart as $item) {
    $create['cart']['items'][] = $item;
}

$order->create($create);
import klarnacheckout

# Dictionary containing the cart items
cart = (
    {
        'quantity': 1,
        'reference': '123456789',
        'name': 'Klarna t-shirt',
        'unit_price': 12300,
        'discount_rate': 1000,
        'tax_rate': 2500
    }, {
        'quantity': 1,
        'type': 'shipping_fee',
        'reference': 'SHIPPING',
        'name': 'Shipping Fee',
        'unit_price': 4900,
        'tax_rate': 2500
    }
)

# Merchant ID
eid = "0"

# Shared Secret
shared_secret = 'shared_secret'


klarnacheckout.Order.base_uri = \
    'https://checkout.testdrive.klarna.com/checkout/orders'
klarnacheckout.Order.content_type = \
    'application/vnd.klarna.checkout.aggregated-order-v2+json'

connector = klarnacheckout.create_connector(shared_secret)

order = None

merchant = {
    'id': eid,
    'terms_uri': 'http://example.com/terms.html',
    'checkout_uri': 'http://example.com/checkout',
    'confirmation_uri': ('http://example.com/thank-you' +
                         '?sid=123&klarna_order={checkout.order.uri}'),
    # You can not receive push notification on
    # a non publicly available uri
    'push_uri': ('http://example.com/push' +
                 '?sid=123&klarna_order={checkout.order.uri}')
}

data = {
    'purchase_country': 'SE',
    'purchase_currency': 'SEK',
    'locale': 'sv-se',
    'merchant': merchant
}
data["cart"] = {"items": []}

for item in cart:
    data["cart"]["items"].append(item)

order = klarnacheckout.Order(connector)
order.create(data)
%>
<!-- #include file="../Klarna.Asp/JSON.asp" -->
<!-- #include file="../Klarna.Asp/Order.asp" -->
<!-- #include file="../Klarna.Asp/Digest.asp" -->
<!-- #include file="../Klarna.Asp/UserAgent.asp" -->
<!-- #include file="../Klarna.Asp/BasicConnector.asp" -->
<!-- #include file="../Klarna.Asp/HttpRequest.asp" -->
<!-- #include file="../Klarna.Asp/HttpResponse.asp" -->
<!-- #include file="../Klarna.Asp/HttpTransport.asp" -->
<%
'------------------------------------------------------------------------------
' The create checkout example.
'------------------------------------------------------------------------------
Class Create

    '--------------------------------------------------------------------------
    ' The example.
    '--------------------------------------------------------------------------
    Public Sub Example()
        ' Cart
        Dim item1
        Set item1 = Server.CreateObject("Scripting.Dictionary")
        item1.Add "reference", "123456789"
        item1.Add "name", "Klarna t-shirt"
        item1.Add "quantity", 2
        item1.Add "unit_price", 12300
        item1.Add "discount_rate", 1000
        item1.Add "tax_rate", 2500

        Dim item2
        Set item2 = Server.CreateObject("Scripting.Dictionary")
        item2.Add "type", "shipping_fee"
        item2.Add "reference", "SHIPPING"
        item2.Add "name", "Shipping Fee"
        item2.Add "quantity", 1
        item2.Add "unit_price", 4900
        item2.Add "discount_rate", 2500
        item2.Add "tax_rate", 2500

        Dim cartItems(1)
        Set cartItems(0) = item1
        Set cartItems(1) = item2

        Dim cart
        Set cart = Server.CreateObject("Scripting.Dictionary")
        cart.Add "items", cartItems

        ' Create connector
        Dim transport
        Set transport = new HttpTransport
        Dim digest
        Set digest = New Digest
        Dim sharedSecret
        sharedSecret = "sharedSecret"
        Dim connector
        Set connector = CreateBasicConnector(transport, digest, sharedSecret)

        Dim contentType
        contentType = "application/vnd.klarna.checkout.aggregated-order-v2+json"

        Dim eid
        eid = "0"

        Dim merchant
        Set merchant = Server.CreateObject("Scripting.Dictionary")
        merchant.Add "id", eid
        merchant.Add "terms_uri", "http://example.com/terms.asp"
        merchant.Add "checkout_uri", "https://example.com/checkout.asp"
        merchant.Add "confirmation_uri", _
            "https://example.com/thankyou.asp?sid=123&klarna_order={checkout.order.uri}"
        ' You cannot receive push notification on a non publicly available uri.
        merchant.Add "push_uri", _
            "https://example.com/push.asp?sid=123&klarna_order={checkout.order.uri}"

        Dim data
        Set data = Server.CreateObject("Scripting.Dictionary")
        data.Add "purchase_country", "SE"
        data.Add "purchase_currency", "SEK"
        data.Add "locale", "sv-se"
        data.Add "merchant", merchant
        data.Add "cart", cart

        Dim order
        Set order = CreateOrder(connector)
        order.SetBaseUri "https://checkout.testdrive.klarna.com/checkout/orders"
        order.SetContentType contentType

        order.Create data
    End Sub

End Class
package examples;

import com.klarna.checkout.Connector;
import com.klarna.checkout.IConnector;
import com.klarna.checkout.Order;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * The create checkout example.
 */
public final class Create {

    /**
     * The example.
     */
    public void example()
            throws URISyntaxException, NoSuchAlgorithmException, IOException {

        final Map<String, Object> cart = new HashMap<String, Object>() {
            {
                put("items", new ArrayList<HashMap<String, Object>>() {
                    {
                        add(new HashMap<String, Object>() {
                            {
                                put("quantity", 2);
                                put("reference", "123456789");
                                put("name", "Klarna t-shirt");
                                put("unit_price", 12300);
                                put("discount_rate", 1000);
                                put("tax_rate", 2500);
                            }
                        });
                        add(new HashMap<String, Object>() {
                            {
                                put("quantity", 1);
                                put("type", "shipping_fee");
                                put("reference", "SHIPPING");
                                put("name", "Shipping Fee");
                                put("unit_price", 4900);
                                put("tax_rate", 2500);
                            }
                        });
                    }
                });
            }
        };

        // Merchant ID
        final String eid = "0";
        final String secret = "sharedSecret";

        Order.setContentType(
                "application/vnd.klarna.checkout.aggregated-order-v2+json");
        URI uri = new URI(
                "https://checkout.testdrive.klarna.com/checkout/orders");

        Order.setBaseUri(uri);
        IConnector connector = Connector.create(secret);

        Order order = null;

        // Start a new session.
        final Map<String, Object> merchant;
        merchant = new HashMap<String, Object>() {
            {
                put("id", eid);
                put("terms_uri", "http://example.com/terms.html");
                put("checkout_uri", "http://example.com/checkout.jsp");
                put("confirmation_uri",
                        "http://example.com/thank-you.jsp"
                        + "?sid=123&klarna_order={checkout.order.uri}");
                // You can not receive push notification on a
                // non-publicly available uri.
                put("push_uri",
                        "http://example.com/push.jsp"
                        + "?sid=123&klarna_order={checkout.order.uri}");
            }
        };

        Map<String, Object> data = new HashMap<String, Object>() {
            {
                put("purchase_country", "SE");
                put("purchase_currency", "SEK");
                put("locale", "sv-se");
                put("merchant", merchant);
                put("cart", cart);
            }
        };

        order = new Order(connector);
        order.create(data);
    }
}
namespace Klarna.Kco.Examples
{
    using System;
    using System.Collections.Generic;

    using Klarna.Checkout;

    /// <summary>
    /// The create checkout example.
    /// </summary>
    public class Create
    {
        /// <summary>
        /// The example.
        /// </summary>
        public void Example()
        {
            const string ContentType =
                "application/vnd.klarna.checkout.aggregated-order-v2+json";

            // Cart
            var cartItems = new List<Dictionary<string, object>>
                    {
                        new Dictionary<string, object>
                            {
                                { "reference", "123456789" },
                                { "name", "Klarna t-shirt" },
                                { "quantity", 2 },
                                { "unit_price", 12300 },
                                { "discount_rate", 1000 },
                                { "tax_rate", 2500 }
                            },
                        new Dictionary<string, object>
                            {
                                { "type", "shipping_fee" },
                                { "reference", "SHIPPING" },
                                { "name", "Shipping Fee" },
                                { "quantity", 1 },
                                { "unit_price", 4900 },
                                { "tax_rate", 2500 }
                            }
                    };
            var cart = new Dictionary<string, object> { { "items", cartItems } };

            // Merchant ID
            const string Eid = "0";

            const string SharedSecret = "sharedSecret";
            var connector = Connector.Create(SharedSecret);

            Order order = null;

            var merchant = new Dictionary<string, object>
                {
                    { "id", Eid },
                    { "terms_uri", "http://example.com/terms.aspx" },
                    { "checkout_uri", "https://example.com/checkout.aspx" },
                    {
                        "confirmation_uri",
                        "https://example.com/thankyou.aspx?sid=123&klarna_order={checkout.order.uri}"
                    },
                    //// You cannot receive push notification on a non publicly available uri.
                    { "push_uri", "https://example.com/push.aspx?sid=123&klarna_order={checkout.order.uri}" }
                };

            var data =
                new Dictionary<string, object>
                    {
                        { "purchase_country", "SE" },
                        { "purchase_currency", "SEK" },
                        { "locale", "sv-se" },
                        { "merchant", merchant},
                        { "cart", cart }
                    };

            order =
                new Order(connector)
                    {
                        BaseUri = new Uri("https://checkout.testdrive.klarna.com/checkout/orders"),
                        ContentType = ContentType
                    };

            order.Create(data);
        }
    }
}

Read order

  • Description: Read a Checkout Order resource
     
  • Request
    • Method: GET
    • URI: https://checkout.testdrive.klarna.com/checkout/orders/{id}
    • Accept: application/vnd.klarna.checkout.aggregated-order-v2+json
    • Content-Type: -
    • Body: -
       
  • Response
    • A representation of the Checkout Order
require_once 'src/Klarna/Checkout.php';

$sharedSecret = 'sharedSecret';

Klarna_Checkout_Order::$contentType
    = 'application/vnd.klarna.checkout.aggregated-order-v2+json';

$orderUri = 'https://checkout.testdrive.klarna.com/checkout/orders/ABC123';

$connector = Klarna_Checkout_Connector::create($sharedSecret);
$order = new Klarna_Checkout_Order($connector, $orderUri);

$order->fetch();
import klarnacheckout

# Shared Secret
shared_secret = 'shared_secret'

klarnacheckout.Order.content_type = \
    'application/vnd.klarna.checkout.aggregated-order-v2+json'

resource_location = \
    'https://checkout.testdrive.klarna.com/checkout/orders/ABC123'

connector = klarnacheckout.create_connector(shared_secret)

order = klarnacheckout.Order(connector, resource_location)

order.fetch()
%>
<!-- #include file="../Klarna.Asp/Order.asp" -->
<!-- #include file="../Klarna.Asp/Digest.asp" -->
<!-- #include file="../Klarna.Asp/UserAgent.asp" -->
<!-- #include file="../Klarna.Asp/BasicConnector.asp" -->
<!-- #include file="../Klarna.Asp/HttpRequest.asp" -->
<!-- #include file="../Klarna.Asp/HttpResponse.asp" -->
<!-- #include file="../Klarna.Asp/HttpTransport.asp" -->
<%
'------------------------------------------------------------------------------
' The fetch checkout example.
'------------------------------------------------------------------------------
Class Fetch

    '--------------------------------------------------------------------------
    ' The example.
    '--------------------------------------------------------------------------
    Public Sub Example()
        ' Create connector
        Dim transport
        Set transport = new HttpTransport
        Dim digest
        Set digest = New Digest
        Dim sharedSecret
        sharedSecret = "sharedSecret"
        Dim connector
        Set connector = CreateBasicConnector(transport, digest, sharedSecret)

        Dim resourceUri
        resourceUri = "https://checkout.testdrive.klarna.com/checkout/orders/ABC123"

        Dim contentType
        contentType = "application/vnd.klarna.checkout.aggregated-order-v2+json"
        Dim order
        Set order = CreateOrder(connector)
        order.SetLocation resourceUri
        order.SetContentType contentType

        order.Fetch
    End Sub

End Class
package examples;

import com.klarna.checkout.Connector;
import com.klarna.checkout.IConnector;
import com.klarna.checkout.Order;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;

/**
 * The fetch checkout example.
 */
public final class Fetch {

    /**
     * The example.
     */
    public void example()
            throws URISyntaxException, NoSuchAlgorithmException, IOException {

        final String secret = "sharedSecret";

        Order.setContentType(
                "application/vnd.klarna.checkout.aggregated-order-v2+json");

        URI resourceURI = new URI(
                "https://checkout.testdrive.klarna.com/checkout/orders/ABC123");

        IConnector connector = Connector.create(secret);

        Order order = new Order(connector, resourceURI);
        order.fetch();
    }
}
namespace Klarna.Kco.Examples
{
    using System;
    using System.Collections.Generic;

    using Klarna.Checkout;

    /// <summary>
    /// The fetch checkout example.
    /// </summary>
    public class Fetch
    {
        /// <summary>
        /// The example.
        /// </summary>
        public void Example()
        {
            const string ContentType =
                "application/vnd.klarna.checkout.aggregated-order-v2+json";

            Uri resourceUri = new Uri("https://checkout.testdrive.klarna.com/checkout/orders/ABC123");

            const string SharedSecret = "sharedSecret";
            var connector = Connector.Create(SharedSecret);

            Order order = new Order(connector, resourceUri)
                {
                    ContentType = ContentType
                };

            order.Fetch();
        }
    }
}

Update order

  • Description: Update a Checkout Order resource
     
  • Request
    • Method: POST
    • URI: https://checkout.testdrive.klarna.com/checkout/orders/{id}
    • Accept: application/vnd.klarna.checkout.aggregated-order-v2+json
    • Content-Type: application/vnd.klarna.checkout.aggregated-order-v2+json
    • Body: ...
       
  • Response
    • An updated representation of the Checkout Order
       
  • Please note: For orders in state checkout_complete, only the merchant_reference and statusproperties can be updated. For orders in state created, only the merchant_reference can be updated.
require_once 'src/Klarna/Checkout.php';

$sharedSecret = 'sharedSecret';

Klarna_Checkout_Order::$contentType
    = 'application/vnd.klarna.checkout.aggregated-order-v2+json';

$orderUri = 'https://checkout.testdrive.klarna.com/checkout/orders/ABC123';

$connector = Klarna_Checkout_Connector::create($sharedSecret);
$order = new Klarna_Checkout_Order($connector, $orderUri);

// Array containing the cart items
$cart = array(
    array(
        'reference' => '123456789',   
        'name' => 'Klarna t-shirt',         
        'quantity' => 4,
        'unit_price' => 12300,
        'discount_rate' => 1000,
        'tax_rate' => 2500
    ),
    array(
        'type' => 'shipping_fee',    
        'reference' => 'SHIPPING',
        'name' => 'Shipping Fee',
        'quantity' => 1,        
        'unit_price' => 4900,
        'tax_rate' => 2500
    )
);

// Reset cart
$update['cart']['items'] = array();

foreach ($cart as $item) {
    $update['cart']['items'][] = $item;
}

$order->update($update);
import klarnacheckout

# Dictionary containing the cart items
cart = (
    {
        'quantity': 1,
        'reference': '123456789',
        'name': 'Klarna t-shirt',
        'unit_price': 12300,
        'discount_rate': 1000,
        'tax_rate': 2500
    }, {
        'quantity': 1,
        'type': 'shipping_fee',
        'reference': 'SHIPPING',
        'name': 'Shipping Fee',
        'unit_price': 4900,
        'tax_rate': 2500
    }
)

# Merchant ID
eid = "0"

# Shared Secret
shared_secret = 'shared_secret'

klarnacheckout.Order.content_type = \
    'application/vnd.klarna.checkout.aggregated-order-v2+json'
klarnacheckout.Order.base_uri = \
    'https://checkout.testdrive.klarna.com/checkout/orders'

connector = klarnacheckout.create_connector(shared_secret)

resource_location = \
    'https://checkout.testdrive.klarna.com/checkout/orders/ABC123'

order = klarnacheckout.Order(connector, resource_location)

# Reset cart
data = {'cart': []}
data["cart"] = {"items": []}

for item in cart:
    data["cart"]["items"].append(item)

order.update(data)
%>
<!-- #include file="../Klarna.Asp/JSON.asp" -->
<!-- #include file="../Klarna.Asp/Order.asp" -->
<!-- #include file="../Klarna.Asp/Digest.asp" -->
<!-- #include file="../Klarna.Asp/UserAgent.asp" -->
<!-- #include file="../Klarna.Asp/BasicConnector.asp" -->
<!-- #include file="../Klarna.Asp/HttpRequest.asp" -->
<!-- #include file="../Klarna.Asp/HttpResponse.asp" -->
<!-- #include file="../Klarna.Asp/HttpTransport.asp" -->
<%
'------------------------------------------------------------------------------
' The update checkout example.
'------------------------------------------------------------------------------
Class Update

    '--------------------------------------------------------------------------
    ' The example.
    '--------------------------------------------------------------------------
    Public Sub Example()
        ' Cart
        Dim item1
        Set item1 = Server.CreateObject("Scripting.Dictionary")
        item1.Add "reference", "123456789"
        item1.Add "name", "Klarna t-shirt"
        item1.Add "quantity", 2
        item1.Add "unit_price", 12300
        item1.Add "discount_rate", 1000
        item1.Add "tax_rate", 2500

        Dim item2
        Set item2 = Server.CreateObject("Scripting.Dictionary")
        item2.Add "type", "shipping_fee"
        item2.Add "reference", "SHIPPING"
        item2.Add "name", "Shipping Fee"
        item2.Add "quantity", 1
        item2.Add "unit_price", 4900
        item2.Add "tax_rate", 2500

        Dim cartItems(1)
        Set cartItems(0) = item1
        Set cartItems(1) = item2

        Dim cart
        Set cart = Server.CreateObject("Scripting.Dictionary")
        cart.Add "items", cartItems

        ' Create connector
        Dim transport
        Set transport = new HttpTransport
        Dim digest
        Set digest = New Digest
        Dim sharedSecret
        sharedSecret = "sharedSecret"
        Dim connector
        Set connector = CreateBasicConnector(transport, digest, sharedSecret)

        Dim contentType
        contentType = "application/vnd.klarna.checkout.aggregated-order-v2+json"

        Dim eid
        eid = "0"

        Dim resourceUri
        resourceUri = "https://checkout.testdrive.klarna.com/checkout/orders/ABC123"
        Dim order
        Set order = CreateOrder(connector)
        order.SetLocation resourceUri
        order.SetContentType contentType

        ' Reset cart
        Dim data
        Set data = Server.CreateObject("Scripting.Dictionary")
        data.Add "cart", cart

        order.Update data
    End Sub

End Class
package examples;

import com.klarna.checkout.Connector;
import com.klarna.checkout.IConnector;
import com.klarna.checkout.Order;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * The update checkout example.
 */
public final class Update {

    /**
     * The example.
     */
    public void example()
            throws URISyntaxException, NoSuchAlgorithmException, IOException {

        final Map<String, Object> cart = new HashMap<String, Object>() {
            {
                put("items", new ArrayList<HashMap<String, Object>>() {
                    {
                        add(new HashMap<String, Object>() {
                            {
                                put("quantity", 2);
                                put("reference", "123456789");
                                put("name", "Klarna t-shirt");
                                put("unit_price", 12300);
                                put("discount_rate", 1000);
                                put("tax_rate", 2500);
                            }
                        });
                        add(new HashMap<String, Object>() {
                            {
                                put("quantity", 1);
                                put("type", "shipping_fee");
                                put("reference", "SHIPPING");
                                put("name", "Shipping Fee");
                                put("unit_price", 4900);
                                put("tax_rate", 2500);
                            }
                        });
                    }
                });
            }
        };

        // Merchant ID
        final String eid = "0";
        final String secret = "sharedSecret";

        Order.setContentType(
                "application/vnd.klarna.checkout.aggregated-order-v2+json");
        URI uri = new URI(
                "https://checkout.testdrive.klarna.com/checkout/orders");

        Order.setBaseUri(uri);
        IConnector connector = Connector.create(secret);

        URI resourceURI = new URI(
                "https://checkout.testdrive.klarna.com/checkout/orders/ABC123");
        Order order = new Order(connector, resourceURI);

        // Reset cart
        Map<String, Object> data = new HashMap<String, Object>() {
            {
                put("cart", cart);
            }
        };

        order.update(data);
    }
}
namespace Klarna.Kco.Examples
{
    using System;
    using System.Collections.Generic;

    using Klarna.Checkout;

    /// <summary>
    /// The update checkout example.
    /// </summary>
    public class Update
    {
        /// <summary>
        /// The example.
        /// </summary>
        public void Example()
        {
            const string ContentType =
                "application/vnd.klarna.checkout.aggregated-order-v2+json";

            Uri resourceUri = new Uri("https://checkout.testdrive.klarna.com/checkout/orders/ABC123");

            // Cart
            var cartItems = new List<Dictionary<string, object>>
                    {
                        new Dictionary<string, object>
                            {
                                { "reference", "123456789" },
                                { "name", "Klarna t-shirt" },
                                { "quantity", 2 },
                                { "unit_price", 12300 },
                                { "discount_rate", 1000 },
                                { "tax_rate", 2500 }
                            },
                        new Dictionary<string, object>
                            {
                                { "type", "shipping_fee" },
                                { "reference", "SHIPPING" },
                                { "name", "Shipping Fee" },
                                { "quantity", 1 },
                                { "unit_price", 4900 },
                                { "tax_rate", 2500 }
                            }
                    };
            var cart = new Dictionary<string, object> { { "items", cartItems } };

            const string SharedSecret = "sharedSecret";
            var connector = Connector.Create(SharedSecret);

            Order order = new Order(connector, resourceUri)
                {
                    ContentType = ContentType
                };

            // Reset cart
            var data = new Dictionary<string, object> { { "cart", cart } };

            order.Update(data);
        }
    }
}