Get purchase history of user in SDKBOX IAP plugin

Hi,

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.

This can be handled using the java api directly : http://developer.android.com/training/in-app-billing/purchase-iab-products.html.

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
      }
   }
};

Hello @abhinav

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.

Let me know if it solves your issue.

Best,
Pabitra

Just to confirm, we need to call restore once call to refresh completes successfully?

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.

Best,
Pabitra

Hi @pabitrapadhy

restore will call onRestored() and purchase will call onSuccess? Can it happen that restore can call onSuccess as well?

Thanks
-Abhinav-

Hello @abhinav

I dont see the requirement of calling so, could you tell me why do you need it.

I am giving you a scenario

set your current non-consumable IAP item associated with a UserDefault value.
and maintain the value of UD based on the response from onRestored()

Let me know, if you have a use case scenario where I could help you.

Best,
Pabitra

Sorry for being not so clear in my question.

Two cases for which I wanted to confirm the expected behaviour

  1. New Purchase : call purchase(item name) This will result in onSuccess() to be called once IAP completes successfully
  2. 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

Thanks again for your patience :smile: