mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Fix payment_total calculation
For payment that complete during the checkout (Paypal, Stripe) the amount was recorded twice against `order.payment_total`. This is because the `payment_total` gets updated in an afer_save Payment callback when a payment is completed, and then once more when we process payment in `Spree::Order#process_each_payment`. This is an existing issue on master, but it was hidden by the `update_shipping_fees!` callback, it trigerred an update of the order's total, which then updated `order.payment_total` with the correct value. Now that we removed the callback, the bug showed up. Note, I updated the stripe specs for consistency even though they are currently disabled.
This commit is contained in:
@@ -673,10 +673,6 @@ module Spree
|
||||
break if payment_total >= total
|
||||
|
||||
yield payment
|
||||
|
||||
if payment.completed?
|
||||
self.payment_total += payment.amount
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
%td.text-right{colspan: "3"}
|
||||
%strong
|
||||
= t :order_amount_paid
|
||||
%td.text-right.total
|
||||
%td.text-right.total{id: "amount-paid"}
|
||||
%strong
|
||||
= order.display_payment_total.to_html
|
||||
- if order.outstanding_balance.positive?
|
||||
|
||||
@@ -294,15 +294,6 @@ RSpec.describe Spree::Order do
|
||||
expect(payment).to receive(:process!)
|
||||
expect(order.process_payments!).to be_truthy
|
||||
end
|
||||
|
||||
it "stores the payment total on the order" do
|
||||
allow(payment).to receive(:process!)
|
||||
allow(payment).to receive(:completed?).and_return(true)
|
||||
|
||||
order.process_payments!
|
||||
|
||||
expect(order.payment_total).to eq(payment.amount)
|
||||
end
|
||||
end
|
||||
|
||||
context "when a payment raises a GatewayError" do
|
||||
|
||||
@@ -69,6 +69,7 @@ RSpec.describe "Check out with Paypal" do
|
||||
|
||||
click_on "Complete order"
|
||||
expect(page).to have_content "Your order has been processed successfully"
|
||||
expect(page.find("#amount-paid").text).to have_content "$19.99"
|
||||
|
||||
expect(order.reload.state).to eq "complete"
|
||||
expect(order.payments.count).to eq 1
|
||||
|
||||
@@ -71,6 +71,8 @@ RSpec.describe "Check out with Stripe" do
|
||||
checkout_with_stripe
|
||||
|
||||
expect(page).to have_content "Confirmed"
|
||||
expect(page.find("#amount-paid").text).to have_content "$19.99"
|
||||
|
||||
expect(order.reload.completed?).to eq true
|
||||
expect(order.payments.first.state).to eq "completed"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user