Solved

How do I check the user's eligibility for intro pricing and free trials on Android?

  • 23 July 2021
  • 2 replies
  • 165 views

Badge

I have set up various products on play store and am able to fetch them successful via the Purchases.sharedInstance.getOfferingsWith function. 

Some of my products have introductory pricing and/or free trials. I have tried testing this functionality and it seems to work. The problem I am running into now is if I have a user that has made use of the free trial or intro pricing for the subscription, cancels the subscription, and then wants to resubscribe I don’t appear to have a way to tell that the user is not longer eligible for intro pricing or free trials. The only way to tell is only after the user has started to go through the play store billing flow, but I need to display the correct information about the product in my app’s UI.

icon

Best answer by sharif 23 July 2021, 23:55

Since there’s no checkTrialOrIntroductoryPriceEligibility method on Android, you have to manually check whether a product has been purchased before showing an intro offer.

If you attach your products to entitlements, this can be done by looping over the EntitlementInfos found in the PurchaserInfo (Kotlin and Java save you from looping by using the isNotEmpty() method):

if (purchaserInfo.entitlements.all.isNotEmpty()) {
// user has had access to an entitlement which means they're not eligible for the offer
// remove offer messaging
} else {
// user has never had access to any entitlements
// show intro offer
}

If you want to check whether a user has ever had access to a specific entitlement:

if (purchaserInfo.entitlements["your_entitlement_id"] != null) {
// user has had access to "your_entitlement_id" which means they're not eligible for the offer
// remove offer messaging
} else {
// user has never had access to "your_entitlement_id"
// show intro offer
}

If you don’t use entitlements, you’ll have to use the allPurchaseDatesByProduct property of the PurchaserInfo to check if a product has been previously purchased.

View original

2 replies

Userlevel 2
Badge +6

Since there’s no checkTrialOrIntroductoryPriceEligibility method on Android, you have to manually check whether a product has been purchased before showing an intro offer.

If you attach your products to entitlements, this can be done by looping over the EntitlementInfos found in the PurchaserInfo (Kotlin and Java save you from looping by using the isNotEmpty() method):

if (purchaserInfo.entitlements.all.isNotEmpty()) {
// user has had access to an entitlement which means they're not eligible for the offer
// remove offer messaging
} else {
// user has never had access to any entitlements
// show intro offer
}

If you want to check whether a user has ever had access to a specific entitlement:

if (purchaserInfo.entitlements["your_entitlement_id"] != null) {
// user has had access to "your_entitlement_id" which means they're not eligible for the offer
// remove offer messaging
} else {
// user has never had access to "your_entitlement_id"
// show intro offer
}

If you don’t use entitlements, you’ll have to use the allPurchaseDatesByProduct property of the PurchaserInfo to check if a product has been previously purchased.

With this method you can’t detect if an user was suscriber without use a trial/intro period. So this works only if all your suscriptions has intro/trial offer. What happens if the first subscription was without offer → Unsuscribe. If you send a trial offer this code wont show it, because the user had bought this entitlement before.

Reply