Skip to content

Commit

Permalink
Merge pull request dfridrich#4 from czPechy/master
Browse files Browse the repository at this point in the history
  • Loading branch information
dfridrich authored Jul 10, 2018
2 parents e7a5bb8 + c36f622 commit f71dbee
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 78 deletions.
24 changes: 11 additions & 13 deletions .travis.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm

matrix:
allow_failures:
- php: hhvm
allow_failures:
- php: hhvm

before_script:
- composer self-update
- composer install --no-interaction --prefer-source
- composer self-update
- composer install --no-interaction --prefer-source

script:
- phpunit
- phpunit

after_success:
- if [ $TRAVIS_PHP_VERSION = '5.6' ] && [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST = 'false' ]; then sh generate-api.sh; fi
- if [ $TRAVIS_PHP_VERSION = '5.6' ] && [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST = 'false' ]; then sh generate-api.sh; fi
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ QRPlatbu v současné době podporují tyto banky:
Air Bank, Česká spořitelna, ČSOB, Equa bank, Era, Fio banka, Komerční banka, mBank, Raiffeisenbank, ZUNO.


Podporuje PHP 5.4 až 7.2.
Podporuje PHP 5.6 až 7.2.

## Instalace pomocí Composeru

Expand Down Expand Up @@ -63,14 +63,25 @@ echo QRPlatba::create('12-3456789012/0100', 987.60)

Uložení do souboru
```php
// Uloží jpg o velikosti 100x100 px a paddingem 0 px
$qrPlatba->saveQRCodeImage("qrcode.jpg", "jpg", 100, 0);
// Uloží png o velikosti 100x100 px
$qrPlatba->saveQRCodeImage("qrcode.png", "png", 100);

// Uloží svg o velikosti 100x100 px
$qrPlatba->saveQRCodeImage("qrcode.svg", "svg", 100);
```

Aktuální možné formáty jsou:
* Png
* Svg
* Eps
* binární

Pro další je potřeba dopsat vlastní Writter

Zobrazení data-uri
```php
// data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAFAAQMAAAD3XjfpAAAA...
echo $qrPlatba->getQRCodeInstance()->getDataUri();
echo $qrPlatba->getQRCodeInstance()->writeDataUri();
```

## Odkazy
Expand Down
30 changes: 30 additions & 0 deletions Tests/IBANTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the library "QRPlatba".
*
* (c) Dennis Fridrich <[email protected]>
*
* For the full copyright and license information,
* please view LICENSE.
*/

use Defr\QRPlatba\QRPlatba;

/**
* Class QRPlatbaTest.
*/
class IBANTest extends PHPUnit_Framework_TestCase
{

public function testAccountHigherThanMaxInt()
{
$string = QRPlatba::accountToIban('2501301193/2010');

$this->assertSame(
'CZ3620100000002501301193',
$string
);
}

}
60 changes: 30 additions & 30 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"name": "dfridrich/qr-platba",
"type": "library",
"description": "Generování QR plateb v PHP.",
"keywords": [
"php",
"qr",
"platba"
],
"homepage": "https://github.com/dfridrich/QRPlatba",
"license": "MIT",
"authors": [
{
"name": "Dennis Fridrich",
"email": "[email protected]"
"name": "dfridrich/qr-platba",
"type": "library",
"description": "Generování QR plateb v PHP.",
"keywords": [
"php",
"qr",
"platba"
],
"homepage": "https://github.com/dfridrich/QRPlatba",
"license": "MIT",
"authors": [
{
"name": "Dennis Fridrich",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.6.0",
"endroid/qr-code": "^2.0"
},
"autoload": {
"psr-4": {
"Defr\\QRPlatba\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "4.8.36"
},
"config": {
"bin-dir": "bin"
}
],
"require": {
"php": ">=5.4.0",
"endroid/qrcode": "^1.5"
},
"autoload": {
"psr-4": {
"Defr\\QRPlatba\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "4.8.36"
},
"config": {
"bin-dir": "bin"
}
}
53 changes: 22 additions & 31 deletions src/QRPlatba.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class QRPlatba
* @param null $amount
* @param null $variable
* @param null $currency
* @throws \InvalidArgumentException
*/
public function __construct($account = null, $amount = null, $variable = null, $currency = null)
{
Expand All @@ -122,6 +123,7 @@ public function __construct($account = null, $amount = null, $variable = null, $
* @param null $variable
*
* @return QRPlatba
* @throws \InvalidArgumentException
*/
public static function create($account = null, $amount = null, $variable = null)
{
Expand All @@ -137,7 +139,7 @@ public static function create($account = null, $amount = null, $variable = null)
*/
public function setAccount($account)
{
$this->keys['ACC'] = $this->accountToIban($account);
$this->keys['ACC'] = self::accountToIban($account);

return $this;
}
Expand Down Expand Up @@ -196,7 +198,7 @@ public function setConstantSymbol($cs)
public function setSpecificSymbol($ss)
{
if (mb_strlen($ss) > 10) {
throw new QRPlatbaException();
throw new QRPlatbaException('Specific symbol is higher than 10 chars');
}
$this->keys['X-SS'] = $ss;

Expand Down Expand Up @@ -235,6 +237,7 @@ public function setDueDate(\DateTime $date)
* @param $cc
*
* @return $this
* @throws \InvalidArgumentException
*/
public function setCurrency($cc)
{
Expand Down Expand Up @@ -270,16 +273,13 @@ public function __toString()
*
* @param bool $htmlTag
* @param int $size
* @param int $padding
*
* @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException
*
* @return string
*/
public function getQRCodeImage($htmlTag = true, $size = 300, $padding = 10)
public function getQRCodeImage($htmlTag = true, $size = 300)
{
$qrCode = $this->getQRCodeInstance($size, $padding);
$data = $qrCode->getDataUri();
$qrCode = $this->getQRCodeInstance($size);
$data = $qrCode->writeDataUri();

return $htmlTag
? sprintf('<img src="%s" alt="QR Platba">', $data)
Expand All @@ -290,18 +290,17 @@ public function getQRCodeImage($htmlTag = true, $size = 300, $padding = 10)
* Uložení QR kódu do souboru.
*
* @param null|string $filename File name of the QR Code
* @param null|string $format Format of the file (png, jpeg, jpg, gif, wbmp)
* @param int $size
* @param int $padding
*
* @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException
* @param null|string $format Format of the file (png, jpeg, jpg, gif, wbmp)
* @param int $size
*
* @return QRPlatba
* @throws \Endroid\QrCode\Exception\UnsupportedExtensionException
*/
public function saveQRCodeImage($filename = null, $format = 'png', $size = 300, $padding = 10)
public function saveQRCodeImage($filename = null, $format = 'png', $size = 300)
{
$qrCode = $this->getQRCodeInstance($size, $padding);
$qrCode->render($filename, $format);
$qrCode = $this->getQRCodeInstance($size);
$qrCode->setWriterByExtension($format);
$qrCode->writeFile($filename);

return $this;
}
Expand All @@ -310,17 +309,15 @@ public function saveQRCodeImage($filename = null, $format = 'png', $size = 300,
* Instance třídy QrCode pro libovolné úpravy (barevnost, atd.).
*
* @param int $size
* @param int $padding
*
* @return QrCode
*/
public function getQRCodeInstance($size = 300, $padding = 10)
public function getQRCodeInstance($size = 300)
{
$qrCode = new QrCode();
$qrCode
->setText((string) $this)
->setSize($size)
->setPadding($padding)
->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);

Expand All @@ -346,11 +343,12 @@ public static function accountToIban($accountNumber)
list($pre, $acc) = explode('-', $accountNumber[0]);
}

$accountPart = sprintf('%06d%010d', $pre, $acc);
$accountPart = sprintf('%06d%010s', $pre, $acc);
$iban = 'CZ00'.$bank.$accountPart;

$alfa = 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';
$alfa = explode(' ', $alfa);
$alfa_replace = [];
for ($i = 1; $i < 27; ++$i) {
$alfa_replace[] = $i + 9;
}
Expand All @@ -360,7 +358,7 @@ public static function accountToIban($accountNumber)
mb_substr($iban, 4, mb_strlen($iban) - 4).mb_substr($iban, 0, 2).'00'
);
$controlegetal = 98 - (int) bcmod($controlegetal, 97);
$iban = sprintf('CZ%02d%04d%06d%010d', $controlegetal, $bank, $pre, $acc);
$iban = sprintf('CZ%02d%04d%06d%010s', $controlegetal, $bank, $pre, $acc);

return $iban;
}
Expand All @@ -379,22 +377,15 @@ private function stripDiacritics($string)
'ě', 'š', 'č', 'ř', 'ž', 'ý', 'á', 'í', 'é', 'ú', 'ů',
'ó', 'ť', 'ď', 'ľ', 'ň', 'ŕ', 'â', 'ă', 'ä', 'ĺ', 'ć',
'ç', 'ę', 'ë', 'î', 'ń', 'ô', 'ő', 'ö', 'ů', 'ű', 'ü',
'Ě', 'Š', 'Č', 'Ř', 'Ž', 'Ý', 'Á', 'Í', 'É', 'Ú', 'Ů',
'Ó', 'Ť', 'Ď', 'Ľ', 'Ň', 'Ä', 'Ć', 'Ë', 'Ö', 'Ü'
],
[
'e', 's', 'c', 'r', 'z', 'y', 'a', 'i', 'e', 'u', 'u',
'o', 't', 'd', 'l', 'n', 'a', 'a', 'a', 'a', 'a', 'a',
'c', 'e', 'e', 'i', 'n', 'o', 'o', 'o', 'u', 'u', 'u',
],
$string
);
$string = str_replace(
[
'Ě', 'Š', 'Č', 'Ř', 'Ž', 'Ý', 'Á', 'Í', 'É', 'Ú', 'Ů',
'Ó', 'Ť', 'Ď', 'Ľ', 'Ň', 'Ä', 'Ć', 'Ë', 'Ö', 'Ü',
],
[
'E', 'S', 'C', 'R', 'Z', 'Y', 'A', 'I', 'E', 'U', 'U',
'O', 'T', 'D', 'L', 'N', 'A', 'C', 'E', 'O', 'U',
'O', 'T', 'D', 'L', 'N', 'A', 'C', 'E', 'O', 'U'
],
$string
);
Expand Down

0 comments on commit f71dbee

Please sign in to comment.