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
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#state_code ⇒ Object
readonly
Returns the value of attribute state_code.
Instance Method Summary collapse
-
#initialize(order: nil, country_code: nil, state_code: nil) ⇒ TaxRateCalculator
constructor
A new instance of TaxRateCalculator.
- #tax_rate ⇒ Object
- #unknown_tax_rate ⇒ Object
Constructor Details
#initialize(order: nil, country_code: nil, state_code: nil) ⇒ TaxRateCalculator
Returns a new instance of TaxRateCalculator.
23 24 25 26 27 |
# File 'app/models/effective/tax_rate_calculator.rb', line 23 def initialize(order: nil, country_code: nil, state_code: nil) @order = order @country_code = country_code @state_code = state_code end |
Instance Attribute Details
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
3 4 5 |
# File 'app/models/effective/tax_rate_calculator.rb', line 3 def country_code @country_code end |
#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 |
#state_code ⇒ Object (readonly)
Returns the value of attribute state_code.
3 4 5 |
# File 'app/models/effective/tax_rate_calculator.rb', line 3 def state_code @state_code end |
Instance Method Details
#tax_rate ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/effective/tax_rate_calculator.rb', line 29 def tax_rate country = country_code state = state_code if order.present? country ||= order.billing_address.try(:country_code) country ||= order.organization.try(:billing_address).try(:country_code) country ||= order.user.try(:billing_address).try(:country_code) state ||= order.billing_address.try(:state_code) state ||= order.organization.try(:billing_address).try(:state_code) state ||= order.user.try(:billing_address).try(:state_code) end 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
50 51 52 |
# File 'app/models/effective/tax_rate_calculator.rb', line 50 def unknown_tax_rate (order && order.skip_buyer_validations?) ? nil : 0 end |