143 lines
3.5 KiB
PHP
143 lines
3.5 KiB
PHP
<?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'] ?? []
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
?>
|