Skip to content

Commit bb8f6fe

Browse files
committed
Payment: variable, constant and specific symbol accept string
1 parent 00a938d commit bb8f6fe

File tree

11 files changed

+46
-32
lines changed

11 files changed

+46
-32
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ composer.lock
33
*~
44
/tests/**/output/
55
tests/src/E2E/account.ini
6-
/coverage.html
6+
coverage.html

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $fioPay->createEuro();
2828
$fioPay->createEuro();
2929
$fioPay->send();
3030
```
31+
- variable, constant and specific symbols are type string, integer is deprecated
3132

3233
### v 2.0
3334
- support only php 7.1+

src/Exceptions/InvalidArgument.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ public static function check(string $text, int $size): string
1515
}
1616

1717

18-
public static function checkRange(int $number, int $limit): int
18+
public static function checkRange(int|string $number, int $limit): void
1919
{
20-
if ($number < 0 || $number > $limit) {
21-
throw new self(sprintf('Value is out of range "%s" must contain 1-%s positive digits.', $number, strlen((string) $limit)));
20+
$check = intval($number);
21+
if ($check < 0 || $check > $limit) {
22+
throw new self(sprintf('Value is out of range "%s" must contain 1-%s positive digits.', $check, $limit));
2223
}
23-
24-
return $number;
2524
}
2625

2726

src/Pay/Payment/Property.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public function setDate(int|string|\DateTimeInterface $date): static
9191

9292
public function setPaymentReason(int $code): static
9393
{
94-
$this->paymentReason = InvalidArgument::checkRange($code, 999);
94+
InvalidArgument::checkRange($code, 999);
95+
$this->paymentReason = $code;
9596

9697
return $this;
9798
}

src/Pay/Payment/Symbols.php

+21-9
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,44 @@
66

77
trait Symbols
88
{
9-
protected int $ks = 0;
9+
protected string $ks = '';
1010

11-
protected int $vs = 0;
11+
protected string $vs = '';
1212

13-
protected int $ss = 0;
13+
protected string $ss = '';
1414

1515

16-
public function setConstantSymbol(int $ks): static
16+
/**
17+
* @param string $ks - int is deprecated
18+
*/
19+
public function setConstantSymbol(int|string $ks): static
1720
{
18-
$this->ks = InvalidArgument::checkRange($ks, 9999);
21+
InvalidArgument::checkRange($ks, 9999);
22+
$this->ks = (string) $ks;
1923

2024
return $this;
2125
}
2226

2327

24-
public function setVariableSymbol(int $vs): static
28+
/**
29+
* @param string $vs - int is deprecated
30+
*/
31+
public function setVariableSymbol(int|string $vs): static
2532
{
26-
$this->vs = InvalidArgument::checkRange($vs, 9999999999);
33+
InvalidArgument::checkRange($vs, 9999999999);
34+
$this->vs = (string) $vs;
2735

2836
return $this;
2937
}
3038

3139

32-
public function setSpecificSymbol(int $ss): static
40+
/**
41+
* @param string $ss - int is deprecated
42+
*/
43+
public function setSpecificSymbol(int|string $ss): static
3344
{
34-
$this->ss = InvalidArgument::checkRange($ss, 9999999999);
45+
InvalidArgument::checkRange($ss, 9999999999);
46+
$this->ss = (string) $ss;
3547

3648
return $this;
3749
}

tests/data/payment/euro-maximum.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.fio.cz/schema/importIB.xsd"><Orders><T2Transaction><accountFrom>123456789</accountFrom><currency>USD</currency><amount>500</amount><accountTo>AT611904300234573201</accountTo><ks>321</ks><vs>123456789</vs><ss>378</ss><bic>ABAGATWWXXX</bic><date>2014-01-23</date><comment>Lorem ipsum</comment><benefName>Milan</benefName><benefStreet>Street 44</benefStreet><benefCity>Prague</benefCity><benefCountry>JP</benefCountry><remittanceInfo1>info 1</remittanceInfo1><remittanceInfo2>info 2</remittanceInfo2><remittanceInfo3>info 3</remittanceInfo3><paymentReason>110</paymentReason><paymentType>431009</paymentType></T2Transaction></Orders></Import>
2+
<Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.fio.cz/schema/importIB.xsd"><Orders><T2Transaction><accountFrom>123456789</accountFrom><currency>USD</currency><amount>500</amount><accountTo>AT611904300234573201</accountTo><ks>0321</ks><vs>0123456789</vs><ss>0378</ss><bic>ABAGATWWXXX</bic><date>2014-01-23</date><comment>Lorem ipsum</comment><benefName>Milan</benefName><benefStreet>Street 44</benefStreet><benefCity>Prague</benefCity><benefCountry>JP</benefCountry><remittanceInfo1>info 1</remittanceInfo1><remittanceInfo2>info 2</remittanceInfo2><remittanceInfo3>info 3</remittanceInfo3><paymentReason>110</paymentReason><paymentType>431009</paymentType></T2Transaction></Orders></Import>

tests/data/payment/pay-maximum.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.fio.cz/schema/importIB.xsd"><Orders><DomesticTransaction><accountFrom>123456789</accountFrom><currency>EUR</currency><amount>1000</amount><accountTo>987654</accountTo><bankCode>0123</bankCode><ks>321</ks><vs>123456789</vs><ss>378</ss><date>2014-01-23</date><messageForRecipient>Hello Mr. Joe</messageForRecipient><comment>Lorem ipsum</comment><paymentReason>333</paymentReason><paymentType>431005</paymentType></DomesticTransaction></Orders></Import>
2+
<Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.fio.cz/schema/importIB.xsd"><Orders><DomesticTransaction><accountFrom>123456789</accountFrom><currency>EUR</currency><amount>1000</amount><accountTo>987654</accountTo><bankCode>0123</bankCode><ks>321</ks><vs>0123456789</vs><ss>378</ss><date>2014-01-23</date><messageForRecipient>Hello Mr. Joe</messageForRecipient><comment>Lorem ipsum</comment><paymentReason>333</paymentReason><paymentType>431005</paymentType></DomesticTransaction></Orders></Import>

tests/src/Unit/Exceptions/InvalidArgumentExceptionTest.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace h4kuna\Fio\Tests\Unit\Exceptions;
44

5+
use h4kuna;
56
use h4kuna\Fio\Exceptions\InvalidArgument;
67
use h4kuna\Fio\Tests\Fixtures\TestCase;
78
use Tester\Assert;
@@ -21,7 +22,7 @@ public function testCheck(): void
2122

2223

2324
/**
24-
* @throws \h4kuna\Fio\Exceptions\InvalidArgument
25+
* @throws h4kuna\Fio\Exceptions\InvalidArgument
2526
*/
2627
public function testCheckThrow(): void
2728
{
@@ -31,16 +32,17 @@ public function testCheckThrow(): void
3132

3233
public function testCheckRange(): void
3334
{
34-
Assert::same(10, InvalidArgument::checkRange(10, 99));
35+
InvalidArgument::checkRange(10, 99);
36+
Assert::true(true);
3537
}
3638

3739

3840
/**
39-
* @throws \h4kuna\Fio\Exceptions\InvalidArgument
41+
* @throws h4kuna\Fio\Exceptions\InvalidArgument
4042
*/
4143
public function testCheckRangeThrow(): void
4244
{
43-
Assert::same(10, InvalidArgument::checkRange(10, 1));
45+
InvalidArgument::checkRange(10, 1);
4446
}
4547

4648

@@ -51,7 +53,7 @@ public function testCheckIsInList(): void
5153

5254

5355
/**
54-
* @throws \h4kuna\Fio\Exceptions\InvalidArgument
56+
* @throws h4kuna\Fio\Exceptions\InvalidArgument
5557
*/
5658
public function testCheckIsInListThrow(): void
5759
{
@@ -66,7 +68,7 @@ public function testCheckLength(): void
6668

6769

6870
/**
69-
* @throws \h4kuna\Fio\Exceptions\InvalidArgument
71+
* @throws h4kuna\Fio\Exceptions\InvalidArgument
7072
*/
7173
public function testCheckLengthThrow(): void
7274
{

tests/src/Unit/Pay/Payment/EuroTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public function testMaximum(): void
3636
->setRemittanceInfo3('info 3')
3737
->setStreet('Street 44')
3838
->setCountry('jp')
39-
->setConstantSymbol(321)
39+
->setConstantSymbol('0321')
4040
->setCurrency('Usd')
4141
->setMyComment('Lorem ipsum')
4242
->setDate('2014-01-23')
4343
->setPaymentReason(110)
44-
->setSpecificSymbol(378)
45-
->setVariableSymbol(123456789)
44+
->setSpecificSymbol('0378')
45+
->setVariableSymbol('0123456789')
4646
->setPaymentType(Fio\Pay\Payment\Euro::PAYMENT_PRIORITY);
4747
$xml = $this->xmlFile->setData($pay)->getXml();
4848
Tester\Assert::equal(Fio\Tests\loadResult('payment/euro-maximum.xml'), $xml);

tests/src/Unit/Pay/Payment/NationalTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public function testMinimum(): void
4444
public function testMaximum(): void
4545
{
4646
$pay = $this->fioPay->createNational(1000, '987654/0123')
47-
->setConstantSymbol(321)
47+
->setConstantSymbol('321')
4848
->setCurrency('eur')
4949
->setMyComment('Lorem ipsum')
5050
->setDate('2014-01-23')
5151
->setPaymentReason(333)
5252
->setMessage('Hello Mr. Joe')
53-
->setSpecificSymbol(378)
54-
->setVariableSymbol(123456789)
53+
->setSpecificSymbol('378')
54+
->setVariableSymbol('0123456789')
5555
->setPaymentType(Fio\Pay\Payment\National::PAYMENT_PRIORITY);
5656
$xml = $this->xmlFile->setData($pay)->getXml();
5757

tests/src/bootstrap.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Nette\Utils\FileSystem;
66
use Nette\Utils\Json;
7-
use Nette\Utils\Strings;
87
use Tracy;
98
use Tester;
109

@@ -25,7 +24,7 @@
2524
function loadResult(string $name, $save = null)
2625
{
2726
$raw = false;
28-
if (Strings::startsWith($name, 'raw://')) {
27+
if (str_starts_with($name, 'raw://')) {
2928
$name = substr($name, 6);
3029
$raw = true;
3130
}

0 commit comments

Comments
 (0)