ongudidan/mpesa 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ongudidan/mpesa

Composer 安装命令:

composer require ongudidan/mpesa

包简介

This is a daraja API package used to connect all the services offered like C2B, B2C, B2B etc...

README 文档

README

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 ongudidan/mpesa

Configuration
At your project root, create a yii2.cfg file and in it set the consumer key and consumer secret as follows
MPESA_CONSUMER_KEY= "consumer key"
MPESA_INITIATOR= "username for the user with the assigned permissions"
MPESA_INITIATOR_PASSWORD= "password for that user"
MPESA_CONSUMER_SECRET="consumer secret"
MPESA_BUSINESS_SHORTCODE=" enter business shortcode eg 174379"
LIPA_NA_MPESA_PASSKEY="enter lipa na mpesa passkey eg bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919"

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 \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 or Pay Bill)

$mpesa= new \Mpesa\Mpesa();

$balanceInquiry=$mpesa->accountBalance($IdentifierType, $QueueTimeOutURL, $ResultURL);

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

$mpesa= new \Mpesa\Mpesa();

$trasactionStatus=$mpesa->transactionStatus($TransactionID, $IdentifierType, $ResultURL, $QueueTimeOutURL);

B2B Payment Request

This is used to transfer funds between two companies.

$mpesa= new \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 \Mpesa\Mpesa();

$c2bTransaction=$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 \Mpesa\Mpesa();

$stkPushSimulation = $mpesa->STKPushSimulation($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 \Mpesa\Mpesa();

$STKPushRequestStatus = $mpesa->STKPushQuery($checkoutRequestID);

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 \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 \Mpesa\Mpesa();

$callbackData=$mpesa->finishTransaction();

If validation fails, pass false to finishTransaction()

$mpesa= new \Mpesa\Mpesa();

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

ongudidan/mpesa 适用场景与选型建议

ongudidan/mpesa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 ongudidan/mpesa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ongudidan/mpesa 我们能提供哪些服务?
定制开发 / 二次开发

基于 ongudidan/mpesa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 32
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-03-28