RyzeDeskRyzeDesk

Stripe

4105 articles

Set up a subscription with Klarna


Set up a subscription with Klarna

Learn how to create and charge for a subscription with Klarna.

Use this guide to set up a subscription using Klarna as a payment method.

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.

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 a product and price Dashboard

Products represent the item or service you’re selling. Prices define how much and how frequently you charge for a product. This includes how much the product costs, what currency you accept, and whether it’s a one-off or recurring charge. If you only have a few products and prices, create and manage them in the Dashboard.

This guide uses a stock photo service as an example and charges customers a 15 USD monthly subscription. To model this:

  1. Go to the Products page and click Create product .
  2. Enter a Name for the product. You can optionally add a Description and upload an image of the product.
  3. Select a Product tax code . Learn more about product tax codes .
  4. Select Recurring . Then enter 15 for the price and select USD as the currency.
  5. Choose whether to Include tax in price . You can either use the default value from your tax settings or set the value manually. In this example, select Auto .
  6. Select Monthly for the Billing period .
  7. Click More pricing options . Then select Flat rate as the pricing model for this example. Learn more about flat rate and other pricing models .
  8. Add an internal Price description and Lookup key to organise, query and update specific prices in the future.
  9. Click Next . Then click Add product .

After you create the product and the price, record the price ID so you can use it in subsequent steps. The pricing page displays the ID and it looks similar to this: price_G0FvDp6vZvdwRZ.

Create a Checkout Session Client-side Server-side

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>

Create a Checkout Session with the ID of an existing Price. Set the mode to subscription and pass at least one recurring price. You can add one-off prices in addition to recurring prices. After creating the Checkout Session, redirect your customer to the URL returned in the response.

Command Line

Select a language

cURL

Stripe CLI

Ruby

Python

PHP

Java

Node.js

Go

.NET

No results

When your customer successfully completes their payment, Stripe redirects them to the success_url, a page on your website that informs the customer that their payment was successful. 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.

Checkout Sessions expire 24 hours after creation.

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 .

Set up a trial

You can create free trials in a Checkout Session by using the subscription_data parameter to provide information about the length, end date, and other trial settings.

Learn how to configure free trials to cancel or pause when they end without a payment method.

Retrieve the subscription Server-side

After a customer submits their payment details, Stripe automatically creates a Subscription. You can retrieve the Subscription synchronously using the success_url or asynchronously using webhooks.

The decision to retrieve the subscription synchronously or asynchronously depends on your tolerance for drop-off because 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 encountering this form of drop-off.

Handle checkout.session.completed webhooks, which contain a Session object. Learn how to set 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_a1h2mO4eLbjemY0JWW9rCz5dcglwr3M5ldjLOvpGxWD37i1Oi5SeFhSup1",
 "object": "checkout.session",
 "billing_address_collection": null,
 "client_reference_id": null,
 "customer": null,
 "customer_email": null,
 "display_items": [],
 "mode": "setup",
 "subscription": "sub_1Op9VFCvDOElLqwO6fs7Na4P",
 "submit_type": null,
 "success_url": "https://example.com/success"
 }
 },
 "livemode": false,
 "pending_webhooks": 1,
 "request": {
 "id": null,
 "idempotency_key": null
 },
 "type": "checkout.session.completed"
}

Keep a record of the value of the subscription key, which is the ID for the Subscription created from the Checkout Session.

Test your integration

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
Last verified 2026-09-27

Is this helpful?