src/Entity/Payment.php line 76

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\Post;
  7. use ApiPlatform\OpenApi\Model\Operation;
  8. use ApiPlatform\OpenApi\Model\RequestBody;
  9. use App\Controller\Api\Controller\Payment\PayerAbonnementController;
  10. use App\Controller\Api\Controller\Payment\PayerCoursController;
  11. use App\Controller\Api\Controller\Payment\StudentPaymentController;
  12. use App\Repository\PaymentRepository;
  13. use DateTimeImmutable;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. #[ORM\Entity(repositoryClassPaymentRepository::class)]
  17. #[ApiResource(
  18.     operations: [
  19.         new Get(
  20.             openapiContext: [
  21.                 'security' => [['bearerAuth' => []]]
  22.             ]
  23.         ),
  24.         new GetCollection(),
  25.         new GetCollection(
  26.             uriTemplate'/student/{id}/payments',
  27.             controllerStudentPaymentController::class,
  28.             readfalse,
  29.             openapiContext: [
  30.                 'security' => [['bearerAuth' => []]]
  31.             ]
  32.         ),
  33.         new Post(
  34.             uriTemplate'/abonnement/{id}/subscribe',
  35.             controllerPayerAbonnementController::class,
  36.             readfalse,
  37.             writefalse,
  38.             openapi: new Operation(
  39.                 requestBody: new RequestBody(
  40.                     content: new \ArrayObject([
  41.                         'application/json' => [
  42.                             'schema' => [
  43.                                 'type' => 'object',
  44.                                 'properties' => [
  45.                                     'payment_method' => [
  46.                                         'type' => 'string',
  47.                                     ],
  48.                                 ]
  49.                             ]
  50.                         ]
  51.                     ])
  52.                 ),
  53.                 security: [['bearerAuth' => []]],
  54.                 description"Cette route permet à un élève de payer un abonnement. Ici ID = id de l'abonnement. Dans le corps de la requête HTTP, il faut envoyé la propriété payment_method contenant la methode de paiement et initiate_payment qui est juste un booleen",
  55.                 summary"Cette route permet à un élève de payer un abonnement. Ici ID = id de l'abonnement. Dans le corps de la requête HTTP, il faut envoyé la propriété payment_method contenant la methode de paiement et initiate_payment qui est juste un booleen"
  56.             ),
  57.         ),
  58.         new Post(
  59.             uriTemplate'/cours/{id}/paied',
  60.             controllerPayerCoursController::class,
  61.             readfalse,
  62.             writefalse,
  63.             openapiContext: [
  64.                 'security' => [['bearerAuth' => []]],
  65.                 'description' => "Cette route permet à un élève de payer un cours. Ici ID = id du cours. Dans le corps de la requête HTTP, il faut envoyé la propriété payment_method contenant la methode de paiement"
  66.             ]
  67.         ),
  68.     ],
  69.     normalizationContext: [
  70.         'groups' => ['read:payment:collection']
  71.     ]
  72. )]
  73. class Payment
  74. {
  75.     #[ORM\Id]
  76.     #[ORM\GeneratedValue]
  77.     #[ORM\Column]
  78.     #[Groups(['read:payment:collection'])]
  79.     private ?int $id null;
  80.     #[ORM\ManyToOne(inversedBy'payments')]
  81.     #[ORM\JoinColumn(nullablefalse)]
  82.     private ?Eleve $eleve null;
  83.     #[ORM\ManyToOne(inversedBy'payments')]
  84.     #[Groups(['read:payment:collection'])]
  85.     private ?Abonnement $abonnement null;
  86.     #[ORM\ManyToOne(inversedBy'payments')]
  87.     #[Groups(['read:payment:collection'])]
  88.     private ?Cours $cours null;
  89.     #[ORM\Column]
  90.     #[Groups(['read:payment:collection'])]
  91.     private ?\DateTimeImmutable $paidAt null;
  92.     #[ORM\Column]
  93.     #[Groups(['read:payment:collection'])]
  94.     private ?bool $isExpired null;
  95.     #[ORM\Column(nullabletrue)]
  96.     #[Groups(['read:payment:collection'])]
  97.     private ?\DateTimeImmutable $expiredAt null;
  98.     #[ORM\ManyToOne(inversedBy'payments')]
  99.     #[ORM\JoinColumn(nullablefalse)]
  100.     #[Groups(['read:payment:collection'])]
  101.     private ?PaymentMethod $paymentMethod null;
  102.     #[ORM\Column(length20)]
  103.     #[Groups(['read:payment:collection'])]
  104.     private ?string $reference null;
  105.     #[ORM\Column(nullabletrue)]
  106.     #[Groups(['read:payment:collection'])]
  107.     private ?float $amount null;
  108.     #[ORM\Column(length50nullabletrue)]
  109.     #[Groups(['read:payment:collection'])]
  110.     private ?string $status null;
  111.     #[ORM\Column(length150nullabletrue)]
  112.     #[Groups(['read:payment:collection'])]
  113.     private ?string $transactionReference null;
  114.     public function __construct()
  115.     {
  116.         $this->paidAt = new DateTimeImmutable();
  117.     }
  118.     public function getId(): ?int
  119.     {
  120.         return $this->id;
  121.     }
  122.     public function getEleve(): ?Eleve
  123.     {
  124.         return $this->eleve;
  125.     }
  126.     public function setEleve(?Eleve $eleve): self
  127.     {
  128.         $this->eleve $eleve;
  129.         return $this;
  130.     }
  131.     public function getAbonnement(): ?Abonnement
  132.     {
  133.         return $this->abonnement;
  134.     }
  135.     public function setAbonnement(?Abonnement $abonnement): self
  136.     {
  137.         $this->abonnement $abonnement;
  138.         return $this;
  139.     }
  140.     public function getCours(): ?Cours
  141.     {
  142.         return $this->cours;
  143.     }
  144.     public function setCours(?Cours $cours): self
  145.     {
  146.         $this->cours $cours;
  147.         return $this;
  148.     }
  149.     public function getPaidAt(): ?\DateTimeImmutable
  150.     {
  151.         return $this->paidAt;
  152.     }
  153.     public function setPaidAt(\DateTimeImmutable $paidAt): self
  154.     {
  155.         $this->paidAt $paidAt;
  156.         return $this;
  157.     }
  158.     public function isIsExpired(): ?bool
  159.     {
  160.         return $this->isExpired;
  161.     }
  162.     public function setIsExpired(bool $isExpired): self
  163.     {
  164.         $this->isExpired $isExpired;
  165.         return $this;
  166.     }
  167.     public function getExpiredAt(): ?\DateTimeImmutable
  168.     {
  169.         return $this->expiredAt;
  170.     }
  171.     public function setExpiredAt(?\DateTimeImmutable $expiredAt): self
  172.     {
  173.         $this->expiredAt $expiredAt;
  174.         return $this;
  175.     }
  176.     public function getPaymentMethod(): ?PaymentMethod
  177.     {
  178.         return $this->paymentMethod;
  179.     }
  180.     public function setPaymentMethod(?PaymentMethod $paymentMethod): self
  181.     {
  182.         $this->paymentMethod $paymentMethod;
  183.         return $this;
  184.     }
  185.     public function getReference(): ?string
  186.     {
  187.         return $this->reference;
  188.     }
  189.     public function setReference(string $reference): self
  190.     {
  191.         $this->reference $reference;
  192.         return $this;
  193.     }
  194.     public function getAmount(): ?float
  195.     {
  196.         return $this->amount;
  197.     }
  198.     public function setAmount(?float $amount): self
  199.     {
  200.         $this->amount $amount;
  201.         return $this;
  202.     }
  203.     public function getStatus(): ?string
  204.     {
  205.         return $this->status;
  206.     }
  207.     public function setStatus(?string $status): static
  208.     {
  209.         $this->status $status;
  210.         return $this;
  211.     }
  212.     public function getTransactionReference(): ?string
  213.     {
  214.         return $this->transactionReference;
  215.     }
  216.     public function setTransactionReference(?string $transactionReference): static
  217.     {
  218.         $this->transactionReference $transactionReference;
  219.         return $this;
  220.     }
  221. }