1. Are you ready for the Galaxy S20? Here is everything we know so far!

Will A Consumed IAP Still Appear in Purchases?

Discussion in 'Android Development' started by RewindJAA, Sep 16, 2020.

  1. RewindJAA

    RewindJAA Newbie
    Thread Starter

    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 (Text):
    1.  
    2. void handlePurchases(List<Purchase>  purchases) {
    3.        String str;
    4.        int numberOfPurchases = 0;
    5.  
    6.        for(Purchase purchase:purchases) {
    7.            switch(purchase.getPurchaseState()) {
    8.                case Purchase.PurchaseState.PURCHASED:
    9.                    if (!verifyValidSignature(purchase.getOriginalJson(), purchase.getSignature())) {
    10.                        // Invalid purchase
    11.                        // show error to user
    12.                        Toast.makeText(getApplicationContext(), "Error : Invalid Purchase", Toast.LENGTH_SHORT).show();
    13.                        return;
    14.                    }
    15.                    // else purchase is valid
    16.                    //if item is purchased and not acknowledged
    17.                    if (!purchase.isAcknowledged()) {
    18.                        AcknowledgePurchaseParams acknowledgePurchaseParams =
    19.                                AcknowledgePurchaseParams.newBuilder()
    20.                                        .setPurchaseToken(purchase.getPurchaseToken())
    21.                                        .build();
    22.                        mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, ackPurchase);
    23.                    }
    24.                    //else item is purchased and also acknowledged
    25.                    else {
    26.                        numberOfPurchases++;
    27.  
    28.                        // HOW DOES IT KNOW IF IT IS CONSUMED???
    29.  
    30.                        // DONT DELETE - if you want to keep on consuming
    31.                        // ConsumeParams consumeParams = ConsumeParams.newBuilder()
    32.                        //        .setPurchaseToken(purchase.getPurchaseToken())
    33.                        //        .build();
    34.                        //
    35.                        //ConsumeResponseListener consumeResponseListener = new ConsumeResponseListener() {
    36.                        //    @Override
    37.                        //    public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
    38.                        //
    39.                        //        Toast.makeText(DiamondsActivity.this, "Purchase successful", Toast.LENGTH_SHORT).show();
    40.                        //
    41.                        //        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
    42.                        //
    43.                        //            if (purchase.getSku().equalsIgnoreCase(ITEM_SKU_diamond_500)) {
    44.                        //                Toast.makeText(DiamondsActivity.this, "Thank you for purchasing!", Toast.LENGTH_SHORT).show();
    45.                        //            }
    46.                        //        }
    47.                        //    }
    48.                        //};
    49.                        //billingClient.consumeAsync(consumeParams, consumeResponseListener);
    50.                    }
    51.                    break;
    52.                case Purchase.PurchaseState.PENDING:
    53.                    Toast.makeText(getApplicationContext(), "Purchase is Pending. Please complete Transaction", Toast.LENGTH_SHORT).show();
    54.                    break;
    55.                case Purchase.PurchaseState.UNSPECIFIED_STATE:
    56.                    Toast.makeText(getApplicationContext(), "Purchase Status Unknown", Toast.LENGTH_SHORT).show();
    57.                    break;
    58.            }
    59.        }
    60.    }
    61.  
    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?
     


Loading...
Similar Threads - Consumed IAP Still
  1. Alex Marasco
    Replies:
    0
    Views:
    163
  2. chris096
    Replies:
    7
    Views:
    929
  3. ddfs
    Replies:
    0
    Views:
    269
  4. TF_Social
    Replies:
    1
    Views:
    1,235
  5. Gaggz
    Replies:
    6
    Views:
    13,532
  6. Yoseph8
    Replies:
    0
    Views:
    330
  7. kpdunn
    Replies:
    0
    Views:
    354
  8. MoodyBlues
    Replies:
    0
    Views:
    588
  9. MoodyBlues
    Replies:
    49
    Views:
    3,458
  10. Sebastián García
    Replies:
    2
    Views:
    718

Share This Page

Loading...