Adding Klarna Checkout to your application is as easy as adding a view and performing a few operations on it.
This guide will teach you how to:
Using our the SDK, your mobile app presents the Klarna Checkout view. In your mobile app. You will need to fetch a Klarna Checkout HTML snippet from your web server, add the Klarna Checkout view to your app, and set the snippet on the view. This integration guide will not go through the Klarna Checkout integration in detail but assumes it has been set up already and is available at an API endpoint <YOUR-URL> on your servers. If needed, you can learn how to do it in the regular Klarna Checkout Integration guide here.
The Checkout View in Android is called KlarnaCheckoutView. You can initialize the `KlarnaCheckoutView` in your activity either using XML or by creating it programmatically:
You can add the view to your layout as shown below:
You should then be able to set up the view in code by setting an event handler:
If you instead want to create the view in code, you can use its constructor to set it up with a single line:
Parameter | Type | Description |
---|---|---|
context | Context | the Context the Checkout View is in. |
returnURL | String | (Optional) URL schema as defined in your AndroidManifest.xml to return from external applications. |
eventHandler | KlarnaEventHandler | (Optional) Event handler instance to receive events and errors from the SDK |
environment | KlarnaEnvironment | (Optional) Environment or "mode" that this SDK runs in. Defaults to `.production`. |
region | KlarnaRegion | (Optional) Geographic region that the SDK performs requests to. Defaults to `.eu`. |
theme | KlarnaTheme | (Optional) Theme to render this component with. Defaults to `.light`. |
To initialize the Klarna Checkout in your flow, supply a Checkout HTML snippet hosted at <YOUR-URL>:
The SDK will notify you of events or errors via an event handler object that you’ll need to implement.
Here is a code example of how this is done:
Parameter | Parameter Type | Description |
---|---|---|
klarnaComponent | KlarnaComponent | The Klarna component instance sending the events or errors. You can safely cast this object to KlarnaCheckoutView type. |
event | KlarnaProductEvent | The event you might receive from the SDK. You can check the event's action (name) and its possible parameters by accessing its properties as demonstrated in the example above. |
error | KlarnaMobileSDKError | The error you might receive from the SDK. You can check the error's name and its message by accessing its properties as demonstrated in the example above. |
When a server side call to Klarna is being processed, you can trigger the suspend action to prevent the user/customer from altering the state of their Checkout order. The suspend action will turn the Klarna Checkout unresponsive to user interactions.
After the server side call to Klarna has been processed, you should trigger the resume action to once again let the user interact with Klarna Checkout.
If you wish to handle external payment methods (such as PayPal, Google Pay, etc), you can turn on the following feature flag in the SDK. By doing so, the Klarna Checkout will not handle the external payment methods automatically:
Whenever the SDK reaches an external payment method selected by the customer, you will receive an event named “external” in your callback with a “uri” parameter pointing to the external payment’s url:
If you wish to handle validation errors and you don’t want Klarna Checkout to show a pop-up window showing the errors, you can turn on the following feature flag in the SDK:
Whenever the SDK detects a validation error, you will receive an event named “validation_error” in your callback with “error_type” and “error_text” parameters:
Some payment methods require authorization through third-party applications. These can return to your application upon completion, but to do that, you need to supply a URL that should be used for returning. There do not need to be any special handlers on application load for that URL. Our only requirement is that the user is returned to your application from the third-party application.
Note: In cases where the user needs to authenticate with their bank for credit card payments, the bank itself might open a third-party app such as Bank ID. Since the SDK does not create these sessions, the user would have to return to the app manually, and then you will get the completion signal from the checkout.