How to know if a user has used a free trial with Google Play Billing Library?

Viewed 848

I can't seem to find any relevant information in the Purchase object returned by Google. I know there is a "getFreeTrialPeriod()" method for SkuDetails, but that only returns the duration of the free trial, and not if the user used the free trial or not.

Any ideas? Thanks!

1 Answers

This is only possible if you use backend to process subscriptions. Then from your server you can make a request that will return you JSON with purchase information, where you can find paymentState field.

Possible values:

  • 0 - Payment pending
  • 1 - Payment received
  • 2 - Free trial

You can use it if you want to determine if the trial is active now. To determine if a trial was active in the past, your server should receive Real-time developer notifications and store information about purchased subscriptions.

For example, when you receive SUBSCRIPTION_PURCHASED notification, you can make the same request as above, to retrieve information about purchase. In the JSON you'll get there will be priceAmountMicros field. It should be 0 for trial. So you can store that on your server and check for it later.

Related