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

consumeAsync Return Error Code 5

RewindJAA

Newbie
Jun 13, 2018
27
6
I am getting error code 5 which I believe is 'Developer Error'. The mDebugMessage in the BillingResult is Invalid Token. (I have checked the name and I am sure it is correct.)

I am calling consumeAsync("noadverts"); where "noadverts" is the name of my in app product.

When I check my purchases, it records the following:

Code:
{"orderId":"GPA.1111-1111-1111-1111",
"packageName":"myname.com.myname",
"productId":"noadverts",
"purchaseTime":1565188785096,
"purchaseState":0,
"purchaseToken":"edited for length",
"acknowledged":true}

Unusually, when I call:

Code:
int val1 = purchase.getPurchaseState();

then val1 is 1 and not 0 as it suggested in the purchase JSON.

I am using much of the TestDrive example, but without the BillingUpdatesListener.

Code:
public void consumeAsync(final String purchaseToken) {
   // If we've already scheduled to consume this token - no action is needed (this could happen
   // if you received the token when querying purchases inside onReceive() and later from
   // onActivityResult()
   if (mTokensToBeConsumed == null) {
       mTokensToBeConsumed = new HashSet<>();
   } else if (mTokensToBeConsumed.contains(purchaseToken)) {
       //Log.i(TAG, "Token was already scheduled to be consumed - skipping...");
       return;
   }
   mTokensToBeConsumed.add(purchaseToken);

   // Generating Consume Response listener
   final ConsumeResponseListener onConsumeListener = new ConsumeResponseListener() {
       @Override
       public void onConsumeResponse(BillingResult response, String purchaseToken) {
           @BillingClient.BillingResponseCode int responseCode = response.getResponseCode();

           // THIS IS WHERE I GET ERROR CODE 5
       }
   };

   // Creating a runnable from the request to use it inside our connection retry policy below
   Runnable consumeRequest = new Runnable() {
       @Override
       public void run() {
           // Consume the purchase async
           //mBillingClient.consumeAsync(purchaseToken, onConsumeListener);

           ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchaseToken).build();
           // Consume the purchase async
           mBillingClient.consumeAsync(consumeParams, onConsumeListener);
       }
   };

   executeServiceRequest(consumeRequest);
}

Any ideas what might be the issue?

If I try and purchase "noadverts" again I get the error code Item is already owned.
 

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