feat: implementation UsetrenoQRCodeProvider
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Remote\Edge\Exceptions;
|
||||
|
||||
class MissingParameterException extends \RuntimeException
|
||||
{
|
||||
|
||||
}
|
||||
62
src/Service/Remote/Edge/QRCodeEntityConverter.php
Normal file
62
src/Service/Remote/Edge/QRCodeEntityConverter.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Remote\Edge;
|
||||
|
||||
use App\Entity\QRCode\QRCode;
|
||||
use App\Entity\QRCode\QRCodeMoney;
|
||||
use App\Entity\QRCode\QRCodePaymentIdentification;
|
||||
use App\Entity\QRCode\QRCodeQROptions;
|
||||
use App\Entity\Remote\Usetreno\Edge\EdgeQRCode;
|
||||
use App\Entity\Remote\Usetreno\Edge\EdgeQRCodeMoney;
|
||||
use App\Entity\Remote\Usetreno\Edge\EdgeQRCodePaymentIdentification;
|
||||
use App\Entity\Remote\Usetreno\Edge\EdgeQRCodeQROptions;
|
||||
use App\Service\Remote\Edge\Exceptions\MissingParameterException;
|
||||
|
||||
class QRCodeEntityConverter
|
||||
{
|
||||
public function __construct() { }
|
||||
|
||||
public function convert(QRCode $code): EdgeQRCode {
|
||||
return new EdgeQRCode(
|
||||
$code->getIban() ?? throw new MissingParameterException("iban not set"),
|
||||
$code->getDueDate() ? $code->getDueDate()->format('Y-m-d') : throw new MissingParameterException("due date not set"),
|
||||
$code->getMessage() ?? throw new MissingParameterException("message not set"),
|
||||
$this->convertMoney($code->getMoney() ?? throw new MissingParameterException("money not set")),
|
||||
$this->convertCodeOptions($code->getCodeQROptions() ?? throw new MissingParameterException("codeQROptions not set")),
|
||||
$this->convertIdentification($code->getPaymentIdentification())
|
||||
);
|
||||
}
|
||||
|
||||
protected function convertMoney(QRCodeMoney $money): EdgeQRCodeMoney
|
||||
{
|
||||
return new EdgeQRCodeMoney(
|
||||
$money->getAmount() ?? throw new MissingParameterException("amount not set"),
|
||||
$money->getCurrency() ?? throw new MissingParameterException("currency not set")
|
||||
);
|
||||
}
|
||||
|
||||
protected function convertCodeOptions(QRCodeQROptions $options): EdgeQRCodeQROptions
|
||||
{
|
||||
return new EdgeQRCodeQROptions(
|
||||
$options->getScale(),
|
||||
$options->getMargin()
|
||||
);
|
||||
}
|
||||
|
||||
protected function convertIdentification(?QRCodePaymentIdentification $ident): EdgeQRCodePaymentIdentification {
|
||||
// OMG: proc? symboly v ostatnich statech nejsou, prijde me lepsi posilat NULL, nebo empty string ;-)
|
||||
return match ($ident) {
|
||||
null => new EdgeQRCodePaymentIdentification(
|
||||
"0",
|
||||
"0",
|
||||
"0"
|
||||
),
|
||||
default => new EdgeQRCodePaymentIdentification(
|
||||
$ident->getVariableSymbol() ?? "0",
|
||||
$ident->getSpecificSymbol() ?? "0",
|
||||
$ident->getConstantSymbol() ?? "0"
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user