Class: Spree::TaxCalculator::ShippingRate
- Inherits:
-
Object
- Object
- Spree::TaxCalculator::ShippingRate
- Includes:
- Spree::Tax::TaxHelpers
- Defined in:
- app/models/spree/tax_calculator/shipping_rate.rb
Overview
Note:
This API is currently in development and likely to change. Specifically, the input format is not yet finalized.
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.
Instance Attribute Summary collapse
- #shipping_rate ⇒ Object readonly
Instance Method Summary collapse
-
#calculate ⇒ Array<Spree::Tax::ItemTax>
Calculate taxes for a shipping rate.
-
#initialize(shipping_rate) ⇒ Spree::TaxCalculator::ShippingRate
constructor
Create a new tax calculator.
Constructor Details
#initialize(shipping_rate) ⇒ Spree::TaxCalculator::ShippingRate
Create a new tax calculator.
24 25 26 |
# File 'app/models/spree/tax_calculator/shipping_rate.rb', line 24 def initialize(shipping_rate) @shipping_rate = shipping_rate end |
Instance Attribute Details
#shipping_rate ⇒ Object (readonly)
17 18 19 |
# File 'app/models/spree/tax_calculator/shipping_rate.rb', line 17 def shipping_rate @shipping_rate end |
Instance Method Details
#calculate ⇒ Array<Spree::Tax::ItemTax>
Calculate taxes for a shipping rate.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/spree/tax_calculator/shipping_rate.rb', line 32 def calculate 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: amount ) end end |