AuroraMeter. Plans
(Aurora Meter v0.1.0)
View Source
Compile-time DSL for declaring billing plans, plus runtime lookups.
Define a plans module:
defmodule MyApp.Plans do
use AuroraMeter.Plans
plan :free do
price 0
limit :ai_generations, 50, :hard
feature :api_access, false
end
plan :pro do
price 2_000
limit :ai_generations, 1_000, :hard
feature :api_access, true
end
plan :scale do
price 2_000
metered :ai_generations, included: 1_000, unit_price: 2
feature :api_access, true
end
endThen point config :aurora_meter, plans: MyApp.Plans. Definitions are validated
at compile time (duplicate features, invalid modes, negative numbers all raise).
Summary
Functions
Returns all plans as %{id => Plan.t()} from the configured plans module.
Declares plain feature access: feature :feature, boolean.
Returns the feature config for feature in plan_id, or nil.
Returns a single plan by id, or nil.
Declares a hard-capped feature: limit :feature, n, :hard.
Declares a metered feature: metered :feature, included: n, unit_price: cents.
Declares a plan. Contains price, limit, metered, and feature calls.
Sets the plan's monthly price in minor units (cents).
Functions
@spec all() :: %{optional(atom()) => AuroraMeter.Plan.t()}
Returns all plans as %{id => Plan.t()} from the configured plans module.
Declares plain feature access: feature :feature, boolean.
@spec feature_config(atom(), atom()) :: AuroraMeter.Plan.feature_config() | nil
Returns the feature config for feature in plan_id, or nil.
@spec get(atom()) :: AuroraMeter.Plan.t() | nil
Returns a single plan by id, or nil.
Declares a hard-capped feature: limit :feature, n, :hard.
Declares a metered feature: metered :feature, included: n, unit_price: cents.
Declares a plan. Contains price, limit, metered, and feature calls.
Sets the plan's monthly price in minor units (cents).