# `Payzum.Webhooks`
[🔗](https://github.com/payzum-dev/payzum-elixir/blob/main/lib/payzum/webhooks.ex#L1)

Verification for the three webhook families Payzum sends.

They are NOT interchangeable, and confusing them is the most expensive mistake
you can make with this API — 20 of the 21 Payzum cart plugins read
`x-payzum-signature` (the mass-payout header) for a payment IPN. The signature
never verifies, deliveries 401, the gateway retries five times and dead-letters,
and the order is silently never fulfilled.

  * payment IPN — HMAC-SHA-512, `x-nowpayments-sig`, key-sorted JSON
  * CoinPayments IPN — HMAC-SHA-512, `HMAC`, form-urlencoded
  * mass payout — HMAC-SHA-256, `X-Payzum-Signature`, JSON as sent

Header names are fixed and owned by this module. They are deliberately not
parameters: a setting is an invitation to fill it with the wrong value.

# `t`

```elixir
@type t() :: %Payzum.Webhooks{replay_window: pos_integer(), secret: String.t()}
```

# `coinpayments_header`

# `event_id`

The deduplication id from the header.

The header is NOT covered by the signature, so prefer `event_id_from_payload/1`.

# `event_id_from_payload`

The deduplication id carried INSIDE the signed body.

The payment IPN signs `event_id`, a mass payout signs `eventId` and a
CoinPayments IPN signs `ipn_id`. Retries reuse the value, so a second delivery
with the same id must be a no-op — and because it is inside the signed body, an
attacker cannot forge a new one from a captured delivery.

# `event_id_header`

# `header_value`

Case-insensitive header lookup, including the CGI form.

Frameworks normalise header casing differently — Plug lower-cases and prefixes
some of them, Cowboy passes the raw name — and matching case-sensitively would
work in development and fail in production.

# `ipn_event_type?`

Whether the event is one of the five documented types.

# `ipn_event_types`

The five event types the payment IPN emits — five, not two.

An integration that handles only paid/expired silently discards the three
others, including the two that matter for security.

# `mass_payout_header`

# `new`

```elixir
@spec new(String.t(), keyword()) :: {:ok, t()} | {:error, Payzum.Errors.Signature.t()}
```

Build a verifier.

# `payment_ipn_header`

# `verify_coinpayments_ipn`

```elixir
@spec verify_coinpayments_ipn(t(), binary(), map()) ::
  {:ok, map()} | {:error, Payzum.Errors.Signature.t()}
```

Verify a CoinPayments-shaped IPN and return its form fields.

There is no freshness check: the payload carries no timestamp, so a replay
window is impossible. Deduplicating on `ipn_id` is the only defence available.

# `verify_mass_payout`

```elixir
@spec verify_mass_payout(t(), binary(), map(), keyword()) ::
  {:ok, map()} | {:error, Payzum.Errors.Signature.t()}
```

Verify a mass-payout webhook and return its payload.

# `verify_payment_ipn`

```elixir
@spec verify_payment_ipn(t(), binary(), map(), keyword()) ::
  {:ok, map()} | {:error, Payzum.Errors.Signature.t()}
```

Verify a payment IPN and return its decoded payload.

`raw_body` must be the bytes exactly as received, before any parsing.

---

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