Hello Team,
I have some errors while submitting a sample invoice to get my production CSID.
I’m using php code to manually generate the QR. I mean I don’t use the SDK.
I will attach the errors along with the function that generate the QR.
“errorMessages”:[
{
“type”:“ERROR”,
“code”:“invalid-invoice-hash”,
“category”:“INVOICE_HASHING_ERRORS”,
“message”:“The invoice hash API body does not match the (calculated) Hash of the XML”,
“status”:“ERROR”
},
{
“type”:“ERROR”,
“code”:“CERTIFICATE_SIGNATURE_QRCODE_INVALID”,
“category”:“QRCODE_VALIDATION”,
“message”:“certificate signature does not match with qr certificate signature value”,
“status”:“ERROR”
},
{
“type”:“ERROR”,
“code”:“signed-properties-hashing”,
“category”:“CERTIFICATE_ERRORS”,
“message”:“Invalid signed properties hashing, SignedProperties with id=‘xadesSignedProperties’”,
“status”:“ERROR”
}
],
public function generateQR(DOMDocument $invoice_xml, string $digital_signature, string $public_key, string $signature, string $invoice_timestamp, string $invoice_hash): string
{
$doc = $invoice_xml;
// Get seller data
$seller_name = $doc->getElementsByTagName('RegistrationName')[0]->textContent;
$VAT_number = $doc->getElementsByTagName('CompanyID')[0]->textContent;
// Get amounts
$invoice_total = $doc->getElementsByTagName('TaxInclusiveAmount')[0]->textContent;
$VAT_total = '0.00';
if ($tax_total = $doc->getElementsByTagName('TaxTotal')[0]) {
$VAT_total = $tax_total->getElementsByTagName('TaxAmount')[0]->textContent;
}
// Ensure consistent number formatting
$invoice_total = number_format((float)$invoice_total, 2, '.', '');
$VAT_total = number_format((float)$VAT_total, 2, '.', '');
// Build TLV data in exact order
$qr_data = [
$seller_name, // Tag 1
$VAT_number, // Tag 2
$invoice_timestamp, // Tag 3
$invoice_total, // Tag 4
$VAT_total, // Tag 5
$invoice_hash, // Tag 6
$digital_signature, // Tag 7
$public_key, // Tag 8
$signature // Tag 9
];
// Generate TLV
$qr_tlv = $this->TLV($qr_data);
// Ensure max length
$qr_tlv = substr($qr_tlv, 0, 1000);
return base64_encode($qr_tlv);
}
private function TLV(array $tags): string
{
$tlv = '';
foreach ($tags as $index => $value) {
$tag = $index + 1;
$length = strlen($value);
$tlv .= pack('C', $tag) . pack('C', $length) . $value;
}
return $tlv;
}