Avatax_TaxService 1.0.1
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.
- data/Avatax Ruby SDK Guide.docx +0 -0
- data/Avatax_TaxService.gemspec +22 -0
- data/LICENSE.txt +21 -0
- data/lib/avatax_taxservice.rb +965 -0
- data/lib/tax_log.txt +0 -0
- data/lib/taxservice_dev.wsdl +1091 -0
- data/lib/taxservice_prd.wsdl +1091 -0
- data/lib/template_adjusttax.erb +101 -0
- data/lib/template_canceltax.erb +30 -0
- data/lib/template_committax.erb +31 -0
- data/lib/template_gettax.erb +97 -0
- data/lib/template_gettaxhistory.erb +29 -0
- data/lib/template_isauthorized.erb +22 -0
- data/lib/template_ping.erb +22 -0
- data/lib/template_posttax.erb +26 -0
- data/lib/template_reconciletaxhistory.erb +32 -0
- data/lib/xpath_adjtax.txt +74 -0
- data/lib/xpath_cancel.txt +10 -0
- data/lib/xpath_commit.txt +10 -0
- data/lib/xpath_gettax.txt +74 -0
- data/lib/xpath_gettaxhistory.txt +128 -0
- data/lib/xpath_isauthorized.txt +4 -0
- data/lib/xpath_ping.txt +9 -0
- data/lib/xpath_post.txt +9 -0
- data/lib/xpath_reconciletaxhistory.txt +31 -0
- data/test/test_adjtax.rb +116 -0
- data/test/test_gettax.rb +191 -0
- data/test/test_gettaxhistory.rb +50 -0
- data/test/test_reconciletaxhistory.rb +77 -0
- metadata +112 -0
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "Avatax_TaxService"
|
3
|
+
s.version = "1.0.1"
|
4
|
+
s.date = "2012-10-28"
|
5
|
+
s.author = "Graham S Wilson"
|
6
|
+
s.email = "support@Avalara.com"
|
7
|
+
s.summary = "Ruby SDK for Avatax Web Services"
|
8
|
+
s.homepage = "http://www.avalara.com/"
|
9
|
+
s.description = "Ruby SDK provides means of communication with Avatax Web Services."
|
10
|
+
s.files = ["lib/tax_log.txt", "lib/taxservice_dev.wsdl", "lib/taxservice_prd.wsdl", "lib/avatax_taxservice.rb",
|
11
|
+
"lib/template_adjusttax.erb", "lib/template_canceltax.erb", "lib/template_committax.erb","lib/template_gettax.erb",
|
12
|
+
"lib/template_gettaxhistory.erb","lib/template_isauthorized.erb","lib/template_ping.erb","lib/template_posttax.erb",
|
13
|
+
"lib/template_reconciletaxhistory.erb","lib/xpath_adjtax.txt","lib/xpath_cancel.txt","lib/xpath_commit.txt","lib/xpath_gettax.txt",
|
14
|
+
"lib/xpath_gettaxhistory.txt","lib/xpath_isauthorized.txt","lib/xpath_ping.txt","lib/xpath_post.txt","lib/xpath_reconciletaxhistory.txt",
|
15
|
+
"test/test_adjtax.rb","test/test_gettax.rb","test/test_gettaxhistory.rb","test/test_reconciletaxhistory.rb", "Avatax_TaxService.gemspec",
|
16
|
+
"Avatax Ruby SDK Guide.docx", "LICENSE.txt"]
|
17
|
+
s.add_dependency "nokogiri", ">= 1.4.0", "< 1.6"
|
18
|
+
s.add_dependency "savon", ">= 2.3.0"
|
19
|
+
s.required_ruby_version = '>=1.9.3'
|
20
|
+
s.post_install_message = 'Thanks for installing the Avalara AddressService Ruby SDK. Refer to "Avatax Ruby SDK User Guide.docx" to get started.'
|
21
|
+
end
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Ruby SDK for AvaTax [License]
|
2
|
+
Copyright (c) 2013 Avalara Inc.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,965 @@
|
|
1
|
+
require 'savon'
|
2
|
+
require 'erb'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
module AvaTax
|
7
|
+
|
8
|
+
#Avalara tax class
|
9
|
+
class TaxService
|
10
|
+
|
11
|
+
def initialize(username,password,name,clientname,adapter,machine)
|
12
|
+
|
13
|
+
#Set credentials and Profile information
|
14
|
+
@username = username == nil ? "" : username
|
15
|
+
@password = password == nil ? "" : password
|
16
|
+
@name = name == nil ? "" : name
|
17
|
+
@clientname = clientname == nil ? "" : clientname
|
18
|
+
@adapter = adapter == nil ? "" : adapter
|
19
|
+
@machine = machine == nil ? "" : machine
|
20
|
+
|
21
|
+
#Set @def_locn to the Avatax-x.x.x gem install library. This enables the ruby programs to
|
22
|
+
#find other objects that it needs.
|
23
|
+
@def_locn = 'C:\Ruby193\lib\ruby\gems\1.9.1\gems\Avatax_TaxService-1.0.0\lib'
|
24
|
+
|
25
|
+
#Header for response data
|
26
|
+
@responsetime_hdr = " (User) (System) (Total) (Real)"
|
27
|
+
|
28
|
+
#Open Avatax Error Log
|
29
|
+
@log = File.new(@def_locn + '/tax_log.txt', "w")
|
30
|
+
@log.puts "#{Time.now}: Tax service started"
|
31
|
+
|
32
|
+
#Get service details from WSDL - control_array[2] contains the WSDL read from the address_control file
|
33
|
+
#log :false turns off HTTP logging
|
34
|
+
@client = Savon.client(wsdl: @def_locn + '/taxservice_dev.wsdl', log: false)
|
35
|
+
|
36
|
+
#Read in the SOAP template for Get tax
|
37
|
+
begin
|
38
|
+
@template_gettax = ERB.new(File.read(@def_locn + '/template_gettax.erb'))
|
39
|
+
rescue
|
40
|
+
@log.puts "#{Time.now}: Error loading the GetTax template"
|
41
|
+
end
|
42
|
+
|
43
|
+
#Read in the SOAP template for Adjust tax
|
44
|
+
begin
|
45
|
+
@template_adjust = ERB.new(File.read(@def_locn + '/template_adjusttax.erb'))
|
46
|
+
rescue
|
47
|
+
@log.puts "#{Time.now}: Error loading the AdjustTax template"
|
48
|
+
end
|
49
|
+
|
50
|
+
#Read in the SOAP template for Ping
|
51
|
+
begin
|
52
|
+
@template_ping = ERB.new(File.read(@def_locn + '/template_ping.erb'))
|
53
|
+
rescue
|
54
|
+
@log.puts "#{Time.now}: Error loading the Ping template"
|
55
|
+
end
|
56
|
+
|
57
|
+
#Read in the SOAP template for IsAuthorized
|
58
|
+
begin
|
59
|
+
@template_isauthorized = ERB.new(File.read(@def_locn + '/template_isauthorized.erb'))
|
60
|
+
rescue
|
61
|
+
@log.puts "#{Time.now}: Error loading the IsAuthorized template"
|
62
|
+
end
|
63
|
+
|
64
|
+
#Read in the SOAP template for Tax
|
65
|
+
begin
|
66
|
+
@template_post = ERB.new(File.read(@def_locn + '/template_posttax.erb'))
|
67
|
+
rescue
|
68
|
+
@log.puts "#{Time.now}: Error loading the Post template"
|
69
|
+
end
|
70
|
+
|
71
|
+
#Read in the SOAP template for Commit tax
|
72
|
+
begin
|
73
|
+
@template_commit = ERB.new(File.read(@def_locn + '/template_committax.erb'))
|
74
|
+
rescue
|
75
|
+
@log.puts "#{Time.now}: Error loading the CommitTax template"
|
76
|
+
end
|
77
|
+
|
78
|
+
#Read in the SOAP template for Cancel tax
|
79
|
+
begin
|
80
|
+
@template_cancel = ERB.new(File.read(@def_locn + '/template_canceltax.erb'))
|
81
|
+
rescue
|
82
|
+
@log.puts "#{Time.now}: Error loading the CancelTax template"
|
83
|
+
end
|
84
|
+
|
85
|
+
#Read in the SOAP template for GetTaxHistory tax
|
86
|
+
begin
|
87
|
+
@template_gettaxhistory = ERB.new(File.read(@def_locn + '/template_gettaxhistory.erb'))
|
88
|
+
rescue
|
89
|
+
@log.puts "#{Time.now}: Error loading the GetTaxHistory template"
|
90
|
+
end
|
91
|
+
|
92
|
+
#Read in the SOAP template for GetTaxHistory tax
|
93
|
+
begin
|
94
|
+
@template_reconciletaxhistory = ERB.new(File.read(@def_locn + '/template_reconciletaxhistory.erb'))
|
95
|
+
rescue
|
96
|
+
@log.puts "#{Time.now}: Error loading the ReconcileTaxHistory template"
|
97
|
+
end
|
98
|
+
|
99
|
+
# Create hash for validate result
|
100
|
+
@return_data = Hash.new
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
####################################################################################################
|
105
|
+
# ping - Verifies connectivity to the web service and returns version information about the service.
|
106
|
+
####################################################################################################
|
107
|
+
def ping(message = nil)
|
108
|
+
#Read in the SOAP template
|
109
|
+
@message = message == nil ? "?" : message
|
110
|
+
|
111
|
+
# Subsitute real vales for template place holders
|
112
|
+
@soap = @template_ping.result(binding)
|
113
|
+
|
114
|
+
#Clear return hash
|
115
|
+
@return_data.clear
|
116
|
+
|
117
|
+
# Make the call to the Avalara service
|
118
|
+
begin
|
119
|
+
@response = @client.call(:ping, xml: @soap).to_s
|
120
|
+
rescue
|
121
|
+
@log.puts "#{Time.now}: Error calling Ping service ... check that your account name and password are correct."
|
122
|
+
end
|
123
|
+
# Load the response into a Nokogiri object and remove namespaces
|
124
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
125
|
+
|
126
|
+
#Read in an array of XPATH pointers
|
127
|
+
@ping_xpath = File.readlines(@def_locn + '/xpath_ping.txt')
|
128
|
+
|
129
|
+
#Parse the returned repsonse and return to caller as a hash
|
130
|
+
@ping_xpath.each do |xpath|
|
131
|
+
if xpath.rstrip.length != 0
|
132
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
return @return_data
|
137
|
+
end
|
138
|
+
|
139
|
+
####################################################################################################
|
140
|
+
# gettax - Calls the Avatax GetTax Service
|
141
|
+
####################################################################################################
|
142
|
+
def gettax(companycode,
|
143
|
+
doctype,
|
144
|
+
doccode,
|
145
|
+
docdate,
|
146
|
+
salespersoncode,
|
147
|
+
customercode,
|
148
|
+
customerusagetype,
|
149
|
+
discount,
|
150
|
+
purchaseorderno,
|
151
|
+
exemptionno,
|
152
|
+
origincode,
|
153
|
+
destinationcode,
|
154
|
+
addresses,
|
155
|
+
lines,
|
156
|
+
detaillevel,
|
157
|
+
referencecode,
|
158
|
+
hashcode,
|
159
|
+
locationcode,
|
160
|
+
commit,
|
161
|
+
batchcode,
|
162
|
+
taxoverridetype,
|
163
|
+
taxamount,
|
164
|
+
taxdate,
|
165
|
+
reason,
|
166
|
+
currencycode,
|
167
|
+
servicemode,
|
168
|
+
paymentdate,
|
169
|
+
exchangerate,
|
170
|
+
exchangerateeffdate,
|
171
|
+
poslanecode,
|
172
|
+
businessidentificationno,
|
173
|
+
debug,
|
174
|
+
validate)
|
175
|
+
|
176
|
+
#Set parms passed by user - If Nil then default else use passed value
|
177
|
+
@companycode = companycode == nil ? "" : companycode
|
178
|
+
@doctype = doctype == nil ? "" : doctype
|
179
|
+
@doccode = doccode == nil ? "" : doccode
|
180
|
+
@docdate = docdate == nil ? "" : docdate
|
181
|
+
@salespersoncode = salespersoncode == nil ? "" : salespersoncode
|
182
|
+
@customercode = customercode == nil ? "" : customercode
|
183
|
+
@customerusagetype = customerusagetype == nil ? "" : customerusagetype
|
184
|
+
@discount = discount == nil ? "" : discount
|
185
|
+
@purchaseorderno = purchaseorderno == nil ? "" : purchaseorderno
|
186
|
+
@exemptionno = exemptionno == nil ? "" : exemptionno
|
187
|
+
@origincode = origincode == nil ? "" : origincode
|
188
|
+
@destinationcode = destinationcode == nil ? "" : destinationcode
|
189
|
+
@addresses = addresses == nil ? "" : addresses
|
190
|
+
@lines = lines == nil ? "" : lines
|
191
|
+
@detaillevel = detaillevel == nil ? "" : detaillevel
|
192
|
+
@referencecode = referencecode == nil ? "" : referencecode
|
193
|
+
@hashcode = hashcode == nil ? "" : hashcode
|
194
|
+
@locationcode = locationcode == nil ? "" : locationcode
|
195
|
+
@commit = commit == nil ? "" : commit
|
196
|
+
@batchcode = batchcode == nil ? "" : batchcode
|
197
|
+
@taxoverridetype = taxoverridetype == nil ? "" : taxoverridetype
|
198
|
+
@taxamount = taxamount == nil ? "" : taxamount
|
199
|
+
@taxdate = taxdate == nil ? "" : taxdate
|
200
|
+
@reason = reason == nil ? "" : reason
|
201
|
+
@currencycode = currencycode == nil ? "" : currencycode
|
202
|
+
@servicemode = servicemode == nil ? "" : servicemode
|
203
|
+
@paymentdate = paymentdate == nil ? "" : paymentdate
|
204
|
+
@exchangerate = exchangerate == nil ? "" : exchangerate
|
205
|
+
@exchangerateeffdate = exchangerateeffdate == nil ? "" : exchangerateeffdate
|
206
|
+
@poslanecode = poslanecode == nil ? "" : poslanecode
|
207
|
+
@businessidentificationno = businessidentificationno == nil ? "" : businessidentificationno
|
208
|
+
@debug = debug == nil ? false : debug
|
209
|
+
@validate = validate == nil ? false : validate
|
210
|
+
|
211
|
+
# If vaidate set to true then user has requested address validation before the tax call
|
212
|
+
if @validate
|
213
|
+
if @debug
|
214
|
+
#Use Ruby built in Benchmark function to record response times
|
215
|
+
time = Benchmark.measure do
|
216
|
+
valaddr
|
217
|
+
end
|
218
|
+
if @val_addr[:ResultCode] == "Success"
|
219
|
+
@log.puts "#{Time.now}: Validation OK"
|
220
|
+
else
|
221
|
+
@log.puts "#{Time.now}: Address #{line1}, #{line2}, #{line3}, #{city}, #{region}, #{postalcode}, #{country} failed to validate."
|
222
|
+
end
|
223
|
+
@log.puts "Response times for Address Validation:"
|
224
|
+
@log.puts @responsetime_hdr
|
225
|
+
@log.puts time
|
226
|
+
else
|
227
|
+
#Validate with no benchmarking
|
228
|
+
valaddr
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# Subsitute template place holders with real values
|
233
|
+
@soap = @template_gettax.result(binding)
|
234
|
+
if debug
|
235
|
+
@log.puts "#{Time.now}: SOAP request created:"
|
236
|
+
@log.puts @soap
|
237
|
+
end
|
238
|
+
|
239
|
+
#Clear return hash
|
240
|
+
@return_data.clear
|
241
|
+
|
242
|
+
# Make the call to the Avalara service
|
243
|
+
begin
|
244
|
+
# Call using debug
|
245
|
+
if debug
|
246
|
+
# Use Ruby built in Benchmark funtion to record response times
|
247
|
+
@log.puts "#{Time.now}: Calling GetTax Service for DocCode: #{@doccode}"
|
248
|
+
time = Benchmark.measure do
|
249
|
+
# Call GetTax Service
|
250
|
+
@response = @client.call(:get_tax, xml: @soap).to_s
|
251
|
+
end
|
252
|
+
@log.puts "Response times for GetTax:"
|
253
|
+
@log.puts @responsetime_hdr
|
254
|
+
@log.puts time
|
255
|
+
else
|
256
|
+
# Call GetTax Service
|
257
|
+
@response = @client.call(:get_tax, xml: @soap).to_s
|
258
|
+
end
|
259
|
+
#Capture unexepected errors
|
260
|
+
rescue
|
261
|
+
@log.puts "#{Time.now}: Error calling GetTax service ... check that your account name and password are correct."
|
262
|
+
end
|
263
|
+
|
264
|
+
#Parse the response
|
265
|
+
#Read in an array of XPATH pointers
|
266
|
+
@gettax_xpath = File.readlines(@def_locn + '/xpath_gettax.txt')
|
267
|
+
|
268
|
+
# Call using debug
|
269
|
+
if debug
|
270
|
+
# Use Ruby built in Benchmark funtion to record response times
|
271
|
+
@log.puts "#{Time.now}: Parsing the GeTax response:"
|
272
|
+
time = Benchmark.measure do
|
273
|
+
# Load the response into a Nokogiri object and remove namespaces
|
274
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
275
|
+
#Parse the returned repsonse and return to caller as a hash
|
276
|
+
@gettax_xpath.each do |xpath|
|
277
|
+
if xpath.rstrip.length != 0
|
278
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
@log.puts @responsetime_hdr
|
283
|
+
@log.puts time
|
284
|
+
else
|
285
|
+
# Load the response into a Nokogiri object and remove namespaces
|
286
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
287
|
+
#Parse the returned repsonse and return to caller as a hash
|
288
|
+
@gettax_xpath.each do |xpath|
|
289
|
+
if xpath.rstrip.length != 0
|
290
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
#Return data to calling program
|
295
|
+
return @return_data
|
296
|
+
end
|
297
|
+
|
298
|
+
####################################################################################################
|
299
|
+
# adjusttax - Calls the Avatax AdjustTax Service
|
300
|
+
####################################################################################################
|
301
|
+
def adjusttax(adjustmentreason,
|
302
|
+
adjustmentdescription,
|
303
|
+
companycode,
|
304
|
+
doctype,
|
305
|
+
doccode,
|
306
|
+
docdate,
|
307
|
+
salespersoncode,
|
308
|
+
customercode,
|
309
|
+
customerusagetype,
|
310
|
+
discount,
|
311
|
+
purchaseorderno,
|
312
|
+
exemptionno,
|
313
|
+
origincode,
|
314
|
+
destinationcode,
|
315
|
+
addresses,
|
316
|
+
lines,
|
317
|
+
detaillevel,
|
318
|
+
referencecode,
|
319
|
+
hashcode,
|
320
|
+
locationcode,
|
321
|
+
commit,
|
322
|
+
batchcode,
|
323
|
+
taxoverridetype,
|
324
|
+
taxamount,
|
325
|
+
taxdate,
|
326
|
+
reason,
|
327
|
+
currencycode,
|
328
|
+
servicemode,
|
329
|
+
paymentdate,
|
330
|
+
exchangerate,
|
331
|
+
exchangerateeffdate,
|
332
|
+
poslanecode,
|
333
|
+
businessidentificationno,
|
334
|
+
debug,
|
335
|
+
validate)
|
336
|
+
|
337
|
+
|
338
|
+
#Set parms passed by user - If Nil then default else use passed value
|
339
|
+
@adjustmentreason = adjustmentreason == nil ? "" : adjustmentreason
|
340
|
+
@adjustmentdescription = adjustmentdescription == nil ? "" : adjustmentdescription
|
341
|
+
@companycode = companycode == nil ? "" : companycode
|
342
|
+
@doctype = doctype == nil ? "" : doctype
|
343
|
+
@doccode = doccode == nil ? "" : doccode
|
344
|
+
@docdate = docdate == nil ? "" : docdate
|
345
|
+
@salespersoncode = salespersoncode == nil ? "" : salespersoncode
|
346
|
+
@customercode = customercode == nil ? "" : customercode
|
347
|
+
@customerusagetype = customerusagetype == nil ? "" : customerusagetype
|
348
|
+
@discount = discount == nil ? "" : discount
|
349
|
+
@purchaseorderno = purchaseorderno == nil ? "" : purchaseorderno
|
350
|
+
@exemptionno = exemptionno == nil ? "" : exemptionno
|
351
|
+
@origincode = origincode == nil ? "" : origincode
|
352
|
+
@destinationcode = destinationcode == nil ? "" : destinationcode
|
353
|
+
@addresses = addresses == nil ? "" : addresses
|
354
|
+
@lines = lines == nil ? "" : lines
|
355
|
+
@detaillevel = detaillevel == nil ? "" : detaillevel
|
356
|
+
@referencecode = referencecode == nil ? "" : referencecode
|
357
|
+
@hashcode = hashcode == nil ? "" : hashcode
|
358
|
+
@locationcode = locationcode == nil ? "" : locationcode
|
359
|
+
@commit = commit == nil ? "" : commit
|
360
|
+
@batchcode = batchcode == nil ? "" : batchcode
|
361
|
+
@taxoverridetype = taxoverridetype == nil ? "" : taxoverridetype
|
362
|
+
@taxamount = taxamount == nil ? "" : taxamount
|
363
|
+
@taxdate = taxdate == nil ? "" : taxdate
|
364
|
+
@reason = reason == nil ? "" : reason
|
365
|
+
@currencycode = currencycode == nil ? "" : currencycode
|
366
|
+
@servicemode = servicemode == nil ? "" : servicemode
|
367
|
+
@paymentdate = paymentdate == nil ? "" : paymentdate
|
368
|
+
@exchangerate = exchangerate == nil ? "" : exchangerate
|
369
|
+
@exchangerateeffdate = exchangerateeffdate == nil ? "" : exchangerateeffdate
|
370
|
+
@poslanecode = poslanecode == nil ? "" : poslanecode
|
371
|
+
@businessidentificationno = businessidentificationno == nil ? "" : businessidentificationno
|
372
|
+
@debug = debug == nil ? false : debug
|
373
|
+
@validate = validate == nil ? false : validate
|
374
|
+
|
375
|
+
# If vaidate set to true then user has requested address validation before the tax call
|
376
|
+
if @validate
|
377
|
+
if @debug
|
378
|
+
#Use Ruby built in Benchmark function to record response times
|
379
|
+
time = Benchmark.measure do
|
380
|
+
valaddr
|
381
|
+
end
|
382
|
+
if @val_addr[:ResultCode] == "Success"
|
383
|
+
@log.puts "#{Time.now}: Validation OK"
|
384
|
+
else
|
385
|
+
@log.puts "#{Time.now}: Address #{line1}, #{line2}, #{line3}, #{city}, #{region}, #{postalcode}, #{country} failed to validate."
|
386
|
+
end
|
387
|
+
@log.puts "Response times for Address Validation:"
|
388
|
+
@log.puts @responsetime_hdr
|
389
|
+
@log.puts time
|
390
|
+
else
|
391
|
+
#Validate with no benchmarking
|
392
|
+
valaddr
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
# Subsitute template place holders with real values
|
397
|
+
@soap = @template_adjust.result(binding)
|
398
|
+
if debug
|
399
|
+
@log.puts "#{Time.now}: SOAP request created:"
|
400
|
+
@log.puts @soap
|
401
|
+
end
|
402
|
+
|
403
|
+
#Clear return hash
|
404
|
+
@return_data.clear
|
405
|
+
|
406
|
+
# Make the call to the Avalara service
|
407
|
+
begin
|
408
|
+
# Call using debug
|
409
|
+
if debug
|
410
|
+
# Use Ruby built in Benchmark funtion to record response times
|
411
|
+
@log.puts "#{Time.now}: Calling AdjustTax Service for DocCode: #{@doccode}"
|
412
|
+
time = Benchmark.measure do
|
413
|
+
# Call AdjustTax Service
|
414
|
+
@response = @client.call(:adjust_tax, xml: @soap).to_s
|
415
|
+
end
|
416
|
+
@log.puts "Response times for AdjustTax:"
|
417
|
+
@log.puts @responsetime_hdr
|
418
|
+
@log.puts time
|
419
|
+
else
|
420
|
+
# Call AdjustTax Service
|
421
|
+
@response = @client.call(:adjust_tax, xml: @soap).to_s
|
422
|
+
end
|
423
|
+
#Capture unexepected errors
|
424
|
+
rescue
|
425
|
+
@log.puts "#{Time.now}: Error calling AdjustTax service ... check that your account name and password are correct."
|
426
|
+
end
|
427
|
+
|
428
|
+
#Parse the response
|
429
|
+
#Read in an array of XPATH pointers
|
430
|
+
@adjtax_xpath = File.readlines(@def_locn + '/xpath_adjtax.txt')
|
431
|
+
|
432
|
+
# Call using debug
|
433
|
+
if debug
|
434
|
+
# Use Ruby built in Benchmark funtion to record response times
|
435
|
+
@log.puts "#{Time.now}: Parsing the AdjustTax response:"
|
436
|
+
time = Benchmark.measure do
|
437
|
+
# Load the response into a Nokogiri object and remove namespaces
|
438
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
439
|
+
#Parse the returned repsonse and return to caller as a hash
|
440
|
+
@adjtax_xpath.each do |xpath|
|
441
|
+
if xpath.rstrip.length != 0
|
442
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
@log.puts @responsetime_hdr
|
447
|
+
@log.puts time
|
448
|
+
else
|
449
|
+
# Load the response into a Nokogiri object and remove namespaces
|
450
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
451
|
+
#Parse the returned repsonse and return to caller as a hash
|
452
|
+
@adjtax_xpath.each do |xpath|
|
453
|
+
if xpath.rstrip.length != 0
|
454
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
458
|
+
#Return data to calling program
|
459
|
+
return @return_data
|
460
|
+
end
|
461
|
+
|
462
|
+
####################################################################################################
|
463
|
+
# posttax - Calls the Avatax PostTax Service
|
464
|
+
####################################################################################################
|
465
|
+
def posttax(docid,
|
466
|
+
companycode,
|
467
|
+
doctype,
|
468
|
+
doccode,
|
469
|
+
docdate,
|
470
|
+
totalamount,
|
471
|
+
totaltax,
|
472
|
+
hashcode,
|
473
|
+
commit,
|
474
|
+
newdoccode,
|
475
|
+
debug)
|
476
|
+
|
477
|
+
#Set parms passed by user - If Nil then default else use passed value
|
478
|
+
@docid = docid == nil ? "" : docid
|
479
|
+
@companycode = companycode == nil ? "" : companycode
|
480
|
+
@doctype = doctype == nil ? "" : doctype
|
481
|
+
@doccode = doccode == nil ? "" : doccode
|
482
|
+
@docdate = docdate == nil ? "" : docdate
|
483
|
+
@totalamount = totalamount == nil ? "" : totalamount
|
484
|
+
@totaltax = totaltax == nil ? "" : totaltax
|
485
|
+
@hashcode = hashcode == nil ? "" : hashcode
|
486
|
+
@commit = commit == nil ? "" : commit
|
487
|
+
@newdoccode = newdoccode == nil ? "" : newdoccode
|
488
|
+
@debug = debug == nil ? false : debug
|
489
|
+
|
490
|
+
# Subsitute template place holders with real values
|
491
|
+
@soap = @template_post.result(binding)
|
492
|
+
if debug
|
493
|
+
@log.puts "#{Time.now}: SOAP request created:"
|
494
|
+
@log.puts @soap
|
495
|
+
end
|
496
|
+
|
497
|
+
#Clear return hash
|
498
|
+
@return_data.clear
|
499
|
+
|
500
|
+
# Make the call to the Avalara service
|
501
|
+
begin
|
502
|
+
# Call using debug
|
503
|
+
if debug
|
504
|
+
# Use Ruby built in Benchmark funtion to record response times
|
505
|
+
@log.puts "#{Time.now}: Calling PostTax Service for DocCode: #{@doccode}"
|
506
|
+
time = Benchmark.measure do
|
507
|
+
# Call PostTax Service
|
508
|
+
@response = @client.call(:post_tax, xml: @soap).to_s
|
509
|
+
end
|
510
|
+
@log.puts "Response times for PostTax:"
|
511
|
+
@log.puts @responsetime_hdr
|
512
|
+
@log.puts time
|
513
|
+
else
|
514
|
+
# Call PostTax Service
|
515
|
+
@response = @client.call(:post_tax, xml: @soap).to_s
|
516
|
+
end
|
517
|
+
#Capture unexepected errors
|
518
|
+
rescue
|
519
|
+
@log.puts "#{Time.now}: Error calling PostTax service ... check that your account name and password are correct."
|
520
|
+
end
|
521
|
+
|
522
|
+
#Parse the response
|
523
|
+
#Read in an array of XPATH pointers
|
524
|
+
@posttax_xpath = File.readlines(@def_locn + '/xpath_post.txt')
|
525
|
+
|
526
|
+
# Call using debug
|
527
|
+
if debug
|
528
|
+
# Use Ruby built in Benchmark funtion to record response times
|
529
|
+
@log.puts "#{Time.now}: Parsing the PostTax response:"
|
530
|
+
time = Benchmark.measure do
|
531
|
+
# Load the response into a Nokogiri object and remove namespaces
|
532
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
533
|
+
#Parse the returned repsonse and return to caller as a hash
|
534
|
+
@posttax_xpath.each do |xpath|
|
535
|
+
if xpath.rstrip.length != 0
|
536
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
@log.puts @responsetime_hdr
|
541
|
+
@log.puts time
|
542
|
+
else
|
543
|
+
# Load the response into a Nokogiri object and remove namespaces
|
544
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
545
|
+
#Parse the returned repsonse and return to caller as a hash
|
546
|
+
@posttax_xpath.each do |xpath|
|
547
|
+
if xpath.rstrip.length != 0
|
548
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
549
|
+
end
|
550
|
+
end
|
551
|
+
end
|
552
|
+
#Return data to calling program
|
553
|
+
return @return_data
|
554
|
+
end
|
555
|
+
|
556
|
+
####################################################################################################
|
557
|
+
# committax - Calls the Avatax CommitTax Service
|
558
|
+
####################################################################################################
|
559
|
+
def committax(docid,
|
560
|
+
companycode,
|
561
|
+
doctype,
|
562
|
+
doccode,
|
563
|
+
newdoccode,
|
564
|
+
debug)
|
565
|
+
|
566
|
+
#Set parms passed by user - If Nil then default else use passed value
|
567
|
+
@docid = docid == nil ? "" : docid
|
568
|
+
@companycode = companycode == nil ? "" : companycode
|
569
|
+
@doctype = doctype == nil ? "" : doctype
|
570
|
+
@doccode = doccode == nil ? "" : doccode
|
571
|
+
@newdoccode = newdoccode == nil ? "" : newdoccode
|
572
|
+
@debug = debug == nil ? false : debug
|
573
|
+
@message =""
|
574
|
+
|
575
|
+
# Subsitute template place holders with real values
|
576
|
+
@soap = @template_commit.result(binding)
|
577
|
+
if debug
|
578
|
+
@log.puts "#{Time.now}: SOAP request created:"
|
579
|
+
@log.puts @soap
|
580
|
+
end
|
581
|
+
|
582
|
+
#Clear return hash
|
583
|
+
@return_data.clear
|
584
|
+
|
585
|
+
# Make the call to the Avalara service
|
586
|
+
begin
|
587
|
+
# Call using debug
|
588
|
+
if debug
|
589
|
+
# Use Ruby built in Benchmark funtion to record response times
|
590
|
+
@log.puts "#{Time.now}: Calling CommitTax Service for DocCode: #{@doccode}"
|
591
|
+
time = Benchmark.measure do
|
592
|
+
# Call CommitTax Service
|
593
|
+
@response = @client.call(:commit_tax, xml: @soap).to_s
|
594
|
+
end
|
595
|
+
@log.puts "Response times for CommitTax:"
|
596
|
+
@log.puts @responsetime_hdr
|
597
|
+
@log.puts time
|
598
|
+
else
|
599
|
+
# Call CommitTax Service
|
600
|
+
@response = @client.call(:commit_tax, xml: @soap).to_s
|
601
|
+
end
|
602
|
+
#Capture unexepected errors
|
603
|
+
rescue
|
604
|
+
@log.puts "#{Time.now}: Error calling CommitTax service ... check that your account name and password are correct."
|
605
|
+
end
|
606
|
+
|
607
|
+
#Parse the response
|
608
|
+
#Read in an array of XPATH pointers
|
609
|
+
@committax_xpath = File.readlines(@def_locn + '/xpath_commit.txt')
|
610
|
+
|
611
|
+
# Call using debug
|
612
|
+
if debug
|
613
|
+
# Use Ruby built in Benchmark funtion to record response times
|
614
|
+
@log.puts "#{Time.now}: Parsing the commitTax response:"
|
615
|
+
time = Benchmark.measure do
|
616
|
+
# Load the response into a Nokogiri object and remove namespaces
|
617
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
618
|
+
#Parse the returned repsonse and return to caller as a hash
|
619
|
+
@committax_xpath.each do |xpath|
|
620
|
+
if xpath.rstrip.length != 0
|
621
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
622
|
+
end
|
623
|
+
end
|
624
|
+
end
|
625
|
+
@log.puts @responsetime_hdr
|
626
|
+
@log.puts time
|
627
|
+
else
|
628
|
+
# Load the response into a Nokogiri object and remove namespaces
|
629
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
630
|
+
#Parse the returned repsonse and return to caller as a hash
|
631
|
+
@Committax_xpath.each do |xpath|
|
632
|
+
if xpath.rstrip.length != 0
|
633
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
634
|
+
end
|
635
|
+
end
|
636
|
+
end
|
637
|
+
#Return data to calling program
|
638
|
+
return @return_data
|
639
|
+
end
|
640
|
+
|
641
|
+
####################################################################################################
|
642
|
+
# canceltax - Calls the Avatax CancelTax Service
|
643
|
+
####################################################################################################
|
644
|
+
def canceltax(docid,
|
645
|
+
companycode,
|
646
|
+
doctype,
|
647
|
+
doccode,
|
648
|
+
cancelcode,
|
649
|
+
debug)
|
650
|
+
|
651
|
+
#Set parms passed by user - If Nil then default else use passed value
|
652
|
+
@docid = docid == nil ? "" : docid
|
653
|
+
@companycode = companycode == nil ? "" : companycode
|
654
|
+
@doctype = doctype == nil ? "" : doctype
|
655
|
+
@doccode = doccode == nil ? "" : doccode
|
656
|
+
@cancelcode = cancelcode == nil ? "" : cancelcode
|
657
|
+
@debug = debug == nil ? false : debug
|
658
|
+
@message =""
|
659
|
+
|
660
|
+
# Subsitute template place holders with real values
|
661
|
+
@soap = @template_cancel.result(binding)
|
662
|
+
if debug
|
663
|
+
@log.puts "#{Time.now}: SOAP request created:"
|
664
|
+
@log.puts @soap
|
665
|
+
end
|
666
|
+
|
667
|
+
#Clear return hash
|
668
|
+
@return_data.clear
|
669
|
+
|
670
|
+
# Make the call to the Avalara service
|
671
|
+
begin
|
672
|
+
# Call using debug
|
673
|
+
if debug
|
674
|
+
# Use Ruby built in Benchmark funtion to record response times
|
675
|
+
@log.puts "#{Time.now}: Calling CancelTax Service for DocCode: #{@doccode}"
|
676
|
+
time = Benchmark.measure do
|
677
|
+
# Call CancelTax Service
|
678
|
+
@response = @client.call(:cancel_tax, xml: @soap).to_s
|
679
|
+
end
|
680
|
+
@log.puts "Response times for CancelTax:"
|
681
|
+
@log.puts @responsetime_hdr
|
682
|
+
@log.puts time
|
683
|
+
else
|
684
|
+
# Call CancelTax Service
|
685
|
+
@response = @client.call(:cancel_tax, xml: @soap).to_s
|
686
|
+
end
|
687
|
+
#Capture unexepected errors
|
688
|
+
rescue
|
689
|
+
@log.puts "#{Time.now}: Error calling CancelTax service ... check that your account name and password are correct."
|
690
|
+
end
|
691
|
+
|
692
|
+
#Parse the response
|
693
|
+
#Read in an array of XPATH pointers
|
694
|
+
@canceltax_xpath = File.readlines(@def_locn + '/xpath_cancel.txt')
|
695
|
+
|
696
|
+
# Call using debug
|
697
|
+
if debug
|
698
|
+
# Use Ruby built in Benchmark funtion to record response times
|
699
|
+
@log.puts "#{Time.now}: Parsing the CancelTax response:"
|
700
|
+
time = Benchmark.measure do
|
701
|
+
# Load the response into a Nokogiri object and remove namespaces
|
702
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
703
|
+
#Parse the returned repsonse and return to caller as a hash
|
704
|
+
@canceltax_xpath.each do |xpath|
|
705
|
+
if xpath.rstrip.length != 0
|
706
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
707
|
+
end
|
708
|
+
end
|
709
|
+
end
|
710
|
+
@log.puts @responsetime_hdr
|
711
|
+
@log.puts time
|
712
|
+
else
|
713
|
+
# Load the response into a Nokogiri object and remove namespaces
|
714
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
715
|
+
#Parse the returned repsonse and return to caller as a hash
|
716
|
+
@canceltax_xpath.each do |xpath|
|
717
|
+
if xpath.rstrip.length != 0
|
718
|
+
@return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.search(xpath).map{ |n| n.text}
|
719
|
+
end
|
720
|
+
end
|
721
|
+
end
|
722
|
+
#Return data to calling program
|
723
|
+
return @return_data
|
724
|
+
end
|
725
|
+
|
726
|
+
|
727
|
+
####################################################################################################
|
728
|
+
# gettaxhistory - Calls the Avatax GetTaxHistory Service
|
729
|
+
####################################################################################################
|
730
|
+
def gettaxhistory(docid,
|
731
|
+
companycode,
|
732
|
+
doctype,
|
733
|
+
doccode,
|
734
|
+
detaillevel,
|
735
|
+
debug)
|
736
|
+
|
737
|
+
#Set parms passed by user - If Nil then default else use passed value
|
738
|
+
@docid = docid == nil ? "" : docid
|
739
|
+
@companycode = companycode == nil ? "" : companycode
|
740
|
+
@doctype = doctype == nil ? "" : doctype
|
741
|
+
@doccode = doccode == nil ? "" : doccode
|
742
|
+
@detaillevel = detaillevel == nil ? "" : detaillevel
|
743
|
+
@debug = debug == nil ? false : debug
|
744
|
+
|
745
|
+
# Subsitute template place holders with real values
|
746
|
+
@soap = @template_gettaxhistory.result(binding)
|
747
|
+
if debug
|
748
|
+
@log.puts "#{Time.now}: SOAP request created:"
|
749
|
+
@log.puts @soap
|
750
|
+
end
|
751
|
+
|
752
|
+
#Clear return hash
|
753
|
+
@return_data.clear
|
754
|
+
|
755
|
+
# Make the call to the Avalara service
|
756
|
+
begin
|
757
|
+
# Call using debug
|
758
|
+
if debug
|
759
|
+
# Use Ruby built in Benchmark funtion to record response times
|
760
|
+
@log.puts "#{Time.now}: Calling GetTaxHistory Service"
|
761
|
+
time = Benchmark.measure do
|
762
|
+
# Call GetTaxHistory Service
|
763
|
+
@response = @client.call(:get_tax_history, xml: @soap).to_s
|
764
|
+
end
|
765
|
+
@log.puts "Response times for GetTaxHistory:"
|
766
|
+
@log.puts @responsetime_hdr
|
767
|
+
@log.puts time
|
768
|
+
else
|
769
|
+
# Call GetTaxHistory Service
|
770
|
+
@response = @client.call(:get_tax_history, xml: @soap).to_s
|
771
|
+
end
|
772
|
+
#Capture unexepected errors
|
773
|
+
rescue
|
774
|
+
@log.puts "#{Time.now}: Error calling GetTaxHistory service ... check that your account name and password are correct."
|
775
|
+
end
|
776
|
+
|
777
|
+
#Parse the response
|
778
|
+
#Read in an array of XPATH pointers
|
779
|
+
@gettaxhistory_xpath = File.readlines(@def_locn + '/xpath_gettaxhistory.txt')
|
780
|
+
|
781
|
+
# Call using debug
|
782
|
+
if debug
|
783
|
+
# Use Ruby built in Benchmark funtion to record response times
|
784
|
+
@log.puts "#{Time.now}: Parsing the GetTaxHistory response:"
|
785
|
+
time = Benchmark.measure do
|
786
|
+
# Load the response into a Nokogiri object and remove namespaces
|
787
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
788
|
+
#Parse the returned repsonse and return to caller as a hash
|
789
|
+
@gettaxhistory_xpath.each do |xpath|
|
790
|
+
if xpath.rstrip.length != 0
|
791
|
+
@return_data[xpath.gsub('/', '').chomp.gsub('"', '').to_sym] = @doc.search(xpath).map{ |n| n.text}
|
792
|
+
end
|
793
|
+
end
|
794
|
+
end
|
795
|
+
@log.puts @responsetime_hdr
|
796
|
+
@log.puts time
|
797
|
+
else
|
798
|
+
# Load the response into a Nokogiri object and remove namespaces
|
799
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
800
|
+
#Parse the returned repsonse and return to caller as a hash
|
801
|
+
@gettaxhistory_xpath.each do |xpath|
|
802
|
+
if xpath.rstrip.length != 0
|
803
|
+
@return_data[xpath.gsub('/', '').chomp.gsub('"', '').to_sym] = @doc.search(xpath).map{ |n| n.text}
|
804
|
+
end
|
805
|
+
end
|
806
|
+
end
|
807
|
+
#Return data to calling program
|
808
|
+
return @return_data
|
809
|
+
end
|
810
|
+
|
811
|
+
####################################################################################################
|
812
|
+
# reconciletaxhistory - Calls the Avatax ReconcileTaxHistory Service
|
813
|
+
####################################################################################################
|
814
|
+
def reconciletaxhistory(companycode,
|
815
|
+
lastdocid,
|
816
|
+
reconciled,
|
817
|
+
startdate,
|
818
|
+
enddate,
|
819
|
+
docstatus,
|
820
|
+
doctype,
|
821
|
+
lastdoccode,
|
822
|
+
pagesize,
|
823
|
+
debug)
|
824
|
+
|
825
|
+
#Set parms passed by user - If Nil then default else use passed value
|
826
|
+
@companycode = companycode == nil ? "" : companycode
|
827
|
+
@lastdocid = lastdocid == nil ? "" : lastdocid
|
828
|
+
@reconciled = reconciled == nil ? "" : reconciled
|
829
|
+
@startdate = startdate == nil ? "" : startdate
|
830
|
+
@enddate = enddate == nil ? "" : enddate
|
831
|
+
@docstatus = docstatus == nil ? "" : docstatus
|
832
|
+
@doctype = doctype == nil ? "" : doctype
|
833
|
+
@lastdoccode = lastdoccode == nil ? "" : lastdoccode
|
834
|
+
@pagesize = pagesize == nil ? "" : pagesize
|
835
|
+
@debug = debug == nil ? false : debug
|
836
|
+
|
837
|
+
# Subsitute template place holders with real values
|
838
|
+
@soap = @template_reconciletaxhistory.result(binding)
|
839
|
+
if debug
|
840
|
+
@log.puts "#{Time.now}: SOAP request created:"
|
841
|
+
@log.puts @soap
|
842
|
+
end
|
843
|
+
|
844
|
+
#Clear return hash
|
845
|
+
@return_data.clear
|
846
|
+
|
847
|
+
# Make the call to the Avalara service
|
848
|
+
begin
|
849
|
+
# Call using debug
|
850
|
+
if debug
|
851
|
+
# Use Ruby built in Benchmark funtion to record response times
|
852
|
+
@log.puts "#{Time.now}: Calling ReconcileTaxHistory Service"
|
853
|
+
time = Benchmark.measure do
|
854
|
+
# Call ReconcileTaxHistory Service
|
855
|
+
@response = @client.call(:reconcile_tax_history, xml: @soap).to_s
|
856
|
+
end
|
857
|
+
@log.puts "Response times for ReconcileTaxHistory:"
|
858
|
+
@log.puts @responsetime_hdr
|
859
|
+
@log.puts time
|
860
|
+
else
|
861
|
+
# Call ReconcileTaxHistory Service
|
862
|
+
@response = @client.call(:reconcile_tax_history, xml: @soap).to_s
|
863
|
+
end
|
864
|
+
#Capture unexepected errors
|
865
|
+
rescue
|
866
|
+
@log.puts "#{Time.now}: Error calling ReconcileTaxHistory service ... check that your account name and password are correct."
|
867
|
+
end
|
868
|
+
|
869
|
+
#Parse the response
|
870
|
+
#Read in an array of XPATH pointers
|
871
|
+
@reconciletaxhistory_xpath = File.readlines(@def_locn + '/xpath_reconciletaxhistory.txt')
|
872
|
+
|
873
|
+
# Call using debug
|
874
|
+
if debug
|
875
|
+
# Use Ruby built in Benchmark funtion to record response times
|
876
|
+
@log.puts "#{Time.now}: Parsing the ReconcileTaxHistory response:"
|
877
|
+
time = Benchmark.measure do
|
878
|
+
# Load the response into a Nokogiri object and remove namespaces
|
879
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
880
|
+
#Parse the returned repsonse and return to caller as a hash
|
881
|
+
@reconciletaxhistory_xpath.each do |xpath|
|
882
|
+
if xpath.rstrip.length != 0
|
883
|
+
@return_data[xpath.gsub('/', '').chomp.gsub('"', '').to_sym] = @doc.search(xpath).map{ |n| n.text}
|
884
|
+
end
|
885
|
+
end
|
886
|
+
end
|
887
|
+
@log.puts @responsetime_hdr
|
888
|
+
@log.puts time
|
889
|
+
else
|
890
|
+
# Load the response into a Nokogiri object and remove namespaces
|
891
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
892
|
+
#Parse the returned repsonse and return to caller as a hash
|
893
|
+
@reconciletaxhistory_xpath.each do |xpath|
|
894
|
+
if xpath.rstrip.length != 0
|
895
|
+
@return_data[xpath.gsub('/', '').chomp.gsub('"', '').to_sym] = @doc.search(xpath).map{ |n| n.text}
|
896
|
+
end
|
897
|
+
end
|
898
|
+
end
|
899
|
+
#Return data to calling program
|
900
|
+
return @return_data
|
901
|
+
end
|
902
|
+
|
903
|
+
|
904
|
+
############################################################################################################
|
905
|
+
# isauthorized - Verifies connectivity to the web service and returns expiry information about the service.
|
906
|
+
############################################################################################################
|
907
|
+
def isauthorized(operation = nil)
|
908
|
+
#Read in the SOAP template
|
909
|
+
@operation = operation == nil ? "?" : operation
|
910
|
+
|
911
|
+
# Subsitute real vales for template place holders
|
912
|
+
@soap = @template_isauthorized.result(binding)
|
913
|
+
|
914
|
+
#Clear return hash
|
915
|
+
@return_data.clear
|
916
|
+
|
917
|
+
# Make the call to the Avalara service
|
918
|
+
begin
|
919
|
+
@response = @client.call(:is_authorized, xml: @soap).to_s
|
920
|
+
rescue
|
921
|
+
@log.puts "#{Time.now}: Error calling IsAuthorized service ... check username and password"
|
922
|
+
end
|
923
|
+
|
924
|
+
# Load the response into a Nokogiri object and remove namespaces
|
925
|
+
@doc = Nokogiri::XML(@response).remove_namespaces!
|
926
|
+
|
927
|
+
#Read in an array of XPATH pointers
|
928
|
+
@isauthorized_xpath = File.readlines(@def_locn + '/xpath_isauthorized.txt')
|
929
|
+
|
930
|
+
#Read each array element, extract the result returned by the service and place in a the @return_data hash
|
931
|
+
@isauthorized_xpath.each{|xpath| @return_data[xpath.gsub('/', '').chomp.to_sym] = @doc.xpath(xpath).text}
|
932
|
+
|
933
|
+
return @return_data
|
934
|
+
end
|
935
|
+
|
936
|
+
private
|
937
|
+
############################################################################################################
|
938
|
+
# valaddr - Validates an address using the Avatax Address Validation Service
|
939
|
+
############################################################################################################
|
940
|
+
def valaddr
|
941
|
+
@x = 0
|
942
|
+
@addresses.each do |addresscode,line1,line2,line3,city,region,postalcode,country,taxregionid,latitude,longitude,textcase,coordinates,taxability|
|
943
|
+
@log.puts "#{Time.now}: Calling Address Validation Service for Address #{line1}, #{line2}, #{line3}, #{city}, #{region}, #{postalcode}, #{country}"
|
944
|
+
#Call the address validation service
|
945
|
+
@val_addr = AddrService.validate(addresscode,line1,line2,line3,city,region,postalcode,country,taxregionid,latitude,longitude,textcase,coordinates,taxability)
|
946
|
+
#Update address details with the validated results
|
947
|
+
@val_addr.each do
|
948
|
+
@addresses[@x][0] = @val_addr[:AddressCode]
|
949
|
+
@addresses[@x][1] = @val_addr[:Line1]
|
950
|
+
@addresses[@x][2] = @val_addr[:Line2]
|
951
|
+
@addresses[@x][3] = @val_addr[:Line3]
|
952
|
+
@addresses[@x][4] = @val_addr[:City]
|
953
|
+
@addresses[@x][5] = @val_addr[:Region]
|
954
|
+
@addresses[@x][6] = @val_addr[:PostalCode]
|
955
|
+
@addresses[@x][7] = @val_addr[:Country]
|
956
|
+
@addresses[@x][8] = @val_addr[:TaxRegionId]
|
957
|
+
@addresses[@x][9] = @val_addr[:Latitude]
|
958
|
+
@addresses[@x][10] = @val_addr[:Longitude]
|
959
|
+
end
|
960
|
+
@x += @x
|
961
|
+
end
|
962
|
+
end
|
963
|
+
|
964
|
+
end
|
965
|
+
end
|