This section of the guide walks you through initiating a payment and letting your customers pay with Klarna.
When your customer wants to pay with Klarna, you have to open a payment session and share the shopping cart details in a POST
request to the {apiURL}/payments/v1/sessions
endpoint. In that request, you also specify if the payment is one-time or recurring.
Once you start a payment session, it stays open for 48 hours or until you place an order. You can also send a separate POST
request to cancel the session.
Klarna payments API uses HTTP basic authentication. To authenticate, use your API credentials that consist of:
If you're using an API platform that lets you store your credentials, you can add them in relevant fields. Otherwise, make sure to include the Base64-encoded username:password in the Authorization header field of each API request, as shown below.
To get a success response, include the following required parameters in your POST {apiURL}/payments/v1/sessions
request.
Parameter | Description |
---|---|
locale | The language of information presented on the Klarna widget. Learn more about using locale in API calls. |
purchase_country | The country where the purchase is made. Learn more about supported countries. |
purchase_currency | The currency in which the customer is charged. Learn more about supported currencies. |
order_amount | The total price of the order, including tax and discounts. |
order_lines | The details of order lines in the purchase. |
intent | The purpose of the payment session. |
merchant_urls.authorization | Get a callback once the customer has completed the flow and you can create an order. |
We recommend you don't include customer details when initiating a payment session. Instead, use the authorize()
call to share them with Klarna at a later stage of the checkout process when the customer clicks Buy.
As we already mentioned, you can use Klarna payments in a variety of payment scenarios. Depending on the scenario, add the right value in the intent
field of the request.
For one-time payments, set intent
to buy
.
For recurring payments:
intent
to tokenize
if you don't want to place an order at checkout.intent
to buy_and_tokenize
if you want to place the first order at checkout.intent
to buy_and_default_tokenize
if you want to place the first order at checkout and add an additional service at the same time.To open a one-time payment session, include all common parameters in the request body and set intent
to buy
.
To enable recurring payments without charging your customer at checkout, include the following in your request:
intent
set to tokenize
subscription
objectYou can charge the customer later using a customer token created in the same Klarna payments session.
To charge the customer at checkout and enable recurring payments at the same time, include the following in your request:
intent
set to buy_and_tokenize
subscription
objectMixed payments allows you to charge the customer at the checkout for one item and enable future orders by tokenizing another payment method.
intent
set to buy_and_default_tokenize
subscription
objectYou will be able to charge the customer later using a customer token.
In response to a create session call, you receive:
session_id
, a payment session identifier you can use to update the session and retrieve session detailsclient_token
, a token you pass to the JavaScript SDK to launch the Klarna widgetpayment_method_categories
, an array that lists the grouped Klarna payment methods available for the session. We can respond with one or more categories depending on the market and account configuration.If your request doesn't pass our validation, you'll receive an error response.
Go to Error Handling to learn more about common errors and troubleshooting suggestions. You can use the value in correlation_id
to find entries related to the request under Logs in the Merchant portal.