Skip to content

Commit cc4ef1a

Browse files
authored
Merge pull request #164 from paytrail/klarna-documentation
Add Klarna documentation
2 parents 72dc3ea + 2a4b5d7 commit cc4ef1a

2 files changed

Lines changed: 201 additions & 10 deletions

File tree

docs/README.md

Lines changed: 200 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,125 @@ if (applePayButton.canMakePayment()) {
454454

455455
_**Note:** The callback given to `mount()` is called on a successful payment, and is called with the merchants (your) Paytrail success redirect url. You can customize the actions after a successful payment. The example callback above will redirect the user to the success url after 1.5 seconds, to give time for the Apple Pay modal success-animation to finish._
456456

457+
## Klarna
458+
459+
For a comprehensive guide on optimizing your integration and boosting sales, please refer to [Klarna's dedicated Paytrail documentation](https://docs.klarna.com/acquirer/paytrail/get-started/ecosystem-overview/?utm_source=paytrail-docs).
460+
461+
For operational topics such as dispute handling, accessing the Klarna Partner Portal, and configuring payment methods, please visit the [Paytrail Help Center](https://support.paytrail.com/hc/en-us/sections/40564512581009-Klarna).
462+
463+
### Payments
464+
465+
#### Standard Integration
466+
467+
The standard Paytrail integration for Klarna doesn't require any Klarna-specific API calls. Payments are created using the normal **Create payment** API.
468+
469+
Klarna also supports **manual invoice activation (capture)**; see [Invoices](#invoices).
470+
471+
472+
For payment reference and examples, see:
473+
474+
- [Create](#create)
475+
- [List providers](#list-providers)
476+
477+
**How to present Klarna when you don't use Klarna Web SDK**
478+
479+
Klarna is shown either on the Paytrail hosted payment page or as a selectable payment method when rendering payment buttons in your store.
480+
481+
The Klarna payment option is returned as part of the standard payment method response in the credit [PaymentMethodGroup](#paymentmethodgroup).
482+
483+
#### Share customer data to increase conversion rates
484+
485+
Always share as much payment information as possible with Klarna. This is crucial for improving session continuity, enabling personalization, and increasing conversion rates. It also helps accelerate customer authentication, ensure consistency across all touchpoints, and streamline reconciliation and dispute management:
486+
487+
- Customer first and last name
488+
- Customer email address
489+
- Reference
490+
- Items
491+
- Invoicing address
492+
- Delivery address
493+
- Klarna Network Session Token
494+
- Klarna Network Data
495+
496+
**Klarna Network Session Token:** When customers interact with Klarna's [Conversion features](#conversion-features), Klarna Web SDK returns a Klarna Network Session Token.
497+
498+
In such cases, when the Klarna Network Session Token is present, you must collect this token and share it in [Klarna provider details](#klarna-provider-details) under the `providerDetails` object when creating the payment session with Paytrail. This is required for session continuity, personalization, and improved conversion rates. Note that Paytrail simply passes the token along; it's your responsibility to obtain and handle it.
499+
500+
Sharing the `klarna.networkSessionToken` is required with the Conversion features.
501+
502+
**Klarna Network Data:** You can also send `klarna.networkData` in the `providerDetails` object as a serialized JSON. This enriched data helps increase approval rates and reduce false declines by enabling Klarna to make smarter decisions. Providing complete and accurate data improves acceptance rates. For more details, refer to Klarna's [Optimize Conversion Rate](https://docs.klarna.com/acquirer/paytrail/get-started/maximize-sales-with-klarna/optimize-conversion-rate/?utm_source=paytrail-docs) documentation and also check [Klarna Network Data Schema](https://docs.klarna.com/acquirer/paytrail/api/klarna-network-data-schema/?utm_source=paytrail-docs).
503+
504+
505+
Example:
506+
507+
```json
508+
{
509+
"stamp": "29858472953",
510+
"reference": "9187445",
511+
"amount": 1590,
512+
"...",
513+
"providerDetails": {
514+
"klarna": {
515+
"networkSessionToken": "krn:network:eu1:live:session-token:eyJhbGciOiJFU...",
516+
"networkData": "{\"content_type\": \"application/vnd.klarna.example+json\",\"content\": ...}",
517+
}
518+
}
519+
}
520+
521+
```
522+
523+
#### Klarna provider details
524+
525+
| Field | Type | Required | Example / constraints | Description |
526+
| ------------------- | ------ | ------------------ | ----------------------------- | --------------------------------------------------------------------------- |
527+
| networkSessionToken | string | <center>x</center> | Min length 1, max length 8192 | Klarna Network Session Token from the Web SDK (Conversion features). |
528+
| networkData | string | <center>x</center> | Min length 1, max length 10240 | Optional serialized JSON; enriched data to improve approval rates. |
529+
530+
531+
#### Highest-converting Klarna Integration
532+
Integrate Klarna's Web SDK to deliver a seamless, optimized checkout experience on your site. Initialize the SDK, present Klarna in the payment selector, and finalize the flow with Klarna's payment button. You will also utilize the same Klarna Web SDK for [Conversion features](#conversion-features).
533+
534+
Refer to the Klarna documentation for [Implementing Klarna Web SDK](https://docs.klarna.com/acquirer/paytrail/recommended-integration/build-the-checkout/klarna-websdk/?utm_source=paytrail-docs).
535+
536+
### Presenting Klarna
537+
538+
Integrate Klarna into your checkout by following Klarna's branding and messaging guidelines to optimize the customer journey and maximize conversions.
539+
540+
Refer to the Klarna documentation for [Presenting Klarna in your checkout](https://docs.klarna.com/acquirer/paytrail/recommended-integration/klarna-in-your-checkout/?utm_source=paytrail-docs) and [Checkout form overview](https://docs.klarna.com/acquirer/paytrail/recommended-integration/build-the-checkout/overview/?utm_source=paytrail-docs).
541+
542+
### Conversion features
543+
544+
You can implement Klarna's [Conversion features](https://docs.klarna.com/acquirer/paytrail/additional-features/partner-portal/conversion-boosters/?utm_source=paytrail-docs) with your payments. These features should be implemented directly on your online store using the guidelines provided in Klarna Docs and the Klarna Partner Portal:
545+
546+
- [Klarna Express Checkout](https://docs.klarna.com/acquirer/paytrail/express-checkout/integration-prerequisites/?utm_source=paytrail-docs)
547+
- [On-site Messaging](https://docs.klarna.com/acquirer/paytrail/on-site-messaging/integration-prerequisites/?utm_source=paytrail-docs)
548+
- [Sign in with Klarna](https://docs.klarna.com/acquirer/paytrail/sign-in-with-klarna/integration-prerequisites/?utm_source=paytrail-docs)
549+
550+
For Conversion features, make sure to add the `klarna_network_session_token` returned by the Klarna Web SDK to the `providerDetails.klarna.networkSessionToken` field in Paytrail's `/payments` call.
551+
552+
Alternative to the `/payments` endpoint, you can also utilize two other dedicated endpoints for Klarna:
553+
- `/payments/klarna/charge` (for auto-capture)
554+
- `/payments/klarna/authorization-hold` (for manual capture)
555+
556+
Using one of these endpoints instead of the `/payments` endpoint helps create a faster checkout experience for your customers by shortening API response times and eliminating unnecessary redirection to a payment link when it's not required.
557+
558+
With these endpoints, you can use the exact same request body you already have for the `/payments` endpoint, however, their response would be different than `/payments`.
559+
560+
If `/payments/klarna/charge` or `/payments/klarna/authorization-hold` is successful, `HTTP 201` and the `transactionId` of the payment is directly returned. This means that the information provided with the `klarna.networkSessionToken` was sufficient to finalize the payment, so no further action is needed from the customer. You can then proceed to create the order in your system.
561+
562+
If the customer still needs to get redirected to take further action about the payment, `HTTP 403` along with the `transactionId` and `stepUpUrl` is returned. In this case, redirect the customer to the `stepUpUrl`, so that they can complete their purchase:
563+
564+
```json
565+
{
566+
"transactionId": "8772e75a-7439-........-c0b5a7184fc4",
567+
"stepUpUrl": "https://pay.klarna.com/eu/requests/53bc0e65-........-90d3-48cd2378031f/start",
568+
"error": "Step-up required"
569+
}
570+
```
571+
572+
If you prefer to use `/payments/klarna/authorization-hold`;
573+
- to capture the authorization, you need to call `/payments/{transactionId}/klarna/commit`
574+
- to void (cancel) the authorization, you need to call `/payments/{transactionId}/klarna/revert`
575+
457576
## Token payments
458577

459578
Paytrail provides an API for tokenizing payment cards and issuing payments on those tokenized payment cards.
@@ -763,27 +882,91 @@ If the flow fails due to issues with the card itself (insufficient funds, fraud
763882

764883
## Invoices
765884

766-
### Manually activating invoices
885+
### Manually activating payments
886+
887+
For Klarna and Walley B2C/B2B, you can activate the payment at a later time, for example for pre-ordered products.
888+
Activation window:
889+
890+
- Klarna: up to 28 days
891+
- Walley: up to 90 days
892+
893+
After this time, the payment **can no** longer be activated.
894+
895+
#### Creating payments with pending status
896+
897+
Set the `manualInvoiceActivation` flag to true. New payment is set to `pending` state.
898+
If the payment is made with unsupported providers, this flag is ignored.
899+
900+
- with Klarna, an authorization hold is made for the amount and is kept for the maximum duration of activation window.
901+
- with Walley, no authorization hold is made.
902+
903+
Refer to [create payment request body section](#create-payment)
904+
905+
```json
906+
{
907+
"stamp": "29858472953",
908+
"reference": "9187445",
909+
"amount": 1590,
910+
"currency": "EUR",
911+
"language": "FI",
912+
"manualInvoiceActivation": true
913+
"..."
914+
}
915+
```
916+
917+
### Capturing payments
918+
919+
!> Updated endpoint! Old endpoint remains functional but all new integrations should use the new endpoint.
920+
921+
`HTTP POST /payments/{transactionId}/capture-order` manually activates invoice by transaction ID.
922+
923+
Deprecated endpoint `HTTP POST /payments/{transactionId}/activate-invoice`
767924

768-
Paytrail provides customer an option to pay with invoice. For certain invoice payment methods (currently only Walley), it is possible to activate the invoice manually later. This can be used for example with preordered products.
925+
Sending a capture-order request changes the payment status to `accepted` and with:
769926

770-
Walley will keep the incvoice open for a maximum of 90 days. An invoice **cannot** be activated after this 90 day period.
927+
- Klarna, issues a charge for the authorization hold
928+
- Walley, activates the invoice
771929

772-
#### Payment creation to pending status
930+
##### Request
773931

774-
Payment needs to be created with the `manualInvoiceActivation` flag set to true. If paid with invoice, the payment will be left to `pending` status and invoice will not be activated automatically.
932+
No request body required.
775933

776-
#### Activating invoice
934+
##### Response
777935

778-
`HTTP POST /payments/{transactionId}/activate-invoice` manually activates invoice by transaction ID. Can only be used if payment was paid with Walley, is in pending status and the payment was created within 90 days of the activation call.
936+
Capture will return `HTTP 200` when successful.
937+
938+
| field | type | description |
939+
| ------- | ------ | --------------------------------------------- |
940+
| status | string | Status of activation. `ok` or `error` |
941+
| message | string | Response details, eg. detailed error message. |
942+
943+
### Cancelling payment
944+
945+
!> Relevant for Klarna payment method only, and only for payments made with `manualInvoiceActivation`. If you're looking to make a refund, please refer to [refund](#Refund) section.
946+
947+
`HTTP POST /payments/{transactionId}/cancel-order` cancels the payment and releases any authorization holds made.
948+
949+
Klarna payments made requiring manual invoice activation are going to be cancelled automatically after the activation window expires.
950+
951+
With `manualInvoiceActivation` you are issuing an authorization hold for the amount. It is advised to issue a cancel for the payment as soon as you know you are going to do so, even though this is an automatic operation at the end of expiry window.
779952

780953
##### Request
781954

782955
No request body required.
783956

784957
##### Response
785958

786-
Activation will return `HTTP 200` when successful.
959+
Cancel will return `HTTP 201` when successful, or `HTTP 202` when request is received but response to cancellation cannot be given right away.
960+
961+
| Status code | Explanation |
962+
| ----------- | ------------------------------------------------------------------------------------- |
963+
| 201 | Invoice cancelled |
964+
| 202 | Invoice cancellation requested, status of the payment will be updated asynchronously. |
965+
| 200 | Invoice already cancelled. |
966+
| 400 | Invalid request. Refer to body.message for more information |
967+
| 500 | Other error. Refer to body.message for more information |
968+
969+
###### Body
787970

788971
| field | type | description |
789972
| ------- | ------ | --------------------------------------------- |
@@ -1025,12 +1208,13 @@ General API HTTP status codes and what to expect of them.
10251208
| customer | [Customer](#customer-1) | <center>x</center> | Customer information |
10261209
| deliveryAddress | [Address](#address) | <center>-</center> | Delivery address |
10271210
| invoicingAddress | [Address](#address) | <center>-</center> | Invoicing address |
1028-
| manualInvoiceActivation | boolean | <center>-</center> | If paid with invoice payment method, the invoice will not be activated automatically immediately. Currently only supported with Walley. |
1211+
| manualInvoiceActivation | boolean | <center>-</center> | If paid with invoice payment method, the invoice will not be activated automatically immediately. Supported with Walley and Klarna. |
10291212
| redirectUrls | [CallbackUrl](#callbackurl) | <center>x</center> | Where to redirect browser after a payment is paid or cancelled. A single redirect URL can have maximum of 300 characters. |
10301213
| callbackUrls | [CallbackUrl](#callbackurl) | <center>-</center> | Which url to ping after this payment is paid or cancelled. |
10311214
| callbackDelay | number | <center>-</center> | Callback URL polling delay in seconds. If callback URLs are given, the call can be delayed up to 900 seconds. Default: 0 |
10321215
| groups | [PaymentMethodGroup](#paymentmethodgroup)[] | <center>-</center> | Instead of all enabled payment methods, return only those of given groups. It is highly recommended to use [list providers](#list-providers) before initiating the payment if filtering by group. If the payment methods are rendered in the webshop the grouping functionality can be implemented based on the `group` attribute of each returned payment instead of filtering when creating a payment. |
10331216
| usePricesWithoutVat | boolean | <center>-</center> | If true, `amount` and `items.unitPrice` should be sent to API not including VAT, and final amount is calculated by Paytrail's system using the items' `unitPrice` and `vatPercentage` (with amounts rounded to closest cent). Also, when true, **items must be included** and all item unit prices must be positive. |
1217+
| providerDetails | [ProviderDetails](#providerdetails) | <center>-</center> | Pass properties to payment methdos that support additional functionality. Content depends on payment method used. |
10341218

10351219
##### Item
10361220

@@ -1087,6 +1271,12 @@ These URLs must use HTTPS.
10871271
| amount | integer | <center>x</center> | 250 | Amount of commission in currency's minor units, e.g. for Euros use cents. VAT not applicable. |
10881272
| vatPercentage | integer | <center></center> | 25.5 | Commissions VAT percentage. Values between 0 and 100 are allowed with one number in decimal part. If not given, 25.5 will be used as default |
10891273

1274+
##### ProviderDetails
1275+
1276+
| Field | Type | Required | Example | Description |
1277+
| ------ | ------------------------------------------------- | ------------------ | ------- | ---------------------------------- |
1278+
| klarna | [KlarnaProviderDetails](#Klarna-provider-details) | <center>-</center> | | Parameters for conversion boosters |
1279+
10901280
See [an example payload and response](/examples#create)
10911281

10921282
#### Response body
@@ -1133,7 +1323,7 @@ The form field values are rendered as hidden `<input>` elements in the form. See
11331323
| `mobile` | Mobile payment methods: Pivo, Siirto, MobilePay |
11341324
| `bank` | Bank payment methods |
11351325
| `creditcard` | Visa, MasterCard, American Express |
1136-
| `credit` | Instalment and invoice payment methods: OP Lasku, Walley, Jousto, AfterPay |
1326+
| `credit` | Instalment and invoice payment methods: Klarna, OP Lasku, Walley |
11371327

11381328
##### PaymentMethodGroupData
11391329

0 commit comments

Comments
 (0)