Klarna Docs - Klarna Payments (Standalone)
Klarna Payments (Standalone)

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 the payment method via its Payment View.

For additional information on methods, parameters and integrations you can also refer to the Klarna Payments SDK documentation for web.

A Payment View in Android is called a KlarnaPaymentView. You can initialize the KlarnaPaymentView in your activity either using XML or by creating it programmatically:

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

JSON
<com.klarna.mobile.sdk.api.payments.KlarnaPaymentView
    ...
    android:id="@+id/paymentView"/>

You should then be able to set up the view in code by setting a category and registering a callback:

If you instead want to create the view in code, you can use its constructor to set it up with a single line.

ParamTypeDescription
contextContextThe context of the Activity the Payment View is in.
categoryStringThe payment method category that will be rendered in the view. It has to be the same as the one in the response object when initiating a payment. It is usually 'klarna'.
callbackKlarnaPaymentViewCallbackCallback interface that receives events during the payment process.
returnURLStringURL schema as defined in your AndroidManifest.xml to return from external applications.

The SDK will notify you of events via a callback object that you’ll need to implement. It acts like a listener on Android, however, unlike a listener, it’s not optional.

We expose six methods on the payment view that you can use to interact with the payment method it’s presenting:

Before content is rendered into a payment view, it needs to be configured. You can do this by initializing the view.

After the view has been added and set up, you’ll need to call initialize() with the clientToken you received from the back-end.

ParamTypeDescription
clientTokenStringToken that was returned when you created the session.
returnURLStringURL schema as defined in your AndroidManifest.xml to return from external applications.

If successful, onInitialized() will be called in the callback you supplied (in e.g registerPaymentViewCallback). If it’s not successful onErrorOccurred() will be called instead.

ParamTypeDescription
viewKlarnaPaymentViewThe payment view that was initialized.

Once you’ve initialized the view and you’re ready to display the KlarnaPaymentView.

Simply call load(), supplying an optional string with updated order data to update the session. This string should be formatted as valid JSON.

ParamTypeDescription
argsString?An optional string with the order data to update the session. Formatted as JSON.

If successful, onLoaded() will be called in the callback you supplied. If anything went wrong, onErrorOccurred() will be called. If you’ve loaded several views, you should keep track of which view your user selected to know what to authorize in the next step.

ParamTypeDescription
viewKlarnaPaymentViewThe payment view that was loaded.

When the payment view is loaded, and the user has confirmed that they want to pay with Klarna, it’s time to authorize the session.

When you are ready to authorize the session, call authorize(). As with load, you can supply an optional string to update the session. You can also specify whether auto-finalization should be turned off; if it is, the user may need to be prompted a second time to input data.

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

If successful, onAuthorized() will be called in the callback. If not, onErrorOccurred() will be called.

ParamTypeDescription
viewKlarnaPaymentViewThe payment view that was authorized.
approvedBooleanWhether the authorization was approved or not.
authTokenString?If the session was authorized, the token will not be null.
finalizedRequiredBoolean?Will be true if autoFinalizewas false and this payment method needs a second confirmation step.

There are cases when you might want to allow your customer to change their order after it has been authorized (e.g. in some form of order/summary view). In these cases, if the order or customer details have changed, you’ll need to reauthorize the session.

ParamTypeDescription
sessionDataString?An optional string to update the session. Formatted as JSON

If successful, onReauthorized() will be called, and if not, onErrorOccurred() will be called instead.

ParamTypeDescription
viewKlarnaPaymentViewThe payment view that was reauthorized.
approvedBooleanWhether the reauthorization was approved or not.
authTokenString?If the session was previously authorized, the token will not be null.

If the session needs to be finalized, you’ll need to perform this last step to get an authorization token.

Call finalize() in order to get the token.

ParamTypeDescription
sessionDataString?An optional string to update the session. Formatted as JSON

If successful, onFinalized() will be called in the callback. If not successful, onErrorOccurred() will be called.

ParamTypeDescription
viewKlarnaPaymentViewThe payment view that was finalized.
approvedBooleanWhether the user was approved on finalize or not.
authTokenString?If the finalization went through, the token will not be null.

If you’d like to allow the user to review their payment after it’s authorized, this can be done in two ways:

  1. Render it in a new view:
    undefinedundefinedundefined
  2. Render it in the existing payment view:
    undefined

Only specific countries are currently supported. Contact us to make sure that you can call this method.

This will load/replace the view’s content with a description of how your customer will have to perform payment.

If successful onLoadPaymentReview() will be called in your callback. If not, onErrorOccurred() will be called instead.

ParamTypeDescription
viewKlarnaPaymentViewThe payment view that dsplayed payment review.