rikudou/czqrpayment
Composer 安装命令:
composer require rikudou/czqrpayment
包简介
QR payment library for Czech accounts
README 文档
README
A simple library to generate QR payment code for Czech Republic. All methods are documented in source code.
See also QR code payment generator for Slovak, Hungarian or European Union accounts.
Using Symfony? See the QR Payment Bundle.
Installation
Via composer: composer require rikudou/czqrpayment
Usage
You can create the QR payment for an object implementing \Rikudou\Iban\Iban\IbanInterface or from account number
and bank account (which is then converted to \Rikudou\Iban\Iban\CzechIbanAdapter object).
See rikudou/iban for description of the interface and classes which let you for example validate the iban and/or the bank account number and bank code.
From IbanInterface implementing classes:
<?php use Rikudou\CzQrPayment\QrPayment; use Rikudou\Iban\Iban\IBAN; use Rikudou\Iban\Iban\CzechIbanAdapter; // initialized with IBAN directly $payment = new QrPayment(new IBAN('CZ5530300000001325090010')); // initialized from Czech account number and bank code $payment = new QrPayment(new CzechIbanAdapter('1325090010', '3030')); // the IBAN classes don't use strict typing so you can also use implicit conversion like this // beware of bank codes that start with zero, those need to always be supplied as a string (like 0300) $payment = new QrPayment(new CzechIbanAdapter(1325090010, 3030));
From account number and bank code directly:
<?php use Rikudou\CzQrPayment\QrPayment; $payment = QrPayment::fromAccountAndBankCode('1325090010', '3030'); // the class does not use strict typing so you can also use implicit conversion like this // beware of bank codes that start with zero, those need to always be supplied as a string (like 0300) $payment = QrPayment::fromAccountAndBankCode(1325090010, 3030);
Setting payment details
There are two approaches to setting payment details. You can set them in an associative array or using the methods provided in the class.
Using associative array
<?php use Rikudou\CzQrPayment\QrPayment; use Rikudou\CzQrPayment\Options\QrPaymentOptions; use Rikudou\Iban\Iban\CzechIbanAdapter; $payment = new QrPayment(new CzechIbanAdapter('1325090010', '3030'), [ QrPaymentOptions::VARIABLE_SYMBOL => 123456, QrPaymentOptions::AMOUNT => 100, QrPaymentOptions::CURRENCY => "CZK", QrPaymentOptions::DUE_DATE => date("Y-m-d", strtotime("+14 days")) ]); // or you can assign the options later via setOptions() $payment->setOptions([ QrPaymentOptions::VARIABLE_SYMBOL => 123456, QrPaymentOptions::AMOUNT => 100, QrPaymentOptions::CURRENCY => "CZK", QrPaymentOptions::DUE_DATE => date("Y-m-d", strtotime("+14 days")), QrPaymentOptions::INSTANT_PAYMENT => true, ]);
Using methods
<?php use Rikudou\CzQrPayment\QrPayment; use Rikudou\Iban\Iban\CzechIbanAdapter; $payment = new QrPayment(new CzechIbanAdapter('1325090010', '3030')); $payment ->setVariableSymbol(123456) ->setAmount(100) ->setCurrency("CZK") ->setDueDate(new DateTimeImmutable('+14 days')) ->setInstantPayment(true);
Exceptions
Description of exceptions thrown:
__construct()InvalidArgumentException- if you provide options in constructor and any of those options does not exist\Rikudou\CzQrPayment\Exception\InvalidValueException- if any of the options contains an asteriskTypeError- if any of the values is not assignable to the properties after standard php conversions
setOptions()- same as constructorgetQrString()\Rikudou\CzQrPayment\Exception\InvalidValueException- if any of the options contains an asterisk or if the iban is not valid
getQrImage()\Rikudou\CzQrPayment\Exception\MissingLibraryException- if the endroid/qr-code library is missing
All of these exceptions (except InvalidArgumentException and TypeError) extend the base
\Rikudou\CzQrPayment\Exception\QrPaymentException.
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 Rikudou\CzQrPayment\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()}'>";
List of public methods
Constructor
Params
\Rikudou\Iban\Iban\IbanInterface $ibanrequired - the IBAN for the paymentarray|null $options- the array with options. The helper classQrPaymentOptionscan be used for options names.
Example
<?php use Rikudou\CzQrPayment\QrPayment; use Rikudou\CzQrPayment\Options\QrPaymentOptions; use Rikudou\Iban\Iban\CzechIbanAdapter; $payment = new QrPayment(new CzechIbanAdapter('1325090010', '3030')); // or with options $payment = new QrPayment(new CzechIbanAdapter('1325090010', '3030'), [ QrPaymentOptions::AMOUNT => 100 ]);
setOptions()
Sets the options, useful if you don't want to set them in constructor.
Params
array $optionsrequired - the same as the constructor param$options
Returns
Returns itself, you can use this method for chaining.
Example
<?php use Rikudou\CzQrPayment\QrPayment; use Rikudou\CzQrPayment\Options\QrPaymentOptions; use Rikudou\Iban\Iban\CzechIbanAdapter; $payment = new QrPayment(new CzechIbanAdapter('1325090010', '3030')); $payment->setOptions([ QrPaymentOptions::AMOUNT => 100 ]);
getIban()
Returns the iban.
Returns
\Rikudou\Iban\Iban\IbanInterface
Example
<?php use Rikudou\CzQrPayment\QrPayment; use Rikudou\Iban\Iban\CzechIbanAdapter; $payment = new QrPayment(new CzechIbanAdapter('1325090010', '3030')); $myIBAN = $payment->getIban();
getQrString()
Returns the string that should be encoded in QR image.
Returns
string
Example
<?php use Rikudou\CzQrPayment\QrPayment; use Rikudou\CzQrPayment\Options\QrPaymentOptions; use Rikudou\Iban\Iban\CzechIbanAdapter; $payment = new QrPayment(new CzechIbanAdapter('1325090010', '3030'), [ QrPaymentOptions::AMOUNT => 100, QrPaymentOptions::VARIABLE_SYMBOL => 1502, QrPaymentOptions::DUE_DATE => new DateTimeImmutable('+14 days'), ]); $qrString = $payment->getQrString(); // SPD*1.0*ACC:CZ5530300000001325090010*AM:100.00*CC:CZK*X-PER:7*X-VS:1502*DT:20210413
static fromAccountAndBankCode()
Returns a new instance of the payment object created from the account and bank code.
Is pretty much an alias to new QrPayment(new CzechIbanAdapter()).
Params
string $accountNumberrequired - The account numberstring $bankCoderequired - The bank code
Returns
Returns itself, you can use this method for chaining.
Example
<?php use Rikudou\CzQrPayment\QrPayment; $payment = QrPayment::fromAccountAndBankCode('1325090010', '3030'); // do all the other stuff
getQrImage()
Returns a Qr code via suggested third-party library.
Returns
\Endroid\QrCode\QrCode
Example
<?php use Rikudou\CzQrPayment\QrPayment; use Rikudou\CzQrPayment\Options\QrPaymentOptions; $payment = QrPayment::fromAccountAndBankCode('1325090010', '3030')->setOptions([ QrPaymentOptions::AMOUNT => 100 ]); header('Content-Type: image/png'); echo $payment->getQrImage()->writeString();
Options
This is a list of options you can set.
int $variableSymbol- the variable symbol, has no defaultint $specificSymbol- the specific symbol, has no defaultint $constantSymbol- the constant symbol, has no defaultstring $currency- ISO 4217 code for currency, defaults toCZKstring $comment- the payment comment, has no defaultint $repeat- the number of days that the payment should be repeated if it fails, defaults to7string $internalId- internal id of the payment, has no defaultDateTimeInterface dueDate- the due date for payment, has no defaultfloat $amount- the amount for the payment, shouldn't have more than 2 decimal places, has no defaultstring $country- ISO 3166-1 alpha-2 code for country, defaults toCZbool $instantPayment- whether the payment should be made as instant instead of standard payment (depends on bank support)
All of these options can be set using the QrPaymentOptions helper class as constants for the constructor or
setOptions() or as methods.
For example, the amount can be set in an array using the constant QrPaymentOptions::AMOUNT or using the
method setAmount().
rikudou/czqrpayment 适用场景与选型建议
rikudou/czqrpayment 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 469.14k 次下载、GitHub Stars 达 29, 最近一次更新时间为 2016 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「qr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rikudou/czqrpayment 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rikudou/czqrpayment 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rikudou/czqrpayment 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
TrinkPOS Sanal POS (Virtual POS) API client for PHP
Merchant-side PHP SDK for YoPay Pay Open API.
Laravel Cashier Bachs provides an expressive, fluent interface to Bachs' subscription billing services.
Standalone PayPal REST Orders v2 payment integration for Magento 2. No Magento_Paypal or SOAP/NVP dependency. Server-side redirect checkout with capture, refund, and admin transaction support.
Laravel integration for the Telebirr payment SDK
Headless PHP SDK for Ethio Telecom Telebirr payment gateway
统计信息
- 总下载量: 469.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 14
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-26