stripe-react-native icon indicating copy to clipboard operation
stripe-react-native copied to clipboard

isGooglePaySupported causes crash in android

Open kostiantyn-solianyk opened this issue 3 years ago • 14 comments

Describe the bug App is wrapped in the StripeProvider and in the child component I'm calling isGooglePaySupported promise, but each time it causes crash in android. java.lang.IllegalStateException: PaymentConfiguration was not initialized. Call PaymentConfiguration.init().

In manifest I have

<meta-data
      android:name="com.google.android.gms.wallet.api.enabled"
      android:value="true" />

Smartphone (please complete the following information):

  • Device: android (real and emulator)
  • OS: 10
  • Stripe: 0.15.0
  • RN: 0.68.2

Case that I have:

 <StripeProvider publishableKey={stripePublishableKey} merchantIdentifier={merchantIdentifier}>
     <ChildComponent />
 </StripeProvider>

Inside ChildComponent I'm calling

useEffect(() => {
  async function igGPaySupported() {
    const isSupported = await isGooglePaySupported({ testEnv: true });
  }
  igGPaySupported();
}, []);

and isGooglePaySupported causes a crash

kostiantyn-solianyk avatar Jul 28 '22 19:07 kostiantyn-solianyk

We call PaymentConfiguration.init behind the scenes in the initialize function (called by the StripeProvider), so it looks like there's a race condition where that call hasn't completed yet and you're calling out to isGooglePaySupported.

Could you confirm that for me?

charliecruzan-stripe avatar Jul 28 '22 19:07 charliecruzan-stripe

Yes, can confirm, If I wrap the call of isGooglePaySupported to setTimeout() func then it works, hmm. Thanks for the hint!! Is it possible to check whether PaymentConfiguration.init was completed or not?

kostiantyn-solianyk avatar Jul 28 '22 19:07 kostiantyn-solianyk

+1

kartavyaparekh96 avatar Jul 29 '22 12:07 kartavyaparekh96

Having the same issue only on first build. After the crash, the issue goes away when reopening app. I assume init is called at that point.

<StripeProvider
publishableKey={stripeApiKey}
merchantIdentifier='package.com'
urlScheme='mytakeouts-payment'
setReturnUrlSchemeOnAndroid
>
  <Payment /> // isGoogleSupported sits in here
</StripeProvider>

The way React mounts components is always children first, so this is probably the issue for people who have isGoogleSupported in a child component of StripeProvider. Looks like @kostiantyn-solianyk suggested setTimeout is the current workaround.

Rc85 avatar Aug 08 '22 23:08 Rc85

@charliecruzan-stripe any updates from the team on getting this on the roadmap to fix? Glad there's a short-term workaround but would love to proactively address this in the library if possible

b13i avatar Apr 20 '23 15:04 b13i

Yep, this will get fixed soon. Have a branch open to fix this and other cases soon

charliecruzan-stripe avatar Apr 25 '23 19:04 charliecruzan-stripe

@charliecruzan-stripe - Any update here? This is breaking our app in production and not able to replicate.

NathHorrigan avatar May 19 '23 10:05 NathHorrigan

I think the crash occurs because the <StripeProvider> doesn't have time to initialize, so maybe it's better to avoid wrapping a button directly with the <StripeProvider> but move it to a much higher level in the component tree. Let me know if this solved it

Filippo39 avatar May 23 '23 11:05 Filippo39

Any update on this? Any workaround possible while waiting for a proper fix? We don't use StripeProvider and call initStripe only further in the app once we know the user's country (i.e. after calling isPlatformPaySupported).

sregg avatar Jun 26 '23 18:06 sregg

Hello @sregg ,

I had the exact same problem, don't init until we know the user's country which requires waiting until the store was loaded from storage.

I found the best solution was to wrap the initStripe call in a function that accepts an optional country param, if the param is undefined then assume US/UK/FR etc, you can then call this function in your index.js file before any of your app code executes.

Once your app has loaded you can recall your initStripe wrapper method again with the correct country, It's not a perfect approach but we are using this in production just fine.

NathHorrigan avatar Jun 26 '23 22:06 NathHorrigan

Thanks Nathan. That's pretty much what I ended up doing.

sregg avatar Jun 27 '23 00:06 sregg

@charliecruzan-stripe Is there any update on this? We are experiencing this issue as well. Would be good to know where you are with the issue. Thanks!

joe-yeomans avatar Aug 03 '23 09:08 joe-yeomans

I got an issue because I called isPlatformPaySupported before there was a publishable key. Please double-check if you got the issue like me.

trilam1409 avatar Nov 28 '23 09:11 trilam1409

I got an issue because I called isPlatformPaySupported before there was a publishable key. Please double-check if you got the issue like me.

Many thanks, it was my issue as well

AndrejStarusev avatar Mar 21 '24 16:03 AndrejStarusev