简体   繁体   中英

How can I know that user just renewed a google play subscription?

I'm working with google play subscription and couldn't figure out how to know when user renewed the plan for one more period. I'm giving 3 credit's to use one feature of my app, and each month the user would receive 3 more credit's if renewed the subscription.
I'm monitoring the user plan using this method below, but it caches the user subscription for a while, so I'm afraid of giving the user 3 more credits when he actually did not renewed the subscription.

fun queryPurchases() {
    val purchasesResult = mBillingClient?.queryPurchases(BillingClient.SkuType.SUBS)
    if (mBillingClient?.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS)?.responseCode ==  BillingClient.BillingResponseCode.OK) {
        if (purchasesResult?.responseCode == BillingClient.BillingResponseCode.OK) {
            purchasesResult.purchasesList?.addAll(
                    purchasesResult.purchasesList)
        }
    }

    if (purchasesResult != null && purchasesResult.purchasesList != null) {
        if (purchasesResult.purchasesList.isEmpty()){
            purchasedPlan.postValue(null)
        }else {
            purchasedPlan.postValue(purchasesResult.purchasesList[0])
        }
    }
}

How can i handle this situation properly? I thought about giving the user 3 credits anyway on the following month and remove 3 credits if suddenly the plan turns out a free plan, but I think this approach would be very abusable

To get the most recent information about subscriptions you can use queryPurchaseHistoryAsync() instead of queryPurchases() . You can combine it with your local caching algorithm to reduce abuse level. Link to documentation

Warning: queryPurchaseHistoryAsync() makes a network call, which could result in a charge to the app user.

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