Adding Klarna payments to your application is as easy as adding a view and performing the payment operations on it.
Klarna’s Mobile SDK is the official toolkit for integrating Klarna products into native iOS apps. It enables you to offer Klarna’s payment methods with a seamless in-app user experience. The SDK is designed to provide the optimal integration and, under the hood, the SDK handles web-based flows in a mobile-friendly way to reduce friction and ensures that all the features listed below are fully supported for a superior customer experience across all mobile platforms.
Feature support with Klarna’s Mobile SDK:
Remember Returning Customers: enable faster checkouts and improved conversion by reducing friction for returning users.
Device-Wide Login Experience: simplify repeat purchases by enabling customers to remain logged in to Klarna across merchant apps on the same device.
Passkey Support: offer biometric-based login for enhanced security and a frictionless user authentication experience.
Application Redirects: seamlessly redirect users to external apps (e.g. bank or identity verification apps) and ensure a smooth return back into your app to complete payments without disruption.
Camera Access for ID Verification: improve acceptance by enabling secure and instant identity verification within the app.
Secure Browser Context: provide a secure, embedded browser environment for displaying Klarna-hosted content (payment pages or terms).
File Sharing and Download for T&Cs: Let customers download or share terms and conditions directly from the app for full transparency.
For a Mobile SDK integration your Payment Server and Mobile App must work together to complete the purchase flow:
sequenceDiagram
participant Consumer
participant Merchant App
participant Mobile SDK
participant Merchant Server
participant Klarna API
Consumer->>Merchant App: Navigate to checkout screen
Merchant App->>Merchant Server: Create payment session
Merchant Server->>Klarna API: Create Klarna Payment session
Note over Merchant Server, Klarna API: "intent" should be set in relevance to the desired use case
Klarna API-->>Merchant Server: Klarna payment session response
Merchant Server-->>Merchant App: Klarna payment session client_token
Merchant App->>Mobile SDK: Create the Payment View
Note over Merchant App: Includes 'Klarna' category and an eventListener
Merchant App->>Mobile SDK: Initialize the payment session using client_token
Merchant App->>Mobile SDK: Load the Payment View
Consumer->>Merchant App: Select Klarna in Payment selector
Merchant App->>Merchant App: Display the KlarnaPaymentView
Consumer->>Merchant App: Click "Continue with Klarna"
Merchant App->>Mobile SDK: Authorize the session
Note over Merchant App: Consumer completes to purchase flow.
Mobile SDK-->>Merchant App: Provide authorization token (valid for 60 minutes)
Merchant App->>Merchant Server: Sends the authorization token for creating order
Merchant Server->>Klarna API: Create Order POST (setup/payments/v1/authorizations/{authorizationToken}/order)
Klarna API-->>Merchant Server: Provide order_id and redirect_url
Merchant Server-->>Merchant App: Provide order details
Merchant App->>Consumer: Redirected to order confirmation screen
1.
Prepare: Make sure you have the credentials for Klarna Payments.
2.
Initiate payment (Server-side): Create a payment session from your backend and pass client_token to your app.
3.
Set up your app (Mobile App): Install the Klarna SDK using your package manager.
4.
Render payment view (Mobile App): Present Klarna’s native view to display Klarna in your checkout.
5.
Authorize the session (Mobile App): Trigger the authorization through the SDK and handle the callback.
6.
Create an order (Server-side): Pass the resulting authToken to your backend to finalize the payment and create an order.
Presenting Klarna in your mobile checkout
To maximize conversion and usability, you must dynamically retrieve Klarna’s branding, payment descriptors, and payment widget via Klarna’s API and SDK to present accurate, localized, and up-to-date payment options.
1.
Payment Descriptor: Dynamically populated in Klarna Payment session response, in the payment_method_categories.name field.
2.
Payment Sub header: Added by merchant.
3.
Widget: Provided with the KlarnaPaymentView from the Mobile SDK.
4.
Klarna Badge: Dynamically populated in Klarna Payment session response, in the payment_method_categories.asset_urls.standard field.
When you integrate Klarna payments into your online store, your customers see Klarna as an option when they select a payment method for their purchases. If your customers select Klarna for their purchase, they are redirected to log into their Klarna account.
Your customers select their preferred Klarna payment option (pay now, pay later, pay in parts) once they're logged into their Klarna account. We handle the Klarna account user flow, so you don't have to worry about it.
To test your Klarna API integration, you need a set of test credentials.
The API reference. You can download the Open API specification for the Klarna payments API and use the specification to generate an API SDK for your programming language.
When your customer wants to pay with Klarna, you have to open a payment session and share the shopping cart details in a POST request to the {apiURL}/payments/v1/sessions endpoint. In that request, you also specify if the payment is one-time or recurring.
Once you start a payment session, it stays open for 48 hours or until you place an order. You can also send a separate POST request to cancel the session.
Klarna payments API uses HTTP basic authentication. To authenticate, use your API credentials that consist of:
A username linked to your Klarna merchant ID (MID)
A password associated with your username
If you're using an API platform that lets you store your credentials, you can add them in relevant fields. Otherwise, make sure to include the Base64-encoded username:password in the Authorization header field of each API request, as shown below.
JSON
1
2
Authorization: Basic pwhcueUff0MmwLShJiBE9JHA==
A sample authorization request header with Base64-encoded credentials.
payment_method_categories, an array that lists the grouped Klarna payment methods available for the session. We can respond with one or more categories depending on the market and account configuration.
A sample error response caused by incorrect order line details.
Go to Error Handling to learn more about common errors and troubleshooting suggestions. You can use the value in correlation_id to find entries related to the request under Logs in the Merchant portal.
Mobile SDK integrations might, at some point, open third-party applications. To automatically return the user, these third-party applications need to know how to build a return intent or URL.
To do that, you’ll need to provide the SDK with what we call the “Return URL” parameter. If you haven’t done so already, follow this documentation for Android and this documentation for iOS.
Klarna purchase flows might require authorizations in other applications (e.g. bank apps) or do a handover to the Klarna app. In such cases, a return URL to your application ensures seamless return to the flow in your app, hence setting up a return URL is required. It is expected that redirects to this URL should only open your application without any changes in the UI state, ensuring the customer can continue the flow prior to external navigation.
Important: The return URL string passed to Klarna must include :// after the scheme name. For example, if you defined myApp as the scheme, you must use "myApp://" as the return URL argument to Klarna.
To avoid a Klarna specific app scheme, you can use a host in a common scheme for Klarna redirects, e.g. myApp://klarna-redirect , this can allow you to differentiate and handle these redirect in your handler.
Considering the return URL is a constant value in Constants.klarnaReturnUrl, you can handle redirects to your return URL as such:
SWIFT
1
2
3
4
5
6
7
8
9
10
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guardlet url = URLContexts.first?.url else {
return
}
if (url.absoluteString.starts(with: Constants.klarnaReturnUrl.absoluteString)) {
// This is a return URL for Klarna – skip deep linkingreturn
}
// This was not a return URL for Klarna
}
Klarna flows on mobile utilize Application Queries for Klarna app schemes to offer seamless app handover experience to customers. In order for the SDK to check availability of the Klarna app, we need you to enable querying Klarna app on the device by adding Klarna app schemes to LSApplicationQueriesSchemes.
This can be configured easily in XCode by going to your project setting and under "Info"(alternatively this is also available in your Info.plist file) you should see an entry list for Queried URL Schemes, this list should contain the klarna and klarnaconsent schemes:
You can import the KlarnaPaymentView from the library. You’ll then be able to add it as a component to your app. This component exposes callbacks as props and methods you can call via the component’s ref.
The view will auto-size height-wise and grow to fill it’s containing view’s width.
Before content is rendered into a payment view or an authorization, payment session with it's client token needs to be initialized. This can be done by calling initialize and handling result in klarnaInitialized.
TYPESCRIPT
1
2
3
// initilize with clientToken for session created from server-side
paymentViewRef.current?.initialize(props.clientToken);
Param
Type
Description
clientToken
String
The client token you get from Klarna Payments API session response.
If successful, onInitialized will be called in the property you supplied. If it’s not successful, onError will be called instead.
If successful, klarnaInitialized from KlarnaPaymentEventListener will be called in the listener you supplied. If it’s not successful, klarnaFailed will be called instead.
Once the user has confirmed that they want to pay with Klarna, it’s time to authorize the session. This is done by calling authorize, and similar to load, you can supply an optional JSON string with jsonData parameter to update the session. You can also specify whether auto-finalization should be turned off(on by default) and in that case you might be required to finalize the session after.
TYPESCRIPT
1
2
3
// authorize the payment session
paymentViewRef.current?.authorize();
Param
Type
Description
autoFinalize
Boolean
boolean
undefined
An optional flag used to turn off auto-finalization for direct bank transfer.
sessionData
String
string
undefined
An optional string to update the session. Formatted as JSON.
If successful, onAuthorized will be called in property you supplied and for errors onError will be called instead.
TYPESCRIPT
1
2
3
4
5
6
7
8
9
10
onAuthorized={(approved, authToken, finalizeRequired) => {
if (authToken && approved) {
// authorization is successful, backend may create order
}
if (finalizeRequired) {
// finalize() call is required
}
}
To continue with the purchase, you have to create an order in Klarna's system. This step takes place in the server side through the Klarna payments API.
To create an order for a one-time payment, send a POST request to the {apiUrl}/payments/v1/authorizations/{authorizationToken}/order endpoint and include authorization_token in the path.
For example, if the authorization_token is b4bd3423-24e3, send your request to the {apiUrl}/payments/v1/authorizations/b4bd3423-24e3/order endpoint.
When you receive a success response, the customer gets charged and the Klarna payments session is closed.
As part of the response, you receive the following details:
order_id, an order identifier that you can later use to capture or refund the order using the Order management API
redirect_url, a URL to which you redirect the customer. This isn't included in the response received if you didn't include the URL when initiating a payment
fraud_status, an indicator of whether the transaction is suspected to be legitimate or fraudulent
authorized_payment_method, the payment method selected by your customer for this purchase
A success response to the order creation request for a one-time payment.
Send the customer browser to redirect_url provided in the response. Klarna places a cookie in the browser and redirects the customer back to the confirmation URL you provided when creating the session. This makes the checkout faster the next time the customer chooses to pay with Klarna.
An error response to the order creation request for a one-time payment.
Here are examples of common errors with troubleshooting suggestions. You can use the value in correlation_id to find entries related to the request under Logs in the Merchant portal.
Error code
Error message
Description
NOT_FOUND
Invalid authorization token
The authorization token has expired because the order was placed more than 60 minutes after authorization. To fix the error, request a new authorization_token and use it to place the order.
BAD_VALUE
Not matching fields: [billing_address.postal_code]
The data shared with Klarna in a previous step (create_session, load(), or authorize()) have been modified causing the validation to fail.
BAD_VALUE
Not matching fields: [Incorrect number of items in the cart. Expected: 2, Actual: 3]
The order lines or the cart were updated after the authorize() call. Please ensure that the cart is kept as-is or send a new authorization request.
REJECTED
Rejected
This is an edge case reason, but can be triggered in case the merchant is configured with being allowed to update the cart. This could be updated from the authorize to the place order in such a way that a new authorize is triggered. In this case this is rejected.
Klarna Mobile SDK provides a full suite of mobile-first integrations, including Klarna products like:
Sign in with Klarna
On-site Messaging
Express Checkout
On-site Messaging: Show contextual messaging let your customers know about the available payment options in pre-checkout: click here to learn more.
Sign in with Klarna: Seamlessly identify and let users login via their Klarna account: click here to learn more.
Express Checkout: Accelerate your checkout process and boost conversion by offering a one-click checkout, click here to learn more (Mobile SDK support available soon).