# `Stripe.Webhook`
[🔗](https://github.com/jeffhuen/tiger_stripe/blob/main/lib/stripe/webhook.ex#L1)

Webhook signature verification and event construction.

## Usage

    case Stripe.Webhook.construct_event(payload, sig_header, secret) do
      {:ok, event} -> handle_event(event)
      {:error, error} -> send_resp(conn, 400, error.message)
    end

# `compute_signature`

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

Compute the expected signature for a payload.

# `construct_event`

```elixir
@spec construct_event(binary(), String.t(), String.t(), keyword()) ::
  {:ok, struct() | map()} | {:error, Stripe.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`

```elixir
@spec verify_header(binary(), String.t(), String.t(), keyword()) ::
  :ok | {:error, Stripe.Error.t()}
```

Verify a webhook signature header without constructing the event.

Returns `:ok` or `{:error, %Error{}}`.

---

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