gocardless_pro 2.21.0 → 2.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +25 -43
  3. data/Gemfile +7 -0
  4. data/gocardless_pro.gemspec +2 -2
  5. data/lib/gocardless_pro.rb +6 -0
  6. data/lib/gocardless_pro/api_service.rb +1 -1
  7. data/lib/gocardless_pro/client.rb +11 -1
  8. data/lib/gocardless_pro/resources/event.rb +12 -0
  9. data/lib/gocardless_pro/resources/payer_authorisation.rb +119 -0
  10. data/lib/gocardless_pro/resources/payout.rb +2 -0
  11. data/lib/gocardless_pro/resources/payout_item.rb +6 -0
  12. data/lib/gocardless_pro/resources/tax_rate.rb +51 -0
  13. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +0 -10
  14. data/lib/gocardless_pro/services/base_service.rb +11 -0
  15. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +0 -10
  16. data/lib/gocardless_pro/services/creditors_service.rb +0 -10
  17. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +0 -10
  18. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +0 -10
  19. data/lib/gocardless_pro/services/customer_notifications_service.rb +0 -10
  20. data/lib/gocardless_pro/services/customers_service.rb +0 -10
  21. data/lib/gocardless_pro/services/events_service.rb +0 -10
  22. data/lib/gocardless_pro/services/instalment_schedules_service.rb +0 -10
  23. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +0 -10
  24. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -10
  25. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +0 -10
  26. data/lib/gocardless_pro/services/mandates_service.rb +0 -10
  27. data/lib/gocardless_pro/services/payer_authorisations_service.rb +208 -0
  28. data/lib/gocardless_pro/services/payments_service.rb +0 -10
  29. data/lib/gocardless_pro/services/payout_items_service.rb +0 -10
  30. data/lib/gocardless_pro/services/payouts_service.rb +0 -10
  31. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -10
  32. data/lib/gocardless_pro/services/refunds_service.rb +6 -11
  33. data/lib/gocardless_pro/services/subscriptions_service.rb +1 -11
  34. data/lib/gocardless_pro/services/tax_rates_service.rb +74 -0
  35. data/lib/gocardless_pro/version.rb +1 -1
  36. data/spec/resources/payer_authorisation_spec.rb +418 -0
  37. data/spec/resources/payout_item_spec.rb +5 -0
  38. data/spec/resources/payout_spec.rb +8 -0
  39. data/spec/resources/tax_rate_spec.rb +198 -0
  40. data/spec/services/creditor_bank_accounts_service_spec.rb +1 -1
  41. data/spec/services/customer_bank_accounts_service_spec.rb +1 -1
  42. data/spec/services/customer_notifications_service_spec.rb +1 -1
  43. data/spec/services/customers_service_spec.rb +1 -1
  44. data/spec/services/instalment_schedules_service_spec.rb +1 -1
  45. data/spec/services/mandate_imports_service_spec.rb +2 -2
  46. data/spec/services/mandates_service_spec.rb +2 -2
  47. data/spec/services/payer_authorisations_service_spec.rb +572 -0
  48. data/spec/services/payments_service_spec.rb +2 -2
  49. data/spec/services/payout_items_service_spec.rb +9 -0
  50. data/spec/services/payouts_service_spec.rb +12 -0
  51. data/spec/services/redirect_flows_service_spec.rb +1 -1
  52. data/spec/services/subscriptions_service_spec.rb +3 -3
  53. data/spec/services/tax_rates_service_spec.rb +381 -0
  54. metadata +19 -7
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -153,15 +152,6 @@ module GoCardlessPro
153
152
  def envelope_key
154
153
  'creditor_bank_accounts'
155
154
  end
156
-
157
- # take a URL with placeholder params and substitute them out for the actual value
158
- # @param url [String] the URL with placeholders in
159
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
160
- def sub_url(url, param_map)
161
- param_map.reduce(url) do |new_url, (param, value)|
162
- new_url.gsub(":#{param}", URI.escape(value))
163
- end
164
- end
165
155
  end
166
156
  end
167
157
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -129,15 +128,6 @@ module GoCardlessPro
129
128
  def envelope_key
130
129
  'creditors'
131
130
  end
132
-
133
- # take a URL with placeholder params and substitute them out for the actual value
134
- # @param url [String] the URL with placeholders in
135
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
136
- def sub_url(url, param_map)
137
- param_map.reduce(url) do |new_url, (param, value)|
138
- new_url.gsub(":#{param}", URI.escape(value))
139
- end
140
- end
141
131
  end
142
132
  end
143
133
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -53,15 +52,6 @@ module GoCardlessPro
53
52
  def envelope_key
54
53
  'currency_exchange_rates'
55
54
  end
56
-
57
- # take a URL with placeholder params and substitute them out for the actual value
58
- # @param url [String] the URL with placeholders in
59
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
60
- def sub_url(url, param_map)
61
- param_map.reduce(url) do |new_url, (param, value)|
62
- new_url.gsub(":#{param}", URI.escape(value))
63
- end
64
- end
65
55
  end
66
56
  end
67
57
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -186,15 +185,6 @@ module GoCardlessPro
186
185
  def envelope_key
187
186
  'customer_bank_accounts'
188
187
  end
189
-
190
- # take a URL with placeholder params and substitute them out for the actual value
191
- # @param url [String] the URL with placeholders in
192
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
193
- def sub_url(url, param_map)
194
- param_map.reduce(url) do |new_url, (param, value)|
195
- new_url.gsub(":#{param}", URI.escape(value))
196
- end
197
- end
198
188
  end
199
189
  end
200
190
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -52,15 +51,6 @@ module GoCardlessPro
52
51
  def envelope_key
53
52
  'customer_notifications'
54
53
  end
55
-
56
- # take a URL with placeholder params and substitute them out for the actual value
57
- # @param url [String] the URL with placeholders in
58
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
59
- def sub_url(url, param_map)
60
- param_map.reduce(url) do |new_url, (param, value)|
61
- new_url.gsub(":#{param}", URI.escape(value))
62
- end
63
- end
64
54
  end
65
55
  end
66
56
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -153,15 +152,6 @@ module GoCardlessPro
153
152
  def envelope_key
154
153
  'customers'
155
154
  end
156
-
157
- # take a URL with placeholder params and substitute them out for the actual value
158
- # @param url [String] the URL with placeholders in
159
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
160
- def sub_url(url, param_map)
161
- param_map.reduce(url) do |new_url, (param, value)|
162
- new_url.gsub(":#{param}", URI.escape(value))
163
- end
164
- end
165
155
  end
166
156
  end
167
157
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -70,15 +69,6 @@ module GoCardlessPro
70
69
  def envelope_key
71
70
  'events'
72
71
  end
73
-
74
- # take a URL with placeholder params and substitute them out for the actual value
75
- # @param url [String] the URL with placeholders in
76
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
77
- def sub_url(url, param_map)
78
- param_map.reduce(url) do |new_url, (param, value)|
79
- new_url.gsub(":#{param}", URI.escape(value))
80
- end
81
- end
82
72
  end
83
73
  end
84
74
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -239,15 +238,6 @@ module GoCardlessPro
239
238
  def envelope_key
240
239
  'instalment_schedules'
241
240
  end
242
-
243
- # take a URL with placeholder params and substitute them out for the actual value
244
- # @param url [String] the URL with placeholders in
245
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
246
- def sub_url(url, param_map)
247
- param_map.reduce(url) do |new_url, (param, value)|
248
- new_url.gsub(":#{param}", URI.escape(value))
249
- end
250
- end
251
241
  end
252
242
  end
253
243
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -85,15 +84,6 @@ module GoCardlessPro
85
84
  def envelope_key
86
85
  'mandate_import_entries'
87
86
  end
88
-
89
- # take a URL with placeholder params and substitute them out for the actual value
90
- # @param url [String] the URL with placeholders in
91
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
92
- def sub_url(url, param_map)
93
- param_map.reduce(url) do |new_url, (param, value)|
94
- new_url.gsub(":#{param}", URI.escape(value))
95
- end
96
- end
97
87
  end
98
88
  end
99
89
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -176,15 +175,6 @@ module GoCardlessPro
176
175
  def envelope_key
177
176
  'mandate_imports'
178
177
  end
179
-
180
- # take a URL with placeholder params and substitute them out for the actual value
181
- # @param url [String] the URL with placeholders in
182
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
183
- def sub_url(url, param_map)
184
- param_map.reduce(url) do |new_url, (param, value)|
185
- new_url.gsub(":#{param}", URI.escape(value))
186
- end
187
- end
188
178
  end
189
179
  end
190
180
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -85,15 +84,6 @@ module GoCardlessPro
85
84
  def envelope_key
86
85
  'mandate_pdfs'
87
86
  end
88
-
89
- # take a URL with placeholder params and substitute them out for the actual value
90
- # @param url [String] the URL with placeholders in
91
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
92
- def sub_url(url, param_map)
93
- param_map.reduce(url) do |new_url, (param, value)|
94
- new_url.gsub(":#{param}", URI.escape(value))
95
- end
96
- end
97
87
  end
98
88
  end
99
89
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -225,15 +224,6 @@ module GoCardlessPro
225
224
  def envelope_key
226
225
  'mandates'
227
226
  end
228
-
229
- # take a URL with placeholder params and substitute them out for the actual value
230
- # @param url [String] the URL with placeholders in
231
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
232
- def sub_url(url, param_map)
233
- param_map.reduce(url) do |new_url, (param, value)|
234
- new_url.gsub(":#{param}", URI.escape(value))
235
- end
236
- end
237
227
  end
238
228
  end
239
229
  end
@@ -0,0 +1,208 @@
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
+ else
61
+ raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
62
+ end
63
+ end
64
+
65
+ raise e
66
+ end
67
+
68
+ return if response.body.nil?
69
+
70
+ Resources::PayerAuthorisation.new(unenvelope_body(response.body), response)
71
+ end
72
+
73
+ # Updates a Payer Authorisation. Updates the Payer Authorisation with the
74
+ # request data.Can be invoked as many times as needed. Only fields present in
75
+ # the request will be modified. An empty array of incomplete_fields means that
76
+ # the resource is valid. This endpoint has been designed this way so you do not
77
+ # need to save any payer data on your servers or the browser while still being
78
+ # able to implement a progressive solution, such a multi-step form. <p
79
+ # class="notice"> Note that in order to update the `metadata` attribute values
80
+ # it must be sent completely as it overrides the previously existing values.
81
+ # </p>
82
+ # Example URL: /payer_authorisations/:identity
83
+ #
84
+ # @param identity # Unique identifier, beginning with "PA".
85
+ # @param options [Hash] parameters as a hash, under a params key.
86
+ def update(identity, options = {})
87
+ path = sub_url('/payer_authorisations/:identity', 'identity' => identity)
88
+
89
+ params = options.delete(:params) || {}
90
+ options[:params] = {}
91
+ options[:params][envelope_key] = params
92
+
93
+ options[:retry_failures] = true
94
+
95
+ response = make_request(:put, path, options)
96
+
97
+ return if response.body.nil?
98
+
99
+ Resources::PayerAuthorisation.new(unenvelope_body(response.body), response)
100
+ end
101
+
102
+ # Submits all the data previously pushed to this PayerAuthorisation for
103
+ # verification.This time, a 200 HTTP status is returned if the resource is valid
104
+ # and a 422 error response in case of validation errors. After it is
105
+ # successfully submitted, the Payer Authorisation can no longer be edited.
106
+ # Example URL: /payer_authorisations/:identity/actions/submit
107
+ #
108
+ # @param identity # Unique identifier, beginning with "PA".
109
+ # @param options [Hash] parameters as a hash, under a params key.
110
+ def submit(identity, options = {})
111
+ path = sub_url('/payer_authorisations/:identity/actions/submit', 'identity' => identity)
112
+
113
+ params = options.delete(:params) || {}
114
+ options[:params] = {}
115
+ options[:params]['data'] = params
116
+
117
+ options[:retry_failures] = false
118
+
119
+ begin
120
+ response = make_request(:post, path, options)
121
+
122
+ # Response doesn't raise any errors until #body is called
123
+ response.tap(&:body)
124
+ rescue InvalidStateError => e
125
+ if e.idempotent_creation_conflict?
126
+ case @api_service.on_idempotency_conflict
127
+ when :raise
128
+ raise IdempotencyConflict, e.error
129
+ when :fetch
130
+ return get(e.conflicting_resource_id)
131
+ else
132
+ raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
133
+ end
134
+ end
135
+
136
+ raise e
137
+ end
138
+
139
+ return if response.body.nil?
140
+
141
+ Resources::PayerAuthorisation.new(unenvelope_body(response.body), response)
142
+ end
143
+
144
+ # Confirms the Payer Authorisation, indicating that the resources are ready to
145
+ # be created.
146
+ # A Payer Authorisation cannot be confirmed if it hasn't been submitted yet.
147
+ #
148
+ # <p class="notice">
149
+ # The main use of the confirm endpoint is to enable integrators to acknowledge
150
+ # the end of the setup process.
151
+ # They might want to make the payers go through some other steps after they go
152
+ # through our flow or make them go through the necessary verification
153
+ # mechanism(upcomming feature).
154
+ # </p>
155
+ # Example URL: /payer_authorisations/:identity/actions/confirm
156
+ #
157
+ # @param identity # Unique identifier, beginning with "PA".
158
+ # @param options [Hash] parameters as a hash, under a params key.
159
+ def confirm(identity, options = {})
160
+ path = sub_url('/payer_authorisations/:identity/actions/confirm', 'identity' => identity)
161
+
162
+ params = options.delete(:params) || {}
163
+ options[:params] = {}
164
+ options[:params]['data'] = params
165
+
166
+ options[:retry_failures] = false
167
+
168
+ begin
169
+ response = make_request(:post, path, options)
170
+
171
+ # Response doesn't raise any errors until #body is called
172
+ response.tap(&:body)
173
+ rescue InvalidStateError => e
174
+ if e.idempotent_creation_conflict?
175
+ case @api_service.on_idempotency_conflict
176
+ when :raise
177
+ raise IdempotencyConflict, e.error
178
+ when :fetch
179
+ return get(e.conflicting_resource_id)
180
+ else
181
+ raise ArgumentError, 'Unknown mode for :on_idempotency_conflict'
182
+ end
183
+ end
184
+
185
+ raise e
186
+ end
187
+
188
+ return if response.body.nil?
189
+
190
+ Resources::PayerAuthorisation.new(unenvelope_body(response.body), response)
191
+ end
192
+
193
+ private
194
+
195
+ # Unenvelope the response of the body using the service's `envelope_key`
196
+ #
197
+ # @param body [Hash]
198
+ def unenvelope_body(body)
199
+ body[envelope_key] || body['data']
200
+ end
201
+
202
+ # return the key which API responses will envelope data under
203
+ def envelope_key
204
+ 'payer_authorisations'
205
+ end
206
+ end
207
+ end
208
+ end