AdyenClient.Webhooks.Handler behaviour (AdyenClient v1.0.0)

Copy Markdown View Source

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

Summary

Callbacks

Handle an incoming webhook event.

Functions

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

Types

event_code()

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

handle_result()

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

notification_item()

@type notification_item() :: map()

Callbacks

handle_event(event_code, notification_item)

@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).

Functions

dispatch(payload, handler_module)

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