Module: Easyship::SalesTax::Calculator
- Defined in:
- lib/easyship/sales_tax/calculator.rb,
lib/easyship/sales_tax/calculator/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- FALLBACK_VALUE =
{sales_tax: 0, provincial_sales_tax: 0}.freeze
- FALLBACK_VALUE_WITH_DETAILS =
{ sales_tax: 0, provincial_sales_tax: 0, sales_tax_detail: Easyship::SalesTax::Formula::NO_TAX, provincial_sales_tax_detail: Easyship::SalesTax::Formula::NO_TAX }.freeze
- EU_COUNTRY_ALPHA2S =
%w[NL LU EE LT HU BE PT SK HR CZ IT FI PL MT DE SI RO BG AT SE CY DK FR IE ES GR LV].freeze
- VERSION =
"0.8.0"
Class Method Summary collapse
- .calculate(origin_country_alpha2: nil, destination_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil, effective_timestamp: nil, effective_country_alpha2s: [], with_detail: false) ⇒ Object
- .calculate_with_detail(**kwargs) ⇒ Object
- .sales_tax_website_name(country_alpha2, effective_timestamp = nil) ⇒ Object
Class Method Details
.calculate(origin_country_alpha2: nil, destination_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil, effective_timestamp: nil, effective_country_alpha2s: [], with_detail: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/easyship/sales_tax/calculator.rb', line 20 def calculate( origin_country_alpha2: nil, destination_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil, effective_timestamp: nil, effective_country_alpha2s: [], with_detail: false ) return fallback_value(with_detail: with_detail) if origin_country_alpha2&.strip&.empty? || destination_country_alpha2&.strip&.empty? return fallback_value(with_detail: with_detail) unless fees.is_a?(Fee) return fallback_value(with_detail: with_detail) unless tax_eligible?(origin_country_alpha2, destination_country_alpha2) domestic_value( origin_country_alpha2: origin_country_alpha2, origin_state: origin_state, destination_state: destination_state, fees: fees, effective_timestamp: , effective_country_alpha2s: effective_country_alpha2s, with_detail: with_detail ) rescue fallback_value(with_detail: with_detail) end |
.calculate_with_detail(**kwargs) ⇒ Object
47 48 49 |
# File 'lib/easyship/sales_tax/calculator.rb', line 47 def calculate_with_detail(**kwargs) calculate(with_detail: true, **kwargs) end |
.sales_tax_website_name(country_alpha2, effective_timestamp = nil) ⇒ Object
51 52 53 54 |
# File 'lib/easyship/sales_tax/calculator.rb', line 51 def sales_tax_website_name(country_alpha2, = nil) rates = Formula.effective_data(country_alpha2, ) (rates || {}).dig(:sales_tax_website_name) end |