salestax

package module
v0.0.0-...-67705e0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 6 Imported by: 0

README

salestax-go

This repository contains a library for performing international sales tax calculation, such as for countries in the European Union (VAT MOSS), completely offline. It is based on the node-sales-tax library for NodeJS.

Usage

package main

import (
	"fmt"
	"os"

	"github.com/majd/salestax-go"
)

func main() {
	ctrl := &salestax.Ctrl{
		OriginCountryCode:  salestax.Ptr("DE"),
		RegionalTaxEnabled: true,
	}

	tax, err := ctrl.GetSalesTax("DE", nil, nil)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	fmt.Printf("%+v\n", tax)
}

License

The code in this library is released under the MIT license.

Documentation

Index

Constants

View Source
const (
	TaxExchangeBusiness TaxExchange = "business"
	TaxExchangeConsumer TaxExchange = "consumer"

	TaxAreaWorldwide TaxArea = "worldwide"
	TaxAreaNational  TaxArea = "national"
	TaxAreaRegional  TaxArea = "regional"
)

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](val T) *T

Types

type Ctrl

type Ctrl struct {
	// OriginCountryCode is the country code of the tax registration and liability.
	OriginCountryCode *string
	// RegionalTaxEnabled specifies whether regional taxation is enabled, such as in the EU region.
	// If this value is set to true (VAT OSS threshold is not exceeded), the rate of the origin country will be used.
	RegionalTaxEnabled bool
	// contains filtered or unexported fields
}

Ctrl is the salestax controller.

func (*Ctrl) GetSalesTax

func (t *Ctrl) GetSalesTax(countryCode string, stateCode *string, taxNumber *string) (*SalesTax, error)

GetSalesTax returns the sales tax for the desired country. The parameters stateCode and taxNumber are optional.

type SalesTax

type SalesTax struct {
	// Type is the type of the sales tax.
	Type string
	// Rate is the sales tax rate.
	Rate float32
	// Area is the area of the sales tax.
	Area TaxArea
	// Exchange is the tax exchange type of the sales tax.
	Exchange TaxExchange
	// Charge contains information about the charge types of the sales tax.
	Charge TaxCharge
}

SalesTax is the sales tax object.

type TaxArea

type TaxArea string

type TaxCharge

type TaxCharge struct {
	// Direct implies that direct-charge rule should be in effect.
	Direct bool
	// Reverse implies that reverse-charge rule should be in effect.
	Reverse bool
}

TaxCharge contains information about the charge types of the sales tax.

type TaxExchange

type TaxExchange string

Jump to

Keyboard shortcuts

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