stripe / stripe-react-native

React Native library for Stripe.
https://stripe.dev/stripe-react-native
MIT License
1.29k stars 263 forks source link

Google Pay not working in Android, am getting false when I call isPlatformPaySupported #1561

Open Stancobridge opened 1 year ago

Stancobridge commented 1 year ago

I can't seem to get Google pay to work on Android, am using Expo Custom dev client, after installing stripe I rebuilt the dev client

I also added this in my app.json

  [
      '@stripe/stripe-react-native',
      {
        enableGooglePay: true,
      },
    ],

Here is the code am using


import { initStripe, usePlatformPay } from '@stripe/stripe-react-native';
import { useEffect } from 'react';
import Toast from 'react-native-toast-message';
import { useInitializePlanSubscription } from './useInitializePlanSubscription';

export const useProcessSubscriptionIntent = () => {
  const { initializePaymentIntent } = useInitializePlanSubscription();
  const { isPlatformPaySupported, confirmPlatformPayPayment } = usePlatformPay();
  useEffect(() => {}, []);
  const showPaymentSheet = async () => {
    await initStripe({
      publishableKey:
        'pk_test_51O945CDwXNu7P228DqG3OyOQ3G7Le4qSi8hUtp7wqWppxIMpZkmeLw7Kjh2VSA1HWbN92cfY0Gq9ISFQDxvDd6NL00WX1zTsup',
    });
    const platformPayAvailable = await isPlatformPaySupported();
    if (!platformPayAvailable) {
      Toast.show({
        type: 'errorToast',
        text1: 'Platform payment not supported',
      });
      return;
    }
    const paymentIntent = await initializePaymentIntent(1);
    const { paymentIntent: data, error } = await confirmPlatformPayPayment(paymentIntent.payment.paymentIntent, {
      googlePay: { currencyCode: 'USD', merchantCountryCode: 'US', testEnv: true },
    });

    console.log({ data, error });
  };

  return { showPaymentSheet };
};```
Stancobridge commented 1 year ago

I created this example to help track this, https://github.com/Stancobridge/google-pay-rn-example