gocardless_pro 2.40.0 → 2.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::VerificationDetail 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.verification_details.create(params: new_resource) }
14
+ context 'with a valid request' do
15
+ let(:new_resource) do
16
+ {
17
+
18
+ 'address_line1' => 'address_line1-input',
19
+ 'address_line2' => 'address_line2-input',
20
+ 'address_line3' => 'address_line3-input',
21
+ 'city' => 'city-input',
22
+ 'company_number' => 'company_number-input',
23
+ 'description' => 'description-input',
24
+ 'directors' => 'directors-input',
25
+ 'links' => 'links-input',
26
+ 'postal_code' => 'postal_code-input',
27
+ }
28
+ end
29
+
30
+ before do
31
+ stub_request(:post, %r{.*api.gocardless.com/verification_details}).
32
+ with(
33
+ body: {
34
+ 'verification_details' => {
35
+
36
+ 'address_line1' => 'address_line1-input',
37
+ 'address_line2' => 'address_line2-input',
38
+ 'address_line3' => 'address_line3-input',
39
+ 'city' => 'city-input',
40
+ 'company_number' => 'company_number-input',
41
+ 'description' => 'description-input',
42
+ 'directors' => 'directors-input',
43
+ 'links' => 'links-input',
44
+ 'postal_code' => 'postal_code-input',
45
+ },
46
+ }
47
+ ).
48
+ to_return(
49
+ body: {
50
+ 'verification_details' =>
51
+
52
+ {
53
+
54
+ 'address_line1' => 'address_line1-input',
55
+ 'address_line2' => 'address_line2-input',
56
+ 'address_line3' => 'address_line3-input',
57
+ 'city' => 'city-input',
58
+ 'company_number' => 'company_number-input',
59
+ 'description' => 'description-input',
60
+ 'directors' => 'directors-input',
61
+ 'links' => 'links-input',
62
+ 'postal_code' => 'postal_code-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::VerificationDetail)
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/verification_details}).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
+ 'address_line1' => 'address_line1-input',
106
+ 'address_line2' => 'address_line2-input',
107
+ 'address_line3' => 'address_line3-input',
108
+ 'city' => 'city-input',
109
+ 'company_number' => 'company_number-input',
110
+ 'description' => 'description-input',
111
+ 'directors' => 'directors-input',
112
+ 'links' => 'links-input',
113
+ 'postal_code' => 'postal_code-input',
114
+ }
115
+ end
116
+
117
+ let!(:post_stub) do
118
+ stub_request(:post, %r{.*api.gocardless.com/verification_details}).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
+ it 'raises an InvalidStateError' do
140
+ expect { post_create_response }.to raise_error(GoCardlessPro::InvalidStateError)
141
+ expect(post_stub).to have_been_requested
142
+ end
143
+ end
144
+ end
145
+ end
@@ -869,4 +869,109 @@ describe GoCardlessPro::Services::CreditorsService do
869
869
  end
870
870
  end
871
871
  end
872
+
873
+ describe '#apply_scheme_identifier' do
874
+ subject(:post_response) { client.creditors.apply_scheme_identifier(resource_id) }
875
+
876
+ let(:resource_id) { 'ABC123' }
877
+
878
+ let!(:stub) do
879
+ # /creditors/%v/actions/apply_scheme_identifier
880
+ stub_url = '/creditors/:identity/actions/apply_scheme_identifier'.gsub(':identity', resource_id)
881
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
882
+
883
+ body: {
884
+ 'creditors' => {
885
+
886
+ 'activated' => 'activated-input',
887
+ 'address_line1' => 'address_line1-input',
888
+ 'address_line2' => 'address_line2-input',
889
+ 'address_line3' => 'address_line3-input',
890
+ 'can_create_refunds' => 'can_create_refunds-input',
891
+ 'city' => 'city-input',
892
+ 'country_code' => 'country_code-input',
893
+ 'created_at' => 'created_at-input',
894
+ 'creditor_type' => 'creditor_type-input',
895
+ 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
896
+ 'fx_payout_currency' => 'fx_payout_currency-input',
897
+ 'id' => 'id-input',
898
+ 'links' => 'links-input',
899
+ 'logo_url' => 'logo_url-input',
900
+ 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
901
+ 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
902
+ 'name' => 'name-input',
903
+ 'postal_code' => 'postal_code-input',
904
+ 'region' => 'region-input',
905
+ 'scheme_identifiers' => 'scheme_identifiers-input',
906
+ 'verification_status' => 'verification_status-input',
907
+ },
908
+ }.to_json,
909
+
910
+ headers: response_headers
911
+ )
912
+ end
913
+
914
+ it 'wraps the response and calls the right endpoint' do
915
+ expect(post_response).to be_a(GoCardlessPro::Resources::Creditor)
916
+
917
+ expect(stub).to have_been_requested
918
+ end
919
+
920
+ describe 'retry behaviour' do
921
+ it "doesn't retry errors" do
922
+ stub_url = '/creditors/:identity/actions/apply_scheme_identifier'.gsub(':identity', resource_id)
923
+ stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
924
+ to_timeout
925
+
926
+ expect { post_response }.to raise_error(Faraday::ConnectionFailed)
927
+ expect(stub).to have_been_requested
928
+ end
929
+ end
930
+
931
+ context 'when the request needs a body and custom header' do
932
+ let(:body) { { foo: 'bar' } }
933
+ let(:headers) { { 'Foo' => 'Bar' } }
934
+ subject(:post_response) { client.creditors.apply_scheme_identifier(resource_id, body, headers) }
935
+
936
+ let(:resource_id) { 'ABC123' }
937
+
938
+ let!(:stub) do
939
+ # /creditors/%v/actions/apply_scheme_identifier
940
+ stub_url = '/creditors/:identity/actions/apply_scheme_identifier'.gsub(':identity', resource_id)
941
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
942
+ with(
943
+ body: { foo: 'bar' },
944
+ headers: { 'Foo' => 'Bar' }
945
+ ).to_return(
946
+ body: {
947
+ 'creditors' => {
948
+
949
+ 'activated' => 'activated-input',
950
+ 'address_line1' => 'address_line1-input',
951
+ 'address_line2' => 'address_line2-input',
952
+ 'address_line3' => 'address_line3-input',
953
+ 'can_create_refunds' => 'can_create_refunds-input',
954
+ 'city' => 'city-input',
955
+ 'country_code' => 'country_code-input',
956
+ 'created_at' => 'created_at-input',
957
+ 'creditor_type' => 'creditor_type-input',
958
+ 'custom_payment_pages_enabled' => 'custom_payment_pages_enabled-input',
959
+ 'fx_payout_currency' => 'fx_payout_currency-input',
960
+ 'id' => 'id-input',
961
+ 'links' => 'links-input',
962
+ 'logo_url' => 'logo_url-input',
963
+ 'mandate_imports_enabled' => 'mandate_imports_enabled-input',
964
+ 'merchant_responsible_for_notifications' => 'merchant_responsible_for_notifications-input',
965
+ 'name' => 'name-input',
966
+ 'postal_code' => 'postal_code-input',
967
+ 'region' => 'region-input',
968
+ 'scheme_identifiers' => 'scheme_identifiers-input',
969
+ 'verification_status' => 'verification_status-input',
970
+ },
971
+ }.to_json,
972
+ headers: response_headers
973
+ )
974
+ end
975
+ end
976
+ end
872
977
  end
@@ -26,6 +26,7 @@ describe GoCardlessPro::Services::MandatesService do
26
26
  'reference' => 'reference-input',
27
27
  'scheme' => 'scheme-input',
28
28
  'status' => 'status-input',
29
+ 'verified_at' => 'verified_at-input',
29
30
  }
30
31
  end
31
32
 
@@ -46,6 +47,7 @@ describe GoCardlessPro::Services::MandatesService do
46
47
  'reference' => 'reference-input',
47
48
  'scheme' => 'scheme-input',
48
49
  'status' => 'status-input',
50
+ 'verified_at' => 'verified_at-input',
49
51
  },
50
52
  }
51
53
  ).
@@ -66,6 +68,7 @@ describe GoCardlessPro::Services::MandatesService do
66
68
  'reference' => 'reference-input',
67
69
  'scheme' => 'scheme-input',
68
70
  'status' => 'status-input',
71
+ 'verified_at' => 'verified_at-input',
69
72
  },
70
73
 
71
74
  }.to_json,
@@ -142,6 +145,7 @@ describe GoCardlessPro::Services::MandatesService do
142
145
  'reference' => 'reference-input',
143
146
  'scheme' => 'scheme-input',
144
147
  'status' => 'status-input',
148
+ 'verified_at' => 'verified_at-input',
145
149
  }
146
150
  end
147
151
 
@@ -185,6 +189,7 @@ describe GoCardlessPro::Services::MandatesService do
185
189
  'reference' => 'reference-input',
186
190
  'scheme' => 'scheme-input',
187
191
  'status' => 'status-input',
192
+ 'verified_at' => 'verified_at-input',
188
193
  },
189
194
  }.to_json,
190
195
  headers: response_headers
@@ -234,6 +239,7 @@ describe GoCardlessPro::Services::MandatesService do
234
239
  'reference' => 'reference-input',
235
240
  'scheme' => 'scheme-input',
236
241
  'status' => 'status-input',
242
+ 'verified_at' => 'verified_at-input',
237
243
  }],
238
244
  meta: {
239
245
  cursors: {
@@ -273,6 +279,8 @@ describe GoCardlessPro::Services::MandatesService do
273
279
  expect(get_list_response.records.first.scheme).to eq('scheme-input')
274
280
 
275
281
  expect(get_list_response.records.first.status).to eq('status-input')
282
+
283
+ expect(get_list_response.records.first.verified_at).to eq('verified_at-input')
276
284
  end
277
285
 
278
286
  it 'exposes the cursors for before and after' do
@@ -324,6 +332,7 @@ describe GoCardlessPro::Services::MandatesService do
324
332
  'reference' => 'reference-input',
325
333
  'scheme' => 'scheme-input',
326
334
  'status' => 'status-input',
335
+ 'verified_at' => 'verified_at-input',
327
336
  }],
328
337
  meta: {
329
338
  cursors: { after: 'AB345' },
@@ -350,6 +359,7 @@ describe GoCardlessPro::Services::MandatesService do
350
359
  'reference' => 'reference-input',
351
360
  'scheme' => 'scheme-input',
352
361
  'status' => 'status-input',
362
+ 'verified_at' => 'verified_at-input',
353
363
  }],
354
364
  meta: {
355
365
  limit: 2,
@@ -385,6 +395,7 @@ describe GoCardlessPro::Services::MandatesService do
385
395
  'reference' => 'reference-input',
386
396
  'scheme' => 'scheme-input',
387
397
  'status' => 'status-input',
398
+ 'verified_at' => 'verified_at-input',
388
399
  }],
389
400
  meta: {
390
401
  cursors: { after: 'AB345' },
@@ -411,6 +422,7 @@ describe GoCardlessPro::Services::MandatesService do
411
422
  'reference' => 'reference-input',
412
423
  'scheme' => 'scheme-input',
413
424
  'status' => 'status-input',
425
+ 'verified_at' => 'verified_at-input',
414
426
  }],
415
427
  meta: {
416
428
  limit: 2,
@@ -442,6 +454,7 @@ describe GoCardlessPro::Services::MandatesService do
442
454
  'reference' => 'reference-input',
443
455
  'scheme' => 'scheme-input',
444
456
  'status' => 'status-input',
457
+ 'verified_at' => 'verified_at-input',
445
458
  }],
446
459
  meta: {
447
460
  cursors: { after: 'AB345' },
@@ -471,6 +484,7 @@ describe GoCardlessPro::Services::MandatesService do
471
484
  'reference' => 'reference-input',
472
485
  'scheme' => 'scheme-input',
473
486
  'status' => 'status-input',
487
+ 'verified_at' => 'verified_at-input',
474
488
  }],
475
489
  meta: {
476
490
  limit: 2,
@@ -513,6 +527,7 @@ describe GoCardlessPro::Services::MandatesService do
513
527
  'reference' => 'reference-input',
514
528
  'scheme' => 'scheme-input',
515
529
  'status' => 'status-input',
530
+ 'verified_at' => 'verified_at-input',
516
531
  },
517
532
  }.to_json,
518
533
  headers: response_headers
@@ -549,6 +564,7 @@ describe GoCardlessPro::Services::MandatesService do
549
564
  'reference' => 'reference-input',
550
565
  'scheme' => 'scheme-input',
551
566
  'status' => 'status-input',
567
+ 'verified_at' => 'verified_at-input',
552
568
  },
553
569
  }.to_json,
554
570
  headers: response_headers
@@ -662,6 +678,7 @@ describe GoCardlessPro::Services::MandatesService do
662
678
  'reference' => 'reference-input',
663
679
  'scheme' => 'scheme-input',
664
680
  'status' => 'status-input',
681
+ 'verified_at' => 'verified_at-input',
665
682
  },
666
683
  }.to_json,
667
684
  headers: response_headers
@@ -724,6 +741,7 @@ describe GoCardlessPro::Services::MandatesService do
724
741
  'reference' => 'reference-input',
725
742
  'scheme' => 'scheme-input',
726
743
  'status' => 'status-input',
744
+ 'verified_at' => 'verified_at-input',
727
745
  },
728
746
  }.to_json,
729
747
 
@@ -777,6 +795,7 @@ describe GoCardlessPro::Services::MandatesService do
777
795
  'reference' => 'reference-input',
778
796
  'scheme' => 'scheme-input',
779
797
  'status' => 'status-input',
798
+ 'verified_at' => 'verified_at-input',
780
799
  },
781
800
  }.to_json,
782
801
  headers: response_headers
@@ -809,6 +828,7 @@ describe GoCardlessPro::Services::MandatesService do
809
828
  'reference' => 'reference-input',
810
829
  'scheme' => 'scheme-input',
811
830
  'status' => 'status-input',
831
+ 'verified_at' => 'verified_at-input',
812
832
  },
813
833
  }.to_json,
814
834
 
@@ -862,6 +882,7 @@ describe GoCardlessPro::Services::MandatesService do
862
882
  'reference' => 'reference-input',
863
883
  'scheme' => 'scheme-input',
864
884
  'status' => 'status-input',
885
+ 'verified_at' => 'verified_at-input',
865
886
  },
866
887
  }.to_json,
867
888
  headers: response_headers