diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 5b8a86ebad..776e654192 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -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 diff --git a/app/models/spree/order/checkout.rb b/app/models/spree/order/checkout.rb index 3671639bcc..01997e676c 100644 --- a/app/models/spree/order/checkout.rb +++ b/app/models/spree/order/checkout.rb @@ -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 diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index bf91d71aae..fe31ab000a 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -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) }