# `Rapyd.Types.WebhookEvent`
[🔗](https://github.com/iamkanishka/rapyd/blob/v1.0.0/lib/rapyd/types/webhook_event.ex#L1)

A decoded and verified Rapyd webhook event.

After calling `Rapyd.Services.Webhook.parse_and_verify/3`, you receive
one of these structs. Pattern-match on `:type` to branch on event kind,
then cast `:data` to the specific payload struct using the helpers below.

## Example

    defmodule MyApp.WebhookHandler do
      alias Rapyd.Types.WebhookEvent

      def handle(%WebhookEvent{type: "PAYMENT_SUCCEEDED"} = event) do
        MyApp.Payments.mark_paid(event.data["id"])
      end

      def handle(%WebhookEvent{type: "PAYOUT_COMPLETED"} = event) do
        Logger.info("payout delivered", id: event.data["id"])
      end

      def handle(%WebhookEvent{}), do: :ok
    end

# `t`

```elixir
@type t() :: %Rapyd.Types.WebhookEvent{
  created_at: integer(),
  data: map(),
  id: String.t(),
  status: String.t(),
  trigger_operation_id: String.t() | nil,
  type: String.t()
}
```

# `card_event_types`

Returns all known card issuing event type strings.

# `contact_event_types`

Returns all known contact event type strings.

# `dispatch`

```elixir
@spec dispatch(t(), %{
  optional(String.t()) =&gt; (t() -&gt; any()),
  optional(:default) =&gt; (t() -&gt; any())
}) ::
  any()
```

Route the event to the matching handler from a map-based dispatch table.

The table maps event type strings (or the atom `:default`) to 1-arity
functions. If no matching key is found the `:default` handler is called,
or `:unhandled` is returned when no default is provided.

## Example

    WebhookEvent.dispatch(event, %{
      "PAYMENT_SUCCEEDED" => &handle_payment_ok/1,
      "PAYMENT_FAILED"    => &handle_payment_fail/1,
      default:              &log_unknown/1
    })

# `dispute_event_types`

Returns all known dispute event type strings.

# `from_map`

```elixir
@spec from_map(map()) :: t()
```

Build a `WebhookEvent` from a decoded JSON map (the outer Rapyd envelope).

# `invoice_event_types`

Returns all known invoice event type strings.

# `payment_event_types`

Returns all known payment event type strings.

# `payout_event_types`

Returns all known payout event type strings.

# `refund_event_types`

Returns all known refund event type strings.

# `transfer_event_types`

Returns all known transfer event type strings.

# `virtual_account_event_types`

Returns all known virtual account event type strings.

# `wallet_event_types`

Returns all known wallet event type strings.

---

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