gocardless_pro 2.41.0 → 2.41.2

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/Gemfile +0 -10
  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,520 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe GoCardlessPro::Services::PayoutsService 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.payouts.list }
15
-
16
- let(:body) do
17
- {
18
- 'payouts' => [{
19
-
20
- 'amount' => 'amount-input',
21
- 'arrival_date' => 'arrival_date-input',
22
- 'created_at' => 'created_at-input',
23
- 'currency' => 'currency-input',
24
- 'deducted_fees' => 'deducted_fees-input',
25
- 'fx' => 'fx-input',
26
- 'id' => 'id-input',
27
- 'links' => 'links-input',
28
- 'metadata' => 'metadata-input',
29
- 'payout_type' => 'payout_type-input',
30
- 'reference' => 'reference-input',
31
- 'status' => 'status-input',
32
- 'tax_currency' => 'tax_currency-input',
33
- }],
34
- meta: {
35
- cursors: {
36
- before: nil,
37
- after: 'ABC123',
38
- },
39
- },
40
- }.to_json
41
- end
42
-
43
- before do
44
- stub_request(:get, %r{.*api.gocardless.com/payouts}).to_return(
45
- body: body,
46
- headers: response_headers
47
- )
48
- end
49
-
50
- it 'wraps each item in the resource class' do
51
- expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::Payout)
52
-
53
- expect(get_list_response.records.first.amount).to eq('amount-input')
54
-
55
- expect(get_list_response.records.first.arrival_date).to eq('arrival_date-input')
56
-
57
- expect(get_list_response.records.first.created_at).to eq('created_at-input')
58
-
59
- expect(get_list_response.records.first.currency).to eq('currency-input')
60
-
61
- expect(get_list_response.records.first.deducted_fees).to eq('deducted_fees-input')
62
-
63
- expect(get_list_response.records.first.fx).to eq('fx-input')
64
-
65
- expect(get_list_response.records.first.id).to eq('id-input')
66
-
67
- expect(get_list_response.records.first.metadata).to eq('metadata-input')
68
-
69
- expect(get_list_response.records.first.payout_type).to eq('payout_type-input')
70
-
71
- expect(get_list_response.records.first.reference).to eq('reference-input')
72
-
73
- expect(get_list_response.records.first.status).to eq('status-input')
74
-
75
- expect(get_list_response.records.first.tax_currency).to eq('tax_currency-input')
76
- end
77
-
78
- it 'exposes the cursors for before and after' do
79
- expect(get_list_response.before).to eq(nil)
80
- expect(get_list_response.after).to eq('ABC123')
81
- end
82
-
83
- specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
84
-
85
- describe 'retry behaviour' do
86
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
87
-
88
- it 'retries timeouts' do
89
- stub = stub_request(:get, %r{.*api.gocardless.com/payouts}).
90
- to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
91
-
92
- get_list_response
93
- expect(stub).to have_been_requested.twice
94
- end
95
-
96
- it 'retries 5XX errors' do
97
- stub = stub_request(:get, %r{.*api.gocardless.com/payouts}).
98
- to_return(status: 502,
99
- headers: { 'Content-Type' => 'text/html' },
100
- body: '<html><body>Response from Cloudflare</body></html>').
101
- then.to_return(status: 200, headers: response_headers, body: body)
102
-
103
- get_list_response
104
- expect(stub).to have_been_requested.twice
105
- end
106
- end
107
- end
108
- end
109
-
110
- describe '#all' do
111
- let!(:first_response_stub) do
112
- stub_request(:get, %r{.*api.gocardless.com/payouts$}).to_return(
113
- body: {
114
- 'payouts' => [{
115
-
116
- 'amount' => 'amount-input',
117
- 'arrival_date' => 'arrival_date-input',
118
- 'created_at' => 'created_at-input',
119
- 'currency' => 'currency-input',
120
- 'deducted_fees' => 'deducted_fees-input',
121
- 'fx' => 'fx-input',
122
- 'id' => 'id-input',
123
- 'links' => 'links-input',
124
- 'metadata' => 'metadata-input',
125
- 'payout_type' => 'payout_type-input',
126
- 'reference' => 'reference-input',
127
- 'status' => 'status-input',
128
- 'tax_currency' => 'tax_currency-input',
129
- }],
130
- meta: {
131
- cursors: { after: 'AB345' },
132
- limit: 1,
133
- },
134
- }.to_json,
135
- headers: response_headers
136
- )
137
- end
138
-
139
- let!(:second_response_stub) do
140
- stub_request(:get, %r{.*api.gocardless.com/payouts\?after=AB345}).to_return(
141
- body: {
142
- 'payouts' => [{
143
-
144
- 'amount' => 'amount-input',
145
- 'arrival_date' => 'arrival_date-input',
146
- 'created_at' => 'created_at-input',
147
- 'currency' => 'currency-input',
148
- 'deducted_fees' => 'deducted_fees-input',
149
- 'fx' => 'fx-input',
150
- 'id' => 'id-input',
151
- 'links' => 'links-input',
152
- 'metadata' => 'metadata-input',
153
- 'payout_type' => 'payout_type-input',
154
- 'reference' => 'reference-input',
155
- 'status' => 'status-input',
156
- 'tax_currency' => 'tax_currency-input',
157
- }],
158
- meta: {
159
- limit: 2,
160
- cursors: {},
161
- },
162
- }.to_json,
163
- headers: response_headers
164
- )
165
- end
166
-
167
- it 'automatically makes the extra requests' do
168
- expect(client.payouts.all.to_a.length).to eq(2)
169
- expect(first_response_stub).to have_been_requested
170
- expect(second_response_stub).to have_been_requested
171
- end
172
-
173
- describe 'retry behaviour' do
174
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
175
-
176
- it 'retries timeouts' do
177
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/payouts$}).to_return(
178
- body: {
179
- 'payouts' => [{
180
-
181
- 'amount' => 'amount-input',
182
- 'arrival_date' => 'arrival_date-input',
183
- 'created_at' => 'created_at-input',
184
- 'currency' => 'currency-input',
185
- 'deducted_fees' => 'deducted_fees-input',
186
- 'fx' => 'fx-input',
187
- 'id' => 'id-input',
188
- 'links' => 'links-input',
189
- 'metadata' => 'metadata-input',
190
- 'payout_type' => 'payout_type-input',
191
- 'reference' => 'reference-input',
192
- 'status' => 'status-input',
193
- 'tax_currency' => 'tax_currency-input',
194
- }],
195
- meta: {
196
- cursors: { after: 'AB345' },
197
- limit: 1,
198
- },
199
- }.to_json,
200
- headers: response_headers
201
- )
202
-
203
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/payouts\?after=AB345}).
204
- to_timeout.then.
205
- to_return(
206
- body: {
207
- 'payouts' => [{
208
-
209
- 'amount' => 'amount-input',
210
- 'arrival_date' => 'arrival_date-input',
211
- 'created_at' => 'created_at-input',
212
- 'currency' => 'currency-input',
213
- 'deducted_fees' => 'deducted_fees-input',
214
- 'fx' => 'fx-input',
215
- 'id' => 'id-input',
216
- 'links' => 'links-input',
217
- 'metadata' => 'metadata-input',
218
- 'payout_type' => 'payout_type-input',
219
- 'reference' => 'reference-input',
220
- 'status' => 'status-input',
221
- 'tax_currency' => 'tax_currency-input',
222
- }],
223
- meta: {
224
- limit: 2,
225
- cursors: {},
226
- },
227
- }.to_json,
228
- headers: response_headers
229
- )
230
-
231
- client.payouts.all.to_a
232
-
233
- expect(first_response_stub).to have_been_requested
234
- expect(second_response_stub).to have_been_requested.twice
235
- end
236
-
237
- it 'retries 5XX errors' do
238
- first_response_stub = stub_request(:get, %r{.*api.gocardless.com/payouts$}).to_return(
239
- body: {
240
- 'payouts' => [{
241
-
242
- 'amount' => 'amount-input',
243
- 'arrival_date' => 'arrival_date-input',
244
- 'created_at' => 'created_at-input',
245
- 'currency' => 'currency-input',
246
- 'deducted_fees' => 'deducted_fees-input',
247
- 'fx' => 'fx-input',
248
- 'id' => 'id-input',
249
- 'links' => 'links-input',
250
- 'metadata' => 'metadata-input',
251
- 'payout_type' => 'payout_type-input',
252
- 'reference' => 'reference-input',
253
- 'status' => 'status-input',
254
- 'tax_currency' => 'tax_currency-input',
255
- }],
256
- meta: {
257
- cursors: { after: 'AB345' },
258
- limit: 1,
259
- },
260
- }.to_json,
261
- headers: response_headers
262
- )
263
-
264
- second_response_stub = stub_request(:get, %r{.*api.gocardless.com/payouts\?after=AB345}).
265
- to_return(
266
- status: 502,
267
- body: '<html><body>Response from Cloudflare</body></html>',
268
- headers: { 'Content-Type' => 'text/html' }
269
- ).then.to_return(
270
- body: {
271
- 'payouts' => [{
272
-
273
- 'amount' => 'amount-input',
274
- 'arrival_date' => 'arrival_date-input',
275
- 'created_at' => 'created_at-input',
276
- 'currency' => 'currency-input',
277
- 'deducted_fees' => 'deducted_fees-input',
278
- 'fx' => 'fx-input',
279
- 'id' => 'id-input',
280
- 'links' => 'links-input',
281
- 'metadata' => 'metadata-input',
282
- 'payout_type' => 'payout_type-input',
283
- 'reference' => 'reference-input',
284
- 'status' => 'status-input',
285
- 'tax_currency' => 'tax_currency-input',
286
- }],
287
- meta: {
288
- limit: 2,
289
- cursors: {},
290
- },
291
- }.to_json,
292
- headers: response_headers
293
- )
294
-
295
- client.payouts.all.to_a
296
-
297
- expect(first_response_stub).to have_been_requested
298
- expect(second_response_stub).to have_been_requested.twice
299
- end
300
- end
301
- end
302
-
303
- describe '#get' do
304
- let(:id) { 'ID123' }
305
-
306
- subject(:get_response) { client.payouts.get(id) }
307
-
308
- context 'passing in a custom header' do
309
- let!(:stub) do
310
- stub_url = '/payouts/:identity'.gsub(':identity', id)
311
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).
312
- with(headers: { 'Foo' => 'Bar' }).
313
- to_return(
314
- body: {
315
- 'payouts' => {
316
-
317
- 'amount' => 'amount-input',
318
- 'arrival_date' => 'arrival_date-input',
319
- 'created_at' => 'created_at-input',
320
- 'currency' => 'currency-input',
321
- 'deducted_fees' => 'deducted_fees-input',
322
- 'fx' => 'fx-input',
323
- 'id' => 'id-input',
324
- 'links' => 'links-input',
325
- 'metadata' => 'metadata-input',
326
- 'payout_type' => 'payout_type-input',
327
- 'reference' => 'reference-input',
328
- 'status' => 'status-input',
329
- 'tax_currency' => 'tax_currency-input',
330
- },
331
- }.to_json,
332
- headers: response_headers
333
- )
334
- end
335
-
336
- subject(:get_response) do
337
- client.payouts.get(id, headers: {
338
- 'Foo' => 'Bar',
339
- })
340
- end
341
-
342
- it 'includes the header' do
343
- get_response
344
- expect(stub).to have_been_requested
345
- end
346
- end
347
-
348
- context 'when there is a payout to return' do
349
- before do
350
- stub_url = '/payouts/:identity'.gsub(':identity', id)
351
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
352
- body: {
353
- 'payouts' => {
354
-
355
- 'amount' => 'amount-input',
356
- 'arrival_date' => 'arrival_date-input',
357
- 'created_at' => 'created_at-input',
358
- 'currency' => 'currency-input',
359
- 'deducted_fees' => 'deducted_fees-input',
360
- 'fx' => 'fx-input',
361
- 'id' => 'id-input',
362
- 'links' => 'links-input',
363
- 'metadata' => 'metadata-input',
364
- 'payout_type' => 'payout_type-input',
365
- 'reference' => 'reference-input',
366
- 'status' => 'status-input',
367
- 'tax_currency' => 'tax_currency-input',
368
- },
369
- }.to_json,
370
- headers: response_headers
371
- )
372
- end
373
-
374
- it 'wraps the response in a resource' do
375
- expect(get_response).to be_a(GoCardlessPro::Resources::Payout)
376
- end
377
- end
378
-
379
- context 'when nothing is returned' do
380
- before do
381
- stub_url = '/payouts/:identity'.gsub(':identity', id)
382
- stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
383
- body: '',
384
- headers: response_headers
385
- )
386
- end
387
-
388
- it 'returns nil' do
389
- expect(get_response).to be_nil
390
- end
391
- end
392
-
393
- context "when an ID is specified which can't be included in a valid URI" do
394
- let(:id) { '`' }
395
-
396
- it "doesn't raise an error" do
397
- expect { get_response }.to_not raise_error(/bad URI/)
398
- end
399
- end
400
-
401
- describe 'retry behaviour' do
402
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
403
-
404
- it 'retries timeouts' do
405
- stub_url = '/payouts/:identity'.gsub(':identity', id)
406
-
407
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
408
- to_timeout.then.to_return(status: 200, headers: response_headers)
409
-
410
- get_response
411
- expect(stub).to have_been_requested.twice
412
- end
413
-
414
- it 'retries 5XX errors, other than 500s' do
415
- stub_url = '/payouts/:identity'.gsub(':identity', id)
416
-
417
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
418
- to_return(status: 502,
419
- headers: { 'Content-Type' => 'text/html' },
420
- body: '<html><body>Response from Cloudflare</body></html>').
421
- then.to_return(status: 200, headers: response_headers)
422
-
423
- get_response
424
- expect(stub).to have_been_requested.twice
425
- end
426
-
427
- it 'retries 500 errors returned by the API' do
428
- stub_url = '/payouts/:identity'.gsub(':identity', id)
429
-
430
- gocardless_error = {
431
- 'error' => {
432
- 'message' => 'Internal server error',
433
- 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
434
- 'errors' => [{
435
- 'message' => 'Internal server error',
436
- 'reason' => 'internal_server_error',
437
- }],
438
- 'type' => 'gocardless',
439
- 'code' => 500,
440
- 'request_id' => 'dummy_request_id',
441
- 'id' => 'dummy_exception_id',
442
- },
443
- }
444
-
445
- stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
446
- to_return(status: 500,
447
- headers: response_headers,
448
- body: gocardless_error.to_json).
449
- then.to_return(status: 200, headers: response_headers)
450
-
451
- get_response
452
- expect(stub).to have_been_requested.twice
453
- end
454
- end
455
- end
456
-
457
- describe '#update' do
458
- subject(:put_update_response) { client.payouts.update(id, params: update_params) }
459
- let(:id) { 'ABC123' }
460
-
461
- context 'with a valid request' do
462
- let(:update_params) { { 'hello' => 'world' } }
463
-
464
- let!(:stub) do
465
- stub_url = '/payouts/:identity'.gsub(':identity', id)
466
- stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
467
- body: {
468
- 'payouts' => {
469
-
470
- 'amount' => 'amount-input',
471
- 'arrival_date' => 'arrival_date-input',
472
- 'created_at' => 'created_at-input',
473
- 'currency' => 'currency-input',
474
- 'deducted_fees' => 'deducted_fees-input',
475
- 'fx' => 'fx-input',
476
- 'id' => 'id-input',
477
- 'links' => 'links-input',
478
- 'metadata' => 'metadata-input',
479
- 'payout_type' => 'payout_type-input',
480
- 'reference' => 'reference-input',
481
- 'status' => 'status-input',
482
- 'tax_currency' => 'tax_currency-input',
483
- },
484
- }.to_json,
485
- headers: response_headers
486
- )
487
- end
488
-
489
- it 'updates and returns the resource' do
490
- expect(put_update_response).to be_a(GoCardlessPro::Resources::Payout)
491
- expect(stub).to have_been_requested
492
- end
493
-
494
- describe 'retry behaviour' do
495
- before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
496
-
497
- it 'retries timeouts' do
498
- stub_url = '/payouts/:identity'.gsub(':identity', id)
499
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
500
- to_timeout.then.to_return(status: 200, headers: response_headers)
501
-
502
- put_update_response
503
- expect(stub).to have_been_requested.twice
504
- end
505
-
506
- it 'retries 5XX errors' do
507
- stub_url = '/payouts/:identity'.gsub(':identity', id)
508
- stub = stub_request(:put, /.*api.gocardless.com#{stub_url}/).
509
- to_return(status: 502,
510
- headers: { 'Content-Type' => 'text/html' },
511
- body: '<html><body>Response from Cloudflare</body></html>').
512
- then.to_return(status: 200, headers: response_headers)
513
-
514
- put_update_response
515
- expect(stub).to have_been_requested.twice
516
- end
517
- end
518
- end
519
- end
520
- end