Skip to content

Commit 4dc6273

Browse files
Merge pull request #48 from hyperwallet/feature/DTPAYHWBM-1-V3-python-adding-reject-reasons
feature/DTPAYHWBM-1-V3-python-adding-reject-reasons
2 parents a923a2a + c26662c commit 4dc6273

4 files changed

Lines changed: 167 additions & 4 deletions

File tree

hyperwallet/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
StatusTransition, # noqa
3333
TransferMethodConfiguration, # noqa
3434
Webhook, # noqa
35-
TransferRefunds # naqa
35+
TransferRefunds, # naqa
36+
HyperwalletVerificationDocument,
37+
HyperwalletVerificationDocumentReason,
38+
RejectReason,
3639
)
3740

3841
from .api import Api # noqa

hyperwallet/api.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
StatusTransition,
2424
TransferMethodConfiguration,
2525
Webhook,
26-
TransferRefunds
26+
TransferRefunds,
27+
HyperwalletVerificationDocument,
28+
HyperwalletVerificationDocumentReason,
29+
RejectReason
2730
)
2831

2932

@@ -2761,6 +2764,38 @@ def listWebhookNotifications(self,
27612764
def __buildUrl(self, *paths):
27622765
return '/'.join(s.strip('/') for s in paths)
27632766

2767+
def setDocumentAndReasonFromResponseHelper(self,
2768+
data=None):
2769+
'''
2770+
Helper to modify dictionary with Document and Reason classes
2771+
2772+
:param data:
2773+
A dictionary containing data for either a User
2774+
sample data:
2775+
jsonData={'data': ['{"documents": [{"type": "DRIVERS_LICENSE", "country": "US", "category": "IDENTIFICATION", "reasons": {"name": 0, "description": "STRING_VAL"}}]}']};
2776+
:returns:
2777+
A Dictionary with documents and reasons information
2778+
'''
2779+
2780+
if "documents" in data.keys():
2781+
documents = data["documents"]
2782+
listOfDocs = []
2783+
for dVal in documents:
2784+
if "reasons" in dVal.keys():
2785+
reasons = dVal["reasons"]
2786+
dVal["reasons"] = []
2787+
for rVal in reasons:
2788+
if type(rVal["name"]) == str:
2789+
rVal["name"] = RejectReason[rVal["name"]]
2790+
else:
2791+
rVal["name"] = RejectReason(rVal["name"])
2792+
rVal = HyperwalletVerificationDocumentReason(rVal)
2793+
dVal["reasons"].append(rVal)
2794+
dVal = HyperwalletVerificationDocument(dVal)
2795+
listOfDocs.append(dVal)
2796+
data["documents"] = listOfDocs
2797+
return data
2798+
27642799
def uploadDocumentsForUser(self,
27652800
userToken=None,
27662801
data=None,
@@ -2796,7 +2831,7 @@ def uploadDocumentsForUser(self,
27962831
data,
27972832
files
27982833
)
2799-
2834+
response = self.setDocumentAndReasonFromResponseHelper(response)
28002835
return User(response)
28012836

28022837
'''

hyperwallet/models.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
import json
4-
4+
from enum import Enum
55

66
class HyperwalletModel(object):
77
'''
@@ -129,6 +129,76 @@ def __repr__(self):
129129
token=self.token
130130
)
131131

132+
class HyperwalletVerificationDocument(HyperwalletModel):
133+
'''
134+
The HyperwalletVerificationDocument Model.
135+
136+
:param data:
137+
A dictionary containing the attributes for the HyperwalletVerificationDocument.
138+
'''
139+
140+
def __init__(self, data):
141+
'''
142+
Create a new HyperwalletVerificationDocument with the provided attributes.
143+
'''
144+
145+
super(HyperwalletVerificationDocument, self).__init__(data)
146+
147+
self.defaults = {
148+
'category': None,
149+
'type': None,
150+
'status': None,
151+
'country': None,
152+
'reasons': None,
153+
'createdOn': None,
154+
'uploadFiles': None,
155+
}
156+
157+
for (param, default) in self.defaults.items():
158+
setattr(self, param, data.get(param, default))
159+
160+
def __repr__(self):
161+
return "HyperwalletVerificationDocument({category}, {createdOn})".format(
162+
createdOn=self.createdOn, category=self.category
163+
)
164+
165+
class HyperwalletVerificationDocumentReason(HyperwalletModel):
166+
'''
167+
The HyperwalletVerificationDocumentReason Model.
168+
169+
:param data:
170+
A dictionary containing the attributes for the HyperwalletVerificationDocumentReason.
171+
'''
172+
173+
def __init__(self, data):
174+
'''
175+
Create a new HyperwalletVerificationDocumentReason with the provided attributes.
176+
'''
177+
178+
super(HyperwalletVerificationDocumentReason, self).__init__(data)
179+
180+
self.defaults = {
181+
'name': None,
182+
'description': None,
183+
}
184+
185+
for (param, default) in self.defaults.items():
186+
setattr(self, param, data.get(param, default))
187+
188+
def __repr__(self):
189+
return "HyperwalletVerificationDocumentReason({name}, {description})".format(
190+
name=self.name, description=self.description
191+
)
192+
193+
class RejectReason(Enum):
194+
DOCUMENT_EXPIRED = 0
195+
DOCUMENT_NOT_RELATED_TO_PROFILE = 1
196+
DOCUMENT_NOT_READABLE = 2
197+
DOCUMENT_NOT_DECISIVE = 3
198+
DOCUMENT_NOT_COMPLETE = 4
199+
DOCUMENT_CORRECTION_REQUIRED = 5
200+
DOCUMENT_NOT_VALID_WITH_NOTES = 6
201+
DOCUMENT_TYPE_NOT_VALID = 7
132202

133203
class AuthenticationToken(HyperwalletModel):
134204
'''

hyperwallet/tests/test_api.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ def setUp(self):
6464
'currencies': ['USD'],
6565
'type': 'INDIVIDUAL'
6666
}
67+
68+
self.uploadSuccessData = {
69+
'token': 'tkn-12345',
70+
"documents": [{
71+
"category": "IDENTIFICATION",
72+
"type": "DRIVERS_LICENSE",
73+
"country": "AL",
74+
"status": "NEW"
75+
}]
76+
}
77+
78+
self.uploadRejectionData = {
79+
'token': 'tkn-12345',
80+
"documents": [{
81+
"category": "IDENTIFICATION",
82+
"type": "DRIVERS_LICENSE",
83+
"country": "AL",
84+
"status": "INVALID",
85+
"reasons": [
86+
{
87+
"name": "DOCUMENT_CORRECTION_REQUIRED",
88+
"description": "Document requires correction"
89+
},
90+
{
91+
"name": "DOCUMENT_NOT_DECISIVE",
92+
"description": "Decision cannot be made based on document. Alternative document required"
93+
}
94+
],
95+
"createdOn": "2020-11-24T19:05:02"
96+
}]
97+
}
6798

6899
self.value = {
69100
'data': ['{"documents": [{"type": "DRIVERS_LICENSE", "country": "AL", "category": "IDENTIFICATION"}]}']
@@ -2637,6 +2668,30 @@ def test_uploadDocumentsForUser_success(self, mock_put):
26372668

26382669
self.assertTrue(response.token, self.data.get('token'))
26392670

2671+
@mock.patch('hyperwallet.utils.ApiClient._makeRequest')
2672+
def test_uploadDocumentsForUserAndParse_success(self, mock_put):
2673+
2674+
mock_put.return_value = self.uploadSuccessData
2675+
response = self.api.uploadDocumentsForUser('token', self.value)
2676+
2677+
self.assertEqual(response.token, self.uploadSuccessData.get('token'))
2678+
self.assertEqual(response.documents[0].type, self.uploadSuccessData.get("documents")[0].type)
2679+
2680+
2681+
@mock.patch('hyperwallet.utils.ApiClient._makeRequest')
2682+
def test_uploadDocumentsForUserAndParseRejection_success(self, mock_put):
2683+
2684+
mock_put.return_value = self.uploadRejectionData
2685+
response = self.api.uploadDocumentsForUser('token', self.value)
2686+
2687+
# print(response.documents)
2688+
# print(response.documents[0].reasons[0].name.name)
2689+
2690+
self.assertEqual(response.token, self.uploadRejectionData.get('token'))
2691+
self.assertEqual(response.documents[0].reasons[0].name.name, self.uploadRejectionData.get("documents")[0].reasons[0].name.name)
2692+
self.assertEqual(response.documents[0].reasons[1].name.name, self.uploadRejectionData.get("documents")[0].reasons[1].name.name)
2693+
self.assertEqual(response.documents[0].type, self.uploadRejectionData.get("documents")[0].type)
2694+
26402695
'''
26412696
26422697
Transfer Refunds

0 commit comments

Comments
 (0)