I have an app which has in-app purchases using Google's In-App Billing API. This generally works well, even with internet connection being lost after the purchase has been made, which makes the product show up as an un-consumed purchase. However in some edge case involving turning wifi on & off a few times during the purchase, it sometimes happens that the purchase is processed (i.e. money has been paid), but not yet consumed in the app.
When using the getPurchases() method, this product is not returned as an un-consumed purchase, even though the documentation says it should be. When trying to purchase this product again, however, the API does return the code BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED
.
So this product is marked as un-consumed.
Interestingly, after I run the command adb shell pm clear com.android.vending
in my terminal, this product does show up in the list returned from getPurchases()
.
What is happening here that the product only shows up as an un-consumed product after running the terminal command? How can I get this product to show up as it should in the getPurchases call?
(If this issue cannot be fixed, perhaps I might, upon loading the view where purchases can be made, "simulate" the buying process for each item, check whether it returns the BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED
code, grant the user the purchase for each item that does and resolve this purchase programmatically. This seems way exaggerated though.)
Because the google play service will cache the result and return the cache value first.
The purchase is proceeded before the internet is disconnected. As a result, the purchase state is not updated in the cache. When you query getPurchases() first time, it return the cached value, so the product is not shown up in the purchase list.
After you use command to clean the cache, it force google play service update the cache before return the list for getPurchases(). So the product shows up!
So, I think you should handle the already_owned code instead of checking the purchase state by calling getPurchases() in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With