mirror of
https://github.com/standardebooks/web.git
synced 2025-07-16 03:16:36 -04:00
Notify admins of new fully-anonymous patrons
This commit is contained in:
parent
b0a6e353c8
commit
9f87133cb9
4 changed files with 35 additions and 21 deletions
|
@ -10,7 +10,6 @@ use Facebook\WebDriver\Firefox\FirefoxDriver;
|
|||
use Facebook\WebDriver\Firefox\FirefoxOptions;
|
||||
|
||||
use Safe\DateTime;
|
||||
use function Safe\file_get_contents;
|
||||
use function Safe\preg_match;
|
||||
use function Safe\preg_replace;
|
||||
use function Safe\putenv;
|
||||
|
@ -60,12 +59,13 @@ try{
|
|||
|
||||
foreach($pendingPayments as $pendingPayment){
|
||||
if($pendingPayment->ChannelId == PAYMENT_CHANNEL_FA){
|
||||
if(Db::QueryInt('SELECT count(*) from Payments where TransactionId = ? limit 1', [$pendingPayment->TransactionId]) > 0){
|
||||
$log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...');
|
||||
|
||||
if(Db::QueryInt('SELECT count(*) from Payments where TransactionId = ?', [$pendingPayment->TransactionId]) > 0){
|
||||
$log->Write('Donation already exists in database.');
|
||||
continue;
|
||||
}
|
||||
|
||||
$log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...');
|
||||
$driver->get('https://fundraising.fracturedatlas.org/admin/donations?query=' . $pendingPayment->TransactionId);
|
||||
|
||||
// Check if we need to log in to FA.
|
||||
|
@ -152,12 +152,12 @@ try{
|
|||
continue;
|
||||
}
|
||||
|
||||
// If this payment isn't anonymous, does it put us in the Patrons Circle?
|
||||
if($payment->User !== null){
|
||||
if(($payment->IsRecurring && $payment->Amount >= 10 && $payment->Created >= $lastMonth) || ($payment->Amount >= 100 && $payment->Created >= $lastYear)){
|
||||
// This payment is eligible for the Patrons Circle.
|
||||
// Does this payment put us in the Patrons Circle?
|
||||
if(($payment->IsRecurring && $payment->Amount >= 10 && $payment->Created >= $lastMonth) || (!$payment->IsRecurring && $payment->Amount >= 100 && $payment->Created >= $lastYear)){
|
||||
// This payment is eligible for the Patrons Circle!
|
||||
if($payment->User !== null){
|
||||
// Are we already a patron?
|
||||
if(!Db::QueryInt('SELECT count(*) from Patrons where UserId = ? and Ended is null', [$payment->UserId])){
|
||||
if(Db::QueryInt('SELECT count(*) from Patrons where UserId = ? and Ended is null', [$payment->UserId]) == 0){
|
||||
// Not a patron yet, add them to the Patrons Circle
|
||||
|
||||
$patron = new Patron();
|
||||
|
@ -177,9 +177,23 @@ try{
|
|||
$patron->Create();
|
||||
}
|
||||
}
|
||||
else{
|
||||
// Not eligible to be a patron; send a thank you email anyway, but only if this is a non-recurring donation,
|
||||
// or if it's their very first recurring donation
|
||||
elseif(!$payment->IsRecurring){
|
||||
// Fully-anonymous, non-recurring donation eligible for the Patrons Circle. We can't notify them, but do notify the admins.
|
||||
$patron = new Patron();
|
||||
$patron->User = new User();
|
||||
|
||||
$em = new Email();
|
||||
$em->To = ADMIN_EMAIL_ADDRESS;
|
||||
$em->From = ADMIN_EMAIL_ADDRESS;
|
||||
$em->Subject = 'New Patrons Circle member';
|
||||
$em->Body = Template::EmailAdminNewPatron(['patron' => $patron, 'payment' => $payment]);
|
||||
$em->TextBody = Template::EmailAdminNewPatronText(['patron' => $patron, 'payment' => $payment]);;
|
||||
$em->Send();
|
||||
}
|
||||
}
|
||||
else{
|
||||
// Not eligible to be a patron; send a thank you email anyway, but only if this is a non-recurring donation, or if it's their very first recurring donation
|
||||
if($payment->User !== null){
|
||||
$previousPaymentCount = Db::QueryInt('SELECT count(*) from Payments where UserId = ? and IsRecurring = true', [$payment->UserId]);
|
||||
|
||||
// We just added a payment to the system, so if this is their very first recurring payment, we expect the count to be exactly 1
|
||||
|
|
|
@ -10,7 +10,7 @@ $now = new DateTime();
|
|||
$lastYear = new DateTime('-1 year');
|
||||
|
||||
$expiredPatrons = Db::Query('
|
||||
select * from Patrons
|
||||
SELECT * from Patrons
|
||||
where
|
||||
Ended is null and
|
||||
UserId not in
|
||||
|
@ -19,9 +19,9 @@ $expiredPatrons = Db::Query('
|
|||
UserId is not null
|
||||
and
|
||||
(
|
||||
(IsRecurring = 1 and Amount >= 10 and Created > ? - interval 45 day)
|
||||
(IsRecurring = true and Amount >= 10 and Created > ? - interval 45 day)
|
||||
or
|
||||
(IsRecurring = 0 and Amount >= 100 and Created > ? - interval 1 year)
|
||||
(IsRecurring = false and Amount >= 100 and Created > ? - interval 1 year)
|
||||
)
|
||||
)
|
||||
', [$now, $now], 'Patron');
|
||||
|
@ -46,12 +46,12 @@ if(sizeof($expiredPatrons) > 0){
|
|||
}
|
||||
|
||||
foreach($expiredPatrons as $patron){
|
||||
Db::Query('update Patrons set Ended = ? where UserId = ?', [$now, $patron->UserId]);
|
||||
Db::Query('update Benefits set CanAccessFeeds = false, CanVote = false, CanBulkDownload = false where UserId = ?', [$patron->UserId]);
|
||||
Db::Query('UPDATE Patrons set Ended = ? where UserId = ?', [$now, $patron->UserId]);
|
||||
Db::Query('UPDATE Benefits set CanAccessFeeds = false, CanVote = false, CanBulkDownload = false where UserId = ?', [$patron->UserId]);
|
||||
|
||||
// Email the patron to notify them their term has ended
|
||||
// Is the patron a recurring subscriber?
|
||||
$lastPayment = Db::Query('select * from Payments where UserId = ? order by Created desc limit 1;', [$patron->UserId], 'Payment');
|
||||
$lastPayment = Db::Query('SELECT * from Payments where UserId = ? order by Created desc limit 1;', [$patron->UserId], 'Payment');
|
||||
|
||||
if(sizeof($lastPayment) > 0 && $patron->User->Email !== null){
|
||||
$em = new Email();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue