src/Entity/Transaction.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\TransactionRepository;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use App\Entity\Traits\TimestampableEntity;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  11. /**
  12.  * @ApiResource(
  13.  *      attributes={"security"="is_granted('ROLE_SUPER_ADMIN')"},
  14.  *      normalizationContext={"groups"={"Transaction:Read"}, "skip_null_values"=false},
  15.  *      denormalizationContext={"groups"={"Transaction:Write"}},
  16.  *      collectionOperations={
  17.  *          "get_transaction"={
  18.  *              "path"="/transactions/get-transaction",
  19.  *              "method"="GET",
  20.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')"
  21.  *          }
  22.  *      },
  23.  *      itemOperations={
  24.  *          "get"
  25.  *      }
  26.  * )
  27.  * @ApiFilter(SearchFilter::class, properties={"id": "exact", "client.id": "exact", "user.id": "exact", "status": "exact", "stripeSessionId": "exact"})
  28.  * @ApiFilter(OrderFilter::class, properties={"id", "createdAt"})
  29.  * @ORM\Entity(repositoryClass=TransactionRepository::class)
  30.  */
  31. class Transaction
  32. {
  33.     /**
  34.      * Hook timestampable behavior
  35.      * updates createdAt, updatedAt fields
  36.      */
  37.     use TimestampableEntity;
  38.     /**
  39.      * @ORM\Id
  40.      * @ORM\GeneratedValue
  41.      * @ORM\Column(type="integer")
  42.      * @Groups({"Transaction:Read"})
  43.      */
  44.     private $id;
  45.     /**
  46.      * @ORM\Column(type="integer")
  47.      * @Groups({"Transaction:Read"})
  48.      */
  49.     private $totalAmount;
  50.     /**
  51.      * @ORM\Column(type="string", length=32)
  52.      * @Groups({"Transaction:Read"})
  53.      */
  54.     private $status;
  55.     public const TRANSACTION_STATUS_CREATED "CREATED";
  56.     public const TRANSACTION_STATUS_SUCCESS "SUCCESS";
  57.     public const TRANSACTION_STATUS_FAILED "FAILED";
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="transactions")
  60.      * @Groups({"Transaction:Read"})
  61.      */
  62.     private $user;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=Client::class, inversedBy="transactions")
  65.      * @ORM\JoinColumn(nullable=false)
  66.      */
  67.     private $client;
  68.     /**
  69.      * @ORM\Column(type="json", nullable=true)
  70.      * @Groups({"Transaction:Read"})
  71.      */
  72.     private $req = [];
  73.     /**
  74.      * @ORM\Column(type="json", nullable=true)
  75.      */
  76.     private $res = [];
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $stripeSessionId;
  81.     /**
  82.      * @ORM\ManyToOne(targetEntity=Container::class)
  83.      */
  84.     private $container;
  85.     /**
  86.      * @ORM\Column(type="json", nullable=true)
  87.      * @Groups({"Transaction:Read"})
  88.      */
  89.     private $confirmRes = [];
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function getTotalAmount(): ?int
  95.     {
  96.         return $this->totalAmount;
  97.     }
  98.     public function setTotalAmount(int $totalAmount): self
  99.     {
  100.         $this->totalAmount $totalAmount;
  101.         return $this;
  102.     }
  103.     public function getStatus(): ?string
  104.     {
  105.         return $this->status;
  106.     }
  107.     public function setStatus(string $status): self
  108.     {
  109.         $this->status $status;
  110.         return $this;
  111.     }
  112.     public function getUser(): ?User
  113.     {
  114.         return $this->user;
  115.     }
  116.     public function setUser(?User $user): self
  117.     {
  118.         $this->user $user;
  119.         return $this;
  120.     }
  121.     public function getClient(): ?Client
  122.     {
  123.         return $this->client;
  124.     }
  125.     public function setClient(?Client $client): self
  126.     {
  127.         $this->client $client;
  128.         return $this;
  129.     }
  130.     public function getReq(): ?array
  131.     {
  132.         return $this->req;
  133.     }
  134.     public function setReq(?array $req): self
  135.     {
  136.         $this->req $req;
  137.         return $this;
  138.     }
  139.     public function getRes(): ?array
  140.     {
  141.         return $this->res;
  142.     }
  143.     public function setRes(?array $res): self
  144.     {
  145.         $this->res $res;
  146.         return $this;
  147.     }
  148.     public function getStripeSessionId(): ?string
  149.     {
  150.         return $this->stripeSessionId;
  151.     }
  152.     public function setStripeSessionId(?string $stripeSessionId): self
  153.     {
  154.         $this->stripeSessionId $stripeSessionId;
  155.         return $this;
  156.     }
  157.     public function getContainer(): ?Container
  158.     {
  159.         return $this->container;
  160.     }
  161.     public function setContainer(?Container $container): self
  162.     {
  163.         $this->container $container;
  164.         return $this;
  165.     }
  166.     public function getConfirmRes(): ?array
  167.     {
  168.         return $this->confirmRes;
  169.     }
  170.     public function setConfirmRes(?array $confirmRes): self
  171.     {
  172.         $this->confirmRes $confirmRes;
  173.         return $this;
  174.     }
  175. }