_User) && $this->UserId !== null){ $this->_User = User::Get($this->UserId); } return $this->_User; } protected function GetProcessorUrl(): string{ if(!isset($this->_ProcessorUrl)){ switch($this->Processor){ case Enums\PaymentProcessorType::FracturedAtlas: // This is not a permalink per se, because the FA permalink shows us the donor-facing receipt, without useful information like attribution, etc. However if we search by donation ID, we *do* get that information. $this->_ProcessorUrl = 'https://fundraising.fracturedatlas.org/admin/general_support/donations?query=' . $this->TransactionId; break; default: $this->_ProcessorUrl = ''; } } return $this->_ProcessorUrl; } // ******* // METHODS // ******* /** * @throws Exceptions\PaymentExistsException */ public function Create(): void{ 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($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; // 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\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(requireEmail: false); } catch(Exceptions\UserExistsException | Exceptions\InvalidUserException){ // `User` already exists, pass. } } $this->UserId = $this->User->UserId; } } try{ $this->PaymentId = Db::QueryInt(' INSERT into Payments (UserId, Created, Processor, TransactionId, Amount, Fee, IsRecurring, IsMatchingDonation) values(?, ?, ?, ?, ?, ?, ?, ?) returning PaymentId ', [$this->UserId, $this->Created, $this->Processor, $this->TransactionId, $this->Amount, $this->Fee, $this->IsRecurring, $this->IsMatchingDonation]); } catch(Exceptions\DuplicateDatabaseKeyException){ throw new Exceptions\PaymentExistsException(); } } }