Avatax_TaxService 1.0.4 → 1.0.7

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