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
        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 Elements
Payment scenarios
Handle multiple currencies
Custom payment flows
Flexible acquiring
Orchestration
In-person payments
Terminal
Beyond payments
Incorporate your company
Crypto
Financial Connections
Climate
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.
  • Saving Klarna to a wallet to streamline future on-demand purchases without requiring customer re-authentication.

The following select payment options, subscription lengths, and buyer countries support Klarna recurring payments:

Payment optionsSupported use casesSupported buyer countries
Pay in full
  • Short term subscriptions (weekly or monthly)
  • Long term subscriptions (longer than monthly)
  • Mixed cart (one-off purchase and subscription)
  • On-demand payments
AT, BE, CA, CH, DE, DK, ES, FI, FR, IE, IT, GR, NL, NO, PL, PT, SE, UK, US
Pay later
  • Short term subscriptions (weekly or monthly)
  • Long term subscriptions (longer than monthly)
  • On-demand payments
DE, SE, US
Pay in 3 or 4
  • Long term subscriptions (longer than monthly) only
AT, CA, CH, DE, DK, ES, FI, FR, IE, IT, GR, NL, NO, PL, PT, UK, US

Choose your payment integration type below to save Klarna as a payment method. If you use Stripe Billing, see Klarna for subscriptions.

Use Stripe Checkout to collect Klarna payment details in advance, with the final amount or payment date determined later. Use this for:

  • Saving payment methods to a wallet to streamline future purchases.
  • Collecting surcharges after fulfilling a service.
  • Starting a free trial for a subscription.

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
Ruby
# Available as a gem sudo gem install stripe
Gemfile
Ruby
# 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
curl -X POST https://api.stripe.com/v1/customers \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"

Create a Checkout Session
Client-side
Server-side

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

Add a checkout button to your website that calls a server-side endpoint to create a Checkout Session.

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

When using Checkout to set up a subscription, it’s recommended that you pass subscription details. This optimises authorisation rates and ensures your customers have access to all applicable Klarna payment options.

The subscription reference you use isn’t visible to customers and is an arbitrary identifier of your choosing. Use the same reference when charging the saved payment method.

The example below shows how to pass details for an annual subscription. For more information on these fields, see the Klarna subscription payment method options.

Command Line
cURL
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d mode=setup \ -d customer={{CUSTOMER_ID}} \ --data-urlencode success_url="https://example.com/success?session_id={CHECKOUT_SESSION_ID}" \ --data-urlencode cancel_url="https://example.com/cancel" \ -d "payment_method_options[klarna][subscriptions][0][reference]"=EXAMPLE_REFERENCE \ -d "payment_method_options[klarna][subscriptions][0][name]"="Customer-facing name for subscription" \ -d "payment_method_options[klarna][subscriptions][0][interval]"=year \ -d "payment_method_options[klarna][subscriptions][0][next_billing][amount]"=10000 \ -d "payment_method_options[klarna][subscriptions][0][next_billing][date]"=2026-01-01

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 {CHECKOUT_SESSION_ID} template variable in the success_url as in the above example.

When your customer clicks on your logo in a Checkout Session without providing their payment method details, Checkout redirects them back to your website by navigating to the cancel_url. This is usually the page on your website that the customer viewed prior to redirecting to Stripe Checkout.

Caution

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

  • Malicious users could directly access the success_url without paying and gain access to your goods or services.
  • Customers may not always reach the success_url after a successful payment—they might close their browser tab before the redirect occurs.

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, "cancel_url": "https://example.com/cancel", "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’s Klarna account information for future payments. Retrieve the SetupIntent object with the ID.

Command Line
cURL
curl https://api.stripe.com/v1/setup_intents/seti_1EzVO3HssDVaQm2PJjXHmLlM \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"

Handle post-setup events
Server-side

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

When a customer successfully authorises 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 authorise 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

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

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.

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

OptionalRemove a saved Klarna account
Server-side

Was this page helpful?
YesNo
Need help? Contact Support.
Join our early access programme.
Check out our changelog.
Questions? Contact Sales.
LLM? Read llms.txt.
Powered by Markdoc