$enqURL, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'Authorization:'.$token, 'Accept: */* ', 'X-Country: MW', 'X-Currency: MWK' ), )); $response = curl_exec($curl); curl_close($curl); return $response; } function authenticate($baseURL, $wallet, $password) { // JSON payload $postData = json_encode([ 'client_id' => $wallet, 'client_secret' => $password, 'grant_type' => "client_credentials" ]); // Initialize cURL $ch = curl_init($baseURL); // Set cURL options curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response curl_setopt($ch, CURLOPT_POST, true); // Use POST method curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);// Set the request body curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen($postData) ]); // Execute the request $response = curl_exec($ch); // Check for cURL errors if (curl_errno($ch)) { curl_close($ch); return [ 'success' => false, 'error' => 'Curl error: ' . curl_error($ch) ]; } // Get HTTP status code $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // Decode JSON response $result = json_decode($response, true); // Check if token is present if ($httpCode === 200 && isset($result['access_token'])) { return [ 'success' => true, 'token' => $result['access_token'] ]; } else { return [ 'success' => false, 'error' => $result['error_description'] ?? 'Unknown error', 'details' => $result['error'] ?? [] ]; } } ?>