gocardless_pro 2.1.0 → 2.2.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/circle.yml +11 -3
  4. data/demo.rb +3 -3
  5. data/gocardless_pro.gemspec +6 -6
  6. data/lib/gocardless_pro.rb +2 -1
  7. data/lib/gocardless_pro/api_service.rb +3 -2
  8. data/lib/gocardless_pro/client.rb +6 -6
  9. data/lib/gocardless_pro/error.rb +4 -4
  10. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +4 -4
  11. data/lib/gocardless_pro/request.rb +2 -2
  12. data/lib/gocardless_pro/resources/bank_details_lookup.rb +1 -0
  13. data/lib/gocardless_pro/resources/creditor.rb +1 -0
  14. data/lib/gocardless_pro/resources/creditor_bank_account.rb +1 -0
  15. data/lib/gocardless_pro/resources/customer.rb +1 -0
  16. data/lib/gocardless_pro/resources/customer_bank_account.rb +1 -0
  17. data/lib/gocardless_pro/resources/event.rb +1 -0
  18. data/lib/gocardless_pro/resources/mandate.rb +1 -0
  19. data/lib/gocardless_pro/resources/mandate_pdf.rb +1 -0
  20. data/lib/gocardless_pro/resources/payment.rb +1 -0
  21. data/lib/gocardless_pro/resources/payout.rb +1 -0
  22. data/lib/gocardless_pro/resources/redirect_flow.rb +1 -0
  23. data/lib/gocardless_pro/resources/refund.rb +1 -0
  24. data/lib/gocardless_pro/resources/subscription.rb +1 -0
  25. data/lib/gocardless_pro/services/base_service.rb +1 -1
  26. data/lib/gocardless_pro/version.rb +1 -1
  27. data/spec/api_service_spec.rb +49 -49
  28. data/spec/client_spec.rb +1 -1
  29. data/spec/error_spec.rb +13 -13
  30. data/spec/middlewares/raise_gocardless_errors_spec.rb +15 -16
  31. data/spec/resources/bank_details_lookup_spec.rb +18 -18
  32. data/spec/resources/creditor_bank_account_spec.rb +46 -46
  33. data/spec/resources/creditor_spec.rb +42 -42
  34. data/spec/resources/customer_bank_account_spec.rb +48 -48
  35. data/spec/resources/customer_spec.rb +42 -42
  36. data/spec/resources/event_spec.rb +18 -18
  37. data/spec/resources/mandate_pdf_spec.rb +18 -18
  38. data/spec/resources/mandate_spec.rb +54 -54
  39. data/spec/resources/payment_spec.rb +54 -54
  40. data/spec/resources/payout_spec.rb +18 -18
  41. data/spec/resources/redirect_flow_spec.rb +36 -36
  42. data/spec/resources/refund_spec.rb +42 -42
  43. data/spec/resources/subscription_spec.rb +48 -48
  44. data/spec/response_spec.rb +1 -2
  45. data/spec/services/bank_details_lookups_service_spec.rb +25 -25
  46. data/spec/services/creditor_bank_accounts_service_spec.rb +86 -86
  47. data/spec/services/creditors_service_spec.rb +87 -87
  48. data/spec/services/customer_bank_accounts_service_spec.rb +95 -95
  49. data/spec/services/customers_service_spec.rb +87 -87
  50. data/spec/services/events_service_spec.rb +49 -49
  51. data/spec/services/mandate_pdfs_service_spec.rb +25 -25
  52. data/spec/services/mandates_service_spec.rb +103 -103
  53. data/spec/services/payments_service_spec.rb +103 -103
  54. data/spec/services/payouts_service_spec.rb +49 -49
  55. data/spec/services/redirect_flows_service_spec.rb +52 -52
  56. data/spec/services/refunds_service_spec.rb +87 -87
  57. data/spec/services/subscriptions_service_spec.rb +95 -95
  58. metadata +10 -10
@@ -21,13 +21,13 @@ describe GoCardlessPro::Services::RefundsService do
21
21
  'id' => 'id-input',
22
22
  'links' => 'links-input',
23
23
  'metadata' => 'metadata-input',
24
- 'reference' => 'reference-input'
24
+ 'reference' => 'reference-input',
25
25
  }
26
26
  end
27
27
 
28
28
  before do
29
- stub_request(:post, %r{.*api.gocardless.com/refunds})
30
- .with(
29
+ stub_request(:post, %r{.*api.gocardless.com/refunds}).
30
+ with(
31
31
  body: {
32
32
  'refunds' => {
33
33
 
@@ -37,11 +37,11 @@ describe GoCardlessPro::Services::RefundsService do
37
37
  'id' => 'id-input',
38
38
  'links' => 'links-input',
39
39
  'metadata' => 'metadata-input',
40
- 'reference' => 'reference-input'
41
- }
40
+ 'reference' => 'reference-input',
41
+ },
42
42
  }
43
- )
44
- .to_return(
43
+ ).
44
+ to_return(
45
45
  body: {
46
46
  'refunds' =>
47
47
 
@@ -53,8 +53,8 @@ describe GoCardlessPro::Services::RefundsService do
53
53
  'id' => 'id-input',
54
54
  'links' => 'links-input',
55
55
  'metadata' => 'metadata-input',
56
- 'reference' => 'reference-input'
57
- }
56
+ 'reference' => 'reference-input',
57
+ },
58
58
 
59
59
  }.to_json,
60
60
  headers: response_headers
@@ -69,19 +69,19 @@ describe GoCardlessPro::Services::RefundsService do
69
69
  before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
70
70
 
71
71
  it 'retries timeouts' do
72
- stub = stub_request(:post, %r{.*api.gocardless.com/refunds})
73
- .to_timeout.then.to_return(status: 200, headers: response_headers)
72
+ stub = stub_request(:post, %r{.*api.gocardless.com/refunds}).
73
+ to_timeout.then.to_return(status: 200, headers: response_headers)
74
74
 
75
75
  post_create_response
76
76
  expect(stub).to have_been_requested.twice
77
77
  end
78
78
 
79
79
  it 'retries 5XX errors' do
80
- stub = stub_request(:post, %r{.*api.gocardless.com/refunds})
81
- .to_return(status: 502,
82
- headers: { 'Content-Type' => 'text/html' },
83
- body: '<html><body>Response from Cloudflare</body></html>')
84
- .then.to_return(status: 200, headers: response_headers)
80
+ stub = stub_request(:post, %r{.*api.gocardless.com/refunds}).
81
+ to_return(status: 502,
82
+ headers: { 'Content-Type' => 'text/html' },
83
+ body: '<html><body>Response from Cloudflare</body></html>').
84
+ then.to_return(status: 200, headers: response_headers)
85
85
 
86
86
  post_create_response
87
87
  expect(stub).to have_been_requested.twice
@@ -99,9 +99,9 @@ describe GoCardlessPro::Services::RefundsService do
99
99
  type: 'validation_failed',
100
100
  code: 422,
101
101
  errors: [
102
- { message: 'test error message', field: 'test_field' }
103
- ]
104
- }
102
+ { message: 'test error message', field: 'test_field' },
103
+ ],
104
+ },
105
105
  }.to_json,
106
106
  headers: response_headers,
107
107
  status: 422
@@ -125,7 +125,7 @@ describe GoCardlessPro::Services::RefundsService do
125
125
  'id' => 'id-input',
126
126
  'links' => 'links-input',
127
127
  'metadata' => 'metadata-input',
128
- 'reference' => 'reference-input'
128
+ 'reference' => 'reference-input',
129
129
  }
130
130
  end
131
131
 
@@ -140,11 +140,11 @@ describe GoCardlessPro::Services::RefundsService do
140
140
  message: 'A resource has already been created with this idempotency key',
141
141
  reason: 'idempotent_creation_conflict',
142
142
  links: {
143
- conflicting_resource_id: id
144
- }
145
- }
146
- ]
147
- }
143
+ conflicting_resource_id: id,
144
+ },
145
+ },
146
+ ],
147
+ },
148
148
  }.to_json,
149
149
  headers: response_headers,
150
150
  status: 409
@@ -153,8 +153,8 @@ describe GoCardlessPro::Services::RefundsService do
153
153
 
154
154
  let!(:get_stub) do
155
155
  stub_url = "/refunds/#{id}"
156
- stub_request(:get, /.*api.gocardless.com#{stub_url}/)
157
- .to_return(
156
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
157
+ to_return(
158
158
  body: {
159
159
  'refunds' => {
160
160
 
@@ -164,8 +164,8 @@ describe GoCardlessPro::Services::RefundsService do
164
164
  'id' => 'id-input',
165
165
  'links' => 'links-input',
166
166
  'metadata' => 'metadata-input',
167
- 'reference' => 'reference-input'
168
- }
167
+ 'reference' => 'reference-input',
168
+ },
169
169
  }.to_json,
170
170
  headers: response_headers
171
171
  )
@@ -193,14 +193,14 @@ describe GoCardlessPro::Services::RefundsService do
193
193
  'id' => 'id-input',
194
194
  'links' => 'links-input',
195
195
  'metadata' => 'metadata-input',
196
- 'reference' => 'reference-input'
196
+ 'reference' => 'reference-input',
197
197
  }],
198
198
  meta: {
199
199
  cursors: {
200
200
  before: nil,
201
- after: 'ABC123'
202
- }
203
- }
201
+ after: 'ABC123',
202
+ },
203
+ },
204
204
  }.to_json
205
205
  end
206
206
 
@@ -238,19 +238,19 @@ describe GoCardlessPro::Services::RefundsService do
238
238
  before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
239
239
 
240
240
  it 'retries timeouts' do
241
- stub = stub_request(:get, %r{.*api.gocardless.com/refunds})
242
- .to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
241
+ stub = stub_request(:get, %r{.*api.gocardless.com/refunds}).
242
+ to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
243
243
 
244
244
  get_list_response
245
245
  expect(stub).to have_been_requested.twice
246
246
  end
247
247
 
248
248
  it 'retries 5XX errors' do
249
- stub = stub_request(:get, %r{.*api.gocardless.com/refunds})
250
- .to_return(status: 502,
251
- headers: { 'Content-Type' => 'text/html' },
252
- body: '<html><body>Response from Cloudflare</body></html>')
253
- .then.to_return(status: 200, headers: response_headers, body: body)
249
+ stub = stub_request(:get, %r{.*api.gocardless.com/refunds}).
250
+ to_return(status: 502,
251
+ headers: { 'Content-Type' => 'text/html' },
252
+ body: '<html><body>Response from Cloudflare</body></html>').
253
+ then.to_return(status: 200, headers: response_headers, body: body)
254
254
 
255
255
  get_list_response
256
256
  expect(stub).to have_been_requested.twice
@@ -271,12 +271,12 @@ describe GoCardlessPro::Services::RefundsService do
271
271
  'id' => 'id-input',
272
272
  'links' => 'links-input',
273
273
  'metadata' => 'metadata-input',
274
- 'reference' => 'reference-input'
274
+ 'reference' => 'reference-input',
275
275
  }],
276
276
  meta: {
277
277
  cursors: { after: 'AB345' },
278
- limit: 1
279
- }
278
+ limit: 1,
279
+ },
280
280
  }.to_json,
281
281
  headers: response_headers
282
282
  )
@@ -293,12 +293,12 @@ describe GoCardlessPro::Services::RefundsService do
293
293
  'id' => 'id-input',
294
294
  'links' => 'links-input',
295
295
  'metadata' => 'metadata-input',
296
- 'reference' => 'reference-input'
296
+ 'reference' => 'reference-input',
297
297
  }],
298
298
  meta: {
299
299
  limit: 2,
300
- cursors: {}
301
- }
300
+ cursors: {},
301
+ },
302
302
  }.to_json,
303
303
  headers: response_headers
304
304
  )
@@ -324,19 +324,19 @@ describe GoCardlessPro::Services::RefundsService do
324
324
  'id' => 'id-input',
325
325
  'links' => 'links-input',
326
326
  'metadata' => 'metadata-input',
327
- 'reference' => 'reference-input'
327
+ 'reference' => 'reference-input',
328
328
  }],
329
329
  meta: {
330
330
  cursors: { after: 'AB345' },
331
- limit: 1
332
- }
331
+ limit: 1,
332
+ },
333
333
  }.to_json,
334
334
  headers: response_headers
335
335
  )
336
336
 
337
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/refunds\?after=AB345})
338
- .to_timeout.then
339
- .to_return(
337
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/refunds\?after=AB345}).
338
+ to_timeout.then.
339
+ to_return(
340
340
  body: {
341
341
  'refunds' => [{
342
342
 
@@ -346,12 +346,12 @@ describe GoCardlessPro::Services::RefundsService do
346
346
  'id' => 'id-input',
347
347
  'links' => 'links-input',
348
348
  'metadata' => 'metadata-input',
349
- 'reference' => 'reference-input'
349
+ 'reference' => 'reference-input',
350
350
  }],
351
351
  meta: {
352
352
  limit: 2,
353
- cursors: {}
354
- }
353
+ cursors: {},
354
+ },
355
355
  }.to_json,
356
356
  headers: response_headers
357
357
  )
@@ -373,18 +373,18 @@ describe GoCardlessPro::Services::RefundsService do
373
373
  'id' => 'id-input',
374
374
  'links' => 'links-input',
375
375
  'metadata' => 'metadata-input',
376
- 'reference' => 'reference-input'
376
+ 'reference' => 'reference-input',
377
377
  }],
378
378
  meta: {
379
379
  cursors: { after: 'AB345' },
380
- limit: 1
381
- }
380
+ limit: 1,
381
+ },
382
382
  }.to_json,
383
383
  headers: response_headers
384
384
  )
385
385
 
386
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/refunds\?after=AB345})
387
- .to_return(
386
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/refunds\?after=AB345}).
387
+ to_return(
388
388
  status: 502,
389
389
  body: '<html><body>Response from Cloudflare</body></html>',
390
390
  headers: { 'Content-Type' => 'text/html' }
@@ -398,12 +398,12 @@ describe GoCardlessPro::Services::RefundsService do
398
398
  'id' => 'id-input',
399
399
  'links' => 'links-input',
400
400
  'metadata' => 'metadata-input',
401
- 'reference' => 'reference-input'
401
+ 'reference' => 'reference-input',
402
402
  }],
403
403
  meta: {
404
404
  limit: 2,
405
- cursors: {}
406
- }
405
+ cursors: {},
406
+ },
407
407
  }.to_json,
408
408
  headers: response_headers
409
409
  )
@@ -424,9 +424,9 @@ describe GoCardlessPro::Services::RefundsService do
424
424
  context 'passing in a custom header' do
425
425
  let!(:stub) do
426
426
  stub_url = '/refunds/:identity'.gsub(':identity', id)
427
- stub_request(:get, /.*api.gocardless.com#{stub_url}/)
428
- .with(headers: { 'Foo' => 'Bar' })
429
- .to_return(
427
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
428
+ with(headers: { 'Foo' => 'Bar' }).
429
+ to_return(
430
430
  body: {
431
431
  'refunds' => {
432
432
 
@@ -436,8 +436,8 @@ describe GoCardlessPro::Services::RefundsService do
436
436
  'id' => 'id-input',
437
437
  'links' => 'links-input',
438
438
  'metadata' => 'metadata-input',
439
- 'reference' => 'reference-input'
440
- }
439
+ 'reference' => 'reference-input',
440
+ },
441
441
  }.to_json,
442
442
  headers: response_headers
443
443
  )
@@ -445,7 +445,7 @@ describe GoCardlessPro::Services::RefundsService do
445
445
 
446
446
  subject(:get_response) do
447
447
  client.refunds.get(id, headers: {
448
- 'Foo' => 'Bar'
448
+ 'Foo' => 'Bar',
449
449
  })
450
450
  end
451
451
 
@@ -468,8 +468,8 @@ describe GoCardlessPro::Services::RefundsService do
468
468
  'id' => 'id-input',
469
469
  'links' => 'links-input',
470
470
  'metadata' => 'metadata-input',
471
- 'reference' => 'reference-input'
472
- }
471
+ 'reference' => 'reference-input',
472
+ },
473
473
  }.to_json,
474
474
  headers: response_headers
475
475
  )
@@ -508,8 +508,8 @@ describe GoCardlessPro::Services::RefundsService do
508
508
  it 'retries timeouts' do
509
509
  stub_url = '/refunds/:identity'.gsub(':identity', id)
510
510
 
511
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/)
512
- .to_timeout.then.to_return(status: 200, headers: response_headers)
511
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
512
+ to_timeout.then.to_return(status: 200, headers: response_headers)
513
513
 
514
514
  get_response
515
515
  expect(stub).to have_been_requested.twice
@@ -518,11 +518,11 @@ describe GoCardlessPro::Services::RefundsService do
518
518
  it 'retries 5XX errors' do
519
519
  stub_url = '/refunds/:identity'.gsub(':identity', id)
520
520
 
521
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/)
522
- .to_return(status: 502,
523
- headers: { 'Content-Type' => 'text/html' },
524
- body: '<html><body>Response from Cloudflare</body></html>')
525
- .then.to_return(status: 200, headers: response_headers)
521
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
522
+ to_return(status: 502,
523
+ headers: { 'Content-Type' => 'text/html' },
524
+ body: '<html><body>Response from Cloudflare</body></html>').
525
+ then.to_return(status: 200, headers: response_headers)
526
526
 
527
527
  get_response
528
528
  expect(stub).to have_been_requested.twice
@@ -549,8 +549,8 @@ describe GoCardlessPro::Services::RefundsService do
549
549
  'id' => 'id-input',
550
550
  'links' => 'links-input',
551
551
  'metadata' => 'metadata-input',
552
- 'reference' => 'reference-input'
553
- }
552
+ 'reference' => 'reference-input',
553
+ },
554
554
  }.to_json,
555
555
  headers: response_headers
556
556
  )
@@ -566,8 +566,8 @@ describe GoCardlessPro::Services::RefundsService do
566
566
 
567
567
  it 'retries timeouts' do
568
568
  stub_url = '/refunds/:identity'.gsub(':identity', id)
569
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/)
570
- .to_timeout.then.to_return(status: 200, headers: response_headers)
569
+ stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
570
+ to_timeout.then.to_return(status: 200, headers: response_headers)
571
571
 
572
572
  put_update_response
573
573
  expect(stub).to have_been_requested.twice
@@ -575,11 +575,11 @@ describe GoCardlessPro::Services::RefundsService do
575
575
 
576
576
  it 'retries 5XX errors' do
577
577
  stub_url = '/refunds/:identity'.gsub(':identity', id)
578
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/)
579
- .to_return(status: 502,
580
- headers: { 'Content-Type' => 'text/html' },
581
- body: '<html><body>Response from Cloudflare</body></html>')
582
- .then.to_return(status: 200, headers: response_headers)
578
+ stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
579
+ to_return(status: 502,
580
+ headers: { 'Content-Type' => 'text/html' },
581
+ body: '<html><body>Response from Cloudflare</body></html>').
582
+ then.to_return(status: 200, headers: response_headers)
583
583
 
584
584
  put_update_response
585
585
  expect(stub).to have_been_requested.twice
@@ -30,13 +30,13 @@ describe GoCardlessPro::Services::SubscriptionsService do
30
30
  'payment_reference' => 'payment_reference-input',
31
31
  'start_date' => 'start_date-input',
32
32
  'status' => 'status-input',
33
- 'upcoming_payments' => 'upcoming_payments-input'
33
+ 'upcoming_payments' => 'upcoming_payments-input',
34
34
  }
35
35
  end
36
36
 
37
37
  before do
38
- stub_request(:post, %r{.*api.gocardless.com/subscriptions})
39
- .with(
38
+ stub_request(:post, %r{.*api.gocardless.com/subscriptions}).
39
+ with(
40
40
  body: {
41
41
  'subscriptions' => {
42
42
 
@@ -55,11 +55,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
55
55
  'payment_reference' => 'payment_reference-input',
56
56
  'start_date' => 'start_date-input',
57
57
  'status' => 'status-input',
58
- 'upcoming_payments' => 'upcoming_payments-input'
59
- }
58
+ 'upcoming_payments' => 'upcoming_payments-input',
59
+ },
60
60
  }
61
- )
62
- .to_return(
61
+ ).
62
+ to_return(
63
63
  body: {
64
64
  'subscriptions' =>
65
65
 
@@ -80,8 +80,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
80
80
  'payment_reference' => 'payment_reference-input',
81
81
  'start_date' => 'start_date-input',
82
82
  'status' => 'status-input',
83
- 'upcoming_payments' => 'upcoming_payments-input'
84
- }
83
+ 'upcoming_payments' => 'upcoming_payments-input',
84
+ },
85
85
 
86
86
  }.to_json,
87
87
  headers: response_headers
@@ -96,19 +96,19 @@ describe GoCardlessPro::Services::SubscriptionsService do
96
96
  before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
97
97
 
98
98
  it 'retries timeouts' do
99
- stub = stub_request(:post, %r{.*api.gocardless.com/subscriptions})
100
- .to_timeout.then.to_return(status: 200, headers: response_headers)
99
+ stub = stub_request(:post, %r{.*api.gocardless.com/subscriptions}).
100
+ to_timeout.then.to_return(status: 200, headers: response_headers)
101
101
 
102
102
  post_create_response
103
103
  expect(stub).to have_been_requested.twice
104
104
  end
105
105
 
106
106
  it 'retries 5XX errors' do
107
- stub = stub_request(:post, %r{.*api.gocardless.com/subscriptions})
108
- .to_return(status: 502,
109
- headers: { 'Content-Type' => 'text/html' },
110
- body: '<html><body>Response from Cloudflare</body></html>')
111
- .then.to_return(status: 200, headers: response_headers)
107
+ stub = stub_request(:post, %r{.*api.gocardless.com/subscriptions}).
108
+ to_return(status: 502,
109
+ headers: { 'Content-Type' => 'text/html' },
110
+ body: '<html><body>Response from Cloudflare</body></html>').
111
+ then.to_return(status: 200, headers: response_headers)
112
112
 
113
113
  post_create_response
114
114
  expect(stub).to have_been_requested.twice
@@ -126,9 +126,9 @@ describe GoCardlessPro::Services::SubscriptionsService do
126
126
  type: 'validation_failed',
127
127
  code: 422,
128
128
  errors: [
129
- { message: 'test error message', field: 'test_field' }
130
- ]
131
- }
129
+ { message: 'test error message', field: 'test_field' },
130
+ ],
131
+ },
132
132
  }.to_json,
133
133
  headers: response_headers,
134
134
  status: 422
@@ -161,7 +161,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
161
161
  'payment_reference' => 'payment_reference-input',
162
162
  'start_date' => 'start_date-input',
163
163
  'status' => 'status-input',
164
- 'upcoming_payments' => 'upcoming_payments-input'
164
+ 'upcoming_payments' => 'upcoming_payments-input',
165
165
  }
166
166
  end
167
167
 
@@ -176,11 +176,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
176
176
  message: 'A resource has already been created with this idempotency key',
177
177
  reason: 'idempotent_creation_conflict',
178
178
  links: {
179
- conflicting_resource_id: id
180
- }
181
- }
182
- ]
183
- }
179
+ conflicting_resource_id: id,
180
+ },
181
+ },
182
+ ],
183
+ },
184
184
  }.to_json,
185
185
  headers: response_headers,
186
186
  status: 409
@@ -189,8 +189,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
189
189
 
190
190
  let!(:get_stub) do
191
191
  stub_url = "/subscriptions/#{id}"
192
- stub_request(:get, /.*api.gocardless.com#{stub_url}/)
193
- .to_return(
192
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
193
+ to_return(
194
194
  body: {
195
195
  'subscriptions' => {
196
196
 
@@ -209,8 +209,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
209
209
  'payment_reference' => 'payment_reference-input',
210
210
  'start_date' => 'start_date-input',
211
211
  'status' => 'status-input',
212
- 'upcoming_payments' => 'upcoming_payments-input'
213
- }
212
+ 'upcoming_payments' => 'upcoming_payments-input',
213
+ },
214
214
  }.to_json,
215
215
  headers: response_headers
216
216
  )
@@ -247,14 +247,14 @@ describe GoCardlessPro::Services::SubscriptionsService do
247
247
  'payment_reference' => 'payment_reference-input',
248
248
  'start_date' => 'start_date-input',
249
249
  'status' => 'status-input',
250
- 'upcoming_payments' => 'upcoming_payments-input'
250
+ 'upcoming_payments' => 'upcoming_payments-input',
251
251
  }],
252
252
  meta: {
253
253
  cursors: {
254
254
  before: nil,
255
- after: 'ABC123'
256
- }
257
- }
255
+ after: 'ABC123',
256
+ },
257
+ },
258
258
  }.to_json
259
259
  end
260
260
 
@@ -310,19 +310,19 @@ describe GoCardlessPro::Services::SubscriptionsService do
310
310
  before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
311
311
 
312
312
  it 'retries timeouts' do
313
- stub = stub_request(:get, %r{.*api.gocardless.com/subscriptions})
314
- .to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
313
+ stub = stub_request(:get, %r{.*api.gocardless.com/subscriptions}).
314
+ to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
315
315
 
316
316
  get_list_response
317
317
  expect(stub).to have_been_requested.twice
318
318
  end
319
319
 
320
320
  it 'retries 5XX errors' do
321
- stub = stub_request(:get, %r{.*api.gocardless.com/subscriptions})
322
- .to_return(status: 502,
323
- headers: { 'Content-Type' => 'text/html' },
324
- body: '<html><body>Response from Cloudflare</body></html>')
325
- .then.to_return(status: 200, headers: response_headers, body: body)
321
+ stub = stub_request(:get, %r{.*api.gocardless.com/subscriptions}).
322
+ to_return(status: 502,
323
+ headers: { 'Content-Type' => 'text/html' },
324
+ body: '<html><body>Response from Cloudflare</body></html>').
325
+ then.to_return(status: 200, headers: response_headers, body: body)
326
326
 
327
327
  get_list_response
328
328
  expect(stub).to have_been_requested.twice
@@ -352,12 +352,12 @@ describe GoCardlessPro::Services::SubscriptionsService do
352
352
  'payment_reference' => 'payment_reference-input',
353
353
  'start_date' => 'start_date-input',
354
354
  'status' => 'status-input',
355
- 'upcoming_payments' => 'upcoming_payments-input'
355
+ 'upcoming_payments' => 'upcoming_payments-input',
356
356
  }],
357
357
  meta: {
358
358
  cursors: { after: 'AB345' },
359
- limit: 1
360
- }
359
+ limit: 1,
360
+ },
361
361
  }.to_json,
362
362
  headers: response_headers
363
363
  )
@@ -383,12 +383,12 @@ describe GoCardlessPro::Services::SubscriptionsService do
383
383
  'payment_reference' => 'payment_reference-input',
384
384
  'start_date' => 'start_date-input',
385
385
  'status' => 'status-input',
386
- 'upcoming_payments' => 'upcoming_payments-input'
386
+ 'upcoming_payments' => 'upcoming_payments-input',
387
387
  }],
388
388
  meta: {
389
389
  limit: 2,
390
- cursors: {}
391
- }
390
+ cursors: {},
391
+ },
392
392
  }.to_json,
393
393
  headers: response_headers
394
394
  )
@@ -423,19 +423,19 @@ describe GoCardlessPro::Services::SubscriptionsService do
423
423
  'payment_reference' => 'payment_reference-input',
424
424
  'start_date' => 'start_date-input',
425
425
  'status' => 'status-input',
426
- 'upcoming_payments' => 'upcoming_payments-input'
426
+ 'upcoming_payments' => 'upcoming_payments-input',
427
427
  }],
428
428
  meta: {
429
429
  cursors: { after: 'AB345' },
430
- limit: 1
431
- }
430
+ limit: 1,
431
+ },
432
432
  }.to_json,
433
433
  headers: response_headers
434
434
  )
435
435
 
436
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/subscriptions\?after=AB345})
437
- .to_timeout.then
438
- .to_return(
436
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/subscriptions\?after=AB345}).
437
+ to_timeout.then.
438
+ to_return(
439
439
  body: {
440
440
  'subscriptions' => [{
441
441
 
@@ -454,12 +454,12 @@ describe GoCardlessPro::Services::SubscriptionsService do
454
454
  'payment_reference' => 'payment_reference-input',
455
455
  'start_date' => 'start_date-input',
456
456
  'status' => 'status-input',
457
- 'upcoming_payments' => 'upcoming_payments-input'
457
+ 'upcoming_payments' => 'upcoming_payments-input',
458
458
  }],
459
459
  meta: {
460
460
  limit: 2,
461
- cursors: {}
462
- }
461
+ cursors: {},
462
+ },
463
463
  }.to_json,
464
464
  headers: response_headers
465
465
  )
@@ -490,18 +490,18 @@ describe GoCardlessPro::Services::SubscriptionsService do
490
490
  'payment_reference' => 'payment_reference-input',
491
491
  'start_date' => 'start_date-input',
492
492
  'status' => 'status-input',
493
- 'upcoming_payments' => 'upcoming_payments-input'
493
+ 'upcoming_payments' => 'upcoming_payments-input',
494
494
  }],
495
495
  meta: {
496
496
  cursors: { after: 'AB345' },
497
- limit: 1
498
- }
497
+ limit: 1,
498
+ },
499
499
  }.to_json,
500
500
  headers: response_headers
501
501
  )
502
502
 
503
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/subscriptions\?after=AB345})
504
- .to_return(
503
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/subscriptions\?after=AB345}).
504
+ to_return(
505
505
  status: 502,
506
506
  body: '<html><body>Response from Cloudflare</body></html>',
507
507
  headers: { 'Content-Type' => 'text/html' }
@@ -524,12 +524,12 @@ describe GoCardlessPro::Services::SubscriptionsService do
524
524
  'payment_reference' => 'payment_reference-input',
525
525
  'start_date' => 'start_date-input',
526
526
  'status' => 'status-input',
527
- 'upcoming_payments' => 'upcoming_payments-input'
527
+ 'upcoming_payments' => 'upcoming_payments-input',
528
528
  }],
529
529
  meta: {
530
530
  limit: 2,
531
- cursors: {}
532
- }
531
+ cursors: {},
532
+ },
533
533
  }.to_json,
534
534
  headers: response_headers
535
535
  )
@@ -550,9 +550,9 @@ describe GoCardlessPro::Services::SubscriptionsService do
550
550
  context 'passing in a custom header' do
551
551
  let!(:stub) do
552
552
  stub_url = '/subscriptions/:identity'.gsub(':identity', id)
553
- stub_request(:get, /.*api.gocardless.com#{stub_url}/)
554
- .with(headers: { 'Foo' => 'Bar' })
555
- .to_return(
553
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
554
+ with(headers: { 'Foo' => 'Bar' }).
555
+ to_return(
556
556
  body: {
557
557
  'subscriptions' => {
558
558
 
@@ -571,8 +571,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
571
571
  'payment_reference' => 'payment_reference-input',
572
572
  'start_date' => 'start_date-input',
573
573
  'status' => 'status-input',
574
- 'upcoming_payments' => 'upcoming_payments-input'
575
- }
574
+ 'upcoming_payments' => 'upcoming_payments-input',
575
+ },
576
576
  }.to_json,
577
577
  headers: response_headers
578
578
  )
@@ -580,7 +580,7 @@ describe GoCardlessPro::Services::SubscriptionsService do
580
580
 
581
581
  subject(:get_response) do
582
582
  client.subscriptions.get(id, headers: {
583
- 'Foo' => 'Bar'
583
+ 'Foo' => 'Bar',
584
584
  })
585
585
  end
586
586
 
@@ -612,8 +612,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
612
612
  'payment_reference' => 'payment_reference-input',
613
613
  'start_date' => 'start_date-input',
614
614
  'status' => 'status-input',
615
- 'upcoming_payments' => 'upcoming_payments-input'
616
- }
615
+ 'upcoming_payments' => 'upcoming_payments-input',
616
+ },
617
617
  }.to_json,
618
618
  headers: response_headers
619
619
  )
@@ -652,8 +652,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
652
652
  it 'retries timeouts' do
653
653
  stub_url = '/subscriptions/:identity'.gsub(':identity', id)
654
654
 
655
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/)
656
- .to_timeout.then.to_return(status: 200, headers: response_headers)
655
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
656
+ to_timeout.then.to_return(status: 200, headers: response_headers)
657
657
 
658
658
  get_response
659
659
  expect(stub).to have_been_requested.twice
@@ -662,11 +662,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
662
662
  it 'retries 5XX errors' do
663
663
  stub_url = '/subscriptions/:identity'.gsub(':identity', id)
664
664
 
665
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/)
666
- .to_return(status: 502,
667
- headers: { 'Content-Type' => 'text/html' },
668
- body: '<html><body>Response from Cloudflare</body></html>')
669
- .then.to_return(status: 200, headers: response_headers)
665
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
666
+ to_return(status: 502,
667
+ headers: { 'Content-Type' => 'text/html' },
668
+ body: '<html><body>Response from Cloudflare</body></html>').
669
+ then.to_return(status: 200, headers: response_headers)
670
670
 
671
671
  get_response
672
672
  expect(stub).to have_been_requested.twice
@@ -702,8 +702,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
702
702
  'payment_reference' => 'payment_reference-input',
703
703
  'start_date' => 'start_date-input',
704
704
  'status' => 'status-input',
705
- 'upcoming_payments' => 'upcoming_payments-input'
706
- }
705
+ 'upcoming_payments' => 'upcoming_payments-input',
706
+ },
707
707
  }.to_json,
708
708
  headers: response_headers
709
709
  )
@@ -719,8 +719,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
719
719
 
720
720
  it 'retries timeouts' do
721
721
  stub_url = '/subscriptions/:identity'.gsub(':identity', id)
722
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/)
723
- .to_timeout.then.to_return(status: 200, headers: response_headers)
722
+ stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
723
+ to_timeout.then.to_return(status: 200, headers: response_headers)
724
724
 
725
725
  put_update_response
726
726
  expect(stub).to have_been_requested.twice
@@ -728,11 +728,11 @@ describe GoCardlessPro::Services::SubscriptionsService do
728
728
 
729
729
  it 'retries 5XX errors' do
730
730
  stub_url = '/subscriptions/:identity'.gsub(':identity', id)
731
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/)
732
- .to_return(status: 502,
733
- headers: { 'Content-Type' => 'text/html' },
734
- body: '<html><body>Response from Cloudflare</body></html>')
735
- .then.to_return(status: 200, headers: response_headers)
731
+ stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
732
+ to_return(status: 502,
733
+ headers: { 'Content-Type' => 'text/html' },
734
+ body: '<html><body>Response from Cloudflare</body></html>').
735
+ then.to_return(status: 200, headers: response_headers)
736
736
 
737
737
  put_update_response
738
738
  expect(stub).to have_been_requested.twice
@@ -768,8 +768,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
768
768
  'payment_reference' => 'payment_reference-input',
769
769
  'start_date' => 'start_date-input',
770
770
  'status' => 'status-input',
771
- 'upcoming_payments' => 'upcoming_payments-input'
772
- }
771
+ 'upcoming_payments' => 'upcoming_payments-input',
772
+ },
773
773
  }.to_json,
774
774
  headers: response_headers
775
775
  )
@@ -784,8 +784,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
784
784
  describe 'retry behaviour' do
785
785
  it "doesn't retry errors" do
786
786
  stub_url = '/subscriptions/:identity/actions/cancel'.gsub(':identity', resource_id)
787
- stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/)
788
- .to_timeout
787
+ stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/).
788
+ to_timeout
789
789
 
790
790
  expect { post_response }.to raise_error(Faraday::TimeoutError)
791
791
  expect(stub).to have_been_requested
@@ -802,8 +802,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
802
802
  let!(:stub) do
803
803
  # /subscriptions/%v/actions/cancel
804
804
  stub_url = '/subscriptions/:identity/actions/cancel'.gsub(':identity', resource_id)
805
- stub_request(:post, /.*api.gocardless.com#{stub_url}/)
806
- .with(
805
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
806
+ with(
807
807
  body: { foo: 'bar' },
808
808
  headers: { 'Foo' => 'Bar' }
809
809
  ).to_return(
@@ -825,8 +825,8 @@ describe GoCardlessPro::Services::SubscriptionsService do
825
825
  'payment_reference' => 'payment_reference-input',
826
826
  'start_date' => 'start_date-input',
827
827
  'status' => 'status-input',
828
- 'upcoming_payments' => 'upcoming_payments-input'
829
- }
828
+ 'upcoming_payments' => 'upcoming_payments-input',
829
+ },
830
830
  }.to_json,
831
831
  headers: response_headers
832
832
  )