You can hook up your web view to the SDK in only a few steps and immediately provide a much more pleasant experience when using Klarna products on mobile.
This guide will walk you through:
Setting up the SDK consists of creating an instance of the SDK and implementing a listener.
Initialize the Hybrid SDK by creating a new instance of KlarnaHybridSDK. You should hold a strong reference to the SDK. It will deallocate all its resources if you null it. You only need a single instance of the SDK, regardless of how many web views you have, but if you need to, you can create several SDKs.
Param | Type | Description |
---|---|---|
returnUrl | String | A URL that the SDK can use to return customers to your app. |
eventCallback | KlarnaEventCallback | (Optional) Event Callback interface that will notify you about messages and errors. |
fullscreenEventCallback | KlarnaFullscreenEventCallback | (Optional) Fullscreen event Callback interface that will notify you about fullscreen transition events. |
The SDK will notify you of events and errors via event callback object that you’ll need to implement. The SDK also notifies you about different events during fullscreen transition via fullscreen event callback.
You can read more about the callback at the end of this page.
You need to add the web views that the SDK should track. The SDK will hold weak references to these web views, so if they’re deallocated, the SDK will lose track of them.
Create an instance of WebView either in your layout or directly in your code and pass it to the SDK with addWebView(). This web view will be used to render your checkout content.
Param | Type | Description |
---|---|---|
webView | WebView | A WebView that the SDK will track ongoingly. |
To add a web view to the SDK from a layout:
To add a web view to the SDK from code:
There are two instances at which you’ll need to notify the SDK of events in your web view (as we don’t override your WebViewClient).
You should notify the SDK about upcoming navigations by calling the SDK’s shouldFollowNavigation() from your WebViewClient.
Param | Param | Description |
---|---|---|
url | URL | The URL that will be loaded. |
You need to notify the SDK after a page has loaded by calling the SDK’s newPageLoad() from your WebViewClient.
Param | Type | Description |
---|---|---|
webView | WebView | The WebView that new content has loaded in. |
KlarnaEventCallback
You will need to implement the KlarnaEventCallback interface in order to receive events and errors from the SDK. This will let your app be notified about relevant events and errors that happen inside the web view that the SDK is observing.
KlarnaFullscreenEventCallback
You will need to implement the KlarnaFullscreenEventCallback interface in order to receive events from the SDK during the fullscreen transition.
All of these provide you with the web view these events occurred in. You can read more about the fullscreen events here.
The completion handler completion.run() should be called when you have performed any animations or changes to let the SDK know that your app is done with this step. The only exception is onErrorOccurred() which does not expect an action to be performed by the app when called.