diff --git a/core/app/models/spree/in_memory_order_updater.rb b/core/app/models/spree/in_memory_order_updater.rb index 00d98ef1f67..e0770ba59f5 100644 --- a/core/app/models/spree/in_memory_order_updater.rb +++ b/core/app/models/spree/in_memory_order_updater.rb @@ -22,7 +22,7 @@ def recalculate(persist: true) update_shipment_amounts(persist:) update_totals(persist:) if order.completed? - update_payment_state + recalculate_payment_state update_shipments recalculate_shipment_state end @@ -54,7 +54,7 @@ def recalculate_shipment_state alias_method :update_shipment_state, :recalculate_shipment_state deprecate update_shipment_state: :recalculate_shipment_state, deprecator: Spree.deprecator - # Updates the +payment_state+ attribute according to the following logic: + # Recalculates the +payment_state+ attribute according to the following logic: # # paid when +payment_total+ is equal to +total+ # balance_due when +payment_total+ is less than +total+ @@ -63,13 +63,15 @@ def recalculate_shipment_state # void when the order has been canceled and the payment total is 0 # # The +payment_state+ value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention. - def update_payment_state + def recalculate_payment_state log_state_change('payment') do order.payment_state = determine_payment_state end order.payment_state end + alias_method :update_payment_state, :recalculate_shipment_state + deprecate update_payment_state: :recalculate_shipment_state, deprecator: Spree.deprecator private diff --git a/core/spec/models/spree/in_memory_order_updater_spec.rb b/core/spec/models/spree/in_memory_order_updater_spec.rb index 00d2e21dfd2..ebfb8aef1c4 100644 --- a/core/spec/models/spree/in_memory_order_updater_spec.rb +++ b/core/spec/models/spree/in_memory_order_updater_spec.rb @@ -255,7 +255,6 @@ module Spree context "updating payment state" do let(:order) { build(:order) } - let(:updater) { order.recalculator } before { allow(order).to receive(:refund_total).and_return(0) } context 'no valid payments with non-zero order total' do @@ -264,7 +263,7 @@ module Spree order.total = 1 order.payment_total = 0 - updater.update_payment_state + updater.recalculate_payment_state expect(order.payment_state).to eq('failed') end end @@ -276,7 +275,7 @@ module Spree order.payment_total = 0 expect { - updater.update_payment_state + updater.recalculate_payment_state }.to change { order.payment_state }.to 'paid' end end @@ -287,7 +286,7 @@ module Spree order.total = 1 expect { - updater.update_payment_state + updater.recalculate_payment_state }.to change { order.payment_state }.to 'credit_owed' end end @@ -298,7 +297,7 @@ module Spree order.total = 2 expect { - updater.update_payment_state + updater.recalculate_payment_state }.to change { order.payment_state }.to 'balance_due' end end @@ -309,7 +308,7 @@ module Spree order.total = 30 expect { - updater.update_payment_state + updater.recalculate_payment_state }.to change { order.payment_state }.to 'paid' end end @@ -324,7 +323,7 @@ module Spree order.payment_total = 0 order.total = 30 expect { - updater.update_payment_state + updater.recalculate_payment_state }.to change { order.payment_state }.to 'void' end end @@ -335,7 +334,7 @@ module Spree order.total = 30 create(:payment, order: order, state: 'completed', amount: 30) expect { - updater.update_payment_state + updater.recalculate_payment_state }.to change { order.payment_state }.to 'credit_owed' end end @@ -345,7 +344,7 @@ module Spree order.payment_total = 0 order.total = 30 expect { - updater.update_payment_state + updater.recalculate_payment_state }.to change { order.payment_state }.to 'void' end end @@ -356,7 +355,7 @@ module Spree before { allow(order).to receive_messages completed?: true } it "updates payment state" do - expect(updater).to receive(:update_payment_state) + expect(updater).to receive(:recalculate_payment_state) updater.recalculate end @@ -385,7 +384,7 @@ module Spree before { allow(order).to receive_messages completed?: false } it "doesnt update payment state" do - expect(updater).not_to receive(:update_payment_state) + expect(updater).not_to receive(:recalculate_payment_state) updater.recalculate end