2017 © Pedro Peláez
 

library mpesa

PHP SDK for M-Pesa Mozambique API

image

abdulmueid/mpesa

PHP SDK for M-Pesa Mozambique API

  • Sunday, March 25, 2018
  • by abdulmueid
  • Repository
  • 2 Watchers
  • 8 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Welcome to M-Pesa PHP API

This project aims to provide an easy-to-use and up-to-date PHP wrapper for the M-Pesa Mozambique API., (*1)

Target version of M-Pesa API: v1x, (*2)

Installation

Install using composer:, (*3)

composer require abdulmueid/mpesa

Usage

  1. Load the configuration from file., (*4)

    $config = \abdulmueid\mpesa\Config::loadFromFile('/path/to/config.php');
    

    See sample configuration file in examples folder., (*5)

  2. Create a Transaction using the configuration., (*6)

    $transaction = new \abdulmueid\mpesa\Transaction($config);
    
  3. Execute API operations and pass appropriate parameters., (*7)

    1. Initiate a C2B payment collection., (*8)

      $c2b = $transaction->c2b(
         float $amount,
         string $msisdn,
         string $reference,
         string $third_party_reference
      );
      
    2. Initiate a B2C payment., (*9)

      $b2c = $transaction->b2c(
         float $amount,
         string $msisdn,
         string $reference,
         string $third_party_reference
      );
      
    3. Initiate a B2B payment., (*10)

      $b2b = $transaction->b2b(
          float $amount,
          string $receiver_party_code,
          string $reference,
          string $third_party_reference
      );
      
    4. Initiate a reversal., (*11)

      $reversal = $transaction->reversal(
         float $amount,  
         string $transaction_id,
         string $third_party_reference
      );
      
    5. Query a transaction., (*12)

      $query = $transaction->query(
         string $query_reference,
         string $third_party_reference
      );
      
  4. Check Response, (*13)

    All transactions return the TransactionResponse object. The object has the following public methods:, (*14)

    1. getCode() - Returns the response code i.e. INS-0, (*15)

    2. getDescription() - Returns the description., (*16)

    3. getTransactionID() - Returns the transaction ID., (*17)

    4. getConversationID() - Returns the conversation ID., (*18)

    5. getTransactionStatus() - Returns the transaction status. Only populated when calling the query() transaction., (*19)

    6. getResponse() - Returns the full response JSON object as received from M-Pesa servers. Good for debugging any issues or undocumented behaviors of the M-Pesa API., (*20)

In a typical scenario, code to check for successful transactions should be as follows:, (*21)

$c2b = $transaction->c2b(...);

if($c2b->getCode() === 'INS-0') {
    // Transaction Successful, Do something here
}

Testing

This repo provides Unit Tests to validate the objects and their interaction with M-Pesa., (*22)

To run tests, 1. Open the phpunit.xml file and add the require credentials/parameters as supplied by M-Pesa. 2. Run phpunit 3. Check the handset for USSD prompts to approve test transactions., (*23)

All tests use 1MT as the test amount., (*24)

License

This library is release under the MIT License. See LICENSE file for details., (*25)

The Versions

25/03 2018

dev-master

9999999-dev

PHP SDK for M-Pesa Mozambique API

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Abdul Mueid Akhtar