CRM-17426 fix paylater showing when not configured to
authoreileenmcnaugton <eileen@fuzion.co.nz>
Thu, 22 Oct 2015 02:29:01 +0000 (15:29 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Thu, 22 Oct 2015 02:29:01 +0000 (15:29 +1300)
CRM/Contribute/Form/ContributionBase.php
CRM/Core/Form.php
CRM/Event/Form/Registration.php

index 5967757f2d515349b3a02fdcd9a3fb7b6cc599be..2da894c39fa6d87e5f9683bcb2dc40b09c477825 100644 (file)
@@ -302,7 +302,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
           CRM_Utils_Array::value('payment_processor', $this->_values)
         );
 
-        $this->assignPaymentProcessor();
+        $this->assignPaymentProcessor($isPayLater);
       }
 
       // get price info
index 63ab7fb4048f0647e8be3f59aaba4f7d4c7cb07a..47ccf65f3328c7d3bd0a696df8e2ed34e0439ac9 100644 (file)
@@ -93,13 +93,36 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * Available payment processors (IDS).
    *
    * As part of trying to consolidate various payment pages we store processors here & have functions
-   * at this level to manage them.
+   * at this level to manage them. An alternative would be to have a separate Form that is inherited
+   * by all forms that allow payment processing.
    *
    * @var array
    *   An array of the IDS available on this form.
    */
   public $_paymentProcessorIDs;
 
+  /**
+   * Default or selected processor id.
+   *
+   * As part of trying to consolidate various payment pages we store processors here & have functions
+   * at this level to manage them. An alternative would be to have a separate Form that is inherited
+   * by all forms that allow payment processing.
+   *
+   * @var int
+   */
+  protected $_paymentProcessorID;
+
+  /**
+   * Is pay later enabled for the form.
+   *
+   * As part of trying to consolidate various payment pages we store processors here & have functions
+   * at this level to manage them. An alternative would be to have a separate Form that is inherited
+   * by all forms that allow payment processing.
+   *
+   * @var int
+   */
+  protected $_is_pay_later_enabled;
+
   /**
    * The renderer used for this form
    *
@@ -657,15 +680,20 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    * It would be good to sync it with the back-end function on abstractEditPayment & use one everywhere.
    *
+   * @param bool $is_pay_later_enabled
+   *
    * @throws \CRM_Core_Exception
    */
-  protected function assignPaymentProcessor() {
+  protected function assignPaymentProcessor($is_pay_later_enabled) {
     $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(
       array(ucfirst($this->_mode) . 'Mode'),
       $this->_paymentProcessorIDs
     );
 
     if (!empty($this->_paymentProcessors)) {
+      if ($is_pay_later_enabled) {
+        $this->_paymentProcessors[0] = CRM_Financial_BAO_PaymentProcessor::getPayment(0);
+      }
       foreach ($this->_paymentProcessors as $paymentProcessorID => $paymentProcessorDetail) {
         if (empty($this->_paymentProcessor) && $paymentProcessorDetail['is_default'] == 1 || (count($this->_paymentProcessors) == 1)
         ) {
@@ -734,7 +762,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   protected function preProcessPaymentOptions() {
     $this->_paymentProcessorID = NULL;
-    $this->_paymentProcessors[0] = CRM_Financial_BAO_PaymentProcessor::getPayment(0);
     if ($this->_paymentProcessors) {
       if (!empty($this->_submitValues)) {
         $this->_paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $this->_submitValues);
index f600b1a1817c91a5b5123caeba02f0ece1a7192d..f550c3fcfc4fe144b7eabbf461dff02e9653c6d7 100644 (file)
@@ -299,7 +299,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
         $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor',
           $this->_values['event']
         ));
-        $this->assignPaymentProcessor();
+        $this->assignPaymentProcessor($isPayLater);
 
       }
       //init event fee.