Class: Effective::TaxRateCalculator
- Inherits:
-
Object
- Object
- Effective::TaxRateCalculator
- Defined in:
- app/models/effective/tax_rate_calculator.rb
Constant Summary collapse
- RATES =
{ 'CA' => { # Canada 'AB' => 5.00, # Alberta 'BC' => 5.00, # British Columbia 'MB' => 5.00, # Manitoba 'NB' => 15.0, # New Brunswick 'NL' => 15.0, # Newfoundland and Labrador 'NT' => 5.00, # Northwest Territories 'NS' => 15.0, # Nova Scotia 'ON' => 13.0, # Ontario 'PE' => 15.0, # Prince Edward Island 'QC' => 5.00, # Quebec 'SK' => 5.00, # Saskatchewan 'YT' => 5.00, # Yukon Territory 'NU' => 5.00 # Nunavut } }
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
-
#initialize(order:) ⇒ TaxRateCalculator
constructor
A new instance of TaxRateCalculator.
- #tax_rate ⇒ Object
- #unknown_tax_rate ⇒ Object
Constructor Details
#initialize(order:) ⇒ TaxRateCalculator
Returns a new instance of TaxRateCalculator.
23 24 25 |
# File 'app/models/effective/tax_rate_calculator.rb', line 23 def initialize(order:) @order = order end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
3 4 5 |
# File 'app/models/effective/tax_rate_calculator.rb', line 3 def order @order end |
Instance Method Details
#tax_rate ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/effective/tax_rate_calculator.rb', line 27 def tax_rate return nil unless order.billing_address.try(:country_code).present? country = order.billing_address.country_code state = order.billing_address.state_code rate = RATES[country] return rate if rate.kind_of?(Numeric) return unknown_tax_rate() if rate.nil? rate[state].presence || unknown_tax_rate() end |
#unknown_tax_rate ⇒ Object
40 41 42 |
# File 'app/models/effective/tax_rate_calculator.rb', line 40 def unknown_tax_rate order.skip_buyer_validations? ? nil : 0 end |