Money v2.3.0 Money.Subscription.Plan View Source
Defines a standard subscription plan data structure.
Link to this section Summary
Functions
Defines the structure of a subscription plan
Returns {:ok, Money.Subscription.Plan.t}
or an {:error, reason}
tuple
Returns {:ok, Money.Subscription.Plan.t}
or raises an
exception
Link to this section Types
A plan interval type.
A integer interval count for a plan.
Link to this section Functions
Defines the structure of a subscription plan.
Returns {:ok, Money.Subscription.Plan.t}
or an {:error, reason}
tuple.
Arguments
:price
is anyMoney.t
:interval
is the period of the plan. The valid intervals are:day
,
:week,
:monthor ':year
.:interval_count
is an integer count of the number of:interval
s of the plan. The default is1
Returns
A Money.Subscription.Plan.t
Examples
iex> Money.Subscription.Plan.new Money.new(:USD, 100), :month, 1
{:ok,
%Money.Subscription.Plan{
interval: :month,
interval_count: 1,
price: Money.new(:USD, 100)
}}
iex> Money.Subscription.Plan.new Money.new(:USD, 100), :month
{:ok,
%Money.Subscription.Plan{
interval: :month,
interval_count: 1,
price: Money.new(:USD, 100)
}}
iex> Money.Subscription.Plan.new Money.new(:USD, 100), :day, 30
{:ok,
%Money.Subscription.Plan{
interval: :day,
interval_count: 30,
price: Money.new(:USD, 100)
}}
iex> Money.Subscription.Plan.new 23, :day, 30
{:error, {Money.Invalid, "Invalid subscription plan definition"}}
Returns {:ok, Money.Subscription.Plan.t}
or raises an
exception.
Takes the same arguments as Money.Subscription.Plan.new/3
.
Example
iex> Money.Subscription.Plan.new! Money.new(:USD, 100), :day, 30
%Money.Subscription.Plan{
interval: :day,
interval_count: 30,
price: Money.new(:USD, 100)
}