# Airwallex iOS SDK ![Pod Version](https://img.shields.io/cocoapods/v/Airwallex.svg?style=flat) ![Pod Platform](https://img.shields.io/cocoapods/p/Airwallex.svg?style=flat) ![Pod License](https://img.shields.io/cocoapods/l/Airwallex.svg?style=flat) [![CocoaPods compatible](https://img.shields.io/badge/CocoaPods-compatible-green.svg?style=flat)](https://cocoapods.org) - [API Reference](https://airwallex.github.io/airwallex-payment-ios/) Airwallex iOS SDK是一个框架,通过它可以在您的应用程序中轻松,快速和安全地完成付款。它提供了简单的功能,可以将敏感的信用卡数据直接发送到Airwallex,还提供了功能详细的界面,用于收集用户付款明细。
开始使用我们的集成指南和示例项目。 目录 ================= * [要求](#要求) * [整合](#整合) * [CocoaPods](#cocoapods) * [Swift](#swift) * [基本整合](#基本整合) * [设置微信支付](#设置微信支付) * [设置 Apple Pay](#设置-Apple-Pay) * [主题色](#主题色) * [例子](#例子) * [贡献](#贡献) ## 要求 Airwallex iOS SDK 支持 iOS 11.0 及以上版本。 ## 整合 ### CocoaPods Airwallex可通过[CocoaPods](https://cocoapods.org/) 整合。 将此行添加到您的`Podfile`中: ```ruby pod 'Airwallex' ``` 或者,你也可以选择直接安装可选模组(最小化依赖): ```ruby pod 'Airwallex/Core' pod 'Airwallex/Card' pod 'Airwallex/WechatPay' pod 'Airwallex/Redirect' pod 'Airwallex/ApplePay' ``` 运行以下命令: ```ruby pod install ``` ### Swift 即使`Airwallex`是用Objective-C编写的,它也可以轻松地用在Swift中。如果您使用[CocoaPods](https://cocoapods.org/),请将以下行添加到[Podfile](https://guides.cocoapods.org/using/using-cocoapods.html)中: ```ruby use_frameworks! ``` ### 基本整合 启动应用时,请先配置SDK的`mode`. ```objective-c [Airwallex setMode:AirwallexSDKStagingMode]; // AirwallexSDKDemoMode, AirwallexSDKStagingMode, AirwallexSDKProductionMode ``` 如果你想在不同的服务端进行测试,你可以自定义mode和payment URL. ```objective-c [Airwallex setDefaultBaseURL:[NSURL URLWithString:@”Airwallex payment base URL”]]; ``` - 创建payment intent 当客户想要结帐时,您应该在服务器端创建payment intent,然后将payment intent传递给移动端,以所选的付款方式确认payment intent。 ``` [AWXAPIClientConfiguration sharedConfiguration].clientSecret = "The payment intent's client secret"; ``` 注: 当checkoutMode 为AirwallexCheckoutRecurringMode时,我们不需要创建 payment intent,这时你需要使用customer id来创建client secret并传入AWXAPIClientConfiguration。 ``` [AWXAPIClientConfiguration sharedConfiguration].clientSecret = "The client secret generated with customer id"; ``` - 创建session 如果你想完成一次性支付,请创建一次性支付的session。 ``` AWXOneOffSession *session = [AWXOneOffSession new]; session.countryCode = "Your country code"; session.billing = "Your shipping address"; session.returnURL = "App return url"; session.paymentIntent = "Payment intent"; session.autoCapture = "Whether the card payment will be captured automatically (Default YES)"; ``` 如果你想完成订阅,请创建订阅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 (Default NO)"; session.merchantTriggerReason = "Unscheduled or scheduled"; ``` 如果你想完成特定payment intent的订阅,请使用payment 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.autoCapture = "Whether the card payment will be captured automatically (Default YES)"; session.nextTriggerByType = "customer or merchant"; session.requiresCVC = "Whether it requires CVC (Default NO)"; session.merchantTriggerReason = "Unscheduled or scheduled"; ``` - 处理付款流程 在结帐界面中,添加一个按钮,让客户输入或更改他们的付款方式。点击后,用`AWXUIContext`显示付款流程。 ```objective-c AWXUIContext *context = [AWXUIContext sharedContext]; context.delegate = ”The target to handle AWXPaymentResultDelegate protocol”; context.session = session; [context presentPaymentFlowFrom:self]; ``` - 处理付款结果 用户成功完成付款或出现错误后,您需要处理付款结果。 ```objective-c #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 }]; } ``` ### 设置微信支付 付款完成后,微信将重定向到商家的应用程序,并使用onRes()进行回调,然后在通知商家服务器后可以检索payment intent状态,因此请保持监听通知。 ```objective-c @interface AppDelegate ()