mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-05 02:41:33 +00:00
Merge pull request #8526 from jibees/3584-fix-adjustment-on-voiding-payment
Revoke transaction fee if payment is cancelled
This commit is contained in:
@@ -138,7 +138,7 @@ module Spree
|
||||
end
|
||||
|
||||
def ensure_correct_adjustment
|
||||
revoke_adjustment_eligibility if ['failed', 'invalid'].include?(state)
|
||||
revoke_adjustment_eligibility if ['failed', 'invalid', 'void'].include?(state)
|
||||
return if adjustment.try(:finalized?)
|
||||
|
||||
if adjustment
|
||||
|
||||
@@ -356,6 +356,22 @@ describe Spree::Payment do
|
||||
payment.void_transaction!
|
||||
end
|
||||
end
|
||||
|
||||
context "if payment has any adjustment" do
|
||||
let!(:order) { create(:order) }
|
||||
let!(:payment_method) { create(:payment_method, calculator: ::Calculator::FlatRate.new(preferred_amount: 10)) }
|
||||
|
||||
it "should create another adjustment and revoke the previous one" do
|
||||
payment = create(:payment, order: order, payment_method: payment_method)
|
||||
expect(order.all_adjustments.payment_fee.eligible.length).to eq(1)
|
||||
|
||||
payment.void_transaction!
|
||||
expect(order.all_adjustments.payment_fee.eligible.length).to eq(0)
|
||||
|
||||
payment = create(:payment, order: order, payment_method: payment_method)
|
||||
expect(order.all_adjustments.payment_fee.eligible.length).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#credit" do
|
||||
|
||||
Reference in New Issue
Block a user