# `MishkaPay.Product`
[🔗](https://github.com/mishka-group/mishka_pay/blob/v0.0.1/lib/mishka_pay/product.ex#L5)

Something sold, as the provider keeps it in its catalog (`prod_...` at Stripe), with its prices
(`MishkaPay.Price` with `:product_id`). A guarded_struct.

Made with `MishkaPay.create_product/1`, changed with `MishkaPay.update_product/1`, taken off sale
with `MishkaPay.archive_product/3`, read with `MishkaPay.fetch_product/3` and
`MishkaPay.list_products/3`. A checkout sells a catalog price by its id (`items: [%{id:
"price_..."}]`).

What the caller gives:

  * `:provider`, `:tenant`: which provider, with whose keys.
  * `:id`: optional, the product's own id (`"shop-ebook"`); the provider makes one when it is
    left out.
  * `:name`, `:description`: what the buyer sees.
  * `:tax_code`: the provider's tax category, such as Stripe's `"txcd_10302000"`.
  * `:active`: on sale (`true` by default); `false` keeps it for past sales only.
  * `:metadata`: extra pairs, string keys to string values.

What the provider fills in: `:default_price_id`, `:created_at`.

# `t`

```elixir
@type t() :: %MishkaPay.Product{
  active: boolean() | nil,
  created_at: DateTime.t() | nil,
  default_price_id: String.t() | nil,
  description: String.t() | nil,
  id: String.t() | nil,
  metadata: map() | nil,
  name: String.t() | nil,
  provider: String.t() | nil,
  tax_code: String.t() | nil,
  tenant: term() | nil
}
```

The struct that `builder/1` returns.

| Field | Type | Required | Default | Description | Derives |
| --- | --- | --- | --- | --- | --- |
| `:provider` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty)` |
| `:tenant` | `term()` \| `nil` | no |  |  |  |
| `:id` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty, max_len=200)` |
| `:name` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty, max_len=250)` |
| `:description` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty, max_len=1000)` |
| `:tax_code` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty, max_len=100)` |
| `:active` | `boolean()` \| `nil` | no |  |  | `validate(boolean)` |
| `:metadata` | `map()` \| `nil` | no | `%{}` |  | `validate(map)`<br>validator `{MishkaPay.Checkout, :metadata}` |
| `:default_price_id` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:created_at` | `DateTime.t()` \| `nil` | no |  |  | `validate(struct)` |

# `builder`

# `enforce_keys`

# `enforce_keys`

# `example`

A sample %MishkaPay.Product{} populated from defaults + type-based fallbacks.

# `keys`

# `keys`

---

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