-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuser_verification_data.py
More file actions
68 lines (59 loc) · 2.12 KB
/
user_verification_data.py
File metadata and controls
68 lines (59 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import json
from typing import Any, BinaryIO, ClassVar, Dict, List, Tuple
from mati.types import UserValidationFile, VerificationInputType
from .base import Resource
def get_file_type(file: UserValidationFile) -> str:
input_type = file.input_type
if input_type == 'selfie-video':
file_type = 'video'
elif input_type == 'selfie-photo':
file_type = 'selfie'
else:
file_type = 'document'
return file_type
class UserValidationData(Resource):
"""
Based on: https://docs.getmati.com/#step-3-upload-user-verification-data
"""
_endpoint: ClassVar[str] = '/v2/identities/{identity_id}/send-input'
@staticmethod
def _append_file(
files_metadata: List[Dict[str, Any]], file: UserValidationFile
):
if file.input_type == VerificationInputType.document_photo:
files_metadata.append(
dict(
inputType=file.input_type,
group=file.group,
data=dict(
type=file.validation_type,
country=file.country,
page=file.page,
filename=file.filename,
region=file.region,
),
)
)
else:
files_metadata.append(
dict(
inputType=file.input_type,
data=dict(filename=file.filename),
)
)
@classmethod
def upload(
cls, identity_id: str, user_validation_files: List[UserValidationFile]
) -> List[Dict[str, Any]]:
endpoint = cls._endpoint.format(identity_id=identity_id)
files_metadata: List[Dict[str, Any]] = []
files_with_types: List[Tuple[str, BinaryIO]] = []
for file in user_validation_files:
cls._append_file(files_metadata, file)
files_with_types.append((get_file_type(file), file.content))
resp = cls._client.post(
endpoint,
data=dict(inputs=json.dumps(files_metadata)),
files=files_with_types,
)
return resp