Webhook signature verification and event construction.
Usage
case StripeElixir.Webhook.construct_event(payload, sig_header, secret) do
{:ok, event} -> handle_event(event)
{:error, error} -> send_resp(conn, 400, error.message)
end
Summary
Functions
Compute the expected signature for a payload.
Verify a webhook signature and construct a typed event struct.
Verify a webhook signature header without constructing the event.
Functions
Compute the expected signature for a payload.
@spec construct_event(binary(), String.t(), String.t(), keyword()) :: {:ok, struct() | map()} | {:error, StripeElixir.Error.t()}
Verify a webhook signature and construct a typed event struct.
Parameters
payload- Raw request body (binary string, NOT parsed JSON)sig_header- Value of theStripe-Signatureheadersecret- Webhook endpoint signing secret (whsec_...)
Options
:tolerance- Maximum age of the event in seconds (default: 300)
@spec verify_header(binary(), String.t(), String.t(), keyword()) :: :ok | {:error, StripeElixir.Error.t()}
Verify a webhook signature header without constructing the event.
Returns :ok or {:error, %Error{}}.