Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get active subscriptions In-app Billing Android

I have used the In-app billing library for adding subscriptions in my app. Everything is working properly but I am unable to find how do I get a Users current active subscription?

As per the docs, the method queryPurchaseHistoryAsync returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed. Due to this, I am unable to know whether a current subscription is active or not.

According to this post, if we cancel the subscription, it will still be considered active for that day. But I am getting the subscriptions in the response which were canceled before 15 days.

Any help will be appreciated. Thanks in advance.

like image 549
Mehul Kanzariya Avatar asked Nov 04 '18 10:11

Mehul Kanzariya


1 Answers

To query users subscription i use this method:

public void querySubscriptions() {
    Runnable queryToExecute = () -> {
        Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);

        if (mBillingClient == null ||
                purchasesResult.getResponseCode() != BillingClient.BillingResponse.OK) {
            return;
        }
        mPurchases.clear();
        onPurchasesUpdated(BillingClient.BillingResponse.OK, purchasesResult.getPurchasesList());
    };

    executeServiceRequest(queryToExecute);
}

If you need more details, ask.

like image 66
Obsthändler Avatar answered Oct 17 '22 05:10

Obsthändler