void payments requiring auth upon marking order paid

This commit is contained in:
Andy Brett
2021-08-25 17:17:28 -07:00
committed by Matt-Yorkley
parent b388196ce3
commit 60677bce4f
2 changed files with 22 additions and 0 deletions

View File

@@ -344,6 +344,7 @@ module Spree
# update payment and shipment(s) states, and save
updater.update_payment_state
cancel_payments_requiring_auth
shipments.each do |shipment|
shipment.update!(self)
shipment.finalize!
@@ -611,6 +612,12 @@ module Spree
private
def cancel_payments_requiring_auth
return unless payment_state == "paid"
payments.requires_authorization.each(&:void_transaction!)
end
def fee_handler
@fee_handler ||= OrderFeesHandler.new(self)
end

View File

@@ -195,6 +195,21 @@ describe Spree::Order do
expect(order.updater).to receive(:before_save_hook)
order.finalize!
end
context "extra payments exist that require authorization" do
let!(:cash_payment) { build(:payment, state: "completed", amount: order.new_outstanding_balance) }
let!(:stripe_payment) { build(:payment, state: "requires_authorization") }
before do
order.payments << cash_payment
order.payments << stripe_payment
allow_any_instance_of(Spree::Payment).to receive(:void_transaction!) {}
end
it "cancels payments requiring authorization" do
expect_any_instance_of(Spree::Payment).to receive(:void_transaction!)
order.finalize!
end
end
end
context "#process_payments!" do