diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index d1ebf2aaeb..8d66fc2757 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -147,7 +147,7 @@ module Spree adjustment.originator = payment_method adjustment.label = adjustment_label adjustment.save - elsif payment_method.present? + elsif !processing_refund? && payment_method.present? payment_method.create_adjustment(adjustment_label, self, true) adjustment.reload end @@ -163,6 +163,10 @@ module Spree private + def processing_refund? + amount.negative? + end + # Don't charge fees for invalid or failed payments. # This is called twice for failed payments, because the persistence of the 'failed' # state is acheived through some trickery using an after_rollback callback on the diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 420160ae60..49b54b3256 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -405,6 +405,19 @@ describe Spree::Payment do end end + context "if payment method has any payment fees" do + before do + expect(payment.order).to receive(:outstanding_balance).at_least(:once) { 10 } + expect(payment).to receive(:credit_allowed) { 200 } + end + + it "should not applied any transaction fees" do + payment.credit! + expect(payment.adjustment.finalized?).to eq(false) + expect(order.all_adjustments.payment_fee.length).to eq(0) + end + end + context "when outstanding_balance is equal to payment amount" do before do payment.order.stub outstanding_balance: payment.amount