Notify admins of new fully-anonymous patrons

This commit is contained in:
Alex Cabal 2022-12-11 12:10:27 -06:00
parent b0a6e353c8
commit 9f87133cb9
4 changed files with 35 additions and 21 deletions

View file

@ -10,7 +10,6 @@ use Facebook\WebDriver\Firefox\FirefoxDriver;
use Facebook\WebDriver\Firefox\FirefoxOptions; use Facebook\WebDriver\Firefox\FirefoxOptions;
use Safe\DateTime; use Safe\DateTime;
use function Safe\file_get_contents;
use function Safe\preg_match; use function Safe\preg_match;
use function Safe\preg_replace; use function Safe\preg_replace;
use function Safe\putenv; use function Safe\putenv;
@ -60,12 +59,13 @@ try{
foreach($pendingPayments as $pendingPayment){ foreach($pendingPayments as $pendingPayment){
if($pendingPayment->ChannelId == PAYMENT_CHANNEL_FA){ 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.'); $log->Write('Donation already exists in database.');
continue; continue;
} }
$log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...');
$driver->get('https://fundraising.fracturedatlas.org/admin/donations?query=' . $pendingPayment->TransactionId); $driver->get('https://fundraising.fracturedatlas.org/admin/donations?query=' . $pendingPayment->TransactionId);
// Check if we need to log in to FA. // Check if we need to log in to FA.
@ -152,12 +152,12 @@ try{
continue; continue;
} }
// If this payment isn't anonymous, does it put us in the Patrons Circle? // Does this payment put us in the Patrons Circle?
if($payment->User !== null){ if(($payment->IsRecurring && $payment->Amount >= 10 && $payment->Created >= $lastMonth) || (!$payment->IsRecurring && $payment->Amount >= 100 && $payment->Created >= $lastYear)){
if(($payment->IsRecurring && $payment->Amount >= 10 && $payment->Created >= $lastMonth) || ($payment->Amount >= 100 && $payment->Created >= $lastYear)){ // This payment is eligible for the Patrons Circle!
// This payment is eligible for the Patrons Circle. if($payment->User !== null){
// Are we already a patron? // 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 // Not a patron yet, add them to the Patrons Circle
$patron = new Patron(); $patron = new Patron();
@ -177,9 +177,23 @@ try{
$patron->Create(); $patron->Create();
} }
} }
else{ elseif(!$payment->IsRecurring){
// Not eligible to be a patron; send a thank you email anyway, but only if this is a non-recurring donation, // Fully-anonymous, non-recurring donation eligible for the Patrons Circle. We can't notify them, but do notify the admins.
// or if it's their very first recurring donation $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]); $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 // 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

View file

@ -10,7 +10,7 @@ $now = new DateTime();
$lastYear = new DateTime('-1 year'); $lastYear = new DateTime('-1 year');
$expiredPatrons = Db::Query(' $expiredPatrons = Db::Query('
select * from Patrons SELECT * from Patrons
where where
Ended is null and Ended is null and
UserId not in UserId not in
@ -19,9 +19,9 @@ $expiredPatrons = Db::Query('
UserId is not null UserId is not null
and and
( (
(IsRecurring = 1 and Amount >= 10 and Created > ? - interval 45 day) (IsRecurring = true and Amount >= 10 and Created > ? - interval 45 day)
or or
(IsRecurring = 0 and Amount >= 100 and Created > ? - interval 1 year) (IsRecurring = false and Amount >= 100 and Created > ? - interval 1 year)
) )
) )
', [$now, $now], 'Patron'); ', [$now, $now], 'Patron');
@ -46,12 +46,12 @@ if(sizeof($expiredPatrons) > 0){
} }
foreach($expiredPatrons as $patron){ foreach($expiredPatrons as $patron){
Db::Query('update Patrons set Ended = ? where UserId = ?', [$now, $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]); 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 // Email the patron to notify them their term has ended
// Is the patron a recurring subscriber? // 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){ if(sizeof($lastPayment) > 0 && $patron->User->Email !== null){
$em = new Email(); $em = new Email();

View file

@ -21,9 +21,9 @@ $current = Db::QueryInt('
UserId is null UserId is null
and and
( (
(Amount >= 100 and IsRecurring = false and Created >= ?) (IsRecurring = true and Amount >= 10 and Created >= ?)
or or
(Amount >= 10 and IsRecurring = true and Created >= ?) (IsRecurring = false and Amount >= 100 and Created >= ?)
) )
) )
union all union all

View file

@ -25,9 +25,9 @@ $anonymousPatronCount = Db::QueryInt('SELECT sum(cnt)
UserId is null UserId is null
and and
( (
(Amount >= 100 and IsRecurring = false and Created >= utc_timestamp() - interval 1 year) (IsRecurring = true and Amount >= 10 and Created >= utc_timestamp() - interval 30 day)
or or
(Amount >= 10 and IsRecurring = true and Created >= utc_timestamp() - interval 30 day) (IsRecurring = false and Amount >= 100 and Created >= utc_timestamp() - interval 1 year)
) )
) )
union all union all