kpay/laravel-kpay
Composer 安装命令:
composer require kpay/laravel-kpay
包简介
Laravel 12 package for integrating with the K-Pay payment gateway.
README 文档
README
Laravel 12 package for integrating with the K-Pay payment gateway.
Based on the official K-Pay API documentation: https://developers.kpay.africa/documentation.php
Installation
Require the package via Composer:
composer require kpay/laravel-kpay
Publish the config:
php artisan vendor:publish --tag=kpay-config
Configuration
Set these environment variables:
KPAY_BASE_URL=https://pay.esicia.com/ KPAY_API_KEY=your_api_key KPAY_USERNAME=your_username KPAY_PASSWORD=your_password KPAY_RETAILER_ID=YOUR_RETAILER_ID KPAY_RETURL=https://your-app.com/kpay/callback KPAY_REDIRECTURL=https://your-app.com/payment/return KPAY_CURRENCY=RWF
Usage
Initiate a payment
use KPay; use KPay\LaravelKPay\Enums\PaymentMethod; $result = KPay::pay([ 'msisdn' => '250783300000', 'email' => 'customer@example.com', 'details' => 'Order #12345', 'refid' => 'ORDER123456789', 'amount' => 5000, 'cname' => 'John Doe', 'cnumber' => 'CUST001', 'pmethod' => PaymentMethod::Momo, // or 'momo', 'cc', 'spenn' ]); // If success == 1, redirect user to $result['url']
Payment method amount limits (RWF)
| Method | pmethod |
Minimum | Maximum |
|---|---|---|---|
| Mobile Money (MTN / Airtel) | momo |
100 | 5,000,000 |
| Credit / Debit Card | cc |
1,000 | 10,000,000 |
| SPENN wallet | spenn |
100 | 1,000,000 |
Check payment status
use KPay; $status = KPay::checkStatus('ORDER123456789'); // statusid: '01' (success), '02' (failed), '03' (pending)
Webhook (Callback)
By default the package registers:
POST /kpay/callback
K-Pay sends a POST to your callback URL and requires the endpoint to respond:
{ "tid": "...", "refid": "...", "reply": "OK" }
The controller dispatches events based on statusid. K-Pay callbacks only send 01 (success) or 02 (failed); 03 (pending) is only returned by checkStatus.
statusid |
Event dispatched |
|---|---|
01 |
KPay\LaravelKPay\Events\PaymentSucceeded |
02 |
KPay\LaravelKPay\Events\PaymentFailed |
03 |
KPay\LaravelKPay\Events\PaymentPending |
Each event exposes typed properties alongside the raw $payload array:
use KPay\LaravelKPay\Events\PaymentSucceeded; // In your listener: public function handle(PaymentSucceeded $event): void { $event->tid; // K-Pay transaction ID $event->refid; // your merchant reference $event->statusid; // '01' $event->statusdesc; // human-readable status $event->payaccount; // mobile/card account used $event->payload; // full raw payload array }
To customize the path or middleware:
KPAY_CALLBACK_PATH=kpay/callback KPAY_CALLBACK_MIDDLEWARE=api KPAY_CALLBACK_ENABLED=true
Enums
use KPay\LaravelKPay\Enums\PaymentMethod; use KPay\LaravelKPay\Enums\PaymentStatus; PaymentMethod::Momo->value; // 'momo' PaymentMethod::Card->value; // 'cc' PaymentMethod::Spenn->value; // 'spenn' PaymentStatus::Succeeded->value; // '01' PaymentStatus::Failed->value; // '02' PaymentStatus::Pending->value; // '03'
Error handling
The package throws typed exceptions you can catch:
use KPay\LaravelKPay\Exceptions\KPayApiException; use KPay\LaravelKPay\Exceptions\KPayException; try { $result = KPay::pay([...]); } catch (KPayApiException $e) { // API-level error returned by K-Pay $e->retcode; // e.g. 604 $e->reply; // e.g. 'DUPLICATE_REFID' } catch (\InvalidArgumentException $e) { // Validation failure (missing field, invalid pmethod, amount out of range) } catch (KPayException $e) { // Any other package exception }
K-Pay API error codes
retcode |
reply |
Description |
|---|---|---|
| 0 | PENDING | Payment initiated successfully |
| 600 | INVALID_REQUEST | Missing or invalid parameters |
| 601 | INVALID_API_KEY | API key inactive or not found |
| 602 | INVALID_AUTH | Authentication credentials invalid |
| 603 | IP_NOT_WHITELISTED | Unauthorized IP address |
| 604 | DUPLICATE_REFID | Reference ID already processed |
| 605 | AMOUNT_OUT_OF_RANGE | Amount outside allowed limits |
| 606 | TARGET_AUTHORIZATION_ERROR | Provider rejected transaction |
| 607 | INSUFFICIENT_FUNDS | Insufficient customer balance |
| 608 | TIMEOUT | Transaction timed out |
| 609 | CANCELLED | Customer cancelled |
Testing
composer test
Contributing
Please follow our commit message convention (Conventional Commits). See CONTRIBUTING.md.
License
MIT
kpay/laravel-kpay 适用场景与选型建议
kpay/laravel-kpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payments」 「laravel」 「visa」 「mastercard」 「momo」 「kpay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kpay/laravel-kpay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kpay/laravel-kpay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kpay/laravel-kpay 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel >=5.6 integration for the PHP Credit Cards package that allows to perform operations on debit and credit cards like format, validate brand, number and Luhn algorithm.
Dealing with payments through the Egyptian payment gateway PayMob
Client SDK for CyberSource REST APIs
Librería para la gestión sencilla de pagos mediante TPV Redsys y Paypal
PHP library for working with Georgian payment providers and banks
Laravel Blade components for SVG credit card and payment icons
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-18