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. [API Development](/categories/api)
4. /
5. vptrading/safaricom-ussd

ActiveLibrary[API Development](/categories/api)

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

Easy package to ease your safaricom integration

1.0.6(1y ago)1193MITPHP

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 yesterday

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 52% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

623d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/86159029?v=4)[vptrading](/maintainers/vptrading)[@VPTrading](https://github.com/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

[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.6k3](/packages/defstudio-telegraph)[resend/resend-laravel

Resend for Laravel

1222.7M9](/packages/resend-resend-laravel)[smodav/mpesa

M-Pesa API implementation

16467.9k1](/packages/smodav-mpesa)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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