prgayman/laravel-zatca

Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing

1.0.0 2021-12-12 10:13 UTC

This package is auto-updated.

Last update: 2024-04-13 15:50:45 UTC


README

Introduction

Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing

Installation

To get the latest version of laravel-zatca on your project, require it from "composer":

$ composer require prgayman/laravel-zatca

Or you can add it directly in your composer.json file:

{
  "require": {
    "prgayman/laravel-zatca": "1.0.0"
  }
}

Laravel

Register the provider directly in your app configuration file config/app.php config/app.php:

Laravel >= 5.5 provides package auto-discovery, thanks to rasmuscnielsen and luiztessadri who help to implement this feature in Zatca, the registration of the provider and the facades should not be necessary anymore.

'providers' => [
    Prgayman\Zatca\ZatcaServiceProvider::class,
]

Add the facade aliases in the same file:

'aliases' => [
  'Zatca' => Prgayman\Zatca\Facades\Zatca::class,
]

Lumen

Register the provider in your bootstrap app file boostrap/app.php

Add the following line in the "Register Service Providers" section at the bottom of the file.

$app->register(Prgayman\Zatca\ZatcaServiceProvider::class);

For facades, add the following lines in the section "Create The Application" .

class_alias(\Prgayman\Zatca\Facades\Zatca::class, 'Zatca');

Usage

Generate Base64

use Prgayman\Zatca\Facades\Zatca;

$base64 = Zatca::sellerName('Zatca')
            ->vatRegistrationNumber("123456789123456")
            ->timestamp("2021-12-01T14:00:09Z")
            ->totalWithVat('100.00')
            ->vatTotal('15.00')
            ->toBase64();
// Output
// AQVaYXRjYQIPMTIzNDU2Nzg5MTIzNDU2AxQyMDIxLTEyLTAxVDE0OjAwOjA5WgQGMTAwLjAwBQUxNS4wMA==

Generate Plain

use Prgayman\Zatca\Facades\Zatca;

$tlv = Zatca::sellerName('Zatca')
            ->vatRegistrationNumber("123456789123456")
            ->timestamp("2021-12-01T14:00:09Z")
            ->totalWithVat('100.00')
            ->vatTotal('15.00')
            ->toTLV();

Render A QR Code Image

use Prgayman\Zatca\Facades\Zatca;
use Prgayman\Zatca\Utilis\QrCodeOptions; // Optional

// Optional
$qrCodeOptions = new QrCodeOptions;

// Format (png,svg,eps)
$qrCodeOptions->format("svg");

// Color 
$qrCodeOptions->color(255,0,0,1);

// Background Color 
$qrCodeOptions->backgroundColor(0,0,0);

// Size
$qrCodeOptions->size(100);

// Margin 
$qrCodeOptions->margin(0);

// Style (square,dot,round)
$qrCodeOptions->style('square',0.5);

// Eye (square,circle)
$qrCodeOptions->eye('square');

$qrCode = Zatca::sellerName('Zatca')
            ->vatRegistrationNumber("123456789123456")
            ->timestamp("2021-12-01T14:00:09Z")
            ->totalWithVat('100.00')
            ->vatTotal('15.00')
            ->toQrCode($qrCodeOptions);

Generate Base64 Using Function

$base64 = zatca()
            ->sellerName('Zatca')
            ->vatRegistrationNumber("123456789123456")
            ->timestamp("2021-12-01T14:00:09Z")
            ->totalWithVat('100.00')
            ->vatTotal('15.00')
            ->toBase64();
// Output
// AQVaYXRjYQIPMTIzNDU2Nzg5MTIzNDU2AxQyMDIxLTEyLTAxVDE0OjAwOjA5WgQGMTAwLjAwBQUxNS4wMA==

Generate Plain Using Function

$tlv = zatca()
            ->sellerName('Zatca')
            ->vatRegistrationNumber("123456789123456")
            ->timestamp("2021-12-01T14:00:09Z")
            ->totalWithVat('100.00')
            ->vatTotal('15.00')
            ->toTLV();

Render A QR Code Image Using Function

$qrCode = zatca()
            ->sellerName('Zatca')
            ->vatRegistrationNumber("123456789123456")
            ->timestamp("2021-12-01T14:00:09Z")
            ->totalWithVat('100.00')
            ->vatTotal('15.00')
            ->toQrCode(
              qrCodeOptions()
                ->format("svg")
                ->color(255,0,0,1)
                ->size(300)
            );

Testing

composer test

Licence

This library is open-sourced software licensed under the MIT license.