ExVatcheck.VIESClient.XMLParser (ExVatcheck v0.3.1) View Source

A module for parsing XML responses from VIES client requests into Elixir maps.

Link to this section Summary

Functions

The parse_response/1 function parses the XML response returned by requests to the checkVatService.

The parse_service/1 function parses the URL of the checkVatService from the VIES WSDL response.

Link to this section Types

Specs

response() :: %{
  country_code: binary(),
  vat_number: binary(),
  request_date: binary(),
  valid: boolean(),
  name: binary() | nil,
  address: binary() | nil
}

Link to this section Functions

Link to this function

parse_response(response_body)

View Source

Specs

parse_response(binary()) :: {:ok, map()} | {:error, binary()}

The parse_response/1 function parses the XML response returned by requests to the checkVatService.

When the service is available, the response has the following structure:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <ns2:checkVatResponse xmlns="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
      <ns2:countryCode>BE</countryCode>
      <ns2:vatNumber>0829071668</vatNumber>
      <ns2:requestDate>2016-01-16+01:00</requestDate>
      <ns2:valid>true</valid>
      <ns2:name>SPRL BIGUP</name>
      <ns2:address>RUE LONGUE 93 1320 BEAUVECHAIN</address>
    </ns2:checkVatResponse>
  </env:Body>
</env:Envelope>

Sometimes, the VIES service is unavailable (see http://ec.europa.eu/taxation_customs/vies/help.html). In the case that it is not, the response has the following structure:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <env:Fault>
      ...
    </env:Fault>
  </env:Body>
</env:Envelope>

If ex_vatcheck is not able to parse either of the above XML responses, the function will return an error tuple.

Link to this function

parse_service(wsdl_response)

View Source

Specs

parse_service(binary()) :: {:ok, binary()} | {:error, binary()}

The parse_service/1 function parses the URL of the checkVatService from the VIES WSDL response.

The WSDL has the following structure:

<wsdl:definitions ...>
  ...
  <wsdl:service name="checkVatService">
    <wsdl:port name="checkVatPort" binding="impl:checkVatBinding">
      <wsdlsoap:address location="https://ec.europa.eu/taxation_customs/vies/services/checkVatService"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>