Skip to content

Commit

Permalink
Fix symbols with leading zeroes, fixes #40 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Nov 23, 2021
1 parent ad759f1 commit 496b234
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/QrPayment.php
Expand Up @@ -139,13 +139,13 @@ public function getQrString(): string
$qrString .= sprintf('X-ID:%s*', $this->internalId);
}
if ($this->variableSymbol !== null) {
$qrString .= sprintf('X-VS:%d*', $this->variableSymbol);
$qrString .= sprintf('X-VS:%s*', $this->variableSymbol);
}
if ($this->specificSymbol !== null) {
$qrString .= sprintf('X-SS:%d*', $this->specificSymbol);
$qrString .= sprintf('X-SS:%s*', $this->specificSymbol);
}
if ($this->constantSymbol !== null) {
$qrString .= sprintf('X-KS:%d*', $this->constantSymbol);
$qrString .= sprintf('X-KS:%s*', $this->constantSymbol);
}
if ($this->payeeName !== null) {
$qrString .= sprintf('RN:%s*', $this->payeeName);
Expand Down
12 changes: 12 additions & 0 deletions tests/QrPaymentTest.php
Expand Up @@ -128,6 +128,10 @@ public function testVariableSymbol()
self::assertEquals('789', $this->instance->getVariableSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-VS:789", $this->instance->getQrString());

$this->instance->setVariableSymbol('001');
self::assertEquals('001', $this->instance->getVariableSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-VS:001", $this->instance->getQrString());

$this->expectException(TypeError::class);
$this->instance->setVariableSymbol([]);
}
Expand All @@ -145,6 +149,10 @@ public function testSpecificSymbol()
self::assertEquals('7890', $this->instance->getSpecificSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-SS:7890", $this->instance->getQrString());

$this->instance->setSpecificSymbol('001');
self::assertEquals('001', $this->instance->getSpecificSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-SS:001", $this->instance->getQrString());

$this->expectException(TypeError::class);
$this->instance->setSpecificSymbol([]);
}
Expand All @@ -162,6 +170,10 @@ public function testConstantSymbol()
self::assertEquals('741', $this->instance->getConstantSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-KS:741", $this->instance->getQrString());

$this->instance->setConstantSymbol('001');
self::assertEquals('001', $this->instance->getConstantSymbol());
self::assertEquals("{$this->getDefaultEmptyString()}*X-KS:001", $this->instance->getQrString());

$this->expectException(TypeError::class);
$this->instance->setConstantSymbol([]);
}
Expand Down

0 comments on commit 496b234

Please sign in to comment.