Installation and Setup
This guide will help you install and set up the CashOnRails library for your Node.js application.
Installation
Using npm
npm install cashonrails-node
Basic Setup
First, import the library into your project:
// Using ES modules
import { CashOnRailsClient } from 'cashonrails-node';
// Using CommonJS
const { CashOnRailsClient } = require('cashonrails-node');
Initialize the Client
Create a new instance of the CashOnRails client with your API credentials:
const client = new CashOnRailsClient('your_api_key', 'your_public_key', {
environment: 'TEST', // Use 'LIVE' for production
});
Required Parameters
Parameter | Type | Description |
---|---|---|
apiKey | string | Your CashOnRails API key from the dashboard |
publicKey | string | Your CashOnRails public key from the dashboard |
Optional Configuration
Option | Type | Default | Description |
---|---|---|---|
environment | string | 'TEST' | API environment (‘TEST’ or ‘LIVE’) |
timeout | number | 30000 | Request timeout in milliseconds |
baseUrl | string | undefined | Custom API base URL (if needed) |
Environment Configuration
Test Environment
The test environment allows you to experiment with the API without processing real transactions:
const testClient = new CashOnRailsClient('test_api_key', 'test_public_key', {
environment: 'TEST'
});
Live Environment
For production use with real transactions:
const liveClient = new CashOnRailsClient('live_api_key', 'live_public_key', {
environment: 'LIVE'
});
Verifying Setup
To verify that your client is set up correctly, you can check your wallet balance:
try {
const balance = await client.transfer.getWalletBalance('NGN');
console.log('Connection successful! Wallet balance:', balance.data.balance);
} catch (error) {
console.error('Setup failed:', error.message);
}
Next Steps
Now that you’ve successfully installed and configured the CashOnRails library, you can:
- Process payments using the Payment Services
- Set up bank transfers with the Transfers module
- Create dedicated accounts using Reserved Accounts
- Manage your customers with Customer Management
For complete API reference, check out the API Reference documentation.