solidus_avatax_certified 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/.env_example +4 -0
  3. data/.gitignore +16 -0
  4. data/.rspec +3 -0
  5. data/.ruby-version +1 -0
  6. data/GEM_VERSION +1 -0
  7. data/Gemfile +18 -0
  8. data/LICENSE +26 -0
  9. data/README.md +27 -0
  10. data/Rakefile +21 -0
  11. data/app/assets/javascripts/spree/backend/address_validator.js +84 -0
  12. data/app/assets/javascripts/spree/backend/solidus_avatax_certified.js +5 -0
  13. data/app/assets/javascripts/spree/backend/use_code_picker.js +51 -0
  14. data/app/assets/javascripts/spree/frontend/address_validator.js +87 -0
  15. data/app/assets/javascripts/spree/frontend/flash.js.coffee +26 -0
  16. data/app/assets/javascripts/spree/frontend/solidus_avatax_certified.js +4 -0
  17. data/app/assets/stylesheets/spree/backend/solidus_avatax_certified.css +4 -0
  18. data/app/assets/stylesheets/spree/frontend/solidus_avatax_certified.css +4 -0
  19. data/app/controllers/spree/admin/avalara_entity_use_codes_controller.rb +15 -0
  20. data/app/controllers/spree/admin/avatax_settings_controller.rb +82 -0
  21. data/app/controllers/spree/admin/users_controller_decorator.rb +11 -0
  22. data/app/controllers/spree/checkout_controller_decorator.rb +22 -0
  23. data/app/models/solidus_avatax_certified/address.rb +95 -0
  24. data/app/models/solidus_avatax_certified/avatax_log.rb +69 -0
  25. data/app/models/solidus_avatax_certified/line.rb +146 -0
  26. data/app/models/solidus_avatax_certified/preference_updater.rb +74 -0
  27. data/app/models/spree/address_decorator.rb +13 -0
  28. data/app/models/spree/adjustment_decorator.rb +10 -0
  29. data/app/models/spree/avalara_entity_use_code.rb +5 -0
  30. data/app/models/spree/avalara_preference.rb +72 -0
  31. data/app/models/spree/avalara_transaction.rb +181 -0
  32. data/app/models/spree/calculator/avalara_transaction.rb +86 -0
  33. data/app/models/spree/line_item_decorator.rb +25 -0
  34. data/app/models/spree/order_decorator.rb +85 -0
  35. data/app/models/spree/payment_decorator.rb +23 -0
  36. data/app/models/spree/refund_decorator.rb +30 -0
  37. data/app/models/spree/shipment_decorator.rb +28 -0
  38. data/app/models/spree/shipping_rate_decorator.rb +25 -0
  39. data/app/models/spree/user_decorator.rb +3 -0
  40. data/app/models/tax_svc.rb +143 -0
  41. data/app/overrides/spree/admin/shared/_configuration_menu.rb +10 -0
  42. data/app/overrides/spree/admin/users/sidebar.rb +8 -0
  43. data/app/overrides/spree/admin/users/validation_button.rb +6 -0
  44. data/app/views/spree/admin/avalara_entity_use_codes/_form.html.erb +27 -0
  45. data/app/views/spree/admin/avalara_entity_use_codes/edit.html.erb +16 -0
  46. data/app/views/spree/admin/avalara_entity_use_codes/index.html.erb +33 -0
  47. data/app/views/spree/admin/avalara_entity_use_codes/new.html.erb +17 -0
  48. data/app/views/spree/admin/avalara_entity_use_codes/show.html.erb +24 -0
  49. data/app/views/spree/admin/avatax_settings/edit.html.erb +183 -0
  50. data/app/views/spree/admin/avatax_settings/ping_my_service.js.erb +8 -0
  51. data/app/views/spree/admin/avatax_settings/show.html.erb +124 -0
  52. data/app/views/spree/admin/avatax_settings/validate_address.js.erb +8 -0
  53. data/app/views/spree/admin/users/avalara_information.html.erb +53 -0
  54. data/app/views/spree/checkout/_address.html.erb +35 -0
  55. data/app/views/spree/checkout/_address_validator_button.html.erb +3 -0
  56. data/bin/rails +7 -0
  57. data/circle.yml +17 -0
  58. data/config/initializers/avatax.rb +5 -0
  59. data/config/initializers/spree.rb +3 -0
  60. data/config/locales/en.yml +35 -0
  61. data/config/routes.rb +18 -0
  62. data/db/migrate/20160624154205_create_spree_avalara_transactions.rb +9 -0
  63. data/db/migrate/20160624154423_create_spree_avalara_entity_use_codes.rb +9 -0
  64. data/db/migrate/20160624155217_add_columns_to_spree_users.rb +6 -0
  65. data/db/migrate/20160628200504_create_spree_avalara_preferences.rb +10 -0
  66. data/db/migrate/20160805193512_add_vat_id_to_spree_users.rb +5 -0
  67. data/db/seeds.rb +1 -0
  68. data/lib/generators/solidus_avatax_certified/install/install_generator.rb +45 -0
  69. data/lib/solidus_avatax_certified/engine.rb +22 -0
  70. data/lib/solidus_avatax_certified/preference_seeder.rb +69 -0
  71. data/lib/solidus_avatax_certified/seeder.rb +117 -0
  72. data/lib/solidus_avatax_certified.rb +2 -0
  73. data/lib/tasks/load_seeds.rake +15 -0
  74. data/setup.md +12 -0
  75. data/solidus_avatax_certified.gemspec +42 -0
  76. data/spec/controllers/spree/admin/avalara_entity_use_codes_controller_spec.rb +53 -0
  77. data/spec/controllers/spree/admin/avatax_settings_controller_spec.rb +67 -0
  78. data/spec/factories/avalara_entity_use_code_factory.rb +6 -0
  79. data/spec/factories/avalara_factories.rb +76 -0
  80. data/spec/factories/avalara_order_factory.rb +62 -0
  81. data/spec/factories/avalara_preference_factory.rb +7 -0
  82. data/spec/factories/avalara_shipment_factory.rb +27 -0
  83. data/spec/factories/avalara_shipping_method_factory.rb +23 -0
  84. data/spec/factories/tax_rate_factory.rb +19 -0
  85. data/spec/features/certification_spec.rb +77 -0
  86. data/spec/features/checkout_spec.rb +156 -0
  87. data/spec/features/vat_spec.rb +153 -0
  88. data/spec/models/solidus_avatax_certified/address_spec.rb +80 -0
  89. data/spec/models/solidus_avatax_certified/avatax_log_spec.rb +97 -0
  90. data/spec/models/solidus_avatax_certified/line_spec.rb +100 -0
  91. data/spec/models/spree/address_decorator_spec.rb +44 -0
  92. data/spec/models/spree/adjustment_decorator_spec.rb +25 -0
  93. data/spec/models/spree/avalara_entity_use_code_spec.rb +5 -0
  94. data/spec/models/spree/avalara_preference_spec.rb +173 -0
  95. data/spec/models/spree/avalara_transaction_spec.rb +203 -0
  96. data/spec/models/spree/calculator/avalara_transaction_spec.rb +129 -0
  97. data/spec/models/spree/line_item_decorator_spec.rb +33 -0
  98. data/spec/models/spree/order_decorator_spec.rb +164 -0
  99. data/spec/models/spree/payment_decorator_spec.rb +117 -0
  100. data/spec/models/spree/refund_decorator_spec.rb +81 -0
  101. data/spec/models/spree/shipment_decorator_spec.rb +36 -0
  102. data/spec/models/spree/shipping_rate_decorator_spec.rb +17 -0
  103. data/spec/models/spree/user_decorator_spec.rb +5 -0
  104. data/spec/spec_helper.rb +81 -0
  105. data/spec/support/avatax_config_preferences.rb +8 -0
  106. data/spec/support/vcr.rb +9 -0
  107. data/spec/vcr/Certification/Exempt_sales_should_be_reflected_in_the_test_data_through_use_of_ExemptionNo_or_CustomerUsageType_/does_not_add_additional_tax.yml +276 -0
  108. data/spec/vcr/Certification/Transactions_have_been_committed_/commits_an_order.yml +336 -0
  109. data/spec/vcr/Certification/Transactions_have_been_voided/cancelled_/should_be_successful/returns_ResultCode_with_value_Success.yml +522 -0
  110. data/spec/vcr/Certification/return_orders/_commit_avatax_final/should_commit_avatax_final.yml +404 -0
  111. data/spec/vcr/Checkout/complete_order/has_tax_and_shipping_tax_adjustments_on_page.yml +72 -0
  112. data/spec/vcr/Checkout/complete_order/order_line_items_and_shipments_have_an_additional_tax_total_sum_of_0_40.yml +72 -0
  113. data/spec/vcr/Checkout/payment/tax_included/has_tax_and_shipping_tax_adjustments_on_page.yml +72 -0
  114. data/spec/vcr/Checkout/payment/tax_included/order_line_items_and_shipments_have_an_included_tax_total_sum_of_0_38.yml +72 -0
  115. data/spec/vcr/Checkout/payment/tax_not_included/on_payment_page/has_tax_and_shipping_tax_adjustments_on_page.yml +72 -0
  116. data/spec/vcr/Checkout/payment/tax_not_included/on_payment_page/order_line_items_and_shipments_and_shipments_have_an_additional_tax_total_sum_of_0_40.yml +72 -0
  117. data/spec/vcr/Checkout/payment/with_promotion/tax_not_included/has_adjusted_tax_amount_after_promotion_applied.yml +73 -0
  118. data/spec/vcr/SolidusAvataxCertified_Address/_validate/fails_when_information_is_incorrect.yml +54 -0
  119. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_included_in_price/should_be_equal_to_the_item_pre-tax_total_rate.yml +137 -0
  120. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_included_in_price/should_be_equal_to_the_previous_included_tax_total_is_order_is_at_address.yml +138 -0
  121. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_included_in_price/should_be_equal_to_the_previous_included_tax_total_is_order_is_at_cart.yml +137 -0
  122. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_not_included_in_price/should_be_equal_to_the_item_pre-tax_total_rate.yml +136 -0
  123. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_not_included_in_price/should_be_equal_to_the_previous_additional_tax_total_if_order_is_at_address.yml +137 -0
  124. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_not_included_in_price/should_be_equal_to_the_previous_additional_tax_total_if_order_is_at_cart.yml +136 -0
  125. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_not_included_in_price/should_be_equal_to_the_previous_tax_total_if_preference_tax_calculation_is_false.yml +136 -0
  126. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_not_included_in_price/when_the_line_item_is_discounted/should_be_equal_to_the_items_pre-tax_total_rate.yml +276 -0
  127. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_computing_a_line_item/when_tax_is_not_included_in_price/when_the_order_is_discounted/should_be_equal_to_the_items_pre-tax_total_rate.yml +206 -0
  128. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_given_a_shipment/computing_normal_shipment/should_be_equal_4_0.yml +141 -0
  129. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_given_a_shipment/when_tax_is_included_in_price/should_be_equal_to_3_85.yml +143 -0
  130. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_given_a_shipment/with_promotion/should_equal_3_96.yml +210 -0
  131. data/spec/vcr/Spree_Calculator_AvalaraTransaction/_compute/when_given_an_order/when_computing_an_order/should_raise_error.yml +136 -0
  132. data/spec/vcr/Spree_Order/_cancel_avalara/should_receive_cancel_order_when_cancel_avalara_is_called.yml +136 -0
  133. data/spec/vcr/Spree_Order/_cancel_avalara/state_machine_event_cancel/should_recieve_cancel_avalara_when_event_cancel_is_called.yml +259 -0
  134. data/spec/vcr/Spree_Order/_validate_ship_address/should_return_false_if_validation_failed.yml +54 -0
  135. data/spec/vcr/Spree_Order/_validate_ship_address/should_return_the_response_if_refuse_checkout_on_address_validation_is_disabled.yml +59 -0
  136. data/spec/vcr/Spree_Order/_validate_ship_address/should_return_the_response_if_validation_is_success.yml +59 -0
  137. data/spec/vcr/Spree_Payment/_avalara_finalize/should_update_the_amount_to_be_the_order_total.yml +136 -0
  138. data/spec/vcr/Spree_Payment/_cancel_avalara/committed_order/should_be_successful/ResultCode_returns_Success.yml +205 -0
  139. data/spec/vcr/Spree_Payment/_cancel_avalara/uncommitted_order/should_fail/ResultCode_returns_Error.yml +191 -0
  140. data/spec/vcr/Spree_Payment/_purchase_/receive_avalara_finalize.yml +136 -0
  141. data/spec/vcr/Spree_Payment/_void_transaction_/receive_cancel_avalara.yml +136 -0
  142. data/spec/vcr/Spree_Refund/full_refund/returns_correct_tax_calculations.yml +270 -0
  143. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_in_another_EU_country/Seller_does_not_have_Nexus_Jurisdition_Registered/TotalTax_is_equal_to_order_included_tax_total.yml +137 -0
  144. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_in_another_EU_country/Seller_does_not_have_Nexus_Jurisdition_Registered/origin_country_tax_is_returned.yml +138 -0
  145. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_in_another_EU_country/Seller_does_not_have_Nexus_Jurisdition_Registered/with_BusinessIdentificationNo/origin_country_zero_rate_is_returned.yml +143 -0
  146. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_in_another_EU_country/Seller_has_Nexus_Jurisdition_Registered/TotalTax_is_equal_to_order_included_tax_total.yml +139 -0
  147. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_in_another_EU_country/Seller_has_Nexus_Jurisdition_Registered/destination_country_tax_is_returned.yml +139 -0
  148. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_in_another_EU_country/Seller_has_Nexus_Jurisdition_Registered/with_BusinessIdentificationNo/origin_country_zero_rate_is_returned.yml +144 -0
  149. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_in_same_EU_country/TotalTax_is_equal_to_order_included_tax_total.yml +137 -0
  150. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_in_same_EU_country/tax_detail_country_equals_to_IT.yml +138 -0
  151. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_is_outside_EU/Seller_does_not_have_Nexus_Jurisdition_registered/TotalTax_is_equal_to_order_included_tax_total.yml +137 -0
  152. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_is_outside_EU/Seller_does_not_have_Nexus_Jurisdition_registered/tax_detail_country_equals_to_IT.yml +137 -0
  153. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_is_outside_EU/Seller_does_not_have_Nexus_Jurisdition_registered/total_tax_is_0_since_utah_is_not_in_jurisdiction.yml +137 -0
  154. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_is_outside_EU/Seller_does_not_have_Nexus_Jurisdition_registered/with_BusinessIdentificationNo/origin_country_zero_rate_is_returned.yml +138 -0
  155. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_is_outside_EU/Seller_has_Nexus_Jurisdiction_Registered/TotalTax_is_equal_to_order_included_tax_total.yml +195 -0
  156. data/spec/vcr/VAT/Seller_in_EU_country_Buyer_is_outside_EU/Seller_has_Nexus_Jurisdiction_Registered/tax_detail_region_equals_to_AL.yml +195 -0
  157. data/spec/vcr/address_validation_success.yml +59 -0
  158. data/spec/vcr/capture_with_customer_usage_type.yml +72 -0
  159. data/spec/vcr/order_cancel.yml +258 -0
  160. data/spec/vcr/order_capture.yml +72 -0
  161. data/spec/vcr/order_capture_finalize.yml +141 -0
  162. data/spec/vcr/order_capture_with_promo.yml +73 -0
  163. data/spec/vcr/order_return_capture.yml +68 -0
  164. data/spec/vcr/tax_included_order.yml +73 -0
  165. metadata +581 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a887c27e84dad711cddf9d4fb3aeae1f8f218cd
4
+ data.tar.gz: c0b14deafc45577a96fb16d4245b82e2e986679d
5
+ SHA512:
6
+ metadata.gz: 0d006929267b836849d0b4a8f552ad79ba1da794045d9b78fcd261051a53b659591374725b3f859930d9228f162c2a4b3fd45cf8273a66ae56fbdbeaccf78f65
7
+ data.tar.gz: b3f43090df24a9545a291b13e5f5bcce024cc70f74805430fd4f3bd73fc94b68c40acc9a7f528c64bb1796642655c05a979b4fa62e587bd58036dd821a1ec6fa
data/.env_example ADDED
@@ -0,0 +1,4 @@
1
+ AVATAX_COMPANY_CODE =
2
+ AVATAX_ENDPOINT = https://development.avalara.net
3
+ AVATAX_ACCOUNT =
4
+ AVATAX_LICENSE_KEY =
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
15
+ .env
16
+ log/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -f documentation
3
+ -r spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.3
data/GEM_VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "https://rubygems.org"
2
+
3
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'v2.0')
4
+ gem "solidus", github: "solidusio/solidus", branch: branch
5
+ gem "solidus_auth_devise", github: "solidusio/solidus_auth_devise"
6
+
7
+ group :test, :development do
8
+ gem "pry"
9
+ end
10
+
11
+ if branch == 'master' || branch >= "v2.0"
12
+ gem "rails-controller-testing", group: :test
13
+ else
14
+ gem "rails", '~> 4.2.7' # workaround for bundler resolution issue
15
+ gem "rails_test_params_backport", group: :test
16
+ end
17
+
18
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2016 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ SolidusAvataxCertified
2
+ ===========
3
+
4
+ SolidusAvataxCertified is the *only* [officially certified Avatax solution](http://www.avalara.com/avalara-certified/) that integrates with Solidus. With this extension you can add instantaneous sales tax decisions to your store.
5
+
6
+ From Avalara's own explanation of the certification program:
7
+
8
+ > Relax. It’s certified.
9
+ >
10
+ > Our “Certified for AvaTax” Program features integrations that perform at the highest level, providing the best possible customer experience.
11
+
12
+ > Avalara’s partners who have created certified integrations for AvaTax have demonstrated that those integrations contain elements which are essential to providing customers with easy-to-use software that gives accurate sales tax calculations. The certification criteria used to demonstrate these elements are based on Avalara’s years of experience integrating into ERP, ecommerce and point-of-sale applications.
13
+
14
+
15
+ **[For Installation and Setup instructions, please visit our wiki.](https://github.com/boomerdigital/solidus_avatax_certified/wiki)**
16
+
17
+ Testing
18
+ -------
19
+
20
+ Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
21
+
22
+ $ bundle
23
+ $ bundle exec rake test_app
24
+ $ bundle exec rspec spec
25
+
26
+ Copyright (c) 2016 Boomer Digital LLC, released under the New BSD License
27
+
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'solidus_avatax_certified'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
@@ -0,0 +1,84 @@
1
+ Spree.ready(function(){
2
+ validator = new AddressValidator();
3
+ validator.bindListeners();
4
+ });
5
+
6
+ function AddressValidator(){
7
+ this.lineHash = {
8
+ address1: "Line1",
9
+ address2: "Line2",
10
+ city: "City",
11
+ zipcode: "PostalCode",
12
+ country: "Country",
13
+ state: "Region"
14
+ };
15
+ }
16
+
17
+ AddressValidator.prototype = {
18
+ bindListeners: function(){
19
+ $(".address_validator").on("click", this.validate.bind(this));
20
+ },
21
+ validate: function(){
22
+ event.preventDefault();
23
+ var address = this.formatAddress();
24
+
25
+ $.ajax({
26
+ url: Spree.routes.validate_address,
27
+ data: {
28
+ address: address
29
+ }
30
+ }).done(function(data){
31
+ var controller = this;
32
+ var wrapper = controller.addressWrapper();
33
+
34
+ if (data['ResultCode'] === 'Error') {
35
+ return this.showFlash(data);
36
+ }
37
+
38
+ $.each(["Line1", "Line2", "City", "PostalCode"], function(index, value){
39
+ var keyVal = controller.getKeyByValue(value);
40
+ $(wrapper + " input[id*='" + keyVal + "']").val(data.Address[value]);
41
+ }.bind(address));
42
+
43
+ this.showFlash(data);
44
+ }.bind(this));
45
+ },
46
+ formatAddress: function() {
47
+ var address = {};
48
+ controller = this;
49
+ var wrapper = controller.addressWrapper();
50
+
51
+ $(wrapper + " input").not("[name$='name]']").not("[class*=select2]").each(function(){
52
+ var id = $(this).attr("id");
53
+ var line = controller.lineHash[id.split("_").pop()];
54
+ address[line] = $(this).val();
55
+ });
56
+
57
+ $(wrapper + " select.select2").each(function(){
58
+ var line = controller.lineHash[$(this).attr("id")];
59
+ address[line] = $(this).select2("val");
60
+ });
61
+
62
+ return address;
63
+ },
64
+ getKeyByValue: function(value) {
65
+ return Object.keys(this.lineHash).find(function(key){ return this[key] === value}.bind(this.lineHash));
66
+ },
67
+ showFlash: function(data){
68
+ var resultCode = data.ResultCode.toLowerCase();
69
+
70
+ if(resultCode === "success") {
71
+ window.show_flash("success", "Address Validation Successful");
72
+ } else {
73
+ details = $(data['Messages']).map(function(){return this['Summary']}).get().join(' ');
74
+ window.show_flash("error", "Address Validation Error: " + details);
75
+ }
76
+ },
77
+ addressWrapper: function(){
78
+ if($("#shipping").length != 0){
79
+ return "#shipping";
80
+ } else {
81
+ return "#business-address";
82
+ }
83
+ }
84
+ }
@@ -0,0 +1,5 @@
1
+ //= require spree/backend/use_code_picker
2
+ //= require spree/backend/address_validator
3
+
4
+ Spree.routes.use_code_search = Spree.pathFor("admin/avalara_entity_use_codes")
5
+ Spree.routes.validate_address = Spree.pathFor("admin/avatax_settings/validate_address")
@@ -0,0 +1,51 @@
1
+ $.fn.usecodeAutocomplete = function () {
2
+ 'use strict';
3
+
4
+ this.select2({
5
+ minimumInputLength: 1,
6
+ multiple: false,
7
+ initSelection: function (element, callback) {
8
+ Spree.ajax({
9
+ url: Spree.routes.use_code_search,
10
+ data: {
11
+ ids: element.val()
12
+ },
13
+ success: function(data) {
14
+ callback(data[0]);
15
+ }
16
+ })
17
+ },
18
+ ajax: {
19
+ url: Spree.routes.use_code_search,
20
+ datatype: 'json',
21
+ data: function (term) {
22
+ return {
23
+ q: term
24
+ };
25
+ },
26
+ results: function (data) {
27
+ return {
28
+ results: data
29
+ };
30
+ }
31
+ },
32
+ formatResult: function (use_codes) {
33
+ if( !use_codes.use_code ){
34
+ return "Enter Avalara Entity Use Code"
35
+ } else {
36
+ return use_codes.use_code + ') Description: ' + use_codes.use_code_description;
37
+ }
38
+ },
39
+ formatSelection: function (use_codes) {
40
+ if( !use_codes.use_code ){
41
+ return "Enter Avalara Entity Use Code"
42
+ } else {
43
+ return use_codes.use_code + ') Description: ' + use_codes.use_code_description;
44
+ }
45
+ }
46
+ });
47
+ };
48
+
49
+ $(document).ready(function () {
50
+ $('.use_code_picker').usecodeAutocomplete();
51
+ });
@@ -0,0 +1,87 @@
1
+ Spree.ready(function(){
2
+ validator = new AddressValidator();
3
+ validator.bindListeners();
4
+ });
5
+
6
+ function AddressValidator(){
7
+ this.lineHash = {
8
+ address1: "Line1",
9
+ address2: "Line2",
10
+ city: "City",
11
+ zipcode: "PostalCode",
12
+ country: "Country",
13
+ state: "Region"
14
+ };
15
+ }
16
+
17
+ AddressValidator.prototype = {
18
+ bindListeners: function(){
19
+ $(".address_validator").on("click", this.validate.bind(this));
20
+ },
21
+ validate: function(){
22
+ event.preventDefault();
23
+ $("#checkout_form_address").validate().form();
24
+ var address = this.formatAddress();
25
+
26
+ $.ajax({
27
+ url: Spree.routes.validate_address,
28
+ data: {
29
+ address: address,
30
+ state: "address"
31
+ }
32
+ }).done(function(data){
33
+ var controller = this;
34
+ var wrapper = controller.addressWrapper();
35
+
36
+ if (data['ResultCode'] === 'Error') {
37
+ return this.showFlash(data);
38
+ }
39
+
40
+ $.each(["Line1", "Line2", "City", "PostalCode"], function(index, value){
41
+ var keyVal = controller.getKeyByValue(value);
42
+ $(wrapper + " input[id*='" + keyVal + "']").val(data.Address[value]);
43
+ }.bind(address));
44
+
45
+ this.showFlash(data);
46
+ }.bind(this));
47
+ },
48
+ formatAddress: function() {
49
+ var address = {};
50
+ controller = this;
51
+ var wrapper = controller.addressWrapper();
52
+
53
+ $(wrapper + " input").not("select").each(function(){
54
+ var id = $(this).attr("id");
55
+ var line = controller.lineHash[id.split("_").pop()];
56
+ address[line] = $(this).val();
57
+ });
58
+
59
+ $(wrapper + " select").each(function(){
60
+ var id = $(this).attr("id");
61
+ var line = controller.lineHash[id.slice(0, -3).split("_").pop()];
62
+ address[line] = $(this).val();
63
+ });
64
+
65
+ return address;
66
+ },
67
+ getKeyByValue: function(value) {
68
+ return Object.keys(this.lineHash).find(function(key){ return this[key] === value}.bind(this.lineHash));
69
+ },
70
+ showFlash: function(data){
71
+ var resultCode = data.ResultCode.toLowerCase();
72
+
73
+ if(resultCode === "success") {
74
+ window.show_flash("success", "Address Validation Successful");
75
+ } else {
76
+ details = $(data['Messages']).map(function(){return this['Summary']}).get().join(' ');
77
+ window.show_flash("error", "Address Validation Error: " + details);
78
+ }
79
+ },
80
+ addressWrapper: function(){
81
+ if($("#order_use_billing").is(":checked")){
82
+ return "#billing";
83
+ } else {
84
+ return "#shipping";
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,26 @@
1
+ showTime = 5000
2
+ fadeOutTime = 500
3
+
4
+ Spree.ready ($) ->
5
+ # Make flash messages dissapear
6
+ # We only want to target the flash messages which are initially on the page.
7
+ # Otherwise we risk hiding messages added by show_flash
8
+ $initialFlash = $(".flash")
9
+ setTimeout (->
10
+ $initialFlash.fadeOut(fadeOutTime)
11
+ ), showTime
12
+
13
+ window.show_flash = (type, message) ->
14
+ $addressValidator = $('.address_validator')
15
+
16
+ if type == 'success'
17
+ $addressValidator.attr('disabled', true).text(message).addClass('flash success disabled')
18
+ else
19
+ $flashWrapper = $(".js-flash-wrapper")
20
+ if $flashWrapper.length == 0
21
+ $addressValidator.before("<div class=\"js-flash-wrapper\" />")
22
+ $flashWrapper = $(".js-flash-wrapper")
23
+ $flashWrapper.empty()
24
+ flash_div = $("<div class='flash " + type + "' />")
25
+ $flashWrapper.prepend(flash_div)
26
+ flash_div.html(message).show().delay(showTime).fadeOut(fadeOutTime)
@@ -0,0 +1,4 @@
1
+ //= require spree/frontend/address_validator
2
+ //= require spree/frontend/flash
3
+
4
+ Spree.routes.validate_address = Spree.pathFor("checkout/validate_address")
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module Admin
3
+ class AvalaraEntityUseCodesController < Spree::Admin::ResourceController
4
+
5
+ def index
6
+ @avalara_entity_use_codes = Spree::AvalaraEntityUseCode.all
7
+
8
+ respond_to do |format|
9
+ format.html
10
+ format.json { render json: @avalara_entity_use_codes }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,82 @@
1
+ module Spree
2
+ module Admin
3
+ class AvataxSettingsController < Spree::Admin::BaseController
4
+
5
+ before_action :load_avatax_origin, only: [:show, :edit]
6
+
7
+ def show
8
+ end
9
+
10
+ def get_file_txt_tax_svc
11
+ send_file "#{Rails.root}/log/tax_svc.log"
12
+ end
13
+
14
+ def get_file_post_order_to_avalara
15
+ send_file "#{Rails.root}/log/post_order_to_avalara.log"
16
+ end
17
+
18
+ def get_file_avalara_order
19
+ send_file "#{Rails.root}/log/avalara_order.log"
20
+ end
21
+
22
+ def erase_data
23
+ File.open("log/#{params['log_name']}.log", 'w') {}
24
+
25
+ head :ok
26
+ end
27
+
28
+ def ping_my_service
29
+ mytax = TaxSvc.new
30
+ pingResult = mytax.ping
31
+ if pingResult['ResultCode'] == 'Success'
32
+ flash[:success] = 'Ping Successful'
33
+
34
+ else
35
+ flash[:error] = 'Ping Error'
36
+ end
37
+
38
+ respond_to do |format|
39
+ format.js
40
+ end
41
+ end
42
+
43
+ def validate_address
44
+ mytax = TaxSvc.new
45
+ address = permitted_address_validation_attrs
46
+
47
+ address['Country'] = Spree::Country.find_by(id: address['Country']).try(:iso)
48
+ address['Region'] = Spree::State.find_by(id: address['Region']).try(:abbr)
49
+
50
+ response = mytax.validate_address(address)
51
+
52
+ respond_to do |format|
53
+ format.json { render json: response }
54
+ end
55
+ end
56
+
57
+ def update
58
+ updater = SolidusAvataxCertified::PreferenceUpdater.new(params)
59
+ if updater.update
60
+ redirect_to admin_avatax_settings_path
61
+ else
62
+ flash[:error] = 'There was an error updating your Avalara Preferences'
63
+ redirect_to :back
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def load_avatax_origin
70
+ if Spree::AvalaraPreference.origin_address.value.blank?
71
+ @avatax_origin = {}
72
+ else
73
+ @avatax_origin = JSON.parse(Spree::AvalaraPreference.origin_address.value)
74
+ end
75
+ end
76
+
77
+ def permitted_address_validation_attrs
78
+ params['address'].permit(:Line1, :Line2, :City, :PostalCode, :Country, :Region).to_h
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,11 @@
1
+ Spree::Admin::UsersController.class_eval do
2
+ def avalara_information
3
+ if request.put?
4
+ if @user.update_attributes(user_params)
5
+ flash.now[:success] = Spree.t(:account_updated)
6
+ end
7
+ end
8
+
9
+ render :avalara_information
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ Spree::CheckoutController.class_eval do
2
+ def validate_address
3
+ mytax = TaxSvc.new
4
+ address = permitted_address_validation_attrs
5
+
6
+ address['Country'] = Spree::Country.find_by(id: address['Country']).try(:iso)
7
+ address['Region'] = Spree::State.find_by(id: address['Region']).try(:abbr)
8
+
9
+ response = mytax.validate_address(address)
10
+
11
+ respond_to do |format|
12
+ format.json { render json: response }
13
+ end
14
+ end
15
+
16
+
17
+ private
18
+
19
+ def permitted_address_validation_attrs
20
+ params['address'].permit(:Line1, :Line2, :City, :PostalCode, :Country, :Region).to_h
21
+ end
22
+ end
@@ -0,0 +1,95 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'base64'
4
+ require 'logger'
5
+
6
+ module SolidusAvataxCertified
7
+ class Address
8
+ attr_reader :order, :addresses
9
+
10
+ def initialize(order)
11
+ @order = order
12
+ @ship_address = order.ship_address
13
+ @origin_address = JSON.parse(Spree::AvalaraPreference.origin_address.value)
14
+ @addresses = []
15
+
16
+ build_addresses
17
+ end
18
+
19
+ def build_addresses
20
+ origin_address
21
+ order_ship_address unless @ship_address.nil?
22
+ origin_ship_addresses
23
+
24
+ logger.debug @addresses
25
+ end
26
+
27
+ def origin_address
28
+ addresses << {
29
+ AddressCode: 'Orig',
30
+ Line1: @origin_address['Line1'],
31
+ Line2: @origin_address['Line2'],
32
+ City: @origin_address['City'],
33
+ Region: @origin_address['Region'],
34
+ PostalCode: @origin_address['PostalCode'],
35
+ Country: @origin_address['Country']
36
+ }
37
+ end
38
+
39
+ def order_ship_address
40
+ addresses << {
41
+ AddressCode: 'Dest',
42
+ Line1: @ship_address.address1,
43
+ Line2: @ship_address.address2,
44
+ City: @ship_address.city,
45
+ Region: @ship_address.state_name,
46
+ Country: @ship_address.country.try(:iso),
47
+ PostalCode: @ship_address.zipcode
48
+ }
49
+ end
50
+
51
+ def origin_ship_addresses
52
+ Spree::StockLocation.where(id: stock_loc_ids).each do |stock_location|
53
+ addresses << {
54
+ AddressCode: "#{stock_location.id}",
55
+ Line1: stock_location.address1,
56
+ Line2: stock_location.address2,
57
+ City: stock_location.city,
58
+ PostalCode: stock_location.zipcode,
59
+ Country: stock_location.country.try(:iso)
60
+ }
61
+ end
62
+ end
63
+
64
+ def validate
65
+ return 'Address validation disabled' unless @ship_address.validation_enabled?
66
+ return @ship_address if @ship_address.nil?
67
+
68
+ address_hash = {
69
+ Line1: @ship_address.address1,
70
+ Line2: @ship_address.address2,
71
+ City: @ship_address.city,
72
+ Region: @ship_address.state.try(:abbr),
73
+ Country: @ship_address.country.try(:iso),
74
+ PostalCode: @ship_address.zipcode
75
+ }
76
+
77
+ validation_response(address_hash)
78
+ end
79
+
80
+ private
81
+
82
+ def validation_response(address)
83
+ validator = TaxSvc.new
84
+ validator.validate_address(address)
85
+ end
86
+
87
+ def stock_loc_ids
88
+ order.shipments.pluck(:stock_location_id).uniq
89
+ end
90
+
91
+ def logger
92
+ @logger ||= SolidusAvataxCertified::AvataxLog.new('avalara_order_addresses', 'SolidusAvataxCertified::Address', "Building Addresses for Order#: #{order.number}")
93
+ end
94
+ end
95
+ end