Skip to main content

Get Banks

The get banks endpoint allows you to retrieve a list of all available banks for bank transfers. This is useful for building bank selection interfaces in your application.

Endpoint​

GET https://api.resolutpay.com/bank

Parameters​

ParameterTypeRequiredDescription
countrystringNoCountry code (default: NG for Nigeria)

Example Request​

const axios = require("axios");

const getBanks = async (country = "GH") => {
try {
const response = await axios.get(
`https://api.resolutpay.com/bank?country=${country}`,
{
headers: {
Authorization: "Bearer YOUR_SECRET_KEY",
},
}
);

const banks = response.data.data;
console.log("Available banks:", banks);
return banks;
} catch (error) {
console.error("Error fetching banks:", error.response.data);
throw error;
}
};

// Get Ghanaian banks (default)
getBanks("GH");

// Get Nigerian banks
getBanks("NG");

Example Response​

{
"status": true,
"message": "Banks retrieved",
"data": [
{
"id": 1,
"name": "Ghana Commercial Bank",
"code": "001",
"active": true,
"country": "Ghana",
"currency": "GHS",
"type": "account_number",
"createdAt": "2023-01-01T00:00:00.000Z",
"updatedAt": "2023-01-01T00:00:00.000Z"
},
{
"id": 2,
"name": "Agricultural Development Bank",
"code": "002",
"active": true,
"country": "Ghana",
"currency": "GHS",
"type": "account_number",
"createdAt": "2023-01-01T00:00:00.000Z",
"updatedAt": "2023-01-01T00:00:00.000Z"
},
{
"id": 3,
"name": "Bank of Ghana",
"code": "003",
"active": true,
"country": "Ghana",
"currency": "GHS",
"type": "account_number",
"createdAt": "2023-01-01T00:00:00.000Z",
"updatedAt": "2023-01-01T00:00:00.000Z"
}
]
}

Supported Countries​

CountryCodeCurrencyBank Type
GhanaGHGHSAccount Number
NigeriaNGNGNNUBAN
KenyaKEKESAccount Number
UgandaUGUGXAccount Number
TanzaniaTZTZSAccount Number

Bank Object Properties​

PropertyTypeDescription
idintegerUnique bank identifier
namestringBank name
codestringBank code
activebooleanWhether bank is active
countrystringCountry name
currencystringCurrency code
typestringAccount type (nuban, account_number)
createdAtstringCreation timestamp
updatedAtstringLast update timestamp

Complete Example with React​

import React, { useState, useEffect } from "react";
import axios from "axios";

const BankSelector = ({ onBankSelect }) => {
const [banks, setBanks] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [selectedCountry, setSelectedCountry] = useState("GH");

const countries = [
{ code: "GH", name: "Ghana" },
{ code: "NG", name: "Nigeria" },
{ code: "KE", name: "Kenya" },
{ code: "UG", name: "Uganda" },
{ code: "TZ", name: "Tanzania" },
];

const fetchBanks = async (country) => {
try {
setLoading(true);
setError(null);

const response = await axios.get(
`https://api.resolutpay.com/bank?country=${country}`,
{
headers: {
Authorization: `Bearer ${process.env.REACT_APP_RESOLUTPAY_SECRET_KEY}`,
},
}
);

setBanks(response.data.data);
} catch (error) {
setError("Failed to fetch banks");
console.error("Error:", error.response?.data || error.message);
} finally {
setLoading(false);
}
};

useEffect(() => {
fetchBanks(selectedCountry);
}, [selectedCountry]);

const handleCountryChange = (event) => {
setSelectedCountry(event.target.value);
};

const handleBankSelect = (bank) => {
onBankSelect(bank);
};

if (loading) {
return <div>Loading banks...</div>;
}

if (error) {
return <div>Error: {error}</div>;
}

return (
<div className="bank-selector">
<div className="country-selector">
<label htmlFor="country">Country:</label>
<select
id="country"
value={selectedCountry}
onChange={handleCountryChange}
>
{countries.map((country) => (
<option key={country.code} value={country.code}>
{country.name}
</option>
))}
</select>
</div>

<div className="bank-list">
<label htmlFor="bank">Select Bank:</label>
<select
id="bank"
onChange={(e) => {
const bank = banks.find((b) => b.id === parseInt(e.target.value));
if (bank) handleBankSelect(bank);
}}
>
<option value="">Select a bank</option>
{banks.map((bank) => (
<option key={bank.id} value={bank.id}>
{bank.name}
</option>
))}
</select>
</div>

<div className="bank-info">
{banks.length > 0 && (
<p>
Found {banks.length} banks in{" "}
{countries.find((c) => c.code === selectedCountry)?.name}
</p>
)}
</div>
</div>
);
};

export default BankSelector;

Complete Example with Express.js​

const express = require("express");
const axios = require("axios");
const app = express();

app.use(express.json());

// Get banks endpoint
app.get("/banks", async (req, res) => {
try {
const { country = "GH" } = req.query;

const response = await axios.get(
`https://api.resolutpay.com/bank?country=${country}`,
{
headers: {
Authorization: `Bearer ${process.env.RESOLUTPAY_SECRET_KEY}`,
},
}
);

res.json({
success: true,
data: response.data.data,
});
} catch (error) {
console.error(
"Error fetching banks:",
error.response?.data || error.message
);

res.status(500).json({
success: false,
message: error.response?.data?.message || "Failed to fetch banks",
});
}
});

// Get specific bank by code
app.get("/banks/:code", async (req, res) => {
try {
const { code } = req.params;
const { country = "GH" } = req.query;

const response = await axios.get(
`https://api.resolutpay.com/bank?country=${country}`,
{
headers: {
Authorization: `Bearer ${process.env.RESOLUTPAY_SECRET_KEY}`,
},
}
);

const bank = response.data.data.find((b) => b.code === code);

if (!bank) {
return res.status(404).json({
success: false,
message: "Bank not found",
});
}

res.json({
success: true,
data: bank,
});
} catch (error) {
console.error(
"Error fetching bank:",
error.response?.data || error.message
);

res.status(500).json({
success: false,
message: error.response?.data?.message || "Failed to fetch bank",
});
}
});

app.listen(3000, () => {
console.log("Server running on port 3000");
});

Caching Banks​

Since the bank list doesn't change frequently, consider caching the results:

const NodeCache = require("node-cache");
const bankCache = new NodeCache({ stdTTL: 3600 }); // Cache for 1 hour

const getBanksWithCache = async (country = "GH") => {
const cacheKey = `banks_${country}`;

// Check cache first
let banks = bankCache.get(cacheKey);

if (banks) {
return banks;
}

// Fetch from API if not in cache
try {
const response = await axios.get(
`https://api.resolutpay.com/bank?country=${country}`,
{
headers: {
Authorization: `Bearer ${process.env.RESOLUTPAY_SECRET_KEY}`,
},
}
);

banks = response.data.data;

// Store in cache
bankCache.set(cacheKey, banks);

return banks;
} catch (error) {
console.error(
"Error fetching banks:",
error.response?.data || error.message
);
throw error;
}
};

Error Responses​

Common error responses:

{
"status": false,
"message": "Invalid country code",
"data": null
}
ErrorDescription
Invalid country codeCountry code is not supported
UnauthorizedInvalid API key

Next Steps​