Skip to content

B2B: standard invoices ​

Standard tax invoices (business customers) must be cleared by ZATCA before they are given to the buyer. ZATCA returns the cleared invoice, which carries ZATCA's stamp.

Share only cleared invoices

Do not send a standard invoice to the buyer before its status is CLEARED. Send the cleared XML returned by ZATCA (stored by the package as artifact cleared_xml), not your own signed XML.

Two ways to send ​

MethodWhat happens in your requestUse when
Zatca::b2b()->issue($payload, $options)Validate, sign (counter assigned), queue clearanceYou want the counter and UUID immediately
Zatca::b2b()->submit($payload, $options)Validate and store only; signing and clearance run on the queueBulk / ERP batches; fastest response
php
use CodingTriplets\Zatca\Laravel\Facades\Zatca;

$result = Zatca::b2b()->submit($payload, ['device' => $deviceId]);
$result->toArray();
// {"status": true, "message": "invoice accepted for processing", "invoice_id": "01M6...", "processing_status": "READY_FOR_PROCESSING"}

Options and idempotency are the same as for B2C.

After clearance ​

ZATCA resultprocessing_statusclearance_statusEvent
ClearedCLEAREDCLEAREDInvoiceAccepted
Cleared with warningsCLEAREDCLEARED_WITH_WARNINGSInvoiceAccepted
Not clearedREJECTEDNOT_CLEAREDInvoiceRejected
Clearance switched off (HTTP 303)QUEUED → REPORTEDCLEARANCE_DEACTIVATEDClearanceDeactivated
Temporary failureRETRY_PENDINGPENDING(retried automatically)

Getting the cleared invoice ​

php
use CodingTriplets\Zatca\Core\Domain\Enums\ArtifactKind;
use CodingTriplets\Zatca\Laravel\Database\Models\InvoiceArtifact;
use CodingTriplets\Zatca\Laravel\Storage\InvoiceArtifacts;

$artifact = InvoiceArtifact::where('issuance_id', $invoice->current_issuance_id)
    ->where('kind', ArtifactKind::ClearedXml)->firstOrFail();

$xml = app(InvoiceArtifacts::class)->contents($artifact);

This works wherever the XML is kept (in the database by default, or on a disk with ZATCA_ARTIFACT_DRIVER=filesystem). The SHA-256 is checked on every read; modified content raises an error instead of being returned.

A convenient place to deliver the invoice is a listener on InvoiceAccepted:

php
Event::listen(InvoiceAccepted::class, function (InvoiceAccepted $e) {
    if ($e->workflow === 'b2b') {
        SendClearedInvoiceToBuyer::dispatch($e->invoiceId);
    }
});

Clearance switched off (303) ​

ZATCA can temporarily switch clearance off and answer HTTP 303. By default (zatca.b2b.on_clearance_deactivated = report) the package then sends the same signed document to the reporting API, and the invoice ends as REPORTED with clearance_status = CLEARANCE_DEACTIVATED. Set it to manual_review to park such invoices until an operator retries them.

INFO

This behaviour follows ZATCA's API description of the 303 answer; it has not been observed live yet (the sandbox does not switch clearance off).

Buyer requirements ​

See Invoice payload → Buyer. In short: name, Saudi address, and a VAT number or another ID. Export invoices (subtype.export = true) must not contain a buyer VAT number.

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