Accept a Klarna payment
Learn how to accept Klarna, a global buy now, pay later payment method.
Beta
Klarna on the Express Checkout Element is launching a limited beta in mid October. Reach out here to gain access.
Stripe users can use the Payment Intents API—a single integration path for creating payments using any supported method—to accept Klarna payments from customers in Klarna’s supported countries.
Klarna is a single use, immediate notification payment method that requires customers to authenticate their payment. Customers are redirected to a Klarna page, where they select among multiple payment options (immediate full payment, payment in installments, or deferred payment). When the customer accepts the terms, Klarna guarantees that the funds are available to the customer and transfers the funds to your Stripe account. The customer repays Klarna according to their selected payment option.
Note
Before you start the integration, make sure your account is eligible for Klarna by navigating to your Payment methods settings.
Set up StripeServer-side
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
Create a PaymentIntentServer-side
A PaymentIntent is an object that represents your intent to collect payment from a customer and tracks the lifecycle of the payment process through each stage. First, create a PaymentIntent
on your server.
If you already have an integration using the Payment Intents API, add klarna
to the list of payment method types for your PaymentIntent
.
Klarna requires the billing address country to determine which payment options to present to the customer. A billing email is also required. If you pass the optional shipping parameter, ensure these fields are defined and non-empty: name
, email
, address.
, city
, country
, and postal_
.
This integration guide suggests passing the billing details client-side after the customer selects their payment method (step 3).
Retrieve the client secret
The PaymentIntent includes a client secret that the client side uses to securely complete the payment process. You can use different approaches to pass the client secret to the client side.
Submit the payment to StripeClient-side
In this step, you’ll complete Klarna payments on the client with Stripe.js.
Set up Stripe.js
When a customer clicks to pay with Klarna, we recommend using Stripe.js to submit the payment to Stripe. Stripe.js is our foundational JavaScript library for building payment flows. It automatically handles complexities like the redirect described below, and enables you to easily extend your integration to other payment methods in the future. 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/v3/"></script> </head>
Create an instance of Stripe.js with the following JavaScript on your checkout page.
// Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys var stripe = Stripe(
);'pk_test_TYooMQauvdEDq54NiTphI7jx'
Rather than sending the entire PaymentIntent object to the client, use its client secret from step 2. This is different from your API keys that authenticate Stripe API requests.
The client secret should still be handled carefully because it can complete the charge. Don’t log it, embed it in URLs, or expose it to anyone but the customer.
Use stripe.confirmKlarnaPayment to handle the redirect away from your page and to complete the payment. Add a return_url to this function to indicate where Stripe should redirect the user after they complete the payment on the Klarna website or mobile application.
On Klarna’s payments page, the customer selects among the payment options available in their market. See the table on the overview page for availability by market. You can’t limit or pre-select payment options on the Klarna payments page—deferring this choice to the consumer maximizes their opportunity to transact with you.
// Redirects away from the client const {error} = await stripe.confirmKlarnaPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}', { payment_method: { billing_details: { email: 'jenny.rosen@example.com', address: { country: 'DE', }, }, }, return_url: 'https://example.com/checkout/complete', } ); if (error) { // Inform the customer that there was an error. }
When your customer submits a payment, Stripe redirects them to the return_
and includes the following URL query parameters. The return page can use them to get the status of the PaymentIntent so it can display the payment status to the customer.
When you specify the return_
, you can also append your own query parameters for use on the return page.
Parameter | Description |
---|---|
payment_ | The unique identifier for the PaymentIntent . |
payment_ | The client secret of the PaymentIntent object. |
When the customer is redirected back to your site, you can use the payment_
to query for the PaymentIntent and display the transaction status to your customer.
You can find details about the Klarna payment option the customer selected on the charge
in the payment_method_details property. There are four possible values: pay_
, pay_
, pay_
, and pay_
. See our Klarna overview page for more information on these options.
You can also find the locale used to localize Klarna’s payments page under the payment_method_details property.
{ "charges": { "data": [ { "payment_method_details": { "klarna": { "payment_method_category": "pay_in_installments", "preferred_locale": "en-US" }, "type": "klarna" }, "id": "src_16xhynE8WzK49JbAs9M21jaR", "object": "source", "amount": 1099, "client_secret": "src_client_secret_UfwvW2WHpZ0s3QEn9g5x7waU",
Test Klarna integration
Below, we have specially selected test data for the currently supported customer countries. In test mode, Klarna approves or denies a transaction based on the supplied email address.
For production testing, you can use an amount of 3500
in your local currency to test all Klarna payment options besides Financing. For example, if you want to test “Pay in 3” in Italy, you can use a transaction of 35.00 EUR.
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 |
|
Failed payments
Klarna takes into account multiple factors when deciding to accept or decline a transaction (for example, length of time buyer has been using Klarna, outstanding amount customer has to repay, value of the current order).
When the customer selects a deferred payment method, Klarna performs a risk assessment before accepting the transaction. Klarna might decline the transaction due to unsatisfactory risk assessment result, the transaction amount involved, or the customer having a large outstanding debt. As such, we recommend that you present additional payment options such as card
in your checkout flow. In these cases, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions to requires_
.
Customers are expected to complete the payment within 1 hour after they are redirected to the Klarna site. If no action is taken after 1 hour, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions from requires_
to requires_
.
In these cases, inform your customer to try again with a different payment option presented in your checkout flow.
Klarna rate limits
API requests to Klarna are subject to additional rate limits beyond Stripe’s API-wide rate limits. These limits can differ depending on the shape of the API requests that you make. In general, if you make more than around 360 requests per minute, you may see some rate limiting in the form of responses with HTTP status code 400
or 402
. Please contact us for more details if you’re concerned that your usage may reach these levels, as Klarna may be able to increase these limits on a case by case basis.
Error messaging
Failed Klarna payments normally return one of the following failure codes. These codes show in the last_payment_error API object.
Caution
Before the 2023-08-16
API version, every Klarna error reported as payment_intent_authentication_failure. Make sure your API version is up to date to see the detailed errors listed below.
Failure code | Explanation |
---|---|
payment_method_customer_decline | The customer cancelled the checkout on Klarna’s page |
payment_method_provider_decline | Klarna declined the customer’s payment |
payment_intent_payment_attempt_expired | The customer never completed the checkout on Klarna’s page, and the payment session has expired |
payment_method_not_available | An unexpected error occurred when trying to use Klarna |