paymentsds / mpesa
MPesa API 的 PHP 客户端库
1.0.1
2022-11-07 14:20 UTC
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: 7.*
Requires (Dev)
- phpunit/phpunit: ^9.5
- vlucas/phpdotenv: ^5.4
This package is auto-updated.
Last update: 2024-09-04 10:24:41 UTC
README
这是一个库,可以帮助您将 Vodacom M-Pesa 操作集成到您的应用程序中。
特性
使用此库,您可以实现以下操作
- 从移动账户接收资金到商业账户(C2B)
- 从商业账户向移动账户发送资金(B2C)
- 从商业账户向另一个商业账户发送资金(B2B)
- 撤销上述任何交易
- 查询交易状态
要求
安装
使用 Composer
composer require paymentsds/mpesa
手动安装
git clone https://github.com/paymentsds/mpesa-php-sdk mpesa-php-sdk
cd mpesa-php-sdk
composer install
使用方法
使用此 SDK 非常简单快捷,让我们看看一些示例
C2B 交易(从移动账户接收资金)
use Paymentsds\MPesa\Client; use Paymentsds\MPesa\Environment; $client = new Client([ 'apiKey' => '<REPLACE>', // API Key 'publicKey' => '<REPLACE>', // Public Key 'serviceProviderCode' => '<REPLACE>' // Service Provider Code 'environment' => Environment::SANDBOX // Environment. Use Environment::PRODUCTION for production ]); $paymentData = [ 'from' => '841234567', // Customer MSISDN 'reference' => '11114', // Third Party Reference 'transaction' => 'T12344CC', // Transaction Reference 'amount' => '10' // Amount ]; $result = $client->receive($paymentData); if ($result->success) { // Handle success } else { // Handle failure }
B2C 交易(向移动账户发送资金)
use Paymentsds\MPesa\Client; $client = new Client([ 'apiKey' => '<REPLACE>', // API Key 'publicKey' => '<REPLACE>', // Public Key 'serviceProviderCode' => '<REPLACE>' // Service Provider Code ]); $paymentData = [ 'to' => '841234567', // Customer MSISDN 'reference' => '11114', // Third Party Reference 'transaction' => 'T12344CC', // Transaction Reference 'amount' => '10' // Amount ]; $result = $client->send($paymentData); if ($result->success) { // Handle success scenario } else { // Handle failure scenario }
B2B 交易(向商业账户发送资金)
$client = new Client([ 'apiKey' => '<REPLACE>', // API Key 'publicKey' => '<REPLACE>', // Public Key 'serviceProviderCode' => '<REPLACE>' // Service Provider Code ]); $paymentData = [ 'from' => '979797', // Receiver Party Code 'reference' => '11114', // Third Party Reference 'transaction' => 'T12344CC', // Transaction Reference 'amount' => '10' // Amount ]; $result = $client->send($paymentData) if ($result->success) { // Handle success scenario } else { // Handle failure scenario }
交易撤销
use Paymentsds\MPesa\Client; $client = new Client([ 'apiKey' => '<REPLACE>', // API Key 'publicKey' => '<REPLACE>', // Public Key 'serviceProviderCode' => '<REPLACE>', // Service Provider Code 'initiatorIdentifier' => '<REPLACE>', // Initiator Identifier 'securityIdentifier' => '<REPLACE>' // Security Credential ]); $paymentData = [ 'reference' => '11114', // Third Party Reference 'transaction' => 'T12344CC', // Transaction Reference 'amount' => '10' // Amount ]; $result = $client->revert($paymentData); if ($result->success) { // Handle success scenario } else { // Handle failure scenario }
查询交易状态
use Paymentsds\MPesa\Client; $client = new Client([ 'apiKey' => '<REPLACE>', // API Key 'publicKey' => '<REPLACE>', // Public Key 'serviceProviderCode' => '<REPLACE>' // Service Provider Code ]); $paymentData = [ 'subject' => '11114', // Query Reference 'transaction' => 'T12344CC', // Transaction Reference ]; $result = $client->query($paymentData); if ($result->success) { // Handle success scenario } else { // Handle failure scenario }
朋友
作者
贡献
感谢您考虑为此包做出贡献。如果您想这样做,请通过developers@paymentsds.org给我们发邮件,我们将会尽快回复您。
安全漏洞
如果您发现安全漏洞,请通过developers@paymentsds.org给我们发邮件,我们会以必要的紧急性解决这个问题。
许可
版权 2020 © PaymentsDS 团队
根据 Apache 许可证 2.0 版(“许可证”);除非符合许可证规定,否则您不得使用此文件。您可以在以下地址获取许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”基础分发,不提供任何明示或暗示的保证或条件。有关许可证的特定语言管辖权限和限制,请参阅许可证。