1
1
from collections import namedtuple
2
2
from trolley .exceptions .invalidFieldException import InvalidFieldException
3
3
import trolley .configuration
4
+ from trolley .types .log import Log
4
5
from trolley .types .meta import Meta
6
+ from trolley .types .payment import Payment
7
+ from trolley .types .recipient import Recipient
5
8
from trolley .utils .url_utils import UrlUtils
6
9
7
10
@@ -15,13 +18,18 @@ def __init__(self, gateway, config):
15
18
self .gateway = gateway
16
19
self .config = config
17
20
21
+ """
22
+ Retrieve a recipient
23
+ A recipient_id is required::
24
+ recipient.find('R-fjeracjmuflh')
25
+ """
18
26
def find (self , recipient_id , term = "" ):
19
27
if recipient_id is None :
20
28
raise InvalidFieldException ("Recipient id cannot be None." )
21
29
endpoint = f'/v1/recipients/{ recipient_id } /{ term } '
22
30
response = trolley .configuration .Configuration .client (
23
31
self .config ).get (endpoint )
24
- recip = trolley . Recipient .factory (response )
32
+ recip = Recipient .factory (response )
25
33
recipient = namedtuple ("Recipient" , recip .keys ())(* recip .values ())
26
34
count = 0
27
35
for account in recipient .accounts :
@@ -30,16 +38,27 @@ def find(self, recipient_id, term=""):
30
38
count = count + 1
31
39
return recipient
32
40
41
+ """
42
+ Create a recipient
43
+ A body is required::
44
+ recipient.create({"type": "individual", "firstName": "John",
45
+ "lastName": "Smith", "email": "[email protected] "})
46
+ """
33
47
def create (self , body ):
34
48
if body is None :
35
49
raise InvalidFieldException ("Body cannot be None." )
36
50
endpoint = '/v1/recipients/'
37
51
response = trolley .configuration .Configuration .client (
38
52
self .config ).post (endpoint , body )
39
- recip = trolley . Recipient .factory (response )
53
+ recip = Recipient .factory (response )
40
54
recipient = namedtuple ("Recipient" , recip .keys ())(* recip .values ())
41
55
return recipient
42
56
57
+ """
58
+ Update a recipient
59
+ A recipient_id and body are required::
60
+ recipient.update('R-fjeracjmuflh', {'firstName': 'tom'})
61
+ """
43
62
def update (self , recipient_id , body ):
44
63
if recipient_id is None :
45
64
raise InvalidFieldException ("Recipient id cannot be None." )
@@ -50,6 +69,11 @@ def update(self, recipient_id, body):
50
69
self .config ).patch (endpoint , body )
51
70
return True
52
71
72
+ """
73
+ Delete a recipient
74
+ A recipient_id is required::
75
+ recipient.delete('R-fjeracjmuflh')
76
+ """
53
77
def delete (self , recipient_id ):
54
78
if recipient_id is None :
55
79
raise InvalidFieldException ("Recipient id cannot be None." )
@@ -58,6 +82,14 @@ def delete(self, recipient_id):
58
82
self .config ).delete (endpoint )
59
83
return True
60
84
85
+ """
86
+ Delete multiple recipients
87
+ A list of recipient_ids is required::
88
+ recipient.delete_multiple([
89
+ 'R-fjeracjmuflh',
90
+ 'R-ajerasdfuflf'
91
+ ])
92
+ """
61
93
def delete_multiple (self , recipient_ids ):
62
94
if recipient_ids is None :
63
95
raise InvalidFieldException ("Recipient ids cannot be None." )
@@ -67,6 +99,11 @@ def delete_multiple(self, recipient_ids):
67
99
self .config ).delete (endpoint , recipient_ids )
68
100
return True
69
101
102
+ """
103
+ Retrieve Recipient activity logs, by page
104
+ A recipient_id is required:
105
+ recipient.retrieve_logs('R-fjeracjmuflh')
106
+ """
70
107
def retrieve_logs (self , recipient_id , page = 1 , pageSize = 10 ):
71
108
if recipient_id is None :
72
109
raise InvalidFieldException ("Recipient id cannot be None." )
@@ -78,7 +115,7 @@ def retrieve_logs(self, recipient_id, page=1, pageSize=10):
78
115
logs = []
79
116
count = 0
80
117
for log in response ['recipientLogs' ]:
81
- temp = trolley . Log .factory (log )
118
+ temp = Log .factory (log )
82
119
83
120
logs .insert (count , namedtuple ("Log" , temp .keys ())(* temp .values ()))
84
121
@@ -89,6 +126,11 @@ def retrieve_logs(self, recipient_id, page=1, pageSize=10):
89
126
90
127
return logs
91
128
129
+ """
130
+ Retrieve all payments of the Recipient
131
+ A recipient_id is required:
132
+ recipient.get_all_payments('R-fjeracjmuflh')
133
+ """
92
134
def get_all_payments (self , recipient_id ):
93
135
if recipient_id is None :
94
136
raise InvalidFieldException ("Recipient id cannot be None." )
@@ -99,7 +141,7 @@ def get_all_payments(self, recipient_id):
99
141
payments = []
100
142
count = 0
101
143
for payment in response ['payments' ]:
102
- temppayment = trolley . Payment .factory (payment )
144
+ temppayment = Payment .factory (payment )
103
145
newpayment = namedtuple ("Payment" , temppayment .keys ())(* temppayment .values ())
104
146
payments .insert (count , newpayment )
105
147
count = count + 1
@@ -109,6 +151,11 @@ def get_all_payments(self, recipient_id):
109
151
110
152
return payments
111
153
154
+ """
155
+ Retrieve all offline payments of the Recipient
156
+ A recipient_id is required:
157
+ recipient.get_all_offline_payments('R-fjeracjmuflh')
158
+ """
112
159
def get_all_offline_payments (self , recipient_id ):
113
160
if recipient_id is None :
114
161
raise InvalidFieldException ("Recipient id cannot be None." )
@@ -119,7 +166,7 @@ def get_all_offline_payments(self, recipient_id):
119
166
offlinePayments = []
120
167
count = 0
121
168
for offlinePayment in response ['offlinePayments' ]:
122
- temppayment = trolley . Payment .factory (offlinePayment )
169
+ temppayment = Payment .factory (offlinePayment )
123
170
newpayment = namedtuple ("Payment" , temppayment .keys ())(* temppayment .values ())
124
171
offlinePayments .insert (count , newpayment )
125
172
count = count + 1
@@ -134,7 +181,8 @@ def get_all_offline_payments(self, recipient_id):
134
181
You can use this generator in a foreach loop to sequentially go through all the
135
182
search results without needing to call this method again.
136
183
137
- For accessing specific pages, check the search_by_page() method. """
184
+ For accessing specific pages, check the search_by_page() method.
185
+ """
138
186
def search (self , search = None , name = None , email = None , reference_id = None , start_date = None ,
139
187
end_date = None , status = None , compliance_status = None , country = None , payout_method = None , currency = None ,
140
188
order_by = None , sort_by = None ):
@@ -156,7 +204,9 @@ def search(self, search=None, name=None, email=None, reference_id=None, start_da
156
204
157
205
""" Search Recipients by providing a page number.
158
206
This method returns a list.
159
- You should use this function when you want to paginate manually. """
207
+ You should use this function when you want to paginate manually.
208
+ recipient.search_by_page(1,10,'test')
209
+ """
160
210
def search_by_page (self , page = 1 , page_size = 10 , search = None , name = None , email = None , reference_id = None , start_date = None ,
161
211
end_date = None , status = None , compliance_status = None , country = None , payout_method = None , currency = None ,
162
212
order_by = None , sort_by = None ):
@@ -169,7 +219,7 @@ def __build_recipients_from_response(self, response, include_meta=False):
169
219
recipients = []
170
220
count = 0
171
221
for recipient in response ['recipients' ]:
172
- temp = trolley . recipient . Recipient .factory (recipient )
222
+ temp = Recipient .factory (recipient )
173
223
174
224
recipient = namedtuple ("Recipient" , temp .keys ())(* temp .values ())
175
225
recipients .insert (count , recipient )
0 commit comments