Last active
June 23, 2025 10:37
-
-
Save ovicko/4fe02adf537278f33e54f1f7dbbc68b3 to your computer and use it in GitHub Desktop.
MPESA test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function actionPay() { | |
$tillNumber = 174379; | |
$storeNumber = 174379; | |
$customerPhoneNumber = 2547xxxx; | |
$timeStamp = date("Ymdhis"); | |
$passKey = "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919"; | |
$password = base64_encode($storeNumber . $passKey . $timeStamp); | |
// $token = $this->getToken(); | |
$token ="GGpPaGYBCs3VLl7W2Bl0KzQ3h5MP"; | |
$ch2 = curl_init(); | |
curl_setopt($ch2, CURLOPT_URL, "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"); | |
curl_setopt($ch2, CURLOPT_HTTPHEADER, array( | |
'Content-Type:application/json', | |
'Authorization:Bearer ' . $token) | |
); | |
$postData = [ | |
'BusinessShortCode' => $storeNumber,//store number | |
'Password' => $password, | |
'Timestamp' => $timeStamp, | |
'TransactionType' => "CustomerBuyGoodsOnline", | |
'Amount' => 1, | |
'PartyA' => $customerPhoneNumber, | |
'PartyB' => $tillNumber,//till number | |
'PhoneNumber' => $customerPhoneNumber, | |
'CallBackURL' => $link, | |
'AccountReference' => "TEST_".time(), | |
'TransactionDesc' => "Test transaction", | |
]; | |
$postDataString = json_encode($postData); | |
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch2, CURLOPT_POST, true); | |
curl_setopt($ch2, CURLOPT_POSTFIELDS, $postDataString); | |
curl_setopt($ch2, CURLOPT_HEADER, false); | |
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 0); | |
$apiResponse = json_decode(curl_exec($ch2),true); | |
print_r($apiResponse); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment