如何在swift(IOS)中获得费用以及如何将令牌id传递给费用
如何在swift中生成条带令牌id、费用id。请问,有人能在swift中帮助生成条带支付吗?首先进行条带支付配置如何在swift(IOS)中获得费用以及如何将令牌id传递给费用,ios,swift,iphone,stripe-payments,Ios,Swift,Iphone,Stripe Payments,如何在swift中生成条带令牌id、费用id。请问,有人能在swift中帮助生成条带支付吗?首先进行条带支付配置 let configuration = STPPaymentConfiguration.shared() configuration.additionalPaymentMethods = .all configuration.appleMerchantIdentifier = "Your stripe identifier" configura
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生成ephermal密钥的代码
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)
}
}
}
试试这个方法。从条纹文件
let cardParams = STPCardParams()
cardParams.number = "4242424242424242"
cardParams.expMonth = 10
cardParams.expYear = 2021
cardParams.cvc = "123"
STPAPIClient.shared().createToken(withCard: cardParams) { (token: STPToken?, error: Error?) in
guard let token = token, error == nil else {
// Present error to user...
return
}
submitTokenToBackend(token, completion: { (error: Error?) in
if let error = error {
// Present error to user...
}
else {
// Continue with payment...
}
})
}
我没有获得AppConstant.Server.EPHERMAL_密钥EPHERMAL_密钥是后端开发人员提供给您的url。没有url,我可以进行条带支付吗?我可以像在ios中那样执行以下操作吗?获取此错误条带卡。validateCardReturningError(&UnderlineError)您可以为我提供一个示例项目吗
let cardParams = STPCardParams()
cardParams.number = "4242424242424242"
cardParams.expMonth = 10
cardParams.expYear = 2021
cardParams.cvc = "123"
STPAPIClient.shared().createToken(withCard: cardParams) { (token: STPToken?, error: Error?) in
guard let token = token, error == nil else {
// Present error to user...
return
}
submitTokenToBackend(token, completion: { (error: Error?) in
if let error = error {
// Present error to user...
}
else {
// Continue with payment...
}
})
}