Skip to main content

What is Klarna?

Klarna is a buy now, pay later (BNPL) payment method that offers flexible payment options and supports recurring payments. This allows for accepting recurring payments and giving buyers more flexible ways to pay.

Sign-up

A Klarna account can be requested from the Klarna Business Portal.

Credentials

To connect a Klarna account, obtain the following credentials from the Klarna Business Portal.
  • Username: An API username which can be generated by navigating to PreferencesSettingsManage Klarna API Credentials.
  • Password: An API password which can be generated by navigating to PreferencesSettingsManage Klarna API Credentials.
  • Region: The region of the Klarna account. This can be Europe, North America, or Oceania.

Subscriptions (MIT)

Klarna can be used to:
  1. Store the buyer’s Klarna payment method during the first (customer-present) payment, and
  2. Charge future subscription renewals as merchant-initiated transactions (MIT) using the saved payment method - typically with no redirect.
This is the recommended approach for recurring subscriptions.

When to use this flow

Use this flow when:
  • A customer approves Klarna once during sign-up or checkout, and
  • they need to be charged again later for subscription renewals without requiring them to re-authenticate each time.

Prerequisites

  • A Klarna payment service needs to be configured for the merchant account.
  • Webhooks need to be configured for the Klarna payment service (required for tokenization).

How it works

Step 1. First payment (customer present)

On the initial subscription payment:
  • Use Klarna as the payment method
  • Provide a redirect_url so the customer can complete Klarna approval
  • Set store: true so the Klarna payment method is saved for the buyer
Example request
using Gr4vy;
using Gr4vy.Models.Components;

// Load your private key from disk, env, or your secret manager
var privateKey = "...";

var sdk = new Gr4vySDK(
    id: "example",
    server: SDKConfig.Server.Sandbox,
    bearerAuthSource: Auth.WithToken(privateKey),
    merchantAccountId: "default"
);

var res = await sdk.Transactions.CreateAsync(transactionCreate: new TransactionCreate() {
    Amount = 5000,
    Currency = "USD",
    Country = "US",
    PaymentMethod = new PaymentMethodRequest() {
        Method = "klarna",
        RedirectUrl = "https://yourapp.com/callback",
        Country = "US",
        Currency = "USD"
    },
    Store = true,
    PaymentSource = "recurring",
    MerchantInitiated = false,
    IsSubsequentPayment = false,
});
// handle response

Step 2. Subscription renewals (merchant initiated)

For each renewal:
  • Use the saved payment method ID by setting method to "id"
  • Mark the transaction as a subsequent recurring payment and merchant-initiated
Example request
using Gr4vy;
using Gr4vy.Models.Components;

// Load your private key from disk, env, or your secret manager
var privateKey = "...";

var sdk = new Gr4vySDK(
    id: "example",
    server: SDKConfig.Server.Sandbox,
    bearerAuthSource: Auth.WithToken(privateKey),
    merchantAccountId: "default"
);

var res = await sdk.Transactions.CreateAsync(transactionCreate: new TransactionCreate() {
    Amount = 5000,
    Currency = "USD",
    Country = "US",
    PaymentMethod = new PaymentMethodRequest() {
        Method = "id",
        Id = "c2495b14-ca95-4199-87c3-27cbfefcbe9e"
    },
    PaymentSource = "recurring",
    MerchantInitiated = true,
    IsSubsequentPayment = true,
});
// handle response