Swiftpack.co - airwallex/airwallex-payment-ios as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by airwallex.
airwallex/airwallex-payment-ios 3.0.2
Airwallex PA iOS SDK
⭐️ 0
🕓 2 weeks ago
.package(url: "https://github.com/airwallex/airwallex-payment-ios.git", from: "3.0.2")

Airwallex iOS SDK

Pod Version Pod Platform Pod License Carthage compatible CocoaPods compatible

The Airwallex iOS SDK is a framework for integrating easy, fast and secure payments inside your app with Airwallex. It provides simple functions to send sensitive credit card data directly to Airwallex, it also provides a powerful, customizable interface src="https://raw.github.com/airwallex/airwallex-payment-ios/master/ollecting user payment details.

AWXShippingViewController AWXCardViewController AWXPaymentViewController

Get started with our integration guide and example project.

Table of contents


The Airwallex iOS SDK requires Xcode 11.0 or later and is compatible with apps targeting iOS 11.0 or above.



Airwallex for iOS is available through either CocoaPods or Carthage.

If you haven't already, install the latest version of CocoaPods. If you don't have an existing Podfile, run the following command to create one:

pod init

Add this line to your Podfile:

pod 'Airwallex'

Run the following command

pod install

Don’t forget to use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on out. In the feature, to update to the latest version of the SDK, just run:

pod update Airwallex


github "airwallex/airwallex-payment-ios"


Even though Airwallex is written in Objective-C, it can be used in Swift with no hassle. If you use CocoaPods, add the following line to your Podfile:


Basic Integration

When your app starts, configure the SDK with mode.

[Airwallex setMode:AirwallexSDKStagingMode]; // AirwallexSDKDemoMode, AirwallexSDKStagingMode, AirwallexSDKProductionMode

If you want to test on different endpoint, you can customize mode and payment URL.

[Airwallex setDefaultBaseURL:[NSURL URLWithString:@”Airwallex payment base URL”]];
  • Create a payment intent

When the customer wants to checkout an order, you should create a payment intent on your server-side and then pass the payment intent to the mobile-side to confirm the payment intent with the payment method selected.

[AWXAPIClientConfiguration sharedConfiguration].clientSecret = "The payment intent's client secret";

Note: When checkoutMode is AirwallexCheckoutRecurringMode, no need to create payment intent, then you need generate client secret with customer id and pass it to AWXAPIClientConfiguration.

[AWXAPIClientConfiguration sharedConfiguration].clientSecret = "The client secret generated with customer id";
  • Create session

If you want to make one-off payment, create one-off session.

AWXOneOffSession *session = [AWXOneOffSession new];
session.countryCode = "Your country code";
session.billing = "Your shipping address";
session.returnURL = "App return url";
session.paymentIntent = "Payment intent";

If you want to make recurring, create recurring session.

AWXRecurringSession *session = [AWXRecurringSession new];
session.countryCode = "Your country code";
session.billing = "Your shipping address";
session.returnURL = "App return url";
session.currency = "Currency code";
session.amount = "Total amount";
session.customerId = "Customer id";
session.nextTriggerByType = "customer or merchant";
session.requiresCVC = "Whether it requires CVC";
session.merchantTriggerReason = "Unscheduled or scheduled";

If you want to make recurring with payment intent, create recurring with intent session.

AWXRecurringWithIntentSession *session = [AWXRecurringWithIntentSession new];
session.countryCode = "Your country code";
session.billing = "Your shipping address";
session.returnURL = "App return url";
session.paymentIntent = "Payment intent";
session.nextTriggerByType = "customer or merchant";
session.requiresCVC = "Whether it requires CVC";
session.merchantTriggerReason = "Unscheduled or scheduled";
  • Handle the one-off payment or recurring flow

Add a button to let the customer enter or change their payment method. When tapped, use AWXUIContext to present the payment flow.

AWXUIContext *context = [AWXUIContext sharedContext];
context.delegate = ”The target to handle AWXPaymentResultDelegate protocol”;
context.session = session;
[context presentPaymentFlowFrom:self];
  • Handle the payment result

After the user completes the payment successfully or with error, you need to handle the payment result.

#pragma mark - AWXPaymentResultDelegate

- (void)paymentViewController:(UIViewController *)controller didCompleteWithStatus:(AirwallexPaymentStatus)status error:(nullable NSError *)error
    [controller dismissViewControllerAnimated:YES completion:^{
        // Status may be success/in progress/ failure / cancel

Set Up WeChat Pay

After completing payment, WeChat will be redirected to the merchant's app and do a callback using onResp(), then it can retrieve the payment intent status after the merchant server is notified, so please keep listening to the notification.

@interface AppDelegate () <WXApiDelegate>


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    [WXApi registerApp:@"WeChat app id" universalLink:@"https://airwallex.com/"];
    return YES;

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
    return [WXApi handleOpenURL:url delegate:self];

 You can retrieve the payment intent status after your server is notified
- (void)onResp:(BaseResp *)resp
    if ([resp isKindOfClass:[PayResp class]]) {
        NSString *message = nil;
        PayResp *response = (PayResp *)resp;
        switch (response.errCode) {
            case WXSuccess:
                message = NSLocalizedString(@"Succeed to pay", nil);
            case WXErrCodeUserCancel:
                message = NSLocalizedString(@"User cancelled.", nil);
                message = NSLocalizedString(@"Failed to pay", nil);
        UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil
        [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Close", nil) style:UIAlertActionStyleCancel handler:nil]];
        [self.window.rootViewController presentViewController:controller animated:YES completion:nil];


Theme Color

You can customize the theme color.

UIColor *tintColor = [UIColor colorWithRed:97.0f/255.0f green:47.0f/255.0f blue:255.0f/255.0f alpha:1];
[AWXTheme sharedTheme].tintColor = tintColor;
[UIView.appearance setTintColor:tintColor];


To run the example project, you should follow these steps.

  • Preparing
  1. Install the lastest version of Xcode and iOS SDK from Mac Store.

  2. Install Bundle

gem install bundler
  • Clone source code

Run the following script to clone this project to your local disk.

git clone git@github.com:airwallex/airwallex-payment-ios.git
  • Install dependencies and open project
  1. Go into the project directory
cd airwallex-payment-ios
  1. Install dependencies
bundle install
pod install
  1. Open Airwallex.xcworkspace from Xcode or run the following script to open it. Be sure you always open the project from the work space.
open Airwallex.xcworkspace
  • Build Configurations

There are two schemes Airwallex and Examples. You can switch the schemes in project scheme settings.

Airwallex will generate a framework for developer

Examples will build and run an example application

  • Run the app on your iOS device

Select your target device from the top left panel, then press "Command + R" on your keyboard (or "Product > Run" from the top menu bar) to run this project on your iOS device.


We welcome contributions of any kind including new features, bug fixes, and documentation improvements. The best way to contribute is by submitting a pull request – we'll do our best to respond to your patch as soon as possible. You can also submit an issue if you find bugs or have any questions.


Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics