src/Entity/Subscription.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubscriptionRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity(repositoryClass=SubscriptionRepository::class)
  7.  * @ORM\Table(name="`subscription`")
  8.  */
  9. class Subscription
  10. {
  11.     /**
  12.      * @ORM\Id
  13.      * @ORM\GeneratedValue
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private ?int $id null;
  17.     /**
  18.      * @ORM\Column(type="string")
  19.      */
  20.     private ?string $stripeId null;
  21.     /**
  22.      * @ORM\OneToOne (targetEntity="App\Entity\User", inversedBy="subscription")
  23.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  24.      */
  25.     private ?User $user null;
  26.     /**
  27.      * @ORM\Column(type="string")
  28.      */
  29.     private ?string $stripeUser null;
  30.     /**
  31.      * @ORM\Column(type="string", nullable=true)
  32.      */
  33.     private ?string $stripePlan null;
  34.     /**
  35.      * @ORM\Column(type="datetime", nullable=true)
  36.      */
  37.     private ?\DateTime $periodStart null;
  38.     /**
  39.      * @ORM\Column(type="datetime", nullable=true)
  40.      */
  41.     private ?\DateTime $periodEnd null;
  42.     /**
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      */
  45.     private ?\DateTime $cancelAt null;
  46.     /**
  47.      * @ORM\Column(type="string", nullable=true)
  48.      */
  49.     private ?string $status null;
  50.     /**
  51.      * @ORM\Column(type="datetime")
  52.      */
  53.     private ?\DateTime $created null;
  54.     public function __construct()
  55.     {
  56.         $this->created = new \DateTime();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function setId(?int $id): void
  63.     {
  64.         $this->id $id;
  65.     }
  66.     public function getStripeId(): ?string
  67.     {
  68.         return $this->stripeId;
  69.     }
  70.     public function setStripeId(?string $stripeId): void
  71.     {
  72.         $this->stripeId $stripeId;
  73.     }
  74.     public function getUser(): ?User
  75.     {
  76.         return $this->user;
  77.     }
  78.     public function setUser(?User $user): void
  79.     {
  80.         $this->user $user;
  81.         $user->setSubscription($this);
  82.     }
  83.     public function getStripeUser(): ?string
  84.     {
  85.         return $this->stripeUser;
  86.     }
  87.     public function setStripeUser(?string $stripeUser): void
  88.     {
  89.         $this->stripeUser $stripeUser;
  90.     }
  91.     public function getStripePlan(): ?string
  92.     {
  93.         return $this->stripePlan;
  94.     }
  95.     public function setStripePlan(?string $stripePlan): void
  96.     {
  97.         $this->stripePlan $stripePlan;
  98.     }
  99.     public function getPeriodStart(): ?\DateTime
  100.     {
  101.         return $this->periodStart;
  102.     }
  103.     public function setPeriodStart(?\DateTime $periodStart): void
  104.     {
  105.         $this->periodStart $periodStart;
  106.     }
  107.     public function getPeriodEnd(): ?\DateTime
  108.     {
  109.         return $this->periodEnd;
  110.     }
  111.     public function setPeriodEnd(?\DateTime $periodEnd): void
  112.     {
  113.         $this->periodEnd $periodEnd;
  114.     }
  115.     public function getCancelAt(): ?\DateTime
  116.     {
  117.         return $this->cancelAt;
  118.     }
  119.     public function setCancelAt(?\DateTime $cancelAt): void
  120.     {
  121.         $this->cancelAt $cancelAt;
  122.     }
  123.     public function getStatus(): ?string
  124.     {
  125.         return $this->status;
  126.     }
  127.     public function setStatus(?string $status): void
  128.     {
  129.         $this->status $status;
  130.     }
  131.     public function getCreated(): ?\DateTime
  132.     {
  133.         return $this->created;
  134.     }
  135.     public function setCreated(?\DateTime $created): void
  136.     {
  137.         $this->created $created;
  138.     }
  139.     public function isValid(): bool
  140.     {
  141.         if (in_array($this->status, ['active''past_due'])) {
  142.             return true;
  143.         }
  144.         if ('canceled' === $this->status) {
  145.             return false;
  146.         }
  147.         return null === $this->cancelAt || new \DateTime() < $this->cancelAt;
  148.     }
  149.     public function __toString(): string
  150.     {
  151.         return $this->getStripeId() ?? '';
  152.     }
  153. }