ahmedabdelnaby/zatca-tools
Composer 安装命令:
composer require ahmedabdelnaby/zatca-tools
包简介
A helper to generate the QR code and signed it for ZATCA e-invoicing
关键字:
README 文档
README
🧾 ZATCA (Fatoora) QR-Code & Invoice Signing
A PHP library to generate QR codes and sign invoices for ZATCA e-invoicing compliance in Saudi Arabia.
🐛 Report Bug ·
✨ Request Feature
✅ Requirements
- 🐘 PHP >= 8.0
- 🔡
mbstringextension - 📜
ext-domextension
📦 Installation
Install the package via Composer:
composer require ahmedabdelnaby/zatca-tools
🚀 Usage
This package supports both Phase 1 and Phase 2 of ZATCA compliance.
- Phase 1: 🔲 QR code generation.
- Phase 2: ✍️ Invoice signing & 🏢 System integration with ZATCA.
1️⃣ Generating CSR (Certificate Signing Request)
Before signing invoices, you need to generate a CSR and register your merchant in ZATCA APIs.
use ZATCA\Tools\GenerateCSR; use ZATCA\Tools\Models\CSRRequest; $data = CSRRequest::make() ->setUID('string $OrganizationIdentifier') ->setSerialNumber('string $solutionName', 'string $version', 'string $serialNumber') ->setCommonName('string $commonName') ->setCountryName('SA') ->setOrganizationName('string $organizationName') ->setOrganizationalUnitName('string $organizationalUnitName') ->setRegisteredAddress('string $registeredAddress') ->setInvoiceType(true, true) // invoice types, default is true, true ->setCurrentZatcaEnv('sandbox') // Supports ['sandbox', 'simulation', 'core'] ->setBusinessCategory('string $businessCategory'); $CSR = GenerateCSR::fromRequest($data)->initialize()->generate(); // Save 🔑 private key openssl_pkey_export_to_file($CSR->getPrivateKey(), 'private-key.pem'); // Save 📝 CSR content file_put_contents('csr.pem', $CSR->getCsrContent());
🔹 Now, submit the CSR to ZATCA APIs to receive your certificate.
2️⃣ Signing Invoices & Generating QR Code
After receiving a certificate from ZATCA, you can sign invoices and generate QR codes.
use ZATCA\Tools\Helpers\Certificate; use ZATCA\Tools\Models\InvoiceSign; $xmlInvoice = 'xml invoice text'; $certificate = (new Certificate( 'certificate plain text (base64 decoded)', // 📜 Get from ZATCA 'private key plain text' // 🔑 Generated in CSR step ))->setSecretKey('🔒 secret key text'); // 🔑 Get from ZATCA $invoice = (new InvoiceSign($xmlInvoice, $certificate))->sign(); // Get invoice details 📄 $invoice->getHash(); // 🏷️ Invoice Hash $invoice->getInvoice(); // 📝 Signed XML Invoice $invoice->getQRCode(); // 🔲 QR Code in Base64 format
3️⃣ Generating QR Code from Invoice Data
use ZATCA\Tools\GenerateQrCode; use ZATCA\Tools\Helpers\UXML; use ZATCA\Tools\Helpers\Certificate; $xmlInvoice = 'xml invoice text'; $certificate = (new Certificate( 'certificate plain text (base64 decoded)', 'private key plain text' ))->setSecretKey('secret key text'); $tags = UXML::fromString($xmlInvoice)->toTagsArray($certificate); $QRCodeAsBase64 = GenerateQrCode::fromArray($tags)->toBase64();
4️⃣ Generating Basic QR Code (Phase 1)
use ZATCA\Tools\GenerateQrCode; use ZATCA\Tools\Tags\InvoiceDate; use ZATCA\Tools\Tags\InvoiceTaxAmount; use ZATCA\Tools\Tags\InvoiceTotalAmount; use ZATCA\Tools\Tags\Seller; use ZATCA\Tools\Tags\TaxNumber; $generatedString = GenerateQrCode::fromArray([ new Seller('Company Name'), new TaxNumber('1234567891'), new InvoiceDate('2024-02-17T14:25:09Z'), new InvoiceTotalAmount('500.00'), new InvoiceTaxAmount('75.00') ])->toBase64();
5️⃣ Display QR Code in HTML
$displayQRCodeAsBase64 = GenerateQrCode::fromArray([ new Seller('Company Name'), new TaxNumber('1234567891'), new InvoiceDate('2024-02-17T14:25:09Z'), new InvoiceTotalAmount('500.00'), new InvoiceTaxAmount('75.00') ])->render();
Now, use it in an <img> tag:
<img src="<?php echo $displayQRCodeAsBase64; ?>" alt="Invoice QR Code" />
🔎 Reading the QR Code
The QR code follows ZATCA's TLV format, making it unreadable by normal scanners.
To check your QR code, use this online scanner:
🔗 📸 Online QR Code Reader
🧪 Running Tests
Run the tests using:
composer test
🔒 Security
If you discover security vulnerabilities, please do not open an issue. Instead, email:
📧 ahmedabdelnabyfahmy1@gmail.com
ahmedabdelnaby/zatca-tools 适用场景与选型建议
ahmedabdelnaby/zatca-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.87k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「qr-code」 「e-invoicing」 「ZATCA」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ahmedabdelnaby/zatca-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ahmedabdelnaby/zatca-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ahmedabdelnaby/zatca-tools 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
QR Code generator
Based in http://phpqrcode.sourceforge.net/
A clean, modern, and easy-to-use QR code generator for Laravel
An unofficial PHP library for generating ZATCA Fatoora e-invoices. This library facilitates the creation of compliant e-invoices, QR Codes, and certificates, as well as the submission of e-invoices to ZATCA's servers. It provides developers with an easy-to-use, customizable, and robust toolkit to in
Laravel package for ZATCA e-invoicing integration (Saudi Arabia Phase 2)
Laravel helper to generate the QRcode for ZATCA E-Invoicing system
统计信息
- 总下载量: 1.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-17