Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to check if subscription is renewed?

I have an android app with renewable monthly subscriptions. In this app I want to notify user some info when his subcription continues in next month.

As I can see renewals in merchant center(orderId ends with eg. ..0, ..1), but when querying the inventory my purchase orderId is same as befor eq.

{
    "orderId": "GPA.XXXX-YYYY-XXXX-ZZZZZ",
    "packageName": "my.packageName",
    "productId": "my.sku",
    "purchaseTime": 1456398623654,
    "purchaseState": 0,
    "developerPayload": "mypayload",
    "purchaseToken": "token",
    "autoRenewing": true
}

What bothers me more is that purchaseTime also doesn't change.

So my question is: If there is any way to detect in app that renewal occured?

Edit:

I'm using Google Play Developer API to get subscription info and then calculate number of renewals myself.

like image 421
Axxxon Avatar asked Apr 13 '16 07:04

Axxxon


People also ask

How do I see all my Subscriptions?

On an Android device, go to the Play Store, then tap the menu icon (the box with lines in the upper left corner) and look for “subscriptions.” And on the Amazon website, use the “accounts and lists” drop-down menu next to the search bar to click on “memberships and subscription.”


1 Answers

Order id for all recurrences are returned in orderId field of the INAPP_PURCHASE_DATA JSON field (in V3) with each recurring transaction appended by an integer.

Subscription order numbers

To help you track transactions relating to a given subscription, Google payments provides a base Merchant Order Number for all recurrences of the subscription and denotes each recurring transaction by appending an integer as follows:

GPA.1234-5678-9012-34567 (base order number)
GPA.1234-5678-9012-34567..0 (first recurrence orderID)
GPA.1234-5678-9012-34567..1 (second recurrence orderID)
GPA.1234-5678-9012-34567..2 (third recurrence orderID) ...

But due to local caching you might not get the latest information. So try clearing cache from application manager to first see if you get correct purchase information.

Since purchase query this way is not reliable, it makes more sense to call Google Play Developer Purchases.subscriptions: get API from a backend to get Purchases.subscriptions resource which will return expiryTimeMillis of current subscription.

{
  "kind": "androidpublisher#subscriptionPurchase",
  "startTimeMillis": long,
  "expiryTimeMillis": long,
  "autoRenewing": boolean,
  "priceCurrencyCode": string,
  "priceAmountMicros": long,
  "countryCode": string,
  "developerPayload": string,
  "paymentState": integer,
  "cancelReason": integer
}
like image 162
random Avatar answered Sep 18 '22 08:09

random