Download the PHP package smodav/mpesa without Composer

On this page you can find all versions of the php package smodav/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

M-PESA API Package

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

This is a PHP package for the Safaricom's M-Pesa API. The API allows a merchant to initiate C2B online checkout (paybill via web) transactions. The merchant submits authentication details, transaction details, callback url and callback method.

After request submission, the merchant receives instant feedback with validity status of their requests. The C2B API handles customer validation and authentication via USSD push. The customer then confirms the transaction. If the validation of the customer fails or the customer declines the transaction, the API makes a callback to merchant. Otherwise the transaction is processed and its status is made through a callback.

If you enjoy using this package, please take a moment and buy me some coffee.

Installation

Pull in the package through Composer.

Native Addon

When using vanilla PHP, modify your composer.json file to include:

This script will copy the default configuration file to a config folder in the root directory of your project. Now proceed to require the package.

General Install

Run composer require smodav/mpesa to get the latest stable version of the package.

Migration from previous versions

v5 of the package changes the implementation and introduces some breaking changes. Please have a look at the CHANGELOG.

v4 of this package uses a new configuration setup. You will need to update your config file in order to upgrade v3 to v4. v2 is still incompatible since it uses the older API version.

Laravel

When using Laravel 5.5+, the package will automatically register. For laravel 5.4 and below, include the service provider and its alias within your config/app.php.

Publish the package specific config using:

Other Frameworks

To implement this package, a configuration repository is needed, thus any other framework will need to create its own implementation of the ConfigurationStore and CacheStore interfaces.

Configuration

The package allows you to have multiple accounts. Each account will have its specific credentials and endpoints that are independent of the rest. You will be required to set the default account to be used for all transactions, which you can override on each request you make. The package comes with two default accounts that you can modify.

You can add as many accounts as required and switch the connection using the method usingAccount on STK, Register and Simulate as shown below.

Also, note the difference between the business shortcode and your paybill number in the configuration as getting them wrong will cost you a lot of time debugging.

Usage

For Vanilla PHP you will need to initialize the core engine before any requests as shown below. The package comes with a vanilla php implementation of the cache and configuration store, NativeCache and NativeConfig.

The NativeConfig receives the custom location for the configuration file to be used as the first constructor argument. If no value is passed when creating the instance, it will use the default configuration and look for a configuration file on the root of the project under configs directory.

The NativeCache receives a custom directory path as the first constructor argument. The path denotes where the cache should store its files. If no path is provided, the default cache location in the config will be used.

URL Registration

submit(shortCode = null, confirmationURL = null, validationURL = null, onTimeout = 'Completed|Cancelled', account = null)

Register callback URLs

Vanilla

When having multiple accounts, switch using the usingAccount method. We currently have staging, paybill_1 and paybill_2 with staging as the default:

Laravel

Using the paybill_1 account:

Simulate Transaction

push(amount = null, number = null, reference = null, account = null, command = null)

Initiate a C2B simulation transaction request.

Note that when initiating a C2B simulation, setting the command type is optional and by default CustomerPaybillOnline will be used.

Vanilla

Using the paybill_1 account:

Using the CustomerBuyGoodsOnline command:

Laravel

Using the paybill_1 account:

Using the CustomerBuyGoodsOnline command:

STK PUSH

push(amount = null, number = null, reference = null, description = null, account = null, command = null)

Initiate a C2B STK Push request.

Note that when initiating an STK Push, setting the command type is optional and by default CustomerPaybillOnline will be used.

Vanilla

Using the paybill_2 account:

Using CustomerBuyGoodsOnline command:

Laravel

Using the paybill_2 account:

Using the CustomerGoodsOnline command:

STK PUSH Transaction Validation

validate(merchantReferenceId, account = null)

Validate a C2B STK Push transaction.

Vanilla

Using the paybill_2 account:

Laravel

Using the paybill_1 account:

When going live, you should change the default value of the config file to the production account.

License

The M-Pesa Package is open-sourced software licensed under the MIT license.


All versions of mpesa with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
guzzlehttp/guzzle Version ^6.2|^7.4.5
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
nesbot/carbon Version ^1.0 || ^2.0|^3.0
ext-json Version *
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 smodav/mpesa contains the following files

Loading the files please wait ....