mService.consumePurchase(3, packageName, purchaseToken) always returns RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API

android, in-app-billing, in-app-purchase

Solution

The purchase token is different from the SKU itself, instead, you should retrieve the `purchaseToken` via code such as:

// Note the null is the continueToken you may not get all of the purchased items
// in one call - check ownedItems.getString("INAPP_CONTINUATION_TOKEN") for 
// the next continueToken and re-call with that until you don't get a token
Bundle ownedItems = service.getPurchases(3, getPackageName(), "inapp", null);
// Check response
int responseCode = ownedItems.getInt("RESPONSE_CODE");
if (responseCode != 0) {
   throw new Exception("Error");
}
// Get the list of purchased items
ArrayList<String> purchaseDataList = 
    ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
for (String purchaseData : purchaseDataList) {
    JSONObject o = new JSONObject(purchaseData);
    String purchaseToken = o.optString("token", o.optString("purchaseToken"));
    // Consume purchaseToken, handling any errors
    mService.consumePurchase(3, getPackageName(), purchaseToken);
}

Problem

I'm always getting "RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API", when trying to consume a purchase with ``` String purchaseToken = "inapp:" + getPackageName() + ":" + productId; int response = 0; try { response = mService.consumePurchase(3, getPackageName(), purchaseToken); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } ``` For that reason, I can always only make a purchase once. However, I need to be able to make the purchase much more often. I've been trying to fix this problem for 2 days now, no success. :/ Making and consuming purchases with SKU "android.test.purchased" works completely fine, however as soon as I export the .apk with the production key and add a live SKU, the purchase only shows up once and then never again. Here some more details - The version code of the .apk in the play store and the exported .apk I'm using on my phone are the same and were signed with the same keystore - I've tried it for both managed and unmanaged products, however that shouldn't matter, because according to the latest in-app billing documentation, managed and unmanaged are treated as managed products and both have to be consumed - I only have 5 SKU items, so it doesn't hit the limit of 20, which was the problem here

Original source

Related problems