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.

VEN-412 Pass payment in Processing#cancel! to PaymentMethod#cancel (#11642)

Aleksandar Petrushevea0c9009239e
diff --git a/core/app/models/spree/gateway/bogus.rb b/core/app/models/spree/gateway/bogus.rb
index 7a07f89b02..de8f275d99 100644
--- a/core/app/models/spree/gateway/bogus.rb
+++ b/core/app/models/spree/gateway/bogus.rb
@@ -58,7 +58,7 @@ module Spree
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
end
- def cancel(_response_code)
+ def cancel(_response_code, _payment = nil)
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
end
diff --git a/core/app/models/spree/payment/processing.rb b/core/app/models/spree/payment/processing.rb
index 8112780547..23ad3d32d1 100644
--- a/core/app/models/spree/payment/processing.rb
+++ b/core/app/models/spree/payment/processing.rb
@@ -72,7 +72,7 @@ module Spree
end
def cancel!
- response = payment_method.cancel(response_code)
+ response = payment_method.cancel(response_code, self)
handle_response(response, :void, :failure)
end
diff --git a/core/app/models/spree/payment_method/store_credit.rb b/core/app/models/spree/payment_method/store_credit.rb
index 063132aa26..a7694fea52 100644
--- a/core/app/models/spree/payment_method/store_credit.rb
+++ b/core/app/models/spree/payment_method/store_credit.rb
@@ -74,7 +74,7 @@ module Spree
handle_action(action, :credit, auth_code)
end
- def cancel(auth_code)
+ def cancel(auth_code, _payment = nil)
store_credit_event = StoreCreditEvent.find_by(authorization_code: auth_code,
action: Spree::StoreCredit::CAPTURE_ACTION)
store_credit = store_credit_event.try(:store_credit)
diff --git a/core/app/models/spree/refund.rb b/core/app/models/spree/refund.rb
index 7871c5e298..209497129c 100644
--- a/core/app/models/spree/refund.rb
+++ b/core/app/models/spree/refund.rb
@@ -29,6 +29,8 @@ module Spree
scope :non_reimbursement, -> { where(reimbursement_id: nil) }
+ attr_reader :response
+
def money
Spree::Money.new(amount, currency: payment.currency)
end
diff --git a/core/spec/models/spree/payment/store_credit_spec.rb b/core/spec/models/spree/payment/store_credit_spec.rb
index 51ef08f48c..ecf6420587 100644
--- a/core/spec/models/spree/payment/store_credit_spec.rb
+++ b/core/spec/models/spree/payment/store_credit_spec.rb
@@ -40,8 +40,8 @@ describe 'Payment' do
)
end
- it 'attemps to cancels the payment' do
- expect(payment.payment_method).to receive(:cancel).with(payment.response_code) { successful_response }
+ it 'attempts to cancels the payment' do
+ expect(payment.payment_method).to receive(:cancel).with(payment.response_code, payment) { successful_response }
subject
end
@@ -53,7 +53,7 @@ describe 'Payment' do
context 'does not cancel successfully' do
it 'does not change the payment state' do
- expect(payment.payment_method).to receive(:cancel).with(payment.response_code) { failed_response }
+ expect(payment.payment_method).to receive(:cancel).with(payment.response_code, payment) { failed_response }
expect { subject }.to raise_error(Spree::Core::GatewayError)
expect(payment.reload.state).not_to eq 'void'
end