Download the PHP package thesmarter/zatca without Composer

On this page you can find all versions of the php package thesmarter/zatca. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package zatca

English | العربية

# 🧾 ZATCA E-Invoicing Phase 2 ### PHP Package for Saudi Arabia's ZATCA (Fatoora) Integration Simplifies Phase 2 e-invoicing requirements including certificate generation, invoice signing, QR code generation, and submission to ZATCA's API [![Latest Version](https://img.shields.io/packagist/v/thesmarter/zatca?style=flat-square)](https://packagist.org/packages/thesmarter/zatca) [![License](https://img.shields.io/packagist/l/thesmarter/zatca?style=flat-square)](LICENSE) [![PHP Version](https://img.shields.io/packagist/php-v/thesmarter/zatca?style=flat-square)](composer.json) [![Tests](https://github.com/thesmarter/zatca/actions/workflows/tests.yml/badge.svg)](https://github.com/thesmarter/zatca/actions) **Developed with ❤️ by [Smart Team](https://smart.sd)** [View Examples](https://github.com/thesmarter/zatca/tree/main/examples) • [Report a Bug](https://github.com/thesmarter/zatca/issues) ---

Table of Contents

Features

Requirements

Installation

Install the package via Composer:

Quick Start

1. Generate Certificate Signing Request (CSR)

First, generate a CSR and private key for your organization:

2. Request Compliance Certificate

Obtain a compliance certificate from ZATCA using your CSR and OTP:

3. Hash Invoice XML

Hash your unsigned invoice XML:

4. Sign Invoice

Sign the invoice with your private key and compliance certificate:

5. Check Compliance

Validate your signed invoice against ZATCA's compliance checks:

6. Generate Production Certificate

After successful compliance validation, request a production certificate:

7. Submit Invoice to ZATCA

Submit your signed invoice to ZATCA (Reporting for simplified, Clearance for standard):

Environment Configuration

The package supports three ZATCA environments:

Using the Facade (Alternative Approach)

The Zatca facade provides a cleaner, more convenient API for accessing all services. Instead of manually instantiating services and their dependencies, you can use the facade as a single entry point.

Benefits of Using the Facade

Facade Example: Complete Workflow

Facade API Methods

The Zatca facade provides the following methods:

Comparison: Traditional vs Facade

Traditional Approach:

Facade Approach:

The facade handles all dependency injection automatically, making your code cleaner and easier to maintain.

Invoice Types

When generating CSR, specify the invoice type using a 4-digit code:

Each digit acts as a boolean flag: [Standard, Simplified, Future Use, Future Use]

API Reference

Core Services

CertificateSigningRequestBuilder

Generates CSR and private key for ZATCA onboarding.

Methods:

ComplianceService

Handles compliance certificate requests and validation.

Methods:

InvoiceHashingService

Hashes invoice XML according to ZATCA specifications.

Methods:

InvoiceSigningService

Signs invoices with digital signature and generates QR codes.

Methods:

QrCodeGeneratorService

Generates ZATCA-compliant QR codes.

Methods:

ProductionCsidGeneratorService

Requests production certificates after compliance validation, and renews them when needed.

Methods:

InvoiceSubmissionService

Submits invoices to ZATCA via Reporting or Clearance APIs.

Methods:

InvoiceBuilder

Builds UBL 2.1 invoice XML (unsigned) from plain PHP arrays, with automatic totals and VAT grouping.

Methods:

Entities

CSID

Represents a Certificate Signing ID (compliance or production certificate).

Properties:

Methods:

InvoiceHashingResult

Result of invoice hashing operation.

Properties:

InvoiceSigningResult

Result of invoice signing operation.

Properties:

SubmissionResponse

Response from invoice submission to ZATCA.

Properties:

ValidationResponse

Response from compliance validation.

Properties:

ValidationResults

Validation messages from ZATCA.

Properties:

Build UBL Invoices From Arrays

Supports invoice (388), credit (383) and debit (381) via 'type' => .... The builder emits the unsigned invoice (no UBLExtensions/QR/signature); feed it to the hashing service, then InvoiceSigningService::sign(), which inserts the fragments with namespace-aware DOM handling.

Renew a Production Certificate

Examples

Complete working examples are available in the examples/ directory:

  1. 0_using_facade.php - Using the Zatca Facade (Recommended)
  2. 1_generate_csr.php - Generate CSR and private key
  3. 2_generate_compliance_csid.php - Request compliance certificate
  4. 3_hash_invoice_xml.php - Hash invoice XML
  5. 4_generate_qr_code_xml.php - Generate QR code
  6. 5_sign_invoice_xml.php - Sign invoice
  7. 6_check_compliance.php - Validate compliance
  8. 7_generate_production_csid.php - Request production certificate
  9. 8_build_ubl_invoice.php - Build a UBL invoice from PHP arrays
  10. 9_renew_production_csid.php - Renew a production certificate

Testing

Run the test suite:

Or use PHPUnit directly:

Error Handling

The package throws specific exceptions for different error scenarios:

Best Practices

  1. Store Certificates Securely: Keep your private keys and certificates in secure storage
  2. Use Environment Variables: Store sensitive data like OTPs and secrets in environment variables
  3. Validate Before Submission: Always check compliance before submitting to production
  4. Handle Errors Gracefully: Implement proper error handling and logging
  5. Test in Sandbox: Thoroughly test your integration in the sandbox environment
  6. Keep Certificates Updated: Monitor certificate expiration and renew as needed

ZATCA Integration Workflow

Resources

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This package is open-sourced software licensed under the MIT License.

Credits

Developed and maintained by Smart Team — eltayeb and CoderX249.

Support

For issues, questions, or contributions, please visit the GitHub repository.


Disclaimer: This is an unofficial package and is not affiliated with or endorsed by ZATCA. Use at your own risk and ensure compliance with all ZATCA regulations.


All versions of zatca with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-openssl Version *
guzzlehttp/guzzle Version ^7.2
ext-dom Version *
ext-xsl Version *
ext-json Version *
ext-bcmath Version *
ext-simplexml Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package thesmarter/zatca contains the following files

Loading the files please wait ...