VIES VAT number validation

VIES VAT number validation

Postby Maurizio » Fri Aug 10, 2018 3:22 pm

Hello ,
anyone knows a way to use VIES validation ?

I found this in PHP
Code: Select all  Expand view
<?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
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: VIES VAT number validation

Postby quim » Mon Aug 13, 2018 9:05 am

Here you are ... Regards !
Code: Select all  Expand view

/*
 * 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

//-----------------------------------------------------------------------------------------//

 
quim
 
Posts: 42
Joined: Mon Apr 11, 2011 6:22 pm

Re: VIES VAT number validation

Postby Maurizio » Mon Aug 13, 2018 12:31 pm

Thanks quim

just what I was looking for


Maurizio
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: VIES VAT number validation

Postby David Williams » Mon Aug 13, 2018 3:01 pm

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
User avatar
David Williams
 
Posts: 82
Joined: Fri Mar 03, 2006 6:26 pm
Location: Ireland


Re: VIES VAT number validation

Postby Maurizio » Tue Aug 14, 2018 6:51 am

This works without hbcurl
Code: Select all  Expand view
#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
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: VIES VAT number validation

Postby Marc Vanzegbroeck » Tue Aug 14, 2018 7:39 am

Thank you Maurizio, it's working very nice.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: VIES VAT number validation

Postby David Williams » Tue Aug 14, 2018 9:09 am

Thank you so much Maurizio. It opens up a lot of possibilities for me.

David
User avatar
David Williams
 
Posts: 82
Joined: Fri Mar 03, 2006 6:26 pm
Location: Ireland

Re: VIES VAT number validation

Postby kajot » Tue Aug 14, 2018 3:40 pm

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<<<
best regards
kajot
User avatar
kajot
 
Posts: 339
Joined: Thu Nov 02, 2006 6:53 pm
Location: Poland


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 92 guests