Module: SuperGood::SolidusTaxjar::CalculatorHelper
- Extended by:
- ActiveSupport::Concern
- Included in:
- TaxCalculator, TaxRateCalculator
- Defined in:
- lib/super_good/solidus_taxjar/calculator_helper.rb
Instance Method Summary collapse
- #cache ⇒ Object
- #exception_handler ⇒ Object
- #incomplete_address?(address) ⇒ Boolean
-
#state_required?(country) ⇒ Boolean
Only require a “state” value if this is an address for Canada or the USA.
- #taxable_address?(address) ⇒ Boolean
Instance Method Details
#cache ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/super_good/solidus_taxjar/calculator_helper.rb', line 28 def cache if !Rails.env.test? Rails.cache.fetch( cache_key, expires_in: SuperGood::SolidusTaxjar.cache_duration ) { yield } else yield end end |
#exception_handler ⇒ Object
39 40 41 |
# File 'lib/super_good/solidus_taxjar/calculator_helper.rb', line 39 def exception_handler SuperGood::SolidusTaxjar.exception_handler end |
#incomplete_address?(address) ⇒ Boolean
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/super_good/solidus_taxjar/calculator_helper.rb', line 6 def incomplete_address?(address) return true if address.is_a?(::Spree::Tax::TaxLocation) fields = [ address.address1, address.city, address.zipcode, address.country&.iso ] if state_required?(address.country) fields << (address.state&.abbr || address.state_name) end fields.any?(&:blank?) end |
#state_required?(country) ⇒ Boolean
Only require a “state” value if this is an address for Canada or the USA. This aligns with TaxJar’s API requirement for ‘to_state`.
48 49 50 |
# File 'lib/super_good/solidus_taxjar/calculator_helper.rb', line 48 def state_required?(country) ["CA", "US"].include?(country&.iso) end |
#taxable_address?(address) ⇒ Boolean
23 24 25 26 |
# File 'lib/super_good/solidus_taxjar/calculator_helper.rb', line 23 def taxable_address?(address) SuperGood::SolidusTaxjar.taxable_address_check.call(address) && address_in_nexus_region?(address) end |