Merge pull request #8689 from apricot12/Transaction_fee_when_crediting

Revoke transaction fee if there is an amount to be credited in order
This commit is contained in:
Filipe
2022-02-21 20:30:19 +00:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

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

View File

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