Merge pull request #13902 from mkllnk/refund-simple

Simplify refund logic
This commit is contained in:
Rachel Arnould
2026-02-19 11:06:00 +01:00
committed by GitHub
9 changed files with 39 additions and 124 deletions

View File

@@ -109,7 +109,7 @@ RSpec.describe Spree::Gateway::StripeSCA, :vcr, :stripe_version do
end
it "refunds the payment" do
response = subject.void(payment_intent.id, nil, {})
response = subject.void(payment_intent.id, {})
expect(response.success?).to eq true
end
@@ -131,7 +131,7 @@ RSpec.describe Spree::Gateway::StripeSCA, :vcr, :stripe_version do
end
it "void the payment" do
response = subject.void(payment_intent.id, nil, {})
response = subject.void(payment_intent.id, {})
expect(response.success?).to eq true
end
@@ -162,7 +162,7 @@ RSpec.describe Spree::Gateway::StripeSCA, :vcr, :stripe_version do
stripe_account: stripe_test_account
)
response = subject.credit(1000, nil, payment_intent.id, {})
response = subject.credit(1000, payment_intent.id, {})
expect(response.success?).to eq true
end

View File

@@ -14,8 +14,14 @@ RSpec.describe Spree::Gateway do
end
it "passes through all arguments on a method_missing call" do
expect(Rails.env).to receive(:local?).and_return(false)
gateway = test_gateway.new
expect(gateway.provider).to receive(:imaginary_method).with('foo')
gateway.imaginary_method('foo')
end
it "raises an error in test env" do
gateway = test_gateway.new
expect { gateway.imaginary_method('foo') }.to raise_error StandardError
end
end

View File

@@ -345,24 +345,6 @@ RSpec.describe Spree::Payment do
allow(payment_method).to receive(:void).and_return(success_response)
end
context "when profiles are supported" do
it "should call payment_enterprise.void with the payment's response_code" do
allow(payment_method).to receive(:payment_profiles_supported) { true }
expect(payment_method).to receive(:void).with('123', card,
anything).and_return(success_response)
payment.void_transaction!
end
end
context "when profiles are not supported" do
it "should call payment_gateway.void with the payment's response_code" do
allow(payment_method).to receive(:payment_profiles_supported) { false }
expect(payment_method).to receive(:void).with('123', card,
anything).and_return(success_response)
payment.void_transaction!
end
end
it "should log the response" do
payment.void_transaction!
expect(payment).to have_received(:record_response)
@@ -437,7 +419,7 @@ RSpec.describe Spree::Payment do
end
it "should call credit on the gateway with the credit amount and response_code" do
expect(payment_method).to receive(:credit).with(1000, card, '123',
expect(payment_method).to receive(:credit).with(1000, '123',
anything).and_return(success_response)
payment.credit!
end
@@ -463,7 +445,7 @@ RSpec.describe Spree::Payment do
it "should call credit on the gateway with the credit amount and response_code" do
expect(payment_method).to receive(:credit).with(
amount_in_cents, card, '123', anything
amount_in_cents, '123', anything
).and_return(success_response)
payment.credit!
end
@@ -476,7 +458,7 @@ RSpec.describe Spree::Payment do
it "should call credit on the gateway with original payment amount and response_code" do
expect(payment_method).to receive(:credit).with(
amount_in_cents.to_f, card, '123', anything
amount_in_cents.to_f, '123', anything
).and_return(success_response)
payment.credit!
end
@@ -658,7 +640,6 @@ RSpec.describe Spree::Payment do
context "when profiles are supported" do
before do
allow(payment_method).to receive(:payment_profiles_supported?) { true }
allow(payment.source).to receive(:has_payment_profile?) { false }
end
@@ -700,26 +681,6 @@ RSpec.describe Spree::Payment do
end
end
context "when profiles are not supported" do
before do
allow(payment_method).to receive(:payment_profiles_supported?) { false }
end
it "should not create a payment profile" do
payment_method.name = 'Gateway'
payment_method.distributors << create(:distributor_enterprise)
payment_method.save!
expect(payment_method).not_to receive :create_profile
payment = Spree::Payment.create(
amount: 100,
order: create(:order),
source: card,
payment_method:
)
end
end
context 'when the payment was completed but now void' do
let(:payment) { create(:payment, :completed, amount: 100, order:) }
@@ -877,23 +838,6 @@ RSpec.describe Spree::Payment do
end
end
describe "performing refunds" do
before do
allow(payment).to receive(:calculate_refund_amount) { 123 }
expect(payment.payment_method).to receive(:refund).and_return(success)
end
it "performs the refund without payment profiles" do
allow(payment.payment_method).to receive(:payment_profiles_supported?) { false }
payment.refund!
end
it "performs the refund with payment profiles" do
allow(payment.payment_method).to receive(:payment_profiles_supported?) { true }
payment.refund!
end
end
it "records the response" do
allow(payment).to receive(:calculate_refund_amount) { 123 }
allow(payment.payment_method).to receive(:refund).and_return(success)