PHP code example of engazan / pay-by-square

1. Go to this page and download the library: Download engazan/pay-by-square 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/ */

    

engazan / pay-by-square example snippets


use Engazan\PayBySquare\Generator;
use Engazan\PayBySquare\QrStyle;

$qr = (new Generator())
    ->setIban('SK7700000000000000000000')   // povinné, bez medzier
    ->setSwift('CEKOSKBX')
    ->setAmount(49.99)                       // povinné
    ->setRecipient('Jozko Mrkvicka')
    ->setVariableSymbol('20240001')          // max 10 číslic
    ->setConstantSymbol('0308')              // max 4 znaky
    ->setSpecificSymbol('9999')
    ->setPaymentReference('/VS1234/SS5678')   // max 35 znakov
    ->setNote('Faktura č. 2024/001')         // max 35 znakov
    ->setDueDate(new DateTime('+14 days'))
    ->setStyle(QrStyle::PayBySquare);

// HTML <img> tag – priamo do šablóny
echo $qr->getImgTag(300);

// Len data URI
$uri = $qr->getDataUri(300);
echo "<img src=\"{$uri}\">";

// Uložiť PNG súbor
$qr->saveToFile('/var/www/qr/platba.png', 300);

// Surové PNG bajty (napr. pre HTTP response)
header('Content-Type: image/png');
echo $qr->getPngBytes(300);

// Len Pay by square reťazec (ak máš vlastný QR renderer)
$string = $qr->generateString();

use Engazan\PayBySquare\QrStyle;

$qr->setStyle(QrStyle::PayBySquare);

$qr->setXzPath('/usr/local/bin/xz');

use Engazan\PayBySquare\Exception\ValidationException;
use Engazan\PayBySquare\Exception\PayBySquareException;

try {
    echo $qr->getImgTag();
} catch (ValidationException $e) {
    // Chýba IBAN, suma <= 0, príliš dlhá poznámka...
    echo 'Neplatné dáta: ' . $e->getMessage();
} catch (PayBySquareException $e) {
    // xz binárka sa nenašla, kompresia zlyhala...
    echo 'Chyba generovania: ' . $e->getMessage();
}