项目作者: skukx

项目描述 :
Ruby client for avatax
高级语言: Ruby
项目地址: git://github.com/skukx/avatax.git
创建时间: 2017-04-09T03:29:29Z
项目社区:https://github.com/skukx/avatax

开源协议:MIT License

下载


Avatax

CircleCI

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:

  1. gem 'avatax-ruby', git: 'git@github.com:skukx/avatax.git'

Or

  1. gem 'avatax-ruby'

And then execute:

  1. $ bundle

Usage

Setting Up the client

  1. client = Avatax::Client.new(
  2. username: 'avatax_user',
  3. password: 'avatax_password',
  4. logger: Logger.new(STDOUT),
  5. env: :sandbox
  6. )

The env can be set to :sandbox or :production.

Estimating Taxes

  1. ##
  2. # Estimate by address
  3. # @see http://developer.avalara.com/avatax/api-reference/tax/v2/TaxRates/#ApiV2TaxratesByaddressGet
  4. #
  5. params = {
  6. line1: '350 State St.',
  7. city: 'Salt Lake City',
  8. region: 'CA',
  9. postalCode: '84111',
  10. country: 'US'
  11. }
  12. resp = client.tax_rates.get(:by_address, params)
  13. ##
  14. # Estimate by postal code
  15. # @see http://developer.avalara.com/avatax/api-reference/tax/v2/TaxRates/#ApiV2TaxratesBypostalcodeGet
  16. #
  17. params = { country: 'US', postalCode: '84111' }
  18. resp = client.tax_rates.get(:by_postal_code, params)
  19. resp.success? # => true

Transactions

Get all transactions within a company.

  1. client.transactions.all('my_company')

Find a transaction by code

  1. client.transactions.find_by_code('my_company', 'transaction_code')

Find a transaction by avatax id.

  1. client.transactions.find_by_id('my_company', '123')

Adjust an existing transaction.

  1. params = {
  2. adjustmentReason: 8,
  3. adjustmentDescription: 'New line item.',
  4. new_transaction: { ... }
  5. }
  6. client.transactions.adjust('my_company', 'my_code', params)

Change a transaction code

  1. params = { newCode: 'my_new_code' }
  2. 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 }

  1. 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.

  1. params = { ... }
  2. client.transactions.settle('my_company', 'my_code', params)

Void a transaction.

  1. client.transactions.void('my_company', 'my_code')

Create a transaction

  1. params = {
  2. code: 'my_code',
  3. type: 'SalesInvoice',
  4. companyCode: 'my_company',
  5. date: Date.current.to_s,
  6. customerCode: 1,
  7. discount: 0.00,
  8. addresses: {
  9. ShipTo: {
  10. line1: '50 Main street',
  11. city: 'Salt Lake City',
  12. region: 'UT',
  13. country: 'US',
  14. postalCode: '84144'
  15. }
  16. },
  17. lines: [
  18. {
  19. amount: 9.99,
  20. quantity: 1
  21. }
  22. ]
  23. }
  24. 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.