Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check purchase state of subscription in all new Play Billing Library?

Hi am using new Play Billing Library for in app subscriptions. https://developer.android.com/google/play/billing/billing_library.html

Everthing works perfect and am able to subscribe the product. But i didn't find any ways to check the purchase state of subscription. I mean whether it is active or expired.

In the documentation it says : You can then call a variety of methods on the Purchase object to view relevant information about the item, such as its purchase state or time.

But there is no purchase state method in Purchase Object, check link below https://developer.android.com/reference/com/android/billingclient/api/Purchase.html

Take a look at this video too : https://www.youtube.com/watch?v=9chvh1WYCvw&feature=youtu.be&t=301

How is it possible to check the purchase state?

like image 724
jomin v george Avatar asked Dec 06 '22 12:12

jomin v george


1 Answers

This is an old question and you may have solved it. I've just started using the new library and I have the same question. Reading the javadoc for the Purchase class I think you have to use:

isAutoRenewing()

This will return false for any subscription that has been cancelled. It returns true for any subscription that is active or is in the grace period.

Just an update to this. This won't work in the case of a subscription that has been cancelled and has not expired.

I found it odd that the above commentators seem to be in disagreement. Further investigation reveals that the two different queries for purchases give different results - something that the javadoc doesn't seem to make clear.

queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS, listener)

will, as its javadoc explains, return everything - including all expired subscriptions. Using this there doesn't seem to be a way to differentiate between active and inactive subscriptions. This returns the history as it currently is on Google servers.

queryPurchases(BillingClient.SkuType.SUBS)

returns only the current active subscriptions. It returns a cached result immediately.

like image 164
cbn Avatar answered Dec 21 '22 22:12

cbn