Learn how to share the QR code with the customer and monitor the distribution status.
To share the QR code that the customer will scan in-store and to monitor the distribution status, you have to get the distribution result from Klarna. You can do so in one of two ways:
To get the distribution result from Klarna, send an empty request body to the result endpoint.
Link to result endpoint is included in distribution.result_url
field in session initiation response.
In response to your request, you'll receive the distribution status and the URL that you can use to display the QR code on a payment device.
The response will differ depending on the value you provided in the method parameter when initiating the payment session.
Success response parameters
Parameter | Type | Description |
---|---|---|
status | string | The distribution status of the payment. Depending on the distribution status, you can take some additional actions. |
qr | string | The URL that contains the QR code and the QR code has a payment link embedded. You can display this QR code to customers to scan and pay. |
payment_link | string | The payment link URL. You can distribute the link by encoding it as a QR code or by sending it in an SMS. |
If the QR code distribution fails, the response includes the status
parameter equal to FAILED
and an error code you can use to fix the error.
{
“status”: “FAILED”
“error”: { // mandatory if status = FAILED
“code” : “INTERNAL_ERROR”
}
}
A sample error response to the distribution request.
The distribution statuses change when an action is performed either by you, the customer, or by the system.
The distribution statuses in an ongoing In-store session.
Below is a list of all possible distribution statuses, along with actions you can take for each.
Distribution status | Description | Action to take |
---|---|---|
WAITING | The payment link has not been distributed yet. | Try to distribute the payment again if enough time has passed since the last attempt, for example, after 2 minutes. |
DISTRIBUTED | The payment link has been distributed. | Use the link from the distribution result endpoint and display the QR code to the customer. |
ACCESSED | The customer has accessed the payment link. | No action. |
COMPLETED | The customer has completed the payment and a new order has been automatically placed. | Get the order id from the distribution result endpoint or webhook. |
CANCELED | The payment session has been canceled. | No action. |
FAILED | The payment link could not be distributed. | Read the error code sent in response. |
If you have provided a URL endpoint when initiating the payment session, you'll get the distribution status updates via a webhook notification instead of having to poll the server for status updates.
The URL provided as the status_update
parameter must use HTTPS, but to be able to authenticate that the notification comes from Klarna, we recommend you generate a one-time token that you'll only use for this specific In-store payment session.
"distribution": {
"method": "qr",
"callback_urls": {
"status_update": "https://example.com/statsCallbackEndpoint?klarnaId={klarna_session_id}&secretToken=7d1cbc3b-b30c-4be2-a8c4-dc76482d7bf6"
}
}
}
For extra security, when you get a webhook notification and the distribution status is COMPLETED
, send a GET
request to the distribution result endpoint. This lets you validate if the notification of the status update was sent by Klarna.
The webhook sends the distribution result payload for the following distribution status changes:
Distribution status | Description | Action to take |
---|---|---|
DISTRIBUTED | The payment link has been distributed. | If method = qr , use the link from the distribution result endpoint and display the QR code to the customer. |
ACCESSED | The customer has accessed the payment link. | No action. |
COMPLETED | The customer has completed the payment and a new order has been automatically placed. | Get the order id from the distribution result endpoint or webhook. |
CANCELED | The payment session has been canceled. | No action. |
FAILED | The payment link could not be distributed. | Read the error code sent in response. |
Once you share the QR code with the customer, they can pay. Once the payment is completed, a new order gets created in Klarna's systems.
A message is displayed to the customer informing them that the payment is done. The module page displays the payment status.
The new order is automatically placed and captured. You can retrieve the order identifier from the distribution result URL specified when creating the payment session.
If you've provided the distribution webhook URL as the callback_url
parameter, you'll get the order identifier via a webhook notification.
{
"status": "COMPLETED"
"order_id": "588314f6-dd10-11ed-afa1-0242ac120002",
"klarna_reference": "XDC23412"
}
The order identifier (order_id
) is returned to the distribution result endpoint URL and the webhook URL.
If a payment error occurs, you may retry the process by first canceling the existing payment session and initiating a new payment.