suretax 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.travis.yml +14 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +74 -0
  6. data/Gemfile.travis +12 -0
  7. data/LICENSE.txt +22 -0
  8. data/NOTES.md +3 -0
  9. data/README.md +58 -0
  10. data/Rakefile +1 -0
  11. data/circle.yml +7 -0
  12. data/lib/suretax.rb +24 -0
  13. data/lib/suretax/api.rb +7 -0
  14. data/lib/suretax/api/cancel_request.rb +64 -0
  15. data/lib/suretax/api/group.rb +16 -0
  16. data/lib/suretax/api/item_message.rb +13 -0
  17. data/lib/suretax/api/request.rb +133 -0
  18. data/lib/suretax/api/request_item.rb +84 -0
  19. data/lib/suretax/api/response.rb +53 -0
  20. data/lib/suretax/api/tax.rb +25 -0
  21. data/lib/suretax/api/tax_amount.rb +46 -0
  22. data/lib/suretax/concerns.rb +7 -0
  23. data/lib/suretax/concerns/validatable.rb +208 -0
  24. data/lib/suretax/configuration.rb +84 -0
  25. data/lib/suretax/connection.rb +48 -0
  26. data/lib/suretax/constants.rb +7 -0
  27. data/lib/suretax/constants/regulatory_codes.rb +11 -0
  28. data/lib/suretax/constants/response_groups.rb +8 -0
  29. data/lib/suretax/constants/sales_type_codes.rb +8 -0
  30. data/lib/suretax/constants/tax_situs_codes.rb +12 -0
  31. data/lib/suretax/constants/transaction_type_codes.rb +505 -0
  32. data/lib/suretax/response.rb +70 -0
  33. data/lib/suretax/version.rb +3 -0
  34. data/spec/lib/suretax/api/group_spec.rb +50 -0
  35. data/spec/lib/suretax/api/request_item_spec.rb +54 -0
  36. data/spec/lib/suretax/api/request_item_validations_spec.rb +237 -0
  37. data/spec/lib/suretax/api/request_spec.rb +197 -0
  38. data/spec/lib/suretax/api/request_validations_spec.rb +384 -0
  39. data/spec/lib/suretax/api/response_spec.rb +165 -0
  40. data/spec/lib/suretax/api/tax_amount_spec.rb +37 -0
  41. data/spec/lib/suretax/api/tax_spec.rb +59 -0
  42. data/spec/lib/suretax/configuration_spec.rb +97 -0
  43. data/spec/lib/suretax/connection_spec.rb +77 -0
  44. data/spec/lib/suretax/response_spec.rb +136 -0
  45. data/spec/spec_helper.rb +45 -0
  46. data/spec/support/cancellation_helper.rb +31 -0
  47. data/spec/support/connection_shared_examples.rb +37 -0
  48. data/spec/support/request_helper.rb +309 -0
  49. data/spec/support/suretax_helper.rb +27 -0
  50. data/spec/support/validations_shared_examples.rb +28 -0
  51. data/suretax.gemspec +33 -0
  52. metadata +281 -0
@@ -0,0 +1,31 @@
1
+ module CancellationSpecHelper
2
+
3
+ def cancel_response_body
4
+ {
5
+ "Successful" => "Y",
6
+ "ResponseCode" => "9999",
7
+ "HeaderMessage" => "Success",
8
+ "ClientTracking" => "test",
9
+ "TransId" => 0
10
+ }
11
+ end
12
+
13
+ def cancel_request_body
14
+ {
15
+ "ClientNumber" => suretax_client_number,
16
+ "ClientTracking" => "test",
17
+ "TransId" => "999",
18
+ "ValidationKey" => suretax_key
19
+ }
20
+ end
21
+
22
+ def cancel_failed_response_body
23
+ {
24
+ "Successful" => "N",
25
+ "ResponseCode" => nil,
26
+ "HeaderMessage" => nil,
27
+ "ClientTracking" => nil,
28
+ "TransId" => 0
29
+ }
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'API connection' do
4
+ context 'with a valid request' do
5
+ before do
6
+ stub_request(:post, "#{suretax_url}#{api_path}").to_return(
7
+ status: 200,
8
+ body: response_body
9
+ )
10
+ end
11
+
12
+ it 'should be successful' do
13
+ expect(response).to be_success
14
+ end
15
+
16
+ it 'should have a urlencode header' do
17
+ expect(connection.headers['Content-Type']).to include('application/x-www-form-urlencoded')
18
+ end
19
+ end
20
+
21
+ context 'with an invalid request' do
22
+
23
+ let(:request_body) { {} }
24
+
25
+ before do
26
+ stub_request(:post, "#{suretax_url}#{api_path}").to_return(
27
+ status: 500,
28
+ body: invalid_response_body
29
+ )
30
+ end
31
+
32
+ it 'should not be successful' do
33
+ expect(response).to_not be_success
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,309 @@
1
+ # encoding: utf-8
2
+
3
+ module RequestSpecHelper
4
+
5
+ def valid_encoded_test_request_body
6
+ {
7
+ "ClientNumber" => suretax_client_number,
8
+ "BusinessUnit" => "testing",
9
+ "ValidationKey" => suretax_key,
10
+ "ClientTracking" => "track",
11
+ "DataMonth" => "7",
12
+ "DataYear" => "2013",
13
+ "ResponseGroup" => "03",
14
+ "ResponseType" => "D6",
15
+ "ReturnFileCode" => "0",
16
+ "TotalRevenue" => 40.0,
17
+ "IndustryExemption" => "",
18
+ "ItemList" => [
19
+ {
20
+ "LineNumber" => "1",
21
+ "InvoiceNumber" => "1",
22
+ "CustomerNumber" => "000000007",
23
+ "OrigNumber" => "8585260000",
24
+ "TermNumber" => "8585260000",
25
+ "BillToNumber" => "8585260000",
26
+ "Zipcode" => "",
27
+ "Plus4" => "",
28
+ "P2PZipcode" => "",
29
+ "P2PPlus4" => "",
30
+ "TransDate" => "2013-12-01T00:00:00",
31
+ "Revenue" => 40.0,
32
+ "Units" => 1,
33
+ "UnitType" => "00",
34
+ "Seconds" => 55,
35
+ "TaxIncludedCode" => "0",
36
+ "TaxSitusRule" => "01",
37
+ "TransTypeCode" => "010101",
38
+ "SalesTypeCode" => "R",
39
+ "RegulatoryCode" => "99",
40
+ "TaxExemptionCodeList" => [
41
+ "00",
42
+ "00"
43
+ ]
44
+ }
45
+ ]
46
+ }
47
+ end
48
+
49
+ def valid_test_response_body
50
+ {
51
+ "Successful" => "Y",
52
+ "ResponseCode" => "9999",
53
+ "HeaderMessage" => "Success",
54
+ "ItemMessages" => [],
55
+ "ClientTracking" => "track",
56
+ "TotalTax" => "1.394490",
57
+ "TransId" => 2664495,
58
+ "GroupList" => [
59
+ {
60
+ "StateCode" => "CA",
61
+ "InvoiceNumber" => "1",
62
+ "CustomerNumber" => "000000007",
63
+ "TaxList" => [
64
+ {
65
+ "TaxTypeCode" => "106",
66
+ "TaxTypeDesc" => "CA EMERG TEL. USERS SURCHARGE",
67
+ "TaxAmount" => "0.200760"
68
+ },
69
+ {
70
+ "TaxTypeCode" => "108",
71
+ "TaxTypeDesc" => "CA P.U.C. FEE",
72
+ "TaxAmount" => "0.072130"
73
+ },
74
+ {
75
+ "TaxTypeCode" => "109",
76
+ "TaxTypeDesc" => "CA TELECOM RELAY SYSTEMS SURCHARGE",
77
+ "TaxAmount" => "0.080000"
78
+ },
79
+ {
80
+ "TaxTypeCode" => "117",
81
+ "TaxTypeDesc" => "CA HIGH COST FUND(B) SURCHARGE",
82
+ "TaxAmount" => "0.120000"
83
+ },
84
+ {
85
+ "TaxTypeCode" => "118",
86
+ "TaxTypeDesc" => "CA TELECONNECT FUND",
87
+ "TaxAmount" => "0.236000"
88
+ },
89
+ {
90
+ "TaxTypeCode" => "119",
91
+ "TaxTypeDesc" => "CA HIGH COST FUND(A) SURCHARGE",
92
+ "TaxAmount" => "0.160000"
93
+ },
94
+ {
95
+ "TaxTypeCode" => "120",
96
+ "TaxTypeDesc" => "CA ADVANCED SERV FUND SURCH",
97
+ "TaxAmount" => "0.065600"
98
+ },
99
+ {
100
+ "TaxTypeCode" => "122",
101
+ "TaxTypeDesc" => "CA UNIVERSAL LIFELINE SURCHARGE",
102
+ "TaxAmount" => "0.460000"
103
+ }
104
+ ]
105
+ }
106
+ ]
107
+ }
108
+ end
109
+
110
+ def valid_v03_response_body
111
+ {
112
+ "Successful" => "Y",
113
+ "ResponseCode" => "9999",
114
+ "HeaderMessage" => "Success",
115
+ "ItemMessages" => [],
116
+ "ClientTracking" => "track",
117
+ "TotalTax" => "1.394490",
118
+ "TransId" => 2872159,
119
+ "GroupList" => [
120
+ {
121
+ "LineNumber" => "1",
122
+ "StateCode" => "CA",
123
+ "InvoiceNumber" => "1",
124
+ "CustomerNumber" => "000000007",
125
+ "TaxList" => [
126
+ {
127
+ "TaxTypeCode" => "106",
128
+ "TaxTypeDesc" => "CA EMERG TEL. USERS SURCHARGE",
129
+ "TaxAmount" => "0.200760",
130
+ "Revenue" => "40",
131
+ "CountyName" => "SAN DIEGO",
132
+ "CityName" => "SAN DIEGO",
133
+ "TaxRate" => 0.005,
134
+ "PercentTaxable" => 1.0
135
+ },
136
+ {
137
+ "TaxTypeCode" => "108",
138
+ "TaxTypeDesc" => "CA P.U.C. FEE",
139
+ "TaxAmount" => "0.072130",
140
+ "Revenue" => "40",
141
+ "CountyName" => "SAN DIEGO",
142
+ "CityName" => "SAN DIEGO",
143
+ "TaxRate" => 0.0018,
144
+ "PercentTaxable" => 1.0
145
+ },
146
+ {
147
+ "TaxTypeCode" => "109",
148
+ "TaxTypeDesc" => "CA TELECOM RELAY SYSTEMS SURCHARGE",
149
+ "TaxAmount" => "0.080000",
150
+ "Revenue" => "40",
151
+ "CountyName" => "SAN DIEGO",
152
+ "CityName" => "SAN DIEGO",
153
+ "TaxRate" => 0.002,
154
+ "PercentTaxable" => 1.0
155
+ },
156
+ {
157
+ "TaxTypeCode" => "117",
158
+ "TaxTypeDesc" => "CA HIGH COST FUND(B) SURCHARGE",
159
+ "TaxAmount" => "0.120000",
160
+ "Revenue" => "40",
161
+ "CountyName" => "SAN DIEGO",
162
+ "CityName" => "SAN DIEGO",
163
+ "TaxRate" => 0.003,
164
+ "PercentTaxable" => 1.0
165
+ },
166
+ {
167
+ "TaxTypeCode" => "118",
168
+ "TaxTypeDesc" => "CA TELECONNECT FUND",
169
+ "TaxAmount" => "0.236000",
170
+ "Revenue" => "40",
171
+ "CountyName" => "SAN DIEGO",
172
+ "CityName" => "SAN DIEGO",
173
+ "TaxRate" => 0.0059,
174
+ "PercentTaxable" => 1.0
175
+ },
176
+ {
177
+ "TaxTypeCode" => "119",
178
+ "TaxTypeDesc" => "CA HIGH COST FUND(A) SURCHARGE",
179
+ "TaxAmount" => "0.160000",
180
+ "Revenue" => "40",
181
+ "CountyName" => "SAN DIEGO",
182
+ "CityName" => "SAN DIEGO",
183
+ "TaxRate" => 0.004,
184
+ "PercentTaxable" => 1.0
185
+ },
186
+ {
187
+ "TaxTypeCode" => "120",
188
+ "TaxTypeDesc" => "CA ADVANCED SERV FUND SURCH",
189
+ "TaxAmount" => "0.065600",
190
+ "Revenue" => "40",
191
+ "CountyName" => "SAN DIEGO",
192
+ "CityName" => "SAN DIEGO",
193
+ "TaxRate" => 0.00164,
194
+ "PercentTaxable" => 1.0
195
+ },
196
+ {
197
+ "TaxTypeCode" => "122",
198
+ "TaxTypeDesc" => "CA UNIVERSAL LIFELINE SURCHARGE",
199
+ "TaxAmount" => "0.460000",
200
+ "Revenue" => "40",
201
+ "CountyName" => "SAN DIEGO",
202
+ "CityName" => "SAN DIEGO",
203
+ "TaxRate" => 0.0115,
204
+ "PercentTaxable" => 1.0
205
+ }]
206
+ }
207
+ ]
208
+ }
209
+ end
210
+
211
+ def post_failed_response_body
212
+ {
213
+ "Successful"=>"N",
214
+ "ResponseCode"=>"1101",
215
+ "HeaderMessage"=>"Failure - Error parsing request",
216
+ "ItemMessages"=>[],
217
+ "ClientTracking"=>nil,
218
+ "TotalTax"=>nil,
219
+ "TransId"=>2667859,
220
+ "GroupList"=>[]
221
+ }
222
+ end
223
+
224
+ def success_with_item_errors
225
+ {
226
+ "Successful" => "Y",
227
+ "ResponseCode" => "9001",
228
+ "HeaderMessage" => "Success with Item errors",
229
+ "ItemMessages" => [
230
+ {
231
+ "LineNumber" => "1",
232
+ "ResponseCode" => "9220",
233
+ "Message" => "Invalid Unit Type – Must be 00"
234
+ }
235
+ ],
236
+ "ClientTracking" => "7310",
237
+ "TotalTax" => "26.53",
238
+ "TransId" => 4366,
239
+ "GroupList" => [
240
+ {
241
+ "CustomerNumber" => "00123",
242
+ "InvoiceNumber" => "12345678",
243
+ "StateCode" => "CA",
244
+ "TaxList" => [
245
+ {
246
+ "TaxAmount" => "10.45",
247
+ "TaxTypeCode" => "316",
248
+ "TaxTypeDesc" => "LOCAL UTILITY USERS TAX"
249
+ },
250
+ {
251
+ "TaxAmount" => "15.50",
252
+ "TaxTypeCode" => "035",
253
+ "TaxTypeDesc" => "FEDERAL UNIVERSAL SERVICE FUND"
254
+ },
255
+ {
256
+ "TaxAmount" => "0.58",
257
+ "TaxTypeCode" => "060",
258
+ "TaxTypeDesc" => "FEDERAL TRS FUND"
259
+ }
260
+ ]
261
+ }
262
+ ]
263
+ }
264
+ end
265
+
266
+ def suretax_valid_request_params
267
+ {
268
+ business_unit: "testing",
269
+ client_number: suretax_client_number,
270
+ client_tracking: "track",
271
+ data_month: "7",
272
+ data_year: "2013",
273
+ industry_exemption: "",
274
+ response_group: "03",
275
+ response_type: "D6",
276
+ return_file_code: "0",
277
+ total_revenue: "40",
278
+ validation_key: suretax_key,
279
+ items: [ suretax_valid_request_item_params ]
280
+ }
281
+ end
282
+
283
+ def suretax_valid_request_item_params
284
+ {
285
+ bill_to_number: "8585260000",
286
+ customer_number: "000000007",
287
+ invoice_number: "1",
288
+ line_number: "1",
289
+ orig_number: "8585260000",
290
+ p_to_p_plus_four: "",
291
+ p_to_p_zipcode: "",
292
+ plus_four: "",
293
+ regulatory_code: "99",
294
+ revenue: "40",
295
+ sales_type_code: "R",
296
+ seconds: "55",
297
+ tax_included_code: "0",
298
+ tax_situs_rule: "01",
299
+ term_number: "8585260000",
300
+ trans_date: "2013-12-01T00:00:00",
301
+ trans_type_code: "010101",
302
+ unit_type: "00",
303
+ units: "1",
304
+ zipcode: "",
305
+ tax_exemption_codes: [ "00", "00" ]
306
+ }
307
+ end
308
+
309
+ end
@@ -0,0 +1,27 @@
1
+ module SuretaxSpecHelper
2
+
3
+ def suretax_key
4
+ ENV['SURETAX_VALIDATION_KEY']
5
+ end
6
+
7
+ def suretax_url
8
+ Suretax.configuration.base_url
9
+ end
10
+
11
+ def suretax_client_number
12
+ ENV['SURETAX_CLIENT_NUMBER']
13
+ end
14
+
15
+ def suretax_post_path
16
+ Suretax.configuration.request_path
17
+ end
18
+
19
+ def suretax_cancel_path
20
+ Suretax.configuration.cancel_path
21
+ end
22
+
23
+ def suretax_wrap_response(json_string)
24
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\">" + json_string + "</string>"
25
+ end
26
+
27
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'optional phone number' do
4
+ it 'can be blank' do
5
+ request_item.send("#{subject}=",nil)
6
+
7
+ expect(request_item.errors.any?).to eq false
8
+ end
9
+
10
+ it 'must be numeric' do
11
+ request_item.send("#{subject}=",'abcdefghij')
12
+
13
+ expect(request_item.errors.any?).to eq true
14
+ expect(request_item.errors.messages).to eq [%Q{Invalid #{subject}: abcdefghij}]
15
+ end
16
+
17
+ it 'must ten digits' do
18
+ request_item.send("#{subject}=",'1' * 11)
19
+
20
+ expect(request_item.errors.any?).to eq true
21
+ expect(request_item.errors.messages).to eq [%Q{Invalid #{subject}: #{'1' * 11}}]
22
+
23
+ request_item.send("#{subject}=",'1' * 9)
24
+
25
+ expect(request_item.errors.any?).to eq true
26
+ expect(request_item.errors.messages).to eq [%Q{Invalid #{subject}: #{'1' * 9}}]
27
+ end
28
+ end
data/suretax.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'suretax/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "suretax"
8
+ spec.version = Suretax::VERSION
9
+ spec.authors = ["Damon Davison"]
10
+ spec.email = ["damon@allolex.net"]
11
+ spec.description = %q{A wrapper library for the SureTax communications tax API}
12
+ spec.summary = %q{This gem will allow Ruby developers to easily integrate SureTax into their apps.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "faraday"
22
+ spec.add_dependency "money"
23
+ spec.add_dependency "monetize"
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", '~> 3.0.0'
27
+ spec.add_development_dependency 'rspec-its', '~> 1.0'
28
+ spec.add_development_dependency "dotenv"
29
+ spec.add_development_dependency "awesome_print"
30
+ spec.add_development_dependency "webmock"
31
+ spec.add_development_dependency "simplecov"
32
+ spec.add_development_dependency "pry"
33
+ end