Skip to content

Instantly share code, notes, and snippets.

@levizwannah
Last active August 18, 2022 09:37
Show Gist options
  • Save levizwannah/34d18c81da11110aa6885feb80d4cfbb to your computer and use it in GitHub Desktop.
Save levizwannah/34d18c81da11110aa6885feb80d4cfbb to your computer and use it in GitHub Desktop.
mpesa-sdk-php-set-up
<?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