All Projects → safaricom → Mpesa Php Sdk

safaricom / Mpesa Php Sdk

A PHP sdk for the new Mpesa RESTful APIs

Projects that are alternatives of or similar to Mpesa Php Sdk

Laravel Paytm Wallet
Integrate paytm wallet in your laravel application easily with this package. This package uses official Paytm PHP SDK's.
Stars: ✭ 58 (-56.72%)
Mutual labels:  payment-gateway, laravel
Laravel Paddle
Paddle.com API integration for Laravel with support for webhooks/events
Stars: ✭ 132 (-1.49%)
Mutual labels:  payment-gateway, laravel
Eloquent Tree
Eloquent Tree is a tree model for Laravel Eloquent ORM.
Stars: ✭ 131 (-2.24%)
Mutual labels:  laravel
Repository
🖖Repository Pattern in Laravel. The package allows to filter by request out-of-the-box, as well as to integrate customized criteria and any kind of filters.
Stars: ✭ 134 (+0%)
Mutual labels:  laravel
Daybydaycrm
DaybydayCRM an open-source CRM, to help you keep track of your daily workflow.
Stars: ✭ 1,856 (+1285.07%)
Mutual labels:  laravel
Laravel Seo
SEO package made for maximum customization and flexibility
Stars: ✭ 130 (-2.99%)
Mutual labels:  laravel
Laravel Emojione
Laravel package to make it easy to use the gorgeous emojis from EmojiOne
Stars: ✭ 133 (-0.75%)
Mutual labels:  laravel
Health
Laravel Health Panel
Stars: ✭ 1,774 (+1223.88%)
Mutual labels:  laravel
F Admin
f-admin是一套基于Laravel框架开发的基础权限后台系统
Stars: ✭ 134 (+0%)
Mutual labels:  laravel
Laravel Getting Started
本文介绍如何开始使用 Laravel !
Stars: ✭ 132 (-1.49%)
Mutual labels:  laravel
Laravel Mobile Verification
This package provides convenient methods for sending and verifying mobile verification requests.
Stars: ✭ 132 (-1.49%)
Mutual labels:  laravel
Laravel Coreui Vue
Laravel 5.6 with CoreUI (VueJS Full Starter Template) >>> Deprecated, please go to https://coreui.io/laravel/
Stars: ✭ 132 (-1.49%)
Mutual labels:  laravel
Menus
📌 Menu generator package for the Laravel framework
Stars: ✭ 133 (-0.75%)
Mutual labels:  laravel
Chemex
☕ 咖啡壶是一个免费、开源、高效且漂亮的运维资产管理平台。软硬件资产管理、归属/使用者追溯、盘点以及可靠的服务器状态管理面板。基于优雅的Laravel框架和DcatAdmin开发。
Stars: ✭ 132 (-1.49%)
Mutual labels:  laravel
Eager Load Pivot Relations
Eager load pivot relations for Laravel Eloquent's BelongsToMany relation.
Stars: ✭ 134 (+0%)
Mutual labels:  laravel
Laravel Governor
Manage authorization with granular role-based permissions in your Laravel Apps.
Stars: ✭ 131 (-2.24%)
Mutual labels:  laravel
Tenancy
Automatic multi-tenancy for Laravel. No code changes needed.
Stars: ✭ 2,133 (+1491.79%)
Mutual labels:  laravel
Laravel cities
Find any country/city in the world. Get Long/Lat etc. Deploy geonames.org database localy. Optimized DB tree
Stars: ✭ 133 (-0.75%)
Mutual labels:  laravel
Simple Qrcode
An easy-to-use PHP QrCode generator with first-party support for Laravel.
Stars: ✭ 1,923 (+1335.07%)
Mutual labels:  laravel
Hdcms
支持 PC、H5、微信公众号、微信小程序多应用平台
Stars: ✭ 134 (+0%)
Mutual labels:  laravel

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 https://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]
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

Usage

Confirmation and validation urls

B2C Payment Request

This creates transaction between an M-Pesa short code to a phone number registered on M-Pesa.

$mpesa= new \Safaricom\Mpesa\Mpesa();

$b2cTransaction=$mpesa->b2c($InitiatorName, $SecurityCredential, $CommandID, $Amount, $PartyA, $PartyB, $Remarks, $QueueTimeOutURL, $ResultURL, $Occasion);

Account Balance Request

This is used to enquire the balance on an M-Pesa BuyGoods (Till Number)

$mpesa= new \Safaricom\Mpesa\Mpesa();

$balanceInquiry=$mpesa->accountBalance($CommandID, $Initiator, $SecurityCredential, $PartyA, $IdentifierType, $Remarks, $QueueTimeOutURL, $ResultURL);

Transaction Status Request This is used to check the status of transaction.

$mpesa= new \Safaricom\Mpesa\Mpesa();

$trasactionStatus=$mpesa->transactionStatus($Initiator, $SecurityCredential, $CommandID, $TransactionID, $PartyA, $IdentifierType, $ResultURL, $QueueTimeOutURL, $Remarks, $Occasion);

B2B Payment Request

This is used to transfer funds between two companies.

$mpesa= new \Safaricom\Mpesa\Mpesa();

$b2bTransaction=$mpesa->b2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );

C2B Payment Request

This is used to Simulate transfer of funds between a customer and business.

$mpesa= new \Safaricom\Mpesa\Mpesa();

$b2bTransaction=$mpesa->c2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );

Also important to note is that you should have registered validation and confirmation urls where the callback responses will be sent.

STK Push Simulation

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

$mpesa= new \Safaricom\Mpesa\Mpesa();

$stkPushSimulation=$mpesa->STKPushSimulation($BusinessShortCode, $LipaNaMpesaPasskey, $TransactionType, $Amount, $PartyA, $PartyB, $PhoneNumber, $CallBackURL, $AccountReference, $TransactionDesc, $Remarks);

STK Push Status Query

This is used to check the status of a Lipa Na M-Pesa Online Payment.

$mpesa= new \Safaricom\Mpesa\Mpesa();

$STKPushRequestStatus=$mpesa->STKPushQuery($checkoutRequestID,$businessShortCode,$password,$timestamp);

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.

$mpesa= new \Safaricom\Mpesa\Mpesa();

$callbackData=$mpesa->getDataFromCallback();

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

$mpesa= new \Safaricom\Mpesa\Mpesa();

$callbackData=$mpesa->finishTransaction();

If validation fails, pass false to finishTransaction()

$mpesa= new \Safaricom\Mpesa\Mpesa();

$callbackData=$mpesa->finishTransaction(false);

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].