gocardless_pro 2.24.0 → 2.29.0

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -4
  3. data/lib/gocardless_pro/api_service.rb +4 -0
  4. data/lib/gocardless_pro/client.rb +46 -1
  5. data/lib/gocardless_pro/error/authentication_error.rb +4 -0
  6. data/lib/gocardless_pro/error/permission_error.rb +4 -0
  7. data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
  8. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
  9. data/lib/gocardless_pro/resources/bank_authorisation.rb +81 -0
  10. data/lib/gocardless_pro/resources/billing_request.rb +108 -0
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +72 -0
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  13. data/lib/gocardless_pro/resources/block.rb +66 -0
  14. data/lib/gocardless_pro/resources/creditor.rb +2 -3
  15. data/lib/gocardless_pro/resources/event.rb +20 -0
  16. data/lib/gocardless_pro/resources/institution.rb +47 -0
  17. data/lib/gocardless_pro/resources/payer_authorisation.rb +131 -0
  18. data/lib/gocardless_pro/resources/payout_item.rb +4 -0
  19. data/lib/gocardless_pro/resources/redirect_flow.rb +2 -0
  20. data/lib/gocardless_pro/resources/scenario_simulator.rb +42 -0
  21. data/lib/gocardless_pro/resources/webhook.rb +62 -0
  22. data/lib/gocardless_pro/services/bank_authorisations_service.rb +80 -0
  23. data/lib/gocardless_pro/services/billing_request_flows_service.rb +70 -0
  24. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  25. data/lib/gocardless_pro/services/billing_requests_service.rb +352 -0
  26. data/lib/gocardless_pro/services/blocks_service.rb +223 -0
  27. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +1 -5
  28. data/lib/gocardless_pro/services/creditors_service.rb +1 -3
  29. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +1 -1
  30. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +1 -5
  31. data/lib/gocardless_pro/services/customers_service.rb +1 -3
  32. data/lib/gocardless_pro/services/events_service.rb +1 -1
  33. data/lib/gocardless_pro/services/instalment_schedules_service.rb +1 -7
  34. data/lib/gocardless_pro/services/institutions_service.rb +56 -0
  35. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +1 -1
  36. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  37. data/lib/gocardless_pro/services/mandates_service.rb +1 -7
  38. data/lib/gocardless_pro/services/payer_authorisations_service.rb +202 -0
  39. data/lib/gocardless_pro/services/payments_service.rb +1 -7
  40. data/lib/gocardless_pro/services/payout_items_service.rb +1 -1
  41. data/lib/gocardless_pro/services/payouts_service.rb +1 -1
  42. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  43. data/lib/gocardless_pro/services/refunds_service.rb +1 -3
  44. data/lib/gocardless_pro/services/scenario_simulators_service.rb +170 -0
  45. data/lib/gocardless_pro/services/subscriptions_service.rb +10 -13
  46. data/lib/gocardless_pro/services/tax_rates_service.rb +1 -1
  47. data/lib/gocardless_pro/services/webhooks_service.rb +111 -0
  48. data/lib/gocardless_pro/version.rb +1 -1
  49. data/lib/gocardless_pro.rb +30 -0
  50. data/spec/api_service_spec.rb +12 -1
  51. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  52. data/spec/resources/bank_authorisation_spec.rb +259 -0
  53. data/spec/resources/billing_request_flow_spec.rb +219 -0
  54. data/spec/resources/billing_request_spec.rb +782 -0
  55. data/spec/resources/billing_request_template_spec.rb +502 -0
  56. data/spec/resources/block_spec.rb +560 -0
  57. data/spec/resources/institution_spec.rb +108 -0
  58. data/spec/resources/payer_authorisation_spec.rb +418 -0
  59. data/spec/resources/redirect_flow_spec.rb +9 -0
  60. data/spec/resources/scenario_simulator_spec.rb +63 -0
  61. data/spec/resources/webhook_spec.rb +323 -0
  62. data/spec/services/bank_authorisations_service_spec.rb +353 -0
  63. data/spec/services/billing_request_flows_service_spec.rb +253 -0
  64. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  65. data/spec/services/billing_requests_service_spec.rb +1082 -0
  66. data/spec/services/blocks_service_spec.rb +823 -0
  67. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -13
  68. data/spec/services/creditors_service_spec.rb +0 -13
  69. data/spec/services/customer_bank_accounts_service_spec.rb +0 -13
  70. data/spec/services/customers_service_spec.rb +0 -13
  71. data/spec/services/instalment_schedules_service_spec.rb +0 -26
  72. data/spec/services/institutions_service_spec.rb +232 -0
  73. data/spec/services/mandate_imports_service_spec.rb +0 -13
  74. data/spec/services/mandates_service_spec.rb +0 -13
  75. data/spec/services/payer_authorisations_service_spec.rb +559 -0
  76. data/spec/services/payments_service_spec.rb +0 -13
  77. data/spec/services/redirect_flows_service_spec.rb +9 -13
  78. data/spec/services/refunds_service_spec.rb +0 -13
  79. data/spec/services/scenario_simulators_service_spec.rb +74 -0
  80. data/spec/services/subscriptions_service_spec.rb +0 -13
  81. data/spec/services/webhooks_service_spec.rb +545 -0
  82. metadata +64 -7
@@ -0,0 +1,352 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # This client is automatically generated from a template and JSON schema definition.
6
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
7
+ #
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the BillingRequest endpoints
12
+ class BillingRequestsService < BaseService
13
+ # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
14
+ # billing_requests.
15
+ # Example URL: /billing_requests
16
+ # @param options [Hash] parameters as a hash, under a params key.
17
+ def list(options = {})
18
+ path = '/billing_requests'
19
+
20
+ options[:retry_failures] = true
21
+
22
+ response = make_request(:get, path, options)
23
+
24
+ ListResponse.new(
25
+ response: response,
26
+ unenveloped_body: unenvelope_body(response.body),
27
+ resource_class: Resources::BillingRequest
28
+ )
29
+ end
30
+
31
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
32
+ #
33
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
34
+ # Otherwise they will be the body of the request.
35
+ def all(options = {})
36
+ Paginator.new(
37
+ service: self,
38
+ options: options
39
+ ).enumerator
40
+ end
41
+
42
+ #
43
+ # Example URL: /billing_requests
44
+ # @param options [Hash] parameters as a hash, under a params key.
45
+ def create(options = {})
46
+ path = '/billing_requests'
47
+
48
+ params = options.delete(:params) || {}
49
+ options[:params] = {}
50
+ options[:params][envelope_key] = params
51
+
52
+ options[:retry_failures] = true
53
+
54
+ begin
55
+ response = make_request(:post, path, options)
56
+
57
+ # Response doesn't raise any errors until #body is called
58
+ response.tap(&:body)
59
+ rescue InvalidStateError => e
60
+ if e.idempotent_creation_conflict?
61
+ case @api_service.on_idempotency_conflict
62
+ when :raise
63
+ raise IdempotencyConflict, e.error
64
+ when :fetch
65
+ return get(e.conflicting_resource_id)
66
+ end
67
+ end
68
+
69
+ raise e
70
+ end
71
+
72
+ return if response.body.nil?
73
+
74
+ Resources::BillingRequest.new(unenvelope_body(response.body), response)
75
+ end
76
+
77
+ # Fetches a billing request
78
+ # Example URL: /billing_requests/:identity
79
+ #
80
+ # @param identity # Unique identifier, beginning with "BRQ".
81
+ # @param options [Hash] parameters as a hash, under a params key.
82
+ def get(identity, options = {})
83
+ path = sub_url('/billing_requests/:identity', 'identity' => identity)
84
+
85
+ options[:retry_failures] = true
86
+
87
+ response = make_request(:get, path, options)
88
+
89
+ return if response.body.nil?
90
+
91
+ Resources::BillingRequest.new(unenvelope_body(response.body), response)
92
+ end
93
+
94
+ # If the billing request has a pending <code>collect_customer_details</code>
95
+ # action, this endpoint can be used to collect the details in order to
96
+ # complete it.
97
+ #
98
+ # The endpoint takes the same payload as Customers, but checks that the
99
+ # customer fields are populated correctly for the billing request scheme.
100
+ #
101
+ # Whatever is provided to this endpoint is used to update the referenced
102
+ # customer, and will take effect immediately after the request is
103
+ # successful.
104
+ # Example URL: /billing_requests/:identity/actions/collect_customer_details
105
+ #
106
+ # @param identity # Unique identifier, beginning with "BRQ".
107
+ # @param options [Hash] parameters as a hash, under a params key.
108
+ def collect_customer_details(identity, options = {})
109
+ path = sub_url('/billing_requests/:identity/actions/collect_customer_details', 'identity' => identity)
110
+
111
+ params = options.delete(:params) || {}
112
+ options[:params] = {}
113
+ options[:params]['data'] = params
114
+
115
+ options[:retry_failures] = false
116
+
117
+ begin
118
+ response = make_request(:post, path, options)
119
+
120
+ # Response doesn't raise any errors until #body is called
121
+ response.tap(&:body)
122
+ rescue InvalidStateError => e
123
+ if e.idempotent_creation_conflict?
124
+ case @api_service.on_idempotency_conflict
125
+ when :raise
126
+ raise IdempotencyConflict, e.error
127
+ when :fetch
128
+ return get(e.conflicting_resource_id)
129
+ end
130
+ end
131
+
132
+ raise e
133
+ end
134
+
135
+ return if response.body.nil?
136
+
137
+ Resources::BillingRequest.new(unenvelope_body(response.body), response)
138
+ end
139
+
140
+ # If the billing request has a pending
141
+ # <code>collect_bank_account</code> action, this endpoint can be
142
+ # used to collect the details in order to complete it.
143
+ #
144
+ # The endpoint takes the same payload as Customer Bank Accounts, but check
145
+ # the bank account is valid for the billing request scheme before creating
146
+ # and attaching it.
147
+ # Example URL: /billing_requests/:identity/actions/collect_bank_account
148
+ #
149
+ # @param identity # Unique identifier, beginning with "BRQ".
150
+ # @param options [Hash] parameters as a hash, under a params key.
151
+ def collect_bank_account(identity, options = {})
152
+ path = sub_url('/billing_requests/:identity/actions/collect_bank_account', 'identity' => identity)
153
+
154
+ params = options.delete(:params) || {}
155
+ options[:params] = {}
156
+ options[:params]['data'] = params
157
+
158
+ options[:retry_failures] = false
159
+
160
+ begin
161
+ response = make_request(:post, path, options)
162
+
163
+ # Response doesn't raise any errors until #body is called
164
+ response.tap(&:body)
165
+ rescue InvalidStateError => e
166
+ if e.idempotent_creation_conflict?
167
+ case @api_service.on_idempotency_conflict
168
+ when :raise
169
+ raise IdempotencyConflict, e.error
170
+ when :fetch
171
+ return get(e.conflicting_resource_id)
172
+ end
173
+ end
174
+
175
+ raise e
176
+ end
177
+
178
+ return if response.body.nil?
179
+
180
+ Resources::BillingRequest.new(unenvelope_body(response.body), response)
181
+ end
182
+
183
+ # If a billing request is ready to be fulfilled, call this endpoint to cause
184
+ # it to fulfil, executing the payment.
185
+ # Example URL: /billing_requests/:identity/actions/fulfil
186
+ #
187
+ # @param identity # Unique identifier, beginning with "BRQ".
188
+ # @param options [Hash] parameters as a hash, under a params key.
189
+ def fulfil(identity, options = {})
190
+ path = sub_url('/billing_requests/:identity/actions/fulfil', 'identity' => identity)
191
+
192
+ params = options.delete(:params) || {}
193
+ options[:params] = {}
194
+ options[:params]['data'] = params
195
+
196
+ options[:retry_failures] = false
197
+
198
+ begin
199
+ response = make_request(:post, path, options)
200
+
201
+ # Response doesn't raise any errors until #body is called
202
+ response.tap(&:body)
203
+ rescue InvalidStateError => e
204
+ if e.idempotent_creation_conflict?
205
+ case @api_service.on_idempotency_conflict
206
+ when :raise
207
+ raise IdempotencyConflict, e.error
208
+ when :fetch
209
+ return get(e.conflicting_resource_id)
210
+ end
211
+ end
212
+
213
+ raise e
214
+ end
215
+
216
+ return if response.body.nil?
217
+
218
+ Resources::BillingRequest.new(unenvelope_body(response.body), response)
219
+ end
220
+
221
+ # This is needed when you have mandate_request. As a scheme compliance rule we
222
+ # are required to
223
+ # allow the payer to crosscheck the details entered by them and confirm it.
224
+ # Example URL: /billing_requests/:identity/actions/confirm_payer_details
225
+ #
226
+ # @param identity # Unique identifier, beginning with "BRQ".
227
+ # @param options [Hash] parameters as a hash, under a params key.
228
+ def confirm_payer_details(identity, options = {})
229
+ path = sub_url('/billing_requests/:identity/actions/confirm_payer_details', 'identity' => identity)
230
+
231
+ params = options.delete(:params) || {}
232
+ options[:params] = {}
233
+ options[:params]['data'] = params
234
+
235
+ options[:retry_failures] = false
236
+
237
+ begin
238
+ response = make_request(:post, path, options)
239
+
240
+ # Response doesn't raise any errors until #body is called
241
+ response.tap(&:body)
242
+ rescue InvalidStateError => e
243
+ if e.idempotent_creation_conflict?
244
+ case @api_service.on_idempotency_conflict
245
+ when :raise
246
+ raise IdempotencyConflict, e.error
247
+ when :fetch
248
+ return get(e.conflicting_resource_id)
249
+ end
250
+ end
251
+
252
+ raise e
253
+ end
254
+
255
+ return if response.body.nil?
256
+
257
+ Resources::BillingRequest.new(unenvelope_body(response.body), response)
258
+ end
259
+
260
+ # Immediately cancels a billing request, causing all billing request flows
261
+ # to expire.
262
+ # Example URL: /billing_requests/:identity/actions/cancel
263
+ #
264
+ # @param identity # Unique identifier, beginning with "BRQ".
265
+ # @param options [Hash] parameters as a hash, under a params key.
266
+ def cancel(identity, options = {})
267
+ path = sub_url('/billing_requests/:identity/actions/cancel', 'identity' => identity)
268
+
269
+ params = options.delete(:params) || {}
270
+ options[:params] = {}
271
+ options[:params]['data'] = params
272
+
273
+ options[:retry_failures] = false
274
+
275
+ begin
276
+ response = make_request(:post, path, options)
277
+
278
+ # Response doesn't raise any errors until #body is called
279
+ response.tap(&:body)
280
+ rescue InvalidStateError => e
281
+ if e.idempotent_creation_conflict?
282
+ case @api_service.on_idempotency_conflict
283
+ when :raise
284
+ raise IdempotencyConflict, e.error
285
+ when :fetch
286
+ return get(e.conflicting_resource_id)
287
+ end
288
+ end
289
+
290
+ raise e
291
+ end
292
+
293
+ return if response.body.nil?
294
+
295
+ Resources::BillingRequest.new(unenvelope_body(response.body), response)
296
+ end
297
+
298
+ # Notifies the customer linked to the billing request, asking them to authorise
299
+ # it.
300
+ # Currently, the customer can only be notified by email.
301
+ # Example URL: /billing_requests/:identity/actions/notify
302
+ #
303
+ # @param identity # Unique identifier, beginning with "BRQ".
304
+ # @param options [Hash] parameters as a hash, under a params key.
305
+ def notify(identity, options = {})
306
+ path = sub_url('/billing_requests/:identity/actions/notify', 'identity' => identity)
307
+
308
+ params = options.delete(:params) || {}
309
+ options[:params] = {}
310
+ options[:params]['data'] = params
311
+
312
+ options[:retry_failures] = false
313
+
314
+ begin
315
+ response = make_request(:post, path, options)
316
+
317
+ # Response doesn't raise any errors until #body is called
318
+ response.tap(&:body)
319
+ rescue InvalidStateError => e
320
+ if e.idempotent_creation_conflict?
321
+ case @api_service.on_idempotency_conflict
322
+ when :raise
323
+ raise IdempotencyConflict, e.error
324
+ when :fetch
325
+ return get(e.conflicting_resource_id)
326
+ end
327
+ end
328
+
329
+ raise e
330
+ end
331
+
332
+ return if response.body.nil?
333
+
334
+ Resources::BillingRequest.new(unenvelope_body(response.body), response)
335
+ end
336
+
337
+ private
338
+
339
+ # Unenvelope the response of the body using the service's `envelope_key`
340
+ #
341
+ # @param body [Hash]
342
+ def unenvelope_body(body)
343
+ body[envelope_key] || body['data']
344
+ end
345
+
346
+ # return the key which API responses will envelope data under
347
+ def envelope_key
348
+ 'billing_requests'
349
+ end
350
+ end
351
+ end
352
+ end
@@ -0,0 +1,223 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # This client is automatically generated from a template and JSON schema definition.
6
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
7
+ #
8
+
9
+ module GoCardlessPro
10
+ module Services
11
+ # Service for making requests to the Block endpoints
12
+ class BlocksService < BaseService
13
+ # Creates a new Block of a given type. By default it will be active.
14
+ # Example URL: /blocks
15
+ # @param options [Hash] parameters as a hash, under a params key.
16
+ def create(options = {})
17
+ path = '/blocks'
18
+
19
+ params = options.delete(:params) || {}
20
+ options[:params] = {}
21
+ options[:params][envelope_key] = params
22
+
23
+ options[:retry_failures] = true
24
+
25
+ begin
26
+ response = make_request(:post, path, options)
27
+
28
+ # Response doesn't raise any errors until #body is called
29
+ response.tap(&:body)
30
+ rescue InvalidStateError => e
31
+ if e.idempotent_creation_conflict?
32
+ case @api_service.on_idempotency_conflict
33
+ when :raise
34
+ raise IdempotencyConflict, e.error
35
+ when :fetch
36
+ return get(e.conflicting_resource_id)
37
+ end
38
+ end
39
+
40
+ raise e
41
+ end
42
+
43
+ return if response.body.nil?
44
+
45
+ Resources::Block.new(unenvelope_body(response.body), response)
46
+ end
47
+
48
+ # Retrieves the details of an existing block.
49
+ # Example URL: /blocks/:identity
50
+ #
51
+ # @param identity # Unique identifier, beginning with "BLC".
52
+ # @param options [Hash] parameters as a hash, under a params key.
53
+ def get(identity, options = {})
54
+ path = sub_url('/blocks/:identity', 'identity' => identity)
55
+
56
+ options[:retry_failures] = true
57
+
58
+ response = make_request(:get, path, options)
59
+
60
+ return if response.body.nil?
61
+
62
+ Resources::Block.new(unenvelope_body(response.body), response)
63
+ end
64
+
65
+ # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
66
+ # blocks.
67
+ # Example URL: /blocks
68
+ # @param options [Hash] parameters as a hash, under a params key.
69
+ def list(options = {})
70
+ path = '/blocks'
71
+
72
+ options[:retry_failures] = true
73
+
74
+ response = make_request(:get, path, options)
75
+
76
+ ListResponse.new(
77
+ response: response,
78
+ unenveloped_body: unenvelope_body(response.body),
79
+ resource_class: Resources::Block
80
+ )
81
+ end
82
+
83
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
84
+ #
85
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
86
+ # Otherwise they will be the body of the request.
87
+ def all(options = {})
88
+ Paginator.new(
89
+ service: self,
90
+ options: options
91
+ ).enumerator
92
+ end
93
+
94
+ # Disables a block so that it no longer will prevent mandate creation.
95
+ # Example URL: /blocks/:identity/actions/disable
96
+ #
97
+ # @param identity # Unique identifier, beginning with "BLC".
98
+ # @param options [Hash] parameters as a hash, under a params key.
99
+ def disable(identity, options = {})
100
+ path = sub_url('/blocks/:identity/actions/disable', 'identity' => identity)
101
+
102
+ params = options.delete(:params) || {}
103
+ options[:params] = {}
104
+ options[:params]['data'] = params
105
+
106
+ options[:retry_failures] = false
107
+
108
+ begin
109
+ response = make_request(:post, path, options)
110
+
111
+ # Response doesn't raise any errors until #body is called
112
+ response.tap(&:body)
113
+ rescue InvalidStateError => e
114
+ if e.idempotent_creation_conflict?
115
+ case @api_service.on_idempotency_conflict
116
+ when :raise
117
+ raise IdempotencyConflict, e.error
118
+ when :fetch
119
+ return get(e.conflicting_resource_id)
120
+ end
121
+ end
122
+
123
+ raise e
124
+ end
125
+
126
+ return if response.body.nil?
127
+
128
+ Resources::Block.new(unenvelope_body(response.body), response)
129
+ end
130
+
131
+ # Enables a previously disabled block so that it will prevent mandate creation
132
+ # Example URL: /blocks/:identity/actions/enable
133
+ #
134
+ # @param identity # Unique identifier, beginning with "BLC".
135
+ # @param options [Hash] parameters as a hash, under a params key.
136
+ def enable(identity, options = {})
137
+ path = sub_url('/blocks/:identity/actions/enable', 'identity' => identity)
138
+
139
+ params = options.delete(:params) || {}
140
+ options[:params] = {}
141
+ options[:params]['data'] = params
142
+
143
+ options[:retry_failures] = false
144
+
145
+ begin
146
+ response = make_request(:post, path, options)
147
+
148
+ # Response doesn't raise any errors until #body is called
149
+ response.tap(&:body)
150
+ rescue InvalidStateError => e
151
+ if e.idempotent_creation_conflict?
152
+ case @api_service.on_idempotency_conflict
153
+ when :raise
154
+ raise IdempotencyConflict, e.error
155
+ when :fetch
156
+ return get(e.conflicting_resource_id)
157
+ end
158
+ end
159
+
160
+ raise e
161
+ end
162
+
163
+ return if response.body.nil?
164
+
165
+ Resources::Block.new(unenvelope_body(response.body), response)
166
+ end
167
+
168
+ # Creates new blocks for a given reference. By default blocks will be active.
169
+ # Returns 201 if at least one block was created. Returns 200 if there were no
170
+ # new
171
+ # blocks created.
172
+ # Example URL: /block_by_ref
173
+ # @param options [Hash] parameters as a hash, under a params key.
174
+ def block_by_ref(options = {})
175
+ path = '/block_by_ref'
176
+
177
+ params = options.delete(:params) || {}
178
+ options[:params] = {}
179
+ options[:params]['data'] = params
180
+
181
+ options[:retry_failures] = false
182
+
183
+ begin
184
+ response = make_request(:post, path, options)
185
+
186
+ # Response doesn't raise any errors until #body is called
187
+ response.tap(&:body)
188
+ rescue InvalidStateError => e
189
+ if e.idempotent_creation_conflict?
190
+ case @api_service.on_idempotency_conflict
191
+ when :raise
192
+ raise IdempotencyConflict, e.error
193
+ when :fetch
194
+ return get(e.conflicting_resource_id)
195
+ end
196
+ end
197
+
198
+ raise e
199
+ end
200
+
201
+ ListResponse.new(
202
+ response: response,
203
+ unenveloped_body: unenvelope_body(response.body),
204
+ resource_class: Resources::Block
205
+ )
206
+ end
207
+
208
+ private
209
+
210
+ # Unenvelope the response of the body using the service's `envelope_key`
211
+ #
212
+ # @param body [Hash]
213
+ def unenvelope_body(body)
214
+ body[envelope_key] || body['data']
215
+ end
216
+
217
+ # return the key which API responses will envelope data under
218
+ def envelope_key
219
+ 'blocks'
220
+ end
221
+ end
222
+ end
223
+ end
@@ -34,8 +34,6 @@ module GoCardlessPro
34
34
  raise IdempotencyConflict, e.error
35
35
  when :fetch
36
36
  return get(e.conflicting_resource_id)
37
- else
38
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
39
37
  end
40
38
  end
41
39
 
@@ -65,7 +63,7 @@ module GoCardlessPro
65
63
  )
66
64
  end
67
65
 
68
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
66
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
69
67
  #
70
68
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
71
69
  # Otherwise they will be the body of the request.
@@ -126,8 +124,6 @@ module GoCardlessPro
126
124
  raise IdempotencyConflict, e.error
127
125
  when :fetch
128
126
  return get(e.conflicting_resource_id)
129
- else
130
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
131
127
  end
132
128
  end
133
129
 
@@ -34,8 +34,6 @@ module GoCardlessPro
34
34
  raise IdempotencyConflict, e.error
35
35
  when :fetch
36
36
  return get(e.conflicting_resource_id)
37
- else
38
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
39
37
  end
40
38
  end
41
39
 
@@ -65,7 +63,7 @@ module GoCardlessPro
65
63
  )
66
64
  end
67
65
 
68
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
66
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
69
67
  #
70
68
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
71
69
  # Otherwise they will be the body of the request.
@@ -28,7 +28,7 @@ module GoCardlessPro
28
28
  )
29
29
  end
30
30
 
31
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
31
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
32
32
  #
33
33
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
34
34
  # Otherwise they will be the body of the request.
@@ -46,8 +46,6 @@ module GoCardlessPro
46
46
  raise IdempotencyConflict, e.error
47
47
  when :fetch
48
48
  return get(e.conflicting_resource_id)
49
- else
50
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
51
49
  end
52
50
  end
53
51
 
@@ -77,7 +75,7 @@ module GoCardlessPro
77
75
  )
78
76
  end
79
77
 
80
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
78
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
81
79
  #
82
80
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
83
81
  # Otherwise they will be the body of the request.
@@ -159,8 +157,6 @@ module GoCardlessPro
159
157
  raise IdempotencyConflict, e.error
160
158
  when :fetch
161
159
  return get(e.conflicting_resource_id)
162
- else
163
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
164
160
  end
165
161
  end
166
162
 
@@ -34,8 +34,6 @@ module GoCardlessPro
34
34
  raise IdempotencyConflict, e.error
35
35
  when :fetch
36
36
  return get(e.conflicting_resource_id)
37
- else
38
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
39
37
  end
40
38
  end
41
39
 
@@ -65,7 +63,7 @@ module GoCardlessPro
65
63
  )
66
64
  end
67
65
 
68
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
66
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
69
67
  #
70
68
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
71
69
  # Otherwise they will be the body of the request.
@@ -28,7 +28,7 @@ module GoCardlessPro
28
28
  )
29
29
  end
30
30
 
31
- # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
31
+ # Get a lazily enumerated list of all the items returned. This is similar to the `list` method but will paginate for you automatically.
32
32
  #
33
33
  # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
34
34
  # Otherwise they will be the body of the request.