suretax 0.2.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +4 -0
  3. data/.rubocop.yml +111 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +9 -9
  6. data/lib/suretax.rb +0 -1
  7. data/lib/suretax/api.rb +7 -7
  8. data/lib/suretax/api/cancel_request.rb +7 -7
  9. data/lib/suretax/api/group.rb +5 -6
  10. data/lib/suretax/api/item_message.rb +3 -3
  11. data/lib/suretax/api/request.rb +37 -37
  12. data/lib/suretax/api/request_item.rb +13 -17
  13. data/lib/suretax/api/response.rb +18 -19
  14. data/lib/suretax/api/tax.rb +11 -12
  15. data/lib/suretax/api/tax_amount.rb +3 -4
  16. data/lib/suretax/concerns.rb +1 -3
  17. data/lib/suretax/concerns/validatable.rb +21 -27
  18. data/lib/suretax/configuration.rb +17 -20
  19. data/lib/suretax/connection.rb +3 -5
  20. data/lib/suretax/constants/regulatory_codes.rb +8 -8
  21. data/lib/suretax/constants/response_groups.rb +6 -6
  22. data/lib/suretax/constants/sales_type_codes.rb +5 -5
  23. data/lib/suretax/constants/tax_situs_codes.rb +10 -10
  24. data/lib/suretax/constants/transaction_type_codes.rb +2 -2
  25. data/lib/suretax/response.rb +7 -10
  26. data/lib/suretax/version.rb +1 -1
  27. data/spec/lib/suretax/api/group_spec.rb +21 -22
  28. data/spec/lib/suretax/api/request_item_spec.rb +10 -12
  29. data/spec/lib/suretax/api/request_item_validations_spec.rb +73 -76
  30. data/spec/lib/suretax/api/request_spec.rb +62 -66
  31. data/spec/lib/suretax/api/request_validations_spec.rb +141 -143
  32. data/spec/lib/suretax/api/response_spec.rb +48 -52
  33. data/spec/lib/suretax/api/tax_amount_spec.rb +12 -12
  34. data/spec/lib/suretax/api/tax_spec.rb +26 -28
  35. data/spec/lib/suretax/configuration_spec.rb +21 -24
  36. data/spec/lib/suretax/connection_spec.rb +11 -15
  37. data/spec/lib/suretax/response_spec.rb +27 -31
  38. data/spec/spec_helper.rb +16 -17
  39. data/spec/support/cancellation_helper.rb +0 -1
  40. data/spec/support/connection_shared_examples.rb +8 -10
  41. data/spec/support/request_helper.rb +13 -14
  42. data/spec/support/suretax_helper.rb +2 -4
  43. data/spec/support/validations_shared_examples.rb +12 -12
  44. data/suretax.gemspec +10 -8
  45. metadata +7 -7
  46. data/.travis.yml +0 -13
@@ -482,6 +482,6 @@ module Suretax
482
482
  "980512" => "Leasing, Deferred Payment Contract - Greater Than 6 Months - Stream",
483
483
  "990101" => "General Sales, General Sales",
484
484
  "999999" => "General Sales, Tax Exempt Products and Services",
485
- "010151" => "Long Distance, Long Distance Toll - INTRASTATE",
486
- }
485
+ "010151" => "Long Distance, Long Distance Toll - INTRASTATE"
486
+ }.freeze
487
487
  end
@@ -1,7 +1,6 @@
1
- require 'json'
1
+ require "json"
2
2
 
3
3
  module Suretax
4
-
5
4
  class Response
6
5
  attr_reader :response, :body, :status, :api
7
6
 
@@ -9,8 +8,8 @@ module Suretax
9
8
  @response = api_response
10
9
  sanitized_body = remove_xml_brackets(api_response.body)
11
10
 
12
- if sanitized_body == 'invalid request'
13
- invalid_request_response(sanitized_body)
11
+ if sanitized_body == "invalid request"
12
+ invalid_request_response(sanitized_body)
14
13
  else
15
14
  valid_request_response(sanitized_body)
16
15
  end
@@ -45,7 +44,7 @@ module Suretax
45
44
 
46
45
  def remove_xml_brackets(response_string)
47
46
  if matches = response_string.match(extract_json_from_urlencoded_string_regex)
48
- matches['json_string']
47
+ matches["json_string"]
49
48
  else
50
49
  response_string
51
50
  end
@@ -53,9 +52,9 @@ module Suretax
53
52
 
54
53
  def map_response_code_to_http_status(api_status_code)
55
54
  case api_status_code
56
- when '9999'
55
+ when "9999"
57
56
  200
58
- when '9001'
57
+ when "9001"
59
58
  409
60
59
  else
61
60
  400
@@ -63,7 +62,7 @@ module Suretax
63
62
  end
64
63
 
65
64
  def log_response
66
- logger.debug "\nSureTax Response Received:\n#{@body.inspect}" if logger
65
+ logger&.debug "\nSureTax Response Received:\n#{@body.inspect}"
67
66
  end
68
67
 
69
68
  def logger
@@ -73,7 +72,5 @@ module Suretax
73
72
  def configuration
74
73
  Suretax.configuration
75
74
  end
76
-
77
75
  end
78
-
79
76
  end
@@ -1,3 +1,3 @@
1
1
  module Suretax
2
- VERSION = '0.2.3'
2
+ VERSION = "1.0.0".freeze
3
3
  end
@@ -1,49 +1,48 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Suretax::Api::Group do
4
-
5
4
  let(:group) { Suretax::Api::Group.new(group_hash) }
6
5
 
7
- context 'with a v01 API response' do
8
- let(:group_hash) { valid_test_response_body['GroupList'].first }
6
+ context "with a v01 API response" do
7
+ let(:group_hash) { valid_test_response_body["GroupList"].first }
9
8
 
10
- it 'should have a state' do
11
- expect(group.state).to eql('CA')
9
+ it "should have a state" do
10
+ expect(group.state).to eql("CA")
12
11
  end
13
12
 
14
- it 'should have an invoice number' do
15
- expect(group.invoice).to eql('1')
13
+ it "should have an invoice number" do
14
+ expect(group.invoice).to eql("1")
16
15
  end
17
16
 
18
- it 'should have a customer number' do
19
- expect(group.customer).to eql('000000007')
17
+ it "should have a customer number" do
18
+ expect(group.customer).to eql("000000007")
20
19
  end
21
20
 
22
- it 'should have a list of taxes' do
21
+ it "should have a list of taxes" do
23
22
  expect(group.taxes.count).to eql(8)
24
23
  end
25
24
  end
26
25
 
27
- context 'with a v03 API response' do
28
- let(:group_hash) { valid_v03_response_body['GroupList'].first }
26
+ context "with a v03 API response" do
27
+ let(:group_hash) { valid_v03_response_body["GroupList"].first }
29
28
 
30
- it 'should have a state' do
31
- expect(group.state).to eql('CA')
29
+ it "should have a state" do
30
+ expect(group.state).to eql("CA")
32
31
  end
33
32
 
34
- it 'should have an invoice number' do
35
- expect(group.invoice).to eql('1')
33
+ it "should have an invoice number" do
34
+ expect(group.invoice).to eql("1")
36
35
  end
37
36
 
38
- it 'should have a line number' do
39
- expect(group.line).to eql('1')
37
+ it "should have a line number" do
38
+ expect(group.line).to eql("1")
40
39
  end
41
40
 
42
- it 'should have a customer number' do
43
- expect(group.customer).to eql('000000007')
41
+ it "should have a customer number" do
42
+ expect(group.customer).to eql("000000007")
44
43
  end
45
44
 
46
- it 'should have a list of taxes' do
45
+ it "should have a list of taxes" do
47
46
  expect(group.taxes.count).to eql(8)
48
47
  end
49
48
  end
@@ -1,18 +1,16 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Suretax::Api::RequestItem do
4
-
5
4
  let(:args) { suretax_valid_request_item_params }
6
5
  let(:subject) { Suretax::Api::RequestItem.new(args) }
7
6
 
8
- describe '#tax_exemption_codes' do
9
-
10
- it 'should have two codes' do
7
+ describe "#tax_exemption_codes" do
8
+ it "should have two codes" do
11
9
  expect(subject.tax_exemption_codes.count).to eql(2)
12
10
  end
13
11
  end
14
12
 
15
- describe '#params' do
13
+ describe "#params" do
16
14
  {
17
15
  bill_to_number: "8585260000",
18
16
  customer_number: "000000007",
@@ -34,7 +32,7 @@ describe Suretax::Api::RequestItem do
34
32
  unit_type: "00",
35
33
  units: "1",
36
34
  zipcode: "",
37
- user_defined_field: '',
35
+ user_defined_field: "",
38
36
  ship_from_zipcode: "",
39
37
  ship_from_plus_four: "",
40
38
  order_placement_zipcode: "",
@@ -50,20 +48,20 @@ describe Suretax::Api::RequestItem do
50
48
  common_carrier: "1",
51
49
  origin_country_code: "",
52
50
  dest_country_code: ""
53
- }.each_pair do |key,value|
51
+ }.each_pair do |key, value|
54
52
  it "##{key} should return the correct value" do
55
- subject.send("#{key.to_s}=",value)
53
+ subject.send("#{key}=", value)
56
54
  expect(subject.send(key)).to eql(value)
57
55
  end
58
56
  end
59
57
  end
60
58
 
61
- describe '#params' do
59
+ describe "#params" do
62
60
  let(:valid_params) do
63
- valid_encoded_test_request_body['ItemList'].first
61
+ valid_encoded_test_request_body["ItemList"].first
64
62
  end
65
63
 
66
- it 'should return a valid parameters hash' do
64
+ it "should return a valid parameters hash" do
67
65
  expect(subject.params).to eql(valid_params)
68
66
  end
69
67
  end
@@ -1,40 +1,39 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe "Suretax API Request Item Validations" do
4
-
5
4
  let(:request_item) do
6
5
  Suretax::Api::RequestItem.new(suretax_valid_request_item_params)
7
6
  end
8
7
 
9
- describe '#customer_number' do
10
- it 'should not be valid when it is not a number' do
11
- request_item.customer_number = ''
8
+ describe "#customer_number" do
9
+ it "should not be valid when it is not a number" do
10
+ request_item.customer_number = ""
12
11
 
13
12
  expect(request_item.errors.any?).to eq true
14
- expect(request_item.errors.messages).to eq [%Q{Invalid customer_number: ''}]
13
+ expect(request_item.errors.messages).to eq [%(Invalid customer_number: '')]
15
14
  end
16
15
 
17
- it 'should not be valid when the length is wrong' do
18
- request_item.customer_number = '1' * 11
16
+ it "should not be valid when the length is wrong" do
17
+ request_item.customer_number = "1" * 11
19
18
 
20
19
  expect(request_item.errors.any?).to eq true
21
- expect(request_item.errors.messages).to eq [%Q{Invalid customer_number: #{'1' * 11}}]
20
+ expect(request_item.errors.messages).to eq [%(Invalid customer_number: #{'1' * 11})]
22
21
  end
23
22
 
24
- it 'should not be valid when it is not a number' do
25
- request_item.customer_number = 'a' * 9
23
+ it "should not be valid when it is not a number" do
24
+ request_item.customer_number = "a" * 9
26
25
 
27
26
  expect(request_item.errors.any?).to eq true
28
- expect(request_item.errors.messages).to eq [%Q{Invalid customer_number: #{'a' * 9}}]
27
+ expect(request_item.errors.messages).to eq [%(Invalid customer_number: #{'a' * 9})]
29
28
  end
30
29
 
31
- it 'should be valid when it is a nine-digit number' do
30
+ it "should be valid when it is a nine-digit number" do
32
31
  expect(request_item.errors.any?).to eq false
33
32
  end
34
33
  end
35
34
 
36
- describe '#invoice_number' do
37
- %w{123 a1234 abcdef}.each do |value|
35
+ describe "#invoice_number" do
36
+ %w[123 a1234 abcdef].each do |value|
38
37
  it "can be '#{value}'" do
39
38
  request_item.invoice_number = value
40
39
 
@@ -42,35 +41,35 @@ describe "Suretax API Request Item Validations" do
42
41
  end
43
42
  end
44
43
 
45
- it 'cannot be longer than 20 characters' do
46
- request_item.invoice_number = '1' * 21
44
+ it "cannot be longer than 20 characters" do
45
+ request_item.invoice_number = "1" * 21
47
46
 
48
47
  expect(request_item.errors.any?).to eq true
49
- expect(request_item.errors.messages).to eq [%Q{Invalid invoice_number: #{'1' * 21}}]
48
+ expect(request_item.errors.messages).to eq [%(Invalid invoice_number: #{'1' * 21})]
50
49
  end
51
50
 
52
- it 'can be blank' do
51
+ it "can be blank" do
53
52
  request_item.invoice_number = nil
54
53
 
55
54
  expect(request_item.errors.any?).to eq false
56
55
  end
57
56
  end
58
57
 
59
- describe '#line_number' do
60
- it 'must not be more than 20 characters in length' do
61
- request_item.line_number = '1' * 21
58
+ describe "#line_number" do
59
+ it "must not be more than 20 characters in length" do
60
+ request_item.line_number = "1" * 21
62
61
 
63
62
  expect(request_item.errors.any?).to eq true
64
- expect(request_item.errors.messages).to eq [%Q{Invalid line_number: #{'1' * 21}}]
63
+ expect(request_item.errors.messages).to eq [%(Invalid line_number: #{'1' * 21})]
65
64
  end
66
65
 
67
- it 'can be blank' do
66
+ it "can be blank" do
68
67
  request_item.line_number = nil
69
68
 
70
69
  expect(request_item.errors.any?).to eq false
71
70
  end
72
71
 
73
- %w{1 40 580 12345678901234567890 a D0 S10}.each do |number|
72
+ %w[1 40 580 12345678901234567890 a D0 S10].each do |number|
74
73
  it "can be '#{number}'" do
75
74
  request_item.line_number = number
76
75
 
@@ -78,37 +77,35 @@ describe "Suretax API Request Item Validations" do
78
77
  end
79
78
  end
80
79
 
81
- %w{_}.each do |bad_content|
80
+ %w[_].each do |bad_content|
82
81
  it "cannot be '#{bad_content}'" do
83
82
  request_item.line_number = bad_content
84
83
 
85
84
  expect(request_item.errors.any?).to eq true
86
- expect(request_item.errors.messages).to eq [%Q{Invalid line_number: #{bad_content}}]
85
+ expect(request_item.errors.messages).to eq [%(Invalid line_number: #{bad_content})]
87
86
  end
88
87
  end
89
88
  end
90
89
 
91
- context 'phone number fields' do
92
- %w{orig_number term_number bill_to_number}.each do |phone_method|
93
-
90
+ context "phone number fields" do
91
+ %w[orig_number term_number bill_to_number].each do |phone_method|
94
92
  describe "##{phone_method}" do
95
- it_should_behave_like 'optional phone number' do
93
+ it_should_behave_like "optional phone number" do
96
94
  let(:subject) { phone_method }
97
95
  end
98
96
  end
99
-
100
97
  end
101
98
  end
102
99
 
103
- describe '#tax_situs_rule' do
104
- it 'must be present' do
100
+ describe "#tax_situs_rule" do
101
+ it "must be present" do
105
102
  request_item.tax_situs_rule = nil
106
103
 
107
104
  expect(request_item.errors.any?).to eq true
108
- expect(request_item.errors.messages).to eq [%Q{Invalid tax_situs_rule: nil}]
105
+ expect(request_item.errors.messages).to eq [%(Invalid tax_situs_rule: nil)]
109
106
  end
110
107
 
111
- %w{01 02 03 04 05 06 07 14}.each do |number|
108
+ %w[01 02 03 04 05 06 07 14].each do |number|
112
109
  it "can be '#{number}'" do
113
110
  request_item.tax_situs_rule = number
114
111
 
@@ -116,121 +113,121 @@ describe "Suretax API Request Item Validations" do
116
113
  end
117
114
  end
118
115
 
119
- %w{a D0 S10 _}.each do |bad_content|
116
+ %w[a D0 S10 _].each do |bad_content|
120
117
  it "cannot be '#{bad_content}'" do
121
118
  request_item.tax_situs_rule = bad_content
122
119
 
123
120
  expect(request_item.errors.any?).to eq true
124
- expect(request_item.errors.messages).to eq [%Q{Invalid tax_situs_rule: #{bad_content}}]
121
+ expect(request_item.errors.messages).to eq [%(Invalid tax_situs_rule: #{bad_content})]
125
122
  end
126
123
  end
127
124
  end
128
125
 
129
- describe '#trans_type_code' do
130
- context 'when present' do
131
- it 'should pass validation' do
132
- request_item.trans_type_code = '010101'
126
+ describe "#trans_type_code" do
127
+ context "when present" do
128
+ it "should pass validation" do
129
+ request_item.trans_type_code = "010101"
133
130
 
134
131
  expect(request_item.errors.any?).to eq false
135
132
  end
136
133
  end
137
134
 
138
- context 'when absent' do
139
- it 'should fail validation' do
135
+ context "when absent" do
136
+ it "should fail validation" do
140
137
  request_item.trans_type_code = nil
141
138
 
142
139
  expect(request_item.errors.any?).to eq true
143
- expect(request_item.errors.messages).to eq [%Q{Invalid trans_type_code: nil}]
140
+ expect(request_item.errors.messages).to eq [%(Invalid trans_type_code: nil)]
144
141
  end
145
142
  end
146
143
  end
147
144
 
148
- describe '#sales_type_code' do
149
- context 'when present' do
150
- it 'should allow valid codes' do
151
- %w{R B I L}.each do |code|
145
+ describe "#sales_type_code" do
146
+ context "when present" do
147
+ it "should allow valid codes" do
148
+ %w[R B I L].each do |code|
152
149
  request_item.sales_type_code = code
153
150
 
154
151
  expect(request_item.errors.any?).to eq false
155
152
  end
156
153
  end
157
154
 
158
- it 'should not allow invalid codes' do
159
- %w{A X Y Z}.each do |code|
155
+ it "should not allow invalid codes" do
156
+ %w[A X Y Z].each do |code|
160
157
  request_item.sales_type_code = code
161
158
 
162
159
  expect(request_item.errors.any?).to eq true
163
- expect(request_item.errors.messages).to eq [%Q{Invalid sales_type_code: #{code}}]
160
+ expect(request_item.errors.messages).to eq [%(Invalid sales_type_code: #{code})]
164
161
  end
165
162
  end
166
163
  end
167
164
 
168
- context 'when absent' do
169
- it 'should fail validation' do
165
+ context "when absent" do
166
+ it "should fail validation" do
170
167
  request_item.sales_type_code = nil
171
168
 
172
169
  expect(request_item.errors.any?).to eq true
173
- expect(request_item.errors.messages).to eq [%Q{Invalid sales_type_code: nil}]
170
+ expect(request_item.errors.messages).to eq [%(Invalid sales_type_code: nil)]
174
171
  end
175
172
  end
176
173
  end
177
174
 
178
- describe '#regulatory_code' do
179
- context 'when present' do
180
- it 'should allow valid codes' do
181
- %w{00 01 02 03 04 05 99}.each do |code|
175
+ describe "#regulatory_code" do
176
+ context "when present" do
177
+ it "should allow valid codes" do
178
+ %w[00 01 02 03 04 05 99].each do |code|
182
179
  request_item.regulatory_code = code
183
180
 
184
181
  expect(request_item.errors.any?).to eq false
185
182
  end
186
183
  end
187
184
 
188
- it 'should not allow invalid codes' do
189
- %w{44 77 4 f -}.each do |code|
185
+ it "should not allow invalid codes" do
186
+ %w[44 77 4 f -].each do |code|
190
187
  request_item.regulatory_code = code
191
188
 
192
189
  expect(request_item.errors.any?).to eq true
193
- expect(request_item.errors.messages).to eq [%Q{Invalid regulatory_code: #{code}}]
190
+ expect(request_item.errors.messages).to eq [%(Invalid regulatory_code: #{code})]
194
191
  end
195
192
  end
196
193
  end
197
194
 
198
- context 'when absent' do
199
- it 'should fail validation' do
195
+ context "when absent" do
196
+ it "should fail validation" do
200
197
  request_item.regulatory_code = nil
201
198
 
202
199
  expect(request_item.errors.any?).to eq true
203
- expect(request_item.errors.messages).to eq [%Q{Invalid regulatory_code: nil}]
200
+ expect(request_item.errors.messages).to eq [%(Invalid regulatory_code: nil)]
204
201
  end
205
202
  end
206
203
  end
207
204
 
208
- describe '#tax_exemption_codes' do
209
- context 'when present' do
210
- context 'and the list has content' do
211
- it 'should pass validation' do
212
- request_item.tax_exemption_codes = ['00']
205
+ describe "#tax_exemption_codes" do
206
+ context "when present" do
207
+ context "and the list has content" do
208
+ it "should pass validation" do
209
+ request_item.tax_exemption_codes = ["00"]
213
210
 
214
211
  expect(request_item.errors.any?).to eq false
215
212
  end
216
213
  end
217
214
 
218
- context 'and the list is empty' do
219
- it 'should fail validation' do
215
+ context "and the list is empty" do
216
+ it "should fail validation" do
220
217
  request_item.tax_exemption_codes = []
221
218
 
222
219
  expect(request_item.errors.any?).to eq true
223
- expect(request_item.errors.messages).to eq [%Q{Invalid tax_exemption_codes: []}]
220
+ expect(request_item.errors.messages).to eq [%(Invalid tax_exemption_codes: [])]
224
221
  end
225
222
  end
226
223
  end
227
224
 
228
- context 'when absent' do
229
- it 'should fail validation' do
225
+ context "when absent" do
226
+ it "should fail validation" do
230
227
  request_item.tax_exemption_codes = nil
231
228
 
232
229
  expect(request_item.errors.any?).to eq true
233
- expect(request_item.errors.messages).to eq [%Q{Invalid tax_exemption_codes: nil}]
230
+ expect(request_item.errors.messages).to eq [%(Invalid tax_exemption_codes: nil)]
234
231
  end
235
232
  end
236
233
  end