Nile PayNile Pay

Configuration

Initialize the Nile Pay SDK with your credentials

createNilePay()

The factory function createNilePay() returns a configured SDK instance.

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

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

Configuration Options

OptionTypeDefaultDescription
environment"sandbox" | "live"requiredTarget environment
apiKeystringrequiredYour Nile Pay API key (npk_...)
apiSecretstringrequiredYour Nile Pay API secret (nps_...)
baseUrlstringautoAPI base URL (set automatically by environment)
timeoutMsnumber30000Per-request timeout in milliseconds
maxRetriesnumber3Maximum retry attempts for failed requests
maxPollDurationnumber300000Maximum wait time for wait() in milliseconds (5 min)
maxPollAttemptsnumber150Maximum poll attempts for wait()
fetchtypeof fetchglobalThis.fetchCustom fetch implementation

Environment Setup

Sandbox

Use sandbox credentials for development and testing.

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

Production

Use live credentials for production transactions.

const nile = createNilePay({
  environment: "live",
  apiKey: "npk_live_...",
  apiSecret: "nps_live_...",
});

Custom Fetch

For testing scenarios, you can provide a custom fetch implementation.

import { createNilePay } from "@nilepay/sdk";
import { setupServer } from "msw/node";
import { handlers } from "./mocks/handlers";

const server = setupServer(...handlers);

const nile = createNilePay({
  environment: "sandbox",
  apiKey: "npk_test_...",
  apiSecret: "nps_test_...",
  fetch: server.fetch.bind(server),
});

Environment Auto-Detection

If you omit baseUrl, it is set automatically:

  • Sandbox: https://api-sandbox.nilepay.com
  • Live: https://api.nilepay.com

Timeout and Polling

For high-traffic scenarios, you may want to adjust polling behavior:

const nile = createNilePay({
  environment: "sandbox",
  apiKey: "npk_...",
  apiSecret: "nps_...",
  maxPollDuration: 600000, // 10 minutes
  maxPollAttempts: 300,
  timeoutMs: 60000, // 1 minute per request
});

On this page