Skip to content

Commit 58a84ba

Browse files
committed
Merge branch 'dev'
2 parents ae24369 + adcd94f commit 58a84ba

12 files changed

Lines changed: 89 additions & 18 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ target/
6262

6363
.DS_Store
6464
*.html
65+
66+
venv

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ pip install synapse_pay_rest_native
1515
# synapse_pay_rest after installation.
1616
```
1717

18+
## Development
19+
1. Clone the repo from GitHub.
20+
2. Install requirements:
21+
```bash
22+
pip install -r requirements.txt
23+
```
24+
25+
Running the test suite:
26+
```bash
27+
python -m unittest synapse_pay_rest.tests
28+
```
29+
1830
## License
1931

2032
The MIT License (MIT)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests==2.11.1

samples.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ options = {
8181
'phone_number': '707-555-5555',
8282
'ip': '127.0.0.1',
8383
'name': 'Doctor BaseDoc',
84-
'aka': 'Basey',
84+
'alias': 'Basey',
8585
'entity_type': 'F',
8686
'entity_scope': 'Arts & Entertainment',
8787
'birth_day': 28,
@@ -106,7 +106,7 @@ options = {
106106
'phone_number': '415-555-5555',
107107
'ip': '127.0.0.2',
108108
'name': 'Doctor Boop',
109-
'aka': 'Boopsie',
109+
'alias': 'Boopsie',
110110
'entity_type': 'M',
111111
'entity_scope': 'Education',
112112
'birth_day': 21,
@@ -151,6 +151,7 @@ base_document = physical_document.base_document
151151
```python
152152
byte_stream = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00...'
153153
physical_document = base_document.add_physical_document(type='GOVT_ID',
154+
mime_type='image/jpeg',
154155
byte_stream=byte_stream)
155156
base_document = physical_document.base_document
156157
```

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Versions should comply with PEP440. For a discussion on single-sourcing
1818
# the version across setup.py and the project code, see
1919
# https://packaging.python.org/en/latest/single_source_version.html
20-
version='1.0.1',
20+
version='1.0.3',
2121

2222
description='SynapsePay Rest Native Python Library',
2323

synapse_pay_rest/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
more at https://docs.synapsepay.com
66
"""
77

8-
from .version import VERSION
98
from .client import Client
109
from .api import Users, Nodes, Trans
1110
from .models import User, Node, Transaction

synapse_pay_rest/models/transactions/transaction.py

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def __init__(self, **kwargs):
1212

1313
@classmethod
1414
def from_response(cls, node, response):
15+
"""Construct a Transaction from a response dict."""
1516
return cls(
1617
node=node,
1718
id=response['_id'],
@@ -40,12 +41,14 @@ def from_response(cls, node, response):
4041

4142
@classmethod
4243
def multiple_from_response(cls, node, response):
43-
nodes = [cls.from_response(node, trans_data)
44-
for trans_data in response]
45-
return nodes
44+
"""Construct multiple Transactions from a response dict."""
45+
transactions = [cls.from_response(node, trans_data)
46+
for trans_data in response]
47+
return transactions
4648

4749
@staticmethod
4850
def payload_for_create(to_type, to_id, amount, currency, ip, **kwargs):
51+
"""Build the API 'create transaction' payload from property values."""
4952
payload = {
5053
'to': {
5154
'type': to_type,
@@ -80,8 +83,29 @@ def payload_for_create(to_type, to_id, amount, currency, ip, **kwargs):
8083
@classmethod
8184
def create(cls, node=None, to_type=None, to_id=None, amount=None,
8285
currency=None, ip=None, **kwargs):
83-
# TODO allow multiple fees
84-
# TODO idempotency key
86+
"""Create a trans record in API and corresponding Transaction instance.
87+
88+
Args:
89+
node (BaseNode): the node from which to send funds
90+
to_type (str): type of the 'to' node (e.g. 'ACH-US')
91+
to_id (id): id of the 'to' node
92+
amount (float): amount of currency
93+
currency (str): type of currency (e.g. 'USD')
94+
ip (str): ip of the sender
95+
process_in (int): delay in days until processing (default 1)
96+
note (str): a note to synapse
97+
supp_id (str): a supplementary id
98+
fee_amount (float): an additional fee to include
99+
fee_note (str): a note to go with the fee
100+
fee_to_id (str): the node id from which to take the fee
101+
102+
Todo:
103+
- allow multiple fees
104+
- idempotency key
105+
106+
Returns:
107+
Transaction: a new Transaction instance
108+
"""
85109
payload = cls.payload_for_create(to_type, to_id, amount, currency, ip,
86110
**kwargs)
87111
node.user.authenticate()
@@ -91,15 +115,42 @@ def create(cls, node=None, to_type=None, to_id=None, amount=None,
91115

92116
@classmethod
93117
def by_id(cls, node=None, id=None):
118+
"""Retrieve a trans record by id and create a Transaction instance from it.
119+
120+
Args:
121+
node (BaseNode): the node from which to send funds
122+
id (str): id of the transaction to retrieve
123+
124+
Returns:
125+
Transaction: a Transaction instance corresponding to the record
126+
"""
94127
response = node.user.client.trans.get(node.user.id, node.id, id)
95128
return cls.from_response(node, response)
96129

97130
@classmethod
98131
def all(cls, node=None, **kwargs):
132+
"""Retrieve all trans records (limited by pagination) as Transactions.
133+
134+
Args:
135+
node (BaseNode): the node from which to send funds
136+
per_page (int, str): (opt) number of records to retrieve
137+
page (int, str): (opt) page number to retrieve
138+
139+
Returns:
140+
list: containing 0 or more Transaction instances
141+
"""
99142
response = node.user.client.trans.get(node.user.id, node.id, **kwargs)
100143
return cls.multiple_from_response(node, response['trans'])
101144

102145
def add_comment(self, comment):
146+
"""Add a comment to the transaction's recent_status.
147+
148+
Args:
149+
comment (str): text of the comment
150+
151+
Returns:
152+
Transaction: a new instance representing the same record updated
153+
"""
103154
payload = {'comment': comment}
104155
response = self.node.user.client.trans.update(self.node.user.id,
105156
self.node.id,
@@ -108,6 +159,11 @@ def add_comment(self, comment):
108159
return self.from_response(self.node, response['trans'])
109160

110161
def cancel(self):
162+
"""Cancel the transaction (will show in status).
163+
164+
Returns:
165+
Transaction: a new instance representing the same record updated
166+
"""
111167
response = self.node.user.client.trans.delete(self.node.user.id,
112168
self.node.id,
113169
self.id)

synapse_pay_rest/models/users/base_document.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def create(cls, user, **kwargs):
7777
phone_number=kwargs['phone_number'],
7878
ip=kwargs['ip'],
7979
name=kwargs['name'],
80-
aka=kwargs['aka'],
80+
alias=kwargs['alias'],
8181
entity_type=kwargs['entity_type'],
8282
entity_scope=kwargs['entity_scope'],
8383
birth_day=kwargs['birth_day'],
@@ -96,7 +96,7 @@ def create(cls, user, **kwargs):
9696
return base_document
9797

9898
@staticmethod
99-
def payload_for_create(email, phone_number, ip, name, aka,
99+
def payload_for_create(email, phone_number, ip, name, alias,
100100
entity_type, entity_scope, birth_day, birth_month,
101101
birth_year, address_street, address_city,
102102
address_subdivision, address_postal_code,
@@ -108,7 +108,7 @@ def payload_for_create(email, phone_number, ip, name, aka,
108108
'phone_number': phone_number,
109109
'ip': ip,
110110
'name': name,
111-
'alias': aka,
111+
'alias': alias,
112112
'entity_type': entity_type,
113113
'entity_scope': entity_scope,
114114
'day': birth_day,

synapse_pay_rest/models/users/physical_document.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def create(cls, base_document, value=None, type=None, file_path=None,
4646
def byte_stream_to_base64(byte_stream, mime_type):
4747
"""Convert a byte stream / array to a properly padded base64 string.
4848
"""
49-
encoded_string = str(base64.b64encode(byte_stream))
49+
base64_string = base64.b64encode(byte_stream).decode("utf-8")
5050
mime_padding = 'data:{0};base64,'.format(mime_type)
51-
base64_string = mime_padding + encoded_string
52-
return base64_string
51+
padded_base64 = mime_padding + base64_string
52+
return padded_base64
5353

5454
@staticmethod
5555
def file_to_base64(file_path):

synapse_pay_rest/tests/models/base_document_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def setUp(self):
1919
'phone_number': '707-555-5555',
2020
'ip': '127.0.0.1',
2121
'name': 'Doctor BaseDoc',
22-
'aka': 'Basey',
22+
'alias': 'Basey',
2323
'entity_type': 'F',
2424
'entity_scope': 'Arts & Entertainment',
2525
'birth_day': 28,

0 commit comments

Comments
 (0)