View Source Money.Subscription.Plan (Money v5.12.1)

Defines a standard subscription plan data structure.

Link to this section Summary

Types

A plan interval type.

A integer interval count for a plan.

t()

A Subscription Plan

Functions

Defines the structure of a subscription plan.

Returns {:ok, Money.Subscription.Plan.t} or raises an exception.

Returns {:ok, Money.Subscription.Plan.t} or an {:error, reason} tuple.

Link to this section Types

@type interval() :: :day | :week | :month | :year

A plan interval type.

@type interval_count() :: non_neg_integer()

A integer interval count for a plan.

@type t() :: %Money.Subscription.Plan{
  interval: interval(),
  interval_count: interval_count(),
  price: Money.t() | nil
}

A Subscription Plan

Link to this section Functions

Link to this function

%Money.Subscription.Plan{}

View Source (struct)

Defines the structure of a subscription plan.

Link to this function

new!(price, interval, interval_count \\ 1)

View Source
@spec new!(Money.t(), interval(), interval_count()) :: t() | no_return()

Returns {:ok, Money.Subscription.Plan.t} or raises an exception.

Takes the same arguments as Money.Subscription.Plan.new/3.

example

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)
}
Link to this function

new(price, interval, interval_count \\ 1)

View Source
@spec new(Money.t(), interval(), interval_count()) ::
  {:ok, t()} | {:error, {module(), String.t()}}

Returns {:ok, Money.Subscription.Plan.t} or an {:error, reason} tuple.

arguments

Arguments

  • :price is any Money.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 :intervals of the plan. The default is 1

returns

Returns

A Money.Subscription.Plan.t

examples

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"}}