PHPackages                             vptrading/safaricom-ussd - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vptrading/safaricom-ussd

ActiveLibrary

vptrading/safaricom-ussd
========================

Easy package to ease your safaricom integration

1.0.6(1y ago)1147MITPHP

Since Oct 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/VP-Trading/safaricom-ussd)[ Packagist](https://packagist.org/packages/vptrading/safaricom-ussd)[ Docs](https://github.com/vp-trading/safaricom-ussd)[ RSS](/packages/vptrading-safaricom-ussd/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (9)Used By (0)

[![VP Logo](/src/imgs/logo.png)](https://vptrading.et)

Laravel Package For
 Safaricom USSD
===================================

[](#laravel-package-for-safaricom-ussd)

[![Latest Version on Packagist](https://camo.githubusercontent.com/eb38f8f4295fed0ca0cb05843e9c7f37682d8606f235b8ee2c5de5663b2e549f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f767074726164696e672f736166617269636f6d2d757373642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vptrading/safaricom-ussd)[![Total Downloads](https://camo.githubusercontent.com/dca3a027f09f75ccfc2694e26f794dfec35a79dcd43e3319f8b7886a74975171/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f767074726164696e672f736166617269636f6d2d757373642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vptrading/safaricom-ussd)

This Laravel package is a featherweight package to integrate Safaricom MPesa.

Installation
------------

[](#installation)

Via Composer

```
composer require vptrading/safaricom-ussd
```

Run the artisan command to publish the Vptrading\\SafaricomUssd configuration file.

```
php artisan vendor:publish --provider="Vptrading\SafaricomUssd\SafaricomUssdServiceProvider"
```

Usage
-----

[](#usage)

### Send Push

[](#send-push)

In order to send a buy request using MPesa all you have to do is import the SafaricomUssd Facade where you want to use it and call the push method. The SafaricomUssd::push() method accepts five parameters, these are: Amount, Phone, Reference Number, a `nullable` Description and `nullable` array of ReferenceData (Refer to the Safaricom MPesa Documentation for the description of ReferenceData).

**Example**

```
use Vptrading\SafaricomUssd\Facades\SafaricomUssd;

$response = SafaricomUssd::push(1, '0912345678', 'VP_212fw323r3', 'Pay for Good', "ReferenceData":[
    {
        "Key": "CashierName",
        "Value": "Test User"
    },
    {
        "Key": "CashierNumber",
        "Value": "251712121212"
    },
    {
        "Key": "CustomerTINNumber",
        "Value": "0012345678"
    }
]);
```

When calling the method if successful, it will respond with the following.

**Example**

```
{
    "MerchantRequestID": "850ee93b",
    "CheckoutRequestID": "ws_CO_1710202417354636158753",
    "ResponseCode": "0",
    "ResponseDescription": "Request accepted for processing",
    "CustomerMessage": "Request accepted for processing"
}
```

### Deconstruct Callback Data

[](#deconstruct-callback-data)

The next is being notified when a payment is successful. After the user has paid the amount described, Safaricom MPesa will send you a notification on the Result URL you specified in the safaricom-uss.php config file.

**Example Data**

```
{"Envelope":{"Body":{"stkCallback":{"MerchantRequestID":"b36272fa","CheckoutRequestID":"ws_CO_1710202412231281053980","ResultCode":3002,"ResultDesc":"No response from user.","CallbackMetadata":{"Item":[{"Name":"MpesaReceiptNumber"},{"Name":"Amount"},{"Name":"TransactionDate"},{"Name":"PhoneNumber","Value":251777713780}]}}}}}
```

In order to decode this, the package provides a `SafaricomUssd::deconstruct()` method. All you need to do is put the notification string sent from Safaricom MPesa in to that method and it will be decoded.

**Example**

```
use Vptrading\SafaricomUssd\Facades\SafaricomUssd;

$decoded = SafaricomUssd::deconstruct('{"Envelope":{"Body":{"stkCallback":{"MerchantRequestID":"b36272fa","CheckoutRequestID":"ws_CO_1710202412231281053980","ResultCode":3002,"ResultDesc":"No response from user.","CallbackMetadata":{"Item":[{"Name":"MpesaReceiptNumber"},{"Name":"Amount"},{"Name":"TransactionDate"},{"Name":"PhoneNumber","Value":251777713780}]}}}}}');
```

**Result**

```
array (
  'Envelope' =>
  array (
    'Body' =>
    array (
      'stkCallback' =>
      array (
        'MerchantRequestID' => '41ec1de4',
        'CheckoutRequestID' => 'ws_CO_1710202416562907417583',
        'ResultCode' => 0,
        'ResultDesc' => 'The service request is processed successfully.',
        'CallbackMetadata' =>
        array (
          'Item' =>
          array (
            0 =>
            array (
              'Name' => 'MpesaReceiptNumber',
              'Value' => 'SJH9BVRIO3',
            ),
            1 =>
            array (
              'Name' => 'Amount',
              'Value' => 1.0,
            ),
            2 =>
            array (
              'Name' => 'TransactionDate',
              'Value' => 20241017165717,
            ),
            3 =>
            array (
              'Name' => 'PhoneNumber',
              'Value' => 251777713780,
            ),
          ),
        ),
      ),
    ),
  ),
)
```

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Alazar Kassahun](https://github.com/vptrading)
- [All Contributors](../../contributors)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

🚀 And that's it. Do your thing and Give us a star if this helped you.🚀

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

568d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1214089c541d816fb8e652c04039c17ee78639ddef4b2d1582c5a1b49d157105?d=identicon)[vptrading](/maintainers/vptrading)

---

Top Contributors

[![alazark94](https://avatars.githubusercontent.com/u/35865798?v=4)](https://github.com/alazark94 "alazark94 (20 commits)")

---

Tags

phplaravelsafaricomvpSafaricomUssdVPTrading

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vptrading-safaricom-ussd/health.svg)

```
[![Health](https://phpackages.com/badges/vptrading-safaricom-ussd/health.svg)](https://phpackages.com/packages/vptrading-safaricom-ussd)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M710](/packages/maatwebsite-excel)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[monicahq/laravel-cloudflare

Add Cloudflare ip addresses to trusted proxies for Laravel.

3372.7M4](/packages/monicahq-laravel-cloudflare)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2031.2M2](/packages/glushkovds-phpclickhouse-laravel)[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)[kra8/laravel-snowflake

Snowflake for Laravel and Lumen.

188402.3k6](/packages/kra8-laravel-snowflake)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
