iOS Swift无法获得条纹付款令牌
我正在实施Stripe PaymentsDK,并且在实施代码后,我会在控制台中遇到错误,这里是我的代码:
查看控制器类
func stripPayment(CVC:String){
// Initiate the card
let stripCard = STPCardParams()
if cardMM == "" && cardYY == "" {
// Send the card info to Strip to get the token
stripCard.number=card_number
stripCard.name=card_name
stripCard.cvc=CVC
stripCard.expYear=UInt(cardYY)!
stripCard.expMonth=UInt(cardMM)!
}
print("card_number:",card_number)
print("card_name:",card_name)
print("CVC:",CVC)
print("cardYY:",cardYY)
print("cardMM:",cardMM)
STPAPIClient.shared.createToken(withCard: stripCard) { (token: STPToken?, error: Error?) in
print("Printing Strip response:\(String(describing: token?.allResponseFields))\n\n")
print("Printing Strip Token:\(String(describing: token?.tokenId))")
if error != nil {
print(error)
print(error?.localizedDescription ?? "")
}
if token != nil{
print("Token:",token!.tokenId)
self.placeOrderApi(tokenStripe: token!.tokenId, completion: {
self.pushVC(id: "PaymentConfirmationVCID")
})
}
}
}
app app did finishlaunch
STPAPIClient.shared.publishableKey = "pk_test_51KuLPhJ4jB1YaTRoUayoteEXbtl5QvbayNeDDhjv4Nto9UvdM4LcTsP2EXAbU0IuOoKsIsOAk565HzvjLRPVP9wY00Ro5T3PYq"
错误我正在进入控制台
打印条件令牌:零 可选(错误域= com.stripe.lib code = 50“存在意外错误 - 在几秒钟内重试错误 - 在几秒钟内重试,com.stripe.lib:errormessagekey =丢失必需参数:card [number]。,com.stripe.lib:stripeerrortypekey = invalid_request_error,com.stripe.lib:stripeerrorcodekey = parameter_missing}) 出乎意料的错误 - 几秒钟内重试
I am implementing stripe paymentSDK and after implementing my code I am getting error in my console, here my code:
View Controller Class
func stripPayment(CVC:String){
// Initiate the card
let stripCard = STPCardParams()
if cardMM == "" && cardYY == "" {
// Send the card info to Strip to get the token
stripCard.number=card_number
stripCard.name=card_name
stripCard.cvc=CVC
stripCard.expYear=UInt(cardYY)!
stripCard.expMonth=UInt(cardMM)!
}
print("card_number:",card_number)
print("card_name:",card_name)
print("CVC:",CVC)
print("cardYY:",cardYY)
print("cardMM:",cardMM)
STPAPIClient.shared.createToken(withCard: stripCard) { (token: STPToken?, error: Error?) in
print("Printing Strip response:\(String(describing: token?.allResponseFields))\n\n")
print("Printing Strip Token:\(String(describing: token?.tokenId))")
if error != nil {
print(error)
print(error?.localizedDescription ?? "")
}
if token != nil{
print("Token:",token!.tokenId)
self.placeOrderApi(tokenStripe: token!.tokenId, completion: {
self.pushVC(id: "PaymentConfirmationVCID")
})
}
}
}
App Delegate DidFinishLaunch
STPAPIClient.shared.publishableKey = "pk_test_51KuLPhJ4jB1YaTRoUayoteEXbtl5QvbayNeDDhjv4Nto9UvdM4LcTsP2EXAbU0IuOoKsIsOAk565HzvjLRPVP9wY00Ro5T3PYq"
Error I am getting in console
Printing Strip Token:nil
Optional(Error Domain=com.stripe.lib Code=50 "There was an unexpected error -- try again in a few seconds" UserInfo={com.stripe.lib:ErrorParameterKey=card[number], NSLocalizedDescription=There was an unexpected error -- try again in a few seconds, com.stripe.lib:ErrorMessageKey=Missing required param: card[number]., com.stripe.lib:StripeErrorTypeKey=invalid_request_error, com.stripe.lib:StripeErrorCodeKey=parameter_missing})
There was an unexpected error -- try again in a few seconds
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难说出问题是什么,而不显示
card_number
的定义以及它是什么类型。您的整体代码确实具有适当的值,例如,但抛用了这一点,收集原始卡详细信息并创建像这样的令牌并将其发布到后端是不寻常的,这是一种旧的集成。我建议直接使用Stripe的当前集成和插件付款组件,而是 https://stripe.com/docs/payments/accept-a-payment?platform=ios
It's a bit hard to say what the problem is without showing where
card_number
is defined and what type it is. Your code overall does work given appropriate values likeBut putting that aside, it's unusual to collect the raw card details and create Tokens like this and post them to a backend, it's a legacy integration. I'd suggest using Stripe's current integrations and plug-in payment components directly instead https://stripe.com/docs/payments/accept-a-payment?platform=ios