Vat
VAT number validation and VAT rates for the EU
Install / Use
/learn @Keats/VatREADME
VAT
Introduction
This a module to validate the format and the existence of a VAT number. It queries the VIES api which is terribly unstable and will often have one of the country not available.
It also contains the current VAT rates of the EU countries. It doesn't contain any historical data or the reduced rates.
TODO: see what the api returns when country db is down
Installation
Add the following to Cargo.toml:
vat = "0.1"
Usage
VAT number validation
use vat::{validate_format, validate_vat_number, VatError};
// vat_number should contian the country code
// it can contain spaces or dashes, those will be stripped by `vat`
fn is_vat_number_valid(vat_number: &str) -> bool {
// checks if the format is ok first
if !validate_format(vat_number) {
return false;
}
// format is valid, check that this is an existing VAT number
match validate_vat_number(vat_number) {
Ok(_) => true,
Err(e) => match e {
// could be the api is down, allow it since the format is ok
// in practice you would probably refuse it
VatError::HttpError(_) => true,
_ => false,
}
}
}
Look at src/errors.rs for the kind of error that could happen.
In the case above we are only doing verification but the validate_vat_number function will return
the information for that company as the following struct:
pub struct Company {
pub country_code: String,
pub vat_number: String,
pub name: String,
pub address: String,
}
Get VAT rates
use vat::{get_rate, get_all_rates};
// casing is not important
let fr_rate = get_rate("fr").unwrap();
let all_rates = get_all_rates();
Related Skills
node-connect
347.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
