56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package cart
|
|
|
|
// NordicTaxProvider implements TaxProvider for the Nordic countries
|
|
// (SE, NO, DK, FI). It encodes the standard statutory VAT rates:
|
|
//
|
|
// SE: 25 % (standard), 12 % (food, hotels), 6 % (books, transport)
|
|
// NO: 25 % (standard), 15 % (food), 12 %
|
|
// DK: 25 % (standard)
|
|
// FI: 25 % (standard; actual rate is 25.5 % as of 2026)
|
|
//
|
|
// All rates are raw percent (25 = 25 %). Fractional rates (FI 25.5) are
|
|
// truncated to the nearest integer per the raw-percent convention.
|
|
//
|
|
// NordicTaxProvider does not make network calls — all logic is local math.
|
|
// An external provider (Avalara, TaxJar) can be added by implementing
|
|
// TaxProvider and switching on TAX_PROVIDER.
|
|
type NordicTaxProvider struct {
|
|
defaultCountry string
|
|
}
|
|
|
|
// NewNordicTaxProvider returns a NordicTaxProvider. defaultCountry is used
|
|
// when DefaultTaxRate is called with an empty country code; it defaults to
|
|
// "SE" if empty.
|
|
func NewNordicTaxProvider(defaultCountry string) *NordicTaxProvider {
|
|
if defaultCountry == "" {
|
|
defaultCountry = "SE"
|
|
}
|
|
return &NordicTaxProvider{defaultCountry: defaultCountry}
|
|
}
|
|
|
|
var _ TaxProvider = (*NordicTaxProvider)(nil)
|
|
|
|
func (p *NordicTaxProvider) Name() string { return "nordic" }
|
|
|
|
func (p *NordicTaxProvider) ComputeTax(total int64, taxRate int) int64 {
|
|
return ComputeTax(total, taxRate)
|
|
}
|
|
|
|
// nordicStandardRates maps country code → default standard VAT rate (raw percent).
|
|
var nordicStandardRates = map[string]int{
|
|
"SE": 25,
|
|
"NO": 25,
|
|
"DK": 25,
|
|
"FI": 25,
|
|
}
|
|
|
|
func (p *NordicTaxProvider) DefaultTaxRate(country string) int {
|
|
if country == "" {
|
|
country = p.defaultCountry
|
|
}
|
|
if rate, ok := nordicStandardRates[country]; ok {
|
|
return rate
|
|
}
|
|
return nordicStandardRates[p.defaultCountry]
|
|
}
|