New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Purchase Task never completed if item is already purchased #121
Comments
Hi @jason2211 |
Hi @AndreiMisiukevich |
I think, you are right. @jamesmontemagno what do you think? |
We should handle it correct. Would need to see where in the code this is happening or send a PR I can review. |
@jamesmontemagno https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs#L322-L326 here is the reason. I think, we should throw error instead of trying to retrieve bought product. |
Ahhh I see, so we are basically just returning the existing purchase instead of throwing... I see why I did this. sounds good. can you PR me? |
no problem |
I still have the issue, it says that the item was already purchased and will be restored for free but then PurchaseAsync never ends. I have the latest version of the plugin. |
When attempting to purchase an item that has already been purchased, the tcsPurchase task will be created but is never complete so no future purchases can be made until the app is restarted.
In the Plugin.InAppBilling.Android project, class Plugin.InAppBillingImplementation, method PurchaseAsync (line 321), the code checks if the purchase has already been made and if so it returns the purchase. However, the tcsPurchase is still in a state of WaitingforActivation.
Since the HandleActivityResult will never be called due to the BuyIntent never being sent to Android, all future purchase attempts will return null due to the tcsPurchase.Task.IsCompleted check at the beginning of PurchaseAsync method (line 290).
I would suggest modifying the task check verify the TaskStatus is not WaitingForActivation. If it is still waiting for activation, I think it is safe to assume the prior purchase call never created the BuyIntent.
Another option would be to set the tcsPurchase to null whenever the purchase is returned without invoking the BuyIntent.
Version Number of Plugin: 1.2.4 (also used the latest in GitHub)
Device Tested On: Nexus 7
Simulator Tested On: None
Version of VS: Android 4.4.4
Version of Xamarin: 4.8.0.757
Steps to reproduce the Behavior
Attempt to purchase an item that has already been purchased. Code will correctly return the purchase item without attempting to purchase it again. Attempt to buy another item and the call to PurchaseAsync will always return NULL until the app is restarted.
Expected Behavior
Future calls to PurchaseAsync should not return null.
Actual Behavior
Null is always returned from PurchaseAsync after attempting to purchase an item that is already purchased.
The text was updated successfully, but these errors were encountered: