Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.11 KB | None | 0 0
  1. <?php
  2.  
  3. declare (strict_types = 1);
  4.  
  5. namespace TonicForHealth\PaymentProcessing\Domain\PaymentProcessingContext\Entity\PurchaseTransaction;
  6.  
  7. /**
  8.  * Domain value object for a purchase transaction status.
  9.  */
  10. class PurchaseTransactionStatus
  11. {
  12.     const STATUS_CODE_PENDING = 1;
  13.     const STATUS_CODE_APPROVED = 2;
  14.     const STATUS_CODE_DECLINED = 3;
  15.  
  16.     /**
  17.      * @var string[]
  18.      */
  19.     private static $statusTexts = [
  20.         self::STATUS_CODE_PENDING => 'Pending',
  21.         self::STATUS_CODE_APPROVED => 'Approved',
  22.         self::STATUS_CODE_DECLINED => 'Declined',
  23.     ];
  24.  
  25.     /**
  26.      * @var int
  27.      */
  28.     private $statusCode;
  29.  
  30.     /**
  31.      * @return PurchaseTransactionStatus
  32.      */
  33.     public static function createPending(): self
  34.     {
  35.         return new self(self::STATUS_CODE_PENDING);
  36.     }
  37.  
  38.     /**
  39.      * @return PurchaseTransactionStatus
  40.      */
  41.     public static function createApproved(): self
  42.     {
  43.         return new self(self::STATUS_CODE_APPROVED);
  44.     }
  45.  
  46.     /**
  47.      * @return PurchaseTransactionStatus
  48.      */
  49.     public static function createDeclined(): self
  50.     {
  51.         return new self(self::STATUS_CODE_DECLINED);
  52.     }
  53.  
  54.     /**
  55.      * @return bool
  56.      */
  57.     public function isPending(): bool
  58.     {
  59.         return self::STATUS_CODE_PENDING === $this->statusCode;
  60.     }
  61.  
  62.     /**
  63.      * @return bool
  64.      */
  65.     public function isApproved(): bool
  66.     {
  67.         return self::STATUS_CODE_APPROVED === $this->statusCode;
  68.     }
  69.  
  70.     /**
  71.      * @return bool
  72.      */
  73.     public function isDeclined(): bool
  74.     {
  75.         return self::STATUS_CODE_DECLINED === $this->statusCode;
  76.     }
  77.  
  78.     /**
  79.      * @param int $statusCode
  80.      */
  81.     private function __construct(int $statusCode)
  82.     {
  83.         $this->statusCode = $statusCode;
  84.     }
  85.  
  86.     /**
  87.      * @return int
  88.      *
  89.      * @deprecated
  90.      */
  91.     public function getStatusCode(): int
  92.     {
  93.         return $this->statusCode;
  94.     }
  95.  
  96.     /**
  97.      * @return string
  98.      */
  99.     public function __toString(): string
  100.     {
  101.         return self::$statusTexts[$this->statusCode];
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement