Stripe SCA 需要处理下一步操作

Stripe SCA need to handle next action

我以前在这个应用程序中使用字符串,但后端开发人员所做的所有事情现在都改变了它们的实现,并通过 SCA 支持欧洲支付更改(支持 3D 安全身份验证),所以现在我需要在中添加库我的本地代码,但我停留在这个地方。

我从服务器获得了客户端 ID,但处理下一步操作时会出现类似这样的错误。

Error Domain=STPPaymentHandlerErrorDomain Code=1 "There was an unexpected error -- try again in a few seconds" UserInfo={com.stripe.lib:ErrorMessageKey=The PaymentIntent requires a PaymentMethod or Source to be attached before using STPPaymentHandler., NSLocalizedDescription=There was an unexpected error -- try again in a few seconds}

我没有找到任何相关文件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)
                    }
                }

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