In-App Billing Version 3 refunds.

There is really no difference between a consumable item and a non-consumable item so far as Google Play is concerned; this distinction is entirely based on what you implement within your app. So, even though the SKU you are testing is intended to be non-consumable (e.g., a permanent premium upgrade), for testing purposes, you can treat it as a consumable and consume it, so that it can be purchased again.

A convenient approach is to set up a temporary testing menu within your app (e.g., by adding a menu item during testing onto your app's main options menu), and then to have that item's handler invoke the consumeAsync() method of your IabHelper instance for the SKU that you want to test buying again. This will consume the item and thus make it immediately available for repurchase from your device.

You will, of course, still want to refund the purchase from Google Checkout, so that you won't be spending your own money just to test your app.

I would add that consumeAsync() also seems to work just fine for resetting the test SKU android.test.purchased if you are testing with such static values.

Regarding the updating of purchase state to reflect a refund, I have personally experienced (and there are many similar reports posted by other developers) that manually initiating a refund via Checkout (e.g., for a test purchase from the TrivialDrive app) takes days to result in a change to the purchase state of the product (to INAPP_PURCHASE_STATE_REFUNDED).

(Knowing that misery loves company, some of those additional reports can be found on this discussion thread:

At least part of this is due to Google Play's caching of purchase data on the device.

In my experience, re-booting a device can sometimes cause Google Play to refresh its cache from the GP servers. So, it may be that changes due to  the cancellation or refunding of an order via Checkout could also be detected after a reboot.

It might seem that such a long turnaround period would not be good for you as you can't know when users reboot. But then again, you know that every device will eventually get rebooted, and so if your concern is that a user who receives a refund should eventually be blocked from using the refunded IAB product, a few days of delay may not matter much, so long as it eventually happens.

Of course, remember that this notion that cache will refresh on a reboot is undocumented and anecdotal (like quite a number of IAB3 and TrivialDrive behaviors, thus far). Folklore, they call it.

Another thing that triggers an update is when the user attempts to purchase the product. As soon as the purchase is launched, the system has to be sure that the product has not been already owned, and so it updates the Google Play cache. In my personal experience this has always occurred. But again, this is not a very practical way to check for a refund, because that would involve showing the purchase dialog unbidden, and also an error message that tells the user "you already own this, " (if they do own it).

Where this does come in handy is when the user pays for an IAB item on one of her devices and then attempts to access that item on a different device that is owned by the same account as was used to buy it. The purchase information in that case has not been cached very often. But you can just put a little note in your purchase dialog that if the item has already been purchased, attempting a re-purchase should make it available on the present device at no additional charge. Sometimes it takes two (user-initiated) purchase attempts to finally get the IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED response. Yes, a bit kludge, but I think in human terms it will work with an appropriate highlighting of the message and apologetic wording of the confirmation dialog telling them that they own the item, etc. :-) ).

As a practical matter, you can see how Google might not want every instance of every IAB app in the world to access its servers every time the purchase data of apps is being accessed, especially given that they are advising developers to do a check for what has been purchased each time the app is started. It's also a performance issue for your app - that's what caching is all about. So, you need to be aware of the triggers for updating the cache, and I haven't found a single place where this is officially documented (except, we presume, in the code). So, get ready to put your hands out in front of you and start feeling around in the dark.

For some additional information regarding Google Play buffering see this page:

Under What Conditions are In-App Billing Version 3 Server Changes Made Available on Client Devices?

I would note that in your post code snippet you are calling inventory.hasPurchase(SKU_REMOVE_ADS), but that will only tell you if the purchase is in the list of purchases returned in the inventory object; it will not tell you the state of the purchase for that SKU. I know that this is an approach used by the TrivialDrive app, but that app is not dealing with refunds and cancellations. To detect refunds and canceled orders, you'll need something like this:

GooglePurchaseTemplate removeAdsPurchase =  AndroidInAppPurchaseManager.instance.inventory.GetPurchaseDetails(SKU_REMOVE_ADS);
switch(removeAdsPurchase.state) {
	case GooglePurchaseState.PURCHASED:
		//Do remove ads stuf here
	case GooglePurchaseState.CANCELED:
		//Do cancelled purchase stuff here
	case GooglePurchaseState.REFUNDED:
		//Do refunded purchase stuff here

The good news about refunds and canceled orders is that both are, AFAIK, entirely at the option of the developer. So, if you find those users, who get these, are able to continue using your app for a long interval, and if you find that lots of users are taking advantage of this, then you can decide if you want to continue providing the refunds in all cases. My best guess is that it will not be a problem; even if some users who get a refund get to use your app for a while after this that doesn't seem like a very big deal.

It is for testing that you need the ability to re-try a purchase very rapidly, and using consumeAsync() definitely works for that purpose.


Article Source. Code example was changed to fit Android Native Plugin API.