Rapyd.Types.WebhookEvent (rapyd v1.0.0)

Copy Markdown View Source

A decoded and verified Rapyd webhook event.

After calling Rapyd.Services.Webhook.parse_and_verify/3, you receive one of these structs. Pattern-match on :type to branch on event kind, then cast :data to the specific payload struct using the helpers below.

Example

defmodule MyApp.WebhookHandler do
  alias Rapyd.Types.WebhookEvent

  def handle(%WebhookEvent{type: "PAYMENT_SUCCEEDED"} = event) do
    MyApp.Payments.mark_paid(event.data["id"])
  end

  def handle(%WebhookEvent{type: "PAYOUT_COMPLETED"} = event) do
    Logger.info("payout delivered", id: event.data["id"])
  end

  def handle(%WebhookEvent{}), do: :ok
end

Summary

Functions

Returns all known card issuing event type strings.

Returns all known contact event type strings.

Route the event to the matching handler from a map-based dispatch table.

Returns all known dispute event type strings.

Build a WebhookEvent from a decoded JSON map (the outer Rapyd envelope).

Returns all known invoice event type strings.

Returns all known payment event type strings.

Returns all known payout event type strings.

Returns all known refund event type strings.

Returns all known transfer event type strings.

Returns all known virtual account event type strings.

Returns all known wallet event type strings.

Types

t()

@type t() :: %Rapyd.Types.WebhookEvent{
  created_at: integer(),
  data: map(),
  id: String.t(),
  status: String.t(),
  trigger_operation_id: String.t() | nil,
  type: String.t()
}

Functions

card_event_types()

Returns all known card issuing event type strings.

contact_event_types()

Returns all known contact event type strings.

dispatch(event, handlers)

@spec dispatch(t(), %{
  optional(String.t()) => (t() -> any()),
  optional(:default) => (t() -> any())
}) ::
  any()

Route the event to the matching handler from a map-based dispatch table.

The table maps event type strings (or the atom :default) to 1-arity functions. If no matching key is found the :default handler is called, or :unhandled is returned when no default is provided.

Example

WebhookEvent.dispatch(event, %{
  "PAYMENT_SUCCEEDED" => &handle_payment_ok/1,
  "PAYMENT_FAILED"    => &handle_payment_fail/1,
  default:              &log_unknown/1
})

dispute_event_types()

Returns all known dispute event type strings.

from_map(map)

@spec from_map(map()) :: t()

Build a WebhookEvent from a decoded JSON map (the outer Rapyd envelope).

invoice_event_types()

Returns all known invoice event type strings.

payment_event_types()

Returns all known payment event type strings.

payout_event_types()

Returns all known payout event type strings.

refund_event_types()

Returns all known refund event type strings.

transfer_event_types()

Returns all known transfer event type strings.

virtual_account_event_types()

Returns all known virtual account event type strings.

wallet_event_types()

Returns all known wallet event type strings.