gocardless_pro 2.18.0 → 2.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +25 -43
  3. data/Gemfile +7 -0
  4. data/gocardless_pro.gemspec +2 -2
  5. data/lib/gocardless_pro/api_service.rb +1 -1
  6. data/lib/gocardless_pro/client.rb +1 -1
  7. data/lib/gocardless_pro/resources/creditor_bank_account.rb +1 -2
  8. data/lib/gocardless_pro/resources/customer_notification.rb +3 -5
  9. data/lib/gocardless_pro/resources/event.rb +2 -1
  10. data/lib/gocardless_pro/resources/mandate_import.rb +5 -8
  11. data/lib/gocardless_pro/resources/mandate_import_entry.rb +3 -5
  12. data/lib/gocardless_pro/resources/payout.rb +2 -0
  13. data/lib/gocardless_pro/resources/redirect_flow.rb +2 -0
  14. data/lib/gocardless_pro/resources/subscription.rb +36 -29
  15. data/lib/gocardless_pro/services/customers_service.rb +1 -2
  16. data/lib/gocardless_pro/services/instalment_schedules_service.rb +21 -0
  17. data/lib/gocardless_pro/services/mandates_service.rb +1 -1
  18. data/lib/gocardless_pro/services/payouts_service.rb +21 -0
  19. data/lib/gocardless_pro/services/subscriptions_service.rb +129 -0
  20. data/lib/gocardless_pro/version.rb +1 -1
  21. data/spec/resources/instalment_schedule_spec.rb +35 -0
  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 +195 -0
  25. data/spec/services/creditor_bank_accounts_service_spec.rb +1 -1
  26. data/spec/services/customer_bank_accounts_service_spec.rb +1 -1
  27. data/spec/services/customer_notifications_service_spec.rb +1 -1
  28. data/spec/services/customers_service_spec.rb +1 -1
  29. data/spec/services/instalment_schedules_service_spec.rb +61 -1
  30. data/spec/services/mandate_imports_service_spec.rb +2 -2
  31. data/spec/services/mandates_service_spec.rb +2 -2
  32. data/spec/services/payments_service_spec.rb +2 -2
  33. data/spec/services/payouts_service_spec.rb +74 -0
  34. data/spec/services/redirect_flows_service_spec.rb +10 -1
  35. data/spec/services/subscriptions_service_spec.rb +222 -1
  36. metadata +7 -8
  37. data/gocardless_pro-2.17.1.gem +0 -0
@@ -692,7 +692,7 @@ describe GoCardlessPro::Services::CreditorBankAccountsService do
692
692
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
693
693
  to_timeout
694
694
 
695
- expect { post_response }.to raise_error(Faraday::TimeoutError)
695
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
696
696
  expect(stub).to have_been_requested
697
697
  end
698
698
  end
@@ -754,7 +754,7 @@ describe GoCardlessPro::Services::CustomerBankAccountsService do
754
754
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
755
755
  to_timeout
756
756
 
757
- expect { post_response }.to raise_error(Faraday::TimeoutError)
757
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
758
758
  expect(stub).to have_been_requested
759
759
  end
760
760
  end
@@ -45,7 +45,7 @@ describe GoCardlessPro::Services::CustomerNotificationsService do
45
45
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
46
46
  to_timeout
47
47
 
48
- expect { post_response }.to raise_error(Faraday::TimeoutError)
48
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
49
49
  expect(stub).to have_been_requested
50
50
  end
51
51
  end
@@ -882,7 +882,7 @@ describe GoCardlessPro::Services::CustomersService do
882
882
  stub = stub_request(:delete, /.*api.gocardless.com#{stub_url}/).
883
883
  to_timeout
884
884
 
885
- expect { delete_response }.to raise_error(Faraday::TimeoutError)
885
+ expect { delete_response }.to raise_error(Faraday::ConnectionFailed)
886
886
  expect(stub).to have_been_requested
887
887
  end
888
888
  end
@@ -828,6 +828,66 @@ describe GoCardlessPro::Services::InstalmentSchedulesService do
828
828
  end
829
829
  end
830
830
 
831
+ describe '#update' do
832
+ subject(:put_update_response) { client.instalment_schedules.update(id, params: update_params) }
833
+ let(:id) { 'ABC123' }
834
+
835
+ context 'with a valid request' do
836
+ let(:update_params) { { 'hello' => 'world' } }
837
+
838
+ let!(:stub) do
839
+ stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
840
+ stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
841
+ body: {
842
+ 'instalment_schedules' => {
843
+
844
+ 'created_at' => 'created_at-input',
845
+ 'currency' => 'currency-input',
846
+ 'id' => 'id-input',
847
+ 'links' => 'links-input',
848
+ 'metadata' => 'metadata-input',
849
+ 'name' => 'name-input',
850
+ 'payment_errors' => 'payment_errors-input',
851
+ 'status' => 'status-input',
852
+ 'total_amount' => 'total_amount-input',
853
+ },
854
+ }.to_json,
855
+ headers: response_headers
856
+ )
857
+ end
858
+
859
+ it 'updates and returns the resource' do
860
+ expect(put_update_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
861
+ expect(stub).to have_been_requested
862
+ end
863
+
864
+ describe 'retry behaviour' do
865
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
866
+
867
+ it 'retries timeouts' do
868
+ stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
869
+ stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
870
+ to_timeout.then.to_return(status: 200, headers: response_headers)
871
+
872
+ put_update_response
873
+ expect(stub).to have_been_requested.twice
874
+ end
875
+
876
+ it 'retries 5XX errors' do
877
+ stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
878
+ stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
879
+ to_return(status: 502,
880
+ headers: { 'Content-Type' => 'text/html' },
881
+ body: '<html><body>Response from Cloudflare</body></html>').
882
+ then.to_return(status: 200, headers: response_headers)
883
+
884
+ put_update_response
885
+ expect(stub).to have_been_requested.twice
886
+ end
887
+ end
888
+ end
889
+ end
890
+
831
891
  describe '#cancel' do
832
892
  subject(:post_response) { client.instalment_schedules.cancel(resource_id) }
833
893
 
@@ -867,7 +927,7 @@ describe GoCardlessPro::Services::InstalmentSchedulesService do
867
927
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
868
928
  to_timeout
869
929
 
870
- expect { post_response }.to raise_error(Faraday::TimeoutError)
930
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
871
931
  expect(stub).to have_been_requested
872
932
  end
873
933
  end
@@ -363,7 +363,7 @@ describe GoCardlessPro::Services::MandateImportsService do
363
363
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
364
364
  to_timeout
365
365
 
366
- expect { post_response }.to raise_error(Faraday::TimeoutError)
366
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
367
367
  expect(stub).to have_been_requested
368
368
  end
369
369
  end
@@ -432,7 +432,7 @@ describe GoCardlessPro::Services::MandateImportsService do
432
432
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
433
433
  to_timeout
434
434
 
435
- expect { post_response }.to raise_error(Faraday::TimeoutError)
435
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
436
436
  expect(stub).to have_been_requested
437
437
  end
438
438
  end
@@ -718,7 +718,7 @@ describe GoCardlessPro::Services::MandatesService do
718
718
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
719
719
  to_timeout
720
720
 
721
- expect { post_response }.to raise_error(Faraday::TimeoutError)
721
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
722
722
  expect(stub).to have_been_requested
723
723
  end
724
724
  end
@@ -797,7 +797,7 @@ describe GoCardlessPro::Services::MandatesService do
797
797
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
798
798
  to_timeout
799
799
 
800
- expect { post_response }.to raise_error(Faraday::TimeoutError)
800
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
801
801
  expect(stub).to have_been_requested
802
802
  end
803
803
  end
@@ -790,7 +790,7 @@ describe GoCardlessPro::Services::PaymentsService do
790
790
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
791
791
  to_timeout
792
792
 
793
- expect { post_response }.to raise_error(Faraday::TimeoutError)
793
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
794
794
  expect(stub).to have_been_requested
795
795
  end
796
796
  end
@@ -877,7 +877,7 @@ describe GoCardlessPro::Services::PaymentsService do
877
877
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
878
878
  to_timeout
879
879
 
880
- expect { post_response }.to raise_error(Faraday::TimeoutError)
880
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
881
881
  expect(stub).to have_been_requested
882
882
  end
883
883
  end
@@ -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',
@@ -403,7 +411,7 @@ describe GoCardlessPro::Services::RedirectFlowsService do
403
411
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
404
412
  to_timeout
405
413
 
406
- expect { post_response }.to raise_error(Faraday::TimeoutError)
414
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
407
415
  expect(stub).to have_been_requested
408
416
  end
409
417
  end
@@ -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',
@@ -21,6 +21,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
21
21
  'created_at' => 'created_at-input',
22
22
  'currency' => 'currency-input',
23
23
  'day_of_month' => 'day_of_month-input',
24
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
24
25
  'end_date' => 'end_date-input',
25
26
  'id' => 'id-input',
26
27
  'interval' => 'interval-input',
@@ -49,6 +50,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
49
50
  'created_at' => 'created_at-input',
50
51
  'currency' => 'currency-input',
51
52
  'day_of_month' => 'day_of_month-input',
53
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
52
54
  'end_date' => 'end_date-input',
53
55
  'id' => 'id-input',
54
56
  'interval' => 'interval-input',
@@ -77,6 +79,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
77
79
  'created_at' => 'created_at-input',
78
80
  'currency' => 'currency-input',
79
81
  'day_of_month' => 'day_of_month-input',
82
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
80
83
  'end_date' => 'end_date-input',
81
84
  'id' => 'id-input',
82
85
  'interval' => 'interval-input',
@@ -161,6 +164,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
161
164
  'created_at' => 'created_at-input',
162
165
  'currency' => 'currency-input',
163
166
  'day_of_month' => 'day_of_month-input',
167
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
164
168
  'end_date' => 'end_date-input',
165
169
  'id' => 'id-input',
166
170
  'interval' => 'interval-input',
@@ -212,6 +216,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
212
216
  'created_at' => 'created_at-input',
213
217
  'currency' => 'currency-input',
214
218
  'day_of_month' => 'day_of_month-input',
219
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
215
220
  'end_date' => 'end_date-input',
216
221
  'id' => 'id-input',
217
222
  'interval' => 'interval-input',
@@ -282,6 +287,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
282
287
  'created_at' => 'created_at-input',
283
288
  'currency' => 'currency-input',
284
289
  'day_of_month' => 'day_of_month-input',
290
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
285
291
  'end_date' => 'end_date-input',
286
292
  'id' => 'id-input',
287
293
  'interval' => 'interval-input',
@@ -327,6 +333,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
327
333
 
328
334
  expect(get_list_response.records.first.day_of_month).to eq('day_of_month-input')
329
335
 
336
+ expect(get_list_response.records.first.earliest_charge_date_after_resume).to eq('earliest_charge_date_after_resume-input')
337
+
330
338
  expect(get_list_response.records.first.end_date).to eq('end_date-input')
331
339
 
332
340
  expect(get_list_response.records.first.id).to eq('id-input')
@@ -396,6 +404,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
396
404
  'created_at' => 'created_at-input',
397
405
  'currency' => 'currency-input',
398
406
  'day_of_month' => 'day_of_month-input',
407
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
399
408
  'end_date' => 'end_date-input',
400
409
  'id' => 'id-input',
401
410
  'interval' => 'interval-input',
@@ -430,6 +439,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
430
439
  'created_at' => 'created_at-input',
431
440
  'currency' => 'currency-input',
432
441
  'day_of_month' => 'day_of_month-input',
442
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
433
443
  'end_date' => 'end_date-input',
434
444
  'id' => 'id-input',
435
445
  'interval' => 'interval-input',
@@ -473,6 +483,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
473
483
  'created_at' => 'created_at-input',
474
484
  'currency' => 'currency-input',
475
485
  'day_of_month' => 'day_of_month-input',
486
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
476
487
  'end_date' => 'end_date-input',
477
488
  'id' => 'id-input',
478
489
  'interval' => 'interval-input',
@@ -507,6 +518,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
507
518
  'created_at' => 'created_at-input',
508
519
  'currency' => 'currency-input',
509
520
  'day_of_month' => 'day_of_month-input',
521
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
510
522
  'end_date' => 'end_date-input',
511
523
  'id' => 'id-input',
512
524
  'interval' => 'interval-input',
@@ -546,6 +558,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
546
558
  'created_at' => 'created_at-input',
547
559
  'currency' => 'currency-input',
548
560
  'day_of_month' => 'day_of_month-input',
561
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
549
562
  'end_date' => 'end_date-input',
550
563
  'id' => 'id-input',
551
564
  'interval' => 'interval-input',
@@ -583,6 +596,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
583
596
  'created_at' => 'created_at-input',
584
597
  'currency' => 'currency-input',
585
598
  'day_of_month' => 'day_of_month-input',
599
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
586
600
  'end_date' => 'end_date-input',
587
601
  'id' => 'id-input',
588
602
  'interval' => 'interval-input',
@@ -633,6 +647,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
633
647
  'created_at' => 'created_at-input',
634
648
  'currency' => 'currency-input',
635
649
  'day_of_month' => 'day_of_month-input',
650
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
636
651
  'end_date' => 'end_date-input',
637
652
  'id' => 'id-input',
638
653
  'interval' => 'interval-input',
@@ -677,6 +692,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
677
692
  'created_at' => 'created_at-input',
678
693
  'currency' => 'currency-input',
679
694
  'day_of_month' => 'day_of_month-input',
695
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
680
696
  'end_date' => 'end_date-input',
681
697
  'id' => 'id-input',
682
698
  'interval' => 'interval-input',
@@ -798,6 +814,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
798
814
  'created_at' => 'created_at-input',
799
815
  'currency' => 'currency-input',
800
816
  'day_of_month' => 'day_of_month-input',
817
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
801
818
  'end_date' => 'end_date-input',
802
819
  'id' => 'id-input',
803
820
  'interval' => 'interval-input',
@@ -849,6 +866,208 @@ describe GoCardlessPro::Services::SubscriptionsService do
849
866
  end
850
867
  end
851
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::ConnectionFailed)
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::ConnectionFailed)
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
+
852
1071
  describe '#cancel' do
853
1072
  subject(:post_response) { client.subscriptions.cancel(resource_id) }
854
1073
 
@@ -867,6 +1086,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
867
1086
  'created_at' => 'created_at-input',
868
1087
  'currency' => 'currency-input',
869
1088
  'day_of_month' => 'day_of_month-input',
1089
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
870
1090
  'end_date' => 'end_date-input',
871
1091
  'id' => 'id-input',
872
1092
  'interval' => 'interval-input',
@@ -898,7 +1118,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
898
1118
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
899
1119
  to_timeout
900
1120
 
901
- expect { post_response }.to raise_error(Faraday::TimeoutError)
1121
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
902
1122
  expect(stub).to have_been_requested
903
1123
  end
904
1124
  end
@@ -927,6 +1147,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
927
1147
  'created_at' => 'created_at-input',
928
1148
  'currency' => 'currency-input',
929
1149
  'day_of_month' => 'day_of_month-input',
1150
+ 'earliest_charge_date_after_resume' => 'earliest_charge_date_after_resume-input',
930
1151
  'end_date' => 'end_date-input',
931
1152
  'id' => 'id-input',
932
1153
  'interval' => 'interval-input',