PHPackages                             beamlak/mpesa-php - 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. beamlak/mpesa-php

ActiveLibrary[API Development](/categories/api)

beamlak/mpesa-php
=================

A PHP Composer package used to integrate M-Pesa services into your PHP app

00PHP

Since Mar 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/BeamlakAschalew/mpesa-php)[ Packagist](https://packagist.org/packages/beamlak/mpesa-php)[ RSS](/packages/beamlak-mpesa-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Mpesa PHP
=========

[](#mpesa-php)

A PHP Composer package used to integrate M-Pesa services into your PHP application.

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

[](#installation)

To install the package, you need to have Composer installed. Run the following command to install the package:

```
composer require beamlak/mpesa-php
```

Configuration
-------------

[](#configuration)

Create a `.env` file in the root of your project and add the following configuration variables:

```
MPESA_CONSUMER_KEY=your_consumer_key
MPESA_CONSUMER_SECRET=your_consumer_secret
MPESA_ENV=sandbox

```

Replace `your_consumer_key` and `your_consumer_secret` with your actual M-Pesa API credentials.

Usage
-----

[](#usage)

### Initialization

[](#initialization)

To use the Mpesa class, you need to initialize it with the callback URL:

```
use Beamlak\MpesaPhp\Mpesa;

$mpesa = new Mpesa('https://www.yourcallbackurl.com');
```

### Authentication

[](#authentication)

To authenticate with the Mpesa API and obtain an access token:

```
$mpesa->authenticatePublic();
echo $mpesa->getAccessToken();
echo $mpesa->getExpiresIn();
```

### USSD Push Request

[](#ussd-push-request)

To initiate a USSD push request:

```
$response = $mpesa->ussdPush('254700000000', '100', 'TestReference', 'ThirdPartyID', '123456', 'passKey');
print_r($response);
```

### Register URL

[](#register-url)

To register confirmation and validation URLs:

```
$response = $mpesa->registerUrl('123456', 'https://www.yourcallbackurl.com/confirmation', 'https://www.yourcallbackurl.com/validation');
print_r($response);
```

### Simulate C2B Transaction

[](#simulate-c2b-transaction)

To simulate a C2B transaction:

```
$response = $mpesa->simulateC2B('123456', '254700000000', '100', 'TestReference');
print_r($response);
```

### Payout Request

[](#payout-request)

To initiate a payout request:

```
$response = $mpesa->payout('123456', '254700000000', '100', 'passKey');
print_r($response);
```

### Query Transaction Status

[](#query-transaction-status)

To query the status of a transaction:

```
$response = $mpesa->queryTransactionStatus('transactionId', '123456', 'passKey');
print_r($response);
```

### Reverse Transaction

[](#reverse-transaction)

To reverse a transaction:

```
$response = $mpesa->reverseTransaction('transactionId', '123456', '100', 'receiver', 'receiverType', 'passKey', 'originalConversationID');
print_r($response);
```

### Account Balance

[](#account-balance)

To query the account balance:

```
$response = $mpesa->accountBalance('123456', 'passKey');
print_r($response);
```

Testing
-------

[](#testing)

This package uses Pest for testing. To run the tests, use the following command:

```
vendor/bin/pest
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

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

[](#contributing)

Feel free to contribute to this package by submitting a pull request or opening an issue.

Authors
-------

[](#authors)

- Beamlak Aschalew ()

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![BeamlakAschalew](https://avatars.githubusercontent.com/u/72562470?v=4)](https://github.com/BeamlakAschalew "BeamlakAschalew (9 commits)")

### Embed Badge

![Health badge](/badges/beamlak-mpesa-php/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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