On This Page
Creating an Inline Session
Create a new session whenever the customer displays your checkout page.
- Inline Specifications
- When you send a session request, set theapSessionService_paymentFlowModefield toinline.Cybersourceresponds with a pre-approval token in theprocessorInformation.tokenfield. 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 Method Field Value | Description | Klarna Products |
|---|---|---|
pay_later | Customer pays total bill at a set date. |
|
pay_now | Customer pays total bill at the time of checkout. |
|
pay_over_time | Customer pays bill in equal multiple installments. |
|
- 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-referencesTest:
POST
https://apitest.cybersource.com
/pts/v2/payment-referencesResponse 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 toCOMPLETED. 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.
- Send aPOSTrequest to thehttps://apitest.cybersource.com/pts/v2/payment-referencesendpoint and include these required fields:IMPORTANTDo not send any personally identifiable information (PII) data about the customer in the request to create a session.
- paymentInformation.paymentType.method.name
- Set toKLARNA.
- paymentInformation.paymentType.method.type
- Set toINVOICE.
- Set toAP_SESSIONS.
- processingInformation.paymentFlowMode
- Set toinlineto display the Klarna widget on your checkout page.
- Non-US Countries
- US and Canada
- IMPORTANTThe billing state and billing postal code fields are required when the billing country is set toUSorCA.
- You can include these optional fields in the request:
- IMPORTANTIf this field is not included, the language is set to English by default.
- For a list of possible values, see theISO Standard Language Codesguide.
- orderInformation.lineItems[].productCode
- orderInformation.lineItems[].productDescription
- orderInformation.lineItems[].quantity
- orderInformation.lineItems[].taxAmount
- paymentInformation.paymentType.method.type
- paymentInformation.type
- processingInformation.sessionType
- To include an optional coupon in the request, include these fields:
- Set the Session Token ID in the Klarna widget to theprocessorInformation.tokenfield value from the session response.IDeyJhbGciOiJSUzI1NiIsImtpZCI6IjgyMzA1ZWJjLWI4MTEtMzYzNy...
- 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
- When you send the follow-on authorization request, set theprocessorInformation.preApprovalTokenrequest 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" }