Page 1 of 1
VIES VAT number validation
Posted: Fri Aug 10, 2018 3:22 pm
by Maurizio
Hello ,
anyone knows a way to use VIES validation ?
I found this in PHP
Code: Select all
<?php
$PIVA = '12345678901';
$PAESE = 'IT';
$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
var_dump($client->checkVat(array(
'countryCode' => $PAESE,
'vatNumber' => $PIVA
)));
?>
Thanks
Maurizio
Re: VIES VAT number validation
Posted: Mon Aug 13, 2018 9:05 am
by quim
Here you are ... Regards !
Code: Select all
/*
* Vies test
* v.1.0 23-02-2016
* (c)2016 Joaquim Ferrer <quim_ferrer@yahoo.es>
*/
#include "hbcurl.ch"
#include "common.ch"
//-----------------------------------------------------------------------------------------//
function main()
? checkVies( "ES", "A28017895" )
return NIL
//-----------------------------------------------------------------------------------------//
function checkVies( cCountry, cVatNumber )
local aHeader := {}
local hCurl
local cUrl := "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
local cError, cResponse
local strpost :=;
'<?xml version="1.0" encoding="utf-8"?>'+;
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">'+;
' <soapenv:Body>'+;
' <urn:checkVat>'+;
' <urn:countryCode>'+ cCountry +'</urn:countryCode>'+;
' <urn:vatNumber>'+ cVatNumber +'</urn:vatNumber>'+;
' </urn:checkVat>'+;
' </soapenv:Body>'+;
'</soapenv:Envelope>'
setmode( 25, 80 )
hCurl := curl_easy_init()
if !empty(hCurl)
aadd(aHeader,"Content-Type: text/xml;charset=UTF-8")
aadd(aHeader,"Connection: Keep-Alive" )
aadd(aHeader,"Content-length: "+ Str( len( strpost )) )
curl_easy_setopt(hCurl, HB_CURLOPT_URL, cUrl)
curl_easy_setopt(hCurl, HB_CURLOPT_POST, .T.)
curl_easy_setopt(hCurl, HB_CURLOPT_POSTFIELDS, strpost)
curl_easy_setopt(hCurl, HB_CURLOPT_HTTPHEADER, aHeader)
curl_easy_setopt(hCurl, HB_CURLOPT_FRESH_CONNECT, .T.)
curl_easy_setopt(hCurl, HB_CURLOPT_FORBID_REUSE, .T.)
curl_easy_setopt(hCurl, HB_CURLOPT_VERBOSE, .F. )
curl_easy_setopt(hCurl, HB_CURLOPT_DL_BUFF_SETUP )
cError := curl_easy_perform( hCurl )
if empty(cError)
cResponse := curl_easy_dl_buff_get( hCurl )
else
? "Error:" + curl_easy_strerror(cError)
endif
else
? "No handle"
endif
if !empty(hCurl)
curl_global_cleanup( hCurl )
else
? "Error hCurl"
endif
if empty(cResponse)
? "Error, no response"
else
? cResponse
endif
return NIL
//-----------------------------------------------------------------------------------------//
Re: VIES VAT number validation
Posted: Mon Aug 13, 2018 12:31 pm
by Maurizio
Thanks quim
just what I was looking for
Maurizio
Re: VIES VAT number validation
Posted: Mon Aug 13, 2018 3:01 pm
by David Williams
Hi Maurizio,
Did you get this to work in Harbour or xHarbour? Also where can I get the latest hbcurl.ch and hbcurl.lib for both Harbour and xHarbour?
Grazie,
David
Re: VIES VAT number validation
Posted: Mon Aug 13, 2018 3:25 pm
by Maurizio
Re: VIES VAT number validation
Posted: Tue Aug 14, 2018 6:51 am
by Maurizio
This works without hbcurl
Code: Select all
#include "fivewin.ch"
Static cDoc , cHttp
Function Main()
TRY
cDoc := CreateObject( "MSXML2.DOMDocument" )
CATCH
Alert("Error object MSXML2.DOMDocument : " + Ole2TxtError())
return NIL
END
TRY
cHttp := CreateObject( "MSXML2.XMLHTTP" )
CATCH
Alert("Error object MSXML2.XMLHTTP : " + Ole2TxtError())
END
checkVies( "ES", "A28017895" )
Return nil
//=========================================================================================
Function checkVies(cCountry, cVatNumber )
Local cResponse := " " ,hVar
Local cRequestXML := ""
DEFAULT cCountry := "ES"
DEFAULT cVatNumber := "A28017895"
cRequestXML := [<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ] +;
[xmlns:tns1="urn:ec.europa.eu:taxud:vies:services:checkVat:types" ] +;
[xmlns:impl="urn:ec.europa.eu:taxud:vies:services:checkVat"> ] +;
[<soap:Header> ]+;
[</soap:Header> ]+;
[<soap:Body> ]+;
[<tns1:checkVat xmlns:tns1="urn:ec.europa.eu:taxud:vies:services:checkVat:types" ]+;
[xmlns="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ]+;
[<tns1:countryCode>] + cCountry + [</tns1:countryCode> ] +;
[<tns1:vatNumber>] + cVatNumber + [</tns1:vatNumber> ] +;
[</tns1:checkVat> ]+;
[</soap:Body> ]+;
[</soap:Envelope> ]
//
//cHttp:Open( "POST","http://ec.europa.eu/taxation_customs/vies/services/checkVatService", .t.)
// Wait...
cHttp:Open( "POST","http://ec.europa.eu/taxation_customs/vies/services/checkVatService", .F.)
cHttp:SetRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" )
cHttp:setRequestHeader('User-Agent', 'node-soap')
cHttp:setRequestHeader('Accept' , 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8')
cHttp:setRequestHeader('Accept-Encoding', 'none')
cHttp:setRequestHeader('Accept-Charset', 'utf-8')
//cHttp:setRequestHeader('Connection', 'close')
//cHttp:setRequestHeader('Host', 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService')
cHttp:setRequestHeader('SOAPAction', 'urn:ec.europa.eu:taxud:vies:services:checkVat/checkVat')
//MsgGet( 'Wait',,@cRequestXML)
//cDoc:LoadXML( cRequestXML )
//lXmlHttp.send(lXmlDoc);
cHttp:send(cRequestXML)
//cHttp:send(cDOc:xml )
//If cHttp:status == 200
// ? cResponse
cResponse := cHttp:responseText
? cResponse
//endif
RETURN NIL
Maurizio
www.nipeservice.com
Re: VIES VAT number validation
Posted: Tue Aug 14, 2018 7:39 am
by Marc Vanzegbroeck
Thank you Maurizio, it's working very nice.
Re: VIES VAT number validation
Posted: Tue Aug 14, 2018 9:09 am
by David Williams
Thank you so much Maurizio. It opens up a lot of possibilities for me.
David
Re: VIES VAT number validation
Posted: Tue Aug 14, 2018 3:40 pm
by kajot
when I compile this source, get error / I'am using xHB.com/
Type: C >>>xhb.exe -o"t.c" -m -n -p -q -gc0 -I"S:\include" -I"R:\include" -I"R:\include\w32" "t.prg"<<<
xHarbour 1.2.3 Intl. (SimpLex) (Build 20180529)
Copyright 1999-2018,
http://www.xharbour.org http://www.harbour-project.org/
Generating object output to 't.obj'...
Type: C >>>xhb.exe -o"errorsys.c" -m -n -p -q -gc0 -I"S:\include" -I"R:\include" -I"R:\include\w32" "errorsys.prg"<<<
xHarbour 1.2.3 Intl. (SimpLex) (Build 20180529)
Copyright 1999-2018,
http://www.xharbour.org http://www.harbour-project.org/
Generating object output to 'errorsys.obj'...
Type: C >>>xlink.exe -NOEXPOBJ -MAP -FORCE:MULTIPLE -NOIMPLIB -subsystem:windows -UNMANGLE -LIBPATH:"S:\lib" -LIBPATH:"R:\lib" -LIBPATH:"R:\c_lib" -LIBPATH:"R:\c_lib\win" "t.obj" "errorsys.obj" "s:\lib\mem32.lib" "s:\lib\send32.lib" "s:\lib\png.lib" "r:\c_lib\win\gdi32.lib" "r:\c_lib\win\gdiplus.lib" "xhbzip.lib" "xhbzipdll.lib" "s:\lib\xfw.lib" "s:\lib\hbcurl.lib" "FiveHCM.lib" "FiveHMX.lib" "OptG.lib" "xhb.lib" "dbf.lib" "nsx.lib" "ntx.lib" "cdx.lib" "rmdbfcdx.lib" "ct3comm.lib" crt.lib kernel32.lib user32.lib winspool.lib ole32.lib oleaut32.lib odbc32.lib odbccp32.lib uuid.lib wsock32.lib ws2_32.lib wininet.lib advapi32.lib shlwapi.lib msimg32.lib mpr.lib OleDlg.lib version.lib comctl32.lib comdlg32.lib gdi32.lib shell32.lib winmm.lib lz32.lib Netapi32.lib -out:"t.EXE"<<<
xLINK: fatal error: Corrupt library: 's:\lib\hbcurl.lib'.
Type: C >>>Couldn't build: t.EXE<<<
Type: C >>>TMAKEPROJECT<<<
Type: C >>>TMAKEPROJECT:REFRESH<<<
Type: N >>> 1428<<<