iOS
The Checkout SDK is a Swift framework (library) provided by Ottu, designed to facilitate the seamless integration of an Ottu-powered checkout process into iOS applications.
With the Checkout SDK, both the visual appearance and the forms of payment available during the checkout process can be fully customized.
To integrate the Checkout SDK, the library must be included in the iOS application and initialized with the following parameters:
Additionally, optional configurations such as the forms of payment to accept and the theme styling for the checkout interface can be specified.
API private key should never be used on the client side. Instead, API public key should be used. This is essential to ensure the security of your application and the protection of sensitive data.
This video walks you step-by-step through the iOS SDK integration process. Watch it to quickly understand setup, configuration, and key features in action.
Before integrating the Checkout SDK, please review the following requirements:
Since the minimum supported iOS version is 14, the primary demo application is implemented using UIKit framework (SwiftUI is recommended starting from iOS 15). ottu-ios/Example at main · ottuco/ottu-ios
However, there’s also a minimalistic SwiftUI-based demo app: ottu-ios/Example_SwiftUI at main · ottuco/ottu-ios
You can install the SDK via two paths:
Swift Package Manager (Recommended)
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:
Open your project
Go to Project > Targets > Package Dependencies
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
When ottu_checkout_sdk is added to the Podfile, the GitHub repository must also be specified as follows:
pod 'ottu_checkout_sdk', :git => 'https://github.com/ottuco/ottu-ios'
If you see “could not find compatible versions for pod”, run:
pod repo update
Once the SDK is installed, follow these steps to integrate it into your app.
Import the SDK
In your ViewController.swift
(or any file responsible for presenting the SDK):
import ottu_checkout_sdk
Conform to OttuDelegate
Your view controller must implement the OttuDelegate
protocol:
class ViewController: UIViewController, OttuDelegate
Declare a Checkout Member
Inside your ViewController
private var checkout: Checkout?
Initialize Checkout
Inside viewDidLoad
, initialize the Checkout SDK:
do {
self.checkout = try Checkout(
displaySettings: PaymentOptionsDisplaySettings(
mode: PaymentOptionsDisplaySettings.PaymentOptionsDisplayMode.list,
),
sessionId: sessionId,
merchantId: merchantId,
apiKey: apiKey,
delegate: self
)
} catch let error as LocalizedError {
print(error)
return
} catch {
print("Unexpected error: \(error)")
return
}
Required parameters
sessionId
→ ID of the created transactionmerchantId
→ Same as the domain address in API requestsapiKey
→ Public API key for authorizationdelegate
→ Callback listener (usuallyself
)
Recommended parameters
formsOfPayment
→ Defines available payment methodssetupPreload
→ 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 aTransactionDetails
object. See an example: MainViewController.swift
The simplest version of the initialization looks like this:
do {
self.checkout =
try Checkout(
sessionId: sessionId,
merchantId: merchantId,
apiKey: apiKey,
delegate: self
)
} catch
let error as LocalizedError {
// display an error here
return
} catch {
print("Unexpected error: \(error)")
return
}
Add the Payment View
Still inside viewDidLoad
, embed the payment view into your container:
if let paymentVC = self.checkout?.paymentViewController(),
let paymentView = paymentVC.view {
self.addChild(paymentVC)
paymentVC.didMove(toParent: self)
view.addSubview(paymentView)
}
This is a basic example that adds the Checkout view without handling dimensions. For proper layout with constraints, refer to the demo app: OttuPaymentsViewController.swift
In order ViewController
to be compliant to OttuDelegate
, add the following functions to ViewController
class:
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)
}
Error → Displays an error alert and navigates back
Cancel → Displays cancel reason (custom handling for
kpay
)Success → Displays success confirmation
This code describes callbacks to be handled by the parent app.
If your app should support Apple Pay:
Enable Apple Pay capability in:
Xcode > Targets > Signing & Capabilities
Add Apple Pay Merchant IDs (MID) in project settings
Last updated