Currently I'm testing my app's in app billing. I'm trying to buy items and test signature verification etc. The problem comes when I need to purchase a item again: I consumed the purchase but it still says I own the product when I try to buy it and now after consuming the purchase once the getPurchases() method says I don't own anything. Am I doing something wrong here? Is it a bug in the V3 API? And if I can't consume the purchase from my app, can I consume it from somewhere else?
Consume purchase:
try {
//Get purchases and consume them all
Bundle b = mac.service.getPurchases(3, package, "inapp", null);
ArrayList<String> datalist = b.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
for(String str : datalist) {
JSONObject jpurchase = new JSONObject(str);
String token = jpurchase.getString("purchaseToken");
mac.service.consumePurchase(3, package, token);
}
} catch (Exception e) {
e.printStackTrace();
}
Buy items:
//Get buy intent and send it
PendingIntent buyIntent = mac.service.getBuyIntent(3, package, purchasepopup.id, //purchasepopup.id = item id
"inapp", "").getParcelable("BUY_INTENT");
if(buyIntent != null) mac.startIntentSenderForResult(buyIntent.getIntentSender(),
1002, new Intent(), 0, 0, 0);
It seems like this is a bug in Google's API where if you start multiple buy intents at once before the first one ends, you can buy the item multiple times. And when you try to consume the item, it only consumes the first(or last) purchase and the rest are stuck on your account but won't show on queries.
How to fix:
Make sure your app only calls a buy intent when the user doesn't own it and only send one intent. If you have a item(s) stuck on account(s) and want to remove them you can either
1) Delete the bugged items from your app trough Google Play Console and create new ones (this is not good if you have already published the game on Google Play and somebody has bought a bugged item) or
2) Delete the items directly from your account (I don't know how to do this but it should be possible. If you know how to do this, please comment it, so I can add it.)