src/Entity/Payment.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PaymentRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassPaymentRepository::class)]
  6. class Payment
  7. {
  8.     public const STATUS_PAID      'pagado';
  9.     public const STATUS_NOT_PAID  'no pagado';
  10.     public const STATUS_CANCELLED 'cancelado';
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     private ?int $id null;
  15.     #[ORM\Column(type'float')]
  16.     private float $amount;
  17.     #[ORM\Column(type'datetime')]
  18.     private \DateTimeInterface $paidAt;
  19.     #[ORM\Column(type'string'length20)]
  20.     private string $status;
  21.     #[ORM\OneToOne(targetEntityOrder::class, inversedBy'payment'cascade: ['persist''remove'])]
  22.     #[ORM\JoinColumn(nullablefalse)]
  23.     private Order $order;
  24.     // Getters y setters
  25.     public function getId(): ?int
  26.     {
  27.         return $this->id;
  28.     }
  29.     public function getAmount(): ?float
  30.     {
  31.         return $this->amount;
  32.     }
  33.     public function setAmount(float $amount): self
  34.     {
  35.         $this->amount $amount;
  36.         return $this;
  37.     }
  38.     public function getPaidAt(): ?\DateTimeInterface
  39.     {
  40.         return $this->paidAt;
  41.     }
  42.     public function setPaidAt(\DateTimeInterface $paidAt): self
  43.     {
  44.         $this->paidAt $paidAt;
  45.         return $this;
  46.     }
  47.     public function getStatus(): ?string
  48.     {
  49.         return $this->status;
  50.     }
  51.     public function setStatus(string $status): self
  52.     {
  53.         $allowed = [
  54.             self::STATUS_PAID,
  55.             self::STATUS_NOT_PAID,
  56.             self::STATUS_CANCELLED
  57.         ];
  58.         if (!in_array($status$allowedtrue)) {
  59.             throw new \InvalidArgumentException("Estado de pago no vĂ¡lido.");
  60.         }
  61.         $this->status $status;
  62.         return $this;
  63.     }
  64.     public function getOrder(): ?Order
  65.     {
  66.         return $this->order;
  67.     }
  68.     public function setOrder(Order $order): self
  69.     {
  70.         $this->order $order;
  71.         return $this;
  72.     }
  73.     public function getOrderName(): ?string
  74.     {
  75.         if ($this->getOrder()) {
  76.             return $this->getOrder()->getName() . ' ' $this->getOrder()->getSurename();
  77.         }
  78.         return null;
  79.     }
  80.     public function getOrderEmail(): ?string
  81.     {
  82.         return $this->getOrder() ? $this->getOrder()->getEmail() : null;
  83.     }
  84.     public function getOrderId()
  85.     {
  86.         return $this->getOrder() ? $this->getOrder()->getId() : null;
  87.     }
  88. }