11namespace ComusParty\Controllers;
13use ComusParty\App\Exceptions\NotFoundException;
14use ComusParty\App\Mailer;
15use ComusParty\App\MessageHandler;
16use ComusParty\Models\ArticleDAO;
17use ComusParty\Models\InvoiceDAO;
18use ComusParty\Models\PlayerDAO;
19use ComusParty\Models\UserDAO;
20use DateMalformedStringException;
23use Twig\Error\LoaderError;
24use Twig\Error\RuntimeError;
25use Twig\Error\SyntaxError;
26use Twig\Loader\FilesystemLoader;
58 $articles = $managerArticle->findAll();
59 $pfps = $managerArticle->findAllPfps();
60 $banners = $managerArticle->findAllBanners();
61 $pfpsOwned = $managerArticle->findAllPfpsOwnedByPlayer($_SESSION[
'uuid']);
63 foreach ($pfpsOwned as $pfpOwned) {
64 $idsPfpsOwned[] = $pfpOwned->getId();
66 $bannersOwned = $managerArticle->findAllBannersOwnedByPlayer($_SESSION[
'uuid']);
67 $idsBannersOwned = [];
68 foreach ($bannersOwned as $bannerOwned) {
69 $idsBannersOwned[] = $bannerOwned->getId();
71 $template = $this->
getTwig()->load(
'player/shop.twig');
72 if (isset($_SESSION[
'basket'])) {
73 $numberArticlesInBasket = count($_SESSION[
'basket']);
75 $numberArticlesInBasket = 0;
77 echo $template->render(array(
78 'articles' => $articles,
80 'banners' => $banners,
81 'idsPfpsOwned' => $idsPfpsOwned,
82 'idsBannersOwned' => $idsBannersOwned,
83 'numberArticlesInBasket' => $numberArticlesInBasket
99 $articles = $managerArticle->findAll();
100 $template = $this->
getTwig()->load(
'player/shop.twig');
102 echo $template->render(array(
'articles' => $articles));
116 foreach ($_SESSION[
'basket'] as $id) {
118 $article = $managerArticle->findById($id);
119 $articles[] = $article;
122 $template = $this->
getTwig()->load(
'player/checkout.twig');
123 echo $template->render(array(
'articles' => $articles));
138 $cardNumber = preg_replace(
'/\s/',
'', $datas[
'cardNumber']);
140 if (strlen($cardNumber) !== 16) {
141 MessageHandler::sendJsonCustomException(400,
"Le numéro de la carte doit contenir 16 chiffres.");
146 MessageHandler::sendJsonCustomException(400,
"Le numéro de carte n'est pas valide.");
150 if (strlen($datas[
'cvv']) !== 3) {
151 MessageHandler::sendJsonCustomException(400,
"Le cryptogramme de sécurité doit contenir 3 chiffres.");
156 list($month, $year) = explode(
"/", $datas[
'expirationDate']);
157 $expirationDate =
new DateTime();
158 $expirationDate->setDate(2000 + (
int)$year, (
int)$month, 1);
159 $now =
new DateTime();
160 if ($expirationDate < $now) {
161 MessageHandler::sendJsonCustomException(400,
"La date d'expiration de la carte est dépassée.");
165 echo MessageHandler::sendJsonMessage(200,
"Paiement effectué avec succès.");
183 $length = strlen($card);
185 for ($i = 0; $i < $length - 1; $i++) {
187 $digit = (int)$card[$i] * 2;
189 $digitStr = (string)$digit;
190 $digit = (int)$digitStr[0] + (
int)$digitStr[1];
194 $sum += (int)$card[$i];
197 $key = 10 - ($sum % 10) % 10;
198 return $key == $card[$length - 1];
218 $articles = $managerArticle->findArticlesByInvoiceId($invoiceId);
219 $player = $managerPlayer->findWithDetailByUuid($_SESSION[
'uuid']);
220 $email = $managerUser->findById($player->getUserId())->getEmail();
221 $invoice = $managerInvoice->findById($invoiceId);
223 $template = $this->
getTwig()->load(
'player/invoice.twig');
224 echo $template->render(array(
225 'invoice' => $invoice,
226 'username' => $player->getUsername(),
228 'articles' => $articles
246 $managerInvoice->createInvoiceWithArticles($playerUuid, $paymentType, $articles);
249 $player = $managerPlayer->findByUuid($playerUuid);
251 $user = $managerUser->findById($player->getUserId());
253 $mail =
new Mailer(array($user->getEmail()),
"ComusParty - Paiement effectué",
"Votre paiement a bien été effectué. Vous pouvez consulter votre facture sur votre profil.");
256 $template = $this->
getTwig()->load(
'player/success-payment.twig');
257 echo $template->render();
259 unset($_SESSION[
'basket']);
260 header(
"Refresh: 5; url=/");
showCheckout()
Permet d'afficher la page de paiement.
showSuccessPayment(array $articles, string $playerUuid, string $paymentType)
Affiche la page de succès de paiement.
show()
Permet d'afficher tous les articles (avatars / bannières)
__construct(FilesystemLoader $loader, Environment $twig)
Constructeur de la classe ControllerShop.
showAll()
Permet d'afficher tous les articles.
checkLuhnValid(?string $card)
Exécute l'algorithme de Luhn sur le numéro de carte passé en paramètre.
showInvoice(int $invoiceId)
Affiche la facture générée grâce à l'ID passé en paramètre GET.
checkPaymentRequirement(?array $datas)
Vérifie si l'ensemble des données du formulaire de paiement, passées en paramètre via un tableau asso...
getTwig()
Retourne l'attribut twig, correspondant à l'environnement de Twig.
getPdo()
Retourne l'attribut PDO, correspondant à la connexion à la base de données.