Avatax
This gem is a work in progress for providing a ruby client for Avatax REST api v2. See: http://developer.avalara.com/avatax/api-reference/tax/v2/
Installation
Add this line to your application's Gemfile:
gem 'avatax-ruby', git: 'git@github.com:skukx/avatax.git'
Or
gem 'avatax-ruby'
And then execute:
$ bundle
Usage
Setting Up the client
client = Avatax::Client.new(
username: 'avatax_user',
password: 'avatax_password',
logger: Logger.new(STDOUT),
env: :sandbox
)
The env
can be set to :sandbox
or :production
.
Estimating Taxes
##
# Estimate by address
# @see http://developer.avalara.com/avatax/api-reference/tax/v2/TaxRates/#ApiV2TaxratesByaddressGet
#
params = {
line1: '350 State St.',
city: 'Salt Lake City',
region: 'CA',
postalCode: '84111',
country: 'US'
}
resp = client.tax_rates.get(:by_address, params)
##
# Estimate by postal code
# @see http://developer.avalara.com/avatax/api-reference/tax/v2/TaxRates/#ApiV2TaxratesBypostalcodeGet
#
params = { country: 'US', postalCode: '84111' }
resp = client.tax_rates.get(:by_postal_code, params)
resp.success? # => true
Transactions
Get all transactions within a company.
client.transactions.all('my_company')
Find a transaction by code
client.transactions.find_by_code('my_company', 'transaction_code')
Find a transaction by avatax id.
client.transactions.find_by_id('my_company', '123')
Adjust an existing transaction.
params = {
adjustmentReason: 8,
adjustmentDescription: 'New line item.',
new_transaction: { ... }
}
client.transactions.adjust('my_company', 'my_code', params)
Change a transaction code
params = { newCode: 'my_new_code' }
client.transactions.change_code('my_company', 'my_code', params)
Commit a transaction
By default, if not present, the post request will contain the body { commit: true }
client.transactions.commit('my_company', 'my_code')
Settle a transaction
This call can perform multiple actions on a transaction. See avatax docs for more information.
params = { ... }
client.transactions.settle('my_company', 'my_code', params)
Void a transaction.
client.transactions.void('my_company', 'my_code')
Create a transaction
params = {
code: 'my_code',
type: 'SalesInvoice',
companyCode: 'my_company',
date: Date.current.to_s,
customerCode: 1,
discount: 0.00,
addresses: {
ShipTo: {
line1: '50 Main street',
city: 'Salt Lake City',
region: 'UT',
country: 'US',
postalCode: '84144'
}
},
lines: [
{
amount: 9.99,
quantity: 1
}
]
}
client.transactions.create(params)
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/avatax.
License
The gem is available as open source under the terms of the MIT License.