Hi, I’m a little new to unity android development, trying to get IAP working with a generic test app. Currently I’m able to purchase items using OpenIAB.purchase(“sku”) but I want to make some consumable items on the store, and i’ve read that I need to consume() the items immediately after successfully purchasing, however I can’t quite figure out how to get the Purchase item thats used in the consumeProduct(Purchase) method. Also I can’t quite figure out how to use the queryInventory method either, this is the only documentation that I’m working off: https://github.com/onepf/OpenIAB/tree/master/unity_plugin
Anyone else use this plugin maybe able to help me out?
Add the PurchaseSucceeded method which receives a Purchase object and consume the item there:
private void PurchaseSucceeded(Purchase prod)
{
if (prod.Sku == ...) //check that the product is a consumable item
{
OpenIAB.consumeProduct(prod);
}
}
After you’ve mapped your skus and initialized OpenIAB, it will fire its OpenIABEventManager.billingSupportedEvent. Subscribe to this event with your own method as stated above and let it call OpenIAB.queryInventory(string array with your IAP skus).
We’ve implemented OpenIAB for iOS and Android in our Simple IAP System plugin.
If i screwed up and forgot to consumn the items while testing… is there a way to free them up again? Now that ived bought them all it wont let me buy them again because i forgot to consume them…
The OpenIABEventManager.queryInventorySucceededEvent actions returns your inventory on the device once it is ready. Subscribe to its callback as shown above and iterate over all products to consume them (remove it after testing):
//subscribed to queryInventorySucceededEvent
private void ProductDataReceived(Inventory inv)
{
List<Purchase> prods = inv.GetAllPurchases();
for(int i = 0; i < prods.Count; i++)
OpenIAB.consumeProduct(prods[i])
}
Thanks. But somehow consume purchase is detecting fake purchases (assuming my analytics are correct).
In my game analytics, I’ve noticed fake purchases on ios where a user is repeatedly trying to buy consumable product.
My application receive OnPurchaseSuccess callback. Then it try to consume the purchase - which results in onConsumeFailed callback - “Error: product does not exist”. This makes me wonder how consume product is protecting against those fake purchases?
Consuming a product does not prevent fake purchases at all, it’s just an internal thing that lets your users buy the product again. If you want to protect your app against fake purchases, you should consider implementing receipt verification and only grant the item if the result has been verified.