Initial commit

This commit is contained in:
Kwesi Banson Jnr
2026-04-08 05:53:02 +00:00
commit 592a161ee6
63 changed files with 4105 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
/*
Developer: David Kumwenda
Contact: 0881161942 or 0996139030
App: Mpamba 4 MSE
Date: 30 August 2025
Duration: 1 day dev work*/
// Read raw POST data
$rawData = file_get_contents("php://input");
// Decode JSON
$data = json_decode($rawData, true);
// Basic logging (optional, useful for debugging)
file_put_contents("logs/callback_log_".date('Ymd').'.txt', date("Y-m-d H:i:s") . " - " . $rawData . PHP_EOL, FILE_APPEND); exit();
// Validate required fields
if (isset($data["receipt_number"], $data["result_code"], $data["transaction_id"])) {
$receiptNumber = $data["receipt_number"];
$resultCode = $data["result_code"];
$resultDescription = $data["result_description"] ?? "";
$resultTime = $data["result_time"] ?? date("Y-m-d H:i:s");
$transactionId = $data["transaction_id"];
$success = $data["success"] ?? false;
// Example: Save to database
// (Replace this with your actual DB insert/update code)
/*
$conn = mysqli_connect("localhost", "user", "password", "dbname");
$stmt = mysqli_prepare($conn, "INSERT INTO payments (transaction_id, receipt_number, result_code, result_description, result_time, success) VALUES (?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "ssissi", $transactionId, $receiptNumber, $resultCode, $resultDescription, $resultTime, $success);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($conn);
*/
// Respond with 200 OK to acknowledge receipt
http_response_code(200);
echo json_encode(["status" => "callback received"]);
} else {
// Missing required fields
http_response_code(400);
echo json_encode(["error" => "Invalid callback payload"]);
}
?>

View File

@@ -0,0 +1,170 @@
<?php
$clientID="94351d4d-4909-4056-ad9d-8052a332d6b9";
$clientSecret="bf665590-2519-49af-8d1f-7cd0dce1dc7a";
//CONTINENTAL CAPITAL
$clientID="9ff18a6d-331e-4ec5-9ecc-4e512e13747c";
$clientSecret="40f44254-10e7-4eb8-b161-38125117f4ba";
$authURL="https://openapiuat.airtel.africa/auth/oauth2/token";
$res=authenticate($authURL, $clientID, $clientSecret);
if($res['success']){
$bearerToken=$res['token'];
$country = "MW";
$currency = "MWK";
//enquire trans status
$res=getAirtelBalance($country, $currency, $bearerToken);
if ($res["status"] === "SUCCESS") {
echo "Balance: {$res['balance']} {$res['currency']}\n";
echo "Account Status: {$res['account_status']}";
} else {
echo "Error: " . $res["message"];
}
}else{
echo(print_r($res,true));
exit();
}
function getAirtelBalance($country, $currency, $token) {
$url = "https://openapiuat.airtel.africa/standard/v1/users/balance";
// Initialize cURL
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"X-Country: $country",
"X-Currency: $currency",
"Authorization: Bearer $token"
],
]);
$response = curl_exec($curl);
if (curl_errno($curl)) {
$error = curl_error($curl);
curl_close($curl);
return [
"status" => "ERROR",
"message" => "cURL Error: $error"
];
}
curl_close($curl);
// Decode response
$result = json_decode($response, true);
// Handle invalid JSON
if (!$result) {
return [
"status" => "ERROR",
"message" => "Invalid JSON response from Airtel API"
];
}
// Check for API structure
if (!isset($result["status"])) {
return [
"status" => "ERROR",
"message" => "Unexpected API response format".print_r($result,true)
];
}
$statusCode = $result["status"]["code"] ?? null;
$message = $result["status"]["message"] ?? "Unknown error";
// ✅ SUCCESS case
if ($statusCode == "200" && isset($result["data"])) {
return [
"status" => "SUCCESS",
"balance" => $result["data"]["balance"] ?? "0",
"currency" => $result["data"]["currency"] ?? $currency,
"account_status" => $result["data"]["account_status"] ?? "Unknown"
];
}
// ❌ ERROR case (e.g. "User not found", "Invalid token", etc.)
return [
"status" => "ERROR",
"message" => $message,
"code" => $statusCode,
"responseCode" => $result["status"]["response_code"] ?? null,
"resultCode" => $result["status"]["result_code"] ?? null
];
}
function authenticate($baseURL, $wallet, $password)
{
// JSON payload
$postData = json_encode([
'client_id' => $wallet,
'client_secret' => $password,
'grant_type' => "client_credentials"
]);
// Initialize cURL
$ch = curl_init($baseURL);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response
curl_setopt($ch, CURLOPT_POST, true); // Use POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);// Set the request body
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
]);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
// Check if token is present
if ($httpCode === 200 && isset($result['access_token'])) {
return [
'success' => true,
'token' => $result['access_token']
];
} else {
return [
'success' => false,
'error' => $result['error_description'] ?? 'Unknown error',
'details' => $result['error'] ?? []
];
}
}
?>

View File

@@ -0,0 +1,323 @@
<?php
$incoming=file_get_contents("php://input");
$data=json_decode($incoming,true);
$subscriber_country = $data['country'];
$subscriber_currency = $data['currency'];
$subscriber_msisdn = $data['msisdn'];
$transaction_amount = $data['amount'];
$transaction_country = $data['country'];
$transaction_currency = $data['currency'];
$transaction_id = $data['transactionID'];
$authURL="https://openapiuat.airtel.mw/auth/oauth2/token";
/*CEDAR CAPITAL
$clientID="94351d4d-4909-4056-ad9d-8052a332d6b9";
$clientSecret="bf665590-2519-49af-8d1f-7cd0dce1dc7a";*/
//CONTINENTAL CAPITAL DISBURSEMENTS
$clientID="7f96ba01-2a74-4342-a50d-f0a36874f985";
$clientSecret="d31861d6-125e-4c0f-a0b3-2bca7af3cad0";
//CEDAR DISBURSEMENTS
//$clientID="0ffd5cef-40f6-4673-8620-9ace5c798364";
//$clientSecret="15fdc659-1431-4536-8c95-4307857464ce";
//STOCK BROKERS DISBURSEMENTS [not approved]
//$clientID="9ff18a6d-331e-4ec5-9ecc-4e512e13747c";
//$clientSecret="40f44254-10e7-4eb8-b161-38125117f4ba";
$res=authenticate($authURL, $clientID, $clientSecret);
if($res['success']){
$bearerToken=$res['token'];
echo $bearerToken;
//send a payment request
$payment = airtelDisbursement(
$bearerToken,
$subscriber_msisdn,
$transaction_amount,
'MSEMW',
'IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=',
uniqid('mse-')
);
echo (json_encode($payment));
//$data = json_decode($res, true);
/* Check if the response has a status and success flag
if (isset($data['status']['success']) && $data['status']['success'] === true) {
// Success case
$transactionId = $data['data']['transaction']['id'];
$transactionStatus = $data['data']['transaction']['status'];
$message = $data['status']['message'];
echo "✅ Transaction Successful!\n";
echo "Transaction ID: $transactionId\n";
echo "Status: $transactionStatus\n";
echo "Message: $message\n";
} else {
// Failure case
$errorCode = $data['status']['result_code'] ?? 'N/A';
$errorMessage = $data['status']['message'] ?? 'Unknown error';
echo "❌ Transaction Failed!\n";
echo "Error Code: $errorCode\n";
echo "Message: $errorMessage\n";
}
*/
}else{
echo(json_encode($res));
exit();
}
function airtelDisbursement(string $accessToken,string $msisdn,float $amount,string $reference,string $pin,string $transactionId,
string $country = 'MW',string $currency = 'MWK',int $timeout = 30) {
$url = 'https://openapiuat.airtel.mw/standard/v1/disbursements/';
$payload = [
"payee" => [
"msisdn" => $msisdn
],
"reference" => $reference,
"pin" => $pin,
"transaction" => [
"amount" => $amount,
"id" => $transactionId
]
];
file_put_contents('logs/requests.txt',json_encode($payload).PHP_EOL,FILE_APPEND);
$headers = [
'Content-Type: application/json',
'Accept: */*',
'X-Country: ' . $country,
'X-Currency: ' . $currency,
'Authorization: Bearer ' . $accessToken
];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_SSL_VERIFYPEER => true
]);
$response = curl_exec($ch);
$error = curl_error($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($error) {
return [
'success' => false,
'error' => 'CURL_ERROR',
'message' => $error
];
}
return [
'success' => ($code === 200),
'http_code' => $code,
'response' => json_decode($response, true),
'raw' => $response
];
}
function sendUSSDPush($token, $data) {
// Endpoint
$url = "https://openapiuat.airtel.africa/merchant/v1/payments/";
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $token,
"Content-Type: application/json",
"X-Country: MW",
"X-Currency: MWK"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return false;
}
// Close connection
curl_close($ch);
// Decode and return response
return $response;
}
function changePassword($baseURL, $token,$newPassword, $newPasswordConfirmation) {
// Endpoint URL
$url = rtrim($baseURL, "/") . "/password";
// Prepare data
$data = [
"new_password" => $newPassword,
"new_password_confirmation" => $newPasswordConfirmation
];
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH"); // PATCH request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $token,
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute and capture response
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return false;
}
// Close connection
curl_close($ch);
// Decode JSON response
return json_decode($response, true);
}
function validate_msisdn($baseURL, $msisdn, $bearerToken)
{
// Ensure proper endpoint format
$url = rtrim($baseURL, '/') . '/payments/validate/' . urlencode($msisdn);
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $bearerToken,
'Accept: application/json'
]);
// Execute the request
$response = curl_exec($ch);
// Handle cURL error
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
if ($httpCode === 200 && isset($result['data']['full_name'])) {
return [
'success' => true,
'full_name' => $result['data']['full_name']
];
} else {
return [
'success' => false,
'error' => $result['message'] ?? 'Unknown error',
'details' => $result['errors'] ?? []
];
}
}
function authenticate($baseURL, $wallet, $password)
{
// JSON payload
$postData = json_encode([
'client_id' => $wallet,
'client_secret' => $password,
'grant_type' => "client_credentials"
]);
// Initialize cURL
$ch = curl_init($baseURL);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response
curl_setopt($ch, CURLOPT_POST, true); // Use POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);// Set the request body
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
]);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
// Check if token is present
if ($httpCode === 200 && isset($result['access_token'])) {
return [
'success' => true,
'token' => $result['access_token']
];
} else {
return [
'success' => false,
'error' => $result['error_description'] ?? 'Unknown error',
'details' => $result['error'] ?? []
];
}
}
?>

View File

@@ -0,0 +1,8 @@
2025-10-24 04:47:56 - {
"transaction": {
"id": "BBZMiscxy",
"message": "Paid UGX 5,000 to TECHNOLOGIES LIMITED Charge UGX 140, Trans ID MP210603.1234.L06941.",
"status_code": "TS",
"airtel_money_id": "MP210603.1234.L06941"
}
}

View File

@@ -0,0 +1,5 @@
2025-11-07 13:14:45 -
2025-11-07 13:15:13 -
2025-11-07 13:15:31 -
2025-11-07 18:36:52 -
2025-11-07 19:00:47 -

View File

@@ -0,0 +1 @@
2026-02-12 08:45:17 - {"transaction":{"status_code":"TF","code":"DP00800001005","airtel_money_id":"null","id":"1234567919","message":"Transaction id is invalid"}}

View File

@@ -0,0 +1,44 @@
{"payee":{"msisdn":"996139030"},"reference":"MSE","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a54c4b7e054"}}
{"payee":{"msisdn":"996139030"},"reference":"MSE","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a54d2c75c62"}}
{"payee":{"msisdn":"996139030"},"reference":"MSE","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a54d3ceab6e"}}
{"payee":{"msisdn":"996139030"},"reference":"MSE","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a58de1834d8"}}
{"payee":{"msisdn":"996139030"},"reference":"MSE","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a58ed675c14"}}
{"payee":{"msisdn":"996139030"},"reference":"MSE","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a58fc2bb56d"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a5906ab20c0"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a590f316b25"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a5942d5434d"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a59b2c6a361"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a5a35dbf63e"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a9293a81d78"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a9310f9dd96"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse_69a931d2eb29e"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse-69aa7f7549067"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse-69aa7ff5ea099"}}
{"payee":{"msisdn":"996139030"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000,"id":"mse-69aa80405eef1"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":100,"id":"mse-69aa88596095c"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":100,"id":"mse-69aa8960bca7f"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":100,"id":"mse-69aa89ab291dc"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":10,"id":"mse-69aa89ca9dd83"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":50,"id":"mse-69aa89fc03810"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":49,"id":"mse-69aa8a286793a"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":200000,"id":"mse-69aa8a5b59210"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":200.5,"id":"mse-69aa8ace57745"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":0,"id":"mse-69aa8b45944b1"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":0,"id":"mse-69aa8bd951d17"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":800000,"id":"mse-69aa8c56e961a"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1800000,"id":"mse-69aa8d48d4725"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000000,"id":"mse-69aa8da5e5a46"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1000001,"id":"mse-69aa8db2be4d7"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":100,"id":"mse-69aa8de74fa4d"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":100,"id":"mse-69aa8df1239ab"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":100,"id":"mse-69aa8effbeb72"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":50.5,"id":"mse-69aa8f3cc16fd"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":550.5,"id":"mse-69aa8fa266f85"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":50,"id":"mse-69aa90141ef14"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":50,"id":"mse-69aa90355ff2f"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":200,"id":"mse-69aa906ab50d9"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":200000,"id":"mse-69aa90d3ea868"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":1200000,"id":"mse-69aa910b28409"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":10,"id":"mse-69aa9386358f9"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":50,"id":"mse-69aa94788ea87"}}
{"payee":{"msisdn":"999959024"},"reference":"MSEMW","pin":"IGbCqXwRoiqsHTIIjxfo6vWyzPMKg6iF3+pNQK6gTXbOyJgOd1bbPuIstTcMwSAiRXOgQrkRC0+sQU5wHF33aha+AL0TevBntLzVyGl8002ZXy6Ux4Pu+zymRdlw7J6H\/PXRC2kXhbR2GIHLHlqHC49gu65OzpJ8fvpnscg1yjE=","transaction":{"amount":50,"id":"mse-69c636d71e959"}}

View File

@@ -0,0 +1,250 @@
<?php
$incoming=file_get_contents("php://input");
$data=json_decode($incoming,true);
$subscriber_country = $data['subscriber']['country'];
$subscriber_currency = $data['subscriber']['currency'];
$subscriber_msisdn = $data['subscriber']['msisdn'];
$transaction_amount = $data['transaction']['amount'];
$transaction_country = $data['transaction']['country'];
$transaction_currency = $data['transaction']['currency'];
$transaction_id = $data['transaction']['id'];
$authURL="https://openapi.airtel.mw/auth/oauth2/token";
/*CEDAR CAPITAL
$clientID="94351d4d-4909-4056-ad9d-8052a332d6b9";
$clientSecret="bf665590-2519-49af-8d1f-7cd0dce1dc7a";*/
//CONTINENTAL CAPITAL UAT
$clientID="9ff18a6d-331e-4ec5-9ecc-4e512e13747c";
$clientSecret="40f44254-10e7-4eb8-b161-38125117f4ba";
//CONTINENTAL CAPITAL PROD
$clientID="37063c29-d090-4133-8a6c-6f3295d7c2a9";
$clientSecret="6502ff2d-be8d-485f-8fa4-d03e2d8ed11d";
$res=authenticate($authURL, $clientID, $clientSecret);
if($res['success']){
$bearerToken=$res['token'];
//send a ussd push
$res=sendUSSDPush($bearerToken, $data);
$data = json_decode($res, true);
// Check if the response has a status and success flag
if (isset($data['status']['success']) && $data['status']['success'] === true) {
// Success case
$transactionId = $data['data']['transaction']['id'];
$transactionStatus = $data['data']['transaction']['status'];
$message = $data['status']['message'];
echo "✅ Transaction Successful!\n";
echo "Transaction ID: $transactionId\n";
echo "Status: $transactionStatus\n";
echo "Message: $message\n";
} else {
// Failure case
$errorCode = $data['status']['result_code'] ?? 'N/A';
$errorMessage = $data['status']['message'] ?? 'Unknown error';
echo "❌ Transaction Failed!\n";
echo "Error Code: $errorCode\n";
echo "Message: $errorMessage\n";
}
}else{
echo(print_r($res,true));
exit();
}
function sendUSSDPush($token, $data) {
// Endpoint
$url = "https://openapi.airtel.mw/merchant/v1/payments/";
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $token,
"Content-Type: application/json",
"X-Country: MW",
"X-Currency: MWK"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return false;
}
// Close connection
curl_close($ch);
// Decode and return response
return $response;
}
function changePassword($baseURL, $token,$newPassword, $newPasswordConfirmation) {
// Endpoint URL
$url = rtrim($baseURL, "/") . "/password";
// Prepare data
$data = [
"new_password" => $newPassword,
"new_password_confirmation" => $newPasswordConfirmation
];
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH"); // PATCH request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $token,
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute and capture response
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return false;
}
// Close connection
curl_close($ch);
// Decode JSON response
return json_decode($response, true);
}
function validate_msisdn($baseURL, $msisdn, $bearerToken)
{
// Ensure proper endpoint format
$url = rtrim($baseURL, '/') . '/payments/validate/' . urlencode($msisdn);
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $bearerToken,
'Accept: application/json'
]);
// Execute the request
$response = curl_exec($ch);
// Handle cURL error
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
if ($httpCode === 200 && isset($result['data']['full_name'])) {
return [
'success' => true,
'full_name' => $result['data']['full_name']
];
} else {
return [
'success' => false,
'error' => $result['message'] ?? 'Unknown error',
'details' => $result['errors'] ?? []
];
}
}
function authenticate($baseURL, $wallet, $password)
{
// JSON payload
$postData = json_encode([
'client_id' => $wallet,
'client_secret' => $password,
'grant_type' => "client_credentials"
]);
// Initialize cURL
$ch = curl_init($baseURL);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response
curl_setopt($ch, CURLOPT_POST, true); // Use POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);// Set the request body
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
]);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
// Check if token is present
if ($httpCode === 200 && isset($result['access_token'])) {
return [
'success' => true,
'token' => $result['access_token']
];
} else {
return [
'success' => false,
'error' => $result['error_description'] ?? 'Unknown error',
'details' => $result['error'] ?? []
];
}
}
?>

View File

@@ -0,0 +1,142 @@
<?php
//$requestUri = $_SERVER['REQUEST_URI'];
//$parts = explode('/', trim($requestUri, '/'));
$id = $_GET['id'];//end($parts);
//echo $id;
$enqURL="https://openapiuat.airtel.africa/standard/v1/payments/".$id;
$authURL="https://openapiuat.airtel.africa/auth/oauth2/token";
$clientID="94351d4d-4909-4056-ad9d-8052a332d6b9";
$clientSecret="bf665590-2519-49af-8d1f-7cd0dce1dc7a";
//CONTINENTAL CAPITAL
$clientID="9ff18a6d-331e-4ec5-9ecc-4e512e13747c";
$clientSecret="40f44254-10e7-4eb8-b161-38125117f4ba";
$res=authenticate($authURL, $clientID, $clientSecret);
if($res['success']){
$bearerToken=$res['token'];
//enquire trans status
$res=trans_enquiry($enqURL,$bearerToken);
echo $res;
exit();
$data = json_decode($res, true);
// Check if the response has a status and success flag
if (isset($data['status']['success']) && $data['status']['success'] === true) {
// Success case
$transactionId = $data['data']['transaction']['id'];
$transactionStatus = $data['data']['transaction']['status'];
$message = $data['status']['message'];
echo "✅ Transaction Successful!\n";
echo "Transaction ID: $transactionId\n";
echo "Status: $transactionStatus\n";
echo "Message: $message\n";
} else {
// Failure case
$errorCode = $data['status']['result_code'] ?? 'N/A';
$errorMessage = $data['status']['message'] ?? 'Unknown error';
echo "❌ Transaction Failed!\n";
echo "Error Code: $errorCode\n";
echo "Message: $errorMessage\n";
}
}else{
echo(print_r($res,true));
exit();
}
function trans_enquiry($enqURL,$token){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $enqURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization:'.$token,
'Accept: */* ',
'X-Country: MW',
'X-Currency: MWK'
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
function authenticate($baseURL, $wallet, $password)
{
// JSON payload
$postData = json_encode([
'client_id' => $wallet,
'client_secret' => $password,
'grant_type' => "client_credentials"
]);
// Initialize cURL
$ch = curl_init($baseURL);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response
curl_setopt($ch, CURLOPT_POST, true); // Use POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);// Set the request body
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
]);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
// Check if token is present
if ($httpCode === 200 && isset($result['access_token'])) {
return [
'success' => true,
'token' => $result['access_token']
];
} else {
return [
'success' => false,
'error' => $result['error_description'] ?? 'Unknown error',
'details' => $result['error'] ?? []
];
}
}
?>

View File

@@ -0,0 +1,50 @@
<?php
/*
Developer: David Kumwenda
Contact: 0881161942 or 0996139030
App: Mpamba 4 MSE
Date: 30 August 2025
Duration: 1 day dev work*/
// Read raw POST data
$rawData = file_get_contents("php://input");
// Decode JSON
$data = json_decode($rawData, true);
// Basic logging (optional, useful for debugging)
file_put_contents("logs/callback_log_".date('Ymd').'.txt', date("Y-m-d H:i:s") . " - " . $rawData . PHP_EOL, FILE_APPEND);
// Validate required fields
if (isset($data["receipt_number"], $data["result_code"], $data["transaction_id"])) {
$receiptNumber = $data["receipt_number"];
$resultCode = $data["result_code"];
$resultDescription = $data["result_description"] ?? "";
$resultTime = $data["result_time"] ?? date("Y-m-d H:i:s");
$transactionId = $data["transaction_id"];
$success = $data["success"] ?? false;
// Example: Save to database
// (Replace this with your actual DB insert/update code)
/*
$conn = mysqli_connect("localhost", "user", "password", "dbname");
$stmt = mysqli_prepare($conn, "INSERT INTO payments (transaction_id, receipt_number, result_code, result_description, result_time, success) VALUES (?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "ssissi", $transactionId, $receiptNumber, $resultCode, $resultDescription, $resultTime, $success);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($conn);
*/
// Respond with 200 OK to acknowledge receipt
http_response_code(200);
echo json_encode(["status" => "callback received"]);
} else {
// Missing required fields
http_response_code(400);
echo json_encode(["error" => "Invalid callback payload"]);
}
?>

View File

@@ -0,0 +1,5 @@
<?php
$data=file_get_contents('php://input');
echo 'This is the correct path.';
?>

View File

@@ -0,0 +1 @@
{"Hi":"Hello"}

View File

@@ -0,0 +1,2 @@
2025-09-01 09:02:45 - {"receipt_number":"10887331688742698041","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-01 11:02:44","transaction_id":"cedar6","success":false}
2025-09-01 09:03:42 - {"receipt_number":"10003173421101776517","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-01 11:03:42","transaction_id":"cedar7","success":false}

View File

@@ -0,0 +1 @@
2025-09-08 08:05:34 - {"receipt_number":"10004158814706547506","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-08 10:05:33","transaction_id":"cedar10","success":false}

View File

@@ -0,0 +1,15 @@
2025-09-17 09:10:09 - {"receipt_number":"CIH0000000","result_description":": Invalid Account Number","result_code":2002,"result_time":"2025-09-17 11:10:08","transaction_id":"cedar12","success":false}
2025-09-17 09:10:55 - {"receipt_number":"10216260777279973276","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-17 11:10:55","transaction_id":"cedar11","success":false}
2025-09-17 09:21:36 - {"receipt_number":"CIH22CNO3O4","result_description":": Process service request successfully.","result_code":0,"result_time":"2025-09-17 11:21:35","transaction_id":"cedar14","success":true}
2025-09-17 09:26:28 - {"receipt_number":"CIH42CNO3O6","result_description":": Balance insufficient.","result_code":2006,"result_time":"2025-09-17 11:26:27","transaction_id":"cedar15","success":false}
2025-09-17 09:31:58 - {"receipt_number":"10395173983942501327","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-17 11:31:57","transaction_id":"cedar16","success":false}
2025-09-17 09:35:40 - {"receipt_number":"CIH32CNO3OF","result_description":": Balance insufficient.","result_code":2006,"result_time":"2025-09-17 11:35:39","transaction_id":"cedar19","success":false}
2025-09-17 09:35:52 - {"receipt_number":"10839014874366890664","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-17 11:35:51","transaction_id":"cedar17","success":false}
2025-09-17 09:36:25 - {"receipt_number":"10016670262346814213","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-17 11:36:24","transaction_id":"cedar18","success":false}
2025-09-17 09:41:23 - {"receipt_number":"CIH92CNO3OL","result_description":": Balance insufficient.","result_code":2006,"result_time":"2025-09-17 11:41:22","transaction_id":"cedar22","success":false}
2025-09-17 09:41:41 - {"receipt_number":"10694042274274847334","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-17 11:41:40","transaction_id":"cedar20","success":false}
2025-09-17 09:42:11 - {"receipt_number":"10310137165383093703","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-17 11:42:10","transaction_id":"cedar21","success":false}
2025-09-17 09:46:38 - {"receipt_number":"CIH32CNO3OP","result_description":": Process service request successfully.","result_code":0,"result_time":"2025-09-17 11:46:37","transaction_id":"cedar23","success":true}
2025-09-17 09:49:16 - {"receipt_number":"CIH0000000","result_description":": Amount invalid.","result_code":2004,"result_time":"2025-09-17 11:49:15","transaction_id":"cedar24","success":false}
2025-09-17 09:52:11 - {"receipt_number":"10716865356500456126","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-17 11:52:10","transaction_id":"cedar25","success":false}
2025-09-17 09:54:17 - {"receipt_number":"10988964508151890908","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-09-17 11:54:17","transaction_id":"cedar26","success":false}

View File

@@ -0,0 +1,2 @@
2025-11-19 11:35:02 - {"receipt_number":"10478257471611622849","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-11-19 13:34:56","transaction_id":"12345666","success":false}
2025-11-19 11:46:47 - {"receipt_number":"10847714824278927203","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-11-19 13:46:41","transaction_id":"12345667","success":false}

View File

@@ -0,0 +1,2 @@
2025-11-26 11:22:08 - {"receipt_number":"10342708118343667220","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-11-26 13:22:02","transaction_id":"kiddo2","success":false}
2025-11-26 11:25:22 - {"receipt_number":"10498981254538029140","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-11-26 13:25:15","transaction_id":"kiddo3","success":false}

View File

@@ -0,0 +1,14 @@
2025-12-18 07:59:16 - {"receipt_number":"10225876409109341761","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-12-18 09:59:15","transaction_id":"12345771","success":false}
2025-12-18 08:08:28 - {"receipt_number":"CLI0000000","result_description":": Invalid Account Number","result_code":2002,"result_time":"2025-12-18 10:08:28","transaction_id":"12345772","success":false}
2025-12-18 08:16:03 - {"receipt_number":"CLI72HP9KFT","result_description":": Process service request successfully.","result_code":0,"result_time":"2025-12-18 10:16:02","transaction_id":"12345773","success":true}
2025-12-18 08:41:39 - {"receipt_number":"CLI42HP9KG0","result_description":": Process service request successfully.","result_code":0,"result_time":"2025-12-18 10:41:38","transaction_id":"12345775","success":true}
2025-12-18 08:42:12 - {"receipt_number":"10615975978933751017","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-12-18 10:42:11","transaction_id":"12345774","success":false}
2025-12-18 09:04:18 - {"receipt_number":"CLI02HP9KG6","result_description":": Process service request successfully.","result_code":0,"result_time":"2025-12-18 11:04:17","transaction_id":"12345778","success":true}
2025-12-18 09:05:26 - {"receipt_number":"10025084431939463372","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-12-18 11:05:25","transaction_id":"12345777","success":false}
2025-12-18 09:08:56 - {"receipt_number":"CLI22HP9KG8","result_description":": Balance insufficient.","result_code":2006,"result_time":"2025-12-18 11:08:56","transaction_id":"12345779","success":false}
2025-12-18 09:11:53 - {"receipt_number":"CLI52HP9KGB","result_description":": Process service request successfully.","result_code":0,"result_time":"2025-12-18 11:11:52","transaction_id":"12345780","success":true}
2025-12-18 09:13:41 - {"receipt_number":"CLI72HP9KGD","result_description":": Rule limited.","result_code":2005,"result_time":"2025-12-18 11:13:40","transaction_id":"12345781","success":false}
2025-12-18 09:15:34 - {"receipt_number":"CLI92HP9KGF","result_description":": Balance insufficient.","result_code":2006,"result_time":"2025-12-18 11:15:34","transaction_id":"12345782","success":false}
2025-12-18 09:16:48 - {"receipt_number":"CLI22HP9KGI","result_description":": Balance insufficient.","result_code":2006,"result_time":"2025-12-18 11:16:48","transaction_id":"12345783","success":false}
2025-12-18 09:27:41 - {"receipt_number":"10280516611960183870","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-12-18 11:27:40","transaction_id":"12345785","success":false}
2025-12-18 09:33:07 - {"receipt_number":"10729630476149503786","result_description":": Process service request successfully.","result_code":402,"result_time":"2025-12-18 11:33:06","transaction_id":"12345786","success":false}

View File

@@ -0,0 +1 @@
2026-01-29 23:40:42 - {"receipt_number":"10230529140546671414","result_description":": Process service request successfully.","result_code":402,"result_time":"2026-01-30 01:40:42","transaction_id":"12345789","success":false}

View File

@@ -0,0 +1,2 @@
2026-01-30 00:41:32 - {"receipt_number":"10369576091684466032","result_description":": Process service request successfully.","result_code":402,"result_time":"2026-01-30 02:41:31","transaction_id":"10388103","success":false}
2026-01-30 00:59:38 - {"receipt_number":"10345565245761348404","result_description":": Process service request successfully.","result_code":402,"result_time":"2026-01-30 02:59:37","transaction_id":"10389339","success":false}

View File

@@ -0,0 +1 @@
2026-02-03 00:00:53 - {"receipt_number":"10931861926510111848","result_description":": Process service request successfully.","result_code":402,"result_time":"2026-02-03 02:00:52","transaction_id":"3805907571","success":false}

View File

@@ -0,0 +1,311 @@
<?php
$incoming=file_get_contents("php://input");
$details=json_decode($incoming,true);
$transactionId=$details['transactionId'];
$amount=$details['amount'];
$msisdn=$details['msisdn'];
$description=$details['description'];
$baseURL="https://devpayouts.tnmmpamba.co.mw/api";
$wallet="505073";
$password="N8O7L0vpl5mflfwHzf4DSle9bToV*";//CEDAR PASSWORD & All other wallets
$res=authenticate($baseURL, $wallet, $password);
//echo print_r($res,true);
$bearerToken=$res['token'];//"102164|newoEd6QOFaTptUiGAp232jULtUmgMtaX1x2CRww4Ka2270dc49";
//echo $bearerToken;
//$res=validate_msisdn($baseURL, '265881161942', $bearerToken);
//$res=changePassword($baseURL, $bearerToken, "N8O7L0vpl5mflfwHzf4DSle9bToV*", "N8O7L0vpl5mflfwHzf4DSle9bToV*");
//$res=sendUSSDPush($baseURL, $bearerToken, $invoiceNumber, $amount, $msisdn, $description);
$result=makePayment($baseURL,$bearerToken,$msisdn, $amount, $transactionId, $description);
echo (print_r($result,true));
if (!isset($result['http_code'])) {
// Network or cURL failure
echo "SYSTEM ERROR: " . $result['message'];
exit;
}
switch ($result['http_code']) {
case 200:
// Completed successfully
$transID = $result['response']['data']['transaction_id'] ?? '';
$receipt = $result['response']['data']['receipt_number'] ?? '';
echo "SUCCESS: Payment completed. Transaction ID: $transID Receipt: " . $receipt;
//mark transaction as SUCCESSFUL in db later
break;
case 202:
// Accepted but pending
echo "PENDING: Transaction accepted and processing.";
//mark transaction as PENDING / SUSPENSE in the db
break;
case 400:
// Invalid request
echo "FAILED: Bad request. Check parameters.";
//mark transaction as FAILED in the db
break;
case 503:
// Service unavailable
echo "FAILED: Service unavailable. Try again later.";
//mark transaction as FAILED or RETRY later after setting a retry cron
break;
default:
echo "UNKNOWN RESPONSE: " . $result['http_code'];
//unkown response, do nothing
}
function makePayment($baseURL,$bearerToken,$msisdn, $amount, $transactionId, $description)
{
$url = $baseURL . "/payments";
// Request payload
$payload = array(
"msisdn" => $msisdn,
"amount" => (int)$amount,
"transaction_id" => $transactionId,
"narration" => $description
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Bearer " . $bearerToken
));
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return array(
"status" => "ERROR",
"message" => "cURL error: " . $error
);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$responseData = json_decode($response, true);
return array(
"http_code" => $httpCode,
"response" => $responseData
);
}
function sendUSSDPush($baseURL, $token, $invoiceNumber, $amount, $msisdn, $description) {
// Endpoint
$url = rtrim($baseURL, "/") . "/invoices";
// Prepare payload
$data = [
"invoice_number" => $invoiceNumber,
"amount" => (int)$amount,
"msisdn" => $msisdn,
"description" => $description
];
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $token,
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return false;
}
// Close connection
curl_close($ch);
// Decode and return response
return $response;//json_decode($response, true);
}
function changePassword($baseURL, $token,$newPassword, $newPasswordConfirmation) {
// Endpoint URL
$url = rtrim($baseURL, "/") . "/password";
// Prepare data
$data = [
"new_password" => $newPassword,
"new_password_confirmation" => $newPasswordConfirmation
];
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH"); // PATCH request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $token,
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute and capture response
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return false;
}
// Close connection
curl_close($ch);
// Decode JSON response
return json_decode($response, true);
}
function validate_msisdn($baseURL, $msisdn, $bearerToken)
{
// Ensure proper endpoint format
$url = rtrim($baseURL, '/') . '/payments/validate/' . urlencode($msisdn);
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $bearerToken,
'Accept: application/json'
]);
// Execute the request
$response = curl_exec($ch);
// Handle cURL error
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
if ($httpCode === 200 && isset($result['data']['full_name'])) {
return [
'success' => true,
'full_name' => $result['data']['full_name']
];
} else {
return [
'success' => false,
'error' => $result['message'] ?? 'Unknown error',
'details' => $result['errors'] ?? []
];
}
}
function authenticate($baseURL, $wallet, $password)
{
// Endpoint URL
$url = rtrim($baseURL, '/') . '/authenticate';
// JSON payload
$postData = json_encode([
'wallet' => $wallet,
'password' => $password
]);
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response
curl_setopt($ch, CURLOPT_POST, true); // Use POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);// Set the request body
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
]);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
// Check if token is present
if ($httpCode === 200 && isset($result['data']['token'])) {
return [
'success' => true,
'token' => $result['data']['token'],
'expires_at' => $result['data']['expires_at']
];
} else {
return [
'success' => false,
'error' => $result['message'] ?? 'Unknown error',
'details' => $result['errors'] ?? []
];
}
}
?>

View File

@@ -0,0 +1,147 @@
<?php
$incoming=file_get_contents("php://input");
$details=json_decode($incoming,true);
$transactionId=$details['transactionId'];
//$token=$details['token'];
$baseURL="https://devpayouts.tnmmpamba.co.mw/api";
$wallet="505073";
$password="N8O7L0vpl5mflfwHzf4DSle9bToV*";//CEDAR PASSWORD & All other wallets
$res=authenticate($baseURL, $wallet, $password);
//echo print_r($res,true);
$bearerToken=$res['token'];
$res=checkPaymentStatus($transactionId, $bearerToken, $baseURL);
echo(print_r($res,true));
function checkPaymentStatus($transactionId, $bearerToken, $baseURL)
{
$url = rtrim($baseURL, '/') . "/payments/" . urlencode($transactionId);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $bearerToken,
"Accept: application/json"
),
CURLOPT_TIMEOUT => 30
));
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return array(
"status" => "ERROR",
"message" => "cURL error: " . $error
);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$decoded = json_decode($response, true);
if ($httpCode !== 200 || !$decoded) {
return array(
"status" => "FAILED",
"http_code" => $httpCode,
"raw" => $response
);
}
// Safely extract data
$data = $decoded['data'] ?? [];
$success = $data['success'] ?? false;
$resultCode = $data['result_code'] ?? null;
$receipt = $data['receipt_number'] ?? null;
// Determine final status
if ($success === true && $resultCode === "0") {
$finalStatus = "SUCCESS";
} else {
$finalStatus = "PENDING"; // default fallback
}
return array(
"status" => $finalStatus,
"transaction_id" => $data['transaction_id'] ?? $transactionId,
"receipt_number" => $receipt,
"result_code" => $resultCode,
"result_description" => $data['result_description'] ?? null,
"created_at" => $data['created_at'] ?? null,
"message" => $decoded['message'] ?? null,
"raw_response" => $decoded
);
}
function authenticate($baseURL, $wallet, $password)
{
$url = rtrim($baseURL, '/') . '/authenticate';
$postData = json_encode([
'wallet' => $wallet,
'password' => $password
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response
curl_setopt($ch, CURLOPT_POST, true); // Use POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);// Set the request body
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
]);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
// Check if token is present
if ($httpCode === 200 && isset($result['data']['token'])) {
return [
'success' => true,
'token' => $result['data']['token'],
'expires_at' => $result['data']['expires_at']
];
} else {
return [
'success' => false,
'error' => $result['message'] ?? 'Unknown error',
'details' => $result['errors'] ?? []
];
}
}
?>

View File

@@ -0,0 +1,216 @@
<?php
$incoming=file_get_contents("php://input");
$details=json_decode($incoming,true);
$invoiceNumber=$details['invoiceNumber'];
$amount=$details['amount'];
$msisdn=$details['msisdn'];
$description=$details['description'];
$baseURL="https://devpayouts.tnmmpamba.co.mw/api";
$wallet="505072";
$password="N8O7L0vpl5mflfwHzf4DSle9bToV*";//CEDAR PASSWORD & All other wallets
$res=authenticate($baseURL, $wallet, $password);
echo print_r($res,true);
$bearerToken=$res['token'];//"102164|newoEd6QOFaTptUiGAp232jULtUmgMtaX1x2CRww4Ka2270dc49";
echo $bearerToken;
//$res=validate_msisdn($baseURL, '265881161942', $bearerToken);
//$res=changePassword($baseURL, $bearerToken, "N8O7L0vpl5mflfwHzf4DSle9bToV*", "N8O7L0vpl5mflfwHzf4DSle9bToV*");
$res=sendUSSDPush($baseURL, $bearerToken, $invoiceNumber, $amount, $msisdn, $description);
echo (print_r($res,true));
function sendUSSDPush($baseURL, $token, $invoiceNumber, $amount, $msisdn, $description) {
// Endpoint
$url = rtrim($baseURL, "/") . "/invoices";
// Prepare payload
$data = [
"invoice_number" => $invoiceNumber,
"amount" => (int)$amount,
"msisdn" => $msisdn,
"description" => $description
];
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $token,
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return false;
}
// Close connection
curl_close($ch);
// Decode and return response
return $response;//json_decode($response, true);
}
function changePassword($baseURL, $token,$newPassword, $newPasswordConfirmation) {
// Endpoint URL
$url = rtrim($baseURL, "/") . "/password";
// Prepare data
$data = [
"new_password" => $newPassword,
"new_password_confirmation" => $newPasswordConfirmation
];
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH"); // PATCH request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $token,
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute and capture response
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return false;
}
// Close connection
curl_close($ch);
// Decode JSON response
return json_decode($response, true);
}
function validate_msisdn($baseURL, $msisdn, $bearerToken)
{
// Ensure proper endpoint format
$url = rtrim($baseURL, '/') . '/payments/validate/' . urlencode($msisdn);
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $bearerToken,
'Accept: application/json'
]);
// Execute the request
$response = curl_exec($ch);
// Handle cURL error
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
if ($httpCode === 200 && isset($result['data']['full_name'])) {
return [
'success' => true,
'full_name' => $result['data']['full_name']
];
} else {
return [
'success' => false,
'error' => $result['message'] ?? 'Unknown error',
'details' => $result['errors'] ?? []
];
}
}
function authenticate($baseURL, $wallet, $password)
{
// Endpoint URL
$url = rtrim($baseURL, '/') . '/authenticate';
// JSON payload
$postData = json_encode([
'wallet' => $wallet,
'password' => $password
]);
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response
curl_setopt($ch, CURLOPT_POST, true); // Use POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);// Set the request body
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
]);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
curl_close($ch);
return [
'success' => false,
'error' => 'Curl error: ' . curl_error($ch)
];
}
// Get HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Decode JSON response
$result = json_decode($response, true);
// Check if token is present
if ($httpCode === 200 && isset($result['data']['token'])) {
return [
'success' => true,
'token' => $result['data']['token'],
'expires_at' => $result['data']['expires_at']
];
} else {
return [
'success' => false,
'error' => $result['message'] ?? 'Unknown error',
'details' => $result['errors'] ?? []
];
}
}
?>

View File

@@ -0,0 +1,60 @@
<?php
$incoming=file_get_contents("php://input");
$details=json_decode($incoming,true);
$invoiceNumber=$details['invoiceNumber'];
$token=$details['token'];
$baseURL="https://devpayouts.tnmmpamba.co.mw/api";
//$res=authenticate($baseURL, $wallet, $password);
$bearerToken=$token;//"102164|newoEd6QOFaTptUiGAp232jULtUmgMtaX1x2CRww4Ka2270dc49";
$res=checkInvoiceStatus($invoiceNumber, $bearerToken, $baseURL);
echo $res;//(print_r($res,true));
function checkInvoiceStatus($invoiceNumber, $bearerToken, $baseURL) {
// Build request URL
$url = rtrim($baseURL, '/') . "/invoices/" . urlencode($invoiceNumber);
// Initialize cURL
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . $bearerToken,
"Accept: application/json"
]
]);
// Execute the request
$response = curl_exec($ch);
// Handle errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
curl_close($ch);
return null;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Check for successful response
if ($httpCode === 200 && $response) {
return $response;//json_decode($response, true);
} else {
echo "Request failed. HTTP Code: " . $httpCode . "\nResponse: " . $response;
return null;
}
}
?>