1
1
# -*- coding: utf-8 -*-
2
- import json
3
-
4
2
import collections
3
+ import json
5
4
6
- from yoti_python_sdk import config
5
+ from yoti_python_sdk .anchor import Anchor
6
+ from yoti_python_sdk import config , attribute
7
7
from yoti_python_sdk .protobuf .v1 .protobuf import Protobuf
8
8
9
9
10
10
class ActivityDetails :
11
11
def __init__ (self , receipt , decrypted_profile = None ):
12
12
self .decrypted_profile = decrypted_profile
13
- self .user_profile = {}
13
+ self .user_profile = {} # will be deprecated in v3.0.0
14
+ self .profile = {}
14
15
self .base64_selfie_uri = None
15
16
16
17
if decrypted_profile and hasattr (decrypted_profile , 'attributes' ):
@@ -19,17 +20,21 @@ def __init__(self, receipt, decrypted_profile=None):
19
20
field .value ,
20
21
field .content_type
21
22
)
22
- self .user_profile [field .name ] = value
23
+
24
+ anchors = Anchor ().parse_anchors (field .anchors )
25
+
26
+ self .profile [field .name ] = attribute .attribute (field .name , value , anchors )
27
+ self .user_profile [field .name ] = value # will be deprecated in v3.0.0
23
28
24
29
if field .name == 'selfie' :
25
30
self .try_parse_selfie_field (field )
26
31
27
32
if field .name .startswith (config .ATTRIBUTE_AGE_OVER ) or field .name .startswith (
28
33
config .ATTRIBUTE_AGE_UNDER ):
29
- self .try_parse_age_verified_field (field )
34
+ self .try_parse_age_verified_field (field , anchors )
30
35
31
36
if field .name == config .ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS :
32
- self .try_convert_structured_postal_address_to_dict (field )
37
+ self .try_convert_structured_postal_address_to_dict (field , anchors )
33
38
34
39
self .set_address_to_be_formatted_address_if_null ()
35
40
@@ -42,33 +47,45 @@ def try_parse_selfie_field(self, field):
42
47
field .content_type
43
48
)
44
49
45
- def try_parse_age_verified_field (self , field ):
50
+ def try_parse_age_verified_field (self , field , anchors ):
46
51
if field is not None :
47
52
is_age_verified = Protobuf ().value_based_on_content_type (
48
53
field .value ,
49
54
field .content_type
50
55
)
51
56
if is_age_verified == 'true' :
52
57
self .user_profile ['is_age_verified' ] = True
58
+ self .profile ['is_age_verified' ] = attribute .attribute (is_age_verified , True , anchors )
53
59
return
54
60
if is_age_verified == 'false' :
55
61
self .user_profile ['is_age_verified' ] = False
62
+ self .profile ['is_age_verified' ] = attribute .attribute (is_age_verified , False , anchors )
56
63
return
57
64
58
65
raise TypeError ("age_verified_field unable to be parsed" )
59
66
60
- def try_convert_structured_postal_address_to_dict (self , field ):
67
+ def try_convert_structured_postal_address_to_dict (self , field , anchors ):
61
68
decoder = json .JSONDecoder (object_pairs_hook = collections .OrderedDict )
62
69
self .user_profile [config .ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS ] = decoder .decode (field .value )
70
+ self .profile [config .ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS ] = attribute .attribute (
71
+ "structured_postal_address" ,
72
+ decoder .decode (field .value ),
73
+ anchors )
63
74
64
75
def set_address_to_be_formatted_address_if_null (self ):
65
76
if 'postal_address' not in self .user_profile and 'structured_postal_address' in self .user_profile :
66
77
if 'formatted_address' in self .user_profile ['structured_postal_address' ]:
67
78
self .user_profile ['postal_address' ] = self .user_profile ['structured_postal_address' ][
68
79
'formatted_address' ]
69
80
81
+ if 'postal_address' not in self .profile and 'structured_postal_address' in self .profile :
82
+ if 'formatted_address' in self .profile ['structured_postal_address' ].get_value ():
83
+ self .profile ['postal_address' ] = self .profile ['structured_postal_address' ].get_value ()[
84
+ 'formatted_address' ]
85
+
70
86
def __iter__ (self ):
71
87
yield 'user_id' , self .user_id
72
88
yield 'outcome' , self .outcome
73
89
yield 'user_profile' , self .user_profile
90
+ yield 'profile' , self .profile
74
91
yield 'base64_selfie_uri' , self .base64_selfie_uri
0 commit comments