Plug middleware that gates configured routes behind x402 payment verification.
For matching routes, requests without an x-payment header receive a 402
response with x402 payment requirements. Requests with x-payment are
decoded, verified, and settled with the configured facilitator before the
request is allowed to continue through the plug pipeline.
Summary
Functions
Gates matching requests behind x402 payment verification.
Validates and compiles X402.Plug.PaymentGate options.
Types
@type options() :: %{ facilitator: X402.Facilitator.server(), hooks: module(), payment_identifier_cache: X402.Extensions.PaymentIdentifier.ETSCache.server() | nil, routes: [compiled_route()] }
Configuration map produced by init/1.
Functions
@spec call(Plug.Conn.t(), options()) :: Plug.Conn.t()
Gates matching requests behind x402 payment verification.
Validates and compiles X402.Plug.PaymentGate options.
Options
:facilitator(term/0) - Facilitator server pid/name used for verification and settlement. The default value isX402.Facilitator.:hooks- Lifecycle hook module implementingX402.Hooks. The default value isX402.Hooks.Default.:payment_identifier_cache- OptionalETSCacheserver pid/name used for idempotency. When set, the plug performs an atomic claim (viaput_new) on the payment proof hash before settling, preventing concurrent requests from double-settling the same payment. The default value isnil.:routes(list ofmap/0) - Required. Route gate definitions.