validateRequest(['GET']); if (!$validation['valid']) { http_response_code($validation['http_code']); echo json_encode(['status' => 'error', 'message' => $validation['error']]); exit; } // 2. Validate Student ID $studentId = trim($_GET['student_id'] ?? ''); if (empty($studentId)) { http_response_code(400); echo json_encode(['status' => 'error', 'message' => 'Student ID is required']); exit; } $studentCheck = $validator->validateStudentExists($studentId); if (!$studentCheck['valid']) { http_response_code($studentCheck['http_code']); echo json_encode(['status' => 'error', 'message' => $studentCheck['error']]); exit; } try { // 3. Fetch Data $data = $processor->getTotalOutstandingBalance($studentId); // 4. Send Response echo json_encode([ 'status' => 'success', 'data' => $data ]); } catch (Exception $e) { // Log error (if logging enabled) if (function_exists('log_api_request')) { // log_api_request would be defined in api_config or similar, // but for now we just handle the output. } http_response_code(500); echo json_encode(['status' => 'error', 'message' => 'Internal server error: ' . $e->getMessage()]); }