Download the PHP package corecave/laravel-zatca without Composer
On this page you can find all versions of the php package corecave/laravel-zatca. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download corecave/laravel-zatca
More information about corecave/laravel-zatca
Files in corecave/laravel-zatca
Package laravel-zatca
Short Description Laravel package for ZATCA e-invoicing integration (Saudi Arabia Phase 2)
License MIT
Informations about the package laravel-zatca
Laravel ZATCA
A comprehensive Laravel package for integrating with Saudi Arabia's ZATCA (Zakat, Tax and Customs Authority) e-invoicing system (FATOORA platform).
Features
- CSR generation and certificate management
- Invoice XML generation (UBL 2.1 compliant)
- Digital signing with ECDSA (secp256k1)
- QR code generation (TLV format with 9 tags)
- QR code image generation (PNG/SVG) for invoices
- Invoice reporting (B2C simplified invoices)
- Invoice clearance (B2B standard invoices)
- Credit and debit note handling
- Hash chain management (ICV & PIH)
- Sandbox, simulation, and production environments
Requirements
- PHP 8.1+
- Laravel 10.x, 11.x, or 12.x
- OpenSSL extension
- GMP extension (recommended for better performance)
simplesoftwareio/simple-qrcode(optional, for QR code image generation)
Installation
Publish the configuration file:
Run the migrations:
Optional: QR Code Image Generation
To generate QR code images (PNG/SVG) for embedding in emails or PDFs:
Configuration
Add these environment variables to your .env file:
Understanding ZATCA Environments
| Environment | Portal | API Endpoint | Purpose |
|---|---|---|---|
sandbox |
Developer Portal | /developer-portal |
Basic development testing with mock certificates |
simulation |
Simulation Portal | /simulation |
Real testing with ZATCA - invoices are validated but not recorded |
production |
FATOORA Portal | /core |
Live production - invoices are legally binding |
Important Notes:
- Sandbox uses mock certificates that won't pass ZATCA validators - only for initial development
- Simulation uses real ZATCA certificates but invoices aren't recorded - use for integration testing
- Production is live - every invoice submitted is legally binding
Complete Onboarding Process
Overview
The onboarding process involves 4 steps:
- Generate CSR - Create a Certificate Signing Request
- Get Compliance CSID - Submit CSR with OTP to get a compliance certificate
- Pass Compliance Checks - Submit sample invoices for validation
- Get Production CSID - Exchange compliance certificate for production certificate
Step 1: Generate CSR
This generates:
- A private key (stored securely)
- A CSR file for submission to ZATCA
Step 2: Get Compliance CSID & Run Compliance Checks
-
Log in to the appropriate ZATCA portal:
- Simulation: https://fatoora.zatca.gov.sa/ (simulation section)
- Production: https://fatoora.zatca.gov.sa/ (production section)
-
Navigate to your EGS (e-Invoice Generation Solution) unit
-
Generate a new OTP (One-Time Password)
- Run the compliance command within 1 hour (OTP expires):
Step 3: Get Production CSID
After ALL compliance checks pass, request your production certificate:
Important:
- This command does NOT require a new OTP
- It uses your compliance certificate to authenticate
- The compliance request ID is used to verify you passed compliance
- Only works if you completed Step 2 successfully
Step 4: Start Issuing Invoices
Once you have a production certificate, you can start issuing legally-binding invoices:
Full Usage Example
Here's a complete example from building an invoice to submitting it:
VAT Number & Registration Number Formats
VAT Number (15 digits)
Format: 3XXXXXXXXXX0003
| Position | Value | Description |
|---|---|---|
| 1 | 3 |
Always 3 (country code for Saudi Arabia) |
| 2-11 | XXXXXXXXXX |
Your 10-digit Commercial Registration Number |
| 12-15 | 0003 |
Fixed suffix |
Example: If your CR is 1234567890, your VAT number is 312345678900003
Commercial Registration Number (10 digits)
This is your company's official registration number from the Ministry of Commerce.
Example: 1234567890
Buyer Identification Schemes
When specifying buyer information for B2B invoices, use the appropriate scheme:
| Scheme ID | Description | Format |
|---|---|---|
CRN |
Commercial Registration Number | 10 digits |
MOM |
Momra License | Variable |
MLS |
MLSD License | Variable |
SAG |
Sagia License | Variable |
NAT |
National ID | 10 digits |
GCC |
GCC ID | Variable |
IQA |
Iqama Number | 10 digits |
TIN |
Tax Identification Number (VAT) | 15 digits |
700 |
700 Number | Variable |
OTH |
Other ID | Variable |
Creating Credit Notes (Refunds)
QR Code Image Generation
Generate QR code images for receipts, emails, or PDFs:
Note: Requires simplesoftwareio/simple-qrcode package.
Artisan Commands
Generate CSR
Run Compliance Process
Get Production CSID
Renew Production Certificate
Cleanup Utility
Debugging
Enable debug mode to save XML files for inspection:
Debug files are saved to storage/app/zatca/debug/:
{invoice}_unsigned.xml- XML before signing{invoice}_signed.xml- XML after signing{invoice}_hash.txt- Invoice hash{invoice}_qr.txt- QR code TLV data
Error Handling
Common ZATCA Validation Errors
| Error Code | Message | Solution |
|---|---|---|
BR-KSA-F-13 |
Invalid Seller/Buyer ID | Check VAT number format (15 digits: 3XXXXXXXXXX0003) |
BR-KSA-63 |
Missing buyer address fields | Include all required fields for SA buyers |
BR-KSA-18 |
Invalid building number | Building number must be exactly 4 digits |
BR-KSA-64 |
Invalid additional number | Additional number must be exactly 4 digits |
X509IssuerName |
Wrong certificate issuer | Use simulation/production environment, not sandbox |
Invalid-CSR |
CSR is invalid | Regenerate CSR with correct configuration |
Events
The package dispatches events you can listen to:
Changelog
v1.2.0 (2024-12-16)
Added
- QR code image generation (
qr_code_imageandqr_code_svgattributes) - Optional dependency on
simplesoftwareio/simple-qrcode
v1.1.0 (2024-12-13)
Fixed
- X509IssuerName format matching ZATCA SDK
- SignedProperties hash computation
- Buyer PartyIdentification with proper schemeID
- SA buyer address fields (BuildingNumber, District, etc.)
Added
- Compliance check command with sample invoice generation
- Certificate cleanup command
- Automatic schemeID detection
v1.0.0 (2024-12-12)
- Initial release with full Phase 2 support
License
MIT License. See LICENSE for more information.
Resources
All versions of laravel-zatca with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
phpseclib/phpseclib Version ^3.0
robrichards/xmlseclibs Version ^3.1
sabre/xml Version ^4.0
guzzlehttp/guzzle Version ^7.0