gocardless_pro 2.23.0 → 2.28.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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -4
  3. data/lib/gocardless_pro.rb +27 -0
  4. data/lib/gocardless_pro/api_service.rb +4 -0
  5. data/lib/gocardless_pro/client.rb +41 -1
  6. data/lib/gocardless_pro/error/authentication_error.rb +4 -0
  7. data/lib/gocardless_pro/error/permission_error.rb +4 -0
  8. data/lib/gocardless_pro/error/rate_limit_error.rb +4 -0
  9. data/lib/gocardless_pro/middlewares/raise_gocardless_errors.rb +12 -1
  10. data/lib/gocardless_pro/resources/bank_authorisation.rb +85 -0
  11. data/lib/gocardless_pro/resources/billing_request.rb +108 -0
  12. data/lib/gocardless_pro/resources/billing_request_flow.rb +72 -0
  13. data/lib/gocardless_pro/resources/billing_request_template.rb +68 -0
  14. data/lib/gocardless_pro/resources/creditor.rb +2 -3
  15. data/lib/gocardless_pro/resources/event.rb +12 -0
  16. data/lib/gocardless_pro/resources/institution.rb +45 -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/scenario_simulator.rb +42 -0
  20. data/lib/gocardless_pro/resources/tax_rate.rb +3 -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/creditor_bank_accounts_service.rb +0 -4
  27. data/lib/gocardless_pro/services/creditors_service.rb +0 -2
  28. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +0 -4
  29. data/lib/gocardless_pro/services/customers_service.rb +0 -2
  30. data/lib/gocardless_pro/services/instalment_schedules_service.rb +0 -6
  31. data/lib/gocardless_pro/services/institutions_service.rb +56 -0
  32. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -6
  33. data/lib/gocardless_pro/services/mandates_service.rb +0 -6
  34. data/lib/gocardless_pro/services/payer_authorisations_service.rb +202 -0
  35. data/lib/gocardless_pro/services/payments_service.rb +0 -6
  36. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -4
  37. data/lib/gocardless_pro/services/refunds_service.rb +0 -2
  38. data/lib/gocardless_pro/services/scenario_simulators_service.rb +170 -0
  39. data/lib/gocardless_pro/services/subscriptions_service.rb +10 -13
  40. data/lib/gocardless_pro/services/webhooks_service.rb +111 -0
  41. data/lib/gocardless_pro/version.rb +1 -1
  42. data/spec/api_service_spec.rb +12 -1
  43. data/spec/middlewares/raise_gocardless_errors_spec.rb +30 -0
  44. data/spec/resources/bank_authorisation_spec.rb +259 -0
  45. data/spec/resources/billing_request_flow_spec.rb +219 -0
  46. data/spec/resources/billing_request_spec.rb +782 -0
  47. data/spec/resources/billing_request_template_spec.rb +502 -0
  48. data/spec/resources/institution_spec.rb +103 -0
  49. data/spec/resources/payer_authorisation_spec.rb +418 -0
  50. data/spec/resources/scenario_simulator_spec.rb +63 -0
  51. data/spec/resources/webhook_spec.rb +323 -0
  52. data/spec/services/bank_authorisations_service_spec.rb +353 -0
  53. data/spec/services/billing_request_flows_service_spec.rb +253 -0
  54. data/spec/services/billing_request_templates_service_spec.rb +789 -0
  55. data/spec/services/billing_requests_service_spec.rb +1082 -0
  56. data/spec/services/creditor_bank_accounts_service_spec.rb +0 -13
  57. data/spec/services/creditors_service_spec.rb +0 -13
  58. data/spec/services/customer_bank_accounts_service_spec.rb +0 -13
  59. data/spec/services/customers_service_spec.rb +0 -13
  60. data/spec/services/instalment_schedules_service_spec.rb +0 -26
  61. data/spec/services/institutions_service_spec.rb +223 -0
  62. data/spec/services/mandate_imports_service_spec.rb +0 -13
  63. data/spec/services/mandates_service_spec.rb +0 -13
  64. data/spec/services/payer_authorisations_service_spec.rb +559 -0
  65. data/spec/services/payments_service_spec.rb +0 -13
  66. data/spec/services/redirect_flows_service_spec.rb +0 -13
  67. data/spec/services/refunds_service_spec.rb +0 -13
  68. data/spec/services/scenario_simulators_service_spec.rb +74 -0
  69. data/spec/services/subscriptions_service_spec.rb +0 -13
  70. data/spec/services/webhooks_service_spec.rb +545 -0
  71. metadata +54 -3
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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
 
@@ -52,8 +52,6 @@ module GoCardlessPro
52
52
  raise IdempotencyConflict, e.error
53
53
  when :fetch
54
54
  return get(e.conflicting_resource_id)
55
- else
56
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
57
55
  end
58
56
  end
59
57
 
@@ -102,8 +100,6 @@ module GoCardlessPro
102
100
  raise IdempotencyConflict, e.error
103
101
  when :fetch
104
102
  return get(e.conflicting_resource_id)
105
- else
106
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
107
103
  end
108
104
  end
109
105
 
@@ -212,8 +208,6 @@ module GoCardlessPro
212
208
  raise IdempotencyConflict, e.error
213
209
  when :fetch
214
210
  return get(e.conflicting_resource_id)
215
- else
216
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
217
211
  end
218
212
  end
219
213
 
@@ -0,0 +1,56 @@
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 Institution endpoints
12
+ class InstitutionsService < BaseService
13
+ # Returns a list of all supported institutions.
14
+ # Example URL: /institutions
15
+ # @param options [Hash] parameters as a hash, under a params key.
16
+ def list(options = {})
17
+ path = '/institutions'
18
+
19
+ options[:retry_failures] = true
20
+
21
+ response = make_request(:get, path, options)
22
+
23
+ ListResponse.new(
24
+ response: response,
25
+ unenveloped_body: unenvelope_body(response.body),
26
+ resource_class: Resources::Institution
27
+ )
28
+ end
29
+
30
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
31
+ #
32
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
33
+ # Otherwise they will be the body of the request.
34
+ def all(options = {})
35
+ Paginator.new(
36
+ service: self,
37
+ options: options
38
+ ).enumerator
39
+ end
40
+
41
+ private
42
+
43
+ # Unenvelope the response of the body using the service's `envelope_key`
44
+ #
45
+ # @param body [Hash]
46
+ def unenvelope_body(body)
47
+ body[envelope_key] || body['data']
48
+ end
49
+
50
+ # return the key which API responses will envelope data under
51
+ def envelope_key
52
+ 'institutions'
53
+ end
54
+ end
55
+ end
56
+ end
@@ -38,8 +38,6 @@ module GoCardlessPro
38
38
  raise IdempotencyConflict, e.error
39
39
  when :fetch
40
40
  return get(e.conflicting_resource_id)
41
- else
42
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
43
41
  end
44
42
  end
45
43
 
@@ -104,8 +102,6 @@ module GoCardlessPro
104
102
  raise IdempotencyConflict, e.error
105
103
  when :fetch
106
104
  return get(e.conflicting_resource_id)
107
- else
108
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
109
105
  end
110
106
  end
111
107
 
@@ -149,8 +145,6 @@ module GoCardlessPro
149
145
  raise IdempotencyConflict, e.error
150
146
  when :fetch
151
147
  return get(e.conflicting_resource_id)
152
- else
153
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
154
148
  end
155
149
  end
156
150
 
@@ -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
 
@@ -148,8 +146,6 @@ module GoCardlessPro
148
146
  raise IdempotencyConflict, e.error
149
147
  when :fetch
150
148
  return get(e.conflicting_resource_id)
151
- else
152
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
153
149
  end
154
150
  end
155
151
 
@@ -198,8 +194,6 @@ module GoCardlessPro
198
194
  raise IdempotencyConflict, e.error
199
195
  when :fetch
200
196
  return get(e.conflicting_resource_id)
201
- else
202
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
203
197
  end
204
198
  end
205
199
 
@@ -0,0 +1,202 @@
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 PayerAuthorisation endpoints
12
+ class PayerAuthorisationsService < BaseService
13
+ # Retrieves the details of a single existing Payer Authorisation. It can be used
14
+ # for polling the status of a Payer Authorisation.
15
+ # Example URL: /payer_authorisations/:identity
16
+ #
17
+ # @param identity # Unique identifier, beginning with "PA".
18
+ # @param options [Hash] parameters as a hash, under a params key.
19
+ def get(identity, options = {})
20
+ path = sub_url('/payer_authorisations/:identity', 'identity' => identity)
21
+
22
+ options[:retry_failures] = true
23
+
24
+ response = make_request(:get, path, options)
25
+
26
+ return if response.body.nil?
27
+
28
+ Resources::PayerAuthorisation.new(unenvelope_body(response.body), response)
29
+ end
30
+
31
+ # Creates a Payer Authorisation. The resource is saved to the database even if
32
+ # incomplete. An empty array of incomplete_fields means that the resource is
33
+ # valid. The ID of the resource is used for the other actions. This endpoint has
34
+ # been designed this way so you do not need to save any payer data on your
35
+ # servers or the browser while still being able to implement a progressive
36
+ # solution, such as a multi-step form.
37
+ # Example URL: /payer_authorisations
38
+ # @param options [Hash] parameters as a hash, under a params key.
39
+ def create(options = {})
40
+ path = '/payer_authorisations'
41
+
42
+ params = options.delete(:params) || {}
43
+ options[:params] = {}
44
+ options[:params][envelope_key] = params
45
+
46
+ options[:retry_failures] = true
47
+
48
+ begin
49
+ response = make_request(:post, path, options)
50
+
51
+ # Response doesn't raise any errors until #body is called
52
+ response.tap(&:body)
53
+ rescue InvalidStateError => e
54
+ if e.idempotent_creation_conflict?
55
+ case @api_service.on_idempotency_conflict
56
+ when :raise
57
+ raise IdempotencyConflict, e.error
58
+ when :fetch
59
+ return get(e.conflicting_resource_id)
60
+ end
61
+ end
62
+
63
+ raise e
64
+ end
65
+
66
+ return if response.body.nil?
67
+
68
+ Resources::PayerAuthorisation.new(unenvelope_body(response.body), response)
69
+ end
70
+
71
+ # Updates a Payer Authorisation. Updates the Payer Authorisation with the
72
+ # request data. Can be invoked as many times as needed. Only fields present in
73
+ # the request will be modified. An empty array of incomplete_fields means that
74
+ # the resource is valid. This endpoint has been designed this way so you do not
75
+ # need to save any payer data on your servers or the browser while still being
76
+ # able to implement a progressive solution, such a multi-step form. <p
77
+ # class="notice"> Note that in order to update the `metadata` attribute values
78
+ # it must be sent completely as it overrides the previously existing values.
79
+ # </p>
80
+ # Example URL: /payer_authorisations/:identity
81
+ #
82
+ # @param identity # Unique identifier, beginning with "PA".
83
+ # @param options [Hash] parameters as a hash, under a params key.
84
+ def update(identity, options = {})
85
+ path = sub_url('/payer_authorisations/:identity', 'identity' => identity)
86
+
87
+ params = options.delete(:params) || {}
88
+ options[:params] = {}
89
+ options[:params][envelope_key] = params
90
+
91
+ options[:retry_failures] = true
92
+
93
+ response = make_request(:put, path, options)
94
+
95
+ return if response.body.nil?
96
+
97
+ Resources::PayerAuthorisation.new(unenvelope_body(response.body), response)
98
+ end
99
+
100
+ # Submits all the data previously pushed to this PayerAuthorisation for
101
+ # verification. This time, a 200 HTTP status is returned if the resource is
102
+ # valid and a 422 error response in case of validation errors. After it is
103
+ # successfully submitted, the Payer Authorisation can no longer be edited.
104
+ # Example URL: /payer_authorisations/:identity/actions/submit
105
+ #
106
+ # @param identity # Unique identifier, beginning with "PA".
107
+ # @param options [Hash] parameters as a hash, under a params key.
108
+ def submit(identity, options = {})
109
+ path = sub_url('/payer_authorisations/:identity/actions/submit', '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::PayerAuthorisation.new(unenvelope_body(response.body), response)
138
+ end
139
+
140
+ # Confirms the Payer Authorisation, indicating that the resources are ready to
141
+ # be created.
142
+ # A Payer Authorisation cannot be confirmed if it hasn't been submitted yet.
143
+ #
144
+ # <p class="notice">
145
+ # The main use of the confirm endpoint is to enable integrators to acknowledge
146
+ # the end of the setup process.
147
+ # They might want to make the payers go through some other steps after they go
148
+ # through our flow or make them go through the necessary verification mechanism
149
+ # (upcoming feature).
150
+ # </p>
151
+ # Example URL: /payer_authorisations/:identity/actions/confirm
152
+ #
153
+ # @param identity # Unique identifier, beginning with "PA".
154
+ # @param options [Hash] parameters as a hash, under a params key.
155
+ def confirm(identity, options = {})
156
+ path = sub_url('/payer_authorisations/:identity/actions/confirm', 'identity' => identity)
157
+
158
+ params = options.delete(:params) || {}
159
+ options[:params] = {}
160
+ options[:params]['data'] = params
161
+
162
+ options[:retry_failures] = false
163
+
164
+ begin
165
+ response = make_request(:post, path, options)
166
+
167
+ # Response doesn't raise any errors until #body is called
168
+ response.tap(&:body)
169
+ rescue InvalidStateError => e
170
+ if e.idempotent_creation_conflict?
171
+ case @api_service.on_idempotency_conflict
172
+ when :raise
173
+ raise IdempotencyConflict, e.error
174
+ when :fetch
175
+ return get(e.conflicting_resource_id)
176
+ end
177
+ end
178
+
179
+ raise e
180
+ end
181
+
182
+ return if response.body.nil?
183
+
184
+ Resources::PayerAuthorisation.new(unenvelope_body(response.body), response)
185
+ end
186
+
187
+ private
188
+
189
+ # Unenvelope the response of the body using the service's `envelope_key`
190
+ #
191
+ # @param body [Hash]
192
+ def unenvelope_body(body)
193
+ body[envelope_key] || body['data']
194
+ end
195
+
196
+ # return the key which API responses will envelope data under
197
+ def envelope_key
198
+ 'payer_authorisations'
199
+ end
200
+ end
201
+ end
202
+ end
@@ -39,8 +39,6 @@ module GoCardlessPro
39
39
  raise IdempotencyConflict, e.error
40
40
  when :fetch
41
41
  return get(e.conflicting_resource_id)
42
- else
43
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
44
42
  end
45
43
  end
46
44
 
@@ -150,8 +148,6 @@ module GoCardlessPro
150
148
  raise IdempotencyConflict, e.error
151
149
  when :fetch
152
150
  return get(e.conflicting_resource_id)
153
- else
154
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
155
151
  end
156
152
  end
157
153
 
@@ -198,8 +194,6 @@ module GoCardlessPro
198
194
  raise IdempotencyConflict, e.error
199
195
  when :fetch
200
196
  return get(e.conflicting_resource_id)
201
- else
202
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
203
197
  end
204
198
  end
205
199
 
@@ -35,8 +35,6 @@ module GoCardlessPro
35
35
  raise IdempotencyConflict, e.error
36
36
  when :fetch
37
37
  return get(e.conflicting_resource_id)
38
- else
39
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
40
38
  end
41
39
  end
42
40
 
@@ -100,8 +98,6 @@ module GoCardlessPro
100
98
  raise IdempotencyConflict, e.error
101
99
  when :fetch
102
100
  return get(e.conflicting_resource_id)
103
- else
104
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
105
101
  end
106
102
  end
107
103
 
@@ -50,8 +50,6 @@ module GoCardlessPro
50
50
  raise IdempotencyConflict, e.error
51
51
  when :fetch
52
52
  return get(e.conflicting_resource_id)
53
- else
54
- raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
55
53
  end
56
54
  end
57
55