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 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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With