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.
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 and manage certificates easily.
⚠️ Note: This is an unofficial library and not maintained by ZATCA. I do not provide personal support or consulting.
If you’re looking for a library to generate XML invoices, you can use this one: https://github.com/sevaske/php-zatca-xml
Features
- Full coverage of ZATCA API endpoints (reporting, clearance, compliance)
- Authentication via certificate and secret or auth token
- Supports middleware for request/response processing
- Typed response objects for easy validation and error handling
- Supports multiple environments: sandbox, simulation, production
- Follows PSR standards (PSR-4, PSR-7, PSR-17, PSR-18)
- Works with any PSR-18 compatible HTTP client (e.g., Guzzle)
Environments
| Environment | Purpose | Certificates |
|---|---|---|
| sandbox | CSR + basic testing | Sandbox certificate |
| simulation | Compliance invoices (6 required) | Compliance cert |
| production | Real invoices | Production cert |
Invoice types
-
Reporting (B2P)
Used for invoices issued to consumers. - Clearance (B2B)
Used for invoices issued to VAT-registered businesses.
Authentication flow
- Generate CSR (outside this library)
- Request compliance certificate
- Create
ZatcaAuthfrom certificate + secret - Submit simulation invoices
- Request production certificate
- Switch client to
productionenvironment
Immutability
Methods like withEnvironment() and withMiddleware() return a new client instance.
The original client is not modified.
Installation
Usage
Client Initialization
Create HTTP client and factories for PSR-17 / PSR-18. For example, GuzzleHttp
Compliance Certificate Request
Authorized requests
Create AuthToken from compliance certificate to make authorized requests.
Submitting Invoices
Once you have a valid compliance certificate and auth token, you can submit invoices in the simulation environment.
Submitting 6 documents is required to switch to production mode.
Production Onboarding
After submitting the required simulation invoices, you can request a production certificate.
This certificate allows you to submit real invoices in the production environment.
Submitting Production Invoices
Once the client is configured with the production certificate and environment, you can submit real invoices to ZATCA.
Middleware
Middleware in ZatcaClient allows you to inspect, modify, or wrap HTTP requests and responses. It works as a pipeline, meaning that multiple middleware can be chained together, each receiving the request and a $next callable that continues to the next middleware and ultimately to the HTTP client.
ZatcaClient provides four ways to manage middleware:
withMiddleware($middleware)– returns a new cloned instance with the provided middleware. Existing middleware in the original client is replaced in the clone.setMiddleware($middleware)– mutates the current instance, replacing its middleware with the given ones.attachMiddleware($middleware)– mutates the current instance, adding the given middleware to the end of the existing middleware stack.withoutMiddleware()- returns a new cloned instance with no middleware attached.
All middleware must implement the MiddlewareInterface:
Example
For example, implementation of "logging" requests and responses:
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
All versions of zatca-api with dependencies
ext-json Version *
psr/http-client Version ^1.0
psr/http-message Version ^1.0||^2.0
sevaske/support Version ^1.0