GithubHelp home page GithubHelp logo

avalara's Introduction

Avalara gem

This API provides access to the Avalara AvaTax API.

Build Status

Setup

Add the gem to your Gemfile.

gem 'avalara'

Setup your Avalara credentials, either in a yml file, or as environment variables. If you want to add a yml file, it'll just need username and password:

username: 'testaccount'
password: 'testkey'

You can also specify a different endpoint for development mode:

endpoint: https://development.avalara.net

Setup the gem in an initializer (if using Rails), or wherever if you're not. You can load in your username/password however you want, but here's a sample way to do this:

file = File.new(File.join(Rails.root, 'config', 'avalara.yml'))

if file.exist?
  begin
    AVALARA_CONFIGURATION = YAML.load_file(path)
    Avalara.configure do |config|
      config.username = AVALARA_CONFIGURATION['username'] || abort("Avalara configuration file (#{path}) is missing the username value.")
      config.password = AVALARA_CONFIGURATION['password'] || abort("Avalara configuration file (#{path}) is missing the password value.")
      config.version = AVALARA_CONFIGURATION['version'] if AVALARA_CONFIGURATION.has_key?('version')
      config.endpoint = AVALARA_CONFIGURATION['endpoint'] if AVALARA_CONFIGURATION.has_key?('endpoint')
    end
  end
else
  abort "Avalara configuration not found."
end

Usage

After that you should be able to use a few endpoints to Avalaras tax service. If you need a new endpoint, feel free to fork this gem, add support for it, add specs and do a pull request back.

Geographical Tax

result = Avalara.geographical_tax('47.627935', '-122.51702', 100)

# Access the details of the result, which is a Avalara::Response::Tax object
result.rate
result.tax
result.tax_details

Get Tax

line = Avalara::Request::Line.new({  
  line_no: "1",
  destination_code: "1",
  origin_code: "1",
  qty: "1",
  amount: 10
})

address = Avalara::Request::Address.new({
  address_code: 1,
  line_1: "435 Ericksen Avenue Northeast",
  line_2: "#250",
  postal_code: "98110"
})

invoice = Avalara::Request::Invoice.new({
  doc_date: Time.now,
  company_code: 1,
  lines: [line],
  addresses: [address]
})

# You'll get back a Response::Invoice object
result = Avalara.get_tax(invoice)

result.result_code
result.total_amount
result.total_tax
result.total_tax_calculated

Contributing

If you want to contribute, please fork this repo and make a pull request back. If you add some specs and everything still passes, we can get your contribution in! Thanks to everyone who has contributed:

avalara's People

Contributors

adamfortuna avatar brandon300055 avatar ice799 avatar imajes avatar sosedoff avatar thewalkingtoast avatar tonkpils avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.