DataFlex
DataFlex
Create SOAP with multiple VeriFactu Digitally Signed Registration Records
See more Verifactu Examples
Creates a SOAP message containing a multiple digitally signed invoice registration records, formatted according to the specifications for Spain's Veri*Factu system.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoXml
Variant vSbXml
Handle hoSbXml
Handle hoSbSignedSoap
String sTemp1
Move False To iSuccess
Move True To iSuccess
// Begin with the following SOAP XML:
// <?xml version="1.0" encoding="utf-8"?>
// <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" xmlns:xd="http://www.w3.org/2000/09/xmldsig#">
// <soapenv:Header/>
// <soapenv:Body>
// <sum:RegFactuSistemaFacturacion>
// <sum:Cabecera>
// <sum1:ObligadoEmision>
// <sum1:NombreRazon>XYZ STORE SL</sum1:NombreRazon>
// <sum1:NIF>B99999999</sum1:NIF>
// </sum1:ObligadoEmision>
// <sum1:RemisionRequerimiento>
// <sum1:RefRequerimiento>3333333333</sum1:RefRequerimiento>
// <sum1:FinRequerimiento>S</sum1:FinRequerimiento>
// </sum1:RemisionRequerimiento>
// </sum:Cabecera>
//
// </sum:RegFactuSistemaFacturacion>
// </soapenv:Body>
// </soapenv:Envelope>
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Set ComTag Of hoXml To "soapenv:Envelope"
Get ComAddAttribute Of hoXml "xmlns:soapenv" "http://schemas.xmlsoap.org/soap/envelope/" To iSuccess
Get ComAddAttribute Of hoXml "xmlns:sum" "https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd" To iSuccess
Get ComAddAttribute Of hoXml "xmlns:sum1" "https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd" To iSuccess
Get ComAddAttribute Of hoXml "xmlns:xd" "http://www.w3.org/2000/09/xmldsig#" To iSuccess
Send ComUpdateChildContent To hoXml "soapenv:Header" ""
Send ComUpdateChildContent To hoXml "soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NombreRazon" "XYZ STORE SL"
Send ComUpdateChildContent To hoXml "soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NIF" "B99999999"
Send ComUpdateChildContent To hoXml "soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:RemisionRequerimiento|sum1:RefRequerimiento" "3333333333"
Send ComUpdateChildContent To hoXml "soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:RemisionRequerimiento|sum1:FinRequerimiento" "S"
// Prior to this code, we created N signed SOAP messages, each containing a single signed record.
// Load each of these signed SOAP messages into a StringBuilder and insert after the "</sum:Cabecera>"
// Note: We must NOT use Chilkat.Xml for this. We must do string operations using Chilkat StringBuilder to prevent whitespace or formatting modifications which would break the signatures.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml
If (Not(IsComObjectCreated(hoSbXml))) Begin
Send CreateComObject of hoSbXml
End
Get pvComObject of hoSbXml to vSbXml
Get ComGetXmlSb Of hoXml vSbXml To iSuccess
// ---------------------------------------------------------------------------------------------
// Load the previously signed XML containing just one signed record.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbSignedSoap
If (Not(IsComObjectCreated(hoSbSignedSoap))) Begin
Send CreateComObject of hoSbSignedSoap
End
Get ComLoadFile Of hoSbSignedSoap "c:/temp/qa_output/signedSoapXml1.xml" "utf-8" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSbSignedSoap To sTemp1
Showln sTemp1
Procedure_Return
End
// Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>"
Get ComRemoveBefore Of hoSbSignedSoap "</sum:Cabecera>" To iSuccess
// Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>"
Get ComRemoveAfterFinal Of hoSbSignedSoap "</sum:RegFactuSistemaFacturacion>" To iSuccess
// We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura>
// Insert it after the </sum:Cabecera>
Get ComPrepend Of hoSbSignedSoap "</sum:Cabecera>" To iSuccess
Get ComGetAsString Of hoSbSignedSoap To sTemp1
Get ComReplaceFirst Of hoSbXml "</sum:Cabecera>" sTemp1 To iSuccess
// ---------------------------------------------------------------------------------------------
// Add the next signed SOAP containing a single signed record.
Get ComLoadFile Of hoSbSignedSoap "c:/temp/qa_output/signedSoapXml2.xml" "utf-8" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSbSignedSoap To sTemp1
Showln sTemp1
Procedure_Return
End
// Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>"
Get ComRemoveBefore Of hoSbSignedSoap "</sum:Cabecera>" To iSuccess
// Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>"
Get ComRemoveAfterFinal Of hoSbSignedSoap "</sum:RegFactuSistemaFacturacion>" To iSuccess
// We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura>
// Insert it after the </sum:Cabecera>
Get ComPrepend Of hoSbSignedSoap "</sum:Cabecera>" To iSuccess
Get ComGetAsString Of hoSbSignedSoap To sTemp1
Get ComReplaceFirst Of hoSbXml "</sum:Cabecera>" sTemp1 To iSuccess
// ---------------------------------------------------------------------------------------------
// Continue adding more signed records if needed.
// Save the SOAP containing multiple signed records..
Get ComWriteFile Of hoSbXml "c:/temp/qa_output/soap_combined.xml" "utf-8" False To iSuccess
End_Procedure