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