Skip to content

Commit 9375f3c

Browse files
authored
Merge pull request #60 from prolific-oss/master
Update VIES format for changed XML response
2 parents 419abd6 + b6eefa9 commit 9375f3c

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

pyvat/registries.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,34 @@ def check_vat_number(self, vat_number, country_code):
103103
# We basically expect the result structure to be as follows,
104104
# where the address and name nodes might be omitted.
105105
#
106-
# <soap:Envelope>
107-
# <soap:Body>
108-
# <checkVatResponse>
109-
# <countryCode>..</countryCode>
110-
# <vatNumber>..</vatNumber>
111-
# <requestDate>..</requestDate>
112-
# <valid>..</valid>
113-
# <name>..</name>
114-
# <address>..</address>
115-
# </checkVatResponse>
116-
# </soap:Body>
117-
# </soap:Envelope>
106+
# <env:Envelope
107+
# xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
108+
# <env:Header/>
109+
# <env:Body>
110+
# <ns2:checkVatResponse
111+
# xmlns:ns2="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
112+
# <ns2:countryCode>DE</ns2:countryCode>
113+
# <ns2:vatNumber>812383453</ns2:vatNumber>
114+
# <ns2:requestDate>2022-08-12+02:00</ns2:requestDate>
115+
# <ns2:valid>true</ns2:valid>
116+
# <ns2:name>---</ns2:name>
117+
# <ns2:address>---</ns2:address>
118+
# </ns2:checkVatResponse>
119+
# </env:Body>
120+
# </env:Envelope>
118121
result_dom = xml.dom.minidom.parseString(response.text.encode('utf-8'))
119122

120123
envelope_node = result_dom.documentElement
121-
if envelope_node.tagName != 'soap:Envelope':
124+
if envelope_node.tagName != 'env:Envelope':
122125
raise ValueError(
123126
'expected response XML root element to be a SOAP envelope'
124127
)
125128

126-
body_node = get_first_child_element(envelope_node, 'soap:Body')
129+
body_node = get_first_child_element(envelope_node, 'env:Body')
127130

128131
# Check for server errors
129132
try:
130-
error_node = get_first_child_element(body_node, 'soap:Fault')
133+
error_node = get_first_child_element(body_node, 'env:Fault')
131134
fault_strings = error_node.getElementsByTagName('faultstring')
132135
fault_code = fault_strings[0].firstChild.nodeValue
133136
raise ServerError(fault_code)
@@ -137,11 +140,11 @@ def check_vat_number(self, vat_number, country_code):
137140
try:
138141
check_vat_response_node = get_first_child_element(
139142
body_node,
140-
'checkVatResponse'
143+
'ns2:checkVatResponse'
141144
)
142145
valid_node = get_first_child_element(
143146
check_vat_response_node,
144-
'valid'
147+
'ns2:valid'
145148
)
146149
except Exception as e:
147150
result.log_lines.append(u'< Response is nondeterministic due to '
@@ -162,7 +165,7 @@ def check_vat_number(self, vat_number, country_code):
162165
try:
163166
name_node = get_first_child_element(
164167
check_vat_response_node,
165-
'name'
168+
'ns2:name'
166169
)
167170
result.business_name = get_text(name_node).strip() or None
168171
except Exception:
@@ -171,7 +174,7 @@ def check_vat_number(self, vat_number, country_code):
171174
try:
172175
address_node = get_first_child_element(
173176
check_vat_response_node,
174-
'address'
177+
'ns2:address'
175178
)
176179
result.business_address = get_text(address_node).strip() or None
177180
except Exception:

0 commit comments

Comments
 (0)