PHP code example of wasksofts-technology / mpesa

1. Go to this page and download the library: Download wasksofts-technology/mpesa library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wasksofts-technology / mpesa example snippets


  
  ksofts\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