PHP code example of djalone / kkm-server-classes

1. Go to this page and download the library: Download djalone/kkm-server-classes 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/ */

    

djalone / kkm-server-classes example snippets



...
/* Получите ИНН и ФИО кассира обычным для вас способом */
    $cashierINN = $lib->getCashierInn();
    $cashierName = $lib->getCashierName();
...
/* Выведите ссылку на меню */
echo "<a href=\"path-to-your-vendor-dir/frontend/menu.php?cashierName={$cashierName}&cashierVatin={$cashierVatin}\">Меню работы с ККТ </a>";
...



use Djalone\KkmServerClasses\Cheque;
use Djalone\KkmServerClasses\Cheque\Enums\PaymentTypes;
use Djalone\KkmServerClasses\Cheque\Items\Position;
use Djalone\KkmServerClasses\Services\CustomGUID;
use Djalone\KkmServerClasses\Services\Serializer;
use Djalone\KkmServerClasses\Services\Helper;

�икальный идентификатор команды
);

// Установка информации о клиенте
$cheque
    ->setClientAddress('+791-------')
    ->setClientInfo('Иванов Иван Иванович');

// Добавление товара в чек
$cheque->addItem(
    (new Position('Товар 1', 1000, 2000))  // название, цена в копейках, количество в тысячных долях
        ->setPaymentType(PaymentTypes::Electronic)
);
// Определите ссылку callBack для получения ответа от фронтенда
$callBackUrl = '/my-callback-url.php';

...
// Выведите форму на экран с разу выполните переход
    echo Helper::echoForm($cheque,$callBackUrl);
...

public function __construct(
    string $cashierName = '',
    string $cashierVatin = '',
    string $kktNumber = '',
    string $idCommand = ''
)

public function __construct(
    string $name,           // Название товара
    int $price,            // Цена в копейках
    int $quantity          // Количество в тысячных долях (1000 = 1 шт)
)

public static function serializeCheque(Cheque $cheque): string
// Возвращает JSON-строку команды чека

public static function deserializeCheque(string $json): Cheque
// Десериализует JSON обратно в объект Cheque

Logger::getInstance()->info('Сообщение', ['дополнительные' => 'данные']);
Logger::getInstance()->error('Ошибка');
Logger::getInstance()->warning('Предупреждение');

$cheque = new Cheque(...);
// ... конфигурация ...

if ($cheque->isValid()) {
    $json = Serializer::serializeCheque($cheque);
} else {
    $errors = $cheque->getErrors();
    // Обработка ошибок
}
bash
php vendor/bin/phpunit tests
bash
php vendor/bin/phpunit tests/ChequeTest.php
bash
php vendor/bin/phpunit --coverage-html coverage/
bash
php vendor/bin/php-cs-fixer fix src/
php vendor/bin/php-cs-fixer fix tests/
bash
php vendor/bin/phpstan analyse src/ --level=9
bash
php vendor/bin/rector process src/

frontend/menu.php         # Интерфейс меню управления ККТ
frontend/printer.php      # Обработчик печати чеков
backend/testCallback.php  # Пример обработчика callback