mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 02:21:55 -04:00
Better support for soft credit donors from funds
This commit is contained in:
parent
8b02a0ab39
commit
2246becb59
1 changed files with 29 additions and 27 deletions
|
@ -19,7 +19,7 @@ require_once('/standardebooks.org/web/lib/Core.php');
|
||||||
// Disable script timeout because Selenium is very slow.
|
// Disable script timeout because Selenium is very slow.
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
// Initialize the Selenium driver
|
// Initialize the Selenium driver.
|
||||||
putenv('WEBDRIVER_FIREFOX_DRIVER=' . SITE_ROOT . '/config/selenium/geckodriver-0.31.0');
|
putenv('WEBDRIVER_FIREFOX_DRIVER=' . SITE_ROOT . '/config/selenium/geckodriver-0.31.0');
|
||||||
|
|
||||||
$firefoxOptions = new FirefoxOptions();
|
$firefoxOptions = new FirefoxOptions();
|
||||||
|
@ -123,12 +123,14 @@ try{
|
||||||
$payment = new Payment();
|
$payment = new Payment();
|
||||||
$payment->User = new User();
|
$payment->User = new User();
|
||||||
$payment->Processor = $pendingPayment->Processor;
|
$payment->Processor = $pendingPayment->Processor;
|
||||||
|
$hasSoftCredit = false;
|
||||||
try{
|
try{
|
||||||
// If the donation is via a foundation (like American Online Giving Foundation) then there will be a 'soft credit' <th> element.
|
// 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){
|
if(sizeof($detailsRow->findElements(WebDriverBy::xpath('//th[normalize-space(.) = "Soft Credit Donor Info"]'))) > 0){
|
||||||
// We're a foundation donation
|
// 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->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());
|
$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{
|
else{
|
||||||
// We're a regular donation
|
// We're a regular donation
|
||||||
|
@ -144,7 +146,7 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can get here via an AOGF donation that is anonymous.
|
// 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;
|
$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.
|
// 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
|
// 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;
|
$payment->User = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +181,8 @@ try{
|
||||||
continue;
|
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(
|
if(
|
||||||
(
|
(
|
||||||
$payment->IsRecurring
|
$payment->IsRecurring
|
||||||
|
@ -243,7 +246,7 @@ try{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif(!$payment->IsRecurring && !$payment->IsMatchingDonation){
|
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 = new Patron();
|
||||||
$patron->User = new User();
|
$patron->User = new User();
|
||||||
|
|
||||||
|
@ -256,29 +259,28 @@ try{
|
||||||
$em->Send();
|
$em->Send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
elseif($payment->User !== null){
|
||||||
// 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
|
// 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.
|
||||||
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.
|
$previousPaymentCount = Db::QueryInt('
|
||||||
if(!$payment->IsRecurring || $previousPaymentCount == 1){
|
SELECT count(*)
|
||||||
$log->Write('Sending thank you email to non-patron donor.');
|
from Payments
|
||||||
$em = new Email();
|
where UserId = ?
|
||||||
$em->To = $payment->User->Email ?? '';
|
and IsRecurring = true
|
||||||
$em->ToName = $payment->User->Name ?? '';
|
', [$payment->UserId]);
|
||||||
$em->From = EDITOR_IN_CHIEF_EMAIL_ADDRESS;
|
|
||||||
$em->FromName = EDITOR_IN_CHIEF_NAME;
|
// 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.
|
||||||
$em->Subject = 'Thank you for supporting Standard Ebooks!';
|
if(!$payment->IsRecurring || $previousPaymentCount == 1){
|
||||||
$em->Body = Template::EmailDonationThankYou();
|
$log->Write('Sending thank you email to non-patron donor.');
|
||||||
$em->TextBody = Template::EmailDonationThankYouText();
|
$em = new Email();
|
||||||
$em->Send();
|
$em->To = $payment->User->Email ?? '';
|
||||||
}
|
$em->ToName = $payment->User->Name ?? '';
|
||||||
|
$em->From = EDITOR_IN_CHIEF_EMAIL_ADDRESS;
|
||||||
|
$em->FromName = EDITOR_IN_CHIEF_NAME;
|
||||||
|
$em->Subject = 'Thank you for supporting Standard Ebooks!';
|
||||||
|
$em->Body = Template::EmailDonationThankYou();
|
||||||
|
$em->TextBody = Template::EmailDonationThankYouText();
|
||||||
|
$em->Send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue