Klarna Docs - Create a Klarna Customer Token

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.

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

JSON
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",

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

JSON
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",

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.

JSON
{
    "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
NOT_FOUNDInvalid authorization tokenThis is returned if order is placed after the authorization token has expired. Please ensure the order is placed within 60 minutes of the authorization.
BAD_VALUEBad value: purchase_countryThe country of the billing address is different from that of the purchase_country of the session. Causing a mismatch
BAD_REQUESTX is not valid for creating customer tokens in YThe payment method X is not available for tokenization in country Y.