Last active
August 18, 2022 09:37
-
-
Save levizwannah/34d18c81da11110aa6885feb80d4cfbb to your computer and use it in GitHub Desktop.
mpesa-sdk-php-set-up
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"); | |
use LeviZwannah\MpesaSdk\Mpesa; | |
$config = [ | |
"key" => "Consumer Key", | |
"secret" => "Consumer Secret", | |
"code" => "Business short code", | |
]; | |
$stk = Mpesa::new()->configure($config)->till(123456)->stk(); | |
$stk->phone("0712345678")->amount(200) | |
->callback("https://callback.url") | |
->buygoods(); | |
$stk->push(); | |
if($stk->error()) { | |
$error = $stk->error(); | |
echo "Error: code: $error->code and message: $error->message \n"; | |
} | |
if(!$stk->accepted()) echo "hmm!, response code != 0\n"; | |
print_r( (array)$stk->response() ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment