Overview of the Hosted Payment Page API
This page will take you through the Hosted Payment Page API and explain how to interact with it and its concepts. Please make sure to understand why you should use the Hosted Payment Page and the Overview of the system before reading this documentation. The Hosted Payment Page works with a Payment Provider from the Klarna ecosystem, and you will need to create a KP Session or KCO Order before being able to create an HPP Session. A different integration guide is available for both platforms.
Ecosystem overview: components and objects
Klarna’s Hosted Payment Page (HPP) requires that you integrate different server-side REST APIs from the Klarna environment and thus requires no client-side integration. The different APIs correspond to different Klarna products and have some defined objects that interact with each other.
1. Payment Provider API
The Hosted Payment Page supports both Klarna Checkout and Klarna Payments, which will be referred to in this documentation as the Payment Provider. You can integrate with both if you have contracted for both products, and the integration with HPP is quite similar, but an HPP Session will work only with one of the two Payment Providers at the same time. Choosing from one of the two Payment Provider will mainly depend on your use case and constrains.
a. Klarna Payments REST API: create Payment Session, place Order
KP Session: a Payment Session on Klarna Payments API. It contains everything regarding the transaction and has a 48 hours lifetime. A KP Session is considered as incomplete until a KP Authorization Token has been used to create an OM Order.
KP Authorization Token: an authorization for the payment of a KP Session to the corresponding Consumer. The token is valid for 60 minutes and has to be used by your backend to create the corresponding OM Order. An authorization can be given multiple times to the same Consumer for the same KP Session, but only one can be used to create an OM Order.
b. Klarna Checkout REST API: create Checkout Order
- KCO Order: a Checkout Order on Klarna Checkout API. It contains everything regarding the transaction and has a 48 hours lifetime. A KCO Session is considered as incomplete until the Consumer has not succeed in getting a valid payment. The KCO API has mechanisms to let you accept or not a payment and then automatically proceeds to the creation of the OM Order.
Both KP Session and KCO Order will be referred to as Payment Session in the documentation.
2. Hosted Payment Page REST API
The Hosted Payment Page REST API can be used to let Klarna host the client-side integration of Klarna Payments or Klarna Checkout for you. You will have to create a Session and then distribute it.
a. HPP Session: a session on HPP that is linked to a Payment Session. When a Payment Session is being completed, canceled or expires, it is also the case for the HPP Session. An HPP Session has an unique URL where the Consumer can be redirected to and can be distributed via different distribution methods.
3. Order Management REST API: capture payment
a. OM Order: a due payment from the Consumer for defined goods. It is created using a KP Authorization Token with the KP Session or automatically by Klarna Checkout when a KCO Order is completed. The OM Order will allow you to capture the payment when goods or service have been delivered, and manage the post purchase experience of the Consumer.
KP Session, KCO Order and HPP Session both have an expiration time, but the expiration is driven by the Payment Session which usually expires 48 hours after its creation. A Consumer will be able to pay on HPP until 1 hour before the Payment Session expiration.
Klarna uses HTTP’s Basic auth to authenticate requests from Merchants. Use your API Credentials to add the corresponding HTTP headers to your requests, the credentials consist of two elements:
- Username: a username linked to your Merchant ID at Klarna
- Password: a unique password that is associated with the username
Use your credentials to generate the token:
UsernameCalculated basic auth
UsernameExample of request
Environments and tests
Klarna offers a test environment named Playground and a Production environment. The different APIs are available on each environment. URL structures are the same for both environment, targeted environment will be defined by the domain you are using. To be able to test your integration, you will need a Test Account.
The HPP API follows the same rules as other Klarna public APIs, we try to update our APIs regularly in a non breaking way, ensuring backward compatibility. You can find more in our and see how we define backward compatibility and non-breaking changes.
- Accept any 2xx codes as success, do not code for a specific error response code
- Interpret any 4xx as an error, do not code for a specific error response code
- Interpret any 5xx as an error, do not code for a specific error response code