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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mpesa

PHP mpesa library

PHPUnit Status

Table of contents

Introduction

A PHP Library that wraps around the mpesa APIs

Getting Started

This library runs on the following:

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.

  1. Introduction to the library
  2. C2B transactions
  3. B2B transactions
  4. B2C transactions
  5. General transactions

For further details that might not have been mention here check:

  1. Library specifications
  2. Mpesa endpoints
  3. 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:

  1. Persist token if the token is stored in database.
  2. 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:

  1. Generally we prefer branches over forks to ease internal collaboration.

  2. When in doubt, use feature branches and gitflow as your branch naming scheme.

  3. We have decided to adopt the Git Feature Branch Workflow.

  4. Keep your repository clean; delete merged branches and avoid committing files specific to your dev environment (e.g. .DS_Store).

  5. Follow this guidance about good commit messages.

  6. Consider signing commits with a GPG key.

  7. Feature branches have the following prefix: feature/.

  8. 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


All versions of mpesa with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
guzzlehttp/guzzle Version ^6.0|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hackdelta/mpesa contains the following files

Loading the files please wait ....