T402 API Reference - v2.8.0
    Preparing search index...

    Function paymentMiddleware

    • Fastify payment middleware for t402 protocol (direct server instance).

      Use this when you want to pass a pre-configured t402ResourceServer instance. This provides more flexibility for testing, custom configuration, and reusing server instances across multiple middlewares.

      Parameters

      • routes: RoutesConfig

        Route configurations for protected endpoints

      • server: t402ResourceServer

        Pre-configured t402ResourceServer instance

      • OptionalpaywallConfig: PaywallConfig

        Optional configuration for the built-in paywall UI

      • Optionalpaywall: PaywallProvider

        Optional custom paywall provider (overrides default)

      • syncFacilitatorOnStart: boolean = true

        Whether to sync with the facilitator on startup (defaults to true)

      Returns preHandlerHookHandler

      Fastify preHandler hook

      import { paymentMiddleware } from "@t402/fastify";
      import { t402ResourceServer } from "@t402/core/server";
      import { registerExactEvmScheme } from "@t402/evm/exact/server";

      const server = new t402ResourceServer(myFacilitatorClient);
      registerExactEvmScheme(server, {});

      app.addHook('preHandler', paymentMiddleware(routes, server, paywallConfig));