itsmurumba / laravel-mpesa
Laravel Mpesa Daraja API 包
v1.0.7
2024-04-02 18:31 UTC
Requires
- php: ^7.1|^8.0|^8.1|^8.2
- guzzlehttp/guzzle: ^6.0|^7.0
- illuminate/support: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^8.0|^9.0
README
这是一个用于 Safaricom Mpesa Daraja API 的 Laravel 包。它包含所有公开可用的端点
- 消费者到企业(C2B)付款
- 企业到消费者(B2C)付款
- Mpesa 快速支付(Lipa Na Mpesa Online)
- 交易状态
- 账户余额
- 撤销
- 企业对企业(B2B)付款
安装
运行以下命令以在您的 Laravel 项目中安装 Laravel Mpesa 包:
composer require itsmurumba/laravel-mpesa
如果您使用的是 Laravel 5.5 及以上版本,请跳转到 配置 步骤。
运行 composer require 命令后,您应该在 config/app.php 文件中添加包的服务提供者和别名。(对于 Laravel 5.4 及以下版本)
Itsmurumba\Mpesa\MpesaServiceProvider::class
配置
安装包后,运行以下命令在 config 文件夹中安装 mpesa.php
配置文件:
php artisan mpesa:install
或者
php artisan vendor:publish
在您的 .env
文件中添加并定义以下变量:
MPESA_CONSUMER_KEY=
MPESA_CONSUMER_SECRET=
MPESA_CALLBACK_URL=
MPESA_BASE_URL=https://sandbox.safaricom.co.ke
MPESA_PAYBILL_NUMBER=600978
LIPA_NA_MPESA_SHORTCODE=174379
LIPA_NA_MPESA_CALLBACK_URL=
LIPA_NA_MPESA_PASSKEY=
MPESA_CONFIRMATION_URL=
MPESA_VALIDATION_URL=
MPESA_INITIATOR_USERNAME=
MPESA_INITIATOR_PASSWORD=
MPESA_ENVIRONMENT=sandbox
MPESA_QUEUE_TIMEOUT_URL=
MPESA_RESULT_URL=
用法
在您的控制器中添加以下构造函数:
protected $mpesa;
public function __construct(){
$this->mpesa = new Mpesa();
}
1. Mpesa 快速支付(Lipa Na Mpesa Online)
$this->mpesa->expressPayment($amount, $phoneNumber, $accountReference = 'CompanyXLTD', $transactionDescription = 'Payment of X');
- $phoneNumber = 254XXXXXXXXX
- $accountReference = 账户参考(最多12个字符)
- transactionDescription = 交易描述(1-13个字符)
2. Mpesa 快速支付查询(Lipa Na Mpesa Online)
$this->mpesa->expressPaymentQuery($checkoutRequestId);
3. C2B 注册 URL
$this->mpesa->c2bRegisterURLs();
4. 消费者到企业(C2B)付款
$this->mpesa->c2bPaymentc2bPayment($commandId, $amount, $phoneNumber, $billRefNumber);
- $commandId = 只能设置为 CustomerPayBillOnline 或 CustomerBuyGoodsOnline
- $billRefNumber = 仅用于 CustomerPayBillOnline 选项,例如账户号码。当 commandId 为 CustomerBuyGoodsOnline 时,将值设置为
''
5. 企业到消费者(B2C)付款
$this->mpesa->b2cPayment($commandId, $amount, $phoneNumber, $remarks, $occassion = '');
6. 交易状态
$this->mpesa->transactionStatus($transactionId, $identifierType, $remarks, $occassion = '');
7. 账户余额
$this->mpesa->accountBalance($identifierType, $remarks);
8. 撤销
$this->mpesa->reversals($transactionId, $amount, $receiverParty, $receiverIdentifierType, $remarks, $occasion = '');
9. 企业对企业支付(B2B)
$this->mpesa->b2bPayment($commandId, $amount, $receiverShortcode, $accountReference, $remarks);
贡献
这是一个社区包,因此欢迎任何感兴趣的人为此包做出贡献。在开始贡献之前,请查阅 Contribution.md。请继续提交 PR 和问题。
给我买杯咖啡
给这个仓库加星标,我将恢复我的超能力。您也可以在推特上关注我 @ItsMurumba
许可
本包采用 MIT 许可证授权。请查阅 许可 文件以获取详细信息