unable to confirmPayment when card is already saved and need to payment with saved card details in react native app with stripe-react-native library..
ConfirmPayment code (Card is already saved and trying to payment with same card details)
const { paymentIntent, error } = await confirmPayment(
this.state.clientSecret,
{
paymentMethodType: 'Card',
},
);
React native version :
"react-native": "0.70.6",
Error:
{"code": "Failed", "declineCode": null, "localizedMessage": "You must provide paymentMethodType", "message": "card detail not found", "stripeErrorCode": null, "type": null}
CodePudding user response:
If you want to use a saved Payment Method you need to provide the ID of that payment method when calling the confirmPayment()
function.
You can see this is the docs for Stripe.js for calling confirmCardPayment
here. While this isn't React Native, all the front-end approaches use the same APIs and so much of the details are similar with differences in syntax.
For React Native, the confirmPayment
function is defined in the SDK reference doc here. This definitions shows us that the second argument should be the PaymentMethod.CreateParams
. When we look at the definition for the CreateParams
, we can see it's a combination of different Payment Method params. The one that matters here is the CardParams
, defined here.
This parameter has a couple different ways it can be constructed but for your purposes I think the second option is the best fit for what you are trying to do. It also matches the Stripe.js approach for confirming a payment with a saved Payment Method (shown below):
{
paymentMethodType: "Card";
paymentMethodData: {
paymentMethodId: string;
cvc?: string;
billingDetails?: BillingDetails
}
}
In this case the only argument for paymentMethodData
that is required is the paymentMethodId
. Providing the paymentMethodId
will allow you to successfully confirmPayment()
used the saved card.