mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 07:42:11 +01:00 
			
		
		
		
	Préparation pour la prise en charge du paiement
This commit is contained in:
		
							
								
								
									
										142
									
								
								server_files/classes/Payment.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								server_files/classes/Payment.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,142 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class Payment
 | 
			
		||||
{
 | 
			
		||||
	private $id;
 | 
			
		||||
	private $user_id;
 | 
			
		||||
	private $tournament_id;
 | 
			
		||||
	private $amount;
 | 
			
		||||
	private $method;
 | 
			
		||||
	private $transaction_infos;
 | 
			
		||||
	private $validation_status;
 | 
			
		||||
 | 
			
		||||
	private function __construct() {}
 | 
			
		||||
 | 
			
		||||
	public static function fromId($id)
 | 
			
		||||
	{
 | 
			
		||||
		global $DB;
 | 
			
		||||
		$req = $DB->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]);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										55
									
								
								server_files/classes/PaymentMethod.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								server_files/classes/PaymentMethod.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class PaymentMethod
 | 
			
		||||
{
 | 
			
		||||
	const CREDIT_CARD = 0;
 | 
			
		||||
	const BANK_CHECK = 1;
 | 
			
		||||
	const BANK_TRANSFER = 2;
 | 
			
		||||
	const CASH = 3;
 | 
			
		||||
	const SCHOLARSHIP = 4;
 | 
			
		||||
 | 
			
		||||
	public static function getTranslatedName($status) {
 | 
			
		||||
		switch ($status) {
 | 
			
		||||
			case self::BANK_CHECK:
 | 
			
		||||
				return "Chèque";
 | 
			
		||||
			case self::BANK_TRANSFER:
 | 
			
		||||
				return "Virement";
 | 
			
		||||
			case self::CASH:
 | 
			
		||||
				return "Espèce";
 | 
			
		||||
			case self::SCHOLARSHIP:
 | 
			
		||||
				return "Je suis boursier";
 | 
			
		||||
			default:
 | 
			
		||||
				return "Carte bancaire";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function getName($status) {
 | 
			
		||||
		switch ($status) {
 | 
			
		||||
			case self::BANK_CHECK:
 | 
			
		||||
				return "BANK_CHECK";
 | 
			
		||||
			case self::BANK_TRANSFER:
 | 
			
		||||
				return "BANK_TRANSFER";
 | 
			
		||||
			case self::CASH:
 | 
			
		||||
				return "CASH";
 | 
			
		||||
			case self::SCHOLARSHIP:
 | 
			
		||||
				return "SCHOLARSHIP";
 | 
			
		||||
			default:
 | 
			
		||||
				return "CREDIT_CARD";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function fromName($name) {
 | 
			
		||||
		switch ($name) {
 | 
			
		||||
			case "BANK_CHECK":
 | 
			
		||||
				return self::BANK_CHECK;
 | 
			
		||||
			case "BANK_TRANSFER":
 | 
			
		||||
				return self::BANK_TRANSFER;
 | 
			
		||||
			case "CASH":
 | 
			
		||||
				return self::CASH;
 | 
			
		||||
			case "SCHOLARSHIP":
 | 
			
		||||
				return self::SCHOLARSHIP;
 | 
			
		||||
			default:
 | 
			
		||||
				return self::CREDIT_CARD;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user