From 727e1af67d05adbbd4dd51d3a52bb46a68bd42d1 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 4 Jul 2022 15:31:16 -0500 Subject: [PATCH] Update user in database if they exist when processing a payment --- lib/Payment.php | 15 +++++++++------ scripts/process-pending-payments | 9 --------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/Payment.php b/lib/Payment.php index 1154f4da..4c534c55 100644 --- a/lib/Payment.php +++ b/lib/Payment.php @@ -25,16 +25,19 @@ class Payment extends PropertiesBase{ // If the User object isn't null, then check if we already have this user in our system if($this->User !== null && $this->User->Email !== null){ - $result = Db::Query('SELECT * from Users where Email = ?', [$this->User->Email], 'User'); + try{ + $user = User::GetByEmail($this->User->Email); - if(sizeof($result) == 0){ + // User exists, use their data + $this->User = $user; + + // Update their name in case we have their email (but not name) recorded from a newsletter subscription + Db::Query('UPDATE Users set Name = ? where UserId = ?', [$this->User->Name, $this->User->UserId]); + } + catch(Exceptions\InvalidUserException $ex){ // User doesn't exist, create it now $this->User->Create(); } - else{ - // User exists, use their data - $this->User = $result[0]; - } $this->UserId = $this->User->UserId; } diff --git a/scripts/process-pending-payments b/scripts/process-pending-payments index 377acd4b..a0cffcb8 100755 --- a/scripts/process-pending-payments +++ b/scripts/process-pending-payments @@ -50,15 +50,6 @@ $pendingPayments = Db::Query('start transaction; update PendingPayments set ProcessedOn = utc_timestamp() where ProcessedOn is null; commit;'); -// $pendingPayments = []; -// $csv = array_map( 'str_getcsv', file( '/home/alex/donations.csv') ); -// foreach($csv as $row){ -// $obj = new stdClass(); -// $obj->TransactionId = $row[0]; -// $obj->ChannelId = PAYMENT_CHANNEL_FA; -// $pendingPayments[] = $obj; -// } - if(sizeof($pendingPayments) == 0){ // Don't start the very slow Selenium driver if we have nothing to process exit();