src/Domain/Payment/Model/PaymentStatus.php line 7

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Payment\Model;
  4. class PaymentStatus
  5. {
  6.     public const INITIATED 'initiated';
  7.     public const PENDING 'pending';
  8.     public const COMPLETED 'completed';
  9.     public const CANCELLED 'cancelled';
  10.     public const REJECTED 'rejected';
  11.     public const VALUES = [
  12.         self::INITIATED,
  13.         self::PENDING,
  14.         self::COMPLETED,
  15.         self::CANCELLED,
  16.         self::REJECTED,
  17.     ];
  18.     private string $value;
  19.     public function __construct(string $value)
  20.     {
  21.         if (!\in_array($valueself::VALUEStrue)) {
  22.             throw new \InvalidArgumentException('Invalid value for payment status.');
  23.         }
  24.         $this->value $value;
  25.     }
  26.     public function __toString(): string
  27.     {
  28.         return $this->value;
  29.     }
  30.     public function getValue(): string
  31.     {
  32.         return $this->value;
  33.     }
  34.     public static function initiated(): self
  35.     {
  36.         return new self(self::INITIATED);
  37.     }
  38.     public static function pending(): self
  39.     {
  40.         return new self(self::PENDING);
  41.     }
  42.     public static function completed(): self
  43.     {
  44.         return new self(self::COMPLETED);
  45.     }
  46.     public static function cancelled(): self
  47.     {
  48.         return new self(self::CANCELLED);
  49.     }
  50.     public static function rejected(): self
  51.     {
  52.         return new self(self::REJECTED);
  53.     }
  54.     public function isCompleted(): bool
  55.     {
  56.         return self::COMPLETED === $this->value;
  57.     }
  58.     public function isRejected(): bool
  59.     {
  60.         return self::REJECTED === $this->value;
  61.     }
  62.     public function isCancelled(): bool
  63.     {
  64.         return self::CANCELLED === $this->value;
  65.     }
  66.     public function isFailed(): bool
  67.     {
  68.         return self::REJECTED === $this->value || self::CANCELLED === $this->value;
  69.     }
  70.     public function isPending(): bool
  71.     {
  72.         return self::PENDING === $this->value;
  73.     }
  74. }