Stripe SCA需要处理下一步操作

时间:2019-09-09 13:58:33

标签: ios swift stripe-payments stripe-sca

我以前在此应用程序中一直使用字符串,但是后端开发人员完成了所有工作,但是现在更改了其实现并使用SCA支持欧洲支付更改(支持3D安全身份验证),因此现在我需要在本地添加库代码,但我停留在这个地方。

我从服务器获取了客户端ID,但是处理下一步操作将给我类似这样的错误。

  

Error Domain = STPPaymentHandlerErrorDomain代码= 1“发生意外错误-请在几秒钟后重试。” UserInfo = {com.stripe.lib:ErrorMessageKey =在使用STPPaymentHandler之前,PaymentIntent需要附加PaymentMethod或Source。 ,NSLocalizedDescription =发生意外错误-请在几秒钟后重试}

我没有找到任何相关文档here

这是我的代码

//Api called on server for client id
    MyAPIClient.sharedClient.createAndConfirmPaymentIntent(paymentResult,
                                                                   amount: self.paymentContext.paymentAmount,
                                                                   returnURL: "payments-example://stripe-redirect",
                                                                   shippingAddress: self.paymentContext.shippingAddress,
                                                                   shippingMethod: self.paymentContext.selectedShippingMethod) { (clientSecret, error) in
                guard let clientSecret = clientSecret else {
                    completion(.error, error ?? NSError(domain: StripeDomain, code: 123, userInfo: [NSLocalizedDescriptionKey: "Unable to parse clientSecret from response"]))
                    return
                }
                STPPaymentHandler.shared().handleNextAction(forPayment: clientSecret, authenticationContext: paymentContext, returnURL: "payments-example://stripe-redirect") { (status, handledPaymentIntent, actionError) in
                    switch (status) {
                    case .succeeded:
                        guard let handledPaymentIntent = handledPaymentIntent else {
                            completion(.error, actionError ?? NSError(domain: StripeDomain, code: 123, userInfo: [NSLocalizedDescriptionKey: "Unknown failure"]))
                            return
                        }
                        if (handledPaymentIntent.status == .requiresConfirmation) {
                            // Confirm again on the backend
                            MyAPIClient.sharedClient.confirmPaymentIntent(handledPaymentIntent) { clientSecret, error in
                                guard let clientSecret = clientSecret else {
                                    completion(.error, error ?? NSError(domain: StripeDomain, code: 123, userInfo: [NSLocalizedDescriptionKey: "Unable to parse clientSecret from response"]))
                                    return
                                }

                                // Retrieve the Payment Intent and check the status for success
                                STPAPIClient.shared().retrievePaymentIntent(withClientSecret: clientSecret) { (paymentIntent, retrieveError) in
                                    guard let paymentIntent = paymentIntent else {
                                        completion(.error, retrieveError ?? NSError(domain: StripeDomain, code: 123, userInfo: [NSLocalizedDescriptionKey: "Unable to parse payment intent from response"]))
                                        return
                                    }

                                    if paymentIntent.status == .succeeded {
                                        completion(.success, nil)
                                    }
                                    else {
                                        completion(.error, NSError(domain: StripeDomain, code: 123, userInfo: [NSLocalizedDescriptionKey: "Authentication failed."]))
                                    }
                                }
                            }
                        } else {
                            // Success
                            completion(.success, nil)
                        }
                    case .failed:
                        completion(.error, actionError)
                    case .canceled:
                        completion(.userCancellation, nil)
                    }
                }

1 个答案:

答案 0 :(得分:1)

我的解决方法是致电paymentManager.confirmPayment(withParams: params, authenticationContext: self)而不是handleNextAction