gocardless_pro 2.27.0 → 2.30.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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +20 -1
  3. data/lib/gocardless_pro/api_service.rb +4 -0
  4. data/lib/gocardless_pro/client.rb +11 -1
  5. data/lib/gocardless_pro/error/authentication_error.rb +4 -0
  6. data/lib/gocardless_pro/error/permission_error.rb +4 -0
  7. data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
  8. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
  9. data/lib/gocardless_pro/resources/bank_authorisation.rb +3 -9
  10. data/lib/gocardless_pro/resources/billing_request.rb +31 -7
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +14 -0
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  13. data/lib/gocardless_pro/resources/block.rb +76 -0
  14. data/lib/gocardless_pro/resources/event.rb +20 -0
  15. data/lib/gocardless_pro/resources/institution.rb +7 -1
  16. data/lib/gocardless_pro/resources/payer_authorisation.rb +9 -0
  17. data/lib/gocardless_pro/resources/redirect_flow.rb +6 -0
  18. data/lib/gocardless_pro/services/bank_authorisations_service.rb +0 -2
  19. data/lib/gocardless_pro/services/billing_request_flows_service.rb +23 -0
  20. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  21. data/lib/gocardless_pro/services/billing_requests_service.rb +89 -24
  22. data/lib/gocardless_pro/services/blocks_service.rb +223 -0
  23. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +1 -5
  24. data/lib/gocardless_pro/services/creditors_service.rb +1 -3
  25. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +1 -1
  26. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +1 -5
  27. data/lib/gocardless_pro/services/customers_service.rb +1 -3
  28. data/lib/gocardless_pro/services/events_service.rb +1 -1
  29. data/lib/gocardless_pro/services/instalment_schedules_service.rb +1 -7
  30. data/lib/gocardless_pro/services/institutions_service.rb +2 -2
  31. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +1 -1
  32. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  33. data/lib/gocardless_pro/services/mandates_service.rb +1 -7
  34. data/lib/gocardless_pro/services/payer_authorisations_service.rb +0 -6
  35. data/lib/gocardless_pro/services/payments_service.rb +1 -7
  36. data/lib/gocardless_pro/services/payout_items_service.rb +1 -1
  37. data/lib/gocardless_pro/services/payouts_service.rb +1 -1
  38. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  39. data/lib/gocardless_pro/services/refunds_service.rb +1 -3
  40. data/lib/gocardless_pro/services/scenario_simulators_service.rb +28 -6
  41. data/lib/gocardless_pro/services/subscriptions_service.rb +3 -11
  42. data/lib/gocardless_pro/services/tax_rates_service.rb +1 -1
  43. data/lib/gocardless_pro/services/webhooks_service.rb +1 -3
  44. data/lib/gocardless_pro/version.rb +1 -1
  45. data/lib/gocardless_pro.rb +9 -0
  46. data/spec/api_service_spec.rb +12 -1
  47. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  48. data/spec/resources/bank_authorisation_spec.rb +7 -7
  49. data/spec/resources/billing_request_flow_spec.rb +104 -0
  50. data/spec/resources/billing_request_spec.rb +183 -29
  51. data/spec/resources/billing_request_template_spec.rb +502 -0
  52. data/spec/resources/block_spec.rb +577 -0
  53. data/spec/resources/creditor_bank_account_spec.rb +2 -0
  54. data/spec/resources/customer_bank_account_spec.rb +2 -0
  55. data/spec/resources/customer_notification_spec.rb +2 -0
  56. data/spec/resources/customer_spec.rb +2 -0
  57. data/spec/resources/instalment_schedule_spec.rb +2 -0
  58. data/spec/resources/institution_spec.rb +5 -0
  59. data/spec/resources/mandate_import_spec.rb +4 -0
  60. data/spec/resources/mandate_spec.rb +4 -0
  61. data/spec/resources/payer_authorisation_spec.rb +4 -0
  62. data/spec/resources/payment_spec.rb +4 -0
  63. data/spec/resources/redirect_flow_spec.rb +11 -0
  64. data/spec/resources/scenario_simulator_spec.rb +2 -0
  65. data/spec/resources/subscription_spec.rb +6 -0
  66. data/spec/resources/webhook_spec.rb +2 -0
  67. data/spec/services/bank_authorisations_service_spec.rb +7 -20
  68. data/spec/services/billing_request_flows_service_spec.rb +115 -0
  69. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  70. data/spec/services/billing_requests_service_spec.rb +210 -47
  71. data/spec/services/blocks_service_spec.rb +840 -0
  72. data/spec/services/creditor_bank_accounts_service_spec.rb +2 -13
  73. data/spec/services/creditors_service_spec.rb +0 -13
  74. data/spec/services/customer_bank_accounts_service_spec.rb +2 -13
  75. data/spec/services/customer_notifications_service_spec.rb +2 -0
  76. data/spec/services/customers_service_spec.rb +2 -13
  77. data/spec/services/instalment_schedules_service_spec.rb +2 -26
  78. data/spec/services/institutions_service_spec.rb +9 -0
  79. data/spec/services/mandate_imports_service_spec.rb +4 -13
  80. data/spec/services/mandates_service_spec.rb +4 -13
  81. data/spec/services/payer_authorisations_service_spec.rb +4 -13
  82. data/spec/services/payments_service_spec.rb +4 -13
  83. data/spec/services/redirect_flows_service_spec.rb +11 -13
  84. data/spec/services/refunds_service_spec.rb +0 -13
  85. data/spec/services/scenario_simulators_service_spec.rb +2 -0
  86. data/spec/services/subscriptions_service_spec.rb +6 -13
  87. data/spec/services/webhooks_service_spec.rb +2 -0
  88. metadata +18 -3
@@ -16,10 +16,17 @@ describe GoCardlessPro::Resources::BillingRequestFlow do
16
16
  {
17
17
 
18
18
  'authorisation_url' => 'authorisation_url-input',
19
+ 'auto_fulfil' => 'auto_fulfil-input',
19
20
  'created_at' => 'created_at-input',
21
+ 'exit_uri' => 'exit_uri-input',
20
22
  'expires_at' => 'expires_at-input',
23
+ 'id' => 'id-input',
21
24
  'links' => 'links-input',
25
+ 'lock_bank_account' => 'lock_bank_account-input',
26
+ 'lock_customer_details' => 'lock_customer_details-input',
22
27
  'redirect_uri' => 'redirect_uri-input',
28
+ 'session_token' => 'session_token-input',
29
+ 'show_redirect_buttons' => 'show_redirect_buttons-input',
23
30
  }
24
31
  end
25
32
 
@@ -30,10 +37,17 @@ describe GoCardlessPro::Resources::BillingRequestFlow do
30
37
  'billing_request_flows' => {
31
38
 
32
39
  'authorisation_url' => 'authorisation_url-input',
40
+ 'auto_fulfil' => 'auto_fulfil-input',
33
41
  'created_at' => 'created_at-input',
42
+ 'exit_uri' => 'exit_uri-input',
34
43
  'expires_at' => 'expires_at-input',
44
+ 'id' => 'id-input',
35
45
  'links' => 'links-input',
46
+ 'lock_bank_account' => 'lock_bank_account-input',
47
+ 'lock_customer_details' => 'lock_customer_details-input',
36
48
  'redirect_uri' => 'redirect_uri-input',
49
+ 'session_token' => 'session_token-input',
50
+ 'show_redirect_buttons' => 'show_redirect_buttons-input',
37
51
  },
38
52
  }
39
53
  ).
@@ -44,10 +58,17 @@ describe GoCardlessPro::Resources::BillingRequestFlow do
44
58
  {
45
59
 
46
60
  'authorisation_url' => 'authorisation_url-input',
61
+ 'auto_fulfil' => 'auto_fulfil-input',
47
62
  'created_at' => 'created_at-input',
63
+ 'exit_uri' => 'exit_uri-input',
48
64
  'expires_at' => 'expires_at-input',
65
+ 'id' => 'id-input',
49
66
  'links' => 'links-input',
67
+ 'lock_bank_account' => 'lock_bank_account-input',
68
+ 'lock_customer_details' => 'lock_customer_details-input',
50
69
  'redirect_uri' => 'redirect_uri-input',
70
+ 'session_token' => 'session_token-input',
71
+ 'show_redirect_buttons' => 'show_redirect_buttons-input',
51
72
  },
52
73
 
53
74
  }.to_json,
@@ -91,10 +112,17 @@ describe GoCardlessPro::Resources::BillingRequestFlow do
91
112
  {
92
113
 
93
114
  'authorisation_url' => 'authorisation_url-input',
115
+ 'auto_fulfil' => 'auto_fulfil-input',
94
116
  'created_at' => 'created_at-input',
117
+ 'exit_uri' => 'exit_uri-input',
95
118
  'expires_at' => 'expires_at-input',
119
+ 'id' => 'id-input',
96
120
  'links' => 'links-input',
121
+ 'lock_bank_account' => 'lock_bank_account-input',
122
+ 'lock_customer_details' => 'lock_customer_details-input',
97
123
  'redirect_uri' => 'redirect_uri-input',
124
+ 'session_token' => 'session_token-input',
125
+ 'show_redirect_buttons' => 'show_redirect_buttons-input',
98
126
  }
99
127
  end
100
128
 
@@ -126,4 +154,80 @@ describe GoCardlessPro::Resources::BillingRequestFlow do
126
154
  end
127
155
  end
128
156
  end
157
+
158
+ describe '#initialise' do
159
+ subject(:post_response) { client.billing_request_flows.initialise(resource_id) }
160
+
161
+ let(:resource_id) { 'ABC123' }
162
+
163
+ let!(:stub) do
164
+ # /billing_request_flows/%v/actions/initialise
165
+ stub_url = '/billing_request_flows/:identity/actions/initialise'.gsub(':identity', resource_id)
166
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
167
+
168
+ body: {
169
+ 'billing_request_flows' => {
170
+
171
+ 'authorisation_url' => 'authorisation_url-input',
172
+ 'auto_fulfil' => 'auto_fulfil-input',
173
+ 'created_at' => 'created_at-input',
174
+ 'exit_uri' => 'exit_uri-input',
175
+ 'expires_at' => 'expires_at-input',
176
+ 'id' => 'id-input',
177
+ 'links' => 'links-input',
178
+ 'lock_bank_account' => 'lock_bank_account-input',
179
+ 'lock_customer_details' => 'lock_customer_details-input',
180
+ 'redirect_uri' => 'redirect_uri-input',
181
+ 'session_token' => 'session_token-input',
182
+ 'show_redirect_buttons' => 'show_redirect_buttons-input',
183
+ },
184
+ }.to_json,
185
+
186
+ headers: response_headers
187
+ )
188
+ end
189
+
190
+ it 'wraps the response and calls the right endpoint' do
191
+ expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequestFlow)
192
+
193
+ expect(stub).to have_been_requested
194
+ end
195
+
196
+ context 'when the request needs a body and custom header' do
197
+ let(:body) { { foo: 'bar' } }
198
+ let(:headers) { { 'Foo' => 'Bar' } }
199
+ subject(:post_response) { client.billing_request_flows.initialise(resource_id, body, headers) }
200
+
201
+ let(:resource_id) { 'ABC123' }
202
+
203
+ let!(:stub) do
204
+ # /billing_request_flows/%v/actions/initialise
205
+ stub_url = '/billing_request_flows/:identity/actions/initialise'.gsub(':identity', resource_id)
206
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
207
+ with(
208
+ body: { foo: 'bar' },
209
+ headers: { 'Foo' => 'Bar' }
210
+ ).to_return(
211
+ body: {
212
+ 'billing_request_flows' => {
213
+
214
+ 'authorisation_url' => 'authorisation_url-input',
215
+ 'auto_fulfil' => 'auto_fulfil-input',
216
+ 'created_at' => 'created_at-input',
217
+ 'exit_uri' => 'exit_uri-input',
218
+ 'expires_at' => 'expires_at-input',
219
+ 'id' => 'id-input',
220
+ 'links' => 'links-input',
221
+ 'lock_bank_account' => 'lock_bank_account-input',
222
+ 'lock_customer_details' => 'lock_customer_details-input',
223
+ 'redirect_uri' => 'redirect_uri-input',
224
+ 'session_token' => 'session_token-input',
225
+ 'show_redirect_buttons' => 'show_redirect_buttons-input',
226
+ },
227
+ }.to_json,
228
+ headers: response_headers
229
+ )
230
+ end
231
+ end
232
+ end
129
233
  end
@@ -19,8 +19,8 @@ describe GoCardlessPro::Resources::BillingRequest do
19
19
  'billing_requests' => [{
20
20
 
21
21
  'actions' => 'actions-input',
22
- 'auto_fulfil' => 'auto_fulfil-input',
23
22
  'created_at' => 'created_at-input',
23
+ 'fallback_enabled' => 'fallback_enabled-input',
24
24
  'id' => 'id-input',
25
25
  'links' => 'links-input',
26
26
  'mandate_request' => 'mandate_request-input',
@@ -45,10 +45,10 @@ describe GoCardlessPro::Resources::BillingRequest do
45
45
 
46
46
  expect(get_list_response.records.first.actions).to eq('actions-input')
47
47
 
48
- expect(get_list_response.records.first.auto_fulfil).to eq('auto_fulfil-input')
49
-
50
48
  expect(get_list_response.records.first.created_at).to eq('created_at-input')
51
49
 
50
+ expect(get_list_response.records.first.fallback_enabled).to eq('fallback_enabled-input')
51
+
52
52
  expect(get_list_response.records.first.id).to eq('id-input')
53
53
 
54
54
  expect(get_list_response.records.first.mandate_request).to eq('mandate_request-input')
@@ -78,8 +78,8 @@ describe GoCardlessPro::Resources::BillingRequest do
78
78
  'billing_requests' => [{
79
79
 
80
80
  'actions' => 'actions-input',
81
- 'auto_fulfil' => 'auto_fulfil-input',
82
81
  'created_at' => 'created_at-input',
82
+ 'fallback_enabled' => 'fallback_enabled-input',
83
83
  'id' => 'id-input',
84
84
  'links' => 'links-input',
85
85
  'mandate_request' => 'mandate_request-input',
@@ -103,8 +103,8 @@ describe GoCardlessPro::Resources::BillingRequest do
103
103
  'billing_requests' => [{
104
104
 
105
105
  'actions' => 'actions-input',
106
- 'auto_fulfil' => 'auto_fulfil-input',
107
106
  'created_at' => 'created_at-input',
107
+ 'fallback_enabled' => 'fallback_enabled-input',
108
108
  'id' => 'id-input',
109
109
  'links' => 'links-input',
110
110
  'mandate_request' => 'mandate_request-input',
@@ -136,8 +136,8 @@ describe GoCardlessPro::Resources::BillingRequest do
136
136
  {
137
137
 
138
138
  'actions' => 'actions-input',
139
- 'auto_fulfil' => 'auto_fulfil-input',
140
139
  'created_at' => 'created_at-input',
140
+ 'fallback_enabled' => 'fallback_enabled-input',
141
141
  'id' => 'id-input',
142
142
  'links' => 'links-input',
143
143
  'mandate_request' => 'mandate_request-input',
@@ -155,8 +155,8 @@ describe GoCardlessPro::Resources::BillingRequest do
155
155
  'billing_requests' => {
156
156
 
157
157
  'actions' => 'actions-input',
158
- 'auto_fulfil' => 'auto_fulfil-input',
159
158
  'created_at' => 'created_at-input',
159
+ 'fallback_enabled' => 'fallback_enabled-input',
160
160
  'id' => 'id-input',
161
161
  'links' => 'links-input',
162
162
  'mandate_request' => 'mandate_request-input',
@@ -174,8 +174,8 @@ describe GoCardlessPro::Resources::BillingRequest do
174
174
  {
175
175
 
176
176
  'actions' => 'actions-input',
177
- 'auto_fulfil' => 'auto_fulfil-input',
178
177
  'created_at' => 'created_at-input',
178
+ 'fallback_enabled' => 'fallback_enabled-input',
179
179
  'id' => 'id-input',
180
180
  'links' => 'links-input',
181
181
  'mandate_request' => 'mandate_request-input',
@@ -226,8 +226,8 @@ describe GoCardlessPro::Resources::BillingRequest do
226
226
  {
227
227
 
228
228
  'actions' => 'actions-input',
229
- 'auto_fulfil' => 'auto_fulfil-input',
230
229
  'created_at' => 'created_at-input',
230
+ 'fallback_enabled' => 'fallback_enabled-input',
231
231
  'id' => 'id-input',
232
232
  'links' => 'links-input',
233
233
  'mandate_request' => 'mandate_request-input',
@@ -268,8 +268,8 @@ describe GoCardlessPro::Resources::BillingRequest do
268
268
  'billing_requests' => {
269
269
 
270
270
  'actions' => 'actions-input',
271
- 'auto_fulfil' => 'auto_fulfil-input',
272
271
  'created_at' => 'created_at-input',
272
+ 'fallback_enabled' => 'fallback_enabled-input',
273
273
  'id' => 'id-input',
274
274
  'links' => 'links-input',
275
275
  'mandate_request' => 'mandate_request-input',
@@ -306,8 +306,8 @@ describe GoCardlessPro::Resources::BillingRequest do
306
306
  'billing_requests' => {
307
307
 
308
308
  'actions' => 'actions-input',
309
- 'auto_fulfil' => 'auto_fulfil-input',
310
309
  'created_at' => 'created_at-input',
310
+ 'fallback_enabled' => 'fallback_enabled-input',
311
311
  'id' => 'id-input',
312
312
  'links' => 'links-input',
313
313
  'mandate_request' => 'mandate_request-input',
@@ -341,8 +341,8 @@ describe GoCardlessPro::Resources::BillingRequest do
341
341
  'billing_requests' => {
342
342
 
343
343
  'actions' => 'actions-input',
344
- 'auto_fulfil' => 'auto_fulfil-input',
345
344
  'created_at' => 'created_at-input',
345
+ 'fallback_enabled' => 'fallback_enabled-input',
346
346
  'id' => 'id-input',
347
347
  'links' => 'links-input',
348
348
  'mandate_request' => 'mandate_request-input',
@@ -393,12 +393,13 @@ describe GoCardlessPro::Resources::BillingRequest do
393
393
  # /billing_requests/%v/actions/collect_customer_details
394
394
  stub_url = '/billing_requests/:identity/actions/collect_customer_details'.gsub(':identity', resource_id)
395
395
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
396
+
396
397
  body: {
397
398
  'billing_requests' => {
398
399
 
399
400
  'actions' => 'actions-input',
400
- 'auto_fulfil' => 'auto_fulfil-input',
401
401
  'created_at' => 'created_at-input',
402
+ 'fallback_enabled' => 'fallback_enabled-input',
402
403
  'id' => 'id-input',
403
404
  'links' => 'links-input',
404
405
  'mandate_request' => 'mandate_request-input',
@@ -408,6 +409,7 @@ describe GoCardlessPro::Resources::BillingRequest do
408
409
  'status' => 'status-input',
409
410
  },
410
411
  }.to_json,
412
+
411
413
  headers: response_headers
412
414
  )
413
415
  end
@@ -437,8 +439,8 @@ describe GoCardlessPro::Resources::BillingRequest do
437
439
  'billing_requests' => {
438
440
 
439
441
  'actions' => 'actions-input',
440
- 'auto_fulfil' => 'auto_fulfil-input',
441
442
  'created_at' => 'created_at-input',
443
+ 'fallback_enabled' => 'fallback_enabled-input',
442
444
  'id' => 'id-input',
443
445
  'links' => 'links-input',
444
446
  'mandate_request' => 'mandate_request-input',
@@ -454,21 +456,22 @@ describe GoCardlessPro::Resources::BillingRequest do
454
456
  end
455
457
  end
456
458
 
457
- describe '#collect_bank_account_details' do
458
- subject(:post_response) { client.billing_requests.collect_bank_account_details(resource_id) }
459
+ describe '#collect_bank_account' do
460
+ subject(:post_response) { client.billing_requests.collect_bank_account(resource_id) }
459
461
 
460
462
  let(:resource_id) { 'ABC123' }
461
463
 
462
464
  let!(:stub) do
463
- # /billing_requests/%v/actions/collect_bank_account_details
464
- stub_url = '/billing_requests/:identity/actions/collect_bank_account_details'.gsub(':identity', resource_id)
465
+ # /billing_requests/%v/actions/collect_bank_account
466
+ stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
465
467
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
468
+
466
469
  body: {
467
470
  'billing_requests' => {
468
471
 
469
472
  'actions' => 'actions-input',
470
- 'auto_fulfil' => 'auto_fulfil-input',
471
473
  'created_at' => 'created_at-input',
474
+ 'fallback_enabled' => 'fallback_enabled-input',
472
475
  'id' => 'id-input',
473
476
  'links' => 'links-input',
474
477
  'mandate_request' => 'mandate_request-input',
@@ -478,6 +481,7 @@ describe GoCardlessPro::Resources::BillingRequest do
478
481
  'status' => 'status-input',
479
482
  },
480
483
  }.to_json,
484
+
481
485
  headers: response_headers
482
486
  )
483
487
  end
@@ -491,13 +495,13 @@ describe GoCardlessPro::Resources::BillingRequest do
491
495
  context 'when the request needs a body and custom header' do
492
496
  let(:body) { { foo: 'bar' } }
493
497
  let(:headers) { { 'Foo' => 'Bar' } }
494
- subject(:post_response) { client.billing_requests.collect_bank_account_details(resource_id, body, headers) }
498
+ subject(:post_response) { client.billing_requests.collect_bank_account(resource_id, body, headers) }
495
499
 
496
500
  let(:resource_id) { 'ABC123' }
497
501
 
498
502
  let!(:stub) do
499
- # /billing_requests/%v/actions/collect_bank_account_details
500
- stub_url = '/billing_requests/:identity/actions/collect_bank_account_details'.gsub(':identity', resource_id)
503
+ # /billing_requests/%v/actions/collect_bank_account
504
+ stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
501
505
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).
502
506
  with(
503
507
  body: { foo: 'bar' },
@@ -507,8 +511,8 @@ describe GoCardlessPro::Resources::BillingRequest do
507
511
  'billing_requests' => {
508
512
 
509
513
  'actions' => 'actions-input',
510
- 'auto_fulfil' => 'auto_fulfil-input',
511
514
  'created_at' => 'created_at-input',
515
+ 'fallback_enabled' => 'fallback_enabled-input',
512
516
  'id' => 'id-input',
513
517
  'links' => 'links-input',
514
518
  'mandate_request' => 'mandate_request-input',
@@ -533,12 +537,13 @@ describe GoCardlessPro::Resources::BillingRequest do
533
537
  # /billing_requests/%v/actions/fulfil
534
538
  stub_url = '/billing_requests/:identity/actions/fulfil'.gsub(':identity', resource_id)
535
539
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
540
+
536
541
  body: {
537
542
  'billing_requests' => {
538
543
 
539
544
  'actions' => 'actions-input',
540
- 'auto_fulfil' => 'auto_fulfil-input',
541
545
  'created_at' => 'created_at-input',
546
+ 'fallback_enabled' => 'fallback_enabled-input',
542
547
  'id' => 'id-input',
543
548
  'links' => 'links-input',
544
549
  'mandate_request' => 'mandate_request-input',
@@ -548,6 +553,7 @@ describe GoCardlessPro::Resources::BillingRequest do
548
553
  'status' => 'status-input',
549
554
  },
550
555
  }.to_json,
556
+
551
557
  headers: response_headers
552
558
  )
553
559
  end
@@ -577,8 +583,80 @@ describe GoCardlessPro::Resources::BillingRequest do
577
583
  'billing_requests' => {
578
584
 
579
585
  'actions' => 'actions-input',
580
- 'auto_fulfil' => 'auto_fulfil-input',
581
586
  'created_at' => 'created_at-input',
587
+ 'fallback_enabled' => 'fallback_enabled-input',
588
+ 'id' => 'id-input',
589
+ 'links' => 'links-input',
590
+ 'mandate_request' => 'mandate_request-input',
591
+ 'metadata' => 'metadata-input',
592
+ 'payment_request' => 'payment_request-input',
593
+ 'resources' => 'resources-input',
594
+ 'status' => 'status-input',
595
+ },
596
+ }.to_json,
597
+ headers: response_headers
598
+ )
599
+ end
600
+ end
601
+ end
602
+
603
+ describe '#confirm_payer_details' do
604
+ subject(:post_response) { client.billing_requests.confirm_payer_details(resource_id) }
605
+
606
+ let(:resource_id) { 'ABC123' }
607
+
608
+ let!(:stub) do
609
+ # /billing_requests/%v/actions/confirm_payer_details
610
+ stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
611
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
612
+
613
+ body: {
614
+ 'billing_requests' => {
615
+
616
+ 'actions' => 'actions-input',
617
+ 'created_at' => 'created_at-input',
618
+ 'fallback_enabled' => 'fallback_enabled-input',
619
+ 'id' => 'id-input',
620
+ 'links' => 'links-input',
621
+ 'mandate_request' => 'mandate_request-input',
622
+ 'metadata' => 'metadata-input',
623
+ 'payment_request' => 'payment_request-input',
624
+ 'resources' => 'resources-input',
625
+ 'status' => 'status-input',
626
+ },
627
+ }.to_json,
628
+
629
+ headers: response_headers
630
+ )
631
+ end
632
+
633
+ it 'wraps the response and calls the right endpoint' do
634
+ expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
635
+
636
+ expect(stub).to have_been_requested
637
+ end
638
+
639
+ context 'when the request needs a body and custom header' do
640
+ let(:body) { { foo: 'bar' } }
641
+ let(:headers) { { 'Foo' => 'Bar' } }
642
+ subject(:post_response) { client.billing_requests.confirm_payer_details(resource_id, body, headers) }
643
+
644
+ let(:resource_id) { 'ABC123' }
645
+
646
+ let!(:stub) do
647
+ # /billing_requests/%v/actions/confirm_payer_details
648
+ stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
649
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
650
+ with(
651
+ body: { foo: 'bar' },
652
+ headers: { 'Foo' => 'Bar' }
653
+ ).to_return(
654
+ body: {
655
+ 'billing_requests' => {
656
+
657
+ 'actions' => 'actions-input',
658
+ 'created_at' => 'created_at-input',
659
+ 'fallback_enabled' => 'fallback_enabled-input',
582
660
  'id' => 'id-input',
583
661
  'links' => 'links-input',
584
662
  'mandate_request' => 'mandate_request-input',
@@ -603,12 +681,13 @@ describe GoCardlessPro::Resources::BillingRequest do
603
681
  # /billing_requests/%v/actions/cancel
604
682
  stub_url = '/billing_requests/:identity/actions/cancel'.gsub(':identity', resource_id)
605
683
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
684
+
606
685
  body: {
607
686
  'billing_requests' => {
608
687
 
609
688
  'actions' => 'actions-input',
610
- 'auto_fulfil' => 'auto_fulfil-input',
611
689
  'created_at' => 'created_at-input',
690
+ 'fallback_enabled' => 'fallback_enabled-input',
612
691
  'id' => 'id-input',
613
692
  'links' => 'links-input',
614
693
  'mandate_request' => 'mandate_request-input',
@@ -618,6 +697,7 @@ describe GoCardlessPro::Resources::BillingRequest do
618
697
  'status' => 'status-input',
619
698
  },
620
699
  }.to_json,
700
+
621
701
  headers: response_headers
622
702
  )
623
703
  end
@@ -647,8 +727,8 @@ describe GoCardlessPro::Resources::BillingRequest do
647
727
  'billing_requests' => {
648
728
 
649
729
  'actions' => 'actions-input',
650
- 'auto_fulfil' => 'auto_fulfil-input',
651
730
  'created_at' => 'created_at-input',
731
+ 'fallback_enabled' => 'fallback_enabled-input',
652
732
  'id' => 'id-input',
653
733
  'links' => 'links-input',
654
734
  'mandate_request' => 'mandate_request-input',
@@ -673,12 +753,13 @@ describe GoCardlessPro::Resources::BillingRequest do
673
753
  # /billing_requests/%v/actions/notify
674
754
  stub_url = '/billing_requests/:identity/actions/notify'.gsub(':identity', resource_id)
675
755
  stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
756
+
676
757
  body: {
677
758
  'billing_requests' => {
678
759
 
679
760
  'actions' => 'actions-input',
680
- 'auto_fulfil' => 'auto_fulfil-input',
681
761
  'created_at' => 'created_at-input',
762
+ 'fallback_enabled' => 'fallback_enabled-input',
682
763
  'id' => 'id-input',
683
764
  'links' => 'links-input',
684
765
  'mandate_request' => 'mandate_request-input',
@@ -688,6 +769,7 @@ describe GoCardlessPro::Resources::BillingRequest do
688
769
  'status' => 'status-input',
689
770
  },
690
771
  }.to_json,
772
+
691
773
  headers: response_headers
692
774
  )
693
775
  end
@@ -717,8 +799,80 @@ describe GoCardlessPro::Resources::BillingRequest do
717
799
  'billing_requests' => {
718
800
 
719
801
  'actions' => 'actions-input',
720
- 'auto_fulfil' => 'auto_fulfil-input',
721
802
  'created_at' => 'created_at-input',
803
+ 'fallback_enabled' => 'fallback_enabled-input',
804
+ 'id' => 'id-input',
805
+ 'links' => 'links-input',
806
+ 'mandate_request' => 'mandate_request-input',
807
+ 'metadata' => 'metadata-input',
808
+ 'payment_request' => 'payment_request-input',
809
+ 'resources' => 'resources-input',
810
+ 'status' => 'status-input',
811
+ },
812
+ }.to_json,
813
+ headers: response_headers
814
+ )
815
+ end
816
+ end
817
+ end
818
+
819
+ describe '#fallback' do
820
+ subject(:post_response) { client.billing_requests.fallback(resource_id) }
821
+
822
+ let(:resource_id) { 'ABC123' }
823
+
824
+ let!(:stub) do
825
+ # /billing_requests/%v/actions/fallback
826
+ stub_url = '/billing_requests/:identity/actions/fallback'.gsub(':identity', resource_id)
827
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
828
+
829
+ body: {
830
+ 'billing_requests' => {
831
+
832
+ 'actions' => 'actions-input',
833
+ 'created_at' => 'created_at-input',
834
+ 'fallback_enabled' => 'fallback_enabled-input',
835
+ 'id' => 'id-input',
836
+ 'links' => 'links-input',
837
+ 'mandate_request' => 'mandate_request-input',
838
+ 'metadata' => 'metadata-input',
839
+ 'payment_request' => 'payment_request-input',
840
+ 'resources' => 'resources-input',
841
+ 'status' => 'status-input',
842
+ },
843
+ }.to_json,
844
+
845
+ headers: response_headers
846
+ )
847
+ end
848
+
849
+ it 'wraps the response and calls the right endpoint' do
850
+ expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
851
+
852
+ expect(stub).to have_been_requested
853
+ end
854
+
855
+ context 'when the request needs a body and custom header' do
856
+ let(:body) { { foo: 'bar' } }
857
+ let(:headers) { { 'Foo' => 'Bar' } }
858
+ subject(:post_response) { client.billing_requests.fallback(resource_id, body, headers) }
859
+
860
+ let(:resource_id) { 'ABC123' }
861
+
862
+ let!(:stub) do
863
+ # /billing_requests/%v/actions/fallback
864
+ stub_url = '/billing_requests/:identity/actions/fallback'.gsub(':identity', resource_id)
865
+ stub_request(:post, /.*api.gocardless.com#{stub_url}/).
866
+ with(
867
+ body: { foo: 'bar' },
868
+ headers: { 'Foo' => 'Bar' }
869
+ ).to_return(
870
+ body: {
871
+ 'billing_requests' => {
872
+
873
+ 'actions' => 'actions-input',
874
+ 'created_at' => 'created_at-input',
875
+ 'fallback_enabled' => 'fallback_enabled-input',
722
876
  'id' => 'id-input',
723
877
  'links' => 'links-input',
724
878
  'mandate_request' => 'mandate_request-input',