Airwallex logo

Airwallex iOS SDK

Copy for LLMView as Markdown

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

iOS Recurring 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.

swift
1let paymentConsentOptions = PaymentConsentOptions(
2 nextTriggeredBy: .customer, // or .merchant
3 merchantTriggerReason: .unscheduled // or .scheduled
4)
5
6let session = Session(
7 paymentIntent: paymentIntent,
8 countryCode: "Your country code",
9 paymentConsentOptions: paymentConsentOptions, // Required for recurring
10 returnURL: "myapp://payment/return"
11)

Present payment flow

Present the payment flow using AWXUIContext:

swift
1let configuration = AWXUIContext.Configuration()
2configuration.layout = .tab // or .accordion
3configuration.launchStyle = .push // or .present
4
5AWXUIContext.launchPayment(
6 from: "hosting view controller which also handles AWXPaymentResultDelegate",
7 session: session,
8 configuration: configuration
9)

Handle authentication result

In AWXPaymentResultDelegate, handle authentication result to present it to the shopper:

swift
1func paymentViewController(_ controller: UIViewController?, didCompleteWith status: AirwallexPaymentStatus, error: Error?) {
2 // call back for status success / in progress / failure / cancel
3}

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:

swift
1func paymentViewController(_ controller: UIViewController?, didCompleteWithPaymentConsentId paymentConsentId: String) {
2 // Store consent ID for future payments
3}

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)

iOS Recurring CIT (card)

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.

swift
1let session = Session(
2 paymentIntent: paymentIntent,
3 countryCode: "Your country code",
4 // paymentConsentOptions is nil for one-off transactions
5 returnURL: "myapp://payment/return"
6)

Present payment flow

Present the payment flow using AWXUIContext. The SDK will automatically display saved cards for the customer:

swift
1let configuration = AWXUIContext.Configuration()
2configuration.layout = .tab // or .accordion
3configuration.launchStyle = .push // or .present
4
5AWXUIContext.launchPayment(
6 from: "hosting view controller which also handles AWXPaymentResultDelegate",
7 session: session,
8 configuration: configuration
9)

Handle payment result

After the PaymentIntent is confirmed by SDK, this delegate will be called by the SDK automatically:

swift
1func paymentViewController(_ controller: UIViewController?, didCompleteWith status: AirwallexPaymentStatus, error: Error?) {
2 // call back for status success / in progress / failure / cancel
3}

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)

MIT (card & E-wallet)

For merchant-initiated transactions (subscriptions, auto-debit), the payment is processed entirely on the server side.

  1. From your server, Create a Payment Intent API to request for a subsequent payment.

  2. Confirm the Payment Intent API with reference to Payment Consent ID of the stored Payment Consent.

Was this page helpful?