Last active
August 23, 2022 02:00
-
-
Save levizwannah/313bea4e2c8e6bb1cc0fb9b62d1762d9 to your computer and use it in GitHub Desktop.
Using the configure method Mpesa SDK PHP
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_once(__DIR__ . "/vendor/autoload.php"); | |
use LeviZwannah\MpesaSdk\Mpesa; | |
$config = [ | |
"key" => "Consumer Key", // consumer key | |
"secret" => "Consumer Secret", // consumer secret | |
"code" => "123456", // business short code | |
"env" => "live" //set environment to live or sandbox | |
]; | |
// using the configure method | |
$mpesa = Mpesa::new(); | |
$mpesa->configure($config); | |
// using the mpesa properties | |
$mpesa->key("consumer key") | |
->secret("consumer secret") | |
->code(123456) | |
->env("live"); | |
$stk = $mpesa->stk(); //stk is of type STK | |
// stk requires a till number, passkey, amount, phone, a callback | |
// let set them using the configure method | |
$stk->configure([ | |
"till" => 234567, | |
"passkey" => "Passkey from live app", | |
"phone" => "0712345678", | |
"amount" => 1, | |
"callback" => "https://callback.url" | |
]); | |
// or lets use the properties of stk | |
$stk->till(23456) | |
->passkey("passkey") | |
->callback("https://callback.url"); | |
// then some stuff happens here... | |
$stk->phone("0712345678") | |
->amount(1) | |
->push(); | |
// ... | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment