gocardless_pro 2.41.0 → 2.41.1

Sign up to get free protection for your applications and to get access to all the features.
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,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Response do
4
- subject(:response) { described_class.new(raw_response) }
5
-
6
- let(:default_headers) do
7
- { 'Content-Type' => 'application/json' }
8
- end
9
-
10
- describe '#body' do
11
- subject(:body) { response.body }
12
-
13
- let(:raw_response) do
14
- double('response',
15
- headers: default_headers,
16
- status: 200,
17
- body: { customers: [] }.to_json)
18
- end
19
-
20
- it 'returns the body parsed into a hash' do
21
- expect(body).to eq('customers' => [])
22
- end
23
-
24
- context 'when the response is empty' do
25
- let(:raw_response) do
26
- double('response', headers: default_headers, status: 204, body: '')
27
- end
28
-
29
- it 'returns nil' do
30
- expect(body).to be_nil
31
- end
32
- end
33
- end
34
- end
@@ -1,353 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::BankAuthorisationsService 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 '#get' do
13
- let(:id) { 'ID123' }
14
-
15
- subject(:get_response) { client.bank_authorisations.get(id) }
16
-
17
- context 'passing in a custom header' do
18
- let!(:stub) do
19
- stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
20
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
21
- with(headers: { 'Foo' => 'Bar' }).
22
- to_return(
23
- body: {
24
- 'bank_authorisations' => {
25
-
26
- 'authorisation_type' => 'authorisation_type-input',
27
- 'authorised_at' => 'authorised_at-input',
28
- 'created_at' => 'created_at-input',
29
- 'expires_at' => 'expires_at-input',
30
- 'id' => 'id-input',
31
- 'last_visited_at' => 'last_visited_at-input',
32
- 'links' => 'links-input',
33
- 'redirect_uri' => 'redirect_uri-input',
34
- 'url' => 'url-input',
35
- },
36
- }.to_json,
37
- headers: response_headers
38
- )
39
- end
40
-
41
- subject(:get_response) do
42
- client.bank_authorisations.get(id, headers: {
43
- 'Foo' => 'Bar',
44
- })
45
- end
46
-
47
- it 'includes the header' do
48
- get_response
49
- expect(stub).to have_been_requested
50
- end
51
- end
52
-
53
- context 'when there is a bank_authorisation to return' do
54
- before do
55
- stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
56
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
57
- body: {
58
- 'bank_authorisations' => {
59
-
60
- 'authorisation_type' => 'authorisation_type-input',
61
- 'authorised_at' => 'authorised_at-input',
62
- 'created_at' => 'created_at-input',
63
- 'expires_at' => 'expires_at-input',
64
- 'id' => 'id-input',
65
- 'last_visited_at' => 'last_visited_at-input',
66
- 'links' => 'links-input',
67
- 'redirect_uri' => 'redirect_uri-input',
68
- 'url' => 'url-input',
69
- },
70
- }.to_json,
71
- headers: response_headers
72
- )
73
- end
74
-
75
- it 'wraps the response in a resource' do
76
- expect(get_response).to be_a(GoCardlessPro::Resources::BankAuthorisation)
77
- end
78
- end
79
-
80
- context 'when nothing is returned' do
81
- before do
82
- stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
83
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
84
- body: '',
85
- headers: response_headers
86
- )
87
- end
88
-
89
- it 'returns nil' do
90
- expect(get_response).to be_nil
91
- end
92
- end
93
-
94
- context "when an ID is specified which can't be included in a valid URI" do
95
- let(:id) { '`' }
96
-
97
- it "doesn't raise an error" do
98
- expect { get_response }.to_not raise_error(/bad URI/)
99
- end
100
- end
101
-
102
- describe 'retry behaviour' do
103
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
104
-
105
- it 'retries timeouts' do
106
- stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
107
-
108
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
109
- to_timeout.then.to_return(status: 200, headers: response_headers)
110
-
111
- get_response
112
- expect(stub).to have_been_requested.twice
113
- end
114
-
115
- it 'retries 5XX errors, other than 500s' do
116
- stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
117
-
118
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
119
- to_return(status: 502,
120
- headers: { 'Content-Type' => 'text/html' },
121
- body: '<html><body>Response from Cloudflare</body></html>').
122
- then.to_return(status: 200, headers: response_headers)
123
-
124
- get_response
125
- expect(stub).to have_been_requested.twice
126
- end
127
-
128
- it 'retries 500 errors returned by the API' do
129
- stub_url = '/bank_authorisations/:identity'.gsub(':identity', id)
130
-
131
- gocardless_error = {
132
- 'error' => {
133
- 'message' => 'Internal server error',
134
- 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
135
- 'errors' => [{
136
- 'message' => 'Internal server error',
137
- 'reason' => 'internal_server_error',
138
- }],
139
- 'type' => 'gocardless',
140
- 'code' => 500,
141
- 'request_id' => 'dummy_request_id',
142
- 'id' => 'dummy_exception_id',
143
- },
144
- }
145
-
146
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
147
- to_return(status: 500,
148
- headers: response_headers,
149
- body: gocardless_error.to_json).
150
- then.to_return(status: 200, headers: response_headers)
151
-
152
- get_response
153
- expect(stub).to have_been_requested.twice
154
- end
155
- end
156
- end
157
-
158
- describe '#create' do
159
- subject(:post_create_response) { client.bank_authorisations.create(params: new_resource) }
160
- context 'with a valid request' do
161
- let(:new_resource) do
162
- {
163
-
164
- 'authorisation_type' => 'authorisation_type-input',
165
- 'authorised_at' => 'authorised_at-input',
166
- 'created_at' => 'created_at-input',
167
- 'expires_at' => 'expires_at-input',
168
- 'id' => 'id-input',
169
- 'last_visited_at' => 'last_visited_at-input',
170
- 'links' => 'links-input',
171
- 'redirect_uri' => 'redirect_uri-input',
172
- 'url' => 'url-input',
173
- }
174
- end
175
-
176
- before do
177
- stub_request(:post, %r{.*api.gocardless.com/bank_authorisations}).
178
- with(
179
- body: {
180
- 'bank_authorisations' => {
181
-
182
- 'authorisation_type' => 'authorisation_type-input',
183
- 'authorised_at' => 'authorised_at-input',
184
- 'created_at' => 'created_at-input',
185
- 'expires_at' => 'expires_at-input',
186
- 'id' => 'id-input',
187
- 'last_visited_at' => 'last_visited_at-input',
188
- 'links' => 'links-input',
189
- 'redirect_uri' => 'redirect_uri-input',
190
- 'url' => 'url-input',
191
- },
192
- }
193
- ).
194
- to_return(
195
- body: {
196
- 'bank_authorisations' =>
197
-
198
- {
199
-
200
- 'authorisation_type' => 'authorisation_type-input',
201
- 'authorised_at' => 'authorised_at-input',
202
- 'created_at' => 'created_at-input',
203
- 'expires_at' => 'expires_at-input',
204
- 'id' => 'id-input',
205
- 'last_visited_at' => 'last_visited_at-input',
206
- 'links' => 'links-input',
207
- 'redirect_uri' => 'redirect_uri-input',
208
- 'url' => 'url-input',
209
- },
210
-
211
- }.to_json,
212
- headers: response_headers
213
- )
214
- end
215
-
216
- it 'creates and returns the resource' do
217
- expect(post_create_response).to be_a(GoCardlessPro::Resources::BankAuthorisation)
218
- end
219
-
220
- describe 'retry behaviour' do
221
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
222
-
223
- it 'retries timeouts' do
224
- stub = stub_request(:post, %r{.*api.gocardless.com/bank_authorisations}).
225
- to_timeout.then.to_return(status: 200, headers: response_headers)
226
-
227
- post_create_response
228
- expect(stub).to have_been_requested.twice
229
- end
230
-
231
- it 'retries 5XX errors' do
232
- stub = stub_request(:post, %r{.*api.gocardless.com/bank_authorisations}).
233
- to_return(status: 502,
234
- headers: { 'Content-Type' => 'text/html' },
235
- body: '<html><body>Response from Cloudflare</body></html>').
236
- then.to_return(status: 200, headers: response_headers)
237
-
238
- post_create_response
239
- expect(stub).to have_been_requested.twice
240
- end
241
- end
242
- end
243
-
244
- context 'with a request that returns a validation error' do
245
- let(:new_resource) { {} }
246
-
247
- before do
248
- stub_request(:post, %r{.*api.gocardless.com/bank_authorisations}).to_return(
249
- body: {
250
- error: {
251
- type: 'validation_failed',
252
- code: 422,
253
- errors: [
254
- { message: 'test error message', field: 'test_field' },
255
- ],
256
- },
257
- }.to_json,
258
- headers: response_headers,
259
- status: 422
260
- )
261
- end
262
-
263
- it 'throws the correct error' do
264
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
265
- end
266
- end
267
-
268
- context 'with a request that returns an idempotent creation conflict error' do
269
- let(:id) { 'ID123' }
270
-
271
- let(:new_resource) do
272
- {
273
-
274
- 'authorisation_type' => 'authorisation_type-input',
275
- 'authorised_at' => 'authorised_at-input',
276
- 'created_at' => 'created_at-input',
277
- 'expires_at' => 'expires_at-input',
278
- 'id' => 'id-input',
279
- 'last_visited_at' => 'last_visited_at-input',
280
- 'links' => 'links-input',
281
- 'redirect_uri' => 'redirect_uri-input',
282
- 'url' => 'url-input',
283
- }
284
- end
285
-
286
- let!(:post_stub) do
287
- stub_request(:post, %r{.*api.gocardless.com/bank_authorisations}).to_return(
288
- body: {
289
- error: {
290
- type: 'invalid_state',
291
- code: 409,
292
- errors: [
293
- {
294
- message: 'A resource has already been created with this idempotency key',
295
- reason: 'idempotent_creation_conflict',
296
- links: {
297
- conflicting_resource_id: id,
298
- },
299
- },
300
- ],
301
- },
302
- }.to_json,
303
- headers: response_headers,
304
- status: 409
305
- )
306
- end
307
-
308
- let!(:get_stub) do
309
- stub_url = "/bank_authorisations/#{id}"
310
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
311
- to_return(
312
- body: {
313
- 'bank_authorisations' => {
314
-
315
- 'authorisation_type' => 'authorisation_type-input',
316
- 'authorised_at' => 'authorised_at-input',
317
- 'created_at' => 'created_at-input',
318
- 'expires_at' => 'expires_at-input',
319
- 'id' => 'id-input',
320
- 'last_visited_at' => 'last_visited_at-input',
321
- 'links' => 'links-input',
322
- 'redirect_uri' => 'redirect_uri-input',
323
- 'url' => 'url-input',
324
- },
325
- }.to_json,
326
- headers: response_headers
327
- )
328
- end
329
-
330
- context 'with default behaviour' do
331
- it 'fetches the already-created resource' do
332
- post_create_response
333
- expect(post_stub).to have_been_requested
334
- expect(get_stub).to have_been_requested
335
- end
336
- end
337
-
338
- context 'with on_idempotency_conflict: :raise' do
339
- let(:client) do
340
- GoCardlessPro::Client.new(
341
- access_token: 'SECRET_TOKEN',
342
- on_idempotency_conflict: :raise
343
- )
344
- end
345
-
346
- it 'raises an IdempotencyConflict error' do
347
- expect { post_create_response }.
348
- to raise_error(GoCardlessPro::IdempotencyConflict)
349
- end
350
- end
351
- end
352
- end
353
- end
@@ -1,144 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::BankDetailsLookupsService do
4
- let(:client) do
5
- GoCardlessPro::Client.new(
6
- access_token: 'SECRET_TOKEN'
7
- )
8
- end
9
-
10
- let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
-
12
- describe '#create' do
13
- subject(:post_create_response) { client.bank_details_lookups.create(params: new_resource) }
14
- context 'with a valid request' do
15
- let(:new_resource) do
16
- {
17
-
18
- 'available_debit_schemes' => 'available_debit_schemes-input',
19
- 'bank_name' => 'bank_name-input',
20
- 'bic' => 'bic-input',
21
- }
22
- end
23
-
24
- before do
25
- stub_request(:post, %r{.*api.gocardless.com/bank_details_lookups}).
26
- with(
27
- body: {
28
- 'bank_details_lookups' => {
29
-
30
- 'available_debit_schemes' => 'available_debit_schemes-input',
31
- 'bank_name' => 'bank_name-input',
32
- 'bic' => 'bic-input',
33
- },
34
- }
35
- ).
36
- to_return(
37
- body: {
38
- 'bank_details_lookups' =>
39
-
40
- {
41
-
42
- 'available_debit_schemes' => 'available_debit_schemes-input',
43
- 'bank_name' => 'bank_name-input',
44
- 'bic' => 'bic-input',
45
- },
46
-
47
- }.to_json,
48
- headers: response_headers
49
- )
50
- end
51
-
52
- it 'creates and returns the resource' do
53
- expect(post_create_response).to be_a(GoCardlessPro::Resources::BankDetailsLookup)
54
- end
55
-
56
- describe 'retry behaviour' do
57
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
58
-
59
- it 'retries timeouts' do
60
- stub = stub_request(:post, %r{.*api.gocardless.com/bank_details_lookups}).
61
- to_timeout.then.to_return(status: 200, headers: response_headers)
62
-
63
- post_create_response
64
- expect(stub).to have_been_requested.twice
65
- end
66
-
67
- it 'retries 5XX errors' do
68
- stub = stub_request(:post, %r{.*api.gocardless.com/bank_details_lookups}).
69
- to_return(status: 502,
70
- headers: { 'Content-Type' => 'text/html' },
71
- body: '<html><body>Response from Cloudflare</body></html>').
72
- then.to_return(status: 200, headers: response_headers)
73
-
74
- post_create_response
75
- expect(stub).to have_been_requested.twice
76
- end
77
- end
78
- end
79
-
80
- context 'with a request that returns a validation error' do
81
- let(:new_resource) { {} }
82
-
83
- before do
84
- stub_request(:post, %r{.*api.gocardless.com/bank_details_lookups}).to_return(
85
- body: {
86
- error: {
87
- type: 'validation_failed',
88
- code: 422,
89
- errors: [
90
- { message: 'test error message', field: 'test_field' },
91
- ],
92
- },
93
- }.to_json,
94
- headers: response_headers,
95
- status: 422
96
- )
97
- end
98
-
99
- it 'throws the correct error' do
100
- expect { post_create_response }.to raise_error(GoCardlessPro::ValidationError)
101
- end
102
- end
103
-
104
- context 'with a request that returns an idempotent creation conflict error' do
105
- let(:id) { 'ID123' }
106
-
107
- let(:new_resource) do
108
- {
109
-
110
- 'available_debit_schemes' => 'available_debit_schemes-input',
111
- 'bank_name' => 'bank_name-input',
112
- 'bic' => 'bic-input',
113
- }
114
- end
115
-
116
- let!(:post_stub) do
117
- stub_request(:post, %r{.*api.gocardless.com/bank_details_lookups}).to_return(
118
- body: {
119
- error: {
120
- type: 'invalid_state',
121
- code: 409,
122
- errors: [
123
- {
124
- message: 'A resource has already been created with this idempotency key',
125
- reason: 'idempotent_creation_conflict',
126
- links: {
127
- conflicting_resource_id: id,
128
- },
129
- },
130
- ],
131
- },
132
- }.to_json,
133
- headers: response_headers,
134
- status: 409
135
- )
136
- end
137
-
138
- it 'raises an InvalidStateError' do
139
- expect { post_create_response }.to raise_error(GoCardlessPro::InvalidStateError)
140
- expect(post_stub).to have_been_requested
141
- end
142
- end
143
- end
144
- end