2021-11-18 04:24:30 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
|
|
|
*
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace AtolOnline\Entities;
|
|
|
|
|
|
|
|
use AtolOnline\{
|
|
|
|
Constants\Constraints,
|
2021-11-20 15:38:19 +00:00
|
|
|
Enums\SnoTypes,
|
2021-12-03 10:23:00 +00:00
|
|
|
Traits\HasEmail,
|
|
|
|
Traits\HasInn
|
|
|
|
};
|
|
|
|
use AtolOnline\Exceptions\{
|
|
|
|
InvalidEmailException,
|
|
|
|
InvalidEnumValueException,
|
|
|
|
InvalidInnLengthException,
|
|
|
|
InvalidPaymentAddressException,
|
|
|
|
TooLongEmailException,
|
|
|
|
TooLongPaymentAddressException
|
|
|
|
};
|
|
|
|
use JetBrains\PhpStorm\ArrayShape;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Класс, описывающий сущность компании-продавца
|
|
|
|
*
|
2021-11-26 01:16:46 +00:00
|
|
|
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 17
|
2021-11-18 04:24:30 +00:00
|
|
|
*/
|
|
|
|
class Company extends Entity
|
|
|
|
{
|
2021-12-03 10:23:00 +00:00
|
|
|
use HasEmail, HasInn;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-26 01:16:46 +00:00
|
|
|
* @var string|null Система налогообложения продавца (1055)
|
2021-11-18 04:24:30 +00:00
|
|
|
*/
|
|
|
|
protected ?string $sno;
|
|
|
|
|
|
|
|
/**
|
2021-11-26 01:16:46 +00:00
|
|
|
* @var string|null Место расчётов (адрес интернет-магазина) (1187)
|
2021-11-18 04:24:30 +00:00
|
|
|
*/
|
|
|
|
protected ?string $payment_address;
|
|
|
|
|
|
|
|
/**
|
2021-11-27 16:57:07 +00:00
|
|
|
* Конструктор
|
2021-11-18 04:24:30 +00:00
|
|
|
*
|
2021-11-26 01:16:46 +00:00
|
|
|
* @param string $sno Система налогообложения продавца (1055)
|
|
|
|
* @param string $inn ИНН (1018)
|
|
|
|
* @param string $payment_address Место расчётов (адрес интернет-магазина) (1187)
|
|
|
|
* @param string $email Почта (1117)
|
2021-11-18 04:24:30 +00:00
|
|
|
* @throws InvalidEmailException
|
|
|
|
* @throws InvalidInnLengthException
|
|
|
|
* @throws InvalidPaymentAddressException
|
2021-11-22 06:51:10 +00:00
|
|
|
* @throws InvalidEnumValueException
|
2021-11-18 04:24:30 +00:00
|
|
|
* @throws TooLongEmailException
|
|
|
|
* @throws TooLongPaymentAddressException
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
string $email,
|
|
|
|
string $sno,
|
|
|
|
string $inn,
|
|
|
|
string $payment_address,
|
|
|
|
) {
|
|
|
|
$this->setEmail($email);
|
|
|
|
$this->setSno($sno);
|
|
|
|
$this->setInn($inn);
|
|
|
|
$this->setPaymentAddress($payment_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Возвращает установленный тип налогообложения
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSno(): string
|
|
|
|
{
|
|
|
|
return $this->sno;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Устанавливает тип налогообложения
|
|
|
|
*
|
|
|
|
* @param string $sno
|
|
|
|
* @return $this
|
2021-11-22 06:51:10 +00:00
|
|
|
* @throws InvalidEnumValueException
|
2021-11-18 04:24:30 +00:00
|
|
|
*/
|
2021-11-21 11:06:55 +00:00
|
|
|
public function setSno(string $sno): self
|
2021-11-18 04:24:30 +00:00
|
|
|
{
|
|
|
|
$sno = trim($sno);
|
2021-11-22 06:51:10 +00:00
|
|
|
SnoTypes::isValid($sno);
|
2021-11-18 04:24:30 +00:00
|
|
|
$this->sno = $sno;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Возвращает установленный адрес места расчётов
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPaymentAddress(): string
|
|
|
|
{
|
|
|
|
return $this->payment_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Устанавливает адрес места расчётов
|
|
|
|
*
|
|
|
|
* @param string $payment_address
|
|
|
|
* @return $this
|
|
|
|
* @throws TooLongPaymentAddressException
|
|
|
|
* @throws InvalidPaymentAddressException
|
|
|
|
*/
|
2021-11-21 11:06:55 +00:00
|
|
|
public function setPaymentAddress(string $payment_address): self
|
2021-11-18 04:24:30 +00:00
|
|
|
{
|
|
|
|
$payment_address = trim($payment_address);
|
|
|
|
if (empty($payment_address)) {
|
|
|
|
throw new InvalidPaymentAddressException();
|
|
|
|
} elseif (mb_strlen($payment_address) > Constraints::MAX_LENGTH_PAYMENT_ADDRESS) {
|
2021-11-22 06:51:10 +00:00
|
|
|
throw new TooLongPaymentAddressException($payment_address);
|
2021-11-18 04:24:30 +00:00
|
|
|
}
|
|
|
|
$this->payment_address = $payment_address;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @throws InvalidEmailException
|
2021-11-22 06:51:10 +00:00
|
|
|
* @throws InvalidEnumValueException
|
2021-11-18 04:24:30 +00:00
|
|
|
* @throws InvalidInnLengthException
|
|
|
|
* @throws InvalidPaymentAddressException
|
|
|
|
*/
|
2021-12-03 10:23:00 +00:00
|
|
|
#[ArrayShape([
|
|
|
|
'email' => "string",
|
|
|
|
'sno' => "string",
|
|
|
|
'inn' => "string",
|
|
|
|
'payment_address' => "string",
|
|
|
|
])]
|
2021-11-23 17:30:54 +00:00
|
|
|
public function jsonSerialize(): array
|
2021-11-18 04:24:30 +00:00
|
|
|
{
|
2021-11-23 17:30:54 +00:00
|
|
|
return [
|
2021-11-18 04:24:30 +00:00
|
|
|
'email' => $this->email
|
|
|
|
? $this->getEmail()
|
|
|
|
: throw new InvalidEmailException(),
|
|
|
|
'sno' => $this->sno
|
|
|
|
? $this->getSno()
|
2021-11-22 06:51:10 +00:00
|
|
|
: throw new InvalidEnumValueException(SnoTypes::class, 'null'),
|
2021-11-18 04:24:30 +00:00
|
|
|
'inn' => $this->inn
|
|
|
|
? $this->getInn()
|
|
|
|
: throw new InvalidInnLengthException(),
|
|
|
|
'payment_address' => $this->payment_address
|
|
|
|
? $this->getPaymentAddress()
|
|
|
|
: throw new InvalidPaymentAddressException(),
|
|
|
|
];
|
|
|
|
}
|
2021-11-23 17:30:54 +00:00
|
|
|
}
|