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
jwtfor the calling user/agent. - Call
POST /api/payment/x402V1Paymentwith the correct body andAuthorizationheader. - On success, attach the returned
xPaymentB64asX-Paymentand retry the original API call. - For withdrawals or revenue splits, call
POST /api/payoutsand track withGET /api/payouts/{payoutId}until terminal.
Mandate-based automatic payment flow:
- Create a mandate via
POST /api/mandates/create-intentand 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/x402V3Paymentwith themandateId— 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-linkswith amount, description, and optionalmaxUses/expiresAt. - Share the returned
urlwith payers. - Track incoming payments with
GET /api/payment-links/{linkId}/payments.
