gocardless_pro 2.22.1 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2380802da7e32b788d03eb0ce5965cb79b27f310c7643bf40078880823dcb2f7
4
- data.tar.gz: ad1ebf6cbec94675df50e0b4a0154fb2eea77f659993625c5d8a9bcb8bd9f7df
3
+ metadata.gz: 380e86ab83d0876327222f7966dbae08687e51cec34c468f2f57b9064a6de49b
4
+ data.tar.gz: 92a6001ee0d724bb218d3d4ef6e245389842391b8d251e7b79afe6210432367a
5
5
  SHA512:
6
- metadata.gz: 54622b040fa474ef16f0431e439bef3603d45cdf74c6001bc175fc638057db41231eae81cd9c502e5d16f3a796d6c1e068d27907aeacc1b0bfceb15186bcce0b
7
- data.tar.gz: e89435ce6a6da8761c8b113e93f34fe1c7268e462aeda83fe8183620334c35f939c362efc1027b7bf0e3bef1a0ab9d56bb1eacf09e3ab64fd6596f1cc0055ad1
6
+ metadata.gz: 6241d24b24dcf35224c87bf2c559c3a0c6f543ef4f3e2c73885e8aee1a4cccc9e8fb748d323df5768c9acd01510b0ae78cf8182d2d684a7feb119bd91ad0c5ac
7
+ data.tar.gz: 2981ece7e5ad7cef1056ed51a02dc805c5a4c3d41ec483604e2b0ae2a552ca6cd2d2da1e7a92fa1740c9ce61b55e3fecd27c9138817bcf87a8d830047acdd552
@@ -95,4 +95,7 @@ require_relative 'gocardless_pro/services/refunds_service'
95
95
  require_relative 'gocardless_pro/resources/subscription'
96
96
  require_relative 'gocardless_pro/services/subscriptions_service'
97
97
 
98
+ require_relative 'gocardless_pro/resources/tax_rate'
99
+ require_relative 'gocardless_pro/services/tax_rates_service'
100
+
98
101
  require_relative 'gocardless_pro/client.rb'
@@ -98,6 +98,11 @@ module GoCardlessPro
98
98
  @subscriptions ||= Services::SubscriptionsService.new(@api_service)
99
99
  end
100
100
 
101
+ # Access to the service for tax_rate to make API calls
102
+ def tax_rates
103
+ @tax_rates ||= Services::TaxRatesService.new(@api_service)
104
+ end
105
+
101
106
  # Get a Client configured to use HTTP Basic authentication with the GC Api
102
107
  #
103
108
  # @param options [Hash<Symbol,String>] configuration for creating the client
@@ -148,7 +153,7 @@ module GoCardlessPro
148
153
  'User-Agent' => user_agent.to_s,
149
154
  'Content-Type' => 'application/json',
150
155
  'GoCardless-Client-Library' => 'gocardless-pro-ruby',
151
- 'GoCardless-Client-Version' => '2.22.1',
156
+ 'GoCardless-Client-Version' => '2.23.0',
152
157
  },
153
158
  }
154
159
  end
@@ -30,6 +30,7 @@ module GoCardlessPro
30
30
  attr_reader :payout_type
31
31
  attr_reader :reference
32
32
  attr_reader :status
33
+ attr_reader :tax_currency
33
34
 
34
35
  # Initialize a payout resource instance
35
36
  # @param object [Hash] an object returned from the API
@@ -48,6 +49,7 @@ module GoCardlessPro
48
49
  @payout_type = object['payout_type']
49
50
  @reference = object['reference']
50
51
  @status = object['status']
52
+ @tax_currency = object['tax_currency']
51
53
  @response = response
52
54
  end
53
55
 
@@ -32,6 +32,7 @@ module GoCardlessPro
32
32
  #
33
33
  class PayoutItem
34
34
  attr_reader :amount
35
+ attr_reader :taxes
35
36
  attr_reader :type
36
37
 
37
38
  # Initialize a payout_item resource instance
@@ -41,6 +42,7 @@ module GoCardlessPro
41
42
 
42
43
  @amount = object['amount']
43
44
  @links = object['links']
45
+ @taxes = object['taxes']
44
46
  @type = object['type']
45
47
  @response = response
46
48
  end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ #
4
+ # This client is automatically generated from a template and JSON schema definition.
5
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
6
+ #
7
+
8
+ require 'uri'
9
+
10
+ module GoCardlessPro
11
+ # A module containing classes for each of the resources in the GC Api
12
+ module Resources
13
+ # Represents an instance of a tax_rate resource returned from the API
14
+
15
+ # Tax rates from tax authority.
16
+ class TaxRate
17
+ attr_reader :end_date
18
+ attr_reader :id
19
+ attr_reader :jurisdiction
20
+ attr_reader :percentage
21
+ attr_reader :start_date
22
+ attr_reader :type
23
+
24
+ # Initialize a tax_rate resource instance
25
+ # @param object [Hash] an object returned from the API
26
+ def initialize(object, response = nil)
27
+ @object = object
28
+
29
+ @end_date = object['end_date']
30
+ @id = object['id']
31
+ @jurisdiction = object['jurisdiction']
32
+ @percentage = object['percentage']
33
+ @start_date = object['start_date']
34
+ @type = object['type']
35
+ @response = response
36
+ end
37
+
38
+ def api_response
39
+ ApiResponse.new(@response)
40
+ end
41
+
42
+ # Provides the tax_rate resource as a hash of all its readable attributes
43
+ def to_h
44
+ @object
45
+ end
46
+ end
47
+ end
48
+ 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.22.1'.freeze
7
+ VERSION = '2.23.0'.freeze
8
8
  end
@@ -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
@@ -0,0 +1,198 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::TaxRate do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: 'SECRET_TOKEN'
7
+ )
8
+ end
9
+
10
+ let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
+
12
+ describe '#list' do
13
+ describe 'with no filters' do
14
+ subject(:get_list_response) { client.tax_rates.list }
15
+
16
+ before do
17
+ stub_request(:get, %r{.*api.gocardless.com/tax_rates}).to_return(
18
+ body: {
19
+ 'tax_rates' => [{
20
+
21
+ 'end_date' => 'end_date-input',
22
+ 'id' => 'id-input',
23
+ 'jurisdiction' => 'jurisdiction-input',
24
+ 'percentage' => 'percentage-input',
25
+ 'start_date' => 'start_date-input',
26
+ 'type' => 'type-input',
27
+ }],
28
+ meta: {
29
+ cursors: {
30
+ before: nil,
31
+ after: 'ABC123',
32
+ },
33
+ },
34
+ }.to_json,
35
+ headers: response_headers
36
+ )
37
+ end
38
+
39
+ it 'wraps each item in the resource class' do
40
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::TaxRate)
41
+
42
+ expect(get_list_response.records.first.end_date).to eq('end_date-input')
43
+
44
+ expect(get_list_response.records.first.id).to eq('id-input')
45
+
46
+ expect(get_list_response.records.first.jurisdiction).to eq('jurisdiction-input')
47
+
48
+ expect(get_list_response.records.first.percentage).to eq('percentage-input')
49
+
50
+ expect(get_list_response.records.first.start_date).to eq('start_date-input')
51
+
52
+ expect(get_list_response.records.first.type).to eq('type-input')
53
+ end
54
+
55
+ it 'exposes the cursors for before and after' do
56
+ expect(get_list_response.before).to eq(nil)
57
+ expect(get_list_response.after).to eq('ABC123')
58
+ end
59
+
60
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
61
+ end
62
+ end
63
+
64
+ describe '#all' do
65
+ let!(:first_response_stub) do
66
+ stub_request(:get, %r{.*api.gocardless.com/tax_rates$}).to_return(
67
+ body: {
68
+ 'tax_rates' => [{
69
+
70
+ 'end_date' => 'end_date-input',
71
+ 'id' => 'id-input',
72
+ 'jurisdiction' => 'jurisdiction-input',
73
+ 'percentage' => 'percentage-input',
74
+ 'start_date' => 'start_date-input',
75
+ 'type' => 'type-input',
76
+ }],
77
+ meta: {
78
+ cursors: { after: 'AB345' },
79
+ limit: 1,
80
+ },
81
+ }.to_json,
82
+ headers: response_headers
83
+ )
84
+ end
85
+
86
+ let!(:second_response_stub) do
87
+ stub_request(:get, %r{.*api.gocardless.com/tax_rates\?after=AB345}).to_return(
88
+ body: {
89
+ 'tax_rates' => [{
90
+
91
+ 'end_date' => 'end_date-input',
92
+ 'id' => 'id-input',
93
+ 'jurisdiction' => 'jurisdiction-input',
94
+ 'percentage' => 'percentage-input',
95
+ 'start_date' => 'start_date-input',
96
+ 'type' => 'type-input',
97
+ }],
98
+ meta: {
99
+ limit: 2,
100
+ cursors: {},
101
+ },
102
+ }.to_json,
103
+ headers: response_headers
104
+ )
105
+ end
106
+
107
+ it 'automatically makes the extra requests' do
108
+ expect(client.tax_rates.all.to_a.length).to eq(2)
109
+ expect(first_response_stub).to have_been_requested
110
+ expect(second_response_stub).to have_been_requested
111
+ end
112
+ end
113
+
114
+ describe '#get' do
115
+ let(:id) { 'ID123' }
116
+
117
+ subject(:get_response) { client.tax_rates.get(id) }
118
+
119
+ context 'passing in a custom header' do
120
+ let!(:stub) do
121
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
122
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
123
+ with(headers: { 'Foo' => 'Bar' }).
124
+ to_return(
125
+ body: {
126
+ 'tax_rates' => {
127
+
128
+ 'end_date' => 'end_date-input',
129
+ 'id' => 'id-input',
130
+ 'jurisdiction' => 'jurisdiction-input',
131
+ 'percentage' => 'percentage-input',
132
+ 'start_date' => 'start_date-input',
133
+ 'type' => 'type-input',
134
+ },
135
+ }.to_json,
136
+ headers: response_headers
137
+ )
138
+ end
139
+
140
+ subject(:get_response) do
141
+ client.tax_rates.get(id, headers: {
142
+ 'Foo' => 'Bar',
143
+ })
144
+ end
145
+
146
+ it 'includes the header' do
147
+ get_response
148
+ expect(stub).to have_been_requested
149
+ end
150
+ end
151
+
152
+ context 'when there is a tax_rate to return' do
153
+ before do
154
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
155
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
156
+ body: {
157
+ 'tax_rates' => {
158
+
159
+ 'end_date' => 'end_date-input',
160
+ 'id' => 'id-input',
161
+ 'jurisdiction' => 'jurisdiction-input',
162
+ 'percentage' => 'percentage-input',
163
+ 'start_date' => 'start_date-input',
164
+ 'type' => 'type-input',
165
+ },
166
+ }.to_json,
167
+ headers: response_headers
168
+ )
169
+ end
170
+
171
+ it 'wraps the response in a resource' do
172
+ expect(get_response).to be_a(GoCardlessPro::Resources::TaxRate)
173
+ end
174
+ end
175
+
176
+ context 'when nothing is returned' do
177
+ before do
178
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
179
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
180
+ body: '',
181
+ headers: response_headers
182
+ )
183
+ end
184
+
185
+ it 'returns nil' do
186
+ expect(get_response).to be_nil
187
+ end
188
+ end
189
+
190
+ context "when an ID is specified which can't be included in a valid URI" do
191
+ let(:id) { '`' }
192
+
193
+ it "doesn't raise an error" do
194
+ expect { get_response }.to_not raise_error(/bad URI/)
195
+ end
196
+ end
197
+ end
198
+ end
@@ -19,6 +19,7 @@ describe GoCardlessPro::Services::PayoutItemsService do
19
19
 
20
20
  'amount' => 'amount-input',
21
21
  'links' => 'links-input',
22
+ 'taxes' => 'taxes-input',
22
23
  'type' => 'type-input',
23
24
  }],
24
25
  meta: {
@@ -42,6 +43,8 @@ describe GoCardlessPro::Services::PayoutItemsService do
42
43
 
43
44
  expect(get_list_response.records.first.amount).to eq('amount-input')
44
45
 
46
+ expect(get_list_response.records.first.taxes).to eq('taxes-input')
47
+
45
48
  expect(get_list_response.records.first.type).to eq('type-input')
46
49
  end
47
50
 
@@ -85,6 +88,7 @@ describe GoCardlessPro::Services::PayoutItemsService do
85
88
 
86
89
  'amount' => 'amount-input',
87
90
  'links' => 'links-input',
91
+ 'taxes' => 'taxes-input',
88
92
  'type' => 'type-input',
89
93
  }],
90
94
  meta: {
@@ -103,6 +107,7 @@ describe GoCardlessPro::Services::PayoutItemsService do
103
107
 
104
108
  'amount' => 'amount-input',
105
109
  'links' => 'links-input',
110
+ 'taxes' => 'taxes-input',
106
111
  'type' => 'type-input',
107
112
  }],
108
113
  meta: {
@@ -130,6 +135,7 @@ describe GoCardlessPro::Services::PayoutItemsService do
130
135
 
131
136
  'amount' => 'amount-input',
132
137
  'links' => 'links-input',
138
+ 'taxes' => 'taxes-input',
133
139
  'type' => 'type-input',
134
140
  }],
135
141
  meta: {
@@ -148,6 +154,7 @@ describe GoCardlessPro::Services::PayoutItemsService do
148
154
 
149
155
  'amount' => 'amount-input',
150
156
  'links' => 'links-input',
157
+ 'taxes' => 'taxes-input',
151
158
  'type' => 'type-input',
152
159
  }],
153
160
  meta: {
@@ -171,6 +178,7 @@ describe GoCardlessPro::Services::PayoutItemsService do
171
178
 
172
179
  'amount' => 'amount-input',
173
180
  'links' => 'links-input',
181
+ 'taxes' => 'taxes-input',
174
182
  'type' => 'type-input',
175
183
  }],
176
184
  meta: {
@@ -192,6 +200,7 @@ describe GoCardlessPro::Services::PayoutItemsService do
192
200
 
193
201
  'amount' => 'amount-input',
194
202
  'links' => 'links-input',
203
+ 'taxes' => 'taxes-input',
195
204
  'type' => 'type-input',
196
205
  }],
197
206
  meta: {
@@ -29,6 +29,7 @@ describe GoCardlessPro::Services::PayoutsService do
29
29
  'payout_type' => 'payout_type-input',
30
30
  'reference' => 'reference-input',
31
31
  'status' => 'status-input',
32
+ 'tax_currency' => 'tax_currency-input',
32
33
  }],
33
34
  meta: {
34
35
  cursors: {
@@ -70,6 +71,8 @@ describe GoCardlessPro::Services::PayoutsService do
70
71
  expect(get_list_response.records.first.reference).to eq('reference-input')
71
72
 
72
73
  expect(get_list_response.records.first.status).to eq('status-input')
74
+
75
+ expect(get_list_response.records.first.tax_currency).to eq('tax_currency-input')
73
76
  end
74
77
 
75
78
  it 'exposes the cursors for before and after' do
@@ -122,6 +125,7 @@ describe GoCardlessPro::Services::PayoutsService do
122
125
  'payout_type' => 'payout_type-input',
123
126
  'reference' => 'reference-input',
124
127
  'status' => 'status-input',
128
+ 'tax_currency' => 'tax_currency-input',
125
129
  }],
126
130
  meta: {
127
131
  cursors: { after: 'AB345' },
@@ -149,6 +153,7 @@ describe GoCardlessPro::Services::PayoutsService do
149
153
  'payout_type' => 'payout_type-input',
150
154
  'reference' => 'reference-input',
151
155
  'status' => 'status-input',
156
+ 'tax_currency' => 'tax_currency-input',
152
157
  }],
153
158
  meta: {
154
159
  limit: 2,
@@ -185,6 +190,7 @@ describe GoCardlessPro::Services::PayoutsService do
185
190
  'payout_type' => 'payout_type-input',
186
191
  'reference' => 'reference-input',
187
192
  'status' => 'status-input',
193
+ 'tax_currency' => 'tax_currency-input',
188
194
  }],
189
195
  meta: {
190
196
  cursors: { after: 'AB345' },
@@ -212,6 +218,7 @@ describe GoCardlessPro::Services::PayoutsService do
212
218
  'payout_type' => 'payout_type-input',
213
219
  'reference' => 'reference-input',
214
220
  'status' => 'status-input',
221
+ 'tax_currency' => 'tax_currency-input',
215
222
  }],
216
223
  meta: {
217
224
  limit: 2,
@@ -244,6 +251,7 @@ describe GoCardlessPro::Services::PayoutsService do
244
251
  'payout_type' => 'payout_type-input',
245
252
  'reference' => 'reference-input',
246
253
  'status' => 'status-input',
254
+ 'tax_currency' => 'tax_currency-input',
247
255
  }],
248
256
  meta: {
249
257
  cursors: { after: 'AB345' },
@@ -274,6 +282,7 @@ describe GoCardlessPro::Services::PayoutsService do
274
282
  'payout_type' => 'payout_type-input',
275
283
  'reference' => 'reference-input',
276
284
  'status' => 'status-input',
285
+ 'tax_currency' => 'tax_currency-input',
277
286
  }],
278
287
  meta: {
279
288
  limit: 2,
@@ -317,6 +326,7 @@ describe GoCardlessPro::Services::PayoutsService do
317
326
  'payout_type' => 'payout_type-input',
318
327
  'reference' => 'reference-input',
319
328
  'status' => 'status-input',
329
+ 'tax_currency' => 'tax_currency-input',
320
330
  },
321
331
  }.to_json,
322
332
  headers: response_headers
@@ -354,6 +364,7 @@ describe GoCardlessPro::Services::PayoutsService do
354
364
  'payout_type' => 'payout_type-input',
355
365
  'reference' => 'reference-input',
356
366
  'status' => 'status-input',
367
+ 'tax_currency' => 'tax_currency-input',
357
368
  },
358
369
  }.to_json,
359
370
  headers: response_headers
@@ -468,6 +479,7 @@ describe GoCardlessPro::Services::PayoutsService do
468
479
  'payout_type' => 'payout_type-input',
469
480
  'reference' => 'reference-input',
470
481
  'status' => 'status-input',
482
+ 'tax_currency' => 'tax_currency-input',
471
483
  },
472
484
  }.to_json,
473
485
  headers: response_headers
@@ -0,0 +1,381 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Services::TaxRatesService do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: 'SECRET_TOKEN'
7
+ )
8
+ end
9
+
10
+ let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
+
12
+ describe '#list' do
13
+ describe 'with no filters' do
14
+ subject(:get_list_response) { client.tax_rates.list }
15
+
16
+ let(:body) do
17
+ {
18
+ 'tax_rates' => [{
19
+
20
+ 'end_date' => 'end_date-input',
21
+ 'id' => 'id-input',
22
+ 'jurisdiction' => 'jurisdiction-input',
23
+ 'percentage' => 'percentage-input',
24
+ 'start_date' => 'start_date-input',
25
+ 'type' => 'type-input',
26
+ }],
27
+ meta: {
28
+ cursors: {
29
+ before: nil,
30
+ after: 'ABC123',
31
+ },
32
+ },
33
+ }.to_json
34
+ end
35
+
36
+ before do
37
+ stub_request(:get, %r{.*api.gocardless.com/tax_rates}).to_return(
38
+ body: body,
39
+ headers: response_headers
40
+ )
41
+ end
42
+
43
+ it 'wraps each item in the resource class' do
44
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::TaxRate)
45
+
46
+ expect(get_list_response.records.first.end_date).to eq('end_date-input')
47
+
48
+ expect(get_list_response.records.first.id).to eq('id-input')
49
+
50
+ expect(get_list_response.records.first.jurisdiction).to eq('jurisdiction-input')
51
+
52
+ expect(get_list_response.records.first.percentage).to eq('percentage-input')
53
+
54
+ expect(get_list_response.records.first.start_date).to eq('start_date-input')
55
+
56
+ expect(get_list_response.records.first.type).to eq('type-input')
57
+ end
58
+
59
+ it 'exposes the cursors for before and after' do
60
+ expect(get_list_response.before).to eq(nil)
61
+ expect(get_list_response.after).to eq('ABC123')
62
+ end
63
+
64
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
65
+
66
+ describe 'retry behaviour' do
67
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
68
+
69
+ it 'retries timeouts' do
70
+ stub = stub_request(:get, %r{.*api.gocardless.com/tax_rates}).
71
+ to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
72
+
73
+ get_list_response
74
+ expect(stub).to have_been_requested.twice
75
+ end
76
+
77
+ it 'retries 5XX errors' do
78
+ stub = stub_request(:get, %r{.*api.gocardless.com/tax_rates}).
79
+ to_return(status: 502,
80
+ headers: { 'Content-Type' => 'text/html' },
81
+ body: '<html><body>Response from Cloudflare</body></html>').
82
+ then.to_return(status: 200, headers: response_headers, body: body)
83
+
84
+ get_list_response
85
+ expect(stub).to have_been_requested.twice
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '#all' do
92
+ let!(:first_response_stub) do
93
+ stub_request(:get, %r{.*api.gocardless.com/tax_rates$}).to_return(
94
+ body: {
95
+ 'tax_rates' => [{
96
+
97
+ 'end_date' => 'end_date-input',
98
+ 'id' => 'id-input',
99
+ 'jurisdiction' => 'jurisdiction-input',
100
+ 'percentage' => 'percentage-input',
101
+ 'start_date' => 'start_date-input',
102
+ 'type' => 'type-input',
103
+ }],
104
+ meta: {
105
+ cursors: { after: 'AB345' },
106
+ limit: 1,
107
+ },
108
+ }.to_json,
109
+ headers: response_headers
110
+ )
111
+ end
112
+
113
+ let!(:second_response_stub) do
114
+ stub_request(:get, %r{.*api.gocardless.com/tax_rates\?after=AB345}).to_return(
115
+ body: {
116
+ 'tax_rates' => [{
117
+
118
+ 'end_date' => 'end_date-input',
119
+ 'id' => 'id-input',
120
+ 'jurisdiction' => 'jurisdiction-input',
121
+ 'percentage' => 'percentage-input',
122
+ 'start_date' => 'start_date-input',
123
+ 'type' => 'type-input',
124
+ }],
125
+ meta: {
126
+ limit: 2,
127
+ cursors: {},
128
+ },
129
+ }.to_json,
130
+ headers: response_headers
131
+ )
132
+ end
133
+
134
+ it 'automatically makes the extra requests' do
135
+ expect(client.tax_rates.all.to_a.length).to eq(2)
136
+ expect(first_response_stub).to have_been_requested
137
+ expect(second_response_stub).to have_been_requested
138
+ end
139
+
140
+ describe 'retry behaviour' do
141
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
142
+
143
+ it 'retries timeouts' do
144
+ first_response_stub = stub_request(:get, %r{.*api.gocardless.com/tax_rates$}).to_return(
145
+ body: {
146
+ 'tax_rates' => [{
147
+
148
+ 'end_date' => 'end_date-input',
149
+ 'id' => 'id-input',
150
+ 'jurisdiction' => 'jurisdiction-input',
151
+ 'percentage' => 'percentage-input',
152
+ 'start_date' => 'start_date-input',
153
+ 'type' => 'type-input',
154
+ }],
155
+ meta: {
156
+ cursors: { after: 'AB345' },
157
+ limit: 1,
158
+ },
159
+ }.to_json,
160
+ headers: response_headers
161
+ )
162
+
163
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/tax_rates\?after=AB345}).
164
+ to_timeout.then.
165
+ to_return(
166
+ body: {
167
+ 'tax_rates' => [{
168
+
169
+ 'end_date' => 'end_date-input',
170
+ 'id' => 'id-input',
171
+ 'jurisdiction' => 'jurisdiction-input',
172
+ 'percentage' => 'percentage-input',
173
+ 'start_date' => 'start_date-input',
174
+ 'type' => 'type-input',
175
+ }],
176
+ meta: {
177
+ limit: 2,
178
+ cursors: {},
179
+ },
180
+ }.to_json,
181
+ headers: response_headers
182
+ )
183
+
184
+ client.tax_rates.all.to_a
185
+
186
+ expect(first_response_stub).to have_been_requested
187
+ expect(second_response_stub).to have_been_requested.twice
188
+ end
189
+
190
+ it 'retries 5XX errors' do
191
+ first_response_stub = stub_request(:get, %r{.*api.gocardless.com/tax_rates$}).to_return(
192
+ body: {
193
+ 'tax_rates' => [{
194
+
195
+ 'end_date' => 'end_date-input',
196
+ 'id' => 'id-input',
197
+ 'jurisdiction' => 'jurisdiction-input',
198
+ 'percentage' => 'percentage-input',
199
+ 'start_date' => 'start_date-input',
200
+ 'type' => 'type-input',
201
+ }],
202
+ meta: {
203
+ cursors: { after: 'AB345' },
204
+ limit: 1,
205
+ },
206
+ }.to_json,
207
+ headers: response_headers
208
+ )
209
+
210
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/tax_rates\?after=AB345}).
211
+ to_return(
212
+ status: 502,
213
+ body: '<html><body>Response from Cloudflare</body></html>',
214
+ headers: { 'Content-Type' => 'text/html' }
215
+ ).then.to_return(
216
+ body: {
217
+ 'tax_rates' => [{
218
+
219
+ 'end_date' => 'end_date-input',
220
+ 'id' => 'id-input',
221
+ 'jurisdiction' => 'jurisdiction-input',
222
+ 'percentage' => 'percentage-input',
223
+ 'start_date' => 'start_date-input',
224
+ 'type' => 'type-input',
225
+ }],
226
+ meta: {
227
+ limit: 2,
228
+ cursors: {},
229
+ },
230
+ }.to_json,
231
+ headers: response_headers
232
+ )
233
+
234
+ client.tax_rates.all.to_a
235
+
236
+ expect(first_response_stub).to have_been_requested
237
+ expect(second_response_stub).to have_been_requested.twice
238
+ end
239
+ end
240
+ end
241
+
242
+ describe '#get' do
243
+ let(:id) { 'ID123' }
244
+
245
+ subject(:get_response) { client.tax_rates.get(id) }
246
+
247
+ context 'passing in a custom header' do
248
+ let!(:stub) do
249
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
250
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).
251
+ with(headers: { 'Foo' => 'Bar' }).
252
+ to_return(
253
+ body: {
254
+ 'tax_rates' => {
255
+
256
+ 'end_date' => 'end_date-input',
257
+ 'id' => 'id-input',
258
+ 'jurisdiction' => 'jurisdiction-input',
259
+ 'percentage' => 'percentage-input',
260
+ 'start_date' => 'start_date-input',
261
+ 'type' => 'type-input',
262
+ },
263
+ }.to_json,
264
+ headers: response_headers
265
+ )
266
+ end
267
+
268
+ subject(:get_response) do
269
+ client.tax_rates.get(id, headers: {
270
+ 'Foo' => 'Bar',
271
+ })
272
+ end
273
+
274
+ it 'includes the header' do
275
+ get_response
276
+ expect(stub).to have_been_requested
277
+ end
278
+ end
279
+
280
+ context 'when there is a tax_rate to return' do
281
+ before do
282
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
283
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
284
+ body: {
285
+ 'tax_rates' => {
286
+
287
+ 'end_date' => 'end_date-input',
288
+ 'id' => 'id-input',
289
+ 'jurisdiction' => 'jurisdiction-input',
290
+ 'percentage' => 'percentage-input',
291
+ 'start_date' => 'start_date-input',
292
+ 'type' => 'type-input',
293
+ },
294
+ }.to_json,
295
+ headers: response_headers
296
+ )
297
+ end
298
+
299
+ it 'wraps the response in a resource' do
300
+ expect(get_response).to be_a(GoCardlessPro::Resources::TaxRate)
301
+ end
302
+ end
303
+
304
+ context 'when nothing is returned' do
305
+ before do
306
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
307
+ stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
308
+ body: '',
309
+ headers: response_headers
310
+ )
311
+ end
312
+
313
+ it 'returns nil' do
314
+ expect(get_response).to be_nil
315
+ end
316
+ end
317
+
318
+ context "when an ID is specified which can't be included in a valid URI" do
319
+ let(:id) { '`' }
320
+
321
+ it "doesn't raise an error" do
322
+ expect { get_response }.to_not raise_error(/bad URI/)
323
+ end
324
+ end
325
+
326
+ describe 'retry behaviour' do
327
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
328
+
329
+ it 'retries timeouts' do
330
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
331
+
332
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
333
+ to_timeout.then.to_return(status: 200, headers: response_headers)
334
+
335
+ get_response
336
+ expect(stub).to have_been_requested.twice
337
+ end
338
+
339
+ it 'retries 5XX errors, other than 500s' do
340
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
341
+
342
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
343
+ to_return(status: 502,
344
+ headers: { 'Content-Type' => 'text/html' },
345
+ body: '<html><body>Response from Cloudflare</body></html>').
346
+ then.to_return(status: 200, headers: response_headers)
347
+
348
+ get_response
349
+ expect(stub).to have_been_requested.twice
350
+ end
351
+
352
+ it 'retries 500 errors returned by the API' do
353
+ stub_url = '/tax_rates/:identity'.gsub(':identity', id)
354
+
355
+ gocardless_error = {
356
+ 'error' => {
357
+ 'message' => 'Internal server error',
358
+ 'documentation_url' => 'https://developer.gocardless.com/#gocardless',
359
+ 'errors' => [{
360
+ 'message' => 'Internal server error',
361
+ 'reason' => 'internal_server_error',
362
+ }],
363
+ 'type' => 'gocardless',
364
+ 'code' => 500,
365
+ 'request_id' => 'dummy_request_id',
366
+ 'id' => 'dummy_exception_id',
367
+ },
368
+ }
369
+
370
+ stub = stub_request(:get, /.*api.gocardless.com#{stub_url}/).
371
+ to_return(status: 500,
372
+ headers: response_headers,
373
+ body: gocardless_error.to_json).
374
+ then.to_return(status: 200, headers: response_headers)
375
+
376
+ get_response
377
+ expect(stub).to have_been_requested.twice
378
+ end
379
+ end
380
+ end
381
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gocardless_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.22.1
4
+ version: 2.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-15 00:00:00.000000000 Z
11
+ date: 2020-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -128,7 +128,7 @@ dependencies:
128
128
  - - "<"
129
129
  - !ruby/object:Gem::Version
130
130
  version: '13'
131
- description:
131
+ description:
132
132
  email:
133
133
  - engineering@gocardless.com
134
134
  executables: []
@@ -178,6 +178,7 @@ files:
178
178
  - lib/gocardless_pro/resources/redirect_flow.rb
179
179
  - lib/gocardless_pro/resources/refund.rb
180
180
  - lib/gocardless_pro/resources/subscription.rb
181
+ - lib/gocardless_pro/resources/tax_rate.rb
181
182
  - lib/gocardless_pro/response.rb
182
183
  - lib/gocardless_pro/services/bank_details_lookups_service.rb
183
184
  - lib/gocardless_pro/services/base_service.rb
@@ -199,6 +200,7 @@ files:
199
200
  - lib/gocardless_pro/services/redirect_flows_service.rb
200
201
  - lib/gocardless_pro/services/refunds_service.rb
201
202
  - lib/gocardless_pro/services/subscriptions_service.rb
203
+ - lib/gocardless_pro/services/tax_rates_service.rb
202
204
  - lib/gocardless_pro/version.rb
203
205
  - lib/gocardless_pro/webhook.rb
204
206
  - spec/api_response_spec.rb
@@ -225,6 +227,7 @@ files:
225
227
  - spec/resources/redirect_flow_spec.rb
226
228
  - spec/resources/refund_spec.rb
227
229
  - spec/resources/subscription_spec.rb
230
+ - spec/resources/tax_rate_spec.rb
228
231
  - spec/response_spec.rb
229
232
  - spec/services/bank_details_lookups_service_spec.rb
230
233
  - spec/services/creditor_bank_accounts_service_spec.rb
@@ -245,13 +248,14 @@ files:
245
248
  - spec/services/redirect_flows_service_spec.rb
246
249
  - spec/services/refunds_service_spec.rb
247
250
  - spec/services/subscriptions_service_spec.rb
251
+ - spec/services/tax_rates_service_spec.rb
248
252
  - spec/spec_helper.rb
249
253
  - spec/webhook_spec.rb
250
254
  homepage: https://github.com/gocardless/gocardless-pro-ruby
251
255
  licenses:
252
256
  - MIT
253
257
  metadata: {}
254
- post_install_message:
258
+ post_install_message:
255
259
  rdoc_options: []
256
260
  require_paths:
257
261
  - lib
@@ -266,8 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
270
  - !ruby/object:Gem::Version
267
271
  version: '0'
268
272
  requirements: []
269
- rubygems_version: 3.0.8
270
- signing_key:
273
+ rubygems_version: 3.1.2
274
+ signing_key:
271
275
  specification_version: 4
272
276
  summary: A gem for calling the GoCardless Pro API
273
277
  test_files:
@@ -295,6 +299,7 @@ test_files:
295
299
  - spec/resources/redirect_flow_spec.rb
296
300
  - spec/resources/refund_spec.rb
297
301
  - spec/resources/subscription_spec.rb
302
+ - spec/resources/tax_rate_spec.rb
298
303
  - spec/response_spec.rb
299
304
  - spec/services/bank_details_lookups_service_spec.rb
300
305
  - spec/services/creditor_bank_accounts_service_spec.rb
@@ -315,5 +320,6 @@ test_files:
315
320
  - spec/services/redirect_flows_service_spec.rb
316
321
  - spec/services/refunds_service_spec.rb
317
322
  - spec/services/subscriptions_service_spec.rb
323
+ - spec/services/tax_rates_service_spec.rb
318
324
  - spec/spec_helper.rb
319
325
  - spec/webhook_spec.rb