-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
[vouchers] error moving between summary and cart pages #11117
Merged
mkllnk
merged 24 commits into
openfoodfoundation:master
from
rioug:10857-voucher-error-moving-between-summary-and-cart-take2
Aug 9, 2023
Merged
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
04bbea5
Move voucher processing out of checkout controller
Matt-Yorkley 60c0c54
Update create_adjustment to create with an amount of 0
rioug 87790b2
Fix VoucherAdjustmentsService.calculate so we can call it mutiple time
rioug 366cca7
Prevent voucher adjustment from bein updated when update is called
rioug ca7dcb8
Apply voucher after transitionning to the confirmation step
rioug edabc56
Add voucher calculation after updating an order
rioug a8062e9
Add a scenario to make sure voucher adjustment a recalculated
rioug 789ce39
Fixing Rubocop errors
rioug 751056b
As per review comment, spell out voucher code when entering a voucher
rioug 4127119
Per review, Makes quantity change more explicit
rioug 3d9542f
Per review, rename amount to adjustment_amount
rioug 5a59396
Remove call to VoucherAdjustmentService when creating a voucher
rioug 0e0850e
Add specs to cover re calculation
rioug a584f9a
Refactor VoucherAdjustmentsService
rioug a5b2bc6
Per review, Refactor VoucherAdjustmentsService
rioug 895f534
Remove unnecessary extra page load
dacook be1a727
Pending spec: vouchers should not require payment
dacook ef62fb8
Check if record actually saved
dacook f35001d
Update voucher adjustment and order total when adding a voucher
rioug 33ef8de
Update order total after removing a voucher
rioug 089d2b9
Clear any existing payment and payment fees when adding a voucher
rioug 2857930
Fix voucher adjustment request spec
rioug 85adb9f
Fix rubocop warning
rioug 6ed35f4
Per review, delete only incomplete payments
rioug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question: do we ever have complete payments in this code path?
It looks like they would influence the calculation if we kept them. So that would need special consideration.
Looking into the state machine, we can restart the checkout any time until the order is finalised. At the time of finalising the order, the payment has been taken already. So I think, it can happen that we take a payment and then face a stock conflict and have to restart the checkout.
@rioug, do you agree with my theory? It would mean that you need to calculate totals for voucher amounts considering payments instead of clearing them out, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that payment are processed once we confirm the order, see below:
openfoodnetwork/app/controllers/split_checkout_controller.rb
Lines 115 to 126 in ad37c40
and once the order is confirmed then the state machine will finalise the order. So If I understand correctly we shouldn't have any completed payments when navigating between checkout steps.
Also if the checkout is restarted, the the user will be going through the payment step again and will be able to (re) choose the payment method.
I added this to fix a specific scenario where the user goes through the checkout till the confirmation step, then goes back to the payment step and add a voucher covering the order amount. In this case we need to remove any existing payment/payment fee as now there is no payment required.
Would we have an already completed payment if we face a stock conflict and have to restart the checkout ? You would think that we would check the stock situation before taking a payment.
From what I can see, we would be redirected to cart if there is a stock issue when navigation checkout steps:
openfoodnetwork/app/controllers/concerns/checkout_callbacks.rb
Line 34 in ad37c40
openfoodnetwork/app/controllers/concerns/checkout_callbacks.rb
Lines 66 to 70 in ad37c40
I couldn't see any other checks so maybe I am missing something here.
Anyway, I'll apply @dacook suggestion to be on the safer side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course we check the stock before we take a payment but there's always room for race conditions. We often process several checkouts in the same second and it can happen that two people try to checkout the same last item at the same time. It's really hard to predict what exactly happens because it depends on the timing and where the error is raised.
Actually, the CurrentOrderLocker should prevent this. So maybe it's not a problem any more. I'm just scared that this race condition will come back to haunt us... 😨