1. Go to this page and download the library: Download saleh7/php-zatca-xml library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
saleh7 / php-zatca-xml example snippets
use Saleh7\Zatca\CertificateBuilder;
(new CertificateBuilder)
->setOrganizationIdentifier('3XXXXXXXXXXXXX3') // 15-digit VAT number
->setSerialNumber('ERP', '1.0', 'unique-device-uuid')
->setCommonName('ERP-886431145-3XXXXXXXXXXXXX3')
->setCountryName('SA')
->setOrganizationName('Your Company Name') // Arabic supported
->setOrganizationalUnitName('Branch Name')
->setAddress('RRRD2929')
->setInvoiceType('1100') // Standard + Simplified
->setEnvironment(CertificateBuilder::ENV_PRODUCTION)
->setBusinessCategory('Supply activities')
->generateAndSave('output/certificate.csr', 'output/private.pem');
use Saleh7\Zatca\ZatcaAPI;
$api = new ZatcaAPI('production'); // or 'sandbox', 'simulation'
$csr = file_get_contents('output/certificate.csr');
$result = $api->requestComplianceCertificate($csr, $otp);
$api->saveToJson(
$result->getCertificate(),
$result->getSecret(),
$result->getRequestId(),
'output/compliance_credentials.json'
);