Skip to main content

Overview

The Moment Swift SDK enables seamless payment integration into any native iOS application. The SDK provides a clean, idiomatic Swift API with full async/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. Moment Mobile SDK

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

  1. App launchesMoment(clientKey:) creates the SDK instance; moment.checkout(...) creates and returns the checkout instance, registering your fetchClientToken, fetchSessionStatus, and event closures
  2. Customer taps Paycheckout.launch() is called
  3. SDK calls fetchClientToken — your closure creates a session on your backend (with a success_url deep link) and returns the client_token
  4. Checkout opens in a native bottom sheet
  5. Customer submits payment — Moment takes over and redirects to the authentication page
  6. Customer completes authentication on the external page
  7. Customer is redirected back to your app via redirect link with ?session_id=abc123
  8. SDK detects the redirect link and calls your fetchSessionStatus("abc123") closure automatically
  9. Your closure fetches the status from your backend, which queries Moment API
  10. SDK routes to the right handleronSuccess, onFailure, onExpired, or onCancel
  11. Webhooks are delivered to your backend regardless of outcome

Installation

In Xcode, go to File → Add Package Dependencies and enter:
Or add to your Package.swift:

CocoaPods

Add to your Podfile:
Then run:

Platform Configuration

Requirements

  • iOS 15.0+
  • Swift 5.7+
  • Xcode 14+

Quick Start

1. Initialize the SDK and configure checkout

Create the SDK instance with Moment(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:
server.js
iOS — initialize once on app launch:
AppDelegate.swift

2. Launch Checkout

CheckoutViewController.swift

API Reference

Moment(clientKey:)

Creates the SDK instance. Call once when your app launches — typically stored as a global let before your AppDelegate class or App struct.

moment.checkout(config)

Creates and returns a MomentCheckout 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!. Example:

checkout.launch()

Opens the payment checkout in a native bottom sheet. Internally calls your fetchClientToken closure to retrieve a fresh token.

checkout.close()

Manually dismisses the bottom sheet checkout.

Security Best Practices

  1. Never embed your secret key (sk_...) in your iOS app — it must only live on your backend
  2. Always create sessions server-side via your backend API
  3. Validate webhooks to confirm payment state before fulfilling orders
  4. Use HTTPS for all backend communication
  5. Handle token expiry — the SDK calls fetchClientToken on every open(), so tokens are always fresh
  6. Use the Keychain to store any persistent credentials — never UserDefaults
  7. Avoid logging sensitive data — do not log client_token or session IDs in production builds

Next Steps