Skip to content
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

Closed
jason2211 opened this issue Feb 23, 2018 · 8 comments
Closed

Purchase Task never completed if item is already purchased #121

jason2211 opened this issue Feb 23, 2018 · 8 comments

Comments

@jason2211
Copy link

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.

@AndreiMisiukevich
Copy link
Contributor

Hi @jason2211
You should consume previous product, before buying new one.

https://developer.android.com/google/play/billing/api.html

@jason2211
Copy link
Author

Hi @AndreiMisiukevich
Thanks for the reply. Shouldn't the library respond better? It appears to be coded for this exact scenario since it is checking if the item is already purchased and correctly returns it. I would just expect the library not to go into a state where no future purchase calls will work after this scenario.

@AndreiMisiukevich
Copy link
Contributor

I think, you are right.

@jamesmontemagno what do you think?

@jamesmontemagno
Copy link
Owner

We should handle it correct. Would need to see where in the code this is happening or send a PR I can review.

@AndreiMisiukevich
Copy link
Contributor

AndreiMisiukevich commented Feb 26, 2018

@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.

@jamesmontemagno
Copy link
Owner

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?

@AndreiMisiukevich
Copy link
Contributor

no problem
give me some time

@Yohandah
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants