_amount; } /** * Проверяет, была ли установлена сумма оплаты. * * @return bool True если сумма оплаты была установлена, false если нет */ public function hasAmount(): bool { return !empty($this->_amount); } /** * Устанавливает сумму оплаты. * * @param AmountInterface|array|string $amount Сумма оплаты * * @return self */ public function setAmount(mixed $amount = null): AbstractRequestInterface { $this->_amount = $this->validatePropertyValue('_amount', $amount); return $this; } /** * Возвращает чек, если он есть. * * @return null|ReceiptInterface Данные фискального чека 54-ФЗ или null, если чека нет */ public function getReceipt(): ?ReceiptInterface { return $this->_receipt; } /** * Устанавливает чек. * * @param null|array|ReceiptInterface $receipt Инстанс чека или null для удаления информации о чеке * * @return self */ public function setReceipt(mixed $receipt): AbstractRequestInterface { $this->_receipt = $this->validatePropertyValue('_receipt', $receipt); return $this; } /** * Проверяет наличие чека. * * @return bool True если чек есть, false если нет */ public function hasReceipt(): bool { return (bool) $this->getReceipt()?->notEmpty(); } /** * Удаляет чек из запроса. * * @return self */ public function removeReceipt(): AbstractRequestInterface { $this->_receipt = null; return $this; } /** * Возвращает данные авиабилетов. * * @return null|AirlineInterface Данные авиабилетов */ public function getAirline(): ?AirlineInterface { return $this->_airline; } /** * Проверяет, были ли установлены данные авиабилетов. */ public function hasAirline(): bool { return null !== $this->_airline; } /** * Устанавливает данные авиабилетов. * * @param AirlineInterface|array|null $airline Данные авиабилетов */ public function setAirline(mixed $airline): AbstractRequestInterface { $this->_airline = $this->validatePropertyValue('_airline', $airline); return $this; } /** * Проверяет наличие данных о распределении денег. */ public function hasTransfers(): bool { return !$this->getTransfers()->isEmpty(); } /** * Возвращает данные о распределении денег — сколько и в какой магазин нужно перевести. * Присутствует, если вы используете решение ЮKassa для платформ. * (https://yookassa.ru/developers/special-solutions/checkout-for-platforms/basics). * * @return TransferDataInterface[]|ListObjectInterface Данные о распределении денег */ public function getTransfers(): ListObjectInterface { if ($this->_transfers === null) { $this->_transfers = new ListObject(TransferData::class); } return $this->_transfers; } /** * Устанавливает transfers (массив распределения денег между магазинами). * * @param ListObjectInterface|array|null $transfers Массив распределения денег * * @return self */ public function setTransfers(mixed $transfers = null): AbstractRequestInterface { $this->_transfers = $this->validatePropertyValue('_transfers', $transfers); return $this; } /** * Валидирует объект запроса. * * @return bool True если запрос валиден и его можно отправить в API, false если нет */ public function validate(): bool { if (null === $this->_amount) { $this->setValidationError('Payment amount not specified'); return false; } $value = $this->_amount->getValue(); if (empty($value) || $value <= 0.0) { $this->setValidationError('Invalid Payment amount value: ' . $value); return false; } if ($this->hasTransfers()) { $sum = 0; foreach ($this->getTransfers() as $i => $transfer) { if (null === $transfer->getAmount()) { $this->setValidationError('Transfer[' . $i . '] amount not specified'); return false; } $value = $transfer->getAmount()?->getValue(); if (empty($value) || $value <= 0.0) { $this->setValidationError('Invalid Transfer[' . $i . '] amount value: ' . $value); return false; } $sum += (float) $value; $accountId = $transfer->getAccountId(); if (empty($accountId)) { $this->setValidationError('Transfer[' . $i . '] account id not specified'); return false; } } if ($sum !== (float) $this->getAmount()?->getValue()) { $this->setValidationError('Transfer amount sum does not match top-level amount'); } } if ($this->getReceipt()?->notEmpty()) { $email = $this->getReceipt()?->getCustomer()?->getEmail(); $phone = $this->getReceipt()?->getCustomer()?->getPhone(); if (empty($email) && empty($phone)) { $this->setValidationError('Both email and phone values are empty in receipt'); return false; } } return true; } }