Closed AminAllahham closed 1 year ago
`import { EGS, EGSUnitInfo, ZATCASimplifiedInvoiceLineItem, ZATCASimplifiedTaxInvoice, } from "zatca-xml-js";
const run = async () => { console.log("Running ZATCA XML JS");
// Sample line item const line_item: ZATCASimplifiedInvoiceLineItem = { id: "1", name: "TEST NAME", quantity: 5, tax_exclusive_price: 10, VAT_percent: 0.15, other_taxes: [{ percent_amount: 1 }], discounts: [ { amount: 2, reason: "A discount" }, { amount: 2, reason: "A second discount" }, ], };
// Sample EGSUnit const egsunit: EGSUnitInfo = { uuid: "6f4d20e0-6bfe-4a80-9389-7dabe6620f12", custom_id: "EGS1-886431145", model: "IOS", CRN_number: "454634645645654", VAT_name: "Wesam Alzahir", VAT_number: "301121971500003", location: { city: "Khobar", city_subdivision: "West", street: "King Fahahd st", plot_identification: "0000", building: "0000", postal_zone: "31952", }, branch_name: "My Branch Name", branch_industry: "Food", };
// Sample Invoice const invoice = new ZATCASimplifiedTaxInvoice({ props: { egs_info: egsunit, invoice_counter_number: 1, invoice_serial_number: "EGS1-886431145-1", issue_date: "2022-03-13", issue_time: "14:40:40", previous_invoice_hash: "NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==", line_items: [line_item, line_item, line_item], }, });
try { // Init a new EGS const egs = new EGS(egsunit);
// New Keys & CSR for the EGS
await egs.generateNewKeysAndCSR(false, "solution_name");
// Issue a new compliance cert for the EGS
const compliance_request_id = await egs.issueComplianceCertificate(
"123345"
);
// Sign invoice
const { signed_invoice_string, invoice_hash, qr } =
egs.signInvoice(invoice);
// Check invoice compliance
console.log(
await egs.checkInvoiceCompliance(signed_invoice_string, invoice_hash)
);
// Issue production certificate
const production_request_id = await egs.issueProductionCertificate(
compliance_request_id
);
// Report invoice production
// Note: This request currently fails because ZATCA sandbox returns a constant fake production certificate
await egs.reportInvoice(signed_invoice_string, invoice_hash);
} catch (err: any) { console.log(err.response.data.validationResults); } };
run(); `
This is expected. If you look at the production certificate ZATCA is returning to you after egs.issueProductionCertificate
. (Can be found at egs.production_certificate
). Examine the details of the certificate it will have different information that the info you supplied. That is because ZATCA is returning a constant hardcoded certificate for production in their sandbox for some reason.
So when you try to report an invoice using their cert. Above errors appear which are valid.
can I request csid using c# without using openssl?
@AminAllahham @wes4m same error come to my how can i solve ?
User only allowed to use the vat number that exists in the authentication certificate
Hello i facing an issue when i trying to run full example script
errorMessages: [ { type: 'ERROR', code: 'certificate-permissions', category: 'CERTIFICATE_ERRORS', message: 'Production CSID does not cover Simplified documents', status: 'ERROR' }, { type: 'ERROR', code: 'certificate-permissions', category: 'CERTIFICATE_ERRORS', message: 'User only allowed to use the vat number that exists in the authentication certificate', status: 'ERROR' } ]
how can i implement this example for production