Reset test in-app purchase for Google Play Billing

I decided to play around with Google Play Billing and I have to say that my opinion about it is not really good.

1) Different products have a different name – “one-time” products are called “managed” products
2) Usage is truly complex – you have several methods that accept a callback, you have like 100 cases to handle if you want to use subscriptions inside your app.
3) Testing & requesting data is hard – you constantly have to use builders, pass around different objects and if you want to properly test it – it is really hard to do that.

In order to avoid the above problems, you can use a library that is a simple wrapper around the Play Billing shit. This library seems to do a good job: https://github.com/anjlab/android-inapp-billing-v3 or you can just search GitHub and you will find quite a lot of examples where people extract the BillingClient to a separate class called BillingManager in most of the places.

About the testing, you can actually use a test product SKU like “android.test.purchased”. But the problem is that even if you acknowledge the purchase and try to buy it again, Google Play Billing returns Item already purchased. In order to reset it, there are not many things you can do. There is only one that actually works:

adb shell pm clear com.android.vending

So after buying this “android.test.purchased” SKU you can use the above command to reset the process and the SKU will appear as unpurchased again so you can launch the billing flow.

You may also like...