Extension-iap: how to check if user already bought an item?

I want to sell in my game an “unlock” item, but I can’t imagine how to check if user already bought it. I guess that i should to use IAP.queryInventory, but how should i do it properly?
I have found this example: https://gist.github.com/jgranick/9369381, but this possibility is not considered there, and sample that comes with library is difficult for me, so I can’t understand it. I could not find other examples or tutorials on the subject. So if somebody can show me how it works, it will be great.

You might have to keep track of it using a shared object. Can anyone who has done IAP in their projects help share how you track what’s purchased?

I want to do so, as it should be). Shared object isn’t suitable for some cases. Users may play on different devices, for example…

I think that’s how it works:

 private function PURCHASE_QUERY_INVENTORY_COMPLETE(e:IAPEvent):Void
 {
        if (e.productsData != null)
        {
            for (i in 0...e.productsData.length)
            {
                var pr:IAProduct = e.productsData[i];
                if (IAP.inventory != null)
                {
                    if(IAP.inventory.hasPurchase(pr.productID))
                    {
                             //item already bought, restore it
                    }
                }
            }
       }
}
1 Like

Somehow length of e.productsData always is 0. I know that product was purchased, because google transaction successfully completed and i can’t buy the product anymore. I do the following:

IAP.initialize (licenseKey);

private function IAP_onInitSuccess (event:IAPEvent):Void
{
       IAP.addEventListener (IAPEvent.PURCHASE_QUERY_INVENTORY_COMPLETE, onPurchaseQueryInventoryComplete);
       IAP.queryInventory();
}

private function onPurchaseQueryInventoryComplete(e:IAPEvent):Void
{
       trace(e.productsData.length);
}

private function buy():Void
{
       IAP.purchase ("temp");
}

What do i do wrong? Should i use other way?

Maybe you are using consumable items instead of one-time-purchases?
I’ve just checked and e.productsData returns one item for me, so it should work fine.

Maybe. But how to set one-time-purchased item? When i try to add a new product in developer console, i see only two possibilities: “controlled by Google” and “Subscription”. I select “controlled by Google”.

I have my item added as managed one

I too. But something goes wrong (

It’s strangely. IAP.queryInventory(true) works fine, but IAP.queryInventory(); does not work.