Skip to content
Create account
or
Sign in
The Stripe Docs logo
/
Ask AI
Create account
Sign in
Get started
Payments
Revenue
Platforms and marketplaces
Money management
Developer resources
Overview
About Stripe payments
Upgrade your integration
Payments analytics
Online payments
OverviewFind your use caseManaged Payments
Use Payment Links
Build a checkout page
Build an advanced integration
Build an in-app integration
Payment methods
Add payment methods
    Overview
    Payment method integration options
    Manage default payment methods in the Dashboard
    Payment method types
    Cards
    Pay with Stripe balance
    Crypto
    Bank debits
    Bank redirects
    Bank transfers
    Credit transfers (Sources)
    Buy now, pay later
      Affirm
      Afterpay / Clearpay
      Alma
      Billie
      Capchase Pay
      Klarna
        Accept a payment
        Set up future payments
        Optimize conversion
        Comply with Klarna rules
        Respond to disputes
      Kriya
      Mondu
      Payment on Invoice
      Scalapay
      SeQura
      Sunbit
      Zip
    Real-time payments
    Vouchers
    Wallets
    Enable local payment methods by country
    Custom payment methods
Manage payment methods
Faster checkout with Link
Payment interfaces
Payment Links
Checkout
Web Elements
In-app Payments
Payment scenarios
Handle multiple currencies
Custom payment flows
Flexible acquiring
Orchestration
In-person payments
Terminal
Beyond payments
Incorporate your company
Crypto
Financial Connections
Climate
Understand fraud
Radar fraud protection
Manage disputes
Verify identities
HomePaymentsAdd payment methodsBuy now, pay laterKlarna

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 buyer 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.

If you want to create a customized payments UI with the Payment Element, use the Payment Intents API with setup_future_usage or the Setup Intents API to save Klarna payment method details.

Set up Stripe
Server-side
Client-side

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

Command Line
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
# Available as a gem sudo gem install stripe
Gemfile
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
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl -X POST https://api.stripe.com/v1/customers \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"

Create a PaymentIntent or SetupIntent
Server-side

Select the scenario below that best fits your use case.

If you’re setting up a subscription and charging the initial payment, use the Payment Intents API with setup_future_usage. You should pass subscription details when you set up the 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, GYM_ANNUAL_MEMBERSHIP or ID_123).

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
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d amount=5000 \ -d currency=usd \ -d customer={{CUSTOMER_ID}} \ -d setup_future_usage=off_session \ -d "amount_details[line_items][0][product_name]"="Annual subscription" \ -d "amount_details[line_items][0][quantity]"=1 \ -d "amount_details[line_items][0][unit_cost]"=5000 \ -d "amount_details[line_items][0][payment_method_options][klarna][subscription_reference]"=EXAMPLE_REFERENCE \ -d "payment_method_options[klarna][subscriptions][0][reference]"=EXAMPLE_REFERENCE \ -d "payment_method_options[klarna][subscriptions][0][interval]"=year

The resulting PaymentIntent contains a client_secret. Pass the secret to the client side to redirect your buyer to Klarna and authorize the saved payment method.

Redirect your customer
Client-side

When a customer attempts to set up their Klarna account for future payments, use Stripe.js to confirm the PaymentIntent or SetupIntent. Stripe.js is our foundational JavaScript library for building payment flows. It automatically handles functions such as the redirect described below, and enables you to extend your integration to other payment methods in the future.

Set up Stripe.js

Include the Stripe.js script on your checkout page by adding it to the head of your HTML file.

checkout.html
<head> <title>Checkout</title> <script src="https://js.stripe.com/basil/stripe.js"></script> </head>

Create an instance of Stripe.js with the following JavaScript on your checkout page.

import {loadStripe} from '@stripe/stripe-js'; const stripe = await loadStripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
);

To confirm the setup on the client side, pass the client secret of the PaymentIntent or SetupIntent object that you created in step 3.

The client secret is different from your API keys that authenticate Stripe API requests. Handle it carefully because it can complete the charge. Don’t log it, embed it in URLs, or expose it to anyone but the customer.

Confirm and redirect

Stripe.js automatically redirects your customer to Klarna when you confirm the PaymentIntent or SetupIntent. After the customer completes the process, Klarna redirects them back to the return_url you specify.

Pass the client_secret you received when creating your PaymentIntent in step 3. The client secret is different from your API keys that authenticate Stripe API requests. Handle it carefully, because it can complete the payment. Don’t log it, embed it in URLs, or expose it to anyone but the customer.

client.js
// Redirects away from the client const {error} = await stripe.confirmKlarnaPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}', { payment_method: { billing_details: { email: 'jenny@example.com', address: { country: 'DE', }, }, }, return_url: 'https://example.com/setup/complete', } ); if (error) { // Inform the customer that there was an error. }

Monitor webhooks
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.

Charge a saved Klarna payment method
Server-side

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
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d amount=5000 \ -d currency=usd \ -d confirm=true \ -d customer={{CUSTOMER_ID}} \ -d payment_method={{PAYMENT_METHOD_ID}} \ -d off_session=true \ --data-urlencode return_url="https://example.com/setup/complete" \ -d "amount_details[line_items][0][product_name]"="Annual subscription renewal" \ -d "amount_details[line_items][0][quantity]"=1 \ -d "amount_details[line_items][0][unit_cost]"=5000 \ -d "amount_details[line_items][0][payment_method_options][klarna][subscription_reference]"=EXAMPLE_REFERENCE \ -d "payment_method_options[klarna][subscriptions][0][reference]"=EXAMPLE_REFERENCE \ -d "payment_method_options[klarna][subscriptions][0][interval]"=year

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 integration in a testing environment, you can simulate different outcomes within Klarna’s redirect.

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
Emailcustomer@email.aucustomer+denied@email.au

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 DebitDE11520513735120710131
Bank transferDemo Bank
Credit Card
  • Number: 4111 1111 1111 1111
  • CVV: 123
  • Expiration: any valid date in the future
Debit Card
  • Number: 4012 8888 8888 1881
  • CVV: 123
  • Expiration: any valid date in the future

OptionalHandle the Klarna redirect manually
Server-side

We recommend relying on Stripe.js to handle Klarna redirects and billing authorizations on the client. Using the native SDK allows you to extend your integration to other payment methods. However, you can manually redirect your customers on your server using the following steps.

Confirm the PaymentIntent or SetupIntent at creation time by including confirm: true. Provide a return_url to indicate where Stripe needs to redirect the user after they complete the setup on Klarna’s website or mobile application.

The Intent status is requires_action and the next_action type is redirect_to_url.

{ "id": "seti_1IQ9hjJJahOk1vSNevPWnhEN", "object": "setup_intent", "status": "requires_action", "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/setup/complete" } }, "application": null,

Redirect the customer to the URL provided in the next_action.redirect_to_url.url property.

OptionalUpgrade a saved payment method
Server-side

Bringing the customer through the Klarna payment flow again if they upgrade their subscription. This ensures Klarna has the most accurate subscription information and optimizes authorization rates.

Create a PaymentIntent with the same structure as when you charge a saved payment method and include setup_future_usage to indicate that you want to upgrade the existing payment method. Pass the new subscription information and use the same reference as when you first saved the payment method.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d amount=10000 \ -d currency=usd \ -d customer={{CUSTOMER_ID}} \ -d payment_method={{PAYMENT_METHOD_ID}} \ -d setup_future_usage=off_session \ --data-urlencode return_url="https://example.com/setup/complete" \ -d "amount_details[line_items][0][product_name]"="Annual subscription renewal" \ -d "amount_details[line_items][0][quantity]"=1 \ -d "amount_details[line_items][0][unit_cost]"=10000 \ -d "amount_details[line_items][0][payment_method_options][klarna][subscription_reference]"=EXAMPLE_REFERENCE \ -d "payment_method_options[klarna][subscriptions][0][reference]"=EXAMPLE_REFERENCE \ -d "payment_method_options[klarna][subscriptions][0][interval]"=year

The resulting PaymentIntent requires a redirect to Klarna to be completed. Learn how to handle the redirect.

OptionalRemove a saved Klarna account
Server-side

You can use the detach API to remove a customer’s saved Klarna account as a payment method. Remove a Klarna account when you know it won’t be used again, such as when the customer cancels their subscription.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl -X POST https://api.stripe.com/v1/payment_methods/{{PAYMENT_METHOD_ID}}/detach \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
Was this page helpful?
YesNo
  • Need help? Contact Support.
  • Join our early access program.
  • Check out our changelog.
  • Questions? Contact Sales.
  • LLM? Read llms.txt.
  • Powered by Markdoc