1. Go to this page and download the library: Download feldsam-inc/paybysquare-php 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/ */
feldsam-inc / paybysquare-php example snippets
ayBySquare\PayBySquare;
// Create a new PayBySquare instance with payment attributes
$payBySquare = new PayBySquare([
'amount' => 15.00,
'currencyCode' => 'EUR',
'iban' => 'SK2483300000002403097934',
'bic' => 'FIOZSKBAXXX',
'paymentDueDate' => '20250301', // Format: YYYYMMDD
'constantSymbol' => '0308',
'paymentNote' => 'MMSR-2025-V0SU9'
]);
// Generate QR code and save to file
$payBySquare->saveQrCode('payment-qr.png');
// Get the PAY by square data string (for custom QR code generation)
$payBySquareData = $payBySquare->getPayBySquareData();
echo $payBySquareData;
// You can also convert the PayBySquare object directly to a string
echo (string)$payBySquare; // Same as $payBySquare->getPayBySquareData()
ayBySquare\PayBySquare;
use PayBySquare\Models\Payment;
use PayBySquare\Models\BankAccount;
// Create a new PayBySquare instance
$payBySquare = new PayBySquare();
// Create a payment manually
$payment = new Payment();
$payment->setAmount(15.00);
$payment->setCurrencyCode('EUR');
$payment->setPaymentDueDate('20250301');
// Add multiple bank accounts
$bankAccount1 = new BankAccount('SK2483300000002403097934', 'FIOZSKBAXXX');
$payment->addBankAccount($bankAccount1);
$bankAccount2 = new BankAccount('SK1234500000000000123456', 'TATRSKBXXXX');
$payment->addBankAccount($bankAccount2);
// Set the payment on the PayBySquare instance
$payBySquare->setPayment($payment);
// Generate QR code
$qrCodePng = $payBySquare->generateQrCode();
file_put_contents('payment-qr.png', $qrCodePng);
// Set beneficiary information
$payment->setBeneficiaryName('Company Name Ltd.');
$payment->setBeneficiaryAddressLine1('Street Name 123');
$payment->setBeneficiaryAddressLine2('12345 City, Country');
// Generate QR code with custom options
$qrCodePng = $payBySquare->generateQrCode([
'size' => 400, // QR code size in pixels
'margin' => 20, // QR code margin in pixels
]);
// Set payment symbols
$payment->setVariableSymbol('1234567890'); // Variable symbol (up to 10 digits)
$payment->setConstantSymbol('0308'); // Constant symbol (up to 4 digits)
$payment->setSpecificSymbol('9876543210'); // Specific symbol (up to 10 digits)
// Set payment reference (up to 35 characters)
$payment->setReference('REF123456789');
// This will clear any previously set symbols
$payment->setReference('REF123456789');
// This will clear the reference
$payment->setVariableSymbol('1234567890');
// Using paymentNote for reference information
$payment->setPaymentNote('REF123456789: Your payment description');
// Get QR code as HTML img tag
$htmlTag = $payBySquare->getQRCodeImage(true, 300, 10);
echo $htmlTag; // Outputs: <img src="data:image/png;base64,..." width="300" height="300" alt="QR Platba" />
// Get QR code as data URI
$dataUri = $payBySquare->getQRCodeImage(false, 300, 10);
echo $dataUri; // Outputs: data:image/png;base64,...
// Or use the dedicated method
$dataUri = $payBySquare->getDataUri(300, 10);
// Save as PNG (default)
$payBySquare->saveQRCodeImage('payment-qr.png', PayBySquare::FORMAT_PNG);
// Save as SVG
$payBySquare->saveQRCodeImage('payment-qr.svg', PayBySquare::FORMAT_SVG);
use Endroid\QrCode\Color\Color;
// Create custom colors
$black = new Color(0, 0, 0); // RGB values for black
$blue = new Color(0, 0, 255); // RGB values for blue
// Generate QR code with custom colors
$qrCodePng = $payBySquare->generateQrCode([
'foregroundColor' => $black,
'backgroundColor' => new Color(255, 255, 255), // White background
]);
// Or with the HTML tag method
$htmlTag = $payBySquare->getQRCodeImage(true, 300, 10, [
'foregroundColor' => $blue,
'backgroundColor' => new Color(255, 255, 0), // Yellow background
]);
// Save with custom colors
$payBySquare->saveQRCodeImage('payment-qr.png', PayBySquare::FORMAT_PNG, 300, 10, [
'foregroundColor' => $black,
'backgroundColor' => new Color(255, 255, 255),
]);
// Specify the path to the XZ binary
$payBySquare = new PayBySquare([
'amount' => 15.00,
'currencyCode' => 'EUR',
'iban' => 'SK2483300000002403097934',
// other payment attributes...
], '/custom/path/to/xz');
// Or when creating an instance without payment attributes
$payBySquare = new PayBySquare(null, '/custom/path/to/xz');
// Get the PAY by square data string
$payBySquareData = $payBySquare->getPayBySquareData();
echo $payBySquareData;
// You can also convert the PayBySquare object directly to a string
echo (string)$payBySquare;
// Now you can use this data string with any QR code library
ayBySquare\PayBySquare;
use PayBySquare\Exceptions\EncodingException;
// Create a PayBySquare instance with payment attributes
$payBySquare = new PayBySquare([
'amount' => 15.00,
'currencyCode' => 'EUR',
'iban' => 'SK2483300000002403097934',
'bic' => 'FIOZSKBAXXX'
]);
try {
// Generate QR code
$qrCode = $payBySquare->generateQrCode();
file_put_contents('payment-qr.png', $qrCode);
} catch (EncodingException $e) {
// Handle encoding errors (e.g., XZ binary not installed)
echo "Encoding error: " . $e->getMessage();
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.