-
-
Notifications
You must be signed in to change notification settings - Fork 718
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 checkout order total and payment fees calculation #12880
base: master
Are you sure you want to change the base?
Fix checkout order total and payment fees calculation #12880
Conversation
Although the change fix the issue in the back office scenario, it has the side effect of getting the order total out of sync. Updating a payment adjustment need to be followed by udpating the order total and payment amount to keep everything in sync.
The order updater did not take into account payment fees on pending payment.
Previous iteration did not actually check the payment fee had been updated. It also checks the order total get correctly updated. Spec is passing, so fixing the order updater also fix this bug : openfoodfoundation#12512
Check if payment actually have an adjustment before trying to update it
The future is now ! :D
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.
Well done for finding that! Great work.
context "when updating cart after summary step" do | ||
let(:order) { | ||
create(:order_ready_for_payment, distributor:) | ||
} | ||
let!(:payment_with_fee) { | ||
create( | ||
:payment_method, | ||
distributors: [distributor], | ||
name: "Payment with Fee", description: "Payment with fee", | ||
calculator: Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) | ||
) | ||
} | ||
|
||
it "calculated the correct order total" do | ||
visit checkout_step_path(:payment) | ||
expect(page).to have_checked_field "Payment with Fee" | ||
|
||
click_button "Next - Order summary" | ||
expect(page).to have_title "Checkout Summary - Open Food Network" | ||
|
||
# Back to the shop | ||
click_link "Shopping @ #{distributor.name}" | ||
expect(page).to have_content(distributor.name) | ||
|
||
# Add item to cart | ||
within_variant(order.line_items.first.variant) do | ||
click_button increase_quantity_symbol | ||
end | ||
wait_for_cart | ||
|
||
# Checkout | ||
toggle_cart | ||
click_link "Checkout" | ||
|
||
# Check summary page total | ||
expect(page).to have_title "Checkout Summary - Open Food Network" | ||
expect(page).to have_selector("#order_total", text: 22.00) | ||
expect(order.reload.payments.first.amount).to eql(22.00) | ||
end | ||
end | ||
|
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.
@mkllnk I was wondering if we actually need to keep this spec ? this is covered by the unit test on the order updater
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.
Good point. Let's remove it then.
It's covered by unit test of order updater
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.
Great work, well done on fixing the whole bug!
What? Why?
The order updater wasn't updating payment fee when an order was updated after payment had already been added.This resulted in the order total being wrong on the checkout summary page. The fee was getting updated once the order was finalised but it wasn't added to the payment amount, this resulted in customer owing money when they paid with Stripe, the owed money being the missing payment fee.
Because of the fix introduced by fixing #12512, the payment fees was actually correct on the summary page.
To fix this, I made sure that payment fees are recalculated if the order has a pending payment, and then update the order total and payment total accordingly.
What should we test?
Testing #5574 :
In the back end :
In the front end
With a Stripe payment method:
Use the same scenario as above
Testing #12512
In the back office:
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates