4. Place Order

You finalize the order in this step via a server side call. Before you place the order, you must have received a authorization_token from the previous step. For a recurring order, the customer token created in the previous step can be used.

 

4.1. The Merchant places a single order

When you have received the authorization_token from the authorization, you place the order by posting to Payments API/orders. Among the other order details in this request, you include a URL to the confirmation page for the customer.

POST /credit/v1/authorizations/<authorization_token>/order
Authorization: Basic pwhcueUff0MmwLShJiBE9JHA==
Content-Type: application/json

{
    "purchase_country": "GB",
    "purchase_currency": "GBP",
    "billing_address": {
        "given_name": "John",
        "family_name": "Doe",
        "email": "john@doe.com",
        "title": "Mr",
        "street_address": "13 New Burlington St",
        "street_address2": "Apt 214",
        "postal_code": "W13 3BG",
        "city": "London",
        "region": "",
        "phone": "01895808221",
        "country": "GB"
    },
    "shipping_address": {
        "given_name": "John",
        "family_name": "Doe",
        "email": "john@doe.com",
        "title": "Mr",
        "street_address": "13 New Burlington St",
        "street_address2": "Apt 214",
        "postal_code": "W13 3BG",
        "city": "London",
        "region": "",
        "phone": "01895808221",
        "country": "GB"
    },
    "order_amount": 10,
    "order_tax_amount": 0, // optional
    "order_lines": [
        {
            "type": "physical", // optional
            "reference": "19-402", // optional
            "name": "Battery Power Pack",
            "quantity": 1,
            "unit_price": 10,
            "tax_rate": 0, // optional
            "total_amount": 10,
            "total_discount_amount": 0, // optional
            "total_tax_amount": 0, // optional
            "product_url": "https://www.estore.com/products/f2a8d7e34", // optional
            "image_url": "https://www.exampleobjects.com/logo.png" // optional
        }
    ],
    "merchant_urls": {
        "confirmation": "https://example.com/confirmation",
        "notification": "https://example.com/pending" // optional
    },
    "merchant_reference1": "45aa52f387871e3a210645d4", // optional
}

4.2 Handle the response

You can either get a successful response, or an error.

The response contains the following information

  • order_id - used for order management interactions, such as capturing or refunding the order
  • redirect_url - a URL which you immediately redirect the consumer to
  • fraud_status - may indicate that this is a suspected fraudulent order

Successful response: the order is confirmed

You receive an Order ID, a redirect URL and fraud_status ACCEPTED. 

{
  "order_id": "3eaeb557-5e30-47f8-b840-b8d987f5945d",
  "redirect_url": "https://credit.klarna.com/redirect/asdasADserDF",
  "fraud_status": "ACCEPTED"
}

Store the Order ID for future reference during order fulfillment or service center management.

To display your confirmation page, your last step is to redirect the customer to the redirect_urlThe reason for this redirect is to allow us to recognize the customer's device in future interactions. We therefore need to interact with the customer's browser as first party (not in an iframe or similar). This is achieved by ‘bouncing’ the browser on a klarna.com page before presenting your confirmation page.

Pending order

Instead of immediately accepting the order, it may happen that Klarna flags this transaction for additional review. This is indicated if the fraud_status is PENDING. Read more about what to next in our section about pending orders.

Error response

If an error is returned, see here for details.

There are two reasons we would reject

  1. The order was placed within the required time window. However, the data was not matching the data provided during the authorization call.
  2. The order was placed outside the authorization window, and Klarna could not re-authorize it successfully. 

If you want to give the consumer the option to complete the order at this point, then update the session and proceed with loading the Widget again.

 

 

 

4.3 Place recurring order (tokenization)

The customer token created previously can be used to charge the customer at any time. The customer is charged by creating an order using the customer token. This is done by calling the customer token API with the customer token ID and data of order to be created. 
The order can be automatically captured at time of creation by setting the auto_capture flag to true (default is false)
 
See following example:
POST /customer-token/v1/tokens/{customerToken}/order
Authorization: Basic pwhcueUff0MmwLShJiBE9JHA==
Content-Type: application/json

{
	"merchant_reference1": "45aa52f387871e3a210645d4",
	"merchant_data": "optional string",
	"locale": "sv-SE",
	"auto_capture": true,
	"purchase_currency": "SEK",
	"order_amount": 9900,
	"order_tax_amount": 0,
	"order_lines": [{
		"type": "digital",
		"reference": "ABC123",
		"name": "Premium package",
		"quantity": 1,
		"unit_price": 9900,
		"tax_rate": 0,
		"total_amount": 9900,
		"total_discount_amount": 0,
		"total_tax_amount": 0
	}]
}
// Success response format
{
	"order_id": "a89ec121-1276-419d-882a-c343d58fd1bc",
	"fraud_status": "ACCEPTED"
}
// Error response format
{
	"error_code" : "ERROR_CODE",
	"error_messages" : ["Array of error messages"],
	"correlation_id" : "Unique id for this request used for troubleshooting."
}

 

 

ERROR_CODEHTTP status CodeDescription
N/A200Order successfully created. Order ID returned.
TOKEN_NOT_FOUND404Customer token not found
TOKEN_SUSPENDED403Customer token has been suspended
TOKEN_CANCELLED403Customer token has been cancelled
TOKEN_FORBIDDEN403Customer token usage forbidden
BAD_REQUEST400Bad request. Error message includes more details.
UNAVAILABLE_PAYMENT_METHOD403Payment method type is not available.
PAYMENT_METHOD_CURRENCY_MISMATCH403Payment method not available for given currency
PAYMENT_METHOD_FAILED403Purchase for payment method failed. You can try again for PAYMENT_METHOD_FAILED errors.
INTERNAL_SERVER_ERROR500Internal server error.
SERVICE_UNAVAILABLE503Purchase failed because of a temporary internal Klarna error. You can try again for a 503.

 

 

 

Summary so far: “A Job Well Done”

Congratulations, you’ve just placed an order at Klarna! The widget is up and running the way it should.


What's next?

Just a few more steps before start taking orders live‚Äč. Go through our go live check list!