mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #8105 from andrewpbrett/void-extra-outstanding-payments
Void payments requiring auth upon marking order paid
This commit is contained in:
@@ -122,6 +122,7 @@ module OrderManagement
|
||||
last_payment_state = order.payment_state
|
||||
|
||||
order.payment_state = infer_payment_state
|
||||
cancel_payments_requiring_auth unless last_payment_state == "paid"
|
||||
track_payment_state_change(last_payment_state)
|
||||
|
||||
order.payment_state
|
||||
@@ -162,6 +163,12 @@ module OrderManagement
|
||||
|
||||
private
|
||||
|
||||
def cancel_payments_requiring_auth
|
||||
return unless order.payment_state == "paid"
|
||||
|
||||
payments.to_a.select(&:requires_authorization?).each(&:void_transaction!)
|
||||
end
|
||||
|
||||
def round_money(value)
|
||||
(value * 100).round / 100.0
|
||||
end
|
||||
|
||||
@@ -360,6 +360,22 @@ module OrderManagement
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when unused payments records exist which require authorization, but the order is fully paid" 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
|
||||
end
|
||||
|
||||
it "cancels unused payments requiring authorization" do
|
||||
expect(stripe_payment).to receive(:void_transaction!)
|
||||
expect(cash_payment).to_not receive(:void_transaction!)
|
||||
|
||||
order.updater.update_payment_state
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user