Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isGooglePaySupported causes crash in android #1065

Open
kostiantyn-solianyk opened this issue Jul 28, 2022 · 14 comments
Open

isGooglePaySupported causes crash in android #1065

kostiantyn-solianyk opened this issue Jul 28, 2022 · 14 comments
Labels
android bug Something isn't working

Comments

@kostiantyn-solianyk
Copy link

kostiantyn-solianyk commented Jul 28, 2022

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

@charliecruzan-stripe
Copy link
Collaborator

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?

@kostiantyn-solianyk
Copy link
Author

kostiantyn-solianyk commented Jul 28, 2022

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?

@charliecruzan-stripe charliecruzan-stripe added bug Something isn't working android labels Jul 28, 2022
@kartavyaparekh96
Copy link

+1

@Rc85
Copy link

Rc85 commented Aug 8, 2022

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.

@b13i
Copy link

b13i commented Apr 20, 2023

@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

@charliecruzan-stripe
Copy link
Collaborator

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

@NathHorrigan
Copy link

NathHorrigan commented May 19, 2023

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

@Filippo39
Copy link

Filippo39 commented May 23, 2023

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

@sregg
Copy link

sregg commented Jun 26, 2023

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).

@NathHorrigan
Copy link

NathHorrigan commented Jun 26, 2023

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.

@sregg
Copy link

sregg commented Jun 27, 2023

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

@joe-yeomans
Copy link

@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!

@trilam1409
Copy link

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

@AndrejStarusev
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android bug Something isn't working
Projects
None yet
Development

No branches or pull requests