-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetTaxTest.py
130 lines (118 loc) · 2.94 KB
/
GetTaxTest.py
1
2
3
4
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Required Imports
import sys
import urllib2
import urllib
import json
import base64
from credentials import serviceURL, accountNumber, licenseKey
# Required Request Parameters
data = ({
"CustomerCode": "ABC4335",
"DocDate": "2014-01-01",
"CompanyCode": "APITrialCompany",
"Client": "AvaTaxSample",
"DocCode": "INV001",
"DetailLevel": "Tax",
"Commit": "false",
"DocType": "SalesInvoice",
# Situational Request Document Parameters
# "CustomerUsageType": "G",
# "ExemptionNo": "12345",
# "Discount": "50",
# "TaxOverride": {
# "TaxOverrideType": "TaxDate",
# "Reason": "Adjustment for return",
# "TaxDate": "2013-07-01",
# "TaxAmount": "0",
# },
# Optional Request Parameters
"PurchaseOrderNo": "PO123456",
"ReferenceCode": "ref123456",
"PosLaneCode": "09",
"CurrencyCode": "USD",
"Addresses": [
{
"AddressCode": "01",
"Line1": "45 Fremont Street",
"City": "San Francisco",
"Region": "CA" },
{
"AddressCode": "02",
"Line1": "118 N Clark St",
"Line2": "Suite 100",
"Line3": "ATTN Accounts Payable",
"City": "Chicago",
"Region": "IL",
"Country": "US",
"PostalCode": "60602" },
{
"AddressCode": "03",
"Latitude": "47.627935",
"Longitude": "-122.51702" }
],
"Lines": [
{
"LineNo": "01",
"ItemCode": "N543",
"Qty": "1",
"Amount": "10",
"OriginCode": "01",
"DestinationCode": "02",
"Description": "Red Size 7 Widget",
"TaxCode": "NT",
# Situational Request Parameters
# "CustomerUsageType": "L",
# "Discounted": "true",
# "TaxIncluded": "true",
# "TaxOverride":
# {
# "TaxOverrideType": "TaxDate",
# "Reason": "Adjustment for return",
# "TaxDate": "2013-07-01",
# "TaxAmount": "0" },
"Ref1": "ref123",
"Ref2": "ref456" },
{
"LineNo": "02",
"ItemCode": "T345",
"Qty": "3",
"Amount": "150",
"OriginCode": "01",
"DestinationCode": "03",
"Description": " Size 10 Green Running Shoe",
"TaxCode": "PC030147" },
{
"LineNo": "02-FR",
"ItemCode": "FREIGHT",
"Qty": "1",
"Amount": "15",
"OriginCode": "01",
"DestinationCode": "03",
"Description": "Shipping Charge",
"TaxCode": "FR" },
],
})
# Format data
data = json.dumps(data)
# Build Connector
credentials = accountNumber + ':' + licenseKey
authKey = base64.b64encode(credentials)
headers = {"Content-Type":"application/json", "Authorization":"Basic " + authKey}
resource = '/1.0/tax/get'
url = serviceURL + resource
# Submit Request
getTaxRequest = urllib2.Request(url, data, {'Content-Type': 'application/json'})
for key, value in headers.items():
getTaxRequest.add_header(key, value)
try:
response = urllib2.urlopen(getTaxRequest)
# Results and Error Handling
except urllib2.URLError as e:
if hasattr(e, 'code'):
print 'HTTP Error code: ', e.code
print 'Message: ', e.read()
sys.exit()
else:
print "Success"
html = response.read()
print html