2021-11-23 17:30:54 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-11-23 17:30:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-14 16:19:55 +00:00
|
|
|
|
declare(strict_types=1);
|
2021-11-23 17:30:54 +00:00
|
|
|
|
|
|
|
|
|
namespace AtolOnline\Entities;
|
|
|
|
|
|
2022-12-14 16:19:55 +00:00
|
|
|
|
use AtolOnline\Constraints;
|
2021-12-03 10:23:00 +00:00
|
|
|
|
use AtolOnline\Exceptions\{
|
|
|
|
|
InvalidPhoneException,
|
2021-12-08 11:04:14 +00:00
|
|
|
|
TooLongPayingAgentOperationException};
|
2021-12-03 10:23:00 +00:00
|
|
|
|
use AtolOnline\Traits\HasPhones;
|
2021-11-23 17:30:54 +00:00
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-24 09:54:04 +00:00
|
|
|
|
* Класс, описывающий платёжного агента
|
2021-11-23 17:30:54 +00:00
|
|
|
|
*
|
|
|
|
|
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 19
|
|
|
|
|
*/
|
2021-12-03 10:24:21 +00:00
|
|
|
|
final class PayingAgent extends Entity
|
2021-11-23 17:30:54 +00:00
|
|
|
|
{
|
2021-12-03 10:23:00 +00:00
|
|
|
|
use HasPhones;
|
|
|
|
|
|
2021-11-23 17:30:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var string|null Наименование операции (1044)
|
|
|
|
|
*/
|
|
|
|
|
protected ?string $operation = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Конструктор
|
|
|
|
|
*
|
|
|
|
|
* @param string|null $operation Наименование операции (1044)
|
2021-11-24 09:54:04 +00:00
|
|
|
|
* @param array|Collection|null $phones Телефоны платёжного агента (1073)
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* @throws TooLongPayingAgentOperationException
|
|
|
|
|
* @throws InvalidPhoneException
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
?string $operation = null,
|
2022-12-14 16:19:55 +00:00
|
|
|
|
array | Collection | null $phones = null,
|
2021-11-23 17:30:54 +00:00
|
|
|
|
) {
|
|
|
|
|
!is_null($operation) && $this->setOperation($operation);
|
|
|
|
|
$this->setPhones($phones);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливает операцию
|
|
|
|
|
*
|
|
|
|
|
* @param string|null $operation
|
|
|
|
|
* @return $this
|
|
|
|
|
* @throws TooLongPayingAgentOperationException
|
|
|
|
|
*/
|
|
|
|
|
public function setOperation(?string $operation): self
|
|
|
|
|
{
|
|
|
|
|
if (!is_null($operation)) {
|
|
|
|
|
$operation = trim($operation);
|
|
|
|
|
if (mb_strlen($operation) > Constraints::MAX_LENGTH_PAYING_AGENT_OPERATION) {
|
|
|
|
|
throw new TooLongPayingAgentOperationException($operation);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-08 11:04:14 +00:00
|
|
|
|
$this->operation = $operation ?: null;
|
2021-11-23 17:30:54 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Вoзвращает установленную операцию
|
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getOperation(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->operation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
*/
|
|
|
|
|
public function jsonSerialize(): array
|
|
|
|
|
{
|
|
|
|
|
$json = [];
|
|
|
|
|
$this->getOperation() && $json['operation'] = $this->getOperation();
|
|
|
|
|
!$this->getPhones()->isEmpty() && $json['phones'] = $this->getPhones()->toArray();
|
|
|
|
|
return $json;
|
|
|
|
|
}
|
|
|
|
|
}
|