条纹基本付款意向确认付款错误

时间:2019-12-27 10:07:56

标签: ios swift stripe-payments payment

我在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中得到了付款结果,

<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>

非常感谢。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

我认为您忘记了在PaymentIntent中传递客户的权限。由于客户端是将clientIdephemeral_key绑定在一起的唯一内容,因此必须传递client_secret。 请尝试在服务器端遵循以下代码来生成client_secret

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