• 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
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.
 
Thanks for the reply, but I am moving away from using 3rd party stuff. The last 3rd party api I used will be out of date in December this year. They appear to have no intention to update it. So, I want to use the google play apis.
 
POSTMAN is a tool for you to test your API. You can use it to send a request, see whether you get expected output.
If you receive a wrong output, then you probably need to check with API developer.
 
Back
Top Bottom