npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ng-pay/middleware

v0.1.6

Published

Express, NestJS and Fastify webhook middleware for ng-pay

Readme

@ng-pay/middleware

Express, NestJS, and Fastify webhook middleware for the ng-pay unified Nigerian fintech SDK.

Handles signature verification, raw body parsing, error responses, and event parsing — so you never wire webhooks manually again.

Installation

npm install @ng-pay/core @ng-pay/middleware

Install your provider adapter too:

npm install @ng-pay/paystack   # or flutterwave, monnify

Express

import express from 'express';
import { ngPayWebhook } from '@ng-pay/middleware/express';
import { PaystackProvider } from '@ng-pay/paystack';

const app = express();
const paystack = new PaystackProvider({ secretKey: process.env.PAYSTACK_SECRET_KEY! });

app.post(
  '/webhooks/paystack',
  express.raw({ type: 'application/json' }), // must come before the middleware
  ngPayWebhook({
    provider: paystack,
    onEvent: async (event) => {
      if (event.event === 'charge.success') {
        await fulfillOrder(event.reference!);
      }
    },
  })
);

The middleware automatically:

  • Reads the correct signature header per provider (x-paystack-signature, verif-hash, monnify-signature)
  • Returns 400 if the header is missing
  • Returns 401 if the signature is invalid
  • Sends 200 before calling onEvent (prevents provider retries)

NestJS

// app.module.ts
import { NgPayWebhookModule } from '@ng-pay/middleware/nestjs';
import { PaystackProvider } from '@ng-pay/paystack';

@Module({
  imports: [
    NgPayWebhookModule.register({
      provider: new PaystackProvider({ secretKey: process.env.PAYSTACK_SECRET_KEY! }),
    }),
  ],
})
export class AppModule {}
// webhook.controller.ts
import { Controller, Post, UseGuards } from '@nestjs/common';
import { createNgPayGuard, NgPayWebhookEvent } from '@ng-pay/middleware/nestjs';
import { PaystackProvider } from '@ng-pay/paystack';
import type { WebhookEvent } from '@ng-pay/core';

const paystack = new PaystackProvider({ secretKey: process.env.PAYSTACK_SECRET_KEY! });
const PaystackGuard = createNgPayGuard({ provider: paystack });

@Controller('webhooks')
export class WebhookController {
  @Post('paystack')
  @UseGuards(PaystackGuard)
  async handlePaystack(@NgPayWebhookEvent() event: WebhookEvent) {
    if (event.event === 'charge.success') {
      await this.ordersService.fulfill(event.reference!);
    }
    return { received: true };
  }
}

Enable raw body parsing in main.ts:

const app = await NestFactory.create(AppModule, { rawBody: true });

Fastify

Plugin — registers a dedicated POST route:

import Fastify from 'fastify';
import { ngPayWebhookPlugin } from '@ng-pay/middleware/fastify';
import { PaystackProvider } from '@ng-pay/paystack';

const app = Fastify();
const paystack = new PaystackProvider({ secretKey: process.env.PAYSTACK_SECRET_KEY! });

await app.register(ngPayWebhookPlugin, {
  provider: paystack,
  routePrefix: '/webhooks/paystack',
  onEvent: async (event) => {
    if (event.event === 'charge.success') {
      await fulfillOrder(event.reference!);
    }
  },
});

Hook — use as a preHandler on existing routes:

import { ngPayWebhookHook } from '@ng-pay/middleware/fastify';
import type { WebhookEvent } from '@ng-pay/core';

app.post('/webhooks/paystack', {
  preHandler: ngPayWebhookHook({ provider: paystack }),
}, async (request, reply) => {
  const event = request.ngPayEvent as WebhookEvent;
  reply.send({ received: true });
});

Custom signature header

If your provider uses a non-standard header:

ngPayWebhook({
  provider: paystack,
  signatureHeader: 'x-custom-sig', // overrides the default
  onEvent: async (event) => { ... },
})

Default signature headers

| Provider | Header | |---|---| | Paystack | x-paystack-signature | | Flutterwave | verif-hash | | Monnify | monnify-signature |

Links