In Google Play Billing Library 5 there are ProductDetais instead of deprecated SkuDetails. SkuDetails had freeTrialPeriod field which returned free trial of subscribtion. In ProductDetails I can't find any similar field, is there a way to get free trial period from ProductDetails?
Asked
Active
Viewed 1,428 times
1 Answers
7
Yes, there is a way. First check that this is a subscription (and not a one-time purchase). Then get the pricing plan that you need. The free trial period is always the first pricing phase of the pricing plan and will have priceAmountMicros = 0 and FormattedPrice="free". If the first pricing phase in your pricing plan matches the criteria, you can use its billing period as the trial period.
int trialDays = -1;
if(BillingClient.ProductType.SUBS.equals(productDetails.getProductType()))
{
List<ProductDetails.SubscriptionOfferDetails> subscriptionPlans = productDetails.getSubscriptionOfferDetails();
ProductDetails.SubscriptionOfferDetails pricingPlan = subscriptionOffers.get(planIndex);
ProductDetails.PricingPhase firstPricingPhase = offer.getPricingPhases().getPricingPhaseList().get(0);
if(firstPricingPhase.getPriceAmountMicros() == 0)
{
trialDays = BillingFlavor.parseDuration(firstPricingPhase.getBillingPeriod());
}
}
return trialDays;

M.Paunov
- 1,737
- 1
- 15
- 19
-
2They made it harder... – SUR4IDE Nov 11 '22 at 05:24
-
What is BillingFlavor? Where did you get from? – abalta Dec 20 '22 at 10:33
-
This is my class which handles billing logic. You need to parse the billing period yourself. From the documentation of getBillingPeriod(): "Billing period for which the given price applies, specified in ISO 8601 format. For example, P1W equates to one week, P1M equates to one month, P3M equates to three months, P6M equates to six months, and P1Y equates to one year. " – M.Paunov Dec 22 '22 at 09:12