PHPackages                             crysoft/mpesa-bundle - 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. crysoft/mpesa-bundle

ActiveLibrary[API Development](/categories/api)

crysoft/mpesa-bundle
====================

Symfony Bundle for Safaricom Online Mpesa API Implementation

v1.0.0(8y ago)011MITPHPPHP &gt;=5.6.0

Since Jun 9Pushed 8y ago1 watchersCompare

[ Source](https://github.com/creative-junk/MpesaBundle)[ Packagist](https://packagist.org/packages/crysoft/mpesa-bundle)[ RSS](/packages/crysoft-mpesa-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

SYMFONY M-PESA API Bundle
=========================

[](#symfony-m-pesa-api-bundle)

This is a Symfony Bundle for the integration Safaricom's M-Pesa Online API. The API allows a merchant to initiate Online C2B (Paybill via web) transactions. The merchant submits authentication details, transaction details, callback url and callback method.

Normally after request submission, the merchant receives instant feedback with validity status of their requests but this bundle implements a custom request for that status. The C2B API handles customer validation and authentication via USSD push. The customer then confirms the transaction.

Requirements
------------

[](#requirements)

- PHP 5.6 or above
- Symfony 2.6 or above

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

[](#installation)

To install this bundle, run the command below and you will get the latest version by \[Packagist\]\[4\].

```
composer require crysoft/mpesa-bundle
```

Load the Bundle
---------------

[](#load-the-bundle)

Load bundle in AppKernel.php:

```
new Crysoft\MpesaBundle\CrysoftMpesaBundle(),
```

Configuration of the Bundle
---------------------------

[](#configuration-of-the-bundle)

Configuration in config.yml:

```
crysoft_mpesa:
    mpesa:

        endpoint:           https://safaricom.co.ke/mpesa_online/lnmo_checkout_server.php?wsdl
        callback_url:       http://yourcallbackurl.com/successurl
        callback_method:    POST
        paybill_number:     123456
        pass_key:           verysecretlongkey

        ...
```

### Config Options

[](#config-options)

- endpoint: [https://safaricom.co.ke/mpesa\_online/lnmo\_checkout\_server.php?wsdl](https://safaricom.co.ke/mpesa_online/lnmo_checkout_server.php?wsdl)

The M-Pesa API Endpoint. Confirm this as it might change at some point

- callback\_url:

The fully qualified callback URL to be queried by Safaricom on transaction completion.

- callback\_method: POST

The callback method to be used. Can also be GET

- paybill\_number: 123456

The merchant's Paybill number.

- pass\_key: verysecretlongkey

The SAG Passkey given by Safaricom on registration. You probably have to ask for it.

Usage
-----

[](#usage)

Usage of the Bundle is simple. Use it in your controller you have access to the Service Container using *"$this-&gt;container"* which in turn accesses the config variables.

In your controller do:

```
public function checkoutAction()
{
     //Instantiate a new Mpesa Request passing it the Service Container(Don't worry if you dont know what that is,
     //Symfony does :-) just do as i do below and you'll be fine)
     $mpesa = new Mpesa($this->container);

     //Generate a New Transaction Id unique to thsi transaction. You can generate it however you want or simply use an
     //Order ID or User ID. it's completely up to you as long as it's unique
     // We just provided this method as an easy way out for those of us too lazy to think of a different way of doing it.
     $transactionId = $mpesa->generateTransactionNumber();

     $response = $mpesa->request(2500)->from(0722000000)->usingReferenceId(456876)->usingTransactionId($transactionId)->transact();

}
```

You can just chain the method calls into one single call as shown above. This Bundle comes with a handy method named "generateTransactionNumber()" that generates a random transaction number for you to use. Take note of the generated transaction id/number as you will use it to query the status of the transaction isntead of waiting for Safaricom to make the callback.

Requesting for the Status is trivial as this bundle also provides a simple way of doing that:

```
public function checkstatusAction()
{
    //Use the same Mpesa Class as before
    $mpesa = new Mpesa($this->container);

    //Chain the requests. Note this Transaction ID has to be the EXACT same one you used for the Mpesa Transaction request above.
    $response = $mpesa->usingTransactionId($transactionId)->requestStatus();

    //And just to make your life easier we created another class in the Bundle to run through the response from Mpesa and give you the Status

    //Use the response above and pass it to the Bundle's MpesaStatus Class
    $mpesaStatus = new MpesaStatus($response);

    //Use the Classes Getter methods to get the Bits in the Response. Here is an example of how to do it

        $customerNumber             =       $mpesaStatus->getCustomerNumber();
        $transactionAmount          =       $mpesaStatus->getTransactionAmount();
        $transactionStatus          =       $mpesaStatus->getTransactionStatus();
        $transactionDate            =       $mpesaStatus->getTransactionDate();
        $mPesaTransactionId         =       $mpesaStatus->getMpesaTransactionId();
        $merchantTransactionId      =       $mpesaStatus->getMerchantTransactionId();
        $transactionDescription     =       $mpesaStatus->getTransactionDescription();
}
```

You dont have to name your variables as we have named them, you can name them anything. And that's it. You are good to go

\##Testing

Be careful when testing this, Paybill will deduct the amount from Mpesa. You can use kes 10 which is the minimum allowed.

\##License

The M-Pesa Package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3256d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad79b94a7f84a21f17f7627b116b668e8f58b94d35c87607ee6e064ec8bb0945?d=identicon)[crysoft](/maintainers/crysoft)

---

Top Contributors

[![creative-junk](https://avatars.githubusercontent.com/u/15978834?v=4)](https://github.com/creative-junk "creative-junk (4 commits)")

---

Tags

apisymfonytransactionsmpesasafaricommpesa-api

### Embed Badge

![Health badge](/badges/crysoft-mpesa-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/crysoft-mpesa-bundle/health.svg)](https://phpackages.com/packages/crysoft-mpesa-bundle)
```

###  Alternatives

[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)[kabangi/mpesa

M-Pesa API implementation

453.0k2](/packages/kabangi-mpesa)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[welp/mailchimp-bundle

MailChimp API V3 Symfony Bundle

45360.3k1](/packages/welp-mailchimp-bundle)[nilportugues/jsonapi-bundle

Symfony 2 &amp; 3 JSON API Transformer Package

11446.0k](/packages/nilportugues-jsonapi-bundle)[rekalogika/mapper

An object mapper for PHP and Symfony. Maps an object to another object. Primarily used for transforming an entity to a DTO and vice versa.

3847.7k1](/packages/rekalogika-mapper)

PHPackages © 2026

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