hubipe / huqrpayment
QR payment library for Hungary (according to the Magyar Nemzeti Bank standard version 001)
Installs: 52 621
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.3|^8.0
- ext-mbstring: *
- rikudou/iban: ^1.2
- rikudou/qr-payment-interface: ^1.1
- rikudou/qr-payment-qr-code-provider: ^1.1
Requires (Dev)
- endroid/qr-code: ^3.2
- phpstan/phpstan: ^1.10
Suggests
- endroid/qr-code: For generating QR code image
README
Library to generate QR payment codes for Hungarian banks (standard by Hungarian national bank (MNB)). This library was copied and modified from the rikudou's EU QR Payment
See the standard
See also QR code payment generator for Czech, Slovak or European Union accounts.
Installation
Via composer: composer require hubipe/huqrpayment
Usage
In the constructor you must supply IBAN which may be a string
or an instance of hubipe\HuQrPayment\Iban\IbanInterface
.
Example with string:
<?php use hubipe\HuQrPayment\QrPayment; $payment = new QrPayment('HU42117730161111101800000000');
Example with base IBAN class:
<?php use hubipe\HuQrPayment\QrPayment; use hubipe\HuQrPayment\Iban\IBAN; $payment = new QrPayment(new IBAN('HU42117730161111101800000000'));
The IbanInterface
is useful in case you want to create an
adapter that transforms your local format (BBAN) to IBAN.
This package already contains Adapter for Hungarian account numbers:
<?php use hubipe\HuQrPayment\QrPayment; use Rikudou\Iban\Iban\HungarianIbanAdapter; $payment = new QrPayment(new HungarianIbanAdapter('11773016-11111018-00000000'));
Setting payment details
All payment details can be set via setters:
<?php use hubipe\HuQrPayment\Enums\CharacterSet; use hubipe\HuQrPayment\Enums\IdCode; use hubipe\HuQrPayment\Enums\Purpose; use hubipe\HuQrPayment\QrPayment; $payment = new QrPayment('HU42117730161111101800000000'); $payment ->setIdCode(IdCode::TRANSFER_ORDER) ->setCharacterSet(CharacterSet::UTF_8) ->setBic('OTPVHUHB') ->setName('My company name') ->setAmount(53250) ->setCurrency('HUF') ->setDueDate(new DateTimeImmutable('+3 days')) ->setPaymentSituationIdentifier(Purpose::PURCHASE_SALE_OF_GOODS) ->setRemittance('Payment for goods') ->setShopId('SHOP1') ->setMerchantDeviceId('Terminal 1') ->setReceiptId('1234984657S') ->setPayeeInternalId('Payee internal identification') ->setLoyaltyId('GOLDEN_CUSTOMER') ->setNavVerificationCode('FXC4');
QR Code image
This library provides many implementations of QR code image using its sister library
rikudou/qr-payment-qr-code-provider. If any supported
QR code generating library is installed, the method getQrCode()
will return an instance of
\Rikudou\QrPaymentQrCodeProvider\QrCode
which can be used to get an image containing the generated QR payment data.
<?php use hubipe\HuQrPayment\QrPayment; use Endroid\QrCode\QrCode; $payment = new QrPayment(...); $qrCode = $payment->getQrCode(); // get the raw image data and display them in the browser header('Content-Type: image/png'); echo $qrCode->getRawString(); // use in an img html tag echo "<img src='{$qrCode->getDataUri()}'>"; // write to a file $qrCode->writeToFile('/tmp/some-file.png'); // get the raw object from the underlying system $raw = $qrCode->getRawObject(); // let's assume we're using endroid/qr-code v4 assert($raw instanceof QrCode); // do some custom transformations $raw->setLabelFontSize(15); // the object is still referenced by the adapter, meaning we can now render it the same way as before echo "<img src='{$qrCode->getDataUri()}'>";