findApplicantByEmail method

Future<String?> findApplicantByEmail(
  1. String email
)

Find applicant by email

email - Email address to search for

Returns applicant ID if found, null otherwise

Implementation

Future<String?> findApplicantByEmail(String email) async {
  try {
    final response = await _apiClient.get(
      '/sdk/kyc-verification/applicants',
      queryParameters: {'email': email},
    );
    final jsonData = json.decode(response.body) as Map<String, dynamic>;
    return jsonData['id'] as String?;
  } catch (e) {
    // If applicant not found, return null instead of throwing
    if (e is ApexKycException) {
      // Check status code for 404 or 400 (bad request for not found)
      if (e.statusCode == 404 ||
          e.statusCode == 400 ||
          e.toString().toLowerCase().contains('not found')) {
        return null;
      }
      rethrow;
    }
    // Check if it's a 404 or not found error
    final errorString = e.toString().toLowerCase();
    if (errorString.contains('not found') || errorString.contains('404')) {
      return null;
    }
    throw ApexKycException(
      'Failed to find applicant by email: ${e.toString()}',
      originalError: e,
    );
  }
}