【问题标题】:Stripe Apple Pay crash due to format does not match expected client secret由于格式与预期的客户端密码不匹配,Stripe Apple Pay 崩溃
【发布时间】:2021-05-09 12:57:58
【问题描述】:

当我使用 Stripe Apple Pay 付款时,应用程序崩溃并显示错误“断言失败:secret 格式与预期的客户端机密格式不匹配。:文件 Stripe/STPAPIClient.swift,第 593 行”

 let paymentRequest = StripeAPI.paymentRequest(withMerchantIdentifier: STPPaymentConfiguration.shared.appleMerchantIdentifier!, country: "US", currency: "USD")

    paymentRequest.paymentSummaryItems = [
        PKPaymentSummaryItem(label: "iTem 1", amount: NSDecimalNumber(value: 10.0))),
    ]
    
    // Initialize an STPApplePayContext instance
    if let applePayContext = STPApplePayContext(paymentRequest: paymentRequest, delegate: self) {
        // Present Apple Pay payment sheet
        applePayContext.presentApplePay(on: self)
    }
    else{
        // There is a problem with your Apple Pay configuration
        let alert = self.showAlert(withTitle: "Error", andMessage:"Unable to make Apple Pay transaction.", completion: self.alertAction)
        self.present(alert, animated: true)

【问题讨论】:

  • 你在哪里得到错误?您是否通过服务器处理付款?你能告诉我们服务器端的相关代码吗?您是否在应用程序中设置了defaultPublishableKey?您在付款交易的哪个时间点收到错误消息?
  • 它在调用服务器代码之前崩溃,如果条带返回任何成功或失败,那么我们的服务器代码运行但它发生在之前。
  • 您使用过“STPSetupIntentConfirmParams”吗?我不认为问题出在您显示的代码中
  • 我在 AppDelegate 中只使用了 2 行 StripeAPI.defaultPublishableKey = "" STPPaymentConfiguration.shared.appleMerchantIdentifier = "merchant.com.appName"
  • in Controller let paymentRequest = StripeAPI.paymentRequest(withMerchantIdentifier: STPPaymentConfiguration.shared.appleMerchantIdentifier!, country: "US", currency: "USD") // 配置支付请求上的行项 paymentRequest. paymentSummaryItems = [ // 最后一行应该代表你的公司; PKPaymentSummaryItem(label: "item 1", amount: NSDecimalNumber(value: 20.0)), ]

标签: ios swift stripe-payments


【解决方案1】:

您没有客户端密码 - 您共享的代码是这样的:

let clientSecret = ""

这就是问题所在,也是您收到错误格式错误的原因。

您需要在后端服务器上创建一个 PaymentIntent 并将 client_secret 返回到您的应用程序并在该 STPIntentClientSecretCompletionBlock 中使用它。

https://stripe.com/docs/apple-pay#create-automatic-payment-intent

例如,您可能希望查看使用 URLSession 与服务器通信以从后端服务器获取该信息的示例应用程序:https://github.com/stripe-samples/accept-a-card-payment/blob/master/using-webhooks/client/ios/App%20(Swift)/CheckoutViewController.swift#L67-L98

【讨论】:

    猜你喜欢
    • 2015-09-16
    • 2019-05-08
    • 2015-07-04
    • 2020-08-20
    • 2020-06-06
    • 2018-01-18
    • 2016-11-11
    • 2016-04-24
    相关资源
    最近更新 更多