Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare (strict_types = 1);
- namespace TonicForHealth\PaymentProcessing\Domain\PaymentProcessingContext\Entity\PurchaseTransaction;
- /**
- * Domain value object for a purchase transaction status.
- */
- class PurchaseTransactionStatus
- {
- const STATUS_CODE_PENDING = 1;
- const STATUS_CODE_APPROVED = 2;
- const STATUS_CODE_DECLINED = 3;
- /**
- * @var string[]
- */
- private static $statusTexts = [
- self::STATUS_CODE_PENDING => 'Pending',
- self::STATUS_CODE_APPROVED => 'Approved',
- self::STATUS_CODE_DECLINED => 'Declined',
- ];
- /**
- * @var int
- */
- private $statusCode;
- /**
- * @return PurchaseTransactionStatus
- */
- public static function createPending(): self
- {
- return new self(self::STATUS_CODE_PENDING);
- }
- /**
- * @return PurchaseTransactionStatus
- */
- public static function createApproved(): self
- {
- return new self(self::STATUS_CODE_APPROVED);
- }
- /**
- * @return PurchaseTransactionStatus
- */
- public static function createDeclined(): self
- {
- return new self(self::STATUS_CODE_DECLINED);
- }
- /**
- * @return bool
- */
- public function isPending(): bool
- {
- return self::STATUS_CODE_PENDING === $this->statusCode;
- }
- /**
- * @return bool
- */
- public function isApproved(): bool
- {
- return self::STATUS_CODE_APPROVED === $this->statusCode;
- }
- /**
- * @return bool
- */
- public function isDeclined(): bool
- {
- return self::STATUS_CODE_DECLINED === $this->statusCode;
- }
- /**
- * @param int $statusCode
- */
- private function __construct(int $statusCode)
- {
- $this->statusCode = $statusCode;
- }
- /**
- * @return int
- *
- * @deprecated
- */
- public function getStatusCode(): int
- {
- return $this->statusCode;
- }
- /**
- * @return string
- */
- public function __toString(): string
- {
- return self::$statusTexts[$this->statusCode];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement