Overview
The Navio Node.js SDK provides a modern, type-safe interface for integrating Navio payments into your Node.js and TypeScript applications. Built with TypeScript and async/await for the best developer experience.TypeScript Native
Full TypeScript support with complete type definitions
Promise-based
Native Promise support with async/await
Simple API
Clean, intuitive interface
Error Handling
Custom exceptions for different error types
Requirements
- Node.js 16.0.0 or higher
- npm, yarn, or pnpm
Installation
Install via npm:Quick Start
1. Initialize SDK
2. Create Payment Link
3. Check Payment Status
Complete E-commerce Example
Here’s a complete flow for an e-commerce checkout:Framework Integration
Express.js
NestJS
Next.js (App Router)
API Reference
OCPay Class
Main SDK entry point.Constructor
accessToken(string) - Your API access tokenoptions(ClientOptions) - Optional client configuration:timeout(number) - Request timeout in milliseconds (default: 30000)baseURL(string) - Custom base URL (mainly for testing)headers(object) - Additional headers
Methods
createLink(request: CreateLinkRequest): Promise<CreateLinkResponse>
Creates a payment link.
checkPayment(paymentRef: string): Promise<CheckPaymentResponse>
Checks payment status.
Types & Interfaces
ProductInfo
CreateLinkRequest
CreateLinkResponse
CheckPaymentResponse
Exception Handling
All exceptions extendOCPayException:
All exceptions provide:
Important Notes
Merchant Validation Required
Amount Limits
- Minimum: 500 DZD
- Maximum: 500,000 DZD
- Must be whole numbers (integers)
Fee Structure
Low Fees: 0% on balance, only 1% withdrawal fee
Payment Link Expiration
Links expire 20 minutes after creation if payment not initiated.Payment Status Flow
- PENDING - Payment in progress → Poll again later
- CONFIRMED - Payment successful → Fulfill order
- FAILED - Payment declined/expired → Mark order failed
TypeScript Support
This SDK is written in TypeScript and includes complete type definitions. No need to install@types packages!
JavaScript Usage
The SDK works perfectly with plain JavaScript too:Testing
Using Sandbox
The API automatically uses sandbox mode for test accounts:Best Practices
Always Save Payment Reference
Always Save Payment Reference
Store
paymentRef immediately after creating the link. You need it to check payment status.Poll Payment Status
Poll Payment Status
Set up a background job to check payment status every 20 minutes for pending orders.
Handle All Exceptions
Handle All Exceptions
Catch and handle all exception types appropriately. Log errors for debugging.
Secure Your API Key
Secure Your API Key
Store API keys in environment variables, never commit them to version control.
Use HTTPS Only
Use HTTPS Only
Always use HTTPS for redirect URLs and your application endpoints.
Support & Resources
GitHub Repository
Source code, examples, and issues
API Documentation
Detailed API reference
npm Package
View on npm registry
Contact Support
Get help from our team
Next Steps
Navio Best Practices
Learn production-ready tips and security best practices

