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

consumeAsync Return Error Code 5

Discussion in 'Android Development' started by RewindJAA, Aug 7, 2019.

  1. RewindJAA

    RewindJAA Newbie
    Thread Starter

    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 (Text):
    1. {"orderId":"GPA.1111-1111-1111-1111",
    2. "packageName":"myname.com.myname",
    3. "productId":"noadverts",
    4. "purchaseTime":1565188785096,
    5. "purchaseState":0,
    6. "purchaseToken":"edited for length",
    7. "acknowledged":true}
    Unusually, when I call:

    Code (Text):
    1. 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 (Text):
    1.  
    2. public void consumeAsync(final String purchaseToken) {
    3.    // If we've already scheduled to consume this token - no action is needed (this could happen
    4.    // if you received the token when querying purchases inside onReceive() and later from
    5.    // onActivityResult()
    6.    if (mTokensToBeConsumed == null) {
    7.        mTokensToBeConsumed = new HashSet<>();
    8.    } else if (mTokensToBeConsumed.contains(purchaseToken)) {
    9.        //Log.i(TAG, "Token was already scheduled to be consumed - skipping...");
    10.        return;
    11.    }
    12.    mTokensToBeConsumed.add(purchaseToken);
    13.  
    14.    // Generating Consume Response listener
    15.    final ConsumeResponseListener onConsumeListener = new ConsumeResponseListener() {
    16.        @Override
    17.        public void onConsumeResponse(BillingResult response, String purchaseToken) {
    18.            @BillingClient.BillingResponseCode int responseCode = response.getResponseCode();
    19.  
    20.            // THIS IS WHERE I GET ERROR CODE 5
    21.        }
    22.    };
    23.  
    24.    // Creating a runnable from the request to use it inside our connection retry policy below
    25.    Runnable consumeRequest = new Runnable() {
    26.        @Override
    27.        public void run() {
    28.            // Consume the purchase async
    29.            //mBillingClient.consumeAsync(purchaseToken, onConsumeListener);
    30.  
    31.            ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchaseToken).build();
    32.            // Consume the purchase async
    33.            mBillingClient.consumeAsync(consumeParams, onConsumeListener);
    34.        }
    35.    };
    36.  
    37.    executeServiceRequest(consumeRequest);
    38. }
    39.  
    Any ideas what might be the issue?

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


  2. wseng92

    wseng92 Android Enthusiast

    Have you tried using API testing tool, example POSTMAN ?
     
  3. RewindJAA

    RewindJAA Newbie
    Thread Starter

    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.
     
  4. RewindJAA

    RewindJAA Newbie
    Thread Starter

    Bump. Please help, I really need an answer for this.
     
  5. wseng92

    wseng92 Android Enthusiast

    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.
     
Loading...
Similar Threads - consumeAsync Return Error
  1. App Update
    Replies:
    0
    Views:
    104
  2. Nirhan
    Replies:
    2
    Views:
    114
  3. ScttLee184
    Replies:
    6
    Views:
    230
  4. Re_D1234
    Replies:
    0
    Views:
    516
  5. MiniBoatin
    Replies:
    8
    Views:
    1,255
  6. beirou
    Replies:
    1
    Views:
    252
  7. notableuser
    Replies:
    10
    Views:
    894
  8. Raksha Agrawal
    Replies:
    0
    Views:
    496
  9. Tdjohnson7700
    Replies:
    22
    Views:
    5,798
  10. Stacey cogswell
    Replies:
    13
    Views:
    489

Share This Page

Loading...