taxjar / ex_vatcheck Goto Github PK
View Code? Open in Web Editor NEWElixir package for verifying VAT identification numbers using the VIES service.
License: MIT License
Elixir package for verifying VAT identification numbers using the VIES service.
License: MIT License
Running ExVatcheck.check
for a VAT with correct format currently causes the process to exit.
iex(1)> ExVatcheck.check("DE123456789")
[error] 3957- fatal: {:error, {:whitespace_was_expected}}
** (exit) {:fatal, {{:error, {:whitespace_was_expected}}, {:file, :file_name_unknown}, {:line, 1}, {:col, 55}}}
(xmerl 1.3.29) xmerl_scan.erl:4127: :xmerl_scan.fatal/2
(xmerl 1.3.29) xmerl_scan.erl:1209: :xmerl_scan.scan_doctype1/2
(xmerl 1.3.29) xmerl_scan.erl:730: :xmerl_scan.scan_prolog/4
(xmerl 1.3.29) xmerl_scan.erl:571: :xmerl_scan.scan_document/2
(xmerl 1.3.29) xmerl_scan.erl:294: :xmerl_scan.string/2
(sweet_xml 0.7.3) lib/sweet_xml.ex:292: SweetXml.do_parse/2
(sweet_xml 0.7.3) lib/sweet_xml.ex:281: SweetXml.parse/2
(ex_vatcheck 0.2.1) lib/ex_vatcheck/xml.ex:7: ExVatcheck.Xml.parse/3
(ex_vatcheck 0.2.1) lib/ex_vatcheck/vies_client/xml_parser.ex:92: ExVatcheck.VIESClient.XMLParser.parse_response/1
(ex_vatcheck 0.2.1) lib/ex_vatcheck.ex:30: ExVatcheck.validate/1
In lib/ex_vatcheck/vies_client.ex:30
a post is made to an external service which is apparently not available at the moment and thus returns a 500 error code together with an html response. The attempt to parse the response with xmerl causes the process to exit (which imo is not expected behaviour either, but an issue in xmerl).
This is the html response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Draft//EN">
<HTML>
<HEAD>
<TITLE>Error 500--Internal Server Error</TITLE>
</HEAD>
<BODY bgcolor="white">
<FONT FACE=Helvetica><BR CLEAR=all>
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 500--Internal Server Error</H2>
</FONT></TD></TR>
</TABLE>
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100% BGCOLOR=white><FONT FACE="Courier New"><FONT FACE="Helvetica" SIZE="3"><H3>From RFC 2068 <i>Hypertext Transfer Protocol -- HTTP/1.1</i>:</H3>
</FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.5.1 500 Internal Server Error</H4>
</FONT><P><FONT FACE="Courier New">The server encountered an unexpected condition which prevented it from fulfilling the request.</FONT></P>
</FONT></TD></TR>
</TABLE>
</BODY>
</HTML>
Currently we have the XML namespace prefixes hard coded into our SweetXpath structs.
@check_vat_response SweetXml.sigil_x("//env:Envelope/env:Body/ns2:checkVatResponse")
This turned out to be very brittle when VIES updated their SOAP envelope unexpectedly and SweetXml
no longer had a correct path to access values in the responses.
SweetXml seems like it should be able to handle xpaths with no namespaces. If someone could get a prefix-independent path to work when SweetXml.xpath
is called, that would be swell :)
@check_vat_response SweetXml.sigil_x("//Envelope/Body/checkVatResponse")
Hi there. ๐
First of all, thanks a lot for this little but very useful library.
One thing I am struggling a bit with is the return type of the ExVatcheck.check/1
function. Since it is a struct with 4 keys, the number of possible states is too big and doesn't represent the reality.
In the spirit of the "Make Illegal States Unrepresentable" I think it would be more convenient if that function returns structs that represent the only possible outcomes:
%ExVatcheck.InvalidFormatError{}
%ExVatcheck.ViesServiceError{message: String.t()}
%ExVatcheck.ViesResponseInvalid{}
%ExVatcheck.ViesResponseValid{response: map()}
Of course, those structs can be tuples or something similar. It's just a rough idea and I will be happy to implement it, if there's a positive feedback to this and once we agree on a way to do this.
What do you think?
I'm getting this error
Because "the lock" specifies httpoison 2.2.1 and every version of ex_vatcheck depends on httpoison ~> 1.3, the lock is incompatible with ex_vatcheck.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.