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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add `Gateway#gateway_dashboard_payment_url` (#12256)
Damian Legawiec435a946443ea
diff --git a/core/app/models/spree/gateway.rb b/core/app/models/spree/gateway.rbindex c7bf5643dc..de8aa66e83 100644--- a/core/app/models/spree/gateway.rb+++ b/core/app/models/spree/gateway.rb@@ -10,6 +10,13 @@ module SpreeCreditCardend+ # Override in the gateway to provide a payment url+ # eg. for Stripe, this would be the payment intent url+ # https://dashboard.stripe.com/payments/#{payment.transaction_id}+ def gateway_dashboard_payment_url(_payment)+ nil+ end+def providergateway_options = optionsgateway_options.delete :login if gateway_options.key?(:login) && gateway_options[:login].nil?diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rbindex 556cbb8717..1461d303ec 100644--- a/core/app/models/spree/payment.rb+++ b/core/app/models/spree/payment.rb@@ -77,9 +77,7 @@ module Spreeself.whitelisted_ransackable_attributes = %w[number amount state response_code avs_response cvv_response_code cvv_response_message]# transaction_id is much easier to understand- def transaction_id- response_code- end+ alias_attribute :transaction_id, :response_codedelegate :currency, to: :order@@ -194,6 +192,10 @@ module Spreetrueend+ def gateway_dashboard_payment_url+ payment_method.try(:gateway_dashboard_payment_url, self)+ end+def captured_amountcapture_events.sum(:amount)enddiff --git a/core/spec/models/spree/gateway_spec.rb b/core/spec/models/spree/gateway_spec.rbindex 3347dca451..f25dd06e23 100644--- a/core/spec/models/spree/gateway_spec.rb+++ b/core/spec/models/spree/gateway_spec.rb@@ -92,4 +92,23 @@ describe Spree::Gateway, type: :model dopublishable_preference2: 'public2'})end++ describe '#gateway_dashboard_payment_url' do+ let(:payment_method) { create(:credit_card_payment_method) }+ let(:payment) { create(:payment, payment_method: payment_method, transaction_id: '123') }++ it 'returns nil' do+ expect(payment_method.gateway_dashboard_payment_url(payment)).to be_nil+ end++ context 'when implemented' do+ before do+ expect(payment_method).to receive(:gateway_dashboard_payment_url).with(payment).and_return("https://dashboard.stripe.com/payments/#{payment.transaction_id}")+ end++ it 'returns the url' do+ expect(payment_method.gateway_dashboard_payment_url(payment)).to eq('https://dashboard.stripe.com/payments/123')+ end+ end+ endenddiff --git a/core/spec/models/spree/payment_spec.rb b/core/spec/models/spree/payment_spec.rbindex 62f3747f17..02e0cc4d56 100644--- a/core/spec/models/spree/payment_spec.rb+++ b/core/spec/models/spree/payment_spec.rb@@ -1048,4 +1048,22 @@ describe Spree::Payment, type: :model doendendend++ describe '#gateway_dashboard_payment_url' do+ it 'returns nil' do+ expect(payment.gateway_dashboard_payment_url).to be_nil+ end++ let(:payment) { create(:payment, payment_method: gateway, transaction_id: '123') }++ context 'when implemented' do+ before do+ expect(gateway).to receive(:gateway_dashboard_payment_url).with(payment).and_return("https://dashboard.stripe.com/payments/#{payment.transaction_id}")+ end++ it 'returns the url' do+ expect(payment.gateway_dashboard_payment_url).to eq("https://dashboard.stripe.com/payments/#{payment.transaction_id}")+ end+ end+ endend