ios - 我如何获得 Charge 以及如何通过令牌 ID 快速收费(IOS)
问题描述
如何快速生成条带令牌ID,收费ID。请问,有人可以帮助快速生成条带支付吗?
解决方案
先做条带支付配置
let configuration = STPPaymentConfiguration.shared()
configuration.additionalPaymentMethods = .all
configuration.appleMerchantIdentifier = "Your stripe identifier"
configuration.canDeletePaymentMethods = true
configuration.createCardSources = false
let customerContext = STPCustomerContext(keyProvider: MyAPIClient.sharedClient)
paymentMethodViewController = STPPaymentMethodsViewController(configuration: configuration,
theme: STPTheme.init(),
customerContext: customerContext,
delegate: self)
self.navigationController?.pushViewController(controller, animated: true)
ApiClient 生成临时密钥的代码
class MyAPIClient: NSObject, STPEphemeralKeyProvider {
static let sharedClient = MyAPIClient()
func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
let url = AppConstant.Server.EPHERMAL_KEY
let user = UserDefaultManager.shared.readUser()
let header: HTTPHeaders = ["api_token": user.apiToken ?? "",
"Content-Type": "application/json"]
Alamofire.request(url,
method: .get,
parameters: [
"api_version": apiVersion,
"id": user.id ?? -1
],
headers: header)
.validate(statusCode: 200..<300)
.responseJSON { responseJSON in
switch responseJSON.result {
case .success(let json):
completion(json as? [String: AnyObject], nil)
case .failure(let error):
completion(nil, error)
}
}
}
}
然后在委托方法中
func paymentMethodsViewController(_ paymentMethodsViewController: STPPaymentMethodsViewController, didSelect paymentMethod: STPPaymentMethod) {
var paymentStripeId: String?
if let source = paymentMethod as? STPSource {
paymentStripeId = source.stripeID
} else if let card = paymentMethod as? STPCard {
self.stpCard = card
}
}
推荐阅读
- sql - 如何将 ISNULL() 函数与 join 一起使用
- c++ - 从另一个文件夹配置时,Automake 使用源的绝对路径
- python-3.x - 当在 ODOO 12 中创建模型 B 的新实例(模型 A 具有 many2one 字段)时,如何更改模型 A 中的布尔值?
- java - 如何让后台任务在地图上移动标记
- git - Visual Studio Code 和 git:X 的权限被拒绝
- tensorflow - 方向敏感图像数据的问题
- asp.net - ASP Core 3 上的 JWT + SignalR 导致 401 Unauthorized
- reactjs - 我们如何访问和获取传递给组件的 props (wrapper.props().propname) 总是返回 undefined
- python - Python:将xml展平为csv,父标签在子标签中重复
- java - 有没有办法将字符串数组作为服务器端 Xquery 脚本的变量传递?