CHANGES_ icici lumbard started
This commit is contained in:
parent
3cf98e9513
commit
fa2b22a1e4
@ -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'];
|
||||
}
|
||||
|
||||
@ -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');
|
||||
35
app/Controllers/ICICILombardController.php
Normal file
35
app/Controllers/ICICILombardController.php
Normal 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);
|
||||
}
|
||||
}
|
||||
70
app/Helpers/api_helper.php
Normal file
70
app/Helpers/api_helper.php
Normal 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
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user