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.
@@ -26,6 +26,7 @@ describe GoCardlessPro::Resources::Mandate 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::Resources::Mandate 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::Resources::Mandate 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,
@@ -119,6 +122,7 @@ describe GoCardlessPro::Resources::Mandate do
119
122
  'reference' => 'reference-input',
120
123
  'scheme' => 'scheme-input',
121
124
  'status' => 'status-input',
125
+ 'verified_at' => 'verified_at-input',
122
126
  }
123
127
  end
124
128
 
@@ -162,6 +166,7 @@ describe GoCardlessPro::Resources::Mandate do
162
166
  'reference' => 'reference-input',
163
167
  'scheme' => 'scheme-input',
164
168
  'status' => 'status-input',
169
+ 'verified_at' => 'verified_at-input',
165
170
  },
166
171
  }.to_json,
167
172
  headers: response_headers
@@ -196,6 +201,7 @@ describe GoCardlessPro::Resources::Mandate do
196
201
  'reference' => 'reference-input',
197
202
  'scheme' => 'scheme-input',
198
203
  'status' => 'status-input',
204
+ 'verified_at' => 'verified_at-input',
199
205
  }],
200
206
  meta: {
201
207
  cursors: {
@@ -230,6 +236,8 @@ describe GoCardlessPro::Resources::Mandate do
230
236
  expect(get_list_response.records.first.scheme).to eq('scheme-input')
231
237
 
232
238
  expect(get_list_response.records.first.status).to eq('status-input')
239
+
240
+ expect(get_list_response.records.first.verified_at).to eq('verified_at-input')
233
241
  end
234
242
 
235
243
  it 'exposes the cursors for before and after' do
@@ -258,6 +266,7 @@ describe GoCardlessPro::Resources::Mandate do
258
266
  'reference' => 'reference-input',
259
267
  'scheme' => 'scheme-input',
260
268
  'status' => 'status-input',
269
+ 'verified_at' => 'verified_at-input',
261
270
  }],
262
271
  meta: {
263
272
  cursors: { after: 'AB345' },
@@ -284,6 +293,7 @@ describe GoCardlessPro::Resources::Mandate do
284
293
  'reference' => 'reference-input',
285
294
  'scheme' => 'scheme-input',
286
295
  'status' => 'status-input',
296
+ 'verified_at' => 'verified_at-input',
287
297
  }],
288
298
  meta: {
289
299
  limit: 2,
@@ -326,6 +336,7 @@ describe GoCardlessPro::Resources::Mandate do
326
336
  'reference' => 'reference-input',
327
337
  'scheme' => 'scheme-input',
328
338
  'status' => 'status-input',
339
+ 'verified_at' => 'verified_at-input',
329
340
  },
330
341
  }.to_json,
331
342
  headers: response_headers
@@ -362,6 +373,7 @@ describe GoCardlessPro::Resources::Mandate do
362
373
  'reference' => 'reference-input',
363
374
  'scheme' => 'scheme-input',
364
375
  'status' => 'status-input',
376
+ 'verified_at' => 'verified_at-input',
365
377
  },
366
378
  }.to_json,
367
379
  headers: response_headers
@@ -420,6 +432,7 @@ describe GoCardlessPro::Resources::Mandate do
420
432
  'reference' => 'reference-input',
421
433
  'scheme' => 'scheme-input',
422
434
  'status' => 'status-input',
435
+ 'verified_at' => 'verified_at-input',
423
436
  },
424
437
  }.to_json,
425
438
  headers: response_headers
@@ -457,6 +470,7 @@ describe GoCardlessPro::Resources::Mandate do
457
470
  'reference' => 'reference-input',
458
471
  'scheme' => 'scheme-input',
459
472
  'status' => 'status-input',
473
+ 'verified_at' => 'verified_at-input',
460
474
  },
461
475
  }.to_json,
462
476
 
@@ -499,6 +513,7 @@ describe GoCardlessPro::Resources::Mandate do
499
513
  'reference' => 'reference-input',
500
514
  'scheme' => 'scheme-input',
501
515
  'status' => 'status-input',
516
+ 'verified_at' => 'verified_at-input',
502
517
  },
503
518
  }.to_json,
504
519
  headers: response_headers
@@ -531,6 +546,7 @@ describe GoCardlessPro::Resources::Mandate do
531
546
  'reference' => 'reference-input',
532
547
  'scheme' => 'scheme-input',
533
548
  'status' => 'status-input',
549
+ 'verified_at' => 'verified_at-input',
534
550
  },
535
551
  }.to_json,
536
552
 
@@ -573,6 +589,7 @@ describe GoCardlessPro::Resources::Mandate do
573
589
  'reference' => 'reference-input',
574
590
  'scheme' => 'scheme-input',
575
591
  'status' => 'status-input',
592
+ 'verified_at' => 'verified_at-input',
576
593
  },
577
594
  }.to_json,
578
595
  headers: response_headers
@@ -0,0 +1,484 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::SchemeIdentifier 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.scheme_identifiers.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
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
22
+ 'city' => 'city-input',
23
+ 'country_code' => 'country_code-input',
24
+ 'created_at' => 'created_at-input',
25
+ 'currency' => 'currency-input',
26
+ 'email' => 'email-input',
27
+ 'id' => 'id-input',
28
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
29
+ 'name' => 'name-input',
30
+ 'phone_number' => 'phone_number-input',
31
+ 'postal_code' => 'postal_code-input',
32
+ 'reference' => 'reference-input',
33
+ 'region' => 'region-input',
34
+ 'scheme' => 'scheme-input',
35
+ 'status' => 'status-input',
36
+ }
37
+ end
38
+
39
+ before do
40
+ stub_request(:post, %r{.*api.gocardless.com/scheme_identifiers}).
41
+ with(
42
+ body: {
43
+ 'scheme_identifiers' => {
44
+
45
+ 'address_line1' => 'address_line1-input',
46
+ 'address_line2' => 'address_line2-input',
47
+ 'address_line3' => 'address_line3-input',
48
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
49
+ 'city' => 'city-input',
50
+ 'country_code' => 'country_code-input',
51
+ 'created_at' => 'created_at-input',
52
+ 'currency' => 'currency-input',
53
+ 'email' => 'email-input',
54
+ 'id' => 'id-input',
55
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
56
+ 'name' => 'name-input',
57
+ 'phone_number' => 'phone_number-input',
58
+ 'postal_code' => 'postal_code-input',
59
+ 'reference' => 'reference-input',
60
+ 'region' => 'region-input',
61
+ 'scheme' => 'scheme-input',
62
+ 'status' => 'status-input',
63
+ },
64
+ }
65
+ ).
66
+ to_return(
67
+ body: {
68
+ 'scheme_identifiers' =>
69
+
70
+ {
71
+
72
+ 'address_line1' => 'address_line1-input',
73
+ 'address_line2' => 'address_line2-input',
74
+ 'address_line3' => 'address_line3-input',
75
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
76
+ 'city' => 'city-input',
77
+ 'country_code' => 'country_code-input',
78
+ 'created_at' => 'created_at-input',
79
+ 'currency' => 'currency-input',
80
+ 'email' => 'email-input',
81
+ 'id' => 'id-input',
82
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
83
+ 'name' => 'name-input',
84
+ 'phone_number' => 'phone_number-input',
85
+ 'postal_code' => 'postal_code-input',
86
+ 'reference' => 'reference-input',
87
+ 'region' => 'region-input',
88
+ 'scheme' => 'scheme-input',
89
+ 'status' => 'status-input',
90
+ },
91
+
92
+ }.to_json,
93
+ headers: response_headers
94
+ )
95
+ end
96
+
97
+ it 'creates and returns the resource' do
98
+ expect(post_create_response).to be_a(GoCardlessPro::Resources::SchemeIdentifier)
99
+ end
100
+ end
101
+
102
+ context 'with a request that returns a validation error' do
103
+ let(:new_resource) { {} }
104
+
105
+ before do
106
+ stub_request(:post, %r{.*api.gocardless.com/scheme_identifiers}).to_return(
107
+ body: {
108
+ error: {
109
+ type: 'validation_failed',
110
+ code: 422,
111
+ errors: [
112
+ { message: 'test error message', field: 'test_field' },
113
+ ],
114
+ },
115
+ }.to_json,
116
+ headers: response_headers,
117
+ status: 422
118
+ )
119
+ end
120
+
121
+ it 'throws the correct error' do
122
+ expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
123
+ end
124
+ end
125
+
126
+ context 'with a request that returns an idempotent creation conflict error' do
127
+ let(:id) { 'ID123' }
128
+
129
+ let(:new_resource) do
130
+ {
131
+
132
+ 'address_line1' => 'address_line1-input',
133
+ 'address_line2' => 'address_line2-input',
134
+ 'address_line3' => 'address_line3-input',
135
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
136
+ 'city' => 'city-input',
137
+ 'country_code' => 'country_code-input',
138
+ 'created_at' => 'created_at-input',
139
+ 'currency' => 'currency-input',
140
+ 'email' => 'email-input',
141
+ 'id' => 'id-input',
142
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
143
+ 'name' => 'name-input',
144
+ 'phone_number' => 'phone_number-input',
145
+ 'postal_code' => 'postal_code-input',
146
+ 'reference' => 'reference-input',
147
+ 'region' => 'region-input',
148
+ 'scheme' => 'scheme-input',
149
+ 'status' => 'status-input',
150
+ }
151
+ end
152
+
153
+ let!(:post_stub) do
154
+ stub_request(:post, %r{.*api.gocardless.com/scheme_identifiers}).to_return(
155
+ body: {
156
+ error: {
157
+ type: 'invalid_state',
158
+ code: 409,
159
+ errors: [
160
+ {
161
+ message: 'A resource has already been created with this idempotency key',
162
+ reason: 'idempotent_creation_conflict',
163
+ links: {
164
+ conflicting_resource_id: id,
165
+ },
166
+ },
167
+ ],
168
+ },
169
+ }.to_json,
170
+ headers: response_headers,
171
+ status: 409
172
+ )
173
+ end
174
+
175
+ let!(:get_stub) do
176
+ stub_url = "/scheme_identifiers/#{id}"
177
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
178
+ to_return(
179
+ body: {
180
+ 'scheme_identifiers' => {
181
+
182
+ 'address_line1' => 'address_line1-input',
183
+ 'address_line2' => 'address_line2-input',
184
+ 'address_line3' => 'address_line3-input',
185
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
186
+ 'city' => 'city-input',
187
+ 'country_code' => 'country_code-input',
188
+ 'created_at' => 'created_at-input',
189
+ 'currency' => 'currency-input',
190
+ 'email' => 'email-input',
191
+ 'id' => 'id-input',
192
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
193
+ 'name' => 'name-input',
194
+ 'phone_number' => 'phone_number-input',
195
+ 'postal_code' => 'postal_code-input',
196
+ 'reference' => 'reference-input',
197
+ 'region' => 'region-input',
198
+ 'scheme' => 'scheme-input',
199
+ 'status' => 'status-input',
200
+ },
201
+ }.to_json,
202
+ headers: response_headers
203
+ )
204
+ end
205
+
206
+ it 'fetches the already-created resource' do
207
+ post_create_response
208
+ expect(post_stub).to have_been_requested
209
+ expect(get_stub).to have_been_requested
210
+ end
211
+ end
212
+ end
213
+
214
+ describe '#list' do
215
+ describe 'with no filters' do
216
+ subject(:get_list_response) { client.scheme_identifiers.list }
217
+
218
+ before do
219
+ stub_request(:get, %r{.*api.gocardless.com/scheme_identifiers}).to_return(
220
+ body: {
221
+ 'scheme_identifiers' => [{
222
+
223
+ 'address_line1' => 'address_line1-input',
224
+ 'address_line2' => 'address_line2-input',
225
+ 'address_line3' => 'address_line3-input',
226
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
227
+ 'city' => 'city-input',
228
+ 'country_code' => 'country_code-input',
229
+ 'created_at' => 'created_at-input',
230
+ 'currency' => 'currency-input',
231
+ 'email' => 'email-input',
232
+ 'id' => 'id-input',
233
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
234
+ 'name' => 'name-input',
235
+ 'phone_number' => 'phone_number-input',
236
+ 'postal_code' => 'postal_code-input',
237
+ 'reference' => 'reference-input',
238
+ 'region' => 'region-input',
239
+ 'scheme' => 'scheme-input',
240
+ 'status' => 'status-input',
241
+ }],
242
+ meta: {
243
+ cursors: {
244
+ before: nil,
245
+ after: 'ABC123',
246
+ },
247
+ },
248
+ }.to_json,
249
+ headers: response_headers
250
+ )
251
+ end
252
+
253
+ it 'wraps each item in the resource class' do
254
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::SchemeIdentifier)
255
+
256
+ expect(get_list_response.records.first.address_line1).to eq('address_line1-input')
257
+
258
+ expect(get_list_response.records.first.address_line2).to eq('address_line2-input')
259
+
260
+ expect(get_list_response.records.first.address_line3).to eq('address_line3-input')
261
+
262
+ expect(get_list_response.records.first.can_specify_mandate_reference).to eq('can_specify_mandate_reference-input')
263
+
264
+ expect(get_list_response.records.first.city).to eq('city-input')
265
+
266
+ expect(get_list_response.records.first.country_code).to eq('country_code-input')
267
+
268
+ expect(get_list_response.records.first.created_at).to eq('created_at-input')
269
+
270
+ expect(get_list_response.records.first.currency).to eq('currency-input')
271
+
272
+ expect(get_list_response.records.first.email).to eq('email-input')
273
+
274
+ expect(get_list_response.records.first.id).to eq('id-input')
275
+
276
+ expect(get_list_response.records.first.minimum_advance_notice).to eq('minimum_advance_notice-input')
277
+
278
+ expect(get_list_response.records.first.name).to eq('name-input')
279
+
280
+ expect(get_list_response.records.first.phone_number).to eq('phone_number-input')
281
+
282
+ expect(get_list_response.records.first.postal_code).to eq('postal_code-input')
283
+
284
+ expect(get_list_response.records.first.reference).to eq('reference-input')
285
+
286
+ expect(get_list_response.records.first.region).to eq('region-input')
287
+
288
+ expect(get_list_response.records.first.scheme).to eq('scheme-input')
289
+
290
+ expect(get_list_response.records.first.status).to eq('status-input')
291
+ end
292
+
293
+ it 'exposes the cursors for before and after' do
294
+ expect(get_list_response.before).to eq(nil)
295
+ expect(get_list_response.after).to eq('ABC123')
296
+ end
297
+
298
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
299
+ end
300
+ end
301
+
302
+ describe '#all' do
303
+ let!(:first_response_stub) do
304
+ stub_request(:get, %r{.*api.gocardless.com/scheme_identifiers$}).to_return(
305
+ body: {
306
+ 'scheme_identifiers' => [{
307
+
308
+ 'address_line1' => 'address_line1-input',
309
+ 'address_line2' => 'address_line2-input',
310
+ 'address_line3' => 'address_line3-input',
311
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
312
+ 'city' => 'city-input',
313
+ 'country_code' => 'country_code-input',
314
+ 'created_at' => 'created_at-input',
315
+ 'currency' => 'currency-input',
316
+ 'email' => 'email-input',
317
+ 'id' => 'id-input',
318
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
319
+ 'name' => 'name-input',
320
+ 'phone_number' => 'phone_number-input',
321
+ 'postal_code' => 'postal_code-input',
322
+ 'reference' => 'reference-input',
323
+ 'region' => 'region-input',
324
+ 'scheme' => 'scheme-input',
325
+ 'status' => 'status-input',
326
+ }],
327
+ meta: {
328
+ cursors: { after: 'AB345' },
329
+ limit: 1,
330
+ },
331
+ }.to_json,
332
+ headers: response_headers
333
+ )
334
+ end
335
+
336
+ let!(:second_response_stub) do
337
+ stub_request(:get, %r{.*api.gocardless.com/scheme_identifiers\?after=AB345}).to_return(
338
+ body: {
339
+ 'scheme_identifiers' => [{
340
+
341
+ 'address_line1' => 'address_line1-input',
342
+ 'address_line2' => 'address_line2-input',
343
+ 'address_line3' => 'address_line3-input',
344
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
345
+ 'city' => 'city-input',
346
+ 'country_code' => 'country_code-input',
347
+ 'created_at' => 'created_at-input',
348
+ 'currency' => 'currency-input',
349
+ 'email' => 'email-input',
350
+ 'id' => 'id-input',
351
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
352
+ 'name' => 'name-input',
353
+ 'phone_number' => 'phone_number-input',
354
+ 'postal_code' => 'postal_code-input',
355
+ 'reference' => 'reference-input',
356
+ 'region' => 'region-input',
357
+ 'scheme' => 'scheme-input',
358
+ 'status' => 'status-input',
359
+ }],
360
+ meta: {
361
+ limit: 2,
362
+ cursors: {},
363
+ },
364
+ }.to_json,
365
+ headers: response_headers
366
+ )
367
+ end
368
+
369
+ it 'automatically makes the extra requests' do
370
+ expect(client.scheme_identifiers.all.to_a.length).to eq(2)
371
+ expect(first_response_stub).to have_been_requested
372
+ expect(second_response_stub).to have_been_requested
373
+ end
374
+ end
375
+
376
+ describe '#get' do
377
+ let(:id) { 'ID123' }
378
+
379
+ subject(:get_response) { client.scheme_identifiers.get(id) }
380
+
381
+ context 'passing in a custom header' do
382
+ let!(:stub) do
383
+ stub_url = '/scheme_identifiers/:identity'.gsub(':identity', id)
384
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
385
+ with(headers: { 'Foo' => 'Bar' }).
386
+ to_return(
387
+ body: {
388
+ 'scheme_identifiers' => {
389
+
390
+ 'address_line1' => 'address_line1-input',
391
+ 'address_line2' => 'address_line2-input',
392
+ 'address_line3' => 'address_line3-input',
393
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
394
+ 'city' => 'city-input',
395
+ 'country_code' => 'country_code-input',
396
+ 'created_at' => 'created_at-input',
397
+ 'currency' => 'currency-input',
398
+ 'email' => 'email-input',
399
+ 'id' => 'id-input',
400
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
401
+ 'name' => 'name-input',
402
+ 'phone_number' => 'phone_number-input',
403
+ 'postal_code' => 'postal_code-input',
404
+ 'reference' => 'reference-input',
405
+ 'region' => 'region-input',
406
+ 'scheme' => 'scheme-input',
407
+ 'status' => 'status-input',
408
+ },
409
+ }.to_json,
410
+ headers: response_headers
411
+ )
412
+ end
413
+
414
+ subject(:get_response) do
415
+ client.scheme_identifiers.get(id, headers: {
416
+ 'Foo' => 'Bar',
417
+ })
418
+ end
419
+
420
+ it 'includes the header' do
421
+ get_response
422
+ expect(stub).to have_been_requested
423
+ end
424
+ end
425
+
426
+ context 'when there is a scheme_identifier to return' do
427
+ before do
428
+ stub_url = '/scheme_identifiers/:identity'.gsub(':identity', id)
429
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
430
+ body: {
431
+ 'scheme_identifiers' => {
432
+
433
+ 'address_line1' => 'address_line1-input',
434
+ 'address_line2' => 'address_line2-input',
435
+ 'address_line3' => 'address_line3-input',
436
+ 'can_specify_mandate_reference' => 'can_specify_mandate_reference-input',
437
+ 'city' => 'city-input',
438
+ 'country_code' => 'country_code-input',
439
+ 'created_at' => 'created_at-input',
440
+ 'currency' => 'currency-input',
441
+ 'email' => 'email-input',
442
+ 'id' => 'id-input',
443
+ 'minimum_advance_notice' => 'minimum_advance_notice-input',
444
+ 'name' => 'name-input',
445
+ 'phone_number' => 'phone_number-input',
446
+ 'postal_code' => 'postal_code-input',
447
+ 'reference' => 'reference-input',
448
+ 'region' => 'region-input',
449
+ 'scheme' => 'scheme-input',
450
+ 'status' => 'status-input',
451
+ },
452
+ }.to_json,
453
+ headers: response_headers
454
+ )
455
+ end
456
+
457
+ it 'wraps the response in a resource' do
458
+ expect(get_response).to be_a(GoCardlessPro::Resources::SchemeIdentifier)
459
+ end
460
+ end
461
+
462
+ context 'when nothing is returned' do
463
+ before do
464
+ stub_url = '/scheme_identifiers/:identity'.gsub(':identity', id)
465
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
466
+ body: '',
467
+ headers: response_headers
468
+ )
469
+ end
470
+
471
+ it 'returns nil' do
472
+ expect(get_response).to be_nil
473
+ end
474
+ end
475
+
476
+ context "when an ID is specified which can't be included in a valid URI" do
477
+ let(:id) { '`' }
478
+
479
+ it "doesn't raise an error" do
480
+ expect { get_response }.to_not raise_error(/bad URI/)
481
+ end
482
+ end
483
+ end
484
+ end