SDK

Node.js SDK

Fast and lightweight SDK for integrating STK Push and payment verification in Node apps.

Installation

bash
npm install @paynexus/node-sdk

Quick Start

javascript
const axios = require('axios');

class PayNexusClient {
    constructor(apiKey, baseUrl = 'https://paynexus.co.ke/api') {
        this.client = axios.create({
            baseURL: baseUrl,
            headers: {
                'X-API-Key': apiKey,
                'Content-Type': 'application/json',
            },
            timeout: 30000,
        });
    }
    
    async initiatePayment(amount, phone, description = null) {
        const response = await this.client.post('/mpesa/payment/initiate', {
            amount,
            phone,
            description,
        });
        return response.data;
    }
    
    async getPaymentStatus(reference) {
        const response = await this.client.get(`/payments/${reference}`);
        return response.data;
    }
}

// Usage
const client = new PayNexusClient('sk_your_secret_key_here');
const payment = await client.initiatePayment(100, '0746990866', 'Order #12345');