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

Fix Regex expression #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 15 additions & 14 deletions php/include/PLUSPEOPLE/PesaPi/MpesaPrivate/PersonalParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function parse($input) {
$result["SUPER_TYPE"] = Transaction::MONEY_IN;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*You have received Ksh([0-9\.\,]+00) from[\s\n]+([0-9A-Z '\.]+) ([0-9]+)[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*You have received Ksh([0-9\.\,]+[0-9]) from[\s\n]+([0-9A-Z '\.]+) ([0-9]+)[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);

if (isset($temp[1][0])) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_PAYMENT_RECEIVED;
$result["RECEIPT"] = $temp[1][0];
Expand All @@ -68,7 +69,7 @@ public function parse($input) {
$result["BALANCE"] = Utility::numberInput($temp[7][0]);

} else {
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*You have received Ksh([0-9\.\,]+00) from[\s\n]+([0-9]+) - ([A-Z '\.]+) [\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*You have received Ksh([0-9\.\,]+[0-9]) from[\s\n]+([0-9]+) - ([A-Z '\.]+) [\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_B2C_RECEIVED;
$result["RECEIPT"] = $temp[1][0];
Expand All @@ -85,7 +86,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_BUYGOODS_RECEIVED;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*Ksh([0-9\.\,]+00) received from[\s\n]+([0-9]+) ([0-9A-Z '\.]+)[\s\n]*New Account balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*Ksh([0-9\.\,]+[0-9]) received from[\s\n]+([0-9]+) ([0-9A-Z '\.]+)[\s\n]*New Account balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[4][0]);
Expand All @@ -100,7 +101,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_PAYBILL_PAID;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Ksh([0-9\.\,]+) sent to[\s\n]*(.+)[\s\n]*for account (.+)[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Ksh([0-9\.\,]+) sent to[\s\n]*(.+)[\s\n]*for account (.+)[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[2][0]);
Expand All @@ -115,7 +116,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_BUY_GOODS;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Ksh([0-9\.\,]+) paid to[\s\n]*([.]+)[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Ksh([0-9\.\,]+) paid to[\s\n]*([.]+)[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[2][0]);
Expand All @@ -129,7 +130,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_PAYMENT_SENT;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Ksh([0-9\.\,]+00) sent to ([0-9A-Z '\.]+) ([0-9]+) on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Ksh([0-9\.\,]+[0-9]) sent to ([0-9A-Z '\.]+) ([0-9]+) on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[2][0]);
Expand All @@ -144,7 +145,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_DEPOSIT;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*Give Ksh([0-9\.\,]+00) cash to (.+)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*Give Ksh([0-9\.\,]+[0-9]) cash to (.+)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[4][0]);
Expand All @@ -158,7 +159,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_WITHDRAW;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*Withdraw Ksh([0-9\.\,]+) from[\s\n]*(.+)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*Withdraw Ksh([0-9\.\,]+) from[\s\n]*(.+)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[4][0]);
Expand All @@ -172,7 +173,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_WITHDRAW_ATM;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M).[\s\n]*Ksh([0-9\.\,]+) withdrawn from (\d+) - AGENT ATM\.[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M).[\s\n]*Ksh([0-9\.\,]+) withdrawn from (\d+) - AGENT ATM\.[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[4][0]);
Expand All @@ -186,7 +187,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_AIRTIME_YOU;

$temp = array();
preg_match_all("/([A-Z0-9]+) confirmed\.[\s\n]*You bought Ksh([0-9\.\,]+00) of airtime on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) confirmed\.[\s\n]*You bought Ksh([0-9\.\,]+[0-9]) of airtime on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[2][0]);
Expand All @@ -200,7 +201,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_AIRTIME_OTHER;

$temp = array();
preg_match_all("/([A-Z0-9]+) confirmed\.[\s\n]*You bought Ksh([0-9\.\,]+) of airtime for (\d+) on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) confirmed\.[\s\n]*You bought Ksh([0-9\.\,]+) of airtime for (\d+) on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)[\s\n]*New M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[2][0]);
Expand All @@ -214,7 +215,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_FROM_MSHWARI;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*You have transferred Ksh([0-9\.\,]+00)[\s\n]*from your M-Shwari account[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)\.[\s\n]*M-Shwari balance is Ksh[0-9\.\,]+\.[\s\n]*M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*You have transferred Ksh([0-9\.\,]+[0-9])[\s\n]*from your M-Shwari account[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)\.[\s\n]*M-Shwari balance is Ksh[0-9\.\,]+\.[\s\n]*M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[2][0]);
$result["NAME"] = "M-Shwari";
Expand All @@ -226,7 +227,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_TO_MSHWARI;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Ksh([0-9\.\,]+00) transferred to M-Shwari account[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)\.[\s\n]*M-PESA balance is Ksh([0-9\.\,]+00)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Ksh([0-9\.\,]+[0-9]) transferred to M-Shwari account[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)\.[\s\n]*M-PESA balance is Ksh([0-9\.\,]+[0-9])/mi", $input, $temp);
$result["RECEIPT"] = $temp[1][0];
$result["AMOUNT"] = Utility::numberInput($temp[2][0]);
$result["NAME"] = "M-Shwari";
Expand All @@ -238,7 +239,7 @@ public function parse($input) {
$result["TYPE"] = Transaction::MPESA_PRIVATE_BALANCE_REQUEST;

$temp = array();
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Your M-PESA balance was Ksh([0-9\.\,]+00)[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)/mi", $input, $temp);
preg_match_all("/([A-Z0-9]+) Confirmed\.[\s\n]*Your M-PESA balance was Ksh([0-9\.\,]+[0-9])[\s\n]*on (\d\d?\/\d\d?\/\d\d) at (\d\d?:\d\d [AP]M)/mi", $input, $temp);
if (isset($temp[1][0])) {
$result["RECEIPT"] = $temp[1][0];
$result["TIME"] = $this->dateInput($temp[3][0] . " " . $temp[4][0]);
Expand Down