Nombaone.Coupons (Nomba One v0.1.0)

View Source

Coupons — discount rules you apply via Nombaone.Customers.apply_discount/4 or Nombaone.Subscriptions.apply_discount/4.

{:ok, coupon} =
  Nombaone.Coupons.create(client, %{
    code: "LAUNCH20",
    percent_off: 20,
    duration: "repeating",
    duration_in_cycles: 3
  })

Summary

Functions

Create a coupon. Set exactly one of :amount_off_in_kobo (integer kobo) or :percent_off (1–100).

List coupons, newest first. Optional: :limit, :cursor.

Retrieve a coupon by id. Common errors: 404 COUPON_NOT_FOUND.

Update a coupon's :redeem_by, :max_redemptions, or :metadata.

Functions

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

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

Create a coupon. Set exactly one of :amount_off_in_kobo (integer kobo) or :percent_off (1–100).

Common errors: 422 COUPON_INVALID_DEFINITION.

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

@spec create!(Nombaone.Client.t(), map(), keyword()) :: Nombaone.Coupon.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 coupons, newest first. Optional: :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.Coupon.t()} | {:error, Nombaone.Error.t()}

Retrieve a coupon by id. Common errors: 404 COUPON_NOT_FOUND.

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

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

Raising variant of retrieve/3.

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

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

Update a coupon's :redeem_by, :max_redemptions, or :metadata.

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

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

Raising variant of update/4.