mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 10:56:46 -04:00
Add system to retrieve and manage donations in a local database
This commit is contained in:
parent
79c531aacb
commit
70a80d0e02
46 changed files with 782 additions and 910 deletions
58
lib/Payment.php
Normal file
58
lib/Payment.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?
|
||||
|
||||
class Payment extends PropertiesBase{
|
||||
public $PaymentId;
|
||||
protected $User = null;
|
||||
public $UserId = null;
|
||||
public $Timestamp;
|
||||
public $ChannelId;
|
||||
public $TransactionId;
|
||||
public $Amount;
|
||||
public $Fee;
|
||||
public $IsRecurring;
|
||||
|
||||
protected function GetUser(): ?User{
|
||||
if($this->User === null && $this->UserId !== null){
|
||||
$this->User = User::Get($this->UserId);
|
||||
}
|
||||
|
||||
return $this->User;
|
||||
}
|
||||
|
||||
public function Create(): void{
|
||||
if($this->UserId === null){
|
||||
// Check if we have to create a new user in the database
|
||||
|
||||
// If the User object isn't null, then check if we already have this user in our system
|
||||
if($this->User !== null && $this->User->Email !== null){
|
||||
$result = Db::Query('select * from Users where Email = ?', [$this->User->Email], 'User');
|
||||
|
||||
if(sizeof($result) == 0){
|
||||
// User doesn't exist, create it now
|
||||
$this->User->Create();
|
||||
}
|
||||
else{
|
||||
// User exists, use their data
|
||||
$this->User = $result[0];
|
||||
}
|
||||
|
||||
$this->UserId = $this->User->UserId;
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
Db::Query('insert into Payments (UserId, Timestamp, ChannelId, TransactionId, Amount, Fee, IsRecurring) values(?, ?, ?, ?, ?, ?, ?);', [$this->UserId, $this->Timestamp, $this->ChannelId, $this->TransactionId, $this->Amount, $this->Fee, $this->IsRecurring]);
|
||||
}
|
||||
catch(PDOException $ex){
|
||||
if($ex->errorInfo[1] == 1062){
|
||||
// Duplicate unique key; transction ID already exists
|
||||
throw new Exceptions\PaymentExistsException();
|
||||
}
|
||||
else{
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
$this->PaymentId = Db::GetLastInsertedId();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue