Merge pull request #8526 from jibees/3584-fix-adjustment-on-voiding-payment

Revoke transaction fee if payment is cancelled
This commit is contained in:
Filipe
2021-12-02 10:44:08 +00:00
committed by GitHub
2 changed files with 17 additions and 1 deletions

View File

@@ -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

View File

@@ -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