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

cast(event)

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