1. Go to this page and download the library: Download nevar/mpesa library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use MPESA\Services\OnlinePaymentService;
class PaymentController extends Controller
{
public function requestPayment(Request $request,OnlinePaymentService $stk)
{
// phone number
$user_phone_number = "254712345678"; # insert user phone number
$amount = 50; # insert amount payable
// this is optional if you want to overide the IPN on your .env
$stk->callBackURL = "http://8bbea5f4.ngrok.io/api/mpesa/response-callback";
// request for payment
$stk->initiateSTKCheckout($amount,$user_phone_number);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.