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.

Cannot get product from AppStoreConnect

See original GitHub issue

Version of react-native-iap

5.0.1

Version of react-native

0.63.2

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

IOS

Expected behavior

Actual behavior

RNIap.getProducts(sku) return empty list

Tested environment (Emulator? Real Device?)

Real Device

Steps to reproduce the behavior

I already have 5 products in AppStoreConnect (video below) . Here is my code :

const [productList, setProduct] = useState(null);
 const itemSkus = Platform.select({
        ios: [
            'net.tyhh.hoahoc.nap1',
            'net.tyhh.hoahoc.nap2',
            'net.tyhh.hoahoc.nap3',
            'net.tyhh.hoahoc.nap4',
            'net.tyhh.hoahoc.nap5'
        ],
        android: [
            'net.tyhh.hoahoc.nap1',
            'net.tyhh.hoahoc.nap2',
            'net.tyhh.hoahoc.nap3',
            'net.tyhh.hoahoc.nap4',
            'net.tyhh.hoahoc.nap5'
        ]
    });
...

 const getProducts = async () => {
        try {
            const products = await RNIap.getProducts(itemSkus);
            // const products = await RNIap.getSubscriptions(itemSkus);

            setProduct(products);
        } catch (err) {
            console.log(JSON.stringify(err));
        }
    }

useEffect(() => {//config GoogleApple
        RNIap.getAvailablePurchases().then(purchase => {
            console.log('All purchase: ' + purchase);
        }).catch(e => {
            setProcess(false);
        })
        async function prepare() {
            try {
                const result = await RNIap.initConnection();

                //await RNIap.flushFailedPurchasesCachedAsPendingAndroid();
                console.log('result', result);
                getProducts();
            } catch (err) {
                console.log(JSON.stringify(err));
                setProcess(false);
            }
        };

        prepare();

        purchaseUpdateSubscription = purchaseUpdatedListener(
            async (purchase) => {
                console.log('done');
                const receipt = purchase.transactionReceipt;
                if (receipt) {
                    const signature = Platform.OS == 'android' ? purchase.signatureAndroid : '';
                    const device = Platform.OS == 'android' ? 'ANDROID' : 'IOS';
                    const id = uniqueID(stateTree.user.pupil_account.id)
                    console.log(purchase);
                    console.log(signature);
                    //call api
                    Purchase.valiadateGoogleApple(stateTree.user.token_key, receipt, signature, device, id).then(res => {
                        // console.log(res.data);
                        setLog(JSON.stringify(res.data));
                        const transInfo = res.data.data;
                        let paymentInfo = {
                            orderId: id,
                            amount: moneyRef.current.toString(),
                            time: moment().locale('vi-VN').format('LT') + ' ' + moment().locale('vi-VN').format('L'),
                        }

                        if (transInfo.purchase_state == 'PURCHASED') {
                            paymentInfo.isSuccess = true;
                        } else {
                            paymentInfo.isSuccess = true;
                        }
                        setProcess(false);
                        finishTransaction(purchase, true).then(() => {
                            setInfo(paymentInfo);
                        });

                        // if(transInfo.purchase_state == 'PURCHASED'){
                        //     navigation.navigate('PaymentAfter',{isSuccess:true,paymentInfo})
                        // }
                    }).catch(e => {
                        console.log(e);
                        setError(true);
                        setProcess(false);
                    });


                } else {
                    setError(true);
                    setProcess(false);
                }
            }
        );

        purchaseErrorSubscription = purchaseErrorListener(
            async (error) => {
                try {

                    // setError(true);
                    setProcess(false);

                } catch (ex) {
                    console.log('fatal error' + ex);
                    setProcess(false);

                }

            }
        );
        return function cleanUp() {
            if (purchaseUpdateSubscription) {
                purchaseUpdateSubscription.remove();
                purchaseUpdateSubscription = null;
            }
            if (purchaseErrorSubscription) {
                purchaseErrorSubscription.remove();
                purchaseErrorSubscription = null;
            }
            RNIap.endConnection();
        };

    }, [])

I try to log the productList but it is empty. A month ago my in-app purchase function worked very well but recently my team decided to change the package name and bundle Id of project, so we have to fix a lot. I really need help from you guy cause my project’s deadline is this weekend.

https://user-images.githubusercontent.com/69777410/110461001-80c0c700-8101-11eb-86d2-1ba65330cc99.mp4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
binhchilicommented, Mar 16, 2021

My account is newly created and of course I forget to fill the Agreement , Tax and Baking section. Now it returns all of my product. Thank you all u guy for replying my issue.

1reaction
vish2595commented, Mar 12, 2021

Same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IAP Cannot get Product Details and… | Apple Developer Forums
My app cannot fetch product details. I tried change sandbox user, change product id, create new app. So i still get error same...
Read more >
I am getting error while requesting products from App Store for ...
While in the iOS 7 Simulator I'm encountering errors attempting to request products, it successfully fetches them in the iOS 8 Simulator.
Read more >
App Store Connect In-App Purchase Configuration
This post serves as the ultimate guide for how to get your in-app products configured in App Store Connect and Xcode. Every item...
Read more >
How to Configure In-App Subscriptions in App Store Connect
The name cannot be longer than 64 characters. ​​The Product ID is a unique alphanumeric ID used for reporting. Once you use a...
Read more >
iOS - Create or edit a subscription in App Store Connect (Solo ...
Once you have created a new product in your back office > Product Management > My Products , you can create the new...
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