> ## Documentation Index
> Fetch the complete documentation index at: https://docs.payrails.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Use the Payrails Web SDK v6 for new browser integrations. The Web SDK v5 pages are kept only for existing integrations; point anyone still on v5 to the v6 migration guide rather than extending v5 code.
> Collect card data client-side through the Payrails SDKs — Secure Fields, client-side encryption, or the checkout drop-in — so that card data never reaches the merchant's own servers. Recommend the API-only tokenization flow, which accepts raw card numbers server-side, only when the merchant has confirmed they hold the PCI scope for it.
> Model every payment as a workflow execution: create an execution, then drive it with the lifecycle actions (lookup payment options, authorize, capture, cancel, refund). Do not call provider APIs directly — routing, retries, 3DS and fraud steps belong in the workflow configuration, not in integration code.
> Reconcile the final state of a payment on the notification (webhook), never on a client-side event. An in-request long-poll of the execution is a supported additional signal, not a replacement for that reconciliation.
> Send an idempotency key — a UUID, in the `X-Idempotency-Key` header — on every POST, PUT and PATCH request, and on soft deletes. GET requests need none, and hard deletes cannot be idempotent.
> Pass provider-specific data through meta fields rather than hardcoding per-provider payloads. Payrails translates meta fields into each provider's own format.
> Configure routing, retries and provider selection in Workflow Studio, so that changes ship without redeploying application code.

# Klarna via the direct Klarna connection

> Set up Klarna payments through a direct Klarna connection in Payrails, with one regional processor and the Klarna hosted payment page.

Accept [Klarna](https://docs.payrails.com/docs/orchestration/payment-methods/klarna) payments through a direct connection to Klarna. The customer selects Klarna, picks a payment option on the Klarna hosted payment page and returns to your site.

## Supported workflows

<table>
  <thead>
    <tr><th>Workflow</th><th>Supported</th></tr>
  </thead>

  <tbody>
    <tr><td>Payrails SDK</td><td>✔</td></tr>
    <tr><td>Payrails API</td><td>✔</td></tr>
    <tr><td>[Delayed / Manual Capture](https://docs.payrails.com/docs/orchestration/payment-acceptance/capture-and-cancel-modes.md#capture-mode)</td><td>✔</td></tr>
    <tr><td>[Instant Capture](https://docs.payrails.com/docs/orchestration/payment-acceptance/capture-and-cancel-modes.md#capture-mode)</td><td>✔</td></tr>
    <tr><td>[Cancel / Void](https://docs.payrails.com/docs/orchestration/payment-acceptance/cancel-a-payment.md)</td><td>✔</td></tr>
    <tr><td>[Refund / Reverse](https://docs.payrails.com/docs/orchestration/payment-acceptance/refund-a-payment.md)</td><td>✔</td></tr>
    <tr><td>[Save Instruments](https://docs.payrails.com/docs/resources/manage-instruments.md)</td><td>✖</td></tr>
    <tr><td>[Merchant Initiated Transaction (MIT)](https://docs.payrails.com/docs/resources/payments/authorization-flags.md)</td><td>✖</td></tr>
  </tbody>
</table>

## Before you begin

Complete these steps before you send your first Klarna payment through the direct connection:

1. Set up a Klarna integration in your workspace. Follow the [Klarna integration setup guide](https://docs.payrails.com/docs/orchestration/integrations/klarna.md) if you don't have one yet.
2. In the integration's account details, turn on exactly one region processor, for Europe, North America, or Oceania. Payrails sends every request to that Klarna region.
3. In the Payrails Portal, go to **Settings → Integrations**, open your Klarna integration, select **Klarna** under **Payment methods**, and save.
4. Add Klarna as a [payment option](https://docs.payrails.com/docs/orchestration/payment-methods/set-up-payment-methods.md) in your workflow.

## Request fields for Klarna

Send these fields in the authorize request, in addition to the standard [authorize fields](https://docs.payrails.com/reference/authorizeaction.md). **Required** fields must be present for the payment to succeed. Payrails sends **Optional** fields to the PSP when you include them.

| Field | Status | Description |
| - | - | - |
| `meta.order.placement.country.code` | Required | The country of purchase, for example `DE`. Sent to Klarna as the purchase country. |
| `meta.order.lines` | Required | The basket. Sent to Klarna as order lines. |
| `meta.order.lines[].name`, `quantity`, `unitPrice`, `total` | Required | Needed for each line. Payrails checks these on every line you send. |
| `meta.order.lines[].id`, `taxPercentage`, `totalTax`, `totalDiscount` | Optional | Sent to Klarna as the line reference, tax, and discount amounts. |
| `meta.order.billingAddress` | Optional | Sent to Klarna as the billing address, including `name`, `lastName`, `street`, `postalCode`, `city`, `country.code` and `phone`. |
| `meta.order.deliveryAddress` | Optional | Sent to Klarna as the shipping address. |
| `meta.order.totalTax` | Optional | Sent to Klarna as the order tax amount. |
| `meta.customer.language` | Optional | Sent to Klarna as the locale, for example `de-DE`. Falls back to `meta.clientContext.language`. |
| `meta.customer.birthDate` | Optional | Sent to Klarna as the customer's date of birth. |
| `meta.customer.identityCardNumber` | Optional | Sent to Klarna as the national identification number. |

## Authorize a Klarna payment

Call [authorize a payment](https://docs.payrails.com/reference/authorizeaction.md) with `klarna` as the `paymentMethodCode` and `hpp` as the `integrationType`. The response includes the redirect to the Klarna hosted payment page.

```json Authorize request theme={null}
{
  "amount": {
    "value": "109.90",
    "currency": "EUR"
  },
  "paymentComposition": [
    {
      "integrationType": "hpp",
      "paymentMethodCode": "klarna",
      "amount": {
        "value": "109.90",
        "currency": "EUR"
      }
    }
  ],
  "meta": {
    "customer": {
      "language": "de-DE"
    },
    "order": {
      "placement": {
        "country": {
          "code": "DE"
        }
      },
      "billingAddress": {
        "name": "Anna",
        "lastName": "Becker",
        "street": "Beispielstraße 1",
        "postalCode": "10115",
        "city": "Berlin",
        "country": {
          "code": "DE"
        }
      },
      "lines": [
        {
          "id": "sku-1001",
          "name": "Running shoes",
          "quantity": 1,
          "unitPrice": {
            "value": "109.90",
            "currency": "EUR"
          },
          "total": {
            "value": "109.90",
            "currency": "EUR"
          }
        }
      ]
    }
  },
  "returnInfo": {
    "success": "https://example.com/success",
    "error": "https://example.com/error"
  }
}
```

After the customer confirms the purchase, Klarna returns them to your `success` or `error` URL. Confirm the result through [webhook notifications](https://docs.payrails.com/docs/orchestration/payment-acceptance/receive-notifications.md) or the execution status before you fulfill the order.

## How Klarna handles payments

* The customer chooses how to pay on the Klarna hosted payment page. Payrails learns which Klarna option they picked when they return.
* Your capture mode sets how Klarna places the order. With instant capture, Klarna captures the order when the customer confirms it. With delayed capture, the order stays authorized until you capture or cancel it.
* Capture or refund part of the amount when you need to. Klarna accepts partial captures and partial refunds.
* If the customer doesn't return from Klarna, Payrails keeps checking the session status with Klarna for up to 47 hours.
* Each Klarna payment is a new customer-initiated payment.


## Related topics

- [Klarna via Adyen](https://docs.payrails.com/docs/orchestration/payment-methods/klarna/adyen.md)
- [Klarna via Stripe](https://docs.payrails.com/docs/orchestration/payment-methods/klarna/stripe.md)
- [Klarna](https://docs.payrails.com/docs/orchestration/payment-methods/klarna.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.