Adyen iOS 为您提供构建模块,为您的购物者创建结账体验,允许他们使用他们选择的付款方式进行付款。
您可以通过两种方式与 Adyen iOS 集成
| 主版本 | 状态 | 已弃用 | 生命周期结束 |
|---|---|---|---|
| 5.x.x | 活动 | --- | --- |
| 4.x.x | 非活动 | 待定 | 待定 |
| 3.x.x | 已弃用 | 2021 年 11 月 | 2022 年 11 月 |
有关我们版本控制和 Drop-in/组件生命周期的更多信息,请参见此处。
Adyen iOS 可通过 CocoaPods、Carthage 或 Swift Package Manager 获得。
pod 'Adyen' 添加到您的 Podfile。pod install。您可以安装所有模块或添加单个模块,具体取决于您的需求和集成类型。 需要显式添加 Adyen/WeChatPay 模块以支持微信支付。 需要显式添加 Adyen/SwiftUI 模块以使用 SwiftUI 特定助手。
pod 'Adyen' // Add DropIn with all modules except WeChat Pay and SwiftUI.
// Add individual modules
pod 'Adyen/Card' // Card components.
pod 'Adyen/Session' // Handler for the simplified checkout flow.
pod 'Adyen/Encryption' // Encryption module.
pod 'Adyen/Components' // All other payment components except WeChat Pay.
pod 'Adyen/Actions' // Action Components.
pod 'Adyen/WeChatPay' // WeChat Pay Component.
pod 'Adyen/SwiftUI' // SwiftUI apps specific module.
Adyen/AdyenWeChatPay 和 AdyenWeChatPayInternal 模块不支持任何模拟器,只能在真机上进行测试。
github "adyen/adyen-ios" 添加到您的 Cartfile。carthage update。您可以添加所有模块或选择单个模块添加到您的集成中。 但请确保包含每个模块的依赖模块。
AdyenDropIn:DropInComponent。AdyenSession:简化结帐流程的处理程序。AdyenCard:卡片组件。AdyenComponents:除微信支付外的所有其他支付组件。AdyenActions:操作组件。AdyenEncryption:加密。AdyenWeChatPay:微信支付组件。AdyenWeChatPayInternal:微信支付组件。AdyenTwint:Twint 组件。AdyenSwiftUI:SwiftUI 应用程序特定的模块。
AdyenWeChatPay 和 AdyenWeChatPayInternal 模块不支持任何模拟器,只能在真机上进行测试。
https://github.com/Adyen/adyen-ios 作为存储库 URL。4.9.0。您可以添加所有模块或选择单个模块添加到您的集成中。 需要显式添加 AdyenWeChatPay 模块以支持微信支付。 需要显式添加 AdyenTwint 模块以支持 Twint 原生流程。 需要显式添加 AdyenSwiftUI 模块以使用 SwiftUI 特定助手。
AdyenDropIn:除 AdyenWeChatPay 之外的所有模块。AdyenSession:简化结帐流程的处理程序。AdyenCard:卡片组件。AdyenComponents:除微信支付外的所有其他支付组件。AdyenActions:操作组件。AdyenEncryption:加密。AdyenWeChatPay:微信支付组件。AdyenTwint:Twint 组件。AdyenSwiftUI:SwiftUI 应用程序特定的模块。
AdyenWeChatPay 和 AdyenWeChatPayInternal 模块不支持任何模拟器,只能在真机上进行测试。
Drop-in 处理可用付款方式的展示以及随后客户付款详细信息的输入。 它使用 /sessions 的响应进行初始化,并在后台处理整个结账流程。
所有组件都需要一个 AdyenContext。 AdyenContext 的实例包装您的客户端密钥、环境、分析配置等等。 请在此处阅读有关 客户端密钥以及如何获取密钥的更多信息。 环境请使用 Environment.test。 当您准备好接受实时付款时,请将值更改为我们的 实时环境之一
let apiContext = try! APIContext(environment: componentsEnvironment, clientKey: clientKey)
let context = AdyenContext(apiContext: apiContext,
payment: payment)
let configuration = DropInComponent.Configuration()
使用从 /sessions 调用收到的响应和 AdyenContext 实例创建 AdyenSession.Configuration 的实例。
let configuration = AdyenSession.Configuration(sessionIdentifier: response.sessionId,
initialSessionData: response.sessionData,
context: context)
通过提供配置和委托,调用 AdyenSession 的静态 initialize 函数,这将异步创建并返回会话实例。
AdyenSession.initialize(with: configuration, delegate: self, presentationDelegate: self) { [weak self] result in
switch result {
case let .success(session):
// store the session object
self?.session = session
case let .failure(error):
// handle the error
}
}
为 DropInComponent 创建配置对象。 检查特定的付款方式页面,以确认是否需要包含其他必需的参数。
// Check specific payment method pages to confirm if you need to configure additional required parameters.
let dropInConfiguration = DropInComponent.Configuration()
某些付款方式需要其他配置。 例如 ApplePayComponent。 这些特定于付款方式的配置参数可以在 DropInComponent.Configuration 的实例中设置
let summaryItems = [
PKPaymentSummaryItem(label: "Item A", amount: 75, type: .final),
PKPaymentSummaryItem(label: "Item B", amount: 25, type: .final),
PKPaymentSummaryItem(label: "My Company", amount: 100, type: .final)
]
let applePayment = try ApplePayPayment(countryCode: "US",
currencyCode: "USD",
summaryItems: summaryItems)
dropInConfiguration.applePay = .init(payment: applePayment,
merchantIdentifier: "merchant.com.adyen.MY_MERCHANT_ID")
此外,对于像 Doku 变体这样的凭证付款方式,为了让 DokuComponent 能够让购物者保存凭证,需要请求访问购物者照片,因此需要在应用程序 Info.plist 中的 NSPhotoLibraryAddUsageDescription 键中添加合适的文本。
初始化 DropInComponent 类,并将 AdyenSession 实例设置为 DropInComponent 实例的 delegate 和 partialPaymentDelegate(如果需要)。
let dropInComponent = DropInComponent(paymentMethods: session.sessionContext.paymentMethods,
context: context,
configuration: dropInConfiguration)
// Keep the Drop-in instance to avoid it being destroyed after the function is executed.
self.dropInComponent = dropInComponent
// Set session as the delegate for Drop-in
dropInComponent.delegate = session
dropInComponent.partialPaymentDelegate = session
present(dropInComponent.viewController, animated: true)
AdyenSession 进行必要的调用来处理整个流程,并通过其委托 AdyenSessionDelegate 通知您的应用程序。 为了处理 Drop-in 的结果,应实现 AdyenSessionDelegate 的以下方法
func didComplete(with result: AdyenSessionResult, component: Component, session: AdyenSession)
当组件完成且应用程序不需要任何进一步步骤时,将调用此方法。 应用程序只需要关闭当前组件,理想情况下是在调用组件上的 finalizeIfNeeded 之后。
func didFail(with error: Error, from component: Component, session: AdyenSession)
当在使用 Drop-in 或组件期间发生错误时,将调用此方法。 然后,您可以调用组件上的 finalizeIfNeeded,在完成回调中关闭组件的视图控制器,并显示一条错误消息。
func didOpenExternalApplication(component: DropInComponent)
在重定向到外部应用程序后,将调用此可选方法。
操作由 Drop-in 通过其委托 AdyenSession 处理。
如果客户被重定向到外部 URL 或应用程序,请确保在用户返回到您的应用程序时通知 RedirectComponent。 通过在您的 UIApplicationDelegate 中实现以下内容来完成此操作
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
RedirectComponent.applicationDidOpen(from: url)
return true
}
为了在结帐流程中拥有更大的灵活性,您可以使用我们的组件单独呈现每种付款方式。 有关我们组件的实现细节,请参见我们的 组件 API 参考。
Drop-in 和组件都提供了许多定制选项,让您可以匹配您应用程序的外观。 例如,要将 Drop-in 中的节标题标题和表单字段标题更改为红色,并将提交按钮的背景变为黑色,前景变为白色
var style = DropInComponent.Style()
style.listComponent.sectionHeader.title.color = .red
style.formComponent.textField.title.color = .red
style.formComponent.mainButtonItem.button.backgroundColor = .black
style.formComponent.mainButtonItem.button.title.color = .white
let dropInComponent = DropInComponent(paymentMethods: paymentMethods,
configuration: configuration,
style: style)
dropInComponent.delegate = self.session
或者,创建一个带有白色文本的黑色卡片组件
var style = FormComponentStyle()
style.backgroundColor = .black
style.header.title.color = .white
style.textField.title.color = .white
style.textField.text.color = .white
style.switch.title.color = .white
let component = CardComponent(paymentMethod: paymentMethod,
apiContext: context.apiContext,
style: style)
component.delegate = self.session
完整的自定义选项列表可以在 API 参考中找到。
如果您有功能请求,或者发现了一个错误或技术问题,请创建一个 GitHub issue。 对于其他问题,请联系我们的支持团队。
我们强烈建议您加入我们,为这个存储库做出贡献,这样每个人都可以从以下方面受益
阅读我们的贡献指南,了解如何参与。
此存储库是开源的,并根据 MIT 许可证提供。 有关更多信息,请参见 LICENSE 文件。