Rejections, retries and corrections
When something goes wrong, there are exactly three ways forward. Which one applies depends on whether ZATCA gave a final answer for the document.
| Situation | Operation | New UUID / counter? |
|---|---|---|
| No final answer yet (timeout, ZATCA down, retries exhausted, authentication problem) | A. Retry the identical document | No |
| ZATCA rejected the document, or the JSON was invalid | B. Correct and reprocess | Yes (new issuance) |
| ZATCA accepted the document, but it is wrong | C. Credit or debit note | New document, new record |
Never do these
- Change an accepted invoice. ZATCA has it; only a credit or debit note can change it.
- Resend a rejected document unchanged. ZATCA will reject the same bytes again.
- Delete invoices, issuances or attempts. Everything is kept for the audit trail.
Reading the rejection
php artisan zatca:invoice show 01M6E1Y8WXFJ0RK6YXMP4JN9WXshow prints the statuses, the number of unresolved errors and the last error code. ZATCA's full messages (for example BR-KSA-37 Saudi building numbers have exactly 4 digits) are in zatca_errors; every call to ZATCA, with its sanitised response, is in zatca_submission_attempts:
SELECT e.code, e.message, e.severity, e.created_at
FROM zatca_errors e JOIN zatca_invoices i ON i.id = e.invoice_id
WHERE i.public_id = '01M6E1Y8WXFJ0RK6YXMP4JN9WX' AND e.resolved_at IS NULL;A. Retry the submission
Sends the same signed document again: same UUID, counter, hash, signature and QR.
use CodingTriplets\Zatca\Laravel\Facades\Zatca;
Zatca::invoices()->retry($invoiceId, actorId: auth()->id()); // queued
Zatca::invoices()->retry($invoiceId, actorId: auth()->id(), now: true); // inside this callphp artisan zatca:invoice retry 01M6E1Y8WXFJ0RK6YXMP4JN9WX --actor=7
php artisan zatca:invoice retry 01M6E1Y8WXFJ0RK6YXMP4JN9WX --nowAllowed when the invoice is QUEUED, RETRY_PENDING, FAILED, OUTCOME_UNKNOWN or MANUAL_REVIEW and the document has no final ZATCA result. Refused for accepted or rejected documents, and while a worker is sending it.
B. Correct and reprocess
Saves a corrected JSON as a new version (the original stays untouched) and issues it again:
$corrected = $originalPayload;
$corrected['buyer']['address']['building_number'] = '1234';
$result = Zatca::invoices()->correct($invoiceId, $corrected, reason: 'Wrong buyer building number', actorId: auth()->id());
$result->toArray(); // new counter, uuid, qrphp artisan zatca:invoice correct 01M6E1Y8WXFJ0RK6YXMP4JN9WX --file=corrected.json --reason="Wrong buyer building number" --actor=7What happens:
- The corrected JSON is validated. If it is invalid,
InvoiceValidationExceptionis thrown and nothing is saved. - Version n+1 is stored with the reason, the author and the list of changed fields.
- A new issuance is created: new UUID, next counter of the device, PIH = hash of the device's last document. The rejected document stays in the chain (ZATCA has seen it).
- The old issuance is marked
superseded, its errors are marked resolved. - It is submitted like any new document. Events:
InvoiceReissued, and for B2CCustomerCopyReissued(with the new QR, so you can give the customer an updated receipt).
The invoice record (invoice_id) stays the same; both issuances appear in its history.
Correcting also works for invoices that never got a document (VALIDATION_FAILED): the first issuance is then created.
Reissue without changes
If the rejection was caused by something outside the JSON (for example a certificate problem that has since been fixed), issue a new document from the same JSON:
Zatca::invoices()->reissueUnchanged($invoiceId, reason: 'Certificate renewed', actorId: auth()->id());php artisan zatca:invoice reissue 01M6E1Y8WXFJ0RK6YXMP4JN9WX --reason="Certificate renewed"Invoice number and issue date of a corrected document
| Workflow | Invoice number | Issue date | Config |
|---|---|---|---|
| B2C | Kept | Original issue date | zatca.correction.b2c_keep_invoice_number, b2c_keep_issue_date |
| B2B | Kept | Date of the reissue | zatca.correction.b2b_keep_invoice_number, b2b_update_issue_date |
If you set "keep invoice number" to false, the corrected payload must contain a new invoice_number.
Pending ZATCA confirmation
ZATCA's published guidelines do not state these rules explicitly. The defaults above are the package's best reading and are configurable. If ZATCA or your tax advisor requires a credit note for rejected invoices, set zatca.correction.credit_note_for_rejected = true; correcting and reissuing are then refused.
Approval (four-eyes)
With zatca.correction.four_eyes = true, a correction is saved but not issued. The invoice waits in MANUAL_REVIEW until a different user approves it:
Zatca::invoices()->approve($invoiceId, approverId: auth()->id());php artisan zatca:invoice approve 01M6E1Y8WXFJ0RK6YXMP4JN9WX --actor=9C. Credit and debit notes
For accepted invoices. See Credit and debit notes.
Errors
All operations throw CodingTriplets\Zatca\Laravel\Invoices\OperationNotAllowed with a clear reason when the operation does not fit the invoice's state, for example:
- "it was accepted by ZATCA; issue a credit or debit note instead"
- "its document has no final ZATCA result yet; retry the submission instead"
- "a submission is in progress"