Question

Trial Eligibility in Flutter Android


Badge +2

Hi, can you please provide me a full example of getting if Android user is eligible for trial in Flutter application.

 

Your help will be highly appreciated.

Thank you.


17 replies

Userlevel 3
Badge +7

Hi @Neli 

 

I don’t have a full example, but sharing some parts of the code to see if it helps (let me know if it doesn’t).

The flutter repository has a sample app called magic weather with a paywall → https://github.com/RevenueCat/purchases-flutter/blob/main/revenuecat_examples/MagicWeather/lib/src/views/paywall.dart

It gets the store product from the available offering and uses it to render the paywall → https://github.com/RevenueCat/purchases-flutter/blob/main/revenuecat_examples/MagicWeather/lib/src/views/paywall.dart#L67-L79

You can use `final freeOffer = storeProduct.subscriptionOptions?.firstWhere((option) => option.freePhase != null);` to check if there’s a free trial option or not.

 

Hope it helps ;) 

 

Badge +2

Hi Marcos,

Thank you for the provided information, however, I need something else. I need to check whether the user is eligible for trial, not if the product has trial.

Userlevel 3
Badge +7

Ohhh, thanks for clarifying @Neli . The way offers work in Google is different than Apple. When you create an offer in google play console, you have to define the eligibility criteria

 

When play evaluates the eligibility criteria, you don’t need to check anything. Google filters them out if you are not elegible, so if the subscription option is there, you can say the user was elegible for that offer

When selecting developer determined offer, you are in charge of deciding if you apply the offer or not to the user. That is done when performing the purchase, by providing the corresponding offer.

 

One thing to be aware when testing this, there’s heavy caching by Google Play on the device, so if you see any issues with eligibility or offers not being available, you might need to clean the cache of google play

 

Let me know if this makes sense 

Badge +2

Hi Marcos,

Thank you very much for your response. I have tried to delete the cache of Google Play, then I check if the user is eligible for trial by using the following code:

  bool _hasTrial(Package package) {
return package.storeProduct.introductoryPrice != null && package.storeProduct.introductoryPrice?.price == 0.0;
}

Although my user was not eligible for trial, I got true as a result from the function.

Can you please provide me some guidance and sample code on how to check if Android user is eligible for trial or he has used trial previously.

 

Regards,

Neli

Userlevel 3
Badge +7

@Neli 

This is what you would check to see if the user can purchase the free trial → final freeOffer = storeProduct.subscriptionOptions?.firstWhere((option) => option.freePhase != null);

How are you configuring your offer in Google Play and how do you know the user should not be able to purchase the trial?

Badge +2

Hi Marcos, 

I have just tested it but it seems that the storeProduct does not have a property named subscriptionOptions. This is what I am doing:

 bool _hasTrial(Package package) {
final freeOffer = package.storeProduct.subscriptionOptions?.firstWhere((option) => option.freePhase != null);
}

 

Userlevel 3
Badge +7

@Neli what version of flutter SDK are you using? I was assuming that you were on the latest one, my bad

Badge +2

Hi,

I am using purchases_flutter: ^4.13.0.

If it is necessary, I can upgrade. Before that let me ask you if there are any breaking changes or something that I should keep in mind.

Thank you.

Userlevel 3
Badge +7

Yes, there are some changes. 

If you have any problem with it, just tag me again and I can help you

Badge +2

Hi Marcos,

Thank you very much for your suggestions. I didn’t answer to one of your question - we see if the user is eligible for trial from the Google play dialog that appears after tapping the Subscribe button.

When it comes to the new information, can I use the same method in iOS, or maybe it is better to keep using the checkTrialOrIntroductoryPriceEligibility method?

Once again, thank you very much for your support.

Userlevel 3
Badge +7

@Neli I’m happy to help you :) 

`checkTrialOrIntroductoryPriceEligibility` only works in iOS (https://pub.dev/documentation/purchases_flutter/latest/purchases_flutter/Purchases/checkTrialOrIntroductoryPriceEligibility.html) because we have to explicitly check if somebody is elegible or not for a trial or intro price.

Google works differently. We don’t need to check if a user is elegible or not, google does that for us directly. If an offer is available to us, then it means we are eligible. (depending on the eligibility criteria you set when creating the offer in google) That’s why I was asking how did you set the offer in google console.

Badge

Hi @MarcosC,

I’m continuing the work of @Neli.

It looks like everything is ok with the Android side right now, but we have some issues with the iOS free trial eligibility.
We have updated the package to `purchases_flutter: ^5.2.3`

This is our Flutter implementation:
```
final introEligibility = await Purchases.checkTrialOrIntroductoryPriceEligibility([package.storeProduct.identifier]);
```

We receive `introEligibilityStatusUnknown`
With that we have this in the console:
```

[receipt] WARN: 🍎‼️ Unable to load receipt, ensure you are logged in to a valid Apple account.

[receipt] WARN: 🍎‼️ App running in sandbox without a receipt file. Restoring transactions won't work until a purchase is made to generate a receipt. This should not happen in production unless user is logged out of Apple account.

```

No mather what we tried, we always receive `introEligibilityStatusUnknown`.

We have tried with new sandbox users, old users with cleared purchase data.
We have tried it on TestFlight, but the result looks the same.

Any idea?

Badge +1

I am seeing the exact same issue as what lachezar-todorov raised. We receive `introEligibilityStatusUnknown` every single time on iOS. Please help, this seems like a major bug.

Badge

Looks like this is due to the fact that there is no purchase receipt when you test. We assume that introEligibilityStatusUnknown is eligible and it works fine in production.
Revenue cat should update that with more ways to test this logic. Like set a value to a user if he is eligible or not during tests.

Badge +1

oh gotcha, thanks for your quick help. My app still isn’t in production and I presume I cannot test this by installing the app from TestFlight since it will have the same sandbox restrictions. What do you suggest I do?

Badge

You have receipt in test flight, it’s different from the production one, but there is. So test it in TestFlight, but assume the thing just works. I know, it’s hard :) 
In TestFlight you can manipulate your receipt, by resetting test user purchases and creating many sandbox accounts.

Badge +1

Awesome. Thanks.

Reply