How do I know whether a non consumable item has previously been purchased by the user?
Once we call sdkbox::IAP::refresh() using IAP SDKBOX plugin, the onProductRequestSuccess(const std::vector<Product>& products) is called on the listener. The Product class has no member to tell whether that item was purchased previously.
IabHelper.QueryInventoryFinishedListener mGotInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// handle error here
}
else {
// does the user have the premium upgrade?
mIsPremium = inventory.hasPurchase(SKU_PREMIUM);
// update UI accordingly
}
}
};
You should use sdkbox::IAP::restore()
it will check with all the items purchased with user particular apple ID or gmail ID.
If a non-consumable item is already purchased before and then you run restore() then it will return the purchased item in onSuccess() callback.
you can check the product message like this -
if(p.name == "MY_NON_CONSUMABLE_ITEM_NAME")
{
// set a User Default value, and always take value from that UD to check usability of your item.
}
Summary :
Just call sdkbox::IAP::restore() when the app starts.
Maintain an UserDefault value to enable or disable the IAP items.
Yes, refresh will just invoke the latest data from you Google Developer Console for IAP’s.
But, if you invoke restore() it will check for purchased non-consumable items with the currently signed google account.
Two cases for which I wanted to confirm the expected behaviour
New Purchase : call purchase(item name) This will result in onSuccess() to be called once IAP completes successfully
Existing Purchase: call restore. This will result in onRestored to be called once the restore completes for one single item. Once all the restores completes, onRestoreComplete is called