Non-disableable default handler for built-in state reconciliation.
Runs first in the dispatch chain before any user-registered handlers. Cannot be removed or reordered by configuration.
Behaviour
Reconciles Stripe webhook families covering subscription, invoice, charge, refund, and payment method state. Each reducer:
- Derives
evt_tsfrom the raw eventcreatedunix timestamp. - Loads the local row by processor id.
- Skip stale: if
row.last_stripe_event_ts != nilandevt_tsis strictly less than it, emit[:accrue, :webhooks, :stale_event]telemetry and return{:ok, :stale}without calling the processor. Timestamp ties (:eq) still proceed. - Refetch canonical: always call
Accrue.Processor.fetch/2to pull the current object — never trust the payload snapshot alone. - Project via the appropriate
*Projection.decompose/1(or schema-specific upsert) and write via the webhook-path changeset (Invoice.force_status_changeset/2where a legal transition bypass is required). - Stamp
last_stripe_event_ts/last_stripe_event_idon the row so the next out-of-order event can skip. - Record an
accrue_eventsrow in the sameRepo.transact/1.
Entry points
handle/1— accepts the raw event map (both string- and atom-keyed shapes). Used byAccrue.Processor.Fake.synthesize_event/3for in-process test dispatch.handle_event/3— theAccrue.Webhook.Handlerbehaviour entry point invoked byAccrue.Webhook.DispatchWorker. Dispatches via the existing%Accrue.Webhook.Event{}struct (object_id + created_at + type) to the shared reducer.
Summary
Functions
Reduces a raw event map (atom- or string-keyed) through the built-in
reducer chain. Returns {:ok, row} on success, {:ok, :stale} if
the event is older than row.last_stripe_event_ts, or {:ok, :ignored}
if the type has no dedicated reducer.
Callback implementation for Accrue.Webhook.Handler.handle_event/3.
Functions
Reduces a raw event map (atom- or string-keyed) through the built-in
reducer chain. Returns {:ok, row} on success, {:ok, :stale} if
the event is older than row.last_stripe_event_ts, or {:ok, :ignored}
if the type has no dedicated reducer.
Callback implementation for Accrue.Webhook.Handler.handle_event/3.