PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Xml
oleobject loo_SbXml
oleobject loo_SbSignedSoap
li_Success = 0
li_Success = 1
// 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>
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
destroy loo_Xml
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Xml.Tag = "soapenv:Envelope"
loo_Xml.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/")
loo_Xml.AddAttribute("xmlns:sum","https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd")
loo_Xml.AddAttribute("xmlns:sum1","https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd")
loo_Xml.AddAttribute("xmlns:xd","http://www.w3.org/2000/09/xmldsig#")
loo_Xml.UpdateChildContent("soapenv:Header","")
loo_Xml.UpdateChildContent("soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NombreRazon","XYZ STORE SL")
loo_Xml.UpdateChildContent("soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:ObligadoEmision|sum1:NIF","B99999999")
loo_Xml.UpdateChildContent("soapenv:Body|sum:RegFactuSistemaFacturacion|sum:Cabecera|sum1:RemisionRequerimiento|sum1:RefRequerimiento","3333333333")
loo_Xml.UpdateChildContent("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.
loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")
loo_Xml.GetXmlSb(loo_SbXml)
// ---------------------------------------------------------------------------------------------
// Load the previously signed XML containing just one signed record.
loo_SbSignedSoap = create oleobject
li_rc = loo_SbSignedSoap.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_SbSignedSoap.LoadFile("c:/temp/qa_output/signedSoapXml1.xml","utf-8")
if li_Success = 0 then
Write-Debug loo_SbSignedSoap.LastErrorText
destroy loo_Xml
destroy loo_SbXml
destroy loo_SbSignedSoap
return
end if
// Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>"
loo_SbSignedSoap.RemoveBefore("</sum:Cabecera>")
// Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>"
loo_SbSignedSoap.RemoveAfterFinal("</sum:RegFactuSistemaFacturacion>")
// We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura>
// Insert it after the </sum:Cabecera>
loo_SbSignedSoap.Prepend("</sum:Cabecera>")
loo_SbXml.ReplaceFirst("</sum:Cabecera>",loo_SbSignedSoap.GetAsString())
// ---------------------------------------------------------------------------------------------
// Add the next signed SOAP containing a single signed record.
li_Success = loo_SbSignedSoap.LoadFile("c:/temp/qa_output/signedSoapXml2.xml","utf-8")
if li_Success = 0 then
Write-Debug loo_SbSignedSoap.LastErrorText
destroy loo_Xml
destroy loo_SbXml
destroy loo_SbSignedSoap
return
end if
// Remove everything before "</sum:Cabecera>", including the "</sum:Cabecera>"
loo_SbSignedSoap.RemoveBefore("</sum:Cabecera>")
// Remove everything after the "</sum:RegFactuSistemaFacturacion>", including the "</sum:RegFactuSistemaFacturacion>"
loo_SbSignedSoap.RemoveAfterFinal("</sum:RegFactuSistemaFacturacion>")
// We now have the portion of the signed SOAP xml from <sum:RegistroFactura> to </sum:RegistroFactura>
// Insert it after the </sum:Cabecera>
loo_SbSignedSoap.Prepend("</sum:Cabecera>")
loo_SbXml.ReplaceFirst("</sum:Cabecera>",loo_SbSignedSoap.GetAsString())
// ---------------------------------------------------------------------------------------------
// Continue adding more signed records if needed.
// Save the SOAP containing multiple signed records..
loo_SbXml.WriteFile("c:/temp/qa_output/soap_combined.xml","utf-8",0)
destroy loo_Xml
destroy loo_SbXml
destroy loo_SbSignedSoap