Android - How to check if subscription is renewed?

2019-02-12 08:34发布

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.

2条回答
对你真心纯属浪费
2楼-- · 2019-02-12 08:51

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
}
查看更多
聊天终结者
3楼-- · 2019-02-12 08:53

The purchase data for subscriptions is returned only when the subscription is active. If the subscription expires then you won't get this purchase data when you query the inventory.

Excerpt from the link

If a recurring payment fails (for example, because the customer’s credit card has become invalid), the subscription does not renew. The getPurchases() method does not return failed or expired subscriptions.

查看更多
登录 后发表回答