Skip to content

Express

Getting started

Express

Post-settlement only. Fiscal402 does not issue HTTP 402, authorize payment, or settle funds.

Fiscal402 Express integration is post-settlement. It does not create the 402 response, authorize the payment, or settle funds.

  1. Request hits a paid resource.
  2. Your x402 middleware issues HTTP 402 and the client settles.
  3. The merchant handler runs after settlement succeeds.
  4. Fiscal402 records the fiscal event from PAYMENT-RESPONSE evidence.

Lifecycle

StepOwner
HTTP 402 + requirementsYour x402 stack
On-chain / facilitator settleYour x402 stack
PAYMENT-RESPONSE headerYour x402 stack
POST /settlementsFiscal402
EU VAT + UBL + receiptFiscal402

Middleware

@fiscal402/express is source-only. It is not on npm. Copy it from the Fiscal402 repository, or POST /settlements yourself after the handler.

app.ts

import express from "express";
import { fiscal402Middleware } from "@fiscal402/express"; // source only — not on npm

const app = express();
app.use(express.json());

// Your x402 middleware settles first. Fiscal402 runs AFTER res.end.
app.use(
  fiscal402Middleware({
    apiKey: process.env.FISCAL402_API_KEY!,
    endpoint: "https://api.fiscal402.com",
  }),
);

app.get("/inference", (req, res) => {
  // Paid resource handler. Do not put the Fiscal402 key in the browser.
  res.json({ ok: true });
});

PAYMENT-RESPONSE mapping

If you copy the source Node client, you can pass the settled object instead of assembling fields by hand.

recordSettlement.ts

import { Fiscal402 } from "@fiscal402/node"; // source only — not on npm

const fiscal = new Fiscal402({
  apiKey: process.env.FISCAL402_API_KEY!,
  origin: process.env.FISCAL402_ORIGIN ?? "https://api.fiscal402.com",
});

const result = await fiscal.recordSettlement({
  paymentResponse, // settled x402 PAYMENT-RESPONSE object
  timestamp: "2026-09-10T12:00:00.000Z",
  buyer: { country: "DE", legalName: "Buyer GmbH" },
  supply: { kind: "digital", description: "Inference units" },
});

const receipt = await fiscal.getReceipt(result.id);
const jwks = await fiscal.fetchJwks();
const report = await fiscal.verifyReceipt({ receipt, jwks });