Code Monkey home page Code Monkey logo

mpesa-php-sdk2's Introduction

Install using Composer

composer require codeonweekends/mpesa-php-sdk

Usage

The easiest way to use the API is by calling Codeonweekends\Mpesa\Mpesa and accessing the available transaction methods.

  • Create an instance of Codeonweekends\Mpesa\Mpesa
  • Get the api context using the getApiContext() method
  • Set the public key and the api key on the context using setPublicKey(YOUR_PUBLIC_KEY) and setApiKey(YOUR_API_KEY) respectively

Example:

$mpesa = new Codeonweekends\Mpesa\Mpesa();
$context = $mpesa->getApiContext();

$context->setPublicKey(YOUR_PUBLIC_KEY);
$context->setApiKey(YOUR_API_KEY);

Create a C2B Transaction

$c2b = $mpesa->c2b($thirdPartyReference, $amount, $customerMSISDN, $serviceProviderCode, $transactionReference);

View a Transaction Status

$status = $mpesa->transactionStatus($queryReference, $serviceProviderCode, $securityCredential, $initiatorIdentifier);

Transaction Reversal

$reversal = $mpesa->transactionReversal($amount, $serviceProviderCode, $transactionID, $securityCredential, $initiatorIdentifier);

Running Test Suite

  1. Open the file phpunit.xml and fill the <env/> values with appropriate information
  2. Run vendor/bin/phpunit

e.g.

<env name="MPESA_PUBLIC_KEY" value="Your Public Key Here" />
<env name="MPESA_API_KEY" value="Your API Key Here" />
<env name="MPESA_SERVICE_PROVIDER_CODE" value="The Service Provider Code Here" />
<env name="MPESA_CUSTOMER_MSISDN" value="Customer MSISDN here" />
<env name="MPESA_SECURITY_CREDENTIAL" value="Security Credential" />
<env name="MPESA_INITIATOR_IDENTIFIER" value="Initiator Identifier" />

Further Improvements

  • Documentation
  • Laravel support

mpesa-php-sdk2's People

Contributors

amandio avatar giannis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.