Last active
January 30, 2023 10:25
-
-
Save levizwannah/0d75710c5b86d39060fb718076045b17 to your computer and use it in GitHub Desktop.
STK push for Till number using properties
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
<?php | |
require(__DIR__ . "/vendor/autoload.php"); | |
// or read getting started if the vendor is not available | |
use LeviZwannah\MpesaSdk\Mpesa; | |
$config = [ | |
"key" => "consumer Key", | |
"secret" => "consumer secret", | |
"code" => "business short code", | |
"passkey" => "passkey for stk push" | |
]; | |
$mpesa = Mpesa::new()->configure($config); | |
$stk = $mpesa->stk(); | |
$stk->till(1234567); | |
$stk->phone("07123456789") // handles +2547, 07, and 2547 | |
->amount(1) | |
->callback("https://callback.url") | |
->reference("optional account number") | |
->description("optional transaction description"); | |
$stk->buygoods(); | |
$stk->push(); // or $stk(); | |
// check error | |
$error = $stk->error(); | |
if($error){ | |
echo "Error with code: $error->code and message: $error->message occurred"; | |
} | |
// check acceptance | |
if(!$stk->accepted()){ | |
echo "Request not accepted. Look at the response to see"; | |
} | |
// get the response | |
$response = $stk->response(); | |
// ... | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment