Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update VIES format for changed XML response #60

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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