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,401 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::EventsService 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.events.list }
15
-
16
- let(:body) do
17
- {
18
- 'events' => [{
19
-
20
- 'action' => 'action-input',
21
- 'created_at' => 'created_at-input',
22
- 'customer_notifications' => 'customer_notifications-input',
23
- 'details' => 'details-input',
24
- 'id' => 'id-input',
25
- 'links' => 'links-input',
26
- 'metadata' => 'metadata-input',
27
- 'resource_type' => 'resource_type-input',
28
- }],
29
- meta: {
30
- cursors: {
31
- before: nil,
32
- after: 'ABC123',
33
- },
34
- },
35
- }.to_json
36
- end
37
-
38
- before do
39
- stub_request(:get, %r{.*api.gocardless.com/events}).to_return(
40
- body: body,
41
- headers: response_headers
42
- )
43
- end
44
-
45
- it 'wraps each item in the resource class' do
46
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Event)
47
-
48
- expect(get_list_response.records.first.action).to eq('action-input')
49
-
50
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
51
-
52
- expect(get_list_response.records.first.customer_notifications).to eq('customer_notifications-input')
53
-
54
- expect(get_list_response.records.first.details).to eq('details-input')
55
-
56
- expect(get_list_response.records.first.id).to eq('id-input')
57
-
58
- expect(get_list_response.records.first.metadata).to eq('metadata-input')
59
-
60
- expect(get_list_response.records.first.resource_type).to eq('resource_type-input')
61
- end
62
-
63
- it 'exposes the cursors for before and after' do
64
- expect(get_list_response.before).to eq(nil)
65
- expect(get_list_response.after).to eq('ABC123')
66
- end
67
-
68
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
69
-
70
- describe 'retry behaviour' do
71
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
72
-
73
- it 'retries timeouts' do
74
- stub = stub_request(:get, %r{.*api.gocardless.com/events}).
75
- to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
76
-
77
- get_list_response
78
- expect(stub).to have_been_requested.twice
79
- end
80
-
81
- it 'retries 5XX errors' do
82
- stub = stub_request(:get, %r{.*api.gocardless.com/events}).
83
- to_return(status: 502,
84
- headers: { 'Content-Type' => 'text/html' },
85
- body: '<html><body>Response from Cloudflare</body></html>').
86
- then.to_return(status: 200, headers: response_headers, body: body)
87
-
88
- get_list_response
89
- expect(stub).to have_been_requested.twice
90
- end
91
- end
92
- end
93
- end
94
-
95
- describe '#all' do
96
- let!(:first_response_stub) do
97
- stub_request(:get, %r{.*api.gocardless.com/events$}).to_return(
98
- body: {
99
- 'events' => [{
100
-
101
- 'action' => 'action-input',
102
- 'created_at' => 'created_at-input',
103
- 'customer_notifications' => 'customer_notifications-input',
104
- 'details' => 'details-input',
105
- 'id' => 'id-input',
106
- 'links' => 'links-input',
107
- 'metadata' => 'metadata-input',
108
- 'resource_type' => 'resource_type-input',
109
- }],
110
- meta: {
111
- cursors: { after: 'AB345' },
112
- limit: 1,
113
- },
114
- }.to_json,
115
- headers: response_headers
116
- )
117
- end
118
-
119
- let!(:second_response_stub) do
120
- stub_request(:get, %r{.*api.gocardless.com/events\?after=AB345}).to_return(
121
- body: {
122
- 'events' => [{
123
-
124
- 'action' => 'action-input',
125
- 'created_at' => 'created_at-input',
126
- 'customer_notifications' => 'customer_notifications-input',
127
- 'details' => 'details-input',
128
- 'id' => 'id-input',
129
- 'links' => 'links-input',
130
- 'metadata' => 'metadata-input',
131
- 'resource_type' => 'resource_type-input',
132
- }],
133
- meta: {
134
- limit: 2,
135
- cursors: {},
136
- },
137
- }.to_json,
138
- headers: response_headers
139
- )
140
- end
141
-
142
- it 'automatically makes the extra requests' do
143
- expect(client.events.all.to_a.length).to eq(2)
144
- expect(first_response_stub).to have_been_requested
145
- expect(second_response_stub).to have_been_requested
146
- end
147
-
148
- describe 'retry behaviour' do
149
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
150
-
151
- it 'retries timeouts' do
152
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/events$}).to_return(
153
- body: {
154
- 'events' => [{
155
-
156
- 'action' => 'action-input',
157
- 'created_at' => 'created_at-input',
158
- 'customer_notifications' => 'customer_notifications-input',
159
- 'details' => 'details-input',
160
- 'id' => 'id-input',
161
- 'links' => 'links-input',
162
- 'metadata' => 'metadata-input',
163
- 'resource_type' => 'resource_type-input',
164
- }],
165
- meta: {
166
- cursors: { after: 'AB345' },
167
- limit: 1,
168
- },
169
- }.to_json,
170
- headers: response_headers
171
- )
172
-
173
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/events\?after=AB345}).
174
- to_timeout.then.
175
- to_return(
176
- body: {
177
- 'events' => [{
178
-
179
- 'action' => 'action-input',
180
- 'created_at' => 'created_at-input',
181
- 'customer_notifications' => 'customer_notifications-input',
182
- 'details' => 'details-input',
183
- 'id' => 'id-input',
184
- 'links' => 'links-input',
185
- 'metadata' => 'metadata-input',
186
- 'resource_type' => 'resource_type-input',
187
- }],
188
- meta: {
189
- limit: 2,
190
- cursors: {},
191
- },
192
- }.to_json,
193
- headers: response_headers
194
- )
195
-
196
- client.events.all.to_a
197
-
198
- expect(first_response_stub).to have_been_requested
199
- expect(second_response_stub).to have_been_requested.twice
200
- end
201
-
202
- it 'retries 5XX errors' do
203
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/events$}).to_return(
204
- body: {
205
- 'events' => [{
206
-
207
- 'action' => 'action-input',
208
- 'created_at' => 'created_at-input',
209
- 'customer_notifications' => 'customer_notifications-input',
210
- 'details' => 'details-input',
211
- 'id' => 'id-input',
212
- 'links' => 'links-input',
213
- 'metadata' => 'metadata-input',
214
- 'resource_type' => 'resource_type-input',
215
- }],
216
- meta: {
217
- cursors: { after: 'AB345' },
218
- limit: 1,
219
- },
220
- }.to_json,
221
- headers: response_headers
222
- )
223
-
224
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/events\?after=AB345}).
225
- to_return(
226
- status: 502,
227
- body: '<html><body>Response from Cloudflare</body></html>',
228
- headers: { 'Content-Type' => 'text/html' }
229
- ).then.to_return(
230
- body: {
231
- 'events' => [{
232
-
233
- 'action' => 'action-input',
234
- 'created_at' => 'created_at-input',
235
- 'customer_notifications' => 'customer_notifications-input',
236
- 'details' => 'details-input',
237
- 'id' => 'id-input',
238
- 'links' => 'links-input',
239
- 'metadata' => 'metadata-input',
240
- 'resource_type' => 'resource_type-input',
241
- }],
242
- meta: {
243
- limit: 2,
244
- cursors: {},
245
- },
246
- }.to_json,
247
- headers: response_headers
248
- )
249
-
250
- client.events.all.to_a
251
-
252
- expect(first_response_stub).to have_been_requested
253
- expect(second_response_stub).to have_been_requested.twice
254
- end
255
- end
256
- end
257
-
258
- describe '#get' do
259
- let(:id) { 'ID123' }
260
-
261
- subject(:get_response) { client.events.get(id) }
262
-
263
- context 'passing in a custom header' do
264
- let!(:stub) do
265
- stub_url = '/events/:identity'.gsub(':identity', id)
266
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
267
- with(headers: { 'Foo' => 'Bar' }).
268
- to_return(
269
- body: {
270
- 'events' => {
271
-
272
- 'action' => 'action-input',
273
- 'created_at' => 'created_at-input',
274
- 'customer_notifications' => 'customer_notifications-input',
275
- 'details' => 'details-input',
276
- 'id' => 'id-input',
277
- 'links' => 'links-input',
278
- 'metadata' => 'metadata-input',
279
- 'resource_type' => 'resource_type-input',
280
- },
281
- }.to_json,
282
- headers: response_headers
283
- )
284
- end
285
-
286
- subject(:get_response) do
287
- client.events.get(id, headers: {
288
- 'Foo' => 'Bar',
289
- })
290
- end
291
-
292
- it 'includes the header' do
293
- get_response
294
- expect(stub).to have_been_requested
295
- end
296
- end
297
-
298
- context 'when there is a event to return' do
299
- before do
300
- stub_url = '/events/:identity'.gsub(':identity', id)
301
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
302
- body: {
303
- 'events' => {
304
-
305
- 'action' => 'action-input',
306
- 'created_at' => 'created_at-input',
307
- 'customer_notifications' => 'customer_notifications-input',
308
- 'details' => 'details-input',
309
- 'id' => 'id-input',
310
- 'links' => 'links-input',
311
- 'metadata' => 'metadata-input',
312
- 'resource_type' => 'resource_type-input',
313
- },
314
- }.to_json,
315
- headers: response_headers
316
- )
317
- end
318
-
319
- it 'wraps the response in a resource' do
320
- expect(get_response).to be_a(GoCardlessPro::Resources::Event)
321
- end
322
- end
323
-
324
- context 'when nothing is returned' do
325
- before do
326
- stub_url = '/events/:identity'.gsub(':identity', id)
327
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
328
- body: '',
329
- headers: response_headers
330
- )
331
- end
332
-
333
- it 'returns nil' do
334
- expect(get_response).to be_nil
335
- end
336
- end
337
-
338
- context "when an ID is specified which can't be included in a valid URI" do
339
- let(:id) { '`' }
340
-
341
- it "doesn't raise an error" do
342
- expect { get_response }.to_not raise_error(/bad URI/)
343
- end
344
- end
345
-
346
- describe 'retry behaviour' do
347
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
348
-
349
- it 'retries timeouts' do
350
- stub_url = '/events/:identity'.gsub(':identity', id)
351
-
352
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
353
- to_timeout.then.to_return(status: 200, headers: response_headers)
354
-
355
- get_response
356
- expect(stub).to have_been_requested.twice
357
- end
358
-
359
- it 'retries 5XX errors, other than 500s' do
360
- stub_url = '/events/:identity'.gsub(':identity', id)
361
-
362
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
363
- to_return(status: 502,
364
- headers: { 'Content-Type' => 'text/html' },
365
- body: '<html><body>Response from Cloudflare</body></html>').
366
- then.to_return(status: 200, headers: response_headers)
367
-
368
- get_response
369
- expect(stub).to have_been_requested.twice
370
- end
371
-
372
- it 'retries 500 errors returned by the API' do
373
- stub_url = '/events/:identity'.gsub(':identity', id)
374
-
375
- gocardless_error = {
376
- 'error' => {
377
- 'message' => 'Internal server error',
378
- 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
379
- 'errors' => [{
380
- 'message' => 'Internal server error',
381
- 'reason' => 'internal_server_error',
382
- }],
383
- 'type' => 'gocardless',
384
- 'code' => 500,
385
- 'request_id' => 'dummy_request_id',
386
- 'id' => 'dummy_exception_id',
387
- },
388
- }
389
-
390
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
391
- to_return(status: 500,
392
- headers: response_headers,
393
- body: gocardless_error.to_json).
394
- then.to_return(status: 200, headers: response_headers)
395
-
396
- get_response
397
- expect(stub).to have_been_requested.twice
398
- end
399
- end
400
- end
401
- end