Skip to main content

Django Verify VAT number by ARES/VIES

Project description

Django Verify VAT registration number

The Django Verify VAT registration number module is an extension of the Verify VAT registration number project for the Django framework. It is used for verification VAT registration number in EU and VAT identification number in Czechia. This module is used in the DjangoCMS Verify VAT registration number module.

VIES

VIES VAT number validation for European union. It is an electronic mean of validating VAT-identification numbers of economic operators registered in the European Union for cross border transactions on goods or services. Supported countries see README in project Verify VAT - VIES.

ARES

ARES - Access to Registers of Economic Subjects / Entities is an information system allowing a retrieval of information on economic entities registered in the Czech Republic. This system intermediates a display of data from particular registers of the state administration (called source registers) in which the data concerned is kept.

Installation

This library is available on PyPI, it's recommended to install it using pip:

pip install django-verify-vat-number

Append into Django apps and urls

Insert into site settings.py:

INSTALLED_APPS = [
    ...
    'django_verify_vat_number',
]

Insert into site urls.py:

from django.urls import path, include

urlpatterns = [
    ....
    path('verify-vat/', include('django_verify_vat_number.urls')),
]

Usage

Follow instructions Writing your first Django app to launch the site. Then you can make verification:

curl http://127.0.0.1:8000/verify-vat/verify-vat-id-number/?number=67985726

{"status": "OK", "message": null, "company": {
    "company_name": "CZ.NIC, z.s.p.o.",
    "address": "Mile\u0161ovsk\u00e1 1136/5\n13000 Praha 3",
    "street_and_num": "Mile\u0161ovsk\u00e1 1136/5",
    "city": "Praha 3",
    "postal_code": "13000",
    "district": "Praha 3 - Vinohrady",
    "country_code": "CZ"
}, "country": "Czechia"}

curl http://127.0.0.1:8000/verify-vat/verify-vat-reg-number/?number=CZ67985726

{"status": "OK", "message": null, "company": {
    "company_name": "CZ.NIC, z.s.p.o.",
    "address": "Mile\u0161ovsk\u00e1 1136/5\nPRAHA 3 - VINOHRADY\n130 00  PRAHA 3",
    "street_and_num": "Mile\u0161ovsk\u00e1 1136/5",
    "city": "PRAHA 3",
    "postal_code": "130 00",
    "district": "PRAHA 3 - VINOHRADY",
    "country_code": "CZ"
}, "country": "Czechia"}

Country name in current site language

The country name is translated into the current site language.

Define languages in settings.py:

LANGUAGES = [
    ('en', 'English'),
    ('cs', 'Česky'),
    ('fr', 'Francais'),
]

MIDDLEWARE = [
    ...
    'django.middleware.locale.LocaleMiddleware',
]

Enable language prefix in url.py:

urlpatterns += i18n_patterns(
    path('verify-vat/', include('django_verify_vat_number.urls')),
)

Get translated country name:

curl http://127.0.0.1:8000/cs/verify-vat/verify-vat-id-number/?number=67985726

{"status": "OK", "message": null, "company": {"company_name": ... "country_code": "CZ"},
 "country": "\u010cesko"}

curl http://127.0.0.1:8000/fr/verify-vat/verify-vat-id-number/?number=67985726
{"status": "OK", "message": null, "company": {"company_name": ... "country_code": "CZ"},
 "country": "Tch\u00e9quie"}

Cache

The data downloaded from the server is cached. At the next query, they are no longer downloaded from the verification service. The default cache value is one day. The duration of the data in the cache can be reset in the settings by the constant VERIFY_VAT_KEEP_IN_CACHE.

Logging

Temporary unavailability of the resource is logged in the INFO level. An unexpected error is logged in the ERROR level, including the source response.

Example of a temporarily unavailable service:

2022-06-16 14:49:33,806 INFO     ares:get_xml_content:27 https://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi?ico=67985726
2022-06-16 14:49:33,815 INFO     fetchers:fetch_from_ares:47 Service is temporarily unavailable. Please, try later.

Example of a unexpected service failure:

022-06-16 14:55:10,039 INFO     ares:get_xml_content:27 https://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi?ico=67985726
2022-06-16 14:55:10,042 ERROR    fetchers:fetch_from_ares:49 not well-formed (invalid token): line 1, column 11
2022-06-16 14:55:10,042 ERROR    fetchers:fetch_from_ares:50 <are:Error><dtt:Error_kod> ...

If you want to debug complete communication, you can set it in loggers django_verify_vat_number.fetchers and verify_vat_number.ares, verify_vat_number.vies.

In settings.py:

LOGGING = {
    ...
    'loggers': {
        'verify_vat_number.ares': {'handlers': ['console'], 'level': 'DEBUG'},
        'verify_vat_number.vies': {'handlers': ['console'], 'level': 'DEBUG'},
        'django_verify_vat_number.fetchers': {'handlers': ['console'], 'level': 'DEBUG'},
    }
}
2022-06-16 15:03:04,078 INFO     ares:get_xml_content:27 https://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi?ico=67985726
2022-06-16 15:03:04,078 INFO     ares:get_xml_content:27 https://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi?ico=67985726
2022-06-16 15:03:05,401 DEBUG    ares:get_xml_content:38 <?xml version="1.0" encoding="UTF-8"?><are:Ares_odpovedi
    ...
<are:Odpoved>
<are:Pocet_zaznamu>1</are:Pocet_zaznamu>
    ...
</are:Odpoved>
</are:Ares_odpovedi>
2022-06-16 15:10:39,020 INFO     fetchers:fetch_from_ares:30 Cached data: VerifiedCompanyResponse(status=<StatusCode.OK: 'OK'>, message=None, company=VerifiedCompany(company_name='CZ.NIC, z.s.p.o.', address='Milešovská 1136/5\n13000 Praha 3', street_and_num='Milešovská 1136/5', city='Praha 3', postal_code='13000', district='Praha 3 - Vinohrady', country_code='CZ'), country='Česko')

License

GPLv3+

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_verify_vat_number-3.0.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_verify_vat_number-3.0.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file django_verify_vat_number-3.0.0.tar.gz.

File metadata

  • Download URL: django_verify_vat_number-3.0.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for django_verify_vat_number-3.0.0.tar.gz
Algorithm Hash digest
SHA256 aa82fb9ba2dbe46e58cc4920b259476984f7afa2751037181bf25f21e2ba0841
MD5 38bf8340928b7d08535ae0eb03f2e972
BLAKE2b-256 e9fa24a30fbf241ecc4f1ba6d88828389efc6d94b20343c06f759ba93b364dfa

See more details on using hashes here.

File details

Details for the file django_verify_vat_number-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_verify_vat_number-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cca823815bad22fd17cc3ad70c39dc021515b13cc427395e2f6fb819a381ed76
MD5 11b88dc68b08e1c6efe82c72590e956d
BLAKE2b-256 77eee6d473ba92b33aa951d5999353f43d3f644f0ace6158c425dd939f6a0928

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page