Money.Subscription.Plan.new

You're seeing just the function new, go back to Money.Subscription.Plan module for more information.
Link to this function

new(price, interval, interval_count \\ 1)

View Source

Specs

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

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

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

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