CHANGES_ icici lumbard started

This commit is contained in:
Gowtham M 2025-06-26 09:50:43 +05:30
parent 3cf98e9513
commit fa2b22a1e4
4 changed files with 112 additions and 1 deletions

View File

@ -99,5 +99,5 @@ class Autoload extends AutoloadConfig
* @var string[]
* @phpstan-var list<string>
*/
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'];
}

View File

@ -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');

View File

@ -0,0 +1,35 @@
<?php
namespace App\Controllers;
use CodeIgniter\Controller;
class ICICILombardController extends AdminController
{
public function generateAuthToken($scope)
{
helper('api');
$url = 'https://ilesbapigee.insurancearticlez.com/generate-jwt-token';
$method = 'POST';
$headers = [
'Content-Type: application/x-www-form-urlencoded'
];
$body = [
'grant_type' => '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);
}
}

View File

@ -0,0 +1,70 @@
<?php
if (!function_exists('call_third_party_api')) {
function call_third_party_api($url, $method = 'GET', $headers = [], $body = [])
{
$ch = curl_init();
// Normalize method
$method = strtoupper($method);
// Detect content type from headers
$contentType = 'application/json'; // default
foreach ($headers as $h) {
if (stripos($h, 'Content-Type:') !== false) {
$contentType = trim(substr($h, strlen('Content-Type:')));
}
}
// return $contentType;
// echo '<pre>';
// 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
];
}
}