Files
digifi-mware/app/Controllers/Users.php
T
CHIEFSOFT\ameye eab96e3504 New card add
2024-08-05 11:30:39 -04:00

147 lines
4.8 KiB
PHP

<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
class Users extends BaseController
{
use ResponseTrait;
var $request;
function __construct()
{
$this->request = \Config\Services::request();
}
private function assignInternalEmail($id, $uid){
$intE = "message+".str_pad($id, 12, "0", STR_PAD_LEFT)."@chiefsoft.com";
$mysql = "UPDATE customers SET internal_email='".$intE."' WHERE internal_email IS NULL AND id = $id AND uid = '".$uid."'";
$this->db->query($mysql);
return $this->readCustomer($uid);
}
public function userAddCard(){
$in = $this->request->getPost();
$loan_uid = $in["application_uid"];
// $userUid = trim($in["uid"]);
// $mysql ="SELECT id,internal_email from customers where uid ='"+$userUid+"'";
// $query = $this->db->query($mysql);
$row = $this->readCustomer($in["uid"]);
$userID = 0;
$CustomerCode = '';
if (count($row)> 0){
$userID = $row["id"];
if ( $row["internal_email"] == '' ){
$row = $this->assignInternalEmail($userID, $in["uid"]);
}
$userID = $row["id"];
$userInternalEmail = $row["internal_email"];
$CustomerCode = $row["customer_code"];
}
if ( $CustomerCode == ''){
$in_data = [
"email" => $userInternalEmail,
];
$createUserResult = $this->APIcall("POST", "http://10.10.10.48:6334/create-customer", json_encode($in_data));
$CustomerCode = $createUserResult["customer_code"];
$mysql = "UPDATE customers SET customer_code = '".$CustomerCode."' WHERE id = $userID AND uid = '".$in["uid"]."' ";
$this->db->query($mysql);
// $CustomerCode = $createUserResult["customer_code"];
}
$in_data = [
"email" => $userInternalEmail,
"amount" => 500,
"plan" => "PLN_qh2dasmlhweqa1l",
];
$initResult = $this->APIcall("POST", "http://10.10.10.48:6334/initialize-transaction-with-plan", json_encode($in_data));
$data = [
'call_return' => '100',
'customer_code' => $createUserResult["customer_code"],
'redirect_url' => $initResult['authorization_url'],
];
// 'init_subscription' => $initResult
return $this->respond($data, 200);
}
public function userDash(){
$statusDetail[2] =[
"text" => "Pending",
"button" => false,
"advise" => 'Awaiting employers verification'
];
$statusDetail[4] =[
"text" => "Add Card",
"button" => true,
"advise" => 'Add payment card to continue'
];
$statusDetail[7] =[
"text" => "Canceled",
"button" => false,
"advise" => 'Application is cancelled'
];
$in = $this->request->getGet();
$data = [];
if ($in['uid'] !=''){
$query = $this->db->query("SELECT * FROM customers WHERE uid = '".$in['uid']."' ");
$row = $query->getRowArray();
$loanResult = $this->userLoan($in['uid']);
$processLoan = [];
foreach ($loanResult as $value) {
$value["status_text"] = $statusDetail[ $value["status"] ];
$processLoan[] = $value;
}
$data = [
'call_return' => '100',
'customer' => $row,
'loans' => $processLoan,
];
return $this->respond($data, 200);
//'loans' => $loanResult,
}
else{
return $this->respond(['error'=>'empty uid'], 400);
}
//return $this->respond([], 400);
}
private function userLoan($uid){
$query = $this->db->query("SELECT a.uid AS application_uid,a.loan_amount,
a.payment_month,a.status,a.added,
a.updated
FROM applications a
LEFT JOIN customers c ON c.uid = a.customer_uid WHERE a.customer_uid='".$uid."' ");
return $query->getResult('array');
}
public function userProfile(){
$in = $this->request->getGet();
$data = [];
if ($in['uid'] !=''){
$query = $this->db->query("SELECT * FROM customers WHERE uid = '".$in['uid']."' ");
$row = $query->getRowArray();
$data = [
'call_return' => '100',
'customer' => $row
];
return $this->respond($data, 200);
}else{
return $this->respond(['error'=>'empty uid'], 400);
}
// return $this->respond([], 400);
}
}