gocardless_pro 2.19.0 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) 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 +3 -0
  6. data/lib/gocardless_pro/api_service.rb +1 -1
  7. data/lib/gocardless_pro/client.rb +6 -1
  8. data/lib/gocardless_pro/resources/payout.rb +2 -0
  9. data/lib/gocardless_pro/resources/payout_item.rb +2 -0
  10. data/lib/gocardless_pro/resources/tax_rate.rb +48 -0
  11. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +0 -10
  12. data/lib/gocardless_pro/services/base_service.rb +11 -0
  13. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +0 -10
  14. data/lib/gocardless_pro/services/creditors_service.rb +0 -10
  15. data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +0 -10
  16. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +0 -10
  17. data/lib/gocardless_pro/services/customer_notifications_service.rb +0 -10
  18. data/lib/gocardless_pro/services/customers_service.rb +0 -10
  19. data/lib/gocardless_pro/services/events_service.rb +0 -10
  20. data/lib/gocardless_pro/services/instalment_schedules_service.rb +21 -10
  21. data/lib/gocardless_pro/services/mandate_import_entries_service.rb +0 -10
  22. data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -10
  23. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +0 -10
  24. data/lib/gocardless_pro/services/mandates_service.rb +0 -10
  25. data/lib/gocardless_pro/services/payments_service.rb +0 -10
  26. data/lib/gocardless_pro/services/payout_items_service.rb +0 -10
  27. data/lib/gocardless_pro/services/payouts_service.rb +0 -10
  28. data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -10
  29. data/lib/gocardless_pro/services/refunds_service.rb +6 -11
  30. data/lib/gocardless_pro/services/subscriptions_service.rb +0 -10
  31. data/lib/gocardless_pro/services/tax_rates_service.rb +74 -0
  32. data/lib/gocardless_pro/version.rb +1 -1
  33. data/spec/resources/instalment_schedule_spec.rb +35 -0
  34. data/spec/resources/payout_item_spec.rb +5 -0
  35. data/spec/resources/payout_spec.rb +8 -0
  36. data/spec/resources/tax_rate_spec.rb +198 -0
  37. data/spec/services/creditor_bank_accounts_service_spec.rb +1 -1
  38. data/spec/services/customer_bank_accounts_service_spec.rb +1 -1
  39. data/spec/services/customer_notifications_service_spec.rb +1 -1
  40. data/spec/services/customers_service_spec.rb +1 -1
  41. data/spec/services/instalment_schedules_service_spec.rb +61 -1
  42. data/spec/services/mandate_imports_service_spec.rb +2 -2
  43. data/spec/services/mandates_service_spec.rb +2 -2
  44. data/spec/services/payments_service_spec.rb +2 -2
  45. data/spec/services/payout_items_service_spec.rb +9 -0
  46. data/spec/services/payouts_service_spec.rb +12 -0
  47. data/spec/services/redirect_flows_service_spec.rb +1 -1
  48. data/spec/services/subscriptions_service_spec.rb +3 -3
  49. data/spec/services/tax_rates_service_spec.rb +381 -0
  50. metadata +17 -11
@@ -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
@@ -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
  'payments'
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
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -54,15 +53,6 @@ module GoCardlessPro
54
53
  def envelope_key
55
54
  'payout_items'
56
55
  end
57
-
58
- # take a URL with placeholder params and substitute them out for the actual value
59
- # @param url [String] the URL with placeholders in
60
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
61
- def sub_url(url, param_map)
62
- param_map.reduce(url) do |new_url, (param, value)|
63
- new_url.gsub(":#{param}", URI.escape(value))
64
- end
65
- end
66
56
  end
67
57
  end
68
58
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -93,15 +92,6 @@ module GoCardlessPro
93
92
  def envelope_key
94
93
  'payouts'
95
94
  end
96
-
97
- # take a URL with placeholder params and substitute them out for the actual value
98
- # @param url [String] the URL with placeholders in
99
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
100
- def sub_url(url, param_map)
101
- param_map.reduce(url) do |new_url, (param, value)|
102
- new_url.gsub(":#{param}", URI.escape(value))
103
- end
104
- end
105
95
  end
106
96
  end
107
97
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -127,15 +126,6 @@ module GoCardlessPro
127
126
  def envelope_key
128
127
  'redirect_flows'
129
128
  end
130
-
131
- # take a URL with placeholder params and substitute them out for the actual value
132
- # @param url [String] the URL with placeholders in
133
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
134
- def sub_url(url, param_map)
135
- param_map.reduce(url) do |new_url, (param, value)|
136
- new_url.gsub(":#{param}", URI.escape(value))
137
- end
138
- end
139
129
  end
140
130
  end
141
131
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -14,7 +13,8 @@ module GoCardlessPro
14
13
  # Creates a new refund object.
15
14
  #
16
15
  # This fails with:<a name="total_amount_confirmation_invalid"></a><a
17
- # name="number_of_refunds_exceeded"></a>
16
+ # name="number_of_refunds_exceeded"></a><a
17
+ # name="available_refund_amount_insufficient"></a>
18
18
  #
19
19
  # - `total_amount_confirmation_invalid` if the confirmation amount doesn't match
20
20
  # the total amount refunded for the payment. This safeguard is there to prevent
@@ -23,6 +23,10 @@ module GoCardlessPro
23
23
  # - `number_of_refunds_exceeded` if five or more refunds have already been
24
24
  # created against the payment.
25
25
  #
26
+ # - `available_refund_amount_insufficient` if the creditor does not have
27
+ # sufficient balance for refunds available to cover the cost of the requested
28
+ # refund.
29
+ #
26
30
  # Example URL: /refunds
27
31
  # @param options [Hash] parameters as a hash, under a params key.
28
32
  def create(options = {})
@@ -139,15 +143,6 @@ module GoCardlessPro
139
143
  def envelope_key
140
144
  'refunds'
141
145
  end
142
-
143
- # take a URL with placeholder params and substitute them out for the actual value
144
- # @param url [String] the URL with placeholders in
145
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
146
- def sub_url(url, param_map)
147
- param_map.reduce(url) do |new_url, (param, value)|
148
- new_url.gsub(":#{param}", URI.escape(value))
149
- end
150
- end
151
146
  end
152
147
  end
153
148
  end
@@ -1,5 +1,4 @@
1
1
  require_relative './base_service'
2
- require 'uri'
3
2
 
4
3
  # encoding: utf-8
5
4
  #
@@ -324,15 +323,6 @@ module GoCardlessPro
324
323
  def envelope_key
325
324
  'subscriptions'
326
325
  end
327
-
328
- # take a URL with placeholder params and substitute them out for the actual value
329
- # @param url [String] the URL with placeholders in
330
- # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
331
- def sub_url(url, param_map)
332
- param_map.reduce(url) do |new_url, (param, value)|
333
- new_url.gsub(":#{param}", URI.escape(value))
334
- end
335
- end
336
326
  end
337
327
  end
338
328
  end
@@ -0,0 +1,74 @@
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 TaxRate endpoints
12
+ class TaxRatesService < BaseService
13
+ # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of all tax
14
+ # rates.
15
+ # Example URL: /tax_rates
16
+ # @param options [Hash] parameters as a hash, under a params key.
17
+ def list(options = {})
18
+ path = '/tax_rates'
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::TaxRate
28
+ )
29
+ end
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.
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
+ # Retrieves the details of a tax rate.
43
+ # Example URL: /tax_rates/:identity
44
+ #
45
+ # @param identity # The unique identifier created by the jurisdiction, tax type and version
46
+ # @param options [Hash] parameters as a hash, under a params key.
47
+ def get(identity, options = {})
48
+ path = sub_url('/tax_rates/: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::TaxRate.new(unenvelope_body(response.body), response)
57
+ end
58
+
59
+ private
60
+
61
+ # Unenvelope the response of the body using the service's `envelope_key`
62
+ #
63
+ # @param body [Hash]
64
+ def unenvelope_body(body)
65
+ body[envelope_key] || body['data']
66
+ end
67
+
68
+ # return the key which API responses will envelope data under
69
+ def envelope_key
70
+ 'tax_rates'
71
+ end
72
+ end
73
+ end
74
+ end
@@ -4,5 +4,5 @@ end
4
4
 
5
5
  module GoCardlessPro
6
6
  # Current version of the GC gem
7
- VERSION = '2.19.0'.freeze
7
+ VERSION = '2.23.0'.freeze
8
8
  end
@@ -529,6 +529,41 @@ describe GoCardlessPro::Resources::InstalmentSchedule do
529
529
  end
530
530
  end
531
531
 
532
+ describe '#update' do
533
+ subject(:put_update_response) { client.instalment_schedules.update(id, params: update_params) }
534
+ let(:id) { 'ABC123' }
535
+
536
+ context 'with a valid request' do
537
+ let(:update_params) { { 'hello' => 'world' } }
538
+
539
+ let!(:stub) do
540
+ stub_url = '/instalment_schedules/:identity'.gsub(':identity', id)
541
+ stub_request(:put, /.*api.gocardless.com#{stub_url}/).to_return(
542
+ body: {
543
+ 'instalment_schedules' => {
544
+
545
+ 'created_at' => 'created_at-input',
546
+ 'currency' => 'currency-input',
547
+ 'id' => 'id-input',
548
+ 'links' => 'links-input',
549
+ 'metadata' => 'metadata-input',
550
+ 'name' => 'name-input',
551
+ 'payment_errors' => 'payment_errors-input',
552
+ 'status' => 'status-input',
553
+ 'total_amount' => 'total_amount-input',
554
+ },
555
+ }.to_json,
556
+ headers: response_headers
557
+ )
558
+ end
559
+
560
+ it 'updates and returns the resource' do
561
+ expect(put_update_response).to be_a(GoCardlessPro::Resources::InstalmentSchedule)
562
+ expect(stub).to have_been_requested
563
+ end
564
+ end
565
+ end
566
+
532
567
  describe '#cancel' do
533
568
  subject(:post_response) { client.instalment_schedules.cancel(resource_id) }
534
569
 
@@ -20,6 +20,7 @@ describe GoCardlessPro::Resources::PayoutItem do
20
20
 
21
21
  'amount' => 'amount-input',
22
22
  'links' => 'links-input',
23
+ 'taxes' => 'taxes-input',
23
24
  'type' => 'type-input',
24
25
  }],
25
26
  meta: {
@@ -38,6 +39,8 @@ describe GoCardlessPro::Resources::PayoutItem do
38
39
 
39
40
  expect(get_list_response.records.first.amount).to eq('amount-input')
40
41
 
42
+ expect(get_list_response.records.first.taxes).to eq('taxes-input')
43
+
41
44
  expect(get_list_response.records.first.type).to eq('type-input')
42
45
  end
43
46
 
@@ -58,6 +61,7 @@ describe GoCardlessPro::Resources::PayoutItem do
58
61
 
59
62
  'amount' => 'amount-input',
60
63
  'links' => 'links-input',
64
+ 'taxes' => 'taxes-input',
61
65
  'type' => 'type-input',
62
66
  }],
63
67
  meta: {
@@ -76,6 +80,7 @@ describe GoCardlessPro::Resources::PayoutItem do
76
80
 
77
81
  'amount' => 'amount-input',
78
82
  'links' => 'links-input',
83
+ 'taxes' => 'taxes-input',
79
84
  'type' => 'type-input',
80
85
  }],
81
86
  meta: {
@@ -30,6 +30,7 @@ describe GoCardlessPro::Resources::Payout do
30
30
  'payout_type' => 'payout_type-input',
31
31
  'reference' => 'reference-input',
32
32
  'status' => 'status-input',
33
+ 'tax_currency' => 'tax_currency-input',
33
34
  }],
34
35
  meta: {
35
36
  cursors: {
@@ -66,6 +67,8 @@ describe GoCardlessPro::Resources::Payout do
66
67
  expect(get_list_response.records.first.reference).to eq('reference-input')
67
68
 
68
69
  expect(get_list_response.records.first.status).to eq('status-input')
70
+
71
+ expect(get_list_response.records.first.tax_currency).to eq('tax_currency-input')
69
72
  end
70
73
 
71
74
  it 'exposes the cursors for before and after' do
@@ -95,6 +98,7 @@ describe GoCardlessPro::Resources::Payout do
95
98
  'payout_type' => 'payout_type-input',
96
99
  'reference' => 'reference-input',
97
100
  'status' => 'status-input',
101
+ 'tax_currency' => 'tax_currency-input',
98
102
  }],
99
103
  meta: {
100
104
  cursors: { after: 'AB345' },
@@ -122,6 +126,7 @@ describe GoCardlessPro::Resources::Payout do
122
126
  'payout_type' => 'payout_type-input',
123
127
  'reference' => 'reference-input',
124
128
  'status' => 'status-input',
129
+ 'tax_currency' => 'tax_currency-input',
125
130
  }],
126
131
  meta: {
127
132
  limit: 2,
@@ -165,6 +170,7 @@ describe GoCardlessPro::Resources::Payout do
165
170
  'payout_type' => 'payout_type-input',
166
171
  'reference' => 'reference-input',
167
172
  'status' => 'status-input',
173
+ 'tax_currency' => 'tax_currency-input',
168
174
  },
169
175
  }.to_json,
170
176
  headers: response_headers
@@ -202,6 +208,7 @@ describe GoCardlessPro::Resources::Payout do
202
208
  'payout_type' => 'payout_type-input',
203
209
  'reference' => 'reference-input',
204
210
  'status' => 'status-input',
211
+ 'tax_currency' => 'tax_currency-input',
205
212
  },
206
213
  }.to_json,
207
214
  headers: response_headers
@@ -261,6 +268,7 @@ describe GoCardlessPro::Resources::Payout do
261
268
  'payout_type' => 'payout_type-input',
262
269
  'reference' => 'reference-input',
263
270
  'status' => 'status-input',
271
+ 'tax_currency' => 'tax_currency-input',
264
272
  },
265
273
  }.to_json,
266
274
  headers: response_headers