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

Takes back one usage report sent by mistake, with `MishkaPay.cancel_usage/1`: the meter then
counts it as if it was never reported. A guarded_struct.

What the caller gives:

  * `:provider`, `:tenant`: which provider, with whose keys.
  * `:event_name`: the meter's event name the report was sent under.
  * `:usage_id`: the report's id, the `:id` of the `MishkaPay.Usage` that
    `MishkaPay.report_usage/1` answered (made from its `:reference`).

What the provider fills in: `:status`, `:pending` while it takes the report out of the count,
`:complete` once it has.

A provider takes a report back only for a while after it came in (Stripe: 24 hours). After
that, report the same value again below zero to correct the count.

# `t`

```elixir
@type t() :: %MishkaPay.Usage.Cancellation{
  event_name: String.t(),
  provider: String.t(),
  status: (:pending | :complete) | nil,
  tenant: term() | nil,
  usage_id: String.t()
}
```

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 |  |  |  |
| `:event_name` | `String.t()` | yes |  |  | `sanitize(trim) validate(not_nil_value, string, not_empty, max_len=100)` |
| `:usage_id` | `String.t()` | yes |  |  | `sanitize(trim) validate(not_nil_value, string, not_empty, max_len=100)` |
| `:status` | `:pending` \| `:complete` \| `nil` | no |  |  | `validate(enum=Atom[pending::complete])` |

# `builder`

# `enforce_keys`

# `enforce_keys`

# `example`

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

# `keys`

# `keys`

---

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