gocardless_pro 2.27.0 → 2.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +20 -1
  3. data/lib/gocardless_pro.rb +6 -0
  4. data/lib/gocardless_pro/api_service.rb +4 -0
  5. data/lib/gocardless_pro/client.rb +6 -1
  6. data/lib/gocardless_pro/error/authentication_error.rb +4 -0
  7. data/lib/gocardless_pro/error/permission_error.rb +4 -0
  8. data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
  9. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
  10. data/lib/gocardless_pro/resources/bank_authorisation.rb +3 -5
  11. data/lib/gocardless_pro/resources/billing_request.rb +29 -7
  12. data/lib/gocardless_pro/resources/billing_request_flow.rb +10 -0
  13. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  14. data/lib/gocardless_pro/resources/payer_authorisation.rb +9 -0
  15. data/lib/gocardless_pro/services/bank_authorisations_service.rb +0 -2
  16. data/lib/gocardless_pro/services/billing_request_flows_service.rb +23 -0
  17. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  18. data/lib/gocardless_pro/services/billing_requests_service.rb +49 -22
  19. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +0 -4
  20. data/lib/gocardless_pro/services/creditors_service.rb +0 -2
  21. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +0 -4
  22. data/lib/gocardless_pro/services/customers_service.rb +0 -2
  23. data/lib/gocardless_pro/services/instalment_schedules_service.rb +0 -6
  24. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  25. data/lib/gocardless_pro/services/mandates_service.rb +0 -6
  26. data/lib/gocardless_pro/services/payer_authorisations_service.rb +0 -6
  27. data/lib/gocardless_pro/services/payments_service.rb +0 -6
  28. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  29. data/lib/gocardless_pro/services/refunds_service.rb +0 -2
  30. data/lib/gocardless_pro/services/scenario_simulators_service.rb +28 -6
  31. data/lib/gocardless_pro/services/subscriptions_service.rb +2 -10
  32. data/lib/gocardless_pro/services/webhooks_service.rb +0 -2
  33. data/lib/gocardless_pro/version.rb +1 -1
  34. data/spec/api_service_spec.rb +12 -1
  35. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  36. data/spec/resources/bank_authorisation_spec.rb +7 -7
  37. data/spec/resources/billing_request_flow_spec.rb +90 -0
  38. data/spec/resources/billing_request_spec.rb +75 -29
  39. data/spec/resources/billing_request_template_spec.rb +502 -0
  40. data/spec/services/bank_authorisations_service_spec.rb +7 -20
  41. data/spec/services/billing_request_flows_service_spec.rb +101 -0
  42. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  43. data/spec/services/billing_requests_service_spec.rb +87 -47
  44. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -13
  45. data/spec/services/creditors_service_spec.rb +0 -13
  46. data/spec/services/customer_bank_accounts_service_spec.rb +0 -13
  47. data/spec/services/customers_service_spec.rb +0 -13
  48. data/spec/services/instalment_schedules_service_spec.rb +0 -26
  49. data/spec/services/mandate_imports_service_spec.rb +0 -13
  50. data/spec/services/mandates_service_spec.rb +0 -13
  51. data/spec/services/payer_authorisations_service_spec.rb +0 -13
  52. data/spec/services/payments_service_spec.rb +0 -13
  53. data/spec/services/redirect_flows_service_spec.rb +0 -13
  54. data/spec/services/refunds_service_spec.rb +0 -13
  55. data/spec/services/subscriptions_service_spec.rb +0 -13
  56. metadata +16 -7
@@ -18,7 +18,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
18
18
  'billing_requests' => [{
19
19
 
20
20
  'actions' => 'actions-input',
21
- 'auto_fulfil' => 'auto_fulfil-input',
22
21
  'created_at' => 'created_at-input',
23
22
  'id' => 'id-input',
24
23
  'links' => 'links-input',
@@ -49,8 +48,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
49
48
 
50
49
  expect(get_list_response.records.first.actions).to eq('actions-input')
51
50
 
52
- expect(get_list_response.records.first.auto_fulfil).to eq('auto_fulfil-input')
53
-
54
51
  expect(get_list_response.records.first.created_at).to eq('created_at-input')
55
52
 
56
53
  expect(get_list_response.records.first.id).to eq('id-input')
@@ -105,7 +102,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
105
102
  'billing_requests' => [{
106
103
 
107
104
  'actions' => 'actions-input',
108
- 'auto_fulfil' => 'auto_fulfil-input',
109
105
  'created_at' => 'created_at-input',
110
106
  'id' => 'id-input',
111
107
  'links' => 'links-input',
@@ -130,7 +126,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
130
126
  'billing_requests' => [{
131
127
 
132
128
  'actions' => 'actions-input',
133
- 'auto_fulfil' => 'auto_fulfil-input',
134
129
  'created_at' => 'created_at-input',
135
130
  'id' => 'id-input',
136
131
  'links' => 'links-input',
@@ -164,7 +159,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
164
159
  'billing_requests' => [{
165
160
 
166
161
  'actions' => 'actions-input',
167
- 'auto_fulfil' => 'auto_fulfil-input',
168
162
  'created_at' => 'created_at-input',
169
163
  'id' => 'id-input',
170
164
  'links' => 'links-input',
@@ -189,7 +183,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
189
183
  'billing_requests' => [{
190
184
 
191
185
  'actions' => 'actions-input',
192
- 'auto_fulfil' => 'auto_fulfil-input',
193
186
  'created_at' => 'created_at-input',
194
187
  'id' => 'id-input',
195
188
  'links' => 'links-input',
@@ -219,7 +212,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
219
212
  'billing_requests' => [{
220
213
 
221
214
  'actions' => 'actions-input',
222
- 'auto_fulfil' => 'auto_fulfil-input',
223
215
  'created_at' => 'created_at-input',
224
216
  'id' => 'id-input',
225
217
  'links' => 'links-input',
@@ -247,7 +239,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
247
239
  'billing_requests' => [{
248
240
 
249
241
  'actions' => 'actions-input',
250
- 'auto_fulfil' => 'auto_fulfil-input',
251
242
  'created_at' => 'created_at-input',
252
243
  'id' => 'id-input',
253
244
  'links' => 'links-input',
@@ -280,7 +271,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
280
271
  {
281
272
 
282
273
  'actions' => 'actions-input',
283
- 'auto_fulfil' => 'auto_fulfil-input',
284
274
  'created_at' => 'created_at-input',
285
275
  'id' => 'id-input',
286
276
  'links' => 'links-input',
@@ -299,7 +289,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
299
289
  'billing_requests' => {
300
290
 
301
291
  'actions' => 'actions-input',
302
- 'auto_fulfil' => 'auto_fulfil-input',
303
292
  'created_at' => 'created_at-input',
304
293
  'id' => 'id-input',
305
294
  'links' => 'links-input',
@@ -318,7 +307,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
318
307
  {
319
308
 
320
309
  'actions' => 'actions-input',
321
- 'auto_fulfil' => 'auto_fulfil-input',
322
310
  'created_at' => 'created_at-input',
323
311
  'id' => 'id-input',
324
312
  'links' => 'links-input',
@@ -393,7 +381,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
393
381
  {
394
382
 
395
383
  'actions' => 'actions-input',
396
- 'auto_fulfil' => 'auto_fulfil-input',
397
384
  'created_at' => 'created_at-input',
398
385
  'id' => 'id-input',
399
386
  'links' => 'links-input',
@@ -435,7 +422,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
435
422
  'billing_requests' => {
436
423
 
437
424
  'actions' => 'actions-input',
438
- 'auto_fulfil' => 'auto_fulfil-input',
439
425
  'created_at' => 'created_at-input',
440
426
  'id' => 'id-input',
441
427
  'links' => 'links-input',
@@ -471,19 +457,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
471
457
  to raise_error(GoCardlessPro::IdempotencyConflict)
472
458
  end
473
459
  end
474
-
475
- context 'with on_idempotency_conflict: :unknown' do
476
- let(:client) do
477
- GoCardlessPro::Client.new(
478
- access_token: 'SECRET_TOKEN',
479
- on_idempotency_conflict: :unknown
480
- )
481
- end
482
-
483
- it 'raises an ArgumentError' do
484
- expect { post_create_response }.to raise_error(ArgumentError)
485
- end
486
- end
487
460
  end
488
461
  end
489
462
 
@@ -502,7 +475,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
502
475
  'billing_requests' => {
503
476
 
504
477
  'actions' => 'actions-input',
505
- 'auto_fulfil' => 'auto_fulfil-input',
506
478
  'created_at' => 'created_at-input',
507
479
  'id' => 'id-input',
508
480
  'links' => 'links-input',
@@ -537,7 +509,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
537
509
  'billing_requests' => {
538
510
 
539
511
  'actions' => 'actions-input',
540
- 'auto_fulfil' => 'auto_fulfil-input',
541
512
  'created_at' => 'created_at-input',
542
513
  'id' => 'id-input',
543
514
  'links' => 'links-input',
@@ -648,7 +619,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
648
619
  'billing_requests' => {
649
620
 
650
621
  'actions' => 'actions-input',
651
- 'auto_fulfil' => 'auto_fulfil-input',
652
622
  'created_at' => 'created_at-input',
653
623
  'id' => 'id-input',
654
624
  'links' => 'links-input',
@@ -699,7 +669,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
699
669
  'billing_requests' => {
700
670
 
701
671
  'actions' => 'actions-input',
702
- 'auto_fulfil' => 'auto_fulfil-input',
703
672
  'created_at' => 'created_at-input',
704
673
  'id' => 'id-input',
705
674
  'links' => 'links-input',
@@ -716,20 +685,19 @@ describe GoCardlessPro::Services::BillingRequestsService do
716
685
  end
717
686
  end
718
687
 
719
- describe '#collect_bank_account_details' do
720
- subject(:post_response) { client.billing_requests.collect_bank_account_details(resource_id) }
688
+ describe '#collect_bank_account' do
689
+ subject(:post_response) { client.billing_requests.collect_bank_account(resource_id) }
721
690
 
722
691
  let(:resource_id) { 'ABC123' }
723
692
 
724
693
  let!(:stub) do
725
- # /billing_requests/%v/actions/collect_bank_account_details
726
- stub_url = '/billing_requests/:identity/actions/collect_bank_account_details'.gsub(':identity', resource_id)
694
+ # /billing_requests/%v/actions/collect_bank_account
695
+ stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
727
696
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
728
697
  body: {
729
698
  'billing_requests' => {
730
699
 
731
700
  'actions' => 'actions-input',
732
- 'auto_fulfil' => 'auto_fulfil-input',
733
701
  'created_at' => 'created_at-input',
734
702
  'id' => 'id-input',
735
703
  'links' => 'links-input',
@@ -752,7 +720,7 @@ describe GoCardlessPro::Services::BillingRequestsService do
752
720
 
753
721
  describe 'retry behaviour' do
754
722
  it "doesn't retry errors" do
755
- stub_url = '/billing_requests/:identity/actions/collect_bank_account_details'.gsub(':identity', resource_id)
723
+ stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
756
724
  stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
757
725
  to_timeout
758
726
 
@@ -764,13 +732,13 @@ describe GoCardlessPro::Services::BillingRequestsService do
764
732
  context 'when the request needs a body and custom header' do
765
733
  let(:body) { { foo: 'bar' } }
766
734
  let(:headers) { { 'Foo' => 'Bar' } }
767
- subject(:post_response) { client.billing_requests.collect_bank_account_details(resource_id, body, headers) }
735
+ subject(:post_response) { client.billing_requests.collect_bank_account(resource_id, body, headers) }
768
736
 
769
737
  let(:resource_id) { 'ABC123' }
770
738
 
771
739
  let!(:stub) do
772
- # /billing_requests/%v/actions/collect_bank_account_details
773
- stub_url = '/billing_requests/:identity/actions/collect_bank_account_details'.gsub(':identity', resource_id)
740
+ # /billing_requests/%v/actions/collect_bank_account
741
+ stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
774
742
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).
775
743
  with(
776
744
  body: { foo: 'bar' },
@@ -780,7 +748,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
780
748
  'billing_requests' => {
781
749
 
782
750
  'actions' => 'actions-input',
783
- 'auto_fulfil' => 'auto_fulfil-input',
784
751
  'created_at' => 'created_at-input',
785
752
  'id' => 'id-input',
786
753
  'links' => 'links-input',
@@ -810,7 +777,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
810
777
  'billing_requests' => {
811
778
 
812
779
  'actions' => 'actions-input',
813
- 'auto_fulfil' => 'auto_fulfil-input',
814
780
  'created_at' => 'created_at-input',
815
781
  'id' => 'id-input',
816
782
  'links' => 'links-input',
@@ -861,7 +827,85 @@ describe GoCardlessPro::Services::BillingRequestsService do
861
827
  'billing_requests' => {
862
828
 
863
829
  'actions' => 'actions-input',
864
- 'auto_fulfil' => 'auto_fulfil-input',
830
+ 'created_at' => 'created_at-input',
831
+ 'id' => 'id-input',
832
+ 'links' => 'links-input',
833
+ 'mandate_request' => 'mandate_request-input',
834
+ 'metadata' => 'metadata-input',
835
+ 'payment_request' => 'payment_request-input',
836
+ 'resources' => 'resources-input',
837
+ 'status' => 'status-input',
838
+ },
839
+ }.to_json,
840
+ headers: response_headers
841
+ )
842
+ end
843
+ end
844
+ end
845
+
846
+ describe '#confirm_payer_details' do
847
+ subject(:post_response) { client.billing_requests.confirm_payer_details(resource_id) }
848
+
849
+ let(:resource_id) { 'ABC123' }
850
+
851
+ let!(:stub) do
852
+ # /billing_requests/%v/actions/confirm_payer_details
853
+ stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
854
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
855
+ body: {
856
+ 'billing_requests' => {
857
+
858
+ 'actions' => 'actions-input',
859
+ 'created_at' => 'created_at-input',
860
+ 'id' => 'id-input',
861
+ 'links' => 'links-input',
862
+ 'mandate_request' => 'mandate_request-input',
863
+ 'metadata' => 'metadata-input',
864
+ 'payment_request' => 'payment_request-input',
865
+ 'resources' => 'resources-input',
866
+ 'status' => 'status-input',
867
+ },
868
+ }.to_json,
869
+ headers: response_headers
870
+ )
871
+ end
872
+
873
+ it 'wraps the response and calls the right endpoint' do
874
+ expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
875
+
876
+ expect(stub).to have_been_requested
877
+ end
878
+
879
+ describe 'retry behaviour' do
880
+ it "doesn't retry errors" do
881
+ stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
882
+ stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
883
+ to_timeout
884
+
885
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
886
+ expect(stub).to have_been_requested
887
+ end
888
+ end
889
+
890
+ context 'when the request needs a body and custom header' do
891
+ let(:body) { { foo: 'bar' } }
892
+ let(:headers) { { 'Foo' => 'Bar' } }
893
+ subject(:post_response) { client.billing_requests.confirm_payer_details(resource_id, body, headers) }
894
+
895
+ let(:resource_id) { 'ABC123' }
896
+
897
+ let!(:stub) do
898
+ # /billing_requests/%v/actions/confirm_payer_details
899
+ stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
900
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
901
+ with(
902
+ body: { foo: 'bar' },
903
+ headers: { 'Foo' => 'Bar' }
904
+ ).to_return(
905
+ body: {
906
+ 'billing_requests' => {
907
+
908
+ 'actions' => 'actions-input',
865
909
  'created_at' => 'created_at-input',
866
910
  'id' => 'id-input',
867
911
  'links' => 'links-input',
@@ -891,7 +935,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
891
935
  'billing_requests' => {
892
936
 
893
937
  'actions' => 'actions-input',
894
- 'auto_fulfil' => 'auto_fulfil-input',
895
938
  'created_at' => 'created_at-input',
896
939
  'id' => 'id-input',
897
940
  'links' => 'links-input',
@@ -942,7 +985,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
942
985
  'billing_requests' => {
943
986
 
944
987
  'actions' => 'actions-input',
945
- 'auto_fulfil' => 'auto_fulfil-input',
946
988
  'created_at' => 'created_at-input',
947
989
  'id' => 'id-input',
948
990
  'links' => 'links-input',
@@ -972,7 +1014,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
972
1014
  'billing_requests' => {
973
1015
 
974
1016
  'actions' => 'actions-input',
975
- 'auto_fulfil' => 'auto_fulfil-input',
976
1017
  'created_at' => 'created_at-input',
977
1018
  'id' => 'id-input',
978
1019
  'links' => 'links-input',
@@ -1023,7 +1064,6 @@ describe GoCardlessPro::Services::BillingRequestsService do
1023
1064
  'billing_requests' => {
1024
1065
 
1025
1066
  'actions' => 'actions-input',
1026
- 'auto_fulfil' => 'auto_fulfil-input',
1027
1067
  'created_at' => 'created_at-input',
1028
1068
  'id' => 'id-input',
1029
1069
  'links' => 'links-input',
@@ -212,19 +212,6 @@ describe GoCardlessPro::Services::CreditorBankAccountsService do
212
212
  to raise_error(GoCardlessPro::IdempotencyConflict)
213
213
  end
214
214
  end
215
-
216
- context 'with on_idempotency_conflict: :unknown' do
217
- let(:client) do
218
- GoCardlessPro::Client.new(
219
- access_token: 'SECRET_TOKEN',
220
- on_idempotency_conflict: :unknown
221
- )
222
- end
223
-
224
- it 'raises an ArgumentError' do
225
- expect { post_create_response }.to raise_error(ArgumentError)
226
- end
227
- end
228
215
  end
229
216
  end
230
217
 
@@ -252,19 +252,6 @@ describe GoCardlessPro::Services::CreditorsService do
252
252
  to raise_error(GoCardlessPro::IdempotencyConflict)
253
253
  end
254
254
  end
255
-
256
- context 'with on_idempotency_conflict: :unknown' do
257
- let(:client) do
258
- GoCardlessPro::Client.new(
259
- access_token: 'SECRET_TOKEN',
260
- on_idempotency_conflict: :unknown
261
- )
262
- end
263
-
264
- it 'raises an ArgumentError' do
265
- expect { post_create_response }.to raise_error(ArgumentError)
266
- end
267
- end
268
255
  end
269
256
  end
270
257
 
@@ -212,19 +212,6 @@ describe GoCardlessPro::Services::CustomerBankAccountsService do
212
212
  to raise_error(GoCardlessPro::IdempotencyConflict)
213
213
  end
214
214
  end
215
-
216
- context 'with on_idempotency_conflict: :unknown' do
217
- let(:client) do
218
- GoCardlessPro::Client.new(
219
- access_token: 'SECRET_TOKEN',
220
- on_idempotency_conflict: :unknown
221
- )
222
- end
223
-
224
- it 'raises an ArgumentError' do
225
- expect { post_create_response }.to raise_error(ArgumentError)
226
- end
227
- end
228
215
  end
229
216
  end
230
217
 
@@ -247,19 +247,6 @@ describe GoCardlessPro::Services::CustomersService do
247
247
  to raise_error(GoCardlessPro::IdempotencyConflict)
248
248
  end
249
249
  end
250
-
251
- context 'with on_idempotency_conflict: :unknown' do
252
- let(:client) do
253
- GoCardlessPro::Client.new(
254
- access_token: 'SECRET_TOKEN',
255
- on_idempotency_conflict: :unknown
256
- )
257
- end
258
-
259
- it 'raises an ArgumentError' do
260
- expect { post_create_response }.to raise_error(ArgumentError)
261
- end
262
- end
263
250
  end
264
251
  end
265
252
 
@@ -202,19 +202,6 @@ describe GoCardlessPro::Services::InstalmentSchedulesService do
202
202
  to raise_error(GoCardlessPro::IdempotencyConflict)
203
203
  end
204
204
  end
205
-
206
- context 'with on_idempotency_conflict: :unknown' do
207
- let(:client) do
208
- GoCardlessPro::Client.new(
209
- access_token: 'SECRET_TOKEN',
210
- on_idempotency_conflict: :unknown
211
- )
212
- end
213
-
214
- it 'raises an ArgumentError' do
215
- expect { post_create_response }.to raise_error(ArgumentError)
216
- end
217
- end
218
205
  end
219
206
  end
220
207
 
@@ -411,19 +398,6 @@ describe GoCardlessPro::Services::InstalmentSchedulesService do
411
398
  to raise_error(GoCardlessPro::IdempotencyConflict)
412
399
  end
413
400
  end
414
-
415
- context 'with on_idempotency_conflict: :unknown' do
416
- let(:client) do
417
- GoCardlessPro::Client.new(
418
- access_token: 'SECRET_TOKEN',
419
- on_idempotency_conflict: :unknown
420
- )
421
- end
422
-
423
- it 'raises an ArgumentError' do
424
- expect { post_create_response }.to raise_error(ArgumentError)
425
- end
426
- end
427
401
  end
428
402
  end
429
403