vatsense

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

README

Vat Sense Go API Library

Go Reference

The Vat Sense Go library provides convenient access to the Vat Sense REST API from applications written in Go.

It is generated with Stainless.

Installation

import (
	"github.com/VAT-Sense/vatsense-go" // imported as vatsense
)

Or to pin the version:

go get -u 'github.com/VAT-Sense/vatsense-go@v0.0.2'

Requirements

This library requires Go 1.22+.

Usage

The full API of this library can be found in api.md.

package main

import (
	"context"
	"fmt"

	"github.com/VAT-Sense/vatsense-go"
	"github.com/VAT-Sense/vatsense-go/option"
)

func main() {
	client := vatsense.NewClient(
		option.WithUsername("My Username"), // defaults to os.LookupEnv("VAT_SENSE_USERNAME")
		option.WithPassword("My Password"), // defaults to os.LookupEnv("VAT_SENSE_PASSWORD")
	)
	rates, err := client.Rates.List(context.TODO(), vatsense.RateListParams{})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", rates.Code)
}

Request fields

The vatsense library uses the omitzero semantics from the Go 1.24+ encoding/json release for request fields.

Required primitive fields (int64, string, etc.) feature the tag `json:"...,required"`. These fields are always serialized, even their zero values.

Optional primitive types are wrapped in a param.Opt[T]. These fields can be set with the provided constructors, vatsense.String(string), vatsense.Int(int64), etc.

Any param.Opt[T], map, slice, struct or string enum uses the tag `json:"...,omitzero"`. Its zero value is considered omitted.

The param.IsOmitted(any) function can confirm the presence of any omitzero field.

p := vatsense.ExampleParams{
	ID:   "id_xxx",               // required property
	Name: vatsense.String("..."), // optional property

	Point: vatsense.Point{
		X: 0,               // required field will serialize as 0
		Y: vatsense.Int(1), // optional field will serialize as 1
		// ... omitted non-required fields will not be serialized
	},

	Origin: vatsense.Origin{}, // the zero value of [Origin] is considered omitted
}

To send null instead of a param.Opt[T], use param.Null[T](). To send null instead of a struct T, use param.NullStruct[T]().

p.Name = param.Null[string]()       // 'null' instead of string
p.Point = param.NullStruct[Point]() // 'null' instead of struct

param.IsNull(p.Name)  // true
param.IsNull(p.Point) // true

Request structs contain a .SetExtraFields(map[string]any) method which can send non-conforming fields in the request body. Extra fields overwrite any struct fields with a matching key. For security reasons, only use SetExtraFields with trusted data.

To send a custom value instead of a struct, use param.Override[T](value).

// In cases where the API specifies a given type,
// but you want to send something else, use [SetExtraFields]:
p.SetExtraFields(map[string]any{
	"x": 0.01, // send "x" as a float instead of int
})

// Send a number instead of an object
custom := param.Override[vatsense.FooParams](12)
Request unions

Unions are represented as a struct with fields prefixed by "Of" for each of its variants, only one field can be non-zero. The non-zero field will be serialized.

Sub-properties of the union can be accessed via methods on the union struct. These methods return a mutable pointer to the underlying data, if present.

// Only one field can be non-zero, use param.IsOmitted() to check if a field is set
type AnimalUnionParam struct {
	OfCat *Cat `json:",omitzero,inline`
	OfDog *Dog `json:",omitzero,inline`
}

animal := AnimalUnionParam{
	OfCat: &Cat{
		Name: "Whiskers",
		Owner: PersonParam{
			Address: AddressParam{Street: "3333 Coyote Hill Rd", Zip: 0},
		},
	},
}

// Mutating a field
if address := animal.GetOwner().GetAddress(); address != nil {
	address.ZipCode = 94304
}
Response objects

All fields in response structs are ordinary value types (not pointers or wrappers). Response structs also include a special JSON field containing metadata about each property.

type Animal struct {
	Name   string `json:"name,nullable"`
	Owners int    `json:"owners"`
	Age    int    `json:"age"`
	JSON   struct {
		Name        respjson.Field
		Owner       respjson.Field
		Age         respjson.Field
		ExtraFields map[string]respjson.Field
	} `json:"-"`
}

To handle optional data, use the .Valid() method on the JSON field. .Valid() returns true if a field is not null, not present, or couldn't be marshaled.

If .Valid() is false, the corresponding field will simply be its zero value.

raw := `{"owners": 1, "name": null}`

var res Animal
json.Unmarshal([]byte(raw), &res)

// Accessing regular fields

res.Owners // 1
res.Name   // ""
res.Age    // 0

// Optional field checks

res.JSON.Owners.Valid() // true
res.JSON.Name.Valid()   // false
res.JSON.Age.Valid()    // false

// Raw JSON values

res.JSON.Owners.Raw()                  // "1"
res.JSON.Name.Raw() == "null"          // true
res.JSON.Name.Raw() == respjson.Null   // true
res.JSON.Age.Raw() == ""               // true
res.JSON.Age.Raw() == respjson.Omitted // true

These .JSON structs also include an ExtraFields map containing any properties in the json response that were not specified in the struct. This can be useful for API features not yet present in the SDK.

body := res.JSON.ExtraFields["my_unexpected_field"].Raw()
Response Unions

In responses, unions are represented by a flattened struct containing all possible fields from each of the object variants. To convert it to a variant use the .AsFooVariant() method or the .AsAny() method if present.

If a response value union contains primitive values, primitive fields will be alongside the properties but prefixed with Of and feature the tag json:"...,inline".

type AnimalUnion struct {
	// From variants [Dog], [Cat]
	Owner Person `json:"owner"`
	// From variant [Dog]
	DogBreed string `json:"dog_breed"`
	// From variant [Cat]
	CatBreed string `json:"cat_breed"`
	// ...

	JSON struct {
		Owner respjson.Field
		// ...
	} `json:"-"`
}

// If animal variant
if animal.Owner.Address.ZipCode == "" {
	panic("missing zip code")
}

// Switch on the variant
switch variant := animal.AsAny().(type) {
case Dog:
case Cat:
default:
	panic("unexpected type")
}
RequestOptions

This library uses the functional options pattern. Functions defined in the option package return a RequestOption, which is a closure that mutates a RequestConfig. These options can be supplied to the client or at individual requests. For example:

client := vatsense.NewClient(
	// Adds a header to every request made by the client
	option.WithHeader("X-Some-Header", "custom_header_info"),
)

client.Rates.List(context.TODO(), ...,
	// Override the header
	option.WithHeader("X-Some-Header", "some_other_custom_header_info"),
	// Add an undocumented field to the request body, using sjson syntax
	option.WithJSONSet("some.json.path", map[string]string{"my": "object"}),
)

The request option option.WithDebugLog(nil) may be helpful while debugging.

See the full list of request options.

Pagination

This library provides some conveniences for working with paginated list endpoints.

You can use .ListAutoPaging() methods to iterate through items across all pages:

Or you can use simple .List() methods to fetch a single page and receive a standard response object with additional helper methods like .GetNextPage(), e.g.:

Errors

When the API returns a non-success status code, we return an error with type *vatsense.Error. This contains the StatusCode, *http.Request, and *http.Response values of the request, as well as the JSON of the error body (much like other response objects in the SDK).

To handle errors, we recommend that you use the errors.As pattern:

_, err := client.Rates.List(context.TODO(), vatsense.RateListParams{})
if err != nil {
	var apierr *vatsense.Error
	if errors.As(err, &apierr) {
		println(string(apierr.DumpRequest(true)))  // Prints the serialized HTTP request
		println(string(apierr.DumpResponse(true))) // Prints the serialized HTTP response
	}
	panic(err.Error()) // GET "/rates": 400 Bad Request { ... }
}

When other errors occur, they are returned unwrapped; for example, if HTTP transport fails, you might receive *url.Error wrapping *net.OpError.

Timeouts

Requests do not time out by default; use context to configure a timeout for a request lifecycle.

Note that if a request is retried, the context timeout does not start over. To set a per-retry timeout, use option.WithRequestTimeout().

// This sets the timeout for the request, including all the retries.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
client.Rates.List(
	ctx,
	vatsense.RateListParams{},
	// This sets the per-retry timeout
	option.WithRequestTimeout(20*time.Second),
)
File uploads

Request parameters that correspond to file uploads in multipart requests are typed as io.Reader. The contents of the io.Reader will by default be sent as a multipart form part with the file name of "anonymous_file" and content-type of "application/octet-stream".

The file name and content-type can be customized by implementing Name() string or ContentType() string on the run-time type of io.Reader. Note that os.File implements Name() string, so a file returned by os.Open will be sent with the file name on disk.

We also provide a helper vatsense.File(reader io.Reader, filename string, contentType string) which can be used to wrap any io.Reader with the appropriate file name and content type.

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff. We retry by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors.

You can use the WithMaxRetries option to configure or disable this:

// Configure the default for all requests:
client := vatsense.NewClient(
	option.WithMaxRetries(0), // default is 2
)

// Override per-request:
client.Rates.List(
	context.TODO(),
	vatsense.RateListParams{},
	option.WithMaxRetries(5),
)
Accessing raw response data (e.g. response headers)

You can access the raw HTTP response data by using the option.WithResponseInto() request option. This is useful when you need to examine response headers, status codes, or other details.

// Create a variable to store the HTTP response
var response *http.Response
rates, err := client.Rates.List(
	context.TODO(),
	vatsense.RateListParams{},
	option.WithResponseInto(&response),
)
if err != nil {
	// handle error
}
fmt.Printf("%+v\n", rates)

fmt.Printf("Status Code: %d\n", response.StatusCode)
fmt.Printf("Headers: %+#v\n", response.Header)
Making custom/undocumented requests

This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.

Undocumented endpoints

To make requests to undocumented endpoints, you can use client.Get, client.Post, and other HTTP verbs. RequestOptions on the client, such as retries, will be respected when making these requests.

var (
    // params can be an io.Reader, a []byte, an encoding/json serializable object,
    // or a "…Params" struct defined in this library.
    params map[string]any

    // result can be an []byte, *http.Response, a encoding/json deserializable object,
    // or a model defined in this library.
    result *http.Response
)
err := client.Post(context.Background(), "/unspecified", params, &result)
if err != nil {
    …
}
Undocumented request params

To make requests using undocumented parameters, you may use either the option.WithQuerySet() or the option.WithJSONSet() methods.

params := FooNewParams{
    ID:   "id_xxxx",
    Data: FooNewParamsData{
        FirstName: vatsense.String("John"),
    },
}
client.Foo.New(context.Background(), params, option.WithJSONSet("data.last_name", "Doe"))
Undocumented response properties

To access undocumented response properties, you may either access the raw JSON of the response as a string with result.JSON.RawJSON(), or get the raw JSON of a particular field on the result with result.JSON.Foo.Raw().

Any fields that are not present on the response struct will be saved and can be accessed by result.JSON.ExtraFields() which returns the extra fields as a map[string]Field.

Middleware

We provide option.WithMiddleware which applies the given middleware to requests.

func Logger(req *http.Request, next option.MiddlewareNext) (res *http.Response, err error) {
	// Before the request
	start := time.Now()
	LogReq(req)

	// Forward the request to the next handler
	res, err = next(req)

	// Handle stuff after the request
	end := time.Now()
	LogRes(res, err, start - end)

    return res, err
}

client := vatsense.NewClient(
	option.WithMiddleware(Logger),
)

When multiple middlewares are provided as variadic arguments, the middlewares are applied left to right. If option.WithMiddleware is given multiple times, for example first in the client then the method, the middleware in the client will run first and the middleware given in the method will run next.

You may also replace the default http.Client with option.WithHTTPClient(client). Only one http client is accepted (this overwrites any previous client) and receives requests after any middleware has been applied.

Semantic versioning

This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:

  1. Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals.)
  2. Changes that we do not expect to impact the vast majority of users in practice.

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an issue with questions, bugs, or suggestions.

Contributing

See the contributing documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) param.Opt[bool]

func BoolPtr

func BoolPtr(v bool) *bool

func DefaultClientOptions

func DefaultClientOptions() []option.RequestOption

DefaultClientOptions read from the environment (VAT_SENSE_USERNAME, VAT_SENSE_PASSWORD, VAT_SENSE_BASE_URL). This should be used to initialize new clients.

func File

func File(rdr io.Reader, filename string, contentType string) file

func Float

func Float(f float64) param.Opt[float64]

func FloatPtr

func FloatPtr(v float64) *float64

func Int

func Int(i int64) param.Opt[int64]

func IntPtr

func IntPtr(v int64) *int64

func Opt

func Opt[T comparable](v T) param.Opt[T]

func Ptr

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

func String

func String(s string) param.Opt[string]

func StringPtr

func StringPtr(v string) *string

func Time

func Time(t time.Time) param.Opt[time.Time]

func TimePtr

func TimePtr(v time.Time) *time.Time

Types

type Client

type Client struct {

	// VAT/GST rate lookups for countries worldwide
	Rates RateService
	// Country and province information
	Countries CountryService
	// VAT and EORI number validation
	Validate ValidateService
	// Currency exchange rates and conversion
	Currency CurrencyService
	// VAT-compliant invoice management
	Invoice InvoiceService
	// API usage statistics
	Usage UsageService
	// Temporary sandbox API keys for testing
	Sandbox SandboxService
	// contains filtered or unexported fields
}

Client creates a struct with services and top level methods that help with interacting with the vat-sense API. You should not instantiate this client directly, and instead use the NewClient method instead.

func NewClient

func NewClient(opts ...option.RequestOption) (r Client)

NewClient generates a new client with the default option read from the environment (VAT_SENSE_USERNAME, VAT_SENSE_PASSWORD, VAT_SENSE_BASE_URL). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes.

func (*Client) Delete

func (r *Client) Delete(ctx context.Context, path string, params any, res any, opts ...option.RequestOption) error

Delete makes a DELETE request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Execute

func (r *Client) Execute(ctx context.Context, method string, path string, params any, res any, opts ...option.RequestOption) error

Execute makes a request with the given context, method, URL, request params, response, and request options. This is useful for hitting undocumented endpoints while retaining the base URL, auth, retries, and other options from the client.

If a byte slice or an io.Reader is supplied to params, it will be used as-is for the request body.

The params is by default serialized into the body using encoding/json. If your type implements a MarshalJSON function, it will be used instead to serialize the request. If a URLQuery method is implemented, the returned url.Values will be used as query strings to the url.

If your params struct uses param.Field, you must provide either [MarshalJSON], [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a struct uses param.Field without specifying how it is serialized.

Any "…Params" object defined in this library can be used as the request argument. Note that 'path' arguments will not be forwarded into the url.

The response body will be deserialized into the res variable, depending on its type:

  • A pointer to a *http.Response is populated by the raw response.
  • A pointer to a byte array will be populated with the contents of the request body.
  • A pointer to any other type uses this library's default JSON decoding, which respects UnmarshalJSON if it is defined on the type.
  • A nil value will not read the response body.

For even greater flexibility, see option.WithResponseInto and option.WithResponseBodyInto.

func (*Client) Get

func (r *Client) Get(ctx context.Context, path string, params any, res any, opts ...option.RequestOption) error

Get makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Patch

func (r *Client) Patch(ctx context.Context, path string, params any, res any, opts ...option.RequestOption) error

Patch makes a PATCH request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Post

func (r *Client) Post(ctx context.Context, path string, params any, res any, opts ...option.RequestOption) error

Post makes a POST request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Put

func (r *Client) Put(ctx context.Context, path string, params any, res any, opts ...option.RequestOption) error

Put makes a PUT request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

type Country

type Country struct {
	// 2-character ISO 3166-1 alpha-2 country code.
	CountryCode string `json:"country_code"`
	CountryName string `json:"country_name"`
	// Whether the country is subject to EU VAT.
	Eu        bool    `json:"eu"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	// Any of "country".
	Object CountryObject `json:"object"`
	// Whether the country is subject to VAT/GST.
	Vat bool `json:"vat"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		CountryCode respjson.Field
		CountryName respjson.Field
		Eu          respjson.Field
		Latitude    respjson.Field
		Longitude   respjson.Field
		Object      respjson.Field
		Vat         respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (Country) RawJSON

func (r Country) RawJSON() string

Returns the unmodified JSON received from the API

func (*Country) UnmarshalJSON

func (r *Country) UnmarshalJSON(data []byte) error

type CountryListParams

type CountryListParams struct {
	// A 2-character ISO 3166-1 alpha-2 country code (e.g. "GB", "FR").
	CountryCode param.Opt[string] `query:"country_code,omitzero" json:"-"`
	// An IPv4 or IPv6 address. If provided, the country will be determined from the IP
	// address.
	IPAddress param.Opt[string] `query:"ip_address,omitzero" json:"-"`
	// contains filtered or unexported fields
}

func (CountryListParams) URLQuery

func (r CountryListParams) URLQuery() (v url.Values, err error)

URLQuery serializes CountryListParams's query parameters as `url.Values`.

type CountryListProvincesParams

type CountryListProvincesParams struct {
	// A 2-character ISO 3166-1 alpha-2 country code (e.g. "CA").
	CountryCode string `query:"country_code" api:"required" json:"-"`
	// contains filtered or unexported fields
}

func (CountryListProvincesParams) URLQuery

func (r CountryListProvincesParams) URLQuery() (v url.Values, err error)

URLQuery serializes CountryListProvincesParams's query parameters as `url.Values`.

type CountryListProvincesResponse

type CountryListProvincesResponse struct {
	Code    int64                              `json:"code"`
	Data    []CountryListProvincesResponseData `json:"data"`
	Success bool                               `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (CountryListProvincesResponse) RawJSON

Returns the unmodified JSON received from the API

func (*CountryListProvincesResponse) UnmarshalJSON

func (r *CountryListProvincesResponse) UnmarshalJSON(data []byte) error

type CountryListProvincesResponseData

type CountryListProvincesResponseData struct {
	CountryCode string `json:"country_code"`
	// Any of "province".
	Object       string `json:"object"`
	ProvinceCode string `json:"province_code"`
	ProvinceName string `json:"province_name"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		CountryCode  respjson.Field
		Object       respjson.Field
		ProvinceCode respjson.Field
		ProvinceName respjson.Field
		ExtraFields  map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (CountryListProvincesResponseData) RawJSON

Returns the unmodified JSON received from the API

func (*CountryListProvincesResponseData) UnmarshalJSON

func (r *CountryListProvincesResponseData) UnmarshalJSON(data []byte) error

type CountryListResponse

type CountryListResponse struct {
	Code    int64     `json:"code"`
	Data    []Country `json:"data"`
	Success bool      `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (CountryListResponse) RawJSON

func (r CountryListResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*CountryListResponse) UnmarshalJSON

func (r *CountryListResponse) UnmarshalJSON(data []byte) error

type CountryObject

type CountryObject string
const (
	CountryObjectCountry CountryObject = "country"
)

type CountryService

type CountryService struct {
	// contains filtered or unexported fields
}

Country and province information

CountryService contains methods and other services that help with interacting with the vat-sense API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewCountryService method instead.

func NewCountryService

func NewCountryService(opts ...option.RequestOption) (r CountryService)

NewCountryService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*CountryService) List

Returns a list of all countries, including whether they are subject to VAT/GST and whether they are subject to EU VAT. Each country is returned as a country object.

You can optionally filter by country code or IP address.

func (*CountryService) ListProvinces

Retrieve a list of all provinces within a given country.

type CreateInvoiceParam

type CreateInvoiceParam struct {
	Business InvoiceBusinessInputParam `json:"business,omitzero" api:"required"`
	// The 3-character currency code the invoice is billed in.
	CurrencyCode string `json:"currency_code" api:"required"`
	// The date the invoice was issued (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS).
	Date  string                  `json:"date" api:"required"`
	Items []InvoiceItemInputParam `json:"items,omitzero" api:"required"`
	// The tax point or "time of supply" (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS).
	TaxPoint string `json:"tax_point" api:"required"`
	// Whether the invoice is subject to VAT.
	HasVat param.Opt[bool] `json:"has_vat,omitzero"`
	// A unique invoice number. If not provided, defaults to an auto-incremented
	// number.
	InvoiceNumber param.Opt[string] `json:"invoice_number,omitzero"`
	// Whether the invoice is a copy of a primary invoice.
	IsCopy param.Opt[bool] `json:"is_copy,omitzero"`
	// Whether the invoice is zero-rated due to reverse charge.
	IsReverseCharge param.Opt[bool] `json:"is_reverse_charge,omitzero"`
	// Any additional notes for the invoice.
	Notes param.Opt[string] `json:"notes,omitzero"`
	// Pad the auto-generated invoice number with leading zeros to this length.
	PadInvoiceNumber param.Opt[int64] `json:"pad_invoice_number,omitzero"`
	// A serial prepended to the auto-generated invoice number. Each unique serial has
	// its own auto-increment range.
	Serial param.Opt[string] `json:"serial,omitzero"`
	// Whether the invoice has been zero-rated.
	ZeroRated  param.Opt[bool]             `json:"zero_rated,omitzero"`
	Conversion InvoiceConversionInputParam `json:"conversion,omitzero"`
	Customer   InvoiceCustomerInputParam   `json:"customer,omitzero"`
	// Whether item prices include or exclude VAT.
	//
	// Any of "incl", "excl".
	TaxType CreateInvoiceTaxType `json:"tax_type,omitzero"`
	// The type of invoice.
	//
	// Any of "sale", "refund".
	Type CreateInvoiceType `json:"type,omitzero"`
	// contains filtered or unexported fields
}

The properties Business, CurrencyCode, Date, Items, TaxPoint are required.

func (CreateInvoiceParam) MarshalJSON

func (r CreateInvoiceParam) MarshalJSON() (data []byte, err error)

func (*CreateInvoiceParam) UnmarshalJSON

func (r *CreateInvoiceParam) UnmarshalJSON(data []byte) error

type CreateInvoiceTaxType

type CreateInvoiceTaxType string

Whether item prices include or exclude VAT.

const (
	CreateInvoiceTaxTypeIncl CreateInvoiceTaxType = "incl"
	CreateInvoiceTaxTypeExcl CreateInvoiceTaxType = "excl"
)

type CreateInvoiceType

type CreateInvoiceType string

The type of invoice.

const (
	CreateInvoiceTypeSale   CreateInvoiceType = "sale"
	CreateInvoiceTypeRefund CreateInvoiceType = "refund"
)

type CurrencyCalculateVatPriceParams

type CurrencyCalculateVatPriceParams struct {
	// The price to calculate on. Must be a string with exactly 2 decimal places (e.g.
	// "30.00", "59.95").
	Price string `query:"price" api:"required" json:"-"`
	// Whether the provided price is inclusive or exclusive of VAT.
	//
	// Any of "incl", "excl".
	TaxType CurrencyCalculateVatPriceParamsTaxType `query:"tax_type,omitzero" api:"required" json:"-"`
	// A percentage VAT rate to use for the calculation.
	VatRate float64 `query:"vat_rate" api:"required" json:"-"`
	// contains filtered or unexported fields
}

func (CurrencyCalculateVatPriceParams) URLQuery

func (r CurrencyCalculateVatPriceParams) URLQuery() (v url.Values, err error)

URLQuery serializes CurrencyCalculateVatPriceParams's query parameters as `url.Values`.

type CurrencyCalculateVatPriceParamsTaxType

type CurrencyCalculateVatPriceParamsTaxType string

Whether the provided price is inclusive or exclusive of VAT.

const (
	CurrencyCalculateVatPriceParamsTaxTypeIncl CurrencyCalculateVatPriceParamsTaxType = "incl"
	CurrencyCalculateVatPriceParamsTaxTypeExcl CurrencyCalculateVatPriceParamsTaxType = "excl"
)

type CurrencyCalculateVatPriceResponse

type CurrencyCalculateVatPriceResponse struct {
	Code    int64    `json:"code"`
	Data    VatPrice `json:"data"`
	Success bool     `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (CurrencyCalculateVatPriceResponse) RawJSON

Returns the unmodified JSON received from the API

func (*CurrencyCalculateVatPriceResponse) UnmarshalJSON

func (r *CurrencyCalculateVatPriceResponse) UnmarshalJSON(data []byte) error

type CurrencyConvertParams

type CurrencyConvertParams struct {
	// The amount to convert. Must be a string with exactly 2 decimal places (e.g.
	// "39.99").
	Amount string `query:"amount" api:"required" json:"-"`
	// The 3-character source currency code (e.g. "USD", "CAD").
	From string `query:"from" api:"required" json:"-"`
	// The 3-character target currency code. Must be either "GBP" or "EUR".
	//
	// Any of "GBP", "EUR".
	To CurrencyConvertParamsTo `query:"to,omitzero" api:"required" json:"-"`
	// contains filtered or unexported fields
}

func (CurrencyConvertParams) URLQuery

func (r CurrencyConvertParams) URLQuery() (v url.Values, err error)

URLQuery serializes CurrencyConvertParams's query parameters as `url.Values`.

type CurrencyConvertParamsTo

type CurrencyConvertParamsTo string

The 3-character target currency code. Must be either "GBP" or "EUR".

const (
	CurrencyConvertParamsToGbp CurrencyConvertParamsTo = "GBP"
	CurrencyConvertParamsToEur CurrencyConvertParamsTo = "EUR"
)

type CurrencyConvertResponse

type CurrencyConvertResponse struct {
	Code    int64                       `json:"code"`
	Data    CurrencyConvertResponseData `json:"data"`
	Success bool                        `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (CurrencyConvertResponse) RawJSON

func (r CurrencyConvertResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*CurrencyConvertResponse) UnmarshalJSON

func (r *CurrencyConvertResponse) UnmarshalJSON(data []byte) error

type CurrencyConvertResponseData

type CurrencyConvertResponseData struct {
	// The original amount.
	Amount float64 `json:"amount"`
	// The converted amount.
	Converted float64 `json:"converted"`
	From      string  `json:"from"`
	// Any of "conversion".
	Object string `json:"object"`
	// The exchange rate used.
	Rate float64 `json:"rate"`
	To   string  `json:"to"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Amount      respjson.Field
		Converted   respjson.Field
		From        respjson.Field
		Object      respjson.Field
		Rate        respjson.Field
		To          respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (CurrencyConvertResponseData) RawJSON

func (r CurrencyConvertResponseData) RawJSON() string

Returns the unmodified JSON received from the API

func (*CurrencyConvertResponseData) UnmarshalJSON

func (r *CurrencyConvertResponseData) UnmarshalJSON(data []byte) error

type CurrencyListParams

type CurrencyListParams struct {
	// The 3-character currency code(s) to convert from (e.g. "USD", "CAD"). Can be a
	// comma-separated list without spaces (e.g. "USD,CAD,AUD").
	From param.Opt[string] `query:"from,omitzero" json:"-"`
	// The 3-character target currency code. Must be either "GBP" or "EUR".
	//
	// Any of "GBP", "EUR".
	To CurrencyListParamsTo `query:"to,omitzero" json:"-"`
	// contains filtered or unexported fields
}

func (CurrencyListParams) URLQuery

func (r CurrencyListParams) URLQuery() (v url.Values, err error)

URLQuery serializes CurrencyListParams's query parameters as `url.Values`.

type CurrencyListParamsTo

type CurrencyListParamsTo string

The 3-character target currency code. Must be either "GBP" or "EUR".

const (
	CurrencyListParamsToGbp CurrencyListParamsTo = "GBP"
	CurrencyListParamsToEur CurrencyListParamsTo = "EUR"
)

type CurrencyListResponse

type CurrencyListResponse struct {
	Code    int64                      `json:"code"`
	Data    []CurrencyListResponseData `json:"data"`
	Success bool                       `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (CurrencyListResponse) RawJSON

func (r CurrencyListResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*CurrencyListResponse) UnmarshalJSON

func (r *CurrencyListResponse) UnmarshalJSON(data []byte) error

type CurrencyListResponseData

type CurrencyListResponseData struct {
	// The 3-character source currency code.
	From string `json:"from"`
	// Any of "convert_rate".
	Object string `json:"object"`
	// The exchange rate.
	Rate float64 `json:"rate"`
	// The 3-character target currency code (GBP or EUR).
	To string `json:"to"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		From        respjson.Field
		Object      respjson.Field
		Rate        respjson.Field
		To          respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (CurrencyListResponseData) RawJSON

func (r CurrencyListResponseData) RawJSON() string

Returns the unmodified JSON received from the API

func (*CurrencyListResponseData) UnmarshalJSON

func (r *CurrencyListResponseData) UnmarshalJSON(data []byte) error

type CurrencyService

type CurrencyService struct {
	// contains filtered or unexported fields
}

Currency exchange rates and conversion

CurrencyService contains methods and other services that help with interacting with the vat-sense API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewCurrencyService method instead.

func NewCurrencyService

func NewCurrencyService(opts ...option.RequestOption) (r CurrencyService)

NewCurrencyService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*CurrencyService) CalculateVatPrice

Calculate the inclusive and exclusive VAT price on a given amount and VAT rate. This is a standalone calculation that does not look up rates by country.

func (*CurrencyService) Convert

Convert a foreign currency amount to either GBP or EUR using official exchange rates.

GBP rates are from HMRC (updated on the 1st of every month). EUR rates are from the European Central Bank (updated around 16:00 CET on working days).

func (*CurrencyService) List

Returns a list of all currency conversion rates sourced from HMRC (GBP) and the European Central Bank (EUR).

You can optionally filter by source and target currency.

type Error

type Error = apierror.Error

type FindRate

type FindRate struct {
	Code    int64           `json:"code"`
	Data    RateWithTaxRate `json:"data"`
	Success bool            `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (FindRate) RawJSON

func (r FindRate) RawJSON() string

Returns the unmodified JSON received from the API

func (*FindRate) UnmarshalJSON

func (r *FindRate) UnmarshalJSON(data []byte) error

type Invoice

type Invoice struct {
	ID            string                 `json:"id"`
	Business      InvoiceBusiness        `json:"business"`
	Conversion    InvoiceConversionInput `json:"conversion" api:"nullable"`
	Created       time.Time              `json:"created" format:"date-time"`
	CurrencyCode  string                 `json:"currency_code"`
	Customer      InvoiceCustomer        `json:"customer" api:"nullable"`
	Date          string                 `json:"date"`
	HasVat        bool                   `json:"has_vat"`
	InvoiceNumber string                 `json:"invoice_number"`
	// Unique URL to view the invoice. Append "/pdf" to download a PDF copy.
	InvoiceURL      string        `json:"invoice_url" format:"uri"`
	IsCopy          bool          `json:"is_copy"`
	IsReverseCharge bool          `json:"is_reverse_charge"`
	Items           []InvoiceItem `json:"items"`
	Notes           string        `json:"notes" api:"nullable"`
	NumItems        int64         `json:"num_items"`
	// Any of "invoice".
	Object   InvoiceObject `json:"object"`
	TaxPoint string        `json:"tax_point"`
	// Any of "incl", "excl".
	TaxType InvoiceTaxType `json:"tax_type"`
	Totals  InvoiceTotals  `json:"totals"`
	// Any of "sale", "refund".
	Type      InvoiceType `json:"type"`
	Updated   time.Time   `json:"updated" format:"date-time"`
	ZeroRated bool        `json:"zero_rated"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID              respjson.Field
		Business        respjson.Field
		Conversion      respjson.Field
		Created         respjson.Field
		CurrencyCode    respjson.Field
		Customer        respjson.Field
		Date            respjson.Field
		HasVat          respjson.Field
		InvoiceNumber   respjson.Field
		InvoiceURL      respjson.Field
		IsCopy          respjson.Field
		IsReverseCharge respjson.Field
		Items           respjson.Field
		Notes           respjson.Field
		NumItems        respjson.Field
		Object          respjson.Field
		TaxPoint        respjson.Field
		TaxType         respjson.Field
		Totals          respjson.Field
		Type            respjson.Field
		Updated         respjson.Field
		ZeroRated       respjson.Field
		ExtraFields     map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (Invoice) RawJSON

func (r Invoice) RawJSON() string

Returns the unmodified JSON received from the API

func (*Invoice) UnmarshalJSON

func (r *Invoice) UnmarshalJSON(data []byte) error

type InvoiceBusiness

type InvoiceBusiness struct {
	Address       string `json:"address"`
	CompanyNumber string `json:"company_number"`
	Name          string `json:"name"`
	VatNumber     string `json:"vat_number"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Address       respjson.Field
		CompanyNumber respjson.Field
		Logo          respjson.Field
		Name          respjson.Field
		VatNumber     respjson.Field
		ExtraFields   map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceBusiness) RawJSON

func (r InvoiceBusiness) RawJSON() string

Returns the unmodified JSON received from the API

func (*InvoiceBusiness) UnmarshalJSON

func (r *InvoiceBusiness) UnmarshalJSON(data []byte) error

type InvoiceBusinessInputParam

type InvoiceBusinessInputParam struct {
	// Your business trading address.
	Address string `json:"address" api:"required"`
	// Your business trading name.
	Name string `json:"name" api:"required"`
	// Your business VAT number.
	VatNumber   string            `json:"vat_number" api:"required"`
	BankAccount param.Opt[string] `json:"bank_account,omitzero"`
	// Your business company number.
	CompanyNumber param.Opt[string] `json:"company_number,omitzero"`
	Email         param.Opt[string] `json:"email,omitzero" format:"email"`
	// URL to your company logo (HTTPS only, .svg/.jpg/.png). Recommended 240px by
	// 60px.
	Phone   param.Opt[string] `json:"phone,omitzero"`
	Website param.Opt[string] `json:"website,omitzero" format:"uri"`
	// contains filtered or unexported fields
}

The properties Address, Name, VatNumber are required.

func (InvoiceBusinessInputParam) MarshalJSON

func (r InvoiceBusinessInputParam) MarshalJSON() (data []byte, err error)

func (*InvoiceBusinessInputParam) UnmarshalJSON

func (r *InvoiceBusinessInputParam) UnmarshalJSON(data []byte) error

type InvoiceConversionInput

type InvoiceConversionInput struct {
	// The 3-character currency code for the conversion.
	CurrencyCode string `json:"currency_code" api:"required"`
	// The rate of conversion.
	Rate float64 `json:"rate" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		CurrencyCode respjson.Field
		Rate         respjson.Field
		ExtraFields  map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceConversionInput) RawJSON

func (r InvoiceConversionInput) RawJSON() string

Returns the unmodified JSON received from the API

func (InvoiceConversionInput) ToParam

ToParam converts this InvoiceConversionInput to a InvoiceConversionInputParam.

Warning: the fields of the param type will not be present. ToParam should only be used at the last possible moment before sending a request. Test for this with InvoiceConversionInputParam.Overrides()

func (*InvoiceConversionInput) UnmarshalJSON

func (r *InvoiceConversionInput) UnmarshalJSON(data []byte) error

type InvoiceConversionInputParam

type InvoiceConversionInputParam struct {
	// The 3-character currency code for the conversion.
	CurrencyCode string `json:"currency_code" api:"required"`
	// The rate of conversion.
	Rate float64 `json:"rate" api:"required"`
	// contains filtered or unexported fields
}

The properties CurrencyCode, Rate are required.

func (InvoiceConversionInputParam) MarshalJSON

func (r InvoiceConversionInputParam) MarshalJSON() (data []byte, err error)

func (*InvoiceConversionInputParam) UnmarshalJSON

func (r *InvoiceConversionInputParam) UnmarshalJSON(data []byte) error

type InvoiceCustomer

type InvoiceCustomer struct {
	Address       string `json:"address"`
	CompanyNumber string `json:"company_number"`
	Name          string `json:"name"`
	VatNumber     string `json:"vat_number"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Address       respjson.Field
		CompanyNumber respjson.Field
		Logo          respjson.Field
		Name          respjson.Field
		VatNumber     respjson.Field
		ExtraFields   map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceCustomer) RawJSON

func (r InvoiceCustomer) RawJSON() string

Returns the unmodified JSON received from the API

func (*InvoiceCustomer) UnmarshalJSON

func (r *InvoiceCustomer) UnmarshalJSON(data []byte) error

type InvoiceCustomerInputParam

type InvoiceCustomerInputParam struct {
	// The customer's trading name.
	Name          string            `json:"name" api:"required"`
	Address       param.Opt[string] `json:"address,omitzero"`
	CompanyNumber param.Opt[string] `json:"company_number,omitzero"`
	CountryCode   param.Opt[string] `json:"country_code,omitzero"`
	Email         param.Opt[string] `json:"email,omitzero" format:"email"`
	// URL to the customer logo (HTTPS only, .jpg/.png).
	VatNumber param.Opt[string] `json:"vat_number,omitzero"`
	// contains filtered or unexported fields
}

The property Name is required.

func (InvoiceCustomerInputParam) MarshalJSON

func (r InvoiceCustomerInputParam) MarshalJSON() (data []byte, err error)

func (*InvoiceCustomerInputParam) UnmarshalJSON

func (r *InvoiceCustomerInputParam) UnmarshalJSON(data []byte) error

type InvoiceDeleteResponse

type InvoiceDeleteResponse struct {
	Code    int64 `json:"code" api:"required"`
	Success bool  `json:"success" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceDeleteResponse) RawJSON

func (r InvoiceDeleteResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*InvoiceDeleteResponse) UnmarshalJSON

func (r *InvoiceDeleteResponse) UnmarshalJSON(data []byte) error

type InvoiceItem

type InvoiceItem struct {
	ID           string  `json:"id"`
	DiscountRate float64 `json:"discount_rate" api:"nullable"`
	Item         string  `json:"item"`
	// Any of "item".
	Object     InvoiceItemObject `json:"object"`
	PriceEach  float64           `json:"price_each"`
	PriceTotal float64           `json:"price_total"`
	Quantity   float64           `json:"quantity"`
	VatRate    float64           `json:"vat_rate"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID           respjson.Field
		DiscountRate respjson.Field
		Item         respjson.Field
		Object       respjson.Field
		PriceEach    respjson.Field
		PriceTotal   respjson.Field
		Quantity     respjson.Field
		VatRate      respjson.Field
		ExtraFields  map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceItem) RawJSON

func (r InvoiceItem) RawJSON() string

Returns the unmodified JSON received from the API

func (*InvoiceItem) UnmarshalJSON

func (r *InvoiceItem) UnmarshalJSON(data []byte) error

type InvoiceItemAddParams

type InvoiceItemAddParams struct {
	Items []InvoiceItemInputParam `json:"items,omitzero" api:"required"`
	// contains filtered or unexported fields
}

func (InvoiceItemAddParams) MarshalJSON

func (r InvoiceItemAddParams) MarshalJSON() (data []byte, err error)

func (*InvoiceItemAddParams) UnmarshalJSON

func (r *InvoiceItemAddParams) UnmarshalJSON(data []byte) error

type InvoiceItemDeleteParams

type InvoiceItemDeleteParams struct {
	InvoiceID string `path:"invoice_id" api:"required" json:"-"`
	// contains filtered or unexported fields
}

type InvoiceItemGetParams

type InvoiceItemGetParams struct {
	InvoiceID string `path:"invoice_id" api:"required" json:"-"`
	// contains filtered or unexported fields
}

type InvoiceItemGetResponse

type InvoiceItemGetResponse struct {
	Code    int64       `json:"code"`
	Data    InvoiceItem `json:"data"`
	Success bool        `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceItemGetResponse) RawJSON

func (r InvoiceItemGetResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*InvoiceItemGetResponse) UnmarshalJSON

func (r *InvoiceItemGetResponse) UnmarshalJSON(data []byte) error

type InvoiceItemInputParam

type InvoiceItemInputParam struct {
	// The description of the line item.
	Item string `json:"item" api:"required"`
	// The price per item. Must be a decimal with 2 decimal places.
	PriceEach float64 `json:"price_each" api:"required"`
	// The quantity of the item.
	Quantity float64 `json:"quantity" api:"required"`
	// A percentage VAT rate for this item.
	VatRate float64 `json:"vat_rate" api:"required"`
	// A percentage discount to apply to the price.
	DiscountRate param.Opt[float64] `json:"discount_rate,omitzero"`
	// contains filtered or unexported fields
}

The properties Item, PriceEach, Quantity, VatRate are required.

func (InvoiceItemInputParam) MarshalJSON

func (r InvoiceItemInputParam) MarshalJSON() (data []byte, err error)

func (*InvoiceItemInputParam) UnmarshalJSON

func (r *InvoiceItemInputParam) UnmarshalJSON(data []byte) error

type InvoiceItemObject

type InvoiceItemObject string
const (
	InvoiceItemObjectItem InvoiceItemObject = "item"
)

type InvoiceItemService

type InvoiceItemService struct {
	// contains filtered or unexported fields
}

VAT-compliant invoice management

InvoiceItemService contains methods and other services that help with interacting with the vat-sense API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewInvoiceItemService method instead.

func NewInvoiceItemService

func NewInvoiceItemService(opts ...option.RequestOption) (r InvoiceItemService)

NewInvoiceItemService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*InvoiceItemService) Add

func (r *InvoiceItemService) Add(ctx context.Context, invoiceID string, body InvoiceItemAddParams, opts ...option.RequestOption) (res *InvoiceResponse, err error)

Add one or more line items to an existing invoice.

func (*InvoiceItemService) Delete

func (r *InvoiceItemService) Delete(ctx context.Context, itemID string, body InvoiceItemDeleteParams, opts ...option.RequestOption) (res *InvoiceResponse, err error)

Remove a specific line item from an invoice.

func (*InvoiceItemService) Get

Retrieve a specific line item from an invoice.

func (*InvoiceItemService) Update

func (r *InvoiceItemService) Update(ctx context.Context, itemID string, params InvoiceItemUpdateParams, opts ...option.RequestOption) (res *InvoiceResponse, err error)

Update a specific line item on an invoice.

type InvoiceItemUpdateParams

type InvoiceItemUpdateParams struct {
	InvoiceID        string `path:"invoice_id" api:"required" json:"-"`
	InvoiceItemInput InvoiceItemInputParam
	// contains filtered or unexported fields
}

func (InvoiceItemUpdateParams) MarshalJSON

func (r InvoiceItemUpdateParams) MarshalJSON() (data []byte, err error)

func (*InvoiceItemUpdateParams) UnmarshalJSON

func (r *InvoiceItemUpdateParams) UnmarshalJSON(data []byte) error

type InvoiceListParams

type InvoiceListParams struct {
	// Number of invoices to return (default 10, max 100).
	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
	// Number of invoices to skip (default 0).
	Offset param.Opt[int64] `query:"offset,omitzero" json:"-"`
	// Search query to filter invoices.
	Search param.Opt[string] `query:"search,omitzero" json:"-"`
	// contains filtered or unexported fields
}

func (InvoiceListParams) URLQuery

func (r InvoiceListParams) URLQuery() (v url.Values, err error)

URLQuery serializes InvoiceListParams's query parameters as `url.Values`.

type InvoiceListResponse

type InvoiceListResponse struct {
	Code    int64     `json:"code"`
	Data    []Invoice `json:"data"`
	Success bool      `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceListResponse) RawJSON

func (r InvoiceListResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*InvoiceListResponse) UnmarshalJSON

func (r *InvoiceListResponse) UnmarshalJSON(data []byte) error

type InvoiceNewParams

type InvoiceNewParams struct {
	CreateInvoice CreateInvoiceParam
	// contains filtered or unexported fields
}

func (InvoiceNewParams) MarshalJSON

func (r InvoiceNewParams) MarshalJSON() (data []byte, err error)

func (*InvoiceNewParams) UnmarshalJSON

func (r *InvoiceNewParams) UnmarshalJSON(data []byte) error

type InvoiceObject

type InvoiceObject string
const (
	InvoiceObjectInvoice InvoiceObject = "invoice"
)

type InvoiceResponse

type InvoiceResponse struct {
	Code    int64   `json:"code"`
	Data    Invoice `json:"data"`
	Success bool    `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceResponse) RawJSON

func (r InvoiceResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*InvoiceResponse) UnmarshalJSON

func (r *InvoiceResponse) UnmarshalJSON(data []byte) error

type InvoiceService

type InvoiceService struct {

	// VAT-compliant invoice management
	Item InvoiceItemService
	// contains filtered or unexported fields
}

VAT-compliant invoice management

InvoiceService contains methods and other services that help with interacting with the vat-sense API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewInvoiceService method instead.

func NewInvoiceService

func NewInvoiceService(opts ...option.RequestOption) (r InvoiceService)

NewInvoiceService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*InvoiceService) Delete

func (r *InvoiceService) Delete(ctx context.Context, invoiceID string, opts ...option.RequestOption) (res *InvoiceDeleteResponse, err error)

Permanently delete an invoice.

func (*InvoiceService) Get

func (r *InvoiceService) Get(ctx context.Context, invoiceID string, opts ...option.RequestOption) (res *InvoiceResponse, err error)

Retrieve a specific invoice by its ID.

func (*InvoiceService) List

Retrieve a paginated list of all invoices.

func (*InvoiceService) New

Create a new VAT-compliant invoice. VAT Sense will automatically calculate the totals based on the items provided.

Not available with sandbox API keys.

func (*InvoiceService) Update

func (r *InvoiceService) Update(ctx context.Context, invoiceID string, body InvoiceUpdateParams, opts ...option.RequestOption) (res *InvoiceResponse, err error)

Update an existing invoice. Only the fields provided will be updated.

type InvoiceTaxType

type InvoiceTaxType string
const (
	InvoiceTaxTypeIncl InvoiceTaxType = "incl"
	InvoiceTaxTypeExcl InvoiceTaxType = "excl"
)

type InvoiceTotals

type InvoiceTotals struct {
	// Total discount amount.
	Discount float64 `json:"discount"`
	// Total before VAT.
	Subtotal float64 `json:"subtotal"`
	// Grand total.
	Total float64 `json:"total"`
	// Total VAT amount.
	Vat float64 `json:"vat"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Discount    respjson.Field
		Subtotal    respjson.Field
		Total       respjson.Field
		Vat         respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (InvoiceTotals) RawJSON

func (r InvoiceTotals) RawJSON() string

Returns the unmodified JSON received from the API

func (*InvoiceTotals) UnmarshalJSON

func (r *InvoiceTotals) UnmarshalJSON(data []byte) error

type InvoiceType

type InvoiceType string
const (
	InvoiceTypeSale   InvoiceType = "sale"
	InvoiceTypeRefund InvoiceType = "refund"
)

type InvoiceUpdateParams

type InvoiceUpdateParams struct {
	CreateInvoice CreateInvoiceParam
	// contains filtered or unexported fields
}

func (InvoiceUpdateParams) MarshalJSON

func (r InvoiceUpdateParams) MarshalJSON() (data []byte, err error)

func (*InvoiceUpdateParams) UnmarshalJSON

func (r *InvoiceUpdateParams) UnmarshalJSON(data []byte) error

type Rate

type Rate struct {
	// 2-character ISO 3166-1 alpha-2 country code.
	CountryCode string `json:"country_code"`
	CountryName string `json:"country_name"`
	// Whether the country is an EU member.
	Eu bool `json:"eu"`
	// Any of "rate".
	Object RateObject `json:"object"`
	// A list of other tax rates. Null if no additional rates exist.
	Other    []RateOther `json:"other" api:"nullable"`
	Standard TaxRate     `json:"standard"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		CountryCode respjson.Field
		CountryName respjson.Field
		Eu          respjson.Field
		Object      respjson.Field
		Other       respjson.Field
		Standard    respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (Rate) RawJSON

func (r Rate) RawJSON() string

Returns the unmodified JSON received from the API

func (*Rate) UnmarshalJSON

func (r *Rate) UnmarshalJSON(data []byte) error

type RateCalculatePriceParams

type RateCalculatePriceParams struct {
	// The price to calculate on. Must be a string with exactly 2 decimal places (e.g.
	// "30.00", "59.95").
	Price string `query:"price" api:"required" json:"-"`
	// Whether the provided price is inclusive or exclusive of VAT.
	//
	// Any of "incl", "excl".
	TaxType RateCalculatePriceParamsTaxType `query:"tax_type,omitzero" api:"required" json:"-"`
	// A 2-character ISO 3166-1 alpha-2 country code (e.g. "GB", "FR").
	CountryCode param.Opt[string] `query:"country_code,omitzero" json:"-"`
	// Filter results by EU membership. Use 1 for EU countries only, 0 for non-EU only.
	Eu param.Opt[bool] `query:"eu,omitzero" json:"-"`
	// An IPv4 or IPv6 address. If provided, the country will be determined from the IP
	// address.
	IPAddress param.Opt[string] `query:"ip_address,omitzero" json:"-"`
	// A 2-character province code (e.g. "NU", "NT"). If providing a province code, you
	// must also provide the relevant country_code.
	ProvinceCode param.Opt[string] `query:"province_code,omitzero" json:"-"`
	// The product type to find the applicable rate for. See the /rates/types endpoint
	// for a full list of valid values.
	Type param.Opt[string] `query:"type,omitzero" json:"-"`
	// contains filtered or unexported fields
}

func (RateCalculatePriceParams) URLQuery

func (r RateCalculatePriceParams) URLQuery() (v url.Values, err error)

URLQuery serializes RateCalculatePriceParams's query parameters as `url.Values`.

type RateCalculatePriceParamsTaxType

type RateCalculatePriceParamsTaxType string

Whether the provided price is inclusive or exclusive of VAT.

const (
	RateCalculatePriceParamsTaxTypeIncl RateCalculatePriceParamsTaxType = "incl"
	RateCalculatePriceParamsTaxTypeExcl RateCalculatePriceParamsTaxType = "excl"
)

type RateCalculatePriceResponse

type RateCalculatePriceResponse struct {
	Code    int64                          `json:"code"`
	Data    RateCalculatePriceResponseData `json:"data"`
	Success bool                           `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (RateCalculatePriceResponse) RawJSON

func (r RateCalculatePriceResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*RateCalculatePriceResponse) UnmarshalJSON

func (r *RateCalculatePriceResponse) UnmarshalJSON(data []byte) error

type RateCalculatePriceResponseData

type RateCalculatePriceResponseData struct {
	CountryCode string `json:"country_code"`
	CountryName string `json:"country_name"`
	Eu          bool   `json:"eu"`
	// Any of "rate".
	Object   string   `json:"object"`
	TaxRate  TaxRate  `json:"tax_rate"`
	VatPrice VatPrice `json:"vat_price"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		CountryCode respjson.Field
		CountryName respjson.Field
		Eu          respjson.Field
		Object      respjson.Field
		TaxRate     respjson.Field
		VatPrice    respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (RateCalculatePriceResponseData) RawJSON

Returns the unmodified JSON received from the API

func (*RateCalculatePriceResponseData) UnmarshalJSON

func (r *RateCalculatePriceResponseData) UnmarshalJSON(data []byte) error

type RateDetailsParams

type RateDetailsParams struct {
	// A 2-character ISO 3166-1 alpha-2 country code (e.g. "GB", "FR").
	CountryCode param.Opt[string] `query:"country_code,omitzero" json:"-"`
	// Filter results by EU membership. Use 1 for EU countries only, 0 for non-EU only.
	Eu param.Opt[bool] `query:"eu,omitzero" json:"-"`
	// An IPv4 or IPv6 address. If provided, the country will be determined from the IP
	// address.
	IPAddress param.Opt[string] `query:"ip_address,omitzero" json:"-"`
	// A historical date to retrieve rates for (format "YYYY-MM-DD HH:MM:SS"). Must be
	// a past date.
	Period param.Opt[time.Time] `query:"period,omitzero" format:"date-time" json:"-"`
	// A 2-character province code (e.g. "NU", "NT"). If providing a province code, you
	// must also provide the relevant country_code.
	ProvinceCode param.Opt[string] `query:"province_code,omitzero" json:"-"`
	// The product type to find the applicable rate for. See the /rates/types endpoint
	// for a full list of valid values.
	Type param.Opt[string] `query:"type,omitzero" json:"-"`
	// contains filtered or unexported fields
}

func (RateDetailsParams) URLQuery

func (r RateDetailsParams) URLQuery() (v url.Values, err error)

URLQuery serializes RateDetailsParams's query parameters as `url.Values`.

type RateFindParams

type RateFindParams struct {
	// A 2-character ISO 3166-1 alpha-2 country code (e.g. "GB", "FR").
	CountryCode param.Opt[string] `query:"country_code,omitzero" json:"-"`
	// Filter results by EU membership. Use 1 for EU countries only, 0 for non-EU only.
	Eu param.Opt[bool] `query:"eu,omitzero" json:"-"`
	// An IPv4 or IPv6 address. If provided, the country will be determined from the IP
	// address.
	IPAddress param.Opt[string] `query:"ip_address,omitzero" json:"-"`
	// A historical date to retrieve rates for (format "YYYY-MM-DD HH:MM:SS"). Must be
	// a past date.
	Period param.Opt[time.Time] `query:"period,omitzero" format:"date-time" json:"-"`
	// A 2-character province code (e.g. "NU", "NT"). If providing a province code, you
	// must also provide the relevant country_code.
	ProvinceCode param.Opt[string] `query:"province_code,omitzero" json:"-"`
	// The product type to find the applicable rate for. See the /rates/types endpoint
	// for a full list of valid values.
	Type param.Opt[string] `query:"type,omitzero" json:"-"`
	// contains filtered or unexported fields
}

func (RateFindParams) URLQuery

func (r RateFindParams) URLQuery() (v url.Values, err error)

URLQuery serializes RateFindParams's query parameters as `url.Values`.

type RateListParams

type RateListParams struct {
	// A 2-character ISO 3166-1 alpha-2 country code (e.g. "GB", "FR").
	CountryCode param.Opt[string] `query:"country_code,omitzero" json:"-"`
	// Filter results by EU membership. Use 1 for EU countries only, 0 for non-EU only.
	Eu param.Opt[bool] `query:"eu,omitzero" json:"-"`
	// An IPv4 or IPv6 address. If provided, the country will be determined from the IP
	// address.
	IPAddress param.Opt[string] `query:"ip_address,omitzero" json:"-"`
	// A historical date to retrieve rates for (format "YYYY-MM-DD HH:MM:SS"). Must be
	// a past date.
	Period param.Opt[time.Time] `query:"period,omitzero" format:"date-time" json:"-"`
	// contains filtered or unexported fields
}

func (RateListParams) URLQuery

func (r RateListParams) URLQuery() (v url.Values, err error)

URLQuery serializes RateListParams's query parameters as `url.Values`.

type RateListResponse

type RateListResponse struct {
	Code    int64  `json:"code"`
	Data    []Rate `json:"data"`
	Success bool   `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (RateListResponse) RawJSON

func (r RateListResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*RateListResponse) UnmarshalJSON

func (r *RateListResponse) UnmarshalJSON(data []byte) error

type RateListTypesResponse

type RateListTypesResponse struct {
	Code    int64    `json:"code"`
	Data    []string `json:"data"`
	Success bool     `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (RateListTypesResponse) RawJSON

func (r RateListTypesResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*RateListTypesResponse) UnmarshalJSON

func (r *RateListTypesResponse) UnmarshalJSON(data []byte) error

type RateObject

type RateObject string
const (
	RateObjectRate RateObject = "rate"
)

type RateOther

type RateOther struct {
	// The province this rate applies to, if applicable.
	Province string `json:"province" api:"nullable"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Province    respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
	TaxRate
}

func (RateOther) RawJSON

func (r RateOther) RawJSON() string

Returns the unmodified JSON received from the API

func (*RateOther) UnmarshalJSON

func (r *RateOther) UnmarshalJSON(data []byte) error

type RateService

type RateService struct {
	// contains filtered or unexported fields
}

VAT/GST rate lookups for countries worldwide

RateService contains methods and other services that help with interacting with the vat-sense API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewRateService method instead.

func NewRateService

func NewRateService(opts ...option.RequestOption) (r RateService)

NewRateService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*RateService) CalculatePrice

func (r *RateService) CalculatePrice(ctx context.Context, query RateCalculatePriceParams, opts ...option.RequestOption) (res *RateCalculatePriceResponse, err error)

Combines the functionality of the "Find a tax rate" and "VAT price calculation" endpoints to return the particular VAT price for an applicable VAT rate. Requires both a location (country_code or ip_address) and a price to calculate.

func (*RateService) Details

func (r *RateService) Details(ctx context.Context, query RateDetailsParams, opts ...option.RequestOption) (res *FindRate, err error)

Get detailed tax rate information for a location, including all applicable rate classes (standard, reduced, zero, etc.).

func (*RateService) Find

func (r *RateService) Find(ctx context.Context, query RateFindParams, opts ...option.RequestOption) (res *FindRate, err error)

A handy endpoint for finding a rate that applies to a particular country and optional product type, based on country code or IP address.

If no type is provided, or no specific rate is applied to the given type, then the standard rate will be returned if the country is subject to tax.

If the country is not subject to VAT/GST then an error response will be returned, indicating no tax applies.

func (*RateService) List

func (r *RateService) List(ctx context.Context, query RateListParams, opts ...option.RequestOption) (res *RateListResponse, err error)

Returns a list of VAT/GST rates for all countries, sorted alphabetically by country code. Each rate is returned as a rate object containing the standard rate and any other applicable rates.

You can optionally filter by country code, IP address, or EU membership.

func (*RateService) ListTypes

func (r *RateService) ListTypes(ctx context.Context, opts ...option.RequestOption) (res *RateListTypesResponse, err error)

Returns a list of all available product types that can be used to filter tax rates.

type RateWithTaxRate

type RateWithTaxRate struct {
	CountryCode string `json:"country_code"`
	CountryName string `json:"country_name"`
	Eu          bool   `json:"eu"`
	// Any of "rate".
	Object  RateWithTaxRateObject `json:"object"`
	TaxRate TaxRate               `json:"tax_rate"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		CountryCode respjson.Field
		CountryName respjson.Field
		Eu          respjson.Field
		Object      respjson.Field
		TaxRate     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (RateWithTaxRate) RawJSON

func (r RateWithTaxRate) RawJSON() string

Returns the unmodified JSON received from the API

func (*RateWithTaxRate) UnmarshalJSON

func (r *RateWithTaxRate) UnmarshalJSON(data []byte) error

type RateWithTaxRateObject

type RateWithTaxRateObject string
const (
	RateWithTaxRateObjectRate RateWithTaxRateObject = "rate"
)

type SandboxGenerateKeyResponse

type SandboxGenerateKeyResponse struct {
	Code    int64                          `json:"code"`
	Data    SandboxGenerateKeyResponseData `json:"data"`
	Success bool                           `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (SandboxGenerateKeyResponse) RawJSON

func (r SandboxGenerateKeyResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*SandboxGenerateKeyResponse) UnmarshalJSON

func (r *SandboxGenerateKeyResponse) UnmarshalJSON(data []byte) error

type SandboxGenerateKeyResponseData

type SandboxGenerateKeyResponseData struct {
	AllowedEndpoints []string  `json:"allowed_endpoints"`
	ExpiresAt        time.Time `json:"expires_at" format:"date-time"`
	// The temporary sandbox API key.
	Key               string `json:"key"`
	RequestsRemaining int64  `json:"requests_remaining"`
	SignupURL         string `json:"signup_url" format:"uri"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		AllowedEndpoints  respjson.Field
		ExpiresAt         respjson.Field
		Key               respjson.Field
		RequestsRemaining respjson.Field
		SignupURL         respjson.Field
		ExtraFields       map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (SandboxGenerateKeyResponseData) RawJSON

Returns the unmodified JSON received from the API

func (*SandboxGenerateKeyResponseData) UnmarshalJSON

func (r *SandboxGenerateKeyResponseData) UnmarshalJSON(data []byte) error

type SandboxService

type SandboxService struct {
	// contains filtered or unexported fields
}

Temporary sandbox API keys for testing

SandboxService contains methods and other services that help with interacting with the vat-sense API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewSandboxService method instead.

func NewSandboxService

func NewSandboxService(opts ...option.RequestOption) (r SandboxService)

NewSandboxService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*SandboxService) GenerateKey

func (r *SandboxService) GenerateKey(ctx context.Context, opts ...option.RequestOption) (res *SandboxGenerateKeyResponse, err error)

Generate a temporary sandbox API key for testing. Sandbox keys have limited request allowances and restricted endpoint access (no invoice endpoints). Rate limited to 1 key per IP address per 6 hours.

type TaxRate

type TaxRate struct {
	// The rate class (e.g. "standard", "reduced", "zero").
	Class string `json:"class"`
	// A description of what goods/services this rate applies to.
	Description string `json:"description"`
	// Any of "tax_rate".
	Object TaxRateObject `json:"object"`
	// The tax rate percentage.
	Rate float64 `json:"rate"`
	// Comma-separated list of product types this rate applies to, or false if it
	// applies generally.
	Types TaxRateTypesUnion `json:"types"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Class       respjson.Field
		Description respjson.Field
		Object      respjson.Field
		Rate        respjson.Field
		Types       respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (TaxRate) RawJSON

func (r TaxRate) RawJSON() string

Returns the unmodified JSON received from the API

func (*TaxRate) UnmarshalJSON

func (r *TaxRate) UnmarshalJSON(data []byte) error

type TaxRateObject

type TaxRateObject string
const (
	TaxRateObjectTaxRate TaxRateObject = "tax_rate"
)

type TaxRateTypesUnion

type TaxRateTypesUnion struct {
	// This field will be present if the value is a [string] instead of an object.
	OfString string `json:",inline"`
	// This field will be present if the value is a [bool] instead of an object.
	OfBool bool `json:",inline"`
	JSON   struct {
		OfString respjson.Field
		OfBool   respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

TaxRateTypesUnion contains all possible properties and values from [string], [bool].

Use the methods beginning with 'As' to cast the union to one of its variants.

If the underlying value is not a json object, one of the following properties will be valid: OfString OfBool]

func (TaxRateTypesUnion) AsBool

func (u TaxRateTypesUnion) AsBool() (v bool)

func (TaxRateTypesUnion) AsString

func (u TaxRateTypesUnion) AsString() (v string)

func (TaxRateTypesUnion) RawJSON

func (u TaxRateTypesUnion) RawJSON() string

Returns the unmodified JSON received from the API

func (*TaxRateTypesUnion) UnmarshalJSON

func (r *TaxRateTypesUnion) UnmarshalJSON(data []byte) error

type UsageGetResponse

type UsageGetResponse struct {
	Code    int64                `json:"code"`
	Data    UsageGetResponseData `json:"data"`
	Success bool                 `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (UsageGetResponse) RawJSON

func (r UsageGetResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*UsageGetResponse) UnmarshalJSON

func (r *UsageGetResponse) UnmarshalJSON(data []byte) error

type UsageGetResponseData

type UsageGetResponseData struct {
	Requests UsageGetResponseDataRequests `json:"requests"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Requests    respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (UsageGetResponseData) RawJSON

func (r UsageGetResponseData) RawJSON() string

Returns the unmodified JSON received from the API

func (*UsageGetResponseData) UnmarshalJSON

func (r *UsageGetResponseData) UnmarshalJSON(data []byte) error

type UsageGetResponseDataRequests

type UsageGetResponseDataRequests struct {
	// Requests remaining before the limit is reached.
	Remaining int64 `json:"remaining"`
	// Total requests allowed on your plan.
	Total int64 `json:"total"`
	// Requests used in the last 30 days.
	Used int64 `json:"used"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Remaining   respjson.Field
		Total       respjson.Field
		Used        respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (UsageGetResponseDataRequests) RawJSON

Returns the unmodified JSON received from the API

func (*UsageGetResponseDataRequests) UnmarshalJSON

func (r *UsageGetResponseDataRequests) UnmarshalJSON(data []byte) error

type UsageService

type UsageService struct {
	// contains filtered or unexported fields
}

API usage statistics

UsageService contains methods and other services that help with interacting with the vat-sense API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewUsageService method instead.

func NewUsageService

func NewUsageService(opts ...option.RequestOption) (r UsageService)

NewUsageService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*UsageService) Get

func (r *UsageService) Get(ctx context.Context, opts ...option.RequestOption) (res *UsageGetResponse, err error)

Check your used and remaining API requests.

type ValidateCheckParams

type ValidateCheckParams struct {
	// The EORI number to validate. Must include the leading 2-character country code
	// (e.g. "GB123456789123"). UK and EU only.
	EoriNumber param.Opt[string] `query:"eori_number,omitzero" json:"-"`
	// Your own VAT number. If supplied, the response will include a unique
	// consultation number issued by the relevant authority (VIES or HMRC). Must
	// include the leading 2-character country code.
	//
	// Note: GB requester numbers only work for GB validations; EU requester numbers
	// only work for EU validations. Cross-region is not supported.
	RequesterVatNumber param.Opt[string] `query:"requester_vat_number,omitzero" json:"-"`
	// The VAT number to validate. Must include the leading 2-character country code
	// (e.g. "GB288305674", "FR12345678901").
	VatNumber param.Opt[string] `query:"vat_number,omitzero" json:"-"`
	// contains filtered or unexported fields
}

func (ValidateCheckParams) URLQuery

func (r ValidateCheckParams) URLQuery() (v url.Values, err error)

URLQuery serializes ValidateCheckParams's query parameters as `url.Values`.

type ValidateCheckResponse

type ValidateCheckResponse struct {
	Code    int64                     `json:"code"`
	Data    ValidateCheckResponseData `json:"data"`
	Success bool                      `json:"success"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Data        respjson.Field
		Success     respjson.Field
		ExtraFields map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (ValidateCheckResponse) RawJSON

func (r ValidateCheckResponse) RawJSON() string

Returns the unmodified JSON received from the API

func (*ValidateCheckResponse) UnmarshalJSON

func (r *ValidateCheckResponse) UnmarshalJSON(data []byte) error

type ValidateCheckResponseData

type ValidateCheckResponseData struct {
	Company ValidateCheckResponseDataCompanyUnion `json:"company"`
	// Official consultation number (only returned when requester_vat_number is
	// provided).
	ConsultationNumber string `json:"consultation_number" api:"nullable"`
	// Whether the VAT/EORI number is valid.
	Valid bool `json:"valid"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Company            respjson.Field
		ConsultationNumber respjson.Field
		Valid              respjson.Field
		ExtraFields        map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (ValidateCheckResponseData) RawJSON

func (r ValidateCheckResponseData) RawJSON() string

Returns the unmodified JSON received from the API

func (*ValidateCheckResponseData) UnmarshalJSON

func (r *ValidateCheckResponseData) UnmarshalJSON(data []byte) error

type ValidateCheckResponseDataCompanyEoriValidationCompany

type ValidateCheckResponseDataCompanyEoriValidationCompany struct {
	CompanyAddress string `json:"company_address"`
	CompanyName    string `json:"company_name"`
	CountryCode    string `json:"country_code"`
	// The EORI number (without country code prefix).
	EoriNumber string `json:"eori_number"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		CompanyAddress respjson.Field
		CompanyName    respjson.Field
		CountryCode    respjson.Field
		EoriNumber     respjson.Field
		ExtraFields    map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (ValidateCheckResponseDataCompanyEoriValidationCompany) RawJSON

Returns the unmodified JSON received from the API

func (*ValidateCheckResponseDataCompanyEoriValidationCompany) UnmarshalJSON

type ValidateCheckResponseDataCompanyUnion

type ValidateCheckResponseDataCompanyUnion struct {
	CompanyAddress string `json:"company_address"`
	CompanyName    string `json:"company_name"`
	CountryCode    string `json:"country_code"`
	// This field is from variant [ValidateCheckResponseDataCompanyValidationCompany].
	VatNumber string `json:"vat_number"`
	// This field is from variant
	// [ValidateCheckResponseDataCompanyEoriValidationCompany].
	EoriNumber string `json:"eori_number"`
	JSON       struct {
		CompanyAddress respjson.Field
		CompanyName    respjson.Field
		CountryCode    respjson.Field
		VatNumber      respjson.Field
		EoriNumber     respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

ValidateCheckResponseDataCompanyUnion contains all possible properties and values from ValidateCheckResponseDataCompanyValidationCompany, ValidateCheckResponseDataCompanyEoriValidationCompany.

Use the methods beginning with 'As' to cast the union to one of its variants.

func (ValidateCheckResponseDataCompanyUnion) AsValidateCheckResponseDataCompanyEoriValidationCompany

func (u ValidateCheckResponseDataCompanyUnion) AsValidateCheckResponseDataCompanyEoriValidationCompany() (v ValidateCheckResponseDataCompanyEoriValidationCompany)

func (ValidateCheckResponseDataCompanyUnion) AsValidateCheckResponseDataCompanyValidationCompany

func (u ValidateCheckResponseDataCompanyUnion) AsValidateCheckResponseDataCompanyValidationCompany() (v ValidateCheckResponseDataCompanyValidationCompany)

func (ValidateCheckResponseDataCompanyUnion) RawJSON

Returns the unmodified JSON received from the API

func (*ValidateCheckResponseDataCompanyUnion) UnmarshalJSON

func (r *ValidateCheckResponseDataCompanyUnion) UnmarshalJSON(data []byte) error

type ValidateCheckResponseDataCompanyValidationCompany

type ValidateCheckResponseDataCompanyValidationCompany struct {
	CompanyAddress string `json:"company_address"`
	CompanyName    string `json:"company_name"`
	CountryCode    string `json:"country_code"`
	// The VAT number (without country code prefix).
	VatNumber string `json:"vat_number"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		CompanyAddress respjson.Field
		CompanyName    respjson.Field
		CountryCode    respjson.Field
		VatNumber      respjson.Field
		ExtraFields    map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (ValidateCheckResponseDataCompanyValidationCompany) RawJSON

Returns the unmodified JSON received from the API

func (*ValidateCheckResponseDataCompanyValidationCompany) UnmarshalJSON

type ValidateService

type ValidateService struct {
	// contains filtered or unexported fields
}

VAT and EORI number validation

ValidateService contains methods and other services that help with interacting with the vat-sense API.

Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewValidateService method instead.

func NewValidateService

func NewValidateService(opts ...option.RequestOption) (r ValidateService)

NewValidateService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.

func (*ValidateService) Check

Check whether a given VAT number or EORI number is valid against live government records.

**VAT validation** checks against UK (HMRC), EU (VIES), Australia, Norway, Switzerland, South Africa, and Brazil records.

**EORI validation** checks against UK and EU records only.

If the external validation service is temporarily unavailable, the API returns a `412` error and the request does not count against your usage quota.

Provide either `vat_number` or `eori_number`, but not both.

type VatPrice

type VatPrice struct {
	// Any of "vat_price".
	Object VatPriceObject `json:"object"`
	// The price provided.
	Price float64 `json:"price"`
	// The calculated price exclusive of VAT.
	PriceExclVat float64 `json:"price_excl_vat"`
	// The calculated price inclusive of VAT.
	PriceInclVat float64 `json:"price_incl_vat"`
	// Whether the price is inclusive or exclusive of VAT.
	//
	// Any of "incl", "excl".
	TaxType VatPriceTaxType `json:"tax_type"`
	// The total VAT amount.
	Vat float64 `json:"vat"`
	// The VAT rate percentage.
	VatRate float64 `json:"vat_rate"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Object       respjson.Field
		Price        respjson.Field
		PriceExclVat respjson.Field
		PriceInclVat respjson.Field
		TaxType      respjson.Field
		Vat          respjson.Field
		VatRate      respjson.Field
		ExtraFields  map[string]respjson.Field
		// contains filtered or unexported fields
	} `json:"-"`
}

func (VatPrice) RawJSON

func (r VatPrice) RawJSON() string

Returns the unmodified JSON received from the API

func (*VatPrice) UnmarshalJSON

func (r *VatPrice) UnmarshalJSON(data []byte) error

type VatPriceObject

type VatPriceObject string
const (
	VatPriceObjectVatPrice VatPriceObject = "vat_price"
)

type VatPriceTaxType

type VatPriceTaxType string

Whether the price is inclusive or exclusive of VAT.

const (
	VatPriceTaxTypeIncl VatPriceTaxType = "incl"
	VatPriceTaxTypeExcl VatPriceTaxType = "excl"
)

Directories

Path Synopsis
encoding/json
Package json implements encoding and decoding of JSON as defined in RFC 7159.
Package json implements encoding and decoding of JSON as defined in RFC 7159.
encoding/json/shims
This package provides shims over Go 1.2{2,3} APIs which are missing from Go 1.22, and used by the Go 1.24 encoding/json package.
This package provides shims over Go 1.2{2,3} APIs which are missing from Go 1.22, and used by the Go 1.24 encoding/json package.
packages
shared

Jump to

Keyboard shortcuts

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