Remove Order#set_payment_amount!

This commit is contained in:
Matt-Yorkley
2022-02-01 10:50:51 +00:00
parent 31e6405125
commit 35392cb117
3 changed files with 0 additions and 60 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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) }