Skip to content

Instantly share code, notes, and snippets.

@joshnuss
Created June 11, 2013 00:36
Show Gist options
  • Save joshnuss/5753667 to your computer and use it in GitHub Desktop.
Save joshnuss/5753667 to your computer and use it in GitHub Desktop.
require 'avalara'
Avalara.username = "user@example.com"
Avalara.password = 'pass'
Avalara.endpoint = 'https://development.avalara.net' # this is the test url, in production use https://rest.avalara.net
invoice = Avalara::Request::Invoice.new(customer_code: 'customer@example.com')
origin = Avalara::Request::Address.new(address_code: 1, line1: '1600 Amphitheatre Pkwy', city: 'Mountain View', region: 'CA', country: 'USA', postal_code: '94043')
destination = Avalara::Request::Address.new(address_code: 2, line1: '1 Infinite Loop', city: 'Cupertino', region: 'CA', country: 'USA', postal_code: '95014')
line = Avalara::Request::Line.new(line_no: 1, destination_code: 2, origin_code: 1, item_code: 'X123', description: 'T-Shirt', qty: 1, amount: 9.99)
invoice.addresses = [origin, destination]
invoice.lines = [line]
response = Avalara.get_tax(invoice)
total_tax = response.tax_lines.inject(0) {|sum, line| sum + line.tax.to_f }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment