nys_sales_tax

package module
v0.0.0-...-9986494 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2019 License: MIT Imports: 7 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

nys_sales_tax

A Go library to help calculating sales tax in New York State. Can return tax rates based on New York State reporting code and Census county code. It can also connect to the Census geocoding API and allow you to fetch tax rates based just on an address.

Documentation

Index

Constants

View Source
const NYSStateTaxRate = float32(4)

Variables

View Source
var (
	ErrGeocoderCensusException = errors.New("geocoder: the Census server returned an exception")
	ErrGeocoderNoMatches       = errors.New("geocoder: there were no matches for the given address")
)
View Source
var ErrBadFIPSCode = errors.New("nys_sales_tax: the given FIPS code was not valid")
View Source
var ErrBadReportingCode = errors.New("nys_sales_tax: the given reporting code was not valid")
View Source
var FIPSCodeMap = map[int]FIPSCodeInfo{
	1:   FIPSCodeInfo{"Albany", 181, false, "H1"},
	3:   FIPSCodeInfo{"Allegany", 221, false, "H1"},
	5:   FIPSCodeInfo{"Bronx", 0, true, "H6"},
	7:   FIPSCodeInfo{"Broome", 321, false, "H1"},
	9:   FIPSCodeInfo{"Cattaraugus", 0, true, "H1"},
	11:  FIPSCodeInfo{"Cayuga", 0, true, "H1"},
	13:  FIPSCodeInfo{"Chautauqua", 651, false, "H1"},
	15:  FIPSCodeInfo{"Chemung", 771, false, "H1"},
	17:  FIPSCodeInfo{"Chenango", 0, true, "H1"},
	19:  FIPSCodeInfo{"Clinton", 921, false, "H1"},
	21:  FIPSCodeInfo{"Columbia", 1021, false, "H1"},
	23:  FIPSCodeInfo{"Cortland", 1131, false, "H1"},
	25:  FIPSCodeInfo{"Delaware", 1221, false, "H1"},
	27:  FIPSCodeInfo{"Dutchess", 1311, false, "H1"},
	29:  FIPSCodeInfo{"Erie", 1451, false, "H1"},
	31:  FIPSCodeInfo{"Essex", 1521, false, "H1"},
	33:  FIPSCodeInfo{"Franklin", 1621, false, "H1"},
	35:  FIPSCodeInfo{"Fulton", 0, true, "H1"},
	37:  FIPSCodeInfo{"Genesee", 1811, false, "H1"},
	39:  FIPSCodeInfo{"Greene", 1911, false, "H1"},
	41:  FIPSCodeInfo{"Hamilton", 2011, false, "H1"},
	43:  FIPSCodeInfo{"Herkimer", 2121, false, "H1"},
	45:  FIPSCodeInfo{"Jefferson", 2221, false, "H1"},
	47:  FIPSCodeInfo{"Kings", 0, true, "H6"},
	49:  FIPSCodeInfo{"Lewis", 2321, false, "H1"},
	51:  FIPSCodeInfo{"Livingston", 2411, false, "H1"},
	53:  FIPSCodeInfo{"Madison", 0, true, "H1"},
	55:  FIPSCodeInfo{"Monroe", 2611, false, "H1"},
	57:  FIPSCodeInfo{"Montgomery", 2781, false, "H1"},
	59:  FIPSCodeInfo{"Nassau", 2811, false, "H1"},
	61:  FIPSCodeInfo{"New York", 0, true, "H6"},
	63:  FIPSCodeInfo{"Niagara", 2911, false, "H1"},
	65:  FIPSCodeInfo{"Oneida", 0, true, "H1"},
	67:  FIPSCodeInfo{"Onondaga", 3121, false, "H1"},
	69:  FIPSCodeInfo{"Ontario", 3211, false, "H1"},
	71:  FIPSCodeInfo{"Orange", 3321, false, "H1"},
	73:  FIPSCodeInfo{"Orleans", 3481, false, "H1"},
	75:  FIPSCodeInfo{"Oswego", 0, true, "H1"},
	77:  FIPSCodeInfo{"Otsego", 3621, false, "H1"},
	79:  FIPSCodeInfo{"Putnam", 3731, false, "H1"},
	81:  FIPSCodeInfo{"Queens", 0, true, "H6"},
	83:  FIPSCodeInfo{"Rensselaer", 3881, false, "H1"},
	85:  FIPSCodeInfo{"Richmond", 0, true, "H6"},
	87:  FIPSCodeInfo{"Rockland", 3921, false, "H1"},
	89:  FIPSCodeInfo{"St. Lawrence", 4091, false, "H1"},
	91:  FIPSCodeInfo{"Saratoga", 0, true, "H1"},
	93:  FIPSCodeInfo{"Schenectady", 4241, false, "H1"},
	95:  FIPSCodeInfo{"Schoharie", 4321, false, "H1"},
	97:  FIPSCodeInfo{"Schuyler", 4411, false, "H1"},
	99:  FIPSCodeInfo{"Seneca", 4511, false, "H1"},
	101: FIPSCodeInfo{"Steuben", 4691, false, "H1"},
	103: FIPSCodeInfo{"Suffolk", 4711, false, "H1"},
	105: FIPSCodeInfo{"Sullivan", 4821, false, "H1"},
	107: FIPSCodeInfo{"Tioga", 4921, false, "H1"},
	109: FIPSCodeInfo{"Tompkins", 0, true, "H1"},
	111: FIPSCodeInfo{"Ulster", 5111, false, "H1"},
	113: FIPSCodeInfo{"Warren", 0, true, "H1"},
	115: FIPSCodeInfo{"Washington", 5311, false, "H1"},
	117: FIPSCodeInfo{"Wayne", 5421, false, "H1"},
	119: FIPSCodeInfo{"Westchester", 0, true, "H1"},
	121: FIPSCodeInfo{"Wyoming", 5621, false, "H1"},
	123: FIPSCodeInfo{"Yates", 5721, false, "H1"},
}

This only contains counties inside New York State!

View Source
var NYSCountyCityExceptions = map[string]map[string]int{
	"Cattaraugus": map[string]int{
		"Olean":     441,
		"Salamanca": 431,
		"":          481,
	},
	"Cayuga": map[string]int{
		"Auburn": 561,
		"":       511,
	},
	"Chenango": map[string]int{
		"Norwich": 831,
		"":        861,
	},
	"Fulton": map[string]int{
		"Gloversville": 1741,
		"Johnstown":    1751,
		"":             1791,
	},
	"Madison": map[string]int{
		"Oneida": 2541,
		"":       2511,
	},
	"Oneida": map[string]int{
		"Rome":  3015,
		"Utica": 3018,
		"":      3010,
	},
	"Oswego": map[string]int{
		"Oswego City": 3561,
		"":            3501,
	},
	"Saratoga": map[string]int{
		"Saratoga Springs": 4131,
		"":                 4111,
	},
	"Tompkins": map[string]int{
		"Ithaca": 5021,
		"":       5081,
	},
	"Warren": map[string]int{
		"Glens Falls": 5211,
		"":            5281,
	},
	"Westchester": map[string]int{
		"Mount Vernon": 5521,
		"New Rochelle": 6861,
		"White Plains": 6513,
		"Yonkers":      6511,
		"":             5581,
	},
}

Map of exception county -> possible city reporting codes

View Source
var NYSCountyTaxRates = map[int]CountyRateInfo{
	21:   CountyRateInfo{0, false, "New York State only"},
	181:  CountyRateInfo{4, false, "Albany"},
	221:  CountyRateInfo{4.5, false, "Allegany"},
	321:  CountyRateInfo{4, false, "Broome"},
	481:  CountyRateInfo{4, false, "Cattaraugus (except Olean and Salamanca)"},
	441:  CountyRateInfo{4, false, "Cattaraugus (Olean)"},
	431:  CountyRateInfo{4, false, "Cattaraugus (Salamanca)"},
	511:  CountyRateInfo{4, false, "Cayuga (except Auburn)"},
	561:  CountyRateInfo{4, false, "Cayuga (Auburn)"},
	651:  CountyRateInfo{4, false, "Chautauqua"},
	771:  CountyRateInfo{4, false, "Chemung"},
	861:  CountyRateInfo{4, false, "Chenango (except Norwich)"},
	831:  CountyRateInfo{4, false, "Chenango (Norwich)"},
	921:  CountyRateInfo{4, false, "Clinton"},
	1021: CountyRateInfo{4, false, "Columbia"},
	1131: CountyRateInfo{4, false, "Cortland"},
	1221: CountyRateInfo{4, false, "Delaware"},
	1311: CountyRateInfo{4.125, true, "Dutchess"},
	1451: CountyRateInfo{4.75, false, "Erie"},
	1521: CountyRateInfo{4, false, "Essex"},
	1621: CountyRateInfo{4, false, "Franklin"},
	1791: CountyRateInfo{4, false, "Fulton (except Gloversville and Johnstown)"},
	1741: CountyRateInfo{4, false, "Fulton (Gloversville)"},
	1751: CountyRateInfo{4, false, "Fulton (Johnstown)"},
	1811: CountyRateInfo{4, false, "Genesee"},
	1911: CountyRateInfo{4, false, "Greene"},
	2011: CountyRateInfo{4, false, "Hamilton"},
	2121: CountyRateInfo{4.25, false, "Herkimer"},
	2221: CountyRateInfo{4, false, "Jefferson"},
	2321: CountyRateInfo{4, false, "Lewis"},
	2411: CountyRateInfo{4, false, "Livingston"},
	2511: CountyRateInfo{4, false, "Madison (except Oneida)"},
	2541: CountyRateInfo{4, false, "Madison (Oneida)"},
	2611: CountyRateInfo{4, false, "Monroe"},
	2781: CountyRateInfo{4, false, "Montgomery"},
	2811: CountyRateInfo{4.625, true, "Nassau"},
	8081: CountyRateInfo{4.875, true, "New York City"},
	2911: CountyRateInfo{4, false, "Niagara"},
	3010: CountyRateInfo{4.75, false, "Oneida (except Rome and Utica)"},
	3015: CountyRateInfo{4.75, false, "Oneida (Rome)"},
	3018: CountyRateInfo{4.75, false, "Onedia (Utica)"},
	3121: CountyRateInfo{4, false, "Onondaga"},
	3211: CountyRateInfo{3.5, false, "Ontario"},
	3321: CountyRateInfo{4.125, true, "Orange"},
	3481: CountyRateInfo{4, false, "Orleans"},
	3501: CountyRateInfo{4, false, "Oswego (except Oswego City)"},
	3561: CountyRateInfo{4, false, "Oswego (Oswego City)"},
	3621: CountyRateInfo{4, false, "Otsego"},
	3731: CountyRateInfo{4.375, true, "Putnam"},
	3881: CountyRateInfo{4, false, "Rensselaer"},
	3921: CountyRateInfo{4.375, true, "Rockland"},
	4091: CountyRateInfo{4, false, "St. Lawrence"},
	4111: CountyRateInfo{3, false, "Saratoga (except Saratoga Springs)"},
	4131: CountyRateInfo{3, false, "Saratoga (Saratoga Springs)"},
	4241: CountyRateInfo{4, false, "Schenectady"},
	4321: CountyRateInfo{4, false, "Schoharie"},
	4411: CountyRateInfo{4, false, "Schuyler"},
	4511: CountyRateInfo{4, false, "Seneca"},
	4691: CountyRateInfo{4, false, "Steuben"},
	4711: CountyRateInfo{4.625, true, "Suffolk"},
	4821: CountyRateInfo{4, false, "Sullivan"},
	4921: CountyRateInfo{4, false, "Tioga"},
	5081: CountyRateInfo{4, false, "Tompkins (except Ithaca)"},
	5021: CountyRateInfo{4, false, "Tompkins (Ithaca)"},
	5111: CountyRateInfo{4, false, "Ulster"},
	5281: CountyRateInfo{3, false, "Warren (except Glens Falls)"},
	5211: CountyRateInfo{3, false, "Warren (Glens Falls)"},
	5311: CountyRateInfo{3, false, "Washington"},
	5421: CountyRateInfo{4, false, "Wayne"},
	5581: CountyRateInfo{4.375, true, "Westchester (except Mount Vernon, New Rochelle, White Plains, and Yonkers)"},
	5521: CountyRateInfo{4.375, true, "Westchester (Mount Vernon)"},
	6861: CountyRateInfo{4.375, true, "Westchester (New Rochelle)"},
	6513: CountyRateInfo{4.375, true, "Westchester (White Plains)"},
	6511: CountyRateInfo{4.875, true, "Westchester (Yonkers)"},
	5621: CountyRateInfo{4, false, "Wyoming"},
	5721: CountyRateInfo{4, false, "Yates"},
}

Map of reporting code -> rate info struct

Functions

func IsNYSZIPCode

func IsNYSZIPCode(zipCode string) bool

IsNYSZIPCode determines if the given ZIP code is located in New York State.

func LookupCountyCodeAndCityForAddress

func LookupCountyCodeAndCityForAddress(address string) (int, string, error)

Queries the U.S Census geocoding API to get the county FIPS code and city for the given address. Returns: FIPS county code, city name (all caps), error

Types

type CountyRateInfo

type CountyRateInfo struct {
	CountyPercentage float32
	IncludesMCTD     bool
	Name             string
}

type FIPSCodeInfo

type FIPSCodeInfo struct {
	Name             string
	NYSReportingCode int
	SpecialException bool
	ClassCode        string
}

type TaxInfo

type TaxInfo struct {
	ReportingCode int
	StateRate     float32
	CountyInfo    CountyRateInfo
	TotalRate     float32
}

func CalculateNYSSalesTaxFromAddress

func CalculateNYSSalesTaxFromAddress(address string) (TaxInfo, error)

Queries the U.S Census geocoding API to get the county FIPS code and city for the given address. Returns: tax information struct, error

func CalculateNYSSalesTaxFromAddressInfo

func CalculateNYSSalesTaxFromAddressInfo(fipsCode int, city string) (TaxInfo, error)

Calculates the sales tax information for the given FIPS code and city name. The city name is required for some exception counties, where the reporting code/tax rate is different depending on the city in the county. Returns: tax information struct, error

func CalculateNYSSalesTaxFromReportingCode

func CalculateNYSSalesTaxFromReportingCode(reportingCode int) (TaxInfo, error)

Calculates the sales tax information for the given county reporting code. Returns: tax information struct, error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL