Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pi #1

Merged
merged 18 commits into from
Nov 4, 2019
Merged

pi #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 5 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,18 @@ PesaPI
PesaPI is an unofficial open source API for mobile money systems, released under the BSD(lite) license.
The system currently support:
* Kenya: Mpesa paybill accounts
* Kenya: Mpesa buygoods (lipa na mpesa) accounts
* Kenya: Mpesa private accounts
* Kenya: Airtel private accounts
* Kenya: Yu private accounts (experimental)
* Kenya: Airtel paybill accounts (experimental)
* Ghana: Airtel private accounts (experimental)
* Rwanda: MNT private accounts (experimental)
* Tanzania: Mpesa private accounts
* Tanzania: Tigo private accounts
* Somalia: Golis Sahal private accounts (experimental)
* Uganda: MTN private accounts (experimental)

The API supports both PUSH and PULL versions.
The PHP version of the API is generally the most mature and recomended at this point - the system is build using Mysql and Curl.
Please direct all questions to the public mailing-list "pesaPi" on Google-groups: http://groups.google.com/group/pesapi


Short example
-------------
For a short usage example please see:
http://www.youtube.com/gifair


Current status
--------------
The current system should be considered as beta version - at least one commercial solution is using it as its payment gateway.
However it is not recomended that you deploy the system without having a developer available to support the setup.

Version 0.1.0 was recently released and is contains a major rework of the internal structures of PesaPi - be alert that things that worked previously may not be fully working yet - as detailed testing is ongoing.

Currently we are looking for people to provide copies of the SMS messages they are getting from various payment systems.


System design overview
----------------------
* Supports both push and pull notifications.
* Does synchroization between local and server database.
* Transaction data are available even when main server is down.
* Super easy to utilize for integrators.
* Fast response on historical data.
* Keep the load on servers as low as possible.
* Hopefully more reliable than other APIs.


API Overview
------------
The PesaPi class contains several static methods, these methods are the main interface.

* availableBalance(time) -- returns the balance at a given point in time
* locateByReceipt(receipt) -- returns a payment or null for the given receipt number
* locateByPhone(phone, from, until) -- returns an array of payments from a particular phone
* locateByName(name, from, until) -- returns an array of payments from a particular client name
* locateByAccount(account, from, until) -- returns an array of payments from a particular account-no
* locateByTimeInterval(from, until) -- returns an array of all payments within a given time interval

As an alternative you can ask PesaPi to call a your on your site when a new transaction is received (push mechanics).


Way forward
-----------
The following is a highlevel "todo" list for the project

* Getting the code to release/production quality.
* Getting more developers onboard.
* Add support for more payment systems.

For further information please visit http://www.pesapi.com or the the public mailing-list "pesaPi" on Google-groups: http://groups.google.com/group/pesapi
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "pluspeople/pesapi",
"description": "Mobile money middleware",
"version": "1.0.0",
"authors": [
{
"name": "Michael Pedersen",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"PLUSPEOPLE": "php/include/"
}
}
}
6 changes: 6 additions & 0 deletions php/documentation/congo_mpesa_private_examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARGENT RECU du 243881260264 le 13/01/2015 12:51:37
Du compte: 1000624832
Montant: 0.20 USD
Frais: 0.00 USD
Ref: 181346285
Solde Disponible: 0.20 USD
13 changes: 10 additions & 3 deletions php/include/PLUSPEOPLE/PesaPi/Base/Account.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (c) 2011-2014, PLUSPEOPLE Kenya Limited.
/* Copyright (c) 2011-2015, PLUSPEOPLE Kenya Limited.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -34,13 +34,20 @@ class Account {
//############### Properties ####################
const MPESA_PAYBILL = 1;
const MPESA_PRIVATE = 2;
const KENYA_YU_PRIVATE = 3;
const KENYA_YU_PRIVATE = 3; // Yu have folded - this will be removed.
const GHANA_AIRTEL_PRIVATE = 4;
const RWANDA_MTN_PRIVATE = 5;
const TANZANIA_MPESA_PRIVATE = 6;
const TANZANIA_TIGO_PRIVATE = 7;
const KENYA_AIRTEL_PRIVATE = 8;

const KENYA_AIRTEL_PAYBILL = 9;
const SOMALIA_GOLIS_PRIVATE = 10;
const SOMALIA_TELESOME_PRIVATE = 11;
const SOMALIA_HORMUUD_PRIVATE = 12;
const GHANA_MTN_PRIVATE = 13;
const DR_CONGO_MPESA_PRIVATE = 14;
const UGANDA_MTN_PRIVATE = 15;

protected $id = 0;
protected $type = 0;
protected $name = "";
Expand Down
23 changes: 22 additions & 1 deletion php/include/PLUSPEOPLE/PesaPi/Base/AccountFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (c) 2011-2014, PLUSPEOPLE Kenya Limited.
/* Copyright (c) 2011-2015, PLUSPEOPLE Kenya Limited.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -119,6 +119,27 @@ public static function createEntry($type, $id, $initValues=NULL) {
case Account::KENYA_AIRTEL_PRIVATE:
$object = new \PLUSPEOPLE\PesaPi\KenyaAirtelPrivate\Account($id, $initValues);
break;
case Account::KENYA_AIRTEL_PAYBILL:
$object = new \PLUSPEOPLE\PesaPi\KenyaAirtelPaybill\Account($id, $initValues);
break;
case Account::SOMALIA_GOLIS_PRIVATE:
$object = new \PLUSPEOPLE\PesaPi\SomaliaGolisPrivate\Account($id, $initValues);
break;
case Account::SOMALIA_TELESOME_PRIVATE:
$object = new \PLUSPEOPLE\PesaPi\SomaliaTelesomePrivate\Account($id, $initValues);
break;
case Account::SOMALIA_HORMUUD_PRIVATE:
$object = new \PLUSPEOPLE\PesaPi\SomaliaHormuudPrivate\Account($id, $initValues);
break;
case Account::GHANA_MTN_PRIVATE:
$object = new \PLUSPEOPLE\PesaPi\GhanaMTNPrivate\Account($id, $initValues);
break;
case Account::DR_CONGO_MPESA_PRIVATE:
$object = new \PLUSPEOPLE\PesaPi\CongoMpesaPrivate\Account($id, $initValues);
break;
case Account::UGANDA_MTN_PRIVATE:
$object = new \PLUSPEOPLE\PesaPi\UgandaMTNPrivate\Account($id, $initValues);
break;
}
return $object;
}
Expand Down
39 changes: 21 additions & 18 deletions php/include/PLUSPEOPLE/PesaPi/Base/Database.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (c) 2011, PLUSPEOPLE Kenya Limited.
/* Copyright (c) 2011-2015, PLUSPEOPLE Kenya Limited.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -44,12 +44,15 @@ class Database {
# # # # # # # # Initializer # # # # # # # # # #
protected function __construct($type) {
$this->config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
// if we need to use same credentials to the database then we need to use mysql_connect instead of mysql_pconnect.
$this->dbId = mysql_pconnect($this->config->getConfig("DatabaseHost" . $type),$this->config->getConfig("DatabaseUser" . $type),$this->config->getConfig("DatabasePassword" . $type), true);
if ($this->dbId > 0) {
if (!mysql_select_db($this->config->getConfig("DatabaseDatabase" . $type), $this->dbId)) {
exit;
}

$this->db = new \mysqli($this->config->getConfig("DatabaseHost" . $type),
$this->config->getConfig("DatabaseUser" . $type),
$this->config->getConfig("DatabasePassword" . $type),
$this->config->getConfig("DatabaseDatabase" . $type));

if ($this->db->connect_errno) {
print "DB connection error";
exit();
}
}

Expand All @@ -68,42 +71,42 @@ public static function instantiate($type = Database::TYPE_READ) {
}

public function dbIn($input) {
return addslashes($input);
return $this->db->real_escape_string($input);
}

public function dbOut($input) {
return stripslashes($input);
return $input;
}

public function query($input) {
++$this->queryAmount;
return mysql_query($input, $this->dbId);
return $this->db->query($input);
}

public function fetchObject($input) {
return mysql_fetch_object($input);
return $input->fetch_object();
}

public function freeResult($input) {
return mysql_free_result($input);
return $input->close();
}

public function insertId() {
return mysql_insert_id($this->dbId);
return $this->db->insert_id;
}

public function affectedRows() {
return mysql_affected_rows($this->dbId);
return $this->db->affected_rows;
}

public function numRows($input) {
return mysql_num_rows($input);
return $input->num_rows;
}

public function beginTransaction() {
$this->transactionCount++;
if ($this->transactionCount == 1) {
return (bool)mysql_query("START TRANSACTION");
return (bool)$this->query("START TRANSACTION");
}
return true;
}
Expand All @@ -113,15 +116,15 @@ public function commitTransaction() {
$this->transactionCount--;
}
if ($this->transactionCount == 0) {
return (bool)mysql_query("COMMIT");
return (bool)$this->query("COMMIT");
}
return true;
}

public function rollbackTransaction() {
if ($this->transactionCount != 0) {
$this->transactionCount = 0;
return (bool)mysql_query("ROLLBACK");
return (bool)$this->query("ROLLBACK");
}
return true;
}
Expand Down
75 changes: 75 additions & 0 deletions php/include/PLUSPEOPLE/PesaPi/Base/Parser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/* Copyright (c) 2014, PLUSPEOPLE Kenya Limited.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of PLUSPEOPLE nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

File originally by Michael Pedersen <[email protected]>
*/
namespace PLUSPEOPLE\PesaPi\Base;

class Parser {
public function getBlankStructure() {
return array("SUPER_TYPE" => 0,
"TYPE" => 0,
"RECEIPT" => "",
"TIME" => 0,
"PHONE" => "",
"NAME" => "",
"ACCOUNT" => "",
"STATUS" => "",
"AMOUNT" => 0,
"BALANCE" => 0,
"NOTE" => "",
"COST" => 0);
}

public function dateInput($time, $format) {
$dt = \DateTime::createFromFormat($format, $time);
if ($dt !== FALSE) {
return $dt->getTimestamp();
}
return 0;
}

public function numberInput($input) {
$input = trim($input);
$amount = 0;

if (preg_match("/^[0-9,]+\.?$/", $input)) {
$amount = 100 * (int)str_replace(',', '', $input);
} elseif (preg_match("/^[0-9,]+\.[0-9]$/", $input)) {
$amount = 10 * (int)str_replace(array('.', ','), '', $input);
} elseif (preg_match("/^[0-9,]*\.[0-9][0-9]$/", $input)) {
$amount = (int)str_replace(array('.', ','), '', $input);
} else {
$amount = (int)$input;
}
return $amount;
}


}
?>
Loading