Reputation: 1150
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
Upvotes: 2
Views: 339
Reputation: 888
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.
Upvotes: 2