Invoices with correct invoice hash failing with hash error on simulation

@ anusv@calmove.com
@dinanemah
@anusv

Please, can you send the code to my email: madleenawny20@gmail.com?

I use C# SDK, and face the same issue,
please, can you send your code to it@dca.org.sa,
Note, I am still in the onboarding phase.

public RequestResult GetSignedInvoiceRequest(XmlDocument eInvoice, string binarySecurityToken, string privateKey)
{
privateKey = System.IO.File.ReadAllText(“PrivateKey.pem”);

IEInvoiceQRGenerator eInvoiceQRGenerator = new EInvoiceQRGenerator();
QRResult qRResult = eInvoiceQRGenerator.GenerateEInvoiceQRCode(eInvoice);

SignResult signedResult = _eInvoiceSigner.SignDocument(eInvoice, Base64Converter.Base64Decode(binarySecurityToken), privateKey);
var asda = signedResult.SignedEInvoice;
string xmlString = XmlToString(signedResult.SignedEInvoice);
RequestResult request = _requestGenerator.GenerateRequest(signedResult.SignedEInvoice);
HashResult hashInvoice = _eInvoiceHashGenerator.GenerateEInvoiceHashing(signedResult.SignedEInvoice);
request.InvoiceRequest.InvoiceHash = hashInvoice.Hash;

var body = JsonConvert.SerializeObject(request.InvoiceRequest);

return request;

}

Dear Zatca Team,

I think Zatca team can see this case, There might be an error in the user code or maybe an error in the library.

I tried to validate Invoice with status REPORTED using .Net Library from SDK, but it gives the same error as what my colleagues said above…

{
    "requestUri": "https://gw-fatoora.zatca.gov.sa/e-invoicing/simulation/invoices/reporting/single",
    "requestType": "Invoice Reporting",
    "statusCode": "200-OK",
    "reportingStatus": "REPORTED",
    "validationResults": {
        "status": "PASS",
        "infoMessages": [
            {
                "status": "PASS",
                "type": "INFO",
                "code": "XSD_ZATCA_VALID",
                "category": "XSD validation",
                "message": "Complied with UBL 2.1 standards in line with ZATCA specifications"
            }
        ],
        "warningMessages": [],
        "errorMessages": []
    }
}                                 
using System.Xml;
using Zatca.EInvoice.SDK.Contracts.Models;
using Zatca.EInvoice.SDK;

namespace ZatcaWithSDK
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            string certificateContent = File.ReadAllText(@"..\..\..\Data\Certificates\cert.pem");

            XmlDocument eInvoice = new XmlDocument();
            eInvoice.Load(@"..\..\..\Data\Invoice\300535209500003_20240831000000_6 (1).xml");

            EInvoiceValidator EInvoiceValidator = new EInvoiceValidator();
            ValidationResult ValidationResult = EInvoiceValidator.ValidateEInvoice(eInvoice, certificateContent, "Ar3dPjm+LErCuPW+N9Y3Yfpkxbk8LQeWZdeV93dPamU=");

            ShowValidationResult(ValidationResult);

        }
        public static void ShowValidationResult(ValidationResult validationResult)
        {
            Console.WriteLine($"Overall Validation: {(validationResult.IsValid ? "Valid" : "Invalid")}");
            foreach (var step in validationResult.ValidationSteps)
            {
                Console.WriteLine($"Step: {step.ValidationStepName}");
                Console.WriteLine($"  Status: {(step.IsValid ? "Valid" : "Invalid")}");

                if (step.ErrorMessages.Any())
                {
                    Console.WriteLine("  Errors:");
                    foreach (var error in step.ErrorMessages)
                    {
                        Console.WriteLine($"    - {error}");
                    }
                }

                if (step.WarningMessages.Any())
                {
                    Console.WriteLine("  Warnings:");
                    foreach (var warning in step.WarningMessages)
                    {
                        Console.WriteLine($"    - {warning}");
                    }
                }
            }
        }

    }
}

Maybe there is something wrong with the way I use the library from SDK.

Wouldn’t it be better if Zatca Team could share the code as a guide for us .Net SDK users. This would be very helpful for us, without having to guess how to use the SDK to sign B2C invoices and validate them before sending them to the Zatca server.

Thank you.

1 Like