From fa2b22a1e4ffae89140a8c150a3c269b73c1d7cb Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Thu, 26 Jun 2025 09:50:43 +0530 Subject: [PATCH] CHANGES_ icici lumbard started --- app/Config/Autoload.php | 2 +- app/Config/Routes.php | 6 ++ app/Controllers/ICICILombardController.php | 35 +++++++++++ app/Helpers/api_helper.php | 70 ++++++++++++++++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 app/Controllers/ICICILombardController.php create mode 100644 app/Helpers/api_helper.php diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index c80f6c1c..9017581a 100755 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -99,5 +99,5 @@ class Autoload extends AutoloadConfig * @var string[] * @phpstan-var list */ - public $helpers = ['uuid','session','utility', 'form', 'url', 'oauth', 'fileupload', 'excel_import_export', 'file', 'drive','ExcelSanitizeHelper']; + public $helpers = ['uuid','session','utility', 'form', 'url', 'oauth', 'fileupload', 'excel_import_export', 'file', 'drive','ExcelSanitizeHelper', 'api_helper']; } diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 80a25075..d0d6da5f 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -590,3 +590,9 @@ $routes->post("dispatchWebhookData/(:any)/(:any)",'ClientWebHooksController::pus $routes->post("retrieveWebhookDataEmp","ClientWebHooksController::pullData_emp"); $routes->post("retrieveWebhookDataClaim","ClientWebHooksController::pullData_claim"); + + + +//Third party Api Call + +$routes->get('testCall','ICICILombardController::testCall'); \ No newline at end of file diff --git a/app/Controllers/ICICILombardController.php b/app/Controllers/ICICILombardController.php new file mode 100644 index 00000000..74a18bbe --- /dev/null +++ b/app/Controllers/ICICILombardController.php @@ -0,0 +1,35 @@ + 'password', + 'username' => 'Nhanceins', + 'password' => 'SSWW7bFNaLxxQyw', + 'scope' => $scope, + 'client_id' => 'Nhanceins', + 'client_secret' => 'P4W0G6TAYMa0MV8bbVSx4pTAqbCcUIg48kCWa6PJykAhGWzPmpPr0iLuNWtz5wqN' + ]; + + $response = call_third_party_api($url, $method, $headers, $body); + + if($response['status'] != false){ + + } + + return $this->response->setJSON($response); + } +} diff --git a/app/Helpers/api_helper.php b/app/Helpers/api_helper.php new file mode 100644 index 00000000..7dd13bd7 --- /dev/null +++ b/app/Helpers/api_helper.php @@ -0,0 +1,70 @@ +'; + // print_r($headers); + // print_r($body); + // die; + + + // Setup curl options + $options = [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_CUSTOMREQUEST => $method, + CURLOPT_HTTPHEADER => $headers, + ]; + + // Only include body for applicable methods + if (!empty($body) && in_array($method, ['POST', 'PUT', 'PATCH', 'DELETE'])) { + if (stripos($contentType, 'application/json') !== false) { + $options[CURLOPT_POSTFIELDS] = json_encode($body); + } elseif (stripos($contentType, 'application/x-www-form-urlencoded') !== false) { + $options[CURLOPT_POSTFIELDS] = http_build_query($body); + } elseif (stripos($contentType, 'multipart/form-data') !== false) { + $options[CURLOPT_POSTFIELDS] = $body; // For file uploads or multipart fields + } else { + // Default fallback + $options[CURLOPT_POSTFIELDS] = $body; + } + } + + curl_setopt_array($ch, $options); + + $response = curl_exec($ch); + $error = curl_error($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + if ($error) { + return [ + 'status' => false, + 'message' => 'Curl error: ' . $error + ]; + } + + $decoded = json_decode($response, true); + return [ + 'status' => ($httpCode >= 200 && $httpCode < 300), + 'data' => $decoded ?: $response, // fallback to raw response + 'code' => $httpCode + ]; + } +}