Complete guide to integrating with Mago Flash API.
Mago Flash provides a simple and secure way to accept mobile money payments in your applications. This documentation will guide you through the integration process step by step.
Here's how the platform works:
So, without further ado, let's see how to do all this!
To get started with Mago Flash:
Generate your API tokens:
Follow these steps to implement the basic payment flow:
// Using JavaScript with fetch
const apiToken = 'YOUR_API_TOKEN';
// Request a payment number
async function requestPaymentNumber(operatorName = null) {
const url = new URL('https://magoflash.com/api/payment-phone');
if (operatorName) url.searchParams.append('operatorName', operatorName);
const response = await fetch(url, {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json'
}
});
return await response.json();
}
// Verify transaction
async function verifyTransaction(code, transactionId, phoneNumber) {
const response = await fetch('https://magoflash.com/api/verify-transaction', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
code,
transactionId,
phoneNumber
})
});
return await response.json();
}
// Example usage
requestPaymentNumber().then(result => console.log(result));
verifyTransaction('123456', 'TRX123456', '+243123456789').then(result => console.log(result));
<?php
// Using PHP with cURL
$apiToken = 'YOUR_API_TOKEN';
// Request a payment number
function requestPaymentNumber($operatorName = null) {
global $apiToken;
$url = 'https://magoflash.com/api/payment-phone';
if ($operatorName) {
$url .= '?operatorName=' . urlencode($operatorName);
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiToken,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Verify transaction
function verifyTransaction($code, $transactionId, $phoneNumber) {
global $apiToken;
$ch = curl_init('https://magoflash.com/api/verify-transaction');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'code' => $code,
'transactionId' => $transactionId,
'phoneNumber' => $phoneNumber
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiToken,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Example usage
$paymentNumber = requestPaymentNumber();
print_r($paymentNumber);
$transaction = verifyTransaction('123456', 'TRX123456', '+243123456789');
print_r($transaction);
?>
All API requests must be authenticated using a Bearer token. You can generate API tokens from your merchant dashboard.
curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://magoflash.com/api/balances
Verify a transaction using the confirmation code and assign it to your merchant account.
POST /api/verify-transaction
{
"code": "123456",
"transactionId": "TRX123456",
"phoneNumber": "+243123456789"
}
{
"status": "success",
"code": "SUCCESS",
"message": "Transaction verified successfully",
"data": {
"transactionId": "TRX123456",
"amount": 100,
"currency": "USD"
}
}
Retrieve current balances for all currencies in your merchant account.
GET /api/balances
{
"status": "success",
"data": [
{
"currency": "USD",
"amount": 1000.50
},
{
"currency": "EUR",
"amount": 750.25
}
]
}
Retrieve a random remitter phone number for payment. Optionally, you can specify an operator name to get a number from a specific operator.
GET /api/payment-phone
{
"operatorName": "string" // Optional
}
{
"status": "success",
"data": {
"phoneNumber": "+243123456789",
"network": "Operator Name",
"country": "Country Name"
}
}
Retrieve a list of all available operators.
GET /api/operators
{
"status": "success",
"data": [
{
"name": "Operator Name",
"humanReadable": "Operator Human Readable Name",
"country": "Country Name",
"countryCode": "+243",
"prefixes": ["123", "456"]
}
]
}
Transfer money between merchant accounts.
POST /api/transfer
{
"receiverEmail": "recipient@example.com",
"amount": 100,
"currency": "USD"
}
{
"status": "success",
"message": "Money transferred successfully",
"data": {
"transactionId": "MGFT123_1234567890_0001",
"amount": 100,
"currency": "USD",
"status": "completed"
}
}
Status Code | Description |
---|---|
400 | Invalid inputs or insufficient balance |
404 | Recipient not found |
Common error codes:
INVALID_INPUT
: Missing or invalid request parametersRECIPIENT_NOT_FOUND
: The recipient email does not existINSUFFICIENT_BALANCE
: Not enough balance in the specified currencyUNSUPPORTED_EXCHANGE
: Transfer type not supportedThe API uses conventional HTTP response codes to indicate the success or failure of requests.
Status Code | Description |
---|---|
200 - OK | Request succeeded |
400 - Bad Request | Invalid request parameters |
401 - Unauthorized | Invalid or missing API token |
404 - Not Found | Resource not found |
500 - Internal Server Error | Server-side error occurred |