Class: Spree::TaxCalculator::Default

Inherits:
Object
  • Object
show all
Includes:
Spree::Tax::TaxHelpers
Defined in:
app/models/spree/tax_calculator/default.rb

Overview

Default implementation for tax calculations. Will go through all line items and shipments and calculate their tax based on tax rates in the DB.

The class used for tax calculation is configurable, so that the calculation can easily be pushed to third-party services. Users looking to provide their own calculator should adhere to the API of this class.

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ Spree::TaxCalculator::Default

Create a new tax calculator.

Parameters:

  • the order to calculator taxes on



18
19
20
# File 'app/models/spree/tax_calculator/default.rb', line 18

def initialize(order)
  @order = order
end

Instance Method Details

#calculateSpree::Tax::OrderTax

Calculate taxes for an order.

Returns:

  • the calculated taxes for the order



25
26
27
28
29
30
31
32
# File 'app/models/spree/tax_calculator/default.rb', line 25

def calculate
  Spree::Tax::OrderTax.new(
    order_id: order.id,
    order_taxes: order_rates,
    line_item_taxes: line_item_rates,
    shipment_taxes: shipment_rates
  )
end