setType($type)->setSum($sum); } /** * Возвращает установленный тип оплаты * * @return int */ public function getType(): int { return $this->type; } /** * Устанавливает тип оплаты * * @param int $type * @return $this * @throws InvalidEnumValueException */ public function setType(int $type): self { PaymentTypes::isValid($type) && $this->type = $type; return $this; } /** * Возвращает установленную сумму оплаты * * @return float */ public function getSum(): float { return $this->sum; } /** * Устанавливает сумму оплаты * * @param float $sum * @return $this * @throws TooHighPaymentSumException * @throws NegativePaymentSumException */ public function setSum(float $sum): self { $sum = round($sum, 2); if ($sum > Constraints::MAX_COUNT_PAYMENT_SUM) { throw new TooHighPaymentSumException($sum); } if ($sum < 0) { throw new NegativePaymentSumException($sum); } $this->sum = $sum; return $this; } /** * @inheritDoc */ #[Pure] #[ArrayShape(['type' => 'int', 'sum' => 'float'])] public function jsonSerialize(): array { return [ 'type' => $this->getType(), 'sum' => $this->getSum(), ]; } }