Overview
The Moment Swift SDK enables seamless payment integration into any native iOS application. The SDK provides a clean, idiomatic Swift API with fullasync/await support to handle the entire payment flow through a native bottom sheet experience.
Built for iOS with Swift, the SDK supports both UIKit and SwiftUI workflows.

Key Features
- async/await API – Modern Swift concurrency with no callback pyramid
- Native Experience – Bottom sheet presentation using native iOS sheet APIs
- UIKit & SwiftUI – Works seamlessly with both UI frameworks
- Type-Safe – Fully typed closures and result types with Swift-first design
- Flexible Callbacks – Handle success, failure, cancellation, retry, and expiry events
- Secure – Sensitive payment data handled entirely in Moment’s secure WebView
- PCI Compliant – No card data touches your application
How It Works
- App launches —
Moment(clientKey:)creates the SDK instance;moment.checkout(...)creates and returns thecheckoutinstance, registering yourfetchClientToken,fetchSessionStatus, and event closures - Customer taps Pay —
checkout.launch()is called - SDK calls
fetchClientToken— your closure creates a session on your backend (with asuccess_urldeep link) and returns theclient_token - Checkout opens in a native bottom sheet
- Customer submits payment — Moment takes over and redirects to the authentication page
- Customer completes authentication on the external page
- Customer is redirected back to your app via redirect link with
?session_id=abc123 - SDK detects the redirect link and calls your
fetchSessionStatus("abc123")closure automatically - Your closure fetches the status from your backend, which queries Moment API
- SDK routes to the right handler —
onSuccess,onFailure,onExpired, oronCancel - Webhooks are delivered to your backend regardless of outcome
Installation
Swift Package Manager (Recommended)
In Xcode, go to File → Add Package Dependencies and enter:Package.swift:
CocoaPods
Add to yourPodfile:
Platform Configuration
Requirements
- iOS 15.0+
- Swift 5.7+
- Xcode 14+
Quick Start
1. Initialize the SDK and configure checkout
Create the SDK instance withMoment(clientKey:) and configure the checkout product by calling moment.checkout(...). Both are set up once when your app launches — in AppDelegate or your SwiftUI App initializer. You provide two async throwing closures — the SDK calls them automatically at the right moments.
Backend endpoints:
- Node.js
- Python
- Go
- Firebase
- Supabase
- Lambda
server.js
- UIKit · URLSession
- UIKit · Alamofire
- UIKit · Firebase
- UIKit · Supabase
- SwiftUI · URLSession
- SwiftUI · Alamofire
- SwiftUI · Firebase
- SwiftUI · Supabase
AppDelegate.swift
2. Launch Checkout
- UIKit
- SwiftUI
CheckoutViewController.swift
API Reference
Moment(clientKey:)
Creates the SDK instance. Call once when your app launches — typically stored as a globallet before your AppDelegate class or App struct.
| Parameter | Type | Required | Description |
|---|---|---|---|
clientKey | String | Yes | Your publishable key (pk_test_... or pk_live_...) |
moment.checkout(config)
Creates and returns aMomentCheckout instance for the checkout product. Registers your fetch closures and event handlers — the SDK calls them automatically at the right moments. Typically called in AppDelegate or your SwiftUI App init() and assigned to a global var checkout: MomentCheckout!.
| Parameter | Type | Required | Description |
|---|---|---|---|
fetchClientToken | () async throws -> String | Yes | Async throwing closure returning a fresh client token. Called by the SDK when checkout.launch() is invoked. |
fetchSessionStatus | ((String) async throws -> MomentSessionStatus)? | No | Async throwing closure receiving a sessionId, returning session status. Called when a deep link with session_id is detected after a redirect-based payment. Required only if you use redirect mode. |
onSuccess | ((MomentResult) -> Void)? | No | Closure fired when payment succeeds (both embedded and redirect flows) |
onFailure | ((MomentResult) -> Void)? | No | Closure fired when payment fails |
onCancel | ((MomentResult) -> Void)? | No | Closure fired when user cancels |
onAttemptFailed | ((MomentResult) -> Void)? | No | Closure fired when a payment attempt fails (user can retry) |
onExpired | ((MomentResult) -> Void)? | No | Closure fired when the payment session expires |
checkout.launch()
Opens the payment checkout in a native bottom sheet. Internally calls yourfetchClientToken closure to retrieve a fresh token.
| Parameter | Type | Required | Description |
|---|---|---|---|
from | UIViewController | UIKit only | The presenting view controller |
checkout.close()
Manually dismisses the bottom sheet checkout.Security Best Practices
- Never embed your secret key (
sk_...) in your iOS app — it must only live on your backend - Always create sessions server-side via your backend API
- Validate webhooks to confirm payment state before fulfilling orders
- Use HTTPS for all backend communication
- Handle token expiry — the SDK calls
fetchClientTokenon everyopen(), so tokens are always fresh - Use the Keychain to store any persistent credentials — never
UserDefaults - Avoid logging sensitive data — do not log
client_tokenor session IDs in production builds
Next Steps
- View Sample Applications for end-to-end examples
- Create your first Payment Session
- Configure Webhooks
- Test your integration in Sandbox mode

