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

Fix/avoid blindly consuming success purchases #1085

Conversation

AmauryLiet
Copy link
Member

@AmauryLiet AmauryLiet commented Aug 26, 2020

The issue

I noticed that using consumeAllItemsAndroid is pretty dangerous in non-dev environnement:
If a purchase becomes successful while the app is offline or killed, then calling consumeAllItemsAndroid will consume the successful purchase without ever notifying the host app, preventing the purchased product from being delivered (although it is billed)

However consumeAllItemsAndroid still appears to be pretty useful in some prod cases:
When a pending payment fails:

The only way (that I am aware of) to force the cache refresh is to try to consume the pending purchase. You would then get a BillingResponseCode.ITEM_NOT_OWNED error, and the item is available for purchase again. (credit to this post)
This fix was already suggested in some issues: #126 (comment)

The solution suggested in this PR

We should expose a method to flush all failed purchases that are still - wrongly - marked as pending.

It would simply fetch all pending purchases, and try to consume then individually:

  • if they are indeed pending, we would get BillingResponseCode.DEVELOPER_ERROR
  • if they were actually already failed, we would get BillingResponseCode.ITEM_NOT_OWNED

Happy to get your feedback on the implementation/naming/...

I am not a big fan of the "callback hell" of the readme. I guess migrating the example/doc to hooks would help but that a subject for another PR

Worthy discussion:

  • should that be the behaviour by default (done by default in initConnection)?

amauryliet added 2 commits August 26, 2020 16:31
If the purchase is really pending, nothing will happen (error). Otherwise, the Play Store cache will
be force updated
@AmauryLiet AmauryLiet force-pushed the fix/avoid-blindly-consuming-success-purchases branch from 7d20b56 to df3e055 Compare August 26, 2020 14:31
@AmauryLiet
Copy link
Member Author

TODO: update README

@AmauryLiet
Copy link
Member Author

@iaphub @hyochan do you have any feedback on the PR?
is the issue clear to you?

Copy link
Member

@hyochan hyochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so great to see! Let's see how it goes.
Sorry for the delayed review 🙏

@hyochan
Copy link
Member

hyochan commented Sep 14, 2020

The issue

I noticed that using consumeAllItemsAndroid is pretty dangerous in non-dev environnement:
If a purchase becomes successful while the app is offline or killed, then calling consumeAllItemsAndroid will consume the successful purchase without ever notifying the host app, preventing the purchased product from being delivered (although it is billed)

However consumeAllItemsAndroid still appears to be pretty useful in some prod cases:
When a pending payment fails:

The only way (that I am aware of) to force the cache refresh is to try to consume the pending purchase. You would then get a BillingResponseCode.ITEM_NOT_OWNED error, and the item is available for purchase again. (credit to this post)
This fix was already suggested in some issues: #126 (comment)

The solution suggested in this PR

We should expose a method to flush all failed purchases that are still - wrongly - marked as pending.

It would simply fetch all pending purchases, and try to consume then individually:

  • if they are indeed pending, we would get BillingResponseCode.DEVELOPER_ERROR
  • if they were actually already failed, we would get BillingResponseCode.ITEM_NOT_OWNED

Happy to get your feedback on the implementation/naming/...

I am not a big fan of the "callback hell" of the readme. I guess migrating the example/doc to hooks would help but that a subject for another PR

Worthy discussion:

  • should that be the behaviour by default (done by default in initConnection)?

Migrating to react-hook is really a great idea. I am not quite sure what you mentioned on the default behavior on initConnection tough 🤔.

@hyochan hyochan merged commit 6d591e5 into dooboolab-community:master Sep 14, 2020
@hyochan hyochan added the 🍗 enhancement New feature or request label Sep 14, 2020
@AmauryLiet AmauryLiet deleted the fix/avoid-blindly-consuming-success-purchases branch September 14, 2020 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍗 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants