Day 7: Wrap Signature in UBLExtensions for IRBM Compliance #ublsignature #dsintegration

SEO Title: Day 7: Wrap Signature in UBLExtensions for IRBM Compliance #ublsignature #dsintegration
Focus Keyphrase: IRB e-invoice integration
Meta Description: Wrap your ds:Signature block inside ext:UBLExtensions as required by IRBM for e-invoice integration using Laravel and UBL XML.

Adding UBLExtensions Around Signature Block

IRBM requires the digital signature to be inside <ext:UBLExtensions>. This is a required structure in UBL 2.1 and must come as the first child of the root Invoice element.

Step 1: Modify the XML Generator to Add Placeholder

In IRBInvoiceXmlGenerator, before any other child nodes are added to <Invoice>:


$ext = 'urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2';
$invoice->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ext', $ext);

$UBLExtensions = $doc->createElementNS($ext, 'ext:UBLExtensions');
$UBLExt = $doc->createElementNS($ext, 'ext:UBLExtension');
$extContent = $doc->createElementNS($ext, 'ext:ExtensionContent');

$UBLPlaceholder = $doc->createElement('SignaturePlaceholder'); // this will be replaced after signing

$extContent->appendChild($UBLPlaceholder);
$UBLExt->appendChild($extContent);
$UBLExtensions->appendChild($UBLExt);
$invoice->appendChild($UBLExtensions);

Step 2: Modify Signature Service to Replace Placeholder

In IRBXmlSignatureService, replace the placeholder node after signing:


$doc = new \DOMDocument();
$doc->loadXML($unsignedXml);

$placeholder = $doc->getElementsByTagName('SignaturePlaceholder')->item(0);

$objDSig = new XMLSecurityDSig();
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
$objDSig->addReference(
    $doc,
    XMLSecurityDSig::SHA256,
    ['http://www.w3.org/2000/09/xmldsig#enveloped-signature'],
    ['uri' => '']
);

$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, ['type'=>'private']);
$objKey->loadKey($this->pkeyPem, false, true, $this->pkeyPassphrase);

$objDSig->sign($objKey);
$objDSig->add509Cert($this->certPem, true, false);

$sigNode = $objDSig->insertSignature();
$importedSig = $doc->importNode($sigNode, true);

$placeholder->parentNode->replaceChild($importedSig, $placeholder);

return $doc->saveXML();

Step 3: Validate UBL Signature Structure

Open your browser to /irb/xml-preview and check that your UBL XML starts like this:


<Invoice ...>
  <ext:UBLExtensions>
    <ext:UBLExtension>
      <ext:ExtensionContent>
        <ds:Signature>...</ds:Signature>
      </ext:ExtensionContent>
    </ext:UBLExtension>
  </ext:UBLExtensions>

Why This Is Important

If your signature is not inside ext:UBLExtensions, IRBM’s system will reject the invoice. The placement and structure are mandatory as part of UBL 2.1 compliance.

Coming Up in Day 8

We’ll create a proper HTTP request and submit the signed invoice XML to the IRBM API using Laravel’s HTTP client with headers, base64 encoding, and authorization token.

See also  Day 1: XML Signature Missing or Not Wrapped in UBLExtensions #irberror #ublsignature

Tags: #UBL #XMLSignature #IRBIntegration #MyInvois #LaravelUBL

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.