iaphub / react-native-iaphub

The easiest way to implement IAP (In-app purchase) in your React Native app.
https://www.iaphub.com/
MIT License
319 stars 22 forks source link

Iaphub.init() throws "Error: The billing is not available" when not logged into Google Play on Android device #107

Closed scipilot closed 2 years ago

scipilot commented 2 years ago

I'm not sure if this is intended behaviour, but I find I cannot even initialise IAPHub on an Android device when not signed in with a Google account. I am using a real device, and in an internal test group with an unpublished app in fairly early development. It all works fine when I'm signed in to Google on the device - I can list and buy sandbox products. I've set up my IAPHub account, products, listing etc, and most of the Google Play account and app setup, and so that all makes sense.

Q1. Is it assumed that every user would always be signed in into Google on their device?

I know that you have to sign in to be able to make the purchase of course, but I was expecting it to allow the product listing to be fetched from IAPHub itself, then perhaps prompt for login on clicking a payment button which calls Iaphub.buy().

In my app boot , I call Iaphub.init({ appId, apiKey, environment:"production" }) then set the user id and device params etc. But it throws the exception at init().

If I continue anyway and set the userId, getProductsForSale() throws "[Error: Billing is unavailable. This may be a problem with your device, or the Play Store may be down.]" and "GooglePlay did not return the product 'MY-SKU', the product has been filtered, if the sku is valid your GooglePlay account or sandbox environment is probably not configured properly (https://iaphub.com/docs/set-up-android/configure-sandbox-testing)"

If it's true that they must be signed in, then Q2. how can we detect this from your API? I couldn't see an obvious call for that, other than capturing and detecting these error messages and implying the state.

Then (sorry!) Q3. is it possible to trigger the Google account login panel to make them sign in, so I can load the products? Or am I worrying about a scenario that will never happen?

thanks for the help

iaphub commented 2 years ago

Hi @scipilot. You're correct, the user must be signed in in order to load and buy in-app purchases. Which is the case of 99% of users but you should definitely display an error message if the getProductsForSale() method throws an error and you cannot load the products. There is no way to trigger a 'login panel' for the user to log in. The only way to handle this very unlikely scenario is to display an error message when the in-app billing is unavailable (it could also be unavailable for other reasons).

scipilot commented 1 year ago

Does the upgrade to v7 change this? From reading this page, https://github.com/iaphub/react-native-iaphub/blob/master/guides/migrate-v6-to-v7.md#new-authentication-system I would interpret that a user doesn't need to be signed in to view products, but in testing I find I still get the "billing_unavailable" error thrown.

pisacode commented 1 year ago

One more thing about this is if you updated your apk version on android you need to upload the bundle to google play store in order to use that app version for in app products. Even if you are testing on your own device you need to upload a bundle without putting it through the production.