gocardless_pro 2.41.0 → 2.41.2

Sign up to get free protection for your applications and to get access to all the features.
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/Gemfile +0 -10
  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,636 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Resources::InstalmentSchedule 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
- end
74
-
75
- context 'with a request that returns a validation error' do
76
- let(:new_resource) { {} }
77
-
78
- before do
79
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).to_return(
80
- body: {
81
- error: {
82
- type: 'validation_failed',
83
- code: 422,
84
- errors: [
85
- { message: 'test error message', field: 'test_field' },
86
- ],
87
- },
88
- }.to_json,
89
- headers: response_headers,
90
- status: 422
91
- )
92
- end
93
-
94
- it 'throws the correct error' do
95
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
96
- end
97
- end
98
-
99
- context 'with a request that returns an idempotent creation conflict error' do
100
- let(:id) { 'ID123' }
101
-
102
- let(:new_resource) do
103
- {
104
-
105
- 'created_at' => 'created_at-input',
106
- 'currency' => 'currency-input',
107
- 'id' => 'id-input',
108
- 'links' => 'links-input',
109
- 'metadata' => 'metadata-input',
110
- 'name' => 'name-input',
111
- 'payment_errors' => 'payment_errors-input',
112
- 'status' => 'status-input',
113
- 'total_amount' => 'total_amount-input',
114
- }
115
- end
116
-
117
- let!(:post_stub) do
118
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).to_return(
119
- body: {
120
- error: {
121
- type: 'invalid_state',
122
- code: 409,
123
- errors: [
124
- {
125
- message: 'A resource has already been created with this idempotency key',
126
- reason: 'idempotent_creation_conflict',
127
- links: {
128
- conflicting_resource_id: id,
129
- },
130
- },
131
- ],
132
- },
133
- }.to_json,
134
- headers: response_headers,
135
- status: 409
136
- )
137
- end
138
-
139
- let!(:get_stub) do
140
- stub_url = "/instalment_schedules/#{id}"
141
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
142
- to_return(
143
- body: {
144
- 'instalment_schedules' => {
145
-
146
- 'created_at' => 'created_at-input',
147
- 'currency' => 'currency-input',
148
- 'id' => 'id-input',
149
- 'links' => 'links-input',
150
- 'metadata' => 'metadata-input',
151
- 'name' => 'name-input',
152
- 'payment_errors' => 'payment_errors-input',
153
- 'status' => 'status-input',
154
- 'total_amount' => 'total_amount-input',
155
- },
156
- }.to_json,
157
- headers: response_headers
158
- )
159
- end
160
-
161
- it 'fetches the already-created resource' do
162
- post_create_response
163
- expect(post_stub).to have_been_requested
164
- expect(get_stub).to have_been_requested
165
- end
166
- end
167
- end
168
-
169
- describe '#create' do
170
- subject(:post_create_response) { client.instalment_schedules.create_with_schedule(params: new_resource) }
171
- context 'with a valid request' do
172
- let(:new_resource) do
173
- {
174
-
175
- 'created_at' => 'created_at-input',
176
- 'currency' => 'currency-input',
177
- 'id' => 'id-input',
178
- 'links' => 'links-input',
179
- 'metadata' => 'metadata-input',
180
- 'name' => 'name-input',
181
- 'payment_errors' => 'payment_errors-input',
182
- 'status' => 'status-input',
183
- 'total_amount' => 'total_amount-input',
184
- }
185
- end
186
-
187
- before do
188
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).
189
- with(
190
- body: {
191
- 'instalment_schedules' => {
192
-
193
- 'created_at' => 'created_at-input',
194
- 'currency' => 'currency-input',
195
- 'id' => 'id-input',
196
- 'links' => 'links-input',
197
- 'metadata' => 'metadata-input',
198
- 'name' => 'name-input',
199
- 'payment_errors' => 'payment_errors-input',
200
- 'status' => 'status-input',
201
- 'total_amount' => 'total_amount-input',
202
- },
203
- }
204
- ).
205
- to_return(
206
- body: {
207
- 'instalment_schedules' =>
208
-
209
- {
210
-
211
- 'created_at' => 'created_at-input',
212
- 'currency' => 'currency-input',
213
- 'id' => 'id-input',
214
- 'links' => 'links-input',
215
- 'metadata' => 'metadata-input',
216
- 'name' => 'name-input',
217
- 'payment_errors' => 'payment_errors-input',
218
- 'status' => 'status-input',
219
- 'total_amount' => 'total_amount-input',
220
- },
221
-
222
- }.to_json,
223
- headers: response_headers
224
- )
225
- end
226
-
227
- it 'creates and returns the resource' do
228
- expect(post_create_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
229
- end
230
- end
231
-
232
- context 'with a request that returns a validation error' do
233
- let(:new_resource) { {} }
234
-
235
- before do
236
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).to_return(
237
- body: {
238
- error: {
239
- type: 'validation_failed',
240
- code: 422,
241
- errors: [
242
- { message: 'test error message', field: 'test_field' },
243
- ],
244
- },
245
- }.to_json,
246
- headers: response_headers,
247
- status: 422
248
- )
249
- end
250
-
251
- it 'throws the correct error' do
252
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
253
- end
254
- end
255
-
256
- context 'with a request that returns an idempotent creation conflict error' do
257
- let(:id) { 'ID123' }
258
-
259
- let(:new_resource) do
260
- {
261
-
262
- 'created_at' => 'created_at-input',
263
- 'currency' => 'currency-input',
264
- 'id' => 'id-input',
265
- 'links' => 'links-input',
266
- 'metadata' => 'metadata-input',
267
- 'name' => 'name-input',
268
- 'payment_errors' => 'payment_errors-input',
269
- 'status' => 'status-input',
270
- 'total_amount' => 'total_amount-input',
271
- }
272
- end
273
-
274
- let!(:post_stub) do
275
- stub_request(:post, %r{.*api.gocardless.com/instalment_schedules}).to_return(
276
- body: {
277
- error: {
278
- type: 'invalid_state',
279
- code: 409,
280
- errors: [
281
- {
282
- message: 'A resource has already been created with this idempotency key',
283
- reason: 'idempotent_creation_conflict',
284
- links: {
285
- conflicting_resource_id: id,
286
- },
287
- },
288
- ],
289
- },
290
- }.to_json,
291
- headers: response_headers,
292
- status: 409
293
- )
294
- end
295
-
296
- let!(:get_stub) do
297
- stub_url = "/instalment_schedules/#{id}"
298
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
299
- to_return(
300
- body: {
301
- 'instalment_schedules' => {
302
-
303
- 'created_at' => 'created_at-input',
304
- 'currency' => 'currency-input',
305
- 'id' => 'id-input',
306
- 'links' => 'links-input',
307
- 'metadata' => 'metadata-input',
308
- 'name' => 'name-input',
309
- 'payment_errors' => 'payment_errors-input',
310
- 'status' => 'status-input',
311
- 'total_amount' => 'total_amount-input',
312
- },
313
- }.to_json,
314
- headers: response_headers
315
- )
316
- end
317
-
318
- it 'fetches the already-created resource' do
319
- post_create_response
320
- expect(post_stub).to have_been_requested
321
- expect(get_stub).to have_been_requested
322
- end
323
- end
324
- end
325
-
326
- describe '#list' do
327
- describe 'with no filters' do
328
- subject(:get_list_response) { client.instalment_schedules.list }
329
-
330
- before do
331
- stub_request(:get, %r{.*api.gocardless.com/instalment_schedules}).to_return(
332
- body: {
333
- 'instalment_schedules' => [{
334
-
335
- 'created_at' => 'created_at-input',
336
- 'currency' => 'currency-input',
337
- 'id' => 'id-input',
338
- 'links' => 'links-input',
339
- 'metadata' => 'metadata-input',
340
- 'name' => 'name-input',
341
- 'payment_errors' => 'payment_errors-input',
342
- 'status' => 'status-input',
343
- 'total_amount' => 'total_amount-input',
344
- }],
345
- meta: {
346
- cursors: {
347
- before: nil,
348
- after: 'ABC123',
349
- },
350
- },
351
- }.to_json,
352
- headers: response_headers
353
- )
354
- end
355
-
356
- it 'wraps each item in the resource class' do
357
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::InstalmentSchedule)
358
-
359
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
360
-
361
- expect(get_list_response.records.first.currency).to eq('currency-input')
362
-
363
- expect(get_list_response.records.first.id).to eq('id-input')
364
-
365
- expect(get_list_response.records.first.metadata).to eq('metadata-input')
366
-
367
- expect(get_list_response.records.first.name).to eq('name-input')
368
-
369
- expect(get_list_response.records.first.payment_errors).to eq('payment_errors-input')
370
-
371
- expect(get_list_response.records.first.status).to eq('status-input')
372
-
373
- expect(get_list_response.records.first.total_amount).to eq('total_amount-input')
374
- end
375
-
376
- it 'exposes the cursors for before and after' do
377
- expect(get_list_response.before).to eq(nil)
378
- expect(get_list_response.after).to eq('ABC123')
379
- end
380
-
381
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
382
- end
383
- end
384
-
385
- describe '#all' do
386
- let!(:first_response_stub) do
387
- stub_request(:get, %r{.*api.gocardless.com/instalment_schedules$}).to_return(
388
- body: {
389
- 'instalment_schedules' => [{
390
-
391
- 'created_at' => 'created_at-input',
392
- 'currency' => 'currency-input',
393
- 'id' => 'id-input',
394
- 'links' => 'links-input',
395
- 'metadata' => 'metadata-input',
396
- 'name' => 'name-input',
397
- 'payment_errors' => 'payment_errors-input',
398
- 'status' => 'status-input',
399
- 'total_amount' => 'total_amount-input',
400
- }],
401
- meta: {
402
- cursors: { after: 'AB345' },
403
- limit: 1,
404
- },
405
- }.to_json,
406
- headers: response_headers
407
- )
408
- end
409
-
410
- let!(:second_response_stub) do
411
- stub_request(:get, %r{.*api.gocardless.com/instalment_schedules\?after=AB345}).to_return(
412
- body: {
413
- 'instalment_schedules' => [{
414
-
415
- 'created_at' => 'created_at-input',
416
- 'currency' => 'currency-input',
417
- 'id' => 'id-input',
418
- 'links' => 'links-input',
419
- 'metadata' => 'metadata-input',
420
- 'name' => 'name-input',
421
- 'payment_errors' => 'payment_errors-input',
422
- 'status' => 'status-input',
423
- 'total_amount' => 'total_amount-input',
424
- }],
425
- meta: {
426
- limit: 2,
427
- cursors: {},
428
- },
429
- }.to_json,
430
- headers: response_headers
431
- )
432
- end
433
-
434
- it 'automatically makes the extra requests' do
435
- expect(client.instalment_schedules.all.to_a.length).to eq(2)
436
- expect(first_response_stub).to have_been_requested
437
- expect(second_response_stub).to have_been_requested
438
- end
439
- end
440
-
441
- describe '#get' do
442
- let(:id) { 'ID123' }
443
-
444
- subject(:get_response) { client.instalment_schedules.get(id) }
445
-
446
- context 'passing in a custom header' do
447
- let!(:stub) do
448
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
449
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
450
- with(headers: { 'Foo' => 'Bar' }).
451
- to_return(
452
- body: {
453
- 'instalment_schedules' => {
454
-
455
- 'created_at' => 'created_at-input',
456
- 'currency' => 'currency-input',
457
- 'id' => 'id-input',
458
- 'links' => 'links-input',
459
- 'metadata' => 'metadata-input',
460
- 'name' => 'name-input',
461
- 'payment_errors' => 'payment_errors-input',
462
- 'status' => 'status-input',
463
- 'total_amount' => 'total_amount-input',
464
- },
465
- }.to_json,
466
- headers: response_headers
467
- )
468
- end
469
-
470
- subject(:get_response) do
471
- client.instalment_schedules.get(id, headers: {
472
- 'Foo' => 'Bar',
473
- })
474
- end
475
-
476
- it 'includes the header' do
477
- get_response
478
- expect(stub).to have_been_requested
479
- end
480
- end
481
-
482
- context 'when there is a instalment_schedule to return' do
483
- before do
484
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
485
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
486
- body: {
487
- 'instalment_schedules' => {
488
-
489
- 'created_at' => 'created_at-input',
490
- 'currency' => 'currency-input',
491
- 'id' => 'id-input',
492
- 'links' => 'links-input',
493
- 'metadata' => 'metadata-input',
494
- 'name' => 'name-input',
495
- 'payment_errors' => 'payment_errors-input',
496
- 'status' => 'status-input',
497
- 'total_amount' => 'total_amount-input',
498
- },
499
- }.to_json,
500
- headers: response_headers
501
- )
502
- end
503
-
504
- it 'wraps the response in a resource' do
505
- expect(get_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
506
- end
507
- end
508
-
509
- context 'when nothing is returned' do
510
- before do
511
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
512
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
513
- body: '',
514
- headers: response_headers
515
- )
516
- end
517
-
518
- it 'returns nil' do
519
- expect(get_response).to be_nil
520
- end
521
- end
522
-
523
- context "when an ID is specified which can't be included in a valid URI" do
524
- let(:id) { '`' }
525
-
526
- it "doesn't raise an error" do
527
- expect { get_response }.to_not raise_error(/bad URI/)
528
- end
529
- end
530
- end
531
-
532
- describe '#update' do
533
- subject(:put_update_response) { client.instalment_schedules.update(id, params: update_params) }
534
- let(:id) { 'ABC123' }
535
-
536
- context 'with a valid request' do
537
- let(:update_params) { { 'hello' => 'world' } }
538
-
539
- let!(:stub) do
540
- stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
541
- stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
542
- body: {
543
- 'instalment_schedules' => {
544
-
545
- 'created_at' => 'created_at-input',
546
- 'currency' => 'currency-input',
547
- 'id' => 'id-input',
548
- 'links' => 'links-input',
549
- 'metadata' => 'metadata-input',
550
- 'name' => 'name-input',
551
- 'payment_errors' => 'payment_errors-input',
552
- 'status' => 'status-input',
553
- 'total_amount' => 'total_amount-input',
554
- },
555
- }.to_json,
556
- headers: response_headers
557
- )
558
- end
559
-
560
- it 'updates and returns the resource' do
561
- expect(put_update_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
562
- expect(stub).to have_been_requested
563
- end
564
- end
565
- end
566
-
567
- describe '#cancel' do
568
- subject(:post_response) { client.instalment_schedules.cancel(resource_id) }
569
-
570
- let(:resource_id) { 'ABC123' }
571
-
572
- let!(:stub) do
573
- # /instalment_schedules/%v/actions/cancel
574
- stub_url = '/instalment_schedules/:identity/actions/cancel'.gsub(':identity', resource_id)
575
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
576
-
577
- body: {
578
- 'instalment_schedules' => {
579
-
580
- 'created_at' => 'created_at-input',
581
- 'currency' => 'currency-input',
582
- 'id' => 'id-input',
583
- 'links' => 'links-input',
584
- 'metadata' => 'metadata-input',
585
- 'name' => 'name-input',
586
- 'payment_errors' => 'payment_errors-input',
587
- 'status' => 'status-input',
588
- 'total_amount' => 'total_amount-input',
589
- },
590
- }.to_json,
591
-
592
- headers: response_headers
593
- )
594
- end
595
-
596
- it 'wraps the response and calls the right endpoint' do
597
- expect(post_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
598
-
599
- expect(stub).to have_been_requested
600
- end
601
-
602
- context 'when the request needs a body and custom header' do
603
- let(:body) { { foo: 'bar' } }
604
- let(:headers) { { 'Foo' => 'Bar' } }
605
- subject(:post_response) { client.instalment_schedules.cancel(resource_id, body, headers) }
606
-
607
- let(:resource_id) { 'ABC123' }
608
-
609
- let!(:stub) do
610
- # /instalment_schedules/%v/actions/cancel
611
- stub_url = '/instalment_schedules/:identity/actions/cancel'.gsub(':identity', resource_id)
612
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
613
- with(
614
- body: { foo: 'bar' },
615
- headers: { 'Foo' => 'Bar' }
616
- ).to_return(
617
- body: {
618
- 'instalment_schedules' => {
619
-
620
- 'created_at' => 'created_at-input',
621
- 'currency' => 'currency-input',
622
- 'id' => 'id-input',
623
- 'links' => 'links-input',
624
- 'metadata' => 'metadata-input',
625
- 'name' => 'name-input',
626
- 'payment_errors' => 'payment_errors-input',
627
- 'status' => 'status-input',
628
- 'total_amount' => 'total_amount-input',
629
- },
630
- }.to_json,
631
- headers: response_headers
632
- )
633
- end
634
- end
635
- end
636
- end