React-native-iap: RNIap is not working on Android but works in iOS with same code

Created on 7 Jul 2020  ·  33Comments  ·  Source: dooboolab/react-native-iap

Version of react-native-iap
4.4.7

Version of react-native
0.60.6

Platforms you faced the error (IOS or Android or both?)
Android

Expected behavior

     async componentDidMount() {
        try {
            const result = await RNIap.initConnection();
            await RNIap.consumeAllItemsAndroid();
            console.log('result', result);
            const products: Product[] = await RNIap.getProducts(itemSkus);
            this.setState({ products }, () => {console.log(this.state.products)});
        } catch (err) {
            console.warn(err.code, err.message);
        }

Expected behavior is a list of products pulled from play console by .getProducts() printed in terminal

Actual behavior
Promise is not returned. Error 'billing is not available'

Tested environment (Emulator? Real Device?)
Real Device (App is currently in production)

Steps to reproduce the behavior
const itemSkus = Platform.select({ ios: [ 'com.example.1' ], android: [ 'com.example.1' ] });

     async componentDidMount() {
        try {
            const result = await RNIap.initConnection();
            await RNIap.consumeAllItemsAndroid();
            console.log('result', result);
            const products: Product[] = await RNIap.getProducts(itemSkus);
            this.setState({ products }, () => {console.log(this.state.products)});
        } catch (err) {
            console.warn(err.code, err.message);
        }
    this.purchaseUpdateSubscription = purchaseUpdatedListener(async (purchase: InAppPurchase | SubscriptionPurchase | ProductPurchase) => {
        console.log('purchaseUpdatedListener', purchase);
        const receipt = purchase.transactionReceipt;
        if (receipt) {
            try {
                // if (Platform.OS === 'ios') {
                //   finishTransactionIOS(purchase.transactionId);
                // } else if (Platform.OS === 'android') {
                //   // If consumable (can be purchased again)
                //   consumePurchaseAndroid(purchase.purchaseToken);
                //   // If not consumable
                //   acknowledgePurchaseAndroid(purchase.purchaseToken);
                // }
                const ackResult = await finishTransaction(purchase);
            } catch (ackErr) {
                console.warn('ackErr', ackErr);
            }

            this.setState({ receipt }, () => this.goNext());
        }
    },
    );

    this.purchaseErrorSubscription = purchaseErrorListener(
        (error: PurchaseError) => {
            console.log('purchaseErrorListener', error);
        },
    );
}
componentWillUnmount() {
    if (this.purchaseUpdateSubscription) {
        this.purchaseUpdateSubscription.remove();
        this.purchaseUpdateSubscription = null;
    }
    if (this.purchaseErrorSubscription) {
        this.purchaseErrorSubscription.remove();
        this.purchaseErrorSubscription = null;
    }
}

I can't seem to figure out why this is. I'm using this exact code for iOS and it works perfectly. I have set up all products in the play console, added billings permission to the manifest file, and linked IAP package (I'm using AndroidX so the package is auto-linked). I am logged into the play store and I have the latest version of the play store, but initConnection() is still not working. I don't know what else to do. Any help is greatly appreciated! Thank you for reading.

🙏 help wanted 🤖 android

All 33 comments

Would this help?

Would this help?

Unfortunately it didn't help :(. Would this have something to do with AndroidX migration? For some reason initConnection() is not working and I don't know the reason why.

@damialajogun Did you find out what was wrong? I have the exact same mistake and don't understand where it came from... initConnection() is undefined.

@hyochan Do you have an idea?

@damialajogun Did you find out what was wrong? I have the exact same mistake and don't understand where it came from... initConnection() is undefined.

Hey, no I haven't figured it out yet :(

Did you add <uses-permission android:name="com.android.vending.BILLING" /> to your AndroidManifest.xml file?

@hakkikonu Yes I have

In my error loggin, I can see the same error occurring for a small part of my users in several countries like US and NZ. It seems to occur very inconsistent though. Any ideas what this can be caused by?

@joris1995 I also have this problem, a small part of users cannot make in-app purchases, the error is "The sku was not found. Please fetch products first by calling getItems", but the sku is present because in the purchase popup I show the price of the object taken from getProducts, getItems is not even in the API

does your google play store app latest version? Is this problem only happen on your phone or all users.

also can you try to login with to google play store with different gmail account.

be sure to clean your google play services and google play store app cache files from settings / applications / google play on your device.

All users/accounts/phones...

For me, It's only a part of my users. There does not seem to be any consistent factor like country, OS version or device manufacturer. In BugSnag, it shows the error 'Billing is not available. This may be a problem with your device, or the Play Store might be down'. What can this be caused by?

You need to submit a beta version before being able to load the in app purchases and you can only debug it using a release build.

beta is not a must. also closed alpha is ok

I also have the same problem, I have even submitted beta and was approved 4 days ago

If I understand what you're saying, it's that initConnection() doesn't work in test but in beta?

@Kamsou Yes, although it is mainly “getProducts()” that do not work in a debug build.

More information: https://medium.com/bleeding-edge/testing-in-app-purchases-on-android-a6de74f78878

What's going on with me is that, It's that when I want to see if the purchase has been made, I do :
RNIap.getPurchaseHistory()
On iOs everything works normally.
But on Android I have this one mistake: "Error: E_IAP_NOT_AVAILABLE"
_I'm on my local emulator_

``` const initilizeIAPConnection = async () => { await initConnection() .then(async (connection) => { consumeAllItemsAndroid(); await getItems(); console.log('IAP result', connection); }) .catch((error) => { console.warn(IAP ERROR ${error.code}`, error.message);
});
};

const getItems = async () => {
try {
const subscriptions = await getSubscriptions(itemSkus);
console.log('Products', subscriptions);
setSubscriptions(subscriptions);
} catch (err) {
console.warn(err.code, err.message);
}
};
useEffect(() => {
initilizeIAPConnection();
}, []);

``` I just removed await forconsumeAllItemsAndroid(); ` and it started working

@rizshivalli Glad to hear it's working for you. Unfortunately, it still doesn't work for me when I remove await for consumeAllItemsAndroid(). My issue is that initConnection() does not work. How are you able to get that part to work?

@damialajogun I removed try catch and added .then and .catch

@rizshivalli Tried that and it's still not working for me :(. Sorry for all the questions, but are you able to actually see 'products' from below printed in the terminal? I think the problem with mine is that it isn't pulling all my configured products in the play console even though I've set them up and they are active.
const getItems = async () => { try { const subscriptions = await getSubscriptions(itemSkus); console.log('Products', subscriptions);

@damialajogun Yes It is working. I am also able to test payments on android as well. Have you released the build to alpha or beta on android?

@rizshivalli Not alpha or beta but I have released it in production so it is live in the play store. I think as long as it's on a real device (not an emulator) it should work, unfortunately it is not for me....

Hi @rizshivalli quick question - is your app listed as free or paid on Google Play? Mine is free but with in-app purchases (users can download the app for free and choose to buy non-consumables in the app) but now I'm wondering if it has to be listed as paid for the IAP to work?

@damialajogun it is listed as free because users don't need to pay for installing the app

Morning, everyone,
Do any of you have their Android application that works well with payment?
Because with me the initConnection doesn't work.

I do, using the latest version. I don’t think initConnection does anything actually, it just starts the connection, then you need to fetch the products

Any solution for this ?
For me android crashes before launching the app. But Ios works as expected.
Please help

I am facing (probably) the same issue.

I added two more subscriptions to my app, but only the old one is working.
When i try to await RNIap.getSubscriptions() I get "google is indicating that we have some issue connecting to payment"

When i try to RNIap.requestSubscription(subId, true) I get "The sku was not found".

Skus are registered in google play and the ids are correct, double checked that. Tested on emulator and real device, using debug and release modes.

Any idea?

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

still requires attention

We can close !

Le sam. 19 déc. 2020 à 11:03, damialajogun notifications@github.com a
écrit :

Hey there, it looks like there has been no activity on this issue
recently. Has the issue been fixed, or does it still require the
community's attention? This issue may be closed if no further activity
occurs. You may also label this issue as "For Discussion" or "Good first
issue" and I will leave it open. Thank you for your contributions.

still requires attention


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dooboolab/react-native-iap/issues/1040#issuecomment-748451922,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AJ2B2AUIRMGWIHZSFYL6SWTSVR3AXANCNFSM4OSLGZSQ
.

Was this page helpful?
0 / 5 - 0 ratings