Understanding the invoice clearance process

Dears ,

Hope this finds you well .

Just wanted to make sure that i’m doing things correctly regarding the invoice clearance process .

Now that i have the PCSID and secret . i should decode the PCSID BinaryToken and save it in cert.pem .
then i should sign my invoice using this cert.pem and using the private key generated in the process of getting the CCSID .

Please let me know if this is correct because i’m kind of stuck at this point now .

Dear @Hadi

Thanks for reaching out.

Can I kindly ask you, how you generate the CSR?

Thanks.
Ibrahem Daoud.

Dear @idaoud

Thanks for your reply .

i generated it using this :

fatooranet.exe csr -csrConfig …\csr.config -generatedCsr …\cert.csr -privateKey …\ec-secp256k1-priv-key.pem -nonprod true

i got the csr.config from the sample provided in the SDK . and modifed it to match my information .

Dear @Hadi

Please ensure that you are using the private key that generated with your CSR in the following path: zatca-einvoicing-sdk-238-R3.3.3\Data\Certificates\ec-secp256k1-priv-key.pem
With your decoded PCSID BinaryToken

For any further concerns, please do not hesitate to reach out with our support team to the below email,

SP email: sp_support@zatca.gov.sa

Thanks,
Ibrahem Daoud.

Dear @idaoud ,

Note with thanks .

One last thing . once i managed to sign the invoice i should clear it from ZATCA endpoint .

the body should contain :
1- Invoice (signed invoice in Base64) . please confirm this .
2- Invoice Hash . which i got from the signing process .
3- UUID .

And authorization header as usual (PCSID binarytoken and security encoded in Base64) .

Waiting for your confirmation .

Dear @Hadi

Correct, the body in the Reporting & Clerance APIs should contain the hash of the invoice, the UUID, and the signed invoice itself encoded using base64 for B2C invoices.

Additionally, since you are using SDK.Net, you can use the following command to generate a JSON request for you: fatooranet invoiceRequest -invoice “theSignedInvoice.xml”
Just double check if the hash from the generated JSON matches the hash for your signed invoice.

Thanks,
Ibrahem Daoud.

Dear @idaoud ,

Thank you for the clarificatoin . one thing i noted . i’m trying to sign invoices for B2B not B2C .

Also , i keep getting error when validiting my invoices .

[INFO] ValidationProcessorImpl - [PIH] validation result : FAILED
[ERROR] ValidationProcessorImpl - pih validation errors :
[ERROR] ValidationProcessorImpl - CODE : KSA-13, MESSAGE : PIH is inValid
[INFO] InvoiceValidationService -  *** GLOBAL VALIDATION RESULT = FAILED

I’m using the standard invoice provided in the sample folder in the SDK \Data\Samples\Standard\Invoice\Standard_Invoice.xml

I Tried modifying the PIH to 0 or to “MA==” (which is the equilivent of 0 in base64 with no luck .

any advice .

Dear @Hadi , please note that signing invoices from your side only required on B2C invoices, in B2B invoices ZATCA will sign it.

That should be true .

But in practice, ZATCA API Refuses my invoice if not signed.

Tried everything but not working unless I signed it .

So I just did sign it using ZATCA dll’s and it’s clearing fine now