Search code examples
androidmobilegoogle-apiin-app-purchasein-app-billing

InApp subscription expired, how to check it server side


I have an expired Android InApp subscription and when I request the status from the Google API I get this JSON

{"autoRenewing":false,"cancelReason":0,"countryCode":"UK","developerPayload":"","expiryTimeMillis":"1509398029890","kind":"androidpublisher#subscriptionPurchase","paymentState":null,"priceAmountMicros":"1390000","priceCurrencyCode":"EUR","startTimeMillis":"1508863149755","userCancellationTimeMillis":"1509313119197"}

The paymentState field is null instead of being 0, 1 or 2

The expiryTimeMillis field is in the past but that is not a reliable way to detect an expired subscription as Google itself suggests to check the status of any subscription which has this field in the past, there is grace period in which the user is still able to renew

I couldn't find any clear indication on the official documentation on how to check if a subscription is expired or not. On the mobile app is easy to detect the expiration: if the subscription doesn't show up it's expired, if it shows on the product list then it's not expired


Solution

  • If there is cancelReason the subscription is cancelled (or set to be cancelled), if the expiryTimeMillis is also in a past, the subscription is fully cancelled now.

    If subscription is in Grace period, it has expiryTimeMillis dynamically updated to future (to the end of Grace period).