我收到代码50错误:
收到的未知参数:payment_method_data [card] [token]
使用STPAPIClient.shared().confirmPaymentIntent()
和从didCreateToken
收集的令牌时。
我通过以下方式将令牌分配给卡参数:
cardParams.token = token.tokenId
条带版本:15.0.1。 有任何解决方法的想法吗?
完整代码:
func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: @escaping STPErrorBlock) {
let cardParams = STPPaymentMethodCardParams()
cardParams.token = token.tokenId
let paymentMethodParams = STPPaymentMethodParams(card: cardParams, billingDetails: nil, metadata: nil)
//let paymentMethodParams = STPPaymentMethodParams(card: cardParams, billingDetails: billingDetails, metadata: nil)
let clientSecret = paymentIntentData?.token ?? "" //recieve from the API
let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
paymentIntentParams.paymentMethodParams = paymentMethodParams
//paymentIntentParams.returnURL = "your-app://stripe-redirect"
let client = STPAPIClient.shared()
client.confirmPaymentIntent(with: paymentIntentParams, completion: { (paymentIntent, error) in
if let error = error {
// handle error
print(error)
} else if let paymentIntent = paymentIntent {
// see below to handle the confirmed PaymentIntent
if paymentIntent.status == .requiresAction {
guard let redirectContext = STPRedirectContext(paymentIntent: paymentIntent, completion: { clientSecret, redirectError in
// Fetch the latest status of the Payment Intent if necessary
STPAPIClient.shared().retrievePaymentIntent(withClientSecret: clientSecret) { paymentIntent, error in
// Check paymentIntent.status
print(paymentIntent)
}
}) else {
// This PaymentIntent action is not yet supported by the SDK.
return;
}
// Note you must retain this for the duration of the redirect flow - it dismisses any presented view controller upon deallocation.
self.redirectContext = redirectContext
// opens SFSafariViewController to the necessary URL
redirectContext.startRedirectFlow(from: self)
} else {
// Show success message
print("Success")
}
}
self.navigationController?.popViewController(animated: true)
})
}