Integrate Klarna plugins by passing the interoperability token at checkout to support Express and session-based flows with consistent customer recognition.
Interoperability between Acquiring Partner plugins and Klarna plugins relies on a shared interoperability token used to coordinate functionality across supported platforms. When an Acquiring Partner utilizes the Klarna Web SDK, in most cases the interoperability_token can pass seamlessly.
In cases where the Klarna web SDK is not utilized by the Acquiring Partner, and uses the Presentation API instead, there is additional work required. We will outline the necessary steps to support interoperability between Klarna and Acquiring Partner plugins below. This implementation is also recommended as a fallback even if utilizing the Klarna web SDK.
The methods for passing, storing, and retrieving this token vary by platform. Wherever possible, existing platform functionality is used. In cases where native support isn’t available, interoperability is enabled through additional API calls or custom hooks.
Two main interoperability scenarios are defined:
Express Checkout flow: Used when a rapid transition between plugins is required. The interoperability token is exchanged during the checkout notification process.
Session-based flow: Used for general integrations. The Klarna plugin stores the token in the session, and the Acquiring Partner plugin retrieves and applies it when needed.
There are two main use cases for interoperability on platforms that cover for multiple experiences from the customer’s perspective. Interoperability user journeys are detailed here, but will be commented on shortly below to set the context for plugin interoperability.
sequenceDiagram
autonumber
participant A as Customer
participant B as Partner
participant C as Klarna Plugin
participant D as Klarna
participant F as Acquiring Partner Plugin
B->>C: Enable Express Checkout
B->>F: Enable Klarna payments in AP plugin
C->>D: Load the Klarna web SDK
C->>D: Initiate the web SDK
C->>A: Display Klarna Express button
A->>C: Click on Klarna Express button
C->>D: Initiate payment request
C->>A: Start Klarna purchase journey
A->>D: Complete Klarna purchase journey
D->>C: Payment request completed event
Note over D,C: interoperability_token
C->>C: Store interoperability data<br>in session storage
C->>F: Send hook to complete payment
Note over C,F: Share interoperability data points
F->>D: Authorize payment
Note over F,D: Share interoperability data points
D->>F: Approve payment
F->>A: Redirect customer to order confirmation page
In an Express Checkout flow, the customer expects a fast and seamless transition from the Klarna payment experience to the store’s confirmation page.
When a Partner enables Klarna Express Checkout through the Klarna plugin, and Klarna is also activated as a payment method through the Acquiring Partner plugin, the two plugins must maintain seamless interoperability.
The Klarna plugin handles the Web SDK, Klarna button, and initialization.
The Acquiring Partner plugin finalizes the purchase flow by creating the platform-specific order using data retrieved via the interoperability token, and then redirects the customer to the confirmation page.
If a two-step Express Checkout flow is used instead, the Acquiring Partner plugin must redirect the customer to the checkout page, showing only Klarna (since the payment is already initiated from the customer’s perspective). The plugin must then authorize the payment once the customer completes the order.
Failure to handle this correctly causes a broken purchase flow, forcing the customer to repeat checkout and payment authorization.
In setups where the store has complex shipping, discount, or loyalty program logic, the customer first lands on the checkout page.
After completing the Klarna Express Checkout purchase flow, the Acquiring Partner plugin must redirect the customer to the checkout page with Klarna shown as the only payment option (authorization already completed). In this flow, the Klarna hook for Klarna Express Checkout includes the parameter intent: preparation.
If an error occurs, for example, when the Klarna plugin hook does not include payment_state: COMPLETED , the Acquiring Partner plugin must always redirect the customer back to the cart or checkout page.
During this fallback, the plugin must retrieve the interoperability token to ensure Klarna is presented as expected.
This prevents scenarios where the Klarna dialog closes unexpectedly after the Express Checkout process begins, leaving the customer uncertain about their order status.
Redirecting to the checkout page as a fallback also helps reduce abandoned purchases.
By consistently retrieving the interoperability token whenever the customer enters the checkout page, the integration can prevent multiple authorizations for the same purchase.
An alternative fallback solution involves the Klarna plugin monitoring completion of the Express Checkout order via Klarna webhooks, specifically:
payment.transaction.state-change.completed
If no completion event is received within 5 seconds, the Klarna plugin could redirect the customer to the cart page.
Alternatively, the Acquiring Partner plugin could expose a hook triggered when the Klarna Express Checkout transaction completes, which the Klarna plugin would listen to. If no event occurs within 5 seconds, the Klarna plugin would again redirect to the cart page.
This approach introduces timing risks, particularly on slower platforms such as Adobe or WooCommerce, which may lead to conflicting redirects initiated by both plugins.
Once redirected, the Acquiring Partner plugin retrieves the interoperability token from session storage, avoiding additional payment authorizations.
For both fallback options, the Klarna plugin must notify the Acquiring Partner plugin whenever the customer is redirected to the cart page.
sequenceDiagram
autonumber
participant A as Customer
participant B as Partner
participant C as Klarna Plugin
participant D as Klarna
participant F as Acquiring Partner Plugin
%% --- Setup ---
B->>C: Enable On-site Messaging
B->>F: Enable Klarna payments
%% --- Prequalification ---
A->>B: Go to product page
C->>D: Load Klarna SDK
C->>D: Get OSM placement
D->>C: Return messaging / prequalification content
C->>A: Show messaging / prequalification
A->>D: Click "Check purchase power"
D->>A: Start prequalification
A->>D: Complete prequalification
D->>C: Send approval event
C->>A: Update messaging with approval
D->>C: On token update event with latest interoperability_token
C->>C: Stores interoperability_token in platform storage
%% --- Checkout ---
A->>B: Navigate to checkout
F->>C: Retrieve interoperability token from session storage
F->>D: Get payment instructions
F->>D: Create payment request
F->>A: Display Klarna as preselected option
A->>D: Proceed payment with Klarna<br>as preselected and prequalified method
%% --- Authorization & Confirmation ---
F->>D: Authorize payment
Note over F,D: Share interoperability data points
D-->>F: Approve payment
F->>A: Redirect to confirmation page
During Prequalification (On-site messaging) or Sign in with Klarna, customers expect their saved or preselected payment options to appear automatically when they continue with Klarna at checkout.
To enable this behavior, the Klarna plugin—which manages both On-site messaging and Sign in with Klarna—must pass an interoperability token to the Acquiring Partner plugin.
The Acquiring Partner then retrieves the token from platform-specific storage and uses it to present Klarna to the customer through the Klarna Web SDK or the presentation API, ensuring a consistent experience.
Both server-side and client-side implementations are available for interoperability token handling:
Server-side implementation: Mandatory. Ensures secure, consistent token exchange and storage.
Client-side implementation: Optional. Recommended for enhanced performance or user experience.
When the Acquiring Partner plugin integrates the Klarna Web SDK, the interoperability token can be retrieved automatically, provided the SDK is loaded on the same domain.
If the Acquiring Partner loads the Klarna Web SDK inside an iframe or redirects to a different domain, additional handling must be implemented to retrieve and pass the token correctly.
This Wiki page presents some new concepts that will be used to enable interoperability on platforms. The main concepts will be explained shortly below for a generic understanding of them before getting into details for each platform.
Hook: In order to facilitate a seamless transition for Express Checkout in cases where it is integrated via the Klarna plugin, but the payment request is created by the Acquiring Partner, notifications will be implemented. These vary somewhat between the different platforms, in order to accommodate for the differences in them, and to utilize existing mechanisms where possible.
Observer: In order to listen to the notification from the Klarna plugin, the Acquiring Partner plugin will need to use a platform mechanism to get updates from the hook that the Klarna plugin emits that includes their unique Acquiring Partner Key and the interoperability token.
Storing the token: Klarna will always store the interoperability token in the appropriate and below detailed way in the platform storage.
Retrieving the token: The Acquiring Partner plugin is always expected to retrieve the Klarna interoperability token at the point of customer entry to checkout, in order to present Klarna in the expected way. If there is no interoperability token in the session storage, the customer has not interacted with any Klarna products before checkout.
Acquiring Partner Key: Each Acquiring Partner will have a unique key. In some cases, an Acquiring Partner may have several to distinguish multiple different plugins on the same platform. This is used by the Klarna plugin in order to ensure the communication is directed at the correct Partner, in particular in cases where a merchant might have enabled Klarna via several Acquiring Partners. Using this key, Klarna can signal which Acquiring Partner the notification is directed toward, to ensure the transaction is finalized by the same Acquiring Partner the merchant has added credentials for in the Klarna plugin settings. The Acquiring Partner key is not retrievable programmatically, but is instead shared by the Klarna Delivery Manager. Currently this can be found here.
The Klarna plugin will pass the following transactional data to the Acquiring Partner:
Data point
Purpose
interoperability_token
The interoperability_token is a krn that ensures a seamless consumer journey across different integrations. It contains all necessary information, including expiration details, which are set by Klarna, however a Partner can issue a new token within a session. Expired or invalid tokens are ignored for API resilience, and Acquiring Partners should not run any validation on the token.
interoperability_data
The interoperability_data is a serialized JSON object that adheres to Klarna’s Interoperability Data Schema, allowing Partners and Acquiring Partners to send additional data points to improve conversion rates and enhance the customer experience. When available, this data should be forwarded in all API interactions related to accepting payments, tokenizing a consumer, initiating a checkout flow, and post-purchase operations such as captures and refunds.
interoperability_payment_state
To signify if a customer completed the Klarna express checkout flow.
In cases where the platform owns the payment method selector, such as in the case of Woo Payments, the integration will differ somewhat due to a third party being involved.
When a customer has completed a purchase through the Klarna express checkout, the Klarna plugin both saves the interoperability token to the checkout session, but also dispatches an event for the Acquiring Partner to observe. The event from the Klarna plugin is as follows:
The Acquiring Partner plugin is expected to add an observer in order to listen to these events and act when their acquirer key is present in these. The below is a proposal on how to add an observer for listening to the interoperability ready event:
PHP
1
2
3
4
5
6
7
8
9
10
<!-- ModuleName/etc/frontend/events.xml -→
<!-- Setup an observer that listens to the “klarna_interoperability_handover” event -→ <event name="klarna_interoperability_ready_event">
<observer name="observer_name" instance="Project\ModuleName\Observer\ExampleObserver" />
</event>
// ModuleName/Observer/ExampleObserver.phppublicfunction execute(\Magento\Framework\Event\Observer $observer): void
{
$interoperabilityTokenAcquirerKey = $observer->getData('interoperability_acquirer_key');
The Acquiring Partner plugin is here expected to create the payment request and redirect the customer to the confirmation page.
The Acquiring Partner is expected to always retrieve the Klarna interoperability token, if present, and use it to present Klarna in the expected way. This should be done when the customer is entering the checkout, in order to present the Klarna payment option in the expected way. Retrieving the token could be done in the following way:
When a customer has completed a purchase through the Klarna express checkout, the Klarna plugin both saves the interoperability token to the checkout session, but also dispatches an event for the Acquiring Partner to observe. The Klarna module emits the interoperability token through both frontend and backend channels:
To access the Klarna interoperability token, the Acquiring Partner module needs to listen for a custom event emitted by the Klarna module, called “updateKlarnaInteroperabilityToken”. This interoperability mechanism is currently available on the frontend (JavaScript, PrestaShop event emitter) and backend (PHP, PrestaShop hooks). In the backend, modules could listen to the updateKlarnaInteroperabilityToken hook to receive the Klarna token when it's available.
1. Registering the Hook
The hook should be registered in your module’s install() method:
Listen for the hook using a method named hookUpdateKlarnaInteroperabilityToken in your module’s main class:
PHP
1
2
3
4
5
6
7
8
publicfunction hookUpdateKlarnaInteroperabilityToken($params)
{
if (isset($params['klarna_interoperability_token'])) {
$klarnaInteroperabilityToken = $params['klarna_interoperability_token'];
// Use the token as needed
}
}
The SFCC plugin listens for the updated interoperability token from the Klarna Web SDK. When received, it sends a POST request to the Acquiring Partner observer with the following payload:
The AP must expose an endpoint that listens for a POST request from the SFCC server containing the token. The token will be sent in the request in the following JSON format:
The Acquiring Partner is expected to retrieve the Klarna interoperability token and use it to present Klarna at checkout. Retrieving the token on SFCC can be done in the following way:
var interoperability_data = session.privacy.klarna_interoperability_data
var interoperability_token = session.privacy.klarna_interoperability_token
var payment_state = session.privacy.klarna_interoperability_payment_state
When a customer has completed a purchase through the Klarna express checkout, the Klarna plugin both saves the interoperability token to the session, but also dispatches an action for the Acquiring Partner to act on. The action from the Klarna plugin is as follows:
For Shopify, interoperability as it stands for other plugins, can not be enabled. We would however like to ensure the Klarna On-site messaging app can be used also by PSP merchants.
Currently we have logic in place that automatically connects the account based on the url - meaning a PSP merchant can already use the Klarna OSM app. There are, however, cases where a merchant has several accounts with Klarna, and we therefore can not connect automatically as we do not know which one to connect to. In such cases merchants are currently asked to enter their Klarna merchant ID. As PSP merchants do not have such, there is currently no way for them to do this. We would like to, in the future, expose an identifier to them (perhaps the client identifier), that they could then use as a fallback option in cases where the automatic connection does not work. No work for this will be needed on your side, other than an agreement on what such an identifier would be.