Sha256: e77e6b4ef8811cc24ee03eadd6aded9da319c48643c29cbce3ca50dcd33fa8b4
Contents?: true
Size: 1.13 KB
Versions: 2
Compression:
Stored size: 1.13 KB
Contents
module Effective class TaxRateCalculator attr_reader :order 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' => 14.0, # Prince Edward Island 'QC' => 5.00, # Quebec 'SK' => 5.00, # Saskatchewan 'YT' => 5.00, # Yukon Territory 'NU' => 5.00 # Nunavut } } def initialize(order:) @order = order end 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 def unknown_tax_rate order.skip_buyer_validations? ? nil : 0 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
effective_orders-2.1.16 | app/models/effective/tax_rate_calculator.rb |
effective_orders-2.1.15 | app/models/effective/tax_rate_calculator.rb |