Search code examples
flutterstripe-paymentsgoogle-payflutter-stripe

StripeException "Invalid token ID: tok_xx" when integrating flutter_stripe with Google Pay (Pay plugin)


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.


Solution

  • The screen you are referring to is not completed, there is a TODO[1] that need to be completed. You have two options:

    1. 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',
        },
      });
      
    2. Or, work with Stripe Google Pay integration following this screen[3] and use confirmPlatformPayPaymentIntent[4] method to confirm the Payment

    [1] https://github.com/flutter-stripe/flutter_stripe/blob/db72f0ed6f5e47b932825e146f824608574ee75d/example/lib/screens/wallets/google_pay_screen.dart#L85

    [2] https://stripe.com/docs/api/payment_methods/create?lang=node#create_payment_method-card

    [3] https://github.com/flutter-stripe/flutter_stripe/blob/main/example/lib/screens/wallets/google_pay_stripe_screen.dart

    [4] https://github.com/flutter-stripe/flutter_stripe/blob/main/example/lib/screens/wallets/google_pay_stripe_screen.dart#L29