iOS SDK Integration

This guide walks you through installing and integrating the Ottu Checkout iOS SDK into your iOS project. Choose your installation path and follow the journey step by step.

You can install the SDK via two paths:

  • Path One: Swift Package Manager (Recommended)

  • Path Two: CocoaPods (Deprecated)

Add Ottu SDK as a dependency in Package.swift:

dependencies: [
    .package(url: "https://github.com/ottuco/ottu-ios.git", from: "2.1.4")
]

Or in Xcode:

  1. Open your project

  2. Go to Project > Targets > Package Dependencies

  3. Add ottu-ios as a dependency

Add the following line to your Podfile:

pod 'ottu_checkout_sdk', :git => 'https://github.com/ottuco/ottu-ios.git', :tag => '2.1.4'

Run:

pod install

Once the SDK is installed (via Path One or Path Two), follow these steps to integrate it into your app.

1

Import the SDK

In your ViewController.swift (or any file responsible for presenting the SDK):

import ottu_checkout_sdk
2

Conform to OttuDelegate

Your view controller must implement the OttuDelegate protocol:

class ViewController: UIViewController, OttuDelegate 
3

Initialize Checkout

Inside viewDidLoad, initialize the Checkout SDK:

do {
    self.checkout =
        try Checkout(
            formsOfPayments: formsOfPayment,
            theme: theme,
            displaySettings: PaymentOptionsDisplaySettings(
                mode: paymentOptionsDisplayMode,
                visibleItemsCount: visibleItemsCount,
                defaultSelectedPgCode: defaultSelectedPgCode
            ),
            sessionId: sessionId,
            merchantId: merchantId,
            apiKey: apiKey,
            setupPreload: transactionDetailsPreload,
            delegate: self
        )
} catch
let error as LocalizedError {
    showFailAlert(error)
    return
} catch {
    print("Unexpected error: \(error)")
    return
}

Required parameters

  • sessionId → ID of the created transaction

  • merchantId → Same as the domain address in API requests

  • apiKey → Public API key for authorization

  • delegate → Callback listener (usually self)

Recommended parameters

  • formsOfPayment → Defines available payment methods

  • setupPreload → Preloads transaction details for faster initialization

setupPreload comes from the transaction creation response. Passing it prevents the SDK from re-fetching transaction details, reducing initialization time by several seconds. It is a decoded JSON object to a TransactionDetails object. See an example: MainViewController.swift

4

Add the Payment View

Still inside viewDidLoad, embed the payment view into your container:

if let paymentView = self.checkout?.paymentView() {
    paymentView.translatesAutoresizingMaskIntoConstraints = false
    self.paymentContainerView.addSubview(paymentView)

    NSLayoutConstraint.activate([
    paymentView.leadingAnchor.constraint(equalTo: self.paymentContainerView
            .leadingAnchor),
    self.paymentContainerView.trailingAnchor.constraint(equalTo: paymentView
            .trailingAnchor),
    paymentView.topAnchor.constraint(equalTo: self.paymentContainerView.topAnchor),
    self.paymentContainerView.bottomAnchor.constraint(equalTo: paymentView
            .bottomAnchor)
    ])
}

To make your ViewController compliant with OttuDelegate, add an extension in the same file (at the same level as the class):

extension OttuPaymentsViewController: OttuDelegate {
    func errorCallback(_ data: [String: Any] ? ) {
        navigationController?.popViewController(animated: true)
        let alert = UIAlertController(title: "Error", message: data
            ?.debugDescription ?? "", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .cancel))
        self.present(alert, animated: true)
    }

    func cancelCallback(_ data: [String: Any] ? ) {
        var message = ""

        if let paymentGatewayInfo = data ? ["payment_gateway_info"] as ?
            [String: Any],
            let pgName = paymentGatewayInfo["pg_name"] as ? String,
                pgName == "kpay" {
                    message = paymentGatewayInfo["pg_response"]
                        .debugDescription
                } else {
                    message = data?.debugDescription ?? ""
                }

        navigationController?.popViewController(animated: true)
        let alert = UIAlertController(title: "Canсel", message: message,
            preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .cancel))
        self.present(alert, animated: true)
    }

    func successCallback(_ data: [String: Any] ? ) {
        navigationController?.popViewController(animated: true)
        let alert = UIAlertController(title: "Success", message: data
            ?.debugDescription ?? "", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .cancel))
        present(alert, animated: true)
    }

}

Callback behavior:

  • Error → Displays an error alert and navigates back

  • Cancel → Displays cancel reason (custom handling for kpay)

  • Success → Displays success confirmation

These callbacks are fully customizable to match your app’s UX.

If your app should support Apple Pay:

  1. Enable Apple Pay capability in: Xcode > Targets > Signing & Capabilities

  2. Add Apple Pay Merchant IDs (MID) in project settings

Last updated