src/Domain/PaymentNotification/Model/PaymentNotification.php line 14

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\PaymentNotification\Model;
  4. use App\Domain\Payment\Model\Payment;
  5. use App\Domain\Payment\Model\PaymentStatus;
  6. use App\Domain\PaymentNotification\Event\PaymentNotificationCreatedEvent;
  7. use App\Domain\Shared\Model\Aggregate;
  8. use App\Domain\Shared\Model\TimestampTrait;
  9. use Symfony\Component\Uid\Uuid;
  10. class PaymentNotification extends Aggregate
  11. {
  12.     use TimestampTrait;
  13.     private int $attempts;
  14.     private PaymentStatus $paymentStatus;
  15.     public function __construct(
  16.         private readonly Uuid $id,
  17.         private readonly Payment $payment,
  18.         private bool $resolved,
  19.         private \DateTimeImmutable $sendDate
  20.     ) {
  21.         $this->createdAt = new \DateTimeImmutable();
  22.         $this->updatedAt null;
  23.         $this->attempts 0;
  24.         $this->paymentStatus $this->payment->getStatus();
  25.         $this->raise(new PaymentNotificationCreatedEvent($this));
  26.     }
  27.     public function getId(): Uuid
  28.     {
  29.         return $this->id;
  30.     }
  31.     public function getPayment(): Payment
  32.     {
  33.         return $this->payment;
  34.     }
  35.     public function getSendDate(): \DateTimeImmutable
  36.     {
  37.         return $this->sendDate;
  38.     }
  39.     public function setSendDate(\DateTimeImmutable $sendDate): void
  40.     {
  41.         $this->sendDate $sendDate;
  42.         $this->updatedAt = new \DateTimeImmutable();
  43.     }
  44.     public function resolve(): void
  45.     {
  46.         $this->resolved true;
  47.         $this->payment->setResolvedBySite(true);
  48.         $this->updatedAt = new \DateTimeImmutable();
  49.     }
  50.     public function getPaymentStatus(): PaymentStatus
  51.     {
  52.         return $this->paymentStatus;
  53.     }
  54.     public function isResolved(): bool
  55.     {
  56.         return $this->resolved;
  57.     }
  58.     public function incrementAttempts(): void
  59.     {
  60.         ++$this->attempts;
  61.         $this->updatedAt = new \DateTimeImmutable();
  62.     }
  63.     public function getAttempts(): int
  64.     {
  65.         return $this->attempts;
  66.     }
  67. }