Git Product home page Git Product logo

tax_cloud's Introduction

TaxCloud

Build Status

TaxCloud is a free service to calculate sales tax and generate tax reports. The tax_cloud gem allows you to easily integrate with TaxCloud's API.

Getting Started

Create a TaxCloud merchant account at http://www.taxcloud.net. Add a website to your account under Locations. This will generate an API ID and API Key that you will need to use the service.

TaxCloud also offers an optional address verification API. To use it, you need a USPS (United States Postal Service) Address API Username. To obtain your USPS Username:

  1. Go through the Web Tools API Portal registration process at https://registration.shippingapis.com/
  2. Once you have registered for your account, you will receive an email with your USPS username and password.
  3. Enter your USPS username in your TaxCloud initializer (see below).

Setup

Add the gem to your Gemfile.

gem 'tax_cloud'

Configure your environment. For example, create an initializer in Rails in config/initializers/tax_cloud.rb.

TaxCloud.configure do |config|
  config.api_login_id = 'your_tax_cloud_api_login_id'
  config.api_key = 'your_tax_cloud_api_key'
  config.usps_username = 'your_usps_username' # optional
  config.open_timeout = 1 # optional
  config.read_timeout = 1 # optional
end

The open_timeout and read_timeout options are used to specify waiting time for the TaxCloud web service response in seconds. Default values: open_timeout = 2 and read_timeout = 2.

Using TaxCloud

Define the destination and origin addresses using TaxCloud::Address.

origin = TaxCloud::Address.new(
  address1: '162 East Avenue',
  address2: 'Third Floor',
  city: 'Norwalk',
  state: 'CT',
  zip5: '06851'
)
destination = TaxCloud::Address.new(
  address1: '3121 West Government Way',
  address2: 'Suite 2B',
  city: 'Seattle',
  state: 'WA',
  zip5: '98199'
)

Create your Transaction and set up your cart items

transaction = TaxCloud::Transaction.new(
  customer_id: '1',
  cart_id: '1',
  origin: origin,
  destination: destination
)
transaction.cart_items << TaxCloud::CartItem.new(
  index: 0,
  item_id: 'SKU-100',
  tic: TaxCloud::TaxCodes::GENERAL,
  price: 10.00,
  quantity: 1
)
lookup = transaction.lookup # this will return a TaxCloud::Responses::Lookup instance
lookup.tax_amount # total tax amount
lookup.cart_items.each do |cart_item|
  cart_item.tax_amount # tax for a single item
end

After you've authorized and captured the transaction via your merchant account, you should do the same with TaxCloud for maintaining accurate tax information.

transaction.order_id = 100
transaction.authorized_with_capture # returns "OK" or raises an error

Later, you may need to mark some cart items as returned. TaxCloud will ignore any cart items that you don't include.

transaction.order_id = 100
transaction.cart_items << TaxCloud::CartItem.new(
  index: 0,
  item_id: 'SKU-100',
  tic: TaxCloud::TaxCodes::GENERAL,
  price: 10.00,
  quantity: 1
)
transaction.returned # returns "OK" or raises an error

Verifying Addresses

TaxCloud optionally integrates with the USPS Address API. An address can be verified, which can also yield a 9-digit zip code that helps determine a more accurate tax rate.

address = TaxCloud::Address.new({
                                  address1: '888 6th Ave',
                                  city: 'New York',
                                  state: 'New York',
                                  zip5: '10001'
                                })

verified_address = address.verify
verified_address.zip5 # 10001
verified_address.zip4 # 3502
verified_address.zip # 10001-3502

Tax Codes

TaxCloud maintains a list of all Taxability Information Codes or TICs, which can be found at https://taxcloud.net/tic.

You can obtain all tax codes as well as lookup a tax code by ID.

TaxCloud::TaxCodes.all # a hash of all codes
tax_code = TaxCloud::TaxCodes[TaxCloud::TaxCodes::DIRECT_MAIL_RELATED]
tax_code.ticid # 11000 or TaxCloud::TaxCodes::DIRECT_MAIL_RELATED
tax_code.description # "Direct-mail related"

Tax codes are organized in groups.

TaxCloud::TaxCode::Groups.all # a hash of all groups
tax_code_group = TaxCloud::TaxCode::Groups[TaxCloud::TaxCode::Groups::SCHOOL_RELATED_PRODUCTS]
tax_code_group.group_id # 3 or TaxCloud::TaxCode::Groups::SCHOOL_RELATED_PRODUCTS
tax_code_group.description # School Related Products
tax_code_group.tax_codes # a hash of all codes in this group

Tax code constants are defined in tax_code_constants.rb and tax code group constants in tax_code_group_constants.rb. These files can be generated by running the following rake tasks.

TAXCLOUD_API_LOGIN_ID=... TAXCLOUD_API_KEY=... TAXCLOUD_USPS_USERNAME=... tax_cloud:tax_codes
TAXCLOUD_API_LOGIN_ID=... TAXCLOUD_API_KEY=... TAXCLOUD_USPS_USERNAME=... tax_cloud:tax_code_groups

Tax States

TaxCloud manages a list of states in which you can calculate sales tax. The default setup will only have SSUTA (Streamlined Sales and Use Tax Agreement) states enabled. All other states will return $0 for tax values. To enable other states, go to https://taxcloud.com/go/states-management/. You can find more information about SSUTA here.

Running Tests

  • VCR and WebMock are used to replay requests and avoid hitting the API each time. To refresh the mocks, simply delete the test/cassettes directory.

  • Run tests. rake test

  • If you need to record new requests against TaxCloud, set your keys first. TAXCLOUD_API_LOGIN_ID=... TAXCLOUD_API_KEY=... TAXCLOUD_USPS_USERNAME=... rake test

    The mocks will filter out your configuration details.

Bugs, fixes, etc

  • Fork.
  • Write test(s).
  • Fix.
  • Commit.
  • Submit pull request.

License

Copyright Drew Tempelmeyer and contributors, 2011-2020.

This gem is licensed under the MIT license.

tax_cloud's People

Contributors

brchristian avatar danielmorrison avatar dblock avatar drewtempelmeyer avatar etagwerker avatar ghepting avatar ka8725 avatar mperham avatar mrmarcondes avatar nononoy avatar paulhenrich avatar rchekaluk avatar soulcutter avatar tagcincy 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tax_cloud's Issues

Reaching timeout on lookup

Sometimes I reach timeout on the transaction lookup call. This mostly happens on my dev machine, we don't have a production server yet so I can't sure that it happens everywhere and either I can't prove that my internet provider's connection is good. But anyway I'm curious about TaxCloud responses. Do they really not provide responses for each request? Are there the service's fails and how often it happens? Sorry for the disturb, but I don't know anybody who has experience with the service. And taht's why I ask you this question, it seems that you have this experience. Thanks for your answer!

I18N "missing translation" for ApiError on master

Apparently my last PR broke the translations for ApiError. My guess is it has something to do with rubocop or a dependency update. The only change to the file in question is the removal of the UTF-8 magic string (should be a no-op in modern ruby) and a whitespace change. I'm going to troubleshoot this a little later.

Just wanted to put a note here in case anyone else is running on master and finds this.

Problem:
  translation missing: en.taxcloud.errors.messages.api_error.message
Summary:
  translation missing: en.taxcloud.errors.messages.api_error.summary
Resolution:
  translation missing: en.taxcloud.errors.messages.api_error.resolution

Dependency versioning too aggressive

The gemspec locks a number of gems with the ~ operator. This is not friendly to applications using this gem. For instance, we use Savon 1.2 but tax_cloud is locked to savon 0.9.x. Another example, Rails 4 applications can't use tax_cloud.

Could the gemspec just lock a minimum version and not prevent future versions of gems?

Unexpected response with transaction without cart items

I was trying to get the tax amount on one of our orders. Building the transaction is an automated process in our system, and our process had a bug in it that tried to lookup the TaxCloud transaction even when the order didn't have any line items. This is the error that was generated:

TaxCloud::Errors::UnexpectedSoapResponse (
Problem:
  Expected a value for `cart_id` in `lookup_response/lookup_result/cart_id` in the TaxCloud response.
Summary:
  TaxCloud returned an unexpected response: `{:lookup_response=>{:lookup_result=>{:response_type=>"OK", :messages=>nil, :cart_items_response=>nil}, :@xmlns=>"http://taxcloud.net"}}`.
Resolution:
  This is possibly a bug in the tax_cloud gem.
 Please report it in https://github.com/drewtempelmeyer/tax_cloud/issues.):

We shouldn't have sent a transaction that didn't have line items in the first place. However, we did send a cart_id, but it seems that TaxCloud's response didn't include it, so the error shown above was very confusing. A more descriptive error when no cart items are sent would probably save a lot of debugging for future developers.

rdoc -> markdown

Quite unusual to still see rdoc in this project. Shall we migrate all .rdoc to markdown?

Getting tax amount of zero on almost every call

Hi,
I am getting 0.0 returned for almost every call I make. The only time I have gotten a real value back is when I use the addresses in the examples. Is there something I need to do with my account to turn on real values?

Thanks, Tom

Add JSON support

Would you be interested in adding support for the json api as well? Or even dropping soap api if json performs better?

Dockerize and Support for Ruby 1.9.3

Thank you for creating this gem. I created an example program to test the gem without mocking out TaxCloud and it works great.

To create my example program I created a Docker container. The only problem is the Docker container is for Ruby 1.9.3, which is the production environment I eventually need to incorporate this gem into. The joys of supporting legacy code. To get everything working I had to deprecate the RuboCop from 0.51.0 to 0.41.2.

The other issue is running the tests results in lots of warnings but no errors. I tried running the tests in Ruby 2.3 and got a similar list of errors. Is there something I'm missing or is everyone getting a bunch of warnings when running the tests?

Would you be interested in a pull request for the Docker Ruby 1.9.3 setup? If so would you like it in a separate Ruby 1.9.3 branch? Thanks.

Return sales tax percentage in response

Based on the question in #28, it would be great to add support to return the calculated sales tax percentage. Since not all items will be taxable, relying on the tax amount and total of the purchase is not accurate.

undefined method 'headers' for http client

This is when doing a address verification...

recently upgraded to rails 4... suspect some gem incompatibility? Help!

NoMethodError: undefined method `headers' for #<HTTP::Client:0x007fac96262b00>
from /Users/mitch/.rvm/gems/ruby-2.2.2/gems/httpi-2.4.1/lib/httpi/adapter/http.rb:72:in `create_client'

Support Savon 2

I've got two gems using Savon in my app, one that requires Savon 2 and this which requires Savon 1. Oops. :-(

Hopefully it's not too much of a lift to get Savon 2 working.

Not an issue, but a quick question

How to you get the actual tax percentage base on address given?

I see tax amount return the calculated tax but i want the actual tax percentage to be show to customer as well. thanks for creating this amazing gem :- )

TaxCloud::TaxCodes::PREPARED_FOOD got tax?

Hi,

I try calling taxCloud with "TaxCloud::TaxCodes::PREPARED_FOOD" [ tic ]
and i got a tax number value return back. Any idea why?
i thought we don't tax on food purchases?

I look thru Groupon site to verify and see that they don't tax food purchase from merchant store.
Any idea what am i missing here? Thanks for your help.
US tax is so complicated and i'm trying to figure out what is taxable and what is not. :- )

Does tax_cloud has the ability to trigger from client side as well?

Hi Drew,

I stumble on http://dev.taxcloud.net/2013/10/03/taxcloud-js_stripe/
and was wondering if you know / some suggestions on what will be the best way to do the same using tax_cloud gem?

currently all the tax calculations get trigger via ajax request to the server and from there i use the tax cloud gem to calculate the request. I was thinking maybe some request will be ideal to trigger it directly from the client side directly to TaxCloud server and not even calling our server at all.

But i want to still use the tax cloud gem if possible for initial connection[passing the api keys].
Was wondering is this possible?

I look thru the page link above and got stuck on :

"Act 1: The Setup".....
If you run PHP on your server, download our TaxCloud.php proxy file
If you run IIS/C#/ASP.NET, download our TaxCloud.aspx proxy file

trying to figure out how to pass in the initial api keys connection using tax cloud gem.
Try contacting taxcloud folks but have not getting any response yet so i figure maybe you encounter this page link before and have some clue/expertise on what direction approach will be the best for client side request only? Not familiar with their php code that is why i got stuck. :- )

Thanks again for your help : - )

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.