Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

FIX void payment (#13413)

brozek57d572f465a4
diff --git a/core/app/models/spree/payment/processing.rb b/core/app/models/spree/payment/processing.rb
index 7870863c3b..9dd3680b59 100644
--- a/core/app/models/spree/payment/processing.rb
+++ b/core/app/models/spree/payment/processing.rb
@@ -63,6 +63,7 @@ module Spree
def void_transaction!
return true if void?
+ return void if response_code.blank?
protect_from_connection_error do
if payment_method.payment_profiles_supported?
diff --git a/core/spec/models/spree/payment_spec.rb b/core/spec/models/spree/payment_spec.rb
index decdf6d838..3bed924b9f 100644
--- a/core/spec/models/spree/payment_spec.rb
+++ b/core/spec/models/spree/payment_spec.rb
@@ -694,6 +694,19 @@ describe Spree::Payment, type: :model do
payment.void_transaction!
end
end
+
+ context 'if response_code is blank' do
+ before do
+ payment.response_code = nil
+ payment.state = 'pending'
+ end
+
+ it 'voids the payment without calling the gateway' do
+ expect(payment.payment_method).not_to receive(:void)
+ payment.void_transaction!
+ expect(payment.state).to eq('void')
+ end
+ end
end
end