Download the PHP package sevaske/zatca-api without Composer
On this page you can find all versions of the php package sevaske/zatca-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sevaske/zatca-api
More information about sevaske/zatca-api
Files in sevaske/zatca-api
Package zatca-api
Short Description Framework-agnostic PHP client for the ZATCA (Fatoora) e-invoicing API of Saudi Arabia: CSID onboarding and renewal, compliance checks, reporting and clearance, PSR-18 compatible.
License MIT
Homepage https://github.com/sevaske/zatca-api
Informations about the package zatca-api
ZATCA API PHP Client
This is a simple PHP library to work with the ZATCA API. You can send invoice data, check invoice status, verify compliance, and manage certificates easily.
If you’re looking for a library to generate XML invoices, you can use this one: https://github.com/sevaske/php-zatca-xml
Features
- Supports all major ZATCA API endpoints
- Simple authentication with certificate and secret
- Response handling via typed response objects
- Environment support: sandbox, simulation, production
- Uses any PSR-18 compatible HTTP client (e.g., Guzzle). Clients other than Guzzle need
guzzlehttp/psr7ornyholm/psr7installed to build requests
Installation
Quick Start
Available Methods
| Method | Description |
|---|---|
reporting() |
Submit invoice data to ZATCA |
clearance() |
Request invoice clearance status |
compliance() |
Verify invoice compliance |
complianceCertificate() |
Request compliance certificate |
productionCertificate() |
Obtain production certificate |
renewProductionCertificate() |
Renew production certificate |
Notes
$invoiceHashmay benullforreporting(),clearance()andcompliance(): the hash is then taken from the signature of the signed invoice (the digest of theinvoiceSignedDatareference).- Every response has
statusCode()(the HTTP status) andsuccess(). - If your HTTP client does not throw on HTTP errors (e.g. Guzzle with
http_errors => falseor a pure PSR-18 client), responses like 401 or 500 are returned as response objects: always checksuccess().
Exception handling
The library throws the following exceptions which you can catch and handle:
ZatcaException— general exception classZatcaRequestException— errors during the HTTP requestZatcaResponseException— errors processing the API response
When ZATCA answers with an HTTP error (e.g. a rejected invoice), the exception context contains the answer:
status, content, response and errors are present only when the HTTP client provides the error response
(Guzzle does); response and errors only when the body is JSON.
Renewing the production certificate
Renewal is authorized by the current production certificate and requires an OTP from the Fatoora portal and a new CSR.
Security
- The certificate secret is a credential: store it encrypted or in a secret manager, never in a public directory or in git.
The
file_put_contents()calls in the example above only illustrate the flow. - Do not disable TLS verification in the HTTP client.
- Exceptions keep the original HTTP client exception as
getPrevious(); it may reference the request including theAuthorizationheader, so do not dump it to logs.
All versions of zatca-api with dependencies
ext-dom Version *
ext-json Version *
php-http/discovery Version ^1.15
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0 || ^2.0