ExVatcheck.VIESClient.XMLParser (ExVatcheck v0.2.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:

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

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      ...
    </soap:Fault>
  </soap:Body>
</soap:Envelope>
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>