gocardless_pro 2.27.0 → 2.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +20 -1
  3. data/lib/gocardless_pro/api_service.rb +4 -0
  4. data/lib/gocardless_pro/client.rb +11 -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 +3 -9
  10. data/lib/gocardless_pro/resources/billing_request.rb +31 -7
  11. data/lib/gocardless_pro/resources/billing_request_flow.rb +14 -0
  12. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  13. data/lib/gocardless_pro/resources/block.rb +76 -0
  14. data/lib/gocardless_pro/resources/event.rb +20 -0
  15. data/lib/gocardless_pro/resources/institution.rb +7 -1
  16. data/lib/gocardless_pro/resources/payer_authorisation.rb +9 -0
  17. data/lib/gocardless_pro/resources/redirect_flow.rb +6 -0
  18. data/lib/gocardless_pro/services/bank_authorisations_service.rb +0 -2
  19. data/lib/gocardless_pro/services/billing_request_flows_service.rb +23 -0
  20. data/lib/gocardless_pro/services/billing_request_templates_service.rb +131 -0
  21. data/lib/gocardless_pro/services/billing_requests_service.rb +89 -24
  22. data/lib/gocardless_pro/services/blocks_service.rb +223 -0
  23. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +1 -5
  24. data/lib/gocardless_pro/services/creditors_service.rb +1 -3
  25. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +1 -1
  26. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +1 -5
  27. data/lib/gocardless_pro/services/customers_service.rb +1 -3
  28. data/lib/gocardless_pro/services/events_service.rb +1 -1
  29. data/lib/gocardless_pro/services/instalment_schedules_service.rb +1 -7
  30. data/lib/gocardless_pro/services/institutions_service.rb +2 -2
  31. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +1 -1
  32. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  33. data/lib/gocardless_pro/services/mandates_service.rb +1 -7
  34. data/lib/gocardless_pro/services/payer_authorisations_service.rb +0 -6
  35. data/lib/gocardless_pro/services/payments_service.rb +1 -7
  36. data/lib/gocardless_pro/services/payout_items_service.rb +1 -1
  37. data/lib/gocardless_pro/services/payouts_service.rb +1 -1
  38. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  39. data/lib/gocardless_pro/services/refunds_service.rb +1 -3
  40. data/lib/gocardless_pro/services/scenario_simulators_service.rb +28 -6
  41. data/lib/gocardless_pro/services/subscriptions_service.rb +3 -11
  42. data/lib/gocardless_pro/services/tax_rates_service.rb +1 -1
  43. data/lib/gocardless_pro/services/webhooks_service.rb +1 -3
  44. data/lib/gocardless_pro/version.rb +1 -1
  45. data/lib/gocardless_pro.rb +9 -0
  46. data/spec/api_service_spec.rb +12 -1
  47. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  48. data/spec/resources/bank_authorisation_spec.rb +7 -7
  49. data/spec/resources/billing_request_flow_spec.rb +104 -0
  50. data/spec/resources/billing_request_spec.rb +183 -29
  51. data/spec/resources/billing_request_template_spec.rb +502 -0
  52. data/spec/resources/block_spec.rb +577 -0
  53. data/spec/resources/creditor_bank_account_spec.rb +2 -0
  54. data/spec/resources/customer_bank_account_spec.rb +2 -0
  55. data/spec/resources/customer_notification_spec.rb +2 -0
  56. data/spec/resources/customer_spec.rb +2 -0
  57. data/spec/resources/instalment_schedule_spec.rb +2 -0
  58. data/spec/resources/institution_spec.rb +5 -0
  59. data/spec/resources/mandate_import_spec.rb +4 -0
  60. data/spec/resources/mandate_spec.rb +4 -0
  61. data/spec/resources/payer_authorisation_spec.rb +4 -0
  62. data/spec/resources/payment_spec.rb +4 -0
  63. data/spec/resources/redirect_flow_spec.rb +11 -0
  64. data/spec/resources/scenario_simulator_spec.rb +2 -0
  65. data/spec/resources/subscription_spec.rb +6 -0
  66. data/spec/resources/webhook_spec.rb +2 -0
  67. data/spec/services/bank_authorisations_service_spec.rb +7 -20
  68. data/spec/services/billing_request_flows_service_spec.rb +115 -0
  69. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  70. data/spec/services/billing_requests_service_spec.rb +210 -47
  71. data/spec/services/blocks_service_spec.rb +840 -0
  72. data/spec/services/creditor_bank_accounts_service_spec.rb +2 -13
  73. data/spec/services/creditors_service_spec.rb +0 -13
  74. data/spec/services/customer_bank_accounts_service_spec.rb +2 -13
  75. data/spec/services/customer_notifications_service_spec.rb +2 -0
  76. data/spec/services/customers_service_spec.rb +2 -13
  77. data/spec/services/instalment_schedules_service_spec.rb +2 -26
  78. data/spec/services/institutions_service_spec.rb +9 -0
  79. data/spec/services/mandate_imports_service_spec.rb +4 -13
  80. data/spec/services/mandates_service_spec.rb +4 -13
  81. data/spec/services/payer_authorisations_service_spec.rb +4 -13
  82. data/spec/services/payments_service_spec.rb +4 -13
  83. data/spec/services/redirect_flows_service_spec.rb +11 -13
  84. data/spec/services/refunds_service_spec.rb +0 -13
  85. data/spec/services/scenario_simulators_service_spec.rb +2 -0
  86. data/spec/services/subscriptions_service_spec.rb +6 -13
  87. data/spec/services/webhooks_service_spec.rb +2 -0
  88. metadata +18 -3
@@ -0,0 +1,131 @@
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 BillingRequestTemplate endpoints
12
+ class BillingRequestTemplatesService < BaseService
13
+ # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
14
+ # Billing Request Templates.
15
+ # Example URL: /billing_request_templates
16
+ # @param options [Hash] parameters as a hash, under a params key.
17
+ def list(options = {})
18
+ path = '/billing_request_templates'
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::BillingRequestTemplate
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
+ # Fetches a Billing Request Template
43
+ # Example URL: /billing_request_templates/:identity
44
+ #
45
+ # @param identity # Unique identifier, beginning with "BRT".
46
+ # @param options [Hash] parameters as a hash, under a params key.
47
+ def get(identity, options = {})
48
+ path = sub_url('/billing_request_templates/:identity', 'identity' => identity)
49
+
50
+ options[:retry_failures] = true
51
+
52
+ response = make_request(:get, path, options)
53
+
54
+ return if response.body.nil?
55
+
56
+ Resources::BillingRequestTemplate.new(unenvelope_body(response.body), response)
57
+ end
58
+
59
+ #
60
+ # Example URL: /billing_request_templates
61
+ # @param options [Hash] parameters as a hash, under a params key.
62
+ def create(options = {})
63
+ path = '/billing_request_templates'
64
+
65
+ params = options.delete(:params) || {}
66
+ options[:params] = {}
67
+ options[:params][envelope_key] = params
68
+
69
+ options[:retry_failures] = true
70
+
71
+ begin
72
+ response = make_request(:post, path, options)
73
+
74
+ # Response doesn't raise any errors until #body is called
75
+ response.tap(&:body)
76
+ rescue InvalidStateError => e
77
+ if e.idempotent_creation_conflict?
78
+ case @api_service.on_idempotency_conflict
79
+ when :raise
80
+ raise IdempotencyConflict, e.error
81
+ when :fetch
82
+ return get(e.conflicting_resource_id)
83
+ end
84
+ end
85
+
86
+ raise e
87
+ end
88
+
89
+ return if response.body.nil?
90
+
91
+ Resources::BillingRequestTemplate.new(unenvelope_body(response.body), response)
92
+ end
93
+
94
+ # Updates a Billing Request Template, which will affect all future Billing
95
+ # Requests created by this template.
96
+ # Example URL: /billing_request_templates/:identity
97
+ #
98
+ # @param identity # Unique identifier, beginning with "BRQ".
99
+ # @param options [Hash] parameters as a hash, under a params key.
100
+ def update(identity, options = {})
101
+ path = sub_url('/billing_request_templates/:identity', 'identity' => identity)
102
+
103
+ params = options.delete(:params) || {}
104
+ options[:params] = {}
105
+ options[:params][envelope_key] = params
106
+
107
+ options[:retry_failures] = true
108
+
109
+ response = make_request(:put, path, options)
110
+
111
+ return if response.body.nil?
112
+
113
+ Resources::BillingRequestTemplate.new(unenvelope_body(response.body), response)
114
+ end
115
+
116
+ private
117
+
118
+ # Unenvelope the response of the body using the service's `envelope_key`
119
+ #
120
+ # @param body [Hash]
121
+ def unenvelope_body(body)
122
+ body[envelope_key] || body['data']
123
+ end
124
+
125
+ # return the key which API responses will envelope data under
126
+ def envelope_key
127
+ 'billing_request_templates'
128
+ end
129
+ end
130
+ end
131
+ end
@@ -11,7 +11,7 @@ module GoCardlessPro
11
11
  # Service for making requests to the BillingRequest endpoints
12
12
  class BillingRequestsService < BaseService
13
13
  # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
14
- # billing_requests.
14
+ # billing requests.
15
15
  # Example URL: /billing_requests
16
16
  # @param options [Hash] parameters as a hash, under a params key.
17
17
  def list(options = {})
@@ -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.
@@ -63,8 +63,6 @@ module GoCardlessPro
63
63
  raise IdempotencyConflict, e.error
64
64
  when :fetch
65
65
  return get(e.conflicting_resource_id)
66
- else
67
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
68
66
  end
69
67
  end
70
68
 
@@ -79,7 +77,7 @@ module GoCardlessPro
79
77
  # Fetches a billing request
80
78
  # Example URL: /billing_requests/:identity
81
79
  #
82
- # @param identity # Unique identifier, beginning with "PY".
80
+ # @param identity # Unique identifier, beginning with "BRQ".
83
81
  # @param options [Hash] parameters as a hash, under a params key.
84
82
  def get(identity, options = {})
85
83
  path = sub_url('/billing_requests/:identity', 'identity' => identity)
@@ -105,7 +103,7 @@ module GoCardlessPro
105
103
  # successful.
106
104
  # Example URL: /billing_requests/:identity/actions/collect_customer_details
107
105
  #
108
- # @param identity # Unique identifier, beginning with "PY".
106
+ # @param identity # Unique identifier, beginning with "BRQ".
109
107
  # @param options [Hash] parameters as a hash, under a params key.
110
108
  def collect_customer_details(identity, options = {})
111
109
  path = sub_url('/billing_requests/:identity/actions/collect_customer_details', 'identity' => identity)
@@ -128,8 +126,6 @@ module GoCardlessPro
128
126
  raise IdempotencyConflict, e.error
129
127
  when :fetch
130
128
  return get(e.conflicting_resource_id)
131
- else
132
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
133
129
  end
134
130
  end
135
131
 
@@ -142,18 +138,18 @@ module GoCardlessPro
142
138
  end
143
139
 
144
140
  # If the billing request has a pending
145
- # <code>collect_bank_account_details</code> action, this endpoint can be
141
+ # <code>collect_bank_account</code> action, this endpoint can be
146
142
  # used to collect the details in order to complete it.
147
143
  #
148
144
  # The endpoint takes the same payload as Customer Bank Accounts, but check
149
145
  # the bank account is valid for the billing request scheme before creating
150
146
  # and attaching it.
151
- # Example URL: /billing_requests/:identity/actions/collect_bank_account_details
147
+ # Example URL: /billing_requests/:identity/actions/collect_bank_account
152
148
  #
153
- # @param identity # Unique identifier, beginning with "PY".
149
+ # @param identity # Unique identifier, beginning with "BRQ".
154
150
  # @param options [Hash] parameters as a hash, under a params key.
155
- def collect_bank_account_details(identity, options = {})
156
- path = sub_url('/billing_requests/:identity/actions/collect_bank_account_details', 'identity' => identity)
151
+ def collect_bank_account(identity, options = {})
152
+ path = sub_url('/billing_requests/:identity/actions/collect_bank_account', 'identity' => identity)
157
153
 
158
154
  params = options.delete(:params) || {}
159
155
  options[:params] = {}
@@ -173,8 +169,6 @@ module GoCardlessPro
173
169
  raise IdempotencyConflict, e.error
174
170
  when :fetch
175
171
  return get(e.conflicting_resource_id)
176
- else
177
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
178
172
  end
179
173
  end
180
174
 
@@ -190,7 +184,7 @@ module GoCardlessPro
190
184
  # it to fulfil, executing the payment.
191
185
  # Example URL: /billing_requests/:identity/actions/fulfil
192
186
  #
193
- # @param identity # Unique identifier, beginning with "PY".
187
+ # @param identity # Unique identifier, beginning with "BRQ".
194
188
  # @param options [Hash] parameters as a hash, under a params key.
195
189
  def fulfil(identity, options = {})
196
190
  path = sub_url('/billing_requests/:identity/actions/fulfil', 'identity' => identity)
@@ -213,8 +207,45 @@ module GoCardlessPro
213
207
  raise IdempotencyConflict, e.error
214
208
  when :fetch
215
209
  return get(e.conflicting_resource_id)
216
- else
217
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
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 a 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)
218
249
  end
219
250
  end
220
251
 
@@ -230,7 +261,7 @@ module GoCardlessPro
230
261
  # to expire.
231
262
  # Example URL: /billing_requests/:identity/actions/cancel
232
263
  #
233
- # @param identity # Unique identifier, beginning with "PY".
264
+ # @param identity # Unique identifier, beginning with "BRQ".
234
265
  # @param options [Hash] parameters as a hash, under a params key.
235
266
  def cancel(identity, options = {})
236
267
  path = sub_url('/billing_requests/:identity/actions/cancel', 'identity' => identity)
@@ -253,8 +284,6 @@ module GoCardlessPro
253
284
  raise IdempotencyConflict, e.error
254
285
  when :fetch
255
286
  return get(e.conflicting_resource_id)
256
- else
257
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
258
287
  end
259
288
  end
260
289
 
@@ -271,7 +300,7 @@ module GoCardlessPro
271
300
  # Currently, the customer can only be notified by email.
272
301
  # Example URL: /billing_requests/:identity/actions/notify
273
302
  #
274
- # @param identity # Unique identifier, beginning with "PY".
303
+ # @param identity # Unique identifier, beginning with "BRQ".
275
304
  # @param options [Hash] parameters as a hash, under a params key.
276
305
  def notify(identity, options = {})
277
306
  path = sub_url('/billing_requests/:identity/actions/notify', 'identity' => identity)
@@ -294,8 +323,44 @@ module GoCardlessPro
294
323
  raise IdempotencyConflict, e.error
295
324
  when :fetch
296
325
  return get(e.conflicting_resource_id)
297
- else
298
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
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
+ # Triggers a fallback from the open-banking flow to direct debit. Note, the
338
+ # billing request must have fallback enabled.
339
+ # Example URL: /billing_requests/:identity/actions/fallback
340
+ #
341
+ # @param identity # Unique identifier, beginning with "BRQ".
342
+ # @param options [Hash] parameters as a hash, under a params key.
343
+ def fallback(identity, options = {})
344
+ path = sub_url('/billing_requests/:identity/actions/fallback', 'identity' => identity)
345
+
346
+ params = options.delete(:params) || {}
347
+ options[:params] = {}
348
+ options[:params]['data'] = params
349
+
350
+ options[:retry_failures] = false
351
+
352
+ begin
353
+ response = make_request(:post, path, options)
354
+
355
+ # Response doesn't raise any errors until #body is called
356
+ response.tap(&:body)
357
+ rescue InvalidStateError => e
358
+ if e.idempotent_creation_conflict?
359
+ case @api_service.on_idempotency_conflict
360
+ when :raise
361
+ raise IdempotencyConflict, e.error
362
+ when :fetch
363
+ return get(e.conflicting_resource_id)
299
364
  end
300
365
  end
301
366
 
@@ -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.