Module: PricingPlans::ViewHelpers
- Defined in:
- lib/pricing_plans/view_helpers.rb
Class Method Summary collapse
-
.pricing_plan_cta(plan, plan_owner: nil, context: :marketing, current_plan: nil) ⇒ Object
CTA data resolution.
-
.pricing_plan_ui_data(plan) ⇒ Object
Pure-data UI struct for Stimulus/JS pricing toggles Returns keys: - :monthly_price, :yearly_price (formatted labels) - :monthly_price_cents, :yearly_price_cents - :monthly_price_id, :yearly_price_id - :free (boolean) - :label (fallback label for non-numeric).
-
.pricing_plans_subscribe_path(plan, interval: :month) ⇒ Object
Helper that resolves the conventional subscribe path if present in host app Defaults to monthly interval; apps can override by adding interval param in links.
Class Method Details
.pricing_plan_cta(plan, plan_owner: nil, context: :marketing, current_plan: nil) ⇒ Object
CTA data resolution. Returns pure data: { text:, url:, method:, disabled:, reason: } We keep this minimal and policy-free by default; host apps can layer policies.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pricing_plans/view_helpers.rb', line 31 def pricing_plan_cta(plan, plan_owner: nil, context: :marketing, current_plan: nil) text = plan.cta_text url = plan.cta_url(plan_owner: plan_owner) url ||= pricing_plans_subscribe_path(plan) disabled = false reason = nil if current_plan && plan.key.to_sym == current_plan.key.to_sym disabled = true text = "Current Plan" end { text: text, url: url, method: :get, disabled: disabled, reason: reason } end |
.pricing_plan_ui_data(plan) ⇒ Object
Pure-data UI struct for Stimulus/JS pricing toggles Returns keys:
- :monthly_price, :yearly_price (formatted labels)
- :monthly_price_cents, :yearly_price_cents
- :monthly_price_id, :yearly_price_id
- :free (boolean)
- :label (fallback label for non-numeric)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pricing_plans/view_helpers.rb', line 14 def pricing_plan_ui_data(plan) pc_m = plan.monthly_price_components pc_y = plan.yearly_price_components { monthly_price: pc_m.label, yearly_price: pc_y.label, monthly_price_cents: pc_m.amount_cents, yearly_price_cents: pc_y.amount_cents, monthly_price_id: plan.monthly_price_id, yearly_price_id: plan.yearly_price_id, free: plan.free?, label: plan.price_label } end |
.pricing_plans_subscribe_path(plan, interval: :month) ⇒ Object
Helper that resolves the conventional subscribe path if present in host app Defaults to monthly interval; apps can override by adding interval param in links
48 49 50 51 52 53 54 55 56 |
# File 'lib/pricing_plans/view_helpers.rb', line 48 def pricing_plans_subscribe_path(plan, interval: :month) if respond_to?(:main_app) && main_app.respond_to?(:subscribe_path) return main_app.subscribe_path(plan: plan.key, interval: interval) end if defined?(Rails) && Rails.application.routes.url_helpers.respond_to?(:subscribe_path) return Rails.application.routes.url_helpers.subscribe_path(plan: plan.key, interval: interval) end nil end |