gocardless_pro 2.20.0 → 2.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +25 -43
- data/Gemfile +7 -0
- data/gocardless_pro.gemspec +2 -2
- data/lib/gocardless_pro.rb +3 -0
- data/lib/gocardless_pro/api_service.rb +1 -1
- data/lib/gocardless_pro/client.rb +6 -1
- data/lib/gocardless_pro/resources/event.rb +12 -0
- data/lib/gocardless_pro/resources/payout.rb +2 -0
- data/lib/gocardless_pro/resources/payout_item.rb +2 -0
- data/lib/gocardless_pro/resources/tax_rate.rb +51 -0
- data/lib/gocardless_pro/services/bank_details_lookups_service.rb +0 -10
- data/lib/gocardless_pro/services/base_service.rb +11 -0
- data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +0 -10
- data/lib/gocardless_pro/services/creditors_service.rb +0 -10
- data/lib/gocardless_pro/services/currency_exchange_rates_service.rb +0 -10
- data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +0 -10
- data/lib/gocardless_pro/services/customer_notifications_service.rb +0 -10
- data/lib/gocardless_pro/services/customers_service.rb +0 -10
- data/lib/gocardless_pro/services/events_service.rb +0 -10
- data/lib/gocardless_pro/services/instalment_schedules_service.rb +0 -10
- data/lib/gocardless_pro/services/mandate_import_entries_service.rb +0 -10
- data/lib/gocardless_pro/services/mandate_imports_service.rb +0 -10
- data/lib/gocardless_pro/services/mandate_pdfs_service.rb +0 -10
- data/lib/gocardless_pro/services/mandates_service.rb +0 -10
- data/lib/gocardless_pro/services/payments_service.rb +0 -10
- data/lib/gocardless_pro/services/payout_items_service.rb +0 -10
- data/lib/gocardless_pro/services/payouts_service.rb +0 -10
- data/lib/gocardless_pro/services/redirect_flows_service.rb +0 -10
- data/lib/gocardless_pro/services/refunds_service.rb +6 -11
- data/lib/gocardless_pro/services/subscriptions_service.rb +1 -11
- data/lib/gocardless_pro/services/tax_rates_service.rb +74 -0
- data/lib/gocardless_pro/version.rb +1 -1
- data/spec/resources/payout_item_spec.rb +5 -0
- data/spec/resources/payout_spec.rb +8 -0
- data/spec/resources/tax_rate_spec.rb +198 -0
- data/spec/services/creditor_bank_accounts_service_spec.rb +1 -1
- data/spec/services/customer_bank_accounts_service_spec.rb +1 -1
- data/spec/services/customer_notifications_service_spec.rb +1 -1
- data/spec/services/customers_service_spec.rb +1 -1
- data/spec/services/instalment_schedules_service_spec.rb +1 -1
- data/spec/services/mandate_imports_service_spec.rb +2 -2
- data/spec/services/mandates_service_spec.rb +2 -2
- data/spec/services/payments_service_spec.rb +2 -2
- data/spec/services/payout_items_service_spec.rb +9 -0
- data/spec/services/payouts_service_spec.rb +12 -0
- data/spec/services/redirect_flows_service_spec.rb +1 -1
- data/spec/services/subscriptions_service_spec.rb +3 -3
- data/spec/services/tax_rates_service_spec.rb +381 -0
- metadata +13 -7
@@ -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
|
@@ -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
|
#
|
@@ -148,7 +147,7 @@ module GoCardlessPro
|
|
148
147
|
# When `pause_cycles` is omitted the subscription is paused until the [resume
|
149
148
|
# endpoint](#subscriptions-resume-a-subscription) is called.
|
150
149
|
# If the subscription is collecting a fixed number of payments, `end_date` will
|
151
|
-
# be set to `
|
150
|
+
# be set to `null`.
|
152
151
|
# When paused indefinitely, `upcoming_payments` will be empty.
|
153
152
|
#
|
154
153
|
# When `pause_cycles` is provided the subscription will be paused for the number
|
@@ -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
|
@@ -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
|