承接 nyanumba-codes/mpesa 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nyanumba-codes/mpesa

Composer 安装命令:

composer require nyanumba-codes/mpesa

包简介

MPESA Integration into Laravel and other php frameworks

README 文档

README

A robust PHP library for integrating Safaricom's M-Pesa API with Laravel applications. This package simplifies payments, QR code generation, and transaction management.

Features

  • Dynamic QR Code Generation
  • STK Push (Customer Payment)
  • C2B Simulations
  • B2C Transactions
  • Transaction Status Checks
  • Account Balance Inquiry
  • Reversals
  • Secure Authentication

Installation

Install via Composer:

composer require nyanumba-codes/mpesa

Configuration

First Run the Installation:

php artisan mpesa:install {environment}

The Environment value can either be left blank, or written sandbox for The Sandbox Certificate file to be downloaded into the public folder or production for the Production Certificate to be downloaded.

# For Sandbox 

php artisan mpesa:install

# or

php artisan mpesa:install sandbox
# For Production

php artisan mpesa:install production

Ensure the Safaricom public certificate (cert.cer) is stored securely under public/mpesa.

After this you may proceed to update your .env file. This one is rather longer this time round because all the MPESA APIs have been covered by this application. I have even separated all the Callbacks, Timeouts and Result URL to allow for development maleability.

# Environment (sandbox or production)
MPESA_ENV=sandbox

# Consumer credentials
MPESA_CONSUMER_KEY=your_consumer_key_here
MPESA_CONSUMER_SECRET=your_consumer_secret_here

# Security credential
MPESA_USERNAME=your_username_here
MPESA_SECURITY_CREDENTIAL=your_security_credential_here

# Shortcode and passkey
MPESA_SHORTCODE=your_shortcode_here
MPESA_PASSKEY=your_passkey_here

# C2B (Customer to Business) URLs
MPESA_C2B_CONFIRMATION=https://yourdomain.com/api/c2b/confirmation
MPESA_C2B_VALIDATION=https://yourdomain.com/api/c2b/validation

# Transaction status callback URLs
MPESA_TRANSACTION_RESULT=https://yourdomain.com/api/transaction/result
MPESA_TRANSACTION_TIMEOUT=https://yourdomain.com/api/transaction/timeout

# B2C (Business to Customer) URLs
MPESA_B2C_RESULT=https://yourdomain.com/api/b2c/result
MPESA_B2C_TIMEOUT=https://yourdomain.com/api/b2c/timeout

# B2C Top-Up URLs
MPESA_B2C_TOPUP_RESULT=https://yourdomain.com/api/b2c/topup/result
MPESA_B2C_TOPUP_TIMEOUT=https://yourdomain.com/api/b2c/topup/timeout

# Account balance inquiry URLs
MPESA_BALANCE_RESULT=https://yourdomain.com/api/balance/result
MPESA_BALANCE_TIMEOUT=https://yourdomain.com/api/balance/timeout

# Reversal request URLs
MPESA_REVERSAL_RESULT=https://yourdomain.com/api/reversal/result
MPESA_REVERSAL_TIMEOUT=https://yourdomain.com/api/reversal/timeout

# Tax inquiry URLs
MPESA_TAX_RESULT=https://yourdomain.com/api/tax/result
MPESA_TAX_TIMEOUT=https://yourdomain.com/api/tax/timeout

# Ratiba callback URL (if applicable)
MPESA_RATIBA_CALLBACK=https://yourdomain.com/api/ratiba/callback

Usage

Initialize the class where you wish to use it:

use NyanumbaCodes\Mpesa\Mpesa;

$mpesa = new Mpesa();

1. Generate Dynamic QR Code

$response = $mpesa->dynamicQr('MerchantName', 'Ref123');

2. Process STK Push (MPESA Express Simulate)

$response = $mpesa->stkPush(100, '254700000000', 'AccountRef', 'TransactionDesc');

3. Process STK Push (MPESA Express Simulate)

$response = $mpesa->transactionStatus('TransactionID', 'originatorConversationID');

4. Perform C2B Simulation

$response = $mpesa->c2bSimulate(100, '254700000000', 'Ref123');

5. Handle Reversals

$response = $mpesa->reversal('TransactionID', 100);

License

This package is open-source and licensed under the MIT License.

nyanumba-codes/mpesa 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-20