blob: f9c996cdb52f6a7f70f380449a1625a92769da68 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
module SuperGood
module SolidusTaxJar
class TaxRateCalculator
include CalculatorHelper
def initialize(address, api: SuperGood::SolidusTaxJar.api)
@address = address
@api = api
end
def calculate
return no_rate if SuperGood::SolidusTaxJar.test_mode
return no_rate if incomplete_address?(address)
return no_rate unless taxable_address?(address)
cache do
api.tax_rate_for(address).to_d
end
rescue => e
exception_handler.call(e)
no_rate
end
private
attr_reader :address, :api
def no_rate
BigDecimal(0)
end
def cache_key
SuperGood::SolidusTaxJar.cache_key.call(address)
end
end
end
end
|