# pay-by-square-encoder
Generator of QR codes for pay by square

## Introduction

PAY by square is a Slovak banking standard for encoding payment info into QR codes. It uses LZMA-compressed XML/XSD data, Base32 encoding, and CRC32 checksums, formatted as QR Code 2005. The code contains SEPA-compliant details, including up to 5 IBAN/BIC accounts, amounts, and, crucially, variable symbols. 

For detailed specification visit
https://www.sbaonline.sk/wp-content/uploads/2020/03/pay-by-square-specifications-1_1_0.pdf

## About

This library encodes payment information into a Pay-By-Square compliant string. It uses external LZMA compression utility (the 'xz').

Use the string generated by the encoder as the input to your favourite QR code generator library.

### Linux

Linux by default contains a `xz` utility, typicaly located in `/usr/bin/xz`.

### Windows

You will need the `xz.exe` utility which can be downloaded e.g. from https://sourceforge.net/projects/xz-for-windows/files/XZ-5.2.1_Win32%28static%29.zip/download.

## Install

```
composer require hubleto/pay-by-square-qr-code
```

## Usage

```php
$pbsEnc = new \Hubleto\Utilities\PayBySquareEncoder();
$pbsEnc->setAmount(9.99);
$pbsEnc->setIban("SK99 0000 0012 3456 7890");
$pbsEnc->setBic("ABCDEFGH");
$pbsEnc->setBeneficiaryName("The Beneficiary Ltd.");
$pbsEnc->setVariableSymbol("2020123456");
$pbsEnc->setConstantSymbol("0308");
$pbsEnc->setSpecificSymbol("1000");
$pbsEnc->setNote("Payment for the services");

$pbsEnc->setXzPath("/usr/bin/xz"); // set the path to your XZ utility
$encoded = $pbsEnc->getEncodedString();

// Now, use here the `$encoded` in your favourite QR code generator library.
```