|
1
|
|
|
from besepa import util |
|
|
|
|
|
|
2
|
|
|
from besepa.resource import Create, Delete, Find, List, Post, Resource, Update |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class Customer(List, Find, Create, Delete, Update, Post): |
|
|
|
|
|
|
6
|
|
|
"""Customer class wrapping the REST api/1/customers endpoint |
|
7
|
|
|
|
|
8
|
|
|
Usage:: |
|
9
|
|
|
|
|
10
|
|
|
>>> customers = Customer.all() |
|
11
|
|
|
|
|
12
|
|
|
>>> customer = Customer.new({}) |
|
13
|
|
|
>>> customer.create() # return True or False |
|
14
|
|
|
""" |
|
15
|
|
|
path = "api/1/customers" |
|
16
|
|
|
|
|
17
|
|
|
def create_bank_account(self, attributes): |
|
|
|
|
|
|
18
|
|
|
# /customers/<CUSTOMER-ID>/bank_accounts |
|
19
|
|
|
return self.post('bank_accounts', attributes) |
|
20
|
|
|
|
|
21
|
|
|
def list_bank_accounts(self): |
|
|
|
|
|
|
22
|
|
|
# /customers/<CUSTOMER-ID>/bank_accounts |
|
23
|
|
|
endpoint = util.join_url(self.path, str(self['id']), 'bank_accounts') |
|
24
|
|
|
response = self.api.get(endpoint) |
|
25
|
|
|
try: |
|
26
|
|
|
return Resource(response, api=self.api) |
|
27
|
|
|
except AttributeError: |
|
28
|
|
|
# To handle the case when response is JSON Array |
|
29
|
|
|
if isinstance(response, list): |
|
30
|
|
|
new_resp = [Resource(elem, api=self.api) for elem in response] |
|
31
|
|
|
return new_resp |
|
32
|
|
|
|
|
33
|
|
|
def create_debit(self, attributes): |
|
|
|
|
|
|
34
|
|
|
# /customers/invoices/<CUSTOMER-ID>/debits |
|
35
|
|
|
return self.post('debits', attributes) |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
Customer.convert_resources['bank_accounts'] = Resource |
|
39
|
|
|
Customer.convert_resources['bank_account'] = Resource |
|
40
|
|
|
Customer.convert_resources['mandate'] = Resource |
|
41
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.