Braintree.Plan (Braintree v0.13.0)

Plans represent recurring billing plans in a Braintree merchant account. The API for plans is read only.

For additional reference see: https://developers.braintreepayments.com/reference/request/plan/all/ruby

Link to this section Summary

Functions

Get a list of all the plans defined in the merchant account. If there are no plans an empty list is returned.

Create a new plan under a merchant account.

Delete a plan defined in the merchant account by the plan id. A plan can't be deleted if it has any former or current subscriptions associated with it. If there is no plan with the specified id, {:error, :not_found} is returned.

Get a specific plan defined in the merchant account by the plan id. If there is no plan with the specified id, {:error, :not_found} is returned.

Updates a specific plan defined in the merchant account by the plan id. If there is no plan with the specified id, {:error, :not_found} is returned.

Link to this section Types

@type t() :: %Braintree.Plan{
  add_ons: [any()],
  balance: String.t(),
  billing_day_of_month: String.t(),
  billing_frequency: String.t(),
  created_at: String.t(),
  currency_iso_code: String.t(),
  description: String.t(),
  discounts: [any()],
  id: String.t(),
  name: String.t(),
  number_of_billing_cycles: String.t(),
  price: String.t(),
  trial_duration: String.t(),
  trial_duration_unit: String.t(),
  trial_period: String.t(),
  updated_at: String.t()
}

Link to this section Functions

Link to this function

all(opts \\ [])

@spec all(Keyword.t()) :: {:ok, [t()]} | {:error, Braintree.ErrorResponse.t()}

Get a list of all the plans defined in the merchant account. If there are no plans an empty list is returned.

example

Example

{:ok, plans} = Braintree.Plan.all()
Link to this function

create(params, opts \\ [])

@spec create(map(), Keyword.t()) :: {:ok, t()} | {:error, Braintree.ErrorResponse.t()}

Create a new plan under a merchant account.

example

Example

{:ok, plan} = Braintree.Plan.create(%{
  name: "a plan",
  billing_frequency: 3,
  currency_iso_code: "USD",
  price: "10.00"
})
Link to this function

delete(id, opts \\ [])

@spec delete(String.t(), Keyword.t()) :: :ok | {:error, Braintree.ErrorResponse.t()}

Delete a plan defined in the merchant account by the plan id. A plan can't be deleted if it has any former or current subscriptions associated with it. If there is no plan with the specified id, {:error, :not_found} is returned.

Link to this function

find(id, opts \\ [])

@spec find(String.t(), Keyword.t()) ::
  {:ok, t()} | {:error, Braintree.ErrorResponse.t()}

Get a specific plan defined in the merchant account by the plan id. If there is no plan with the specified id, {:error, :not_found} is returned.

example

Example

{:ok, plan} = Braintree.Plan.find("existing plan_id")

{:error, :not_found} = Braintree.Plan.find("non-existing plan_id")
Link to this function

update(id, params, opts \\ [])

@spec update(String.t(), map(), Keyword.t()) ::
  {:ok, t()} | {:error, Braintree.ErrorResponse.t()}

Updates a specific plan defined in the merchant account by the plan id. If there is no plan with the specified id, {:error, :not_found} is returned.

example

Example

{:ok, updated_plan} = Braintree.Plan.find("existing plan_id", %{name: "new_name"})

{:error, :not_found} = Braintree.Plan.find("non-existing plan_id")