测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可协议 | MIT |
发布上次发布 | 2017年2月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Sergey Pronin 维护。
可以将授权的 PKPayment 对象转换为 Stripe 令牌。
将以下行添加到您的 Podfile 以使用 Swift 3.0
pod 'Stripe_watchOS'
如果您想使用 Swift 2.3 版本,使用以下内容
pod 'Stripe_watchOS', :git => 'https://github.com/appintheair/stripe-watchos-tokenizer.git', :branch => 'swift-2.3'
首先提供您发布的密钥
WatchOSStripeManager.provide(publishableKey: "pk_test_<KEY>")
然后在您的代码中,您可能会创建 PKPayment
(通常在您想出售某物时)。然后显示 PKPaymentAuthorizationController
let request = PKPaymentRequest()
request.merchantIdentifier = "<MERCHANT_ID>"
request.supportedNetworks = [.amex, .masterCard, .visa]
request.merchantCapabilities = [.capability3DS]
request.countryCode = "US"
request.currencyCode = "USD"
request.paymentSummaryItems = [
PKPaymentSummaryItem(label: "App in the Air", amount: NSDecimalNumber(value: 10))
]
let controller = PKPaymentAuthorizationController(paymentRequest: request)
controller.delegate = self
controller.present(completion: nil)
然后,在 PKPaymentAuthorizationControllerDelegate
中处理成功支付授权和生成令牌
func paymentAuthorizationController(_ controller: PKPaymentAuthorizationController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
WatchOSStripeManager.shared.createToken(with: payment) { token, error in
if let error = error {
print(error)
self.handlePaymentFailure()
completion(.failure)
return
}
guard let token = token else { return }
print("TOKEN FOR PAYMENT: \(token.tokenId)")
}
}
Stripe_watchOS 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。