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

Android users not eligible for free trial #2476

Open
fbotalla opened this issue Jul 3, 2023 · 13 comments
Open

Android users not eligible for free trial #2476

fbotalla opened this issue Jul 3, 2023 · 13 comments

Comments

@fbotalla
Copy link

fbotalla commented Jul 3, 2023

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

@shivanitp
Copy link

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

@usmanabid94
Copy link

@fbotalla
Copy link
Author

fbotalla commented Jul 13, 2023

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

@usmanabid94
Copy link

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

@shivanitp
Copy link

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

@fbotalla
Copy link
Author

fbotalla commented Jul 13, 2023

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 fbotalla changed the title Android users free trial Android users not eligible for free trial Jul 13, 2023
@fbotalla
Copy link
Author

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

@shivanitp
Copy link

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

@fbotalla
Copy link
Author

fbotalla commented Jul 19, 2023

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

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

Thanks!

@shivanitp
Copy link

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 })

@fbotalla
Copy link
Author

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

@Yevgen32
Copy link

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

@micaeldekleyn
Copy link

@shivanitp @fbotalla @Yevgen32 Hey guys! I'm facing the same issue on version 12.15.0. Did you find a solution?

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

5 participants