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.
Summary
Functions
The deduplication id from the header.
The deduplication id carried INSIDE the signed body.
Case-insensitive header lookup, including the CGI form.
Whether the event is one of the five documented types.
The five event types the payment IPN emits — five, not two.
Build a verifier.
Verify a CoinPayments-shaped IPN and return its form fields.
Verify a mass-payout webhook and return its payload.
Verify a payment IPN and return its decoded payload.
Types
@type t() :: %Payzum.Webhooks{replay_window: pos_integer(), secret: String.t()}
Functions
The deduplication id from the header.
The header is NOT covered by the signature, so prefer event_id_from_payload/1.
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.
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.
Whether the event is one of the five documented 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.
Build a verifier.
@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.
@spec verify_mass_payout(t(), binary(), map(), keyword()) :: {:ok, map()} | {:error, Payzum.Errors.Signature.t()}
Verify a mass-payout webhook and return its payload.
@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.