Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Google Play subscription expiration date from backend server

I'm astonished to find very little documentation or examples about obtaining the expiration date for a Play Store subscription. Throughout the official In-app Billing documentation, the following is noted:

When the user successfully purchases a new subscription, your app notifies a backend server, which stores the purchase token, user name, and other information in a secure location.

Since your app cannot know the expiration date, your server can poll Google Play to get the expiration and store it with the purchase token and other data.

Because your server now knows the expiration date, it does not need to poll Google Play again until after the expiration date, at which time it can confirm that the subscription was not cancelled.

In my app I'm able to obtain an Authorization Token via OAuth and a Purchase Token (using convenience methods for in-app billing) and I can send that information to my back end server. However at that point I can find little information on what to do with those tokens once I have them. The only information I've been able to uncover is reference to Google APIs Client Libraries, which provides sample libraries for various languages Client Libraries (I happen to be using PHP). Inspection of the PHP "Documentation" sample (Getting up and running in 60 seconds LOL), shows the following line of code:

$client->setApplicationName('Google+ PHP Starter Application');

What does this have to do with finding a subscription expiration date???? It seems to me that the parameter passed to setApplicationName should have some reference to the Play Store, but there seems to be NO reference to the Play Store in the list of samples (i.e. Google Analytics API, YouTube Data API, etc) Google APIS

So I'm really at a loss on how to move forward.

Any direction would be appreciated.

like image 981
user1168400 Avatar asked Jul 12 '13 15:07

user1168400


1 Answers

You need to use the Purchase Status API, which has the Purchases:get method which takes a packageName, subscriptionId, and token and returns a Purchases resource, which contains (among other things) the validUntilTimestampMsec field which is the time at which the subscription will expire.

like image 80
ianhanniballake Avatar answered Sep 30 '22 23:09

ianhanniballake