Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INVOICE_HASHING_ERRORS #50

Open
adeelmughal4u opened this issue Jan 21, 2025 · 3 comments
Open

INVOICE_HASHING_ERRORS #50

adeelmughal4u opened this issue Jan 21, 2025 · 3 comments

Comments

@adeelmughal4u
Copy link

adeelmughal4u commented Jan 21, 2025

Getting below error

stdClass Object
(
[validationResults] => stdClass Object
(
[infoMessages] => Array
(
[0] => stdClass Object
(
[type] => INFO
[code] => XSD_ZATCA_VALID
[category] => XSD validation
[message] => Complied with UBL 2.1 standards in line with ZATCA specifications
[status] => PASS
)

            )

        [warningMessages] => Array
            (
            )

        [errorMessages] => Array
            (
                [0] => stdClass Object
                    (
                        [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] => 
[clearanceStatus] => NOT_CLEARED
[qrSellertStatus] => 
[qrBuyertStatus] => 

)

@ashoeb2197
Copy link

ashoeb2197 commented Jan 22, 2025

don't sign the invoice only create hash using DOMDocument

$dom = new \DOMDocument('1.0', 'UTF-8'); $dom->preserveWhiteSpace = true; $dom->formatOutput = true; $dom->loadXML($XML); $invoiceHash = base64_encode(hash('sha256', $XML, true));

@adeelmughal4u
Copy link
Author

Thanks for replying, also when I use the below function, after $invoiceHash = base64_encode(hash('sha256', $XML, true));

use Salla\ZATCA\Helpers\Certificate;
use Salla\ZATCA\Models\InvoiceSign;

$xmlInvoice = 'xml invoice text';

$certificate = (new Certificate(
'certificate plain text (base64 decoded)', // get from ZATCA when you exchange the CSR via APIs
'private key plain text' // generated at stage one
))->setSecretKey('secret key text'); // get from ZATCA when you exchange the CSR via APIs

$invoice = (new InvoiceSign($xmlInvoice, $certificate))->sign();

// invoice Hash: $invoice->getHash()
// invoice signed as XML: $invoice->getInvoice()
// Invoice QR code as base64: $invoice->getQRCode()

@ashoeb2197
Copy link

Standard invoice doesnt need signing . pass only xml and invoice hash generated by my function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants