Advertisement
mnakos

Javascript - How to check VAT number from against VIES

Jul 6th, 2020
1,471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* JQUERY ***************/
  2. var settings = {
  3.   "url": "https://ec.europa.eu/taxation_customs/vies/services/checkVatService",
  4.   "method": "POST",
  5.   "timeout": 0,
  6.   "headers": {
  7.     "Content-Type": "text/plain",
  8.     "Cookie": "JSESSIONID=Ftckke83MgxmHiawNT4IFdE91wT5wtvAYuNt9tFl7_lZzWlUlYoO!1091839786"
  9.   },
  10.   "data": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n  xmlns:tns1=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\"\r\n  xmlns:impl=\"urn:ec.europa.eu:taxud:vies:services:checkVat\">\r\n  <soap:Header>\r\n  </soap:Header>\r\n  <soap:Body>\r\n    <tns1:checkVat xmlns:tns1=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\"\r\n     xmlns=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\">\r\n     <tns1:countryCode>EL</tns1:countryCode>\r\n     <tns1:vatNumber>000000000</tns1:vatNumber>\r\n    </tns1:checkVat>\r\n  </soap:Body>\r\n</soap:Envelope>\r\n",
  11. };
  12.  
  13. $.ajax(settings).done(function (response) {
  14.   console.log(response);
  15. });
  16.  
  17.  
  18. /********* XHR ***************/
  19. var data = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"
  20. \n  xmlns:tns1=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\"
  21. \n  xmlns:impl=\"urn:ec.europa.eu:taxud:vies:services:checkVat\">
  22. \n  <soap:Header>
  23. \n  </soap:Header>
  24. \n  <soap:Body>
  25. \n    <tns1:checkVat xmlns:tns1=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\"
  26. \n     xmlns=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\">
  27. \n     <tns1:countryCode>EL</tns1:countryCode>
  28. \n     <tns1:vatNumber>000000000</tns1:vatNumber>
  29. \n    </tns1:checkVat>
  30. \n  </soap:Body>
  31. \n</soap:Envelope>
  32. \n";
  33.  
  34. var xhr = new XMLHttpRequest();
  35. xhr.withCredentials = true;
  36.  
  37. xhr.addEventListener("readystatechange", function() {
  38.   if(this.readyState === 4) {
  39.     console.log(this.responseText);
  40.   }
  41. });
  42.  
  43. xhr.open("POST", "https://ec.europa.eu/taxation_customs/vies/services/checkVatService");
  44. xhr.setRequestHeader("Content-Type", "text/plain");
  45. xhr.setRequestHeader("Cookie", "JSESSIONID=Ftckke83MgxmHiawNT4IFdE91wT5wtvAYuNt9tFl7_lZzWlUlYoO!1091839786");
  46.  
  47. xhr.send(data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement