From c9e5026cf4061c43bb359a4d470617a00d0664f8 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Fri, 28 Feb 2025 11:43:39 -0600 Subject: [PATCH] Add logic for accepting payments from soft credits marked as 'anonymous' --- lib/Payment.php | 5 ++--- scripts/process-pending-payments | 8 +++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Payment.php b/lib/Payment.php index 911bef49..c0f05cf2 100644 --- a/lib/Payment.php +++ b/lib/Payment.php @@ -64,12 +64,12 @@ class Payment{ if($this->UserId === null){ // Check if we have to create a new `User` in the database. - // If the `User` isn't **null**, then check if we already have this user in our system. + // If the `User` isn't `null`, then check if we already have this `User` in our system. if($this->User !== null && $this->User->Email !== null){ try{ $user = User::GetByEmail($this->User->Email); - // `User` exists, use their data + // `User` exists, use their data. $user->Name = $this->User->Name; $this->User = $user; @@ -82,7 +82,6 @@ class Payment{ } catch(Exceptions\UserNotFoundException){ // User doesn't exist, create it now. - try{ $this->User->Create(); } diff --git a/scripts/process-pending-payments b/scripts/process-pending-payments index d52f822f..c596cb77 100755 --- a/scripts/process-pending-payments +++ b/scripts/process-pending-payments @@ -153,8 +153,14 @@ try{ $payment->IsMatchingDonation = true; } + // Sometimes a soft credit is `Anonymous` or `Anonymous Anonymous`. + // See donation `7f296e18-6492-48e1-aeca-5063c6a0bbbb`. + if($hasSoftCredit && preg_match('/Anonymous(\s*Anonymous)*/ius', $payment->User->Name)){ + $payment->User = null; + } + // We can get here via an AOGF donation that is anonymous. - if(!$hasSoftCredit && ($payment->User->Email == 'Not provided' || $payment->User->Email == '')){ + if(!$hasSoftCredit && ($payment->User?->Email == 'Not provided' || $payment->User?->Email == '')){ $payment->User = null; } }