From 1c6c480d4c12bcfe7dd61833674e7264c8284b4b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 27 Dec 2019 14:54:44 +0100 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9paration=20pour=20la=20prise=20en=20cha?= =?UTF-8?q?rge=20du=20paiement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dispatcher.php | 5 +- server_files/classes/Payment.php | 142 +++++++++++++++++++++++++ server_files/classes/PaymentMethod.php | 55 ++++++++++ server_files/controllers/paiement.php | 2 + server_files/views/header.php | 14 +-- server_files/views/paiement.php | 10 ++ 6 files changed, 221 insertions(+), 7 deletions(-) create mode 100644 server_files/classes/Payment.php create mode 100644 server_files/classes/PaymentMethod.php create mode 100644 server_files/controllers/paiement.php create mode 100644 server_files/views/paiement.php diff --git a/dispatcher.php b/dispatcher.php index 317038c..2328005 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -9,6 +9,8 @@ require_once "server_files/classes/Team.php"; require_once "server_files/classes/Tournament.php"; require_once "server_files/classes/User.php"; require_once "server_files/classes/ValidationStatus.php"; +require_once "server_files/classes/PaymentMethod.php"; +require_once "server_files/classes/Payment.php"; require_once "server_files/services/mail.php"; require_once "server_files/utils.php"; require_once "server_files/model.php"; @@ -41,7 +43,8 @@ $ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"]; $ROUTES["^mon-compte/?$"] = ["server_files/controllers/mon_compte.php"]; $ROUTES["^mon-equipe/(modifier)/?$"] = ["server_files/controllers/mon_equipe.php", "modifier"]; $ROUTES["^mon-equipe/?$"] = ["server_files/controllers/mon_equipe.php"]; -$ROUTES["^organisateurs"] = ["server_files/controllers/organisateurs.php"]; +$ROUTES["^organisateurs/?$"] = ["server_files/controllers/organisateurs.php"]; +$ROUTES["^paiement/?$"] = ["server_files/controllers/paiement.php"]; $ROUTES["^profils/?$"] = ["server_files/controllers/profils.php"]; $ROUTES["^profils-(orphelins)/?$"] = ["server_files/controllers/profils.php", "orphans"]; $ROUTES["^rejoindre_equipe/?$"] = ["server_files/controllers/rejoindre_equipe.php"]; diff --git a/server_files/classes/Payment.php b/server_files/classes/Payment.php new file mode 100644 index 0000000..7cb12bc --- /dev/null +++ b/server_files/classes/Payment.php @@ -0,0 +1,142 @@ +prepare("SELECT * FROM `payments` WHERE `id` = ?;"); + $req->execute([htmlspecialchars($id)]); + $data = $req->fetch(); + + if ($data === false) + return null; + + $payment = new Payment(); + $payment->fill($data); + return $payment; + } + + private function fill($data) + { + $this->id = $data["id"]; + $this->user_id = $data["user"]; + $this->tournament_id = $data["tournament"]; + $this->amount = $data["amount"]; + $this->method = PaymentMethod::fromName($data["method"]); + $this->transaction_infos = $data["transaction_infos"]; + $this->validation_status = ValidationStatus::fromName($data["validation_status"]); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return int + */ + public function getAmount() + { + return $this->amount; + } + + /** + * @return int + */ + public function getMethod() + { + return $this->method; + } + + /** + * @param int $method + */ + public function setMethod($method) + { + global $DB; + $this->method = $method; + $DB->prepare("UPDATE `payments` SET `method` = ? WHERE `id` = ?;")->execute([PaymentMethod::getName($method), $this->id]); + } + + /** + * @return int + */ + public function getTournamentId() + { + return $this->tournament_id; + } + + /** + * @return Tournament|null + */ + public function getTournament() + { + return Tournament::fromId($this->getTournamentId()); + } + + /** + * @return int + */ + public function getUserId() + { + return $this->user_id; + } + + /** + * @return User|null + */ + public function getUser() + { + return User::fromId($this->getUserId()); + } + + /** + * @return string + */ + public function getTransactionInfos() + { + return $this->transaction_infos; + } + + /** + * @param string $transaction_infos + */ + public function setTransactionInfos($transaction_infos) + { + global $DB; + $this->transaction_infos = $transaction_infos; + $DB->prepare("UPDATE `payments` SET `transaction_infos` = ? WHERE `id` = ?;")->execute([$transaction_infos, $this->id]); + } + + /** + * @return int + */ + public function getValidationStatus() + { + return $this->validation_status; + } + + /** + * @param int $validation_status + */ + public function setValidationStatus($validation_status) + { + global $DB; + $this->validation_status = $validation_status; + $DB->prepare("UPDATE `payments` SET `$validation_status` = ? WHERE `id` = ?;")->execute([ValidationStatus::fromName($validation_status), $this->id]); + } +} \ No newline at end of file diff --git a/server_files/classes/PaymentMethod.php b/server_files/classes/PaymentMethod.php new file mode 100644 index 0000000..57885fe --- /dev/null +++ b/server_files/classes/PaymentMethod.php @@ -0,0 +1,55 @@ + getValidationStatus() == ValidationStatus::VALIDATED || true) { ?>