Class: SuperGood::SolidusTaxjar::TaxCalculator
- Inherits:
-
Object
- Object
- SuperGood::SolidusTaxjar::TaxCalculator
- Includes:
- CalculatorHelper
- Defined in:
- lib/super_good/solidus_taxjar/tax_calculator.rb
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(order, api: SuperGood::SolidusTaxjar.api) ⇒ TaxCalculator
constructor
A new instance of TaxCalculator.
Methods included from CalculatorHelper
#cache, #exception_handler, #incomplete_address?, #state_required?, #taxable_address?
Constructor Details
#initialize(order, api: SuperGood::SolidusTaxjar.api) ⇒ TaxCalculator
Returns a new instance of TaxCalculator.
6 7 8 9 |
# File 'lib/super_good/solidus_taxjar/tax_calculator.rb', line 6 def initialize(order, api: SuperGood::SolidusTaxjar.api) @order = order @api = api end |
Instance Method Details
#calculate ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/super_good/solidus_taxjar/tax_calculator.rb', line 11 def calculate return no_tax if SuperGood::SolidusTaxjar.test_mode return no_tax if incomplete_address?(order.tax_address) || order.line_items.none? return no_tax unless taxable_order? order return no_tax unless taxable_address? order.tax_address cache do next no_tax unless taxjar_breakdown ::Spree::Tax::OrderTax.new( order_id: order.id, line_item_taxes: line_item_taxes, shipment_taxes: shipment_taxes ) end rescue => e exception_handler.call(e) no_tax end |