Skip to content

Commit

Permalink
adding errors from docuemnts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexviquez committed Oct 3, 2022
1 parent d5c6df3 commit 50e6474
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
18 changes: 18 additions & 0 deletions mati/resources/verifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from ..types.enums import (
DocumentScore,
Errors,
Liveness,
UserValidationFile,
VerificationDocument,
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 2 additions & 0 deletions mati/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__all__ = [
'Errors',
'SerializableEnum',
'PageType',
'ValidationInputType',
Expand All @@ -13,6 +14,7 @@

from .enums import (
DocumentScore,
Errors,
Liveness,
LivenessMedia,
PageType,
Expand Down
48 changes: 48 additions & 0 deletions mati/types/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']:
Expand Down
2 changes: 1 addition & 1 deletion mati/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.0' # pragma: no cover
__version__ = '2.0.1.dev0' # pragma: no cover
1 change: 1 addition & 0 deletions tests/resources/test_verifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 50e6474

Please sign in to comment.