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: Built payment webhook URLs with a scheme (#15058)

Damian Legawiecdb0f23d5c7f3
diff --git a/spree/core/app/models/spree/payment_method.rb b/spree/core/app/models/spree/payment_method.rb
index 52675ee880..7ee74537e5 100644
--- a/spree/core/app/models/spree/payment_method.rb
+++ b/spree/core/app/models/spree/payment_method.rb
@@ -197,7 +197,7 @@ module Spree
def webhook_url
return nil unless store
- "#{store.url_or_custom_domain}/api/v3/webhooks/payments/#{prefixed_id}"
+ "#{store.formatted_url_or_custom_domain}/api/v3/webhooks/payments/#{prefixed_id}"
end
class WebhookSignatureError < StandardError; end
diff --git a/spree/core/spec/models/spree/payment_method_spec.rb b/spree/core/spec/models/spree/payment_method_spec.rb
index 4b0eb1e7fd..71ce72b0a8 100644
--- a/spree/core/spec/models/spree/payment_method_spec.rb
+++ b/spree/core/spec/models/spree/payment_method_spec.rb
@@ -116,6 +116,19 @@ describe Spree::PaymentMethod, type: :model do
end
end
+ describe '#webhook_url' do
+ let(:payment_method) { create(:credit_card_payment_method) }
+
+ it 'is an absolute url when the store url is a bare host' do
+ store.update!(url: 'shop.example.com')
+
+ url = payment_method.webhook_url
+
+ expect(URI.parse(url).scheme).to be_present
+ expect(url).to end_with("/api/v3/webhooks/payments/#{payment_method.prefixed_id}")
+ end
+ end
+
describe '#gateway_amount' do
it 'hands a method that takes money amounts the amount with its currency' do
method = Spree::Gateway::Bogus.new
diff --git a/spree/providers/stripe/app/models/spree_stripe/gateway/connect.rb b/spree/providers/stripe/app/models/spree_stripe/gateway/connect.rb
index 9bf1437ea9..1092042b78 100644
--- a/spree/providers/stripe/app/models/spree_stripe/gateway/connect.rb
+++ b/spree/providers/stripe/app/models/spree_stripe/gateway/connect.rb
@@ -93,7 +93,7 @@ module SpreeStripe
def connect_webhook_url
return nil unless store
- "#{store.url_or_custom_domain}/api/v3/webhooks/payouts/#{prefixed_id}"
+ "#{store.formatted_url_or_custom_domain}/api/v3/webhooks/payouts/#{prefixed_id}"
end
def create_connect_webhook_endpoint
diff --git a/spree/providers/stripe/spec/models/spree_stripe/gateway/connect_spec.rb b/spree/providers/stripe/spec/models/spree_stripe/gateway/connect_spec.rb
index 753e88e079..4815fbf7db 100644
--- a/spree/providers/stripe/spec/models/spree_stripe/gateway/connect_spec.rb
+++ b/spree/providers/stripe/spec/models/spree_stripe/gateway/connect_spec.rb
@@ -405,5 +405,11 @@ RSpec.describe SpreeStripe::Gateway::Connect do
expect(gateway.connect_webhook_url).to end_with("/api/v3/webhooks/payouts/#{gateway.prefixed_id}")
expect(gateway.connect_webhook_url).not_to eq(gateway.webhook_url)
end
+
+ it 'is an absolute url when the store url is a bare host' do
+ gateway.store.update!(url: 'shop.example.com')
+
+ expect(URI.parse(gateway.connect_webhook_url).scheme).to be_present
+ end
end
end
diff --git a/spree/providers/stripe/spec/models/spree_stripe/gateway_spec.rb b/spree/providers/stripe/spec/models/spree_stripe/gateway_spec.rb
index 83f61e1923..1ce2f5dda1 100644
--- a/spree/providers/stripe/spec/models/spree_stripe/gateway_spec.rb
+++ b/spree/providers/stripe/spec/models/spree_stripe/gateway_spec.rb
@@ -241,7 +241,13 @@ RSpec.describe SpreeStripe::Gateway do
subject { gateway.webhook_url }
it 'returns the core payment webhook url' do
- expect(subject).to eq("#{store.url_or_custom_domain}/api/v3/webhooks/payments/#{gateway.prefixed_id}")
+ expect(subject).to eq("#{store.formatted_url_or_custom_domain}/api/v3/webhooks/payments/#{gateway.prefixed_id}")
+ end
+
+ it 'is an absolute url when the store url is a bare host' do
+ store.update!(url: 'shop.example.com')
+
+ expect(URI.parse(subject).scheme).to be_present
end
end