question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RNIap is not working on Android but works in iOS with same code

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:37 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
damialajoguncommented, Jul 16, 2020

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.

1reaction
hakkikonucommented, Jul 31, 2020

beta is not a must. also closed alpha is ok

Read more comments on GitHub >

github_iconTop Results From Across the Web

RNIap is not working on Android but works in iOS with same ...
I'm using this exact code for iOS and it works perfectly. I have set up all products in the play console, added billings...
Read more >
React Native Android In App Purchase Error - Stack Overflow
getProducts(itemSkus) but on android you need to specify them as subscriptions for it to work. You can do this with RNIAP.
Read more >
react-native-iap - npm
A device simulator, use a real device for testing! The sandbox environment of the project not being configured properly (Configure android ...
Read more >
Implementing in-app purchases in React Native
This tutorial will guide you on how to implement in-app purchases in React Native, which will allow your mobile app to receive user ......
Read more >
React Native : Subscriptions, In-App Purchases & Service ...
First thing you should do is to define your items for iOS and Android separately like defined below. import * as RNIap from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found