AdyenClient.Webhooks.Plug (AdyenClient v1.0.0)

Copy Markdown View Source

A Plug that handles Adyen webhook HTTP requests end-to-end.

Reads the raw body, validates the HMAC signature, dispatches events to your handler module, and responds with [accepted] as Adyen requires.

Usage in Phoenix router

# In your endpoint.ex, add raw body passthrough BEFORE Plug.Parsers:
plug Plug.Parsers,
  parsers: [:urlencoded, :multipart, :json],
  pass: ["*/*"],
  body_reader: {AdyenClient.Webhooks.Plug, :read_body, []},
  json_decoder: Jason

# In your router.ex:
forward "/webhooks/adyen", AdyenClient.Webhooks.Plug,
  handler: MyApp.AdyenWebhookHandler,
  hmac_key: System.get_env("ADYEN_HMAC_KEY")

Options

  • :handler — module implementing AdyenClient.Webhooks.Handler (required)
  • :hmac_key — HMAC key string (optional; falls back to config)
  • :validate_hmac — boolean, default true; set to false in dev only

Summary

Functions

Passthrough body reader — stores raw body in conn private for later HMAC use.

Functions

read_body(conn, opts)

Passthrough body reader — stores raw body in conn private for later HMAC use.