Skip to content

Putting it all together ​

Pay for an x402 resource with a mandate (no per-payment approval):

  1. Register once; store agent_id, token, jwt. Refresh the jwt with /refresh when it expires.
  2. Create a mandate and have the user open authorizationUrl to link the agent and sign. Poll Get mandate by ID until status is signed.
  3. Call the third-party API. On HTTP 402, take the fields from accepts[0].
  4. Call GET /api/mandates/eligible with host, amount, currency to pick a mandateId.
  5. Call POST /api/payment/x402V3Payment (or POST /api/v2/payment/x402-payment for x402 v2 requirements).
  6. Send the returned xPaymentB64 as X-Payment and retry the original request.

Without a mandate, use POST /api/payment/x402V1Payment; if it returns need_approval, show approvalUrl and retry with approvalId.

Send funds out:

Receive funds:

Released under the MIT License.