Skip to content

Commit

Permalink
SUP-2 - One signservice logic concentration and cleanup (#15)
Browse files Browse the repository at this point in the history
* logic concentration and removal ofmultiple sign services

* futher updates

* merge readme organization
  • Loading branch information
IvanoCar authored Dec 15, 2023
1 parent 129c9e2 commit 25af7a0
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 273 deletions.
46 changes: 27 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
# (Under development) Austrian cash register fiscalization
# Austrian cash register fiscalization

**STILL UNDER ACTIVE DEVELOPMENT AND SHOULD NOT BE USED IN PRODUCTION**


------
Updating this package works like this:
- commit
- push to master
- create tag
- push tag
- webhook is triggered to send tag to PHP packages repo
- convert tag to release - exampple github action is on other repos


Other repos using this one will need to update their packages entry to use latest version.


------

**Please be aware this repository is still under active development** if you plan to use it in a production environment.


In Austria the fiscalization process is called Registrierkassensicherheitsverordnung (RKSV).


In this repository, we use about PrimeSign online sign feature.
In this repository, we use about PrimeSign online sign feature (via Cryptas).

What we took from them is a simple service which accepts RKSV payloads and then gives you a properly encrypted & signed response.
Worry free and fewer complications with signing receipts.
Expand Down Expand Up @@ -112,6 +96,30 @@ With new features please describe the changes you made within the pull request a
The project is open sourced under GNU v3.0 public licence.


### TODO and general

- implement proper unit tests which should cover hashing, encryption, qr code generation and other major-impact topics
- implement proper unit tests for entire process - normal sign, training sign and cancel sign + chaining of all those
- implement command which will gneerate the null reciept that can also be used
- documentation on code and RKSV process
- complete remove sign service factory and implement all logic inside a SignService class.
- revise all exeptions and poperly test them via unit tests
- revise all validators and see on what are needed and which can be added
- expand on info on how to incorporate into other peojects (if needed, discuss)


Updating this package works like this:
- commit
- push to master
- create tag
- push tag
- webhook is triggered to send tag to PHP packages repo
- convert tag to release - example github action is on other repos


Other repos using this one will need to update their packages entry to use latest version.


### About us

[Gamebay](https://gamebay.io) is a platform for managing gaming arenas, providing full support for running games and offering cash register solution as all in one software.
Expand Down
2 changes: 0 additions & 2 deletions src/Gamebay/RKSV/Services/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function __construct(string $encryptionKey)
/**
* @param ReceiptData $receiptData
* @return string
* Return will be given in base64 format of the encrypted string,
* but only the first 8 characters are taken into base64 conversion
*/
public function encryptSalesCounter(ReceiptData $receiptData): string
{
Expand Down
9 changes: 5 additions & 4 deletions src/Gamebay/RKSV/Services/ReceiptSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,18 @@ public function extractSignatureForQRCode($jws) {
*/
private function sign(string $signType)
{
$signInterface = $this->getSignService($signType);
$signInterface = $this->getSignService(self::NORMAL_SIGN_TYPE);


if ($signType == self::CANCEL_SIGN_TYPE){
$compactReceiptData = $signInterface->generateCompactReceiptData($this->primeSignCertificateNumber, 'U1RP'); // todo dont hardcode this
}
elseif ($signType == self::TRAINING_SIGN_TYPE){
} elseif ($signType == self::TRAINING_SIGN_TYPE){
$compactReceiptData = $signInterface->generateCompactReceiptData($this->primeSignCertificateNumber, 'VFJB'); // todo dont hardcode this
} elseif ($signType == self::NULL_SIGN_TYPE){
$compactReceiptData = $signInterface->generateCompactReceiptData($this->primeSignCertificateNumber, 'null'); // todo dont hardcode this
} else {
$compactReceiptData = $signInterface->generateCompactReceiptData($this->primeSignCertificateNumber, 'normal');
} // todo add also for null-reciept
}


$response = $signInterface->sign($compactReceiptData);
Expand Down
20 changes: 14 additions & 6 deletions src/Gamebay/RKSV/Services/SignServices/BaseSignService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class BaseSignService
protected string $locationId;

/**
* CancelSignService constructor.
* @param PrimeSignProvider $provider
* @param ReceiptData $receiptData
* @param string $encryptionKey
Expand Down Expand Up @@ -82,15 +81,24 @@ public function sign(string $compactReceiptData): Response
*/
public function generateCompactReceiptData(string $primeSignCertificateNumber, string $salesCounterType='normal'): string
{
$taxValues = implode('_', $this->receiptData->sumItemsByTaxes($this->taxRates));


if ($salesCounterType == 'normal') {
$encryptedSalesCounter = $this->encrypter->encryptSalesCounter($this->receiptData);
} else {
$encryptedSalesCounter = $this->encrypter->encryptSalesCounter($this->receiptData);
} else if ($salesCounterType == 'null') {
$nullItem = [
[
'brutto' => 0,
'tax' => 0
]
];
$this->receiptData->setItems($nullItem);
$this->receiptData->setSalesCounter(0.00);
$this->receiptData->setPreviousReceiptSignature($this->receiptData->getCashboxId());
$encryptedSalesCounter = $this->encrypter->encryptSalesCounter($this->receiptData);
} else { // if training or storno
$encryptedSalesCounter = $salesCounterType;
}

$taxValues = implode('_', $this->receiptData->sumItemsByTaxes($this->taxRates));
$previousCompactSignature = $this->encrypter->getCompactSignature($this->receiptData->getPreviousReceiptSignature());

return '_R1-' . $this->locationId .
Expand Down
41 changes: 0 additions & 41 deletions src/Gamebay/RKSV/Services/SignServices/CancelSignService.php

This file was deleted.

53 changes: 0 additions & 53 deletions src/Gamebay/RKSV/Services/SignServices/NullSignService.php

This file was deleted.

41 changes: 0 additions & 41 deletions src/Gamebay/RKSV/Services/SignServices/TrainingSignService.php

This file was deleted.

20 changes: 0 additions & 20 deletions tests/Unit/Services/EncrypterTest.php

This file was deleted.

87 changes: 0 additions & 87 deletions tests/Unit/Services/ReceiptSignerTest.php

This file was deleted.

0 comments on commit 25af7a0

Please sign in to comment.