react-native-iap icon indicating copy to clipboard operation
react-native-iap copied to clipboard

Android users not eligible for free trial

Open fbotalla opened this issue 1 year ago • 13 comments

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

fbotalla avatar Jul 03 '23 21:07 fbotalla

Hello, @fbotalla I'm having the same problem; did you find a solution?

shivanitp avatar Jul 13 '23 05:07 shivanitp

check this link: https://usmanabid477.medium.com/in-app-purchase-integration-in-react-native-app-96c0acd13649

usmanabid94 avatar Jul 13 '23 06:07 usmanabid94

@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 avatar Jul 13 '23 08:07 fbotalla

@fbotalla it works for me now i will also try with the new updated one,s as you mentioned.

usmanabid94 avatar Jul 13 '23 08:07 usmanabid94

@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?

shivanitp avatar Jul 13 '23 08:07 shivanitp

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..

fbotalla avatar Jul 13 '23 09:07 fbotalla

@shivanitp or @usmanabid94 were you guys able to find a solution?

fbotalla avatar Jul 19 '23 07:07 fbotalla

@fbotalla In my case, I find the solution by parsing the correct offerToken and updating the library.

shivanitp avatar Jul 19 '23 07:07 shivanitp

@shivanitp Could you share how you're parsing the offerToken?

Also are you on "react-native-iap": "^12.10.5", ?

Thanks!

fbotalla avatar Jul 19 '23 08:07 fbotalla

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 avatar Jul 19 '23 09:07 shivanitp

@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 avatar Jul 19 '23 12:07 fbotalla

@fbotalla @shivanitp Hey guys!) I have the same issue, Do you have any updates?) I hope good news

Yevgen32 avatar Feb 14 '24 10:02 Yevgen32