【问题标题】:Stripe Basic PaymentIntent On Confirm Payment ErrorStripe Basic PaymentIntent 确认付款错误
【发布时间】:2020-04-17 07:49:17
【问题描述】:

我已经在我的 ios 应用程序中实现了条带基本集成。我引用此链接进行集成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>

有什么想法吗?

【问题讨论】:

  • 我怀疑您设置服务器时是否有问题。再次检查文档和paymentResult。最好您可以在此处发布您的paymentResult,以便我们查看缺少的内容。
  • @Eddie 请检查问题。我已经更新了
  • 你能分享你在服务器上用来创建 PaymentIntent 的代码吗?
  • 后端代码这样$intent = \Stripe\PaymentIntent::create([ 'amount' =&gt; 100, 'currency' =&gt; 'usd', 'payment_method_types' =&gt; ['card'], ]); $response['client_secret'] = $intent-&gt;client_secret;
  • @Eddie 我是否需要在服务器端的 paymentIntent 方法中传递客户 ID?

标签: ios swift stripe-payments payment


【解决方案1】:

我想你忘了在PaymentIntent 中传递客户。需要传递clientId,因为客户端是唯一将ephemeral_keyclient_secret 绑定在一起的东西。 请在服务器端尝试以下代码生成client_secret

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

【讨论】:

    猜你喜欢
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2021-01-22
    • 2020-08-12
    • 1970-01-01
    • 2011-02-22
    相关资源
    最近更新 更多