Stancer. Webhook. Event
(stancer v0.1.0)
Copy Markdown
Webhook event type definitions and helpers.
Provides strongly-typed event structures for each Stancer webhook type, making it easier to pattern match and handle different events safely.
Summary
Functions
Build a typed event from raw webhook data.
Functions
@spec cast(event :: map()) :: {:ok, Stancer.Webhook.Event.Payment.t() | Stancer.Webhook.Event.Customer.t() | Stancer.Webhook.Event.Card.t() | Stancer.Webhook.Event.Dispute.t() | Stancer.Webhook.Event.Payout.t() | Stancer.Webhook.Event.Subscription.t()} | {:error, :unknown_type}
Build a typed event from raw webhook data.
Takes a parsed webhook map and converts it to the appropriate typed struct based on the event type.
Example
{:ok, event} = Stancer.Webhook.parse(body)
case Stancer.Webhook.Event.cast(event) do
{:ok, %Payment{} = payment} -> handle_payment(payment)
{:ok, %Customer{} = customer} -> handle_customer(customer)
{:error, :unknown_type} -> Logger.warning("Unknown event type")
end