定制 felixmuhoro/laravel-mpesa-analytics 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

felixmuhoro/laravel-mpesa-analytics

Composer 安装命令:

composer require felixmuhoro/laravel-mpesa-analytics

包简介

Analytics, reporting and insights for M-Pesa transactions in Laravel

README 文档

README

Analytics, reporting, and insights for M-Pesa transactions in Laravel.

Requirements

  • PHP 8.1+
  • Laravel 10 / 11 / 12 / 13
  • felixmuhoro/laravel-mpesa: ^1.2

Installation

composer require felixmuhoro/laravel-mpesa-analytics

Publish the config and run migrations:

php artisan vendor:publish --tag=mpesa-analytics-config
php artisan vendor:publish --tag=mpesa-analytics-migrations
php artisan migrate

Dashboard

Navigate to /mpesa-analytics in your browser. The dashboard shows:

  • KPI cards: total revenue, average/median transaction, success rate, failed count, revenue growth
  • Revenue over time (line chart)
  • Success rate gauge (doughnut)
  • Transaction volume — successful vs failed (stacked bar)
  • Hourly pattern (bar chart, 0-23)
  • Top 10 payers table
  • Failure reasons pie chart

Date range picker supports: Today, Yesterday, Last 7/30/90 days, This/Last week, This/Last month, This year, and fully custom date ranges.

Programmatic Usage

use FelixMuhoro\MpesaAnalytics\Facades\Analytics;
use FelixMuhoro\MpesaAnalytics\Period;

$period = Period::last30Days();

// Revenue
$revenue = Analytics::revenue($period);
// => ['total' => 1250000.00, 'average' => 1500.00, 'median' => 1200.00,
//    'growth_percent' => 12.5, 'growth_direction' => 'up', ...]

// Transactions
$txns = Analytics::transactions($period);
// => ['total' => 833, 'successful' => 791, 'failed' => 42, 'success_rate' => 94.96, ...]

// Success rate
$rate = Analytics::successRate($period);   // float: 94.96

// Revenue over time (for charting)
$daily = Analytics::dailyRevenue($period);
// => [['date' => '2024-01-01', 'total' => 45000.0, 'count' => 30], ...]

// Hourly pattern
$hourly = Analytics::hourlyPattern($period);
// => [['hour' => 0, 'label' => '00:00', 'total' => 0, 'count' => 0], ...] (24 items)

// Top payers
$byAmount = Analytics::topPayersByAmount($period, limit: 10);
$byCount  = Analytics::topPayersByCount($period, limit: 10);

// Failure reasons (by M-Pesa result code)
$failures = Analytics::failureReasons($period);
// => [['code' => 1, 'description' => 'Insufficient funds', 'count' => 28], ...]

// New vs returning customers
$split = Analytics::newVsReturning($period);
// => ['new' => 120, 'returning' => 671, 'new_percent' => 15.2, ...]

// Full summary (all metrics in one call)
$summary = Analytics::summary($period);

// Custom period
$custom = Period::custom('2024-01-01', '2024-01-31');
$revenue = Analytics::revenue($custom);

Period Helper

Period::today()
Period::yesterday()
Period::thisWeek()
Period::lastWeek()
Period::thisMonth()
Period::lastMonth()
Period::last7Days()
Period::last30Days()
Period::last90Days()
Period::thisYear()
Period::custom('2024-01-01', '2024-03-31')

Listening to Events

The package auto-discovers events from felixmuhoro/laravel-mpesa. You can also wire your own events in config/mpesa-analytics.php:

'listen' => [
    'App\Events\PaymentSuccessful' => true,
    'App\Events\PaymentFailed'     => true,
],

Each event must carry a transaction property (array or object) with fields matching M-Pesa callback payload keys.

CSV Export

GET /mpesa-analytics/export/csv?range=last_30_days
GET /mpesa-analytics/export/summary?range=this_month
GET /mpesa-analytics/export/csv?from=2024-01-01&to=2024-01-31

Configuration

See config/mpesa-analytics.php:

Key Default Description
route_prefix mpesa-analytics URL prefix
route_middleware ['web'] Middleware stack
default_range last_30_days Default dashboard period
currency_symbol KSh Symbol shown in UI
mask_phones true Mask phone numbers on dashboard
cache_ttl 300 Seconds to cache aggregated metrics
auto_discover_events true Auto-wire laravel-mpesa events

Routes

Method URI Name Description
GET /mpesa-analytics mpesa-analytics.dashboard Dashboard HTML
GET /mpesa-analytics/data mpesa-analytics.data JSON chart data
GET /mpesa-analytics/export/csv mpesa-analytics.export.csv Transaction CSV
GET /mpesa-analytics/export/summary mpesa-analytics.export.summary Summary CSV

Testing

composer test

License

MIT — Felix Muhoro hi@felixmuhoro.dev

felixmuhoro/laravel-mpesa-analytics 适用场景与选型建议

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

它主要适用于以下技术方向: 「laravel」 「kenya」 「mpesa」 「safaricom」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-04