_amount; } /** * Проверяет была ли установлена сумма оплаты * @return bool True если сумма оплаты была установлена, false если нет */ public function hasAmount() { return !empty($this->_amount); } /** * Устанавливает сумму оплаты * @param AmountInterface $value Сумма оплаты */ public function setAmount(AmountInterface $value) { $this->_amount = $value; } /** * Возвращает чек, если он есть * @return ReceiptInterface|null Данные фискального чека 54-ФЗ или null если чека нет */ public function getReceipt() { return $this->_receipt; } /** * Устанавливает чек * @param ReceiptInterface|null $value Инстанс чека или null для удаления информации о чеке * @throws InvalidPropertyValueTypeException Выбрасывается если передан не инстанс класса чека и не null */ public function setReceipt($value) { if ($value === null || $value instanceof ReceiptInterface) { $this->_receipt = $value; } else { throw new InvalidPropertyValueTypeException('Invalid receipt in Refund', 0, 'Refund.receipt', $value); } } /** * Проверяет наличие чека * @return bool True если чек есть, false если нет */ public function hasReceipt() { return $this->_receipt !== null && $this->_receipt->notEmpty(); } /** * Удаляет чек из запроса */ public function removeReceipt() { $this->_receipt = null; } /** * Устанавливает transfers (массив распределения денег между магазинами) * @param TransferInterface[]|array $value */ public function setTransfers($value) { if (!is_array($value)) { $message = 'Transfers must be an array of TransferInterface'; throw new InvalidPropertyValueTypeException($message, 0, 'Payment.transfers', $value); } $transfers = array(); foreach ($value as $item) { if (is_array($item)) { $item = new Transfer($item); } if (!($item instanceof TransferInterface)) { $message = 'Transfers must be an array of TransferInterface'; throw new InvalidPropertyValueTypeException($message, 0, 'Payment.transfers', $value); } $transfers[] = $item; } $this->_transfers = $transfers; } /** * Валидирует объект запроса * @return bool True если запрос валиден и его можно отправить в API, false если нет */ public function validate() { if ($this->_amount === null) { $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 (!empty($this->_transfers)) { $sum = 0; foreach ($this->_transfers as $transfer) { if ($transfer->getAmount() === null) { $this->setValidationError('Payment amount not specified'); return false; } $value = $transfer->getAmount()->getValue(); if (empty($value) || $value <= 0.0) { $this->setValidationError('Invalid transfer amount value: ' . $value); return false; } $sum += (float) $value; $accountId = $transfer->getAccountId(); if (empty($accountId)) { $this->setValidationError('Transfer 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() && $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; } public function hasTransfers() { return !empty($this->_transfers); } public function getTransfers() { return $this->_transfers; } }