livery_stripe_webhook_handler behaviour (livery_stripe v0.1.0)

View Source

A mountable livery handler for the Stripe webhook endpoint.

Add it to a router with routes/0,1:

livery_router:compile(livery_stripe_webhook_handler:routes()).

handle/1 reads the raw body and Stripe-Signature header, verifies the event with livery_stripe_webhook, and dispatches it to the configured callback (the webhook_callback config key). It always answers JSON: 200 when accepted, 400 on a bad payload or signature.

The callback may be a fun/1 (Event), a fun/2 (Type, Event), a module implementing handle_event/2, or a {Module, Function} pair. Persistence (updating a user's subscription, etc.) belongs in the callback; this module stays storage-agnostic.

Summary

Functions

livery route handler. Reads secret and callback from app config.

Like handle/1 but with explicit #{secret, callback} opts.

Routes for the default path /stripe/webhook.

Callbacks

handle_event(Type, Event)

-callback handle_event(Type :: binary(), Event :: map()) -> ok | {error, term()}.

Functions

handle(Req)

-spec handle(livery_req:req()) -> livery_resp:resp().

livery route handler. Reads secret and callback from app config.

handle(Req, Opts)

-spec handle(livery_req:req(), map()) -> livery_resp:resp().

Like handle/1 but with explicit #{secret, callback} opts.

routes()

-spec routes() -> [tuple()].

Routes for the default path /stripe/webhook.

routes(Path)

-spec routes(binary()) -> [tuple()].