• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Will A Consumed IAP Still Appear in Purchases?

RewindJAA

Newbie
Jun 13, 2018
27
6
I am in Android Studio. When I get my purchases it still shows a purchase I thought I had consumed.

Here is my handlePurchases:

Code:
void handlePurchases(List<Purchase>  purchases) {
       String str;
       int numberOfPurchases = 0;

       for(Purchase purchase:purchases) {
           switch(purchase.getPurchaseState()) {
               case Purchase.PurchaseState.PURCHASED:
                   if (!verifyValidSignature(purchase.getOriginalJson(), purchase.getSignature())) {
                       // Invalid purchase
                       // show error to user
                       Toast.makeText(getApplicationContext(), "Error : Invalid Purchase", Toast.LENGTH_SHORT).show();
                       return;
                   }
                   // else purchase is valid
                   //if item is purchased and not acknowledged
                   if (!purchase.isAcknowledged()) {
                       AcknowledgePurchaseParams acknowledgePurchaseParams =
                               AcknowledgePurchaseParams.newBuilder()
                                       .setPurchaseToken(purchase.getPurchaseToken())
                                       .build();
                       mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, ackPurchase);
                   }
                   //else item is purchased and also acknowledged
                   else {
                       numberOfPurchases++;

                       // HOW DOES IT KNOW IF IT IS CONSUMED???

                       // DONT DELETE - if you want to keep on consuming
                       // ConsumeParams consumeParams = ConsumeParams.newBuilder()
                       //        .setPurchaseToken(purchase.getPurchaseToken())
                       //        .build();
                       //
                       //ConsumeResponseListener consumeResponseListener = new ConsumeResponseListener() {
                       //    @Override
                       //    public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
                       //
                       //        Toast.makeText(DiamondsActivity.this, "Purchase successful", Toast.LENGTH_SHORT).show();
                       //
                       //        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                       //
                       //            if (purchase.getSku().equalsIgnoreCase(ITEM_SKU_diamond_500)) {
                       //                Toast.makeText(DiamondsActivity.this, "Thank you for purchasing!", Toast.LENGTH_SHORT).show();
                       //            }
                       //        }
                       //    }
                       //};
                       //billingClient.consumeAsync(consumeParams, consumeResponseListener);
                   }
                   break;
               case Purchase.PurchaseState.PENDING:
                   Toast.makeText(getApplicationContext(), "Purchase is Pending. Please complete Transaction", Toast.LENGTH_SHORT).show();
                   break;
               case Purchase.PurchaseState.UNSPECIFIED_STATE:
                   Toast.makeText(getApplicationContext(), "Purchase Status Unknown", Toast.LENGTH_SHORT).show();
                   break;
           }
       }
   }

The critical bit is where it say // HOW DOES IT KNOW IF IT IS CONSUMED???.

How do I tell if a purchase has been consumed?

Should the consumed purchase still be in the purchases array?

Is there something I should be doing in my Google Play Programmer Account for the IAP, ie a flag of some sort to say it is consumable?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones