PaperTiger.Resources.Coupon (PaperTiger v1.0.2)

Copy Markdown View Source

Handles Coupon resource endpoints.

Endpoints

  • POST /v1/coupons - Create coupon
  • GET /v1/coupons/:id - Retrieve coupon
  • POST /v1/coupons/:id - Update coupon
  • DELETE /v1/coupons/:id - Delete coupon
  • GET /v1/coupons - List coupons

Coupon Object

%{
  id: "SUMMER20",
  object: "coupon",
  created: 1234567890,
  percent_off: 20,
  amount_off: nil,
  currency: nil,
  duration: "forever",
  duration_in_months: nil,
  metadata: %{},
  max_redemptions: nil,
  redeem_by: nil,
  # ... other fields
}

Summary

Functions

Creates a new coupon.

Deletes a coupon.

Lists all coupons with pagination.

Retrieves a coupon by ID.

Updates a coupon.

Functions

create(conn)

@spec create(Plug.Conn.t()) :: Plug.Conn.t()

Creates a new coupon.

Required Parameters

  • id - Coupon code (e.g., "SUMMER20")
  • duration - "forever", "once", or "repeating"

One of:

  • percent_off - Percentage discount (e.g., 20 for 20% off)
  • amount_off - Amount discount in cents (requires currency)

Optional Parameters

  • currency - Three-letter ISO currency code (required if amount_off)
  • duration_in_months - Number of months (required if duration="repeating")
  • metadata - Key-value metadata
  • max_redemptions - Maximum number of times coupon can be redeemed
  • redeem_by - Unix timestamp after which coupon cannot be redeemed

delete(conn, id)

@spec delete(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Deletes a coupon.

Returns a deletion confirmation object.

list(conn)

@spec list(Plug.Conn.t()) :: Plug.Conn.t()

Lists all coupons with pagination.

Parameters

  • limit - Number of items (default: 10, max: 100)
  • starting_after - Cursor for pagination
  • ending_before - Reverse cursor

retrieve(conn, id)

@spec retrieve(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Retrieves a coupon by ID.

update(conn, id)

@spec update(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Updates a coupon.

Note: Coupons are mostly immutable. Only metadata can be updated.

Updatable Fields

  • metadata