Mpesa daraja api 库

v4.0.3 2024-06-18 21:14 UTC

This package is not auto-updated.

Last update: 2024-09-20 23:18:50 UTC


README

一个可以与各种框架(如laravel、codeigniter、cakephp等)一起使用的Mpesa库。本包旨在帮助PHP开发者轻松实现各种Mpesa API。它基于REST API,其文档可在https://developer.safaricom.co.ke找到。

使用composer安装

composer require wasksofts-technology/mpesa

使用示例

 require_once('vendor/autoload.php')

如果是过程式应用程序,使用上面的语句;如果是codeigniter 3.x,则进入config启用 $config['composer_autoload'] = 'vendor/autoload.php';如果vendor是根目录,则应该是 $config['composer_autoload'] = true;对于laravel和其他框架,它们没有问题。

<?php
require_once('vendor/autoload.php');
use Wasksofts\Mpesa\Mpesa;
$mpesa  = new Mpesa();
  
   or
   
$mpesa  = new Wasksofts\MpesaMpesa();
  
$mpesa->config('consumer_key', '');
$mpesa->config('consumer_secret', '');
$mpesa->config('pass_key', '');
$mpesa->config('store_number', '174379');
$mpesa->config('business_shortcode', '');
$mpesa->config('callback_url', 'https://example.com/callback_url/');
$mpesa->config('confirmation_url', 'https://example.com/confirmation_url/');
$mpesa->config('validation_url', 'https://example.com/validation_url/');
$mpesa->config('initiator_name', '');
$mpesa->config('initiator_pass', '');
$mpesa->config('b2c_shortcode', '');
$mpesa->config('security_credential','');
$mpesa->config('result_url', 'https://example.com/result_url/'); 
$mpesa->config('timeout_url', 'https://example.com/timeout_url/');
$mpesa->config('env', 'sandbox');
  
echo " Token : " . $mpesa->oauth_token();
$mpesa->STKPushQuery('ws_CO_DMZ_297481201_09042019174418021');
$mpesa->STKPushSimulation('1','254708374149','pay now','test');
$mpesa->register_url(); 
$mpesa->c2b_simulation('1000', '254708374149', 'account');
$mpesa->b2c('200', 'BusinessPayment', '254708374149', 'payment','b2c_timeout','b2c_result'); // last two parameter define callback https://example.com/result_url.php/b2c_timeout/ or https://example.com/result_url/b2c_result/
$mpesa->b2b('10000','BusinessPayBill','60000','4','4','paytest','cool','b2b_timeout','b2b_result');
$mpesa->tax_remittance('1000', 'kraaccoutn', 'tax_remit_timeout_url','tax_remit_result_url');
$mpesa->accountbalance('600443','4','remarks','acc_timeout','acc_result');
$mpesa->reversal('2','254708374149','1','NCR7S1UXBT','PAY NOW VIA WASKSOFT');
$mpesa->transaction_status('NCR7S1UXBT','254708374149','4','apitest');

#  Usage example for billing
<?php
require_once('vendor/autoload.php');
   
use Wasksofts\Mpesa\BillManager;
$bill_manager  = new BillManager(); 

   or
   
$bill_manager  = new Wasksofts\Mpesa\BillManager(); 
   
$bill_manager->optin_biller('examaple@demo.com');
$bill_manager->optin_update('examaple@demo.com');
$bill_manager->single_invoice($reference, $billedfullname, $billedphoneNumber, $billedperiod, $invoiceName, $dueDate,            $accountRef, $amount);
$bill_manager->bulk_invoicing($array);
$bill_manager->reconciliation($payment_date, $paidAmmount, $actReference, $transactionId, $phoneNumber, $fullName,               $invoiceName, $reference);
$bill_manager->update_invoice_data($payment_date, $paidAmmount, $actReference, $transactionId, $phoneNumber, $fullName,          $invoiceName, $reference);
$bill_manager->cancel_single_invoice($reference);
$bill_manager->cancel_bulk_invoice($array);

# get responses
  echo $mpesa->getResponseData();
  
# Callback json data received from safaricom
  for call back you can use you own implementation 
  this is for testing.
  
  use Wasksofts\Mpesa\Callback;

  $callback = new Callback;
  $callback::processSTKPushRequestCallback();
  $callback::processC2BRequestConfirmation();
  $callback::processC2BRequestValidation();
  $callback::processB2CRequestCallback();
  $callback::processB2BRequestCallback();
  $callback::processAccountBalanceRequestCallback();
  $callback::processReversalRequestCallBack();
  $callback::processTransactionStatusRequestCallback();

贡献

有关详细信息,请参阅CONTRIBUTING

安全

如果您发现任何与安全相关的问题,请通过电子邮件mukamanusteven@gmail.com联系,而不是使用问题跟踪器。

致谢

许可协议

MIT许可协议(MIT)。有关更多信息,请参阅许可文件