Download the PHP package hackdelta/mpesa without Composer
On this page you can find all versions of the php package hackdelta/mpesa. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mpesa
PHP mpesa library
Table of contents
- PHP mpesa library
- Table of contents
- Introduction
- Getting Started
- Installation
- Usage
- Initiating the library
- Editing configurations
- Example usage for the whole library
- Register validation and confirmation urls (C2B)
- Simulate a transaction (C2B)
- Initiate STK push (C2B)
- Checking the stk push query status (C2B)
- Sending money (B2B)
- Sending money (B2C)
- Check transaction status (General)
- Request for reversal (General)
- Check for balance (General)
- Register pull request callback URL (General)
- Send pull request (General)
- Advanced usage
- How To Contribute
- Getting Help
- Security
- Testing
Introduction
A PHP Library that wraps around the mpesa APIs
Getting Started
This library runs on the following:
- PHP ^7.4
- PHP ^8.0
Installation
You can install the package via composer
composer require hackdelta/mpesa
Usage
In order to check for recent changes kindly check the Changelog
The purpose of this package is to wrap around Mpesa APIs in order to provide an easier and much neater methods. This library uses Guzzle http library under the hood for http requests.
This documentation will be divided into five sections covering specific areas. Any other additional notes are welcomed. Feel free to contribute.
- Introduction to the library
- C2B transactions
- B2B transactions
- B2C transactions
- General transactions
For further details that might not have been mention here check:
- Library specifications
- Mpesa endpoints
- Safaricom developer portal
Initiating the library
The library requires one to pass a configuration that will be used in various parts of the library
You don't have to set all those configurations, it's just listed here for all configuration options available to you.
Editing configurations
After initiation, each and every class provides you with a way of editing the configuration class on the fly
For example
Please note that the set methods can be chained.
For a full list of available methods check the specifications
Example usage for the whole library
This just shows an overview of a typical scenario this might be used for testing purposes, in this example we use test credentials, you are however required to provide all the callback URLS, the consumer key, the consumer secret, and your phone number for stk push test. You can get the test credentials from Safaricom developer portal Note: Some of this tests will fail because of having different shortcodes for B2B, anc C2B, in short B2B, C2B, reversal, and pull transaction requests are expected to fail
Register validation and confirmation urls (C2B)
To register the confirmation and validation urls you'll need to set the following configurations
**Note: This can be done only once in production***
Simulate a transaction (C2B)
This is used to simulate a transaction during sandbox testing, if used in production this will throw an error
Initiate STK push (C2B)
This is used for lipa na mpesa online transaction and requires the following configs
Checking the stk push query status (C2B)
This is used to check the status of an stk push request
Sending money (B2B)
This is used for sending money from a business to a business, the following configurations are required
Sending money (B2C)
This is used for sending money from a business to a client, e,g. salary payments, the following configurations are required
Check transaction status (General)
Used to check for account balance for the shortcode
Request for reversal (General)
Used to reverse a transaction
Check for balance (General)
Used to check for account balance for the shortcode
Register pull request callback URL (General)
This is a relatively new API and i'll advice that one first checks the specifications and the mpesa endpoints documentations. This API is used to request for transaction statement from safaricom here we are registering the callback URL that will receive the results of a pull request call.
Send pull request (General)
This is a relatively new API and i'll advice that one first checks the specifications and the mpesa endpoints documentations. This API is used to request for transaction statement from safaricom
Advanced usage
If you have any questions about advanced usage raise an issue in the issues tab. Examples may include:
- Persist token if the token is stored in database.
- Switching between different types of shortcodes e.g. from normal C2B shortcode to a B2C shortcode
The above can be achieved by just changing the configs before sending the next request. Most of this revolve around the config file itself, the config is passed by reference therefore a change in one affects changes in the rest of the configuration. This is by design to enable easy manipulation of the configurations without having to change the config for multiple classes. This behavior forms some sort of shared data between the classes;
TODO: Add example of advanced usage
How To Contribute
Please have a look at the library specifications to see what methods and any other specification your contributions should follow, before continuing.
Git is our version control system of choice and GitHub is our current repository platform. Here is how we work with Git:
-
Generally we prefer branches over forks to ease internal collaboration.
-
When in doubt, use feature branches and gitflow as your branch naming scheme.
-
We have decided to adopt the Git Feature Branch Workflow.
-
Keep your repository clean; delete merged branches and avoid committing files specific to your dev environment (e.g. .DS_Store).
-
Follow this guidance about good commit messages.
-
Consider signing commits with a GPG key.
-
Feature branches have the following prefix: feature/.
- Get your code approved by the project lead before pushing to master and deploying to production.
Getting Help
In case of any assistance regarding the project, you can escalate the issue on the project's issue board.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Testing
TODO