PhoenixKit.Modules.Billing.SubscriptionType (phoenix_kit v1.7.71)

Copy Markdown View Source

Schema for subscription types (pricing tiers).

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

Fields

  • name - Display name (e.g., "Basic", "Pro", "Enterprise")
  • slug - Unique identifier (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 type
  • active - Whether this type is available for new subscriptions
  • sort_order - Display order in type listings

Examples

%SubscriptionType{
  name: "Professional",
  slug: "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 subscription type.

Creates a changeset for a subscription type.

Returns the formatted price string with currency.

Gets a subscription type by its slug.

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

Lists all active subscription types ordered by sort_order.

Calculates the next billing date from a given start date.

Functions

billing_period_days(subscription_type)

Returns the billing period in days for this subscription type.

changeset(type, attrs)

Creates a changeset for a subscription type.

Required fields

  • name - Display name
  • slug - Unique identifier (URL-friendly)
  • price - Price per period

Optional fields

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

formatted_price(subscription_type)

Returns the formatted price string with currency.

get_by_slug(slug)

Gets a subscription type by its slug.

interval_description(subscription_type)

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

list_active()

Lists all active subscription types ordered by sort_order.

next_billing_date(subscription_type, from_date)

Calculates the next billing date from a given start date.