diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2012-02-20 21:40:08 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2012-02-20 21:40:08 +0100 |
commit | 68f62bf36471a85e57f01429d259d7c96f9b845a (patch) | |
tree | f55de8e4e643fe8acecc12466708ffb3f596ebac /stdnum | |
parent | e640e3bfeb2f6efa162ee83a86cb767c61ba9571 (diff) |
add a stdnum.eu.vat.check_vies() function to do an on-line check of the VAT number
git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@157 9dea7c4f-944c-4273-ac1a-574ede026edc
Diffstat (limited to 'stdnum')
-rw-r--r-- | stdnum/eu/vat.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/stdnum/eu/vat.py b/stdnum/eu/vat.py index a408b8f..e8a3bab 100644 --- a/stdnum/eu/vat.py +++ b/stdnum/eu/vat.py @@ -40,6 +40,12 @@ country_codes = set([ _country_modules = dict() +vies_wsdl = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl' +"""The WSDL URL of the VAT Information Exchange System (VIES) """ + +# a cached version of the suds client for VIES +_vies_client = None + def _get_cc_module(cc): """Get the VAT number module based on the country code.""" @@ -83,3 +89,18 @@ def guess_country(number): return [cc for cc in country_codes if _get_cc_module(cc).is_valid(number)] + + +def check_vies(number): # pragma: no cover (no tests for this function) + """Queries the online European Commission VAT Information Exchange + System (VIES) for validity of the provided number. Note that the + service has usage limitations (see the VIES website for details). + This returns a dict-like object.""" + # this function isn't automatically tested because it would require + # network access for the tests and unnecessarily load the VIES website + global _vies_client + if not _vies_client: + from suds.client import Client + _vies_client = Client(vies_wsdl) + number = compact(number) + return _vies_client.service.checkVat(number[:2], number[2:]) |