Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,336 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use Xentral\Modules\FiskalyApi\Exception\InvalidArgumentException;
|
||||
|
||||
class AmountsPerPaymentType
|
||||
{
|
||||
private $paymentType;
|
||||
|
||||
private $currencyCode;
|
||||
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* CashPointClosingPaymentType constructor.
|
||||
*
|
||||
* @param string $paymentType
|
||||
* @param string $amount
|
||||
* @param string|null $currencyCode
|
||||
*/
|
||||
public function __construct(
|
||||
string $paymentType,
|
||||
string $amount,
|
||||
?string $currencyCode = null
|
||||
) {
|
||||
$this->ensureType($paymentType);
|
||||
$this->ensureCurrency($currencyCode);
|
||||
$this->setType($paymentType);
|
||||
$this->setAmount($amount);
|
||||
$this->setCurrencyCode($currencyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getAllowedCurrencies(): array
|
||||
{
|
||||
return [
|
||||
'AED',
|
||||
'AFN',
|
||||
'ALL',
|
||||
'AMD',
|
||||
'ANG',
|
||||
'AOA',
|
||||
'ARS',
|
||||
'AUD',
|
||||
'AWG',
|
||||
'AZN',
|
||||
'BAM',
|
||||
'BBD',
|
||||
'BDT',
|
||||
'BGN',
|
||||
'BHD',
|
||||
'BIF',
|
||||
'BMD',
|
||||
'BND',
|
||||
'BOB',
|
||||
'BOV',
|
||||
'BRL',
|
||||
'BSD',
|
||||
'BTN',
|
||||
'BWP',
|
||||
'BYN',
|
||||
'BYR',
|
||||
'BZD',
|
||||
'CAD',
|
||||
'CDF',
|
||||
'CHE',
|
||||
'CHF',
|
||||
'CHW',
|
||||
'CLF',
|
||||
'CLP',
|
||||
'CN',
|
||||
'COP',
|
||||
'COU',
|
||||
'CRC',
|
||||
'CUC',
|
||||
'CUP',
|
||||
'CVE',
|
||||
'CZK',
|
||||
'DJF',
|
||||
'DKK',
|
||||
'DOP',
|
||||
'DZD',
|
||||
'EGP',
|
||||
'ERN',
|
||||
'ETB',
|
||||
'EUR',
|
||||
'FJD',
|
||||
'FKP',
|
||||
'GBP',
|
||||
'GEL',
|
||||
'GHS',
|
||||
'GIP',
|
||||
'GMD',
|
||||
'GNF',
|
||||
'GTQ',
|
||||
'GYD',
|
||||
'HKD',
|
||||
'HNL',
|
||||
'HRK',
|
||||
'HTG',
|
||||
'HUF',
|
||||
'IDR',
|
||||
'ILS',
|
||||
'INR',
|
||||
'IQD',
|
||||
'IRR',
|
||||
'ISK',
|
||||
'JMD',
|
||||
'JOD',
|
||||
'JPY',
|
||||
'KES',
|
||||
'KGS',
|
||||
'KHR',
|
||||
'KMF',
|
||||
'KPW',
|
||||
'KRW',
|
||||
'KWD',
|
||||
'KYD',
|
||||
'KZT',
|
||||
'LAK',
|
||||
'LBP',
|
||||
'LKR',
|
||||
'LRD',
|
||||
'LSL',
|
||||
'LYD',
|
||||
'MAD',
|
||||
'MDL',
|
||||
'MGA',
|
||||
'MKD',
|
||||
'MMK',
|
||||
'MNT',
|
||||
'MOP',
|
||||
'MRO',
|
||||
'MUR',
|
||||
'MVR',
|
||||
'MWK',
|
||||
'MXN',
|
||||
'MXV',
|
||||
'MYR',
|
||||
'MZN',
|
||||
'NAD',
|
||||
'NGN',
|
||||
'NIO',
|
||||
'NOK',
|
||||
'NPR',
|
||||
'NZD',
|
||||
'OMR',
|
||||
'PAB',
|
||||
'PEN',
|
||||
'PGK',
|
||||
'PHP',
|
||||
'PKR',
|
||||
'PLN',
|
||||
'PYG',
|
||||
'QAR',
|
||||
'RON',
|
||||
'RSD',
|
||||
'RUB',
|
||||
'RWF',
|
||||
'SAR',
|
||||
'SBD',
|
||||
'SCR',
|
||||
'SDG',
|
||||
'SSP',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'SHP',
|
||||
'SLL',
|
||||
'SOS',
|
||||
'SRD',
|
||||
'STD',
|
||||
'SVC',
|
||||
'SYP',
|
||||
'SZL',
|
||||
'THB',
|
||||
'TJS',
|
||||
'TMT',
|
||||
'TND',
|
||||
'TOP',
|
||||
'TRY',
|
||||
'TTD',
|
||||
'TWD',
|
||||
'TZS',
|
||||
'UAH',
|
||||
'UGX',
|
||||
'USD',
|
||||
'UYI',
|
||||
'UYU',
|
||||
'UZS',
|
||||
'VEF',
|
||||
'VND',
|
||||
'VUV',
|
||||
'WST',
|
||||
'XAF',
|
||||
'XCD',
|
||||
'XOF',
|
||||
'XPF',
|
||||
'XSU',
|
||||
'YER',
|
||||
'ZAR',
|
||||
'ZMW',
|
||||
'ZWL',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self(
|
||||
$apiResult->payment_type,
|
||||
$apiResult->amount,
|
||||
$apiResult->currency_code ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self(
|
||||
$dbState['payment_type'],
|
||||
$dbState['amount'],
|
||||
$dbState['currency_code'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = [
|
||||
'payment_type' => $this->getType(),
|
||||
'amount' => $this->getAmount(),
|
||||
'currency_code' => $this->getCurrencyCode(),
|
||||
];
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->paymentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType(string $type): void
|
||||
{
|
||||
$this->ensureType($type);
|
||||
$this->paymentType = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCurrencyCode(): ?string
|
||||
{
|
||||
return $this->currencyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $currencyCode
|
||||
*/
|
||||
public function setCurrencyCode(?string $currencyCode): void
|
||||
{
|
||||
$this->ensureCurrency($currencyCode);
|
||||
$this->currencyCode = $currencyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount(): string
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
*/
|
||||
public function setAmount(string $amount): void
|
||||
{
|
||||
if(!preg_match('/^-?\d+(\.\d{2,64})$/', $amount)) {
|
||||
throw new InvalidArgumentException("invalid amount-format: '{$amount}");
|
||||
}
|
||||
$this->amount = $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
private function ensureType(string $type): void
|
||||
{
|
||||
if (
|
||||
!in_array(
|
||||
$type,
|
||||
['CASH', 'NON_CASH']
|
||||
)) {
|
||||
throw new InvalidArgumentException("invalid paymentType {$type}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $currency
|
||||
*/
|
||||
private function ensureCurrency(?string $currency): void
|
||||
{
|
||||
if($currency === null) {
|
||||
return;
|
||||
}
|
||||
if (!in_array(
|
||||
$currency,
|
||||
self::getAllowedCurrencies(),
|
||||
true
|
||||
)) {
|
||||
throw new InvalidArgumentException("invalid currency {$currency}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
use Xentral\Modules\FiskalyApi\Data\CashPointClosing\AmountPerVatId;
|
||||
|
||||
class AmountsPerPaymentTypeCollection implements IteratorAggregate, Countable
|
||||
{
|
||||
/** @var AmountsPerPaymentType[] $paymentTypes */
|
||||
private $paymentTypes = [];
|
||||
|
||||
/**
|
||||
* CashPointClosingPaymentTypeCollection constructor.
|
||||
*
|
||||
* @param AmountsPerPaymentType[] $paymentTypes
|
||||
*/
|
||||
public function __construct(array $paymentTypes = [])
|
||||
{
|
||||
foreach ($paymentTypes as $paymentType) {
|
||||
$this->addPaymentType($paymentType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AmountsPerPaymentType $paymentType
|
||||
*/
|
||||
public function addPaymentType(AmountsPerPaymentType $paymentType): void
|
||||
{
|
||||
$this->paymentTypes[] = AmountsPerPaymentType::fromDbState($paymentType->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult($apiResult): self
|
||||
{
|
||||
$instance = new self();
|
||||
foreach ($apiResult as $item) {
|
||||
$instance->addPaymentType(AmountsPerPaymentType::fromApiResult($item));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
$instance = new self();
|
||||
foreach ($dbState as $item) {
|
||||
$instance->addPaymentType(AmountsPerPaymentType::fromDbState($item));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = [];
|
||||
/** @var AmountsPerPaymentType $item */
|
||||
foreach ($this as $item) {
|
||||
$dbState[] = $item->toArray();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AmountsPerPaymentType $paymentTypeCollection
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function combine(self $paymentTypeCollection): self
|
||||
{
|
||||
/** @var AmountsPerPaymentType $paymentType */
|
||||
foreach ($paymentTypeCollection as $paymentType) {
|
||||
$keys = $this->findKeysForType($paymentType);
|
||||
if (empty($keys)) {
|
||||
$this->addPaymentType($paymentType);
|
||||
continue;
|
||||
}
|
||||
$key = reset($keys);
|
||||
$amount = number_format(
|
||||
(float)$paymentType->getAmount() + (float)$this->paymentTypes[$key]->getAmount(),
|
||||
2,
|
||||
'.',
|
||||
''
|
||||
);
|
||||
$this->paymentTypes[$key]->setAmount($amount);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $paymentType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function filterByType(string $paymentType): self
|
||||
{
|
||||
$instance = new self();
|
||||
/** @var AmountsPerPaymentType $item */
|
||||
foreach($this as $item) {
|
||||
if($item->getType() === $paymentType) {
|
||||
$instance->addPaymentType($item);
|
||||
}
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getSum(string $currencyCode = 'EUR'): float
|
||||
{
|
||||
$sum = 0;
|
||||
/** @var AmountsPerPaymentType $item */
|
||||
foreach($this as $item) {
|
||||
if($item->getCurrencyCode() !== $currencyCode) {
|
||||
continue;
|
||||
}
|
||||
$sum += (float)$item->getAmount();
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrencyCodes(): array
|
||||
{
|
||||
$currencyCodes = [];
|
||||
/** @var AmountsPerPaymentType $item */
|
||||
foreach($this as $item) {
|
||||
$currencyCode = $item->getCurrencyCode();
|
||||
if(!in_array($currencyCode, $currencyCodes, true)) {
|
||||
$currencyCodes[] = $currencyCode;
|
||||
}
|
||||
}
|
||||
|
||||
return $currencyCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator(): ArrayIterator
|
||||
{
|
||||
return new ArrayIterator($this->paymentTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->paymentTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AmountsPerPaymentType $paymentTypeToFind
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function findKeysForType(AmountsPerPaymentType $paymentTypeToFind): array
|
||||
{
|
||||
$keys = [];
|
||||
/**
|
||||
* @var int $key
|
||||
* @var AmountsPerPaymentType $paymentType
|
||||
*/
|
||||
foreach ($this as $key => $paymentType) {
|
||||
if ($paymentType->getType() !== $paymentTypeToFind->getType()) {
|
||||
continue;
|
||||
}
|
||||
if ($paymentType->getCurrencyCode() !== $paymentTypeToFind->getCurrencyCode()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$keys[] = $key;
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use Xentral\Modules\FiskalyApi\Exception\InvalidArgumentException;
|
||||
|
||||
class AmountsPerVatType
|
||||
{
|
||||
/** @var string $vatRate */
|
||||
private $vatRate;
|
||||
|
||||
/** @var string $amount */
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* AmountsPerVatType constructor.
|
||||
*
|
||||
* @param string $vatRate
|
||||
* @param string $amount
|
||||
*/
|
||||
public function __construct(
|
||||
string $vatRate,
|
||||
string $amount
|
||||
) {
|
||||
$this->setVatRate($vatRate);
|
||||
$this->setAmount($amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self(
|
||||
$apiResult->vat_rate,
|
||||
$apiResult->amount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self(
|
||||
$dbState['vat_rate'],
|
||||
$dbState['amount']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = [
|
||||
'vat_rate' => $this->getVatRate(),
|
||||
'amount' => $this->getAmount(),
|
||||
];
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getVatRate(): string
|
||||
{
|
||||
return $this->vatRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $vatRate
|
||||
*/
|
||||
public function setVatRate(string $vatRate): void
|
||||
{
|
||||
if(!in_array($vatRate, ['NORMAL','REDUCED_1','SPECIAL_RATE_1','SPECIAL_RATE_2', 'NULL'])) {
|
||||
throw new InvalidArgumentException("invalid vatRate: '{$vatRate}");
|
||||
}
|
||||
$this->vatRate = $vatRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount(): string
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
*/
|
||||
public function setAmount(string $amount): void
|
||||
{
|
||||
if(!preg_match('/^-?\d+(\.\d{2,64})$/', $amount)) {
|
||||
throw new InvalidArgumentException("invalid amount-format: '{$amount}");
|
||||
}
|
||||
$this->amount = $amount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
|
||||
class AmountsPerVatTypeCollection implements IteratorAggregate, Countable
|
||||
{
|
||||
/** @var AmountsPerVatType[] $paymentTypes */
|
||||
private $paymentTypes = [];
|
||||
|
||||
/**
|
||||
* AmountsPerVatTypeCollection constructor.
|
||||
*
|
||||
* @param AmountsPerVatType[] $paymentTypes
|
||||
*/
|
||||
public function __construct(array $paymentTypes = [])
|
||||
{
|
||||
foreach ($paymentTypes as $paymentType) {
|
||||
$this->addPaymentType($paymentType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AmountsPerVatType $paymentType
|
||||
*/
|
||||
public function addPaymentType(AmountsPerVatType $paymentType): void
|
||||
{
|
||||
$this->paymentTypes[] = AmountsPerVatType::fromDbState($paymentType->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult($apiResult): self
|
||||
{
|
||||
$instance = new self();
|
||||
foreach ($apiResult as $item) {
|
||||
$instance->addPaymentType(AmountsPerVatType::fromApiResult($item));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
$instance = new self();
|
||||
foreach ($dbState as $item) {
|
||||
$instance->addPaymentType(AmountsPerVatType::fromDbState($item));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = [];
|
||||
/** @var AmountsPerVatType $item */
|
||||
foreach ($this as $item) {
|
||||
$dbState[] = $item->toArray();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AmountsPerVatType $amountsPerVatType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function combine(self $amountsPerVatType): self
|
||||
{
|
||||
/** @var AmountsPerVatType $amountPerVatRate */
|
||||
foreach($amountsPerVatType as $amountPerVatRate) {
|
||||
$keys = $this->findKeysForType($amountPerVatRate);
|
||||
if(empty($keys)) {
|
||||
$this->addPaymentType($amountPerVatRate);
|
||||
continue;
|
||||
}
|
||||
$key = reset($keys);
|
||||
$amount = (float)$this->paymentTypes[$key]->getAmount() + (float)$amountPerVatRate->getAmount();
|
||||
$this->paymentTypes[$key]->setAmount(
|
||||
number_format($amount, 2, '.', '')
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AmountsPerVatType $paymentTypeToFind
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function findKeysForType(AmountsPerVatType $paymentTypeToFind): array
|
||||
{
|
||||
$keys = [];
|
||||
/**
|
||||
* @var int $key
|
||||
* @var AmountsPerVatType $amountPerVatRate
|
||||
*/
|
||||
foreach($this as $key => $amountPerVatRate) {
|
||||
if($amountPerVatRate->getVatRate() !== $paymentTypeToFind->getVatRate()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$keys[] = $key;
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator(): ArrayIterator
|
||||
{
|
||||
return new ArrayIterator($this->paymentTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->paymentTypes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use Xentral\Modules\FiskalyApi\Exception\InvalidArgumentException;
|
||||
|
||||
class OrderLineItem
|
||||
{
|
||||
/** @var string $quantity */
|
||||
private $quantity;
|
||||
|
||||
/** @var string $text */
|
||||
private $text;
|
||||
|
||||
/** @var string $pricePerUnit */
|
||||
private $pricePerUnit;
|
||||
|
||||
/**
|
||||
* OrderLineItem constructor.
|
||||
*
|
||||
* @param string $quantity
|
||||
* @param string $text
|
||||
* @param string $pricePerUnit
|
||||
*/
|
||||
public function __construct(string $quantity, string $text, string $pricePerUnit)
|
||||
{
|
||||
$this->setQuantity($quantity);
|
||||
$this->setText($text);
|
||||
$this->setPricePerUnit($pricePerUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self($apiResult->quantity, $apiResult->text, $apiResult->price_per_unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self($dbState['quantity'], $dbState['text'], $dbState['price_per_unit']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'quantity' => $this->getQuantity(),
|
||||
'text' => $this->getText(),
|
||||
'price_per_unit' => $this->getPricePerUnit(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQuantity(): string
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $quantity
|
||||
*/
|
||||
public function setQuantity(string $quantity): void
|
||||
{
|
||||
if (!preg_match('/^-?\d+(\.\d{1,64})?$/', $quantity)) {
|
||||
throw new InvalidArgumentException("invalid quantity-format '{$quantity}'");
|
||||
}
|
||||
$this->quantity = $quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getText(): string
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText(string $text): void
|
||||
{
|
||||
$this->text = mb_substr($text, 0, 255);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPricePerUnit(): string
|
||||
{
|
||||
return $this->pricePerUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pricePerUnit
|
||||
*/
|
||||
public function setPricePerUnit(string $pricePerUnit): void
|
||||
{
|
||||
if (!preg_match('/^-?\d+(\.\d{2,64})?$/', $pricePerUnit)) {
|
||||
throw new InvalidArgumentException("invalid price-format '{$pricePerUnit}'");
|
||||
}
|
||||
$this->pricePerUnit = $pricePerUnit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
|
||||
class OrderLineItemCollection implements IteratorAggregate, Countable
|
||||
{
|
||||
/** @var OrderLineItem[] $lineItems */
|
||||
private $lineItems = [];
|
||||
|
||||
/**
|
||||
* OrderLineItemCollection constructor.
|
||||
*
|
||||
* @param array $lineItems
|
||||
*/
|
||||
public function __construct(array $lineItems = [])
|
||||
{
|
||||
foreach($lineItems as $lineItem) {
|
||||
$this->addLineItem($lineItem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
$instance = new self();
|
||||
foreach($apiResult as $item) {
|
||||
$instance->addLineItem(OrderLineItem::fromApiResult($item));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState = []): self
|
||||
{
|
||||
$instance = new self();
|
||||
foreach($dbState as $item) {
|
||||
$instance->addLineItem(OrderLineItem::fromDbState($item));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = [];
|
||||
foreach($this as $item) {
|
||||
$dbState[] = $item->toArray();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
public function addLineItem(OrderLineItem $lineItem): void
|
||||
{
|
||||
$this->lineItems[] = OrderLineItem::fromDbState($lineItem->toArray());;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->lineItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator(): ArrayIterator
|
||||
{
|
||||
return new ArrayIterator($this->lineItems);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
class SchemaOrder
|
||||
{
|
||||
/** @var OrderLineItemCollection $lineItems */
|
||||
private $lineItems;
|
||||
|
||||
/**
|
||||
* SchemaOther constructor.
|
||||
*/
|
||||
public function __construct(OrderLineItemCollection $lineItemCollection)
|
||||
{
|
||||
$this->setLineItems($lineItemCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self(OrderLineItemCollection::fromApiResult($apiResult->line_items));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self(OrderLineItemCollection::fromDbState($dbState['line_items']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return ['line_items' => $this->lineItems->toArray()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrderLineItemCollection
|
||||
*/
|
||||
public function getLineItems(): OrderLineItemCollection
|
||||
{
|
||||
return OrderLineItemCollection::fromDbState($this->lineItems->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderLineItemCollection $lineItems
|
||||
*/
|
||||
public function setLineItems(OrderLineItemCollection $lineItems): void
|
||||
{
|
||||
$this->lineItems = OrderLineItemCollection::fromDbState($lineItems->toArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
class SchemaOther
|
||||
{
|
||||
/**
|
||||
* SchemaOther constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
class SchemaRaw
|
||||
{
|
||||
/** @var string $processData */
|
||||
private $processData;
|
||||
|
||||
/** @var string|null $processType */
|
||||
private $processType;
|
||||
|
||||
/**
|
||||
* SchemaRaw constructor.
|
||||
*
|
||||
* @param string $processData
|
||||
* @param string|null $processType
|
||||
*/
|
||||
public function __construct(string $processData, ?string $processType = null)
|
||||
{
|
||||
$this->setProcessData($processData);
|
||||
$this->setProcessType($processType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self($apiResult->process_data, $apiResult->process_type ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self($dbState['process_data'], $dbState['process_type'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = ['process_data' => $this->getProcessData()];
|
||||
if($this->processType !== null) {
|
||||
$dbState['process_type'] = $this->getProcessType();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProcessData(): string
|
||||
{
|
||||
return $this->processData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $processData
|
||||
*/
|
||||
public function setProcessData(string $processData): void
|
||||
{
|
||||
$this->processData = $processData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getProcessType(): ?string
|
||||
{
|
||||
return $this->processType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $processType
|
||||
*/
|
||||
public function setProcessType(?string $processType): void
|
||||
{
|
||||
$this->processType = $processType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use Xentral\Modules\FiskalyApi\Exception\InvalidArgumentException;
|
||||
|
||||
class SchemaReceipt
|
||||
{
|
||||
/** @var string $receipType */
|
||||
private $receiptType;
|
||||
|
||||
/** @var AmountsPerVatTypeCollection $amountsPerVatRate */
|
||||
private $amountsPerVatRate;
|
||||
|
||||
/** @var AmountsPerPaymentTypeCollection $amountsPerPaymentType */
|
||||
private $amountsPerPaymentType;
|
||||
|
||||
/**
|
||||
* SchemaReceipt constructor.
|
||||
*
|
||||
* @param string $receiptType
|
||||
* @param AmountsPerVatTypeCollection $amountsPerVatId
|
||||
* @param AmountsPerPaymentTypeCollection $amountsPerPaymentType
|
||||
*/
|
||||
public function __construct(
|
||||
string $receiptType,
|
||||
AmountsPerVatTypeCollection $amountsPerVatId,
|
||||
AmountsPerPaymentTypeCollection $amountsPerPaymentType
|
||||
) {
|
||||
$this->setReceiptType($receiptType);
|
||||
$this->setAmountsPerVatRate($amountsPerVatId);
|
||||
$this->setAmountsPerPaymentType($amountsPerPaymentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self(
|
||||
$apiResult->receipt_type,
|
||||
AmountsPerVatTypeCollection::fromApiResult($apiResult->amounts_per_vat_rate),
|
||||
AmountsPerPaymentTypeCollection::fromApiResult($apiResult->amounts_per_payment_type)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self(
|
||||
$dbState['receipt_type'],
|
||||
AmountsPerVatTypeCollection::fromDbState($dbState['amounts_per_vat_rate']),
|
||||
AmountsPerPaymentTypeCollection::fromDbState($dbState['amounts_per_payment_type'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'receipt_type' => $this->getReceiptType(),
|
||||
'amounts_per_vat_rate' => $this->amountsPerVatRate->toArray(),
|
||||
'amounts_per_payment_type' => $this->amountsPerPaymentType->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReceiptType(): string
|
||||
{
|
||||
return $this->receiptType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $receiptType
|
||||
*/
|
||||
public function setReceiptType(string $receiptType): void
|
||||
{
|
||||
$this->ensureType($receiptType);
|
||||
$this->receiptType = $receiptType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AmountsPerVatTypeCollection
|
||||
*/
|
||||
public function getAmountsPerVatRate(): AmountsPerVatTypeCollection
|
||||
{
|
||||
return AmountsPerVatTypeCollection::fromDbState($this->amountsPerVatRate->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AmountsPerVatTypeCollection $amountsPerVatRate
|
||||
*/
|
||||
public function setAmountsPerVatRate(AmountsPerVatTypeCollection $amountsPerVatRate): void
|
||||
{
|
||||
$this->amountsPerVatRate = AmountsPerVatTypeCollection::fromDbState($amountsPerVatRate->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AmountsPerPaymentTypeCollection
|
||||
*/
|
||||
public function getAmountsPerPaymentType(): AmountsPerPaymentTypeCollection
|
||||
{
|
||||
return AmountsPerPaymentTypeCollection::fromDbState($this->amountsPerPaymentType->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AmountsPerPaymentTypeCollection $amountsPerPaymentType
|
||||
*/
|
||||
public function setAmountsPerPaymentType(AmountsPerPaymentTypeCollection $amountsPerPaymentType): void
|
||||
{
|
||||
$this->amountsPerPaymentType = AmountsPerPaymentTypeCollection::fromDbState($amountsPerPaymentType->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
private function ensureType(string $type): void
|
||||
{
|
||||
if (in_array(
|
||||
$type,
|
||||
[
|
||||
'RECEIPT',
|
||||
'TRAINING',
|
||||
'TRANSFER',
|
||||
'ORDER',
|
||||
'CANCELLATION',
|
||||
'ABORT',
|
||||
'BENEFIT_IN_KIND',
|
||||
'INVOICE',
|
||||
'OTHER',
|
||||
'ANNULATION',
|
||||
]
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
throw new InvalidArgumentException("invalid Type '{$type}'");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
class SchemaStandardV1
|
||||
{
|
||||
/** @var SchemaReceipt|null $receipt */
|
||||
private $receipt;
|
||||
|
||||
/** @var SchemaOrder|null $order */
|
||||
private $order;
|
||||
|
||||
/** @var SchemaOther|null $other */
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* SchemaStandardV1 constructor.
|
||||
*
|
||||
* @param SchemaReceipt|null $receipt
|
||||
* @param SchemaOrder|null $order
|
||||
* @param SchemaOther|null $other
|
||||
*/
|
||||
public function __construct(?SchemaReceipt $receipt, ?SchemaOrder $order = null, ?SchemaOther $other = null)
|
||||
{
|
||||
$this->setReceipt($receipt);
|
||||
$this->setOrder($order);
|
||||
$this->setOther($other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self(
|
||||
empty($apiResult->receipt) ? null : SchemaReceipt::fromApiResult($apiResult->receipt),
|
||||
empty($apiResult->order) ? null : SchemaOrder::fromApiResult($apiResult->order),
|
||||
empty($apiResult->other) ? null : SchemaOther::fromApiResult($apiResult->other)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self(
|
||||
empty($dbState['receipt']) ? null : SchemaReceipt::fromDbState($dbState['receipt']),
|
||||
empty($dbState['order']) ? null : SchemaOrder::fromDbState($dbState['order']),
|
||||
empty($dbState['other']) ? null : SchemaOther::fromDbState($dbState['other'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = [];
|
||||
if($this->receipt !== null) {
|
||||
$dbState['receipt'] = $this->receipt->toArray();
|
||||
}
|
||||
if($this->order !== null) {
|
||||
$dbState['order'] = $this->order->toArray();
|
||||
}
|
||||
if($this->other !== null) {
|
||||
$dbState['other'] = $this->other->toArray();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SchemaReceipt|null
|
||||
*/
|
||||
public function getReceipt(): ?SchemaReceipt
|
||||
{
|
||||
return $this->receipt === null ? null : SchemaReceipt::fromDbState($this->receipt->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SchemaReceipt|null $receipt
|
||||
*/
|
||||
public function setReceipt(?SchemaReceipt $receipt): void
|
||||
{
|
||||
$this->receipt = $receipt === null ? null : SchemaReceipt::fromDbState($receipt->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SchemaOrder|null
|
||||
*/
|
||||
public function getOrder(): ?SchemaOrder
|
||||
{
|
||||
return $this->order === null ? null : SchemaOrder::fromDbState($this->order->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SchemaOrder|null $order
|
||||
*/
|
||||
public function setOrder(?SchemaOrder $order): void
|
||||
{
|
||||
$this->order = $order === null ? null : SchemaOrder::fromDbState($order->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SchemaOther|null
|
||||
*/
|
||||
public function getOther(): ?SchemaOther
|
||||
{
|
||||
return $this->other === null ? null : SchemaOther::fromDbState($this->other->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SchemaOther|null $other
|
||||
*/
|
||||
public function setOther(?SchemaOther $other): void
|
||||
{
|
||||
$this->other = $other === null ? null : SchemaOther::fromDbState($other->toArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use stdClass;
|
||||
use Xentral\Modules\FiskalyApi\Data\MetaData;
|
||||
use Xentral\Modules\FiskalyApi\Exception\InvalidArgumentException;
|
||||
|
||||
class Transaction
|
||||
{
|
||||
/** @var string $state */
|
||||
protected $state;
|
||||
|
||||
/** @var string $clientId */
|
||||
protected $clientId;
|
||||
|
||||
/** @var TransactionSchema|null $schema */
|
||||
protected $schema;
|
||||
|
||||
/** @var MetaData|null $metaData */
|
||||
protected $metaData;
|
||||
|
||||
/**
|
||||
* Transaction constructor.
|
||||
*
|
||||
* @param string $state
|
||||
* @param string $clientId
|
||||
* @param TransactionSchema|null $schema
|
||||
* @param MetaData|null $metaData
|
||||
*/
|
||||
public function __construct(string $state, string $clientId, ?TransactionSchema $schema = null, ?MetaData $metaData = null)
|
||||
{
|
||||
$this->setState($state);
|
||||
$this->setClientId($clientId);
|
||||
$this->setSchema($schema);
|
||||
$this->setMetaData($metaData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult)
|
||||
{
|
||||
return new self(
|
||||
$apiResult->state,
|
||||
$apiResult->client_id,
|
||||
empty($apiResult->schema) ? null : TransactionSchema::fromApiResult($apiResult->schema),
|
||||
empty($apiResult->metadata) ? null : MetaData::fromApiResult($apiResult->metadata)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return Transaction
|
||||
*/
|
||||
public static function fromDbState(array $dbState)
|
||||
{
|
||||
return new self(
|
||||
$dbState['state'],
|
||||
$dbState['client_id'],
|
||||
empty($dbState['schema']) ? null : TransactionSchema::fromDbState($dbState['schema']),
|
||||
empty($dbState['metadata']) ? null : MetaData::fromDbState($dbState['metadata'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = ['state' => $this->getState(), 'client_id' => $this->getClientId()];
|
||||
if($this->schema !== null) {
|
||||
$dbState['schema'] = $this->schema->toArray();
|
||||
}
|
||||
if($this->metaData !== null) {
|
||||
$dbState['metadata'] = $this->metaData->toArray();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return stdClass
|
||||
*/
|
||||
public function toApiResult()
|
||||
{
|
||||
$apiResult = new stdClass();
|
||||
$apiResult->state = $this->getState();
|
||||
$apiResult->client_id = $this->getClientId();
|
||||
if($this->schema !== null) {
|
||||
$apiResult->schema = $this->schema->toApiResult();
|
||||
}
|
||||
if($this->metaData !== null) {
|
||||
$apiResult->metadata = $this->metaData->toApiResult();
|
||||
}
|
||||
|
||||
return $apiResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getState(): string
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $state
|
||||
*/
|
||||
public function setState(string $state): void
|
||||
{
|
||||
$this->ensureState($state);
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getClientId(): string
|
||||
{
|
||||
return $this->clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientId
|
||||
*/
|
||||
public function setClientId(string $clientId): self
|
||||
{
|
||||
$this->clientId = $clientId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionSchema|null
|
||||
*/
|
||||
public function getSchema(): ?TransactionSchema
|
||||
{
|
||||
return $this->schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionSchema|null $schema
|
||||
*/
|
||||
public function setSchema(?TransactionSchema $schema): void
|
||||
{
|
||||
$this->schema = $schema === null ? null : TransactionSchema::fromDbState($schema->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MetaData|null
|
||||
*/
|
||||
public function getMetaData(): ?MetaData
|
||||
{
|
||||
return $this->metaData === null ? null : MetaData::fromDbState($this->metaData->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MetaData|null $metaData
|
||||
*/
|
||||
public function setMetaData(?MetaData $metaData): void
|
||||
{
|
||||
$this->metaData = $metaData === null ? null : MetaData::fromDbState($metaData->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $state
|
||||
*/
|
||||
private function ensureState(string $state):void
|
||||
{
|
||||
if(!in_array($state, ['ACTIVE', 'CANCELLED', 'FINISHED'])) {
|
||||
throw new InvalidArgumentException("invalid state '{$state}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeZone;
|
||||
use DateTime;
|
||||
use stdClass;
|
||||
|
||||
class TransactionLog
|
||||
{
|
||||
/** @var string $operation */
|
||||
private $operation;
|
||||
|
||||
/** @var DateTimeInterface $timestamp */
|
||||
private $timestamp;
|
||||
|
||||
/** @var string $timestampFormat */
|
||||
private $timestampFormat;
|
||||
|
||||
/**
|
||||
* TransactionLog constructor.
|
||||
*
|
||||
* @param string $operation
|
||||
* @param DateTimeInterface $timestamp
|
||||
* @param string $timestampFormat
|
||||
*/
|
||||
public function __construct(string $operation, DateTimeInterface $timestamp, string $timestampFormat = 'utcTime')
|
||||
{
|
||||
$this->setOperation($operation);
|
||||
$this->setTimestamp($timestamp);
|
||||
$this->setTimestampFormat($timestampFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self(
|
||||
$apiResult->operation,
|
||||
(new DateTime('now', new DateTimeZone('UTC')))->setTimestamp($apiResult->timestamp),
|
||||
$apiResult->timestamp_format
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self(
|
||||
$dbState['operation'],
|
||||
(new DateTime('now', new DateTimeZone('UTC')))->setTimestamp($dbState['timestamp']),
|
||||
$dbState['timestamp_format']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'operation' => $this->getOperation(),
|
||||
'timestamp' => $this->getTimestamp()->getTimestamp(),
|
||||
'timestamp_format' => $this->getTimestampFormat(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return stdClass
|
||||
*/
|
||||
public function toApiResult(): stdClass
|
||||
{
|
||||
$apiResult = new stdClass();
|
||||
$apiResult->operation = $this->getOperation();
|
||||
$apiResult->timestamp = $this->getTimestamp()->getTimestamp();
|
||||
$apiResult->timestamp_format = $this->getTimestampFormat();
|
||||
|
||||
return $apiResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOperation(): string
|
||||
{
|
||||
return $this->operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $operation
|
||||
*/
|
||||
public function setOperation(string $operation): void
|
||||
{
|
||||
$this->operation = $operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTimeInterface
|
||||
*/
|
||||
public function getTimestamp(): DateTimeInterface
|
||||
{
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTimeInterface $timestamp
|
||||
*/
|
||||
public function setTimestamp(DateTimeInterface $timestamp): void
|
||||
{
|
||||
$this->timestamp = $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTimestampFormat(): string
|
||||
{
|
||||
return $this->timestampFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $timestampFormat
|
||||
*/
|
||||
public function setTimestampFormat(string $timestampFormat): void
|
||||
{
|
||||
$this->timestampFormat = $timestampFormat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,527 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use stdClass;
|
||||
use Xentral\Modules\FiskalyApi\Data\MetaData;
|
||||
|
||||
class TransactionReponse extends Transaction
|
||||
{
|
||||
/** @var int|null $number */
|
||||
private $number;
|
||||
|
||||
/** @var string|null */
|
||||
private $qrCodeData;
|
||||
|
||||
/** @var DateTimeInterface|null $timeStart */
|
||||
private $timeStart;
|
||||
|
||||
/** @var DateTimeInterface|null $timeStart */
|
||||
private $timeEnd;
|
||||
|
||||
/** @var string|null $clientSerialNumber */
|
||||
private $clientSerialNumber;
|
||||
|
||||
/** @var string|null $certificateSerial */
|
||||
private $certificateSerial;
|
||||
|
||||
/** @var int|null $revision */
|
||||
private $revision;
|
||||
|
||||
/** @var int|null $latestRevision */
|
||||
private $latestRevision;
|
||||
|
||||
/** @var TransactionLog|null $log */
|
||||
private $log;
|
||||
|
||||
/** @var TransactionSignature|null $signature */
|
||||
private $signature;
|
||||
|
||||
/** @var string|null $tssId */
|
||||
private $tssId;
|
||||
|
||||
/** @var string|null $_type */
|
||||
private $_type;
|
||||
|
||||
/** @var string|null $_id */
|
||||
private $_id;
|
||||
|
||||
/** @var string|null $_env */
|
||||
private $_env;
|
||||
|
||||
/** @var string|null $_version */
|
||||
private $_version;
|
||||
|
||||
|
||||
public function __construct(
|
||||
string $state,
|
||||
string $clientId,
|
||||
?TransactionSchema $schema = null,
|
||||
?MetaData $metaData = null,
|
||||
?int $number = null,
|
||||
?DateTimeInterface $timeStart = null,
|
||||
?DateTimeInterface $timeEnd = null,
|
||||
?string $clientSerialNumber = null,
|
||||
?string $certificateSerial = null,
|
||||
?string $qrCodeData = null,
|
||||
?int $revision = null,
|
||||
?int $latestRevision = null,
|
||||
?TransactionLog $log = null,
|
||||
?TransactionSignature $signature = null,
|
||||
?string $tssId = null,
|
||||
?string $type = null,
|
||||
?string $uuId = null,
|
||||
?string $env = null,
|
||||
?string $vesion = null
|
||||
) {
|
||||
parent::__construct($state, $clientId, $schema, $metaData);
|
||||
$this->setNumber($number);
|
||||
$this->setTimeStart($timeStart);
|
||||
$this->setTimeEnd($timeEnd);
|
||||
$this->setClientSerialNumber($clientSerialNumber);
|
||||
$this->setCertificateSerial($certificateSerial);
|
||||
$this->setQrCodeData($qrCodeData);
|
||||
$this->setRevision($revision);
|
||||
$this->setLatestRevision($latestRevision);
|
||||
$this->setLog($log);
|
||||
$this->setSignature($signature);
|
||||
$this->setTssId($tssId);
|
||||
$this->setType($type);
|
||||
$this->setId($uuId);
|
||||
$this->setEnv($env);
|
||||
$this->setVersion($vesion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return Transaction
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): TransactionReponse
|
||||
{
|
||||
return new self(
|
||||
$apiResult->state,
|
||||
$apiResult->client_id,
|
||||
empty($apiResult->schema) ? null : TransactionSchema::fromApiResult($apiResult->schema),
|
||||
empty($apiResult->metadata) ? null : MetaData::fromApiResult($apiResult->metadata),
|
||||
isset($apiResult->number) ? (int)$apiResult->number : null,
|
||||
!empty($apiResult->time_start) ? (new DateTime('now', new DateTimeZone('UTC')))->setTimestamp(
|
||||
$apiResult->time_start
|
||||
) : null,
|
||||
!empty($apiResult->time_end) ? (new DateTime('now', new DateTimeZone('UTC')))->setTimestamp(
|
||||
$apiResult->time_end
|
||||
) : null,
|
||||
$apiResult->client_serial_number ?? null,
|
||||
$apiResult->certificate_serial ?? null,
|
||||
$apiResult->qr_code_data ?? null,
|
||||
isset($apiResult->revision) ? (int)$apiResult->revision : null,
|
||||
isset($apiResult->latest_revision) ? (int)$apiResult->latest_revision : null,
|
||||
!empty($apiResult->log) ? TransactionLog::fromApiResult($apiResult->log) : null,
|
||||
!empty($apiResult->signature) ? TransactionSignature::fromApiResult($apiResult->signature) : null,
|
||||
$apiResult->tss_id ?? null,
|
||||
$apiResult->_type ?? null,
|
||||
$apiResult->_id ?? null,
|
||||
$apiResult->_env ?? null,
|
||||
$apiResult->_version ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return Transaction
|
||||
*/
|
||||
public static function fromDbState(array $dbState): TransactionReponse
|
||||
{
|
||||
return new self(
|
||||
$dbState['state'],
|
||||
$dbState['client_id'],
|
||||
empty($dbState['schema']) ? null : TransactionSchema::fromDbState($dbState['schema']),
|
||||
!isset($dbState['metadata']) ? null : MetaData::fromDbState($dbState['metadata']),
|
||||
isset($dbState['number']) ? (int)$dbState['number'] : null,
|
||||
!empty($dbState['time_start']) ? (new DateTime('now', new DateTimeZone('UTC')))->setTimestamp(
|
||||
$dbState['time_start']
|
||||
) : null,
|
||||
!empty($dbState['time_end']) ? (new DateTime('now', new DateTimeZone('UTC')))->setTimestamp(
|
||||
$dbState['time_end']
|
||||
) : null,
|
||||
$dbState['client_serial_number'] ?? null,
|
||||
$dbState['certificate_serial'] ?? null,
|
||||
$dbState['qr_code_data'] ?? null,
|
||||
isset($dbState['revision']) ? (int)$dbState['revision'] : null,
|
||||
isset($dbState['latest_revision']) ? (int)$dbState['latest_revision'] : null,
|
||||
!empty($dbState['log']) ? TransactionLog::fromDbState($dbState['log']) : null,
|
||||
!empty($dbState['signature']) ? TransactionSignature::fromDbState($dbState['signature']) : null,
|
||||
$dbState['tss_id'] ?? null,
|
||||
$dbState['_type'] ?? null,
|
||||
$dbState['_id'] ?? null,
|
||||
$dbState['_env'] ?? null,
|
||||
$dbState['_version'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = parent::toArray();
|
||||
if ($this->number !== null) {
|
||||
$dbState['number'] = $this->getNumber();
|
||||
}
|
||||
if ($this->timeStart !== null) {
|
||||
$dbState['time_start'] = $this->timeStart->getTimestamp();
|
||||
}
|
||||
if ($this->timeEnd !== null) {
|
||||
$dbState['time_end'] = $this->timeEnd->getTimestamp();
|
||||
}
|
||||
if ($this->clientSerialNumber !== null) {
|
||||
$dbState['client_serial_number'] = $this->getClientSerialNumber();
|
||||
}
|
||||
if ($this->certificateSerial !== null) {
|
||||
$dbState['certificate_serial'] = $this->getCertificateSerial();
|
||||
}
|
||||
if ($this->qrCodeData !== null) {
|
||||
$dbState['qr_code_data'] = $this->getQrCodeData();
|
||||
}
|
||||
if ($this->revision !== null) {
|
||||
$dbState['revision'] = $this->getRevision();
|
||||
}
|
||||
if ($this->latestRevision !== null) {
|
||||
$dbState['latest_revision'] = $this->getLatestRevision();
|
||||
}
|
||||
if ($this->tssId !== null) {
|
||||
$dbState['tss_id'] = $this->getTssId();
|
||||
}
|
||||
if ($this->log !== null) {
|
||||
$dbState['log'] = $this->log->toArray();
|
||||
}
|
||||
if ($this->signature !== null) {
|
||||
$dbState['signature'] = $this->signature->toArray();
|
||||
}
|
||||
if ($this->tssId !== null) {
|
||||
$dbState['tss_id'] = $this->getTssId();
|
||||
}
|
||||
if ($this->metaData !== null) {
|
||||
$dbState['metadata'] = $this->metaData->toArray();
|
||||
}
|
||||
if ($this->_type !== null) {
|
||||
$dbState['_type'] = $this->getType();
|
||||
}
|
||||
if ($this->_id !== null) {
|
||||
$dbState['_id'] = $this->getId();
|
||||
}
|
||||
if ($this->_version !== null) {
|
||||
$dbState['_version'] = $this->getVersion();
|
||||
}
|
||||
if ($this->_env !== null) {
|
||||
$dbState['_env'] = $this->getEnv();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return stdClass
|
||||
*/
|
||||
public function toApiResult()
|
||||
{
|
||||
$apiResult = parent::toApiResult();
|
||||
if ($this->number !== null) {
|
||||
$apiResult->number = $this->getNumber();
|
||||
}
|
||||
if ($this->timeStart !== null) {
|
||||
$apiResult->time_start = $this->timeStart->getTimestamp();
|
||||
}
|
||||
if ($this->timeEnd !== null) {
|
||||
$apiResult->time_end = $this->timeEnd->getTimestamp();
|
||||
}
|
||||
if ($this->clientSerialNumber !== null) {
|
||||
$apiResult->client_serial_number = $this->getClientSerialNumber();
|
||||
}
|
||||
if ($this->certificateSerial !== null) {
|
||||
$apiResult->certificate_serial = $this->getCertificateSerial();
|
||||
}
|
||||
if ($this->qrCodeData !== null) {
|
||||
$apiResult->qr_code_data = $this->getQrCodeData();
|
||||
}
|
||||
if ($this->revision !== null) {
|
||||
$apiResult->revision = $this->getRevision();
|
||||
}
|
||||
if ($this->latestRevision !== null) {
|
||||
$apiResult->latest_revision = $this->getLatestRevision();
|
||||
}
|
||||
if ($this->tssId !== null) {
|
||||
$apiResult->tss_id = $this->getTssId();
|
||||
}
|
||||
if ($this->log !== null) {
|
||||
$apiResult->log = $this->log->toApiResult();
|
||||
}
|
||||
if ($this->signature !== null) {
|
||||
$apiResult->signature = $this->signature->toApiResult();
|
||||
}
|
||||
if ($this->tssId !== null) {
|
||||
$apiResult->tss_id = $this->getTssId();
|
||||
}
|
||||
if ($this->metaData !== null) {
|
||||
$apiResult->metadata = $this->metaData->toApiResult();
|
||||
}
|
||||
if ($this->_type !== null) {
|
||||
$apiResult->_type = $this->getType();
|
||||
}
|
||||
if ($this->_id !== null) {
|
||||
$apiResult->_id = $this->getId();
|
||||
}
|
||||
if ($this->_version !== null) {
|
||||
$apiResult->_version = $this->getVersion();
|
||||
}
|
||||
if ($this->_env !== null) {
|
||||
$apiResult->_env = $this->getEnv();
|
||||
}
|
||||
|
||||
return $apiResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getNumber(): ?int
|
||||
{
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $number
|
||||
*/
|
||||
public function setNumber(?int $number): void
|
||||
{
|
||||
$this->number = $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getQrCodeData(): ?string
|
||||
{
|
||||
return $this->qrCodeData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $qrCodeData
|
||||
*/
|
||||
public function setQrCodeData(?string $qrCodeData): void
|
||||
{
|
||||
$this->qrCodeData = $qrCodeData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTimeInterface|null
|
||||
*/
|
||||
public function getTimeStart(): ?DateTimeInterface
|
||||
{
|
||||
return $this->timeStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTimeInterface|null $timeStart
|
||||
*/
|
||||
public function setTimeStart(?DateTimeInterface $timeStart): void
|
||||
{
|
||||
$this->timeStart = $timeStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTimeInterface|null
|
||||
*/
|
||||
public function getTimeEnd(): ?DateTimeInterface
|
||||
{
|
||||
return $this->timeEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTimeInterface|null $timeEnd
|
||||
*/
|
||||
public function setTimeEnd(?DateTimeInterface $timeEnd): void
|
||||
{
|
||||
$this->timeEnd = $timeEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getClientSerialNumber(): ?string
|
||||
{
|
||||
return $this->clientSerialNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $clientSerialNumber
|
||||
*/
|
||||
public function setClientSerialNumber(?string $clientSerialNumber): void
|
||||
{
|
||||
$this->clientSerialNumber = $clientSerialNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCertificateSerial(): ?string
|
||||
{
|
||||
return $this->certificateSerial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $certificateSerial
|
||||
*/
|
||||
public function setCertificateSerial(?string $certificateSerial): void
|
||||
{
|
||||
$this->certificateSerial = $certificateSerial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getRevision(): ?int
|
||||
{
|
||||
return $this->revision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $revision
|
||||
*/
|
||||
public function setRevision(?int $revision): void
|
||||
{
|
||||
$this->revision = $revision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getLatestRevision(): ?int
|
||||
{
|
||||
return $this->latestRevision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $latestRevision
|
||||
*/
|
||||
public function setLatestRevision(?int $latestRevision): void
|
||||
{
|
||||
$this->latestRevision = $latestRevision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionLog|null
|
||||
*/
|
||||
public function getLog(): ?TransactionLog
|
||||
{
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionLog|null $log
|
||||
*/
|
||||
public function setLog(?TransactionLog $log): void
|
||||
{
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionSignature|null
|
||||
*/
|
||||
public function getSignature(): ?TransactionSignature
|
||||
{
|
||||
return $this->signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionSignature|null $signature
|
||||
*/
|
||||
public function setSignature(?TransactionSignature $signature): void
|
||||
{
|
||||
$this->signature = $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTssId(): ?string
|
||||
{
|
||||
return $this->tssId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $tssId
|
||||
*/
|
||||
public function setTssId(?string $tssId): void
|
||||
{
|
||||
$this->tssId = $tssId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $type
|
||||
*/
|
||||
public function setType(?string $type): void
|
||||
{
|
||||
$this->_type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id
|
||||
*/
|
||||
public function setId(?string $id): void
|
||||
{
|
||||
$this->_id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getEnv(): ?string
|
||||
{
|
||||
return $this->_env;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $env
|
||||
*/
|
||||
public function setEnv(?string $env): void
|
||||
{
|
||||
$this->_env = $env;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getVersion(): ?string
|
||||
{
|
||||
return $this->_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $version
|
||||
*/
|
||||
public function setVersion(?string $version): void
|
||||
{
|
||||
$this->_version = $version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Exception;
|
||||
use IteratorAggregate;
|
||||
|
||||
class TransactionReponseCollection implements IteratorAggregate, Countable
|
||||
{
|
||||
/** @var array $transactionResponses */
|
||||
private $transactionResponses = [];
|
||||
|
||||
/**
|
||||
* TransactionReponseCollection constructor.
|
||||
*
|
||||
* @param array $transactionResponses
|
||||
*/
|
||||
public function __construct(array $transactionResponses = [])
|
||||
{
|
||||
foreach ($transactionResponses as $transactionResponse) {
|
||||
$this->addTransactionResponse($transactionResponse);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionReponse $transactionReponse
|
||||
*/
|
||||
public function addTransactionResponse(TransactionReponse $transactionReponse): void
|
||||
{
|
||||
$this->transactionResponses[] = TransactionReponse::fromDbState($transactionReponse->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @throws Exception
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
$instance = new self();
|
||||
foreach ($apiResult as $item) {
|
||||
$instance->addTransactionResponse(TransactionReponse::fromApiResult($item));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
$instance = new self();
|
||||
foreach ($dbState as $item) {
|
||||
$instance->addTransactionResponse(TransactionReponse::fromDbState($item));
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = [];
|
||||
/** @var TransactionReponse $item */
|
||||
foreach ($this as $item) {
|
||||
$dbState[] = $item->toArray();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toApiResult(): array
|
||||
{
|
||||
$dbState = [];
|
||||
/** @var TransactionReponse $item */
|
||||
foreach ($this as $item) {
|
||||
$dbState[] = $item->toApiResult();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getClientIds(): array
|
||||
{
|
||||
$clientIds = [];
|
||||
/** @var TransactionReponse $item */
|
||||
foreach ($this as $item) {
|
||||
$clientId = $item->getClientId();
|
||||
if (!in_array($clientId, $clientIds, true)) {
|
||||
$clientIds[] = $clientId;
|
||||
}
|
||||
}
|
||||
|
||||
return $clientIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTrxIds(): array
|
||||
{
|
||||
$rxIds = [];
|
||||
/** @var TransactionReponse $item */
|
||||
foreach ($this as $item) {
|
||||
$rxId = $item->getId();
|
||||
if (!in_array($rxId, $rxIds, true)) {
|
||||
$rxIds[] = $rxId;
|
||||
}
|
||||
}
|
||||
|
||||
return $rxIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactionDates(): array
|
||||
{
|
||||
$dates = [];
|
||||
/** @var TransactionReponse $item */
|
||||
foreach ($this as $item) {
|
||||
$startDate = $item->getTimeStart();
|
||||
if($startDate === null) {
|
||||
continue;
|
||||
}
|
||||
$date = $startDate->format('Y-m-d');
|
||||
if(!in_array($date, $dates)) {
|
||||
$dates[] = $date;
|
||||
}
|
||||
}
|
||||
sort($dates);
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function filterClientId(string $clientId): self
|
||||
{
|
||||
$instance = new self();
|
||||
/** @var TransactionReponse $item */
|
||||
foreach ($this as $item) {
|
||||
if ($clientId !== $item->getClientId()) {
|
||||
continue;
|
||||
}
|
||||
$instance->addTransactionResponse($item);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $date
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function filterDate(string $date): self
|
||||
{
|
||||
$instance = new self();
|
||||
/** @var TransactionReponse $item */
|
||||
foreach ($this as $item) {
|
||||
$startDate = $item->getTimeStart();
|
||||
if($startDate === null) {
|
||||
continue;
|
||||
}
|
||||
if ($date !== $startDate->format('Y-m-d')) {
|
||||
continue;
|
||||
}
|
||||
$instance->addTransactionResponse($item);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $clientId
|
||||
* @param bool $first
|
||||
*
|
||||
* @return TransactionReponse|null
|
||||
*/
|
||||
public function getBoundedTransactionWithClientId(string $clientId, bool $first = true): ?TransactionReponse
|
||||
{
|
||||
$actualKey = null;
|
||||
$actualNumber = null;
|
||||
/** @var TransactionReponse $item */
|
||||
foreach ($this as $key => $item) {
|
||||
if ($clientId !== $item->getClientId()) {
|
||||
continue;
|
||||
}
|
||||
$number = $item->getNumber();
|
||||
if ($number === null) {
|
||||
continue;
|
||||
}
|
||||
if ($actualNumber === null || ($actualNumber > $number && $first) || ($actualNumber < $number && !$first)) {
|
||||
$actualKey = $key;
|
||||
$actualNumber = $number;
|
||||
}
|
||||
}
|
||||
|
||||
return $actualKey === null ? null : TransactionReponse::fromDbState(
|
||||
$this->transactionResponses[$actualKey]->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator(): ArrayIterator
|
||||
{
|
||||
return new ArrayIterator($this->transactionResponses);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->transactionResponses);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use Xentral\Modules\FiskalyApi\UuidTool;
|
||||
|
||||
class TransactionRequest extends Transaction
|
||||
{
|
||||
/** @var string|null $tssId */
|
||||
private $tssId;
|
||||
|
||||
/** @var string|null $_id */
|
||||
private $_id;
|
||||
|
||||
/** @var int $revision */
|
||||
private $revision;
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTssId(): ?string
|
||||
{
|
||||
return $this->tssId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $tssId
|
||||
*/
|
||||
public function setTssId(?string $tssId): self
|
||||
{
|
||||
$this->tssId = $tssId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId(): ?string
|
||||
{
|
||||
if($this->_id !== null) {
|
||||
return $this->_id;
|
||||
}
|
||||
$this->setId(UuidTool::generateUuid());
|
||||
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id
|
||||
*/
|
||||
public function setId(?string $id): self
|
||||
{
|
||||
$this->_id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRevision(): int
|
||||
{
|
||||
return $this->revision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $revision
|
||||
*/
|
||||
public function setRevision(int $revision): self
|
||||
{
|
||||
$this->revision = $revision;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use stdClass;
|
||||
|
||||
class TransactionSchema
|
||||
{
|
||||
/** @var SchemaStandardV1|null $standardV1 */
|
||||
private $standardV1;
|
||||
|
||||
/** @var SchemaRaw|null $raw */
|
||||
private $raw;
|
||||
|
||||
public function __construct(?SchemaStandardV1 $standardV1, ?SchemaRaw $raw = null)
|
||||
{
|
||||
$this->setStandardV1($standardV1);
|
||||
$this->setRaw($raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self(
|
||||
empty($apiResult->standard_v1) ? null : SchemaStandardV1::fromApiResult($apiResult->standard_v1),
|
||||
empty($apiResult->raw) ? null : SchemaRaw::fromApiResult($apiResult->raw)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self(
|
||||
empty($dbState['standard_v1']) ? null : SchemaStandardV1::fromDbState($dbState['standard_v1']),
|
||||
empty($dbState['raw']) ? null : SchemaRaw::fromDbState($dbState['raw'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$dbState = [];
|
||||
if ($this->standardV1 !== null) {
|
||||
$dbState['standard_v1'] = $this->standardV1->toArray();
|
||||
}
|
||||
if ($this->raw !== null) {
|
||||
$dbState['raw'] = $this->raw->toArray();
|
||||
}
|
||||
|
||||
return $dbState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return stdClass
|
||||
*/
|
||||
public function toApiResult()
|
||||
{
|
||||
$apiResult = new stdClass();
|
||||
if ($this->standardV1 !== null) {
|
||||
$apiResult->standard_v1 = json_decode(json_encode($this->standardV1->toArray()));
|
||||
}
|
||||
if ($this->raw !== null) {
|
||||
$apiResult->raw = json_decode(json_encode($this->raw->toArray()));
|
||||
}
|
||||
|
||||
return $apiResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SchemaStandardV1|null
|
||||
*/
|
||||
public function getStandardV1(): ?SchemaStandardV1
|
||||
{
|
||||
return $this->standardV1 === null ? null : SchemaStandardV1::fromDbState($this->standardV1->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SchemaStandardV1|null $standardV1
|
||||
*/
|
||||
public function setStandardV1(?SchemaStandardV1 $standardV1): void
|
||||
{
|
||||
$this->standardV1 = $standardV1 === null ? null : SchemaStandardV1::fromDbState($standardV1->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SchemaRaw|null
|
||||
*/
|
||||
public function getRaw(): ?SchemaRaw
|
||||
{
|
||||
return $this->raw === null ? null : SchemaRaw::fromDbState($this->raw->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SchemaRaw|null $raw
|
||||
*/
|
||||
public function setRaw(?SchemaRaw $raw): void
|
||||
{
|
||||
$this->raw = $raw === null ? null : SchemaRaw::fromDbState($raw->toArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Data\Transaction;
|
||||
|
||||
use stdClass;
|
||||
|
||||
class TransactionSignature
|
||||
{
|
||||
/** @var string $value */
|
||||
private $value;
|
||||
|
||||
/** @var string $algorithm */
|
||||
private $algorithm;
|
||||
|
||||
/** @var int $counter */
|
||||
private $counter;
|
||||
|
||||
/** @var string $publicKey */
|
||||
private $publicKey;
|
||||
|
||||
/**
|
||||
* TransactionSignature constructor.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $algorithm
|
||||
* @param int $counter
|
||||
* @param string $publicKey
|
||||
*/
|
||||
public function __construct(string $value, string $algorithm, int $counter, string $publicKey)
|
||||
{
|
||||
$this->setValue($value);
|
||||
$this->setAlgorithm($algorithm);
|
||||
$this->setCounter($counter);
|
||||
$this->setPublicKey($publicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiResult
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromApiResult(object $apiResult): self
|
||||
{
|
||||
return new self(
|
||||
$apiResult->value,
|
||||
$apiResult->algorithm,
|
||||
(int)$apiResult->counter,
|
||||
$apiResult->public_key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $dbState
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromDbState(array $dbState): self
|
||||
{
|
||||
return new self(
|
||||
$dbState['value'],
|
||||
$dbState['algorithm'],
|
||||
(int)$dbState['counter'],
|
||||
$dbState['public_key']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'value' => $this->getValue(),
|
||||
'algorithm' => $this->getAlgorithm(),
|
||||
'counter' => $this->getCounter(),
|
||||
'public_key' => $this->getPublicKey(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return stdClass
|
||||
*/
|
||||
public function toApiResult(): stdClass
|
||||
{
|
||||
$apiResult = new stdClass();
|
||||
|
||||
$apiResult->value = $this->getValue();
|
||||
$apiResult->algorithm = $this->getAlgorithm();
|
||||
$apiResult->counter = $this->getCounter();
|
||||
$apiResult->public_key = $this->getPublicKey();
|
||||
|
||||
return $apiResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setValue(string $value): void
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAlgorithm(): string
|
||||
{
|
||||
return $this->algorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $algorithm
|
||||
*/
|
||||
public function setAlgorithm(string $algorithm): void
|
||||
{
|
||||
$this->algorithm = $algorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCounter(): int
|
||||
{
|
||||
return $this->counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $counter
|
||||
*/
|
||||
public function setCounter(int $counter): void
|
||||
{
|
||||
$this->counter = $counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicKey(): string
|
||||
{
|
||||
return $this->publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $publicKey
|
||||
*/
|
||||
public function setPublicKey(string $publicKey): void
|
||||
{
|
||||
$this->publicKey = $publicKey;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user