StripeElixir.Webhook (stripe_elixir v0.1.0)

Copy Markdown View Source

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_signature(timestamp, payload, secret)

@spec compute_signature(integer(), binary(), String.t()) :: String.t()

Compute the expected signature for a payload.

construct_event(payload, sig_header, secret, opts \\ [])

@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 the Stripe-Signature header
  • secret - Webhook endpoint signing secret (whsec_...)

Options

  • :tolerance - Maximum age of the event in seconds (default: 300)

verify_header(payload, sig_header, secret, opts \\ [])

@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{}}.