AshBilling.Plug (ash_billing v0.7.0)

Copy Markdown View Source

A Plug for receiving and verifying incoming webhooks from billing providers.

Handlers must return :ok, {:ok, value}, or {:error, reason}. Unexpected returns and exceptions fail closed. PostgreSQL writes in the configured shared Repo transaction roll back on synchronization or handler failure. Leases are released/marked failed after rollback; HTTP responses are sent after commit. External effects cannot be rolled back and require event/effect idempotency.

Usage in Phoenix Router

forward "/webhooks/stripe", AshBilling.Plug,
  provider: AshBilling.Providers.Stripe,
  webhook_secret: {System, :get_env, ["STRIPE_WEBHOOK_SECRET"]},
  handler: MyApp.Billing.WebhookHandler

Summary

Functions

A Plug.Parsers body reader that preserves the exact signed request bytes in conn.assigns[:raw_body], including bodies delivered in multiple chunks.

Functions

read_body(conn, opts)

A Plug.Parsers body reader that preserves the exact signed request bytes in conn.assigns[:raw_body], including bodies delivered in multiple chunks.

plug Plug.Parsers,
  parsers: [:json],
  json_decoder: Jason,
  body_reader: {AshBilling.Plug, :read_body, []}