corgibytes-tax_cloud 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +17 -0
  2. data/.circleci/config.yml +81 -0
  3. data/.circleci/setup-rubygems.sh +9 -0
  4. data/.gitignore +67 -0
  5. data/.rubocop.yml +6 -0
  6. data/.rubocop_todo.yml +66 -0
  7. data/.travis.yml +7 -0
  8. data/CHANGELOG.rdoc +48 -0
  9. data/CONTRIBUTORS.txt +23 -0
  10. data/Dockerfile +9 -0
  11. data/Gemfile +22 -0
  12. data/LICENSE +23 -0
  13. data/README.md +190 -0
  14. data/Rakefile +29 -0
  15. data/docker-compose.yml +10 -0
  16. data/examples/.env.example +2 -0
  17. data/examples/lookup_example.rb +139 -0
  18. data/lib/config/locales/en.yml +34 -0
  19. data/lib/hash.rb +8 -0
  20. data/lib/savon_soap_xml.rb +32 -0
  21. data/lib/tasks/tax_cloud.rake +18 -0
  22. data/lib/tasks/tax_code_groups.rake +37 -0
  23. data/lib/tasks/tax_codes.rake +43 -0
  24. data/lib/tax_cloud.rb +70 -0
  25. data/lib/tax_cloud/address.rb +50 -0
  26. data/lib/tax_cloud/cart_item.rb +26 -0
  27. data/lib/tax_cloud/client.rb +60 -0
  28. data/lib/tax_cloud/configuration.rb +28 -0
  29. data/lib/tax_cloud/errors.rb +6 -0
  30. data/lib/tax_cloud/errors/api_error.rb +17 -0
  31. data/lib/tax_cloud/errors/missing_config_error.rb +13 -0
  32. data/lib/tax_cloud/errors/missing_config_option_error.rb +19 -0
  33. data/lib/tax_cloud/errors/soap_error.rb +30 -0
  34. data/lib/tax_cloud/errors/tax_cloud_error.rb +83 -0
  35. data/lib/tax_cloud/errors/unexpected_soap_response_error.rb +19 -0
  36. data/lib/tax_cloud/record.rb +14 -0
  37. data/lib/tax_cloud/responses.rb +13 -0
  38. data/lib/tax_cloud/responses/authorized.rb +10 -0
  39. data/lib/tax_cloud/responses/authorized_with_capture.rb +10 -0
  40. data/lib/tax_cloud/responses/base.rb +82 -0
  41. data/lib/tax_cloud/responses/captured.rb +10 -0
  42. data/lib/tax_cloud/responses/cart_item.rb +23 -0
  43. data/lib/tax_cloud/responses/generic.rb +31 -0
  44. data/lib/tax_cloud/responses/lookup.rb +38 -0
  45. data/lib/tax_cloud/responses/ping.rb +10 -0
  46. data/lib/tax_cloud/responses/returned.rb +10 -0
  47. data/lib/tax_cloud/responses/tax_code_groups.rb +30 -0
  48. data/lib/tax_cloud/responses/tax_codes.rb +30 -0
  49. data/lib/tax_cloud/responses/tax_codes_by_group.rb +30 -0
  50. data/lib/tax_cloud/responses/verify_address.rb +26 -0
  51. data/lib/tax_cloud/tax_code.rb +11 -0
  52. data/lib/tax_cloud/tax_code_constants.rb +560 -0
  53. data/lib/tax_cloud/tax_code_group.rb +28 -0
  54. data/lib/tax_cloud/tax_code_group_constants.rb +31 -0
  55. data/lib/tax_cloud/tax_code_groups.rb +25 -0
  56. data/lib/tax_cloud/tax_codes.rb +25 -0
  57. data/lib/tax_cloud/transaction.rb +118 -0
  58. data/lib/tax_cloud/version.rb +4 -0
  59. data/tax_cloud.gemspec +23 -0
  60. data/test/cassettes/authorized.yml +826 -0
  61. data/test/cassettes/authorized_with_capture.yml +826 -0
  62. data/test/cassettes/authorized_with_localized_time.yml +826 -0
  63. data/test/cassettes/captured.yml +872 -0
  64. data/test/cassettes/get_tic_groups.yml +783 -0
  65. data/test/cassettes/get_tics.yml +1079 -0
  66. data/test/cassettes/get_tics_by_group.yml +776 -0
  67. data/test/cassettes/invalid_soap_call.yml +778 -0
  68. data/test/cassettes/lookup.yml +780 -0
  69. data/test/cassettes/lookup_ny.yml +780 -0
  70. data/test/cassettes/ping.yml +776 -0
  71. data/test/cassettes/ping_with_invalid_credentials.yml +774 -0
  72. data/test/cassettes/ping_with_invalid_response.yml +774 -0
  73. data/test/cassettes/returned.yml +872 -0
  74. data/test/cassettes/verify_bad_address.yml +772 -0
  75. data/test/cassettes/verify_good_address.yml +772 -0
  76. data/test/helper.rb +17 -0
  77. data/test/test_address.rb +54 -0
  78. data/test/test_cart_item.rb +15 -0
  79. data/test/test_client.rb +27 -0
  80. data/test/test_configuration_optional_keys.rb +42 -0
  81. data/test/test_configuration_required_keys.rb +31 -0
  82. data/test/test_lookup_response.rb +20 -0
  83. data/test/test_setup.rb +17 -0
  84. data/test/test_soap.rb +11 -0
  85. data/test/test_tax_code_groups.rb +29 -0
  86. data/test/test_tax_codes.rb +17 -0
  87. data/test/test_transaction.rb +78 -0
  88. data/test/test_transaction_ny.rb +25 -0
  89. data/test/vcr_setup.rb +9 -0
  90. metadata +174 -0
checksums.yaml ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+ !binary "U0hBMjU2":
3
+ metadata.gz: !binary |-
4
+ NmU1Y2YyYmFlZjM4NzlkODhkMTBhYTc5MWQxNjg4NTU4YWM2NmE2YjBmZGQ0
5
+ MzZiMWY1NDI0MDc5ZmYwMDRiNA==
6
+ data.tar.gz: !binary |-
7
+ YzI0NWVlYWM5OGI0ZDJiZDc4ODViMzg1YTM5NmFhNjhhN2M3OTcyZDkwMmE0
8
+ YzYyMTgyMWI4NTkxN2Y4ODQ5Nw==
9
+ SHA512:
10
+ metadata.gz: !binary |-
11
+ NDY2YTliMmM2OTc5ZWUxN2RlNmUxMmNlYmQ2ZDA2NjViMjBhZWU5NzBmZjBl
12
+ MmM5YzNjZmQ2ZjMwMTFkNDVhMWJlNzhiMzhmOWJiN2Y0ZTczYzg3OWFiMjBl
13
+ NTA2Yzc5N2ZkYzE1OWU1Y2JiOWEzOTE4OGQwZmYxMDVmNmVjMTQ=
14
+ data.tar.gz: !binary |-
15
+ NTNlMzkwYTQyOGVhMDAyNDE5YThlM2MyNGE5NmUxYjg4MmU0OGJjYmIwZWYz
16
+ ZTFjM2EyNmJjMGQzY2Q4ZTU2OTVjZDg0N2E3OGVhOGRlOTlkOTA2M2IwOWIx
17
+ MTE0YmZlNmNiNDMxZDc1NTNiNzA3YzRmNTBhZTA4MmI4Zjc3Mjg=
@@ -0,0 +1,81 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ # Image to run Ruby 1.9.3 with the latest bundler, RubyGems, etc.
6
+ - image: corgibytes/ruby-1.9.3:1.0.0
7
+
8
+ working_directory: ~/repo
9
+
10
+ steps:
11
+ - checkout
12
+
13
+ - run:
14
+ name: install dependencies
15
+ command: |
16
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
17
+
18
+ # Run the tests using the minitest-ci gem. This will
19
+ # create the test/reports folder.
20
+ - run: bundle exec rake test
21
+
22
+ - store_test_results:
23
+ path: test/reports
24
+ - store_artifacts:
25
+ path: test/reports
26
+
27
+
28
+ deploy:
29
+ docker:
30
+ - image: corgibytes/ruby-1.9.3:1.0.0
31
+
32
+ working_directory: ~/repo
33
+
34
+ steps:
35
+ - checkout
36
+
37
+ # Create the RubyGems credential file which as the
38
+ # RubyGems API key in it. See the sh file for details
39
+ # about the Environment variable that should be setup.
40
+ - run:
41
+ name: Setup Rubygems
42
+ command: bash .circleci/setup-rubygems.sh
43
+
44
+ # Assumes the version number in the version.rb file
45
+ # is the same as the tag. If not then this will fail.
46
+ - run:
47
+ name: Publish to Rubygems
48
+ command: |
49
+ VERSION=${CIRCLE_TAG/v/''}
50
+ gem build tax_cloud.gemspec
51
+ mkdir artifacts
52
+ cp corgibytes-tax_cloud-$VERSION.gem artifacts
53
+ gem push corgibytes-tax_cloud-$VERSION.gem
54
+
55
+ - store_artifacts:
56
+ path: artifacts
57
+
58
+ # Do the build on every commit but only do the
59
+ # the deploy to RubyGems on tags. The tag should be
60
+ # v#.#.#. Don't forget to update the version.rb
61
+ # file before tagging the build.
62
+ workflows:
63
+ version: 2
64
+ test-deploy:
65
+ jobs:
66
+ # By default the tag filter is set to ignore all (i.e. /.*/).
67
+ # This is a problem as deploy depends on build but build
68
+ # won't run on tags by default. To fix this allow
69
+ # build to run on any tags.
70
+ - build:
71
+ filters:
72
+ tags:
73
+ only: /.*/
74
+ - deploy:
75
+ requires:
76
+ - build
77
+ filters:
78
+ tags:
79
+ only: /^v[0-9.]+/
80
+ branches:
81
+ ignore: /.*/
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Store the RubyGems password in the credentials file
4
+ # when doing the CI build. Assumes the CI build has
5
+ # a RUBYGEMS_API_KEY value setup.
6
+
7
+ mkdir -p ~/.gem
8
+ echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
9
+ chmod 0600 ~/.gem/credentials
data/.gitignore ADDED
@@ -0,0 +1,67 @@
1
+ # Ignore RubyMine files. I know RubyMine says to not ignore all
2
+ # idea files but that only seems to cause problems and not everyone
3
+ # uses RubyMine.
4
+ .idea/
5
+
6
+ # Test files generated by minitest-ci for Circle CI builds.
7
+ test/reports
8
+
9
+ # Created by https://www.gitignore.io/api/ruby
10
+ # Edit at https://www.gitignore.io/?templates=ruby
11
+
12
+ ### Ruby ###
13
+ *.gem
14
+ *.rbc
15
+ /.config
16
+ /coverage/
17
+ /InstalledFiles
18
+ /pkg/
19
+ /spec/reports/
20
+ /spec/examples.txt
21
+ /test/tmp/
22
+ /test/version_tmp/
23
+ /tmp/
24
+
25
+ # Used by dotenv library to load environment variables.
26
+ # Ignore all .env, even the ones in the examples folder.
27
+ **/.env
28
+
29
+ # Ignore Byebug command history file.
30
+ .byebug_history
31
+
32
+ ## Specific to RubyMotion:
33
+ .dat*
34
+ .repl_history
35
+ build/
36
+ *.bridgesupport
37
+ build-iPhoneOS/
38
+ build-iPhoneSimulator/
39
+
40
+ ## Specific to RubyMotion (use of CocoaPods):
41
+ #
42
+ # We recommend against adding the Pods directory to your .gitignore. However
43
+ # you should judge for yourself, the pros and cons are mentioned at:
44
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
45
+ # vendor/Pods/
46
+
47
+ ## Documentation cache and generated files:
48
+ /.yardoc/
49
+ /_yardoc/
50
+ /doc/
51
+ /rdoc/
52
+
53
+ ## Environment normalization:
54
+ /.bundle/
55
+ /vendor/bundle
56
+ /lib/bundler/man/
57
+
58
+ # for a library or gem, you might want to ignore these files since the code is
59
+ # intended to run in multiple environments; otherwise, check them in:
60
+ Gemfile.lock
61
+ .ruby-version
62
+ .ruby-gemset
63
+
64
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
65
+ .rvmrc
66
+
67
+ # End of https://www.gitignore.io/api/ruby
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**
4
+ - bin/**
5
+
6
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,66 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-11-09 23:32:49 -0500 using RuboCop version 0.51.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 6
10
+ Lint/AmbiguousRegexpLiteral:
11
+ Exclude:
12
+ - 'lib/tasks/tax_code_groups.rake'
13
+ - 'lib/tasks/tax_codes.rake'
14
+
15
+ # Offense count: 2
16
+ Lint/RescueWithoutErrorClass:
17
+ Exclude:
18
+ - 'lib/tasks/tax_code_groups.rake'
19
+ - 'lib/tasks/tax_codes.rake'
20
+
21
+ # Offense count: 4
22
+ Metrics/AbcSize:
23
+ Max: 23
24
+
25
+ # Offense count: 5
26
+ # Configuration parameters: CountComments, ExcludedMethods.
27
+ Metrics/BlockLength:
28
+ Max: 39
29
+
30
+ # Offense count: 1
31
+ # Configuration parameters: CountComments.
32
+ Metrics/ClassLength:
33
+ Max: 261
34
+
35
+ # Offense count: 236
36
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
37
+ # URISchemes: http, https
38
+ Metrics/LineLength:
39
+ Max: 235
40
+
41
+ # Offense count: 2
42
+ # Configuration parameters: CountComments.
43
+ Metrics/MethodLength:
44
+ Max: 14
45
+
46
+ # Offense count: 1
47
+ Style/Documentation:
48
+ Exclude:
49
+ - 'spec/**/*'
50
+ - 'test/**/*'
51
+ - 'lib/tax_cloud/tax_codes.rb'
52
+
53
+ # Offense count: 1
54
+ # Cop supports --auto-correct.
55
+ # Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles.
56
+ # SupportedOctalStyles: zero_with_o, zero_only
57
+ Style/NumericLiteralPrefix:
58
+ Exclude:
59
+ - 'lib/tax_cloud/tax_codes.rb'
60
+
61
+ # Offense count: 4
62
+ # Cop supports --auto-correct.
63
+ # Configuration parameters: SupportedStyles.
64
+ # SupportedStyles: compact, exploded
65
+ Style/RaiseArgs:
66
+ EnforcedStyle: compact
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update bundler
4
+ rvm:
5
+ - 2.1.0
6
+ - 2.2.0
7
+ - 2.4.2
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ === 0.3.1 (Next)
2
+
3
+ * Add <tt>open_timeout</tt> and <tt>read_timeout</tt> options into configuration - @ka8725.
4
+ * Switch to using BigDecimal for <tt>tax_amount</tt> to avoid floating point arithmetic errors - @paulhenrich.
5
+ * Your contribution here.
6
+
7
+ === 0.3.0 (1/9/2014)
8
+
9
+ * #19: Support Savon 2 - @drewtempelmeyer.
10
+ * Implemented Rubocop, Ruby style linter - @dblock.
11
+ * Ruby 1.8.7 and 1.9.2 are no longer supported - @dblock.
12
+
13
+ === 0.2.2 (4/29/2013)
14
+
15
+ * Relaxed thirdparty gem dependency versions - @mperham.
16
+
17
+ === 0.2.1 (3/3/2013)
18
+
19
+ * Fixed date formatting in API requests with localized applications - @soulcutter.
20
+
21
+ === 0.2.0 (11/26/2012)
22
+
23
+ * The gem is now licensed under the MIT license - @dblock.
24
+ * Raise specialized configuration and SOAP errors - @dblock.
25
+ * Added <tt>TaxCloud::Client.ping</tt> - @dblock.
26
+ * Returning a verified <tt>TaxCloud::Address</tt> from <tt>TaxCloud::Address.verify</tt> - @dblock.
27
+ * Added <tt>TaxCloud::Address.zip</tt> that returns a 9-digit address zip code, when available - @dblock.
28
+ * Returning a <tt>TaxCloud::Responses::Lookup</tt> from <tt>TaxCloud::Transaction.lookup</tt> - @dblock.
29
+ * Returning transaction state, ie. <tt>"OK"</tt> from all other TaxCloud transactions. Exceptions are raised on error - @dblock.
30
+ * Added support for tax codes and tax code groups lookup with <tt>TaxCloud::TaxCodes</tt> and <tt>TaxCloud::TaxCode::Groups</tt> - @dblock.
31
+
32
+ === 0.1.5 (5/9/2012)
33
+
34
+ * Fixed compatibility with Ruby 1.8.7 and 1.9.3, removed super from constructors for classes which inherit from <tt>Object</tt> - @gfmurphy.
35
+
36
+ === 0.1.4 (10/20/2011)
37
+
38
+ * Upgraded rdoc - @drewtempelmeyer.
39
+ * Fixed <tt>.gemspec</tt> dependency declaration for savon - @drewtempelmeyer.
40
+
41
+ === 0.1.3 (9/19/2011)
42
+
43
+ * Added support for the "returned" request - @danielmorrison.
44
+ * Refactoreted tests to use vcr and webmock - @danielmorrison.
45
+
46
+ === 0.1.0 (8/23/2011)
47
+
48
+ * Initial public release - @drewtempelmeyer.
data/CONTRIBUTORS.txt ADDED
@@ -0,0 +1,23 @@
1
+ tax_cloud Contributors
2
+
3
+ Lead Developers
4
+ =======================
5
+ * Drew Tempelmeyer
6
+ * Twitter: @tempelmeyer
7
+ * App.net: @tempelmeyer
8
+ * Github: drewtempelmeyer
9
+
10
+ * Daniel Doubrovkine
11
+ * Twitter: @dblockdotorg
12
+ * Github: dblock
13
+
14
+ Contributors
15
+ =======================
16
+ * Daniel Morrison
17
+ * Github: danielmorrison
18
+
19
+ * George F Murphy
20
+ * Github: gfmurphy
21
+
22
+ * Bradley Schaefer
23
+ * Github: soulcutter
data/Dockerfile ADDED
@@ -0,0 +1,9 @@
1
+ FROM corgibytes/ruby-1.9.3:1.0.0
2
+
3
+ # Working folder.
4
+ RUN mkdir /app
5
+ WORKDIR /app
6
+ COPY . .
7
+
8
+ # Install the Gems
9
+ RUN bundle install
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ # Rubocop 0.41.2 is the lastest version to support
7
+ # Ruby 1.9.3.
8
+ gem 'rubocop', '~>0.41.2'
9
+ gem 'dotenv'
10
+ end
11
+
12
+ group :test do
13
+ gem 'minitest'
14
+ gem 'minitest-ci'
15
+ gem 'vcr'
16
+ gem 'webmock'
17
+ end
18
+
19
+ group :development, :test do
20
+ gem 'rake', '~>12.2.1'
21
+ gem 'rdoc'
22
+ end
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2011-2014 Drew Tempelmeyer & Contributors
4
+ Copyright (c) 2019 Corgibytes LLC.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # TaxCloud
2
+
3
+ [TaxCloud](http://www.taxcloud.com) is a free service to calculate sales tax and generate tax reports. The <tt>tax_cloud</tt> gem allows you to easily integrate with TaxCloud's API.
4
+
5
+ [Forked](https://github.com/drewtempelmeyer/tax_cloud) to add support for running this Gem on Ruby 1.9.3. See issue [#39](https://github.com/drewtempelmeyer/tax_cloud/issues/39) on the original repo for more details.
6
+
7
+ ### Getting Started
8
+ Create a [TaxCloud](http://www.taxcloud.com) merchant account at http://www.taxcloud.net. Add a website to your account under [Locations](https://taxcloud.net/account/locations). This will generate an API ID and API Key that you will need to use the service.
9
+
10
+ [TaxCloud](http://www.taxcloud.com) also offers an optional address verification API. To use it, you need a USPS (United States Postal Service) Address API UserID. To obtain your USPS UserID:
11
+ 1. Download and Install the USPS Shipping Assistant from http://www.usps.com/shippingassistant.
12
+ 2. Launch the USPS Shipping Assistant and go through the Shipping Assistant registration process.
13
+ 3. Once you have registered for your Shipping Assistant account, you can find your USPS Shipping Assistant UserID in the "About" box, in parentheses to the right of the name of the registered user.
14
+
15
+ ### Setup
16
+ Add the gem to your Gemfile.
17
+
18
+ gem 'tax_cloud'
19
+
20
+ Configure your environment. For example, create an initializer in Rails in <tt>config/initializers/tax_cloud.rb</tt>.
21
+
22
+ TaxCloud.configure do |config|
23
+ config.api_login_id = 'your_tax_cloud_api_login_id'
24
+ config.api_key = 'your_tax_cloud_api_key'
25
+ config.usps_username = 'your_usps_username' # optional
26
+ config.open_timeout = 1 # optional
27
+ config.read_timeout = 1 # optional
28
+ end
29
+
30
+ The <tt>open_timeout</tt> and <tt>read_timeout</tt> options are used to specify waiting time for the TaxCloud web service response in seconds. Default values: <tt>open_timeout = 2</tt> and <tt>read_timeout = 2</tt>.
31
+
32
+ ### Using TaxCloud
33
+ Define the destination and origin addresses using <tt>TaxCloud::Address</tt>.
34
+
35
+ origin = TaxCloud::Address.new(
36
+ :address1 => '162 East Avenue',
37
+ :address2 => 'Third Floor',
38
+ :city => 'Norwalk',
39
+ :state => 'CT',
40
+ :zip5 => '06851')
41
+ destination = TaxCloud::Address.new(
42
+ :address1 => '3121 West Government Way',
43
+ :address2 => 'Suite 2B',
44
+ :city => 'Seattle',
45
+ :state => 'WA',
46
+ :zip5 => '98199')
47
+
48
+ Create your Transaction and set up your cart items
49
+
50
+ transaction = TaxCloud::Transaction.new(
51
+ :customer_id => '1',
52
+ :cart_id => '1',
53
+ :origin => origin,
54
+ :destination => destination)
55
+ transaction.cart_items << TaxCloud::CartItem.new(
56
+ :index => 0,
57
+ :item_id => 'SKU-100',
58
+ :tic => TaxCloud::TaxCodes::GENERAL,
59
+ :price => 10.00,
60
+ :quantity => 1)
61
+ lookup = transaction.lookup # this will return a TaxCloud::Responses::Lookup instance
62
+ lookup.tax_amount # total tax amount
63
+ lookup.cart_items.each do |cart_item|
64
+ cart_item.tax_amount # tax for a single item
65
+ end
66
+
67
+ After you've authorized and captured the transaction via your merchant account, you should do the same with TaxCloud for maintaining accurate tax information.
68
+
69
+ transaction.order_id = 100
70
+ transaction.authorized_with_capture # returns "OK" or raises an error
71
+
72
+ Later, you may need to mark some cart items as returned. TaxCloud will ignore any cart items that you don't include.
73
+
74
+ transaction.order_id = 100
75
+ transaction.cart_items << TaxCloud::CartItem.new(
76
+ :index => 0,
77
+ :item_id => 'SKU-100',
78
+ :tic => TaxCloud::TaxCodes::GENERAL,
79
+ :price => 10.00,
80
+ :quantity => 1)
81
+ transaction.returned # returns "OK" or raises an error
82
+
83
+ ### Verifying Addresses
84
+
85
+ [TaxCloud](http://www.taxcloud.com) 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.
86
+
87
+ address = TaxCloud::Address.new({
88
+ :address1 => '888 6th Ave',
89
+ :city => 'New York',
90
+ :state => 'New York',
91
+ :zip5 => '10001'
92
+ })
93
+
94
+ verified_address = address.verify
95
+ verified_address.zip5 # 10001
96
+ verified_address.zip4 # 3502
97
+ verified_address.zip # 10001-3502
98
+
99
+ ### Tax Codes
100
+ [TaxCloud](http://www.taxcloud.com) maintains a list of all Taxability Information Codes or TICs, which can be found at https://taxcloud.net/tic.
101
+
102
+ You can obtain all tax codes as well as lookup a tax code by ID.
103
+
104
+ TaxCloud::TaxCodes.all # a hash of all codes
105
+ tax_code = TaxCloud::TaxCodes[TaxCloud::TaxCodes::DIRECT_MAIL_RELATED]
106
+ tax_code.ticid # 11000 or TaxCloud::TaxCodes::DIRECT_MAIL_RELATED
107
+ tax_code.description # "Direct-mail related"
108
+
109
+ Tax codes are organized in groups.
110
+
111
+ TaxCloud::TaxCode::Groups.all # a hash of all groups
112
+ tax_code_group = TaxCloud::TaxCode::Groups[TaxCloud::TaxCode::Groups::SCHOOL_RELATED_PRODUCTS]
113
+ tax_code_group.group_id # 3 or TaxCloud::TaxCode::Groups::SCHOOL_RELATED_PRODUCTS
114
+ tax_code_group.description # School Related Products
115
+ tax_code_group.tax_codes # a hash of all codes in this group
116
+
117
+ Tax code constants are defined in <tt>tax_code_constants.rb</tt> and tax code group constants in <tt>tax_code_group_constants.rb</tt>. These files can be generated by running the following rake tasks.
118
+
119
+ TAXCLOUD_API_LOGIN_ID=... TAXCLOUD_API_KEY=... TAXCLOUD_USPS_USERNAME=... tax_cloud:tax_codes
120
+ TAXCLOUD_API_LOGIN_ID=... TAXCLOUD_API_KEY=... TAXCLOUD_USPS_USERNAME=... tax_cloud:tax_code_groups
121
+
122
+ ### Tax States
123
+ 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.net/account/states. You can find more information about SSUTA [here](http://www.streamlinedsalestax.org/index.php?page=About-Us]).
124
+
125
+ # Developer Setup
126
+ The project is setup to use [Docker](https://www.docker.com/) to run the tests and example programs. Once you have Docker installed you can build the container via:
127
+
128
+ ````bash
129
+ docker-compose build
130
+ ````
131
+
132
+ Once the container is built you can run access the command line to run these tests or example programs via:
133
+
134
+ ````bash
135
+ docker-compose run app bash
136
+ ````
137
+
138
+ ## Running the tests
139
+ Run the test and Rubocop using the following command:
140
+
141
+ ````bash
142
+ rake
143
+ ````
144
+
145
+ If you want to just run the tests and not Rubocop:
146
+
147
+ ````bash
148
+ rake test
149
+ ````
150
+
151
+ [VCR](https://github.com/vcr/vcr) and WebMock are used to replay requests and avoid hitting the API each time. To refresh the mocks, simply delete the <tt>test/cassettes</tt> directory. If you need to record new requests against TaxCloud, set your keys first.
152
+
153
+ ````bash
154
+ TAXCLOUD_API_LOGIN_ID=... TAXCLOUD_API_KEY=... TAXCLOUD_USPS_USERNAME=... rake test
155
+ ````
156
+
157
+ The mocks will filter out your configuration details.
158
+
159
+ Note: The tests all pass but will raise a bunch of warnings. See [issue #3](https://github.com/corgibytes/tax_cloud/issues/3) for more details.
160
+
161
+ ## Running the example programs
162
+ The example programs run directly against TaxCloud (i.e. no VCR mocks). Make sure you aren't running against a live TaxCloud site but a one that is in test mode.
163
+
164
+ To run the example programs you need to copy the `.env.example` file to `.env` and update it with your TaxCloud credentials. Then run the following command from the examples directory so it can find the .env file:
165
+
166
+ ````bash
167
+ bundle exec ruby <example>.rb
168
+ ````
169
+
170
+ For example, to run the lookups example:
171
+
172
+ ````bash
173
+ bundle exec ruby lookup_example.rb
174
+ ````
175
+
176
+ If you login to your TaxCloud account you will see the API activity caused by the example programs.
177
+
178
+ # Bugs, fixes, etc
179
+ * Fork.
180
+ * Write test(s).
181
+ * Fix.
182
+ * Commit.
183
+ * Submit pull request.
184
+
185
+ # License
186
+
187
+ This gem is licensed under the [MIT license](LICENSE).
188
+
189
+ # Acknowledgements
190
+ Thanks for [Drew Tempelmeyer](https://github.com/drewtempelmeyer) and other [contributors](https://github.com/drewtempelmeyer/tax_cloud/graphs/contributors) for creating and maintaining this helpful gem.