-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbilling_requests_service.py
More file actions
370 lines (272 loc) · 12.3 KB
/
Copy pathbilling_requests_service.py
File metadata and controls
370 lines (272 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# WARNING: Do not edit by hand, this file was generated by Crank:
#
# https://github.com/gocardless/crank
#
from . import base_service
from .. import resources
from ..paginator import Paginator
from .. import errors
class BillingRequestsService(base_service.BaseService):
"""Service class that provides access to the billing_requests
endpoints of the GoCardless API.
"""
RESOURCE_CLASS = resources.BillingRequest
RESOURCE_NAME = 'billing_requests'
def create(self,params=None, headers=None):
"""Create a Billing Request.
<p class="notice"><strong>Important</strong>: All properties associated
with `subscription_request` and `instalment_schedule_request` are only
supported for ACH and PAD schemes.</p>
Args:
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = '/billing_requests'
if params is not None:
params = {self._envelope_key(): params}
try:
response = self._perform_request('POST', path, params, headers,
retry_failures=True)
except errors.IdempotentCreationConflictError as err:
if self.raise_on_idempotency_conflict:
raise err
return self.get(identity=err.conflicting_resource_id,
params=params,
headers=headers)
return self._resource_for(response)
def collect_customer_details(self,identity,params=None, headers=None):
"""Collect customer details.
If the billing request has a pending
<code>collect_customer_details</code>
action, this endpoint can be used to collect the details in order to
complete it.
The endpoint takes the same payload as Customers, but checks that the
customer fields are populated correctly for the billing request scheme.
Whatever is provided to this endpoint is used to update the referenced
customer, and will take effect immediately after the request is
successful.
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/collect_customer_details', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)
def collect_bank_account(self,identity,params=None, headers=None):
"""Collect bank account details.
If the billing request has a pending
<code>collect_bank_account</code> action, this endpoint can be
used to collect the details in order to complete it.
The endpoint takes the same payload as Customer Bank Accounts, but
check
the bank account is valid for the billing request scheme before
creating
and attaching it.
If the scheme is PayTo and the pay_id is available, this can be
included in the payload along with the
country_code.
_ACH scheme_ For compliance reasons, an extra validation step is done
using
a third-party provider to make sure the customer's bank account can
accept
Direct Debit. If a bank account is discovered to be closed or invalid,
the
customer is requested to adjust the account number/routing number and
succeed in this check to continue with the flow.
_BACS scheme_ [Payer Name
Verification](https://hub.gocardless.com/s/article/Introduction-to-Payer-Name-Verification?language=en_GB)
is enabled by default for UK based bank accounts, meaning we verify the
account holder name and bank account
number match the details held by the relevant bank.
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/collect_bank_account', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)
def confirm_payer_details(self,identity,params=None, headers=None):
"""Confirm the payer details.
This is needed when you have a mandate request. As a scheme compliance
rule we are required to
allow the payer to crosscheck the details entered by them and confirm
it.
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/confirm_payer_details', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)
def fulfil(self,identity,params=None, headers=None):
"""Fulfil a Billing Request.
If a billing request is ready to be fulfilled, call this endpoint to
cause
it to fulfil, executing the payment.
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/fulfil', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)
def cancel(self,identity,params=None, headers=None):
"""Cancel a Billing Request.
Immediately cancels a billing request, causing all billing request
flows
to expire.
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/cancel', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)
def list(self,params=None, headers=None):
"""List Billing Requests.
Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
billing requests.
Args:
params (dict, optional): Query string parameters.
Returns:
ListResponse of BillingRequest instances
"""
path = '/billing_requests'
response = self._perform_request('GET', path, params, headers,
retry_failures=True)
return self._resource_for(response)
def all(self,params=None):
if params is None:
params = {}
return Paginator(self, params, identity_params={
})
def get(self,identity,params=None, headers=None):
"""Get a single Billing Request.
Fetches a billing request
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Query string parameters.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity', {
'identity': identity,
})
response = self._perform_request('GET', path, params, headers,
retry_failures=True)
return self._resource_for(response)
def notify(self,identity,params=None, headers=None):
"""Notify the customer.
Notifies the customer linked to the billing request, asking them to
authorise it.
Currently, the customer can only be notified by email.
This endpoint is currently supported only for Instant Bank Pay Billing
Requests.
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/notify', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)
def fallback(self,identity,params=None, headers=None):
"""Trigger fallback.
Triggers a fallback from the open-banking flow to direct debit. Note,
the billing request must have fallback enabled.
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/fallback', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)
def choose_currency(self,identity,params=None, headers=None):
"""Change currency.
This will allow for the updating of the currency and subsequently the
scheme if
needed for a Billing Request. This will only be available for mandate
only flows
which do not have the lock_currency flag set to true on the Billing
Request Flow. It
will also not support any request which has a payments request.
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/choose_currency', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)
def select_institution(self,identity,params=None, headers=None):
"""Select institution for a Billing Request.
Creates an Institution object and attaches it to the Billing Request
Args:
identity (string): Unique identifier, beginning with "BRQ".
params (dict, optional): Request body.
Returns:
BillingRequest
"""
path = self._sub_url_params('/billing_requests/:identity/actions/select_institution', {
'identity': identity,
})
if params is not None:
params = {self._envelope_key(): params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)