Klarna Docs - Update the cart

Update the cart

If your customer updates their shopping cart or if you make any changes to payment details, you have to update the payment session before creating an order.

When the customer modifies the content of their shopping cart before authorization, you can update a payment session in two steps.

  1. Send a POST request to the {apiUrl}/payments/v1/sessions/{sessionID} endpoint.
  2. Send a load() call to make the changes visible to your customer.

1: A POST API request

To update the payment session, send the updated order details in a POST request to the {apiUrl}/payments/v1/sessions/{sessionID} endpoint.

The sessionID path parameter must match the session identifier (session_id) you got in response to the create session request.

JSON
{
  "order_amount": 998,
  "order_tax_amount": 0,
  "order_lines": [{
      "type": "physical",
      "reference": "19-315",
      "name": "Battery Power Pack",
      "quantity": 2,
      "unit_price": 499,
      "tax_rate": 0,

A sample request to update the details of a Klarna payments session.

If the request is successful, the Klarna payments session is updated and you'll receive a 204 No content response.

Error response

If your request contains errors, you'll receive an error response.

JSON
{
    "correlation_id":	"6a9b1cb1-73a3-4936-a030-481ba4bb203b",
    "error_code":	"ERROR_CODE",
    "error_messages":	[
        "ERROR_MESSAGE"
    ]
}

An error response to the update session request.

Here are examples of common errors with troubleshooting suggestions. You can use the value in correlation_id to find entries related to the request under Logs in the Merchant portal.

Error codeError messageDescription
BAD_VALUEBad value: order_tax_amountThe tax details in the request aren't aligned with the rules for tax handling.
BAD_VALUEBad value: order_linesSome of the order line details don't follow our guidelines or violate API field restrictions. Refer to the Klarna payments API reference for details.
BAD_VALUEBad value: purchase_currencypurchase_currency is incorrectly formatted or doesn’t match locale . This may occur if the customer updates their billing address, causing country to be updated.
NOT_FOUNDInvalid session idThe session identifier specified in the path can't be found. Make sure the value in sessionID has the correct value and try again.

2: A load() call

To show the updated order details to your customer, send the updated details in a load() call to Klarna.

JAVASCRIPT
Klarna.Payments.load({
container: "#klarna_container",
payment_method_categories:[
      {
       "asset_urls": {},
       "identifier": "klarna",
       "name": "Pay with Klarna"
       }
] }, 
{

A load() call to update the order details.

Learn how to handle responses to the load() call.

If your customer updates the cart after the authorize() call, you can share updates with Klarna in two ways:

  • If the Klarna widget is still displayed to the customer in the browser, send a new authorize() call with updated details to start a new risk and fraud assessment process.
    In response to a successful authorize() call, you'll get a new authorization_token. Make sure to use the new token to place an order.
  • If your checkout solution lets the customer change the order details after payment, for example, on an order review page, you have to re-authorize the session. In this case, a Klarna widget is typically not displayed, meaning you can't authorize the purchase in the standard way with init(), load(), and authorize() calls. A reauthorize() call can handle this and any necessary customer communication in fullscreen modals.

If you're integrating Klarna payments in a multistep checkout following our best practices guide, you don't need to call authorize() as the authorization happens at the last step of the purchase journey.

We recommend you display modals launched during re-authorization as the customer might need to provide some input to complete the purchase.