diff --git a/www/TEST/test_createuser.php b/www/TEST/test_createuser.php index f3120e08..eea9a414 100644 --- a/www/TEST/test_createuser.php +++ b/www/TEST/test_createuser.php @@ -3,9 +3,10 @@ require_once 'config.php'; $url = $local_url . "/createuser"; -$username = urlencode("ses66181+" . rand(1000, 9999) . "@gmail.com"); +$username = urlencode("jubaworker+" . rand(1000, 9999) . "@gmail.com"); -$username = "ses66181+" . rand(1000, 9999) . "@gmail.com"; +$username = "jubaworker+" . rand(1000, 9999) . "@gmail.com"; +//$username = "ameye+" . rand(1000, 9999) . "@chiefsoft.com"; $phone = (rand(1, 2) > 1) ? "770222" . rand(2222, 9999) : ''; include 'sample_data.php'; // just for sample data diff --git a/www/application/controllers/Bkotransaction.php b/www/application/controllers/Bkotransaction.php index 51792f0a..18b1193c 100644 --- a/www/application/controllers/Bkotransaction.php +++ b/www/application/controllers/Bkotransaction.php @@ -25,7 +25,8 @@ class Bkotransaction extends Bko_Controller { $mysql = "SELECT m.id,mp.confirmation, m.added,me.firstname||' '||me.lastname||'
'||me.email AS Sender," . "sr.firstname||' '||sr.lastname||'
ACC:'||sr.account_no||'-'||be.name AS recipient, m.initiatingamount*0.01 AS Amount,m.fee*0.01 AS Fee, " . "'' As Detail, " - . "'' As Process " + . "'' As Process, " + . "m.initiatingamount AS raw_amount, m.fee AS raw_fee, sr.bank_code, sr.account_no " . "FROM money_transfer m " . "LEFT JOIN members me ON me.id=m.member_id " . "LEFT JOIN sendmoney_recipient sr ON sr.id=m.recipientid " @@ -39,7 +40,7 @@ class Bkotransaction extends Bko_Controller { break; - case 'TRANSDETAIL': + case 'TRANSDETAIL': $mysql = "SELECT m.id,mp.confirmation, m.added,me.firstname||' '||me.lastname||'
'||me.email AS Sender," . "sr.firstname||' '||sr.lastname||'
ACC:'||sr.account_no||'-'||be.name AS recipient, m.initiatingamount*0.01 AS Amount,m.fee*0.01 AS Fee " @@ -65,93 +66,155 @@ class Bkotransaction extends Bko_Controller { case 'COMPLETE': //echo 'complete 1'; -// url: "/bkotransaction/smprocess?proc=COMPLETE&sendmoney_id="+link_id+'&tcode='+tcode+'&tref='+tref + // url: "/bkotransaction/smprocess?proc=COMPLETE&sendmoney_id="+link_id+'&tcode='+tcode+'&tref='+tref $data["trans_code"] = $this->input->get('tcode'); $data["trans_tref"] = $this->input->get('tref'); $data["sendmoney_id"] = $sendmoney_id; - $data['action'] = WRENCHBOARD_SMONEY_BKOPROC; - $data['action_mode'] = SMONEY_PROCC_MANUAL; - $this->load->model('backend_model'); - $out = array(); - $this->backend_model->wrenchboard_api($data, $out); - echo $out['status']; - - + echo $this->sendmoneyCompletePage($data); break; } } + protected function sendmoneyCompletePage($data) { + $data['action'] = WRENCHBOARD_SMONEY_BKOPROC; + $data['action_mode'] = SMONEY_PROCC_MANUAL; + $this->load->model('backend_model'); + $out = array(); + $this->backend_model->wrenchboard_api($data, $out); + return $out['status']; + } public function smTransmitProcess() { - // url: "/bkotransaction/smprocess?proc=PROCESS&sendmoney_id="+link_id - $proc = $this->input->get('proc'); - $sendmoney_id = $this->input->get('sendmoney_id'); + // url: "/bkotransaction/smprocess?proc=PROCESS&sendmoney_id="+link_id + $proc = $this->input->get('proc'); + $sendmoney_id = $this->input->get('sendmoney_id'); - switch ($proc) { - case 'PROCESS': - $mysql = "SELECT m.id,mp.confirmation, m.added,me.firstname||' '||me.lastname||'
'||me.email AS Sender," - . "sr.firstname||' '||sr.lastname||'
ACC:'||sr.account_no||'-'||be.name AS recipient, m.initiatingamount*0.01 AS Amount,m.fee*0.01 AS Fee, " - . "'' As Detail, " - . "'' As Process " - . "FROM money_transfer m " - . "LEFT JOIN members me ON me.id=m.member_id " - . "LEFT JOIN sendmoney_recipient sr ON sr.id=m.recipientid " - . "LEFT JOIN members_payments mp ON mp.what_sendmoney = m.id " - . "LEFT JOIN bank_entity_codes be ON be.code=sr.bank_code WHERE m.id=" . $sendmoney_id; + switch ($proc) { + case 'PROCESS': + $mysql = "SELECT m.id,mp.confirmation, m.added,me.firstname||' '||me.lastname||'
'||me.email AS Sender," + . "sr.firstname||' '||sr.lastname||'
ACC:'||sr.account_no||'-'||be.name AS recipient, m.initiatingamount*0.01 AS Amount,m.fee*0.01 AS Fee, " + . "'' As Detail, " + . "'' As Process, " + . "m.initiatingamount AS raw_amount, m.fee AS raw_fee, sr.bank_code, sr.account_no " + . "FROM money_transfer m " + . "LEFT JOIN members me ON me.id=m.member_id " + . "LEFT JOIN sendmoney_recipient sr ON sr.id=m.recipientid " + . "LEFT JOIN members_payments mp ON mp.what_sendmoney = m.id " + . "LEFT JOIN bank_entity_codes be ON be.code=sr.bank_code WHERE m.id=" . $sendmoney_id; - $query = $this->db->query($mysql); - $row = $query->row_array(); + $query = $this->db->query($mysql); + $row = $query->row_array(); - echo $this->sendmoneyProcessPage($row); + echo $this->sendmoneyProcessPage($row); - break; + break; - case 'DETAIL': + case 'DETAIL': - echo 'detail'; + echo 'detail'; - break; + break; - case 'TRANSMIT': - //echo 'complete 1'; -// url: "/bkotransaction/smprocess?proc=COMPLETE&sendmoney_id="+link_id+'&tcode='+tcode+'&tref='+tref - $data["trans_code"] = $this->input->get('tcode'); - $data["trans_tref"] = $this->input->get('tref'); - $data["sendmoney_id"] = $sendmoney_id; - $data['action'] = WRENCHBOARD_SMONEY_BKOPROC; - $data['action_mode'] = SMONEY_PROCC_INTERSWITCH; - $this->load->model('backend_model'); - $out = array(); - $this->backend_model->wrenchboard_api($data, $out); - echo $out['status']; - - - - break; + case 'TRANSMIT': + //echo 'complete 1'; + // url: "/bkotransaction/smprocess?proc=COMPLETE&sendmoney_id="+link_id+'&tcode='+tcode+'&tref='+tref + $data["trans_code"] = $this->input->get('tcode'); + $data["trans_tref"] = $this->input->get('tref'); + $data["sendmoney_id"] = $sendmoney_id; + $mysql = "SELECT m.id,mp.confirmation, m.added,me.firstname||' '||me.lastname||'
'||me.email AS sender, + sr.firstname||' '||sr.lastname||'
ACC:'||sr.account_no||'-'||be.name AS recipient, + m.initiatingamount*0.01 AS amount, m.fee*0.01 AS fee, + m.initiatingamount AS raw_amount, m.fee AS raw_fee, sr.bank_code, sr.account_no + FROM money_transfer m + LEFT JOIN members me ON me.id=m.member_id + LEFT JOIN sendmoney_recipient sr ON sr.id=m.recipientid + LEFT JOIN members_payments mp ON mp.what_sendmoney = m.id + LEFT JOIN bank_entity_codes be ON be.code=sr.bank_code WHERE m.id=" . $sendmoney_id; + + $query = $this->db->query($mysql); + $row = $query->row_array(); + + echo $this->sendmoneyProcessPage($row, $data); + /* + $data['action'] = WRENCHBOARD_SMONEY_BKOPROC; + $data['action_mode'] = SMONEY_PROCC_INTERSWITCH; + $this->load->model('backend_model'); + $out = array(); + $this->backend_model->wrenchboard_api($data, $out); + echo $out['status']; + */ + break; + } } - } private function TransmitSendmoneyProcessPage($out) { - $myTable = "
"; - $myTable .=""; - $myTable .=""; - $myTable .=""; - $myTable .=""; - $myTable .=""; - $myTable .=""; - - $myTable .=""; - $myTable .="
Confirmation" . $out['confirmation'] . "
Trx. Date" . $out['added'] . "
Sender" . $out['sender'] . "
Recipient" . $out['recipient'] . "
Amount" . $out['amount'] . "
Fee" . $out['fee'] . "
"; + $myTable = "
"; + $myTable .=""; + $myTable .=""; + $myTable .=""; + $myTable .=""; + $myTable .=""; + $myTable .=""; + + $myTable .=""; + $myTable .="
Confirmation" . $out['confirmation'] . "
Trx. Date" . $out['added'] . "
Sender" . $out['sender'] . "
Recipient" . $out['recipient'] . "
Amount" . $out['amount'] . "
Fee" . $out['fee'] . "
"; - return $myTable; - } + return $myTable; + } - private function sendmoneyProcessPage($out) { + private function sendmoneyProcessPage($out, $page=array()) { + $data = array( + "account_bank" => $out['bank_code'], + "account_number" => $out['account_no'], + "amount" => $out['raw_amount'], + "narration" => $out['sender'], + "currency" => "NGN", + "reference" => $out['id'], + "debit_currency" => "NGN" + ); + $url = "http://localhost:3000/create"; + $ch = curl_init(); + curl_setopt($ch,CURLOPT_URL, $url); + curl_setopt($ch,CURLOPT_POST, count($data)); + curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($data)); + curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type:application/json')); + curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE); + $result = curl_exec($ch); + curl_close($ch); - $myTable = "
"; + $data = json_decode($result, true); + // Error + // {"status":"failure","message":"Invalid response","details":"Request failed with status code 400","code":400,"data":{"status":"error","code":"UNAUTHORIZED_ACCESS","message":"Unauthorized access. Compliance approval required to use this feature"}} + // Success + // ??? + $page["message"] = ""; + if ($data == null || $data == "" || (array_key_exists("status",$data) && $data["status"]=="failure")) { + if ($data == null || $data == "") { + // Invalid response, not clear what is going on (non-JSON response from the payment API) + $page["message"] = "Invalid payment API respose: ".htmlentities($result); + } else if (array_key_exists("data",$data) && array_key_exists("message",$data["data"])) { + // Payment processor message + $page["message"] = $data["data"]["message"]; + } else if (array_key_exists("message",$data)) { + // Payment API message + $page["message"] = $data["message"]; + } else { + // Not clear what is going on (failure with no messages?) + $page["message"] = "Invalid payment API respose: ".htmlentities($result); + } + } else { + // TODO: success + } + // $page['confirmation'] + // $page['trans_code'] + // $data['trans_tref'] + + $myTable = ""; + $myTable .="".$page["message"].""; + $myTable .="
"; $myTable .=""; $myTable .=""; $myTable .=""; diff --git a/www/svs/api/.htaccess b/www/svs/api/.htaccess new file mode 100644 index 00000000..1939eddc --- /dev/null +++ b/www/svs/api/.htaccess @@ -0,0 +1,22 @@ + + +RewriteEngine On +RewriteBase /svs/api/ +#RewriteBase / + +#Checks to +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ index.php?endpoint=$1 [L,NC,QSA] + + + + + # If we don't have mod_rewrite installed, all 404's + # can be sent to index.php, and everything works as normal. + # Submitted by: ElliotHaughin + +ErrorDocument 404 /index.php + + + diff --git a/www/svs/api/index.php b/www/svs/api/index.php new file mode 100644 index 00000000..d3da8303 --- /dev/null +++ b/www/svs/api/index.php @@ -0,0 +1,2 @@ + array('POST'), + 'generics' => array('POST') +); + +header("Access-Control-Allow-Origin: *"); +header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); +header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"); +header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS"); +header('Content-type: application/json'); + +if ("OPTIONS" === $_SERVER['REQUEST_METHOD']) { + exit(); +} + +$endpoint = strtolower(str_replace('/svs/user/', '', strtok($_SERVER['REQUEST_URI'], '?'))); + +$id = 0; // update, get & delete actions require ID +if (substr($endpoint, 0, 19) == 'gettransportrequest' || substr($endpoint, 0, 13) == 'updateprofile') { + $endpoint = strtok($endpoint, '/'); + $id = strtok('/'); +} + +if (!isset($endpoints[$endpoint])) { + header('HTTP/1.1 400 Bad Request'); + header('Status: 400 Bad Request'); + echo "{\"status\":\"Invalid endpoint url WRB\"}"; + exit(); +} + +$methods = $endpoints[$endpoint]; + +if (array_search($_SERVER['REQUEST_METHOD'], $methods) === false) { + header('HTTP/1.1 405 Method Not Allowed'); + header('Status: 405 Method Not Allowed'); + echo "{\"status\":\"Invalid request method\"}"; + exit(); +} + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $in = flatten(json_decode(file_get_contents('php://input'), true)); +} +if ($_SERVER["REQUEST_METHOD"] == "PUT") { + parse_str(file_get_contents('php://input'), $in); +} +if ($_SERVER["REQUEST_METHOD"] == "GET") { + $in = $_GET; +} +$in["loc"] = $_SERVER["REMOTE_ADDR"]; +switch ($endpoint) { + case 'generics': + case 'apigate': + //$in["action"] = WRENCHBOARD_ACCOUNT_LOGIN; + break; +} + + + +$in["pid"] = 100; +$out = array(); +$ret = $wrenchboard->wrenchboard_api($in, $out); +$out['internal_return'] = $ret; // this is reserved array parameter - to be caprured and reoved before you use the out array() + +header("HTTP/1.1 200 OK"); +header("Status: 200 OK"); +//$out = array_merge($in, $out); // DEBUG +echo json_encode(processOutJson($in, $out)); +exit(); + +function flatten($data, $parentkey = "") { + $result = array(); + foreach ($data as $key => $val) { + if (is_array($val)) { + $result = array_merge($result, flatten($val, $parentkey . $key . "_")); + } else { + $result[$parentkey . $key] = $val; + } + } + return $result; +} + +
Confirmation" . $out['confirmation'] . "
Trx. Date" . $out['added'] . "
Sender" . $out['sender'] . "