【发布时间】: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