On This Page
Creating a HOP Session
Create a new session whenever the customer displays your checkout page.
- HOP Specifications
- When you send a HOP session request, set theapSessionService_paymentFlowModefield value toHOP.Cybersourceresponds with a Klarna redirect URL in theprocessorInformation.paymentUrlfield. Send the customer to the redirect URL to complete the checkout. When the customer completes the checkout, Klarna redirects the customer back to the merchant website and includes a token in the merchant URL. The token generated by Klarna can then be used in the authorization request to link it 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" } }
Endpoints
Production:
POST
https://api.cybersource.com
/pts/v2/payment-referencesTest:
POST
https://apitest.cybersource.com
/pts/v2/payment-referencesLine 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.
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 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 a HOP Session
Follow these steps to successfully create a HOP 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.
- orderInformation.billTo.postalCode
- Set toKLARNA.
- Set toINVOICE.
- Set toAP_SESSIONS.
- processingInformation.paymentFlowMode
- Set toHOPto display the Klarna widget on your checkout page.
- processingInformation.sessionType
- Set toN.
- 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:
- Redirect the customer to the URL in theprocessorInformation.paymentURLresponse field."processorInformation": { "paymentUrl": "https://pay.playground.klarna.com/na/hpp/payments/2JUV3NC" }
- When the customer completes the checkout using their Klarna credentials, Klarna redirects the customer to the URL you specified in themerchantInformation.successURLrequest field. Klarna appends the merchant's success URL with a unique Klarna generated token.https://www.test.com?auth-token=d9b4496b-f4b1-5ad5-bbe0-7f666682126
- When you send the authorization request, set theprocessorInformation.preApprovalTokenfield to the unique token Klarna appended to the success URL."processorInformation":{ "preApprovalToken": "d9b4496b-f4b1-5ad5-bbe0-7f666682126" }
Example: Create a HOP Session
Request
{ "merchantInformation": { "cancelUrl": "https://www.merchant-cancel-redirect-url.com", "successUrl": "https://www.merchant-success-redirect-url.com", "failureUrl": "https://www.merchant-failure-redirect-url.com" }, "orderInformation": { "billTo": { "administrativeArea": "VA", "postalCode": "22901", "country": "US" }, "amountDetails": { "currency": "USD" }, "lineItems": [ { "productName": "Skirt on the sky", "unitPrice": "1.00", "totalAmount": "1.00" } ] }, "paymentInformation": { "paymentType": { "name": "INVOICE", "method": { "name": "KLARNA" } } }, "processingInformation": { "actionList": "AP_SESSIONS", "paymentFlowMode": "HOP", "sessionType": "N" } }
Response to a Successful Request
{ "_links": { "self": { "method": "POST", "href": "/pts/v2/payment-references" }, "updateSession": { "method": "PATCH", "href": "/pts/v2/payment-references/7297155024486439603955" }, "status": { "method": "POST", "href": "/pts/v2/refresh-payment-status/7297155024486439603955" }, "order": { "method": "POST", "href": "/pts/v2/payment-references/7297155024486439603955/intents" } }, "clientReferenceInformation": { "code": "1729715502582" }, "id": "7297155024486439603955", "orderInformation": { "amountDetails": { "totalAmount": "1.00", "currency": "USD" } }, "processorInformation": { "responseDetails": "00000", "paymentUrl": "https://pay.playground.klarna.com/na/hpp/payments/23NmehI", "responseCode": "00000", "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjgyMzA1ZWJjLWI4MTEtMzYzNy1hYTRjLTY2ZWNhMTg3NGYzZCJ9.eyJzZXNzaW9uX2lkIjoiYmRiOGU5MGQtNzhiOS02ZWJkLTllZjMtOTNmNWYyN2Q3MmRhIiwiYmFzZV91cmwiOiJodHRwczovL2pzLnBsYXlncm91bmQua2xhcm5hLmNvbS9uYS9rcCIsImRlc2lnbiI6ImtsYXJuYSIsImxhbmd1YWdlIjoiZW4iLCJwdXJjaGFzZV9jb3VudHJ5IjoiVVMiLCJlbnZpcm9ubWVudCI6InBsYXlncm91bmQiLCJtZXJjaGFudF9uYW1lIjoiUGxheWdyb3VuZCBEZW1vIE1lcmNoYW50Iiwic2Vzc2lvbl90eXBlIjoiUEFZTUVOVFMiLCJjbGllbnRfZXZlbnRfYmFzZV91cmwiOiJodHRwczovL25hLnBsYXlncm91bmQua2xhcm5hZXZ0LmNvbSIsInNjaGVtZSI6dHJ1ZSwiZXhwZXJpbWVudHMiOlt7Im5hbWUiOiJrcGMtcHNlbC00NDI5IiwidmFyaWF0ZSI6ImEifSx7Im5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