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,945 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::InstalmentSchedulesService 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.instalment_schedules.create_with_dates(params: new_resource) }
14
- context 'with a valid request' do
15
- let(:new_resource) do
16
- {
17
-
18
- 'created_at' => 'created_at-input',
19
- 'currency' => 'currency-input',
20
- 'id' => 'id-input',
21
- 'links' => 'links-input',
22
- 'metadata' => 'metadata-input',
23
- 'name' => 'name-input',
24
- 'payment_errors' => 'payment_errors-input',
25
- 'status' => 'status-input',
26
- 'total_amount' => 'total_amount-input',
27
- }
28
- end
29
-
30
- before do
31
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).
32
- with(
33
- body: {
34
- 'instalment_schedules' => {
35
-
36
- 'created_at' => 'created_at-input',
37
- 'currency' => 'currency-input',
38
- 'id' => 'id-input',
39
- 'links' => 'links-input',
40
- 'metadata' => 'metadata-input',
41
- 'name' => 'name-input',
42
- 'payment_errors' => 'payment_errors-input',
43
- 'status' => 'status-input',
44
- 'total_amount' => 'total_amount-input',
45
- },
46
- }
47
- ).
48
- to_return(
49
- body: {
50
- 'instalment_schedules' =>
51
-
52
- {
53
-
54
- 'created_at' => 'created_at-input',
55
- 'currency' => 'currency-input',
56
- 'id' => 'id-input',
57
- 'links' => 'links-input',
58
- 'metadata' => 'metadata-input',
59
- 'name' => 'name-input',
60
- 'payment_errors' => 'payment_errors-input',
61
- 'status' => 'status-input',
62
- 'total_amount' => 'total_amount-input',
63
- },
64
-
65
- }.to_json,
66
- headers: response_headers
67
- )
68
- end
69
-
70
- it 'creates and returns the resource' do
71
- expect(post_create_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
72
- end
73
-
74
- describe 'retry behaviour' do
75
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
76
-
77
- it 'retries timeouts' do
78
- stub = stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).
79
- to_timeout.then.to_return(status: 200, headers: response_headers)
80
-
81
- post_create_response
82
- expect(stub).to have_been_requested.twice
83
- end
84
-
85
- it 'retries 5XX errors' do
86
- stub = stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).
87
- to_return(status: 502,
88
- headers: { 'Content-Type' => 'text/html' },
89
- body: '<html><body>Response from Cloudflare</body></html>').
90
- then.to_return(status: 200, headers: response_headers)
91
-
92
- post_create_response
93
- expect(stub).to have_been_requested.twice
94
- end
95
- end
96
- end
97
-
98
- context 'with a request that returns a validation error' do
99
- let(:new_resource) { {} }
100
-
101
- before do
102
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).to_return(
103
- body: {
104
- error: {
105
- type: 'validation_failed',
106
- code: 422,
107
- errors: [
108
- { message: 'test error message', field: 'test_field' },
109
- ],
110
- },
111
- }.to_json,
112
- headers: response_headers,
113
- status: 422
114
- )
115
- end
116
-
117
- it 'throws the correct error' do
118
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
119
- end
120
- end
121
-
122
- context 'with a request that returns an idempotent creation conflict error' do
123
- let(:id) { 'ID123' }
124
-
125
- let(:new_resource) do
126
- {
127
-
128
- 'created_at' => 'created_at-input',
129
- 'currency' => 'currency-input',
130
- 'id' => 'id-input',
131
- 'links' => 'links-input',
132
- 'metadata' => 'metadata-input',
133
- 'name' => 'name-input',
134
- 'payment_errors' => 'payment_errors-input',
135
- 'status' => 'status-input',
136
- 'total_amount' => 'total_amount-input',
137
- }
138
- end
139
-
140
- let!(:post_stub) do
141
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).to_return(
142
- body: {
143
- error: {
144
- type: 'invalid_state',
145
- code: 409,
146
- errors: [
147
- {
148
- message: 'A resource has already been created with this idempotency key',
149
- reason: 'idempotent_creation_conflict',
150
- links: {
151
- conflicting_resource_id: id,
152
- },
153
- },
154
- ],
155
- },
156
- }.to_json,
157
- headers: response_headers,
158
- status: 409
159
- )
160
- end
161
-
162
- let!(:get_stub) do
163
- stub_url = "/instalment_schedules/#{id}"
164
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
165
- to_return(
166
- body: {
167
- 'instalment_schedules' => {
168
-
169
- 'created_at' => 'created_at-input',
170
- 'currency' => 'currency-input',
171
- 'id' => 'id-input',
172
- 'links' => 'links-input',
173
- 'metadata' => 'metadata-input',
174
- 'name' => 'name-input',
175
- 'payment_errors' => 'payment_errors-input',
176
- 'status' => 'status-input',
177
- 'total_amount' => 'total_amount-input',
178
- },
179
- }.to_json,
180
- headers: response_headers
181
- )
182
- end
183
-
184
- context 'with default behaviour' do
185
- it 'fetches the already-created resource' do
186
- post_create_response
187
- expect(post_stub).to have_been_requested
188
- expect(get_stub).to have_been_requested
189
- end
190
- end
191
-
192
- context 'with on_idempotency_conflict: :raise' do
193
- let(:client) do
194
- GoCardlessPro::Client.new(
195
- access_token: 'SECRET_TOKEN',
196
- on_idempotency_conflict: :raise
197
- )
198
- end
199
-
200
- it 'raises an IdempotencyConflict error' do
201
- expect { post_create_response }.
202
- to raise_error(GoCardlessPro::IdempotencyConflict)
203
- end
204
- end
205
- end
206
- end
207
-
208
- describe '#create' do
209
- subject(:post_create_response) { client.instalment_schedules.create_with_schedule(params: new_resource) }
210
- context 'with a valid request' do
211
- let(:new_resource) do
212
- {
213
-
214
- 'created_at' => 'created_at-input',
215
- 'currency' => 'currency-input',
216
- 'id' => 'id-input',
217
- 'links' => 'links-input',
218
- 'metadata' => 'metadata-input',
219
- 'name' => 'name-input',
220
- 'payment_errors' => 'payment_errors-input',
221
- 'status' => 'status-input',
222
- 'total_amount' => 'total_amount-input',
223
- }
224
- end
225
-
226
- before do
227
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).
228
- with(
229
- body: {
230
- 'instalment_schedules' => {
231
-
232
- 'created_at' => 'created_at-input',
233
- 'currency' => 'currency-input',
234
- 'id' => 'id-input',
235
- 'links' => 'links-input',
236
- 'metadata' => 'metadata-input',
237
- 'name' => 'name-input',
238
- 'payment_errors' => 'payment_errors-input',
239
- 'status' => 'status-input',
240
- 'total_amount' => 'total_amount-input',
241
- },
242
- }
243
- ).
244
- to_return(
245
- body: {
246
- 'instalment_schedules' =>
247
-
248
- {
249
-
250
- 'created_at' => 'created_at-input',
251
- 'currency' => 'currency-input',
252
- 'id' => 'id-input',
253
- 'links' => 'links-input',
254
- 'metadata' => 'metadata-input',
255
- 'name' => 'name-input',
256
- 'payment_errors' => 'payment_errors-input',
257
- 'status' => 'status-input',
258
- 'total_amount' => 'total_amount-input',
259
- },
260
-
261
- }.to_json,
262
- headers: response_headers
263
- )
264
- end
265
-
266
- it 'creates and returns the resource' do
267
- expect(post_create_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
268
- end
269
-
270
- describe 'retry behaviour' do
271
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
272
-
273
- it 'retries timeouts' do
274
- stub = stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).
275
- to_timeout.then.to_return(status: 200, headers: response_headers)
276
-
277
- post_create_response
278
- expect(stub).to have_been_requested.twice
279
- end
280
-
281
- it 'retries 5XX errors' do
282
- stub = stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).
283
- to_return(status: 502,
284
- headers: { 'Content-Type' => 'text/html' },
285
- body: '<html><body>Response from Cloudflare</body></html>').
286
- then.to_return(status: 200, headers: response_headers)
287
-
288
- post_create_response
289
- expect(stub).to have_been_requested.twice
290
- end
291
- end
292
- end
293
-
294
- context 'with a request that returns a validation error' do
295
- let(:new_resource) { {} }
296
-
297
- before do
298
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).to_return(
299
- body: {
300
- error: {
301
- type: 'validation_failed',
302
- code: 422,
303
- errors: [
304
- { message: 'test error message', field: 'test_field' },
305
- ],
306
- },
307
- }.to_json,
308
- headers: response_headers,
309
- status: 422
310
- )
311
- end
312
-
313
- it 'throws the correct error' do
314
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
315
- end
316
- end
317
-
318
- context 'with a request that returns an idempotent creation conflict error' do
319
- let(:id) { 'ID123' }
320
-
321
- let(:new_resource) do
322
- {
323
-
324
- 'created_at' => 'created_at-input',
325
- 'currency' => 'currency-input',
326
- 'id' => 'id-input',
327
- 'links' => 'links-input',
328
- 'metadata' => 'metadata-input',
329
- 'name' => 'name-input',
330
- 'payment_errors' => 'payment_errors-input',
331
- 'status' => 'status-input',
332
- 'total_amount' => 'total_amount-input',
333
- }
334
- end
335
-
336
- let!(:post_stub) do
337
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).to_return(
338
- body: {
339
- error: {
340
- type: 'invalid_state',
341
- code: 409,
342
- errors: [
343
- {
344
- message: 'A resource has already been created with this idempotency key',
345
- reason: 'idempotent_creation_conflict',
346
- links: {
347
- conflicting_resource_id: id,
348
- },
349
- },
350
- ],
351
- },
352
- }.to_json,
353
- headers: response_headers,
354
- status: 409
355
- )
356
- end
357
-
358
- let!(:get_stub) do
359
- stub_url = "/instalment_schedules/#{id}"
360
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
361
- to_return(
362
- body: {
363
- 'instalment_schedules' => {
364
-
365
- 'created_at' => 'created_at-input',
366
- 'currency' => 'currency-input',
367
- 'id' => 'id-input',
368
- 'links' => 'links-input',
369
- 'metadata' => 'metadata-input',
370
- 'name' => 'name-input',
371
- 'payment_errors' => 'payment_errors-input',
372
- 'status' => 'status-input',
373
- 'total_amount' => 'total_amount-input',
374
- },
375
- }.to_json,
376
- headers: response_headers
377
- )
378
- end
379
-
380
- context 'with default behaviour' do
381
- it 'fetches the already-created resource' do
382
- post_create_response
383
- expect(post_stub).to have_been_requested
384
- expect(get_stub).to have_been_requested
385
- end
386
- end
387
-
388
- context 'with on_idempotency_conflict: :raise' do
389
- let(:client) do
390
- GoCardlessPro::Client.new(
391
- access_token: 'SECRET_TOKEN',
392
- on_idempotency_conflict: :raise
393
- )
394
- end
395
-
396
- it 'raises an IdempotencyConflict error' do
397
- expect { post_create_response }.
398
- to raise_error(GoCardlessPro::IdempotencyConflict)
399
- end
400
- end
401
- end
402
- end
403
-
404
- describe '#list' do
405
- describe 'with no filters' do
406
- subject(:get_list_response) { client.instalment_schedules.list }
407
-
408
- let(:body) do
409
- {
410
- 'instalment_schedules' => [{
411
-
412
- 'created_at' => 'created_at-input',
413
- 'currency' => 'currency-input',
414
- 'id' => 'id-input',
415
- 'links' => 'links-input',
416
- 'metadata' => 'metadata-input',
417
- 'name' => 'name-input',
418
- 'payment_errors' => 'payment_errors-input',
419
- 'status' => 'status-input',
420
- 'total_amount' => 'total_amount-input',
421
- }],
422
- meta: {
423
- cursors: {
424
- before: nil,
425
- after: 'ABC123',
426
- },
427
- },
428
- }.to_json
429
- end
430
-
431
- before do
432
- stub_request(:get, %r{.*api.gocardless.com/instalment_schedules}).to_return(
433
- body: body,
434
- headers: response_headers
435
- )
436
- end
437
-
438
- it 'wraps each item in the resource class' do
439
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::InstalmentSchedule)
440
-
441
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
442
-
443
- expect(get_list_response.records.first.currency).to eq('currency-input')
444
-
445
- expect(get_list_response.records.first.id).to eq('id-input')
446
-
447
- expect(get_list_response.records.first.metadata).to eq('metadata-input')
448
-
449
- expect(get_list_response.records.first.name).to eq('name-input')
450
-
451
- expect(get_list_response.records.first.payment_errors).to eq('payment_errors-input')
452
-
453
- expect(get_list_response.records.first.status).to eq('status-input')
454
-
455
- expect(get_list_response.records.first.total_amount).to eq('total_amount-input')
456
- end
457
-
458
- it 'exposes the cursors for before and after' do
459
- expect(get_list_response.before).to eq(nil)
460
- expect(get_list_response.after).to eq('ABC123')
461
- end
462
-
463
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
464
-
465
- describe 'retry behaviour' do
466
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
467
-
468
- it 'retries timeouts' do
469
- stub = stub_request(:get, %r{.*api.gocardless.com/instalment_schedules}).
470
- to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
471
-
472
- get_list_response
473
- expect(stub).to have_been_requested.twice
474
- end
475
-
476
- it 'retries 5XX errors' do
477
- stub = stub_request(:get, %r{.*api.gocardless.com/instalment_schedules}).
478
- to_return(status: 502,
479
- headers: { 'Content-Type' => 'text/html' },
480
- body: '<html><body>Response from Cloudflare</body></html>').
481
- then.to_return(status: 200, headers: response_headers, body: body)
482
-
483
- get_list_response
484
- expect(stub).to have_been_requested.twice
485
- end
486
- end
487
- end
488
- end
489
-
490
- describe '#all' do
491
- let!(:first_response_stub) do
492
- stub_request(:get, %r{.*api.gocardless.com/instalment_schedules$}).to_return(
493
- body: {
494
- 'instalment_schedules' => [{
495
-
496
- 'created_at' => 'created_at-input',
497
- 'currency' => 'currency-input',
498
- 'id' => 'id-input',
499
- 'links' => 'links-input',
500
- 'metadata' => 'metadata-input',
501
- 'name' => 'name-input',
502
- 'payment_errors' => 'payment_errors-input',
503
- 'status' => 'status-input',
504
- 'total_amount' => 'total_amount-input',
505
- }],
506
- meta: {
507
- cursors: { after: 'AB345' },
508
- limit: 1,
509
- },
510
- }.to_json,
511
- headers: response_headers
512
- )
513
- end
514
-
515
- let!(:second_response_stub) do
516
- stub_request(:get, %r{.*api.gocardless.com/instalment_schedules\?after=AB345}).to_return(
517
- body: {
518
- 'instalment_schedules' => [{
519
-
520
- 'created_at' => 'created_at-input',
521
- 'currency' => 'currency-input',
522
- 'id' => 'id-input',
523
- 'links' => 'links-input',
524
- 'metadata' => 'metadata-input',
525
- 'name' => 'name-input',
526
- 'payment_errors' => 'payment_errors-input',
527
- 'status' => 'status-input',
528
- 'total_amount' => 'total_amount-input',
529
- }],
530
- meta: {
531
- limit: 2,
532
- cursors: {},
533
- },
534
- }.to_json,
535
- headers: response_headers
536
- )
537
- end
538
-
539
- it 'automatically makes the extra requests' do
540
- expect(client.instalment_schedules.all.to_a.length).to eq(2)
541
- expect(first_response_stub).to have_been_requested
542
- expect(second_response_stub).to have_been_requested
543
- end
544
-
545
- describe 'retry behaviour' do
546
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
547
-
548
- it 'retries timeouts' do
549
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/instalment_schedules$}).to_return(
550
- body: {
551
- 'instalment_schedules' => [{
552
-
553
- 'created_at' => 'created_at-input',
554
- 'currency' => 'currency-input',
555
- 'id' => 'id-input',
556
- 'links' => 'links-input',
557
- 'metadata' => 'metadata-input',
558
- 'name' => 'name-input',
559
- 'payment_errors' => 'payment_errors-input',
560
- 'status' => 'status-input',
561
- 'total_amount' => 'total_amount-input',
562
- }],
563
- meta: {
564
- cursors: { after: 'AB345' },
565
- limit: 1,
566
- },
567
- }.to_json,
568
- headers: response_headers
569
- )
570
-
571
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/instalment_schedules\?after=AB345}).
572
- to_timeout.then.
573
- to_return(
574
- body: {
575
- 'instalment_schedules' => [{
576
-
577
- 'created_at' => 'created_at-input',
578
- 'currency' => 'currency-input',
579
- 'id' => 'id-input',
580
- 'links' => 'links-input',
581
- 'metadata' => 'metadata-input',
582
- 'name' => 'name-input',
583
- 'payment_errors' => 'payment_errors-input',
584
- 'status' => 'status-input',
585
- 'total_amount' => 'total_amount-input',
586
- }],
587
- meta: {
588
- limit: 2,
589
- cursors: {},
590
- },
591
- }.to_json,
592
- headers: response_headers
593
- )
594
-
595
- client.instalment_schedules.all.to_a
596
-
597
- expect(first_response_stub).to have_been_requested
598
- expect(second_response_stub).to have_been_requested.twice
599
- end
600
-
601
- it 'retries 5XX errors' do
602
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/instalment_schedules$}).to_return(
603
- body: {
604
- 'instalment_schedules' => [{
605
-
606
- 'created_at' => 'created_at-input',
607
- 'currency' => 'currency-input',
608
- 'id' => 'id-input',
609
- 'links' => 'links-input',
610
- 'metadata' => 'metadata-input',
611
- 'name' => 'name-input',
612
- 'payment_errors' => 'payment_errors-input',
613
- 'status' => 'status-input',
614
- 'total_amount' => 'total_amount-input',
615
- }],
616
- meta: {
617
- cursors: { after: 'AB345' },
618
- limit: 1,
619
- },
620
- }.to_json,
621
- headers: response_headers
622
- )
623
-
624
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/instalment_schedules\?after=AB345}).
625
- to_return(
626
- status: 502,
627
- body: '<html><body>Response from Cloudflare</body></html>',
628
- headers: { 'Content-Type' => 'text/html' }
629
- ).then.to_return(
630
- body: {
631
- 'instalment_schedules' => [{
632
-
633
- 'created_at' => 'created_at-input',
634
- 'currency' => 'currency-input',
635
- 'id' => 'id-input',
636
- 'links' => 'links-input',
637
- 'metadata' => 'metadata-input',
638
- 'name' => 'name-input',
639
- 'payment_errors' => 'payment_errors-input',
640
- 'status' => 'status-input',
641
- 'total_amount' => 'total_amount-input',
642
- }],
643
- meta: {
644
- limit: 2,
645
- cursors: {},
646
- },
647
- }.to_json,
648
- headers: response_headers
649
- )
650
-
651
- client.instalment_schedules.all.to_a
652
-
653
- expect(first_response_stub).to have_been_requested
654
- expect(second_response_stub).to have_been_requested.twice
655
- end
656
- end
657
- end
658
-
659
- describe '#get' do
660
- let(:id) { 'ID123' }
661
-
662
- subject(:get_response) { client.instalment_schedules.get(id) }
663
-
664
- context 'passing in a custom header' do
665
- let!(:stub) do
666
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
667
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
668
- with(headers: { 'Foo' => 'Bar' }).
669
- to_return(
670
- body: {
671
- 'instalment_schedules' => {
672
-
673
- 'created_at' => 'created_at-input',
674
- 'currency' => 'currency-input',
675
- 'id' => 'id-input',
676
- 'links' => 'links-input',
677
- 'metadata' => 'metadata-input',
678
- 'name' => 'name-input',
679
- 'payment_errors' => 'payment_errors-input',
680
- 'status' => 'status-input',
681
- 'total_amount' => 'total_amount-input',
682
- },
683
- }.to_json,
684
- headers: response_headers
685
- )
686
- end
687
-
688
- subject(:get_response) do
689
- client.instalment_schedules.get(id, headers: {
690
- 'Foo' => 'Bar',
691
- })
692
- end
693
-
694
- it 'includes the header' do
695
- get_response
696
- expect(stub).to have_been_requested
697
- end
698
- end
699
-
700
- context 'when there is a instalment_schedule to return' do
701
- before do
702
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
703
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
704
- body: {
705
- 'instalment_schedules' => {
706
-
707
- 'created_at' => 'created_at-input',
708
- 'currency' => 'currency-input',
709
- 'id' => 'id-input',
710
- 'links' => 'links-input',
711
- 'metadata' => 'metadata-input',
712
- 'name' => 'name-input',
713
- 'payment_errors' => 'payment_errors-input',
714
- 'status' => 'status-input',
715
- 'total_amount' => 'total_amount-input',
716
- },
717
- }.to_json,
718
- headers: response_headers
719
- )
720
- end
721
-
722
- it 'wraps the response in a resource' do
723
- expect(get_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
724
- end
725
- end
726
-
727
- context 'when nothing is returned' do
728
- before do
729
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
730
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
731
- body: '',
732
- headers: response_headers
733
- )
734
- end
735
-
736
- it 'returns nil' do
737
- expect(get_response).to be_nil
738
- end
739
- end
740
-
741
- context "when an ID is specified which can't be included in a valid URI" do
742
- let(:id) { '`' }
743
-
744
- it "doesn't raise an error" do
745
- expect { get_response }.to_not raise_error(/bad URI/)
746
- end
747
- end
748
-
749
- describe 'retry behaviour' do
750
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
751
-
752
- it 'retries timeouts' do
753
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
754
-
755
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
756
- to_timeout.then.to_return(status: 200, headers: response_headers)
757
-
758
- get_response
759
- expect(stub).to have_been_requested.twice
760
- end
761
-
762
- it 'retries 5XX errors, other than 500s' do
763
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
764
-
765
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
766
- to_return(status: 502,
767
- headers: { 'Content-Type' => 'text/html' },
768
- body: '<html><body>Response from Cloudflare</body></html>').
769
- then.to_return(status: 200, headers: response_headers)
770
-
771
- get_response
772
- expect(stub).to have_been_requested.twice
773
- end
774
-
775
- it 'retries 500 errors returned by the API' do
776
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
777
-
778
- gocardless_error = {
779
- 'error' => {
780
- 'message' => 'Internal server error',
781
- 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
782
- 'errors' => [{
783
- 'message' => 'Internal server error',
784
- 'reason' => 'internal_server_error',
785
- }],
786
- 'type' => 'gocardless',
787
- 'code' => 500,
788
- 'request_id' => 'dummy_request_id',
789
- 'id' => 'dummy_exception_id',
790
- },
791
- }
792
-
793
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
794
- to_return(status: 500,
795
- headers: response_headers,
796
- body: gocardless_error.to_json).
797
- then.to_return(status: 200, headers: response_headers)
798
-
799
- get_response
800
- expect(stub).to have_been_requested.twice
801
- end
802
- end
803
- end
804
-
805
- describe '#update' do
806
- subject(:put_update_response) { client.instalment_schedules.update(id, params: update_params) }
807
- let(:id) { 'ABC123' }
808
-
809
- context 'with a valid request' do
810
- let(:update_params) { { 'hello' => 'world' } }
811
-
812
- let!(:stub) do
813
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
814
- stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
815
- body: {
816
- 'instalment_schedules' => {
817
-
818
- 'created_at' => 'created_at-input',
819
- 'currency' => 'currency-input',
820
- 'id' => 'id-input',
821
- 'links' => 'links-input',
822
- 'metadata' => 'metadata-input',
823
- 'name' => 'name-input',
824
- 'payment_errors' => 'payment_errors-input',
825
- 'status' => 'status-input',
826
- 'total_amount' => 'total_amount-input',
827
- },
828
- }.to_json,
829
- headers: response_headers
830
- )
831
- end
832
-
833
- it 'updates and returns the resource' do
834
- expect(put_update_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
835
- expect(stub).to have_been_requested
836
- end
837
-
838
- describe 'retry behaviour' do
839
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
840
-
841
- it 'retries timeouts' do
842
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
843
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
844
- to_timeout.then.to_return(status: 200, headers: response_headers)
845
-
846
- put_update_response
847
- expect(stub).to have_been_requested.twice
848
- end
849
-
850
- it 'retries 5XX errors' do
851
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
852
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
853
- to_return(status: 502,
854
- headers: { 'Content-Type' => 'text/html' },
855
- body: '<html><body>Response from Cloudflare</body></html>').
856
- then.to_return(status: 200, headers: response_headers)
857
-
858
- put_update_response
859
- expect(stub).to have_been_requested.twice
860
- end
861
- end
862
- end
863
- end
864
-
865
- describe '#cancel' do
866
- subject(:post_response) { client.instalment_schedules.cancel(resource_id) }
867
-
868
- let(:resource_id) { 'ABC123' }
869
-
870
- let!(:stub) do
871
- # /instalment_schedules/%v/actions/cancel
872
- stub_url = '/instalment_schedules/:identity/actions/cancel'.gsub(':identity', resource_id)
873
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
874
-
875
- body: {
876
- 'instalment_schedules' => {
877
-
878
- 'created_at' => 'created_at-input',
879
- 'currency' => 'currency-input',
880
- 'id' => 'id-input',
881
- 'links' => 'links-input',
882
- 'metadata' => 'metadata-input',
883
- 'name' => 'name-input',
884
- 'payment_errors' => 'payment_errors-input',
885
- 'status' => 'status-input',
886
- 'total_amount' => 'total_amount-input',
887
- },
888
- }.to_json,
889
-
890
- headers: response_headers
891
- )
892
- end
893
-
894
- it 'wraps the response and calls the right endpoint' do
895
- expect(post_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
896
-
897
- expect(stub).to have_been_requested
898
- end
899
-
900
- describe 'retry behaviour' do
901
- it "doesn't retry errors" do
902
- stub_url = '/instalment_schedules/:identity/actions/cancel'.gsub(':identity', resource_id)
903
- stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
904
- to_timeout
905
-
906
- expect { post_response }.to raise_error(Faraday::ConnectionFailed)
907
- expect(stub).to have_been_requested
908
- end
909
- end
910
-
911
- context 'when the request needs a body and custom header' do
912
- let(:body) { { foo: 'bar' } }
913
- let(:headers) { { 'Foo' => 'Bar' } }
914
- subject(:post_response) { client.instalment_schedules.cancel(resource_id, body, headers) }
915
-
916
- let(:resource_id) { 'ABC123' }
917
-
918
- let!(:stub) do
919
- # /instalment_schedules/%v/actions/cancel
920
- stub_url = '/instalment_schedules/:identity/actions/cancel'.gsub(':identity', resource_id)
921
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
922
- with(
923
- body: { foo: 'bar' },
924
- headers: { 'Foo' => 'Bar' }
925
- ).to_return(
926
- body: {
927
- 'instalment_schedules' => {
928
-
929
- 'created_at' => 'created_at-input',
930
- 'currency' => 'currency-input',
931
- 'id' => 'id-input',
932
- 'links' => 'links-input',
933
- 'metadata' => 'metadata-input',
934
- 'name' => 'name-input',
935
- 'payment_errors' => 'payment_errors-input',
936
- 'status' => 'status-input',
937
- 'total_amount' => 'total_amount-input',
938
- },
939
- }.to_json,
940
- headers: response_headers
941
- )
942
- end
943
- end
944
- end
945
- end