Reserved Accounts
The Reserved Accounts module allows you to create and manage dedicated bank accounts for your customers. These accounts can be used to receive payments directly from customers through bank transfers.
Features
- Create reserved accounts for customers
- Retrieve account details
- List all reserved accounts
- Get available account providers
Create Reserved Account
Create a dedicated bank account for a customer:
const account = await client.reservedAccounts.create({
customer_code: "CUS_12345",
provider: "wema"
});
console.log('Account Number:', account.data.account_number);
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
customer_code | string | Yes | Unique customer code |
provider | string | Yes | Bank provider (e.g., wema ) |
Response
{
status: "success",
message: "Reserved account created successfully",
data: {
account_number: "9876543210",
account_name: "John Doe/YourBusinessName",
bank_name: "Wema Bank",
reference: "RA_1234567890",
customer_code: "CUS_12345"
}
}
Retrieve All Reserved Accounts
Get a list of all reserved accounts with pagination:
const accounts = await client.reservedAccounts.retrieveAll(1, 20);
// Display all accounts
accounts.data.forEach(account => {
console.log(`${account.account_name}: ${account.account_number} (${account.bank_name})`);
});
Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
page | number | No | 1 | Page number |
limit | number | No | 10 | Items per page |
Response
{
status: "success",
message: "Reserved accounts retrieved successfully",
data: [
{
account_number: "9876543210",
account_name: "John Doe/YourBusinessName",
bank_name: "Wema Bank",
reference: "RA_1234567890",
customer_code: "CUS_12345",
created_at: "2023-05-15T10:30:00Z"
},
// More accounts...
],
pagination: {
limit: 20,
offset: 0,
next_offset: 20,
total: 35,
total_pages: 2
}
}
Retrieve One Reserved Account
Get details of a specific reserved account:
const account = await client.reservedAccounts.retrieveOne('account_id');
console.log('Account Details:', account.data);
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
account_id | string | Yes | ID of the reserved account |
Response
{
status: "success",
message: "Reserved account retrieved successfully",
data: {
account_number: "9876543210",
account_name: "John Doe/YourBusinessName",
bank_name: "Wema Bank",
reference: "RA_1234567890",
customer_code: "CUS_12345",
created_at: "2023-05-15T10:30:00Z",
transactions: [
{
reference: "TRX_1234567890",
amount: "5000",
type: "credit",
status: "success",
narration: "Payment from John Doe",
created_at: "2023-05-15T10:35:00Z"
}
// More transactions...
]
}
}
Get Account Providers
Retrieve available providers for reserved accounts:
const providers = await client.reservedAccounts.accountProviders();
console.log('Available Providers:', providers.data);
Response
{
status: "success",
message: "Account providers retrieved successfully",
data: [
{
name: "Wema Bank",
code: "wema",
logo: "https://example.com/wema-logo.png"
},
// More providers...
]
}
Error Handling
try {
const account = await client.reservedAccounts.create({
customer_code: "CUS_12345",
provider: "wema"
});
} catch (error) {
console.error('Failed to create reserved account:', error.message);
}
Complete Example
const { CashOnRailsClient } = require('cashonrails-node');
const client = new CashOnRailsClient('YOUR_SECRET_KEY');
async function manageReservedAccounts() {
try {
// Create a reserved account
const newAccount = await client.reservedAccounts.create({
customer_code: "CUS_12345",
provider: "wema"
});
console.log('New Account:', newAccount.data);
// List all accounts
const allAccounts = await client.reservedAccounts.retrieveAll(1, 20);
console.log('All Accounts:', allAccounts.data);
// Get specific account
const accountDetails = await client.reservedAccounts.retrieveOne('ACCOUNT_ID');
console.log('Account Details:', accountDetails.data);
// Get providers
const providers = await client.reservedAccounts.accountProviders();
console.log('Available Providers:', providers.data);
} catch (error) {
console.error('Error:', error.message);
}
}
manageReservedAccounts();