PHP8.2 Pass variables rather than co-erce properties when caling AbstractEditPayment...
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 19 Sep 2023 21:36:43 +0000 (09:36 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 20 Sep 2023 04:45:05 +0000 (16:45 +1200)
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Contribute/Form/AdditionalPayment.php
CRM/Contribute/Form/Contribution.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php

index 385e65c119f37f5b7f3a913a04ecb46368e3a79d..204ce4c22848872481afa6a7e8f040746c41a70e 100644 (file)
@@ -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')
       );
     }
 
index 259fc2f89e3a29448aa65a9d40dcec68a1440577..e6e6cb824cfcfba6a5d3136973ed1a970deb4334 100644 (file)
@@ -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;
index 6e2ea4ff0653a3731c0031f7f8862786dae8b3d0..a2cc75411e862e0476f44e91e2a2f6123d25aba1 100644 (file)
@@ -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']);
     }
index efc912def6fdca129685c85eb78f91e87787ab13..9a4cf9b0beeddb5c98c3db9a7b0403bf06fe78b5 100644 (file)
@@ -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);
 
index ca91196a04d7f49dce22612b9c99ffb1de9f300b..aa002c5f6a6c3a7120be574071737dcb2dadba10 100644 (file)
@@ -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')