Skip to content

PHP API ​

Everything is reachable through the Zatca facade (CodingTriplets\Zatca\Laravel\Facades\Zatca).

Issuing — Zatca::b2c() / Zatca::b2b() ​

Both return an InvoiceIssuer bound to one workflow. A B2C issuer never accepts B2B data and vice versa.

MethodReturnsDescription
issue(array $payload, array $options = [])IssueResultValidate, sign, queue submission
submit(array $payload, array $options = [])IssueResultValidate and store; signing and submission on the queue (intended for B2B)
validate(array $payload, array $options = [])ValidationResultValidation only; nothing stored
submitNow(string $invoiceId)stringSubmit a queued invoice inside this call; returns the submission status

Options

KeyDescription
deviceDevice ID or UUID (required)
external_idIdempotency key (default: invoice_number)
actor_idUser ID recorded in the history
sourceYour own record: an Eloquent model or ['type' => …, 'id' => …] (details)

IssueResult ​

Property / methodDescription
toArray()The JSON contract: status, message, qr, counter, uuid, invoice_id, invoice_hash, processing_status, reporting_deadline, errors
httpStatusSuggested HTTP status (201, 200, 422)

Operations — Zatca::invoices() ​

$invoice is the invoice_id (string) or an Invoice model.

MethodReturnsDescription
retry($invoice, ?int $actorId = null, bool $now = false)stringResend the identical document
correct($invoice, array $payload, string $reason, ?int $actorId = null)IssueResultNew version + new issuance
reissueUnchanged($invoice, string $reason, ?int $actorId = null)IssueResultNew issuance from the current JSON
approve($invoice, int $approverId)IssueResultApprove a held correction
creditNote($original, array $payload, string $reason, ?int $actorId = null, array $options = [])IssueResultCredit note (381)
debitNote($original, array $payload, string $reason, ?int $actorId = null, array $options = [])IssueResultDebit note (383)
cancel($original, string $reason, ?int $actorId = null, array $options = [])IssueResultFull credit note for an accepted invoice
discard($invoice, string $reason, ?int $actorId = null)InvoiceClose an invoice that was never signed (CANCELLED)
abandon($invoice, string $reason, ?int $actorId = null)InvoiceClose a rejected invoice (ABANDONED) ⚠

Companies — Zatca::companies() ​

MethodReturnsDescription
create(array $data, ?int $actorId = null)CompanyCompany + VAT registration (+ stores), idempotent by external_ref / VAT number
createStore($company, array $data)BranchStore (code, name, address?, external_ref?), idempotent
resolveCompany($id, string $ids = 'auto')CompanyBy external_ref or package ID
resolveStore(Company $company, $id, string $ids = 'auto')BranchBy external_ref, code or package ID

Devices — Zatca::devices() ​

MethodReturnsDescription
register(array $row, ?int $actorId = null, array $options = [])DeviceOne device
registerMany(iterable $rows, array $options = [])DeviceImportReportMany devices (onboards rows with otp)
import(string|array $file, array $options = [])DeviceImportReportFrom a CSV/XLSX path or ['disk', 'path']
validateMany(iterable|string|array $rows, array $options = [])DeviceImportReportCheck only
onboard($device, string $otp, ?int $actorId = null)DeviceOnboardingOne device
onboardMany(iterable $items, ?int $actorId = null)DeviceImportReport[['device' => …, 'otp' => …], …]
resume($device, ?int $actorId = null)DeviceOnboardingContinue after compliance checks

Options: ids (auto | external | package), onboard (default true), actor_id. See Devices from code and Excel.

Dashboard authorization — Zatca::auth() ​

php
Zatca::auth(fn ($user, string $ability, $subject = null): bool => …);

Decides every dashboard permission (zatca.*); $subject is the invoice for invoice pages and actions. See Dashboard.

Exceptions ​

ExceptionNamespaceWhen
DuplicateInvoiceLaravel\InvoicesSame idempotency key, different payload (->publicId)
DeviceUnavailableLaravel\InvoicesDevice cannot issue for this workflow
OperationNotAllowedLaravel\InvoicesOperation does not fit the invoice's state
InvoiceValidationExceptionCore\Invoice\Shared\ValidationInvalid correction (->result)

Models ​

CodingTriplets\Zatca\Laravel\Database\Models\: Invoice, InvoiceVersion, InvoiceIssuance, InvoiceArtifact, InvoiceLine, InvoiceVatBreakdown, Device, Certificate, VatRegistration, ZatcaError, Warning, … Read them freely; do not write counters, issuances or chain entries yourself.

Other ​

MethodDescription
Zatca::version()Package version
Zatca::defaultEnvironment()Environment enum from the configuration
DeviceOnboardingService::onboard($device, $otp, actorId:)Onboarding from code
CertificateRenewalServiceRenewal from code

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