# `PaperTiger.Resources.Coupon`
[🔗](https://github.com/EnaiaInc/paper_tiger/blob/v1.2.2/lib/paper_tiger/resources/coupon.ex#L1)

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
    }

# `create`

```elixir
@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`

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

Deletes a coupon.

Returns a deletion confirmation object.

# `list`

```elixir
@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`

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

Retrieves a coupon by ID.

# `update`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
