mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-25 02:20:32 +02:00
Page de paiement (en cours)
This commit is contained in:
@ -2,14 +2,17 @@
|
||||
|
||||
class PaymentMethod
|
||||
{
|
||||
const CREDIT_CARD = 0;
|
||||
const BANK_CHECK = 1;
|
||||
const BANK_TRANSFER = 2;
|
||||
const CASH = 3;
|
||||
const SCHOLARSHIP = 4;
|
||||
const CREDIT_CARD = 1;
|
||||
const BANK_CHECK = 2;
|
||||
const BANK_TRANSFER = 3;
|
||||
const CASH = 4;
|
||||
const SCHOLARSHIP = 5;
|
||||
const NOT_PAID = 0;
|
||||
|
||||
public static function getTranslatedName($status) {
|
||||
switch ($status) {
|
||||
case self::CREDIT_CARD:
|
||||
return "Carte bancaire";
|
||||
case self::BANK_CHECK:
|
||||
return "Chèque";
|
||||
case self::BANK_TRANSFER:
|
||||
@ -18,13 +21,15 @@ class PaymentMethod
|
||||
return "Espèce";
|
||||
case self::SCHOLARSHIP:
|
||||
return "Je suis boursier";
|
||||
default:
|
||||
return "Carte bancaire";
|
||||
default:
|
||||
return "Pas encore payé";
|
||||
}
|
||||
}
|
||||
|
||||
public static function getName($status) {
|
||||
switch ($status) {
|
||||
case self::CREDIT_CARD:
|
||||
return "CREDIT_CARD";
|
||||
case self::BANK_CHECK:
|
||||
return "BANK_CHECK";
|
||||
case self::BANK_TRANSFER:
|
||||
@ -34,12 +39,14 @@ class PaymentMethod
|
||||
case self::SCHOLARSHIP:
|
||||
return "SCHOLARSHIP";
|
||||
default:
|
||||
return "CREDIT_CARD";
|
||||
return "NOT_PAID";
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromName($name) {
|
||||
switch ($name) {
|
||||
case "CREDIT_CARD":
|
||||
return self::CREDIT_CARD;
|
||||
case "BANK_CHECK":
|
||||
return self::BANK_CHECK;
|
||||
case "BANK_TRANSFER":
|
||||
@ -49,7 +56,7 @@ class PaymentMethod
|
||||
case "SCHOLARSHIP":
|
||||
return self::SCHOLARSHIP;
|
||||
default:
|
||||
return self::CREDIT_CARD;
|
||||
return self::NOT_PAID;
|
||||
}
|
||||
}
|
||||
}
|
@ -110,6 +110,14 @@ class Team
|
||||
return $this->tournament;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Tournament
|
||||
*/
|
||||
public function getEffectiveTournament()
|
||||
{
|
||||
return $this->isSelectedForFinal() ? Tournament::getFinalTournament() : Tournament::fromId($this->getTournamentId());
|
||||
}
|
||||
|
||||
public function setTournamentId($tournament)
|
||||
{
|
||||
global $DB;
|
||||
|
@ -422,6 +422,22 @@ class User
|
||||
return $docs;
|
||||
}
|
||||
|
||||
public function getPayment() {
|
||||
global $DB;
|
||||
|
||||
$team = Team::fromId($this->team_id);
|
||||
$tournament = $team->getEffectiveTournament();
|
||||
|
||||
$req = $DB->prepare("SELECT `id` FROM `payments` WHERE `user` = ? AND `tournament` = ?;");
|
||||
$req->execute([$this->id, $tournament->getId()]);
|
||||
|
||||
if (($data = $req->fetch()) !== false)
|
||||
return Payment::fromId($data["id"]);
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `payments`(`user`, `tournament`, `amount`, `method`, `transaction_infos`, `validation_status`) VALUES (?, ?, ?, ?, ?, ?);");
|
||||
$req->execute([$this->id, $tournament->getId(), 0, PaymentMethod::getName(PaymentMethod::NOT_PAID), "L'inscription n'est pas encore payée.", ValidationStatus::getName(ValidationStatus::NOT_READY)]);
|
||||
}
|
||||
|
||||
public function getOrganizedTournaments()
|
||||
{
|
||||
global $DB;
|
||||
|
@ -1,2 +1,16 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_SESSION["user_id"]) || ($_SESSION["role"] != Role::PARTICIPANT && $_SESSION["role"] != Role::ENCADRANT))
|
||||
require_once "server_files/403.php";
|
||||
|
||||
/**
|
||||
* @var User $user
|
||||
* @var Team $team
|
||||
* @var Tournament $tournament
|
||||
*/
|
||||
$user = $_SESSION["user"];
|
||||
$team = $_SESSION["team"];
|
||||
$tournament = $team->getEffectiveTournament();
|
||||
$payment = $user->getPayment();
|
||||
|
||||
require_once "server_files/views/paiement.php";
|
@ -7,4 +7,36 @@ require_once "header.php"
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
if ($payment->getValidationStatus() == ValidationStatus::NOT_READY) { ?>
|
||||
<div class="alert alert-danger">
|
||||
Il faut payer maintenant.
|
||||
</div>
|
||||
|
||||
<div class="alert alert-info">
|
||||
<form method="POST">
|
||||
<label for="method"><strong>Mode de paiement :</strong></label>
|
||||
<select class="custom-select" id="method" name="method">
|
||||
<?php
|
||||
for ($method = PaymentMethod::NOT_PAID; $method <= PaymentMethod::SCHOLARSHIP; ++$method) { ?>
|
||||
<option value="<?= strtolower(PaymentMethod::getName($method)) ?>"><?= PaymentMethod::getTranslatedName($method) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<label for="infos"><strong>Informations sur le paiement :</strong></label>
|
||||
<textarea class="form-control" name="infos" id="infos"></textarea>
|
||||
<label for="scholarship"><strong>Notification de bourse :</strong></label>
|
||||
<input type="file" class="form-control" name="scholarship" id="scholarship" />
|
||||
<input class="btn btn-primary btn-block" type="submit" name="pay" value="Envoyer" />
|
||||
</form>
|
||||
</div>
|
||||
<?php } else if ($payment->getValidationStatus() == ValidationStatus::WAITING) { ?>
|
||||
<div class="alert alert-warning">
|
||||
Votre paiement est en attente de validation.
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="alert alert-success">
|
||||
Votre paiement de <?= $payment->getAmount() ?> a bien été validé.
|
||||
</div>
|
||||
<?php }
|
||||
|
||||
require_once "footer.php";
|
Reference in New Issue
Block a user