"Invalid Invoice Hash" Error During ZATCA Sandbox Testing

Yes, of course.

You can describe your problem and provide more information clearly, and also tell us what you have done, so that other users can try to help you.

I am getting error generating validating QR data , i generated UBLextension data and QR data but while testing i am getting error validation , check error below

ECDSA Public Key does not match with qr code ECDSA public key
invoice signature value does not match with qr invoice signature value 
certificate signature does not match with qr certificate signature value

@UnitedDev

It is recommended that you share Clean XML, Signed XML and Code snippets of how you sign your XML.
Tags 6 - 7 are from UBL and Tag 8-9 extracted from x509Certificate

thank you , i am sharing my full XML below , i have not signed XML , can you tell how do you signed XML. and i have one more questions , please provide me code , how do you generate UBLExtenions tags data , i will be thankful to you

my full XML : Unique Download Link | WeTransfer

let me explain procedure in detail below and please read all points so that you can improve it ,

-I had XML format without UBLextensions and QR data so i decided to create it

  • i created UBL extensions data manually , i had invoice hash only , so i download file of private key , public key and certificate to extract more data like serial number , certificate , signature etc . Remember i have not any certificate from zatca all these certificate i got from ChatGpt.

  • i added values in UBLExtensions tags and then decided to generate QR data.

  • Unfortunately my QR data is bigger in character because i am not using correct value.

So you may have understand the issue by now that , may be i am having issue in UBLextensions tags.

You have to understand how to sign an Invoice, then you can focus on how to make a qrcode.

This should help you
SigningProcessUpdated.pdf

1 Like

You are great thanks , now i got clear information , can you please share any document that says how to build QR code , thanks

i am testing in sandbox api integration. i am also getting this error , can you tell me do i have to add any tags or anything different ?

error : ```
{
“type”: “WARNING”,
“code”: “BR-KSA-60”,
“category”: “KSA”,
“message”: “[BR-KSA-60]-Cryptographic stamp (KSA-15) must exist in simplified tax invoices and associated credit notes and debit notes (KSA-2, position 1 and 2 = 02).”,
“status”: “WARNING”
}

E-invoicing-Detailed-Technical-Guideline.pdf

Page 58.

1 Like

thanks you , your given document helped me alot , now i completed signing process and now i am facing issue generating QR data , i am getting invalid QR error , please look below my all given code and XML data.

Full XML : Unique Download Link | WeTransfer

QR generate code : Unique Download Link | WeTransfer

Please let me know if you need any data , Thank you again

Not so sure, probably you got the wrong ECDSA PublicKey and ECDSA Signature. Tag8 and Tag9 should be in Byte[]

Use Certlogic decoder to get the ECDSA PublicKey and ECDSA Signature in Hex . try to debug in Hex and compare with what you get in your code

Your QRCode

Tag: 1, Value: TestPOS Branch #1
Tag: 2, Value: 399999999900003
Tag: 3, Value: 2024-10-16T09:21:11Z
Tag: 4, Value: 50.00
Tag: 5, Value: 6.52
Tag: 6, Value: 4da0dabcb90f1ac7a8ad07efaf57ee80095738c9d1c90aed89e692befaa193e2
Tag: 7, Value: MEUCIQDnddEp+s7RN1fqvUhDj85MVr4FvQKOqhtI0U4qSm1lzwIgFLnMueQCS5Ai0rWpqHqTRXWB5VGRsVlZ00+sXobzfhg=
Tag: 8, Value:
0000: 4D 46 59 77 45 41 59 48 4B 6F 5A 49 7A 6A 30 43
0016: 41 51 59 46 4B 34 45 45 41 41 6F 44 51 67 41 45
0032: 6F 57 43 4B 61 30 53 61 39 46 49 45 72 54 4F 76
0048: 30 75 41 6B 43 31 56 49 4B 58 78 55 39 6E 50 70
0064: 78 32 76 6C 66 34 79 68 4D 65 6A 79 38 63 30 32
0080: 58 4A 62 6C 44 71 37 74 50 79 64 6F 38 6D 71 30
0096: 61 68 4F 4D 6D 4E 6F 38 67 77 6E 69 37 58 74 31
0112: 4B 54 39 55 65 41 3D 3D
Tag: 9, Value:
0000: 38 39 63 38 36 36 39 64 36 35 63 32 35 30 61 35
0016: 31 62 37 31 61 64 66 32 37 32 32 66 32 38 61 62
0032: 30 36 38 62 62 63 35 37 34 37 35 36 33 34 32 62
0048: 62 64 65 32 33 64 62 61 61 30 31 62 30 32 32 30
0064: 33 64 38 34 32 65 30 63 66 32 33 38 30 63 30 34
0080: 30 30 63 66 34 62 33 39 39 64 64 61 65 38 38 66
0096: 32 34 30 65 61 30 32 39 31 64 63 62 31 33 34 64
0112: 64 34 65 66 39 37 61 61 36 63 32 66 65 62 35 63
0128: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0144: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0176: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0192: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0208: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0224: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0256: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0272: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0288: 00 00 00 00 00 00 00 00 .........

Tag8 and Tag 9 should start with 30

and make sure DateTime on QRCode is DateTime from Invoice not from SigningTime

	<cbc:IssueDate>2024-10-16</cbc:IssueDate>
	<cbc:IssueTime>09:21:11</cbc:IssueTime>

2024-10-16T09:21:11

Hi, I am getting the error: The invoice hash API body does not match the (calculated) Hash of the XML.

I have followed the following steps

  1. Canonicalized my invoice using link :XML Canonicalizer

  2. Hash with SHA 256 LINK : SHA256 - Online Tools

  3. Encoded result of point 2 to base64 link:https://www.base64encode.org/
    The above created hash
    to create Invoice body I did the following

    1. Canonicalized my invoice using link :XML Canonicalizer
  4. Encoded result of point 1 to base64 link:https://www.base64encode.org/

Download Files here

I am still getting this error. My invoice IS B2B xml. @Malik , Please guide how you resolved this error.

Hi, try to use ZATCA provided libraries/SDK Java/.NET etc. thanks

Thanks for your reply @Malik . I have tried different suggestion but am stuck here for long. I have created my XML file using C#. The xml format is passing but the error is in the difference btn Invoicehash &Invoice body.

“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
}

@UnitedDev how did you resolve yours? any one with an idea, please assist

I have converted this code to C# from the php code you provided, I was able to create the payload succesfully (InvoiceHash,uuid & Invoice) but when I use the payload, I am still getting the same error. : “The invoice hash API body does not match the (calculated) Hash of the XML”

@James

If you are using C# and .NET Zatca eInvoice SDK library, you can try the code snippet here

Morning @James

Thanks for reaching out,

To ensure comprehensive support as usual, can I kindly ask you to share the full request that you sent to Clerance API?

Thanks,
Ibrahem Daoud.

Hello eCloud, Hope you are doing well. I would like to say thank you for your helps.
I have question about standart invoice.
We will send standard invoice signed to ZATCA. Above on your reply you said that we can send standart invoice without signed to ZATCA. Which Method will be good for us in the production. Could you help me for it?

Thanks
Mustafa

@Mustafa.Acar
It’s up to you, For standard invoice Document will be signed by server and Signed Document is returned via clearedInvoice in api response, but make sure your xml format is according to the example given in Zatca eInvoice SDK, to avoid Invoice Hashing Error problem.