Skip to content

Commit 8bde2b9

Browse files
authored
Merge pull request #135 from gocardless/template-changes
Changes from gocardless/client-library-templates
2 parents 84dd5a5 + fab5e37 commit 8bde2b9

10 files changed

Lines changed: 84 additions & 13 deletions

File tree

gocardless_pro/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
from .client import Client
44

5-
__version__ = '3.4.1'
5+
__version__ = '3.5.0'
66

gocardless_pro/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def _default_headers(self):
172172
'Authorization': 'Bearer {0}'.format(self.access_token),
173173
'Content-Type': 'application/json',
174174
'GoCardless-Client-Library': 'gocardless-pro-python',
175-
'GoCardless-Client-Version': '3.4.1',
175+
'GoCardless-Client-Version': '3.5.0',
176176
'User-Agent': self._user_agent(),
177177
'GoCardless-Version': '2015-07-06',
178178
}
@@ -181,7 +181,7 @@ def _user_agent(self):
181181
python_version = '.'.join(platform.python_version_tuple()[0:2])
182182
vm_version = '{}.{}.{}-{}{}'.format(*sys.version_info)
183183
return ' '.join([
184-
'gocardless-pro-python/3.4.1',
184+
'gocardless-pro-python/3.5.0',
185185
'python/{0}'.format(python_version),
186186
'{0}/{1}'.format(platform.python_implementation(), vm_version),
187187
'{0}/{1}'.format(platform.system(), platform.release()),

gocardless_pro/resources/mandate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def links(self):
5151
return self.Links(self.attributes.get('links'))
5252

5353

54+
@property
55+
def mandate_type(self):
56+
return self.attributes.get('mandate_type')
57+
58+
5459
@property
5560
def metadata(self):
5661
return self.attributes.get('metadata')
@@ -175,4 +180,6 @@ def new_mandate(self):
175180

176181

177182

183+
184+
178185

gocardless_pro/services/base_service.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ def _resource_for(self, response):
6666
api_response = ApiResponse(response)
6767

6868
body = api_response.body
69-
data = body.get(self._envelope_key()) or body.get("data") or body
69+
envelope_key = self._envelope_key()
70+
if envelope_key in body:
71+
data = body[envelope_key]
72+
elif "data" in body:
73+
data = body["data"]
74+
else:
75+
data = body
7076
klass = type(self).RESOURCE_CLASS
7177
if isinstance(data, dict):
7278
return klass(data, api_response)

gocardless_pro/services/billing_requests_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def notify(self,identity,params=None, headers=None):
268268
authorise it.
269269
Currently, the customer can only be notified by email.
270270
271-
This endpoint is currently supported only for Instant Bank Pay Billing
271+
This endpoint is currently supported only for Pay by Bank Billing
272272
Requests.
273273
274274
Args:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name = 'gocardless_pro',
9-
version = '3.4.1',
9+
version = '3.5.0',
1010
packages = find_packages(exclude=['tests']),
1111
install_requires = ['requests>=2.6'],
1212
python_requires = '>=3.6',

tests/code_samples/billing_requests_code_samples_test.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,60 @@ def test_billing_requests_notify_code_sample():
301301

302302

303303

304+
@responses.activate
305+
def test_billing_requests_fallback_code_sample():
306+
# Convert :param placeholders to regex wildcards for flexible matching
307+
stub_url = '/billing_requests/:identity/actions/fallback'
308+
url_pattern = re.compile('https://api.gocardless.com' + re.sub(r':[\w]+', r'[^/]+', stub_url))
309+
# Mock response - repeat multiple times to handle code samples with multiple API calls
310+
response_body = { 'billing_requests': {} }
311+
for _ in range(5):
312+
responses.add(
313+
'POST',
314+
url_pattern,
315+
json=response_body,
316+
status=200
317+
)
318+
319+
client = gocardless_pro.Client(access_token='SECRET_TOKEN', environment='live')
320+
321+
# Suppress stdout from code samples that use print
322+
old_stdout = sys.stdout
323+
sys.stdout = StringIO()
324+
try:
325+
client.billing_requests.fallback("BR123")
326+
finally:
327+
sys.stdout = old_stdout
328+
329+
304330

305331

332+
@responses.activate
333+
def test_billing_requests_choose_currency_code_sample():
334+
# Convert :param placeholders to regex wildcards for flexible matching
335+
stub_url = '/billing_requests/:identity/actions/choose_currency'
336+
url_pattern = re.compile('https://api.gocardless.com' + re.sub(r':[\w]+', r'[^/]+', stub_url))
337+
# Mock response - repeat multiple times to handle code samples with multiple API calls
338+
response_body = { 'billing_requests': {} }
339+
for _ in range(5):
340+
responses.add(
341+
'POST',
342+
url_pattern,
343+
json=response_body,
344+
status=200
345+
)
346+
347+
client = gocardless_pro.Client(access_token='SECRET_TOKEN', environment='live')
348+
349+
# Suppress stdout from code samples that use print
350+
old_stdout = sys.stdout
351+
sys.stdout = StringIO()
352+
try:
353+
client.billing_requests.choose_currency("BR123", params={
354+
"currency": "GBP"
355+
})
356+
finally:
357+
sys.stdout = old_stdout
306358

307359

308360

tests/fixtures/events.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/fixtures/mandates.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
"method": "POST",
66
"path_template": "/mandates",
77
"url_params": [],
8-
"body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 101","max_amount_per_payment":101,"max_amount_per_period":101,"max_payments_per_period":101,"period":"week","start_date":"example start_date 101"},"consent_type":"example consent_type 101","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
8+
"body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 101","max_amount_per_payment":101,"max_amount_per_period":101,"max_payments_per_period":101,"period":"week","start_date":"example start_date 101"},"consent_type":"example consent_type 101","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"mandate_type":"bank_debit","metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
99
},
1010
"list": {
1111
"method": "GET",
1212
"path_template": "/mandates",
1313
"url_params": [],
14-
"body": {"mandates":[{"authorisation_source":"paper","consent_parameters":{"end_date":"example end_date 102","max_amount_per_payment":102,"max_amount_per_period":102,"max_payments_per_period":102,"period":"month","start_date":"example start_date 102"},"consent_type":"example consent_type 102","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"},{"authorisation_source":"web","consent_parameters":{"end_date":"example end_date 103","max_amount_per_payment":103,"max_amount_per_period":103,"max_payments_per_period":103,"period":"year","start_date":"example start_date 103"},"consent_type":"example consent_type 103","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 101","before":"example before 101"},"limit":50}}
14+
"body": {"mandates":[{"authorisation_source":"paper","consent_parameters":{"end_date":"example end_date 102","max_amount_per_payment":102,"max_amount_per_period":102,"max_payments_per_period":102,"period":"month","start_date":"example start_date 102"},"consent_type":"example consent_type 102","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"mandate_type":"bank_debit","metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"},{"authorisation_source":"web","consent_parameters":{"end_date":"example end_date 103","max_amount_per_payment":103,"max_amount_per_period":103,"max_payments_per_period":103,"period":"year","start_date":"example start_date 103"},"consent_type":"example consent_type 103","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"mandate_type":"bank_debit","metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 101","before":"example before 101"},"limit":50}}
1515
},
1616
"get": {
1717
"method": "GET",
1818
"path_template": "/mandates/:identity",
1919
"url_params": ["MD123"],
20-
"body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 104","max_amount_per_payment":104,"max_amount_per_period":104,"max_payments_per_period":104,"period":"flexible","start_date":"example start_date 104"},"consent_type":"example consent_type 104","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
20+
"body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 104","max_amount_per_payment":104,"max_amount_per_period":104,"max_payments_per_period":104,"period":"flexible","start_date":"example start_date 104"},"consent_type":"example consent_type 104","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"mandate_type":"bank_debit","metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
2121
},
2222
"update": {
2323
"method": "PUT",
2424
"path_template": "/mandates/:identity",
2525
"url_params": ["MD123"],
26-
"body": {"mandates":{"authorisation_source":"paper","consent_parameters":{"end_date":"example end_date 105","max_amount_per_payment":105,"max_amount_per_period":105,"max_payments_per_period":105,"period":"day","start_date":"example start_date 105"},"consent_type":"example consent_type 105","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
26+
"body": {"mandates":{"authorisation_source":"paper","consent_parameters":{"end_date":"example end_date 105","max_amount_per_payment":105,"max_amount_per_period":105,"max_payments_per_period":105,"period":"day","start_date":"example start_date 105"},"consent_type":"example consent_type 105","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"mandate_type":"bank_debit","metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
2727
},
2828
"cancel": {
2929
"method": "POST",
3030
"path_template": "/mandates/:identity/actions/cancel",
3131
"url_params": ["MD123"],
32-
"body": {"mandates":{"authorisation_source":"web","consent_parameters":{"end_date":"example end_date 106","max_amount_per_payment":106,"max_amount_per_period":106,"max_payments_per_period":106,"period":"week","start_date":"example start_date 106"},"consent_type":"example consent_type 106","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
32+
"body": {"mandates":{"authorisation_source":"web","consent_parameters":{"end_date":"example end_date 106","max_amount_per_payment":106,"max_amount_per_period":106,"max_payments_per_period":106,"period":"week","start_date":"example start_date 106"},"consent_type":"example consent_type 106","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"mandate_type":"bank_debit","metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
3333
},
3434
"reinstate": {
3535
"method": "POST",
3636
"path_template": "/mandates/:identity/actions/reinstate",
3737
"url_params": ["MD123"],
38-
"body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 107","max_amount_per_payment":107,"max_amount_per_period":107,"max_payments_per_period":107,"period":"month","start_date":"example start_date 107"},"consent_type":"example consent_type 107","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
38+
"body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 107","max_amount_per_payment":107,"max_amount_per_period":107,"max_payments_per_period":107,"period":"month","start_date":"example start_date 107"},"consent_type":"example consent_type 107","created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"mandate_type":"bank_debit","metadata":{},"next_possible_charge_date":"2014-10-27","next_possible_standard_ach_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}}
3939
}
4040
}

tests/integration/mandates_integration_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_mandates_create():
3232
assert response.created_at == body.get('created_at')
3333
assert response.funds_settlement == body.get('funds_settlement')
3434
assert response.id == body.get('id')
35+
assert response.mandate_type == body.get('mandate_type')
3536
assert response.metadata == body.get('metadata')
3637
assert response.next_possible_charge_date == body.get('next_possible_charge_date')
3738
assert response.next_possible_standard_ach_charge_date == body.get('next_possible_standard_ach_charge_date')
@@ -108,6 +109,7 @@ def test_mandates_list():
108109
assert [r.created_at for r in response.records] == [b.get('created_at') for b in body]
109110
assert [r.funds_settlement for r in response.records] == [b.get('funds_settlement') for b in body]
110111
assert [r.id for r in response.records] == [b.get('id') for b in body]
112+
assert [r.mandate_type for r in response.records] == [b.get('mandate_type') for b in body]
111113
assert [r.metadata for r in response.records] == [b.get('metadata') for b in body]
112114
assert [r.next_possible_charge_date for r in response.records] == [b.get('next_possible_charge_date') for b in body]
113115
assert [r.next_possible_standard_ach_charge_date for r in response.records] == [b.get('next_possible_standard_ach_charge_date') for b in body]
@@ -180,6 +182,7 @@ def test_mandates_get():
180182
assert response.created_at == body.get('created_at')
181183
assert response.funds_settlement == body.get('funds_settlement')
182184
assert response.id == body.get('id')
185+
assert response.mandate_type == body.get('mandate_type')
183186
assert response.metadata == body.get('metadata')
184187
assert response.next_possible_charge_date == body.get('next_possible_charge_date')
185188
assert response.next_possible_standard_ach_charge_date == body.get('next_possible_standard_ach_charge_date')
@@ -235,6 +238,7 @@ def test_mandates_update():
235238
assert response.created_at == body.get('created_at')
236239
assert response.funds_settlement == body.get('funds_settlement')
237240
assert response.id == body.get('id')
241+
assert response.mandate_type == body.get('mandate_type')
238242
assert response.metadata == body.get('metadata')
239243
assert response.next_possible_charge_date == body.get('next_possible_charge_date')
240244
assert response.next_possible_standard_ach_charge_date == body.get('next_possible_standard_ach_charge_date')
@@ -290,6 +294,7 @@ def test_mandates_cancel():
290294
assert response.created_at == body.get('created_at')
291295
assert response.funds_settlement == body.get('funds_settlement')
292296
assert response.id == body.get('id')
297+
assert response.mandate_type == body.get('mandate_type')
293298
assert response.metadata == body.get('metadata')
294299
assert response.next_possible_charge_date == body.get('next_possible_charge_date')
295300
assert response.next_possible_standard_ach_charge_date == body.get('next_possible_standard_ach_charge_date')
@@ -340,6 +345,7 @@ def test_mandates_reinstate():
340345
assert response.created_at == body.get('created_at')
341346
assert response.funds_settlement == body.get('funds_settlement')
342347
assert response.id == body.get('id')
348+
assert response.mandate_type == body.get('mandate_type')
343349
assert response.metadata == body.get('metadata')
344350
assert response.next_possible_charge_date == body.get('next_possible_charge_date')
345351
assert response.next_possible_standard_ach_charge_date == body.get('next_possible_standard_ach_charge_date')

0 commit comments

Comments
 (0)