Class: SuperGood::SolidusTaxJar::TaxCalculator

Inherits:
Object
  • Object
show all
Includes:
CalculatorHelper
Defined in:
lib/super_good/solidus_taxjar/tax_calculator.rb

Instance Method Summary collapse

Methods included from CalculatorHelper

#cache, #exception_handler, #incomplete_address?, #taxable_address?

Constructor Details

#initialize(order, api: self.class.default_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: self.class.default_api)
  @order = order
  @api = api
end

Instance Method Details

#calculateObject



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 StandardError => e
  exception_handler.(e)
  no_tax
end