CJara
CJara

Reputation: 69

Know when a suscription was cancelled - Play Billing 1.0

I'm using this tuto to integrate Play Billing Library to my app: http://www.androidrey.com/implement-play-billing-library-in-android-application/ and all works good ... well, not at all. I have problems to know when a suscription was cancelled, I tested all the methods to find a resultCode or something to know this state, but have a method that I could not implement. Could be this the problem?

class: BillingManager.java

public void queryPurchases() {
    Runnable queryToExecute = new Runnable() {
        @Override
        public void run() {
            long time = System.currentTimeMillis();
            Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
            if (areSubscriptionsSupported()) {
                Purchase.PurchasesResult subscriptionResult
                        = billingClient.queryPurchases(BillingClient.SkuType.SUBS);
                System.out.println("QUERY 0");
                if (subscriptionResult.getResponseCode() == BillingClient.BillingResponse.OK) {
                    purchasesResult.getPurchasesList().addAll(
                            subscriptionResult.getPurchasesList());
                    System.out.println("QUERY 1");
                } else {
                    // Handle any error response codes.
                }
            } else if (purchasesResult.getResponseCode() == BillingClient.BillingResponse.OK) {
                // Skip subscription purchases query as they are not supported.
                System.out.println("QUERY 2");
            } else {
                // Handle any other error response codes.
                System.out.println("QUERY 3");
            }
            onQueryPurchasesFinished(purchasesResult);
            System.out.println("QUERY RESULT "+ purchasesResult);
        }
    };

    executeServiceRequest(queryToExecute);
}

private void onQueryPurchasesFinished(Purchase.PurchasesResult result) {
    // Have we been disposed of in the meantime? If so, or bad result code, then quit
    if (billingClient == null || result.getResponseCode() != BillingClient.BillingResponse.OK) {
        Log.w(TAG, "Billing client was null or result code (" + result.getResponseCode()
                + ") was bad – quitting");
        return;
    }

    Log.d(TAG, "Query inventory was successful.");

    // Update the UI and purchases inventory with new list of purchases
    // mPurchases.clear();
    onPurchasesUpdated(BillingClient.BillingResponse.OK, result.getPurchasesList());
}

public boolean areSubscriptionsSupported() {
    int responseCode = billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS);
    if (responseCode != BillingClient.BillingResponse.OK) {
        Log.w(TAG, "areSubscriptionsSupported() got an error response: " + responseCode);
    }
    return responseCode == BillingClient.BillingResponse.OK;
}

It is supposed to be called here: MyBillingUpdateListener.java

public class MyBillingUpdateListener implements BillingManager.BillingUpdatesListener {
//final BillingManager billingManager = new BillingManager(,this );

@Override
public void onBillingClientSetupFinished() {
    //billingManager.queryPurchases(); THIS IS WHAT I COULD NOT IMPLEMENT 
}

Any help is welcome, thanks!.

Upvotes: 2

Views: 562

Answers (1)

oRRs
oRRs

Reputation: 2292

Play Billing 1.0 does not have the concept of purchase states (anymore), so there currently is no way to get this information using the Play Billing library. My understanding is that queryPurchases is supposed to return actual valid purchases only. However, it gets the information from a long living cache and you have no way of updating it manually.

onBillingClientSetupFinished is completely unrelated.

Here is an active discussion on the subject: https://github.com/googlesamples/android-play-billing/issues/122

Upvotes: 1

Related Questions