Skip to content

invalid-invoice-hash #57

@AhmedGamal905

Description

@AhmedGamal905

I get this :

 {
    "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": [
            {
                "type": "WARNING",
                "code": "invoiceTimeStamp_QRCODE_INVALID",
                "category": "QRCODE_VALIDATION",
                "message": "Time on QR Code does not match with Invoice Issue Time (KSA-25). If ZATCA's SDK was used to generate QR Code, kindly use the latest version of SDK",
                "status": "WARNING"
            }
        ],
        "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": "NOT_REPORTED",
    "clearanceStatus": null,
    "qrSellertStatus": null,
    "qrBuyertStatus": null
}

seems like the xml is correct but the hashing isn't.
a the code that i'm using here:

 $xmlContent = file_get_contents('test.xml');

    $certificate = (new Certificate(
        base64_decode(Storage::get('zatca/compliance_certificate.txt')),
        Storage::get('zatca/private_key.pem'),
    ))->setSecretKey(Storage::get('zatca/compliance_secret.txt'));

    $invoice = (new InvoiceSign(UXML::fromString($xmlContent), $certificate))->sign();

    $response = Http::withHeaders([
        'Accept' => 'application/json',
        'Content-Type' => 'application/json',
        'Accept-Language' => 'en',
        'Accept-Version' => 'V2',
        'Authorization' => 'Basic ' . base64_encode(Storage::get('zatca/compliance_certificate.txt') . ':' . Storage::get('zatca/compliance_secret.txt'))
    ])->post('https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/compliance/invoices', [
        'invoiceHash' => $invoice->getHash(),
        'uuid' => '4b3d8272-0f8f-4092-bf72-c5dc339ae0c8',
        'invoice' => base64_encode($invoice->getInvoice())
    ]);

  
    return response()->json([
        'success' => true,
        'message' => 'Invoice success',
        'data' => [
            'invoice_hash' => $invoice->getHash(),
            'invoice_xml' => base64_encode($invoice->getInvoice()),
            'qr_code_base64' => $invoice->getQRCode(),
            'signed_xml' => $invoice->getInvoice(),
        ],
        'full-data' => $response->json(),
    ]);

the code genrates the key, csr, csid and everything looks good.
do i need to report it first or what is the api chain i need to follow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions