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
        Optimize conversion
        Comply with Klarna rules
        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
Understand fraud
Radar fraud protection
Manage disputes
Verify identities
HomePaymentsAdd payment methodsBuy now, pay laterKlarna

Accept a Klarna payment

Learn how to accept Klarna, a global buy now, pay later payment method.

To build an advanced integration that handles complex payment flows and accepts Klarna payments, you can use Stripe Elements, such as the Payment Element and the Express Checkout Element. The Payment Element accepts 40+ payment methods, validates input, and handles errors. The Express Checkout Element provides one-click payment methods buttons for Klarna and other payment methods.

Follow the quickstart to learn how to embed a custom Stripe payment form in your website.

This guide explains the recommended steps for handling Klarna payments in an integration that uses Elements and the Payment Intents API.

Note

Before you start the integration, make sure your account is eligible for Klarna by reviewing your Payment methods settings.

Manually listing payment methods

We recommend using dynamic payment methods, where Stripe handles the logic for dynamically displaying the most relevant eligible payment methods to each customer to maximize conversion. If you choose to manually list payment methods, specify klarna in the payment_method_types list when you create a PaymentIntent.

Create a PaymentIntent

To help maximize acceptance rates and reduce disputes, pass in the following parameters when you create a PaymentIntent for Klarna payments:

  • shipping: Ensure that these fields are defined and not empty: name, address.line1, city, country, and postal_code.
  • line_items
  • billing_details: Ensure these fields are defined and not empty: name, address.line1, city, country, and postal_code.
Command Line
cURL
No results
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d "payment_method_types[]"=klarna \ -d amount=1099 \ -d currency=eur \ -d "shipping[address][city]"=Brothers \ -d "shipping[address][country]"=US \ -d "shipping[address][line1]"="27 Fredrick Ave" \ -d "shipping[address][postal_code]"=97712 \ -d "shipping[address][state]"=OR \ -d "shipping[line_items][object]"=list \ -d "shipping[billing_details][address][city]"=Brothers \ -d "shipping[billing_details][address][country]"=US \ -d "shipping[billing_details][address][line1]"="27 Fredrick Ave" \ -d "shipping[billing_details][address][postal_code]"=97712 \ -d "shipping[billing_details][address][state]"=OR \ --data-urlencode "shipping[billing_details][email]"="jenny.rosen@example.com" \ -d "shipping[billing_details][name]"="Jenny Rosen"

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.

Retrieve the client secret from an endpoint on your server, using the browser’s fetch function. This approach is best if your client side is a single-page application, particularly one built with a modern frontend framework like React. Create the server endpoint that serves the client secret:

main.rb
Ruby
Python
PHP
Java
Node
Go
.NET
No results
get '/secret' do intent = # ... Create or retrieve the PaymentIntent {client_secret: intent.client_secret}.to_json end

And then fetch the client secret with JavaScript on the client side:

(async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })();

Submit the payment to Stripe

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.

checkout.html
<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.

script.js
// 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. (This is different from your API keys that authenticate Stripe API requests.)

Make sure that you handle the client secret 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.

client.js
// Redirects away from the client const {error} = await stripe.confirmKlarnaPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}',{ 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_url 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_url, you can also append your own query parameters for use on the return page.

ParameterDescription
payment_intentThe unique identifier for the PaymentIntent.
payment_intent_client_secretThe client secret of the PaymentIntent object. For subscription integrations, this client_secret is also exposed on the Invoice object through confirmation_secret

When the customer is redirected back to your site, you can use the payment_intent_client_secret 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_later, pay_with_financing, pay_now, and pay_in_installments. 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 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. Klarna also provides sample data.

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

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:

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

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

Customers are expected to complete the payment within 48 hours after they’re redirected to the Klarna site. If no action is taken after 48 hours, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions from requires_action to requires_payment_method.

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 codeExplanation
payment_method_customer_declineThe customer cancelled the checkout on Klarna’s page
payment_method_provider_declineKlarna declined the customer’s payment
payment_intent_payment_attempt_expiredThe customer never completed the checkout on Klarna’s page, and the payment session has expired
payment_method_not_availableAn unexpected error occurred when trying to use Klarna

Optional customizations

You can optionally implement several different customizations for Klarna payment flows (such as separating the authorization and capture of funds) and customer interactions (such as handling redirects).

Separate authorization and capture

Klarna supports separate authorization and capture. If there’s a delay between the payment and delivering the goods to your customer, authorize the payment first and capture it later. At the point of capture, Klarna sends a statement to the customer and initiates the due dates on any subsequent payments that they must make. An authorized Klarna payment must be captured within 28 days of the authorization. Otherwise, the authorization automatically cancels and you can no longer capture the payment.

  1. Tell Stripe to authorize only

    To indicate that you want separate authorization and capture, set capture_method to manual when creating the PaymentIntent. This parameter instructs Stripe to only authorize the amount on the customer’s Klarna account.

    Command Line
    cURL
    Stripe CLI
    Ruby
    Python
    PHP
    Java
    Node
    Go
    .NET
    No results
    curl https://api.stripe.com/v1/payment_intents \ -u "
    sk_test_BQokikJOvBiI2HlWgH4olfQ2
    :"
    \ -d "payment_method_types[]"=klarna \ -d amount=1099 \ -d currency=eur \ -d capture_method=manual
  2. Capture the funds

    After the authorization succeeds, the PaymentIntent status transitions to requires_capture. To capture the authorized funds, make a PaymentIntent capture request. The total authorized amount is captured by default—you can’t capture more than this, but you can capture less.

    Command Line
    cURL
    Stripe CLI
    Ruby
    Python
    PHP
    Java
    Node
    Go
    .NET
    No results
    curl https://api.stripe.com/v1/payment_intents/
    {{PAYMENT_INTENT_ID}}
    /capture
    \ -u "
    sk_test_BQokikJOvBiI2HlWgH4olfQ2
    :"
    \ -d amount_to_capture=750
  3. Optional Cancel the authorization

    Klarna counts any authorized payments against the customer’s total purchasing power within Klarna. Make sure that you actively cancel any authorized payments that you can’t fulfill (for example, the goods can’t be shipped) as soon as this becomes apparent.

    Command Line
    cURL
    Stripe CLI
    Ruby
    Python
    PHP
    Java
    Node
    Go
    .NET
    No results
    curl https://api.stripe.com/v1/payment_intents/
    {{PAYMENT_INTENT_ID}}
    /cancel
    \ -u "
    sk_test_BQokikJOvBiI2HlWgH4olfQ2
    :"
    \ -d cancellation_reason=abandoned

Handle the Klarna redirect manually

We recommend relying on Stripe.js to handle Klarna redirects and payments client-side with confirmKlarnaPayment. Using Stripe.js helps extend your integration to other payment methods. However, you can also manually redirect your customers on your server by following these steps:

  1. Create and confirm a PaymentIntent of type klarna. You must provide the post-payment redirect URL for your customer in the return_url field. You can provide your own query parameters in this URL, and the redirect flow’s final URL will include them.

    Command Line
    cURL
    Stripe CLI
    Ruby
    Python
    PHP
    Java
    Node
    Go
    .NET
    No results
    curl https://api.stripe.com/v1/payment_intents \ -u "
    sk_test_BQokikJOvBiI2HlWgH4olfQ2
    :"
    \ -d "payment_method_types[]"=klarna \ -d amount=1099 \ -d currency=eur \ -d confirm=true \ --data-urlencode return_url="https://example.com/checkout/complete" \ -d "payment_method_data[type]"=klarna
  2. The created PaymentIntent has a status of requires_action and the type for next_action is redirect_to_url.

    { "status": "requires_action", "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } }, "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", "amount": 1099,
  3. Redirect the customer to the URL provided in the next_action.redirect_to_url.url property. The code example here is approximate—the redirect method may be different in your web framework.

    Ruby
    Python
    PHP
    Java
    Node
    Go
    .NET
    No results
    if payment_intent.status == 'requires_action' && payment_intent.next_action.type == 'redirect_to_url' url = payment_intent.next_action.redirect_to_url.url redirect(url) end

When the customer finishes the payment process, they’re sent to the return_url configured in step 1. The payment_intent and payment_intent_client_secret URL query parameters are included. If return_url already included query parameters, they’re preserved too.

We recommend that you rely on webhooks to confirm the status of a payment.

Handle post-payment events

Stripe sends a payment_intent.succeeded event when the payment completes. Use the Dashboard, a custom webhook, or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.

Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also helps you accept more payment methods in the future. Learn about the differences between all supported payment methods.

  • Handle events manually in the Dashboard

    Use the Dashboard to View your test payments in the Dashboard, send email receipts, handle payouts, or retry failed payments.

  • Build a custom webhook

    Build a custom webhook handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI.

  • Integrate a prebuilt app

    Handle common business events, such as automation or marketing and sales, by integrating a partner application.

Customize the Klarna payment page

  • Prefill the Klarna form

    When the customer chooses to pay Klarna with a deferred payment option (pay later, installments, and financing), Klarna collects enough information for risk assessment and approval. The type of information depends on the country of the customer. For most countries in Europe, it’s the full billing details and date of birth. You can pass this information through the API, and the form will be prefilled when your customer arrives on the page.

    Command Line
    cURL
    Stripe CLI
    Ruby
    Python
    PHP
    Java
    Node
    Go
    .NET
    No results
    curl https://api.stripe.com/v1/payment_intents \ -u "
    sk_test_BQokikJOvBiI2HlWgH4olfQ2
    :"
    \ -d "payment_method_types[]"=klarna \ -d amount=1099 \ -d currency=eur \ -d confirm=true \ --data-urlencode return_url="https://example.com/checkout/complete" \ -d "payment_method_data[type]"=klarna \ --data-urlencode "payment_method_data[billing_details][email]"="customer@example.com" \ -d "payment_method_data[billing_details][name]"="Jenny Rosen" \ --data-urlencode "payment_method_data[billing_details][phone]"="+4915142321555" \ -d "payment_method_data[billing_details][address][line1]"="Alexanderplatz 1" \ -d "payment_method_data[billing_details][address][city]"=Berlin \ -d "payment_method_data[billing_details][address][postal_code]"=10551 \ -d "payment_method_data[billing_details][address][country]"=DE \ -d "payment_method_data[klarna][dob][day]"=10 \ -d "payment_method_data[klarna][dob][month]"=10 \ -d "payment_method_data[klarna][dob][year]"=1990
    Screenshot of a Klarna payment page prefilled with billing details from the API and customized to render in English

    A Klarna payment page prefilled with billing details from the API and customized to render in English for a customer in Germany

Add line items to the PaymentIntent

Unified line items with Klarna

To optimize approval rates when you integrate with Klarna, include line_items data to represent what’s in a shopper’s cart. For early access, see Payments line items.

Display payment method messaging on your website

The Payment Method Messaging Element is an embeddable UI component that helps your customers know which buy now, pay later payment options they have at checkout directly from your product, cart, or payment pages.

To add the Payment Method Messaging Element to your website, see Display payment method messaging.

Prince of Persia book
The Making of Prince of Persia: Journals 1985-1993
Jordan Mechner
$99.00
Was this page helpful?
YesNo
  • Need help? Contact Support.
  • Join our early access program.
  • Check out our changelog.
  • Questions? Contact Sales.
  • LLM? Read llms.txt.
  • Powered by Markdoc