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

A provider's webhook message after its signature was checked, as `MishkaPay.Webhook` hands it
to the `mishka_pay:webhook:received` listeners. A guarded_struct the provider fills in.

  * `:provider`, `:tenant`: whose message, with whose keys it was checked.
  * `:id`: the provider's event id (`evt_...` at Stripe). A provider may send one event more
    than once: a listener keeps what it did by this id.
  * `:type`: the provider's own name for what happened, such as `"checkout.session.completed"`.
  * `:object_id`, `:object_type`: what it is about (`"pi_..."`, `"payment_intent"`); an
    entitlement summary has no id of its own.
  * `:payment_id`: the payment it concerns, when it concerns one: the object itself for a
    payment, or the payment a checkout, charge, refund or dispute belongs to. The id
    `MishkaPay.fetch_payment/3` takes.
  * `:subscription_id`: the subscription it concerns, when it concerns one: the object itself
    for a subscription, or the subscription an invoice belongs to. The id
    `MishkaPay.fetch_subscription/3` takes.
  * `:dispute_id`: the dispute it concerns, for a `charge.dispute.*` event
    (`MishkaPay.fetch_dispute/3`).
  * `:customer_id`: the customer it changes: the customer itself, or the one a tax id, a saved
    payment method, a setup or an entitlement summary belongs to (`customer.*`,
    `customer.tax_id.*`, `payment_method.*`, `setup_intent.*`,
    `entitlements.active_entitlement_summary.updated` on Stripe). The id
    `MishkaPay.fetch_customer/3` takes.
  * `:livemode`: whether it came from live or test mode.
  * `:account`: the connected account it is for, when the provider has those.
  * `:created_at`: when the provider made it.

Only the ids matter: a listener reads the object again from the provider
(`MishkaPay.fetch_payment/3`), which stays the source of truth, and never trusts the order
events arrive in.

# `t`

```elixir
@type t() :: %MishkaPay.Event{
  account: String.t() | nil,
  created_at: DateTime.t() | nil,
  customer_id: String.t() | nil,
  dispute_id: String.t() | nil,
  id: String.t(),
  livemode: boolean() | nil,
  object_id: String.t() | nil,
  object_type: String.t() | nil,
  payment_id: String.t() | nil,
  provider: String.t(),
  subscription_id: String.t() | nil,
  tenant: term() | nil,
  type: String.t()
}
```

The struct that `builder/1` returns.

| Field | Type | Required | Default | Description | Derives |
| --- | --- | --- | --- | --- | --- |
| `:provider` | `String.t()` | yes |  |  | `validate(not_nil_value, string)` |
| `:tenant` | `term()` \| `nil` | no |  |  |  |
| `:id` | `String.t()` | yes |  |  | `validate(not_nil_value, string, not_empty)` |
| `:type` | `String.t()` | yes |  |  | `validate(not_nil_value, string, not_empty)` |
| `:object_id` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:object_type` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:payment_id` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:subscription_id` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:dispute_id` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:customer_id` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:livemode` | `boolean()` \| `nil` | no | `false` |  | `validate(boolean)` |
| `:account` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:created_at` | `DateTime.t()` \| `nil` | no |  |  | `validate(struct)` |

# `builder`

# `enforce_keys`

# `enforce_keys`

# `example`

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

# `keys`

# `keys`

---

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