# `MishkaPay.Invoice.Draft`
[🔗](https://github.com/mishka-group/mishka_pay/blob/v0.0.1/nofile#L1)

A bill to make for a customer, outside any subscription, with `MishkaPay.create_invoice/1`: a
service sold by hand, an order paid later. The provider makes it as a draft and answers it as a
`MishkaPay.Invoice`; `MishkaPay.finalize_invoice/3` opens it for payment,
`MishkaPay.send_invoice/3` emails it, and `MishkaPay.pay_invoice/4`, `void_invoice/3`,
`mark_invoice_uncollectible/3` and `delete_invoice/3` end it. A guarded_struct.

  * `:provider`, `:tenant`: as for a checkout.
  * `:customer_id`: the provider customer it bills (`MishkaPay.create_customer/1`).
  * `:items`: one or more `MishkaPay.Price`, all in one currency: a catalog price by its `:id`,
    or a `:name` with an `:amount` and a `:quantity`. A recurring price is refused: a plan
    starts with a checkout. An item's `:tax_rate_ids` add the seller's own tax rates to it.
  * `:tax_rate_ids`: the seller's own tax rates (`MishkaPay.TaxRate`) for every line of the bill
    that names none of its own.
  * `:collection`: `:charge_automatically` (the default) charges the customer's saved payment
    method when it is finalized; `:send_invoice` emails a bill they pay on the provider's page,
    within `:days_until_due` (30 unless given).
  * `:description`, `:footer`: text on the bill.
  * `:reference`: the caller's own id for the bill, such as an order id; it makes the
    idempotency key, so the same reference never makes two bills, and it comes back on it.
  * `:metadata`: extra pairs kept with it.

Stripe sells as merchant of record (Managed Payments) only through checkouts and payment links:
a site with merchant of record on cannot send one-off bills.

# `t`

```elixir
@type t() :: %MishkaPay.Invoice.Draft{
  collection: (:charge_automatically | :send_invoice) | nil,
  customer_id: String.t(),
  days_until_due: pos_integer() | nil,
  description: String.t() | nil,
  footer: String.t() | nil,
  items: [MishkaPay.Price.t()],
  metadata: map() | nil,
  provider: String.t(),
  reference: String.t() | nil,
  tax_rate_ids: list() | nil,
  tenant: term() | nil
}
```

The struct that `builder/1` returns.

| Field | Type | Required | Default | Description | Derives |
| --- | --- | --- | --- | --- | --- |
| `:provider` | `String.t()` | yes |  |  | `sanitize(trim) validate(not_nil_value, string, not_empty)` |
| `:tenant` | `term()` \| `nil` | no |  |  |  |
| `:customer_id` | `String.t()` | yes |  |  | `sanitize(trim) validate(not_nil_value, string, not_empty)` |
| `:items` | [`[MishkaPay.Price.t()]`](`t:MishkaPay.Price.t/0`) | yes |  |  | `validate(not_nil_value, list)` |
| `:collection` | `:charge_automatically` \| `:send_invoice` \| `nil` | no | `:charge_automatically` |  | `validate(not_nil_value, enum=Atom[charge_automatically::send_invoice])`<br>validator `{MishkaPay.Invoice, :collection}` |
| `:days_until_due` | `pos_integer()` \| `nil` | no |  |  | `validate(integer, min_len=1)` |
| `:tax_rate_ids` | `list()` \| `nil` | no |  |  | `sanitize(each=[trim]) validate(list, each=[string, not_empty])` |
| `:description` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, max_len=1500)` |
| `:footer` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, max_len=5000)` |
| `:reference` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty, max_len=200)` |
| `:metadata` | `map()` \| `nil` | no | `%{}` |  | `validate(map)`<br>validator `{MishkaPay.Checkout, :metadata}` |

# `builder`

# `enforce_keys`

# `enforce_keys`

# `example`

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

# `keys`

# `keys`

---

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