Klarna Docs - Adding Klarna Payments to Your App

Adding Klarna Payments to Your App

Adding Klarna Payments to your application is as easy as adding a view and performing a few operations on it. You can read more about the flow here.

This guide will teach you how to:

  • Render a Payment View
  • Operate on a payment method via its Payment View.

RENDERING A PAYMENT VIEW

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.

Creating the View

You can add the view to your layout as shown below:

PROPS FOR KLARNAPAYMENTVIEW

KlarnaPaymentView currently supports following props:

NameTypeDescription
categoryStringThe payment method category you want to render in your view.
onInitialized() => {}The initialize call succeeded.
onLoaded() => {}The load call succeeded.
onLoadedPaymentReview() => {}The load payment review call succeeded.
onAuthorized({}) => {}The authorize call succeeded.
onReauthorized({}) => {}The reauthorize call succeeded.
onFinalized({}) => {}The finalize call succeeded.
onError({}) => {}An error occurred.

PROP CALLBACK PARAMETERS

The onAuthorized, onReauthorized, onFinalized and onError will provide an object (via nativeEvent) with the following parameters:

authorized: Boolean

Determines whether the previous operation was successful and yielded an authorization token.

Available on:

  • onAuthorized
  • onReauthorized
  • onFinalized

authToken: String | undefined

If authorize(), reauthorize() or finalize() succeed, they will return a token you can submit to your backend.

Available on:

  • onAuthorized
  • onReauthorized
  • onFinalized

finalizeRequired: Boolean | undefined

If authorize() requires that you additionally call finalize().

Available on:

  • onAuthorized

error: Object | undefined

If a method fails, onError() will let you know via an error object.

Available on:

  • onError

METHODS FOR KLARNAPAYMENTVIEW

Each payment view exposes a set of methods via a view’s ref. You can see in the test app or in the below example how these can be called. The methods are the following:

Initialize

Initializes the view with a session token. You have to have added the view to your application and supplied a payment method category.

ParamTypeDescription
sessionTokenStringThe session token you get from Klarna.
returnUrlStringAn app-defined URL scheme the component uses to return customers to your app.

Load

Loads the view and renders the content inside.

ParamTypeDescription
sessionDataString | undefinedAn optional string to update the session. Formatted as JSON.

LoadPaymentReview

Renders a description of the payment terms your customer has agreed to.

Once a session is authorized, you can then either render a payment review in the existing payment view or initialize() a new payment view with the same session token and call this method.

Note

This only works with specific payment methods and countries.

Authorize

Authorizes the payment session.

ParamTypeDescription
autoFinalizeBoolean | undefinedAn optional flag used to turn off auto-finalization for direct bank transfer.
sessionDataString | undefinedAn optional string to update the session. Formatted as JSON.

Reauthorize

If the details of the session (e.g. cart contents, customer data) have changed, call this to update the session and get a new authorization token.

ParamTypeDescription
sessionDataString | undefinedAn optional string to update the session. Formatted as JSON.

Finalize

If a specific payment method needs you to trigger a second authorization, call finalize when you’re ready.

ParamTypeDescription
sessionDataString | undefinedAn optional string to update the session. Formatted as JSON.