iOS Swift无法获得条纹付款令牌

发布于 2025-01-26 17:31:26 字数 1776 浏览 2 评论 0原文

我正在实施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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2025-02-02 17:31:26

很难说出问题是什么,而不显示card_number的定义以及它是什么类型。您的整体代码确实具有适当的值,例如

let card_number = "4242424242424242"
let card_name = "Jane Doe"
let CVC = "123"
let cardYY = "27"
let cardMM = "12"

,但抛用了这一点,收集原始卡详细信息并创建像这样的令牌并将其发布到后端是不寻常的,这是一种旧的集成。我建议直接使用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 like

let card_number = "4242424242424242"
let card_name = "Jane Doe"
let CVC = "123"
let cardYY = "27"
let cardMM = "12"

But 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文