gocardless_pro 2.41.0 → 2.41.1

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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gocardless_pro/api_service.rb +4 -5
  3. data/lib/gocardless_pro/client.rb +3 -3
  4. data/lib/gocardless_pro/error/invalid_state_error.rb +1 -0
  5. data/lib/gocardless_pro/error.rb +1 -0
  6. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +7 -9
  7. data/lib/gocardless_pro/request.rb +5 -7
  8. data/lib/gocardless_pro/resources/bank_authorisation.rb +0 -2
  9. data/lib/gocardless_pro/resources/bank_details_lookup.rb +0 -2
  10. data/lib/gocardless_pro/resources/billing_request.rb +0 -2
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +0 -2
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +0 -2
  13. data/lib/gocardless_pro/resources/block.rb +0 -2
  14. data/lib/gocardless_pro/resources/creditor.rb +0 -2
  15. data/lib/gocardless_pro/resources/creditor_bank_account.rb +0 -2
  16. data/lib/gocardless_pro/resources/currency_exchange_rate.rb +0 -2
  17. data/lib/gocardless_pro/resources/customer.rb +0 -2
  18. data/lib/gocardless_pro/resources/customer_bank_account.rb +0 -2
  19. data/lib/gocardless_pro/resources/customer_notification.rb +0 -2
  20. data/lib/gocardless_pro/resources/event.rb +0 -2
  21. data/lib/gocardless_pro/resources/instalment_schedule.rb +0 -2
  22. data/lib/gocardless_pro/resources/institution.rb +0 -2
  23. data/lib/gocardless_pro/resources/mandate.rb +0 -2
  24. data/lib/gocardless_pro/resources/mandate_import.rb +0 -2
  25. data/lib/gocardless_pro/resources/mandate_import_entry.rb +0 -2
  26. data/lib/gocardless_pro/resources/mandate_pdf.rb +0 -2
  27. data/lib/gocardless_pro/resources/payer_authorisation.rb +0 -2
  28. data/lib/gocardless_pro/resources/payment.rb +0 -2
  29. data/lib/gocardless_pro/resources/payout.rb +0 -2
  30. data/lib/gocardless_pro/resources/payout_item.rb +0 -2
  31. data/lib/gocardless_pro/resources/redirect_flow.rb +0 -2
  32. data/lib/gocardless_pro/resources/refund.rb +0 -2
  33. data/lib/gocardless_pro/resources/scenario_simulator.rb +0 -2
  34. data/lib/gocardless_pro/resources/scheme_identifier.rb +0 -2
  35. data/lib/gocardless_pro/resources/subscription.rb +0 -2
  36. data/lib/gocardless_pro/resources/tax_rate.rb +0 -2
  37. data/lib/gocardless_pro/resources/verification_detail.rb +0 -2
  38. data/lib/gocardless_pro/resources/webhook.rb +0 -2
  39. data/lib/gocardless_pro/services/bank_authorisations_service.rb +3 -1
  40. data/lib/gocardless_pro/services/billing_request_flows_service.rb +3 -1
  41. data/lib/gocardless_pro/services/billing_request_templates_service.rb +6 -2
  42. data/lib/gocardless_pro/services/billing_requests_service.rb +27 -9
  43. data/lib/gocardless_pro/services/blocks_service.rb +9 -3
  44. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +6 -2
  45. data/lib/gocardless_pro/services/creditors_service.rb +9 -3
  46. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +9 -3
  47. data/lib/gocardless_pro/services/customer_notifications_service.rb +3 -1
  48. data/lib/gocardless_pro/services/customers_service.rb +9 -3
  49. data/lib/gocardless_pro/services/events_service.rb +3 -1
  50. data/lib/gocardless_pro/services/instalment_schedules_service.rb +9 -3
  51. data/lib/gocardless_pro/services/mandate_imports_service.rb +9 -3
  52. data/lib/gocardless_pro/services/mandates_service.rb +12 -4
  53. data/lib/gocardless_pro/services/payer_authorisations_service.rb +12 -4
  54. data/lib/gocardless_pro/services/payments_service.rb +12 -4
  55. data/lib/gocardless_pro/services/payouts_service.rb +6 -2
  56. data/lib/gocardless_pro/services/redirect_flows_service.rb +6 -2
  57. data/lib/gocardless_pro/services/refunds_service.rb +6 -2
  58. data/lib/gocardless_pro/services/scenario_simulators_service.rb +3 -1
  59. data/lib/gocardless_pro/services/scheme_identifiers_service.rb +3 -1
  60. data/lib/gocardless_pro/services/subscriptions_service.rb +15 -5
  61. data/lib/gocardless_pro/services/tax_rates_service.rb +3 -1
  62. data/lib/gocardless_pro/services/webhooks_service.rb +6 -2
  63. data/lib/gocardless_pro/version.rb +1 -2
  64. data/lib/gocardless_pro/webhook.rb +5 -4
  65. data/lib/gocardless_pro.rb +2 -4
  66. metadata +5 -195
  67. data/.github/workflows/tests.yml +0 -40
  68. data/.gitignore +0 -1
  69. data/.rspec +0 -2
  70. data/.rubocop.yml +0 -5
  71. data/.travis.yml +0 -10
  72. data/LICENSE.txt +0 -22
  73. data/demo.rb +0 -9
  74. data/gocardless_pro.gemspec +0 -39
  75. data/spec/api_response_spec.rb +0 -28
  76. data/spec/api_service_spec.rb +0 -188
  77. data/spec/client_spec.rb +0 -19
  78. data/spec/error_spec.rb +0 -53
  79. data/spec/middlewares/raise_gocardless_errors_spec.rb +0 -127
  80. data/spec/resources/bank_authorisation_spec.rb +0 -259
  81. data/spec/resources/bank_details_lookup_spec.rb +0 -121
  82. data/spec/resources/billing_request_flow_spec.rb +0 -257
  83. data/spec/resources/billing_request_spec.rb +0 -962
  84. data/spec/resources/billing_request_template_spec.rb +0 -515
  85. data/spec/resources/block_spec.rb +0 -577
  86. data/spec/resources/creditor_bank_account_spec.rb +0 -472
  87. data/spec/resources/creditor_spec.rb +0 -659
  88. data/spec/resources/currency_exchange_rate_spec.rb +0 -103
  89. data/spec/resources/customer_bank_account_spec.rb +0 -509
  90. data/spec/resources/customer_notification_spec.rb +0 -75
  91. data/spec/resources/customer_spec.rb +0 -616
  92. data/spec/resources/event_spec.rb +0 -210
  93. data/spec/resources/instalment_schedule_spec.rb +0 -636
  94. data/spec/resources/institution_spec.rb +0 -113
  95. data/spec/resources/mandate_import_entry_spec.rb +0 -206
  96. data/spec/resources/mandate_import_spec.rb +0 -344
  97. data/spec/resources/mandate_pdf_spec.rb +0 -117
  98. data/spec/resources/mandate_spec.rb +0 -600
  99. data/spec/resources/payer_authorisation_spec.rb +0 -422
  100. data/spec/resources/payment_spec.rb +0 -617
  101. data/spec/resources/payout_item_spec.rb +0 -101
  102. data/spec/resources/payout_spec.rb +0 -284
  103. data/spec/resources/redirect_flow_spec.rb +0 -347
  104. data/spec/resources/refund_spec.rb +0 -409
  105. data/spec/resources/scenario_simulator_spec.rb +0 -65
  106. data/spec/resources/scheme_identifier_spec.rb +0 -484
  107. data/spec/resources/subscription_spec.rb +0 -828
  108. data/spec/resources/tax_rate_spec.rb +0 -198
  109. data/spec/resources/verification_detail_spec.rb +0 -145
  110. data/spec/resources/webhook_spec.rb +0 -325
  111. data/spec/response_spec.rb +0 -34
  112. data/spec/services/bank_authorisations_service_spec.rb +0 -353
  113. data/spec/services/bank_details_lookups_service_spec.rb +0 -144
  114. data/spec/services/billing_request_flows_service_spec.rb +0 -291
  115. data/spec/services/billing_request_templates_service_spec.rb +0 -806
  116. data/spec/services/billing_requests_service_spec.rb +0 -1288
  117. data/spec/services/blocks_service_spec.rb +0 -840
  118. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -725
  119. data/spec/services/creditors_service_spec.rb +0 -977
  120. data/spec/services/currency_exchange_rates_service_spec.rb +0 -223
  121. data/spec/services/customer_bank_accounts_service_spec.rb +0 -787
  122. data/spec/services/customer_notifications_service_spec.rb +0 -86
  123. data/spec/services/customers_service_spec.rb +0 -922
  124. data/spec/services/events_service_spec.rb +0 -401
  125. data/spec/services/instalment_schedules_service_spec.rb +0 -945
  126. data/spec/services/institutions_service_spec.rb +0 -241
  127. data/spec/services/mandate_import_entries_service_spec.rb +0 -345
  128. data/spec/services/mandate_imports_service_spec.rb +0 -460
  129. data/spec/services/mandate_pdfs_service_spec.rb +0 -140
  130. data/spec/services/mandates_service_spec.rb +0 -893
  131. data/spec/services/payer_authorisations_service_spec.rb +0 -563
  132. data/spec/services/payments_service_spec.rb +0 -914
  133. data/spec/services/payout_items_service_spec.rb +0 -221
  134. data/spec/services/payouts_service_spec.rb +0 -520
  135. data/spec/services/redirect_flows_service_spec.rb +0 -452
  136. data/spec/services/refunds_service_spec.rb +0 -668
  137. data/spec/services/scenario_simulators_service_spec.rb +0 -76
  138. data/spec/services/scheme_identifiers_service_spec.rb +0 -754
  139. data/spec/services/subscriptions_service_spec.rb +0 -1164
  140. data/spec/services/tax_rates_service_spec.rb +0 -381
  141. data/spec/services/verification_details_service_spec.rb +0 -168
  142. data/spec/services/webhooks_service_spec.rb +0 -547
  143. data/spec/spec_helper.rb +0 -90
  144. data/spec/webhook_spec.rb +0 -122
@@ -1,962 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Resources::BillingRequest 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 '#list' do
13
- describe 'with no filters' do
14
- subject(:get_list_response) { client.billing_requests.list }
15
-
16
- before do
17
- stub_request(:get, %r{.*api.gocardless.com/billing_requests}).to_return(
18
- body: {
19
- 'billing_requests' => [{
20
-
21
- 'actions' => 'actions-input',
22
- 'created_at' => 'created_at-input',
23
- 'fallback_enabled' => 'fallback_enabled-input',
24
- 'id' => 'id-input',
25
- 'links' => 'links-input',
26
- 'mandate_request' => 'mandate_request-input',
27
- 'metadata' => 'metadata-input',
28
- 'payment_request' => 'payment_request-input',
29
- 'resources' => 'resources-input',
30
- 'status' => 'status-input',
31
- }],
32
- meta: {
33
- cursors: {
34
- before: nil,
35
- after: 'ABC123',
36
- },
37
- },
38
- }.to_json,
39
- headers: response_headers
40
- )
41
- end
42
-
43
- it 'wraps each item in the resource class' do
44
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::BillingRequest)
45
-
46
- expect(get_list_response.records.first.actions).to eq('actions-input')
47
-
48
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
49
-
50
- expect(get_list_response.records.first.fallback_enabled).to eq('fallback_enabled-input')
51
-
52
- expect(get_list_response.records.first.id).to eq('id-input')
53
-
54
- expect(get_list_response.records.first.mandate_request).to eq('mandate_request-input')
55
-
56
- expect(get_list_response.records.first.metadata).to eq('metadata-input')
57
-
58
- expect(get_list_response.records.first.payment_request).to eq('payment_request-input')
59
-
60
- expect(get_list_response.records.first.resources).to eq('resources-input')
61
-
62
- expect(get_list_response.records.first.status).to eq('status-input')
63
- end
64
-
65
- it 'exposes the cursors for before and after' do
66
- expect(get_list_response.before).to eq(nil)
67
- expect(get_list_response.after).to eq('ABC123')
68
- end
69
-
70
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
71
- end
72
- end
73
-
74
- describe '#all' do
75
- let!(:first_response_stub) do
76
- stub_request(:get, %r{.*api.gocardless.com/billing_requests$}).to_return(
77
- body: {
78
- 'billing_requests' => [{
79
-
80
- 'actions' => 'actions-input',
81
- 'created_at' => 'created_at-input',
82
- 'fallback_enabled' => 'fallback_enabled-input',
83
- 'id' => 'id-input',
84
- 'links' => 'links-input',
85
- 'mandate_request' => 'mandate_request-input',
86
- 'metadata' => 'metadata-input',
87
- 'payment_request' => 'payment_request-input',
88
- 'resources' => 'resources-input',
89
- 'status' => 'status-input',
90
- }],
91
- meta: {
92
- cursors: { after: 'AB345' },
93
- limit: 1,
94
- },
95
- }.to_json,
96
- headers: response_headers
97
- )
98
- end
99
-
100
- let!(:second_response_stub) do
101
- stub_request(:get, %r{.*api.gocardless.com/billing_requests\?after=AB345}).to_return(
102
- body: {
103
- 'billing_requests' => [{
104
-
105
- 'actions' => 'actions-input',
106
- 'created_at' => 'created_at-input',
107
- 'fallback_enabled' => 'fallback_enabled-input',
108
- 'id' => 'id-input',
109
- 'links' => 'links-input',
110
- 'mandate_request' => 'mandate_request-input',
111
- 'metadata' => 'metadata-input',
112
- 'payment_request' => 'payment_request-input',
113
- 'resources' => 'resources-input',
114
- 'status' => 'status-input',
115
- }],
116
- meta: {
117
- limit: 2,
118
- cursors: {},
119
- },
120
- }.to_json,
121
- headers: response_headers
122
- )
123
- end
124
-
125
- it 'automatically makes the extra requests' do
126
- expect(client.billing_requests.all.to_a.length).to eq(2)
127
- expect(first_response_stub).to have_been_requested
128
- expect(second_response_stub).to have_been_requested
129
- end
130
- end
131
-
132
- describe '#create' do
133
- subject(:post_create_response) { client.billing_requests.create(params: new_resource) }
134
- context 'with a valid request' do
135
- let(:new_resource) do
136
- {
137
-
138
- 'actions' => 'actions-input',
139
- 'created_at' => 'created_at-input',
140
- 'fallback_enabled' => 'fallback_enabled-input',
141
- 'id' => 'id-input',
142
- 'links' => 'links-input',
143
- 'mandate_request' => 'mandate_request-input',
144
- 'metadata' => 'metadata-input',
145
- 'payment_request' => 'payment_request-input',
146
- 'resources' => 'resources-input',
147
- 'status' => 'status-input',
148
- }
149
- end
150
-
151
- before do
152
- stub_request(:post, %r{.*api.gocardless.com/billing_requests}).
153
- with(
154
- body: {
155
- 'billing_requests' => {
156
-
157
- 'actions' => 'actions-input',
158
- 'created_at' => 'created_at-input',
159
- 'fallback_enabled' => 'fallback_enabled-input',
160
- 'id' => 'id-input',
161
- 'links' => 'links-input',
162
- 'mandate_request' => 'mandate_request-input',
163
- 'metadata' => 'metadata-input',
164
- 'payment_request' => 'payment_request-input',
165
- 'resources' => 'resources-input',
166
- 'status' => 'status-input',
167
- },
168
- }
169
- ).
170
- to_return(
171
- body: {
172
- 'billing_requests' =>
173
-
174
- {
175
-
176
- 'actions' => 'actions-input',
177
- 'created_at' => 'created_at-input',
178
- 'fallback_enabled' => 'fallback_enabled-input',
179
- 'id' => 'id-input',
180
- 'links' => 'links-input',
181
- 'mandate_request' => 'mandate_request-input',
182
- 'metadata' => 'metadata-input',
183
- 'payment_request' => 'payment_request-input',
184
- 'resources' => 'resources-input',
185
- 'status' => 'status-input',
186
- },
187
-
188
- }.to_json,
189
- headers: response_headers
190
- )
191
- end
192
-
193
- it 'creates and returns the resource' do
194
- expect(post_create_response).to be_a(GoCardlessPro::Resources::BillingRequest)
195
- end
196
- end
197
-
198
- context 'with a request that returns a validation error' do
199
- let(:new_resource) { {} }
200
-
201
- before do
202
- stub_request(:post, %r{.*api.gocardless.com/billing_requests}).to_return(
203
- body: {
204
- error: {
205
- type: 'validation_failed',
206
- code: 422,
207
- errors: [
208
- { message: 'test error message', field: 'test_field' },
209
- ],
210
- },
211
- }.to_json,
212
- headers: response_headers,
213
- status: 422
214
- )
215
- end
216
-
217
- it 'throws the correct error' do
218
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
219
- end
220
- end
221
-
222
- context 'with a request that returns an idempotent creation conflict error' do
223
- let(:id) { 'ID123' }
224
-
225
- let(:new_resource) do
226
- {
227
-
228
- 'actions' => 'actions-input',
229
- 'created_at' => 'created_at-input',
230
- 'fallback_enabled' => 'fallback_enabled-input',
231
- 'id' => 'id-input',
232
- 'links' => 'links-input',
233
- 'mandate_request' => 'mandate_request-input',
234
- 'metadata' => 'metadata-input',
235
- 'payment_request' => 'payment_request-input',
236
- 'resources' => 'resources-input',
237
- 'status' => 'status-input',
238
- }
239
- end
240
-
241
- let!(:post_stub) do
242
- stub_request(:post, %r{.*api.gocardless.com/billing_requests}).to_return(
243
- body: {
244
- error: {
245
- type: 'invalid_state',
246
- code: 409,
247
- errors: [
248
- {
249
- message: 'A resource has already been created with this idempotency key',
250
- reason: 'idempotent_creation_conflict',
251
- links: {
252
- conflicting_resource_id: id,
253
- },
254
- },
255
- ],
256
- },
257
- }.to_json,
258
- headers: response_headers,
259
- status: 409
260
- )
261
- end
262
-
263
- let!(:get_stub) do
264
- stub_url = "/billing_requests/#{id}"
265
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
266
- to_return(
267
- body: {
268
- 'billing_requests' => {
269
-
270
- 'actions' => 'actions-input',
271
- 'created_at' => 'created_at-input',
272
- 'fallback_enabled' => 'fallback_enabled-input',
273
- 'id' => 'id-input',
274
- 'links' => 'links-input',
275
- 'mandate_request' => 'mandate_request-input',
276
- 'metadata' => 'metadata-input',
277
- 'payment_request' => 'payment_request-input',
278
- 'resources' => 'resources-input',
279
- 'status' => 'status-input',
280
- },
281
- }.to_json,
282
- headers: response_headers
283
- )
284
- end
285
-
286
- it 'fetches the already-created resource' do
287
- post_create_response
288
- expect(post_stub).to have_been_requested
289
- expect(get_stub).to have_been_requested
290
- end
291
- end
292
- end
293
-
294
- describe '#get' do
295
- let(:id) { 'ID123' }
296
-
297
- subject(:get_response) { client.billing_requests.get(id) }
298
-
299
- context 'passing in a custom header' do
300
- let!(:stub) do
301
- stub_url = '/billing_requests/:identity'.gsub(':identity', id)
302
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
303
- with(headers: { 'Foo' => 'Bar' }).
304
- to_return(
305
- body: {
306
- 'billing_requests' => {
307
-
308
- 'actions' => 'actions-input',
309
- 'created_at' => 'created_at-input',
310
- 'fallback_enabled' => 'fallback_enabled-input',
311
- 'id' => 'id-input',
312
- 'links' => 'links-input',
313
- 'mandate_request' => 'mandate_request-input',
314
- 'metadata' => 'metadata-input',
315
- 'payment_request' => 'payment_request-input',
316
- 'resources' => 'resources-input',
317
- 'status' => 'status-input',
318
- },
319
- }.to_json,
320
- headers: response_headers
321
- )
322
- end
323
-
324
- subject(:get_response) do
325
- client.billing_requests.get(id, headers: {
326
- 'Foo' => 'Bar',
327
- })
328
- end
329
-
330
- it 'includes the header' do
331
- get_response
332
- expect(stub).to have_been_requested
333
- end
334
- end
335
-
336
- context 'when there is a billing_request to return' do
337
- before do
338
- stub_url = '/billing_requests/:identity'.gsub(':identity', id)
339
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
340
- body: {
341
- 'billing_requests' => {
342
-
343
- 'actions' => 'actions-input',
344
- 'created_at' => 'created_at-input',
345
- 'fallback_enabled' => 'fallback_enabled-input',
346
- 'id' => 'id-input',
347
- 'links' => 'links-input',
348
- 'mandate_request' => 'mandate_request-input',
349
- 'metadata' => 'metadata-input',
350
- 'payment_request' => 'payment_request-input',
351
- 'resources' => 'resources-input',
352
- 'status' => 'status-input',
353
- },
354
- }.to_json,
355
- headers: response_headers
356
- )
357
- end
358
-
359
- it 'wraps the response in a resource' do
360
- expect(get_response).to be_a(GoCardlessPro::Resources::BillingRequest)
361
- end
362
- end
363
-
364
- context 'when nothing is returned' do
365
- before do
366
- stub_url = '/billing_requests/:identity'.gsub(':identity', id)
367
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
368
- body: '',
369
- headers: response_headers
370
- )
371
- end
372
-
373
- it 'returns nil' do
374
- expect(get_response).to be_nil
375
- end
376
- end
377
-
378
- context "when an ID is specified which can't be included in a valid URI" do
379
- let(:id) { '`' }
380
-
381
- it "doesn't raise an error" do
382
- expect { get_response }.to_not raise_error(/bad URI/)
383
- end
384
- end
385
- end
386
-
387
- describe '#collect_customer_details' do
388
- subject(:post_response) { client.billing_requests.collect_customer_details(resource_id) }
389
-
390
- let(:resource_id) { 'ABC123' }
391
-
392
- let!(:stub) do
393
- # /billing_requests/%v/actions/collect_customer_details
394
- stub_url = '/billing_requests/:identity/actions/collect_customer_details'.gsub(':identity', resource_id)
395
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
396
-
397
- body: {
398
- 'billing_requests' => {
399
-
400
- 'actions' => 'actions-input',
401
- 'created_at' => 'created_at-input',
402
- 'fallback_enabled' => 'fallback_enabled-input',
403
- 'id' => 'id-input',
404
- 'links' => 'links-input',
405
- 'mandate_request' => 'mandate_request-input',
406
- 'metadata' => 'metadata-input',
407
- 'payment_request' => 'payment_request-input',
408
- 'resources' => 'resources-input',
409
- 'status' => 'status-input',
410
- },
411
- }.to_json,
412
-
413
- headers: response_headers
414
- )
415
- end
416
-
417
- it 'wraps the response and calls the right endpoint' do
418
- expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
419
-
420
- expect(stub).to have_been_requested
421
- end
422
-
423
- context 'when the request needs a body and custom header' do
424
- let(:body) { { foo: 'bar' } }
425
- let(:headers) { { 'Foo' => 'Bar' } }
426
- subject(:post_response) { client.billing_requests.collect_customer_details(resource_id, body, headers) }
427
-
428
- let(:resource_id) { 'ABC123' }
429
-
430
- let!(:stub) do
431
- # /billing_requests/%v/actions/collect_customer_details
432
- stub_url = '/billing_requests/:identity/actions/collect_customer_details'.gsub(':identity', resource_id)
433
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
434
- with(
435
- body: { foo: 'bar' },
436
- headers: { 'Foo' => 'Bar' }
437
- ).to_return(
438
- body: {
439
- 'billing_requests' => {
440
-
441
- 'actions' => 'actions-input',
442
- 'created_at' => 'created_at-input',
443
- 'fallback_enabled' => 'fallback_enabled-input',
444
- 'id' => 'id-input',
445
- 'links' => 'links-input',
446
- 'mandate_request' => 'mandate_request-input',
447
- 'metadata' => 'metadata-input',
448
- 'payment_request' => 'payment_request-input',
449
- 'resources' => 'resources-input',
450
- 'status' => 'status-input',
451
- },
452
- }.to_json,
453
- headers: response_headers
454
- )
455
- end
456
- end
457
- end
458
-
459
- describe '#collect_bank_account' do
460
- subject(:post_response) { client.billing_requests.collect_bank_account(resource_id) }
461
-
462
- let(:resource_id) { 'ABC123' }
463
-
464
- let!(:stub) do
465
- # /billing_requests/%v/actions/collect_bank_account
466
- stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
467
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
468
-
469
- body: {
470
- 'billing_requests' => {
471
-
472
- 'actions' => 'actions-input',
473
- 'created_at' => 'created_at-input',
474
- 'fallback_enabled' => 'fallback_enabled-input',
475
- 'id' => 'id-input',
476
- 'links' => 'links-input',
477
- 'mandate_request' => 'mandate_request-input',
478
- 'metadata' => 'metadata-input',
479
- 'payment_request' => 'payment_request-input',
480
- 'resources' => 'resources-input',
481
- 'status' => 'status-input',
482
- },
483
- }.to_json,
484
-
485
- headers: response_headers
486
- )
487
- end
488
-
489
- it 'wraps the response and calls the right endpoint' do
490
- expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
491
-
492
- expect(stub).to have_been_requested
493
- end
494
-
495
- context 'when the request needs a body and custom header' do
496
- let(:body) { { foo: 'bar' } }
497
- let(:headers) { { 'Foo' => 'Bar' } }
498
- subject(:post_response) { client.billing_requests.collect_bank_account(resource_id, body, headers) }
499
-
500
- let(:resource_id) { 'ABC123' }
501
-
502
- let!(:stub) do
503
- # /billing_requests/%v/actions/collect_bank_account
504
- stub_url = '/billing_requests/:identity/actions/collect_bank_account'.gsub(':identity', resource_id)
505
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
506
- with(
507
- body: { foo: 'bar' },
508
- headers: { 'Foo' => 'Bar' }
509
- ).to_return(
510
- body: {
511
- 'billing_requests' => {
512
-
513
- 'actions' => 'actions-input',
514
- 'created_at' => 'created_at-input',
515
- 'fallback_enabled' => 'fallback_enabled-input',
516
- 'id' => 'id-input',
517
- 'links' => 'links-input',
518
- 'mandate_request' => 'mandate_request-input',
519
- 'metadata' => 'metadata-input',
520
- 'payment_request' => 'payment_request-input',
521
- 'resources' => 'resources-input',
522
- 'status' => 'status-input',
523
- },
524
- }.to_json,
525
- headers: response_headers
526
- )
527
- end
528
- end
529
- end
530
-
531
- describe '#fulfil' do
532
- subject(:post_response) { client.billing_requests.fulfil(resource_id) }
533
-
534
- let(:resource_id) { 'ABC123' }
535
-
536
- let!(:stub) do
537
- # /billing_requests/%v/actions/fulfil
538
- stub_url = '/billing_requests/:identity/actions/fulfil'.gsub(':identity', resource_id)
539
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
540
-
541
- body: {
542
- 'billing_requests' => {
543
-
544
- 'actions' => 'actions-input',
545
- 'created_at' => 'created_at-input',
546
- 'fallback_enabled' => 'fallback_enabled-input',
547
- 'id' => 'id-input',
548
- 'links' => 'links-input',
549
- 'mandate_request' => 'mandate_request-input',
550
- 'metadata' => 'metadata-input',
551
- 'payment_request' => 'payment_request-input',
552
- 'resources' => 'resources-input',
553
- 'status' => 'status-input',
554
- },
555
- }.to_json,
556
-
557
- headers: response_headers
558
- )
559
- end
560
-
561
- it 'wraps the response and calls the right endpoint' do
562
- expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
563
-
564
- expect(stub).to have_been_requested
565
- end
566
-
567
- context 'when the request needs a body and custom header' do
568
- let(:body) { { foo: 'bar' } }
569
- let(:headers) { { 'Foo' => 'Bar' } }
570
- subject(:post_response) { client.billing_requests.fulfil(resource_id, body, headers) }
571
-
572
- let(:resource_id) { 'ABC123' }
573
-
574
- let!(:stub) do
575
- # /billing_requests/%v/actions/fulfil
576
- stub_url = '/billing_requests/:identity/actions/fulfil'.gsub(':identity', resource_id)
577
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
578
- with(
579
- body: { foo: 'bar' },
580
- headers: { 'Foo' => 'Bar' }
581
- ).to_return(
582
- body: {
583
- 'billing_requests' => {
584
-
585
- 'actions' => 'actions-input',
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 '#choose_currency' do
604
- subject(:post_response) { client.billing_requests.choose_currency(resource_id) }
605
-
606
- let(:resource_id) { 'ABC123' }
607
-
608
- let!(:stub) do
609
- # /billing_requests/%v/actions/choose_currency
610
- stub_url = '/billing_requests/:identity/actions/choose_currency'.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.choose_currency(resource_id, body, headers) }
643
-
644
- let(:resource_id) { 'ABC123' }
645
-
646
- let!(:stub) do
647
- # /billing_requests/%v/actions/choose_currency
648
- stub_url = '/billing_requests/:identity/actions/choose_currency'.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',
660
- 'id' => 'id-input',
661
- 'links' => 'links-input',
662
- 'mandate_request' => 'mandate_request-input',
663
- 'metadata' => 'metadata-input',
664
- 'payment_request' => 'payment_request-input',
665
- 'resources' => 'resources-input',
666
- 'status' => 'status-input',
667
- },
668
- }.to_json,
669
- headers: response_headers
670
- )
671
- end
672
- end
673
- end
674
-
675
- describe '#confirm_payer_details' do
676
- subject(:post_response) { client.billing_requests.confirm_payer_details(resource_id) }
677
-
678
- let(:resource_id) { 'ABC123' }
679
-
680
- let!(:stub) do
681
- # /billing_requests/%v/actions/confirm_payer_details
682
- stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
683
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
684
-
685
- body: {
686
- 'billing_requests' => {
687
-
688
- 'actions' => 'actions-input',
689
- 'created_at' => 'created_at-input',
690
- 'fallback_enabled' => 'fallback_enabled-input',
691
- 'id' => 'id-input',
692
- 'links' => 'links-input',
693
- 'mandate_request' => 'mandate_request-input',
694
- 'metadata' => 'metadata-input',
695
- 'payment_request' => 'payment_request-input',
696
- 'resources' => 'resources-input',
697
- 'status' => 'status-input',
698
- },
699
- }.to_json,
700
-
701
- headers: response_headers
702
- )
703
- end
704
-
705
- it 'wraps the response and calls the right endpoint' do
706
- expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
707
-
708
- expect(stub).to have_been_requested
709
- end
710
-
711
- context 'when the request needs a body and custom header' do
712
- let(:body) { { foo: 'bar' } }
713
- let(:headers) { { 'Foo' => 'Bar' } }
714
- subject(:post_response) { client.billing_requests.confirm_payer_details(resource_id, body, headers) }
715
-
716
- let(:resource_id) { 'ABC123' }
717
-
718
- let!(:stub) do
719
- # /billing_requests/%v/actions/confirm_payer_details
720
- stub_url = '/billing_requests/:identity/actions/confirm_payer_details'.gsub(':identity', resource_id)
721
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
722
- with(
723
- body: { foo: 'bar' },
724
- headers: { 'Foo' => 'Bar' }
725
- ).to_return(
726
- body: {
727
- 'billing_requests' => {
728
-
729
- 'actions' => 'actions-input',
730
- 'created_at' => 'created_at-input',
731
- 'fallback_enabled' => 'fallback_enabled-input',
732
- 'id' => 'id-input',
733
- 'links' => 'links-input',
734
- 'mandate_request' => 'mandate_request-input',
735
- 'metadata' => 'metadata-input',
736
- 'payment_request' => 'payment_request-input',
737
- 'resources' => 'resources-input',
738
- 'status' => 'status-input',
739
- },
740
- }.to_json,
741
- headers: response_headers
742
- )
743
- end
744
- end
745
- end
746
-
747
- describe '#cancel' do
748
- subject(:post_response) { client.billing_requests.cancel(resource_id) }
749
-
750
- let(:resource_id) { 'ABC123' }
751
-
752
- let!(:stub) do
753
- # /billing_requests/%v/actions/cancel
754
- stub_url = '/billing_requests/:identity/actions/cancel'.gsub(':identity', resource_id)
755
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
756
-
757
- body: {
758
- 'billing_requests' => {
759
-
760
- 'actions' => 'actions-input',
761
- 'created_at' => 'created_at-input',
762
- 'fallback_enabled' => 'fallback_enabled-input',
763
- 'id' => 'id-input',
764
- 'links' => 'links-input',
765
- 'mandate_request' => 'mandate_request-input',
766
- 'metadata' => 'metadata-input',
767
- 'payment_request' => 'payment_request-input',
768
- 'resources' => 'resources-input',
769
- 'status' => 'status-input',
770
- },
771
- }.to_json,
772
-
773
- headers: response_headers
774
- )
775
- end
776
-
777
- it 'wraps the response and calls the right endpoint' do
778
- expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
779
-
780
- expect(stub).to have_been_requested
781
- end
782
-
783
- context 'when the request needs a body and custom header' do
784
- let(:body) { { foo: 'bar' } }
785
- let(:headers) { { 'Foo' => 'Bar' } }
786
- subject(:post_response) { client.billing_requests.cancel(resource_id, body, headers) }
787
-
788
- let(:resource_id) { 'ABC123' }
789
-
790
- let!(:stub) do
791
- # /billing_requests/%v/actions/cancel
792
- stub_url = '/billing_requests/:identity/actions/cancel'.gsub(':identity', resource_id)
793
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
794
- with(
795
- body: { foo: 'bar' },
796
- headers: { 'Foo' => 'Bar' }
797
- ).to_return(
798
- body: {
799
- 'billing_requests' => {
800
-
801
- 'actions' => 'actions-input',
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 '#notify' do
820
- subject(:post_response) { client.billing_requests.notify(resource_id) }
821
-
822
- let(:resource_id) { 'ABC123' }
823
-
824
- let!(:stub) do
825
- # /billing_requests/%v/actions/notify
826
- stub_url = '/billing_requests/:identity/actions/notify'.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.notify(resource_id, body, headers) }
859
-
860
- let(:resource_id) { 'ABC123' }
861
-
862
- let!(:stub) do
863
- # /billing_requests/%v/actions/notify
864
- stub_url = '/billing_requests/:identity/actions/notify'.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',
876
- 'id' => 'id-input',
877
- 'links' => 'links-input',
878
- 'mandate_request' => 'mandate_request-input',
879
- 'metadata' => 'metadata-input',
880
- 'payment_request' => 'payment_request-input',
881
- 'resources' => 'resources-input',
882
- 'status' => 'status-input',
883
- },
884
- }.to_json,
885
- headers: response_headers
886
- )
887
- end
888
- end
889
- end
890
-
891
- describe '#fallback' do
892
- subject(:post_response) { client.billing_requests.fallback(resource_id) }
893
-
894
- let(:resource_id) { 'ABC123' }
895
-
896
- let!(:stub) do
897
- # /billing_requests/%v/actions/fallback
898
- stub_url = '/billing_requests/:identity/actions/fallback'.gsub(':identity', resource_id)
899
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
900
-
901
- body: {
902
- 'billing_requests' => {
903
-
904
- 'actions' => 'actions-input',
905
- 'created_at' => 'created_at-input',
906
- 'fallback_enabled' => 'fallback_enabled-input',
907
- 'id' => 'id-input',
908
- 'links' => 'links-input',
909
- 'mandate_request' => 'mandate_request-input',
910
- 'metadata' => 'metadata-input',
911
- 'payment_request' => 'payment_request-input',
912
- 'resources' => 'resources-input',
913
- 'status' => 'status-input',
914
- },
915
- }.to_json,
916
-
917
- headers: response_headers
918
- )
919
- end
920
-
921
- it 'wraps the response and calls the right endpoint' do
922
- expect(post_response).to be_a(GoCardlessPro::Resources::BillingRequest)
923
-
924
- expect(stub).to have_been_requested
925
- end
926
-
927
- context 'when the request needs a body and custom header' do
928
- let(:body) { { foo: 'bar' } }
929
- let(:headers) { { 'Foo' => 'Bar' } }
930
- subject(:post_response) { client.billing_requests.fallback(resource_id, body, headers) }
931
-
932
- let(:resource_id) { 'ABC123' }
933
-
934
- let!(:stub) do
935
- # /billing_requests/%v/actions/fallback
936
- stub_url = '/billing_requests/:identity/actions/fallback'.gsub(':identity', resource_id)
937
- stub_request(:post, /.*api.gocardless.com#{stub_url}/).
938
- with(
939
- body: { foo: 'bar' },
940
- headers: { 'Foo' => 'Bar' }
941
- ).to_return(
942
- body: {
943
- 'billing_requests' => {
944
-
945
- 'actions' => 'actions-input',
946
- 'created_at' => 'created_at-input',
947
- 'fallback_enabled' => 'fallback_enabled-input',
948
- 'id' => 'id-input',
949
- 'links' => 'links-input',
950
- 'mandate_request' => 'mandate_request-input',
951
- 'metadata' => 'metadata-input',
952
- 'payment_request' => 'payment_request-input',
953
- 'resources' => 'resources-input',
954
- 'status' => 'status-input',
955
- },
956
- }.to_json,
957
- headers: response_headers
958
- )
959
- end
960
- end
961
- end
962
- end