Skip to content

B2C: simplified invoices ​

Simplified tax invoices are given to the customer immediately (with a QR code) and reported to ZATCA within 24 hours.

Issue an invoice ​

php
use CodingTriplets\Zatca\Laravel\Facades\Zatca;

$result = Zatca::b2c()->issue($payload, [
    'device' => $deviceId,          // device ID or device UUID (required)
    'external_id' => 'ORDER-98765', // optional idempotency key (default: invoice_number)
    'actor_id' => auth()->id(),     // optional, recorded in the history
]);

return response()->json($result->toArray(), $result->httpStatus);

What happens during the call ​

  1. The payload is stored unchanged (version 1) and validated.
  2. The device's next counter (ICV) and previous hash (PIH) are taken under a database lock.
  3. The XML is generated, hashed and signed; the QR code is built; the XML is stored.
  4. A reporting job is queued (after the transaction commits).
  5. The result is returned. No call to ZATCA happens in this request (default queue mode).

Response ​

json
{
  "status": true,
  "message": "invoice queued",
  "qr": "AR1NYXhpbXVtIFNwZWVk...",
  "counter": 10452,
  "uuid": "540ce75e-410a-4afa-8630-e603d05a6f13",
  "invoice_id": "01M6E1Y8WXFJ0RK6YXMP4JN9WX",
  "invoice_hash": "I5/YMabWxbVkgy1TisyXDP6qiqDrzTlGwgdQ0+16WdE=",
  "processing_status": "QUEUED",
  "reporting_deadline": "2026-11-03T14:57:29Z"
}
FieldMeaning
statustrue when the invoice was issued (or already existed)
messageinvoice queued, invoice reported, invoice not reported, validation failed, …
qrBase64 QR payload. Render it as a QR code on the receipt
counterThe invoice counter (ICV) of the document
uuidThe document UUID
invoice_idThe package's ID for the invoice record. Use it for lookups and operations
invoice_hashThe document hash
processing_statusSee Statuses
reporting_deadlineUTC time by which ZATCA must have the report
errorsPresent when validation failed or ZATCA rejected the document

$result->httpStatus is 201 for a new invoice, 200 for a repeated request, 422 for invalid data.

Printing the receipt ​

  • Print the QR code from qr (it already contains seller name, VAT number, time, totals, hash and signature as required by ZATCA).
  • The signed XML is stored by the package. You do not need to give the XML to a consumer.

Reporting modes ​

ZATCA_B2C_REPORTING_MODEBehaviourWhen to use
queue (default)Returns right after signing; a worker reportsPOS, web shops, any volume
syncAlso reports inside the request; the response contains ZATCA's answerLow volume, when you must show the ZATCA result immediately

In sync mode the response time includes ZATCA's response time (typically several hundred milliseconds or more). A queued safety-net message is still recorded in case the request dies.

After reporting ​

When the worker has the answer, the invoice is updated and an event fires:

ZATCA resultprocessing_statusreporting_statusEvent
ReportedREPORTEDREPORTEDInvoiceAccepted
Reported with warningsREPORTEDREPORTED_WITH_WARNINGSInvoiceAccepted (withWarnings = true)
RejectedREJECTEDNOT_REPORTEDInvoiceRejected
Temporary failureRETRY_PENDINGPENDING(retried automatically)
Attempts exhaustedFAILEDPENDINGInvoiceSubmissionFailed
Authentication refusedMANUAL_REVIEWPENDINGInvoiceSubmissionFailed

Look it up any time:

php
$invoice = \CodingTriplets\Zatca\Laravel\Database\Models\Invoice::where('public_id', $invoiceId)->first();
$invoice->processing_status;   // ProcessingStatus enum
$invoice->reporting_status;

or GET /api/zatca/invoices/{invoice_id} with the HTTP API.

The 24-hour deadline ​

ZATCA requires simplified invoices to be reported within 24 hours of issuance. The package:

  • retries temporary failures on a schedule compressed to finish before the deadline;
  • fires InvoiceReportingDeadlineAtRisk when an invoice is still unreported 4 hours and 1 hour before the deadline (configurable: zatca.b2c.deadline_alert_hours);
  • marks the invoice as breached, records a CRITICAL error and fires InvoiceReportingDeadlineBreached if the deadline passes. Reporting continues afterwards.

Repeated requests ​

Sending the same invoice_number (or external_id) again returns the original result with HTTP status 200, including the same counter and QR. If the first request stopped before the document was signed (for example the server crashed), the repeat completes it. A different payload under the same number is refused with DuplicateInvoice (HTTP 409).

Errors you should handle ​

ExceptionWhenHTTP API
DuplicateInvoiceSame number, different payload409
DeviceUnavailableDevice not onboarded, expired, suspended, or not registered for B2C503
InvalidArgumentExceptionMissing device or invoice number422

Validation errors do not throw: status is false and errors lists them.

Not affiliated with or endorsed by ZATCA. Verify regulatory requirements with ZATCA and your tax advisor.