Quick Start
Get up and running with the Payrails iOS SDK in about 15 minutes. By the end you will have a working card payment screen in your app.
Prerequisites
- Xcode 16.4+. Each release is built with Xcode 16.4. Swift’s module interface format is not backward compatible across toolchains, so an older Xcode cannot load the prebuilt framework.
- iOS 14.0+ deployment target.
- Swift 5.0+.
- A Payrails merchant account and a backend that can fetch an init payload.
Step 1: Install the SDK
The SDK ships as a prebuilt, signed XCFramework. Swift Package Manager is the only supported installation method.
In Xcode, click File → Add Package Dependencies and enter the package URL:
Select the Payrails product and add it to your app target.
To declare the dependency in a Package.swift instead:
Swift Package Manager downloads the framework and verifies it against the checksum published in the package manifest. Resolution also pulls in PayrailsCSE and PayPalCheckout, so three packages appear in your project, not one.
Step 2: Enable Apple Pay capability (optional)
If you plan to use Apple Pay, add the Apple Pay capability in Xcode under Signing & Capabilities and provide your merchant identifier.
Step 3: Fetch the init payload from your backend
The SDK requires an init payload that your backend fetches from the Payrails API. This payload is a base64-encoded JSON string along with a version string.
Step 4: Initialize the SDK session
Async/await
Recommendedsupply onSessionExpired at createSession time. The SDK invokes it when it detects the current execution is no longer reusable (most commonly: the user abandoned a 3DS challenge). Without it, the next payment attempt against the poisoned Session fails naturally and the SDK logs a warning at init.
Callback
Step 5: Build a card payment screen
Payrails provides UIKit-based elements. Add them to your view hierarchy:
Step 6: Handle payment results
Conform to PayrailsCardPaymentButtonDelegate:
Step 7: Test with the sandbox environment
Change the environment to .test when initializing the session:
Use Payrails sandbox card numbers to test different payment outcomes.
What’s next