A Klarna Payments session is created server-side via our REST API. This is done before the Klarna widget is loaded. Best practice is that you tie the Klarna session to your own user session to keep track of it throughout the purchase flow.
When a session is created you will receive the available
payment_method_categories for the session, a
session_id and a
session_id can be used to update the session using the REST API, the
client_token should be passed to the browser.
Note: A session stays valid for 48 hours after the last update of it.
Best practice: Consumer details could be added to the session creation call. If the checkout process is designed in such a way that not all customer details are known at this stage, they can be added in either Load or Authorize.
Use your API Credentials and HTTP Basic auth to authenticate with Klarna. The credentials consists of two elements:
Klarna’s European and North American environments have different endpoints (URLs) for testing and for live purchases. All Klarna end points use HTTPS. Read more here.
To create the session, send the shopping cart details, country, currency and locale via a server-side call to our REST API. You’ll find the complete REST API reference here.
NOTE: Please make sure you follow all validation rules as described in the create-session section of this article.
The REST API returns the following data:
session_idis used for server-side updates on the session via the server-side REST API
client_tokenis used to initialize the widget
payment_method_categoriesrepresents what categories of payment methods that are available for this purchase. The payment_method_category is required when loading a widget
Example from US.
Best practice: You can use the
correlation_id to troubleshoot the call in the logs app in merchant portal.
|Error Code||Error message||Comment|
|BAD_VALUE||Bad value: order_tax_amount||If you enter any tax for orders, this is validated as described in this article. This validation is not passed in case this error message is thrown.|
|BAD_VALUE||Bad value: order_lines||All order lines are validated as seen in this article. If your added order lines do not follow our guidelines, we will throw an error referring to the specific part of an order line that has failed.|
|BAD_VALUE||Bad value: purchase_currency||In case a purchase_currency is wrongly formatted or doesn’t apply in a certain locale this error message is thrown.|
|BAD_VALUE||Bad value: order_lines[i].tax_rate||If you enter any tax for orders, this is validated as described in this article. This validation is also done per item, so if the validation criteria are not met you will find this error message.|
|BAD_VALUE||Bad value: billing_address.phone||If you share billing address at create_session, this will be validated against format standards. These are not fulfilled in case this validation error is thrown. Please look into this article for details about customer data.|