Correctly process matching donations from funds

This commit is contained in:
Alex Cabal 2025-05-02 15:28:46 -05:00
parent daee86b919
commit 06096fa7dd
4 changed files with 19 additions and 14 deletions

View file

@ -68,7 +68,6 @@ class Payment{
if($this->User !== null && $this->User->Email !== null){ if($this->User !== null && $this->User->Email !== null){
try{ try{
$user = User::GetByEmail($this->User->Email); $user = User::GetByEmail($this->User->Email);
// `User` exists, use their data. // `User` exists, use their data.
$user->Name = $this->User->Name; $user->Name = $this->User->Name;
$this->User = $user; $this->User = $user;
@ -82,8 +81,9 @@ class Payment{
} }
catch(Exceptions\UserNotFoundException){ catch(Exceptions\UserNotFoundException){
// User doesn't exist, create it now. // User doesn't exist, create it now.
// Don't require an email address because we might be an anonymous `User`, or a matching donation from a fund.
try{ try{
$this->User->Create(); $this->User->Create(requireEmail: false);
} }
catch(Exceptions\UserExistsException | Exceptions\InvalidUserException){ catch(Exceptions\UserExistsException | Exceptions\InvalidUserException){
// `User` already exists, pass. // `User` already exists, pass.

View file

@ -189,11 +189,16 @@ class User{
/** /**
* @throws Exceptions\InvalidUserException * @throws Exceptions\InvalidUserException
*/ */
public function Validate(): void{ public function Validate(bool $requireEmail): void{
$error = new Exceptions\InvalidUserException(); $error = new Exceptions\InvalidUserException();
if(!isset($this->Email)){ if(trim($this->Email ?? '') == ''){
$error->Add(new Exceptions\EmailRequiredException()); if($requireEmail){
$error->Add(new Exceptions\EmailRequiredException());
}
else{
$this->Email = null;
}
} }
else{ else{
if(filter_var($this->Email, FILTER_VALIDATE_EMAIL) === false){ if(filter_var($this->Email, FILTER_VALIDATE_EMAIL) === false){
@ -238,10 +243,10 @@ class User{
* @throws Exceptions\InvalidUserException * @throws Exceptions\InvalidUserException
* @throws Exceptions\UserExistsException * @throws Exceptions\UserExistsException
*/ */
public function Create(?string $password = null): void{ public function Create(?string $password = null, bool $requireEmail = true): void{
$this->GenerateUuid(); $this->GenerateUuid();
$this->Validate(); $this->Validate($requireEmail);
$this->Created = NOW; $this->Created = NOW;
@ -270,8 +275,8 @@ class User{
* @throws Exceptions\InvalidUserException * @throws Exceptions\InvalidUserException
* @throws Exceptions\UserExistsException * @throws Exceptions\UserExistsException
*/ */
public function Save(): void{ public function Save(bool $requireEmail = true): void{
$this->Validate(); $this->Validate($requireEmail);
$this->Updated = NOW; $this->Updated = NOW;

View file

@ -1,6 +1,6 @@
#!/usr/bin/php #!/usr/bin/php
<? <?
// Note: This script must be run as a user with a $HOME directory, otherwise Firefox won't be able to start with a profile. // Note: This script must be run as a user with a `$HOME` directory, otherwise Firefox won't be able to start with a profile.
/** /**
* FA is unreliable in the email notifications it sends. They are often missing. * FA is unreliable in the email notifications it sends. They are often missing.
@ -50,8 +50,8 @@ $transactionIds = [];
$today = NOW->format('n/j/Y'); $today = NOW->format('n/j/Y');
$faItemsPerPage = 20; // How many items are on a full page of FA results? $faItemsPerPage = 20; // How many items are on a full page of FA results?
// General plan: Read /tmp/last-fa-donation to see what the last transaction ID was that we processed. // General plan: Read `/tmp/last-fa-donation` to see what the last transaction ID was that we processed.
// If /tmp/last-fa-donation doesn't exist, get all transactions from today and create the file. // If `/tmp/last-fa-donation` doesn't exist, get all transactions from today and create the file.
function InsertTransaction(string $transactionId): bool{ function InsertTransaction(string $transactionId): bool{
$exists = Db::QueryBool('SELECT exists( $exists = Db::QueryBool('SELECT exists(
@ -222,7 +222,7 @@ catch(Exception $ex){
$em->Send(); $em->Send();
} }
finally{ finally{
// `$driver` may be unintialized if we ctrl + c during Selenium initialization. // `$driver` may be unintialized if we `ctrl + c` during Selenium initialization.
/** @phpstan-ignore nullsafe.neverNull */ /** @phpstan-ignore nullsafe.neverNull */
$driver?->quit(); $driver?->quit();
} }

View file

@ -89,7 +89,7 @@ try{
$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.
// Wait until the <body> element is visible, then check the current URL. // Wait until the `<body>` element is visible, then check the current URL.
$driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('/html/body'))); $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('/html/body')));
if(stripos($driver->getCurrentURL(), 'auth0.com')){ if(stripos($driver->getCurrentURL(), 'auth0.com')){
$log->Write('Logging in to Fractured Atlas ...'); $log->Write('Logging in to Fractured Atlas ...');