Invoice hash is incorrect when signing the invoice and need to generate the hash again

Dears ,

I’m facing a weird problem , when signing the invoice i’m getting sucessful message and the invoice hash . but the invoice hash is incorrect and it’s rejected when submitting to ZATCA API (invoice hash not matching the calculated hash) , however , when generating the hash for the same signed invoice , the hash genereated is correct . any explaination ?
below screenshot for the same . the correct hash is 6VUJWVzs/9rWUzGhw4VgEQIhRbec3IqItw1ekTk53sU=

and not ZF9UXdC7GSif4fsIhKeuxSyYD/A2YxPx3BFDZr7clbg=

.....\zatca-einvoicing-sdk-238-R3.3.5\zatca-einvoicing-sdk-238-R3.3.5\Lib\Dot-Net8\Test>fatooraNet sign -invoice Invoice_849_20241015142842.xml -signedInvoice hadi.xml
********************* Welcome to ZATCA E-Invoice .Net SDK 3.3.5 *********************
This App uses .Net to call the SDK passing it an invoice XML file.
It can take a Standard or Simplified XML, Credit Note, or Debit Note.
It returns if the validation is successful or shows errors where the XML validation fails.
It checks for syntax and content as well.
You can use the command (fatooraNet -help) for more information.
You can use the command (fatooraNet {Command} -help) for instructions on how to use the command and expected arguments.

*************************************************************************************


Invoice has been signed successfully
*** Invoice Hash =  ZF9UXdC7GSif4fsIhKeuxSyYD/A2YxPx3BFDZr7clbg=

.....zatca-einvoicing-sdk-238-R3.3.5\zatca-einvoicing-sdk-238-R3.3.5\Lib\Dot-Net8\Test>fatooraNet generateHash -invoice hadi.xml
********************* Welcome to ZATCA E-Invoice .Net SDK 3.3.5 *********************
This App uses .Net to call the SDK passing it an invoice XML file.
It can take a Standard or Simplified XML, Credit Note, or Debit Note.
It returns if the validation is successful or shows errors where the XML validation fails.
It checks for syntax and content as well.
You can use the command (fatooraNet -help) for more information.
You can use the command (fatooraNet {Command} -help) for instructions on how to use the command and expected arguments.

*************************************************************************************


Invoice has been signed successfully
*** Invoice Hash =  6VUJWVzs/9rWUzGhw4VgEQIhRbec3IqItw1ekTk53sU=

Thanks .

Try follow this step

  • Signing Document,
  • Generate apiRequest from Signed Document.
  • Send apirequest to Zatca.

this should accepted

1 Like

Dear @eCloud ,

Thank you for your reply .

I tried doing that , the apiRequest genereted will have the wrong invoice hash : ZF9UXdC7GSif4fsIhKeuxSyYD/A2YxPx3BFDZr7clbg= .
and ZATCA API of course rejeceted it .
(The invoice hash API body does not match the (calculated) Hash of the XML)

Weird enough, this always works on my computer, I’m using windows 11.

Make sure you make an api request from a Signed Document.

D:\zatca>fatooranet sign -invoice b2c.xml -signedInvoice Signed_b2c.xml
********************* Welcome to ZATCA E-Invoice .Net SDK 3.3.5 *********************
This App uses .Net to call the SDK passing it an invoice XML file.
It can take a Standard or Simplified XML, Credit Note, or Debit Note.
It returns if the validation is successful or shows errors where the XML validation fails.
It checks for syntax and content as well.
You can use the command (fatooraNet -help) for more information.
You can use the command (fatooraNet {Command} -help) for instructions on how to use the command and expected arguments.

*************************************************************************************


Invoice has been signed successfully
*** Invoice Hash =  3Tvv3uaqHHnf/gZurU8mDj6pH9dXwgQ8YxyYNulzR8U=

D:\zatca>fatooranet invoiceRequest -invoice signed_b2c.xml -apiRequest Signed_b2c_request.json
********************* Welcome to ZATCA E-Invoice .Net SDK 3.3.5 *********************
This App uses .Net to call the SDK passing it an invoice XML file.
It can take a Standard or Simplified XML, Credit Note, or Debit Note.
It returns if the validation is successful or shows errors where the XML validation fails.
It checks for syntax and content as well.
You can use the command (fatooraNet -help) for more information.
You can use the command (fatooraNet {Command} -help) for instructions on how to use the command and expected arguments.

*************************************************************************************


Operation Completed Successfully!
Step: [Generate Request] [Success]

D:\zatca>

@eCloud ,

Yes , i know . i’m facing a weird problem . it should be okay . but somehow it’s not working on my side until i generate the invoice hash again and then it gives the right invoice hash and i can clear my invoices .

and yes i’m sending the signed document only .

@Hadi,
Can you share your source file Invoice_849_20241015142842.xml?
I just want to know why eInvoice Signatory creates Invoice Hash incorrectly.

Thanks

Sure , here it is :

<?xml version="1.0" encoding="UTF-8"?><Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"><cbc:ProfileID>reporting:1.0</cbc:ProfileID><cbc:ID>2421136</cbc:ID><cbc:UUID>6826873a-a11d-4ef5-8c07-9bcf88f9e30e</cbc:UUID><cbc:IssueDate>2024-10-15</cbc:IssueDate><cbc:IssueTime>14:28:42</cbc:IssueTime><cbc:InvoiceTypeCode name="0100000">388</cbc:InvoiceTypeCode><cbc:DocumentCurrencyCode>SAR</cbc:DocumentCurrencyCode><cbc:TaxCurrencyCode>SAR</cbc:TaxCurrencyCode><cac:AdditionalDocumentReference><cbc:ID>ICV</cbc:ID><cbc:UUID>20</cbc:UUID></cac:AdditionalDocumentReference><cac:AdditionalDocumentReference><cbc:ID>PIH</cbc:ID><cac:Attachment><cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">tA77YBebmAwOFFMeAF4W9iBODyTHXIEYIExiRvP7qh0=</cbc:EmbeddedDocumentBinaryObject></cac:Attachment></cac:AdditionalDocumentReference><cac:AccountingSupplierParty><cac:Party><cac:PartyIdentification><cbc:ID schemeID="CRN">4030189555</cbc:ID></cac:PartyIdentification><cac:PostalAddress><cbc:StreetName>Madinah Road</cbc:StreetName><cbc:BuildingNumber>7571</cbc:BuildingNumber><cbc:CitySubdivisionName>Sharafiya</cbc:CitySubdivisionName><cbc:CityName>Jeddah</cbc:CityName><cbc:PostalZone>21483</cbc:PostalZone><cac:Country><cbc:IdentificationCode>SA</cbc:IdentificationCode></cac:Country></cac:PostalAddress><cac:PartyTaxScheme><cbc:CompanyID>310834741800003</cbc:CompanyID><cac:TaxScheme><cbc:ID>VAT</cbc:ID></cac:TaxScheme></cac:PartyTaxScheme><cac:PartyLegalEntity><cbc:RegistrationName>HOUSE OF RAYS MEDICAL Co.</cbc:RegistrationName></cac:PartyLegalEntity></cac:Party></cac:AccountingSupplierParty><cac:AccountingCustomerParty><cac:Party><cac:PostalAddress><cbc:StreetName>King Fahad Road</cbc:StreetName><cbc:BuildingNumber>8787</cbc:BuildingNumber><cbc:CitySubdivisionName>Olaya</cbc:CitySubdivisionName><cbc:CityName>Riyadh</cbc:CityName><cbc:PostalZone>12214</cbc:PostalZone><cac:Country><cbc:IdentificationCode>SA</cbc:IdentificationCode></cac:Country></cac:PostalAddress><cac:PartyTaxScheme><cbc:CompanyID>300094611410003</cbc:CompanyID><cac:TaxScheme><cbc:ID>VAT</cbc:ID></cac:TaxScheme></cac:PartyTaxScheme><cac:PartyLegalEntity><cbc:RegistrationName>DR.SULAIMAN AL HABIB MEDICAL SERVICES GROUP CO. -RYD</cbc:RegistrationName></cac:PartyLegalEntity></cac:Party></cac:AccountingCustomerParty><cac:Delivery><cbc:ActualDeliveryDate>2024-10-15</cbc:ActualDeliveryDate></cac:Delivery><cac:PaymentMeans><cbc:PaymentMeansCode>30</cbc:PaymentMeansCode></cac:PaymentMeans><cac:TaxTotal><cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount></cac:TaxTotal><cac:TaxTotal><cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount><cac:TaxSubtotal><cbc:TaxableAmount currencyID="SAR">53549.52</cbc:TaxableAmount><cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount><cac:TaxCategory><cbc:ID>Z</cbc:ID><cbc:Percent>0.00</cbc:Percent><cbc:TaxExemptionReasonCode>VATEX-SA-35</cbc:TaxExemptionReasonCode><cbc:TaxExemptionReason>Medical Supplies</cbc:TaxExemptionReason><cac:TaxScheme><cbc:ID>VAT</cbc:ID></cac:TaxScheme></cac:TaxCategory></cac:TaxSubtotal></cac:TaxTotal><cac:LegalMonetaryTotal><cbc:LineExtensionAmount currencyID="SAR">53549.52</cbc:LineExtensionAmount><cbc:TaxExclusiveAmount currencyID="SAR">53549.52</cbc:TaxExclusiveAmount><cbc:TaxInclusiveAmount currencyID="SAR">53549.52</cbc:TaxInclusiveAmount><cbc:AllowanceTotalAmount currencyID="SAR">0.00</cbc:AllowanceTotalAmount><cbc:ChargeTotalAmount currencyID="SAR">0.00</cbc:ChargeTotalAmount><cbc:PrepaidAmount currencyID="SAR">0.00</cbc:PrepaidAmount><cbc:PayableAmount currencyID="SAR">53549.52</cbc:PayableAmount></cac:LegalMonetaryTotal><cac:InvoiceLine><cbc:ID>0</cbc:ID><cbc:InvoicedQuantity unitCode="EA">60000.000000</cbc:InvoicedQuantity><cbc:LineExtensionAmount currencyID="SAR">53549.52</cbc:LineExtensionAmount><cac:TaxTotal><cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount><cbc:RoundingAmount currencyID="SAR">53549.52</cbc:RoundingAmount></cac:TaxTotal><cac:Item><cbc:Name>POLYMED IV Set With Airvent, 150 CMS Tube, Y-Site, Luer Lock, W/O Needle, LATEX Free, Ribbon Pack</cbc:Name><cac:ClassifiedTaxCategory><cbc:ID>Z</cbc:ID><cbc:Percent>0.00</cbc:Percent><cbc:TaxExemptionReasonCode>VATEX-SA-35</cbc:TaxExemptionReasonCode><cbc:TaxExemptionReason>Medical Supplies</cbc:TaxExemptionReason><cac:TaxScheme><cbc:ID>VAT</cbc:ID></cac:TaxScheme></cac:ClassifiedTaxCategory></cac:Item><cac:Price><cbc:PriceAmount currencyID="SAR">0.892492</cbc:PriceAmount></cac:Price></cac:InvoiceLine></Invoice>
1 Like

Your Invoice is has been signed and validated successfully at my end. can you share your signature and validation code?

this is your XML, check it now

<?xml version="1.0" encoding="utf-8"?><Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
  <ext:UBLExtensions>
    <ext:UBLExtension>
        <ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
        <ext:ExtensionContent>
            <sig:UBLDocumentSignatures xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2" xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2">
                <sac:SignatureInformation>
                    <cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID>
                    <sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID>
                    <ds:Signature Id="signature" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                        <ds:SignedInfo>
                            <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2006/12/xml-c14n11" />
                            <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256" />
                            <ds:Reference Id="invoiceSignedData" URI="">
                                <ds:Transforms>
                                    <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
                                        <ds:XPath>not(//ancestor-or-self::ext:UBLExtensions)</ds:XPath>
                                    </ds:Transform>
                                    <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
                                        <ds:XPath>not(//ancestor-or-self::cac:Signature)</ds:XPath>
                                    </ds:Transform>
                                    <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
                                        <ds:XPath>not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])</ds:XPath>
                                    </ds:Transform>
                                    <ds:Transform Algorithm="http://www.w3.org/2006/12/xml-c14n11" />
                                </ds:Transforms>
                                <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                                <ds:DigestValue>ZF9UXdC7GSif4fsIhKeuxSyYD/A2YxPx3BFDZr7clbg=</ds:DigestValue>
                            </ds:Reference>
                            <ds:Reference Type="http://www.w3.org/2000/09/xmldsig#SignatureProperties" URI="#xadesSignedProperties">
                                <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                                <ds:DigestValue>ZjQ2ZjA1Y2Q1ZDI1NWFlZDc1OTM5MDA4YmZiNGJkMmJmNzM2NWIyZDdjOWQ2YWU2ZDE3OTcxYmU4MWYxNzZkMQ==</ds:DigestValue>
                            </ds:Reference>
                        </ds:SignedInfo>
                        <ds:SignatureValue>MEUCIQCEd31YYgp1Zv1NViVCwJkg/tLCkmEcR9RnsGbBTIhX1AIgaTfu9jskYATaDCLIfNuZRjZXElo8LLo30gMLCSbBj6c=</ds:SignatureValue>
                        <ds:KeyInfo>
                            <ds:X509Data>
                                <ds:X509Certificate>MIIFLTCCBNKgAwIBAgITegAAT1YbGELPLmdpGgABAABPVjAKBggqhkjOPQQDAjBiMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxEzARBgoJkiaJk/IsZAEZFgNnb3YxFzAVBgoJkiaJk/IsZAEZFgdleHRnYXp0MRswGQYDVQQDExJQRVpFSU5WT0lDRVNDQTMtQ0EwHhcNMjQwOTE5MDczMDUwWhcNMjYwOTE5MDc0MDUwWjBfMQswCQYDVQQGEwJTQTEmMCQGA1UEChMdQXdhbCBFcXVpcG1lbnQgSGlyaW5nIENvbXBhbnkxEjAQBgNVBAsTCUF3YWxCYW5jaDEUMBIGA1UEAxMLVjczNzcxN1RFU1QwVjAQBgcqhkjOPQIBBgUrgQQACgNCAARqVVnSboXamRsVue+zvE/RVd1/3rUD587hBxPmhqd2AHUfMwk5D69vN+re4seRChdeILBm9eb3d9RMU5I1Y7yco4IDazCCA2cwgdUGA1UdEQSBzTCByqSBxzCBxDFbMFkGA1UEBAxSMS1pSGlyZVNvZnR3YXJlfDItMjAyNC45LjAuMTd8My0wYmVjNzQ0NC03MTQzLTQ1ZDgtOTBkMi1hMDdiYzEyNzdiZDJ8NC1WNzM3NzE3VEVTVDEfMB0GCgmSJomT8ixkAQEMDzMwMDk5NzU5NTMwMDAwMzENMAsGA1UEDAwEMTEwMDERMA8GA1UEGgwIRUVEQzI4MTcxIjAgBgNVBA8MGUVxdWlwbWVudCBSZW50YWwgQnVzaW5lc3MwHQYDVR0OBBYEFBj2WNNkbmFMka5R/wqauR8hNeOjMB8GA1UdIwQYMBaAFN2DcROOubVzb6Z4gH+8z5ofvwUQMIHlBgNVHR8Egd0wgdowgdeggdSggdGGgc5sZGFwOi8vL0NOPVBFWkVJTlZPSUNFU0NBMy1DQSgxKSxDTj1QUlpFSU5WT0lDRVBLSTMsQ049Q0RQLENOPVB1YmxpYyUyMEtleSUyMFNlcnZpY2VzLENOPVNlcnZpY2VzLENOPUNvbmZpZ3VyYXRpb24sREM9ZXh0emF0Y2EsREM9Z292LERDPWxvY2FsP2NlcnRpZmljYXRlUmV2b2NhdGlvbkxpc3Q/YmFzZT9vYmplY3RDbGFzcz1jUkxEaXN0cmlidXRpb25Qb2ludDCBzgYIKwYBBQUHAQEEgcEwgb4wgbsGCCsGAQUFBzAChoGubGRhcDovLy9DTj1QRVpFSU5WT0lDRVNDQTMtQ0EsQ049QUlBLENOPVB1YmxpYyUyMEtleSUyMFNlcnZpY2VzLENOPVNlcnZpY2VzLENOPUNvbmZpZ3VyYXRpb24sREM9ZXh0emF0Y2EsREM9Z292LERDPWxvY2FsP2NBQ2VydGlmaWNhdGU/YmFzZT9vYmplY3RDbGFzcz1jZXJ0aWZpY2F0aW9uQXV0aG9yaXR5MA4GA1UdDwEB/wQEAwIHgDA8BgkrBgEEAYI3FQcELzAtBiUrBgEEAYI3FQiBhqgdhND7EobtnSSHzvsZ08BVZoGc2C2D5cVdAgFkAgEQMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDAzAnBgkrBgEEAYI3FQoEGjAYMAoGCCsGAQUFBwMCMAoGCCsGAQUFBwMDMAoGCCqGSM49BAMCA0kAMEYCIQDcPgqvsTiEBfgXm2bQaPs4rTjrEIAbyItx070DQ3/i5gIhAJxZXWjo+cjU0gMcwmkakgnkJEKm7Lxa7e9mswjqrRmp</ds:X509Certificate>
                            </ds:X509Data>
                        </ds:KeyInfo>
                        <ds:Object>
                            <xades:QualifyingProperties Target="signature" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#">
                                <xades:SignedProperties Id="xadesSignedProperties">
                                    <xades:SignedSignatureProperties>
                                        <xades:SigningTime>2024-10-17T15:06:20</xades:SigningTime>
                                        <xades:SigningCertificate>
                                            <xades:Cert>
                                                <xades:CertDigest>
                                                    <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                                                    <ds:DigestValue>NjA5ZjMwNjlkZTBiZjIyMDcwZTM4NGZkMzc0N2M4NGM2YTQ5OTc0OWI1MmE2Yjg2ZTJmOTc2YjU2YTE5NmFlNw==</ds:DigestValue>
                                                </xades:CertDigest>
                                                <xades:IssuerSerial>
                                                    <ds:X509IssuerName>CN=PEZEINVOICESCA3-CA, DC=extgazt, DC=gov, DC=local</ds:X509IssuerName>
                                                    <ds:X509SerialNumber>2720691019676834767321383131478249469464563542</ds:X509SerialNumber>
                                                </xades:IssuerSerial>
                                            </xades:Cert>
                                        </xades:SigningCertificate>
                                    </xades:SignedSignatureProperties>
                                </xades:SignedProperties>
                            </xades:QualifyingProperties>
                        </ds:Object>
                    </ds:Signature>
                </sac:SignatureInformation>
            </sig:UBLDocumentSignatures>
        </ext:ExtensionContent>
    </ext:UBLExtension>
</ext:UBLExtensions>
  <cbc:ProfileID>reporting:1.0</cbc:ProfileID>
  <cbc:ID>2421136</cbc:ID>
  <cbc:UUID>6826873a-a11d-4ef5-8c07-9bcf88f9e30e</cbc:UUID>
  <cbc:IssueDate>2024-10-15</cbc:IssueDate>
  <cbc:IssueTime>14:28:42</cbc:IssueTime>
  <cbc:InvoiceTypeCode name="0100000">388</cbc:InvoiceTypeCode>
  <cbc:DocumentCurrencyCode>SAR</cbc:DocumentCurrencyCode>
  <cbc:TaxCurrencyCode>SAR</cbc:TaxCurrencyCode>
  <cac:AdditionalDocumentReference>
    <cbc:ID>ICV</cbc:ID>
    <cbc:UUID>20</cbc:UUID>
  </cac:AdditionalDocumentReference>
  <cac:AdditionalDocumentReference>
    <cbc:ID>PIH</cbc:ID>
    <cac:Attachment>
      <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">tA77YBebmAwOFFMeAF4W9iBODyTHXIEYIExiRvP7qh0=</cbc:EmbeddedDocumentBinaryObject>
    </cac:Attachment>
  </cac:AdditionalDocumentReference>
  <cac:AdditionalDocumentReference>
        <cbc:ID>QR</cbc:ID>
        <cac:Attachment>
            <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">ARlIT1VTRSBPRiBSQVlTIE1FRElDQUwgQ28uAg8zMTA4MzQ3NDE4MDAwMDMDEzIwMjQtMTAtMTVUMTQ6Mjg6NDIECDUzNTQ5LjUyBQQwLjAwBixaRjlVWGRDN0dTaWY0ZnNJaEtldXhTeVlEL0EyWXhQeDNCRkRacjdjbGJnPQdgTUVVQ0lRQ0VkMzFZWWdwMVp2MU5WaVZDd0prZy90TENrbUVjUjlSbnNHYkJUSWhYMUFJZ2FUZnU5anNrWUFUYURDTElmTnVaUmpaWEVsbzhMTG8zMGdNTENTYkJqNmM9CFgwVjAQBgcqhkjOPQIBBgUrgQQACgNCAARqVVnSboXamRsVue+zvE/RVd1/3rUD587hBxPmhqd2AHUfMwk5D69vN+re4seRChdeILBm9eb3d9RMU5I1Y7yc</cbc:EmbeddedDocumentBinaryObject>
        </cac:Attachment>
</cac:AdditionalDocumentReference><cac:Signature>
      <cbc:ID>urn:oasis:names:specification:ubl:signature:Invoice</cbc:ID>
      <cbc:SignatureMethod>urn:oasis:names:specification:ubl:dsig:enveloped:xades</cbc:SignatureMethod>
</cac:Signature><cac:AccountingSupplierParty>
    <cac:Party>
      <cac:PartyIdentification>
        <cbc:ID schemeID="CRN">4030189555</cbc:ID>
      </cac:PartyIdentification>
      <cac:PostalAddress>
        <cbc:StreetName>Madinah Road</cbc:StreetName>
        <cbc:BuildingNumber>7571</cbc:BuildingNumber>
        <cbc:CitySubdivisionName>Sharafiya</cbc:CitySubdivisionName>
        <cbc:CityName>Jeddah</cbc:CityName>
        <cbc:PostalZone>21483</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>SA</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
      <cac:PartyTaxScheme>
        <cbc:CompanyID>310834741800003</cbc:CompanyID>
        <cac:TaxScheme>
          <cbc:ID>VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:PartyTaxScheme>
      <cac:PartyLegalEntity>
        <cbc:RegistrationName>HOUSE OF RAYS MEDICAL Co.</cbc:RegistrationName>
      </cac:PartyLegalEntity>
    </cac:Party>
  </cac:AccountingSupplierParty>
  <cac:AccountingCustomerParty>
    <cac:Party>
      <cac:PostalAddress>
        <cbc:StreetName>King Fahad Road</cbc:StreetName>
        <cbc:BuildingNumber>8787</cbc:BuildingNumber>
        <cbc:CitySubdivisionName>Olaya</cbc:CitySubdivisionName>
        <cbc:CityName>Riyadh</cbc:CityName>
        <cbc:PostalZone>12214</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>SA</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
      <cac:PartyTaxScheme>
        <cbc:CompanyID>300094611410003</cbc:CompanyID>
        <cac:TaxScheme>
          <cbc:ID>VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:PartyTaxScheme>
      <cac:PartyLegalEntity>
        <cbc:RegistrationName>DR.SULAIMAN AL HABIB MEDICAL SERVICES GROUP CO. -RYD</cbc:RegistrationName>
      </cac:PartyLegalEntity>
    </cac:Party>
  </cac:AccountingCustomerParty>
  <cac:Delivery>
    <cbc:ActualDeliveryDate>2024-10-15</cbc:ActualDeliveryDate>
  </cac:Delivery>
  <cac:PaymentMeans>
    <cbc:PaymentMeansCode>30</cbc:PaymentMeansCode>
  </cac:PaymentMeans>
  <cac:TaxTotal>
    <cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount>
  </cac:TaxTotal>
  <cac:TaxTotal>
    <cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount>
    <cac:TaxSubtotal>
      <cbc:TaxableAmount currencyID="SAR">53549.52</cbc:TaxableAmount>
      <cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount>
      <cac:TaxCategory>
        <cbc:ID>Z</cbc:ID>
        <cbc:Percent>0.00</cbc:Percent>
        <cbc:TaxExemptionReasonCode>VATEX-SA-35</cbc:TaxExemptionReasonCode>
        <cbc:TaxExemptionReason>Medical Supplies</cbc:TaxExemptionReason>
        <cac:TaxScheme>
          <cbc:ID>VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:TaxCategory>
    </cac:TaxSubtotal>
  </cac:TaxTotal>
  <cac:LegalMonetaryTotal>
    <cbc:LineExtensionAmount currencyID="SAR">53549.52</cbc:LineExtensionAmount>
    <cbc:TaxExclusiveAmount currencyID="SAR">53549.52</cbc:TaxExclusiveAmount>
    <cbc:TaxInclusiveAmount currencyID="SAR">53549.52</cbc:TaxInclusiveAmount>
    <cbc:AllowanceTotalAmount currencyID="SAR">0.00</cbc:AllowanceTotalAmount>
    <cbc:ChargeTotalAmount currencyID="SAR">0.00</cbc:ChargeTotalAmount>
    <cbc:PrepaidAmount currencyID="SAR">0.00</cbc:PrepaidAmount>
    <cbc:PayableAmount currencyID="SAR">53549.52</cbc:PayableAmount>
  </cac:LegalMonetaryTotal>
  <cac:InvoiceLine>
    <cbc:ID>0</cbc:ID>
    <cbc:InvoicedQuantity unitCode="EA">60000.000000</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount currencyID="SAR">53549.52</cbc:LineExtensionAmount>
    <cac:TaxTotal>
      <cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount>
      <cbc:RoundingAmount currencyID="SAR">53549.52</cbc:RoundingAmount>
    </cac:TaxTotal>
    <cac:Item>
      <cbc:Name>POLYMED IV Set With Airvent, 150 CMS Tube, Y-Site, Luer Lock, W/O Needle, LATEX Free, Ribbon Pack</cbc:Name>
      <cac:ClassifiedTaxCategory>
        <cbc:ID>Z</cbc:ID>
        <cbc:Percent>0.00</cbc:Percent>
        <cbc:TaxExemptionReasonCode>VATEX-SA-35</cbc:TaxExemptionReasonCode>
        <cbc:TaxExemptionReason>Medical Supplies</cbc:TaxExemptionReason>
        <cac:TaxScheme>
          <cbc:ID>VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:ClassifiedTaxCategory>
    </cac:Item>
    <cac:Price>
      <cbc:PriceAmount currencyID="SAR">0.892492</cbc:PriceAmount>
    </cac:Price>
  </cac:InvoiceLine>
</Invoice>

@Ather , perfect , you managed to regenerate the same problem .

This is wrong , it’s only validited but if you submit it to ZATCA , you will get the error that the invoice hash calculated is wrong . check from your side . the hash here is ZF9UXdC7GSif4fsIhKeuxSyYD/A2YxPx3BFDZr7clbg=

the correct hash is :
6VUJWVzs/9rWUzGhw4VgEQIhRbec3IqItw1ekTk53sU=

@Hadi,
I can duplicate the Error as you experienced. This happens because you signed the Standard Invoice, which should be done by the server, not us.

{
  "validationResults": {
    "infoMessages": [
      {
        "type": "INFO",
        "code": "XSD_ZATCA_VALID",
        "category": "XSD validation",
        "message": "Complied with UBL 2.1 standards in line with ZATCA specifications",
        "status": "PASS"
      }
    ],
    "warningMessages": [],
    "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"
      }
    ],
    "status": "ERROR"
  },
  "reportingStatus": null,
  "clearanceStatus": "NOT_CLEARED",
  "qrSellertStatus": null,
  "qrBuyertStatus": null
}

Just my assumption is, because the Invoice you sent is a Standard Invoice, then we should not sign the Invoice sent to Zatca.

For Standard Invoice, it is better if we do not sign it,

  • Create InvoiceHash
  • Create RequestApi
  • Then replace the InvoiceHash on the Request created with our generated InvoiceHash at first step.
  • Send it to the Server.

{
  "validationResults": {
    "infoMessages": [
      {
        "type": "INFO",
        "code": "XSD_ZATCA_VALID",
        "category": "XSD validation",
        "message": "Complied with UBL 2.1 standards in line with ZATCA specifications",
        "status": "PASS"
      }
    ],
    "warningMessages": [],
    "errorMessages": [],
    "status": "PASS"
  },
  "reportingStatus": null,
  "clearanceStatus": "CLEARED",
  "qrSellertStatus": null,
  "qrBuyertStatus": null
}

you can see my code here, how i handle this

 public static RequestResult GenerateRequestApi(XmlDocument document, CertificateInfo certInfo, string pih, bool isForCompliance = false)
        {
            RequestResult requestResult = null;

            string x509CertificateContent = Encoding.UTF8.GetString(Convert.FromBase64String(isForCompliance ? certInfo.CCSIDBinaryToken : certInfo.PCSIDBinaryToken));
            string privateKey = certInfo.PrivateKey;

            //Test use Certificate and privatekey from Zatca eInvoice SDK
            if (certInfo.EnvironmentType == EnvironmentType.NonProduction)
            {
                x509CertificateContent = "MIID3jCCA4SgAwIBAgITEQAAOAPF90Ajs/xcXwABAAA4AzAKBggqhkjOPQQDAjBiMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxEzARBgoJkiaJk/IsZAEZFgNnb3YxFzAVBgoJkiaJk/IsZAEZFgdleHRnYXp0MRswGQYDVQQDExJQUlpFSU5WT0lDRVNDQTQtQ0EwHhcNMjQwMTExMDkxOTMwWhcNMjkwMTA5MDkxOTMwWjB1MQswCQYDVQQGEwJTQTEmMCQGA1UEChMdTWF4aW11bSBTcGVlZCBUZWNoIFN1cHBseSBMVEQxFjAUBgNVBAsTDVJpeWFkaCBCcmFuY2gxJjAkBgNVBAMTHVRTVC04ODY0MzExNDUtMzk5OTk5OTk5OTAwMDAzMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEoWCKa0Sa9FIErTOv0uAkC1VIKXxU9nPpx2vlf4yhMejy8c02XJblDq7tPydo8mq0ahOMmNo8gwni7Xt1KT9UeKOCAgcwggIDMIGtBgNVHREEgaUwgaKkgZ8wgZwxOzA5BgNVBAQMMjEtVFNUfDItVFNUfDMtZWQyMmYxZDgtZTZhMi0xMTE4LTliNTgtZDlhOGYxMWU0NDVmMR8wHQYKCZImiZPyLGQBAQwPMzk5OTk5OTk5OTAwMDAzMQ0wCwYDVQQMDAQxMTAwMREwDwYDVQQaDAhSUlJEMjkyOTEaMBgGA1UEDwwRU3VwcGx5IGFjdGl2aXRpZXMwHQYDVR0OBBYEFEX+YvmmtnYoDf9BGbKo7ocTKYK1MB8GA1UdIwQYMBaAFJvKqqLtmqwskIFzVvpP2PxT+9NnMHsGCCsGAQUFBwEBBG8wbTBrBggrBgEFBQcwAoZfaHR0cDovL2FpYTQuemF0Y2EuZ292LnNhL0NlcnRFbnJvbGwvUFJaRUludm9pY2VTQ0E0LmV4dGdhenQuZ292LmxvY2FsX1BSWkVJTlZPSUNFU0NBNC1DQSgxKS5jcnQwDgYDVR0PAQH/BAQDAgeAMDwGCSsGAQQBgjcVBwQvMC0GJSsGAQQBgjcVCIGGqB2E0PsShu2dJIfO+xnTwFVmh/qlZYXZhD4CAWQCARIwHQYDVR0lBBYwFAYIKwYBBQUHAwMGCCsGAQUFBwMCMCcGCSsGAQQBgjcVCgQaMBgwCgYIKwYBBQUHAwMwCgYIKwYBBQUHAwIwCgYIKoZIzj0EAwIDSAAwRQIhALE/ichmnWXCUKUbca3yci8oqwaLvFdHVjQrveI9uqAbAiA9hC4M8jgMBADPSzmd2uiPJA6gKR3LE03U75eqbC/rXA==";
                privateKey = "MHQCAQEEIL14JV+5nr/sE8Sppaf2IySovrhVBtt8+yz+g4NRKyz8oAcGBSuBBAAKoUQDQgAEoWCKa0Sa9FIErTOv0uAkC1VIKXxU9nPpx2vlf4yhMejy8c02XJblDq7tPydo8mq0ahOMmNo8gwni7Xt1KT9UeA==";
            }

            if (IsSimplifiedInvoice(document))
            {
                SignResult signedInvoiceResult = new EInvoiceSigner().SignDocument(document, x509CertificateContent, privateKey);

                if (IsValidInvoice(signedInvoiceResult.SignedEInvoice, x509CertificateContent, pih))
                {
                    requestResult = new RequestGenerator().GenerateRequest(signedInvoiceResult.SignedEInvoice);
                }
            }
            else
            {
                if (IsValidInvoice(document, x509CertificateContent, pih))
                {
                    HashResult hashResult = new EInvoiceHashGenerator().GenerateEInvoiceHashing(document);

                    requestResult = new RequestGenerator().GenerateRequest(document);
                    requestResult.InvoiceRequest.InvoiceHash = hashResult.Hash;
                }
            }

            return requestResult;
        }

Dear @eCloud ,

Yes this is almost the same workaround I’m doing too .

But I think it shouldn’t produce incorrect hash at the first place.

Maybe @idaoud can also advice on this

@Hadi
I agree with you, developers should look into this.

I also think this might be a bug, for documents with linearized XML. InvoiceS ignator seems to change the original Invoice structure of the document when saving the invoice and doesn’t recalculate the InvoiceHash when creating the Invoice Request and causes the InvoiceHash to be incorrect.

hi sir

1-you have to use this code xml.PreserveWhitespace = true;

2- you have to add one space in the beginning of you xml

if you do this 2 steps you r hash will be accpted