Replace use of contributeMode with alternatives
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 7 Nov 2023 23:03:20 +0000 (12:03 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 8 Nov 2023 00:34:10 +0000 (13:34 +1300)
This addresses 2 places contributeMode is used

1)  CRM_Contribute_BAO_Contribution::createAddress does not require this check - it
works by checking if there are appropriate params from the billing profile - which
will have been displayed on the form or not as required by the processor

2) Replaces a specific check for paypal express with a check specific to that
class name. In the process functions are added for getPaymentProcessorValue()
in keeping with recently added getEventValue() getParticipantValue() etc

CRM/Core/Form.php
CRM/Event/Form/Registration.php
CRM/Event/Form/Registration/Confirm.php
CRM/Event/Form/Registration/Register.php
CRM/Financial/Form/PaymentProcessorFormTrait.php

index 3b46f59f0d076041035d4f17a4329caf6755ec1f..4cfc3f115edcd39a30e2230a39706b1a42f89f77 100644 (file)
@@ -918,9 +918,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   }
 
   /**
-   * @return int
+   * @return int|null
    */
-  public function getPaymentProcessorID(): int {
+  public function getPaymentProcessorID(): ?int {
     return (int) $this->_paymentProcessorID;
   }
 
index 1595d77e05a20e9cdb9f276c0c2560e964870e04..c10351632bf855ca45e025d33292519ffa640389 100644 (file)
@@ -21,6 +21,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
 
   use CRM_Financial_Form_FrontEndPaymentFormTrait;
   use CRM_Event_Form_EventFormTrait;
+  use CRM_Financial_Form_PaymentProcessorFormTrait;
 
   /**
    * The id of the event we are processing.
index 5d84a66b683a5f1a2b10073d4528653492c05e29..57cb4c0874e967149534ccb20e5b038e7b91309f 100644 (file)
@@ -124,7 +124,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
    * @throws \CRM_Core_Exception
    */
   private function preProcessExpress() {
-    if ($this->_contributeMode !== 'express') {
+    if ($this->getPaymentProcessorValue('payment_processor_type_id:name') !== 'PayPal_Express') {
       return FALSE;
     }
     $params = [];
@@ -1008,12 +1008,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
         $contribParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
       }
     }
-    //create an contribution address
-    // The concept of contributeMode is deprecated. Elsewhere we use the function processBillingAddress() - although
-    // currently that is only inherited by back-office forms.
-    if ($form->_contributeMode != 'notify' && empty($params['is_pay_later'])) {
-      $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params);
-    }
+    $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params);
 
     $contribParams['skipLineItem'] = 1;
     $contribParams['skipCleanMoney'] = 1;
index 971b0cd269d9593288b3294591beb7e9d55e852d..a3614cfba5216d44338b05a9050360caf47969e6 100644 (file)
@@ -18,7 +18,6 @@
  * This class generates form components for processing Event.
  */
 class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
-  use CRM_Financial_Form_PaymentProcessorFormTrait;
 
   /**
    * The fields involved in this page.
index 8a6451ee82a54ccd080a64b62a59394bbc1a9dc1..15c8e3f8ec25bd351d3bc6abed9c5e0552b16ecb 100644 (file)
@@ -54,4 +54,51 @@ trait CRM_Financial_Form_PaymentProcessorFormTrait {
     return new CRM_Core_Payment_Manual();
   }
 
+  /**
+   * Get the value for a field relating to the in-use payment processor.
+   *
+   * All values returned in apiv4 format. Escaping may be required.
+   *
+   * @api This function will not change in a minor release and is supported for
+   * use outside of core. This annotation / external support for properties
+   * is only given where there is specific test cover.
+   *
+   * @param string $fieldName
+   *
+   * @return mixed
+   * @throws \CRM_Core_Exception
+   */
+  public function getPaymentProcessorValue(string $fieldName) {
+    if ($this->isDefined('PaymentProcessor')) {
+      return $this->lookup('PaymentProcessor', $fieldName);
+    }
+    $id = $this->getPaymentProcessorID();
+    if ($id === 0) {
+      $manualProcessor = [
+        'payment_processor_type_id' => 0,
+        'payment_processor_type_id.name' => 'Manual',
+        'payment_processor_type_id.class_name' => 'Payment_Manual',
+      ];
+      return $manualProcessor[$fieldName] ?? NULL;
+    }
+    if ($id) {
+      $this->define('PaymentProcessor', 'PaymentProcessor', ['id' => $id]);
+      return $this->lookup('PaymentProcessor', $fieldName);
+    }
+    return NULL;
+  }
+
+  /**
+   * Get the ID for the in-use payment processor.
+   *
+   * @api This function will not change in a minor release and is supported for
+   * use outside of core. This annotation / external support for properties
+   * is only given where there is specific test cover.
+   *
+   * @return int|null
+   */
+  public function getPaymentProcessorID(): ?int {
+    return isset($this->_paymentProcessor['id']) ? (int) $this->_paymentProcessor['id'] : NULL;
+  }
+
 }