Reputation: 332
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.)
Upvotes: 8
Views: 452
Reputation: 1104
As docs said
Upon a successful purchase, the user’s purchase data is cached locally by Google Play’s In-app Billing service
I run into the same issue, and the only workaround that I found was to advice the user first open the Play Store app (this should update the internal billing cache), and then return to your app and finish purchase (the purchase must be available in inventory)
Upvotes: 0
Reputation: 120
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.
Upvotes: 1