Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\Payment;
|
||||
|
||||
abstract class BasePayment
|
||||
{
|
||||
/** @var string */
|
||||
private $paymentType;
|
||||
/** @var float */
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* BasePayment constructor.
|
||||
*
|
||||
* @param string $paymentType
|
||||
* @param float $amount
|
||||
*/
|
||||
protected function __construct(string $paymentType, float $amount)
|
||||
{
|
||||
$this->paymentType = $paymentType;
|
||||
$this->amount = $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPaymentType(): string {
|
||||
return $this->paymentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount(): float {
|
||||
return $this->amount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\Payment;
|
||||
|
||||
final class CashPayment extends BasePayment
|
||||
{
|
||||
public function __construct(float $amount)
|
||||
{
|
||||
parent::__construct('CASH', $amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\Payment;
|
||||
|
||||
final class NonCashPayment extends BasePayment
|
||||
{
|
||||
public function __construct(float $amount)
|
||||
{
|
||||
parent::__construct('NON_CASH', $amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\Payment;
|
||||
|
||||
final class OrderLineItem
|
||||
{
|
||||
/** @var float $quantity */
|
||||
private $quantity;
|
||||
|
||||
/** @var string $text */
|
||||
private $text;
|
||||
|
||||
/** @var float $pricePerUnit */
|
||||
private $pricePerUnit;
|
||||
|
||||
public function __construct(float $quantity, string $text, float $pricePerUnit)
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
$this->text = $text;
|
||||
$this->pricePerUnit = $pricePerUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQuantity(): string
|
||||
{
|
||||
return number_format($this->quantity, 2, '.', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $quantity
|
||||
*/
|
||||
public function setQuantity(float $quantity): void
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getText(): string
|
||||
{
|
||||
return mb_substr($this->text, 0, 255);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText(string $text): void
|
||||
{
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPricePerUnit(): string
|
||||
{
|
||||
return number_format($this->pricePerUnit, 2, '.', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $pricePerUnit
|
||||
*/
|
||||
public function setPricePerUnit(float $pricePerUnit): void
|
||||
{
|
||||
$this->pricePerUnit = $pricePerUnit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction;
|
||||
|
||||
use Xentral\Modules\FiskalyApi\Transaction\Payment\BasePayment;
|
||||
use Xentral\Modules\FiskalyApi\Transaction\Payment\OrderLineItem;
|
||||
use Xentral\Modules\FiskalyApi\Transaction\VatAmount\BaseVatAmount;
|
||||
use Xentral\Modules\FiskalyApi\UuidTool;
|
||||
|
||||
/**
|
||||
* Class Transaction
|
||||
*
|
||||
* @package Xentral\Modules\FiskalyApi\Transaction
|
||||
*/
|
||||
class Transaction
|
||||
{
|
||||
/** @var array */
|
||||
private $amountsPerVatRate;
|
||||
|
||||
/** @var BasePayment[] */
|
||||
private $amountsPerPaymentType;
|
||||
|
||||
private $oderLineItems;
|
||||
|
||||
/** @var string */
|
||||
private $uuid;
|
||||
|
||||
/** @var string */
|
||||
private $clientUuid;
|
||||
|
||||
/** @var int */
|
||||
private $lastRevision = -1;
|
||||
|
||||
/** @var int */
|
||||
private $startTime;
|
||||
|
||||
/** @var int */
|
||||
private $endTime;
|
||||
|
||||
/** @var string */
|
||||
private $clientSerialNumber;
|
||||
|
||||
/** @var string */
|
||||
private $certificateSerial;
|
||||
|
||||
// TODO Signature object
|
||||
|
||||
/** @var string */
|
||||
private $signature;
|
||||
|
||||
/** @var string */
|
||||
private $publicKey;
|
||||
|
||||
/** @var string */
|
||||
private $signatureAlgorithm;
|
||||
|
||||
/** @var int */
|
||||
private $signatureCounter;
|
||||
|
||||
/** @var string $qrCodeData */
|
||||
private $qrCodeData;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTransactionNumber(): int
|
||||
{
|
||||
return $this->transactionNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $transactionNumber
|
||||
*/
|
||||
public function setTransactionNumber(int $transactionNumber): void
|
||||
{
|
||||
$this->transactionNumber = $transactionNumber;
|
||||
}
|
||||
|
||||
/** @var int */
|
||||
private $transactionNumber;
|
||||
|
||||
/**
|
||||
* Transaction constructor.
|
||||
*
|
||||
* @param array $amountsPerPaymentType
|
||||
* @param array $amountsPerVatRate
|
||||
* @param OrderLineItem[] $orderLineItems
|
||||
* @param string $clientId
|
||||
* @param string|null $uuid
|
||||
*/
|
||||
public function __construct(
|
||||
array $amountsPerPaymentType,
|
||||
array $amountsPerVatRate,
|
||||
array $orderLineItems,
|
||||
string $clientId,
|
||||
string $uuid = null
|
||||
) {
|
||||
$this->amountsPerPaymentType = $amountsPerPaymentType;
|
||||
$this->amountsPerVatRate = $amountsPerVatRate;
|
||||
$this->oderLineItems = $orderLineItems;
|
||||
$this->uuid = $uuid;
|
||||
$this->clientUuid = $clientId;
|
||||
if (empty($this->uuid)) {
|
||||
$this->uuid = UuidTool::generateUuid();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BaseVatAmount[]
|
||||
*/
|
||||
public function getAmountsPerVatRate(): array
|
||||
{
|
||||
return $this->amountsPerVatRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BasePayment[]
|
||||
*/
|
||||
public function getAmountsPerPaymentType(): array
|
||||
{
|
||||
return $this->amountsPerPaymentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrderLineItem[]
|
||||
*/
|
||||
public function getOrderLineItems(): array
|
||||
{
|
||||
return $this->oderLineItems;
|
||||
}
|
||||
|
||||
/* @return string */
|
||||
public function getUuid(): string
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLastRevision(): int
|
||||
{
|
||||
return $this->lastRevision;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStartTime(): int
|
||||
{
|
||||
return $this->startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $startTime
|
||||
*/
|
||||
public function setStartTime(int $startTime): void
|
||||
{
|
||||
$this->startTime = $startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getEndTime(): int
|
||||
{
|
||||
return $this->endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $endTime
|
||||
*/
|
||||
public function setEndTime(int $endTime): void
|
||||
{
|
||||
$this->endTime = $endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getClientSerialNumber(): string
|
||||
{
|
||||
return $this->clientSerialNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientSerialNumber
|
||||
*/
|
||||
public function setClientSerialNumber(string $clientSerialNumber): void
|
||||
{
|
||||
$this->clientSerialNumber = $clientSerialNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCertificateSerial(): string
|
||||
{
|
||||
return $this->certificateSerial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $certificateSerial
|
||||
*/
|
||||
public function setCertificateSerial(string $certificateSerial): void
|
||||
{
|
||||
$this->certificateSerial = $certificateSerial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSignature(): string
|
||||
{
|
||||
return $this->signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $signature
|
||||
*/
|
||||
public function setSignature(string $signature): void
|
||||
{
|
||||
$this->signature = $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicKey(): string
|
||||
{
|
||||
return $this->publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $publicKey
|
||||
*/
|
||||
public function setPublicKey(string $publicKey): void
|
||||
{
|
||||
$this->publicKey = $publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSignatureAlgorithm(): string
|
||||
{
|
||||
return $this->signatureAlgorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $signatureAlgorithm
|
||||
*/
|
||||
public function setSignatureAlgorithm(string $signatureAlgorithm): void
|
||||
{
|
||||
$this->signatureAlgorithm = $signatureAlgorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSignatureCounter(): int
|
||||
{
|
||||
return $this->signatureCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $signatureCounter
|
||||
*/
|
||||
public function setSignatureCounter(int $signatureCounter): void
|
||||
{
|
||||
$this->signatureCounter = $signatureCounter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getClientUuid(): string
|
||||
{
|
||||
return $this->clientUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isLastRevisionSet(): bool
|
||||
{
|
||||
return $this->lastRevision > -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $lastRevision
|
||||
*/
|
||||
public function setLastRevision(int $lastRevision): void
|
||||
{
|
||||
$this->lastRevision = $lastRevision;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\VatAmount;
|
||||
|
||||
use Xentral\Modules\FiskalyApi\Exception\VatRateNotFoundException;
|
||||
|
||||
abstract class BaseVatAmount
|
||||
{
|
||||
/** @var string */
|
||||
private $vatType;
|
||||
/** @var float */
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* BaseVatAmount constructor.
|
||||
*
|
||||
* @param string $vatType
|
||||
* @param float $amount
|
||||
*/
|
||||
protected function __construct(string $vatType, float $amount)
|
||||
{
|
||||
$this->vatType = $vatType;
|
||||
$this->amount = $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getVatType(): string
|
||||
{
|
||||
return $this->vatType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount(): float
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
*/
|
||||
public function setAmount(float $amount): void
|
||||
{
|
||||
$this->amount = $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amountToAdd
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add(float $amountToAdd): void
|
||||
{
|
||||
$this->amount += $amountToAdd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $percentage
|
||||
* @param float $amount
|
||||
*
|
||||
* @throws VatRateNotFoundException
|
||||
*
|
||||
* @return BaseVatAmount
|
||||
*/
|
||||
public static function fromPercentage(float $percentage, float $amount): BaseVatAmount
|
||||
{
|
||||
$mapping = [
|
||||
19.0 => NormalVatAmount::class,
|
||||
7.0 => Reduced1VatAmount::class,
|
||||
10.7 => SpecialRate1VatAmount::class,
|
||||
5.5 => SpecialRate2VatAmount::class,
|
||||
0 => NullVatAmount::class
|
||||
];
|
||||
|
||||
$class = $mapping[$percentage];
|
||||
|
||||
if(empty($class)){
|
||||
throw VatRateNotFoundException::fromPercentage($percentage);
|
||||
}
|
||||
|
||||
return new $class($amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\VatAmount;
|
||||
|
||||
final class NormalVatAmount extends BaseVatAmount
|
||||
{
|
||||
public function __construct(float $amount)
|
||||
{
|
||||
parent::__construct('NORMAL', $amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\VatAmount;
|
||||
|
||||
class NullVatAmount extends BaseVatAmount
|
||||
{
|
||||
public function __construct(float $amount)
|
||||
{
|
||||
parent::__construct('NULL', $amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\VatAmount;
|
||||
|
||||
class Reduced1VatAmount extends BaseVatAmount
|
||||
{
|
||||
public function __construct(float $amount)
|
||||
{
|
||||
parent::__construct('REDUCED_1', $amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\VatAmount;
|
||||
|
||||
class SpecialRate1VatAmount extends BaseVatAmount
|
||||
{
|
||||
public function __construct(float $amount)
|
||||
{
|
||||
parent::__construct('SPECIAL_RATE_1', $amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\FiskalyApi\Transaction\VatAmount;
|
||||
|
||||
class SpecialRate2VatAmount extends BaseVatAmount
|
||||
{
|
||||
public function __construct(float $amount)
|
||||
{
|
||||
parent::__construct('SPECIAL_RATE_2', $amount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user