Accrue.Webhook.Event (accrue v0.3.0)

Copy Markdown View Source

Lean event struct passed to webhook handlers (D2-29).

Deliberately does NOT include the raw Stripe object -- handlers call Accrue.Processor.retrieve_*(event.object_id) for canonical state. This forces WH-10 compliance (re-fetch current state) by shape.

The type field is kept as a String.t() in the struct. Conversion to atom for pattern-matching dispatch happens at the handler call site in Plan 04, using String.to_existing_atom/1 with a bounded allow-list.

Summary

Functions

Projects a %LatticeStripe.Event{} struct into an %Accrue.Webhook.Event{}.

Projects a persisted %Accrue.Webhook.WebhookEvent{} DB row into an %Accrue.Webhook.Event{}.

Types

t()

@type t() :: %Accrue.Webhook.Event{
  created_at: DateTime.t() | nil,
  livemode: boolean(),
  object_id: String.t() | nil,
  processor: atom(),
  processor_event_id: String.t(),
  type: String.t()
}

Functions

from_stripe(stripe_event, processor)

@spec from_stripe(LatticeStripe.Event.t(), atom()) :: t()

Projects a %LatticeStripe.Event{} struct into an %Accrue.Webhook.Event{}.

Extracts the object ID from data["object"]["id"] (string keys, as returned by LatticeStripe.Event.from_map/1).

from_webhook_event(row)

@spec from_webhook_event(Accrue.Webhook.WebhookEvent.t()) :: t()

Projects a persisted %Accrue.Webhook.WebhookEvent{} DB row into an %Accrue.Webhook.Event{}.

Used by Accrue.Webhook.DispatchWorker to build the lean event struct from the stored row (different from from_stripe/2 which projects from a live LatticeStripe.Event).