Nile PayNile Pay

SDK Overview

Server-side TypeScript SDK for Nile Pay payment integration

The Nile Pay SDK is a server-side TypeScript library for integrating payments into your application. It handles the complexity of payment collection, status tracking, and security so you can focus on your business logic.

Key Features

  • Type-safe: Full TypeScript support with complete type definitions
  • Event-driven: Real-time payment status updates via event listeners
  • Automatic retries: Built-in retry logic for failed network requests
  • Security built-in: HMAC-SHA256 signatures, nonce/timestamp replay protection
  • Result pattern: Consistent error handling across all methods

Installation

import { createNilePay } from "@nilepay/sdk";

Quick Start

import { createNilePay } from "@nilepay/sdk";

const nile = createNilePay({
  environment: "sandbox",
  apiKey: "npk_...",
  apiSecret: "nps_...",
});

// Initiate payment
const payment = nile.collectPayment({
  amount: 5000,
  currency: "UGX",
  customer: { phone: "+256700000000" },
  reference: crypto.randomUUID(), // UUID v4 for idempotency
});

// Listen for events
payment.on("success", (tx) => {
  console.log("Payment successful:", tx.transactionId);
});

payment.on("failed", (tx) => {
  console.log("Payment failed:", tx.status);
});

// Or wait for terminal state
const result = await payment.wait();

Available Documentation

On this page