@pingpay/agentpay-middleware
v0.2.0
Published
Thin Express middleware for Ping Agent Pay (x402 + MPP)
Readme
@pingpay/agentpay-middleware
Thin Express middleware for Ping Agent Pay — gate HTTP routes with x402 or call Ping’s hosted MPP charge endpoint. Settlement is handled by Ping’s facilitator (NEAR Intents / 1Click).
Install
Workspace package in this monorepo:
import { agentPayX402 } from '@pingpay/agentpay-middleware';x402
Point standard x402 middleware at Ping’s facilitator and pass your Ping API key:
import express from 'express';
import { agentPayX402 } from '@pingpay/agentpay-middleware';
const app = express();
app.use(
agentPayX402({
apiKey: process.env.PING_API_KEY!,
facilitatorUrl: 'https://<your-ping-host>/agentpay/x402',
routes: {
'GET /api/resource': {
amountOut: '150000', // destination amount in base units
description: 'Paid API resource',
},
},
}),
);
// The first response is an unquoted 402: one `exact` / `near-intents` entry per
// 1Click origin, with empty `payTo` and `amount`. The client then sends a
// `quote` payment payload whose `refundTo` is an address on that origin chain.
// Ping answers with a second 402 (`payTo`, `amount`, `operationToken`). The
// client deposits and retries with a `deposit` payload (`txHash`).
app.get('/api/resource', (_req, res) => {
res.json({ ok: true });
});MPP
Use buildPingMppChargeUrl / createPingMppChargeClient from @pingpay/agentpay-middleware/mpp to hit Ping’s merchant-scoped charge route (/agentpay/mpp/charge).
Docs
See specs/003-agent-pay.md for architecture, settlement semantics, and acceptance tests (api/tests/agentpay-harness/).
