
How To Intergrate M-Pesa Check Transaction Status With Your Website Php
In this tutorial Ill show you how to intergrate m-pesa check transaction status with your website in php
1.Create a check transaction status file and paste in the following code:
access_token;
curl_close($curl);
/*making the request */
$tstatus_url = 'https://sandbox.safaricom.co.ke/mpesa/transactionstatus/v1/query';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $tstatus_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Bearer '.$access_token)); //setting custom header
$curl_post_data = array(
//Fill in the request parameters with valid values
'Initiator' => '',
'SecurityCredential' => '',
'CommandID' => 'TransactionStatusQuery',
'TransactionID' => '',
'PartyA' => '', // shortcode 1
'IdentifierType' => '4',
'ResultURL' => '',
'QueueTimeOutURL' => '',
'Remarks' => '',
'Occasion' => ''
);
$data_string = json_encode($curl_post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
$curl_response = curl_exec($curl);
print_r($curl_response);
echo $curl_response;
?>
2.Create a callback file and paste in the below code:
<?php
$callbackResponse = file_get_contents(‘php://input’);
$logFile = “transaction-status-response.json”;
$log = fopen($logFile, “a”);
fwrite($log, $callbackResponse);
fclose($log);