iOS SDK
Take card, Apple Pay, and redirect payments in an iOS app, in a ready-made payment sheet or your own screen with SDK-owned card fields.
The Pay.com iOS SDK takes payments in native apps. Your server creates a session, the app starts a checkout with the session's client_secret, and the SDK takes the payment:
- A ready-made sheet, or your own screen. The drop-in shows the session's payment methods, the card form, and the Pay button in a system sheet. To build your own screen, use the headless checkout and the card fields.
- Card fields the SDK owns. You place the card number, expiration date, CVV, and name inputs anywhere in your layout. The app never reads the card number. It gets only the validation state, the card brand, and the first 8 digits.
- 3DS handled for you. When the issuer asks for a challenge, the SDK shows it full screen in a web view over the view controller you pass, then reads the outcome.
- Apple Pay. The SDK builds the Apple Pay request from the session, shows the sheet, and pays with the token.
- Redirect payment methods. Alternative payment methods that complete through a redirect or an app switch come back to your app through a return URL.
- Saved payment methods. At checkout, the customer can pay with one of their saved cards, PayPal accounts, or bank accounts. In a setup session, they pick one of their saved methods or add one, for example to choose where their payouts go.
- Async/await and typed errors. Calls that reach Pay.com are
async, and the checkout's errors are allPayErrorinstances. The card fields are synchronous.
The drop-in for a new customer, and for a returning one:
Requirements
The SDK needs these versions:
| Requirement | Version |
|---|---|
| iOS | 15 or later |
| Swift | 6 (strict concurrency), Swift tools 6.0 |
| Package manager | Swift Package Manager |
The package also lists macOS 12 so its platform-independent code builds and tests on a Mac. The SDK ships for iOS, because the card fields, the drop-in, and the 3DS screens need UIKit.
Install
Add the pay-com-ios package with Swift Package Manager.
Link the products your app uses. Most apps need PayCheckout, PayCore, and PayElements, plus PayDropIn for the drop-in. PayCheckout doesn't re-export PayCore, so an app that names PayResult, PayError, or PaymentIDs must also import PayCore:
| Product | What it contains |
|---|---|
PayCheckout | The headless checkout (PayCheckout and its Configuration, PaySession, PayPaymentMethod, PaySavedPaymentMethod, PayPaymentRequest, PayApplePayConfiguration, and PayCheckout.handleReturn). Depends on PayCore, PayElements, PayThreeDS, and PayCSE, but doesn't re-export them. |
PayCore | Shared types (PayResult, PaymentIDs, PayError, PayEnvironment, PayCardFieldKind, ClientSecret, and PaySDK). |
PayElements | The SDK-owned UIKit card inputs (PayCardNumberField, PayExpiryField, PayCVCField, and PayNameField), grouped by PayCardFields, and their style, PayFieldStyle. |
PayDropIn | PayDropIn, a ready-made payment sheet over a PayCheckout with the Apple Pay button, a returning customer's saved methods, the card and redirect methods, the card form, the save-card switch, and the Pay button. PayDropInAppearance and PayDropInStrings change its look and its text. Depends on PayCheckout, PayCore, and PayElements. |
PayThreeDS | Internal module used by PayCheckout to run the 3DS Method step and 3DS challenge web views. |
PayCSE | Client-side encryption of card data. PayCheckout uses it when clientSideEncryption is on, and a card form of your own can use it directly. See Client-side encryption on mobile. |
PayLinkOut | PayLinkOut opens a checkout your server created in the browser app when the App Store's rules allow it and reports how the customer came back. Standalone product with no SDK dependencies. |
How a payment works
A payment takes these steps:
- Your server creates a payment session with Create a payment session and sends only its
client_secretto the app. - The app starts a checkout with that
client_secret. - The app presents the drop-in, or builds its own screen from the session's payment methods, the card fields, and an Apple Pay button.
- The SDK sends the card or the Apple Pay token to Pay.com, runs 3DS when the session asks for it, and presents any challenge or redirect.
- The drop-in or
payreturns aPayResult. Treat it as a hint for your UI. Your server confirms the payment with Retrieve a payment session or thepayment_session.completedwebhook before it fulfills the order. For a setup session, it uses Retrieve a setup session or thesetup_session.completedwebhook.
A setup session saves a payment method instead of paying. A payout setup session lets the customer choose where their payouts go. See Let customers choose a payout method.