@@ -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 )
0 commit comments