Create an Invoice
Open an agent checkout with multi-chain x402 payment rails
Open an agent checkout with multi-chain x402 payment rails
Creating a Gwop invoice opens an agent checkout — a headless payment session with x402 rails for every supported chain. You define the amount and what you are selling. Gwop ties the payment URLs to the session and returns everything the agent needs to discover and pay the checkout.
The agent fetches the public invoice, picks a chain, and pays the session-scoped x402 URL — the same way it would pay any other x402 endpoint.
The idempotencyKey is sent as a header. Always use crypto.randomUUID() for new invoices.
Every invoice has two identifiers:
Your backend stores id for cancel and internal lookups. You hand publicInvoiceId to the agent.
amountUsdc in the create response is the source of truth for what the payer owes. If Gwop applies fees or other pricing adjustments, the returned amountUsdc can be higher than the base amount you sent. The response metadata may also include the pricing breakdown:
Build your pricing around the base amount you send, but display or enforce the total using the response fields Gwop returns.
The agentProtocol field is the machine-readable checkout instruction set you hand to the agent. It tells the agent how to discover payment methods and complete the purchase — hand it through as-is.
The protocol points the agent to the public invoice via nextAction. The agent follows that path and discovers the actual x402 payment URLs.
When the agent GETs the public invoice, it sees the full checkout session with one x402 payment method per chain:
The agent picks a chain and pays the paymentUrl — the same way it would pay any x402 endpoint. The URL is scoped to this checkout session, not a permanent merchant endpoint. After payment settles, completionCheck confirms status === "PAID" and your backend receives a webhook.
Passing the same idempotencyKey returns the original response without creating a duplicate invoice. This makes retries safe:
Always generate the idempotency key before the try/catch block so retries use the same key.
Invoices expire after 15 minutes by default. Set expiresInSeconds to customize:
By default, metadata is only visible to the merchant. Set metadataPublic: true to make it visible to the payer through the public invoice endpoint:
This is useful when the agent needs context about what it’s paying for.