lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 2.2-5-g7662137

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 2.2-5-g7662137



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  7662137d48daddf3e6f0e79a69d24197c9761d1c (commit)
      from  2413a52f2f62d38be6ae57871d2e370015b085c7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=7662137d48daddf3e6f0e79a69d24197c9761d1c

commit 7662137d48daddf3e6f0e79a69d24197c9761d1c
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jul 19 19:57:21 2026 +0200

    Use the REST service for EU VAT VIES validation
    
    This uses the REST service for EU VAT Vies validation by default instead
    of the SOAP service. The SOAP service can still be use by passing
    `use_soap`.
    
    Closes https://github.com/arthurdejong/python-stdnum/issues/496

diff --git a/stdnum/eu/vat.py b/stdnum/eu/vat.py
index e0feff3..c272f3c 100644
--- a/stdnum/eu/vat.py
+++ b/stdnum/eu/vat.py
@@ -130,6 +130,8 @@ def check_vies(
     number: str,
     timeout: float = 30,
     verify: bool | str = True,
+    *,
+    use_soap: bool = False,
 ) -> dict[str, str | bool | datetime.date]:  # pragma: no cover (not part of 
normal test suite)
     """Use the EU VIES service to validate the provided number.
 
@@ -148,8 +150,17 @@ def check_vies(
     # this function isn't automatically tested because it would require
     # network access for the tests and unnecessarily load the VIES website
     number = compact(number)
-    client = get_soap_client(vies_wsdl, timeout=timeout, verify=verify)
-    return client.checkVat(number[:2], number[2:])  # type: 
ignore[no-any-return]
+    if use_soap:
+        client = get_soap_client(vies_wsdl, timeout=timeout, verify=verify)
+        return client.checkVat(number[:2], number[2:])  # type: 
ignore[no-any-return]
+    else:
+        import requests
+        r = requests.post(
+            
'https://ec.europa.eu/taxation_customs/vies/rest-api/check-vat-number',
+            json={'countryCode': number[:2], 'vatNumber': number[2:]},
+        )
+        r.raise_for_status()
+        return r.json()  # type: ignore[no-any-return]
 
 
 def check_vies_approx(
@@ -157,6 +168,8 @@ def check_vies_approx(
     requester: str,
     timeout: float = 30,
     verify: bool | str = True,
+    *,
+    use_soap: bool = False,
 ) -> dict[str, str | bool | datetime.date]:  # pragma: no cover
     """Use the EU VIES service to validate the provided number.
 
@@ -178,7 +191,21 @@ def check_vies_approx(
     # network access for the tests and unnecessarily load the VIES website
     number = compact(number)
     requester = compact(requester)
-    client = get_soap_client(vies_wsdl, timeout=timeout, verify=verify)
-    return client.checkVatApprox(  # type: ignore[no-any-return]
-        countryCode=number[:2], vatNumber=number[2:],
-        requesterCountryCode=requester[:2], requesterVatNumber=requester[2:])
+    if use_soap:
+        client = get_soap_client(vies_wsdl, timeout=timeout, verify=verify)
+        return client.checkVatApprox(  # type: ignore[no-any-return]
+            countryCode=number[:2], vatNumber=number[2:],
+            requesterCountryCode=requester[:2], 
requesterVatNumber=requester[2:])
+    else:
+        import requests
+        r = requests.post(
+            
'https://ec.europa.eu/taxation_customs/vies/rest-api/check-vat-number',
+            json={
+                'countryCode': number[:2],
+                'vatNumber': number[2:],
+                'requesterCountryCode': requester[:2],
+                'requesterVatNumber': requester[2:],
+            },
+        )
+        r.raise_for_status()
+        return r.json()  # type: ignore[no-any-return]

-----------------------------------------------------------------------

Summary of changes:
 stdnum/eu/vat.py | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
python-stdnum