stripe-react-native
                                
                                
                                
                                    stripe-react-native copied to clipboard
                            
                            
                            
                        isGooglePaySupported causes crash in android
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
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?
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?
+1
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.
@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
Yep, this will get fixed soon. Have a branch open to fix this and other cases soon
@charliecruzan-stripe - Any update here? This is breaking our app in production and not able to replicate.
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
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).
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.
Thanks Nathan. That's pretty much what I ended up doing.
@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!
I got an issue because I called isPlatformPaySupported before there was a publishable key. Please double-check if you got the issue like me.
I got an issue because I called
isPlatformPaySupportedbefore there was a publishable key. Please double-check if you got the issue like me.
Many thanks, it was my issue as well