Friday, 2 August 2019

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



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

No comments:

Post a Comment