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/
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
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
.
##
# 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
client.transactions.all('my_company')
client.transactions.find_by_code('my_company', 'transaction_code')
client.transactions.find_by_id('my_company', '123')
params = {
adjustmentReason: 8,
adjustmentDescription: 'New line item.',
new_transaction: { ... }
}
client.transactions.adjust('my_company', 'my_code', params)
params = { newCode: 'my_new_code' }
client.transactions.change_code('my_company', 'my_code', params)
By default, if not present, the post request will contain the body { commit: true }
client.transactions.commit('my_company', 'my_code')
This call can perform multiple actions on a transaction. See avatax docs for more information.
params = { ... }
client.transactions.settle('my_company', 'my_code', params)
client.transactions.void('my_company', 'my_code')
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)
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/avatax.
The gem is available as open source under the terms of the MIT License.