paygate
v5.0.0
Published
Accept payment from AI agents in two lines of code. Gate any Express or Fastify route with an x402 paywall backed by ArisPay — merchants don't hold keys, agents pay per-request, USDC settles in seconds on Base mainnet.
Maintainers
Readme
paygate
Create agent-payable offers with HTTP 402 and USDC settlement. PayGate handles the x402 challenge, calls the ArisPay facilitator, and lets your handler run only after payment settles.
API endpoint offers are live today. Use the hosted proxy for zero-code acceptance, or install this package when you want the 402 flow on your own domain.
Install
npm install paygateExpress
import express from 'express';
import { paygate } from 'paygate/express';
const app = express();
const pw = paygate({
merchantId: process.env.PAYGATE_MERCHANT_ID,
});
// $0.10 per request
app.get('/api/data', pw({ priceCents: 10 }), (req, res) => {
res.json({ data: 'premium content' });
});
// Dynamic pricing
app.post('/api/analyze', pw({
priceCents: (req) => req.body.depth === 'deep' ? 50 : 10,
description: 'AI analysis',
}), (req, res) => {
res.json({ result: '...' });
});
app.listen(3000);Fastify
import Fastify from 'fastify';
import paygate from 'paygate/fastify';
const app = Fastify();
await app.register(paygate, {
merchantId: process.env.PAYGATE_MERCHANT_ID,
});
// Route-config-driven paywall
app.get('/api/data', {
config: { paygate: { priceCents: 10 } },
}, async (req, reply) => {
reply.send({ data: 'premium content' });
});
// Or imperative API
app.get('/api/research', async (req, reply) => {
const { paid } = await req.paygatePay({
priceCents: 5,
description: 'Research query',
});
if (!paid) return; // 402 challenge already sent
reply.send({ results: '...' });
});
await app.listen({ port: 3000 });Hosted proxy
For a no-code merchant integration:
- Register at
https://paygate.arispay.app/merchant-register. - Add a primary USDC payout wallet in the PayGate dashboard.
- Create an API endpoint offer with
method,path,targetUrl, andpriceCents. - Agents call
https://paygate.arispay.app/{slug}{path}.
Example agent test:
npx payagent pay https://paygate.arispay.app/acme/forecast?city=LondonAPI equivalent for offer creation:
curl -X POST https://api.arispay.app/v1/merchants/me/products \
-H 'authorization: Bearer mp_live_…' \
-H 'content-type: application/json' \
-d '{
"method": "GET",
"path": "/forecast",
"targetUrl": "https://api.acme.com/v1/forecast",
"priceCents": 2,
"description": "Weather forecast"
}'How it works
Agent Your API / Proxy ArisPay Facilitator
│ │ │
├─── GET /api/data ──────►│ │
│ │ no X-Payment header │
│◄── 402 + requirements ──┤ │
│ │ │
│ agent signs USDC transfer authorization │
│ │ │
├─── GET /api/data ──────►│ │
│ + X-Payment header ├── POST /settle ────────►│
│ │ │ verify + settle
│ │◄── { success, txHash } ─┤
│◄── 200 + data ──────────┤ │The agent-side payagent CLI and SDK handle the 402 loop automatically.
Config
| Option | Required | Default | Description |
|---|---|---|---|
| merchantId | Yes | — | PayGate merchant ID from the dashboard. The SDK fetches payout rail, wallet, asset, facilitator, and trust policy from ArisPay. |
| apiUrl | No | https://api.arispay.app | Override ArisPay API URL for staging/self-hosting. |
| facilitatorUrl | No | Manifest value | Compatibility override. In v3, merchant capabilities are authoritative. |
| timeout | No | 30000 | ArisPay/facilitator call timeout in ms. |
| cacheTtlMs | No | 300000 | Merchant capability cache TTL. |
Compatibility mode
Older code that passes wallet and network still works through a v2 shim, but new integrations should use merchantId and configure payout wallets in the dashboard. The shim will be removed in a future major version.
Networks
PayGate currently settles USDC on EVM networks advertised by your merchant capability manifest. Base mainnet (eip155:8453) is the recommended production network.
License
MIT
