A custom MPesa (Tanzania) payment gateway integration built with Laravel 11 conventions.
````markdown
# π M-Pesa Payment Gateway for Laravel / PHP Projects
A **custom Laravel M-Pesa Payment Gateway** built with Laravel 11+ standards.
Supports **STK Push**, secure credential handling, and integrates easily into **any Laravel or PHP project** β perfect for developers targeting **Kenya, Tanzania, and East Africa**.
---
## π Features
- β
**STK Push Payment Integration**
- β
**Reusable Service Class (`MpesaHelper`)**
- β
**Live/Sandbox Environment Support**
- β
**Custom Config File Support**
- β
**Modular & Extendable Code Structure**
- β
**Works with Laravel (9.x to 11.x) & Bagisto**
---
## π¦ Installation
Install via Composer:
```bash
composer require godfrey-em/mpesa-payment-gateway
````
Publish the configuration file (if applicable):
```bash
php artisan vendor:publish --provider="Webkul\Mpesa\Providers\MpesaServiceProvider"
```
---
## βοΈ Configuration
Add the following to your `.env` file:
```env
MPESA_ENV=sandbox
MPESA_CONSUMER_KEY=your-consumer-key
MPESA_CONSUMER_SECRET=your-consumer-secret
MPESA_SHORTCODE=your-shortcode
MPESA_PASSKEY=your-passkey
MPESA_CALLBACK_URL=
yourdomain.com
```
Make sure your `config/mpesa.php` is correctly mapped to use these variables.
---
## π§ Usage Example
Use the service class to initiate an STK push request:
```php
use Webkul\Mpesa\Lib\MpesaHelper;
public function pay(Request $request)
{
$mpesa = new MpesaHelper();
$response = $mpesa->stkPush([
'amount' => 500,
'phone' => '2557XXXXXXXX',
'reference' => 'Order1234',
'description' => 'Purchase Payment',
]);
return response()->json($response);
}
```
> π **Note**: Make sure you validate user input (especially phone numbers) before passing to the gateway.
---
## π Directory Overview
```
Mpesa/
βββ config/
β βββ mpesa.php
βββ src/
β βββ Lib/
β β βββ MpesaHelper.php
β βββ Payment/
β βββ Providers/
βββ tests/
βββ README.md
```
---
## π¨βπ» Author
**Godfrey Ernest Mapunda**
* GitHub: @GODFREY-EM
* Emai β¦