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.
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
Create a product and priceDashboard
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-time 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:
- Navigate to the Add a product page.
- Enter a Name for the product.
- Enter 15 for the price.
- Select USD as the currency.
- Click Save 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_
.
Create a Checkout SessionClient-sideServer-side
Add a checkout button to your website that calls a server-side endpoint to create a Checkout Session.
<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-time prices in addition to recurring prices. After creating the Checkout Session, redirect your customer to the URL returned in the response.
When your customer successfully completes their payment, Stripe redirects them to the success_
, 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 {CHECKOUT_
template variable in the success_
as in the above example.
When your customer clicks your logo in a Checkout Session without completing a payment, Checkout redirects them back to your website by navigating to the cancel_
. Typically, this is the page on your website that the customer viewed prior to redirecting to Checkout.
Checkout Sessions expire 24 hours after creation.
Caution
Don’t rely on the redirect to the success_
alone for detecting payment initiation, as:
- Malicious users could directly access the
success_
without paying and gain access to your goods or services.url - Customers may not always reach the
success_
after a successful payment—they might close their browser tab before the redirect occurs.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 subscriptionServer-side
After a customer submits their payment details, Stripe automatically creates a Subscription}. You can retrieve the Subscription synchronously using the success_
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_
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.
Test your integration
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.
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:
Type | Value |
---|---|
Direct Debit | DE11520513735120710131 |
Bank transfer | Demo Bank |
Credit Card |
|
Debit Card |
|