sevaske / zatca
Zatca laravel library
Fund package maintenance!
sevaske
Requires
- php: ^8.1
- illuminate/contracts: ^10.0||^11.0||^12.0
- sevaske/php-zatca-xml: ^3.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- guzzlehttp/guzzle: ^7.9
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^v2.36.0||^v3.0
- pestphp/pest-plugin-laravel: ^v2.4.0||^v3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
This package is auto-updated.
Last update: 2025-07-25 15:25:42 UTC
README
Zatca is a Laravel package that integrates with the ZATCA e-invoicing system, wrapping the php-zatca-xml core for certificate generation, XML invoice signing, and submission to the ZATCA API β all the Laravel way.
π§± Under the Hood
This package is a Laravel wrapper around:
- sevaske/php-zatca-xml β core logic for XML building and signing
- sevaske/zatca-api β ZATCA API client
β¨ Features
- π§Ύ Generate and sign e-invoices (XML + QR)
- π Manage CSRs, private keys, credentials
- π Sandbox, simulation & production environments
- π Uses Laravel's filesystem to store certs and invoices
- βοΈ Laravel service provider, config, macros and bindings
- π¦ Clean and extendable codebase
π¦ Installation
Install via Composer:
composer require sevaske/zatca:dev-master
Install
php artisan zatca:install
βοΈ Configuration
return [ 'env' => env('ZATCA_ENV', 'sandbox'), 'storage' => [ 'credentials_disk' => env('ZATCA_CREDENTIALS_DISK', env('FILESYSTEM_DISK', 'local')), 'invoices_disk' => env('ZATCA_INVOICES_DISK', env('FILESYSTEM_DISK', 'local')), 'paths' => [ 'invoices' => env('ZATCA_INVOICES_FOLDER_PATH', 'zatca/invoices'), 'csr' => env('ZATCA_CSR_PATH', 'zatca/certificate.csr'), 'private_key' => env('ZATCA_PRIVATE_KEY_PATH', 'zatca/private_key.pem'), 'compliance_credentials' => env('ZATCA_COMPLIANCE_CREDENTIALS_PATH', 'zatca/compliance_credentials.json'), 'production_credentials' => env('ZATCA_PRODUCTION_CREDENTIALS_PATH', 'zatca/production_credentials.json'), ], ], ];
β Usage
Available commands
php artisan zatca:generate-csr php artisan zatca:compliance-certificate
XML Generation and Signing
This library uses php-zatca-xml for generating and signing XML files.
More details: https://github.com/sevaske/php-zatca-xml
API Methods
The \Zatca::api()
method is a wrapper around the sevaske/zatca-api package, providing a simplified interface for interacting with ZATCA services:
use Illuminate\Support\Str; // Reporting Invoice \Zatca::api()->reporting('signed xml', 'hash', Str::uuid()); // Clearance Invoice \Zatca::api()->clearance('signed xml', 'hash', Str::uuid()); // Compliance Check \Zatca::api()->compliance('signed xml', 'hash', Str::uuid()); // Compliance Certificate Request \Zatca::api()->complianceCertificate('csr', 'otp'); // Production Certificate Request \Zatca::api()->productionCertificate('complianceRequestId');
More details: https://github.com/sevaske/zatca-api
File Access Helpers
The \Zatca::files()
method provides access to stored production credentials:
// Get the production certificate \Zatca::files()->productionCredentials()->certificate(); // Get the secret associated with the certificate \Zatca::files()->productionCredentials()->secret(); // Get the request ID used for the certificate \Zatca::files()->productionCredentials()->requestId();
π HTTP Macro
use Illuminate\Support\Facades\Http; Http::zatca(); // \Sevaske\ZatcaApi\Api
π§© Zatca Macro
The main Zatca
class uses Laravelβs Macroable
trait, allowing you to define your own methods at runtime:
use Sevaske\Zatca\Facades\Zatca; Zatca::macro('hello', function () { return 'π Hello from macro!'; }); Zatca::hello(); // "π Hello from macro!"
You can register macros in a service provider or any bootstrap code (like AppServiceProvider
).
π§ͺ Testing
composer test
π Changelog
See CHANGELOG.md for recent changes.
β License
MIT. See LICENSE for details.
π Credits
Made by Sevaske