SetuClient.Webhook.Handler (Setu Client v1.0.0)

Copy Markdown View Source

Unified webhook dispatcher for all Setu notification events.

Supported event categories

UPI Setu

  • payment.initiated/pending/success/failed
  • mandate.initiated/live/rejected/paused/revoked/updated
  • mandate_operation.create/update/revoke/execute/notify.*
  • refund.pending/successful
  • dispute_created/open/closed/in_review/won/lost

Account Aggregator

  • CONSENT_STATUS_UPDATE
  • SESSION_STATUS_UPDATE

BBPS

  • Auto-detected from payload shape (partnerDetails + events keys)

Plug usage (when plug dep is present)

# In your router
post "/webhooks/setu", SetuClient.Webhook.Handler, callbacks: MyApp.SetuCallbacks

Direct dispatch

body = read_request_body(conn)
SetuClient.Webhook.Handler.dispatch_raw(body, MyApp.SetuCallbacks)

Summary

Functions

Returns true when the consent status in the event is "ACTIVE".

Returns the consent ID from an AA consent notification.

Returns the consent status from an AA consent notification data field.

Dispatches a decoded webhook event map to the appropriate callback.

Parses raw JSON and dispatches. Returns {:error, :decode} on bad JSON.

Returns the event type string from a decoded webhook event map.

Returns true when the event is a successful payment.

Returns true when the session status in the event is "COMPLETED".

Returns the data session ID from an AA session notification.

Returns the session status from an AA session notification data field.

Types

callback_name()

@type callback_name() ::
  :handle_payment
  | :handle_mandate
  | :handle_refund
  | :handle_dispute
  | :handle_consent
  | :handle_session
  | :handle_bbps_settlement
  | :handle_unknown

Functions

dispatch(event, callbacks)

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

Dispatches a decoded webhook event map to the appropriate callback.

{:ok, event} = Jason.decode(raw_body)
SetuClient.Webhook.Handler.dispatch(event, MyApp.SetuCallbacks)

dispatch_raw(body, callbacks)

@spec dispatch_raw(String.t(), module()) :: :ok | {:error, :decode}

Parses raw JSON and dispatches. Returns {:error, :decode} on bad JSON.

event_type(event)

@spec event_type(map()) :: String.t()

Returns the event type string from a decoded webhook event map.

payment_successful?(arg1)

@spec payment_successful?(map()) :: boolean()

Returns true when the event is a successful payment.

session_completed?(arg1)

@spec session_completed?(map()) :: boolean()

Returns true when the session status in the event is "COMPLETED".

session_id(event)

@spec session_id(map()) :: String.t() | nil

Returns the data session ID from an AA session notification.

session_status(event)

@spec session_status(map()) :: String.t() | nil

Returns the session status from an AA session notification data field.