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

IAP req ERROR %%% undefined right operand of 'in' is not an object #2455

Closed
Prathameshlabde opened this issue Jun 5, 2023 · 3 comments
Closed

Comments

@Prathameshlabde
Copy link

Prathameshlabde commented Jun 5, 2023

Hello


I have implemented react-native-iap (version:12.10.5) , react-native(version : 0.71.7)
I am trying to implement subscription by using requestSubscription() method, However I am getting below error 

IAP req ERROR %%% undefined right operand of 'in' is not an object
Below is my block of code

 requestSubscriptionFM = async (sku) => {
        await NetInfo.fetch().then(async (state) => {
            if (state.isConnected) {
                this.startLoader();
                // setBuyIsLoading(true);
                try {
                    console.log("subscription function123", sku);
                    await requestSubscription(sku)
                        .then(async (result) => {
                            console.log('IAP req sub', result);
                            if (platform === 'android') {
                                console.log("android sbscription");
                                this.setState({
                                    iapPurchaseToken: result.purchaseToken,
                                    iapPackageName: result.packageNameAndroid,
                                    iapProductId: result.productId,
                                });
                                // can do your API call here to save the purchase details of particular user
                            } else if (platform === 'ios') {
                                console.log("ios subscription", result.transactionReceipt);

                                this.setState({
                                    iapProductId: result.productId,
                                    iapReceipt: result.transactionReceipt,
                                });

                                // can do your API call here to save the purchase details of particular user
                            }
                            this.stopLoader();
                        })
                        .catch((err) => {
                            this.stopLoader();
                            console.warn(
                                `IAP req ERROR %%%%% ${err.code}`,
                                err.message,
                                // isModalVisible,
                            );
                            this.setState({ iapError: err.message });
                            // setError(err.message);
                        });
                } catch (err) {
                    // setBuyIsLoading(false);
                    this.stopLoader();

                    console.warn(`err ${err.code}`, err.message);
                    this.setState({ iapError: err.message });
                    // setError(err.message);
                }
            }
        });
    };

Please suggest to fix this issue

@mansimakwana25
Copy link

Use requestSubscription method like below

await requestSubscription({sku}).then(async (result) => {
//your code
})

@Prathameshlabde
Copy link
Author

hello @mansimakwana25 as per your solution i had done the changes but now i am facing another issue
error : - IAP req ERROR %%% undefined subscriptionOffers are required for Google Play subscriptions

requestSubscriptionFM = async (sku) => {
    await NetInfo.fetch().then(async (state) => {
        if (state.isConnected) {
            this.startLoader();
            try {
                RNIap.getProducts(sku);
                await RNIap.requestSubscription({ sku })
                    .then(async (result) => {
                        console.log('IAP req sub', result);
                        if (Platform.OS === 'android') {
                            console.log("android sbscription");
                            this.setState({
                                iapPurchaseToken: result.purchaseToken,
                                iapPackageName: result.packageNameAndroid,
                                iapProductId: result.productId,
                            });
                            // can do your API call here to save the purchase details of particular user
                        } else if (Platform.OS === 'ios') {
                            console.log("ios subscription", result.transactionReceipt);

                            this.setState({
                                iapProductId: result.productId,
                                iapReceipt: result.transactionReceipt,
                            });

                            // can do your API call here to save the purchase details of particular user
                        }
                        this.stopLoader();
                    })
                    .catch((err) => {
                        this.stopLoader();
                        console.warn(
                            `IAP req ERROR %%%%% ${err.code}`,
                            err.message,
                            // isModalVisible,
                        );
                        this.setState({ iapError: err.message });
                        // setError(err.message);
                    });
            } catch (err) {
                // setBuyIsLoading(false);
                this.stopLoader();

                console.warn(`err ${err.code}`, err.message);
                this.setState({ iapError: err.message });
                // setError(err.message);
            }
        }
    });
};

@mansimakwana25
Copy link

Hi @Prathameshlabde, yes for android you have to pass subscriptionOffers key in requestSubscription function, here is the sample code hope it will help

const offerToken = subscriptions[0].subscriptionOfferDetails[0].offerToken;
await requestSubscription({
    sku,
    subscriptionOffers: [{ sku, offerToken }],
})

subscriptions are the product array that you will find from getSubscriptions method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants