Billing upgrade/downgrade, inviti in app e diretta YouTube da mobile.
Upgrade Stripe con addebito immediato; downgrade programmato a fine periodo. UX billing più sobria con box info; icone piani. API inviti e OAuth YouTube per staff trasmissione; deep link join; scelta partita programmata o nuova. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
60
backend/app/services/billing/stripe/plan_change_messages.rb
Normal file
60
backend/app/services/billing/stripe/plan_change_messages.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
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?
|
||||
"Upgrade a #{plan.name} (#{interval_label}) completato. Addebito immediato: #{amount}."
|
||||
else
|
||||
"Upgrade a #{plan.name} (#{interval_label}) completato. L'addebito della differenza è in elaborazione sulla carta salvata."
|
||||
end
|
||||
else
|
||||
when_label = result.effective_at.present? ? I18n.l(result.effective_at, format: :long) : "il prossimo rinnovo"
|
||||
current_name = current_plan&.name || "il piano attuale"
|
||||
"Passaggio a #{plan.name} (#{interval_label}) programmato: resti su #{current_name} fino al #{when_label}. " \
|
||||
"Nessun addebito aggiuntivo ora; dal prossimo ciclo pagherai il nuovo prezzo."
|
||||
end
|
||||
end
|
||||
|
||||
def button_label(plan:, interval:, kind:)
|
||||
price = PriceCatalog.label(plan_slug: plan.slug, interval: interval)
|
||||
if kind == :checkout
|
||||
"Attiva #{plan.name} — #{price}"
|
||||
else
|
||||
"Passa a #{plan.name} — #{price}"
|
||||
end
|
||||
end
|
||||
|
||||
def billing_info_lines(subscription: nil)
|
||||
lines = [
|
||||
"Upgrade (piano superiore o passaggio alla fatturazione annuale): la differenza viene addebitata subito sulla carta salvata in Stripe.",
|
||||
"Downgrade tra piani a pagamento (es. Full → Light): il nuovo piano è attivo dal prossimo rinnovo; fino ad allora restano le funzioni del piano attuale, senza addebito aggiuntivo ora."
|
||||
]
|
||||
|
||||
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) : "il prossimo rinnovo"
|
||||
lines.unshift(
|
||||
"Hai già richiesto #{subscription.pending_plan.name} dal #{when_label}: fino ad allora resta attivo #{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
|
||||
Reference in New Issue
Block a user