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 imajes avatar sosedoff avatar thewalkingtoast avatar tonkpils avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

avalara's Issues

Allow specifying a request timeout

We should be able to set a request timeout for the Avalara API. Currently, I see no way of specifying it. This could be at a global configuration level or on a per request basis.

What are your thoughts for this?

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Invoice object not getting filled

For some reason an apparently successful request (it looks successful - see below) results in the corresonding Avalara::Response::Invoice object with all its fields set to nil instead.

[83, 92] in /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/avalara-0.0.3/lib/avalara.rb
   83        :body => invoice.to_json,
   84        :headers => API.headers_for(invoice.to_json.length),
   85        :basic_auth => authentication
   86      )
   87   debugger
=> 88      return case response.code
   89        when 200..299
   90          Response::Invoice.new(response)
   91        when 400..599
   92          raise ApiError.new(Response::Invoice.new(response))
(rdb:1) response
#<HTTParty::Response:0x7fa8bb7729d0 parsed_response={"ResultCode"=>
"Success", "DocCode"=>"7d9a6855-b504-4b27-93c9-07f08db5359f",
"DocDate"=>"2014-06-09", "Timestamp"=>"2014-06-09T16:51:37.5020571Z", 
"TotalAmount"=>"2", "TotalDiscount"=>"0", "TotalExemption"=>"0",
"TotalTaxable"=>"2", "TotalTax"=>"0.14", "TotalTaxCalculated"=>"0.14",
"TaxLines"=>[{"LineNo"=>"0", "TaxCode"=>"P0000000", 
"Taxability"=>"true", "BoundaryLevel"=>"Address", "Exemption"=>"0", "Discount"=>"0",
"Taxable"=>"2", "Rate"=>"0.070000", "Tax"=>"0.14", "TaxCalculated"=>"0.14", 
"TaxDetails"=>[{"Country"=>"US", "Region"=>"NJ", "JurisType"=>"State", "Taxable"=>"2", 
"Rate"=>"0.070000", "Tax"=>"0.14", "JurisName"=>"NEW JERSEY",
"TaxName"=>"NJ STATE TAX"}]}], "TaxAddresses"=>[{"Address"=>"1111 Bayhill Dr Ste 375", 
"AddressCode"=>"1", "Country"=>"US", "PostalCode"=>"94037", "Region"=>"CA", 
"TaxRegionId"=>"0", "JurisCode"=>"0600000000"}, {"Address"=>"117 Sherbrook Dr Apt 
3B", "AddressCode"=>"2", "City"=>"Berkeley Heights", "Country"=>"US", 
"PostalCode"=>"07922-2347", "Region"=>"NJ", "TaxRegionId"=>"2118369", 
"JurisCode"=>"3400000000"}], "TaxDate"=>"2014-06-09"}, @response=#<Net::HTTPOK 
200 OK readbody=true>, @headers={"cache-control"=>["private"], "content-type"=>
["text/json; charset=utf-8"], "x-aspnet-version"=>["4.0.30319"], "x-powered-by"=>
["ASP.NET"], "date"=>["Mon, 09 Jun 2014 16:51:36 GMT"], "connection"=>["close"], 
"content-length"=>["1098"]}>
(rdb:1) Response::Invoice.new(response)
#<Avalara::Response::Invoice>

Pull request (simple refactor) after tests

Hi. Thanks for the great library. It has been working great.

However, a simple refactoring of moving all the Avalara class methods into a module, would make everything much more flexible. This was induced by a project requirement.

You can see my diff here:
nearapogee@86bc53a

I would like to make a pull request, but VCR is giving me grief. I only get an error message:

 Real HTTP connections are disabled. Unregistered request: POST https://xxx:[email protected]/1.0/tax/get

(redaction mine)

And an advertisement, with a broken link:

You can use VCR to automatically record this request and replay it later.  For more details, visit the VCR documentation at: http://relishapp.com/myronmarston/vr/v/1-11-3

I have used VCR a couple times in the past, but I generally don't use it or RSpec. Could you shed some wisdom on this for me so I can confirm the specs are good?

Rails 5 support

Build seems to be failing. I'll be a new customer soon and was wondering if this has been tested on rails 5.

Add Address Validation

I'd like to add in address validation. Looking at the address that the validation call takes and the address that the tax call takes I think it would be best to create a base_address that can be used for the validation call and extended for the tax call.

Trying to get Avalara to play nice but has hashie gem issue

Hi,

I just try to use this gem and initially there was a hashie gem issue where it could not load file.

Not sure what that mean? Any pointers? not familiar with hashie gem.
Thanks for your help and creating this Avalara gem :- )

Tried this example: got Avalara return nil. (not sure if it did send to Avalara at all)
irb(main):008:0> result = Avalara.geographical_tax('47.627935', '-122.51702', 100)
=> #Avalara::Response::Tax

Tried the second example, got this error "Avalara::Error: cannot load such file -- hashie/extensions/symbolize_keys"

=> #<Avalara::Request::Invoice Addresses=[#<Avalara::Request::Address AddressCode=1 Line1="435 Ericksen Avenue Northeast" Line2="#250" PostalCode="98110">] CompanyCode=1 DocDate="2015-09-28" Lines=[#<Avalara::Request::Line Amount=10 DestinationCode="1" LineNo="1" OriginCode="1" Qty="1">]>
irb(main):078:0> result = Avalara.get_tax(invoice)
Avalara::Error: cannot load such file -- hashie/extensions/symbolize_keys
from /Users/tomtom/workplace/xxx/vendor/gems/avalara/lib/avalara.rb:101:in rescue in get_tax' from /Users/tomtom/workplace/xxx/vendor/gems/avalara/lib/avalara.rb:80:inget_tax'
from (irb):78
from /Users/tomtom/.rvm/gems/ruby-1.9.3-p286@xxx/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in start' from /Users/tomtom/.rvm/gems/ruby-1.9.3-p286@xxx/gems/railties-3.2.11/lib/rails/commands/console.rb:8:instart'
from /Users/tomtom/.rvm/gems/ruby-1.9.3-p286@xxx/gems/railties-3.2.11/lib/rails/commands.rb:41:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `

'
irb(main):079:0>

Hashie uninitialized constant

A recent install of the avalara gem installs hashie 3.5.5 which, when running Avalara::Request::Invoice.new, produces:

uninitialized constant Hashie::Extensions::Coercion::RubyVersion

Locking hashie to 3.4.6 does not produce the issue.

OS: macOS 10.12.3
Ruby: 2.3.3

Status of repo?

Hi Adam,

We've been using your gem for some time. Recently, I've made a number of minor updates to the gem in order to make it work with Ruby 2.2.1. Not sure what the status is and if you are interested in receiving our pull request for the changes we made.

Thanks.

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.