TaxCloud is a service to calculate sales tax and generate tax reports. tax_cloud allows you to easily integrate with TaxCloud's API.
Add the gem to your Gemfile
gem 'tax_cloud', '~> 0.1.5'
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' end
Define the destination and origin addresses using TaxCloud::Address.
origin = TaxCloud::Address.new(:address1 => '123 Fake Street', :city => 'New York', :state => 'NY', :zip5 => '10001') destination = TaxCloud::Address.new(:address1 => '239 Hollywood Drive', :city => 'Beverly Hills', :state => 'CA', :zip5 => '90210')
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 Savon response object
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 # return Savon response object
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 # return Savon response object
Add your config details to test/helper
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.
The mocks will filter out your config details, but remember not to commit them!
run rake test
Instead of returning Savon response objects, it should return TransactionLookupResponse, TransactionAuthorizedResponse, TransactionCapturedResponse, etc.
Add all tax codes to TaxCloud::TaxCodes
Bugs, fixes, etc
Submit pull request.