Airwallex iOS SDK
This guide covers how to handle recurring payments and saved payment methods for registered users using the Airwallex iOS SDK.
Capturing a stored credential for the first time

Prepare payment session
Follow Prepare payment session to create a customer, payment intent, and payment session.
You must set PaymentConsentOptions when creating the payment session to save payment method for future payment.
1let paymentConsentOptions = PaymentConsentOptions(2 nextTriggeredBy: .customer, // or .merchant3 merchantTriggerReason: .unscheduled // or .scheduled4)56let session = Session(7 paymentIntent: paymentIntent,8 countryCode: "Your country code",9 paymentConsentOptions: paymentConsentOptions, // Required for recurring10 returnURL: "myapp://payment/return"11)
Present payment flow
Present the payment flow using AWXUIContext:
1let configuration = AWXUIContext.Configuration()2configuration.layout = .tab // or .accordion3configuration.launchStyle = .push // or .present45AWXUIContext.launchPayment(6 from: "hosting view controller which also handles AWXPaymentResultDelegate",7 session: session,8 configuration: configuration9)
Handle authentication result
In AWXPaymentResultDelegate, handle authentication result to present it to the shopper:
1func paymentViewController(_ controller: UIViewController?, didCompleteWith status: AirwallexPaymentStatus, error: Error?) {2 // call back for status success / in progress / failure / cancel3}
If the payment consent is created during payment process, you can implement this optional function to get the ID of this payment consent for future use:
1func paymentViewController(_ controller: UIViewController?, didCompleteWithPaymentConsentId paymentConsentId: String) {2 // Store consent ID for future payments3}
Retrieve the Payment Intent API from your server to query payment result and pass it to client app.
Initiating a subsequent one-click transaction (CIT)

For subsequent payments where the customer initiates the transaction using a saved payment method.
Prepare payment session
Follow Prepare payment session to create a payment intent and payment session.
For subsequent one-off transactions, leave paymentConsentOptions as nil when creating the payment session.
1let session = Session(2 paymentIntent: paymentIntent,3 countryCode: "Your country code",4 // paymentConsentOptions is nil for one-off transactions5 returnURL: "myapp://payment/return"6)
Present payment flow
Present the payment flow using AWXUIContext. The SDK will automatically display saved cards for the customer:
1let configuration = AWXUIContext.Configuration()2configuration.layout = .tab // or .accordion3configuration.launchStyle = .push // or .present45AWXUIContext.launchPayment(6 from: "hosting view controller which also handles AWXPaymentResultDelegate",7 session: session,8 configuration: configuration9)
Handle payment result
After the PaymentIntent is confirmed by SDK, this delegate will be called by the SDK automatically:
1func paymentViewController(_ controller: UIViewController?, didCompleteWith status: AirwallexPaymentStatus, error: Error?) {2 // call back for status success / in progress / failure / cancel3}
A completed flow does NOT imply a successful transaction. You need to query the payment result afterwards through your server to know whether the order is paid or not. Inside AWXPaymentResultDelegate, ask your server to retrieve the PaymentIntent.
On your server, retrieve the Payment Intent API, get the payment result within it and pass it to client app.
Initiating a subsequent subscription and auto-debit transaction (MIT)

For merchant-initiated transactions (subscriptions, auto-debit), the payment is processed entirely on the server side.
-
From your server, Create a Payment Intent API to request for a subsequent payment.
-
Confirm the Payment Intent API with reference to Payment Consent ID of the stored Payment Consent.