Creating an Inline Session
Create a new session whenever the customer displays your checkout page.
- Inline Specifications
- When you send a session request, set theapSessionsService_paymentFlowModefield toinline.Cybersourceresponds with a pre-approval token in theapSessionsReply_processorTokenfield. 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
paymentMethod_name
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
- <paymentMehtod_name>pay_later</paymentMethod_name>
Calculating the Grand Total Amount
Klarna requires that the grand total amount of a purchase be included in the request
using the
purchaseTotals_grandTotalAmount
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
billTo_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
- <billTo> <language>es</language> </billTo>
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 as the
item_#_
fields,
starting with item_0_
, and increasing in numerical
order.For more information about how to properly format line items in your request, see
Using Line Items in the Reference Information section.
Endpoints
Set the
apSessionsService_run
field to
true
, and send the request to one of these
endpoints:Production:
https://ics2ws.ic3.com/commerce/1.x/transactionProcessor
Test:
https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor
Response Status
The session service responds with one of these statuses as the
apSessionReply_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.
The session service also responds with a reason code as the
apSessionReply_reasonCode
field value. For more
information about reason codes, see the Reason Codes for the Simple Order
API.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 a request to thehttps://ics2ws.ic3.com/commerce/1.x/transactionProcessorendpoint and include these required fields:Do not send any personally identifiable information (PII) data about the customer in the request to create a session.
- Set toKLI.
- apSessionService_paymentFlowMode
- Set toinlineto display the Klarna widget on your checkout page.
- apSessionsService_cancelURL
- Set to the URL to which the customer is redirected after cancelling the Klarna payment.
- Set to the URL to which the customer is redirected after the Klarna payment fails.
- apSessionsService_paymentMethod_name
- Set to one of these values to display the Klarna product you are offering:
- pay_later: pay later
- pay_now: pay now
- pay_over_time: pay over time
- Set totrue.
- Set toN.
- Set to the URL to which the customer is redirected after successfully completing the Klarna payment.
- Add/Klarna/Reply.jspto the end of the URL.
- https://www.test.com/Klarna/Reply.jsp
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- You can include these optional fields in the request:
- billTo_language
- If this field is not included, the language is set to English by default.
- For a list of possible values, see theISO Standard Language Codesguide.
- To include an optional coupon in the request, include these fields:
- Set tocoupon.
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- Replace the#character with the number0for the first item and consecutive numbers for any additional items.
- Set the Session Token ID in the Klarna widget to theprocessorTokenfield 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 theapAuthService_preapprovalTokenrequest field to the authorization token value created by the Klarna widget.<preapprovalToken>a6b2229c-665b-5660-a5fe-063bef3d9a1e</preapprovalToken>
XML Example: Creating a Session
Inline Request
12345678910111213141516171819202122232425262728293031323334353637<="urn:schemas-cybersource-com:transaction-data-1.213"> <merchantID>test_merchant</merchantID> <merchantReferenceCode>refnum-1234</merchantReferenceCode> <billTo> <firstName>John</firstName> <lastName>Smith</lastName> <street1>123 Happy St</street1> <city>Sunnyville</city> <state>VA</state> <postalCode>12345</postalCode> <country>US</country> <email>john@email.com</email> </billTo> <item> <unitPrice>9.00</unitPrice> <quantity>1</quantity> <productCode>A4890B5023</productCode> <productName>Skirt on the sky</productName> <productSKU>skirtonsky$bluegreen</productSKU> <taxAmount>1.00</taxAmount> <totalAmount>10.00</totalAmount> <productDescription>Amnesiac Shirt</productDescription> </item> <purchaseTotals> <currency>USD</currency> <grandTotalAmount>10.00</grandTotalAmount> </purchaseTotals> <apPaymentType>KLI</apPaymentType> <apSessionsService run="true"> <cancelURL>https://www.merchant.com/Klarna/Reply.jsp</cancelURL> <successURL>https://www.merchant.com/Klarna/Reply.jsp</successURL> <failureURL>https://www.merchant.com/Klarna/Reply.jsp</failureURL> <sessionsType>N</sessionsType> <paymentMethod_name>pay_now</paymentMethod_name> <paymentFlowMode>inline</paymentFlowMode> </apSessionsService> </>
Inline Response
12345678910111213141516171819<:c="urn:schemas-cybersource-com:transaction-data-1.213"> <merchantReferenceCode>refnum-1234</merchantReferenceCode> <requestID>6958601255246857703007</requestID> <decision>ACCEPT</decision> <reasonCode>100</reasonCode> <requestToken>AxjnrwSTeTn93WXAQw5f/6IZYjWmdmbZq0orKCojmjrTtjSBX0GY0MmkmXoxZaH/pN5Of3dZcBDDl8AA9DNl</requestToken> <purchaseTotals> <currency>USD</currency> </purchaseTotals> <apSessionsReply> <reasonCode>100</reasonCode> <responseCode>00000</responseCode> <processorToken>eyJhbGciOiJSUzI1NiIsIm_TEST_TOKEN_1ZWJjLWI4MTEtMzYzNy1hYTRjLTY2ZWNhM</processorToken> <amount>10.00</amount> <reconciliationID>XFZ3YMYURE2A</reconciliationID> <status>COMPLETED</status> <dateTime>2023-09-28T00:15:26Z</dateTime> </apSessionsReply> </>