src/Entity/Payment.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PaymentRepository;
  4. use App\Traits\Timestamps;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassPaymentRepository::class)]
  8. #[ORM\HasLifecycleCallbacks]
  9. class Payment
  10. {
  11.     use Timestamps;
  12.     
  13.     /**
  14.      * Statuts possibles pour un paiement (identiques aux statuts des commandes)
  15.      */
  16.     public const STATUS_PENDING 'pending';
  17.     public const STATUS_CONFIRMED 'confirmed';
  18.     public const STATUS_CANCELLED 'cancelled';
  19.     public const STATUS_UNPAID 'unpaid';
  20.     
  21.     /**
  22.      * Liste des statuts disponibles
  23.      */
  24.     public const STATUSES = [
  25.         'En attente' => self::STATUS_PENDING,
  26.         'Confirmé' => self::STATUS_CONFIRMED,
  27.         'Annulé' => self::STATUS_CANCELLED,
  28.         'Impayé' => self::STATUS_UNPAID
  29.     ];
  30.     #[ORM\Id]
  31.     #[ORM\GeneratedValue]
  32.     #[ORM\Column]
  33.     private ?int $id null;
  34.     #[ORM\Column(length255uniquetrue)]
  35.     private ?string $konnectPaymentId null;
  36.     #[ORM\Column(length20)]
  37.     private ?string $status self::STATUS_PENDING;
  38.     #[ORM\Column(typeTypes::DECIMALprecision10scale2nullabletrue)]
  39.     private ?string $amount null;
  40.     #[ORM\Column(length3nullabletrue)]
  41.     private ?string $currency 'EUR';
  42.     #[ORM\ManyToOne(inversedBy'payments')]
  43.     #[ORM\JoinColumn(nullablefalse)]
  44.     private ?Order $order null;
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getKonnectPaymentId(): ?string
  50.     {
  51.         return $this->konnectPaymentId;
  52.     }
  53.     public function setKonnectPaymentId(string $konnectPaymentId): static
  54.     {
  55.         $this->konnectPaymentId $konnectPaymentId;
  56.         return $this;
  57.     }
  58.     public function getStatus(): ?string
  59.     {
  60.         return $this->status;
  61.     }
  62.     public function setStatus(string $status): static
  63.     {
  64.         if (!in_array($status, [self::STATUS_PENDINGself::STATUS_CONFIRMEDself::STATUS_CANCELLEDself::STATUS_UNPAID])) {
  65.             throw new \InvalidArgumentException(sprintf(
  66.                 'Statut invalide "%s". Les statuts autorisés sont : %s',
  67.                 $status,
  68.                 implode(', ', [self::STATUS_PENDINGself::STATUS_CONFIRMEDself::STATUS_CANCELLEDself::STATUS_UNPAID])
  69.             ));
  70.         }
  71.         
  72.         $this->status $status;
  73.         return $this;
  74.     }
  75.     public function getAmount(): ?string
  76.     {
  77.         return $this->amount;
  78.     }
  79.     public function setAmount(?string $amount): static
  80.     {
  81.         $this->amount $amount;
  82.         return $this;
  83.     }
  84.     public function getCurrency(): ?string
  85.     {
  86.         return $this->currency;
  87.     }
  88.     public function setCurrency(?string $currency): static
  89.     {
  90.         $this->currency $currency;
  91.         return $this;
  92.     }
  93.     public function getOrder(): ?Order
  94.     {
  95.         return $this->order;
  96.     }
  97.     public function setOrder(?Order $order): static
  98.     {
  99.         $this->order $order;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return bool
  104.      */
  105.     public function isPending(): bool
  106.     {
  107.         return $this->status === self::STATUS_PENDING;
  108.     }
  109.     
  110.     /**
  111.      * @return bool
  112.      */
  113.     public function isConfirmed(): bool
  114.     {
  115.         return $this->status === self::STATUS_CONFIRMED;
  116.     }
  117.     
  118.     /**
  119.      * @return bool
  120.      */
  121.     public function isCancelled(): bool
  122.     {
  123.         return $this->status === self::STATUS_CANCELLED;
  124.     }
  125.     
  126.     /**
  127.      * @return bool
  128.      */
  129.     public function isUnpaid(): bool
  130.     {
  131.         return $this->status === self::STATUS_UNPAID;
  132.     }
  133. }