Skip to content

Commit 1664546

Browse files
forkataadammathysstewartbenjaminwilsenemsoy
authored andcommitted
Rename method that recalculates payment state
Update implies that we are persisting the change in Rails, which this method does not do. Co-authored-by: Adam Mueller <[email protected]> Co-authored-by: Andrew Stewart <[email protected]> Co-authored-by: benjamin wil <[email protected]> Co-authored-by: Senem Soy <[email protected]> Co-authored-by: Sofia Besenski <[email protected]> Co-authored-by: Kendra Riga <[email protected]>
1 parent 8343681 commit 1664546

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

core/app/models/spree/order.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def finalize
758758
all_adjustments.each(&:finalize!)
759759

760760
# update payment and shipment(s) states, and save
761-
recalculator.update_payment_state
761+
recalculator.recalculate_payment_state
762762
shipments.each do |shipment|
763763
shipment.update_state
764764
shipment.finalize!

core/app/models/spree/order_updater.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def recalculate
2222
update_shipment_amounts
2323
update_totals
2424
if order.completed?
25-
update_payment_state
25+
recalculate_payment_state
2626
update_shipments
2727
recalculate_shipment_state
2828
end
@@ -53,7 +53,7 @@ def recalculate_shipment_state
5353
alias_method :update_shipment_state, :recalculate_shipment_state
5454
deprecate update_shipment_state: :recalculate_shipment_state, deprecator: Spree.deprecator
5555

56-
# Updates the +payment_state+ attribute according to the following logic:
56+
# Recalculates the +payment_state+ attribute according to the following logic:
5757
#
5858
# paid when +payment_total+ is equal to +total+
5959
# balance_due when +payment_total+ is less than +total+
@@ -62,13 +62,15 @@ def recalculate_shipment_state
6262
# void when the order has been canceled and the payment total is 0
6363
#
6464
# The +payment_state+ value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention.
65-
def update_payment_state
65+
def recalculate_payment_state
6666
log_state_change('payment') do
6767
order.payment_state = determine_payment_state
6868
end
6969

7070
order.payment_state
7171
end
72+
alias_method :update_payment_state, :recalculate_payment_state
73+
deprecate update_payment_state: :recalculate_payment_state, deprecator: Spree.deprecator
7274

7375
private
7476

core/spec/models/spree/order/payment_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module Spree
2828

2929
it 'processes only new payments' do
3030
order.process_payments!
31-
updater.update_payment_state
31+
updater.recalculate_payment_state
3232

3333
expect(order.payment_state).to eq('balance_due')
3434
expect(order.payment_total).to eq(50)
@@ -43,7 +43,7 @@ module Spree
4343

4444
it 'processes all checkout payments' do
4545
order.process_payments!
46-
updater.update_payment_state
46+
updater.recalculate_payment_state
4747

4848
expect(order.payment_state).to eq('paid')
4949
expect(order.payment_total).to eq(100)
@@ -57,7 +57,7 @@ module Spree
5757

5858
it 'does not go over total for order' do
5959
order.process_payments!
60-
updater.update_payment_state
60+
updater.recalculate_payment_state
6161

6262
expect(order.payment_state).to eq('paid')
6363
expect(order.payment_total).to eq(100)

core/spec/models/spree/order_updater_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ module Spree
314314
it "logs a state change for the payment" do
315315
create :payment, order:, state: "processing"
316316

317-
expect { updater.update_payment_state }
317+
expect { updater.recalculate_payment_state }
318318
.to enqueue_job(Spree::StateChangeTrackingJob)
319319
.with(order, nil, "paid", a_kind_of(Time), "payment")
320320
.once
@@ -330,7 +330,7 @@ module Spree
330330
order.total = 1
331331
order.payment_total = 0
332332

333-
updater.update_payment_state
333+
updater.recalculate_payment_state
334334
expect(order.payment_state).to eq('failed')
335335
end
336336
end
@@ -342,7 +342,7 @@ module Spree
342342
order.payment_total = 0
343343

344344
expect {
345-
updater.update_payment_state
345+
updater.recalculate_payment_state
346346
}.to change { order.payment_state }.to 'paid'
347347
end
348348
end
@@ -353,7 +353,7 @@ module Spree
353353
order.total = 1
354354

355355
expect {
356-
updater.update_payment_state
356+
updater.recalculate_payment_state
357357
}.to change { order.payment_state }.to 'credit_owed'
358358
end
359359
end
@@ -364,7 +364,7 @@ module Spree
364364
order.total = 2
365365

366366
expect {
367-
updater.update_payment_state
367+
updater.recalculate_payment_state
368368
}.to change { order.payment_state }.to 'balance_due'
369369
end
370370
end
@@ -375,7 +375,7 @@ module Spree
375375
order.total = 30
376376

377377
expect {
378-
updater.update_payment_state
378+
updater.recalculate_payment_state
379379
}.to change { order.payment_state }.to 'paid'
380380
end
381381
end
@@ -390,7 +390,7 @@ module Spree
390390
order.payment_total = 0
391391
order.total = 30
392392
expect {
393-
updater.update_payment_state
393+
updater.recalculate_payment_state
394394
}.to change { order.payment_state }.to 'void'
395395
end
396396
end
@@ -401,7 +401,7 @@ module Spree
401401
order.total = 30
402402
create(:payment, order:, state: 'completed', amount: 30)
403403
expect {
404-
updater.update_payment_state
404+
updater.recalculate_payment_state
405405
}.to change { order.payment_state }.to 'credit_owed'
406406
end
407407
end
@@ -411,7 +411,7 @@ module Spree
411411
order.payment_total = 0
412412
order.total = 30
413413
expect {
414-
updater.update_payment_state
414+
updater.recalculate_payment_state
415415
}.to change { order.payment_state }.to 'void'
416416
end
417417
end
@@ -422,7 +422,7 @@ module Spree
422422
before { allow(order).to receive_messages completed?: true }
423423

424424
it "updates payment state" do
425-
expect(updater).to receive(:update_payment_state)
425+
expect(updater).to receive(:recalculate_payment_state)
426426
updater.recalculate
427427
end
428428

@@ -451,7 +451,7 @@ module Spree
451451
before { allow(order).to receive_messages completed?: false }
452452

453453
it "doesnt update payment state" do
454-
expect(updater).not_to receive(:update_payment_state)
454+
expect(updater).not_to receive(:recalculate_payment_state)
455455
updater.recalculate
456456
end
457457

core/spec/models/spree/payment_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@
744744
before { allow(order).to receive_messages completed?: true }
745745

746746
it "updates payment_state and shipments" do
747-
expect(order.recalculator).to receive(:update_payment_state)
747+
expect(order.recalculator).to receive(:recalculate_payment_state)
748748
expect(order.recalculator).to receive(:recalculate_shipment_state)
749749
Spree::Payment.create!(amount: 100, order:, payment_method:)
750750
end

0 commit comments

Comments
 (0)