Hola a todos. Pongo una función para validar un documento en el servicio VIES de la UE.
Código Delphi
[-]
function ComprobarDocumentoVIES(Pais, Documento: string): false;
var
LRequest: THTTPClient;
LResponse: TStringStream;
JSONData: TJSONObject;
StringStream: TStringStream;
valido : Boolean;
begin
result := false;
LRequest := THTTPClient.Create;
LResponse := TStringStream.Create;
JSONData := TJSONObject.Create;
JSONData.AddPair('countryCode', Pais);
JSONData.AddPair('vatNumber', Documento);
try
Lrequest.ContentType := 'application/json';
StringStream := TStringStream.Create(JSONData.ToString, TEncoding.UTF8);
LRequest.Post('https://ec.europa.eu/taxation_customs/vies/rest-api/check-vat-number', StringStream , LResponse);
JSONData := TJSONObject.ParseJSONValue(LResponse.DataString) as TJSONObject;
if Assigned(JSONData) then
begin
if JSONData.TryGetValue Boolean ('valid', valido) then begin
result := valido;
end;
end;
JsonData.destroy;
LResponse.Free;
LRequest.Free;
StringStream.Destroy;
except
JsonData.destroy;
LResponse.Free;
LRequest.Free;
StringStream.Destroy;
end;
end;