Merge pull request #10381 from anansilva/8229-listing-orders-payment-state-cancelled-order

Update payment (cash/EFF) state on cancelled order
This commit is contained in:
Filipe
2023-02-15 12:06:38 +00:00
committed by GitHub
4 changed files with 57 additions and 1 deletions

View File

@@ -665,6 +665,7 @@ module Spree
def after_cancel
shipments.each(&:cancel!)
payments.checkout.each(&:void!)
OrderMailer.cancel_email(id).deliver_later if send_cancellation_email
update(payment_state: updater.update_payment_state)
@@ -672,6 +673,8 @@ module Spree
def after_resume
shipments.each(&:resume!)
payments.void.each(&:resume!)
update(payment_state: updater.update_payment_state)
end

View File

@@ -47,9 +47,11 @@ module Spree
scope :with_state, ->(s) { where(state: s.to_s) }
scope :completed, -> { with_state('completed') }
scope :incomplete, -> { where(state: %w(checkout pending requires_authorization)) }
scope :checkout, -> { with_state('checkout') }
scope :pending, -> { with_state('pending') }
scope :failed, -> { with_state('failed') }
scope :valid, -> { where.not(state: %w(failed invalid)) }
scope :void, -> { with_state('void') }
scope :authorization_action_required, -> { where.not(cvv_response_message: nil) }
scope :requires_authorization, -> { with_state("requires_authorization") }
scope :with_payment_intent, ->(code) { where(response_code: code) }
@@ -89,6 +91,10 @@ module Spree
event :complete_authorization do
transition from: [:requires_authorization], to: :completed
end
event :resume do
transition from: [:void], to: :checkout
end
after_transition to: :completed, do: :set_captured_at
end

View File

@@ -61,7 +61,7 @@ module OrderManagement
expect(order.shipment_state).to be_nil
end
["shipped", "ready", "pending"].each do |state|
["shipped", "ready", "pending", "canceled"].each do |state|
it "is #{state}" do
allow(shipment).to receive(:state).and_return(state)
updater.update_shipment_state

View File

@@ -303,6 +303,53 @@ describe Spree::Order do
end
end
describe "#cancel" do
let(:order) { create(:order_with_totals_and_distribution, :completed) }
before { order.cancel! }
it "should cancel the order" do
expect(order.state).to eq 'canceled'
end
it "should cancel the shipments" do
expect(order.shipments.pluck(:state)).to eq ['canceled']
end
context "when payment has not been taken" do
context "and payment is in checkout state" do
it "should change the state of the payment to void" do
order.payments.reload
expect(order.payments.pluck(:state)).to eq ['void']
end
end
end
end
describe "#resume" do
let(:order) { create(:order_with_totals_and_distribution, :completed) }
before do
order.cancel!
order.resume!
end
it "should resume the order" do
expect(order.state).to eq 'resumed'
end
it "should resume the shipments" do
expect(order.shipments.pluck(:state)).to eq ['pending']
end
context "when payment is in void state" do
it "should change the state of the payment to checkout" do
order.payments.reload
expect(order.payments.pluck(:state)).to eq ['checkout']
end
end
end
context "insufficient_stock_lines" do
let(:line_item) { build(:line_item) }