-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsdk_config.py
More file actions
364 lines (307 loc) · 9.99 KB
/
sdk_config.py
File metadata and controls
364 lines (307 loc) · 9.99 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from yoti_python_sdk.doc_scan.constants import CAMERA
from yoti_python_sdk.doc_scan.constants import CAMERA_AND_UPLOAD
from yoti_python_sdk.utils import YotiSerializable, remove_null_values
class SdkConfig(YotiSerializable):
"""
Provides configuration properties for the web/native clients
"""
def __init__(
self,
allowed_capture_methods,
primary_colour,
secondary_colour,
font_colour,
locale,
preset_issuing_country,
success_url,
error_url,
allow_handoff=None,
privacy_policy_url=None,
enforce_handoff=None,
):
"""
:param allowed_capture_methods: the allowed capture methods
:type allowed_capture_methods: str
:param primary_colour: the primary colour
:type primary_colour: str
:param secondary_colour: the secondary colour
:type secondary_colour: str
:param font_colour: the font colour
:type font_colour: str
:param locale: the locale
:type locale: str
:param preset_issuing_country: the preset issuing country
:type preset_issuing_country: str
:param success_url: the success url
:type success_url: str
:param error_url: the error url
:type error_url: str
:param privacy_policy_url: the privacy policy url
:type privacy_policy_url: str
:param allow_handoff: boolean flag for allow_handoff
:type allow_handoff: bool
:param enforce_handoff: boolean flag for enforce_handoff
:type enforce_handoff: bool
"""
self.__allowed_capture_methods = allowed_capture_methods
self.__primary_colour = primary_colour
self.__secondary_colour = secondary_colour
self.__font_colour = font_colour
self.__locale = locale
self.__preset_issuing_country = preset_issuing_country
self.__success_url = success_url
self.__error_url = error_url
self.__privacy_policy_url = privacy_policy_url
self.__allow_handoff = allow_handoff
self.__enforce_handoff = enforce_handoff
@property
def allowed_capture_methods(self):
"""
The methods allowed for capturing document images
:return: the allowed capture methods
"""
return self.__allowed_capture_methods
@property
def primary_colour(self):
"""
The primary colour
:return: the primary colour
"""
return self.__primary_colour
@property
def secondary_colour(self):
"""
The secondary colour
:return: the secondary colour
"""
return self.__secondary_colour
@property
def font_colour(self):
"""
The font colour
:return: the font colour
"""
return self.__font_colour
@property
def locale(self):
"""
The locale
:return: the locale
"""
return self.__locale
@property
def preset_issuing_country(self):
"""
The preset issuing country
:return: the preset issuing country
"""
return self.__preset_issuing_country
@property
def success_url(self):
"""
The success URL
:return: the success url
"""
return self.__success_url
@property
def error_url(self):
"""
The error URL
:return: the error url
"""
return self.__error_url
@property
def privacy_policy_url(self):
"""
The privacy policy URL
:return: the privacy policy url
"""
return self.__privacy_policy_url
@property
def allow_handoff(self):
"""
Flag to enable/disable relying business to handoff
support when creating a session.
:return: the allow_handoff
"""
return self.__allow_handoff
@property
def enforce_handoff(self):
"""
Flag to enforce handoff when allow_handoff is enabled.
Cannot be true if allow_handoff is false.
:return: the enforce_handoff
"""
return self.__enforce_handoff
def to_json(self):
return remove_null_values(
{
"allowed_capture_methods": self.allowed_capture_methods,
"primary_colour": self.primary_colour,
"secondary_colour": self.secondary_colour,
"font_colour": self.font_colour,
"locale": self.locale,
"preset_issuing_country": self.preset_issuing_country,
"success_url": self.success_url,
"error_url": self.error_url,
"privacy_policy_url": self.privacy_policy_url,
"allow_handoff": self.allow_handoff,
"enforce_handoff": self.enforce_handoff,
}
)
class SdkConfigBuilder(object):
"""
Builder to assist in the creation of :class:`SdkConfig`
"""
def __init__(self):
self.__allowed_capture_methods = None
self.__primary_colour = None
self.__secondary_colour = None
self.__font_colour = None
self.__locale = None
self.__preset_issuing_country = None
self.__success_url = None
self.__error_url = None
self.__privacy_policy_url = None
self.__allow_handoff = None
self.__enforce_handoff = None
def with_allowed_capture_methods(self, allowed_capture_methods):
"""
Sets the allowed capture methods on the builder
:param allowed_capture_methods: the allowed capture methods
:type allowed_capture_methods: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__allowed_capture_methods = allowed_capture_methods
return self
def with_allows_camera(self):
"""
Sets the allowed capture method to "CAMERA"
:return: the builder
:rtype: SdkConfigBuilder
"""
return self.with_allowed_capture_methods(CAMERA)
def with_allows_camera_and_upload(self):
"""
Sets the allowed capture method to "CAMERA_AND_UPLOAD"
:return: the builder
:rtype: SdkConfigBuilder
"""
return self.with_allowed_capture_methods(CAMERA_AND_UPLOAD)
def with_primary_colour(self, colour):
"""
Sets the primary colour to be used by the web/native client
:param colour: the primary colour, hexadecimal value e.g. #ff0000
:type colour: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__primary_colour = colour
return self
def with_secondary_colour(self, colour):
"""
Sets the secondary colour to be used by the web/native client (used on the button)
:param colour: the secondary colour, hexadecimal value e.g. #ff0000
:type colour: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__secondary_colour = colour
return self
def with_font_colour(self, colour):
"""
Sets the font colour to be used by the web/native client (used on the button)
:param colour: the font colour, hexadecimal value e.g. #ff0000
:type colour: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__font_colour = colour
return self
def with_locale(self, locale):
"""
Sets the language locale use by the web/native client
:param locale: the locale, e.g. "en"
:type locale: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__locale = locale
return self
def with_preset_issuing_country(self, country):
"""
Sets the preset issuing country used by the web/native client
:param country: the preset issuing country
:type country: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__preset_issuing_country = country
return self
def with_success_url(self, url):
"""
Sets the success URL for the redirect that follows the web/native client uploading documents successfully
:param url: the success URL
:type url: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__success_url = url
return self
def with_error_url(self, url):
"""
Sets the error URL for the redirect that follows the web/native client uploading documents unsuccessfully
:param url: the error URL
:type url: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__error_url = url
return self
def with_privacy_policy_url(self, url):
"""
Sets the privacy policy URL
:param url: the privacy policy URL
:type url: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__privacy_policy_url = url
return self
def with_allow_handoff(self, flag):
"""
Sets the allow handoff flag
:param flag: boolean value for flag
:type flag: bool
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__allow_handoff = flag
return self
def with_enforce_handoff(self, flag):
"""
Sets the enforce handoff flag
:param flag: boolean value for flag
:type flag: bool
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__enforce_handoff = flag
return self
def build(self):
return SdkConfig(
self.__allowed_capture_methods,
self.__primary_colour,
self.__secondary_colour,
self.__font_colour,
self.__locale,
self.__preset_issuing_country,
self.__success_url,
self.__error_url,
self.__allow_handoff,
self.__privacy_policy_url,
self.__enforce_handoff,
)