Last active
May 8, 2023 17:33
-
-
Save levizwannah/d378be75ab2b33afdb4f1eb6b4806c25 to your computer and use it in GitHub Desktop.
STK push for paybill number using properties as setters
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->phone("07123456789") // handles +2547, 07, and 2547 | |
->amount(1) | |
->callback("https://callback.url") | |
->reference("A43765") // paybill account number, but still optional - defaults to payment. | |
->description("optional transaction description"); | |
$stk->paybill(); | |
$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