Skip to content

Commit

Permalink
Merge pull request #60 from prolific-oss/master
Browse files Browse the repository at this point in the history
Update VIES format for changed XML response
  • Loading branch information
Rathcke authored Aug 19, 2022
2 parents 419abd6 + b6eefa9 commit 9375f3c
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions pyvat/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,34 @@ def check_vat_number(self, vat_number, country_code):
# We basically expect the result structure to be as follows,
# where the address and name nodes might be omitted.
#
# <soap:Envelope>
# <soap:Body>
# <checkVatResponse>
# <countryCode>..</countryCode>
# <vatNumber>..</vatNumber>
# <requestDate>..</requestDate>
# <valid>..</valid>
# <name>..</name>
# <address>..</address>
# </checkVatResponse>
# </soap:Body>
# </soap:Envelope>
# <env:Envelope
# xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
# <env:Header/>
# <env:Body>
# <ns2:checkVatResponse
# xmlns:ns2="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
# <ns2:countryCode>DE</ns2:countryCode>
# <ns2:vatNumber>812383453</ns2:vatNumber>
# <ns2:requestDate>2022-08-12+02:00</ns2:requestDate>
# <ns2:valid>true</ns2:valid>
# <ns2:name>---</ns2:name>
# <ns2:address>---</ns2:address>
# </ns2:checkVatResponse>
# </env:Body>
# </env:Envelope>
result_dom = xml.dom.minidom.parseString(response.text.encode('utf-8'))

envelope_node = result_dom.documentElement
if envelope_node.tagName != 'soap:Envelope':
if envelope_node.tagName != 'env:Envelope':
raise ValueError(
'expected response XML root element to be a SOAP envelope'
)

body_node = get_first_child_element(envelope_node, 'soap:Body')
body_node = get_first_child_element(envelope_node, 'env:Body')

# Check for server errors
try:
error_node = get_first_child_element(body_node, 'soap:Fault')
error_node = get_first_child_element(body_node, 'env:Fault')
fault_strings = error_node.getElementsByTagName('faultstring')
fault_code = fault_strings[0].firstChild.nodeValue
raise ServerError(fault_code)
Expand All @@ -137,11 +140,11 @@ def check_vat_number(self, vat_number, country_code):
try:
check_vat_response_node = get_first_child_element(
body_node,
'checkVatResponse'
'ns2:checkVatResponse'
)
valid_node = get_first_child_element(
check_vat_response_node,
'valid'
'ns2:valid'
)
except Exception as e:
result.log_lines.append(u'< Response is nondeterministic due to '
Expand All @@ -162,7 +165,7 @@ def check_vat_number(self, vat_number, country_code):
try:
name_node = get_first_child_element(
check_vat_response_node,
'name'
'ns2:name'
)
result.business_name = get_text(name_node).strip() or None
except Exception:
Expand All @@ -171,7 +174,7 @@ def check_vat_number(self, vat_number, country_code):
try:
address_node = get_first_child_element(
check_vat_response_node,
'address'
'ns2:address'
)
result.business_address = get_text(address_node).strip() or None
except Exception:
Expand Down

0 comments on commit 9375f3c

Please sign in to comment.