Integration Examples
This guide outlines the steps required to integrate MOALA’s SDKs and REST APIs into your application.
SDK Integration
MOALA has developed ready-to-use SDKs to simplify the integration of its platform. These SDKs support several operations, such as: balance check, transaction history, KYC compliance check, deposit, withdrawal, etc.
We provide SDKs in 3 programming languages:
- Java : SDK Moala Java
- Javascript : SDK Moala Javascript
- Php : SDK Moala Php
- Python : SDK Moala Python
To use the SDKs described below, you need to have an account on our back office.
This account is created once you have completed all the administrative steps described in the previous section Prerequisites and integration procedures
Prerequisites
- Java ☕
- Javascript 🎨
- PHP 🐘
- Java 8 or higher
- Maven for dependency management
- Node.js 18 or higher
- npm for dependency management
- PHP 7.2 or higher
- Composer for dependency management
Installation
- Java ☕
- Javascript 🎨
- PHP 🐘
You can install the SDK via Maven.
<dependency>
<groupId>africa.moala</groupId>
<artifactId>sdkmoala</artifactId>
<version>1.0</version>
</dependency>
Add the SDK to your project using the command :
mvn package
You can install the SDK via NPM. Add the SDK to your project using the following command :
npm install js-moala
You can install the SDK via Composer. Add the SDK to your project using the following command :
composer require bitkap/php-moala
Configuration
To use the SDK, you need an API key provided by MOALA. Here’s how to use it to initialize the SDK :
- Java ☕
- Javascript 🎨
- PHP 🐘
import africa.moala;
String urlApi = "https://api.moala.africa";
String appKey = "your_app_key";
String secretKey = "your_secret_key";
MoalaClient moalaClient = new MoalaClient(appKey, secretKey, urlApi);
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);
use MoalaSDK\MoalaClient;
$base_url = "https://api.moala.africa";
$appKey = "your_app_key";
$secretKey = "your_secret_key";
$client = new MoalaClient($base_url, $appKey, $secretKey);
Usage
Balance Check
- Java ☕
- Javascript 🎨
- PHP 🐘
double res = moalaClient.getBalance();
System.out.println(res);
(async () => {
try {
const balance = await client.balance();
console.log('Balance:', balance);
} catch (error) {
console.error('Error:', error);
}
})();
$balance = $client->balance();
print_r($balance);
Transaction Verification
- Java ☕
- Javascript 🎨
- PHP 🐘
TransactionView transactionView = moalaClient.checkTransaction("partnerId");
System.out.println(transactionView);
(async () => {
try {
const transaction = await client.checkTransaction('partnerId');
console.log('Transaction:', transaction);
} catch (error) {
console.error('Error:', error);
}
})();
$transaction = $client->checkTransaction($partnerId);
print_r($transaction);
KYC Verification
- Java ☕
- Javascript 🎨
- PHP 🐘
KycView kycView = moalaClient.getKycNumber("phoneNumber","serviceCode");
System.out.println(kycView);
(async () => {
try {
const kycResult = await client.kyc('phoneNumber', 'serviceCode');
console.log('KYC:', kycResult);
} catch (error) {
console.error('Error:', error);
}
})();
$kyc = $client->kyc($phoneNumber, $serviceCode);
print_r($kyc);
Make a Deposit
- Java ☕
- Javascript 🎨
- PHP 🐘
TransactionView transactionView = moalaClient.cashin("phoneNumber","serviceCode",amount, "partnerId");
System.out.println(transactionView);
(async () => {
try {
const cashinResult = await client.cashin('phoneNumber', 'serviceCode', amount, 'partnerId');
console.log('Cashin:', cashinResult);
} catch (error) {
console.error('Error:', error);
}
})();
$cashin = $client->cashin($phoneNumber, $serviceCode, $amount, $partnerId);
print_r($cashin);
Make a withdrawal
- Java ☕
- Javascript 🎨
- PHP 🐘
TransactionView transactionView = moalaClient.cashout("phoneNumber","serviceCode",amount, "partnerId");
System.out.println(transactionView);
(async () => {
try {
const cashoutResult = await client.cashout('phoneNumber', 'serviceCode', amount, 'partnerId');
console.log('Cashout:', cashoutResult);
} catch (error) {
console.error('Error:', error);
}
})();
$cashout = $client->cashout($phoneNumber, $serviceCode, $amount, $partnerId);
print_r($cashout);
REST API Integration
MOALA’s API is a standard REST API that can be integrated into any backend. Only a few minor configurations are needed to start using it.
Header Configuration
MOALA’s API requires 3 mandatory headers to be added :
- LP-ACCESS-KEY: API Key available in the MOALA Portal Portail MOALA
- LP-ACCESS-TIMESTAMP: epoch time in seconds
- LP-ACCESS-SIGN: the digital signature or API Secret Key that you generate
Signature Generation
The signature format is as follows: LP-ACCESS-TIMESTAMP + requestMethod + pathRequest + body (in JSON)
The resulting string must then be signed using the API key obtained from the admin portal, with the HMAC-SHA256 HEX algorithm
API Get Balance
- Java ☕
- Javascript 🎨
- PHP 🐘
// Java - Récupération du solde
String message = "1718193158GET/v1/api/balance";
String secret_key = "your_secret_key";
String signatureSyn = HmacUtils.hmacSha256Hex(secret_key, message);
// Javascript - Récupération du solde
const crypto = require('crypto');
const message = "1718193158GET/v1/api/balance";
const secret_key = "your_secret_key";
const signatureSyn = crypto.createHmac('sha256', secret_key).update(message).digest('hex');
// PHP - Récupération du solde
$message = "1718193158GET/v1/api/balance";
$secret_key = "your_secret_key";
$signatureSyn = hash_hmac('sha256', $message, $secret_key);
API CashIn Orange Money
- Java ☕
- Javascript 🎨
- PHP 🐘
// Java - Cashin Orange Money
String message = "1718199502POST/v1/api/transaction/withdrawal{\"transactionType\":\"withdrawal\",\"amount\":100,\"serviceCode\":\"CASHIN_MTN_CM\",\"phoneNumber\":\"675598817\",\"partnerId\":\"tst_13\"}";
String secret_key = "your_secret_key";
String signatureSyn = HmacUtils.hmacSha256Hex(secret_key, message);
// JavaScript - Cashin Orange Money
const crypto = require('crypto');
const message = '1718199502POST/v1/api/transaction/withdrawal{"transactionType":"withdrawal","amount":100,"serviceCode":"CASHIN_MTN_CM","phoneNumber":"675598817","partnerId":"tst_13"}';
const secret_key = "your_secret_key";
const signatureSyn = crypto.createHmac('sha256', secret_key).update(message).digest('hex');
// PHP - Cashin Orange Money
$message = '1718199502POST/v1/api/transaction/withdrawal{"transactionType":"withdrawal","amount":100,"serviceCode":"CASHIN_MTN_CM","phoneNumber":"675598817","partnerId":"tst_13"}';
$secret_key = "your_secret_key";
$signatureSyn = hash_hmac('sha256', $message, $secret_key);
The available Service Codes for API calls are :
- CASHIN_MTN_CM: cashin MTN Cameroon
- CASHIN_ORANGE_CM: cashin Orange Cameroon
- CASHIN_AIRTEL_GA: cashin Airtel Gabon
- PAIEMENTMARCHAND_AIRTEL_GA: Merchant payment Airtel Gabon
- PAIEMENTMARCHAND_ORANGE_CM: Merchant payment Orange Cameroun
- PAIEMENTMARCHAND_MTN_CM: Merchant payment MTN Cameroun
Error Handling
Each SDK method may raise exceptions in case of an error, and the API endpoints may return error codes.
Support
If you have questions or face difficulties integrating our APIs, you can open a support ticket here: GitHub repository GitHub repository.