Class: Spree::TaxCalculator::ShippingRate

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

Overview

Default implementation for tax calculations on shipping rates.

The class used for shipping rate 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.

See Also:

Instance Method Summary collapse

Constructor Details

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

Create a new tax calculator.

Parameters:



20
21
22
# File 'app/models/spree/tax_calculator/shipping_rate.rb', line 20

def initialize(order)
  @order = order
end

Instance Method Details

#calculate(shipping_rate) ⇒ Array<Spree::Tax::ItemTax>

Calculate taxes for a shipping rate.

Parameters:

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/spree/tax_calculator/shipping_rate.rb', line 30

def calculate(shipping_rate)
  rates_for_item(shipping_rate).map do |rate|
    amount = rate.compute_amount(shipping_rate)

    Spree::Tax::ItemTax.new(
      item_id: shipping_rate.id,
      label: rate.adjustment_label(amount),
      tax_rate: rate,
      amount:
    )
  end
end