Nombaone.Plans (Nomba One v0.1.0)

View Source

Plans — your catalog. Prices (amount + cadence) nest underneath a plan via Nombaone.Plans.Prices.

Every function returns {:ok, result} or {:error, %Nombaone.Error{}} and has a raising ! variant.

{:ok, plan} = Nombaone.Plans.create(client, %{name: "Pro"})

{:ok, price} =
  Nombaone.Plans.Prices.create(client, plan.id, %{unit_amount_in_kobo: 250_000, interval: "month"})

Summary

Functions

Archive a plan — it stops being subscribable but its history stays.

List plans, newest first. Optional filters: :status (active or archived), :limit, :cursor.

Retrieve a plan by id. Common errors: 404 PLAN_NOT_FOUND.

Update a plan's mutable fields (:name, :description, :metadata). Pass description: nil to clear it.

Functions

archive(client, id, opts \\ [])

@spec archive(Nombaone.Client.t(), String.t(), keyword()) ::
  {:ok, Nombaone.Plan.t()} | {:error, Nombaone.Error.t()}

Archive a plan — it stops being subscribable but its history stays.

Common errors: 409 PLAN_ALREADY_ARCHIVED, 409 PLAN_HAS_ACTIVE_SUBSCRIBERS (migrate or cancel those subscriptions first).

archive!(client, id, opts \\ [])

@spec archive!(Nombaone.Client.t(), String.t(), keyword()) :: Nombaone.Plan.t()

Raising variant of archive/3.

create(client, params, opts \\ [])

@spec create(Nombaone.Client.t(), map(), keyword()) ::
  {:ok, Nombaone.Plan.t()} | {:error, Nombaone.Error.t()}

Create a plan.

Common errors: 409 PLAN_NAME_TAKEN.

Example

{:ok, plan} = Nombaone.Plans.create(client, %{name: "Pro", description: "Everything"})

create!(client, params, opts \\ [])

@spec create!(Nombaone.Client.t(), map(), keyword()) :: Nombaone.Plan.t()

Raising variant of create/3.

list(client, params \\ %{}, opts \\ [])

@spec list(Nombaone.Client.t(), map(), keyword()) ::
  {:ok, Nombaone.Page.t()} | {:error, Nombaone.Error.t()}

List plans, newest first. Optional filters: :status (active or archived), :limit, :cursor.

list!(client, params \\ %{}, opts \\ [])

@spec list!(Nombaone.Client.t(), map(), keyword()) :: Nombaone.Page.t()

Raising variant of list/3.

retrieve(client, id, opts \\ [])

@spec retrieve(Nombaone.Client.t(), String.t(), keyword()) ::
  {:ok, Nombaone.Plan.t()} | {:error, Nombaone.Error.t()}

Retrieve a plan by id. Common errors: 404 PLAN_NOT_FOUND.

retrieve!(client, id, opts \\ [])

@spec retrieve!(Nombaone.Client.t(), String.t(), keyword()) :: Nombaone.Plan.t()

Raising variant of retrieve/3.

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

@spec update(Nombaone.Client.t(), String.t(), map(), keyword()) ::
  {:ok, Nombaone.Plan.t()} | {:error, Nombaone.Error.t()}

Update a plan's mutable fields (:name, :description, :metadata). Pass description: nil to clear it.

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

@spec update!(Nombaone.Client.t(), String.t(), map(), keyword()) :: Nombaone.Plan.t()

Raising variant of update/4.