osenco/mpesa

dev-master 2019-03-15 12:37 UTC

README

Download

Download the latest release from here, or use composer to install
composer require osenco/mpesa

Configuration

Function Arguments

$config = array(
  'env'               => '',
  'name'              => '',
  'type'              => '',
  'shortcode'         => '',
  'honumber'          => '',
  'key'               => '',
  'secret'            => '',
  'username'          => '',
  'passkey'           => '',
  'credentials'       => '',
  'validation_url'    => '',
  'confirmation_url'  => '',
  'callback_url'      => '',
  'timeout_url'       => '',
);

.env File

MPESA_ENV="sandbox"
MPESA_NAME=""
MPESA_TYPE=""
MPESA_SHORTCODE=""
MPESA_HO_NUMBER=""
MPESA_APP_KEY=""
MPESA_APP_SECRET=""
MPESA_USERNAME=""
MPESA_PASSWORD=""
MPESA_PASSKEY=""
MPESA_CREDENTIALS=""
MPESA_VALIDATION_URL=""
MPESA_CONFIRMATION_URL=""
MPESA_CALLBACK_URL=""
MPESA_TIMEOUT_URL=""

Usage

Create URL endpoints for each of the requests you need and call the following functions at each endpoint respectively e.g at https://yoursite.com/mpesa/validate call the mpesa_validate() function

Instantiating

Include the autoload.php file and set up the configuration
require_once( 'path/to/vendor/autoload.php' );
\Saf\Mpesa::init( $config );

Optionally, you can register our classes for use use \Saf\Mpesa;
use \Saf\STK;
use \Saf\C2B;
use \Saf\B2C;
use \Saf\B2B;

Register Urls

$trans = \Saf\Mpesa::register_urls();

Initiate Request

Online Checkout

$trans = \Saf\STK( $amount, $phone, $reference );

C2B Request

$trans = \Saf\C2B( $amount, $phone, $reference );

B2B Request

$trans = \Saf\B2B();

B2C Request

$trans = \Saf\B2C();

Status Check

$status = \Saf\Mpesa::status( $transaction_id );

Balance Check

$trans = \Saf\Mpesa::balance();

Transaction reversal

$trans = \Saf\Mpesa::reverse( $transaction_id );

validate Request

$trans = \Saf\Mpesa::validate( $callback = null );

Confirm Request

$trans = \Saf\Mpesa::confirm( $callback = null );

Reconciliation

$trans = \Saf\Mpesa::reconcile( $callback );