项目作者: codeonweekends

项目描述 :
(Unofficial) PHP SDK for the MPesa payment gateway by Vodacom Mozambique
高级语言: PHP
项目地址: git://github.com/codeonweekends/mpesa-php-sdk.git
创建时间: 2019-01-04T05:19:27Z
项目社区:https://github.com/codeonweekends/mpesa-php-sdk

开源协议:MIT License

下载


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:

  1. $mpesa = new Codeonweekends\Mpesa\Mpesa();
  2. $context = $mpesa->getApiContext();
  3. $context->setPublicKey(YOUR_PUBLIC_KEY);
  4. $context->setApiKey(YOUR_API_KEY);

Create a C2B Transaction

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

View a Transaction Status

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

Transaction Reversal

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

Running Test Suite

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

e.g.

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

Further Improvements

  • Documentation
  • Laravel support