Skip to content

Putting it all together

Typical end‑to‑end flow:

  • Call a third‑party API. If it responds with HTTP 402 / X‑402 metadata, extract amount, host, resource URL, etc.
  • Look up the jwt for the calling user/agent.
  • Call POST /api/payment/x402V1Payment with the correct body and Authorization header.
  • On success, attach the returned xPaymentB64 as X-Payment and retry the original API call.
  • For withdrawals or revenue splits, call POST /api/payouts and track with GET /api/payouts/{payoutId} until terminal.

Mandate-based automatic payment flow:

  • Create a mandate via POST /api/mandates/create-intent and have the user sign it.
  • When a 402 arrives, call GET /api/mandates/eligible?host=...&amount=... to find a matching mandate.
  • If found, call POST /api/payment/x402V3Payment with the mandateId — no per-transaction approval needed.
  • If no mandate matches, fall back to the V1 flow above or create a new mandate.

Payment link flow:

  • Create a link via POST /api/payment-links with amount, description, and optional maxUses/expiresAt.
  • Share the returned url with payers.
  • Track incoming payments with GET /api/payment-links/{linkId}/payments.

Released under the MIT License.