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 +15 -0
- data/Avatax_TaxService.gemspec +2 -1
- data/lib/avatax_taxservice.rb +714 -807
- data/test/test_adjtax.rb +95 -87
- data/test/test_gettax.rb +63 -80
- data/test/test_gettaxhistory.rb +27 -25
- data/test/test_reconciletaxhistory.rb +31 -32
- metadata +6 -11
data/test/test_adjtax.rb
CHANGED
@@ -3,100 +3,108 @@ require 'avatax_taxservice'
|
|
3
3
|
#Load the Avalara Address Service module
|
4
4
|
require 'avatax_addressservice'
|
5
5
|
|
6
|
-
#Create
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
#Create new credentials hash object
|
7
|
+
credentials = Hash.new
|
8
|
+
|
9
|
+
#Create new document hash object
|
10
|
+
document = Hash.new
|
11
|
+
|
12
|
+
#Create new address hash object
|
13
|
+
address = Hash.new
|
14
|
+
|
15
|
+
credentials[:username] = 'USERNAME'
|
16
|
+
credentials[:password] = 'PASSWORD'
|
17
|
+
credentials[:name] = 'Avalara Inc.'
|
18
|
+
credentials[:clientname] = 'MyShoppingCart'
|
19
|
+
credentials[:adapter] = 'Avatax SDK for Ruby 1.0.6'
|
20
|
+
credentials[:machine] = 'Lenovo W520 Windows 7'
|
21
|
+
|
22
|
+
#Create a tax service instance
|
23
|
+
TaxServ = AvaTax::TaxService.new(credentials)
|
14
24
|
|
15
25
|
#Create an address service instance
|
16
|
-
AddrService = AvaTax::AddressService.new(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
paymentdate = "2013-09-26"
|
47
|
-
exchangerate = ".0000"
|
48
|
-
exchangerateeffdate = "1900-01-01"
|
49
|
-
poslanecode = ""
|
50
|
-
businessidentificationno = ""
|
51
|
-
debug = true
|
52
|
-
validate = false
|
53
|
-
|
54
|
-
addresses = [
|
26
|
+
AddrService = AvaTax::AddressService.new(credentials)
|
27
|
+
|
28
|
+
#Populate the fields required by the GetTax call
|
29
|
+
document[:adjustmentreason] = "5"
|
30
|
+
document[:adjustmentdescription] = "Hey I adjusted the tax"
|
31
|
+
document[:companycode] = 'APITrialCompany'
|
32
|
+
document[:doctype] = 'SalesInvoice'
|
33
|
+
document[:doccode] = "MyDocCode"
|
34
|
+
document[:docdate] = "2013-10-11"
|
35
|
+
document[:salespersoncode] = "Bill Sales"
|
36
|
+
document[:customercode] = "CUS001"
|
37
|
+
document[:customerusagetype] = ""
|
38
|
+
document[:discount] = ".0000"
|
39
|
+
document[:purchaseorderno]= "PO123456"
|
40
|
+
document[:exemptionno] = ""
|
41
|
+
document[:origincode] = "123"
|
42
|
+
document[:destinationcode] = "456"
|
43
|
+
#Pass addresses as an array
|
44
|
+
# <AddressCode>123</AddressCode>
|
45
|
+
# <Line1>100 Ravine Lane</Line1>
|
46
|
+
# <Line2/>
|
47
|
+
# <Line3/>
|
48
|
+
# <City>Bainbridge Island</City>
|
49
|
+
# <Region>WA</Region>
|
50
|
+
# <PostalCode>98110</PostalCode>
|
51
|
+
# <Country>US</Country>
|
52
|
+
# <TaxRegionId>0</TaxRegionId>
|
53
|
+
# <Latitude/>
|
54
|
+
# <Longitude/>
|
55
|
+
document[:addresses] = [
|
55
56
|
["123", "100 ravine lane", "", "","Bainbridge Island","WA","98110","US","0","",""],
|
56
57
|
["456", "1S278 Wenmoth", "", "","Batavia","IL","60510","US","0","",""]
|
57
58
|
]
|
58
|
-
|
59
|
-
|
59
|
+
#Pass order/invoice lines as an array
|
60
|
+
# <No>1</No>
|
61
|
+
# <OriginCode></OriginCode>
|
62
|
+
# <DestinationCode></DestinationCode>
|
63
|
+
# <ItemCode>Canoe</ItemCode>
|
64
|
+
# <TaxCode></TaxCode>
|
65
|
+
# <Qty>1</Qty>
|
66
|
+
# <Amount>300</Amount>
|
67
|
+
# <Discounted>false</Discounted>
|
68
|
+
# <RevAcct></RevAcct>
|
69
|
+
# <Ref1>ref1</Ref1>
|
70
|
+
# <Ref2>ref2</Ref2>
|
71
|
+
# <ExemptionNo></ExemptionNo>
|
72
|
+
# <CustomerUsageType></CustomerUsageType>
|
73
|
+
# <Description>Blue canoe</Description>
|
74
|
+
# <TaxOverrideType>TaxAmount</TaxOverrideType>
|
75
|
+
# <TaxAmount>10</TaxAmount>
|
76
|
+
# <TaxDate>1900-01-01</TaxDate>
|
77
|
+
# <Reason>Tax Credit</Reason>
|
78
|
+
# <TaxIncluded>false</TaxIncluded>
|
79
|
+
# <BusinessIdentificationNo></BusinessIdentificationNo>
|
80
|
+
document[:lines] = [["1","","","Canoe","","1","300","false","","ref1","ref2","","","Blue canoe","None",".0000","1900-01-01","","false",""],
|
60
81
|
["2","","","Rowing boat","","1","800","false","","ref3","ref4","","","Red rowing boat","None",".0000","1900-01-01","","false",""]
|
61
82
|
]
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
taxoverridetype,
|
88
|
-
taxamount,
|
89
|
-
taxdate,
|
90
|
-
reason,
|
91
|
-
currencycode,
|
92
|
-
servicemode,
|
93
|
-
paymentdate,
|
94
|
-
exchangerate,
|
95
|
-
exchangerateeffdate,
|
96
|
-
poslanecode,
|
97
|
-
businessidentificationno,
|
98
|
-
debug,
|
99
|
-
validate)
|
83
|
+
document[:detaillevel] = "Tax" #The level of detail you want returned by the service
|
84
|
+
document[:referencecode] = "" #Reference code - used for returns
|
85
|
+
document[:hashcode] = "0" #Set to 0
|
86
|
+
document[:locationcode] = "" #Store Location, Outlet Id, or Outlet code.
|
87
|
+
document[:commit] = "false" #Invoice will be committed if this flag has been set to true.
|
88
|
+
document[:batchcode] = "" #Optional Batch Code
|
89
|
+
document[:taxoverridetype] = "None" #Type of TaxOverride
|
90
|
+
document[:taxamount]= ".0000" #The TaxAmount overrides the total tax for the document, if not 0
|
91
|
+
document[:taxdate] = "1900-01-01" #Tax Date is the date used to calculate tax
|
92
|
+
document[:reason] = "" #Reason for applying TaxOverride. = ""
|
93
|
+
document[:currencycode] = "USD" #3 character ISO 4217 currency code (for example, USD)
|
94
|
+
document[:servicemode] = "Remote" #All lines are calculated by AvaTax remote server
|
95
|
+
document[:paymentdate] = "2013-09-26" #Indicates the date payment was applied to this invoice
|
96
|
+
document[:exchangerate] = ".0000" #Indicates the currency exchange rate
|
97
|
+
document[:exchangerateeffdate] = "1900-01-01" #Indicates the effective date of the exchange rate.
|
98
|
+
document[:poslanecode] = "" #Optional POS Lane Code
|
99
|
+
document[:businessidentificationno] = "" #Optional Business Identification Number
|
100
|
+
document[:debug] = false #Run in debug move - writes data to tax_log.txt
|
101
|
+
document[:validate]= false #If true - addresses will be validated before the tax call
|
102
|
+
|
103
|
+
#Create empty hash for the tax result details
|
104
|
+
tax_result = Hash.new
|
105
|
+
|
106
|
+
#Call the tax service
|
107
|
+
tax_result = TaxServ.gettax(document)
|
100
108
|
|
101
109
|
require 'pp'
|
102
110
|
pp tax_result
|
data/test/test_gettax.rb
CHANGED
@@ -3,31 +3,42 @@ require 'avatax_taxservice'
|
|
3
3
|
#Load the Avalara Address Service module - optional
|
4
4
|
require 'avatax_addressservice'
|
5
5
|
|
6
|
-
#Create
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
#Create new credentials hash object
|
7
|
+
credentials = Hash.new
|
8
|
+
|
9
|
+
#Create new document hash object
|
10
|
+
document = Hash.new
|
11
|
+
|
12
|
+
#Create new address hash object
|
13
|
+
address = Hash.new
|
14
|
+
|
15
|
+
credentials[:username] = 'grahamw'
|
16
|
+
credentials[:password] = 'Avalara1!'
|
17
|
+
credentials[:name] = 'Avalara Inc.'
|
18
|
+
credentials[:clientname] = 'MyShoppingCart'
|
19
|
+
credentials[:adapter] = 'Avatax SDK for Ruby 1.0.6'
|
20
|
+
credentials[:machine] = 'Lenovo W520 Windows 7'
|
21
|
+
|
22
|
+
#Create a tax service instance
|
23
|
+
TaxServ = AvaTax::TaxService.new(credentials)
|
24
|
+
|
25
|
+
#Create an address service instance
|
26
|
+
AddrService = AvaTax::AddressService.new(credentials)
|
17
27
|
|
18
28
|
#Populate the fields required by the GetTax call
|
19
|
-
companycode = '
|
20
|
-
doctype =
|
21
|
-
doccode = "MyDocCode"
|
22
|
-
docdate = "2013-10-11"
|
23
|
-
salespersoncode = "Bill Sales"
|
24
|
-
customercode = "CUS001"
|
25
|
-
customerusagetype = ""
|
26
|
-
discount = ".0000"
|
27
|
-
purchaseorderno
|
28
|
-
exemptionno = ""
|
29
|
-
origincode = "123"
|
30
|
-
destinationcode = "456"
|
29
|
+
document[:companycode] = '1'
|
30
|
+
document[:doctype] = 'SalesInvoice'
|
31
|
+
document[:doccode] = "MyDocCode"
|
32
|
+
document[:docdate] = "2013-10-11"
|
33
|
+
document[:salespersoncode] = "Bill Sales"
|
34
|
+
document[:customercode] = "CUS001"
|
35
|
+
document[:customerusagetype] = ""
|
36
|
+
document[:discount] = ".0000"
|
37
|
+
document[:purchaseorderno]= "PO123456"
|
38
|
+
document[:exemptionno] = ""
|
39
|
+
document[:origincode] = "123"
|
40
|
+
document[:destinationcode] = "456"
|
41
|
+
|
31
42
|
#Pass addresses as an array
|
32
43
|
# <AddressCode>123</AddressCode>
|
33
44
|
# <Line1>100 Ravine Lane</Line1>
|
@@ -40,10 +51,11 @@ destinationcode = "456" #Destination or ship to code - you make it u
|
|
40
51
|
# <TaxRegionId>0</TaxRegionId>
|
41
52
|
# <Latitude/>
|
42
53
|
# <Longitude/>
|
43
|
-
addresses
|
54
|
+
document[:addresses]= [
|
44
55
|
["123", "100 ravine lane", "", "","Bainbridge Island","WA","98110","US","0","",""],
|
45
56
|
["456", "7070 West Arlington Drive", "", "","Lakewood","CO","80123","US","0","",""]
|
46
57
|
]
|
58
|
+
|
47
59
|
#Pass order/invoice lines as an array
|
48
60
|
# <No>1</No>
|
49
61
|
# <OriginCode></OriginCode>
|
@@ -64,66 +76,37 @@ addresses = [
|
|
64
76
|
# <TaxDate>1900-01-01</TaxDate>
|
65
77
|
# <Reason>Tax Credit</Reason>
|
66
78
|
# <TaxIncluded>false</TaxIncluded>
|
67
|
-
# <BusinessIdentificationNo></BusinessIdentificationNo>
|
68
|
-
lines = [
|
79
|
+
# <BusinessIdentificationNo></BusinessIdentificationNo>
|
80
|
+
document[:lines] = [
|
69
81
|
["1","","","Canoe","","1","300.43","false","","ref1","ref2","","","Blue canoe","TaxAmount","10","1900-01-01","Tax credit","false",""],
|
70
82
|
["2","","","Rowing boat","","1","800.12","false","","ref3","ref4","","","Red rowing boat","None",".0000","1900-01-01","","false",""]
|
71
83
|
]
|
72
|
-
detaillevel = "Tax" #The level of detail you want returned by the service
|
73
|
-
referencecode = "" #Reference code - used for returns
|
74
|
-
hashcode = "0" #Set to 0
|
75
|
-
locationcode = "" #Store Location, Outlet Id, or Outlet code.
|
76
|
-
commit = "false" #Invoice will be committed if this flag has been set to true.
|
77
|
-
batchcode = "" #Optional Batch Code
|
78
|
-
taxoverridetype = "None" #Type of TaxOverride
|
79
|
-
taxamount
|
80
|
-
taxdate = "1900-01-01" #Tax Date is the date used to calculate tax
|
81
|
-
reason = "" #Reason for applying TaxOverride.
|
82
|
-
currencycode = "USD" #3 character ISO 4217 currency code (for example, USD)
|
83
|
-
servicemode = "Remote" #All lines are calculated by AvaTax remote server
|
84
|
-
paymentdate = "2013-09-26" #Indicates the date payment was applied to this invoice
|
85
|
-
exchangerate = ".0000" #Indicates the currency exchange rate
|
86
|
-
exchangerateeffdate = "1900-01-01" #Indicates the effective date of the exchange rate.
|
87
|
-
poslanecode = "" #Optional POS Lane Code
|
88
|
-
businessidentificationno = "" #Optional Business Identification Number
|
89
|
-
debug =
|
90
|
-
validate
|
84
|
+
document[:detaillevel] = "Tax" #The level of detail you want returned by the service
|
85
|
+
document[:referencecode] = "" #Reference code - used for returns
|
86
|
+
document[:hashcode] = "0" #Set to 0
|
87
|
+
document[:locationcode] = "" #Store Location, Outlet Id, or Outlet code.
|
88
|
+
document[:commit] = "false" #Invoice will be committed if this flag has been set to true.
|
89
|
+
document[:batchcode] = "" #Optional Batch Code
|
90
|
+
document[:taxoverridetype] = "None" #Type of TaxOverride
|
91
|
+
document[:taxamount]= ".0000" #The TaxAmount overrides the total tax for the document, if not 0
|
92
|
+
document[:taxdate] = "1900-01-01" #Tax Date is the date used to calculate tax
|
93
|
+
document[:reason] = "" #Reason for applying TaxOverride. = ""
|
94
|
+
document[:currencycode] = "USD" #3 character ISO 4217 currency code (for example, USD)
|
95
|
+
document[:servicemode] = "Remote" #All lines are calculated by AvaTax remote server
|
96
|
+
document[:paymentdate] = "2013-09-26" #Indicates the date payment was applied to this invoice
|
97
|
+
document[:exchangerate] = ".0000" #Indicates the currency exchange rate
|
98
|
+
document[:exchangerateeffdate] = "1900-01-01" #Indicates the effective date of the exchange rate.
|
99
|
+
document[:poslanecode] = "" #Optional POS Lane Code
|
100
|
+
document[:businessidentificationno] = "" #Optional Business Identification Number
|
101
|
+
document[:debug] = true #Run in debug move - writes data to tax_log.txt
|
102
|
+
document[:validate]= false #If true - addresses will be validated before the tax call
|
103
|
+
|
91
104
|
|
92
105
|
#Create empty hash for the tax result details
|
93
|
-
tax_result =
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
docdate,
|
98
|
-
salespersoncode,
|
99
|
-
customercode,
|
100
|
-
customerusagetype,
|
101
|
-
discount,
|
102
|
-
purchaseorderno,
|
103
|
-
exemptionno,
|
104
|
-
origincode,
|
105
|
-
destinationcode,
|
106
|
-
addresses,
|
107
|
-
lines,
|
108
|
-
detaillevel,
|
109
|
-
referencecode,
|
110
|
-
hashcode,
|
111
|
-
locationcode,
|
112
|
-
commit,
|
113
|
-
batchcode,
|
114
|
-
taxoverridetype,
|
115
|
-
taxamount,
|
116
|
-
taxdate,
|
117
|
-
reason,
|
118
|
-
currencycode,
|
119
|
-
servicemode,
|
120
|
-
paymentdate,
|
121
|
-
exchangerate,
|
122
|
-
exchangerateeffdate,
|
123
|
-
poslanecode,
|
124
|
-
businessidentificationno,
|
125
|
-
debug,
|
126
|
-
validate)
|
106
|
+
tax_result = Hash.new
|
107
|
+
|
108
|
+
#Call the tax service
|
109
|
+
tax_result = TaxServ.gettax(document)
|
127
110
|
|
128
111
|
#Print out the returned hash
|
129
112
|
require 'pp'
|
@@ -131,7 +114,7 @@ pp tax_result
|
|
131
114
|
puts
|
132
115
|
|
133
116
|
#Always check the result code
|
134
|
-
if tax_result[:ResultCode]
|
117
|
+
if tax_result[:ResultCode] == ["Success"]
|
135
118
|
puts "The GetTax call was successful"
|
136
119
|
else
|
137
120
|
puts "The GetTax call failed"
|
data/test/test_gettaxhistory.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
1
|
#Load the Avalara Address Service module
|
2
2
|
require 'avatax_taxservice'
|
3
3
|
|
4
|
-
#Create
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
debug = false
|
20
|
-
|
21
|
-
tax_result = {}
|
22
|
-
#Call the gettax service
|
23
|
-
tax_result = TaxServ.gettaxhistory(docid,
|
24
|
-
companycode,
|
25
|
-
doctype,
|
26
|
-
doccode,
|
27
|
-
detaillevel,
|
28
|
-
debug)
|
4
|
+
#Create new credentials hash object
|
5
|
+
credentials = Hash.new
|
6
|
+
|
7
|
+
#Create new document hash object
|
8
|
+
document = Hash.new
|
9
|
+
|
10
|
+
credentials[:username] = 'USERNAME'
|
11
|
+
credentials[:password] = 'PASSWORD'
|
12
|
+
credentials[:name] = 'Avalara Inc.'
|
13
|
+
credentials[:clientname] = 'MyShoppingCart'
|
14
|
+
credentials[:adapter] = 'Avatax SDK for Ruby 1.0.6'
|
15
|
+
credentials[:machine] = 'Lenovo W520 Windows 7'
|
16
|
+
|
17
|
+
#Create a tax service instance
|
18
|
+
TaxServ = AvaTax::TaxService.new(credentials)
|
29
19
|
|
20
|
+
document[:docid] = "99999999"
|
21
|
+
document[:companycode] = 'APITrialCompany'
|
22
|
+
document[:doctype] = 'SalesInvoice'
|
23
|
+
document[:doccode] = ""
|
24
|
+
document[:detaillevel] = "Line"
|
25
|
+
document[:debug] = false
|
26
|
+
|
27
|
+
#Create empty hash for the tax result details
|
28
|
+
tax_result = Hash.new
|
29
|
+
|
30
|
+
#Call the gettax service
|
31
|
+
tax_result = TaxServ.gettaxhistory(document)
|
30
32
|
|
31
33
|
require 'pp'
|
32
34
|
pp tax_result
|
@@ -1,39 +1,38 @@
|
|
1
1
|
#Load the Avalara Address Service module
|
2
2
|
require 'avatax_taxservice'
|
3
3
|
|
4
|
-
#Create
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
lastdoccode,
|
34
|
-
pagesize,
|
35
|
-
debug)
|
4
|
+
#Create new credentials hash object
|
5
|
+
credentials = Hash.new
|
6
|
+
|
7
|
+
#Create new document hash object
|
8
|
+
document = Hash.new
|
9
|
+
|
10
|
+
credentials[:username] = 'USERNAME'
|
11
|
+
credentials[:password] = 'PASSWORD'
|
12
|
+
credentials[:name] = 'Avalara Inc.'
|
13
|
+
credentials[:clientname] = 'MyShoppingCart'
|
14
|
+
credentials[:adapter] = 'Avatax SDK for Ruby 1.0.6'
|
15
|
+
credentials[:machine] = 'Lenovo W520 Windows 7'
|
16
|
+
|
17
|
+
#Create a tax service instance
|
18
|
+
TaxServ = AvaTax::TaxService.new(credentials)
|
19
|
+
|
20
|
+
document[:companycode] = 'APITrialCompany'
|
21
|
+
document[:lastdocid] = '99999999'
|
22
|
+
document[:reconciled] = false
|
23
|
+
document[:startdate] = '2013-01-01'
|
24
|
+
document[:enddate] = '2013-10-15'
|
25
|
+
document[:docstatus] = "Any"
|
26
|
+
document[:doctype] = 'SalesInvoice'
|
27
|
+
document[:lastdoccode] = ''
|
28
|
+
document[:pagesize] = '1'
|
29
|
+
document[:debug] = true
|
30
|
+
|
31
|
+
#Create empty hash for the tax result details
|
32
|
+
tax_result = Hash.new
|
36
33
|
|
34
|
+
#Call the gettax service
|
35
|
+
tax_result = TaxServ.reconciletaxhistory(document)
|
37
36
|
|
38
37
|
require 'pp'
|
39
38
|
pp tax_result
|