mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-25 18:17:28 +02: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]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user