问题
I am getting following error while confirming payment intent using this method STPAPIClient.shared().confirmPaymentIntent()
Error Domain=com.stripe.lib Code=50 "No such payment_intent: pi_1ElaQpFSNNCQ7y59" UserInfo={com.stripe.lib:ErrorMessageKey=No such payment_intent: pi_1ElaQpFSNNCQ7y59, com.stripe.lib:StripeErrorCodeKey=resource_missing, com.stripe.lib:StripeErrorTypeKey=invalid_request_error, com.stripe.lib:ErrorParameterKey=intent, NSLocalizedDescription=No such payment_intent: pi_1ElaQpFSNNCQ7y59}
Code which I am executing:
STPAPIClient.shared().confirmPaymentIntent(with: paymentIntentParams, completion: { (paymentIntent, error) in
if let error = error {
// handle 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
}
})else{
// This PaymentIntent action is not yet supported by the SDK.
return;
}
redirectContext.startRedirectFlow(from: self)
}else{
// Show success message
}
}
})
回答1:
I've had a similar problem with the JS api ('No such payment_intent'). My mistake was that I was using stripe.handleCardPayment
instead of stripe.handleCardSetup
with a client_secret
of a SetupIntent.
回答2:
In case of if you are using stripe connect
(direct charge) feature you need to pass stripe connected account id(stripeAccount
) while creating stripe instance in frontend side. see below example
var stripe = Stripe(STRIPE_PUBLIC_KEY, { stripeAccount: "{{ connected_account }}" });
回答3:
add this method in your code and set this sourceid to paymentIntentParams.paymentMethodId = sourceid rest same set this source id to paymentid.
STPAPIClient.shared().createPaymentMethod(with: paymentMethodParams) { paymentMethod, error in
if error == nil {
let data = paymentMethod as? STPSource
sourceid = paymentMethod?.stripeId ?? ""
print(paymentMethod)
self.intentMakePayment(sourceid)
}
}
来源:https://stackoverflow.com/questions/56610256/code-50-no-such-payment-intent-when-confirm-payment-intent-for-stripe