From b86675ba98010767cf1984aa9e54552de13bfced Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 14 Jan 2020 12:21:18 +0100 Subject: [PATCH] Validation paiements --- server_files/controllers/informations.php | 53 ++++++++++++++++++- server_files/controllers/mon_compte.php | 11 ++-- server_files/services/mail.php | 43 +++++++++++++++ .../mail_templates/unvalidate_payment.html | 24 +++++++++ .../mail_templates/validate_payment.html | 24 +++++++++ server_files/views/informations.php | 52 ++++++++++++++++-- 6 files changed, 198 insertions(+), 9 deletions(-) create mode 100644 server_files/services/mail_templates/unvalidate_payment.html create mode 100644 server_files/services/mail_templates/validate_payment.html diff --git a/server_files/controllers/informations.php b/server_files/controllers/informations.php index 6863dec..6d9cb91 100644 --- a/server_files/controllers/informations.php +++ b/server_files/controllers/informations.php @@ -16,6 +16,12 @@ if ($user === null) $team = Team::fromId($user->getTeamId()); +if ($team != null) { + $documents = $user->getAllDocuments($team->getTournamentId()); + $payment = $user->getPayment(); + $tournament = Tournament::fromId($team->getTournamentId()); +} + $has_error = false; $error_message = null; @@ -41,6 +47,17 @@ if (isset($_POST["attribute_team"])) { } } +if (isset($_POST["validate_payment"])) { + $validate_payment = new ValidatePayment($_POST); + try { + $validate_payment->makeVerifications(); + $validate_payment->validate(); + } catch (AssertionError $e) { + $has_error = true; + $error_message = $e->getMessage(); + } +} + if (isset($_POST["view_as"]) && $_SESSION["role"] == Role::ADMIN) { if (!isset($_SESSION["admin"])) $_SESSION["admin"] = $_SESSION["user_id"]; @@ -109,7 +126,39 @@ class AttributeTeam } } -if ($team != null) - $documents = $user->getAllDocuments($team->getTournamentId()); +class ValidatePayment +{ + private $accept, $reject; + private $message; + private $payment; + + public function __construct($data) + { + global $user; + + foreach ($data as $key => $value) + $this->$key = $value; + + $this->payment = $user->getPayment(); + } + + public function makeVerifications() + { + ensure($this->payment->getValidationStatus() == ValidationStatus::WAITING, "Le paiement n'était pas en attente."); + ensure(isset($this->accept) ^ isset($this->reject), "La sélection de validation est invalide."); + } + + public function validate() + { + global $user, $team, $tournament; + + if ($this->accept) + $this->payment->setValidationStatus(ValidationStatus::VALIDATED); + else + $this->payment->setValidationStatus(ValidationStatus::NOT_READY); + + Mailer::sendValidatePayment($user, $team, $tournament, $this->payment, $this->message); + } +} require_once "server_files/views/informations.php"; diff --git a/server_files/controllers/mon_compte.php b/server_files/controllers/mon_compte.php index 69ec017..4f709ca 100644 --- a/server_files/controllers/mon_compte.php +++ b/server_files/controllers/mon_compte.php @@ -11,7 +11,8 @@ if (!isset($_SESSION["user_id"])) $user = $_SESSION["user"]; $team = $_SESSION["team"]; -$tournament = Tournament::fromId($team->getTournamentId()); +if ($team != null) + $tournament = Tournament::fromId($team->getTournamentId()); $has_error = false; $error_message = null; @@ -208,8 +209,10 @@ class SendDocument } } -$documents = $user->getAllDocuments($team->getTournamentId()); -if ($team->isSelectedForFinal()) - $documents_final = $user->getAllDocuments($FINAL->getId()); +if ($team != null) { + $documents = $user->getAllDocuments($team->getTournamentId()); + if ($team->isSelectedForFinal()) + $documents_final = $user->getAllDocuments($FINAL->getId()); +} require_once "server_files/views/mon_compte.php"; diff --git a/server_files/services/mail.php b/server_files/services/mail.php index 18be95b..e3a1a83 100644 --- a/server_files/services/mail.php +++ b/server_files/services/mail.php @@ -127,4 +127,47 @@ class Mailer self::sendMail($organizer->getEmail(), "Ajout d'un organisateur pour le tournoi " . $tournament->getName() . " – TFJM² $YEAR", $content); } + + public static function requestPaymentValidation(User $user, Team $team, Tournament $tournament, Payment $payment) + { + global $YEAR, $URL_BASE; + + $content = self::getTemplate("request_payment_validation"); + $content = preg_replace("#{USER_FIRST_NAME}#", $user->getFirstName(), $content); + $content = preg_replace("#{USER_SURNAME}#", $user->getSurname(), $content); + $content = preg_replace("#{TEAM_NAME}#", $team->getName(), $content); + $content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content); + $content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content); + $content = preg_replace("#{AMOUNT}#", $payment->getAmount(), $content); + $content = preg_replace("#{PAYMENT_METHOD}#", PaymentMethod::getTranslatedName($payment->getMethod()), $content); + if ($payment->getMethod() == PaymentMethod::SCHOLARSHIP) + $content = preg_replace("#{PAYMENT_INFOS}#", "getTransactionInfos() . "\">Voir la notification de bourse", $content); + else + $content = preg_replace("#{PAYMENT_INFOS}#", $payment->getTransactionInfos(), $content); + + self::sendMail($user->getEmail(), "Demande de validation de paiement pour le tournoi " . $tournament->getName() . " – TFJM² $YEAR", $content); + } + + public static function sendValidatePayment(User $user, Team $team, Tournament $tournament, Payment $payment, $message) + { + global $YEAR, $URL_BASE; + + $content = self::getTemplate($payment->getValidationStatus() == ValidationStatus::VALIDATED ? "validate_payment" : "unvalidate_payment"); + $content = preg_replace("#{FIRST_NAME}#", $user->getFirstName(), $content); + $content = preg_replace("#{SURNAME}#", $user->getSurname(), $content); + $content = preg_replace("#{TEAM_NAME}#", $team->getName(), $content); + $content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content); + $content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content); + $content = preg_replace("#{AMOUNT}#", $payment->getAmount(), $content); + $content = preg_replace("#{PAYMENT_METHOD}#", PaymentMethod::getTranslatedName($payment->getMethod()), $content); + if ($payment->getMethod() == PaymentMethod::SCHOLARSHIP) + $content = preg_replace("#{PAYMENT_INFOS}#", "getTransactionInfos() . "\">Voir la notification de bourse", $content); + else + $content = preg_replace("#{PAYMENT_INFOS}#", $payment->getTransactionInfos(), $content); + if (isset($message) && strlen($message) > 0) { + $content = preg_replace("#{MESSAGE}#", "L'équipe d'organisation vous transmet les informations suivantes :

" . $message . "
", $content); + } + + self::sendMail($user->getEmail(), "Paiement pour le tournoi " . $tournament->getName() . " – TFJM² $YEAR", $content); + } } diff --git a/server_files/services/mail_templates/unvalidate_payment.html b/server_files/services/mail_templates/unvalidate_payment.html new file mode 100644 index 0000000..c6e99ff --- /dev/null +++ b/server_files/services/mail_templates/unvalidate_payment.html @@ -0,0 +1,24 @@ + + + + + + Non-validation du paiement pour le TFJM² {YEAR} + + +Bonjour {FIRST_NAME} {SURNAME},
+
+Votre paiement pour le TFJM² {YEAR} a malheureusement été rejeté. Pour rappel, vous aviez fourni ces informations :

+Équipe : {TEAM_NAME} ({TRIGRAM})
+Tournoi : {TOURNAMENT_NAME}
+Moyen de paiement : {PAYMENT_METHOD}
+Montant : {AMOUNT} €
+Informations sur le paiement : {PAYMENT_INFOS}
+
+{MESSAGE} +
+Cordialement, +
+Le comité national d'organisation du TFJM2 + + \ No newline at end of file diff --git a/server_files/services/mail_templates/validate_payment.html b/server_files/services/mail_templates/validate_payment.html new file mode 100644 index 0000000..afe94ba --- /dev/null +++ b/server_files/services/mail_templates/validate_payment.html @@ -0,0 +1,24 @@ + + + + + + Validation du paiement pour le TFJM² {YEAR} + + +Bonjour {FIRST_NAME} {SURNAME},
+
+Votre paiement pour le TFJM² {YEAR} a bien été validé. Pour rappel, vous aviez fourni ces informations :

+Équipe : {TEAM_NAME} ({TRIGRAM})
+Tournoi : {TOURNAMENT_NAME}
+Moyen de paiement : {PAYMENT_METHOD}
+Montant : {AMOUNT} €
+Informations sur le paiement : {PAYMENT_INFOS}
+
+{MESSAGE} +
+Cordialement, +
+Le comité national d'organisation du TFJM2 + + \ No newline at end of file diff --git a/server_files/views/informations.php b/server_files/views/informations.php index 0500384..69dcdf2 100644 --- a/server_files/views/informations.php +++ b/server_files/views/informations.php @@ -14,9 +14,12 @@ if (!$has_error) {
La personne a bien rejoint l'équipe !
- + +
+ La paiement a bien été validé / rejeté ! Un mail a été transmis au participant. +
+ +
Rôle : getRole()) ?> @@ -101,6 +104,49 @@ if (!$has_error) { Adresse e-mail du responsable légal : getResponsibleEmail() ?>
+
+ Récapitulatif du paiement :

+ + getValidationStatus() == ValidationStatus::NOT_READY) { ?> +
+ Cette personne n'a pas encore payé sa participation. +
+ + Tournoi : getName() ?>
+ Montant : getAmount() ?> €
+ Moyen de paiement : getMethod()) ?>
+ getMethod() == PaymentMethod::SCHOLARSHIP) { ?> + Notification de bourse : Télécharger

+ + Informations sur le paiement : getTransactionInfos() ?>

+ getValidationStatus() == ValidationStatus::WAITING) { ?> +
+ Le paiement n'a pas encore été validé. + +
+ + +
+ + +
+ + + +
+
+ +
+ Le paiement a été validé. +
+ + +
+ getDescription() != "") { ?>
Description : getDescription() ?>