Stripe | Financial Infrastructure to Grow Your Revenue

Stripe | Financial Infrastructure to Grow Your Revenue

4466 articles

Set up future Klarna payments


Set up future Klarna payments

Learn how to save Klarna details and charge your customers later.

You can save Klarna as a customer’s payment method and charge future payments to support:

  • Automatic payment for subscriptions , with or without a free trial .
  • Automatic payment for subscriptions for orders that also include non-subscription products.
  • Saving Klarna to a wallet to streamline future on-demand purchases without requiring customer re-authentication.

This guide explains how to save Klarna as a payment method that you can charge immediately or later. This guide isn’t for integrations that use Stripe Billing. If you use Stripe Billing, see Klarna for subscriptions.

Available Klarna payment options vary by use case and customer country

See which payment options are available for your customers before you start your integration.

We recommend using Stripe Checkout to save Klarna as a payment method.

Checkout

Direct API

Mobile

The first part of this guide explains how to use Stripe Checkout to save Klarna as a payment method. The last step explains how to charge the saved payment method for a subscription or on-demand payment.

Set up Stripe Server-side

First, you need a Stripe account. Register now.

Use our official libraries for access to the Stripe API from your application:

Command Line

Select a language

Ruby

Python

PHP

Java

Node.js

Go

.NET

No results

# Available as a gem
sudo gem install stripe

Gemfile

Select a language

Ruby

Python

PHP

Java

Node.js

Go

.NET

No results

# If you use bundler, you can add this line to your Gemfile
gem 'stripe'

Create or retrieve a Customer before setup Server-side

To reuse a Klarna payment method for future payments, you must attach it to a Customer.

Create a Customer object when your customer creates an account on your business. Associating the ID of the Customer object with your own internal representation of a customer enables you to retrieve and use the stored payment method details later. If your customer hasn’t created an account, you can still create a Customer object now and associate it with your internal representation of the customer’s account later.

Command Line

Select a language

cURL

Stripe CLI

Ruby

Python

PHP

Java

Node.js

Go

.NET

No results

Create a Checkout Session Client-side Server-side

Before you can accept Klarna payments, your customer must authorize you to use their Klarna account for future payments through Stripe Checkout.

Add an Authorize button to your site that calls a server-side endpoint to create a Checkout Session.

index.html

<html>
 <head>
 <title>Authorize</title>
 </head>
 <body>
 <form action="/create-checkout-session" method="POST">
 <button type="submit">Authorize</button>
 </form>
 </body>
</html>

You should pass subscription details when you use Checkout to set up a subscription.

Passing in subscription details:

  • Ensures your customers have access to all applicable Klarna payment options , including Pay in 3 or 4, which is only available for subscriptions that have specific lengths.
  • Reduces support rates and customer dropouts due to unclear purchase details in the Klarna app, where Klarna renders subscription data for your customers.

Use the payment_method_options parameter to pass in subscription details. The subscription reference is an arbitrary identifier you choose that isn’t visible to customers (for example, the related setting or the related setting).

Use the same reference to charge the saved payment method

When you charge the saved payment method, use the same subscription reference. The reference value needs to match the value of the amount_details[line_items][payment_method_options][klarna][subscription_reference] field, if you integration uses it later. If you don’t match the value, you receive an error.

The example below shows how to pass details for an annual subscription.

Command Line

Select a language

cURL

Stripe CLI

Ruby

Python

PHP

Java

Node.js

Go

.NET

No results

After creating the Checkout Session, redirect your customer to the URL returned in the response.

Handle redirect back from Checkout Client-side Server-side

When your customer provides their payment method details, they’re redirected to the success_url, a page on your website that informs them that they saved their payment method successfully. Make the Session ID available on your success page by including the {the related setting} template variable in the success_url as in the above example.

Caution

Don’t rely on the redirect to the success_url alone for detecting payment initiation, because:

  • Malicious users could directly access the success _ url without paying and gain access to your goods or services.
  • After a successful payment, customers might close their browser tab before they’re redirected to the success _ url .

Retrieve the payment method Server-side

After a customer submits their payment details, retrieve the PaymentMethod object. A PaymentMethod stores the customer’s Klarna account information for future payments. You can retrieve the PaymentMethod synchronously using the success_url or asynchronously using webhooks.

The decision to retrieve the PaymentMethod synchronously or asynchronously depends on your tolerance for dropoff, as customers might not always reach the success_url after a successful payment (for example, it’s possible for them to close their browser tab before the redirect occurs). Using webhooks prevents your integration from experiencing this form of dropoff.

Handle checkout.session.completed webhooks, which contain a Session object. To learn more, see setting up webhooks. The following example is a checkout.session.completed response.

{
 "id": "evt_1Ep24XHssDVaQm2PpwS19Yt0",
 "object": "event",
 "api_version": "2019-03-14",
 "created": 1561420781,
 "data": {
 "object": {
 "id": "cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k",
 "object": "checkout.session",
 "billing_address_collection": null,
 "client_reference_id": null,
 "customer": null,
 "customer_email": null,
 "display_items": [],
 "mode": "setup",
 "setup_intent": "seti_1EzVO3HssDVaQm2PJjXHmLlM",
 "submit_type": null,
 "subscription": null,
 "success_url": "https://example.com/success"
 }
 },
 "livemode": false,
 "pending_webhooks": 1,
 "request": {
 "id": null,
 "idempotency_key": null
 },
 "type": "checkout.session.completed"
}

Note the value of the setup_intent key, which is the ID for the SetupIntent created with the Checkout Session. A SetupIntent is an object used to set up the customer Klarna account information for future payments. Retrieve the SetupIntent object with the ID. The returned object contains the payment_method ID.

Command Line

Select a language

cURL

Stripe CLI

Ruby

Python

PHP

Java

Node.js

Go

.NET

No results

Handle post-setup events Server-side

Use a method such as webhooks to confirm that the customer authorized the billing agreement. Don’t rely on your customer to return to the payment status page.

When a customer successfully authorizes the billing agreement, Stripe emits a payment_intent.succeeded or setup_intent.succeeded webhook event and the Intent status transitions to succeeded. Store the resulting payment_method ID to make payments using the saved PaymentMethod later.

If a customer doesn’t successfully authorize the billing agreement, Stripe emits a payment_intent.payment_failed or setup_intent.setup_failed webhook event and the Intent status returns to requires_payment_method.

Use the payment method for future payments Server-side

Handle GBP step-up authentication

Because of UK Consumer Credit Act reforms starting July 15, 2026, Klarna handles GBP tokenized payments differently, depending on whether the customer is present in the flow.

For GBP on-session transactions, Klarna requires step-up authentication for tokenized payments. Make sure the customer is present in the flow so you can redirect them to authorize the payment.

If step-up authentication is required, follow the Direct API instructions to redirect your customer for the saved payment method charge.

If the customer doesn’t successfully authorize the billing agreement, Stripe emits a payment_intent.payment_failed or setup_intent.setup_failed webhook event and the Intent status returns to requires_payment_method. As with all webhooks, verify the event signature before acting on the event. You can also allow access from the Stripe public IP addresses.

For GBP off-session transactions, Klarna automatically converts previously set up tokens to Pay in full.

When you’re ready to charge your customer off-session, use the Customer and PaymentMethod IDs to create a PaymentIntent. Set a few other parameters to make the off-session payment:

  • Set off_session to true to indicate that the customer isn’t in your checkout flow during this payment attempt, which causes the PaymentIntent to throw an error if authentication is required.
  • Set the value of the PaymentIntent’s confirm property to true , which causes confirmation to occur immediately when the PaymentIntent is created.
  • Set payment_method to the ID of the PaymentMethod and customer to the ID of the Customer.
  • Specify a return_url to indicate where Stripe needs to redirect the customer after they return from Klarna’s website.

Send subscription details and line items with each renewal. Use the same reference for your subscription as you did when setting up the payment method. If the subscription details have changed since you saved the payment method, send the new information with the same reference.

Command Line

Select a language

cURL

Stripe CLI

Ruby

Python

PHP

Java

Node.js

Go

.NET

No results

Handle reusable payment method revocation Server-side

You can revoke a reusable payment method in two ways:

  • A customer can deactivate a reusable payment method in the Klarna mobile application. In this case, Stripe sends you a mandate.updated event. To handle this, subscribe to webhook events, and call detach PaymentMethod to deactivate it.
  • A customer can also deactivate a reusable payment method on your UI, if supported. In this scenario, your server can call detach PaymentMethod to handle the deactivation.

In both cases, after you call detach PaymentMethod, Stripe sends you a payment_method.detached event.

Test your integration

When testing your Checkout integration, select Klarna as the payment method and click the Save button. In a testing environment, you can then simulate different outcomes within Klarna’s redirect.

Note

Klarna uses cookies for session tracking. To test different customer locations, log out of the Klarna sandbox from the previous session and use the relevant triggers.

Below, we have specially selected test data for the currently supported customer countries. In a sandbox, Klarna approves or denies a transaction based on the supplied email address.

ApprovedDenied
Date of Birth10-07-197003-05-1994
First NameTestJohn
Last NamePerson-ausnow
StreetWharf StSilverwater Rd
House number41-5
Postal Code48772128
CityPort DouglasSilverwater
RegionQLDNSW
Phone+61473752244+61473763254
Email

Two-step authentication

Any six digit number is a valid two-step authentication code. Use 999999 for authentication to fail.

Repayment method

Inside the Klarna flow, you can use the following test values to try various repayment types:

TypeValue
Direct Debitthe related setting
Bank transferDemo Bank
Credit CardNumber: 4111 1111 1111 1111 CVV: 123 Expiration: any valid date in the future
Debit CardNumber: 4012 8888 8888 1881 CVV: 123 Expiration: any valid date in the future

Optional Upgrade a saved payment method Server-side

Optional Remove a saved Klarna account Server-side

Last verified 2026-09-24

Is this helpful?