mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Remove Order#set_payment_amount!
This commit is contained in:
@@ -734,16 +734,5 @@ module Spree
|
||||
adjustment.update_adjustment!(force: true)
|
||||
updater.update_totals_and_states
|
||||
end
|
||||
|
||||
# object_params sets the payment amount to the order total, but it does this
|
||||
# before the shipping method is set. This results in the customer not being
|
||||
# charged for their order's shipping. To fix this, we refresh the payment
|
||||
# amount here.
|
||||
def set_payment_amount!
|
||||
update_totals
|
||||
return unless pending_payments.any?
|
||||
|
||||
pending_payments.first.update_attribute :amount, total
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -81,7 +81,6 @@ module Spree
|
||||
after_transition to: :complete, do: :finalize!
|
||||
after_transition to: :resumed, do: :after_resume
|
||||
after_transition to: :canceled, do: :after_cancel
|
||||
after_transition to: :payment, do: :set_payment_amount!
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1335,54 +1335,6 @@ describe Spree::Order do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#set_payment_amount!' do
|
||||
let(:order) do
|
||||
shipment = build(:shipment_with, :shipping_method, shipping_method: build(:shipping_method))
|
||||
build(:order, shipments: [shipment])
|
||||
end
|
||||
|
||||
context 'after transitioning to payment' do
|
||||
before do
|
||||
order.state = 'delivery' # payment's previous state
|
||||
|
||||
allow(order).to receive(:payment_required?) { true }
|
||||
end
|
||||
|
||||
it 'calls #set_payment_amount! and updates totals' do
|
||||
expect(order).to receive(:set_payment_amount!)
|
||||
expect(order).to receive(:update_totals).at_least(:once)
|
||||
|
||||
order.next
|
||||
end
|
||||
|
||||
context "payment's amount" do
|
||||
let(:failed_payment) { create(:payment, order: order, state: 'failed', amount: 100) }
|
||||
|
||||
before do
|
||||
allow(order).to receive(:total) { 120 }
|
||||
end
|
||||
|
||||
it 'is not updated for failed payments' do
|
||||
failed_payment
|
||||
|
||||
order.next
|
||||
|
||||
expect(failed_payment.reload.amount).to eq 100
|
||||
end
|
||||
|
||||
it 'is updated only for pending payments' do
|
||||
pending_payment = create(:payment, order: order, state: 'pending', amount: 80)
|
||||
failed_payment
|
||||
|
||||
order.next
|
||||
|
||||
expect(failed_payment.reload.amount).to eq 100
|
||||
expect(pending_payment.reload.amount).to eq 120
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ensure_updated_shipments" do
|
||||
before { Spree::Shipment.create!(order: order) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user