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 …