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
| Option | Type | Default | Description |
|---|---|---|---|
environment | "sandbox" | "live" | required | Target environment |
apiKey | string | required | Your Nile Pay API key (npk_...) |
apiSecret | string | required | Your Nile Pay API secret (nps_...) |
baseUrl | string | auto | API base URL (set automatically by environment) |
timeoutMs | number | 30000 | Per-request timeout in milliseconds |
maxRetries | number | 3 | Maximum retry attempts for failed requests |
maxPollDuration | number | 300000 | Maximum wait time for wait() in milliseconds (5 min) |
maxPollAttempts | number | 150 | Maximum poll attempts for wait() |
fetch | typeof fetch | globalThis.fetch | Custom 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
});