iOS SDK
When capturing a Stored Credential for the first time

-
Create a customer object and pass it to your server if it is a new customer. Recurring payment requires a customer ID to be initiated.
From your server, Create a Customer API with customer data received from client app and save the
Customer IDreturned. -
(Optional) If the shopper wishes to pay for the first order
Your client app will need a
PaymentIntentto form a payment session for Airwallex SDK to present payment flow.From your server, access Airwallex API to Create a Payment Intent API and pass the
PaymentIntentreturned to client app. -
Create an
AWXRecurringSession(if No payment is to be made here), or anAWXRecurringWithIntentSession(ifPayment Intentwas created for this order)Parameters required when creating a
Sessionare listed as follows:AWXRecurringSessionswift1let session = AWXRecurringSession()2session.setCurrency(ExamplesKeys.currency)3session.setAmount(NSDecimalNumber(string: ExamplesKeys.amount))4session.setCustomerId(ExamplesKeys.customerId)5session.nextTriggerByType = ExamplesKeys.nextTriggerByType6session.merchantTriggerReason = .unscheduled7session.countryCode = ExamplesKeys.countryCode8session.returnURL = ExamplesKeys.returnUrlAWXRecurringWithIntentSessionswift1let session = AWXRecurringWithIntentSession()2session.paymentIntent = paymentIntent3session.nextTriggerByType = ExamplesKeys.nextTriggerByType4session.autoCapture = ExamplesKeys.autoCapture5session.merchantTriggerReason = .scheduled6session.countryCode = ExamplesKeys.countryCode7session.returnURL = ExamplesKeys.returnUrl -
Present payment/authentication flow by creating an
AWXUIContextwith the Session created in the last stepswift1AWXUIContext.launchPayment(2 from: "hosting view controller which also handles AWXPaymentResultDelegate",3 session: "The session created above",4 filterBy: "An optional array of payment method names used to filter the payment methods returned by the server",5 launchStyle: ".push/.present",6 layout: ".tab/.accordion"7) -
Handle authentication result
In
AWXPaymentResultDelegate, handle authentication result to present it to the shopper.swift1# MARK: - AWXPaymentResultDelegate2func paymentViewController(_ controller: UIViewController?, didCompleteWith status: AirwallexPaymentStatus, error: Error?) {3 // call back for status success/in progress/ failure / cancel4}If
PaymentIntentwas created for this order, retrieve the Payment Intent API from your server to query payment result and pass it to client app.
When initiating a subsequent one-click transaction (CIT)

-
Create a
Payment IntentYour client app will need a
PaymentIntentto form a payment session for Airwallex SDK to present payment flow.From your server, access Airwallex API to Create a Payment Intent API and pass the
PaymentIntentreturned to client app. -
Create an
AWXOneOffSessionwith thePaymentIntentcreated in the previous step, areturnURLto your app, and shipping address and shopper country code of this order.swift1let session = AWXOneOffSession()2session.countryCode = "Your country code"3session.billing = "Your shipping address"4session.returnURL = "App return url"5session.paymentIntent = "payment intent"6session.countryCode = "countryCode"7session.returnURL = "universalLink of your app - required for payments like wechat pay" -
Present payment flow by with the
Sessioncreated in the previous step, Airwallex SDK will handle the rest of the payment process and let you know when the payment flow is completed or cancelled.swift1AWXUIContext.launchPayment(2 from: "hosting view controller which also handles AWXPaymentResultDelegate",3 session: "The session created above",4 filterBy: "An optional array of payment method names used to filter the payment methods returned by the server",5 launchStyle: ".push/.present",6 layout: ".tab/.accordion"7) -
Query and present payment result
After the
PaymentIntentis confirmed by SDK, this delegate will be called by the SDK automatically and you can check the status to see whether the payment process has been completed or not.swift1# MARK: - AWXPaymentResultDelegate2func paymentViewController(_ controller: UIViewController?, didCompleteWith status: AirwallexPaymentStatus, error: Error?) {3 // call back for status success/in progress/ failure / cancel4}Note that 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 thePaymentIntent.On your server, retrieve the Payment Intent API, get the payment result within it and pass it to client app.
When initiating a subsequent subscription and auto-debit transaction (MIT)

-
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