sevaske/zatca

Zatca laravel library

Fund package maintenance!
sevaske

v1.0.0-alpha 2025-07-21 17:52 UTC

This package is auto-updated.

Last update: 2025-07-25 15:25:42 UTC


README

Latest Version on Packagist Total Downloads

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:

✨ 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