Files
MatchLiveTv/backend/app/services/billing/stripe/plan_change_messages.rb
T
eminuxandCursor b88f44ab1c Completa i18n IT/EN/FR/DE/ES su sito pubblico, area autenticata e admin.
Tutte le view marketing, legali, viewer, dashboard e admin usano t(); mailer utente-facing e flash localizzati; admin con LocaleResolver e selettore lingua.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 00:38:50 +02:00

60 lines
2.3 KiB
Ruby

module Billing
module Stripe
module PlanChangeMessages
module_function
def flash_notice(result, current_plan: nil)
plan = Plan[result.plan_slug]
interval_label = PriceCatalog.label(plan_slug: result.plan_slug, interval: result.interval)
if result.upgrade?
amount = format_amount(result.amount_cents, result.currency)
if amount.present?
I18n.t("billing.messages.upgrade_completed_with_amount", plan: plan.name, interval: interval_label, amount: amount)
else
I18n.t("billing.messages.upgrade_completed_pending_charge", plan: plan.name, interval: interval_label)
end
else
when_label = result.effective_at.present? ? I18n.l(result.effective_at, format: :long) : I18n.t("billing.messages.next_renewal")
current_name = current_plan&.name || I18n.t("billing.messages.current_plan_generic")
I18n.t("billing.messages.downgrade_scheduled", plan: plan.name, interval: interval_label, current_name: current_name, when: when_label)
end
end
def button_label(plan:, interval:, kind:)
price = PriceCatalog.label(plan_slug: plan.slug, interval: interval)
if kind == :checkout
I18n.t("billing.messages.activate_button", plan: plan.name, price: price)
else
I18n.t("billing.messages.switch_button", plan: plan.name, price: price)
end
end
def billing_info_lines(subscription: nil)
lines = [
I18n.t("billing.messages.upgrade_info_line"),
I18n.t("billing.messages.downgrade_info_line")
]
if subscription&.plan_change_pending? && subscription.pending_plan.present?
when_at = subscription.current_period_end
when_label = when_at.present? ? I18n.l(when_at, format: :long) : I18n.t("billing.messages.next_renewal")
lines.unshift(
I18n.t("billing.messages.already_requested_line", plan: subscription.pending_plan.name, when: when_label, current_plan: subscription.plan.name)
)
end
lines
end
def format_amount(cents, currency)
return nil if cents.blank? || cents.to_i <= 0
unit = currency.to_s.upcase.presence || "EUR"
amount = cents.to_i / 100.0
format("%.2f %s", amount, unit == "EUR" ? "€" : unit)
end
end
end
end