Make a Deposit via SDK (Js)
You can use our SDKs in different languages to interact with Moala:
- Java: Moala Java SDK
- JavaScript: Moala JavaScript SDK
- PHP: Moala PHP SDK
In this tutorial, we will present a simple approach to integrating the MOALA SDKs in order to perform a cash deposit operation.
Prerequisites
Before getting started, make sure you have the following:
- An account on the MOALA portal with the necessary permissions to perform deposits. You can obtain a Moala account by following the steps detailed here: Get API Keys
- Node.js 18 or higher
- npm to manage dependencies
- The SDK downloaded and integrated from: Moala JavaScript SDK
Installation
You can install the SDK via NPM.
Add the SDK to your project using the following command:
npm install js-moala
1. Authentication
Authentication with the Moala SDK is done by configuring the SDK client with your API key and a secret key.
const { createClient } = require('js-moala');
const baseUrl = 'https://api.moala.africa';
const appKey = 'your_app_key';
const secretKey = 'your_secret_key';
const client = createClient(baseUrl, appKey, secretKey);
Once configuration is complete, you can start using the SDK.
2. Verify Client KYC
Before making a deposit, it is important to perform KYC verification to ensure the deposit is going to the correct recipient.
(async () => {
try {
const transaction = await client.kyc(phoneNumber, serviceCode);
console.log('Transaction:', transaction);
} catch (error) {
console.error('Error:', error);
}
})();
The allowed serviceCode values for this SDK method are:
- CASHOUT_MTN_CM: Cashout MTN Cameroon
- CASHOUT_ORANGE_CM: Cashout Orange Cameroon
- CASHOUT_AIRTEL_GA: Cashout Airtel Gabon
- CASHOUT_MOOV_GA: Cashout Moov Gabon
- PAIEMENTMARCHAND_MTN_CM: Merchant payment MTN Cameroon
- PAIEMENTMARCHAND_ORANGE_CM: Merchant payment Orange Cameroon
- PAIEMENTMARCHAND_AIRTEL_GA: Merchant payment Airtel Gabon
- PAIEMENTMARCHAND_MOOV_GA: Merchant payment Moov Gabon
3. Make a Deposit
Now let’s proceed to perform a cash deposit operation using the MOALA SDK.
(async () => {
try {
const cashinResult = await client.cashin('phoneNumber', 'serviceCode', amount, 'partnerId');
console.log('Cashin:', cashinResult);
} catch (error) {
console.error('Error:', error);
}
})();
The allowed serviceCode values for this SDK method are:
- CASHIN_MTN_CM: Deposit MTN Cameroon
- CASHIN_ORANGE_CM: Deposit Orange Cameroon
- CASHIN_AIRTEL_GA: Deposit Airtel Gabon
- CASHIN_MOOV_GA: Deposit Moov Gabon
- PAIEMENTMARCHAND_MTN_CM: Merchant payment MTN Cameroon
- PAIEMENTMARCHAND_ORANGE_CM: Merchant payment Orange Cameroon
- PAIEMENTMARCHAND_AIRTEL_GA: Merchant payment Airtel Gabon
- PAIEMENTMARCHAND_MOOV_GA: Merchant payment Moov Gabon
The partnerId field must be unique for each transaction, otherwise the request will fail.
4. Check Deposit Status
Once the deposit request has been sent, you can check the success of the operation by making another API call.
(async () => {
try {
const status = await client.checkTransaction(partnerId);
console.log('Status:', status);
} catch (error) {
console.error('Error:', error);
}
})();
5. Conclusion
At the end of this tutorial, you now know how to integrate the MOALA APIs to perform a cash deposit operation.