5

I am implementing a server-side service that checks user's google play subscriptions status. I use the Android Pubisher API (https://developers.google.com/android-publisher/api-ref/purchases/subscriptions/get) to check the subscription status. Though, I cannot understand how to distinguish if the user is on trial period or if he has already paid (i need it for analytics, to attribute revenue)?

How can this be done?

DataGreed
  • 13,245
  • 8
  • 45
  • 64

1 Answers1

3

When you validate the subscription purchase from your server, you are going to get the subscription resource like that:

{
  "kind": "androidpublisher#subscriptionPurchase",
  "startTimeMillis": long,
  "expiryTimeMillis": long,
  "autoRenewing": boolean,
  "priceCurrencyCode": string,
  "priceAmountMicros": long,
  "countryCode": string,
  "developerPayload": string,
  "paymentState": integer,
  "cancelReason": integer,
  "userCancellationTimeMillis": long
}

The paymentState value has 3 states for subscriptions:

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

You can always call the Google Play API to check this state. API Docs: https://developers.google.com/android-publisher/api-ref/purchases/subscriptions#resource

Bruno Paulino
  • 5,611
  • 1
  • 41
  • 40
  • how to get this json when a user purchase – Aravind jayan Mar 02 '21 at 13:19
  • @Aravindjayan you need to POST the purchase data from your Android App to your backend and validate it against Google APIs. [Here is another answer](https://stackoverflow.com/a/44873018/2301092) showing how you can get access to validation tokens via your backend using Google APIs – Bruno Paulino Mar 02 '21 at 14:45