From b1cd612e47079fb05b5c13fc5d6eff53330ba68b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 20 Sep 2023 09:36:43 +1200 Subject: [PATCH] PHP8.2 Pass variables rather than co-erce properties when caling AbstractEditPayment:processBillingAddress --- CRM/Contribute/Form/AbstractEditPayment.php | 18 ++++++++++++------ CRM/Contribute/Form/AdditionalPayment.php | 4 +++- CRM/Contribute/Form/Contribution.php | 4 +--- CRM/Member/Form/Membership.php | 2 +- CRM/Member/Form/MembershipRenewal.php | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 385e65c119..204ce4c228 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -551,12 +551,18 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { * Note that this function works based on the presence or otherwise of billing fields & can be called regardless of * whether they are 'expected' (due to assumptions about the payment processor type or the setting to collect billing * for pay later. + * + * @param int $contactID + * @param string $email + * + * @throws \CRM_Core_Exception + * @throws \Civi\API\Exception\UnauthorizedException */ - protected function processBillingAddress() { + protected function processBillingAddress(int $contactID, string $email): void { $fields = []; $fields['email-Primary'] = 1; - $this->_params['email-5'] = $this->_params['email-Primary'] = $this->_contributorEmail; + $this->_params['email-5'] = $this->_params['email-Primary'] = $email; // now set the values for the billing location. foreach (array_keys($this->_fields) as $name) { $fields[$name] = 1; @@ -565,7 +571,7 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { $fields["address_name-{$this->_bltID}"] = 1; //ensure we don't over-write the payer's email with the member's email - if ($this->_contributorContactID == $this->_contactID) { + if ($contactID == $this->_contactID) { $fields["email-{$this->_bltID}"] = 1; } @@ -582,10 +588,10 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { } //here we are setting up the billing contact - if different from the member they are already created // but they will get billing details assigned - $addressParams['contact_id'] = $this->_contributorContactID; + $addressParams['contact_id'] = $contactID; CRM_Contact_BAO_Contact::createProfileContact($addressParams, $fields, - $this->_contributorContactID, NULL, NULL, - CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contributorContactID, 'contact_type') + $contactID, NULL, NULL, + CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type') ); } diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index 259fc2f89e..e6e6cb824c 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -314,8 +314,10 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract public function submit($submittedValues) { $this->_params = $submittedValues; $this->beginPostProcess(); + // _contributorContactID may no longer need to be set - setting it here + // was for use in processBillingAddress $this->_contributorContactID = $this->_contactID; - $this->processBillingAddress(); + $this->processBillingAddress($this->_contactID, (string) $this->_contributorEmail); $participantId = NULL; if ($this->_component === 'event') { $participantId = $this->_id; diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 6e2ea4ff06..a2cc75411e 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1117,9 +1117,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $now = date('YmdHis'); - $this->_contributorEmail = $this->getContactValue('email_primary.email'); - $this->_contributorContactID = $contactID; - $this->processBillingAddress(); + $this->processBillingAddress($contactID, (string) $this->getContactValue('email_primary.email')); if (!empty($params['source'])) { unset($params['source']); } diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index efc912def6..9a4cf9b0be 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -933,7 +933,7 @@ DESC limit 1"); $params = $softParams = []; - $this->processBillingAddress(); + $this->processBillingAddress($this->getContributionContactID(), (string) $this->_contributorEmail); $formValues = $this->_params; $formValues = $this->setPriceSetParameters($formValues); diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index ca91196a04..aa002c5f6a 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -485,7 +485,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->beginPostProcess(); $now = CRM_Utils_Date::getToday(NULL, 'YmdHis'); $this->assign('receive_date', CRM_Utils_Array::value('receive_date', $this->_params, CRM_Utils_Time::date('Y-m-d H:i:s'))); - $this->processBillingAddress(); + $this->processBillingAddress($this->getContributionContactID(), (string) $this->_contributorEmail); $this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee') -- 2.25.1