Create a Klarna Customer Token

Creating a Klarna Customer Token results in Klarna storing customer and payment method details. You can later used the token_id shared with you to trigger purchases for the Klarna customer token.

Date: 11.07.2019

After having obtained an authorization_token for a successful authorization, this can be used to create a purchase token instead of placing the order.

Since a purchase token has no order lines and amount connected to it, there is no need to charge the customer at this point. Instead the purchase token will be used to charge consumer at a later stage, which can be read in a separate article .

Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
POST /payments/v1/authorizations/{authorizationToken}/customer-token
Authorization: Basic pwhcueUff0MmwLShJiBE9JHA==
Content-Type: application/json

{
    "purchase_country": "SE",
    "locale": "sv-SE",
    "billing_address" : {
        "given_name": "Doe",
        "family_name": "John",
        "email": "direct_debit@klarna.com",
        "phone": "01895808221",
        "street_address": "Stårgatan 1",
        "postal_code": "12345",
        "city": "Ankeborg",
        "country": "SE"
    },
    "description": "MySaaS subscription",
    "intended_use": "subscription",
    "merchant_urls": {
        "confirmation": "string"
    }
}

Responses

Successful responses

The response will contain a redirect URL to which the user should be redirected. The user will bounce through Klarna and be redirected to the confirmation URL provided in the API calls.

Example successful response

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
HTTP/1.1 200 OK

Content-Type: application/json
Klarna-Correlation-Id: e19dc121-1276-419d-882a-c343d58fb9aa

{
    "billing_address": {
        "attention": "string",
        "city": "Beverly Hills",
        "country": "US",
        "email": "john@doe.com",
        "family_name": "Doe",
        "given_name": "John",
        "organization_name": "string",
        "phone": "333444555",
        "postal_code": "90210",
        "region": "CA",
        "street_address": "Lombard St 10",
        "street_address2": "Apt 214",
        "title": "Mr"
    },
    "customer": {
        "date_of_birth": "string",
        "gender": "string",
        "title": "string",
    },
    "payment_method_reference": "0b1d9815-165e-42e2-8867-35bc03789e00",
    "redirect_url": "https://credit.klarna.com/v1/sessions/0b1d9815-165e-42e2-8867-35bc03789e00/redirect",
    "token_id": "0b1d9815-165e-42e2-8867-35bc03789e00"
}

Error responses

If there is an error with the request, the response will follow the standard error-format of Klarna. Below is a description of the most common error reasons.

1
2
3
4
5
6
7
{
    "correlation_id": "6a9b1cb1-73a3-4936-a030-481ba4bb203b",
    "error_code": "ERROR_CODE",
    "error_messages": [
        "ERROR_MESSAGE"
    ]
}

Possible error codes and messages

Below are the most common error codes and what they mean.

Error CodeError messagesComment
Error Code
NOT_FOUND
Error messages
Invalid authorization token
Comment
This is returned if order is placed after the authorization token has expired. Please ensure the order is placed within 60 minutes of the authorization.
Error Code
BAD_VALUE
Error messages
Bad value: purchase_country
Comment
The country of the billing address is different from that of the purchase_country of the session. Causing a mismatch
Error Code
BAD_REQUEST
Error messages
X is not valid for creating customer tokens in Y
Comment
The payment method X is not available for tokenization in country Y.