Better support for soft credit donors from funds

This commit is contained in:
Alex Cabal 2024-09-18 19:12:35 -05:00
parent 8b02a0ab39
commit 2246becb59

View file

@ -19,7 +19,7 @@ require_once('/standardebooks.org/web/lib/Core.php');
// Disable script timeout because Selenium is very slow.
set_time_limit(0);
// Initialize the Selenium driver
// Initialize the Selenium driver.
putenv('WEBDRIVER_FIREFOX_DRIVER=' . SITE_ROOT . '/config/selenium/geckodriver-0.31.0');
$firefoxOptions = new FirefoxOptions();
@ -123,12 +123,14 @@ try{
$payment = new Payment();
$payment->User = new User();
$payment->Processor = $pendingPayment->Processor;
$hasSoftCredit = false;
try{
// If the donation is via a foundation (like American Online Giving Foundation) then there will be a 'soft credit' <th> element.
if(sizeof($detailsRow->findElements(WebDriverBy::xpath('//th[normalize-space(.) = "Soft Credit Donor Info"]'))) > 0){
// We're a foundation donation
$payment->User->Name = trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::th[normalize-space(.) = "Name"] and (ancestor::tbody[1])[(./preceding-sibling::thead[1])//th[normalize-space(.) = "Soft Credit Donor Info"]]]'))->getText());
$payment->User->Email = trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::th[normalize-space(.) = "Email"] and (ancestor::tbody[1])[(./preceding-sibling::thead[1])//th[normalize-space(.) = "Soft Credit Donor Info"]]]'))->getText());
$hasSoftCredit = true;
}
else{
// We're a regular donation
@ -144,7 +146,7 @@ try{
}
// We can get here via an AOGF donation that is anonymous.
if($payment->User->Email == 'Not provided' || $payment->User->Email == ''){
if(!$hasSoftCredit && ($payment->User->Email == 'Not provided' || $payment->User->Email == '')){
$payment->User = null;
}
}
@ -165,7 +167,7 @@ try{
// We might also get a case where the donation is on behalf of a company match, but there's not really a way to distinguish that. Do a rough check.
// See donation 00b60a22-eafa-44cb-9850-54bef9763e8d
if($payment->User !== null && preg_match('/\b(L\.?L\.?C\.?|Foundation|President|Fund|Charitable)\b/ius', $payment->User->Name ?? '')){
if($payment->User !== null && !$hasSoftCredit && preg_match('/\b(L\.?L\.?C\.?|Foundation|President|Fund|Charitable)\b/ius', $payment->User->Name ?? '')){
$payment->User = null;
}
@ -179,7 +181,8 @@ try{
continue;
}
// Does this payment put us in the Patrons Circle?
// Does this payment create a new Patron in the Patrons Circle?
// If the user is *already* a Patron, then we just create the payment without further processing.
if(
(
$payment->IsRecurring
@ -243,7 +246,7 @@ try{
}
}
elseif(!$payment->IsRecurring && !$payment->IsMatchingDonation){
// Fully-anonymous, non-recurring donation eligible for the Patrons Circle. We can't notify them, but do notify the admins.
// Fully-anonymous, non-recurring donation eligible for the Patrons Circle. We can't create a `Patron` or thank them, but we do notify the admins.
$patron = new Patron();
$patron->User = new User();
@ -256,9 +259,9 @@ try{
$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){
elseif($payment->User !== null){
// Payment amount is not eligible for the Patrons Circle; send a thank you email anyway, but only if this is a non-recurring donation, or if it's their very first recurring donation.
$previousPaymentCount = Db::QueryInt('
SELECT count(*)
from Payments
@ -280,7 +283,6 @@ try{
$em->Send();
}
}
}
Db::Query('
DELETE