hubipe / huqrpayment
适用于匈牙利的QR支付库(根据匈牙利国家银行标准版本001)
v1.1.1
2023-08-31 11:56 UTC
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
用于为匈牙利银行生成QR支付码的库(符合匈牙利国家银行(MNB)标准)。此库是从rikudou的欧盟QR支付复制并修改而来。
查看标准
安装
通过composer: composer require hubipe/huqrpayment
使用方法
在构造函数中,您必须提供IBAN,它可以是字符串或hubipe\HuQrPayment\Iban\IbanInterface
的实例。
字符串示例
<?php use hubipe\HuQrPayment\QrPayment; $payment = new QrPayment('HU42117730161111101800000000');
基本IBAN类示例
<?php use hubipe\HuQrPayment\QrPayment; use hubipe\HuQrPayment\Iban\IBAN; $payment = new QrPayment(new IBAN('HU42117730161111101800000000'));
当您想创建一个将本地格式(BBAN)转换为IBAN的适配器时,IbanInterface
很有用。
此包已包含匈牙利账户号码适配器
<?php use hubipe\HuQrPayment\QrPayment; use Rikudou\Iban\Iban\HungarianIbanAdapter; $payment = new QrPayment(new HungarianIbanAdapter('11773016-11111018-00000000'));
设置支付详情
所有支付详情都可以通过setter设置。
<?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码图像
此库通过其姊妹库rikudou/qr-payment-qr-code-provider提供了许多QR码图像实现。如果已安装任何受支持的QR码生成库,则方法getQrCode()
将返回一个\Rikudou\QrPaymentQrCodeProvider\QrCode
实例,可以用于获取包含生成的QR支付数据的图像。
<?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()}'>";