mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user