diff --git a/mati/resources/verifications.py b/mati/resources/verifications.py index 41d11d6..5fdb7f7 100644 --- a/mati/resources/verifications.py +++ b/mati/resources/verifications.py @@ -4,6 +4,7 @@ from ..types.enums import ( DocumentScore, + Errors, Liveness, UserValidationFile, VerificationDocument, @@ -83,6 +84,23 @@ def proof_of_life_document(self) -> Optional[Liveness]: pol = [pol for pol in self.steps if pol.id == 'liveness'] return pol[-1] if pol else None + @property + def proof_of_life_errors(self) -> List[Errors]: + if not self.steps: + return [] + return [ + Errors( + identifier=pol.id, + type=pol.error['type'] if 'type' in pol.error else None, + code=pol.error['code'] if 'code' in pol.error else None, + message=pol.error['message'] + if 'message' in pol.error + else None, + ) + for pol in self.steps + if pol.id == 'liveness' and pol.error + ] + @property def govt_id_document(self) -> Optional[VerificationDocument]: govs = [ diff --git a/mati/types/__init__.py b/mati/types/__init__.py index 4c09475..f408b59 100644 --- a/mati/types/__init__.py +++ b/mati/types/__init__.py @@ -1,4 +1,5 @@ __all__ = [ + 'Errors', 'SerializableEnum', 'PageType', 'ValidationInputType', @@ -13,6 +14,7 @@ from .enums import ( DocumentScore, + Errors, Liveness, LivenessMedia, PageType, diff --git a/mati/types/enums.py b/mati/types/enums.py index 3e95894..49bd02b 100644 --- a/mati/types/enums.py +++ b/mati/types/enums.py @@ -35,6 +35,14 @@ class VerificationDocumentStep: data: Optional[Dict] = field(default_factory=dict) +@dataclass +class Errors: + identifier: str + type: str + code: str + message: str + + @dataclass class VerificationDocument: country: str @@ -44,6 +52,46 @@ class VerificationDocument: type: str fields: Optional[dict] = None + @property + def get_errors(self) -> Optional[List[Errors]]: + if not self.steps: + return [] + errors = [ + Errors( + identifier=step.id, + type=step.error['type'] if 'type' in step.error else None, + code=step.error['code'] if 'code' in step.error else None, + message=step.error['message'] + if 'message' in step.error + else None, + ) + for step in self.steps + if step.error + ] + if self.type == 'proof-of-residency' and self.steps: + step = self.steps[0] + keys = step.data.keys() # type: ignore + required_fileds = [] + for key in keys: + data = step.data[key] # type: ignore + if ( + 'required' in data + and data['required'] + and not data['value'] + ): + required_fileds.append(data['label']) + if required_fileds: + errors.append( + Errors( + identifier=step.id, + type='StepError', + code='document.extractRequiredFields', + message=f"We can't extract the following " + f"fields in the document: {required_fileds}", + ) + ) + return errors + @property def document_type(self) -> str: if self.type in ['national-id', 'passport']: diff --git a/mati/version.py b/mati/version.py index 3cb60e3..d34bfc1 100644 --- a/mati/version.py +++ b/mati/version.py @@ -1 +1 @@ -__version__ = '2.0.0' # pragma: no cover +__version__ = '2.0.1.dev0' # pragma: no cover diff --git a/tests/resources/test_verifications.py b/tests/resources/test_verifications.py index 60474ab..8f8fd87 100644 --- a/tests/resources/test_verifications.py +++ b/tests/resources/test_verifications.py @@ -21,6 +21,7 @@ def test_retrieve_full_verification(client: Client): assert verification.govt_id_validation.is_valid assert verification.proof_of_life_validation.is_valid assert verification.proof_of_residency_validation.is_valid + assert not verification.proof_of_life_errors assert ( verification.proof_of_residency_document.address == 'Varsovia 36, 06600 CDMX'