Ver Mensaje Individual
  #17  
Antiguo 13-03-2024
Avatar de keys
keys keys is offline
Miembro
 
Registrado: sep 2003
Ubicación: Bilbao
Posts: 1.030
Reputación: 22
keys Va por buen camino
Pongo el código por si a alguien le interesa.

Código Delphi [-]

 //Pais son las letras del codigo del pais
function ComprobarDocumentoVIES(Pais, Documento: string): boolean;
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);

  
    Lrequest.ContentType := 'application/json';
    StringStream := TStringStream.Create(JSONData.ToString, TEncoding.UTF8);
    LRequest.SecureProtocols := [THTTPSecureProtocol.TLS12];
    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
        // Obtener el valor del campo deseado de la respuesta que es el valid
         if JSONData.TryGetValue('valid', valido) then
          begin
            result := valido;
          end;
      end;

    JsonData.destroy;
    LResponse.Free;
    LRequest.Free;
    StringStream.Destroy;
 

end;
Responder Con Cita