![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Buscar | Temas de Hoy | Marcar Foros Como Leídos |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
|
|
#1
|
||||
|
||||
|
Cita:
Cita:
|
|
#2
|
|||
|
|||
|
Componente derivado de HTTRIO para facilitar los envíos a verifactu.
Os lo pongo , Por si le sirve a alguien como Idea o como ayuda.
El componente Requiere Delphi 12 , me baso en enviar XML preparados previamente almacenados con un certificado también almacenado en el software. Bàsicamente le cargamos el certificado , el password un XML y lo enviamos. Código:
unit VerifactuHTTPRIO;
interface
uses
System.SysUtils,
System.Classes,
Soap.Rio,
Dialogs,
Xml.XMLDoc,
Xml.XMLIntf,
Soap.SOAPHTTPClient,
Soap.SOAPHTTPTrans;
type
TBeforeExecuteEvent = procedure(const MethodName: string; SOAPRequest: TStream) of object;
TAfterExecuteEvent = procedure(const MethodName: string; SOAPResponse: TStream) of object;
TVerifactuHTTPRIO = class(THTTPRIO)
private
{ Private declarations }
FCertificate : TMemoryStream;
FCertPassword : String;
FXMLRequest : TStringList;
FXMLResponse : TStringList;
FOnAfterExecute : TAfterExecuteEvent;
FOnBeforeExecute: TBeforeExecuteEvent;
function StreamToString(aStream: TStream): string;
protected
{ Protected declarations }
procedure DoAfterExecute(const MethodName: string; Response: TStream); override;
procedure DoBeforeExecute(const MethodName: string; Request: TStream); override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property OnAfterExecute: TAfterExecuteEvent read FOnAfterExecute write FOnAfterExecute;
property OnBeforeExecute: TBeforeExecuteEvent read FOnBeforeExecute write FOnBeforeExecute;
property Certificate : TMemoryStream read FCertificate write FCertificate;
property CertPassword : String read FCertPassword write FCertPassword;
property XMLRequest : TStringList read FXMLRequest write FXMLRequest;
property XMLResponse : TStringList read FXMLResponse write FXMLResponse;
end;
procedure Register;
implementation
constructor TVerifactuHTTPRIO.Create(AOwner: TComponent);
Begin
Inherited Create(Aowner);
FCertificate := TMemoryStream.Create;
FXMLRequest := TStringList.Create;
FXMLResponse := TStringList.Create;
End;
destructor TVerifactuHTTPRIO.Destroy;
begin
FCertificate.Free;
FXMLRequest.Free;
FXMLResponse.Free;
inherited;
end;
procedure TVerifactuHTTPRIO.DoBeforeExecute(const MethodName: string; Request: TStream);
begin
// Si hay XMLRequest la enviamos
if FXMLRequest.Count > 0 then
Begin
Request.Position := 0; // Importante
FXMLRequest.SaveToStream(Request);
End;
// Cetificado
HTTPWebNode.ClientCertificate.Stream := Certificate;
HTTPWebNode.ClientCertificate.Password := CertPassword;
if Assigned(FOnBeforeExecute) then
begin
FOnBeforeExecute(MethodName, Request);
Request.Position := 0;
end;
end;
procedure TVerifactuHTTPRIO.DoAfterExecute(const MethodName: string; Response: TStream);
var RespuestaXML : String;
begin
// Asignamos la respuesta y Maquillamos XML
RespuestaXML := StreamToString(Response);
RespuestaXML := Xml.XMLDoc.FormatXMLData(RespuestaXML);
FXMLResponse.Text := RespuestaXML;
if Assigned(FOnAfterExecute) then
begin
FOnAfterExecute(MethodName, Response);
Response.Position := 0;
end;
end;
function TVerifactuHTTPRIO.StreamToString(aStream: TStream): string;
var
SS: TStringStream;
begin
if aStream <> nil then
begin
SS := TStringStream.Create('');
try
SS.CopyFrom(aStream, 0);
Result := SS.DataString;
finally
SS.Free;
end;
end else
begin
Result := '';
end;
end;
procedure Register;
begin
RegisterComponents('Componentes Verifactu', [TVerifactuHTTPRIO]);
end;
end.
Como Usar: Código:
procedure TFormSoap.Button2Click(Sender: TObject);
var direccion_envio : String;
begin
direccion_envio := 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP';
// Cargar el certificado
VerifactuRIO.Certificate.LoadFromFile('MiCertificado.pfx');
VerifactuRIO.CertPassword := '1234';
// Cargar el XMl enviar , de fichero o de texto
VerifactuRIO.XMLRequest.LoadFromFile('XML_Envio_Verifactu.xml');
// Llamada
GetsfPortTypeVerifactu(False, direccion_envio, VerifactuRIO).RegFactuSistemaFacturacion(nil);
// Aquí tenemnos la respues
VerifactuRIO.XMLResponse.Text;
end;
Un Saludo |
|
#3
|
||||
|
||||
|
Cita:
Gracias por compartirlo. Lo subo al FTP y actualizo el mensaje#2 con códigos y demás....
__________________
Germán Estévez => Web/Blog Guía de estilo, Guía alternativa Utiliza TAG's en tus mensajes. Contactar con el Clubdelphi ![]() P.D: Más tiempo dedicado a la pregunta=Mejores respuestas. |
|
#4
|
|||
|
|||
|
Buenas a todos,
Tengo una duda muy básica... Voy a intentar la semana que viene hacer mi primera subida a pruebas y no tengo claro si en el xml la parte inicial que hace referencia al sopaenv es indiferente de si el fichero va al servidor de pruebas o al real. Esta parte concretamente: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sum="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd" xmlns:sum1="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd"> <soapenv:Header/> <soapenv:Body> Tengo que sustituir ahí los www2.agenciatributaria.gob.es por prewww2.aeat.es dentro del xml según vaya a un lado u otro o el xml siempre es igual Gracias |
|
#5
|
|||
|
|||
|
Cita:
Y la verdad es un alivio que siga así. La contrapartida vendrá más tarde: dado que no hay control de versión en las URL actuales, cuando Hacienda querrá hacer una nueva versión, deberán crear nuevas URL (posiblemente con un indicador de versión) y habilitarlas primero en entorno de test y más tarde en producción. Pero no estamos todavía allá. ![]() Última edición por antoine0 fecha: 04-10-2024 a las 18:43:32. Razón: Inserción de CR para lectura |
|
#6
|
|||
|
|||
|
Cita:
Aclarado lo del fichero. Y en el comando que use para subir el xml ahí sí tengo que poner, hoy por hoy, las https://prewww...no? Gracias antoine0, |
|
#7
|
||||
|
||||
|
Buenos días¡¡
Primero agradeceros a todos el gran esfuerzo. a alguien más le esta pasando esto ? Código:
Error al realizar el envío; (ESOAPHTTPException)-Service Unavailable (503) - 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP' ![]() ![]()
__________________
Inieeeesssstademiviiiiidaaaaa. |
![]() |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| Hijo de Informáticos | gluglu | Humor | 3 | 13-03-2007 11:05:35 |
| Adictos informaticos ... | Trigger | Humor | 2 | 11-10-2004 12:18:32 |
| Nosotros los Informáticos | Trigger | Humor | 1 | 10-10-2004 14:58:09 |
| Patrón de los Informáticos. | obiwuan | Varios | 20 | 10-09-2003 14:44:54 |
| Chistes Informaticos | jhonny | Humor | 2 | 11-08-2003 21:59:09 |
|