PayCheckout
Reference for the iOS checkout's methods, and the session, payment method, and saved payment method types they use.
PayCheckout is the headless checkout for one payment or setup session. It runs on the main actor. The module doesn't re-export PayCore. To name PayResult, PayError, or PaymentIDs, also import PayCore.
import PayCheckout
let checkout = try await PayCheckout(clientSecret: clientSecret, configuration: .init(returnURL: returnURL))
let methods = checkout.paymentMethods()
let result = try await checkout.pay(.card(cardFields), presenter: self)Methods
A PayCheckout has these methods and properties.
| Member | What it does |
|---|---|
PayCheckout(clientSecret:configuration:) | Starts a checkout by validating the client_secret and loading the session. |
session, configuration | The session the checkout loaded, and the configuration you passed. |
paymentMethods(), acceptedCardBrands | The payment methods and card brands the session accepts. |
pay(_:presenter:) | Pays with the card fields, an alternative method, a saved method, or an Apple Pay payment. |
refreshSession() | Reads the amount and currency again, after your server changed them. |
PayCheckout.handleReturn(_:) | Takes the URLs your app is opened with, so redirects that come back to it finish. |
canPayWithApplePay(_:), payWithApplePay(_:presenter:termsAccepted:) | Tells whether to offer Apple Pay, and pays with it. |
applePayPaymentRequest(_:) | Builds the session's Apple Pay request, for your own PassKit code. |
savedPaymentMethods() | The customer's saved methods in a setup session, or the saved methods a sale or authorization session can pay. |
requiresCVC(for:) | Whether paying a saved card needs its CVV. |
removeSavedPaymentMethod(_:) | Deletes one of them. |
Single-method types are documented on each method's page (PayCheckout.Configuration on Start a checkout, PayPaymentRequest on Pay, and PayApplePayConfiguration on Pay with Apple Pay).
PaySession
checkout.session describes the session the checkout loaded, with the amount and currency the SDK last read:
| Property | Type | Description |
|---|---|---|
id | String | The session's ID. |
kind | PaySession.Kind | .sale (charge now), .authorization (authorize now, capture later from your server), .setup (save a payment method without paying), or .unknown, a flow this SDK doesn't recognize. It may charge, so its total is checked as a sale's is. |
amount | String? | The amount as the client API sends it (a decimal string in major units, for example "10.00"). This differs from the minor units you send when you create the session. |
currency | String? | ISO 4217 alpha-3 currency code. |
isLive | Bool | Whether the session is live. |
expiresAt | Date? | When the client_secret stops working. |
setupFutureUsage | String? | The session's setup_future_usage (on_session or off_session), when set. |
isRecurring | Bool | true for a recurring session, whose card is always kept for later charges. |
isPayout | Bool | true for a setup session your server created with payout: true, where the customer chooses where payouts go. See Let customers choose a payout method. |
PayPaymentMethod
A payment method the session accepts, from paymentMethods(). The drop-in's beforePay receives one too.
| Property | Type | Description |
|---|---|---|
type | String | The API's payment method type, such as card, applepay, googlepay, paypal, or ideal. |
kind | PayPaymentMethod.Kind | .card, .wallet (applepay and googlepay), or .alternative (every other type). |
PaySavedPaymentMethod
A payment method saved for the customer, from savedPaymentMethods(). It's Identifiable by its id, and Hashable.
| Property | Type | Description |
|---|---|---|
id | String | The saved method's ID. |
type | String | Its type, for example card, us_bank_account, paypal, or cashapp. |
isDefault | Bool | true for the customer's default method. |
card | PaySavedPaymentMethod.Card? | Card details (brand as the API names it, last4, expiryMonth, expiryYear, and issuerName, the issuing bank's name when Pay.com knows it, each a String?). Its cardBrand is the brand as a PayCardBrand, for a PayCVCField's brand. |
bankAccount | PaySavedPaymentMethod.BankAccount? | Bank account details (bankName, last4, country, and currency, each a String?). |
email | String? | The account's email, for methods that have one, such as PayPal. |
details | [String: String] | The method's other details as the API sends them, with snake_case keys and the values as strings, for example payout: "available" on a card that can receive payouts. |