PHPackages                             mohammadzat/zatca - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mohammadzat/zatca

ActiveLibrary[API Development](/categories/api)

mohammadzat/zatca
=================

provides zatca phase 2

111984[1 issues](https://github.com/alyousfy77885/Laravelzatca/issues)[2 PRs](https://github.com/alyousfy77885/Laravelzatca/pulls)PHP

Since Sep 18Pushed 1y ago2 watchersCompare

[ Source](https://github.com/alyousfy77885/Laravelzatca)[ Packagist](https://packagist.org/packages/mohammadzat/zatca)[ RSS](/packages/mohammadzat-zatca/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

This extension for laravel 10
=============================

[](#this-extension-for-laravel-10)

This extension allows you to use zatca phase2 in KSA develope by Eng/Mohammed alyousfy

Installation steps
==================

[](#installation-steps)

### Installation Using Composer (Recommended)

[](#installation-using-composer-recommended)

```
composer require mohammadzat/zatca:"dev-main"

```

### Manual Setup

[](#manual-setup)

- integration examples:

```
 (string)$i,
        'name' => 'TEST NAME ' . $i,
        'quantity' => 10,
        'tax_exclusive_price' => 10,
        'VAT_percent' => 0.15,
        'other_taxes' => [],
        'discounts' => [],
    ];

    $line_items[] = $line_item; // Add the line item to the array
}
$egs_unit = [
    'uuid' => '6f4d20e0-6bfe-4a80-9389-7dabe6620f12',
    'custom_id' => 'EGS1-886431145',
    'model' => 'IOS',
    'CRN_number' => '454634645645654',
    'VAT_name' => 'موسسه تسالى',
    'VAT_number' => '301121971500003',
    'location' => [
        'city' => 'الرياض',
        'city_subdivision' => 'West',
        'street' => 'شارع الملك فهد',
        'plot_identification' => '0000',
        'building' => '0000',
        'postal_zone' => '31952',
    ],
    'branch_name' => 'تسالي',
    'branch_industry' => 'Food',
    'cancelation' => [
        'cancelation_type' => 'INVOICE',
        'canceled_invoice_number' => '',
    ],
];
$invoice = [
    'invoice_counter_number' => 2,
    'invoice_serial_number' => 'EGS1-886431145-1',
    'issue_date' => '2022-03-13',
    'issue_time' => '14:40:40',
    'previous_invoice_hash' => 'NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==', // AdditionalDocumentReference/PIH
    'line_items' => [

    ],
];
for ($i = 0; $i production = false;

// New Keys & CSR for the EGS
/*list($private_key, $csr) = $egs->generateNewKeysAndCSR('Qr');
echo $private_key;

echo */
list($private_key, $csr) = $egs->generateNewKeysAndCSR('Qr');

echo "\n Private Key:\n";
echo $private_key . "\n\n";
     echo "CSR:\n";
echo $csr . "\n\n\n";

// Issue a new compliance cert for the EGS
list($request_id, $binary_security_token, $secret) = $egs->issueComplianceCertificate('123345', $csr);
echo "secret:\n";
echo $secret. "\n";
// Sign invoice
list($signed_invoice_string, $invoice_hash, $qr,$public_key) = $egs->signInvoice($invoice, $egs_unit, $binary_security_token, $private_key);
echo "\n\n public key:\n";
//echo $signed_invoice_string. "\n\n\n";

$base64_encoded = base64_encode($signed_invoice_string);

// Output the Base64 encoded string
echo $base64_encoded;
//$file_path =base_path().'/tmp/invoice.xml';
$file_path = base_path() . '/public/invoice/invoice.xml';

// Check if the file exists
if (!file_exists($file_path)) {
    // Create the directory if it doesn't exist
    if (!is_dir(dirname($file_path))) {
        mkdir(dirname($file_path), 0755, true);
    }

    // Create a new file
    file_put_contents($file_path, '' . PHP_EOL . '');

    echo "File created: $file_path";
} else {
   }
// Save the XML string to the file
if (file_put_contents($file_path, $signed_invoice_string) !== false) {
    echo "Invoice saved successfully to $file_path.\n";
} else {
    echo "Failed to save the invoice.\n";
}

// Generate QR Code
$qrCode = QrCode::create($qr)
    ->setEncoding(new Encoding('UTF-8'))
    ->setErrorCorrectionLevel(ErrorCorrectionLevel::High)
    ->setSize(300)
    ->setMargin(10)
    ->setForegroundColor(new Color(0, 0, 0))
    ->setBackgroundColor(new Color(255, 255, 255));

// Save QR Code to file
$writer = new PngWriter();
$logo = Logo::create(ROOT_PATH. '/ZATCA/assets/logo.png')
    ->setResizeToWidth(50)
    ->setPunchoutBackground(true);

$label = Label::create('Qr Phase-2')
    ->setTextColor(new Color(255, 0, 0));

$result = $writer->write($qrCode, $logo, $label);
$result->saveToFile(ROOT_PATH . '/ZATCA/assets/phase-2.png');

header('Content-Type: ' . $result->getMimeType());
       // return redirect()->route('task.create');
    }
}
```

After running above code
========================

[](#after-running-above-code)

go to public directory and browse folder invoice and upload to Zatca test xml to show compliance results or scan barcode [![IMG_٢٠٢٤٠٩١٩_٠٠٢٩٤١](https://private-user-images.githubusercontent.com/79579059/368745493-7b8302a7-d6c3-4912-8eab-309bfcea5fb4.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU1NTMyMDQsIm5iZiI6MTc3NTU1MjkwNCwicGF0aCI6Ii83OTU3OTA1OS8zNjg3NDU0OTMtN2I4MzAyYTctZDZjMy00OTEyLThlYWItMzA5YmZjZWE1ZmI0LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA3VDA5MDgyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRkYmJlOGY2OTJlN2Q5Nzk0MzM4NmM1ODBmMzRjNTEzNDJiMTg2MjM2MGIwNWFiY2U0NzUxZTliY2VhZGQxNWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.t4ZYRT0W7iGta6KbUDzhWF0xi6pgZTFIpsKhIm--xh8)](https://private-user-images.githubusercontent.com/79579059/368745493-7b8302a7-d6c3-4912-8eab-309bfcea5fb4.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU1NTMyMDQsIm5iZiI6MTc3NTU1MjkwNCwicGF0aCI6Ii83OTU3OTA1OS8zNjg3NDU0OTMtN2I4MzAyYTctZDZjMy00OTEyLThlYWItMzA5YmZjZWE1ZmI0LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA3VDA5MDgyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRkYmJlOGY2OTJlN2Q5Nzk0MzM4NmM1ODBmMzRjNTEzNDJiMTg2MjM2MGIwNWFiY2U0NzUxZTliY2VhZGQxNWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.t4ZYRT0W7iGta6KbUDzhWF0xi6pgZTFIpsKhIm--xh8)

```

   urn:oasis:names:specification:ubl:dsig:enveloped:xades

      urn:oasis:names:specification:ubl:signature:1
      urn:oasis:names:specification:ubl:signature:Invoice

 reporting:1.0
 EGS1-886431145-1
 6f4d20e0-6bfe-4a80-9389-7dabe6620f12
 2024-09-17
 15:06:05
388

 SAR
 SAR

  ICV
  2

  PIH

   NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==

  QR

  urn:oasis:names:specification:ubl:signature:Invoice
  urn:oasis:names:specification:ubl:dsig:enveloped:xades

    454634645645654

    شارع الملك فهد
    0000
    0000
    West
    الرياض
    31952

     SA

    301121971500003

     VAT

    موسسه تسالى

    311111111111113

    شارع الملك فهد
    0000
    0000
    West
    الرياض
    31952

     SA

     VAT

    موسسه تسالى

  2022-03-13

  10

  false
  discount
  0.00

   S
   15

    VAT

        45.00

            100.00
            15.00

                S
                15.00

                    VAT

            100.00
            15.00

                S
                15.00

                    VAT

            100.00
            15.00

                S
                15.00

                    VAT

        45.00

        300.00
        300.00
        345.00
        0
        0
        345.00

        1
        10
        100.00

            15.00
            115.00

            TEST NAME 1

                S
                15.00

                    VAT

            10

        2
        10
        100.00

            15.00
            115.00

            TEST NAME 2

                S
                15.00

                    VAT

            10

        3
        10
        100.00

            15.00
            115.00

            TEST NAME 3

                S
                15.00

                    VAT

            10

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6359e6fff590a352fd324ba2e0ad59a38ea8d87d55c1040e777ec96413ec89a3?d=identicon)[alyousfy77885](/maintainers/alyousfy77885)

---

Top Contributors

[![alyousfy77885](https://avatars.githubusercontent.com/u/79579059?v=4)](https://github.com/alyousfy77885 "alyousfy77885 (11 commits)")

### Embed Badge

![Health badge](/badges/mohammadzat-zatca/health.svg)

```
[![Health](https://phpackages.com/badges/mohammadzat-zatca/health.svg)](https://phpackages.com/packages/mohammadzat-zatca)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M186](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[microsoft/microsoft-graph

The Microsoft Graph SDK for PHP

65723.5M95](/packages/microsoft-microsoft-graph)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
