I am trying to integrate Google Pay using the Pay plugin to flutter_stripe library in my flutter application. I am getting the token from the Pay plugin after the payment but when I try to send it to Stripe, I am getting exception as "Invalid token ID: tok_xx".
I am following the sample provided by the flutter_stripe library like here:
final token = paymentResult['paymentMethodData']['tokenizationData']['token'];
final tokenJson = Map.castFrom(json.decode(token));
final params = PaymentMethodParams.cardFromToken(
paymentMethodData: PaymentMethodDataCardFromToken(
token: tokenJson['id'],
),
);
await Stripe.instance.confirmPayment(
paymentIntentClientSecret: clientSecret,
data: params,
);
I am getting this error on the confirmPayment method. Do I need to do something more to the token? Is there another way I can verify the token?
I tried testing in release and test mode with same results.
The screen you are referring to is not completed, there is a TODO[1] that need to be completed. You have two options:
Continue working with the pay plugin and check the maintainer of that SDK about the next steps of that TODO. Or create a PaymentMethod from the token using this API[2] and use it while confirming the PaymentIntent, something like this:
const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
token: 'tok_xxxxx',
},
});
Or, work with Stripe Google Pay integration following this screen[3] and use confirmPlatformPayPaymentIntent[4] method to confirm the Payment
[2] https://stripe.com/docs/api/payment_methods/create?lang=node#create_payment_method-card