https://github.com/skukx/avatax
Ruby client for avatax
https://github.com/skukx/avatax
api-client avalara avatax ruby
Last synced: 10 months ago
JSON representation
Ruby client for avatax
- Host: GitHub
- URL: https://github.com/skukx/avatax
- Owner: skukx
- License: mit
- Created: 2017-04-09T03:29:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-08-14T22:46:08.000Z (almost 3 years ago)
- Last Synced: 2024-12-01T01:12:12.138Z (over 1 year ago)
- Topics: api-client, avalara, avatax, ruby
- Language: Ruby
- Size: 58.6 KB
- Stars: 0
- Watchers: 2
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Avatax
[](https://circleci.com/gh/skukx/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:
```ruby
gem 'avatax-ruby', git: 'git@github.com:skukx/avatax.git'
```
Or
```ruby
gem 'avatax-ruby'
```
And then execute:
$ bundle
## Usage
### Setting Up the client
```ruby
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
```ruby
##
# 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.
```ruby
client.transactions.all('my_company')
```
#### Find a transaction by code
```ruby
client.transactions.find_by_code('my_company', 'transaction_code')
```
#### Find a transaction by avatax id.
```ruby
client.transactions.find_by_id('my_company', '123')
```
#### Adjust an existing transaction.
```ruby
params = {
adjustmentReason: 8,
adjustmentDescription: 'New line item.',
new_transaction: { ... }
}
client.transactions.adjust('my_company', 'my_code', params)
```
#### Change a transaction code
```ruby
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 }`
```ruby
client.transactions.commit('my_company', 'my_code')
```
#### Settle a transaction
This call can perform multiple actions on a transaction. See [avatax docs](https://developer.avalara.com/avatax/api-reference/tax/v2/Transactions/#SettleTransaction) for more information.
```ruby
params = { ... }
client.transactions.settle('my_company', 'my_code', params)
```
#### Void a transaction.
```ruby
client.transactions.void('my_company', 'my_code')
```
#### Create a transaction
```ruby
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](https://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](http://opensource.org/licenses/MIT).