Last updated

iOS Integration


This page provides instructions for integrating Kustom Checkout into an iOS application.

Before you start

This guide assumes Kustom Checkout has already been set up and is available at a specified API endpoint. For detailed setup, refer to the general Kustom Checkout Integration guide.

Working with the In-App SDK

Adding Kustom Checkout to your app

The Checkout View in iOS is called KlarnaCheckoutView.

Creating the View from Code

Create the KlarnaCheckoutView instance in your view controller. Initialize the view using the returnURL and eventHandler parameters.

var checkoutView: KlarnaCheckoutView?
override func viewDidLoad() {
    super.viewDidLoad()
    checkoutView = KlarnaCheckoutView(returnURL: URL(“app-schema://”), eventHandler: KlarnaEventHandler)
}

Initialize SDK with the Checkout snippet

Initialize the KlarnaCheckoutView with the Checkout HTML snippet fetched from your server at YOUR-URL.

checkoutView?.setSnippet(snippet)

Configure Event Listeners

The SDK notifies you of events and errors via a handler object. Implement the KlarnaEventHandler protocol.

// In case the handler needs to be updated to another reference
checkoutView?.eventHandler = handlerObject // must implement the KlarnaEventHandler protocol

The KlarnaEventHandler protocol exposes methods for handling various events:

func klarnaComponent(_ klarnaComponent: KlarnaComponent, dispatchedEvent event: KlarnaProductEvent) {
// A few examples of dispatched events shown later in the docs
}

and

func klarnaComponent(_ klarnaComponent: KlarnaComponent, encounteredError error: KlarnaError) {
// Errors related to the sdk
}

Configure Sizing Delegate

The sizingDelegate is used to handle resizing of views within the KlarnaCheckoutView. Implement the KlarnaSizingDelegate protocol.

checkoutView?.sizingDelegate = listenerObject // must implement the KlarnaSizingDelegate protocol

Suspend and Resume Checkout

The suspend() and resume() actions control user interaction with the KlarnaCheckoutView.

checkoutView?.suspend()
checkoutView?.resume()

Handling External Payment Methods

checkoutView?.checkoutOptions.merchantHandlesEPM = true

(Set before starting Checkout)

The SDK handles external payment method events.

Handling Validation Errors

checkoutView?.checkoutOptions.merchantHandlesValidationErrors = true

(Set before starting Checkout)

Return URL

Third-party applications might require returning to your app. The SDK uses the provided returnURL to manage this process.

Note: Bank ID authentication for credit card payments might require manual user return to the app after bank authentication.