PhoenixKit.Modules.Billing.SubscriptionPlan (phoenix_kit v1.7.42)

Copy Markdown View Source

Schema for subscription plans (pricing tiers).

Subscription plans define the pricing, billing interval, and features available at each tier. Plans are managed internally and used to create subscriptions.

Fields

  • name - Display name (e.g., "Basic", "Pro", "Enterprise")
  • code - Unique identifier code (e.g., "basic", "pro")
  • description - Marketing description
  • price - Price per billing period (Decimal)
  • currency - Three-letter currency code (default: "EUR")
  • interval - Billing interval: "day", "week", "month", "year"
  • interval_count - Number of intervals (e.g., 3 months)
  • trial_days - Free trial period in days (default: 0)
  • features - JSON map of features included in this plan
  • active - Whether this plan is available for new subscriptions
  • sort_order - Display order in plan listings

Examples

%SubscriptionPlan{
  name: "Professional",
  code: "pro",
  price: Decimal.new("29.99"),
  currency: "EUR",
  interval: "month",
  interval_count: 1,
  trial_days: 14,
  features: %{"api_calls" => 10000, "storage_gb" => 50},
  active: true
}

Summary

Functions

Returns the billing period in days for this plan.

Creates a changeset for a subscription plan.

Returns the formatted price string with currency.

Gets a plan by its code.

Returns the billing interval description (e.g., "monthly", "every 3 months").

Lists all active subscription plans ordered by sort_order.

Calculates the next billing date from a given start date.

Functions

billing_period_days(subscription_plan)

Returns the billing period in days for this plan.

changeset(plan, attrs)

Creates a changeset for a subscription plan.

Required fields

  • name - Plan display name
  • slug - Unique plan identifier (URL-friendly)
  • price - Price per period

Optional fields

  • description, currency, interval, interval_count
  • trial_days, features, active, sort_order, metadata

formatted_price(subscription_plan)

Returns the formatted price string with currency.

get_by_code(code)

Gets a plan by its code.

interval_description(subscription_plan)

Returns the billing interval description (e.g., "monthly", "every 3 months").

list_active()

Lists all active subscription plans ordered by sort_order.

next_billing_date(subscription_plan, from_date)

Calculates the next billing date from a given start date.