GWM : get wellness changes
This commit is contained in:
parent
053341b4a0
commit
bf6c3ddce7
@ -276,76 +276,65 @@ class ApiServiceController extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//wellness sso url generator landing
|
||||||
|
public function getWellnessUrl($emp_id)
|
||||||
public function getWellnessUrl()
|
|
||||||
{
|
{
|
||||||
|
// $emp_id = $this->request->getGet('emp_id');
|
||||||
$emp_id = $this->request->getGet('emp_id');
|
|
||||||
$client_policy_id = $this->request->getGet('client_policy_id');
|
|
||||||
|
|
||||||
$db = \Config\Database::connect();
|
$db = \Config\Database::connect();
|
||||||
|
$data = $db->table('employees e')
|
||||||
// $data = $db->table('employees e')
|
|
||||||
// ->select('pt.policy_type,
|
|
||||||
// e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation,
|
|
||||||
// cp.policy_no as policyNumber, cp.policy_no as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate')
|
|
||||||
// ->join('employee_polices ep', 'e.id = ep.employee_id')
|
|
||||||
// ->join('client_policy cp', 'ep.client_policy_id = cp.id')
|
|
||||||
// ->join('policy_type pt', 'cp.policy_type_id = pt.id')
|
|
||||||
// ->where('e.id', $emp_id)
|
|
||||||
// ->where('e.emp_status', 'active')
|
|
||||||
// ->where('ep.status', 'active')
|
|
||||||
// ->where('e.is_active', 1)
|
|
||||||
// ->where('ep.is_active', 1)
|
|
||||||
// ->get()
|
|
||||||
// ->getResultArray();
|
|
||||||
|
|
||||||
$data = $db->table('employee_polices ep')
|
|
||||||
->select('pt.policy_type,
|
->select('pt.policy_type,
|
||||||
e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, e.id as employeeId
|
e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation,
|
||||||
cp.policy_no as policyNumber, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate, cp.wellness_plan_id as planId')
|
cp.policy_no as policyNumber, ep.employee_id as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate , cp.wellness_plan_id as planId , cp.wellness_vendor_id')
|
||||||
->join('employees e', 'e.id = ep.employee_id')
|
->join('employee_polices ep', 'e.id = ep.employee_id')
|
||||||
->join('client_policy cp', 'ep.client_policy_id = cp.id')
|
->join('client_policy cp', 'ep.client_policy_id = cp.id')
|
||||||
->join('policy_type pt', 'cp.policy_type_id = pt.id')
|
->join('policy_type pt', 'cp.policy_type_id = pt.id')
|
||||||
->where('ep.employee_id', $emp_id)
|
->where('e.id', $emp_id)
|
||||||
->where('ep.client_policy_id', $client_policy_id)
|
->where('e.emp_status', 'active')
|
||||||
->where('ep.status', 'active')
|
->where('ep.status', 'active')
|
||||||
|
->where('e.is_active', 1)
|
||||||
->where('ep.is_active', 1)
|
->where('ep.is_active', 1)
|
||||||
->get()
|
->get()
|
||||||
->getRow();
|
->getResultArray();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$userParams = [];
|
$userParams = [];
|
||||||
if(!empty($data))
|
foreach ($data as $row) {
|
||||||
{
|
|
||||||
$userParams['name'] = $data->name;
|
|
||||||
$userParams['email'] = $data->email;
|
|
||||||
$userParams['phone'] = $data->phone;
|
|
||||||
$userParams['memberId'] = $data->employeeId; // memberId is unique primary key.
|
|
||||||
$userParams['gender'] = $data->gender;
|
|
||||||
$userParams['dob'] = $data->dob;
|
|
||||||
$userParams['relation'] = $data->relation;
|
|
||||||
$userParams['policyNumber'] = $data->policyNumber;
|
|
||||||
$userParams['employeeId'] = $data->memberId;
|
|
||||||
$userParams['policyStartDate']= $data->policyStartDate;
|
|
||||||
$userParams['policyEndDate'] = $data->policyEndDate;
|
|
||||||
$userParams['policyName'] = 'Nhance ' . $data->policy_type;
|
|
||||||
$userParams['planId'] = $data->planId;
|
|
||||||
$userParams['moduleName'] = 'home';
|
|
||||||
|
|
||||||
|
if($row['wellness_vendor_id'] != null)
|
||||||
|
{
|
||||||
|
$vidalApiController = new VidalApiController();
|
||||||
|
return $vidalApiController->getWellnessSSORedirectUrl($row['email']);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if ($row['planId'] != null) // VISIT
|
||||||
|
{
|
||||||
|
$userParams['name'] = $row['name'];
|
||||||
|
$userParams['email'] = $row['email'];
|
||||||
|
$userParams['phone'] = $row['phone'];
|
||||||
|
$userParams['memberId'] = $row['employeeId']; // memberId is unique primary key.
|
||||||
|
$userParams['gender'] = $row['gender'];
|
||||||
|
$userParams['dob'] = $row['dob'];
|
||||||
|
$userParams['relation'] = $row['relation'];
|
||||||
|
$userParams['policyNumber'] = $row['policyNumber'];
|
||||||
|
$userParams['employeeId'] = $row['memberId'];
|
||||||
|
$userParams['policyStartDate']= $row['policyStartDate'];
|
||||||
|
$userParams['policyEndDate'] = $row['policyEndDate'];
|
||||||
|
$userParams['policyName'] = $row['policy_type'];
|
||||||
|
$userParams['planId'] = $row['planId'];
|
||||||
|
$userParams['moduleName'] = 'home';
|
||||||
|
break; // stop after first GMC match
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dd($userParams);
|
|
||||||
|
|
||||||
if (empty($userParams)) {
|
if (empty($userParams)) {
|
||||||
return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
|
return ['status' => 'failed','message' => 'Coming soon........!'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// echo 'coming';die();
|
||||||
// Derive 32-byte key from SHA256
|
// Derive 32-byte key from SHA256
|
||||||
$derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true);
|
$derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true);
|
||||||
|
|
||||||
// Build query string like Node.js
|
// Build query string like Node.js
|
||||||
$plainText = '';
|
$plainText = '';
|
||||||
foreach ($userParams as $k => $v) {
|
foreach ($userParams as $k => $v) {
|
||||||
@ -359,153 +348,114 @@ class ApiServiceController extends BaseController
|
|||||||
|
|
||||||
// Base64URL encode (same as Node.js output)
|
// Base64URL encode (same as Node.js output)
|
||||||
$output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '=');
|
$output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '=');
|
||||||
|
|
||||||
$baseURL = env('VISIT_BASE_URL');
|
$baseURL = env('VISIT_BASE_URL');
|
||||||
$clientId = env('VISIT_CLIENT_ID');
|
$clientId = env('VISIT_CLIENT_ID');
|
||||||
$finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId;
|
$finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId;
|
||||||
|
|
||||||
if (!empty($finalUrl)) {
|
if (!empty($finalUrl)) {
|
||||||
log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl);
|
log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl);
|
||||||
return $this->respond(['status' => 'success','data' => $finalUrl], 200);
|
return ['status' => 'success','data' => $finalUrl];
|
||||||
} else {
|
} else {
|
||||||
return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
|
return ['status' => 'failed','message' => 'Coming soon........!'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSSORedirectUrl($email = 'test@getvisitapp.com')
|
|
||||||
{
|
|
||||||
log_message('info', "SSO: Starting authentication for email: $email");
|
|
||||||
|
|
||||||
// ---------- CONFIG ----------
|
|
||||||
$authUrl = env('VIDAL_WELLNESS_BASE_URL');
|
|
||||||
$subscriptionKey = env('VIDAL_WELLNESS_SUBSCRIPTION_KEY');
|
|
||||||
$apiVersion = "1";
|
|
||||||
|
|
||||||
// Provided Base64 AES key
|
|
||||||
$base64Key = env('VIDAL_WELLNESS_BASE64_KEY');
|
|
||||||
$key = base64_decode($base64Key);
|
|
||||||
|
|
||||||
log_message('info', "SSO: Config loaded, Auth URL: $authUrl");
|
|
||||||
|
|
||||||
// ---------- STEP 1: Build plaintext payload ----------
|
// public function getWellnessUrl()
|
||||||
$plainPayload = json_encode([
|
// {
|
||||||
"email" => $email,
|
|
||||||
// "corporateId" => env('VIDAL_WELLNESS_CORPORATE_ID'),
|
|
||||||
"urlIdentifier" => env('VIDAL_WELLNESS_URL_IDENTIFIER')
|
|
||||||
]);
|
|
||||||
|
|
||||||
// ---------- STEP 2: Encrypt payload ----------
|
// $emp_id = $this->request->getGet('emp_id');
|
||||||
$iv = random_bytes(16);
|
// $client_policy_id = $this->request->getGet('client_policy_id');
|
||||||
$encryptedRaw = openssl_encrypt($plainPayload, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv);
|
|
||||||
|
|
||||||
$encryptedPayload = base64_encode($iv) . ":" . base64_encode($encryptedRaw);
|
// $db = \Config\Database::connect();
|
||||||
|
|
||||||
log_message('info', "SSO: Payload encrypted successfully");
|
|
||||||
|
|
||||||
// ---------- STEP 3: Call Authentication API ----------
|
// // $data = $db->table('employees e')
|
||||||
$requestBody = json_encode([
|
// // ->select('pt.policy_type,
|
||||||
"payload" => $encryptedPayload,
|
// // e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation,
|
||||||
"source" => env('VIDAL_WELLNESS_SUB_PARTNER_ID'),
|
// // cp.policy_no as policyNumber, cp.policy_no as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate')
|
||||||
"subPartnerId" => env('VIDAL_WELLNESS_SUB_PARTNER_ID')
|
// // ->join('employee_polices ep', 'e.id = ep.employee_id')
|
||||||
]);
|
// // ->join('client_policy cp', 'ep.client_policy_id = cp.id')
|
||||||
|
// // ->join('policy_type pt', 'cp.policy_type_id = pt.id')
|
||||||
|
// // ->where('e.id', $emp_id)
|
||||||
|
// // ->where('e.emp_status', 'active')
|
||||||
|
// // ->where('ep.status', 'active')
|
||||||
|
// // ->where('e.is_active', 1)
|
||||||
|
// // ->where('ep.is_active', 1)
|
||||||
|
// // ->get()
|
||||||
|
// // ->getResultArray();
|
||||||
|
|
||||||
$headers = [
|
// $data = $db->table('employee_polices ep')
|
||||||
"Ocp-Apim-Subscription-Key: $subscriptionKey",
|
// ->select('pt.policy_type,
|
||||||
"apiver: $apiVersion",
|
// e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, e.id as employeeId
|
||||||
"mode: encrypt",
|
// cp.policy_no as policyNumber, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate, cp.wellness_plan_id as planId')
|
||||||
"Content-Type: application/json"
|
// ->join('employees e', 'e.id = ep.employee_id')
|
||||||
];
|
// ->join('client_policy cp', 'ep.client_policy_id = cp.id')
|
||||||
|
// ->join('policy_type pt', 'cp.policy_type_id = pt.id')
|
||||||
|
// ->where('ep.employee_id', $emp_id)
|
||||||
|
// ->where('ep.client_policy_id', $client_policy_id)
|
||||||
|
// ->where('ep.status', 'active')
|
||||||
|
// ->where('ep.is_active', 1)
|
||||||
|
// ->get()
|
||||||
|
// ->getRow();
|
||||||
|
|
||||||
$ch = curl_init($authUrl);
|
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
|
// $userParams = [];
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
// if(!empty($data))
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
// {
|
||||||
|
// $userParams['name'] = $data->name;
|
||||||
|
// $userParams['email'] = $data->email;
|
||||||
|
// $userParams['phone'] = $data->phone;
|
||||||
|
// $userParams['memberId'] = $data->employeeId; // memberId is unique primary key.
|
||||||
|
// $userParams['gender'] = $data->gender;
|
||||||
|
// $userParams['dob'] = $data->dob;
|
||||||
|
// $userParams['relation'] = $data->relation;
|
||||||
|
// $userParams['policyNumber'] = $data->policyNumber;
|
||||||
|
// $userParams['employeeId'] = $data->memberId;
|
||||||
|
// $userParams['policyStartDate']= $data->policyStartDate;
|
||||||
|
// $userParams['policyEndDate'] = $data->policyEndDate;
|
||||||
|
// $userParams['policyName'] = 'Nhance ' . $data->policy_type;
|
||||||
|
// $userParams['planId'] = $data->planId;
|
||||||
|
// $userParams['moduleName'] = 'home';
|
||||||
|
|
||||||
$apiResponse = curl_exec($ch);
|
// }
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
||||||
$curlError = curl_error($ch);
|
// // dd($userParams);
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
log_message('info', "SSO: API response received, HTTP Code: $httpCode");
|
|
||||||
|
|
||||||
// Check for cURL errors
|
// if (empty($userParams)) {
|
||||||
if ($curlError) {
|
// return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
|
||||||
log_message('error', "SSO: cURL error - $curlError");
|
// }
|
||||||
return ["error" => "cURL error: $curlError"];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check HTTP status
|
// // Derive 32-byte key from SHA256
|
||||||
if ($httpCode !== 200) {
|
// $derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true);
|
||||||
log_message('error', "SSO: HTTP error - Code: $httpCode, Response: $apiResponse");
|
|
||||||
return ["error" => "HTTP error: $httpCode", "response" => $apiResponse];
|
|
||||||
}
|
|
||||||
|
|
||||||
$jsonResponse = json_decode($apiResponse, true);
|
// // Build query string like Node.js
|
||||||
|
// $plainText = '';
|
||||||
// Check JSON decode error
|
// foreach ($userParams as $k => $v) {
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
// $plainText .= "&{$k}={$v}";
|
||||||
log_message('error', "SSO: JSON decode error - " . json_last_error_msg());
|
// }
|
||||||
return ["error" => "JSON decode error: " . json_last_error_msg(), "response" => $apiResponse];
|
// $plainText = ltrim($plainText, '&');
|
||||||
}
|
|
||||||
|
// // Encrypt
|
||||||
// Check API response status
|
// $algorithm = "aes-256-cbc";
|
||||||
if (!isset($jsonResponse["status"]) || $jsonResponse["status"] !== "success") {
|
// $encrypted = openssl_encrypt($plainText, $algorithm, $derivedKey, OPENSSL_RAW_DATA, env('VISIT_IV'));
|
||||||
log_message('error', "SSO: API error - " . json_encode($jsonResponse));
|
|
||||||
return ["error" => "API error", "response" => $jsonResponse];
|
// // Base64URL encode (same as Node.js output)
|
||||||
}
|
// $output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '=');
|
||||||
|
|
||||||
if (!isset($jsonResponse["data"])) {
|
|
||||||
log_message('error', "SSO: Missing data field in response");
|
|
||||||
return ["error" => "Invalid API response - missing data field", "response" => $jsonResponse];
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message('info', "SSO: API response validated successfully");
|
|
||||||
|
|
||||||
// ---------- STEP 4: Decrypt response ----------
|
|
||||||
log_message('info', "SSO: Starting response decryption");
|
|
||||||
|
|
||||||
$dataParts = explode(":", $jsonResponse["data"]);
|
|
||||||
|
|
||||||
if (count($dataParts) !== 2) {
|
|
||||||
log_message('error', "SSO: Invalid encrypted data format");
|
|
||||||
return ["error" => "Invalid encrypted data format", "data" => $jsonResponse["data"]];
|
|
||||||
}
|
|
||||||
|
|
||||||
list($ivBase64, $cipherBase64) = $dataParts;
|
|
||||||
|
|
||||||
$respIv = base64_decode($ivBase64);
|
|
||||||
$respCipher = base64_decode($cipherBase64);
|
|
||||||
|
|
||||||
if ($respIv === false || $respCipher === false) {
|
|
||||||
log_message('error', "SSO: Base64 decode error");
|
|
||||||
return ["error" => "Base64 decode error"];
|
|
||||||
}
|
|
||||||
|
|
||||||
$decryptedJson = openssl_decrypt($respCipher, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $respIv);
|
|
||||||
|
|
||||||
if ($decryptedJson === false) {
|
|
||||||
log_message('error', "SSO: Decryption failed");
|
|
||||||
return ["error" => "Decryption failed"];
|
|
||||||
}
|
|
||||||
|
|
||||||
$decryptedData = json_decode($decryptedJson, true);
|
|
||||||
|
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
||||||
log_message('error', "SSO: Decrypted JSON decode error - " . json_last_error_msg());
|
|
||||||
return ["error" => "Decrypted JSON decode error: " . json_last_error_msg()];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($decryptedData["redirectUrl"])) {
|
|
||||||
log_message('error', "SSO: redirectUrl missing in decrypted data");
|
|
||||||
return ["error" => "redirectUrl missing", "decrypted" => $decryptedData];
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- FINAL ----------
|
|
||||||
log_message('info', "SSO: Authentication successful, redirectUrl obtained");
|
|
||||||
return $decryptedData["redirectUrl"];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// $baseURL = env('VISIT_BASE_URL');
|
||||||
|
// $clientId = env('VISIT_CLIENT_ID');
|
||||||
|
// $finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId;
|
||||||
|
|
||||||
|
// if (!empty($finalUrl)) {
|
||||||
|
// log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl);
|
||||||
|
// return $this->respond(['status' => 'success','data' => $finalUrl], 200);
|
||||||
|
// } else {
|
||||||
|
// return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
// function getSSORedirectUrl($email = 'user@example.com')
|
// function getSSORedirectUrl($email = 'user@example.com')
|
||||||
|
|||||||
@ -3028,7 +3028,8 @@ class EmployeeRestController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$emp_reatail_policy_data = $this->getEmpRetailPolicy($employeeSelfData);
|
$emp_reatail_policy_data = $this->getEmpRetailPolicy($employeeSelfData);
|
||||||
$emp_wellness_data = $this->getWellnessUrl($employeeSelfData->id ?? null);
|
$apiServiceController = new ApiServiceController;
|
||||||
|
$emp_wellness_data = $apiServiceController->getWellnessUrl($employeeSelfData->id ?? null);
|
||||||
|
|
||||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'emp_name' => $employeeName, 'pre_policy_count' => $prePolicyCount, 'emp_not_enrolled_count' => $empNotEnrolledCount, 'retail_policy_data' => $emp_reatail_policy_data, 'wellness_data' => $emp_wellness_data], 200);
|
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'emp_name' => $employeeName, 'pre_policy_count' => $prePolicyCount, 'emp_not_enrolled_count' => $empNotEnrolledCount, 'retail_policy_data' => $emp_reatail_policy_data, 'wellness_data' => $emp_wellness_data], 200);
|
||||||
} else {
|
} else {
|
||||||
@ -5012,81 +5013,7 @@ class EmployeeRestController extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWellnessUrl($emp_id)
|
|
||||||
{
|
|
||||||
// $emp_id = $this->request->getGet('emp_id');
|
|
||||||
|
|
||||||
$db = \Config\Database::connect();
|
|
||||||
$data = $db->table('employees e')
|
|
||||||
->select('pt.policy_type,
|
|
||||||
e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation,
|
|
||||||
cp.policy_no as policyNumber, ep.employee_id as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate , cp.wellness_plan_id as planId')
|
|
||||||
->join('employee_polices ep', 'e.id = ep.employee_id')
|
|
||||||
->join('client_policy cp', 'ep.client_policy_id = cp.id')
|
|
||||||
->join('policy_type pt', 'cp.policy_type_id = pt.id')
|
|
||||||
->where('e.id', $emp_id)
|
|
||||||
->where('e.emp_status', 'active')
|
|
||||||
->where('ep.status', 'active')
|
|
||||||
->where('e.is_active', 1)
|
|
||||||
->where('ep.is_active', 1)
|
|
||||||
->get()
|
|
||||||
->getResultArray();
|
|
||||||
|
|
||||||
|
|
||||||
$userParams = [];
|
|
||||||
foreach ($data as $row) {
|
|
||||||
if ($row['planId'] != null) {
|
|
||||||
$userParams['name'] = $row['name'];
|
|
||||||
$userParams['email'] = $row['email'];
|
|
||||||
$userParams['phone'] = $row['phone'];
|
|
||||||
$userParams['memberId'] = $row['employeeId']; // memberId is unique primary key.
|
|
||||||
$userParams['gender'] = $row['gender'];
|
|
||||||
$userParams['dob'] = $row['dob'];
|
|
||||||
$userParams['relation'] = $row['relation'];
|
|
||||||
$userParams['policyNumber'] = $row['policyNumber'];
|
|
||||||
$userParams['employeeId'] = $row['memberId'];
|
|
||||||
$userParams['policyStartDate']= $row['policyStartDate'];
|
|
||||||
$userParams['policyEndDate'] = $row['policyEndDate'];
|
|
||||||
$userParams['policyName'] = $row['policy_type'];
|
|
||||||
$userParams['planId'] = $row['planId'];
|
|
||||||
$userParams['moduleName'] = 'home';
|
|
||||||
break; // stop after first GMC match
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($userParams)) {
|
|
||||||
return ['status' => 'failed','message' => 'Coming soon........!'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// echo 'coming';die();
|
|
||||||
// Derive 32-byte key from SHA256
|
|
||||||
$derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true);
|
|
||||||
|
|
||||||
// Build query string like Node.js
|
|
||||||
$plainText = '';
|
|
||||||
foreach ($userParams as $k => $v) {
|
|
||||||
$plainText .= "&{$k}={$v}";
|
|
||||||
}
|
|
||||||
$plainText = ltrim($plainText, '&');
|
|
||||||
|
|
||||||
// Encrypt
|
|
||||||
$algorithm = "aes-256-cbc";
|
|
||||||
$encrypted = openssl_encrypt($plainText, $algorithm, $derivedKey, OPENSSL_RAW_DATA, env('VISIT_IV'));
|
|
||||||
|
|
||||||
// Base64URL encode (same as Node.js output)
|
|
||||||
$output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '=');
|
|
||||||
|
|
||||||
$baseURL = env('VISIT_BASE_URL');
|
|
||||||
$clientId = env('VISIT_CLIENT_ID');
|
|
||||||
$finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId;
|
|
||||||
|
|
||||||
if (!empty($finalUrl)) {
|
|
||||||
log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl);
|
|
||||||
return ['status' => 'success','data' => $finalUrl];
|
|
||||||
} else {
|
|
||||||
return ['status' => 'failed','message' => 'Coming soon........!'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPolicyTypeAndInsurer()
|
public function getPolicyTypeAndInsurer()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -632,10 +632,10 @@ class MediAssistApiController extends BaseController
|
|||||||
if (!$ticket || empty($ticket['ClaimID'])) {
|
if (!$ticket || empty($ticket['ClaimID'])) {
|
||||||
log_message('error', "IRSubmission FAILED → ClaimID NOT FOUND for ticket_id={$claimId}");
|
log_message('error', "IRSubmission FAILED → ClaimID NOT FOUND for ticket_id={$claimId}");
|
||||||
|
|
||||||
return $this->response->setJSON([
|
return [
|
||||||
'status' => false,
|
'status' => false,
|
||||||
'message' => "ClaimID not found for ticket {$claimId}"
|
'message' => "ClaimID not found for ticket {$claimId}"
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. FETCH IR ATTACHMENTS
|
// 2. FETCH IR ATTACHMENTS
|
||||||
|
|||||||
@ -266,6 +266,140 @@ class VidalApiController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getWellnessSSORedirectUrl($email = 'test@getvisitapp.com')
|
||||||
|
{
|
||||||
|
log_message('info', "SSO: Starting authentication for email: $email");
|
||||||
|
|
||||||
|
// ---------- CONFIG ----------
|
||||||
|
$authUrl = env('VIDAL_WELLNESS_BASE_URL');
|
||||||
|
$subscriptionKey = env('VIDAL_WELLNESS_SUBSCRIPTION_KEY');
|
||||||
|
$apiVersion = "1";
|
||||||
|
|
||||||
|
// Provided Base64 AES key
|
||||||
|
$base64Key = env('VIDAL_WELLNESS_BASE64_KEY');
|
||||||
|
$key = base64_decode($base64Key);
|
||||||
|
|
||||||
|
log_message('info', "SSO: Config loaded, Auth URL: $authUrl");
|
||||||
|
|
||||||
|
// ---------- STEP 1: Build plaintext payload ----------
|
||||||
|
$plainPayload = json_encode([
|
||||||
|
"email" => $email,
|
||||||
|
// "corporateId" => env('VIDAL_WELLNESS_CORPORATE_ID'),
|
||||||
|
"urlIdentifier" => env('VIDAL_WELLNESS_URL_IDENTIFIER')
|
||||||
|
]);
|
||||||
|
|
||||||
|
// ---------- STEP 2: Encrypt payload ----------
|
||||||
|
$iv = random_bytes(16);
|
||||||
|
$encryptedRaw = openssl_encrypt($plainPayload, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv);
|
||||||
|
|
||||||
|
$encryptedPayload = base64_encode($iv) . ":" . base64_encode($encryptedRaw);
|
||||||
|
|
||||||
|
log_message('info', "SSO: Payload encrypted successfully");
|
||||||
|
|
||||||
|
// ---------- STEP 3: Call Authentication API ----------
|
||||||
|
$requestBody = json_encode([
|
||||||
|
"payload" => $encryptedPayload,
|
||||||
|
"source" => env('VIDAL_WELLNESS_SUB_PARTNER_ID'),
|
||||||
|
"subPartnerId" => env('VIDAL_WELLNESS_SUB_PARTNER_ID')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
"Ocp-Apim-Subscription-Key: $subscriptionKey",
|
||||||
|
"apiver: $apiVersion",
|
||||||
|
"mode: encrypt",
|
||||||
|
"Content-Type: application/json"
|
||||||
|
];
|
||||||
|
|
||||||
|
$ch = curl_init($authUrl);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
$apiResponse = curl_exec($ch);
|
||||||
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curlError = curl_error($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
log_message('info', "SSO: API response received, HTTP Code: $httpCode");
|
||||||
|
|
||||||
|
// Check for cURL errors
|
||||||
|
if ($curlError) {
|
||||||
|
log_message('error', "SSO: cURL error - $curlError");
|
||||||
|
return ['status' => 'failed','message' => $curlError];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check HTTP status
|
||||||
|
if ($httpCode !== 200) {
|
||||||
|
log_message('error', "SSO: HTTP error - Code: $httpCode, Response: $apiResponse");
|
||||||
|
return ['status' => 'failed','message' => "HTTP error: $httpCode" , "response" => $apiResponse ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$jsonResponse = json_decode($apiResponse, true);
|
||||||
|
|
||||||
|
// Check JSON decode error
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
log_message('error', "SSO: JSON decode error - " . json_last_error_msg());
|
||||||
|
return ['status' => 'failed','message' => "JSON decode error: " . json_last_error_msg(), "response" => $apiResponse];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check API response status
|
||||||
|
if (!isset($jsonResponse["status"]) || $jsonResponse["status"] !== "success") {
|
||||||
|
log_message('error', "SSO: API error - " . json_encode($jsonResponse));
|
||||||
|
return ['status' => 'failed','message' => "API error", "response" => $jsonResponse];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($jsonResponse["data"])) {
|
||||||
|
log_message('error', "SSO: Missing data field in response");
|
||||||
|
return ['status' => 'failed','message' => "Invalid API response - missing data field", "response" => $jsonResponse];
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message('info', "SSO: API response validated successfully");
|
||||||
|
|
||||||
|
// ---------- STEP 4: Decrypt response ----------
|
||||||
|
log_message('info', "SSO: Starting response decryption");
|
||||||
|
|
||||||
|
$dataParts = explode(":", $jsonResponse["data"]);
|
||||||
|
|
||||||
|
if (count($dataParts) !== 2) {
|
||||||
|
log_message('error', "SSO: Invalid encrypted data format");
|
||||||
|
return ['status' => 'failed','message' => "Invalid encrypted data format", "data" => $jsonResponse["data"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
list($ivBase64, $cipherBase64) = $dataParts;
|
||||||
|
|
||||||
|
$respIv = base64_decode($ivBase64);
|
||||||
|
$respCipher = base64_decode($cipherBase64);
|
||||||
|
|
||||||
|
if ($respIv === false || $respCipher === false) {
|
||||||
|
log_message('error', "SSO: Base64 decode error");
|
||||||
|
return ['status' => 'failed','message' => "Base64 decode error"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$decryptedJson = openssl_decrypt($respCipher, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $respIv);
|
||||||
|
|
||||||
|
if ($decryptedJson === false) {
|
||||||
|
log_message('error', "SSO: Decryption failed");
|
||||||
|
return ['status' => 'failed','message' => "Decryption failed"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$decryptedData = json_decode($decryptedJson, true);
|
||||||
|
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
log_message('error', "SSO: Decrypted JSON decode error - " . json_last_error_msg());
|
||||||
|
return ['status' => 'failed','message' => "Decrypted JSON decode error: " . json_last_error_msg()];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($decryptedData["redirectUrl"])) {
|
||||||
|
log_message('error', "SSO: redirectUrl missing in decrypted data");
|
||||||
|
return ['status' => 'failed','message' => "redirectUrl missing", "decrypted" => $decryptedData];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- FINAL ----------
|
||||||
|
log_message('info', "SSO: Authentication successful, redirectUrl obtained");
|
||||||
|
return ['status' => 'success','data' => $decryptedData["redirectUrl"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------yet to start only submit claim given
|
//----------yet to start only submit claim given
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user