0

M-Pesa Payment Gateway Integration

Introduction

This package seeks to help php developers implement the various Mpesa APIs without much hustle. It is based on the REST API whose documentation is available on http://developer.safaricom.co.ke.

 

Installation using composer

composer require safaricom/mpesa

 

Configuration
At your project root, create a .env file and in it set the consumer key and consumer secret as follows

MPESA_CONSUMER_KEY= [consumer key]
MPESA_CONSUMER_SECRET=[consumer secret]
MPESA_ENV=[live or sandbox]

M-Pesa - Safari

M-Pesa - Environment

 

For Laravel users, open the Config/App.php file and add \Safaricom\Mpesa\MpesaServiceProvider::class under providers and 'Mpesa'=> \Safaricom\Mpesa\MpesaServiceProvider::class under aliases.

Remember to edit the consumer_key and consumer_secret values appropriately when switching between sandbox and live

 

Lipa Na M-Pesa Online Payment API POST

STK Push Simulation

This is used to initiate online payment on behalf of a customer.

 

Request Parameters

M-Pesa-Request-Parameters

 

Response Parameters

M-Pesa - Response Parameters

 

Error Response Message

M-Pesa-Error-Response

 

Request Body

 

Callback Routes M-Pesa APIs are asynchronous. When a valid M-Pesa API request is received by the API Gateway, it is sent to M-Pesa where it is added to a queue. M-Pesa then processes the requests in the queue and sends a response to the API Gateway which then forwards the response to the URL registered in the CallBackURL or ResultURL request parameter. Whenever M-Pesa receives more requests than the queue can handle, M-Pesa responds by rejecting any more requests and the API Gateway sends a queue timeout response to the URL registered in the QueueTimeOutURL request parameter.

Obtaining post data from callbacks This is used to get post data from callback in json format. The data can be decoded and stored in a database.

 

Finishing a transaction After obtaining the Post data from the callbacks, use this at the end of your callback routes to complete the transaction

If validation fails, pass false to finishTransaction()

 

 

Prakash S

Prakash S

I would like to introduce myself as a Software professional opting for the career in software industry. I'm Prakash S, a MCA graduate and trained as industry level practice for Software technology. Basically I am a PHP Developer but now days exploring more in HTML5, CSS, AngularJS and jQuery libraries.