Il piano si attiva solo dopo la conferma admin; Stripe resta a listino se non c'è un prezzo commerciale. Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
969 B
Ruby
35 lines
969 B
Ruby
module Billing
|
|
class ClubQuote < ApplicationRecord
|
|
self.table_name = "billing_club_quotes"
|
|
|
|
PLAN_SLUGS = %w[premium_light premium_full].freeze
|
|
INTERVALS = Billing::Stripe::PriceCatalog::INTERVALS
|
|
|
|
belongs_to :club
|
|
belongs_to :created_by_admin, class_name: "AdminAccount", optional: true
|
|
|
|
validates :plan_slug, inclusion: { in: PLAN_SLUGS }
|
|
validates :billing_interval, inclusion: { in: INTERVALS }
|
|
validates :amount_cents, numericality: { greater_than: 0 }
|
|
validates :currency, presence: true
|
|
|
|
scope :active, -> { where(active: true) }
|
|
|
|
def matches?(plan_slug, interval)
|
|
self.plan_slug == plan_slug.to_s && billing_interval == interval.to_s
|
|
end
|
|
|
|
def plan
|
|
Plan[plan_slug]
|
|
end
|
|
|
|
def formatted_amount
|
|
Billing::Stripe::PriceCatalog.format_eur(amount_cents)
|
|
end
|
|
|
|
def price_label
|
|
Billing::Stripe::PriceCatalog.format_interval_price(amount_cents, billing_interval)
|
|
end
|
|
end
|
|
end
|