# `AdyenClient.Webhooks.Handler`
[🔗](https://github.com/iamkanishka/adyen_client/blob/v1.0.0/lib/adyen_client/webhooks/webhooks.ex#L107)

Behaviour for implementing Adyen webhook event handlers.

## Usage

    defmodule MyApp.AdyenWebhookHandler do
      @behaviour AdyenClient.Webhooks.Handler

      @impl true
      def handle_event("AUTHORISATION", %{"success" => "true"} = item) do
        psp = item["pspReference"]
        ref = item["merchantReference"]
        MyApp.Orders.mark_paid(ref, psp)
        :ok
      end

      def handle_event("REFUND", item) do
        MyApp.Refunds.process(item)
        :ok
      end

      def handle_event(event_code, item) do
        Logger.info("Unhandled Adyen event: #{event_code}", item: item)
        :ok
      end
    end

Then configure it:

    config :adyen_client, webhook_handler: MyApp.AdyenWebhookHandler

# `event_code`

```elixir
@type event_code() :: String.t()
```

# `handle_result`

```elixir
@type handle_result() :: :ok | {:error, term()}
```

# `notification_item`

```elixir
@type notification_item() :: map()
```

# `handle_event`

```elixir
@callback handle_event(event_code(), notification_item()) :: handle_result()
```

Handle an incoming webhook event.

Called once per notification item. Return `:ok` to acknowledge,
`{:error, reason}` to signal failure (the Plug will still return [accepted] to Adyen).

# `dispatch`

```elixir
@spec dispatch(map(), module()) :: :ok
```

Process a raw Adyen webhook payload map, dispatching each item to the handler.

Returns `:ok` if all items were handled successfully.

---

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