Reputation: 12103
I have implemented this project for in app billing https://github.com/blundell/SimpleInAppPurchaseV3 . Everything looks to work except not all Purchased Products are being returned for Inventory
object.
I started with multiple products with id’s that have the same prefix, using a java package format
acmestudio.myapp.upgrade1.red
acmestudio.myapp.upgrade1.blue
acmestudio.myapp.upgrade1.green
This is where the issue started. The first one I purchased, acmestudio.myapp.upgrade1.red worked and shows up in the purchased items for Inventory.
However, there after .. purchasing the other ones would:
I thought maybe it was a format issue, so I changed the dot-notation to be underscores. However, again the same thing happened. Now I have the multiple products with these id’s
acmestudio_myapp_upgrade1_red
acmestudio_myapp_upgrade1_blue
acmestudio_myapp_upgrade1_green
And again, it only worked for the 1st one. So now in my list of purchased Skus, it has: [acmestudio.myapp.upgrade1.red, acmestudio_myapp_upgrade1_blue]
And this happens, even though I see this Order Confirmation returned from the Billing API
PurchaseInfo:{"orderId":"GPA.1390-8158-3067-22151","packageName":"com.acmestudio.myapp”,
”productId":"acmestudio_myapp_upgrade1_red”,”purchaseTime":1455140848461,"purchaseState":0,
"purchaseToken":"akdnfgpkcnckkcdomomimihi.AO-J1OwKCGfAKHDDsBxbKjeVKRZ0hIOSXALhVPeYaKx2GsVGH6NbVDs4nj6sLf48oUy9Zs0MziVA7xFtebELB0Q6udcN_1fvaNynkFLVVJXJmZGeEiRy9c8KH7HIn2QK2SZc1EzB2NLtOoVu324s2EwPmmtLYKj6MA"}
I think I must be missing some step, because I set the debugger to stop here .. inside the github project code for IabHelper.java .. that is, this issue is occuring in the code I haven’t even touched. https://github.com/blundell/SimpleInAppPurchaseV3/blob/master/src/com/android/vending/billing/util/IabHelper.java#L814
ArrayList<String> ownedSkus = ownedItems.getStringArrayList(
RESPONSE_INAPP_ITEM_LIST);
Here’s the code I run to check. Notice I get 2 instances of an inventory object:
In Asynch call
List<String> moreSkus = null;
Inventory inventory = billingHelper.queryInventory(querySkuDetails, moreSkus);
IabHelper.QueryInventoryFinishedListener inventoryLstnr =
new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv)
{
Log.d("Query inventory finished.");
// Is it a failure?
if (result.isFailure()) {
Log.d("Failed to query inventory: " + result);
return;
}
Log.d("Query inventory was successful.");
}
};
billingHelper.queryInventoryAsync(true, inventoryLstnr);
What am I missing here? .. maybe I need unique prefixes?! I will try that next, but it seems it shouldn’t be the case that there would be an issue with that.
Upvotes: 0
Views: 370
Reputation: 12103
Ok, thanks to SO's suggestions as I was posting this question, looks like the issue is related to billingHelper.consumeAsync(..)
call.
By commenting that out, the product Ids that I am purchasing are appearing in the inventory.mPurchaseMap
.
This post I finally stumbled upon explains it perfectly: https://stackoverflow.com/a/25452735/2162226
As the author puts nicely:
This is working as intended - in your code you are consuming the in-app purchase immediately, which means you can then purchase it again ..
There's nothing that says you can't purchase a managed product more than once. What you can't do is purchase a managed product before a previous purchase of the same managed item has been consumed.
This post was SO's suggestion that I saw, and got me going in the right direction: https://stackoverflow.com/a/18808407/2162226
Upvotes: 0