forked from standardebooks/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add system to retrieve and manage donations in a local database
- Loading branch information
Showing
46 changed files
with
782 additions
and
910 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE `Patrons` ( | ||
`UserId` int(10) unsigned NOT NULL, | ||
`IsAnonymous` tinyint(1) unsigned NOT NULL DEFAULT 0, | ||
`AlternateName` varchar(80) DEFAULT NULL, | ||
`IsSubscribedToEmails` tinyint(1) NOT NULL DEFAULT 1, | ||
`Timestamp` datetime NOT NULL, | ||
`DeactivatedTimestamp` datetime DEFAULT NULL, | ||
PRIMARY KEY (`UserId`), | ||
KEY `index2` (`IsAnonymous`,`DeactivatedTimestamp`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE `Payments` ( | ||
`PaymentId` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`UserId` int(10) unsigned DEFAULT NULL, | ||
`Timestamp` datetime NOT NULL, | ||
`ChannelId` tinyint(4) unsigned NOT NULL, | ||
`TransactionId` varchar(80) NOT NULL, | ||
`Amount` decimal(7,2) unsigned NOT NULL, | ||
`Fee` decimal(7,2) unsigned NOT NULL DEFAULT 0.00, | ||
`IsRecurring` tinyint(1) unsigned NOT NULL, | ||
PRIMARY KEY (`PaymentId`), | ||
KEY `index2` (`UserId`,`Amount`,`Timestamp`,`IsRecurring`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=828 DEFAULT CHARSET=utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE `PendingPayments` ( | ||
`Timestamp` datetime NOT NULL, | ||
`ChannelId` tinyint(4) unsigned NOT NULL, | ||
`TransactionId` varchar(80) NOT NULL, | ||
`ProcessedOn` datetime DEFAULT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE `Users` ( | ||
`UserId` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`Email` varchar(80) DEFAULT NULL, | ||
`Name` varchar(255) DEFAULT NULL, | ||
`Timestamp` datetime NOT NULL, | ||
`Uuid` char(36) NOT NULL, | ||
PRIMARY KEY (`UserId`), | ||
UNIQUE KEY `idxEmail` (`Email`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=281 DEFAULT CHARSET=utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
create user 'alex'@'localhost' identified by unix_socket; | ||
create user 'se'@'localhost' identified by unix_socket; | ||
create user 'www-data'@'localhost' identified by unix_socket; | ||
|
||
grant * on * to alex@localhost identified via unix_socket; | ||
grant select, insert, update, delete, execute on se.* to se@localhost identified via unix_socket; | ||
grant select, insert, update, delete, execute on se.* to www-data@localhost identified via unix_socket; | ||
|
||
flush privileges; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<? | ||
require_once('/standardebooks.org/web/lib/Core.php'); | ||
|
||
//file_get_contents('/home/alex/donations.csv'); | ||
|
||
$csv = array_map( 'str_getcsv', file( '/home/alex/donations.csv') ); | ||
vdd($csv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ | |
const CAPTCHA_IMAGE_WIDTH = 230; | ||
|
||
const NO_REPLY_EMAIL_ADDRESS = '[email protected]'; | ||
const ADMIN_EMAIL_ADDRESS = '[email protected]'; | ||
const EDITOR_IN_CHIEF_EMAIL_ADDRESS = '[email protected]'; | ||
// We don't define the email username/password in this file to | ||
// 1) avoid a filesystem read when email isn't being used, and | ||
// 2) allow scripts run by users not in the www-data group to succeed, otherwise they will not be able to open secret files on startup and crash | ||
|
@@ -72,6 +74,10 @@ | |
|
||
const AVERAGE_READING_WORDS_PER_MINUTE = 275; | ||
|
||
const PAYMENT_CHANNEL_FA = 0; | ||
|
||
const FA_FEE_PERCENT = 0.87; | ||
|
||
define('PD_YEAR', intval(gmdate('Y')) - 96); | ||
define('PD_STRING', 'January 1, ' . (PD_YEAR + 1)); | ||
|
||
|
@@ -85,3 +91,10 @@ | |
const GITHUB_IGNORED_REPOS = ['tools', 'manual', 'web']; // If we get GitHub push requests featuring these repos, silently ignore instead of returning an error. | ||
|
||
const POSTMARK_WEBHOOK_LOG_FILE_PATH = '/var/log/local/webhooks-postmark.log'; // Must be writable by `www-data` Unix user. | ||
|
||
const ZOHO_SECRET_FILE_PATH = SITE_ROOT . '/config/secrets/[email protected]'; // Set in the GitHub organization global webhook settings. | ||
const ZOHO_WEBHOOK_LOG_FILE_PATH = '/var/log/local/webhooks-zoho.log'; // Must be writable by `www-data` Unix user. | ||
|
||
const FA_SECRET_FILE_PATH = SITE_ROOT . '/config/secrets/fracturedatlas.org'; | ||
const DONATIONS_LOG_FILE_PATH = '/var/log/local/donations.log'; // Must be writable by `www-data` Unix user. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class PaymentExistsException extends SeException{ | ||
protected $message = 'This transaction ID already exists.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<? | ||
namespace Exceptions; | ||
|
||
class UserExistsException extends SeException{ | ||
protected $message = 'This email already exists in the database.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<? | ||
use Safe\DateTime; | ||
|
||
class Patron extends PropertiesBase{ | ||
protected $User = null; | ||
public $UserId = null; | ||
public $IsAnonymous; | ||
public $AlternateName; | ||
public $IsSubscribedToEmail; | ||
public $Timestamp = null; | ||
public $DeactivatedTimestamp = null; | ||
|
||
public static function Get(int $userId): ?Patron{ | ||
$result = Db::Query('select * from Patrons where UserId = ?', [$userId], 'Patron'); | ||
|
||
return $result[0] ?? null; | ||
} | ||
|
||
protected function GetUser(): ?User{ | ||
if($this->User === null && $this->UserId !== null){ | ||
$this->User = User::Get($this->UserId); | ||
} | ||
|
||
return $this->User; | ||
} | ||
|
||
public function Create(bool $sendEmail = true): void{ | ||
Db::Query('insert into Patrons (Timestamp, UserId, IsAnonymous, AlternateName, IsSubscribedToEmail) values(utc_timestamp(), ?, ?, ?, ?);', [$this->UserId, $this->IsAnonymous, $this->AlternateName, $this->IsSubscribedToEmail]); | ||
|
||
if($sendEmail){ | ||
$this->SendWelcomeEmail(); | ||
} | ||
} | ||
|
||
public function Reactivate(bool $sendEmail = true): void{ | ||
Db::Query('update Patrons set Timestamp = utc_timestamp(), DeactivatedTimestamp = null, IsAnonymous = ?, IsSubscribedToEmail = ?, AlternateName = ? where UserId = ?;', [$this->IsAnonymous, $this->IsSubscribedToEmail, $this->AlternateName, $this->UserId]); | ||
$this->Timestamp = new DateTime(); | ||
$this->DeactivatedTimestamp = null; | ||
|
||
if($sendEmail){ | ||
$this->SendWelcomeEmail(); | ||
} | ||
} | ||
|
||
private function SendWelcomeEmail(): void{ | ||
$this->GetUser(); | ||
if($this->User !== null){ | ||
$em = new Email(); | ||
$em->To = $this->User->Email; | ||
$em->From = EDITOR_IN_CHIEF_EMAIL_ADDRESS; | ||
$em->Subject = 'Thank you for supporting Standard Ebooks!'; | ||
$em->Body = Template::EmailPatronsCircleWelcome(['isAnonymous' => $this->IsAnonymous]); | ||
$em->TextBody = Template::EmailPatronsCircleWelcomeText(['isAnonymous' => $this->IsAnonymous]); | ||
//$em->Send(); | ||
} | ||
} | ||
} |
Oops, something went wrong.