mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 07:42:11 +01:00 
			
		
		
		
	Paiement
This commit is contained in:
		@@ -13,4 +13,66 @@ $team = $_SESSION["team"];
 | 
			
		||||
$tournament = $team->getEffectiveTournament();
 | 
			
		||||
$payment = $user->getPayment();
 | 
			
		||||
 | 
			
		||||
if (isset($_POST["pay"])) {
 | 
			
		||||
    $pay = new Pay($_POST);
 | 
			
		||||
    try {
 | 
			
		||||
        $pay->makeVerifications();
 | 
			
		||||
        $pay->submit();
 | 
			
		||||
    }
 | 
			
		||||
    catch (AssertionError $e) {
 | 
			
		||||
        $has_error = true;
 | 
			
		||||
        $error_message = $e->getMessage();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Pay {
 | 
			
		||||
    private $method;
 | 
			
		||||
    private $infos;
 | 
			
		||||
    private $scholarship;
 | 
			
		||||
 | 
			
		||||
    public function __construct($data)
 | 
			
		||||
    {
 | 
			
		||||
        foreach ($data as $key => $value)
 | 
			
		||||
            $this->$key = $value;
 | 
			
		||||
 | 
			
		||||
        $this->method = PaymentMethod::fromName(strtoupper($this->method));
 | 
			
		||||
 | 
			
		||||
        $this->scholarship = $_FILES["scholarship"];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function makeVerifications()
 | 
			
		||||
    {
 | 
			
		||||
        global $payment;
 | 
			
		||||
 | 
			
		||||
        ensure($payment->getValidationStatus() == ValidationStatus::NOT_READY, "Un paiement est déjà initié.");
 | 
			
		||||
        ensure($this->method != PaymentMethod::NOT_PAID, "Vous n'avez pas payé.");
 | 
			
		||||
        ensure($this->method == PaymentMethod::SCHOLARSHIP || ($this->infos != null && sizeof($this->infos) > 0), "Merci d'indiquer des informations pour retrouver votre paiement.");
 | 
			
		||||
        ensure($this->method != PaymentMethod::SCHOLARSHIP || ($this->scholarship != null && !$this->scholarship["error"]), "Si vous êtes boursier, vous devez indiquer votre notifcation de bourse (une erreur est survenue).");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function submit()
 | 
			
		||||
    {
 | 
			
		||||
        global $DB, $LOCAL_PATH, $payment, $tournament;
 | 
			
		||||
 | 
			
		||||
        $payment->setMethod($this->method);
 | 
			
		||||
        $payment->setAmount($this->method == PaymentMethod::SCHOLARSHIP ? 0 : $tournament->getPrice());
 | 
			
		||||
        $payment->setValidationStatus(ValidationStatus::WAITING);
 | 
			
		||||
        if ($this->method == PaymentMethod::SCHOLARSHIP) {
 | 
			
		||||
            do
 | 
			
		||||
                $id = genRandomPhrase(64);
 | 
			
		||||
            while (file_exists("$LOCAL_PATH/files/$id"));
 | 
			
		||||
 | 
			
		||||
            if (!rename($this->scholarship["tmp_name"], "$LOCAL_PATH/files/$id"))
 | 
			
		||||
                throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
 | 
			
		||||
 | 
			
		||||
            $req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `tournament`, `type`)
 | 
			
		||||
                VALUES (?, ?, ?, ?, ?);");
 | 
			
		||||
            $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $tournament->getId(), DocumentType::getName(DocumentType::SCHOLARSHIP)]);
 | 
			
		||||
            $payment->setTransactionInfos($id);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            $payment->setTransactionInfos($this->infos);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
require_once "server_files/views/paiement.php";
 | 
			
		||||
		Reference in New Issue
	
	Block a user