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 StripeServer-sideClient-side
Use our official libraries for access to the Stripe API from your application:
Create or retrieve a Customer before setupServer-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.
Create a PaymentIntent or SetupIntentServer-side
Select the scenario below that best fits your use case.
Redirect your customerClient-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.
<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_
you specify.
Monitor webhooksServer-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_
.
Handle reusable payment method revocationServer-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.
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 |
|
OptionalHandle the Klarna redirect manuallyServer-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_
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_
and the next_
type is redirect_
.
{ "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_
property.
OptionalUpgrade a saved payment methodServer-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.
OptionalRemove a saved Klarna accountServer-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.