Behaviour for Plaid webhook handlers.
Implement this in your application to receive typed webhook events.
All callbacks are optional — unimplemented ones fall through to
on_unknown/1 which has a default no-op implementation.
Example
defmodule MyApp.PlaidWebhooks do
@behaviour PlaidEx.Webhooks.Handler
@impl true
def on_transactions_sync(%{item_id: item_id}) do
# Triggered by TRANSACTIONS.SYNC_UPDATES_AVAILABLE
# Trigger your sync worker to fetch new data
PlaidEx.Sync.TransactionSync.trigger_sync(
MyApp.Items.get_access_token!(item_id)
)
:ok
end
@impl true
def on_item_error(%{item_id: item_id, error: error}) do
case error["error_code"] do
"ITEM_LOGIN_REQUIRED" ->
MyApp.Users.notify_reconnect_required(item_id)
_ ->
MyApp.Alerts.notify_item_error(item_id, error)
end
:ok
end
@impl true
def on_item_pending_expiration(%{item_id: item_id}) do
# Item will expire in 7 days — notify user to reconnect
MyApp.Users.notify_expiring_connection(item_id)
:ok
end
@impl true
def on_transfer_events_update(_event) do
MyApp.Transfers.sync_events()
:ok
end
# Catch-all for events you haven't handled yet
@impl true
def on_unknown(event) do
require Logger
Logger.debug("[PlaidWebhooks] Unhandled: #{inspect(event)}")
:ok
end
end
Summary
Functions
Injects default no-op implementations for all optional callbacks. Use this when you only want to handle a subset of events.
Types
Callbacks
Functions
Injects default no-op implementations for all optional callbacks. Use this when you only want to handle a subset of events.
defmodule MyApp.PlaidWebhooks do
use PlaidEx.Webhooks.Handler
@impl true
def on_transactions_sync(event) do
# Only this one is custom — all others are no-ops
trigger_my_sync(event.item_id)
:ok
end
end