db = \Config\Database::connect(); $this->fhplTpaId = getenv('FHPL_PRIMARY_KEY_CONSTANT'); } public function generateAuthToken() { $url = env('FHPL_TOKEN_URL'); // example: https://uat.fhpl.net/token // x-www-form-urlencoded body $postData = http_build_query([ 'UserName' => 'TestApi@fhpl', 'Password' => 'Fhpl@12345', 'grant_type' => 'password', ]); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => 'GET', // SAME AS POSTMAN CURLOPT_POSTFIELDS => $postData, CURLOPT_HTTPHEADER => [ 'Content-Type: application/x-www-form-urlencoded', 'Accept: application/json', ], CURLOPT_TIMEOUT => 30, ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { return $this->response->setJSON([ 'status' => false, 'error' => curl_error($ch), ]); } curl_close($ch); return $this->response->setJSON([ 'status' => $httpCode === 200, 'http_code' => $httpCode, 'response' => json_decode($response, true), ]); } }