extract url helpers to helper module

This commit is contained in:
Andy Brett
2021-02-03 09:26:32 -08:00
parent c0b3fc301e
commit 558b01896f
2 changed files with 19 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
# frozen_string_literal: true
module FullUrlHelper
def url_helpers
# This is how we can get the helpers with a usable root_url outside the controllers
Rails.application.routes.default_url_options = ActionMailer::Base.default_url_options
Rails.application.routes.url_helpers
end
def full_checkout_path
URI.join(url_helpers.root_url, url_helpers.checkout_path).to_s
end
def full_order_path(order)
URI.join(url_helpers.root_url, url_helpers.order_path(order)).to_s
end
end

View File

@@ -10,6 +10,8 @@ require 'active_merchant/billing/gateways/stripe_decorator'
module Spree
class Gateway
class StripeSCA < Gateway
include FullUrlHelper
preference :enterprise_id, :integer
validate :ensure_enterprise_selected
@@ -145,16 +147,6 @@ module Spree
errors.add(:stripe_account_owner, I18n.t(:error_required))
end
def full_checkout_path
URI.join(url_helpers.root_url, url_helpers.checkout_path).to_s
end
def url_helpers
# This is how we can get the helpers with a usable root_url outside the controllers
Rails.application.routes.default_url_options = ActionMailer::Base.default_url_options
Rails.application.routes.url_helpers
end
end
end
end