# `Spectre.Operation.Delivery.Receipt`
[🔗](https://github.com/elchemista/spectre/blob/0.3.0/lib/spectre/operation/delivery/receipt.ex#L1)

Portable audit receipt for one governed delivery decision.

# `t`

```elixir
@type t() :: %Spectre.Operation.Delivery.Receipt{
  channel: term(),
  consent_id: term(),
  decided_at: term(),
  dedupe_key: term(),
  delivered_at: term(),
  destination: term(),
  event_id: term(),
  external_receipt: term(),
  id: term(),
  loop_id: term(),
  metadata: term(),
  not_before: term(),
  reason: term(),
  status: term(),
  subject_id: term()
}
```

# `transition`

```elixir
@spec transition(t(), :authorized | :delivered | :failed, term(), non_neg_integer()) ::
  {:ok, t()} | {:error, term()}
```

Re-authorizes a due `:deferred`/`:digest` receipt, or transitions an
`:authorized` receipt to `:delivered` or `:failed`.

For `:delivered`, `detail` is stored as the external receipt and `at` as the
delivery time; for `:failed`, `detail` becomes the failure reason. Repeating a
transition with the same detail is idempotent. Returns `{:ok, receipt}` or
`{:error, reason}` when the transition is not allowed from the current status.

# `validate`

```elixir
@spec validate(t()) :: :ok | {:error, term()}
```

Validates the receipt's identity, target, status, timestamps and portability.

Returns `:ok`, or `{:error, reason}` naming the first invalid field or the
status whose required fields are inconsistent.

# `validate!`

```elixir
@spec validate!(t()) :: t()
```

Same as `validate/1` but returns the receipt, raising `ArgumentError` when invalid.

---

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