FEAT_CLIENT_API_FIRST_COMMIT_SRI
This commit is contained in:
parent
3da45edd0f
commit
6d855d95ac
@ -12,6 +12,7 @@ use CodeIgniter\Filters\SecureHeaders;
|
|||||||
use App\Filters\AuthMVC;
|
use App\Filters\AuthMVC;
|
||||||
use App\Filters\HttpRequestLog;
|
use App\Filters\HttpRequestLog;
|
||||||
use App\Filters\CloseDbConnection;
|
use App\Filters\CloseDbConnection;
|
||||||
|
use App\Filters\AuthClientApi;
|
||||||
|
|
||||||
use App\Filters\AuthJWT;
|
use App\Filters\AuthJWT;
|
||||||
|
|
||||||
@ -34,6 +35,7 @@ class Filters extends BaseConfig
|
|||||||
'authMVC' => AuthMVC::class,
|
'authMVC' => AuthMVC::class,
|
||||||
'HttpRequestLog' => HttpRequestLog::class,
|
'HttpRequestLog' => HttpRequestLog::class,
|
||||||
'authJWT' => AuthJWT::class,
|
'authJWT' => AuthJWT::class,
|
||||||
|
'AuthClientApi' => AuthClientApi::class,
|
||||||
'CloseDbConnection' => CloseDbConnection::class
|
'CloseDbConnection' => CloseDbConnection::class
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -87,6 +87,8 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) {
|
|||||||
$routes->get('view_deposit/(:num)', 'ClientController::view_Deposit/$1');
|
$routes->get('view_deposit/(:num)', 'ClientController::view_Deposit/$1');
|
||||||
$routes->get('createtransaction', 'ClientController::createtransaction');
|
$routes->get('createtransaction', 'ClientController::createtransaction');
|
||||||
$routes->post('save_deposit', 'ClientController::saveDeposit');
|
$routes->post('save_deposit', 'ClientController::saveDeposit');
|
||||||
|
$routes->post("saveApiData", "ClientController::saveApiData");
|
||||||
|
$routes->get("generateToken","ClientController::sendToken");
|
||||||
// $routes->get('view_Deposit/(:num)/(:num)','ClientController/view_Deposit/$1/$2');
|
// $routes->get('view_Deposit/(:num)/(:num)','ClientController/view_Deposit/$1/$2');
|
||||||
|
|
||||||
$routes->group("notification", ["filter" => "authMVC"], function ($routes) {
|
$routes->group("notification", ["filter" => "authMVC"], function ($routes) {
|
||||||
@ -553,3 +555,16 @@ $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) {
|
|||||||
// $routes->post('ticket_messages','TicketController::getTicketMessage');
|
// $routes->post('ticket_messages','TicketController::getTicketMessage');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$routes->group("clientApi",["filter" => "AuthClientApi"], function ($routes){
|
||||||
|
|
||||||
|
$routes->post("getPolicyMaster","ClientAPIController::sendPolicyMaster");
|
||||||
|
$routes->post("getEmployeeMaster","ClientAPIController::sendEmpMaster");
|
||||||
|
$routes->post("getClaimMaster","ClientAPIController::sendClaimMaster");
|
||||||
|
// $routes->post("pushData","ClientWebHooksController::sendSample");
|
||||||
|
});
|
||||||
|
|
||||||
|
$routes->post("dispatchWebhookData/(:any)/(:any)",'ClientWebHooksController::pushData/$1/$2');
|
||||||
|
|
||||||
|
|
||||||
|
$routes->post("retrieveWebhookDataEmp","ClientWebHooksController::pullData_emp");
|
||||||
|
$routes->post("retrieveWebhookDataClaim","ClientWebHooksController::pullData_claim");
|
||||||
|
|||||||
310
app/Controllers/ClientAPIController.php
Normal file
310
app/Controllers/ClientAPIController.php
Normal file
@ -0,0 +1,310 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
|
||||||
|
use App\Helpers\ClientTokenHelper;
|
||||||
|
use App\Helpers\ClientQueryHelper;
|
||||||
|
|
||||||
|
use App\Models\ClientApiModel;
|
||||||
|
use App\Models\ClientPolicyModel;
|
||||||
|
|
||||||
|
use App\Controllers\TicketController;
|
||||||
|
|
||||||
|
class ClientAPIController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
use ResponseTrait;
|
||||||
|
|
||||||
|
protected $clientAPI;
|
||||||
|
protected $clientPolicy;
|
||||||
|
protected $myLogger;
|
||||||
|
protected $clientQueryHelper;
|
||||||
|
protected $clientTokenHelper;
|
||||||
|
protected $ticketController;
|
||||||
|
|
||||||
|
protected $operators;
|
||||||
|
protected $propertyNames;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
set_session_context('Client API Controller');
|
||||||
|
$this->myLogger = \Config\Services::mylogger();
|
||||||
|
|
||||||
|
//models
|
||||||
|
$this->clientAPI = new ClientApiModel();
|
||||||
|
$this->clientPolicy = new ClientPolicyModel();
|
||||||
|
|
||||||
|
//helper
|
||||||
|
$this->clientQueryHelper = new ClientQueryHelper();
|
||||||
|
|
||||||
|
//controller
|
||||||
|
$this->ticketController = new TicketController();
|
||||||
|
|
||||||
|
//variables
|
||||||
|
$this->operators = [
|
||||||
|
|
||||||
|
"GT" => ">",
|
||||||
|
"LT" => "<",
|
||||||
|
"GTE" => ">=",
|
||||||
|
"LTE" => "<=",
|
||||||
|
"ET" => "=",
|
||||||
|
"NE" => "!=",
|
||||||
|
"LIKE" => "LIKE",
|
||||||
|
"NL" => "NOT LIKE",
|
||||||
|
"BTW" => "BETWEEN",
|
||||||
|
"NB" => "NOT BETWEEN",
|
||||||
|
"IS" => "IS NULL",
|
||||||
|
"ISN" => "IS NOT NULL",
|
||||||
|
|
||||||
|
];
|
||||||
|
$this->propertyNames = [
|
||||||
|
'empMaster' => ['name','emp_code','relationship','client_branch_id','emp_status','mobile','email_corporate','change_event','dob','doj','band','gender'],
|
||||||
|
'claimMaster' => ['emp_name','insured_name',"emp_code",'policy_no','emp_mobile','emp_mail','hospital_name','claim_type','claim_status','claim_no','claim_amount','claim_date','si_amt','raised_date','registration_date','denial_date','denial_reason','approved_amount','utr_details','return_remark','cancel_remark','non_id_reason','head_rejection_reason'],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateToken()
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$authHeader = $this->request->getHeaderLine('Authorization');
|
||||||
|
|
||||||
|
// Check if header exists
|
||||||
|
if (empty($authHeader)) {
|
||||||
|
$this->myLogger->log('error', 'Authorization header missing');
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Authorization header missing', 'code' => 401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if Bearer is present
|
||||||
|
if (!str_contains($authHeader, 'Bearer ')) {
|
||||||
|
$this->myLogger->log('error', 'Authorization Bearer missing');
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Invalid Authorization header', 'code' => 401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the token
|
||||||
|
$token = str_replace('Bearer ', '', $authHeader);
|
||||||
|
if (empty($token)) {
|
||||||
|
|
||||||
|
$this->myLogger->log('error', 'Empty Token');
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Invalid Token Format', 'code' => 401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Extract client_id from the token
|
||||||
|
$client_id = ClientTokenHelper::extractClientId($token);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->myLogger->log('error', 'Invalid Client Token Format');
|
||||||
|
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => 'Invalid Token Format'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch client details from the database
|
||||||
|
$client = $this->clientAPI->where('client_id', $client_id)->where("is_active", 1)->where("api_access", 1)->first();
|
||||||
|
|
||||||
|
// Client validation
|
||||||
|
if (!$client) {
|
||||||
|
$this->myLogger->log('error', 'Client Not Found or Unauthorized');
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Client not found or unauthorized', 'code' => '403']], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the token
|
||||||
|
if (hash_equals($client['client_token'], $token)) {
|
||||||
|
$this->myLogger->log('error', 'Access Granted For Client : ' . $client_id);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$this->myLogger->log('error', 'Invalid Token given for client : ' . $client_id);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => "Failure",
|
||||||
|
'error' => ['message' => 'Invalid token', 'code' => 401]
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message('error', 'Error in ClientAPIController:validateToken - ' . $e->getMessage());
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Internal Server Error', 'code' => 500]], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClientIdfromToken()
|
||||||
|
{
|
||||||
|
$authHeader = $this->request->getHeaderLine('Authorization');
|
||||||
|
$token = str_replace('Bearer ', '', $authHeader);
|
||||||
|
$client_id = ClientTokenHelper::extractClientId($token);
|
||||||
|
|
||||||
|
$this->myLogger->log('error', 'Client ID: ' . $client_id);
|
||||||
|
return [$client_id, $token];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendPolicyMaster()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = $this->getClientIdfromToken();
|
||||||
|
$client_id = $data[0];
|
||||||
|
$keyString = $data[1];
|
||||||
|
|
||||||
|
// Extract only the actual key (after colon)
|
||||||
|
// list($prefix, $hexKey) = explode(':', $keyString, 2);
|
||||||
|
|
||||||
|
// // Convert hex to binary (32 bytes)
|
||||||
|
// $key = hex2bin($hexKey);
|
||||||
|
|
||||||
|
|
||||||
|
$clientPolicy = $this->clientQueryHelper->clientPolicyMaster($client_id);
|
||||||
|
|
||||||
|
$this->myLogger->log('error', 'Client Policy Master: ' . json_encode($clientPolicy));
|
||||||
|
|
||||||
|
|
||||||
|
// $encode_data = ClientTokenHelper::encryptData($clientPolicy, $key);
|
||||||
|
// return $this->respond(['status' => "Success", 'data' => $encode_data], 200);
|
||||||
|
|
||||||
|
return $this->respond(['status' => "Success", 'data' => $clientPolicy], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function sendEmpMaster()
|
||||||
|
{
|
||||||
|
$data = $this->getClientIdfromToken();
|
||||||
|
$client_id = $data[0];
|
||||||
|
$keyString = $data[1];
|
||||||
|
|
||||||
|
$received_data = $this->request->getJSON();
|
||||||
|
$filters = $received_data->filters ?? null;
|
||||||
|
$limit = $received_data->limit ?? null;
|
||||||
|
$after = $received_data->after ?? 0;
|
||||||
|
|
||||||
|
if ($limit > getenv('MAX_LIMIT')) {
|
||||||
|
|
||||||
|
$this->myLogger->log('error', "Limit exceeds maximum allowed limit");
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Limit exceeds maximum allowed limit', 'code' => 400]], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
if (!empty($filters)) {
|
||||||
|
$whereConditions = $this->prepareWhereConditions($filters,"",'empMaster');
|
||||||
|
$employees = $this->clientQueryHelper->sendEmpMaster($client_id, $whereConditions,!empty($limit) ? $limit : 10,$after);
|
||||||
|
}else{
|
||||||
|
$employees = $this->clientQueryHelper->sendEmpMaster($client_id, [],!empty($limit) ? $limit : 10,$after);
|
||||||
|
}
|
||||||
|
}catch (\InvalidArgumentException $e) {
|
||||||
|
return $this->respond(['status' => "Failure",'error' => ['message' => $e->getMessage(), 'code' => 400]], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($employees as &$employee){
|
||||||
|
|
||||||
|
$employee['policy_details'] = $this->clientQueryHelper->sendEmpPolicies($employee['ref_no']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$next_after = (count($employees) < $limit) ? null : ($after + $limit);
|
||||||
|
|
||||||
|
if (!empty($employees)){
|
||||||
|
return $this->respond(['Status' => "Success","data" => $employees,'next_after'=>$next_after], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['Status' => "Failure","error" => ['message' => 'No Employees Found', 'code' => 404]], 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendClaimMaster()
|
||||||
|
{
|
||||||
|
$policy_type = $this->ticketController->ticketType;
|
||||||
|
|
||||||
|
$data = $this->getClientIdfromToken();
|
||||||
|
$client_id = $data[0];
|
||||||
|
$keyString = $data[1];
|
||||||
|
|
||||||
|
$received_data = $this->request->getJSON();
|
||||||
|
$filters = $received_data->filters ?? null;
|
||||||
|
$limit = $received_data->limit ?? null;
|
||||||
|
$after = $received_data->after ?? 0;
|
||||||
|
|
||||||
|
if ($limit > getenv('MAX_LIMIT')) {
|
||||||
|
$this->myLogger->log('error', "Limit exceeds maximum allowed limit");
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Limit exceeds maximum allowed limit', 'code' => 400]], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
if (!empty($filters)) {
|
||||||
|
$whereConditions = $this->prepareWhereConditions($filters,"ticket_master",'claimMaster');
|
||||||
|
$claimDetails = $this->clientQueryHelper->sendClaimMaster($client_id,$whereConditions,!empty($limit) ? $limit : 10);
|
||||||
|
}else{
|
||||||
|
$claimDetails = $this->clientQueryHelper->sendClaimMaster($client_id, [],!empty($limit) ? $limit : 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
return $this->respond(['status' => "Failure",'error' => ['message' => $e->getMessage(), 'code' => 400]], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($claimDetails as &$claim){
|
||||||
|
|
||||||
|
$claim['policy_type'] = $policy_type[$claim['policy_type']];
|
||||||
|
}
|
||||||
|
// dd($claimDetails);
|
||||||
|
|
||||||
|
$next_after = (count($claimDetails) < $limit) ? null : ($after + $limit);
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($claimDetails)){
|
||||||
|
return $this->respond(['Status' => "Success","data" => $claimDetails,'next_after'=>$next_after], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['Status' => "Failure","error" => ['message' => 'No Claims Found', 'code' => 404]], 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareWhereConditions($filters,$tableName = null,$model)
|
||||||
|
{
|
||||||
|
$whereConditions = [];
|
||||||
|
|
||||||
|
foreach ($filters as $filter) {
|
||||||
|
|
||||||
|
$propertyName = $filter->propertyName;
|
||||||
|
$operator = $filter->operator;
|
||||||
|
$this->myLogger->log('error', 'Property Name: ' . $propertyName);
|
||||||
|
if (!in_array($operator, array_keys($this->operators))) {
|
||||||
|
$this->myLogger->log('error', 'Invalid operator: ' . $operator);
|
||||||
|
throw new \InvalidArgumentException('Invalid operator');
|
||||||
|
}
|
||||||
|
if (!in_array($propertyName, $this->propertyNames[$model])) {
|
||||||
|
$this->myLogger->log('error', 'Invalid property name: ' . $propertyName);
|
||||||
|
throw new \InvalidArgumentException('Invalid property name '.$propertyName);
|
||||||
|
}
|
||||||
|
$value = isset($filter->value) ? $filter->value : null;
|
||||||
|
$sqlOperator = $this->operators[$operator];
|
||||||
|
|
||||||
|
$column = !empty($tableName) ? "{$tableName}.{$propertyName}" : $propertyName;
|
||||||
|
|
||||||
|
if ($sqlOperator === '=') {
|
||||||
|
$whereConditions[$column] = $value;
|
||||||
|
} else if($sqlOperator == "LIKE" || $sqlOperator == "NOT LIKE") {
|
||||||
|
$whereConditions["{$column} {$sqlOperator}"] = "%{$value}%";
|
||||||
|
|
||||||
|
} else if ($sqlOperator == 'BETWEEN') {
|
||||||
|
if (is_array($value) && count($value) === 2) {
|
||||||
|
// $whereConditions[] = [$column, $sqlOperator, $value[0]];
|
||||||
|
$whereConditions["{$column} >="] = $value[0];
|
||||||
|
$whereConditions["{$column} <="] = $value[1];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Invalid value for BETWEEN operator', 'code' => 400]], 400);
|
||||||
|
}
|
||||||
|
}else if ($sqlOperator == 'NOT BETWEEN') {
|
||||||
|
if (is_array($value) && count($value) === 2) {
|
||||||
|
$whereConditions["{$column} <="] = $value[0];
|
||||||
|
$whereConditions["{$column} >="] = $value[1];
|
||||||
|
} else {
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Invalid value for NOT BETWEEN operator', 'code' => 400]], 400);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
$whereConditions["{$column} {$sqlOperator}"] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $whereConditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ namespace App\Controllers;
|
|||||||
|
|
||||||
use App\Helpers\DepositHelper;
|
use App\Helpers\DepositHelper;
|
||||||
use App\Helpers\MailHelper;
|
use App\Helpers\MailHelper;
|
||||||
|
use App\Helpers\ClientTokenHelper;
|
||||||
use App\helpers\JWTToken;
|
use App\helpers\JWTToken;
|
||||||
use CodeIgniter\HTTP\IncomingRequest;
|
use CodeIgniter\HTTP\IncomingRequest;
|
||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
@ -39,6 +40,7 @@ use App\Models\PolicyTransactionModel;
|
|||||||
use App\Models\PolicyTransactionStatusModel;
|
use App\Models\PolicyTransactionStatusModel;
|
||||||
use App\Models\VehicleModel;
|
use App\Models\VehicleModel;
|
||||||
use App\Models\LeadsModel;
|
use App\Models\LeadsModel;
|
||||||
|
use App\Models\ClientApiModel;
|
||||||
|
|
||||||
use App\Controllers\EmpDataServiceController;
|
use App\Controllers\EmpDataServiceController;
|
||||||
use App\Controllers\GoogleDriveController;
|
use App\Controllers\GoogleDriveController;
|
||||||
@ -83,7 +85,7 @@ class ClientController extends AdminController
|
|||||||
protected $policyTransactionStatusModel;
|
protected $policyTransactionStatusModel;
|
||||||
protected $vehicleModel;
|
protected $vehicleModel;
|
||||||
protected $leadsModel;
|
protected $leadsModel;
|
||||||
|
protected $clientApi;
|
||||||
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@ -119,6 +121,7 @@ class ClientController extends AdminController
|
|||||||
$this->policyTransactionStatusModel = new PolicyTransactionStatusModel();
|
$this->policyTransactionStatusModel = new PolicyTransactionStatusModel();
|
||||||
$this->vehicleModel = new VehicleModel();
|
$this->vehicleModel = new VehicleModel();
|
||||||
$this->leadsModel = new LeadsModel();
|
$this->leadsModel = new LeadsModel();
|
||||||
|
$this->clientApi = new ClientApiModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
@ -751,7 +754,7 @@ class ClientController extends AdminController
|
|||||||
$editData['client_policy']['role'] = get_role_id();
|
$editData['client_policy']['role'] = get_role_id();
|
||||||
$editData['notification'] = $this->notificationModel->select('template_name,enabled')->where('client_id', $id)->findAll();
|
$editData['notification'] = $this->notificationModel->select('template_name,enabled')->where('client_id', $id)->findAll();
|
||||||
$editData['placeHolders'] = ['member_name', 'member_mobile', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
|
$editData['placeHolders'] = ['member_name', 'member_mobile', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
|
||||||
|
$editData['api_data'] = $this->clientApi->where("client_id", $id)->where("is_active",1)->first();
|
||||||
// dd($editData);
|
// dd($editData);
|
||||||
echo view('layout/header', $headerData);
|
echo view('layout/header', $headerData);
|
||||||
echo view('client_onboarding', $editData);
|
echo view('client_onboarding', $editData);
|
||||||
@ -5683,6 +5686,40 @@ class ClientController extends AdminController
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
public function saveApiData(){
|
||||||
|
|
||||||
|
$receivedData = $this->request->getPost();
|
||||||
|
|
||||||
|
if (!empty($receivedData['id'])){
|
||||||
|
$status = $this->clientApi->save($receivedData);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$status = $this->clientApi->insert($receivedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($status){
|
||||||
|
return $this->respond(['status'=>"Sucesss",'message'=>"Submitted Successfully"],200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status'=>"Failed",'message'=>"Submission Faild"],500);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendToken(){
|
||||||
|
|
||||||
|
$client_id = $this->request->getGet('client_id');
|
||||||
|
|
||||||
|
$token = ClientTokenHelper::generateKey($client_id);
|
||||||
|
|
||||||
|
if ($token){
|
||||||
|
return $this->respond(['status' => 'success', 'token' => $token,'message' => "Token Generated Successfully"],200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status' => "Failed","message"=>"Token Generation Failed, Try Again After some time"],500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
319
app/Controllers/ClientWebHooksController.php
Normal file
319
app/Controllers/ClientWebHooksController.php
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
|
||||||
|
use App\Models\ClientApiModel;
|
||||||
|
use App\Models\ClientPolicyModel;
|
||||||
|
|
||||||
|
use App\Helpers\clientWebHookHelper;
|
||||||
|
use App\Helpers\ClientTokenHelper;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class ClientWebHooksController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
protected $myLogger;
|
||||||
|
protected $clientAPI;
|
||||||
|
protected $clientPolicy;
|
||||||
|
|
||||||
|
protected $webHookHelper;
|
||||||
|
protected $clientTokenHelper;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
set_session_context('Client Webhook Controller');
|
||||||
|
$this->myLogger = \Config\Services::mylogger();
|
||||||
|
|
||||||
|
//models
|
||||||
|
$this->clientAPI = new ClientApiModel();
|
||||||
|
$this->clientPolicy = new ClientPolicyModel();
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
$this->webHookHelper = new clientWebHookHelper();
|
||||||
|
$this->clientTokenHelper = new ClientTokenHelper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pushData($clientID, $type)
|
||||||
|
{
|
||||||
|
if ($type == 1) {
|
||||||
|
|
||||||
|
$webHookType = "emp";
|
||||||
|
} else if ($type == 2) {
|
||||||
|
|
||||||
|
$webHookType = "claim";
|
||||||
|
}
|
||||||
|
log_message('error', 'Client ID: ' . $clientID);
|
||||||
|
log_message('error', 'Webhook Type: ' . $webHookType);
|
||||||
|
// Validate client ID
|
||||||
|
if (empty($clientID)) {
|
||||||
|
return $this->respond(["status" => "Failure", "error" => ["message" => 'Client ID is required.', "code" => 400]], 400);
|
||||||
|
}
|
||||||
|
$webhookData = $this->clientAPI->where('client_id', $clientID)->where('is_active', 1)->first();
|
||||||
|
if (empty($webhookData)) {
|
||||||
|
log_message('error', 'Client Not Found or Unauthorized');
|
||||||
|
return $this->respond(["status" => "Failure", "error" => ["message" => 'Client Not Found or Client Does not have any Active Hooks.', "code" => 404]], 404);
|
||||||
|
}
|
||||||
|
$url = $webhookData[$webHookType . '_url'];
|
||||||
|
if (empty($url)) {
|
||||||
|
log_message('error', 'No active webhook found for the client.');
|
||||||
|
return $this->respond(["status" => "Failure", "error" => ["message" => 'No active webhook found for the client.', "code" => 404]], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$method = $webhookData[$webHookType . '_method'];
|
||||||
|
$auth_method = $webhookData[$webHookType . '_tkn_type'];
|
||||||
|
$token = $webhookData[$webHookType . '_token'];
|
||||||
|
$objectType = json_decode($webhookData[$webHookType . '_obj']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$client = \Config\Services::curlrequest();
|
||||||
|
$data = [
|
||||||
|
"name" => "Kavitha",
|
||||||
|
"emp_code" => "EMP001-K4",
|
||||||
|
"emp_status" => "active",
|
||||||
|
"mobile" => "2233448965"
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mapped_data = $this->webHookHelper->mapObjectType($data, $objectType);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$errorMessage = "Object Mapping Failed: " . $e->getMessage();
|
||||||
|
log_message('error', $errorMessage);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 500, 'message' => "Object Mapping Failed"]], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create payload
|
||||||
|
$payload = [
|
||||||
|
'event_type' => 'insert',
|
||||||
|
'timestamp' => date('c'),
|
||||||
|
'data' => $mapped_data
|
||||||
|
];
|
||||||
|
|
||||||
|
log_message("error", "Payload: " . json_encode($payload));
|
||||||
|
|
||||||
|
// Configure request headers
|
||||||
|
$headers = ['Content-Type' => 'application/json'];
|
||||||
|
if ($auth_method && $token) {
|
||||||
|
if (strtolower($auth_method) === 'bearer') {
|
||||||
|
$headers['Authorization'] = 'Bearer ' . $token;
|
||||||
|
} else {
|
||||||
|
$headers[$auth_method] = $token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure request based on method
|
||||||
|
$options = [
|
||||||
|
'headers' => $headers,
|
||||||
|
'timeout' => 10,
|
||||||
|
'http_errors' => false // Don't throw exceptions for 4xx/5xx responses
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($method === 'GET') {
|
||||||
|
$options['query'] = $payload;
|
||||||
|
} else {
|
||||||
|
$options['json'] = $payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute webhook request
|
||||||
|
$response = $client->request($method, $url, $options);
|
||||||
|
$statusCode = $response->getStatusCode();
|
||||||
|
$responseBody = $response->getBody();
|
||||||
|
|
||||||
|
// Log and format response
|
||||||
|
$logMessage = "Webhook to {$url} returned status: {$statusCode}";
|
||||||
|
log_message('error', $logMessage);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'Success', "response" => $responseBody], $statusCode);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$errorMessage = "Webhook failed: " . $e->getMessage();
|
||||||
|
log_message('error', $errorMessage);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 500, 'message' => $errorMessage, 'exception' => get_class($e)]], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateToken($type)
|
||||||
|
{
|
||||||
|
$type = $type == 1 ? "pull_emp_token" : "pull_claim_token";
|
||||||
|
try {
|
||||||
|
|
||||||
|
$authHeader = $this->request->getHeaderLine('Authorization');
|
||||||
|
|
||||||
|
// Check if header exists
|
||||||
|
if (empty($authHeader)) {
|
||||||
|
log_message('error', 'Authorization header missing');
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Authorization header missing', 'code' => 401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if Bearer is present
|
||||||
|
if (!str_contains($authHeader, 'Bearer ')) {
|
||||||
|
log_message('error', 'Authorization Bearer missing');
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Invalid Authorization header', 'code' => 401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the token
|
||||||
|
$token = str_replace('Bearer ', '', $authHeader);
|
||||||
|
if (empty($token)) {
|
||||||
|
|
||||||
|
log_message('error', 'Empty Token');
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Invalid Token Format', 'code' => 401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Extract client_id from the token
|
||||||
|
$client_id = ClientTokenHelper::extractClientId($token);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message('error', 'Invalid Client Token Format');
|
||||||
|
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => 'Invalid Token Format'], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch client details from the database
|
||||||
|
$client = $this->clientAPI->where('client_id', $client_id)->where("is_active", 1)->where("api_access", 1)->first();
|
||||||
|
|
||||||
|
// Client validation
|
||||||
|
if (!$client) {
|
||||||
|
log_message('error', 'Client Not Found or Unauthorized');
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Client not found or unauthorized', 'code' => '403']], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the token
|
||||||
|
if (hash_equals($client[$type], $token)) {
|
||||||
|
log_message('error', 'Access Granted For Client : ' . $client_id);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
log_message('error', 'Invalid Token given for client : ' . $client_id);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => "Failure",
|
||||||
|
'error' => ['message' => 'Invalid token', 'code' => 401]
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message('error', 'Error in ClientAPIController:validateToken - ' . $e->getMessage());
|
||||||
|
return $this->respond(['status' => "Failure", 'error' => ['message' => 'Internal Server Error', 'code' => 500]], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClientIdfromToken()
|
||||||
|
{
|
||||||
|
$authHeader = $this->request->getHeaderLine('Authorization');
|
||||||
|
$token = str_replace('Bearer ', '', $authHeader);
|
||||||
|
$client_id = ClientTokenHelper::extractClientId($token);
|
||||||
|
|
||||||
|
log_message('error', 'Client ID: ' . $client_id);
|
||||||
|
return [$client_id, $token];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pullData_emp()
|
||||||
|
{
|
||||||
|
$validationStatus = $this->validateToken(1);
|
||||||
|
|
||||||
|
$data = $this->getClientIdfromToken();
|
||||||
|
$client_id = $data[0];
|
||||||
|
|
||||||
|
log_message('error', "Pull data emp from Client ID: ". $client_id);
|
||||||
|
$client = $this->clientAPI->where('client_id', $client_id)->where("is_active", 1)->where("api_access", 1)->first();
|
||||||
|
if (empty($client)) {
|
||||||
|
log_message('error', 'Client Not Found or Unauthorized');
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 404, 'message' => 'Client Not Found or Unauthorized']], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$objectType = $client['pull_emp_obj'];
|
||||||
|
|
||||||
|
if ($validationStatus) {
|
||||||
|
$responseBody = $this->request->getBody();
|
||||||
|
$data_to_map = json_decode($responseBody, true);
|
||||||
|
$objectType = json_decode($objectType, true);
|
||||||
|
if (!isset($data_to_map['data']) || !is_array($data_to_map['data'])) {
|
||||||
|
|
||||||
|
log_message('error', "Invalid Response from Endpoint 'data' Key Missing");
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 500, 'message' => "Invalid Response from Endpoint 'data' Key Missing"]], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data_to_map['data'] as $index => $item) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mapped_data = $this->webHookHelper->mapObjectType($item, $objectType);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$errorMessage = "Object Mapping Failed: " . $e->getMessage();
|
||||||
|
log_message('error', $errorMessage);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 500, 'message' => "Object Mapping Failed"]], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mapped_data['client_id'] = $client_id;
|
||||||
|
$this->webHookHelper->insertData($mapped_data, 1);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$errorMessage = "Data Insertion Failed: " . $e->getMessage();
|
||||||
|
log_message('error', $errorMessage);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 500, 'message' => "Data Insertion Failed"]], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message('error', "Data Inserted Successfully for Client ID: " . $client_id);
|
||||||
|
// Return success response
|
||||||
|
return $this->respond(['status' => 'Success', 'message' => "Data Inserted Successfully"], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pullData_claim()
|
||||||
|
{
|
||||||
|
$validationStatus = $this->validateToken(2);
|
||||||
|
|
||||||
|
$data = $this->getClientIdfromToken();
|
||||||
|
$client_id = $data[0];
|
||||||
|
log_message('error', "Pull data claim from Client ID: ". $client_id);
|
||||||
|
$client = $this->clientAPI->where('client_id', $client_id)->where("is_active", 1)->where("api_access", 1)->first();
|
||||||
|
if (empty($client)) {
|
||||||
|
log_message('error', 'Client Not Found or Unauthorized');
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 404, 'message' => 'Client Not Found or Unauthorized']], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$objectType = $client['pull_claim_obj'];
|
||||||
|
|
||||||
|
if ($validationStatus) {
|
||||||
|
$responseBody = $this->request->getBody();
|
||||||
|
$data_to_map = json_decode($responseBody, true);
|
||||||
|
$objectType = json_decode($objectType, true);
|
||||||
|
if (!isset($data_to_map['data']) || !is_array($data_to_map['data'])) {
|
||||||
|
|
||||||
|
log_message('error', "Invalid Response from Endpoint 'data' Key Missing");
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 500, 'message' => "Invalid Response from Endpoint 'data' Key Missing"]], 500);
|
||||||
|
}
|
||||||
|
foreach ($data_to_map['data'] as $index => $item) {
|
||||||
|
try {
|
||||||
|
$mapped_data = $this->webHookHelper->mapObjectType($item, $objectType);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$errorMessage = "Object Mapping Failed: " . $e->getMessage();
|
||||||
|
log_message('error', $errorMessage);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 500, 'message' => "Object Mapping Failed"]], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mapped_data['client_id'] = $client_id;
|
||||||
|
$this->webHookHelper->insertData($mapped_data, 2);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$errorMessage = "Data Insertion Failed: " . $e->getMessage();
|
||||||
|
log_message('error', $errorMessage);
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'Failure', 'error' => ['code' => 500, 'message' => "Data Insertion Failed"]], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
log_message('error', "Data Inserted Successfully for Client ID: " . $client_id);
|
||||||
|
// Return success response
|
||||||
|
return $this->respond(['status' => 'Success', 'message' => "Data Inserted Successfully"], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
87
app/Filters/AuthClientApi.php
Normal file
87
app/Filters/AuthClientApi.php
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
use CodeIgniter\Filters\FilterInterface;
|
||||||
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
|
||||||
|
use App\Helpers\ClientTokenHelper;
|
||||||
|
use App\Models\ClientApiModel;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
|
||||||
|
class AuthClientApi implements FilterInterface
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
protected $clientAPI;
|
||||||
|
protected $myLogger;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
set_session_context('External API Filter');
|
||||||
|
$this->clientAPI = new ClientApiModel();
|
||||||
|
$this->myLogger = \Config\Services::mylogger();
|
||||||
|
|
||||||
|
}
|
||||||
|
public function before(RequestInterface $request, $arguments = null)
|
||||||
|
{
|
||||||
|
$response = service('response');
|
||||||
|
try {
|
||||||
|
|
||||||
|
$authHeader = $request->getHeaderLine('Authorization');
|
||||||
|
|
||||||
|
// Check if header exists
|
||||||
|
if (empty($authHeader)) {
|
||||||
|
$this->myLogger->log('error', 'Authorization header missing');
|
||||||
|
return $response->setJson(['status' => "Failure", 'error' => ['message'=>'Authorization header missing','code'=> 401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!str_contains($authHeader, 'Bearer ')){
|
||||||
|
$this->myLogger->log('error', 'Authorization Bearer missing');
|
||||||
|
return $response->setJson(['status' => "Failure", 'error' => ['message'=>'Invalid Authorization header','code'=>401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
$token = str_replace('Bearer ', '', $authHeader);
|
||||||
|
if (empty($token)) {
|
||||||
|
|
||||||
|
$this->myLogger->log('error', 'Empty Token');
|
||||||
|
return $response->setJson(['status' => "Failure", 'error' => ['message'=>'Invalid Token Format','code'=> 401]], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
$client_id = ClientTokenHelper::extractClientId($token);
|
||||||
|
|
||||||
|
}catch(\Exception $e){
|
||||||
|
|
||||||
|
$this->myLogger->log('error', 'Invalid Client Token Format');
|
||||||
|
|
||||||
|
return $response->setJson(['status' => "Failure", 'error' => 'Invalid Token Format'], 401);
|
||||||
|
}
|
||||||
|
$client = $this->clientAPI->where('client_id', $client_id)->where("is_active", 1)->where("api_access", 1)->first();
|
||||||
|
|
||||||
|
// Client validation
|
||||||
|
if (!$client) {
|
||||||
|
$this->myLogger->log('error', 'Client Not Found or Unauthorized');
|
||||||
|
return $response->setJson(['status' => "Failure", 'error' => ['message' => 'Client not found or unauthorized','code'=>'403']], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hash_equals($client['client_token'], $token)) {
|
||||||
|
$this->myLogger->log('error', 'Access Granted For Client : '.$client_id);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$this->myLogger->log('error', 'Invalid Token given for client : '.$client_id);
|
||||||
|
return $response->setJson(['status' => "Failure", 'error' => ['message' => 'Invalid token','code'=>401]
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message('error', 'Error in ClientAPIController:validateToken - ' . $e->getMessage());
|
||||||
|
return $response->setJson(['status' => "Failure", 'error' => ['message'=>'Internal Server Error','code'=> 500]], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||||
|
{
|
||||||
|
// Do something here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
100
app/Helpers/ClientQueryHelper.php
Normal file
100
app/Helpers/ClientQueryHelper.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\ClientPolicyModel;
|
||||||
|
use App\Models\EmployeeModel;
|
||||||
|
use App\Models\EmployeePolicyModel;
|
||||||
|
use App\Models\TicketMasterModel;
|
||||||
|
|
||||||
|
|
||||||
|
class ClientQueryHelper{
|
||||||
|
|
||||||
|
protected $clientPolicy;
|
||||||
|
protected $empModel;
|
||||||
|
protected $empPolicyModel;
|
||||||
|
protected $claimModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->clientPolicy = new ClientPolicyModel();
|
||||||
|
$this->empModel = new EmployeeModel();
|
||||||
|
$this->empPolicyModel = new EmployeePolicyModel();
|
||||||
|
$this->claimModel = new TicketMasterModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clientPolicyMaster($client_id){
|
||||||
|
|
||||||
|
return $this->clientPolicy->select("client_policy.id as policy_ref_no,client_policy.client_branch_id as branch_ref_no,client_branch.branch_code,
|
||||||
|
client_policy.insurer_id as insurer_ref_no,insurers.name as insurer,client_policy.policy_type_id,policy_type.policy_type,
|
||||||
|
client_policy.tpa_id as tpa_ref_no,client_policy.policy_start_date,client_policy.policy_end_date,client_policy.policy_no,client_policy.policy_status")
|
||||||
|
->join('insurers', 'client_policy.insurer_id = insurers.id and insurers.is_active = 1')
|
||||||
|
->join('policy_type', 'client_policy.policy_type_id = policy_type.id and policy_type.is_active = 1')
|
||||||
|
->join('client_branch', 'client_policy.client_branch_id = client_branch.id and client_branch.is_active = 1')
|
||||||
|
->where('client_policy.is_active', 1)
|
||||||
|
->where('client_policy.client_id', $client_id)
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendEmpMaster($client_id,$where,$limit,$offset = 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->empModel->select("id as ref_no,name,emp_code,
|
||||||
|
relationship,emp_status,mobile,email_corporate,
|
||||||
|
change_event,dob,doj,band,gender")
|
||||||
|
->where("is_active",1)
|
||||||
|
->where("client_id", $client_id)
|
||||||
|
->where($where)
|
||||||
|
->whereNotIn('emp_status', ['truncated'],)
|
||||||
|
->orderBy("id")
|
||||||
|
->limit($limit,$offset)
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendEmpPolicies($emp_id)
|
||||||
|
{
|
||||||
|
return $this->empPolicyModel->select("id as ref_no,client_policy_id as policy_ref_no,
|
||||||
|
tpa_id as tpa_ref_no,uhid as policy_no,pre_existing_alignments,age_band,basic_cover_si,date_coverage,
|
||||||
|
policy_end_date,days,premium,rata_premimum,date_of_exit,reason_for_exit,payable_employee")
|
||||||
|
->where("employee_id", $emp_id)
|
||||||
|
->where("is_active", 1)
|
||||||
|
->whereNotIn("status", ['truncated'])
|
||||||
|
->orderBy("id")
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendClaimMaster($client_id,$where,$limit,$offset = 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->claimModel->select("i.name as insurer,tpa.name as tpa,concat(up.first_name,' ',up.last_name) as acm_name,
|
||||||
|
cs.claim_status,ticket_master.emp_name,ticket_master.insured_name,
|
||||||
|
ticket_master.emp_code,ticket_master.policy_no,ticket_master.ticket_type_id as policy_type,
|
||||||
|
ticket_master.emp_mobile,ticket_master.emp_mail,ticket_master.hospital_name,ticket_master.doa,
|
||||||
|
ticket_master.dod,ticket_master.claim_amount,ticket_master.date_of_join,ticket_master.date_of_incep,
|
||||||
|
ticket_master.date_of_accident,ticket_master.date_of_death,
|
||||||
|
ticket_master.date_of_intimat,ticket_master.claim_number,ticket_master.si_amt,
|
||||||
|
ticket_master.raised_date,ticket_master.registration_date,ticket_master.denial_date,
|
||||||
|
ticket_master.settled_date,ticket_master.denial_reason,ticket_master.approved_amount,
|
||||||
|
ticket_master.utr_details,ticket_master.return_remark,ticket_master.cancel_remark,
|
||||||
|
ticket_master.non_id_reason,ticket_master.head_rejection_reason")
|
||||||
|
->join("tpa","tpa.id = ticket_master.tpa_id and tpa.is_active = 1")
|
||||||
|
->join("user_profiles up", "ticket_master.acm_id = up.id and up.is_active = 1")
|
||||||
|
->join('insurers i', 'ticket_master.insurer_id = i.id and i.is_active = 1')
|
||||||
|
->join('ticket_claim_status cs', 'ticket_master.claim_status_id = cs.id and cs.is_active = 1')
|
||||||
|
->where("ticket_master.client_id", $client_id)
|
||||||
|
->where("ticket_master.is_active", 1)
|
||||||
|
->where($where)
|
||||||
|
->orderBy("ticket_master.id")
|
||||||
|
->limit($limit,$offset)
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
54
app/Helpers/ClientTokenHelper.php
Normal file
54
app/Helpers/ClientTokenHelper.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
|
||||||
|
class ClientTokenHelper{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static function generateKey($clientId,$length = 32)
|
||||||
|
{
|
||||||
|
$clientIdPart = bin2hex($clientId); // Convert client ID to hex
|
||||||
|
$randomPart = bin2hex(random_bytes($length)); // Random part
|
||||||
|
return $clientIdPart . ':' . $randomPart; // Combine with a delimiter
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function extractClientId($token)
|
||||||
|
{
|
||||||
|
$parts = explode(':', $token);
|
||||||
|
return hex2bin($parts[0]); // Decode the hex client ID
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function encryptData($data, $key)
|
||||||
|
{
|
||||||
|
|
||||||
|
$cipher = "AES-256-CBC";
|
||||||
|
$ivlen = openssl_cipher_iv_length($cipher);
|
||||||
|
$iv = openssl_random_pseudo_bytes($ivlen);
|
||||||
|
|
||||||
|
// Convert array to JSON string before encrypting
|
||||||
|
$jsonData = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
|
$encrypted = openssl_encrypt($jsonData, $cipher, $key, OPENSSL_RAW_DATA, $iv);
|
||||||
|
|
||||||
|
// Combine IV + encrypted, then base64 encode it to make it JSON-safe
|
||||||
|
return base64_encode($iv . $encrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function decryptData($encryptedData, $key)
|
||||||
|
{
|
||||||
|
$cipher = "AES-256-CBC";
|
||||||
|
$data = base64_decode($encryptedData);
|
||||||
|
|
||||||
|
$ivlen = openssl_cipher_iv_length($cipher);
|
||||||
|
$iv = substr($data, 0, $ivlen); // Extract IV
|
||||||
|
$ciphertext = substr($data, $ivlen); // Extract Encrypted Payload
|
||||||
|
|
||||||
|
$decryptedJson = openssl_decrypt($ciphertext, $cipher, $key, OPENSSL_RAW_DATA, $iv);
|
||||||
|
|
||||||
|
return json_decode($decryptedJson, true); // return as array
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
39
app/Helpers/clientWebHookHelper.php
Normal file
39
app/Helpers/clientWebHookHelper.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\EmployeeModel;
|
||||||
|
use App\Models\EmployeePolicyModel;
|
||||||
|
use App\Models\TicketMasterModel;
|
||||||
|
|
||||||
|
class clientWebHookHelper
|
||||||
|
{
|
||||||
|
protected $empModel;
|
||||||
|
protected $empPolicyModel;
|
||||||
|
protected $claimModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// Models
|
||||||
|
$this->empModel = new EmployeeModel();
|
||||||
|
$this->empPolicyModel = new EmployeePolicyModel();
|
||||||
|
$this->claimModel = new TicketMasterModel();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mapObjectType($data_to_map, $objectType)
|
||||||
|
{
|
||||||
|
$mapped_data = [];
|
||||||
|
foreach ($objectType as $key => $value){
|
||||||
|
$mapped_data[$key] = $data_to_map[$value];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mapped_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function insertData($mapped_data, $type){
|
||||||
|
|
||||||
|
$model = $type == 1 ? "empModel" : "claimModel";
|
||||||
|
$this->$model->insert($mapped_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
app/Models/ClientApiModel.php
Normal file
45
app/Models/ClientApiModel.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class ClientApiModel extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'client_api';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $protectFields = true;
|
||||||
|
protected $allowedFields = [
|
||||||
|
'id','client_id','api_access','created_by','updated_by','created_at','updated_at',
|
||||||
|
'emp_method',"emp_url","emp_tkn_type","emp_token","emp_obj","claim_method",
|
||||||
|
"claim_url","claim_tkn_type","claim_token","claim_obj",'is_active',"client_token",
|
||||||
|
"pull_emp_token","pull_emp_obj","pull_claim_token","pull_claim_obj"
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||||
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||||
|
|
||||||
|
protected function checkAndADDCreatedByValue(array $data)
|
||||||
|
{
|
||||||
|
// Check if 'updated_by' value is null or empty
|
||||||
|
if (empty($data['data']['created_by'])) {
|
||||||
|
// Set 'updated_by' value to the current session user ID
|
||||||
|
$data['data']['created_by'] = get_session_userid();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
||||||
|
{
|
||||||
|
// Check if 'updated_by' value is null or empty
|
||||||
|
if (empty($data['data']['updated_by'])) {
|
||||||
|
// Set 'updated_by' value to the current session user ID
|
||||||
|
$data['data']['updated_by'] = get_session_userid();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
452
app/Views/client_api.php
Normal file
452
app/Views/client_api.php
Normal file
@ -0,0 +1,452 @@
|
|||||||
|
<style>
|
||||||
|
.card {
|
||||||
|
padding-top: 0px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class="tab-pane fade" id="api-tab">
|
||||||
|
<div class="card">
|
||||||
|
<!-- <div class="card-header">
|
||||||
|
<h5>API Token Management</h5>
|
||||||
|
</div> -->
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="is_api">Enable API Access</label>
|
||||||
|
<label class="switch">
|
||||||
|
<input <?= isset($api_data) ? "Checked" : "" ?> id="is_api" type="checkbox" name="is_api">
|
||||||
|
<span class="slider round" style="height: 27px;"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div id="api-token-section">
|
||||||
|
<!-- Generate Token Section -->
|
||||||
|
<form id="api-form" data-parsley-validate>
|
||||||
|
<input type="hidden" id="apiPK" name="id" value="<?= isset($api_data) ? $api_data['id'] : "" ?>">
|
||||||
|
<div class="mb-4">
|
||||||
|
<h5 class="mb-3">Generate New Token</h5>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<input type="text" name="client_token" value="<?= isset($api_data) ? $api_data['client_token'] : "" ?>" class="form-control" id="client_token" placeholder="Click generate to create token" readonly required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-6 d-flex">
|
||||||
|
<button class="btn btn-primary me-2" type="button" onclick="generateToken('client_token')">
|
||||||
|
<i class="mdi mdi-key-chain-variant me-1"></i> Generate Token
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-secondary" type="button" onclick="copyToken('client_token')">
|
||||||
|
<i class="mdi mdi-content-copy me-1"></i> Copy
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- <div class="row" style="padding-top:10px">
|
||||||
|
<div class="col-md-5">
|
||||||
|
<label for="auth_type">Authorization Type</label>
|
||||||
|
<input type="text" class="form-control" id="auth_type" value="Authorization - Bearer" readonly>
|
||||||
|
</div>
|
||||||
|
</div> -->
|
||||||
|
</div>
|
||||||
|
<!-- <div class="table-responsive">
|
||||||
|
<table class="table table-bordered table-striped">
|
||||||
|
<tr>
|
||||||
|
<td>Get Individual Employee Data</td>
|
||||||
|
<td><?= base_url("getEmpData") ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Get All Employee Data</td>
|
||||||
|
<td><?= base_url("getAllEmpData") ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Get Branch Wise Employee Data</td>
|
||||||
|
<td><?= base_url("getClientBranchEmpData") ?></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Enter Token Section -->
|
||||||
|
<hr>
|
||||||
|
<div class="mt-5">
|
||||||
|
<h5 class="mb-3">Webhooks (PUSH)</h5>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Webhook Action</label>
|
||||||
|
<input type="text" class="form-control" id="webhook_action" value="Employee" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Webhook Method Type</label>
|
||||||
|
<select class="form-control" name="emp_method">
|
||||||
|
<option value="post" <?= isset($api_data['emp_method']) && $api_data['emp_method'] == "post" ? "selected" : "" ?>>POST</option>
|
||||||
|
<option value="get" <?= isset($api_data['emp_method']) && $api_data['emp_method'] == "get" ? "selected" : "" ?>>GET</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label>Webhook URL</label>
|
||||||
|
<input type="text" name="emp_url" value="<?= isset($api_data) ? $api_data['emp_url'] : "" ?>" class="form-control emp_webhook" onchange="validateWebhookUrlById(this.id)" id="webhook_url" placeholder="Enter Webhook URL">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Token Type</label>
|
||||||
|
<select class="form-control" name="emp_tkn_type">
|
||||||
|
<option value="bearer" <?= (isset($api_data) && $api_data['emp_tkn_type'] == 'bearer') ? 'selected' : '' ?>>Bearer Token</option>
|
||||||
|
<option value="X-API-KEY" <?= (isset($api_data) && $api_data['emp_tkn_type'] == 'X-API-KEY') ? 'selected' : '' ?>>API Key</option>
|
||||||
|
<option value="token" <?= (isset($api_data) && $api_data['emp_tkn_type'] == 'token') ? 'selected' : '' ?>>Token</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<label>Authorization Token</label>
|
||||||
|
<input type="text" id="client_api_token" name="emp_token" value="<?= isset($api_data) ? $api_data['emp_token'] : "" ?>" class="form-control emp_webhook" placeholder="Enter Client API token" />
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="client_object_type">Client Object Type</label>
|
||||||
|
<textarea class="form-control emp_webhook" name="emp_obj" onchange="checkValidJson(this)" id="client_object_type" rows="3" placeholder="Enter the object type"><?= isset($api_data) ? htmlspecialchars($api_data['emp_obj']) : "" ?></textarea>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Webhook Action</label>
|
||||||
|
<input type="text" class="form-control" id="webhook_action" value="Claims" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Webhook Method Type</label>
|
||||||
|
<select class="form-control" name="claim_method">
|
||||||
|
<option value="post" <?= isset($api_data['claim_method']) && $api_data['claim_method'] == "post" ? "selected" : "" ?>>POST</option>
|
||||||
|
<option value="get" <?= isset($api_data['claim_method']) && $api_data['claim_method'] == "get" ? "selected" : "" ?>>GET</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label>Webhook URL</label>
|
||||||
|
<input type="text" name="claim_url" value="<?= isset($api_data) ? $api_data['claim_url'] : "" ?>" class="form-control claim_webhook" onchange="validateWebhookUrlById(this.id)" id="webhook_url_claims" placeholder="Enter Webhook URL">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Token Type</label>
|
||||||
|
<select class="form-control" name="claim_tkn_type">
|
||||||
|
<option value="bearer" <?= (isset($api_data) && $api_data['claim_tkn_type'] == 'bearer') ? 'selected' : '' ?>>Bearer Token</option>
|
||||||
|
<option value="X-API-KEY" <?= (isset($api_data) && $api_data['claim_tkn_type'] == 'X-API-KEY') ? 'selected' : '' ?>>API Key</option>
|
||||||
|
<option value="token" <?= (isset($api_data) && $api_data['claim_tkn_type'] == 'token') ? 'selected' : '' ?>>Token</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<label>Authorization Token</label>
|
||||||
|
<input type="text" id="client_api_token" name="claim_token" value="<?= isset($api_data) ? $api_data['claim_token'] : "" ?>" class="form-control claim_webhook" placeholder="Enter Client API token">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="client_object_type">Client Object Type</label>
|
||||||
|
<textarea class="form-control claim_webhook" name="claim_obj" onchange="checkValidJson(this)" id="client_object_type_claims" rows="3" placeholder="Enter the object type"><?= isset($api_data) ? htmlspecialchars($api_data['claim_obj']) : "" ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<h5 class="mt-5">Webhooks (PULL)</h5>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Webhook Action</label>
|
||||||
|
<input type="text" class="form-control" id="webhook_action2" value="Employee" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Webhook Method Type</label>
|
||||||
|
<select class="form-control" disabled>
|
||||||
|
<option value="post" selected>POST</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label>Webhook URL</label>
|
||||||
|
<input type="text" value="<?= base_url("retrieveWebhookDataEmp") ?>" class="form-control" onchange="validateWebhookUrlById(this.id)" id="webhook_url2" readonly placeholder="Enter Webhook URL">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Token Type</label>
|
||||||
|
<select class="form-control" disabled>
|
||||||
|
<option value="bearer" selected>Bearer Token</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row mt-3">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label>Authorization Token</label>
|
||||||
|
<input type="text" name="pull_emp_token" value="<?= isset($api_data) ? $api_data['pull_emp_token'] : "" ?>" class="form-control" id="pull_emp_token" placeholder="Click generate to create token" readonly required>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 d-flex align-items-end">
|
||||||
|
<button class="btn btn-primary me-2" type="button" onclick="generateToken('pull_emp_token')">
|
||||||
|
<i class="mdi mdi-key-chain-variant me-1"></i> Generate Token
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-secondary" type="button" onclick="copyToken('pull_emp_token')">
|
||||||
|
<i class="mdi mdi-content-copy me-1"></i> Copy
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group mt-3">
|
||||||
|
<label for="pull_emp_obj">Emp Object Type</label>
|
||||||
|
<textarea class="form-control" name="pull_emp_obj" onchange="checkValidJson(this)" id="pull_emp_obj" rows="3" placeholder="Enter the object type"><?= isset($api_data) ? htmlspecialchars($api_data['pull_emp_obj']) : "" ?></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div><hr>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Webhook Action</label>
|
||||||
|
<input type="text" class="form-control" id="webhook_action2" value="Claim" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Webhook Method Type</label>
|
||||||
|
<select class="form-control">
|
||||||
|
<option value="post" selected>POST</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label>Webhook URL</label>
|
||||||
|
<input type="text" value="<?= base_url("retrieveWebhookDataClaim") ?>" class="form-control" onchange="validateWebhookUrlById(this.id)" id="webhook_url2" readonly placeholder="Enter Webhook URL">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<label>Token Type</label>
|
||||||
|
<select class="form-control">
|
||||||
|
<option value="bearer" selected>Bearer Token</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label>Authorization Token</label>
|
||||||
|
<input type="text" name="pull_claim_token" value="<?= isset($api_data) ? $api_data['pull_claim_token'] : "" ?>" class="form-control" id="pull_claim_token" placeholder="Click generate to create token" readonly required>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 d-flex align-items-end">
|
||||||
|
<button class="btn btn-primary me-2" type="button" onclick="generateToken('pull_claim_token')">
|
||||||
|
<i class="mdi mdi-key-chain-variant me-1"></i> Generate Token
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-secondary" type="button" onclick="copyToken('pull_claim_token')">
|
||||||
|
<i class="mdi mdi-content-copy me-1"></i> Copy
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-12">
|
||||||
|
<label for="pull_claim_obj">Claim Object Type</label>
|
||||||
|
<textarea class="form-control" name="pull_claim_obj" onchange="checkValidJson(this)" id="pull_claim_obj" rows="3" placeholder="Enter the object type"><?= isset($api_data) ? htmlspecialchars($api_data['pull_claim_obj']) : "" ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex justify-content-end">
|
||||||
|
<button class="btn btn-primary waves-effect waves-light mr-1" type="submit" id="formSubmit">Submit</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function generateToken(element_id) {
|
||||||
|
|
||||||
|
// alert($("#general_PrimaryKey").val());
|
||||||
|
// console.log('element_id:', element_id);
|
||||||
|
$.ajax({
|
||||||
|
url: "<?= base_url('client/generateToken') ?>",
|
||||||
|
type: "GET",
|
||||||
|
data: {
|
||||||
|
client_id: $("#general_PrimaryKey").val()
|
||||||
|
},
|
||||||
|
beforeSend: function() {
|
||||||
|
$('.loader').fadeIn();
|
||||||
|
$('.loader-mask').fadeIn();
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status) {
|
||||||
|
toastr.success(response.message);
|
||||||
|
$(`#${element_id}`).val(response.token);
|
||||||
|
} else {
|
||||||
|
toastr.error(response.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error("Error:", error);
|
||||||
|
toastr.error("An error occurred while processing your request.");
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').fadeOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyToken(element_id) {
|
||||||
|
const tokenField = document.getElementById(`${element_id}`);
|
||||||
|
if (tokenField.value) {
|
||||||
|
tokenField.select();
|
||||||
|
navigator.clipboard.writeText(tokenField.value);
|
||||||
|
toastr.success('Token copied to clipboard!');
|
||||||
|
} else {
|
||||||
|
toastr.warning('Generate a token first!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pasteToken() {
|
||||||
|
try {
|
||||||
|
// Get the target input field
|
||||||
|
const tokenInput = document.getElementById('client_api_token');
|
||||||
|
|
||||||
|
// Request clipboard read permission
|
||||||
|
const permission = await navigator.permissions.query({
|
||||||
|
name: 'clipboard-read'
|
||||||
|
});
|
||||||
|
if (permission.state === 'denied') {
|
||||||
|
toastr.error('Clipboard access denied by user');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read clipboard contents
|
||||||
|
const text = await navigator.clipboard.readText();
|
||||||
|
|
||||||
|
// Security checks
|
||||||
|
if (text.length > 256) {
|
||||||
|
toastr.warning('Invalid token length');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^[a-zA-Z0-9\-_]+$/.test(text)) {
|
||||||
|
toastr.warning('Invalid token format');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert into input field
|
||||||
|
tokenInput.value = text;
|
||||||
|
|
||||||
|
// Visual feedback
|
||||||
|
tokenInput.focus();
|
||||||
|
toastr.success('Token pasted securely');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Paste failed:', error);
|
||||||
|
toastr.error('Failed to read clipboard');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$("#is_api").change(function() {
|
||||||
|
checkAndShowApiElements();
|
||||||
|
});
|
||||||
|
$(document).ready(function() {
|
||||||
|
checkAndShowApiElements();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function checkAndShowApiElements() {
|
||||||
|
if ($("#is_api").is(":checked")) {
|
||||||
|
|
||||||
|
$('.loader').fadeIn();
|
||||||
|
$('.loader-mask').fadeIn();
|
||||||
|
|
||||||
|
$("#api-token-section").show();
|
||||||
|
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').fadeOut();
|
||||||
|
} else {
|
||||||
|
$("#api-token-section").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkValidJson(el) {
|
||||||
|
|
||||||
|
const element = document.getElementById(el.id);
|
||||||
|
if (!element) {
|
||||||
|
console.error('Element with ID "${id}" not found.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSON.parse(element.value);
|
||||||
|
} catch (e) {
|
||||||
|
el.value = '';
|
||||||
|
toastr.error('Invalid JSON format');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateWebhookUrlById(id) {
|
||||||
|
console.log("function called");
|
||||||
|
const element = document.getElementById(id);
|
||||||
|
if (!element) {
|
||||||
|
console.error(`Element with ID "${id}" not found.`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const url = element.value.trim(); // Trim whitespace
|
||||||
|
try {
|
||||||
|
// Use the URL constructor to validate structure
|
||||||
|
const parsedUrl = new URL(url);
|
||||||
|
if (parsedUrl.pathname !== "/" && parsedUrl.pathname.endsWith("/")) {
|
||||||
|
element.value = "";
|
||||||
|
toastr.error("Webhook URL should not end with a trailing slash.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedUrl.pathname.endsWith(".")) {
|
||||||
|
element.value = "";
|
||||||
|
toastr.error("Webhook URL should not end with a trailing dot.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// const strictDomainRegex = /^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/;
|
||||||
|
// if (!strictDomainRegex.test(parsedUrl.hostname)) {
|
||||||
|
// toastr.error("Invalid domain format in webhook URL.");
|
||||||
|
// element.value = "";
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// Check if protocol is HTTP/HTTPS
|
||||||
|
return parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:";
|
||||||
|
} catch (e) {
|
||||||
|
toastr.error("Invalid Webhook URL format");
|
||||||
|
element.value = "";
|
||||||
|
return false; // Invalid URL structure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#api-form").submit(function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const form = $(this);
|
||||||
|
// form.parsley().validate(); // Activate Parsley validation
|
||||||
|
|
||||||
|
if (!$(this).parsley().isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const formData = $(this).serializeArray();
|
||||||
|
formData.push({
|
||||||
|
name: "client_id",
|
||||||
|
value: $("#general_PrimaryKey").val()
|
||||||
|
});
|
||||||
|
formData.push({
|
||||||
|
name: "api_access",
|
||||||
|
value: $("#is_api").is(":checked") ? 1 : 0
|
||||||
|
});
|
||||||
|
console.log(formData);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "<?= base_url('client/saveApiData') ?>",
|
||||||
|
type: "POST",
|
||||||
|
data: formData,
|
||||||
|
beforeSend: function() {
|
||||||
|
$('.loader').fadeIn();
|
||||||
|
$('.loader-mask').fadeIn();
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
if (response.status) {
|
||||||
|
toastr.success(response.message);
|
||||||
|
} else {
|
||||||
|
toastr.error(response.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error("Error:", error);
|
||||||
|
toastr.error("An error occurred while processing your request.");
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').fadeOut();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".claim_webhook").on("input", function() {
|
||||||
|
|
||||||
|
let anyNotEmpty = $(".claim_webhook").toArray().some(input => $(input).val() !== "");
|
||||||
|
|
||||||
|
$(".claim_webhook").prop("required", anyNotEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".emp_webhook").on("input", function() {
|
||||||
|
let anyNotEmpty = $(".emp_webhook").toArray().some(input => $(input).val() !== "");
|
||||||
|
|
||||||
|
$(".emp_webhook").prop("required", anyNotEmpty);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@ -88,6 +88,12 @@ body {
|
|||||||
<span class="d-none d-sm-inline-block">Policies</span>
|
<span class="d-none d-sm-inline-block">Policies</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="#api-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="api_tab">
|
||||||
|
<span class="mdi mdi-api"></span>
|
||||||
|
<span class="d-none d-sm-inline-block">API</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a href="#others-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="others_tab">
|
<a href="#others-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="others_tab">
|
||||||
<span class="mr-1"><i class="mdi mdi-tag-text-outline"></i></span>
|
<span class="mr-1"><i class="mdi mdi-tag-text-outline"></i></span>
|
||||||
@ -96,6 +102,7 @@ body {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
<?php include("client_api.php"); ?>
|
||||||
<?php include('client_others_tab.php'); ?>
|
<?php include('client_others_tab.php'); ?>
|
||||||
<?php include('notification.php'); ?>
|
<?php include('notification.php'); ?>
|
||||||
<?php include('client_basic_info.php'); ?>
|
<?php include('client_basic_info.php'); ?>
|
||||||
@ -246,7 +253,7 @@ body {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
client_notification();
|
client_notification();
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1
app/Views/testWebhook.php
Normal file
1
app/Views/testWebhook.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello
|
||||||
Loading…
Reference in New Issue
Block a user