kabangi/mpesa
Composer 安装命令:
composer require kabangi/mpesa
包简介
M-Pesa API implementation
README 文档
README
This is a PHP package for the Safaricom's M-Pesa REST API dubbed DARAJA API.
If you are looking for a laravel implementation do check the following repo Laravel Implementation
Installation
This project supports both composer dependency management tool and can also be used without composer
Using Composer
- Run the following command
composer require kabangi/mpesa
Without composer
-
Download the source code as zipped
-
Follow the following directions
<?php
require "{PATHTOTHISLIBFOLDER}/src/autoload.php";
use Kabangi\Mpesa\Init as Mpesa;
- Check the following example for usage https://github.com/Kabangi/mpesa/blob/master/example/mpesa.php
Configuration
The library comes with a structured config file based on the API that you intend to use.
To add the necessary configurations:-
-
Open the folder installation.
-
Look for a file named
config/mpesa.php -
Edit the necessary keys that reflects the product you are using.
Usage
<?php
require "../src/autoload.php";
use Kabangi\Mpesa\Init as Mpesa;
// You can also pass your own config here.
// Check the folder ./config/mpesa.php for reference
$mpesa = new Mpesa();
try {
$response = $mpesa->STKPush([
'amount' => 10,
'transactionDesc' => '',
'phoneNumber' => '',
]);
$response = $mpesa->B2C([
'amount' => 10,
'accountReference' => '12',
'callBackURL' => 'https://example.com/v1/payments/C2B/confirmation',
'queueTimeOutURL' => 'https://example.com/v1/payments/C2B/confirmation',
'resultURL' => 'https://example.com/v1/payments/C2B/confirmation',
'Remarks' => 'Test'
]);
// $mpesa->STKStatus([]);
// $mpesa->C2BRegister([]);
// $mpesa->STKPush([]);
// $mpesa->C2BSimulate([]);
// $mpesa->B2C([])
// $mpesa->B2B([]);
// $mpesa->accountBalance([])
// $mpesa->reversal([]);
// $mpesa->transactionStatus([]);
// $mpesa->reversal([]);
}catch(\Exception $e){
$response = json_decode($e->getMessage());
}
header('Content-Type: application/json');
echo json_encode($response);
Support
Need support using this package:- Send a quick message here
API's Supported
The library implements all the exposed endpoints by Safaricom as listed below:-
1. Lipa na M-Pesa Online Payment
What it is?
The Lipa na M-Pesa Online Payment endpoint(STK push) allows you to request payment from your users/clients. With this endpoint all the user is required to do is input their M-PESA pin to a prompt to send a payment to you.
How to implement it?
2. Lipa na M-Pesa Online Query Request
What it is?
When you request payment from your users/clients via Lipa na M-Pesa Online endpoint above you might want to know the status of that request. This endpoint facilitates that. It allows you to query the status of any STK push on demand.
How to implement it?
3. C2B
What it is?
This endpoint enables developers to receive real time notifications when a client makes a payments to a merchant's Till number or Paybill number. It assumes the payment are made via the SIM card toolkit and as a developer you need to know when that payment hits the merchants till/paybill number for reconciliation and accounting purposes.
How to implement it?
4. B2C
What it is?
This endpoints enables merchants to pay their customers from they paybill account. Some of the use cases are but not limited to paying salaries, paying promotions to customers etc.
How to implement it?
5. B2B
What it is?
This endpoint allows merchants to transfer funds from business to business accounts.
How to implement it?
6. Transaction Status
What it is?
This endpoint enables developers to initiate status check of a B2B, B2C and C2B transactions. It really comes in handy where one party in a transactions fails/claims not to have received an acknowledgment for a transaction.
How to implement it?
7. Reverse API
What it is?
This endpoint enables merchants to reverse a B2B, B2C or C2B transaction. It allows automation of reversal of erronous payment to a merchant's paybill/till number or payments to goods never delivered.
How to implement it?
8. Account Balance
What it is?
This endpoint enables merchants to query their Till/Paybill numbers account balance on demand.
How to implement it?
Inspiration
This package was inspired by the work from smodav work on the following project:- https://github.com/SmoDav/mpesa
Contributors
Gratitudes goes to the following Ninjas for their help during my integration process and the things I had to learn along the way fom them or their code:-
License
The M-Pesa Package is open-sourced software licensed under the MIT license.
kabangi/mpesa 适用场景与选型建议
kabangi/mpesa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.05k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2017 年 12 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「transactions」 「mpesa」 「safaricom」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kabangi/mpesa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kabangi/mpesa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kabangi/mpesa 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Beyonic PHP Library
A PSR-7 compatible library for making CRUD API endpoints
A Laravel package to easily integrate Xendit payment gateway. It supports credit and debit cards, and e-wallet payments and custom invoices, queued notifications, webhook listeners and more.
Advanced Redis cache-driver with in-memory store, transactions and preloading
Effortlessly wrap your controller actions with database transactions.
Bundle of annotations to make it easier and faster to develop Rest APIs with Symfony.
统计信息
- 总下载量: 3.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 44
- 点击次数: 10
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-25