Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Colaboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #11  
Antiguo 04-10-2024
Delphier Delphier is offline
Miembro
 
Registrado: feb 2024
Posts: 42
Poder: 0
Delphier Va por buen camino
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
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

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


La franja horaria es GMT +2. Ahora son las 11:23:59.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi