29 NEXT
Search
⌃K

Klarna Checkout Admin API Guide

Implement Klarna Checkout on custom checkouts via the API
Klarna Checkout is a fully integrated payment app, supported both in the storefront checkout, and via the Admin API. Klarna transactions process the customer through the Klarna Checkout redirect flow, with the resulting order information provided back to your application. Below are the steps needed to get Klarna Checkout set up and working on the Admin API.
For custom Klarna checkouts, there are two checkout flows available -- the standard method where a user enters their shipping address, chooses products, and then checks out via Klarna; and the "One-Click" method, where the user is not required to enter shipping information before being redirected to Klarna checkout.

Standard Klarna Checkout Flow

Step 1 - Create Order on Admin API with Klarna as Payment Method

When creating a new order using Klarna, you’ll need to specify the payment_method=klarna as well as provide a payment_return_url. The payment_return_url is your endpoint that will receive a POST request containing the final order data (in Step 3).
{
"payment_method": "klarna",
"payment_details": {
"payment_return_url": "<YOUR APPLICATION ENDPOINT>"
}

Step 2 - Redirect Customer to Klarna Checkout Page

The response from Step 1 will provide a payment_complete_url. Your application should redirect the customer to this url for completing their payment on the store's Klarna Checkout page.
{
"reference_transaction_id": "<Unique Transactions ID>",
"payment_complete_url": "https://<Your Store Domain>/klarna/checkout-order/?order_id=<Unique Transactions ID>"
}

Step 3 - Receive Order Data

After the customer has completed the checkout on the Klarna Checkout page, they will be redirected to your application with a POST request containing data in response key all of the the order information as a string. See examples below. Example parsing the data
""""
Order json data is stored in a variable called response.
If the order data is an empty dictionary {}, it means
payment collection was unsuccessful and order was not created.
"""
import json
def my_view(request):
data = json.loads(request.POST.get("response"))
...
return HttpResponse(status=201)
Example Order data
{
"number": "109405",
"status": "Confirmed",
"lines": [
{
"product": {
"id": 22,
"categories": [
],
"product_class": null,
"images": [
{
"id": 27,
"original": "https://example.cloudfront.net/media/images/products/image.png",
"caption": "",
"display_order": 0,
"date_created": "2019-05-14T12:56:24.991823+07:00"
}
],
"title": "Example Product",
"upc": ""
},
"stockrecord": {
"id": 23,
"partner_sku": "TESTSKU",
"price_currency": "USD",
"points_price": null,
"price_excl_tax": "56.00",
"price_retail": "89.00",
"cost_price": "10.00",
"num_in_stock": 1000,
"low_stock_threshold": 100
},
"quantity": 1,
"price_currency": "USD",
"price_excl_tax": "19.99",
"price_incl_tax": "19.99",
"price_incl_tax_excl_discounts": "19.99",
"price_excl_tax_excl_discounts": "19.99"
}
],
"shipping_incl_tax": "5.00",
"shipping_method": "Default shipping",
"shipping_code": "default-shipping",
"total_incl_tax": "69.99",
"currency": "USD",
"total_excl_tax": "69.99",
"shipping_excl_tax": "5.00",
"user": {
"id": 577,
"email": "[email protected]",
"first_name": "John",
"last_name": "Smith",
"phone_number": null
},
"shipping_address": {
"id": 9658,
"country": "US",
"title": "",
"first_name": "John",
"last_name": "Smith",
"line1": "2200 Testing Lane",
"line2": "PO Box 404",
"line3": "",
"line4": "Hoptown",
"postcode": "33635",
"phone_number": "+1937567889",
"notes": "",
"state": "FL"
},
"billing_address": null,
"date_placed": "2020-10-01T16:00:25.238490+07:00",
"payment_sources": [
{
"source_type": {
"name": "Klarna",
"code": "klarna"
}
}
],
"offer_discounts": [
],
"voucher_discounts": [
],
"attribution": null,
"tags": [
],
"subscriptions": [
],
"metadata": {
},
"transactions": [
{
"partner_transaction_id": "<Unique Transaction ID>",
"txn_type": "Debit",
"currency": "USD",
"amount": "69.99"
}
]
}

"One Click" Klarna Checkout Flow

The One Click Klarna flow sends customers from your custom checkout directly to Klarna, without having to collect shipping address or other customer details first.
When creating a One Click Klarna checkout over the Admin API with the orders_create method, you do not need to specify the user (customer), the billing or shipping addresses, the shipping method, or other details -- these will be posted back from Klarna upon the completion of the checkout.

Step 1 - Create Order on Admin API with Klarna as Payment Method

You are required to specify the product, price, and set the payment_method=klarna as well as provide a payment_return_url. The payment_return_url is your endpoint that will receive a POST request containing the final order data.
Below is an example of the minimum required data to initiate a Klarna One Click checkout.
{
"lines": [
{
"sku": "TESTSKU24",
"quantity": 1,
"currency": "EUR"
}
],
"payment_method": "klarna",
"payment_details": {
"payment_return_url": "YOUR APPLICATION ENDPOINT URL"
}
}

Step 2 - Redirect Customer to Klarna

The response from Step 1 will provide a payment_complete_url. Your application should redirect the customer to this URL for completing their payment on Klarna.
{
"reference_transaction_id": "<Unique Transactions ID>",
"payment_complete_url": "https://<Your Store Domain>/klarna/checkout-order/?order_id=<Unique Transactions ID>"
}
Once redirected to Klarna, the Customer will be prompted to select from their existing billing methods, specify shipping address, and preferred shipping method according to your store's available options. The selected values will be returned in Step 3 order data upon completion of the purchase.
Sales Tax Calculation The Klarna One Click checkout does not require the customer to specify a shipping address before being redirected. Therefore, when they select their preferred shipping address from their Klarna account (usually used for sales tax calculation), Klarna will automatically callback to 29 Next to calculate applicable taxes in real-time.
This is applicable only for stores with Sales Tax or AvaTax enabled.

Step 3 - Receive Order Data

After the customer has completed their purchase on Klarna Checkout, they will be redirected to your application with a POST request containing data in the response key of all the order information as a string. See examples below. Example parsing the data
""""
Order json data is stored in a variable called response.
If the order data is an empty dictionary {}, it means
payment collection was unsuccessful and order was not created.
"""
import json
def my_view(request):
data = json.loads(request.POST.get("response"))
...
return HttpResponse(status=201)