Installation and Setup
Install the Node.js package in a backend service only:
npm install cashonrails-nodeEnvironment Variables
CASHONRAILS_ENV=TEST
CASHONRAILS_BASE_URL=https://api.cashonrails.com
CASHONRAILS_SECRET_KEY=sk_test_or_live_value
CASHONRAILS_PUBLIC_KEY=pk_test_or_live_value
CASHONRAILS_WEBHOOK_KEY=your_webhook_key
CASHONRAILS_RSA_PRIVATE_KEY_PATH=/secure/path/private.pemFor staging, set CASHONRAILS_BASE_URL=https://mainapi.stag.cashonrails.com.
Basic Setup
import { CashOnRailsClient } from "cashonrails-node";
const client = new CashOnRailsClient(process.env.CASHONRAILS_SECRET_KEY, {
environment: process.env.CASHONRAILS_ENV || "TEST",
baseUrl: process.env.CASHONRAILS_BASE_URL || "https://api.cashonrails.com",
timeout: 30000,
});Older SDK versions may use this constructor shape:
const client = new CashOnRailsClient(
process.env.CASHONRAILS_SECRET_KEY,
process.env.CASHONRAILS_PUBLIC_KEY,
{
environment: process.env.CASHONRAILS_ENV || "TEST",
baseUrl: process.env.CASHONRAILS_BASE_URL || "https://api.cashonrails.com",
},
);Smoke Test
Use a low-risk read endpoint to confirm credentials and product access:
try {
const balance = await client.transfer.getWalletBalance("NGN");
console.log("Cashonrails connection ok:", balance);
} catch (error) {
console.error(
"Cashonrails setup failed:",
error.response?.data || error.message,
);
}If you receive 401, check the secret key and environment. If you receive 403, check account status, product access, and IP allowlisting.
Next Steps
Last updated on