diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 33e8759..66fe24e 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -174,6 +174,38 @@ abstract class BaseController extends Controller return $response; } + private function sendSMS33($smsNumber,$smsMessage){ + + $base_url = "https://v3.api.termii.com"; + $api_key = "TLYsgMTZBeasJHHimcWXG1QPHmjH7FPwnbKwiqTEwGCu6TrK0v13hCn8N6SYZp"; + + $curl = curl_init(); + $data = array("api_key" => $api_key, "to" => $smsNumber, "from" => "digiFi", + "sms" => $smsMessage, "type" => "plain", "channel" => "generic" ); + + $post_data = json_encode($data); + + curl_setopt_array($curl, array( + CURLOPT_URL => $base_url."/api/sms/send", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => $post_data, + CURLOPT_HTTPHEADER => array( + "Content-Type: application/json" + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + return $response; + } + public function readCustomer($uid){ $userUid = trim($uid); $mysql ="SELECT * from customers where uid::text ='".$userUid."'"; diff --git a/app/Controllers/DigiFiBVN.php b/app/Controllers/DigiFiBVN.php index db42dbd..4e1cbf4 100644 --- a/app/Controllers/DigiFiBVN.php +++ b/app/Controllers/DigiFiBVN.php @@ -19,6 +19,21 @@ class DigiFiBVN extends BaseController $this->request = \Config\Services::request(); } + private function verifyOTP($verification_id, $otp): bool{ + $ret = false; + $sqlC = " SELECT * FROM + bvn_checks + WHERE pin ='".$otp."' + AND uid= '".$verification_id."' "; + + $query = $this->db->query($sqlC); + $results = $query->getResultArray(); + if ( count($results) > 0 ){ + + $ret = true; + } + return $ret; + } public function completeBVNVerify(){ @@ -27,7 +42,7 @@ class DigiFiBVN extends BaseController && $data['verification_id'] !='' && $data['otp'] !='' ) { - if ( $data['otp'] !='12345'){ + if ( !$this->verifyOTP($data['verification_id'], $data['otp']) /* $data['otp'] !='12345'*/){ $response = [ 'message' => 'Invalid account or OTP', 'call_return' => '0', @@ -111,6 +126,11 @@ class DigiFiBVN extends BaseController "last_login"=> "2024-04-26 13:35:19.750027", "test" => $results, */ + + //+2347032847884 + // + // sendSMS($smsNumber,$smsMessage) + public function startBVNVerify() { $data = $this->request->getPost(); @@ -118,10 +138,24 @@ class DigiFiBVN extends BaseController if ($data['bvn'] != '') { $bvnData = $this->APIcall("POST", "http://10.10.10.48:6332/api/verify/bvn", json_encode($data)); + // send SMS HERE + $pin = rand(10000, 99999); + $smsSend = $this->sendSMS("2347032847884", "This is your pin number ". $pin); + //+2347032847884 + // + // sendSMS($smsNumber,$smsMessage) + + /* + SMS API PORTAL + https://accounts.termii.com/#/ + Email - mdigifi@gmail.com + Password - Clust@r24 + */ $udata = [ - 'bvn' => $data['bvn'] + 'bvn' => $data['bvn'], + 'pin' => $pin ]; $addedData = $this->insert_db('bvn_checks',$udata); @@ -135,6 +169,8 @@ class DigiFiBVN extends BaseController return $this->fail($response, 500); } + $workingUID = $addedData["uid"]; + /* *| Type | Collation | Nullable | Default -------------+-----------------------------+-----------+----------+---------------------------------------- @@ -176,12 +212,23 @@ Indexes: - $sqlUpdate = "UPDATE bvn_checks SET firstname ='$firstname', lastname='$lastname', middlename='$middlename' , phone='$phone' , birthdate='$birthdate' , gender='$gender' , nationality='$nationality' WHERE bvn = '$bvn' "; + $sqlUpdate = "UPDATE bvn_checks + SET firstname ='$firstname', + lastname='$lastname', + middlename='$middlename' , + phone='$phone' , + birthdate='$birthdate' , + gender='$gender' , + nationality='$nationality' + WHERE bvn = '$bvn' + AND uid::text = '".$workingUID."' "; + log_message('critical', "BVN UPDATE URL FINAL => ".$sqlUpdate ); $query = $this->db->query($sqlUpdate); $response = [ 'message' => 'Verification text sent to user', 'call_return' => '100', + 'sms_send' => $smsSend, 'verification_id' => $addedData["uid"], 'status' => $bvnData["res"]["status"], 'test_bvn' => $bvnData["res"]["data"]