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:
Link copied!
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.
Link copied!
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.
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.
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.
Link copied!
Both server-side and client-side implementations are available for interoperability token handling:
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.
Link copied!
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.
The Klarna plugin will pass the following transactional data to the Acquiring Partner:
| Data point | Purpose |
|---|---|
| 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. |
| 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. |
| To signify if a customer completed the Klarna express checkout flow. |
Link copied!
The Acquiring Partner plugin is expected to present Klarna as detailed in Building the payment form documentation.
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.
Link copied!
Below, each of the main concepts for interoperability will be detailed for each top platform.
Link copied!
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:
Copied
$this->eventManager->dispatch(
'klarna_interoperability_ready_event', [
'interoperability_token' =>$interoperabilityToken,
'interoperability_acquirer_key'=> $interoperabilityAcquirerKey
]);
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:
Copied
<!-- 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.php
public function 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 interoperability token is stored by Klarna in the following way in the Adobe Commerce checkout session:
Copied
$this->checkoutSession->setKlarnaOfficialInteroperabilityToken($interoperabilityToken);
It is only stored on the cart and checkout pages.
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:
Copied
public function getInteroperabilityToken() {
return $this->checkoutSession->getKlarnaOfficialInteroperabilityToken();
}
public function getInteroperabilityData() {
return $this->checkoutSession->getKlarnaOfficialInteroperabilityData();
}
public function getInteroperabilityPaymentState() {
return $this->checkoutSession->getKlarnaOfficialInteroperabilityPaymentState();Link copied!
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:
JavaScript Event (Frontend)
Copied
prestashop.emit('updateKlarnaInteroperabilityToken', {
klarna_interoperability_token: token,
Klarna_order_state: order_state,
});
PHP hook (backend)
Copied
Hook::exec('updateKlarnaInteroperabilityToken', [
'klarna_interoperability_token' => $token,
]);
As previously stated, backend is mandatory to implement, while frontend is optional.
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:
Copied
public function install()
{
return parent::install()
&& $this->registerHook('updateKlarnaInteroperabilityToken');
}
2. Implementing the Hook Listener
Listen for the hook using a method named hookUpdateKlarnaInteroperabilityToken in your module’s main class:
Copied
public function hookUpdateKlarnaInteroperabilityToken($params)
{
if (isset($params['klarna_interoperability_token'])) {
$klarnaInteroperabilityToken = $params['klarna_interoperability_token'];
// Use the token as needed
}
}
In this example you can see how the interoperability_token is stored by the Klarna plugin in the session storage.
The field in the session storage is named klarna_interoperability_token and will be accessible as follows:
Copied
sessionStorage.getItem('klarna_interoperability_token')
sessionStorage.getItem('klarna_interoperability_data')
sessionStorage.getItem('klarna_interoperability_payment_state')
Link copied!
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:
Copied
payload: {
interoperabilityToken: <token_value>
paymentState: <payment_state>
}
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:
Copied
payload: {
interoperabilityToken: <token_value>
paymentState: <payment_state>
}
The AP should process this token and prepare their plugin to use it when the shopper reaches the checkout.
Once the token is received on the SFCC client, it is forwarded to the server and stored in the session as follows:
Copied
session.privacy.klarna_interoperability_token = <interoperability_token>
This makes it available for later retrieval by the AP.
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:
Copied
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
Link copied!
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:
Copied
do_action( 'kec_process_order', $wc_order, $interoperability_token, $interoperability_data, $interoperability_payment_state, $other_klarna_data );
The Acquiring Partner plugin should add an observer to ensure they are notified on actions. This could look the following way:
Copied
add_action('kec_process_order', 'psp_kec_process_order', 10, 3);
function psp_kec_process_order( $wc_order, $interoperability_token, $interoperability_data, $interoperability_payment_state, $other_klarna_data ) {
// PSP Logic here...
// ...
// ...
wp_safe_redirect( $psp_redirect_url );
}
The interoperability token will be stored like this in the session for the WooCommerce customer:
Copied
WC()->session->set( 'klarna_interoperability_token', $token );
There is also an option to set this in the frontend, if this would be preferable. Then it can be read with the code:
Copied
const token = window.klarna_interoperability_token; or const token = klarna_interoperability_token;
The interoperability token can be retrieved by reading it using the WooCommerce session with the same key as we set it with, using the following code:
Copied
$token = WC()->session->get( 'klarnainteroperability_token' );
Link copied!
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 Mollie merchants.
Currently we have logic in place that automatically connects the account based on the url - meaning a Mollie 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 Mollie 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.