2

I'm trying to detect grace period using BillingClient.

The documentation says:

A subscription can go through various state changes throughout its lifecycle, and your app needs to respond to each change. To check the subscriber's state, your app can query using either BillingClient.queryPurchasesAsync() in the Google Play Billing Library or Purchases.subscriptions:get in the Google Play Developer API.

Unfortunately, it seems to me that it is not possible to differentiate between an active subscription and a grace period using BillingClient. In both cases isAutoRenewing flag is set to true and purchaseState is 1. At least that's what I see when I try to reproduce such case in test environment by purchasing subscription using Test card, always approves and then changing to Test card, always declines before subscription is renewed.

Any ideas?

wwwww
  • 339
  • 3
  • 15

2 Answers2

1

I don't think you can since you need the Purchases.subscriptions:get API, as described here:

A subscription can go through various state changes throughout its lifecycle, and your app needs to respond to each change. To check the subscriber's state, your app can query using either BillingClient.queryPurchasesAsync() in the Google Play Billing Library or Purchases.subscriptions:get in the Google Play Developer API.

[ ...]

Grace period if:

  • expiryTimeMillis is in the future // Purchases.subscriptions:get
  • paymentState = pending // Purchases.subscriptions:get
  • autoRenewing = true. // Purchases.subscriptions:get or BillingClient
romainsalles
  • 2,051
  • 14
  • 17
1

I had this same question and asked a developer relations engineer at Google (I tweeted at them).

  • Here is what they told me:
  1. The most secure and recommended way is to have a backend for your app and call subscriptionsv2.get. This will return a purchase object with the field SubscriptionState. Check out ClassyTaxi Server for an example implementaton: HERE

  2. If you do not have a backend, you can infer Grace Period with this combination using the BillingClient:

  • PurchaseState is pending
  • autoRenewing is True ie not a Prepaid sub
  • Entitlement is active`
Tristan Elliott
  • 594
  • 10
  • 8