mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 10:02:02 -04:00
Correctly process matching donations from funds
This commit is contained in:
parent
daee86b919
commit
06096fa7dd
4 changed files with 19 additions and 14 deletions
|
@ -68,7 +68,6 @@ class Payment{
|
|||
if($this->User !== null && $this->User->Email !== null){
|
||||
try{
|
||||
$user = User::GetByEmail($this->User->Email);
|
||||
|
||||
// `User` exists, use their data.
|
||||
$user->Name = $this->User->Name;
|
||||
$this->User = $user;
|
||||
|
@ -82,8 +81,9 @@ class Payment{
|
|||
}
|
||||
catch(Exceptions\UserNotFoundException){
|
||||
// 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{
|
||||
$this->User->Create();
|
||||
$this->User->Create(requireEmail: false);
|
||||
}
|
||||
catch(Exceptions\UserExistsException | Exceptions\InvalidUserException){
|
||||
// `User` already exists, pass.
|
||||
|
|
17
lib/User.php
17
lib/User.php
|
@ -189,12 +189,17 @@ class User{
|
|||
/**
|
||||
* @throws Exceptions\InvalidUserException
|
||||
*/
|
||||
public function Validate(): void{
|
||||
public function Validate(bool $requireEmail): void{
|
||||
$error = new Exceptions\InvalidUserException();
|
||||
|
||||
if(!isset($this->Email)){
|
||||
if(trim($this->Email ?? '') == ''){
|
||||
if($requireEmail){
|
||||
$error->Add(new Exceptions\EmailRequiredException());
|
||||
}
|
||||
else{
|
||||
$this->Email = null;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(filter_var($this->Email, FILTER_VALIDATE_EMAIL) === false){
|
||||
$error->Add(new Exceptions\InvalidEmailException('Email is invalid.'));
|
||||
|
@ -238,10 +243,10 @@ class User{
|
|||
* @throws Exceptions\InvalidUserException
|
||||
* @throws Exceptions\UserExistsException
|
||||
*/
|
||||
public function Create(?string $password = null): void{
|
||||
public function Create(?string $password = null, bool $requireEmail = true): void{
|
||||
$this->GenerateUuid();
|
||||
|
||||
$this->Validate();
|
||||
$this->Validate($requireEmail);
|
||||
|
||||
$this->Created = NOW;
|
||||
|
||||
|
@ -270,8 +275,8 @@ class User{
|
|||
* @throws Exceptions\InvalidUserException
|
||||
* @throws Exceptions\UserExistsException
|
||||
*/
|
||||
public function Save(): void{
|
||||
$this->Validate();
|
||||
public function Save(bool $requireEmail = true): void{
|
||||
$this->Validate($requireEmail);
|
||||
|
||||
$this->Updated = NOW;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/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.
|
||||
|
@ -50,8 +50,8 @@ $transactionIds = [];
|
|||
$today = NOW->format('n/j/Y');
|
||||
$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.
|
||||
// If /tmp/last-fa-donation doesn't exist, get all transactions from today and create the file.
|
||||
// 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.
|
||||
|
||||
function InsertTransaction(string $transactionId): bool{
|
||||
$exists = Db::QueryBool('SELECT exists(
|
||||
|
@ -222,7 +222,7 @@ catch(Exception $ex){
|
|||
$em->Send();
|
||||
}
|
||||
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 */
|
||||
$driver?->quit();
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ try{
|
|||
$driver->get('https://fundraising.fracturedatlas.org/admin/donations?query=' . $pendingPayment->TransactionId);
|
||||
|
||||
// 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')));
|
||||
if(stripos($driver->getCurrentURL(), 'auth0.com')){
|
||||
$log->Write('Logging in to Fractured Atlas ...');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue