gocardless_pro 2.17.1 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gocardless_pro.rb +3 -0
  3. data/lib/gocardless_pro/client.rb +6 -1
  4. data/lib/gocardless_pro/resources/creditor_bank_account.rb +1 -2
  5. data/lib/gocardless_pro/resources/currency_exchange_rate.rb +44 -0
  6. data/lib/gocardless_pro/resources/customer_notification.rb +3 -5
  7. data/lib/gocardless_pro/resources/event.rb +2 -1
  8. data/lib/gocardless_pro/resources/mandate_import.rb +5 -8
  9. data/lib/gocardless_pro/resources/mandate_import_entry.rb +3 -5
  10. data/lib/gocardless_pro/resources/payout.rb +2 -0
  11. data/lib/gocardless_pro/resources/redirect_flow.rb +2 -0
  12. data/lib/gocardless_pro/resources/subscription.rb +38 -29
  13. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +67 -0
  14. data/lib/gocardless_pro/services/customers_service.rb +1 -2
  15. data/lib/gocardless_pro/services/instalment_schedules_service.rb +81 -5
  16. data/lib/gocardless_pro/services/mandates_service.rb +1 -1
  17. data/lib/gocardless_pro/services/payouts_service.rb +21 -0
  18. data/lib/gocardless_pro/services/subscriptions_service.rb +129 -0
  19. data/lib/gocardless_pro/version.rb +1 -1
  20. data/spec/resources/currency_exchange_rate_spec.rb +103 -0
  21. data/spec/resources/instalment_schedule_spec.rb +193 -1
  22. data/spec/resources/payout_spec.rb +45 -0
  23. data/spec/resources/redirect_flow_spec.rb +9 -0
  24. data/spec/resources/subscription_spec.rb +210 -0
  25. data/spec/services/currency_exchange_rates_service_spec.rb +223 -0
  26. data/spec/services/instalment_schedules_service_spec.rb +270 -1
  27. data/spec/services/payouts_service_spec.rb +74 -0
  28. data/spec/services/redirect_flows_service_spec.rb +9 -0
  29. data/spec/services/subscriptions_service_spec.rb +240 -0
  30. metadata +9 -3
@@ -25,6 +25,7 @@ describe GoCardlessPro::Services::PayoutsService do
25
25
  'fx' => 'fx-input',
26
26
  'id' => 'id-input',
27
27
  'links' => 'links-input',
28
+ 'metadata' => 'metadata-input',
28
29
  'payout_type' => 'payout_type-input',
29
30
  'reference' => 'reference-input',
30
31
  'status' => 'status-input',
@@ -62,6 +63,8 @@ describe GoCardlessPro::Services::PayoutsService do
62
63
 
63
64
  expect(get_list_response.records.first.id).to eq('id-input')
64
65
 
66
+ expect(get_list_response.records.first.metadata).to eq('metadata-input')
67
+
65
68
  expect(get_list_response.records.first.payout_type).to eq('payout_type-input')
66
69
 
67
70
  expect(get_list_response.records.first.reference).to eq('reference-input')
@@ -115,6 +118,7 @@ describe GoCardlessPro::Services::PayoutsService do
115
118
  'fx' => 'fx-input',
116
119
  'id' => 'id-input',
117
120
  'links' => 'links-input',
121
+ 'metadata' => 'metadata-input',
118
122
  'payout_type' => 'payout_type-input',
119
123
  'reference' => 'reference-input',
120
124
  'status' => 'status-input',
@@ -141,6 +145,7 @@ describe GoCardlessPro::Services::PayoutsService do
141
145
  'fx' => 'fx-input',
142
146
  'id' => 'id-input',
143
147
  'links' => 'links-input',
148
+ 'metadata' => 'metadata-input',
144
149
  'payout_type' => 'payout_type-input',
145
150
  'reference' => 'reference-input',
146
151
  'status' => 'status-input',
@@ -176,6 +181,7 @@ describe GoCardlessPro::Services::PayoutsService do
176
181
  'fx' => 'fx-input',
177
182
  'id' => 'id-input',
178
183
  'links' => 'links-input',
184
+ 'metadata' => 'metadata-input',
179
185
  'payout_type' => 'payout_type-input',
180
186
  'reference' => 'reference-input',
181
187
  'status' => 'status-input',
@@ -202,6 +208,7 @@ describe GoCardlessPro::Services::PayoutsService do
202
208
  'fx' => 'fx-input',
203
209
  'id' => 'id-input',
204
210
  'links' => 'links-input',
211
+ 'metadata' => 'metadata-input',
205
212
  'payout_type' => 'payout_type-input',
206
213
  'reference' => 'reference-input',
207
214
  'status' => 'status-input',
@@ -233,6 +240,7 @@ describe GoCardlessPro::Services::PayoutsService do
233
240
  'fx' => 'fx-input',
234
241
  'id' => 'id-input',
235
242
  'links' => 'links-input',
243
+ 'metadata' => 'metadata-input',
236
244
  'payout_type' => 'payout_type-input',
237
245
  'reference' => 'reference-input',
238
246
  'status' => 'status-input',
@@ -262,6 +270,7 @@ describe GoCardlessPro::Services::PayoutsService do
262
270
  'fx' => 'fx-input',
263
271
  'id' => 'id-input',
264
272
  'links' => 'links-input',
273
+ 'metadata' => 'metadata-input',
265
274
  'payout_type' => 'payout_type-input',
266
275
  'reference' => 'reference-input',
267
276
  'status' => 'status-input',
@@ -304,6 +313,7 @@ describe GoCardlessPro::Services::PayoutsService do
304
313
  'fx' => 'fx-input',
305
314
  'id' => 'id-input',
306
315
  'links' => 'links-input',
316
+ 'metadata' => 'metadata-input',
307
317
  'payout_type' => 'payout_type-input',
308
318
  'reference' => 'reference-input',
309
319
  'status' => 'status-input',
@@ -340,6 +350,7 @@ describe GoCardlessPro::Services::PayoutsService do
340
350
  'fx' => 'fx-input',
341
351
  'id' => 'id-input',
342
352
  'links' => 'links-input',
353
+ 'metadata' => 'metadata-input',
343
354
  'payout_type' => 'payout_type-input',
344
355
  'reference' => 'reference-input',
345
356
  'status' => 'status-input',
@@ -431,4 +442,67 @@ describe GoCardlessPro::Services::PayoutsService do
431
442
  end
432
443
  end
433
444
  end
445
+
446
+ describe '#update' do
447
+ subject(:put_update_response) { client.payouts.update(id, params: update_params) }
448
+ let(:id) { 'ABC123' }
449
+
450
+ context 'with a valid request' do
451
+ let(:update_params) { { 'hello' => 'world' } }
452
+
453
+ let!(:stub) do
454
+ stub_url = '/payouts/:identity'.gsub(':identity', id)
455
+ stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
456
+ body: {
457
+ 'payouts' => {
458
+
459
+ 'amount' => 'amount-input',
460
+ 'arrival_date' => 'arrival_date-input',
461
+ 'created_at' => 'created_at-input',
462
+ 'currency' => 'currency-input',
463
+ 'deducted_fees' => 'deducted_fees-input',
464
+ 'fx' => 'fx-input',
465
+ 'id' => 'id-input',
466
+ 'links' => 'links-input',
467
+ 'metadata' => 'metadata-input',
468
+ 'payout_type' => 'payout_type-input',
469
+ 'reference' => 'reference-input',
470
+ 'status' => 'status-input',
471
+ },
472
+ }.to_json,
473
+ headers: response_headers
474
+ )
475
+ end
476
+
477
+ it 'updates and returns the resource' do
478
+ expect(put_update_response).to be_a(GoCardlessPro::Resources::Payout)
479
+ expect(stub).to have_been_requested
480
+ end
481
+
482
+ describe 'retry behaviour' do
483
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
484
+
485
+ it 'retries timeouts' do
486
+ stub_url = '/payouts/:identity'.gsub(':identity', id)
487
+ stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
488
+ to_timeout.then.to_return(status: 200, headers: response_headers)
489
+
490
+ put_update_response
491
+ expect(stub).to have_been_requested.twice
492
+ end
493
+
494
+ it 'retries 5XX errors' do
495
+ stub_url = '/payouts/:identity'.gsub(':identity', id)
496
+ stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
497
+ to_return(status: 502,
498
+ headers: { 'Content-Type' => 'text/html' },
499
+ body: '<html><body>Response from Cloudflare</body></html>').
500
+ then.to_return(status: 200, headers: response_headers)
501
+
502
+ put_update_response
503
+ expect(stub).to have_been_requested.twice
504
+ end
505
+ end
506
+ end
507
+ end
434
508
  end
@@ -20,6 +20,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
20
20
  'description' => 'description-input',
21
21
  'id' => 'id-input',
22
22
  'links' => 'links-input',
23
+ 'metadata' => 'metadata-input',
23
24
  'redirect_url' => 'redirect_url-input',
24
25
  'scheme' => 'scheme-input',
25
26
  'session_token' => 'session_token-input',
@@ -38,6 +39,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
38
39
  'description' => 'description-input',
39
40
  'id' => 'id-input',
40
41
  'links' => 'links-input',
42
+ 'metadata' => 'metadata-input',
41
43
  'redirect_url' => 'redirect_url-input',
42
44
  'scheme' => 'scheme-input',
43
45
  'session_token' => 'session_token-input',
@@ -56,6 +58,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
56
58
  'description' => 'description-input',
57
59
  'id' => 'id-input',
58
60
  'links' => 'links-input',
61
+ 'metadata' => 'metadata-input',
59
62
  'redirect_url' => 'redirect_url-input',
60
63
  'scheme' => 'scheme-input',
61
64
  'session_token' => 'session_token-input',
@@ -130,6 +133,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
130
133
  'description' => 'description-input',
131
134
  'id' => 'id-input',
132
135
  'links' => 'links-input',
136
+ 'metadata' => 'metadata-input',
133
137
  'redirect_url' => 'redirect_url-input',
134
138
  'scheme' => 'scheme-input',
135
139
  'session_token' => 'session_token-input',
@@ -171,6 +175,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
171
175
  'description' => 'description-input',
172
176
  'id' => 'id-input',
173
177
  'links' => 'links-input',
178
+ 'metadata' => 'metadata-input',
174
179
  'redirect_url' => 'redirect_url-input',
175
180
  'scheme' => 'scheme-input',
176
181
  'session_token' => 'session_token-input',
@@ -237,6 +242,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
237
242
  'description' => 'description-input',
238
243
  'id' => 'id-input',
239
244
  'links' => 'links-input',
245
+ 'metadata' => 'metadata-input',
240
246
  'redirect_url' => 'redirect_url-input',
241
247
  'scheme' => 'scheme-input',
242
248
  'session_token' => 'session_token-input',
@@ -271,6 +277,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
271
277
  'description' => 'description-input',
272
278
  'id' => 'id-input',
273
279
  'links' => 'links-input',
280
+ 'metadata' => 'metadata-input',
274
281
  'redirect_url' => 'redirect_url-input',
275
282
  'scheme' => 'scheme-input',
276
283
  'session_token' => 'session_token-input',
@@ -381,6 +388,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
381
388
  'description' => 'description-input',
382
389
  'id' => 'id-input',
383
390
  'links' => 'links-input',
391
+ 'metadata' => 'metadata-input',
384
392
  'redirect_url' => 'redirect_url-input',
385
393
  'scheme' => 'scheme-input',
386
394
  'session_token' => 'session_token-input',
@@ -431,6 +439,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
431
439
  'description' => 'description-input',
432
440
  'id' => 'id-input',
433
441
  'links' => 'links-input',
442
+ 'metadata' => 'metadata-input',
434
443
  'redirect_url' => 'redirect_url-input',
435
444
  'scheme' => 'scheme-input',
436
445
  'session_token' => 'session_token-input',
@@ -17,9 +17,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
17
17
 
18
18
  'amount' => 'amount-input',
19
19
  'app_fee' => 'app_fee-input',
20
+ 'count' => 'count-input',
20
21
  'created_at' => 'created_at-input',
21
22
  'currency' => 'currency-input',
22
23
  'day_of_month' => 'day_of_month-input',
24
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
23
25
  'end_date' => 'end_date-input',
24
26
  'id' => 'id-input',
25
27
  'interval' => 'interval-input',
@@ -44,9 +46,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
44
46
 
45
47
  'amount' => 'amount-input',
46
48
  'app_fee' => 'app_fee-input',
49
+ 'count' => 'count-input',
47
50
  'created_at' => 'created_at-input',
48
51
  'currency' => 'currency-input',
49
52
  'day_of_month' => 'day_of_month-input',
53
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
50
54
  'end_date' => 'end_date-input',
51
55
  'id' => 'id-input',
52
56
  'interval' => 'interval-input',
@@ -71,9 +75,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
71
75
 
72
76
  'amount' => 'amount-input',
73
77
  'app_fee' => 'app_fee-input',
78
+ 'count' => 'count-input',
74
79
  'created_at' => 'created_at-input',
75
80
  'currency' => 'currency-input',
76
81
  'day_of_month' => 'day_of_month-input',
82
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
77
83
  'end_date' => 'end_date-input',
78
84
  'id' => 'id-input',
79
85
  'interval' => 'interval-input',
@@ -154,9 +160,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
154
160
 
155
161
  'amount' => 'amount-input',
156
162
  'app_fee' => 'app_fee-input',
163
+ 'count' => 'count-input',
157
164
  'created_at' => 'created_at-input',
158
165
  'currency' => 'currency-input',
159
166
  'day_of_month' => 'day_of_month-input',
167
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
160
168
  'end_date' => 'end_date-input',
161
169
  'id' => 'id-input',
162
170
  'interval' => 'interval-input',
@@ -204,9 +212,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
204
212
 
205
213
  'amount' => 'amount-input',
206
214
  'app_fee' => 'app_fee-input',
215
+ 'count' => 'count-input',
207
216
  'created_at' => 'created_at-input',
208
217
  'currency' => 'currency-input',
209
218
  'day_of_month' => 'day_of_month-input',
219
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
210
220
  'end_date' => 'end_date-input',
211
221
  'id' => 'id-input',
212
222
  'interval' => 'interval-input',
@@ -273,9 +283,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
273
283
 
274
284
  'amount' => 'amount-input',
275
285
  'app_fee' => 'app_fee-input',
286
+ 'count' => 'count-input',
276
287
  'created_at' => 'created_at-input',
277
288
  'currency' => 'currency-input',
278
289
  'day_of_month' => 'day_of_month-input',
290
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
279
291
  'end_date' => 'end_date-input',
280
292
  'id' => 'id-input',
281
293
  'interval' => 'interval-input',
@@ -313,12 +325,16 @@ describe GoCardlessPro::Services::SubscriptionsService do
313
325
 
314
326
  expect(get_list_response.records.first.app_fee).to eq('app_fee-input')
315
327
 
328
+ expect(get_list_response.records.first.count).to eq('count-input')
329
+
316
330
  expect(get_list_response.records.first.created_at).to eq('created_at-input')
317
331
 
318
332
  expect(get_list_response.records.first.currency).to eq('currency-input')
319
333
 
320
334
  expect(get_list_response.records.first.day_of_month).to eq('day_of_month-input')
321
335
 
336
+ expect(get_list_response.records.first.earliest_charge_date_after_resume).to eq('earliest_charge_date_after_resume-input')
337
+
322
338
  expect(get_list_response.records.first.end_date).to eq('end_date-input')
323
339
 
324
340
  expect(get_list_response.records.first.id).to eq('id-input')
@@ -384,9 +400,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
384
400
 
385
401
  'amount' => 'amount-input',
386
402
  'app_fee' => 'app_fee-input',
403
+ 'count' => 'count-input',
387
404
  'created_at' => 'created_at-input',
388
405
  'currency' => 'currency-input',
389
406
  'day_of_month' => 'day_of_month-input',
407
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
390
408
  'end_date' => 'end_date-input',
391
409
  'id' => 'id-input',
392
410
  'interval' => 'interval-input',
@@ -417,9 +435,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
417
435
 
418
436
  'amount' => 'amount-input',
419
437
  'app_fee' => 'app_fee-input',
438
+ 'count' => 'count-input',
420
439
  'created_at' => 'created_at-input',
421
440
  'currency' => 'currency-input',
422
441
  'day_of_month' => 'day_of_month-input',
442
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
423
443
  'end_date' => 'end_date-input',
424
444
  'id' => 'id-input',
425
445
  'interval' => 'interval-input',
@@ -459,9 +479,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
459
479
 
460
480
  'amount' => 'amount-input',
461
481
  'app_fee' => 'app_fee-input',
482
+ 'count' => 'count-input',
462
483
  'created_at' => 'created_at-input',
463
484
  'currency' => 'currency-input',
464
485
  'day_of_month' => 'day_of_month-input',
486
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
465
487
  'end_date' => 'end_date-input',
466
488
  'id' => 'id-input',
467
489
  'interval' => 'interval-input',
@@ -492,9 +514,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
492
514
 
493
515
  'amount' => 'amount-input',
494
516
  'app_fee' => 'app_fee-input',
517
+ 'count' => 'count-input',
495
518
  'created_at' => 'created_at-input',
496
519
  'currency' => 'currency-input',
497
520
  'day_of_month' => 'day_of_month-input',
521
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
498
522
  'end_date' => 'end_date-input',
499
523
  'id' => 'id-input',
500
524
  'interval' => 'interval-input',
@@ -530,9 +554,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
530
554
 
531
555
  'amount' => 'amount-input',
532
556
  'app_fee' => 'app_fee-input',
557
+ 'count' => 'count-input',
533
558
  'created_at' => 'created_at-input',
534
559
  'currency' => 'currency-input',
535
560
  'day_of_month' => 'day_of_month-input',
561
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
536
562
  'end_date' => 'end_date-input',
537
563
  'id' => 'id-input',
538
564
  'interval' => 'interval-input',
@@ -566,9 +592,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
566
592
 
567
593
  'amount' => 'amount-input',
568
594
  'app_fee' => 'app_fee-input',
595
+ 'count' => 'count-input',
569
596
  'created_at' => 'created_at-input',
570
597
  'currency' => 'currency-input',
571
598
  'day_of_month' => 'day_of_month-input',
599
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
572
600
  'end_date' => 'end_date-input',
573
601
  'id' => 'id-input',
574
602
  'interval' => 'interval-input',
@@ -615,9 +643,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
615
643
 
616
644
  'amount' => 'amount-input',
617
645
  'app_fee' => 'app_fee-input',
646
+ 'count' => 'count-input',
618
647
  'created_at' => 'created_at-input',
619
648
  'currency' => 'currency-input',
620
649
  'day_of_month' => 'day_of_month-input',
650
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
621
651
  'end_date' => 'end_date-input',
622
652
  'id' => 'id-input',
623
653
  'interval' => 'interval-input',
@@ -658,9 +688,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
658
688
 
659
689
  'amount' => 'amount-input',
660
690
  'app_fee' => 'app_fee-input',
691
+ 'count' => 'count-input',
661
692
  'created_at' => 'created_at-input',
662
693
  'currency' => 'currency-input',
663
694
  'day_of_month' => 'day_of_month-input',
695
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
664
696
  'end_date' => 'end_date-input',
665
697
  'id' => 'id-input',
666
698
  'interval' => 'interval-input',
@@ -778,9 +810,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
778
810
 
779
811
  'amount' => 'amount-input',
780
812
  'app_fee' => 'app_fee-input',
813
+ 'count' => 'count-input',
781
814
  'created_at' => 'created_at-input',
782
815
  'currency' => 'currency-input',
783
816
  'day_of_month' => 'day_of_month-input',
817
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
784
818
  'end_date' => 'end_date-input',
785
819
  'id' => 'id-input',
786
820
  'interval' => 'interval-input',
@@ -832,6 +866,208 @@ describe GoCardlessPro::Services::SubscriptionsService do
832
866
  end
833
867
  end
834
868
 
869
+ describe '#pause' do
870
+ subject(:post_response) { client.subscriptions.pause(resource_id) }
871
+
872
+ let(:resource_id) { 'ABC123' }
873
+
874
+ let!(:stub) do
875
+ # /subscriptions/%v/actions/pause
876
+ stub_url = '/subscriptions/:identity/actions/pause'.gsub(':identity', resource_id)
877
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
878
+ body: {
879
+ 'subscriptions' => {
880
+
881
+ 'amount' => 'amount-input',
882
+ 'app_fee' => 'app_fee-input',
883
+ 'count' => 'count-input',
884
+ 'created_at' => 'created_at-input',
885
+ 'currency' => 'currency-input',
886
+ 'day_of_month' => 'day_of_month-input',
887
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
888
+ 'end_date' => 'end_date-input',
889
+ 'id' => 'id-input',
890
+ 'interval' => 'interval-input',
891
+ 'interval_unit' => 'interval_unit-input',
892
+ 'links' => 'links-input',
893
+ 'metadata' => 'metadata-input',
894
+ 'month' => 'month-input',
895
+ 'name' => 'name-input',
896
+ 'payment_reference' => 'payment_reference-input',
897
+ 'retry_if_possible' => 'retry_if_possible-input',
898
+ 'start_date' => 'start_date-input',
899
+ 'status' => 'status-input',
900
+ 'upcoming_payments' => 'upcoming_payments-input',
901
+ },
902
+ }.to_json,
903
+ headers: response_headers
904
+ )
905
+ end
906
+
907
+ it 'wraps the response and calls the right endpoint' do
908
+ expect(post_response).to be_a(GoCardlessPro::Resources::Subscription)
909
+
910
+ expect(stub).to have_been_requested
911
+ end
912
+
913
+ describe 'retry behaviour' do
914
+ it "doesn't retry errors" do
915
+ stub_url = '/subscriptions/:identity/actions/pause'.gsub(':identity', resource_id)
916
+ stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
917
+ to_timeout
918
+
919
+ expect { post_response }.to raise_error(Faraday::TimeoutError)
920
+ expect(stub).to have_been_requested
921
+ end
922
+ end
923
+
924
+ context 'when the request needs a body and custom header' do
925
+ let(:body) { { foo: 'bar' } }
926
+ let(:headers) { { 'Foo' => 'Bar' } }
927
+ subject(:post_response) { client.subscriptions.pause(resource_id, body, headers) }
928
+
929
+ let(:resource_id) { 'ABC123' }
930
+
931
+ let!(:stub) do
932
+ # /subscriptions/%v/actions/pause
933
+ stub_url = '/subscriptions/:identity/actions/pause'.gsub(':identity', resource_id)
934
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
935
+ with(
936
+ body: { foo: 'bar' },
937
+ headers: { 'Foo' => 'Bar' }
938
+ ).to_return(
939
+ body: {
940
+ 'subscriptions' => {
941
+
942
+ 'amount' => 'amount-input',
943
+ 'app_fee' => 'app_fee-input',
944
+ 'count' => 'count-input',
945
+ 'created_at' => 'created_at-input',
946
+ 'currency' => 'currency-input',
947
+ 'day_of_month' => 'day_of_month-input',
948
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
949
+ 'end_date' => 'end_date-input',
950
+ 'id' => 'id-input',
951
+ 'interval' => 'interval-input',
952
+ 'interval_unit' => 'interval_unit-input',
953
+ 'links' => 'links-input',
954
+ 'metadata' => 'metadata-input',
955
+ 'month' => 'month-input',
956
+ 'name' => 'name-input',
957
+ 'payment_reference' => 'payment_reference-input',
958
+ 'retry_if_possible' => 'retry_if_possible-input',
959
+ 'start_date' => 'start_date-input',
960
+ 'status' => 'status-input',
961
+ 'upcoming_payments' => 'upcoming_payments-input',
962
+ },
963
+ }.to_json,
964
+ headers: response_headers
965
+ )
966
+ end
967
+ end
968
+ end
969
+
970
+ describe '#resume' do
971
+ subject(:post_response) { client.subscriptions.resume(resource_id) }
972
+
973
+ let(:resource_id) { 'ABC123' }
974
+
975
+ let!(:stub) do
976
+ # /subscriptions/%v/actions/resume
977
+ stub_url = '/subscriptions/:identity/actions/resume'.gsub(':identity', resource_id)
978
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
979
+ body: {
980
+ 'subscriptions' => {
981
+
982
+ 'amount' => 'amount-input',
983
+ 'app_fee' => 'app_fee-input',
984
+ 'count' => 'count-input',
985
+ 'created_at' => 'created_at-input',
986
+ 'currency' => 'currency-input',
987
+ 'day_of_month' => 'day_of_month-input',
988
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
989
+ 'end_date' => 'end_date-input',
990
+ 'id' => 'id-input',
991
+ 'interval' => 'interval-input',
992
+ 'interval_unit' => 'interval_unit-input',
993
+ 'links' => 'links-input',
994
+ 'metadata' => 'metadata-input',
995
+ 'month' => 'month-input',
996
+ 'name' => 'name-input',
997
+ 'payment_reference' => 'payment_reference-input',
998
+ 'retry_if_possible' => 'retry_if_possible-input',
999
+ 'start_date' => 'start_date-input',
1000
+ 'status' => 'status-input',
1001
+ 'upcoming_payments' => 'upcoming_payments-input',
1002
+ },
1003
+ }.to_json,
1004
+ headers: response_headers
1005
+ )
1006
+ end
1007
+
1008
+ it 'wraps the response and calls the right endpoint' do
1009
+ expect(post_response).to be_a(GoCardlessPro::Resources::Subscription)
1010
+
1011
+ expect(stub).to have_been_requested
1012
+ end
1013
+
1014
+ describe 'retry behaviour' do
1015
+ it "doesn't retry errors" do
1016
+ stub_url = '/subscriptions/:identity/actions/resume'.gsub(':identity', resource_id)
1017
+ stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
1018
+ to_timeout
1019
+
1020
+ expect { post_response }.to raise_error(Faraday::TimeoutError)
1021
+ expect(stub).to have_been_requested
1022
+ end
1023
+ end
1024
+
1025
+ context 'when the request needs a body and custom header' do
1026
+ let(:body) { { foo: 'bar' } }
1027
+ let(:headers) { { 'Foo' => 'Bar' } }
1028
+ subject(:post_response) { client.subscriptions.resume(resource_id, body, headers) }
1029
+
1030
+ let(:resource_id) { 'ABC123' }
1031
+
1032
+ let!(:stub) do
1033
+ # /subscriptions/%v/actions/resume
1034
+ stub_url = '/subscriptions/:identity/actions/resume'.gsub(':identity', resource_id)
1035
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
1036
+ with(
1037
+ body: { foo: 'bar' },
1038
+ headers: { 'Foo' => 'Bar' }
1039
+ ).to_return(
1040
+ body: {
1041
+ 'subscriptions' => {
1042
+
1043
+ 'amount' => 'amount-input',
1044
+ 'app_fee' => 'app_fee-input',
1045
+ 'count' => 'count-input',
1046
+ 'created_at' => 'created_at-input',
1047
+ 'currency' => 'currency-input',
1048
+ 'day_of_month' => 'day_of_month-input',
1049
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
1050
+ 'end_date' => 'end_date-input',
1051
+ 'id' => 'id-input',
1052
+ 'interval' => 'interval-input',
1053
+ 'interval_unit' => 'interval_unit-input',
1054
+ 'links' => 'links-input',
1055
+ 'metadata' => 'metadata-input',
1056
+ 'month' => 'month-input',
1057
+ 'name' => 'name-input',
1058
+ 'payment_reference' => 'payment_reference-input',
1059
+ 'retry_if_possible' => 'retry_if_possible-input',
1060
+ 'start_date' => 'start_date-input',
1061
+ 'status' => 'status-input',
1062
+ 'upcoming_payments' => 'upcoming_payments-input',
1063
+ },
1064
+ }.to_json,
1065
+ headers: response_headers
1066
+ )
1067
+ end
1068
+ end
1069
+ end
1070
+
835
1071
  describe '#cancel' do
836
1072
  subject(:post_response) { client.subscriptions.cancel(resource_id) }
837
1073
 
@@ -846,9 +1082,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
846
1082
 
847
1083
  'amount' => 'amount-input',
848
1084
  'app_fee' => 'app_fee-input',
1085
+ 'count' => 'count-input',
849
1086
  'created_at' => 'created_at-input',
850
1087
  'currency' => 'currency-input',
851
1088
  'day_of_month' => 'day_of_month-input',
1089
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
852
1090
  'end_date' => 'end_date-input',
853
1091
  'id' => 'id-input',
854
1092
  'interval' => 'interval-input',
@@ -905,9 +1143,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
905
1143
 
906
1144
  'amount' => 'amount-input',
907
1145
  'app_fee' => 'app_fee-input',
1146
+ 'count' => 'count-input',
908
1147
  'created_at' => 'created_at-input',
909
1148
  'currency' => 'currency-input',
910
1149
  'day_of_month' => 'day_of_month-input',
1150
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
911
1151
  'end_date' => 'end_date-input',
912
1152
  'id' => 'id-input',
913
1153
  'interval' => 'interval-input',