FILTER BY TAG

Creating an Inline Session

Create a new session whenever the customer displays your checkout page.
Inline Specifications
When you send a session request, set the
apSessionService_paymentFlowMode
field to
inline
.
Cybersource
responds with a pre-approval token in the
processorInformation.token
field. Set the Klarna widget installed in the merchant website to token. When the customer completes the checkout using the Klarna widget, the widget responds with an authorization token. Include the authorization token in the authorization request to link the authorization to the session.

Klarna Payment Methods

When you request the session service, you can determine the Klarna payment method you want to offer your customers. Set the optional
paymentInformation.paymentType.method.type
request field to a value listed in the Payment Method column.
Payment Methods
Payment Method Field Value
Description
Klarna Products
pay_later
Customer pays total bill at a set date.
  • Klarna Invoice
  • Klarna Pay Later
  • Klarna Pay Later by Card (PLBC)
pay_now
Customer pays total bill at the time of checkout.
  • Klarna Direct Bank Transfer
  • Klarna Direct Debit
pay_over_time
Customer pays bill in equal multiple installments.
  • Klarna Account
  • Klarna Financing
  • Klarna Fixed Installment Plans
  • Klarna Interest Free
Example: Payment Methods in Session Request
{ "paymentInformation": { "paymentType": { "method": { "type": "pay_later" } } } }

Calculating the Grand Total Amount

Klarna requires that the grand total amount of a purchase be included in the request using the
orderInformation.amountDetails.totalAmount
field. The country of the transaction and the use of coupons affect how to calculate the grand total amount.
For more information about how to calculate the grand total amount, see Calculating the Grand Total Amount in the Reference Information section.

Language Specification

To set the language for your Klarna checkout experience, include the
buyerInformation.language
field in your request. By not including this field, the Klarna checkout experience is set to English by default. For a list of all possible values, see the
ISO Standard Language Codes
guide.
Example: Language Specification
{ "buyerInformation": { "language": "es" } }

Line Items

Klarna uses line items when you send a create session and update session requests. Line items are used to include information about the goods that your customers purchase, such as product name, quantity, and price.
Line items are represented in a request as the
lineItem[]
array request fields.
For more information about how to properly format line items in your request, see Using Line Items in the Reference Information section.

Endpoints

Production:
POST
https://api.cybersource.com
/pts/v2/payment-references
Test:
POST
https://apitest.cybersource.com
/pts/v2/payment-references

Response Status

The session service responds with one of these statuses as the
status
field value:
  • FAILED
    : The session request is not successful. Send a new session request.
  • INITIATED
    : The session is initiated and the customer may now checkout. Send periodic check status requests until the status updates to
    COMPLETED
    . For more information, see Check a Request Status.
When you send a check status request for an initiated session, you can receive one of these statuses when the session updates:
  • ABANDONED
    : The customer did not complete the payment using the redirect URL or widget.
  • COMPLETED
    : The customer completed the checkout process. You can now authorize the funds.

Requesting to Create an Inline Session

Follow these steps to successfully create an inline session.
  1. Send a
    POST
    request to the
    https://apitest.cybersource.com/pts/v2/payment-references
    endpoint and include these required fields:
    IMPORTANT
    Do not send any personally identifiable information (PII) data about the customer in the request to create a session.
    Non-US Countries
    US and Canada
    IMPORTANT
    The billing state and billing postal code fields are required when the billing country is set to
    US
    or
    CA
    .
  2. You can include these optional fields in the request:
    IMPORTANT
    If this field is not included, the language is set to English by default.
    For a list of possible values, see the
    ISO Standard Language Codes
    guide.
    orderInformation.lineItems[].productCode
    orderInformation.lineItems[].productDescription
    orderInformation.lineItems[].quantity
    orderInformation.lineItems[].taxAmount
    paymentInformation.paymentType.method.type
    paymentInformation.type
    processingInformation.sessionType
  3. Set the Session Token ID in the Klarna widget to the
    processorInformation.token
    field value from the session response.
    ID
    eyJhbGciOiJSUzI1NiIsImtpZCI6IjgyMzA1ZWJjLWI4MTEtMzYzNy...
  4. When the customer completes the payment using the Klarna widget, the Klarna widget creates a unique authorization token. Store the token for the authorization request.
    Authorizaiton Token:
    a6b2229c-665b-5660-a5fe-063bef3d9a1e
  5. When you send the follow-on authorization request, set the
    processorInformation.preApprovalToken
    request field to the authorization token value created by the Klarna widget.
    { "processorInformation": { "preApprovalToken": "a6b2229c-665b-5660-a5fe-063bef3d9a1e" } }

Example: Create an Inline Session

Request
{ "merchantInformation": { "cancelUrl": "https://www.test0.com", "successUrl": "https://www.google.com", "failureUrl": "https://www.test1.com" }, "orderInformation": { "billTo": { "firstName": "John", "lastName": "Smith", "address1": "123 Happy St", "locality": "Sunnyville", "administrativeArea": "CA", "postalCode": "55555", "country": "US", "email": "test email dot com" }, "amountDetails": { "totalAmount": "1.00", "currency": "USD" }, "lineItems": [ { "productCode": "A4890B5023", "productName": "Skirt on the sky", "productSku": "skirtonsky$bluegreen", "quantity": "1", "unitPrice": "1.00", "totalAmount": "1.00", "taxAmount": "0.00", "productDescription": "Amnesiac Shirt" } ] }, "paymentInformation": { "paymentType": { "name": "INVOICE", "method": { "name": "KLARNA", "type": "pay_now" } } }, "processingInformation": { "actionList": "AP_SESSIONS", "paymentFlowMode": "inline", "sessionType": "N" } }
Response to a Successful Request
{ "_links": { "self": { "method": "POST", "href": "/pts/v2/payment-references" }, "updateSession": { "method": "PATCH", "href": "/pts/v2/payment-references/7322957972776014303955" }, "status": { "method": "POST", "href": "/pts/v2/refresh-payment-status/7322957972776014303955" }, "order": { "method": "POST", "href": "/pts/v2/payment-references/7322957972776014303955/intents" } }, "clientReferenceInformation": { "code": "1732295797319" }, "id": "7322957972776014303955", "orderInformation": { "amountDetails": { "totalAmount": "1.00", "currency": "USD" } }, "processorInformation": { "responseDetails": "00000", "responseCode": "00000", "token": "inline_session_token_value" }, "reconciliationId": "XEKSO3R50AFW", "status": "COMPLETED", "submitTimeUtc": "2024-11-22T171638Z" }