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 tools
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
        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
Custom payment flows
Flexible acquiring
Orchestration
In-person payments
Terminal
Other Stripe products
Financial Connections
Crypto
Climate
HomePaymentsAdd payment methodsBuy now, pay laterKlarna

Accept a Klarna payment

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

Copy page

Unified line items with Klarna

To optimise 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.

When a customer accepts Klarna in your app, a webview for a customer to authenticate their payment appears. The customer then returns to your app, and you can immediately confirm whether the payment succeeded or failed.

Note

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

Set up Stripe
Server-side
Client-side

First, you need a Stripe account. Register now.

Server-side

This integration requires endpoints on your server that talk to the Stripe API. Use the official libraries for access to the Stripe API from your server:

Command Line
Ruby
# Available as a gem sudo gem install stripe
Gemfile
Ruby
# If you use bundler, you can add this line to your Gemfile gem 'stripe'

Client-side

The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above.

To install the SDK, follow these steps:

  1. In Xcode, select File > Add Package Dependencies… and enter https://github.com/stripe/stripe-ios-spm as the repository URL.
  2. Select the latest version number from our releases page.
  3. Add the StripePaymentsUI product to the target of your app.

Note

For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.

Configure the SDK with your Stripe publishable key on app start. This enables your app to make requests to the Stripe API.

AppDelegate.swift
Swift
import UIKit import StripePaymentsUI @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { StripeAPI.defaultPublishableKey =
"pk_test_TYooMQauvdEDq54NiTphI7jx"
// do any other necessary launch configuration return true } }

Note

Use your test keys while you test and develop, and your live mode keys when you publish your app.

Create a PaymentIntent
Server-side
Client-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.

Server-side

First, create a PaymentIntent on your server and specify the amount to collect and the currency. If you already have an integration using the Payment Intents API, add klarna to the list of payment method types for your PaymentIntent.

Command Line
cURL
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d "payment_method_types[]"=klarna \ -d amount=1099 \ -d currency=eur

Client-side

Included in the returned PaymentIntent is a client secret, that the client side can use to securely complete the payment process instead of passing the entire PaymentIntent object. On the client, request a PaymentIntent from your server and store its client secret.

Swift
import UIKit import StripePaymentsUI class CheckoutViewController: UIViewController { var paymentIntentClientSecret: String? func startCheckout() { // Request a PaymentIntent from your server and store its client secret } }}

Submit the payment to Stripe
Client-side

Retrieve the client secret from the PaymentIntent you created in step 2 and call the STPPaymentHandler confirmPayment: method. This presents a webview where the customer can complete the payment, which initiates a call to the completion block with the result of the payment.

Swift
let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret) paymentIntentParams.paymentMethodParams = klarnaParams paymentIntentParams.shipping = shippingDetails STPPaymentHandler.shared().confirmPayment(paymentIntentParams, with: self) { (handlerStatus, paymentIntent, error) in switch handlerStatus { case .succeeded: // Payment succeeded case .canceled: // Payment was canceled case .failed: // Payment failed @unknown default: fatalError() } }

Test Klarna 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.

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

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

OptionalSeparate authorization and capture

OptionalHandle post-payment events

OptionalCustomize the Klarna payment page

OptionalAdd line items to the PaymentIntent

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
Was this page helpful?
YesNo
Need help? Contact Support.
Join our early access programme.
Check out our changelog.
Questions? Contact Sales.
LLM? Read llms.txt.
Powered by Markdoc