react-native-iap
react-native-iap copied to clipboard
Android users not eligible for free trial
All of my new Android users are NOT eligible for the free trial.
I am using the correct way:
... subscriptionOffers: [{sku: productId, offerToken}], ...
My Google Play subscription environment is set up correctly with the free trial as an offer to new users.
"react-native-iap": "^12.10.5", "react-native": "0.71.8", Android devices
Hello, @fbotalla I'm having the same problem; did you find a solution?
check this link: https://usmanabid477.medium.com/in-app-purchase-integration-in-react-native-app-96c0acd13649
@shivanitp Unfortunately no, I am not sure if this library is really being maintained much anymore. @usmanabid94 Thanks for the suggestion. Isn't that medium post a bit outdate with the current version of iap ?
The only main difference I see in it anyway is implementation ‘com.android.billingclient:billing:4.0.0’
I checked the example repo and it looks like they don't even use it on their example.
@fbotalla it works for me now i will also try with the new updated one,s as you mentioned.
@fbotalla yes, you are right this example has an old library version.
do you have any idea about how to pass the offer id when purchasing a subscription?
What I do is this:
subs are all my subscription offerToken looks like this:
let offerTokens: any = {
"productId1": "",
"productId2": "",
};
This happen as an initialize function. UseEffect if you want This works in my case cos I only have one offer per subscription.. if you had more I don't think this would work
subs.forEach((sub: any) => {
sub?.subscriptionOfferDetails?.forEach((offer: any) => {
offerTokens[sub.productId] = offer.offerToken;
});
});
Then when user buys sub
const buySubscription = async (sku: any) => {
let offerToken = offerTokens[sku];
try {
await requestSubscription({
sku,
...(offerToken && {
subscriptionOffers: [{sku, offerToken}],
}),
});
} catch (error) {
if (error instanceof PurchaseError) {
console.log(`[${error.code}]: ${error.message}`, error);
} else {
console.log('handleBuySubscription', error);
}
}
};
Hope this helps. I do get the correct offerToken, but my android users al NOT eligible for free trials..
@shivanitp or @usmanabid94 were you guys able to find a solution?
@fbotalla In my case, I find the solution by parsing the correct offerToken and updating the library.
@shivanitp Could you share how you're parsing the offerToken?
Also are you on "react-native-iap": "^12.10.5", ?
Thanks!
yes, it's latest "react-native-iap": "^12.10.5"
// get the subscritption var subscriptions = await RNIap.getSubscriptions({ skus: skus });
// after slecting plan buyProductId let offerToken = null let selectedPlan = subscriptions.find(x => x.productId === buyProductId) if (selectedPlan) { var trailAvailableIndex = selectedPlan.subscriptionOfferDetails.findIndex(x => x.offerId == "freetrial") if (trailAvailableIndex > -1) { offerToken = selectedPlan.subscriptionOfferDetails[trailAvailableIndex].offerToken; } }
request purchase let subscriptionOffers = [{sku: sku,offerToken: offerToken,}]
let purchase = await requestSubscription({ subscriptionOffers })
@shivanitp
Thank you I will test it out on my end.
just double checking..
await requestSubscription({sku, subscriptionOffers}) and not requestSubscription({ subscriptionOffers })
right? I get an error when I have requestSubscription({ subscriptionOffers }) on iOS, because it requires a sku.
@fbotalla @shivanitp Hey guys!) I have the same issue, Do you have any updates?) I hope good news