Skip to content
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.

Setup your app

Import the SDK

Swift Package Manager

In Xcode, navigate to File → Swift Packages → Add Package Dependency and enter the repository URL: https://github.com/Kustom-Checkout/kustom-mobile-sdk-spm

In Version, Select Up to Next Major and take the default option. Then choose KustomMobileSDK in the Package Product column.

Cocoapods

If you’re using Cocoapods, you can add the SDK by adding the dependency to your Podfile:

pod "KustomMobileSDK"

Followed by performing:

pod install

You should then be able to import the KustomMobileSDK module in your workspace.

Working with the Mobile SDK

Adding Kustom Checkout to your app

The Checkout View in iOS is called KustomCheckoutView.

Creating the View from Code

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

var checkoutView: KustomCheckoutView?
override func viewDidLoad() {
    super.viewDidLoad()
    checkoutView = KustomCheckoutView(returnURL: URL(`app-schema://`), eventHandler: KustomEventHandler)
}

Initialize SDK with the Checkout snippet

Initialize the KustomCheckoutView 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 KustomEventHandler protocol.

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

The KustomEventHandler protocol exposes methods for handling various events:

func kustomComponent(_ kustomComponent: KustomComponent, dispatchedEvent event: KustomProductEvent) {
// A few examples of dispatched events shown later in the docs
}

and

func kustomComponent(_ kustomComponent: KustomComponent, encounteredError error: KustomMobileSDKError) {
// Errors related to the sdk
}

Configure Sizing Delegate

The sizingDelegate is used to handle resizing of views within the KustomCheckoutView. Implement the KustomSizingDelegate protocol.

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

Suspend and Resume Checkout

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

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 payments might require manual user return to the app after bank authentication.