Skip to content

Commit 07128e3

Browse files
committed
Write flow for virtual doc mfa and node microdeposit verification
1 parent 4ab00e7 commit 07128e3

18 files changed

Lines changed: 318 additions & 211 deletions

synapse_pay_rest/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ErrorFactory():
108108

109109
@classmethod
110110
def from_response(cls, response):
111-
import pdb; pdb.set_trace()
111+
# import pdb; pdb.set_trace()
112112
code = response.status_code
113113
klass = cls.ERRORS.get(code, SynapsePayError)
114114
body = response.json()

synapse_pay_rest/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .users import User, PhysicalDocument, SocialDocument, VirtualDocument,\
2-
BaseDocument
2+
BaseDocument, Question
33
from .nodes import AchUsNode, EftIndNode, EftNpNode, IouNode, ReserveUsNode,\
44
SynapseIndNode, SynapseNpNode, SynapseUsNode, WireIntNode,\
55
WireUsNode, Node

synapse_pay_rest/models/nodes/ach_us_node.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ def payload_for_create(cls, nickname, account_number, routing_number,
2727
account_class=account_class,
2828
**kwargs)
2929
return payload
30+
31+
def verify_microdeposits(self, amount1, amount2):
32+
payload = {'micro': [amount1, amount2]}
33+
response = self.user.client.nodes.update(self.user.id, self.id, payload)
34+
return self.from_response(self.user, response)

synapse_pay_rest/models/users/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from .physical_document import PhysicalDocument
44
from .social_document import SocialDocument
55
from .virtual_document import VirtualDocument
6+
from .virtual_document import Question

synapse_pay_rest/models/users/physical_document.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def file_to_base64(file_path):
4040
with open(file_path, 'rb') as file_object:
4141
byte_stream = file_object.read()
4242
mime_type = mimetypes.guess_type(file_object.name)[0]
43-
return PhysicalDocument.byte_stream_to_base64(byte_stream, mime_type)
43+
return PhysicalDocument.byte_stream_to_base64(byte_stream,
44+
mime_type)
4445

4546
@staticmethod
4647
def url_to_base64(url):
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
class Question():
4+
"""
5+
"""
6+
7+
def __init__(self, **kwargs):
8+
for arg, value in kwargs.items():
9+
setattr(self, arg, value)
10+
11+
@classmethod
12+
def from_response(cls, response):
13+
return cls(question=response['question'], answers=response['answers'],
14+
id=response['id'])
15+
16+
@classmethod
17+
def multiple_from_response(cls, response):
18+
return [cls.from_response(question) for question in response]

synapse_pay_rest/models/users/virtual_document.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .document import Document
2+
from .question import Question
23

34

45
class VirtualDocument(Document):
@@ -12,3 +13,40 @@ def create(cls, base_document=None, type=None, value=None):
1213
virtual_doc = [doc for doc in base_doc.virtual_documents
1314
if doc.type == type][0]
1415
return virtual_doc
16+
17+
@classmethod
18+
def from_response(cls, response):
19+
doc = super().from_response(response)
20+
if response.get('meta') and response['meta'].get('question_set'):
21+
question_data = response['meta']['question_set']['questions']
22+
question_set = Question.multiple_from_response(question_data)
23+
doc.question_set = question_set
24+
return doc
25+
26+
def submit_kba(self):
27+
user = self.base_document.user
28+
response = user.client.users.update(user.id, self.payload_for_kba())
29+
user = user.from_response(user.client, response)
30+
base_doc = [base_doc for base_doc in user.base_documents
31+
if base_doc.id == self.base_document.id][0]
32+
virtual_doc = [doc for doc in base_doc.virtual_documents if
33+
doc.id == self.id][0]
34+
return virtual_doc
35+
36+
def payload_for_kba(self):
37+
answers = [{'question_id': question.id, 'answer_id': question.choice}
38+
for question in self.question_set]
39+
payload = {
40+
'documents': [{
41+
'id': self.base_document.id,
42+
'virtual_docs': [{
43+
'id': self.id,
44+
'meta': {
45+
'question_set': {
46+
'answers': answers
47+
}
48+
}
49+
}]
50+
}]
51+
}
52+
return payload

synapse_pay_rest/tests/api/nodes_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
class NodesTestCases(unittest.TestCase):
99
def setUp(self):
10+
print('\n{0}.{1}'.format(type(self).__name__, self._testMethodName))
1011
self.client = test_client
1112
self.user = self.client.users.create(users_create_payload)
1213
refresh_payload = {'refresh_token': self.user['refresh_token']}

synapse_pay_rest/tests/api/trans_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
class TransTestCases(unittest.TestCase):
99
def setUp(self):
10+
print('\n{0}.{1}'.format(type(self).__name__, self._testMethodName))
1011
self.client = test_client
1112
self.user = self.client.users.create(users_create_payload)
1213
refresh_payload = {'refresh_token': self.user['refresh_token']}

synapse_pay_rest/tests/api/users_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
class UsersTestCases(unittest.TestCase):
77
def setUp(self):
8+
print('\n{0}.{1}'.format(type(self).__name__, self._testMethodName))
89
self.client = test_client
910

1011
def test_create_a_new_user(self):

0 commit comments

Comments
 (0)