Seamlessly trigger the Klarna Purchase Journey using the Klarna SDK and Payment Authorize API, ensuring smooth payment authorization and handling step-up scenarios when required.
Once the customer has selected Klarna and decided to proceed to the payment with Klarna, Acquiring Partners are expected to authorize the payment with Klarna and allow the customer to go through Klarna's Purchase Journey.
The following sequence usually applies:
As described in the previous section, once the customer has selected the Klarna payment option in the payment selector, the Acquiring Partner will need to render the Klarna Payment Button. The Payment Authorization will be triggered once the customer clicks on the Payment button.
This requires a combination of server-side and client-side implementation from the Acquiring Partner:
paymentButton
of the Payment Presentation instance by specifying the following attributes in the authorize
button click handler:data
: A function that returns a Promise resolving to an object containing the results of a call to the Payment Authorize API. The function would be triggered as the customer clicks on the payment button.options
: payment request options controlling the behavior of the Klarna Purchase Journey once launched.Sample code
// Klarna Payment Presentation instance declared to build the payment selector
var paymentPresentation = Klarna.Payment.Presentation({
currency: "USD",
amount: 11800,
locale: "en-US",
intents: ["PAY"]
});
// Configure the paymentButton of the Payment Presentation instance and specify the attributes of the authorize button click handler. The data attribute is a function that returns a Promise resolving to an object containing the results of a call to the Payment Authorize API.
The Acquiring Partner can also create a custom button to launch the Klarna Purchase Journey. This is detailed in the Launch the Klarna Purchase Journey with a custom button section.
The authorize data attribute from the SDK requires the Acquiring Partner to call Klarna's Payment Authorize API and return the results to the client-side.
interoperability_token
to share with the Acquiring Partner.interoperability_token
is provided by the Partner, it must be forwarded when calling Klarna's Payment Authorize API.In the request to the Payment Authorize API, the Acquiring Partner will specify the following parameters:
Path parameter
Parameter name | Description |
---|---|
partner_account_id | Identifier of the Partner account the action is done on behalf of. |
Header parameter
Parameter name | Description |
---|---|
Klarna-Interoperability-Token | Must contain the interoperability token if provided by the Partner. |
Request body
Parameter name | Description |
---|---|
currency | Currency in ISO 4217 format. |
request_payment_transaction | Represents a request to authorize a payment transaction. The amount parameter is sent through this object.The parameters will be transferred to the Payment Transaction created on a successful authorization. |
step_up_config | To support a step-up scenario, where the customer must approve the payment, Acquiring Partners must configure customer_interaction_config to determine how the purchase journey is launched. Applicable customer interaction config method for this integration pattern is HANDOVER .Acquiring Partners must also obtain a return_url and/or an app_return_url , to ensure proper redirection after authorization. This will be covered in detail in the section Handle step-up scenario.This object also allows Acquiring Partners to provide a payment_request_reference for the purpose of correlating the payment session or equivalent resource on your side with the Klarna Payment Request. This will also be exposed in payment request webhooks. |
supplementary_purchase_data | Additional information that provides more detailed information about the transaction, which helps reduce the risk of fraud and enhances transparency. Shopping basket, customer billing / shipping details or specific transaction data can be provided through this object. |
interoperability_data | This field should be used for any additional interoperability data sent by the Partner. |
When an interoperability_token
or interoperability_data
were shared by the Partner in the checkout session creation, they must be sent when calling the Payment Authorize API as defined in this section. How to receive those data points is defined in the previous section.
Be mindful when sharing customer data:
Below is an example request body for the Payment Authorize API. (interoperability token sent as an HTTP header parameter):
{
"currency": "USD",
"supplementary_purchase_data": { .. },
"interoperability_data": "<serialized-json>",
"request_payment_transaction": {
"amount": 11800,
"payment_transaction_reference": "acquiring-partner-transaction-reference-1234"
},
"step_up_config": {
"payment_request_reference": "acquiring-partner-request-reference-1234",
The Payment Authorize API can yield 3 different outcomes depending on the transaction and the consumer:
Result | Description |
---|---|
APPROVED | The Payment Authorization is approved without additional customer interaction. A Payment Transaction is created and contained in the response. |
STEP_UP_REQUIRED | Additional customer interaction is required to authorize the payment. Those interactions need to happen in Klarna’s Purchase Journey and the customer has to be redirected to it. Read more about how to handle the Step-up Scenario. |
DECLINED | The payment cannot proceed due to reasons such as fraud, final decline or risk concerns. |
When the request is successful, a Payment Transaction is created on Klarna Network and will be available for post-purchase operations through the Payment Transactions API, no further customer interactions are needed and the Acquiring Partner can directly inform their partners that the payment session is completed and that the customer can be redirected to the order confirmation page.
Acquiring Partners must store the Klarna payment_transaction_id
for future operations on the transaction through the Payment Transactions API, such as capture and refund. The Acquiring Partner will receive the following parameters in the response.
Response body
Parameter name | Description |
---|---|
payment_transaction_response | The response for a payment transaction will contain the result parameter which specifies the outcome of the second authorization.In case of a successful Authorization (result APPROVED ), the response body includes the Payment Transaction object. |
payment_transaction | The Payment Transaction object represents a single payment transaction This field is only returned if the payment_transaction_response.result is set to APPROVED The payment_transaction_id returned is necessary to manage the Payment Transaction through the Payment Transaction API. |
Sample response - APPROVED
{
"payment_transaction_response": {
"result": "APPROVED",
"payment_transaction": {
"payment_transaction_id": "krn:payment:eu1:transaction:6debe89e-98c0-[...]",
"payment_transaction_reference": "acquiring-partner-transaction-reference-1234",
"amount": 11800,
"currency": "USD",
"payment_funding": {...},
"payment_pricing": {...}
Back to the SDK, the Acquiring Partner will return the payment transaction result
and optionally a returnUrl
as output to the authorize handler's data
function, which the SDK will use to handle the redirection.
Sample code
const buttonConfig = {
shape: "pill",
theme: "dark",
authorize: {
data: () => {
// The Acquiring Partner calls the Payment Authorize API endpoint which returns an APPROVED transaction
return {
result: "APPROVED",
returnUrl: "https://" //optional
}
In this scenario as the consumer clicks on the Klarna Payment button, the transaction will be immediately approved and the consumer will be redirected to the order confirmation page.
Acquiring Partners can also register an event handler for the transactionapproved
event. This event can be used by the Acquiring Partner when the outcome of the call to the Authorize API endpoint is an approved transaction.
To implement this method, follow these steps:
on("transactionapproved", callback)
method.klarna.Payment.on("transactionapproved", () => {
// Execute actions appropriate for an approved transaction.
});
If a transaction could not be approved by Klarna and the step-up scenario cannot be triggered (due to missing configuration or for permanent decline), the Acquiring Partner will receive a decline. Declines should not be replayed without change of context.
The Acquiring Partner should inform the Partner that the payment could not be completed and the Partner should invite the customer to select another payment method.
Response body
Parameter name | Description |
---|---|
payment_transaction_response | The response for a payment transaction will contain the result parameter which specifies the outcome of the 1st authorization.In case a decline, the result will be set to DECLINED |
Sample response - DECLINED
{
"payment_transaction_response": {
"result": "DECLINED"
}
}
Back to the SDK, the Acquiring Partner will pass the payment transaction result and optionally a returnUrl
as output to the authorize handler's data
function, which the SDK will use to handle the redirection.
Sample code
const buttonConfig = {
shape: "pill",
theme: "dark",
authorize: {
data: () => {
// The Acquiring Partner calls the Payment Authorize API endpoint which returns a DECLINED transaction
return {
result: "DECLINED",
returnUrl: "https://" //optional
}
The Acquiring Partner should inform the Partner that the transaction could not be completed and the Partner should invite the customer to select another payment method.
Acquiring Partners can register an event handler for the transactiondeclined
event. This event can be used by the Acquiring Partner when the outcome of the call to the Authorize API endpoint is a declined transaction.
To implement this method, follow these steps:
on("transactiondeclined", callback)
method.klarna.Payment.on("transactiondeclined", () => {
// Take appropriate actions when the transaction is declined.
});
When a Payment Transaction could not be immediately created by Klarna and a step-up configuration was provided in the call to the Payment Authorization API, the Step-up scenario will be triggered and the Acquiring Partner will receive a STEP_UP_REQUIRED
result.
In case your systems cannot support a pattern where there is no consumer interaction at the initialization of the session, it is possible to force the Step-up flow. This can be achieved by adding the mode = REQUIRED
to the step_up_config
object.
The mode = REQUIRED
will be available in a future release.
In such scenario, the Payment Authorization API returns a Payment Request in the response. The expectation is that the customer will go through Klarna’s Purchase Journey to complete the payment, usually triggering authentication and payment option selection. The required work to properly make the step-up scenario work is outlined in the next section.
The following parameters are present in the response to the request:
Response body
Parameter name | Description' |
---|---|
payment_transaction_response | The response for a payment transaction will contain the result parameter which specifies the outcome of the 1st authorization.In case of the Step up flow the result will be set to STEP_UP_REQUIRED |
payment_request | The base properties of a Payment Request. This field is only returned if the payment_transaction_response.result is set to STEP_UP_REQUIRED The payment_request_id necessary to continue the payment client side with the SDK will be returned in the state_context.customer_interaction object |
Sample response - STEP_UP_REQUIRED
{
"payment_transaction_response": {
"result": "STEP_UP_REQUIRED"
},
"payment_request": {
"payment_request_id": "krn:payment:eu1:request:552603c0-fe8b-4ab1-aacb-41d55fafbdb4",
"payment_request_reference": "acquiring-partner-request-reference-1234",
"amount": 11800,
"currency": "USD",
"state": "SUBMITTED",
Back to the SDK, the Acquiring Partner will return the payment transaction result
and paymentRequestId
as output to the authorize handler's data
function, which the SDK will use to trigger the Klarna Purchase Journey as the customer clicks on the Klarna Payment Button.
Sample code
const buttonConfig = {
shape: "pill",
theme: "dark",
authorize: {
data: () => {
// The Acquiring Partner calls the Payment Authorize API endpoint which returns a STEP_UP_REQUIRED transaction
return {
result: "STEP_UP_REQUIRED",
paymentRequestId: "<payment_request_id>"
}