ios - Stripe Basic PaymentIntent 确认付款错误

标签 ios swift stripe-payments payment

我已经在我的 ios 应用程序中实现了 strip 基本集成。我引用了这个链接进行集成 https://stripe.com/docs/mobile/ios/basic一体化。

当我调用 STPPaymentHandler.shared().confirmPayment(withParams: paymentIntentParams,authenticationContext: paymentContext) ,

这是我的代码

// Assemble the PaymentIntent parameters
                let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
                paymentIntentParams.paymentMethodId = paymentResult.paymentMethod?.stripeId
                paymentIntentParams.configure(with: paymentResult)

                // Confirm the PaymentIntent
                STPPaymentHandler.shared().confirmPayment(withParams: paymentIntentParams, authenticationContext: paymentContext) { status, paymentIntent, error in
                    switch status {
                    case .succeeded:
                        // Your backend asynchronously fulfills the customer's order, e.g. via webhook
                        completion(.success, nil)
                    case .failed:
                        completion(.error, error) // Report error
                    case .canceled:
                        completion(.userCancellation, nil) // Customer cancelled
                    @unknown default:
                        completion(.error, nil)
                    }
                }


我收到以下错误:
Error Domain=com.stripe.lib Code=50 "The `payment_method` parameter supplied pm_test belongs to the Customer cus_test. Please include the Customer in the `customer` parameter on the PaymentIntent." UserInfo={com.stripe.lib:ErrorMessageKey=The `payment_method` parameter supplied pm_test belongs to the Customer cus_test. Please include the Customer in the `customer` parameter on the PaymentIntent., com.stripe.lib:StripeErrorCodeKey=parameter_missing, com.stripe.lib:StripeErrorTypeKey=invalid_request_error, com.stripe.lib:ErrorParameterKey=paymentMethod, NSLocalizedDescription=The `payment_method` parameter supplied pm_test belongs to the Customer cus_test. Please include the Customer in the `customer` parameter on the PaymentIntent.}.

我在 didCreatePaymentResult 中得到 paymentResult,如下所示:
<STPPaymentMethod: 0x6000029cfb10; stripeId = pm_stripeID; billingDetails = <STPPaymentMethodBillingDetails: 0x60000174a800; name = (null); phone = (null); email = (null); address = <STPPaymentMethodAddress: 0x6000021e8500; line1 = (null); line2 = (null); city = (null); state = (null); postalCode = (null); country = US>>; card = <STPPaymentMethodCard: 0x6000026c2040; brand = Visa; checks = <STPPaymentMethodCardChecks: 0x600000cad2c0; addressLine1Check: (null); addressPostalCodeCheck: (null); cvcCheck: pass>; country = US; expMonth = 2; expYear = 2025; funding = credit; last4 = 4242; fingerprint = (null); threeDSecureUsage = <STPPaymentMethodThreeDSecureUsage: 0x6000002b86a0; supported: YES>; wallet = (null)>; cardPresent = (null); created = 2019-12-27 11:45:05 +0000; customerId = cus_GR9XK62lIkQYto; ideal = (null); fpx = (null); sepaDebit = (null); liveMode = NO; metadata = {
}; type = card>

有任何想法吗?

最佳答案

我想你忘了通过 PaymentIntent 中的客户.需通过clientId因为客户端是唯一绑定(bind) ephemeral_key 的东西和 client_secret一起。
请在服务器端尝试以下代码生成client_secret .

$intent = \Stripe\PaymentIntent::create([
    'customer' => $customerId,
    'amount' => 100,
    'currency' => 'usd',
]);
$response['client_secret'] = $intent->client_secret;

关于ios - Stripe Basic PaymentIntent 确认付款错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59499088/

相关文章:

swift - 使用文件数组上传 MultipartFormData

ios - Swift Firebase 以更智能的方式检索数据?

android - 无法在 flutter 中运行 stripe_sdk 示例

ios - 使用 iOS Twilio SDK 在对话历史记录中显示系统消息

ios - 努力将 NSArray 解析为带有分隔符的字符串,以快速生成 QR 码

ios - 我在 uitableview 中使用广告,列表中每第 4 个左右的项目就是一个广告

快速 coreML : prediction function without "options" parameter

javascript - 实现 Oauth。第三方认证后应该重定向到哪里?

stripe-payments - 字段legal_entity.personal_id_number 指定什么身份证明文件?

ios - 使用导航 Controller 将 View 复制到项目中 - "Image View"的框架在运行时会有所不同