vptrading/safaricom-ussd
Composer 安装命令:
composer require vptrading/safaricom-ussd
包简介
Easy package to ease your safaricom integration
README 文档
README
Laravel Package For
Safaricom USSD
This Laravel package is a featherweight package to integrate Safaricom MPesa.
Installation
Via Composer
composer require vptrading/safaricom-ussd
Run the artisan command to publish the Vptrading\SafaricomUssd configuration file.
php artisan vendor:publish --provider="Vptrading\SafaricomUssd\SafaricomUssdServiceProvider"
Usage
Send Push
In order to send a buy request using MPesa all you have to do is import the SafaricomUssd Facade where you want to use it and call the push method. The SafaricomUssd::push() method accepts five parameters, these are: Amount, Phone, Reference Number, a nullable Description and nullable array of ReferenceData (Refer to the Safaricom MPesa Documentation for the description of ReferenceData).
Example
use Vptrading\SafaricomUssd\Facades\SafaricomUssd; $response = SafaricomUssd::push(1, '0912345678', 'VP_212fw323r3', 'Pay for Good', "ReferenceData":[ { "Key": "CashierName", "Value": "Test User" }, { "Key": "CashierNumber", "Value": "251712121212" }, { "Key": "CustomerTINNumber", "Value": "0012345678" } ]);
When calling the method if successful, it will respond with the following.
Example
{
"MerchantRequestID": "850ee93b",
"CheckoutRequestID": "ws_CO_1710202417354636158753",
"ResponseCode": "0",
"ResponseDescription": "Request accepted for processing",
"CustomerMessage": "Request accepted for processing"
}
Deconstruct Callback Data
The next is being notified when a payment is successful. After the user has paid the amount described, Safaricom MPesa will send you a notification on the Result URL you specified in the safaricom-uss.php config file.
Example Data
{"Envelope":{"Body":{"stkCallback":{"MerchantRequestID":"b36272fa","CheckoutRequestID":"ws_CO_1710202412231281053980","ResultCode":3002,"ResultDesc":"No response from user.","CallbackMetadata":{"Item":[{"Name":"MpesaReceiptNumber"},{"Name":"Amount"},{"Name":"TransactionDate"},{"Name":"PhoneNumber","Value":251777713780}]}}}}}
In order to decode this, the package provides a SafaricomUssd::deconstruct() method. All you need to do is put the notification string sent from Safaricom MPesa in to that method and it will be decoded.
Example
use Vptrading\SafaricomUssd\Facades\SafaricomUssd; $decoded = SafaricomUssd::deconstruct('{"Envelope":{"Body":{"stkCallback":{"MerchantRequestID":"b36272fa","CheckoutRequestID":"ws_CO_1710202412231281053980","ResultCode":3002,"ResultDesc":"No response from user.","CallbackMetadata":{"Item":[{"Name":"MpesaReceiptNumber"},{"Name":"Amount"},{"Name":"TransactionDate"},{"Name":"PhoneNumber","Value":251777713780}]}}}}}');
Result
array ( 'Envelope' => array ( 'Body' => array ( 'stkCallback' => array ( 'MerchantRequestID' => '41ec1de4', 'CheckoutRequestID' => 'ws_CO_1710202416562907417583', 'ResultCode' => 0, 'ResultDesc' => 'The service request is processed successfully.', 'CallbackMetadata' => array ( 'Item' => array ( 0 => array ( 'Name' => 'MpesaReceiptNumber', 'Value' => 'SJH9BVRIO3', ), 1 => array ( 'Name' => 'Amount', 'Value' => 1.0, ), 2 => array ( 'Name' => 'TransactionDate', 'Value' => 20241017165717, ), 3 => array ( 'Name' => 'PhoneNumber', 'Value' => 251777713780, ), ), ), ), ), ), )
Change log
Please see the changelog for more information on what has changed recently.
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email dev@vptrading.et instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.
🚀 And that's it. Do your thing and Give us a star if this helped you.🚀
vptrading/safaricom-ussd 适用场景与选型建议
vptrading/safaricom-ussd 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 169 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 10 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「safaricom」 「vp」 「SafaricomUssd」 「VPTrading」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vptrading/safaricom-ussd 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vptrading/safaricom-ussd 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vptrading/safaricom-ussd 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
Laravel package for Accurate Online API integration.
Official Safaricom Daraja M-Pesa integration for Laravel built on ysg/payment-core.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
统计信息
- 总下载量: 169
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-17
