简体   繁体   中英

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.

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
}

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.

您可以在您的数据库中提供到期日期,并且每次获取数据时,您都可以使用数据库的值检查到期日期,如果它晚了,则订阅已续订))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM