verifyDocumentFront method
Verify document front (recto)
Implementation
@override
Future<Map<String, dynamic>> verifyDocumentFront(String sessionId, Map<String, dynamic> verificationData) async {
try {
// Create multipart request for form-data
final request = http.MultipartRequest(
'POST',
Uri.parse('$_baseAppUrl/verify/front/$sessionId'),
);
// Add bearer token if available
if (_hasValidBearerToken) {
request.headers['Authorization'] = 'Bearer $_bearerToken';
}
// Add text fields
request.fields['document_type'] = verificationData['document_type'] as String;
request.fields['document_country'] = verificationData['document_country'] as String;
// Add photo file
if (verificationData['photo'] is File) {
final photoFile = verificationData['photo'] as File;
final photoStream = http.ByteStream(photoFile.openRead());
final photoLength = await photoFile.length();
request.files.add(http.MultipartFile(
'photo',
photoStream,
photoLength,
filename: photoFile.path.split('/').last,
));
} else if (verificationData['photo'] is String) {
// Handle base64 string
final photoBytes = base64Decode(verificationData['photo'] as String);
request.files.add(http.MultipartFile.fromBytes(
'photo',
photoBytes,
filename: 'photo.jpg',
));
}
final streamedResponse = await request.send();
final response = await http.Response.fromStream(streamedResponse);
if (response.statusCode == 200) {
final responseData = jsonDecode(response.body);
print('=== API RESPONSE: VERIFY DOCUMENT FRONT ===');
print('Status Code: ${response.statusCode}');
print('Response Data: $responseData');
print('=====================================');
return responseData;
} else {
print('=== API ERROR: VERIFY DOCUMENT FRONT ===');
print('Status Code: ${response.statusCode}');
print('Error Body: ${response.body}');
print('=====================================');
throw Exception('Failed to verify document front: ${response.statusCode}');
}
} catch (e) {
throw Exception('Error verifying document front: $e');
}
}