Laravel M-PESA Integration Package

Maintainers

Package info

github.com/silahkosgei/mpesa

pkg:composer/silahkosgei/mpesa

Statistics

Installs: 26

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.7 2025-07-10 06:43 UTC

This package is auto-updated.

Last update: 2026-04-10 08:31:28 UTC


README

A Laravel package for integrating with Safaricom's M-PESA STK Push and B2C APIs. Simple, extensible, and production-ready.

Installation

composer require SilahKosgei/mpesa:^1.1

Then publish the configuration file:

php artisan vendor:publish --tag=mpesa-config

Configuration

Add these to your .env file:

MPESA_ENV=sandbox                      # or production
MPESA_SHORTCODE=601234
MPESA_BUY_GOODS_TILL=174379
MPESA_SHORTCODE_TYPE=PayBill          # or BuyGoods
MPESA_PASSKEY=YOUR_PASSKEY_HERE
MPESA_CONSUMER_KEY=YOUR_CONSUMER_KEY
MPESA_CONSUMER_SECRET=YOUR_CONSUMER_SECRET
MPESA_CALLBACK_URL=https://yourapp.com/api/complete-payment
MPESA_CONFIRMATION_URL=https://yourapp.com/api/confirmation-payment

Usage

Initiate STK Push

use SilahKosgei\Mpesa\Mpesa;

$mpesa = new Mpesa();

$response = $mpesa->initiateStkPush(
    '254712345678',                  // phone
    100,                             // amount
    'ORDER-12345',                   // account reference
    'Payment for Order #12345',      // description
    12345                            // reference ID for callback
);

Lookup STK Push Payment

$response = $mpesa->lookupPayment('ws_CO_123456789');

👤 Author

Silh Kosgei
📧 silakosy@gmail.com
🔗 GitHub: @silahkosgei

Version

v1.1.1