Node.js SDK

The official NahuPay Node.js library supports Node 18+, Edge Runtime, and Deno. It's written in TypeScript and ships full type definitions.

Installation

npm install nahupay
# yarn
yarn add nahupay
# pnpm
pnpm add nahupay

Initialisation

import NahuPay from 'nahupay';const client = new NahuPay({apiKey: process.env.NAHUPAY_SECRET_KEY,// Optional: defaults showntimeout:    30_000,   // msmaxRetries: 2,});

Payments

Create

const payment = await client.payments.create({amount:      150000,currency:   'ETB',methods:    ['telebirr', 'mpesa', 'bank_transfer'],success_url: 'https://myshop.com/success',cancel_url:  'https://myshop.com/cart',});console.log(payment.checkout_url);

Retrieve

const payment = await client.payments.retrieve('pay_01hx9m2k');console.log(payment.status);   // "completed"

List

const list = await client.payments.list({limit:  20,status: 'completed',});for await (const payment of client.payments.list.autoPaginate()) {console.log(payment.id);  // auto-follows cursors}

Webhooks

import { NahuPayError } from 'nahupay';

export async function POST(req: Request) {
  const body = await req.text();
  const sig  = req.headers.get('NahuPay-Signature')!;
  let event;
  try {
    event = client.webhooks.constructEvent(body, sig,
      process.env.NAHUPAY_WEBHOOK_SECRET);
  } catch (err) {
    return Response.json({ error: 'bad signature' }, { status: 400 });
  }
  if (event.type === 'payment.completed') {
    await fulfillOrder(event.data.object);
  }
  return Response.json({ received: true });
}

TypeScript

The SDK ships complete TypeScript definitions. All request params and response objects are typed:

import type { Payment, WebhookEvent } from 'nahupay';

function handleCompleted(payment: Payment) {
  // payment.id, payment.status — fully typed
}

Full reference

All available methods mirror the REST API 1:1. See the Payments reference, Webhooks reference, and Errors reference for the complete parameter and response docs.