gocardless_pro 2.41.0 → 2.41.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gocardless_pro/api_service.rb +4 -5
  3. data/lib/gocardless_pro/client.rb +3 -3
  4. data/lib/gocardless_pro/error/invalid_state_error.rb +1 -0
  5. data/lib/gocardless_pro/error.rb +1 -0
  6. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +7 -9
  7. data/lib/gocardless_pro/request.rb +5 -7
  8. data/lib/gocardless_pro/resources/bank_authorisation.rb +0 -2
  9. data/lib/gocardless_pro/resources/bank_details_lookup.rb +0 -2
  10. data/lib/gocardless_pro/resources/billing_request.rb +0 -2
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +0 -2
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +0 -2
  13. data/lib/gocardless_pro/resources/block.rb +0 -2
  14. data/lib/gocardless_pro/resources/creditor.rb +0 -2
  15. data/lib/gocardless_pro/resources/creditor_bank_account.rb +0 -2
  16. data/lib/gocardless_pro/resources/currency_exchange_rate.rb +0 -2
  17. data/lib/gocardless_pro/resources/customer.rb +0 -2
  18. data/lib/gocardless_pro/resources/customer_bank_account.rb +0 -2
  19. data/lib/gocardless_pro/resources/customer_notification.rb +0 -2
  20. data/lib/gocardless_pro/resources/event.rb +0 -2
  21. data/lib/gocardless_pro/resources/instalment_schedule.rb +0 -2
  22. data/lib/gocardless_pro/resources/institution.rb +0 -2
  23. data/lib/gocardless_pro/resources/mandate.rb +0 -2
  24. data/lib/gocardless_pro/resources/mandate_import.rb +0 -2
  25. data/lib/gocardless_pro/resources/mandate_import_entry.rb +0 -2
  26. data/lib/gocardless_pro/resources/mandate_pdf.rb +0 -2
  27. data/lib/gocardless_pro/resources/payer_authorisation.rb +0 -2
  28. data/lib/gocardless_pro/resources/payment.rb +0 -2
  29. data/lib/gocardless_pro/resources/payout.rb +0 -2
  30. data/lib/gocardless_pro/resources/payout_item.rb +0 -2
  31. data/lib/gocardless_pro/resources/redirect_flow.rb +0 -2
  32. data/lib/gocardless_pro/resources/refund.rb +0 -2
  33. data/lib/gocardless_pro/resources/scenario_simulator.rb +0 -2
  34. data/lib/gocardless_pro/resources/scheme_identifier.rb +0 -2
  35. data/lib/gocardless_pro/resources/subscription.rb +0 -2
  36. data/lib/gocardless_pro/resources/tax_rate.rb +0 -2
  37. data/lib/gocardless_pro/resources/verification_detail.rb +0 -2
  38. data/lib/gocardless_pro/resources/webhook.rb +0 -2
  39. data/lib/gocardless_pro/services/bank_authorisations_service.rb +3 -1
  40. data/lib/gocardless_pro/services/billing_request_flows_service.rb +3 -1
  41. data/lib/gocardless_pro/services/billing_request_templates_service.rb +6 -2
  42. data/lib/gocardless_pro/services/billing_requests_service.rb +27 -9
  43. data/lib/gocardless_pro/services/blocks_service.rb +9 -3
  44. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +6 -2
  45. data/lib/gocardless_pro/services/creditors_service.rb +9 -3
  46. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +9 -3
  47. data/lib/gocardless_pro/services/customer_notifications_service.rb +3 -1
  48. data/lib/gocardless_pro/services/customers_service.rb +9 -3
  49. data/lib/gocardless_pro/services/events_service.rb +3 -1
  50. data/lib/gocardless_pro/services/instalment_schedules_service.rb +9 -3
  51. data/lib/gocardless_pro/services/mandate_imports_service.rb +9 -3
  52. data/lib/gocardless_pro/services/mandates_service.rb +12 -4
  53. data/lib/gocardless_pro/services/payer_authorisations_service.rb +12 -4
  54. data/lib/gocardless_pro/services/payments_service.rb +12 -4
  55. data/lib/gocardless_pro/services/payouts_service.rb +6 -2
  56. data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -2
  57. data/lib/gocardless_pro/services/refunds_service.rb +6 -2
  58. data/lib/gocardless_pro/services/scenario_simulators_service.rb +3 -1
  59. data/lib/gocardless_pro/services/scheme_identifiers_service.rb +3 -1
  60. data/lib/gocardless_pro/services/subscriptions_service.rb +15 -5
  61. data/lib/gocardless_pro/services/tax_rates_service.rb +3 -1
  62. data/lib/gocardless_pro/services/webhooks_service.rb +6 -2
  63. data/lib/gocardless_pro/version.rb +1 -2
  64. data/lib/gocardless_pro/webhook.rb +5 -4
  65. data/lib/gocardless_pro.rb +2 -4
  66. metadata +5 -195
  67. data/.github/workflows/tests.yml +0 -40
  68. data/.gitignore +0 -1
  69. data/.rspec +0 -2
  70. data/.rubocop.yml +0 -5
  71. data/.travis.yml +0 -10
  72. data/LICENSE.txt +0 -22
  73. data/demo.rb +0 -9
  74. data/gocardless_pro.gemspec +0 -39
  75. data/spec/api_response_spec.rb +0 -28
  76. data/spec/api_service_spec.rb +0 -188
  77. data/spec/client_spec.rb +0 -19
  78. data/spec/error_spec.rb +0 -53
  79. data/spec/middlewares/raise_gocardless_errors_spec.rb +0 -127
  80. data/spec/resources/bank_authorisation_spec.rb +0 -259
  81. data/spec/resources/bank_details_lookup_spec.rb +0 -121
  82. data/spec/resources/billing_request_flow_spec.rb +0 -257
  83. data/spec/resources/billing_request_spec.rb +0 -962
  84. data/spec/resources/billing_request_template_spec.rb +0 -515
  85. data/spec/resources/block_spec.rb +0 -577
  86. data/spec/resources/creditor_bank_account_spec.rb +0 -472
  87. data/spec/resources/creditor_spec.rb +0 -659
  88. data/spec/resources/currency_exchange_rate_spec.rb +0 -103
  89. data/spec/resources/customer_bank_account_spec.rb +0 -509
  90. data/spec/resources/customer_notification_spec.rb +0 -75
  91. data/spec/resources/customer_spec.rb +0 -616
  92. data/spec/resources/event_spec.rb +0 -210
  93. data/spec/resources/instalment_schedule_spec.rb +0 -636
  94. data/spec/resources/institution_spec.rb +0 -113
  95. data/spec/resources/mandate_import_entry_spec.rb +0 -206
  96. data/spec/resources/mandate_import_spec.rb +0 -344
  97. data/spec/resources/mandate_pdf_spec.rb +0 -117
  98. data/spec/resources/mandate_spec.rb +0 -600
  99. data/spec/resources/payer_authorisation_spec.rb +0 -422
  100. data/spec/resources/payment_spec.rb +0 -617
  101. data/spec/resources/payout_item_spec.rb +0 -101
  102. data/spec/resources/payout_spec.rb +0 -284
  103. data/spec/resources/redirect_flow_spec.rb +0 -347
  104. data/spec/resources/refund_spec.rb +0 -409
  105. data/spec/resources/scenario_simulator_spec.rb +0 -65
  106. data/spec/resources/scheme_identifier_spec.rb +0 -484
  107. data/spec/resources/subscription_spec.rb +0 -828
  108. data/spec/resources/tax_rate_spec.rb +0 -198
  109. data/spec/resources/verification_detail_spec.rb +0 -145
  110. data/spec/resources/webhook_spec.rb +0 -325
  111. data/spec/response_spec.rb +0 -34
  112. data/spec/services/bank_authorisations_service_spec.rb +0 -353
  113. data/spec/services/bank_details_lookups_service_spec.rb +0 -144
  114. data/spec/services/billing_request_flows_service_spec.rb +0 -291
  115. data/spec/services/billing_request_templates_service_spec.rb +0 -806
  116. data/spec/services/billing_requests_service_spec.rb +0 -1288
  117. data/spec/services/blocks_service_spec.rb +0 -840
  118. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -725
  119. data/spec/services/creditors_service_spec.rb +0 -977
  120. data/spec/services/currency_exchange_rates_service_spec.rb +0 -223
  121. data/spec/services/customer_bank_accounts_service_spec.rb +0 -787
  122. data/spec/services/customer_notifications_service_spec.rb +0 -86
  123. data/spec/services/customers_service_spec.rb +0 -922
  124. data/spec/services/events_service_spec.rb +0 -401
  125. data/spec/services/instalment_schedules_service_spec.rb +0 -945
  126. data/spec/services/institutions_service_spec.rb +0 -241
  127. data/spec/services/mandate_import_entries_service_spec.rb +0 -345
  128. data/spec/services/mandate_imports_service_spec.rb +0 -460
  129. data/spec/services/mandate_pdfs_service_spec.rb +0 -140
  130. data/spec/services/mandates_service_spec.rb +0 -893
  131. data/spec/services/payer_authorisations_service_spec.rb +0 -563
  132. data/spec/services/payments_service_spec.rb +0 -914
  133. data/spec/services/payout_items_service_spec.rb +0 -221
  134. data/spec/services/payouts_service_spec.rb +0 -520
  135. data/spec/services/redirect_flows_service_spec.rb +0 -452
  136. data/spec/services/refunds_service_spec.rb +0 -668
  137. data/spec/services/scenario_simulators_service_spec.rb +0 -76
  138. data/spec/services/scheme_identifiers_service_spec.rb +0 -754
  139. data/spec/services/subscriptions_service_spec.rb +0 -1164
  140. data/spec/services/tax_rates_service_spec.rb +0 -381
  141. data/spec/services/verification_details_service_spec.rb +0 -168
  142. data/spec/services/webhooks_service_spec.rb +0 -547
  143. data/spec/spec_helper.rb +0 -90
  144. data/spec/webhook_spec.rb +0 -122
@@ -1,787 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::CustomerBankAccountsService do
4
- let(:client) do
5
- GoCardlessPro::Client.new(
6
- access_token: 'SECRET_TOKEN'
7
- )
8
- end
9
-
10
- let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
-
12
- describe '#create' do
13
- subject(:post_create_response) { client.customer_bank_accounts.create(params: new_resource) }
14
- context 'with a valid request' do
15
- let(:new_resource) do
16
- {
17
-
18
- 'account_holder_name' => 'account_holder_name-input',
19
- 'account_number_ending' => 'account_number_ending-input',
20
- 'account_type' => 'account_type-input',
21
- 'bank_name' => 'bank_name-input',
22
- 'country_code' => 'country_code-input',
23
- 'created_at' => 'created_at-input',
24
- 'currency' => 'currency-input',
25
- 'enabled' => 'enabled-input',
26
- 'id' => 'id-input',
27
- 'links' => 'links-input',
28
- 'metadata' => 'metadata-input',
29
- }
30
- end
31
-
32
- before do
33
- stub_request(:post, %r{.*api.gocardless.com/customer_bank_accounts}).
34
- with(
35
- body: {
36
- 'customer_bank_accounts' => {
37
-
38
- 'account_holder_name' => 'account_holder_name-input',
39
- 'account_number_ending' => 'account_number_ending-input',
40
- 'account_type' => 'account_type-input',
41
- 'bank_name' => 'bank_name-input',
42
- 'country_code' => 'country_code-input',
43
- 'created_at' => 'created_at-input',
44
- 'currency' => 'currency-input',
45
- 'enabled' => 'enabled-input',
46
- 'id' => 'id-input',
47
- 'links' => 'links-input',
48
- 'metadata' => 'metadata-input',
49
- },
50
- }
51
- ).
52
- to_return(
53
- body: {
54
- 'customer_bank_accounts' =>
55
-
56
- {
57
-
58
- 'account_holder_name' => 'account_holder_name-input',
59
- 'account_number_ending' => 'account_number_ending-input',
60
- 'account_type' => 'account_type-input',
61
- 'bank_name' => 'bank_name-input',
62
- 'country_code' => 'country_code-input',
63
- 'created_at' => 'created_at-input',
64
- 'currency' => 'currency-input',
65
- 'enabled' => 'enabled-input',
66
- 'id' => 'id-input',
67
- 'links' => 'links-input',
68
- 'metadata' => 'metadata-input',
69
- },
70
-
71
- }.to_json,
72
- headers: response_headers
73
- )
74
- end
75
-
76
- it 'creates and returns the resource' do
77
- expect(post_create_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
78
- end
79
-
80
- describe 'retry behaviour' do
81
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
82
-
83
- it 'retries timeouts' do
84
- stub = stub_request(:post, %r{.*api.gocardless.com/customer_bank_accounts}).
85
- to_timeout.then.to_return(status: 200, headers: response_headers)
86
-
87
- post_create_response
88
- expect(stub).to have_been_requested.twice
89
- end
90
-
91
- it 'retries 5XX errors' do
92
- stub = stub_request(:post, %r{.*api.gocardless.com/customer_bank_accounts}).
93
- to_return(status: 502,
94
- headers: { 'Content-Type' => 'text/html' },
95
- body: '<html><body>Response from Cloudflare</body></html>').
96
- then.to_return(status: 200, headers: response_headers)
97
-
98
- post_create_response
99
- expect(stub).to have_been_requested.twice
100
- end
101
- end
102
- end
103
-
104
- context 'with a request that returns a validation error' do
105
- let(:new_resource) { {} }
106
-
107
- before do
108
- stub_request(:post, %r{.*api.gocardless.com/customer_bank_accounts}).to_return(
109
- body: {
110
- error: {
111
- type: 'validation_failed',
112
- code: 422,
113
- errors: [
114
- { message: 'test error message', field: 'test_field' },
115
- ],
116
- },
117
- }.to_json,
118
- headers: response_headers,
119
- status: 422
120
- )
121
- end
122
-
123
- it 'throws the correct error' do
124
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
125
- end
126
- end
127
-
128
- context 'with a request that returns an idempotent creation conflict error' do
129
- let(:id) { 'ID123' }
130
-
131
- let(:new_resource) do
132
- {
133
-
134
- 'account_holder_name' => 'account_holder_name-input',
135
- 'account_number_ending' => 'account_number_ending-input',
136
- 'account_type' => 'account_type-input',
137
- 'bank_name' => 'bank_name-input',
138
- 'country_code' => 'country_code-input',
139
- 'created_at' => 'created_at-input',
140
- 'currency' => 'currency-input',
141
- 'enabled' => 'enabled-input',
142
- 'id' => 'id-input',
143
- 'links' => 'links-input',
144
- 'metadata' => 'metadata-input',
145
- }
146
- end
147
-
148
- let!(:post_stub) do
149
- stub_request(:post, %r{.*api.gocardless.com/customer_bank_accounts}).to_return(
150
- body: {
151
- error: {
152
- type: 'invalid_state',
153
- code: 409,
154
- errors: [
155
- {
156
- message: 'A resource has already been created with this idempotency key',
157
- reason: 'idempotent_creation_conflict',
158
- links: {
159
- conflicting_resource_id: id,
160
- },
161
- },
162
- ],
163
- },
164
- }.to_json,
165
- headers: response_headers,
166
- status: 409
167
- )
168
- end
169
-
170
- let!(:get_stub) do
171
- stub_url = "/customer_bank_accounts/#{id}"
172
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
173
- to_return(
174
- body: {
175
- 'customer_bank_accounts' => {
176
-
177
- 'account_holder_name' => 'account_holder_name-input',
178
- 'account_number_ending' => 'account_number_ending-input',
179
- 'account_type' => 'account_type-input',
180
- 'bank_name' => 'bank_name-input',
181
- 'country_code' => 'country_code-input',
182
- 'created_at' => 'created_at-input',
183
- 'currency' => 'currency-input',
184
- 'enabled' => 'enabled-input',
185
- 'id' => 'id-input',
186
- 'links' => 'links-input',
187
- 'metadata' => 'metadata-input',
188
- },
189
- }.to_json,
190
- headers: response_headers
191
- )
192
- end
193
-
194
- context 'with default behaviour' do
195
- it 'fetches the already-created resource' do
196
- post_create_response
197
- expect(post_stub).to have_been_requested
198
- expect(get_stub).to have_been_requested
199
- end
200
- end
201
-
202
- context 'with on_idempotency_conflict: :raise' do
203
- let(:client) do
204
- GoCardlessPro::Client.new(
205
- access_token: 'SECRET_TOKEN',
206
- on_idempotency_conflict: :raise
207
- )
208
- end
209
-
210
- it 'raises an IdempotencyConflict error' do
211
- expect { post_create_response }.
212
- to raise_error(GoCardlessPro::IdempotencyConflict)
213
- end
214
- end
215
- end
216
- end
217
-
218
- describe '#list' do
219
- describe 'with no filters' do
220
- subject(:get_list_response) { client.customer_bank_accounts.list }
221
-
222
- let(:body) do
223
- {
224
- 'customer_bank_accounts' => [{
225
-
226
- 'account_holder_name' => 'account_holder_name-input',
227
- 'account_number_ending' => 'account_number_ending-input',
228
- 'account_type' => 'account_type-input',
229
- 'bank_name' => 'bank_name-input',
230
- 'country_code' => 'country_code-input',
231
- 'created_at' => 'created_at-input',
232
- 'currency' => 'currency-input',
233
- 'enabled' => 'enabled-input',
234
- 'id' => 'id-input',
235
- 'links' => 'links-input',
236
- 'metadata' => 'metadata-input',
237
- }],
238
- meta: {
239
- cursors: {
240
- before: nil,
241
- after: 'ABC123',
242
- },
243
- },
244
- }.to_json
245
- end
246
-
247
- before do
248
- stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts}).to_return(
249
- body: body,
250
- headers: response_headers
251
- )
252
- end
253
-
254
- it 'wraps each item in the resource class' do
255
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::CustomerBankAccount)
256
-
257
- expect(get_list_response.records.first.account_holder_name).to eq('account_holder_name-input')
258
-
259
- expect(get_list_response.records.first.account_number_ending).to eq('account_number_ending-input')
260
-
261
- expect(get_list_response.records.first.account_type).to eq('account_type-input')
262
-
263
- expect(get_list_response.records.first.bank_name).to eq('bank_name-input')
264
-
265
- expect(get_list_response.records.first.country_code).to eq('country_code-input')
266
-
267
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
268
-
269
- expect(get_list_response.records.first.currency).to eq('currency-input')
270
-
271
- expect(get_list_response.records.first.enabled).to eq('enabled-input')
272
-
273
- expect(get_list_response.records.first.id).to eq('id-input')
274
-
275
- expect(get_list_response.records.first.metadata).to eq('metadata-input')
276
- end
277
-
278
- it 'exposes the cursors for before and after' do
279
- expect(get_list_response.before).to eq(nil)
280
- expect(get_list_response.after).to eq('ABC123')
281
- end
282
-
283
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
284
-
285
- describe 'retry behaviour' do
286
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
287
-
288
- it 'retries timeouts' do
289
- stub = stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts}).
290
- to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
291
-
292
- get_list_response
293
- expect(stub).to have_been_requested.twice
294
- end
295
-
296
- it 'retries 5XX errors' do
297
- stub = stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts}).
298
- to_return(status: 502,
299
- headers: { 'Content-Type' => 'text/html' },
300
- body: '<html><body>Response from Cloudflare</body></html>').
301
- then.to_return(status: 200, headers: response_headers, body: body)
302
-
303
- get_list_response
304
- expect(stub).to have_been_requested.twice
305
- end
306
- end
307
- end
308
- end
309
-
310
- describe '#all' do
311
- let!(:first_response_stub) do
312
- stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts$}).to_return(
313
- body: {
314
- 'customer_bank_accounts' => [{
315
-
316
- 'account_holder_name' => 'account_holder_name-input',
317
- 'account_number_ending' => 'account_number_ending-input',
318
- 'account_type' => 'account_type-input',
319
- 'bank_name' => 'bank_name-input',
320
- 'country_code' => 'country_code-input',
321
- 'created_at' => 'created_at-input',
322
- 'currency' => 'currency-input',
323
- 'enabled' => 'enabled-input',
324
- 'id' => 'id-input',
325
- 'links' => 'links-input',
326
- 'metadata' => 'metadata-input',
327
- }],
328
- meta: {
329
- cursors: { after: 'AB345' },
330
- limit: 1,
331
- },
332
- }.to_json,
333
- headers: response_headers
334
- )
335
- end
336
-
337
- let!(:second_response_stub) do
338
- stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts\?after=AB345}).to_return(
339
- body: {
340
- 'customer_bank_accounts' => [{
341
-
342
- 'account_holder_name' => 'account_holder_name-input',
343
- 'account_number_ending' => 'account_number_ending-input',
344
- 'account_type' => 'account_type-input',
345
- 'bank_name' => 'bank_name-input',
346
- 'country_code' => 'country_code-input',
347
- 'created_at' => 'created_at-input',
348
- 'currency' => 'currency-input',
349
- 'enabled' => 'enabled-input',
350
- 'id' => 'id-input',
351
- 'links' => 'links-input',
352
- 'metadata' => 'metadata-input',
353
- }],
354
- meta: {
355
- limit: 2,
356
- cursors: {},
357
- },
358
- }.to_json,
359
- headers: response_headers
360
- )
361
- end
362
-
363
- it 'automatically makes the extra requests' do
364
- expect(client.customer_bank_accounts.all.to_a.length).to eq(2)
365
- expect(first_response_stub).to have_been_requested
366
- expect(second_response_stub).to have_been_requested
367
- end
368
-
369
- describe 'retry behaviour' do
370
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
371
-
372
- it 'retries timeouts' do
373
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts$}).to_return(
374
- body: {
375
- 'customer_bank_accounts' => [{
376
-
377
- 'account_holder_name' => 'account_holder_name-input',
378
- 'account_number_ending' => 'account_number_ending-input',
379
- 'account_type' => 'account_type-input',
380
- 'bank_name' => 'bank_name-input',
381
- 'country_code' => 'country_code-input',
382
- 'created_at' => 'created_at-input',
383
- 'currency' => 'currency-input',
384
- 'enabled' => 'enabled-input',
385
- 'id' => 'id-input',
386
- 'links' => 'links-input',
387
- 'metadata' => 'metadata-input',
388
- }],
389
- meta: {
390
- cursors: { after: 'AB345' },
391
- limit: 1,
392
- },
393
- }.to_json,
394
- headers: response_headers
395
- )
396
-
397
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts\?after=AB345}).
398
- to_timeout.then.
399
- to_return(
400
- body: {
401
- 'customer_bank_accounts' => [{
402
-
403
- 'account_holder_name' => 'account_holder_name-input',
404
- 'account_number_ending' => 'account_number_ending-input',
405
- 'account_type' => 'account_type-input',
406
- 'bank_name' => 'bank_name-input',
407
- 'country_code' => 'country_code-input',
408
- 'created_at' => 'created_at-input',
409
- 'currency' => 'currency-input',
410
- 'enabled' => 'enabled-input',
411
- 'id' => 'id-input',
412
- 'links' => 'links-input',
413
- 'metadata' => 'metadata-input',
414
- }],
415
- meta: {
416
- limit: 2,
417
- cursors: {},
418
- },
419
- }.to_json,
420
- headers: response_headers
421
- )
422
-
423
- client.customer_bank_accounts.all.to_a
424
-
425
- expect(first_response_stub).to have_been_requested
426
- expect(second_response_stub).to have_been_requested.twice
427
- end
428
-
429
- it 'retries 5XX errors' do
430
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts$}).to_return(
431
- body: {
432
- 'customer_bank_accounts' => [{
433
-
434
- 'account_holder_name' => 'account_holder_name-input',
435
- 'account_number_ending' => 'account_number_ending-input',
436
- 'account_type' => 'account_type-input',
437
- 'bank_name' => 'bank_name-input',
438
- 'country_code' => 'country_code-input',
439
- 'created_at' => 'created_at-input',
440
- 'currency' => 'currency-input',
441
- 'enabled' => 'enabled-input',
442
- 'id' => 'id-input',
443
- 'links' => 'links-input',
444
- 'metadata' => 'metadata-input',
445
- }],
446
- meta: {
447
- cursors: { after: 'AB345' },
448
- limit: 1,
449
- },
450
- }.to_json,
451
- headers: response_headers
452
- )
453
-
454
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/customer_bank_accounts\?after=AB345}).
455
- to_return(
456
- status: 502,
457
- body: '<html><body>Response from Cloudflare</body></html>',
458
- headers: { 'Content-Type' => 'text/html' }
459
- ).then.to_return(
460
- body: {
461
- 'customer_bank_accounts' => [{
462
-
463
- 'account_holder_name' => 'account_holder_name-input',
464
- 'account_number_ending' => 'account_number_ending-input',
465
- 'account_type' => 'account_type-input',
466
- 'bank_name' => 'bank_name-input',
467
- 'country_code' => 'country_code-input',
468
- 'created_at' => 'created_at-input',
469
- 'currency' => 'currency-input',
470
- 'enabled' => 'enabled-input',
471
- 'id' => 'id-input',
472
- 'links' => 'links-input',
473
- 'metadata' => 'metadata-input',
474
- }],
475
- meta: {
476
- limit: 2,
477
- cursors: {},
478
- },
479
- }.to_json,
480
- headers: response_headers
481
- )
482
-
483
- client.customer_bank_accounts.all.to_a
484
-
485
- expect(first_response_stub).to have_been_requested
486
- expect(second_response_stub).to have_been_requested.twice
487
- end
488
- end
489
- end
490
-
491
- describe '#get' do
492
- let(:id) { 'ID123' }
493
-
494
- subject(:get_response) { client.customer_bank_accounts.get(id) }
495
-
496
- context 'passing in a custom header' do
497
- let!(:stub) do
498
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
499
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
500
- with(headers: { 'Foo' => 'Bar' }).
501
- to_return(
502
- body: {
503
- 'customer_bank_accounts' => {
504
-
505
- 'account_holder_name' => 'account_holder_name-input',
506
- 'account_number_ending' => 'account_number_ending-input',
507
- 'account_type' => 'account_type-input',
508
- 'bank_name' => 'bank_name-input',
509
- 'country_code' => 'country_code-input',
510
- 'created_at' => 'created_at-input',
511
- 'currency' => 'currency-input',
512
- 'enabled' => 'enabled-input',
513
- 'id' => 'id-input',
514
- 'links' => 'links-input',
515
- 'metadata' => 'metadata-input',
516
- },
517
- }.to_json,
518
- headers: response_headers
519
- )
520
- end
521
-
522
- subject(:get_response) do
523
- client.customer_bank_accounts.get(id, headers: {
524
- 'Foo' => 'Bar',
525
- })
526
- end
527
-
528
- it 'includes the header' do
529
- get_response
530
- expect(stub).to have_been_requested
531
- end
532
- end
533
-
534
- context 'when there is a customer_bank_account to return' do
535
- before do
536
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
537
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
538
- body: {
539
- 'customer_bank_accounts' => {
540
-
541
- 'account_holder_name' => 'account_holder_name-input',
542
- 'account_number_ending' => 'account_number_ending-input',
543
- 'account_type' => 'account_type-input',
544
- 'bank_name' => 'bank_name-input',
545
- 'country_code' => 'country_code-input',
546
- 'created_at' => 'created_at-input',
547
- 'currency' => 'currency-input',
548
- 'enabled' => 'enabled-input',
549
- 'id' => 'id-input',
550
- 'links' => 'links-input',
551
- 'metadata' => 'metadata-input',
552
- },
553
- }.to_json,
554
- headers: response_headers
555
- )
556
- end
557
-
558
- it 'wraps the response in a resource' do
559
- expect(get_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
560
- end
561
- end
562
-
563
- context 'when nothing is returned' do
564
- before do
565
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
566
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
567
- body: '',
568
- headers: response_headers
569
- )
570
- end
571
-
572
- it 'returns nil' do
573
- expect(get_response).to be_nil
574
- end
575
- end
576
-
577
- context "when an ID is specified which can't be included in a valid URI" do
578
- let(:id) { '`' }
579
-
580
- it "doesn't raise an error" do
581
- expect { get_response }.to_not raise_error(/bad URI/)
582
- end
583
- end
584
-
585
- describe 'retry behaviour' do
586
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
587
-
588
- it 'retries timeouts' do
589
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
590
-
591
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
592
- to_timeout.then.to_return(status: 200, headers: response_headers)
593
-
594
- get_response
595
- expect(stub).to have_been_requested.twice
596
- end
597
-
598
- it 'retries 5XX errors, other than 500s' do
599
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
600
-
601
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
602
- to_return(status: 502,
603
- headers: { 'Content-Type' => 'text/html' },
604
- body: '<html><body>Response from Cloudflare</body></html>').
605
- then.to_return(status: 200, headers: response_headers)
606
-
607
- get_response
608
- expect(stub).to have_been_requested.twice
609
- end
610
-
611
- it 'retries 500 errors returned by the API' do
612
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
613
-
614
- gocardless_error = {
615
- 'error' => {
616
- 'message' => 'Internal server error',
617
- 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
618
- 'errors' => [{
619
- 'message' => 'Internal server error',
620
- 'reason' => 'internal_server_error',
621
- }],
622
- 'type' => 'gocardless',
623
- 'code' => 500,
624
- 'request_id' => 'dummy_request_id',
625
- 'id' => 'dummy_exception_id',
626
- },
627
- }
628
-
629
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
630
- to_return(status: 500,
631
- headers: response_headers,
632
- body: gocardless_error.to_json).
633
- then.to_return(status: 200, headers: response_headers)
634
-
635
- get_response
636
- expect(stub).to have_been_requested.twice
637
- end
638
- end
639
- end
640
-
641
- describe '#update' do
642
- subject(:put_update_response) { client.customer_bank_accounts.update(id, params: update_params) }
643
- let(:id) { 'ABC123' }
644
-
645
- context 'with a valid request' do
646
- let(:update_params) { { 'hello' => 'world' } }
647
-
648
- let!(:stub) do
649
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
650
- stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
651
- body: {
652
- 'customer_bank_accounts' => {
653
-
654
- 'account_holder_name' => 'account_holder_name-input',
655
- 'account_number_ending' => 'account_number_ending-input',
656
- 'account_type' => 'account_type-input',
657
- 'bank_name' => 'bank_name-input',
658
- 'country_code' => 'country_code-input',
659
- 'created_at' => 'created_at-input',
660
- 'currency' => 'currency-input',
661
- 'enabled' => 'enabled-input',
662
- 'id' => 'id-input',
663
- 'links' => 'links-input',
664
- 'metadata' => 'metadata-input',
665
- },
666
- }.to_json,
667
- headers: response_headers
668
- )
669
- end
670
-
671
- it 'updates and returns the resource' do
672
- expect(put_update_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
673
- expect(stub).to have_been_requested
674
- end
675
-
676
- describe 'retry behaviour' do
677
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
678
-
679
- it 'retries timeouts' do
680
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
681
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
682
- to_timeout.then.to_return(status: 200, headers: response_headers)
683
-
684
- put_update_response
685
- expect(stub).to have_been_requested.twice
686
- end
687
-
688
- it 'retries 5XX errors' do
689
- stub_url = '/customer_bank_accounts/:identity'.gsub(':identity', id)
690
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
691
- to_return(status: 502,
692
- headers: { 'Content-Type' => 'text/html' },
693
- body: '<html><body>Response from Cloudflare</body></html>').
694
- then.to_return(status: 200, headers: response_headers)
695
-
696
- put_update_response
697
- expect(stub).to have_been_requested.twice
698
- end
699
- end
700
- end
701
- end
702
-
703
- describe '#disable' do
704
- subject(:post_response) { client.customer_bank_accounts.disable(resource_id) }
705
-
706
- let(:resource_id) { 'ABC123' }
707
-
708
- let!(:stub) do
709
- # /customer_bank_accounts/%v/actions/disable
710
- stub_url = '/customer_bank_accounts/:identity/actions/disable'.gsub(':identity', resource_id)
711
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
712
-
713
- body: {
714
- 'customer_bank_accounts' => {
715
-
716
- 'account_holder_name' => 'account_holder_name-input',
717
- 'account_number_ending' => 'account_number_ending-input',
718
- 'account_type' => 'account_type-input',
719
- 'bank_name' => 'bank_name-input',
720
- 'country_code' => 'country_code-input',
721
- 'created_at' => 'created_at-input',
722
- 'currency' => 'currency-input',
723
- 'enabled' => 'enabled-input',
724
- 'id' => 'id-input',
725
- 'links' => 'links-input',
726
- 'metadata' => 'metadata-input',
727
- },
728
- }.to_json,
729
-
730
- headers: response_headers
731
- )
732
- end
733
-
734
- it 'wraps the response and calls the right endpoint' do
735
- expect(post_response).to be_a(GoCardlessPro::Resources::CustomerBankAccount)
736
-
737
- expect(stub).to have_been_requested
738
- end
739
-
740
- describe 'retry behaviour' do
741
- it "doesn't retry errors" do
742
- stub_url = '/customer_bank_accounts/:identity/actions/disable'.gsub(':identity', resource_id)
743
- stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
744
- to_timeout
745
-
746
- expect { post_response }.to raise_error(Faraday::ConnectionFailed)
747
- expect(stub).to have_been_requested
748
- end
749
- end
750
-
751
- context 'when the request needs a body and custom header' do
752
- let(:body) { { foo: 'bar' } }
753
- let(:headers) { { 'Foo' => 'Bar' } }
754
- subject(:post_response) { client.customer_bank_accounts.disable(resource_id, body, headers) }
755
-
756
- let(:resource_id) { 'ABC123' }
757
-
758
- let!(:stub) do
759
- # /customer_bank_accounts/%v/actions/disable
760
- stub_url = '/customer_bank_accounts/:identity/actions/disable'.gsub(':identity', resource_id)
761
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
762
- with(
763
- body: { foo: 'bar' },
764
- headers: { 'Foo' => 'Bar' }
765
- ).to_return(
766
- body: {
767
- 'customer_bank_accounts' => {
768
-
769
- 'account_holder_name' => 'account_holder_name-input',
770
- 'account_number_ending' => 'account_number_ending-input',
771
- 'account_type' => 'account_type-input',
772
- 'bank_name' => 'bank_name-input',
773
- 'country_code' => 'country_code-input',
774
- 'created_at' => 'created_at-input',
775
- 'currency' => 'currency-input',
776
- 'enabled' => 'enabled-input',
777
- 'id' => 'id-input',
778
- 'links' => 'links-input',
779
- 'metadata' => 'metadata-input',
780
- },
781
- }.to_json,
782
- headers: response_headers
783
- )
784
- end
785
- end
786
- end
787
- end