Fix event payment fields display CRM-12279
authorColeman Watts <coleman@civicrm.org>
Fri, 5 Apr 2013 21:19:26 +0000 (14:19 -0700)
committerColeman Watts <coleman@civicrm.org>
Fri, 5 Apr 2013 21:40:13 +0000 (14:40 -0700)
CRM/Contribute/Form/Contribution/Main.php
CRM/Event/Form/Registration/Register.php

index 0f31fbae117e1d6ce3208e591830f7e871c869fd..332ebcba8c73be8a691e9307b03c30547cdcbdbc 100644 (file)
@@ -387,7 +387,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       TRUE
     );
     $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email');
-    $this->_paymentProcessors = $this->get('paymentProcessors');
     $pps = array();
     if (!empty($this->_paymentProcessors)) {
       $pps = $this->_paymentProcessors;
@@ -1336,13 +1335,13 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
    * Handle Payment Processor switching
    * For contribution and event registration forms
    */
-  static function preProcessPaymentOptions(&$form) {
+  static function preProcessPaymentOptions(&$form, $noFees = FALSE) {
     $form->_snippet = CRM_Utils_Array::value('snippet', $_GET);
     $form->assign('snippet', $form->_snippet);
 
-    $paymentProcessors = $form->get('paymentProcessors');
+    $form->_paymentProcessors = $noFees ? array() : $form->get('paymentProcessors');
     $form->_ppType = NULL;
-    if ($paymentProcessors) {
+    if ($form->_paymentProcessors) {
       // Fetch type during ajax request
       if (isset($_GET['type']) && $form->_snippet) {
         $form->_ppType = $_GET['type'];
@@ -1350,15 +1349,15 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       // Remember type during form post
       elseif (!empty($form->_submitValues)) {
         $form->_ppType = CRM_Utils_Array::value('payment_processor', $form->_submitValues);
-        $form->_paymentProcessor = CRM_Utils_Array::value($form->_ppType, $paymentProcessors);
+        $form->_paymentProcessor = CRM_Utils_Array::value($form->_ppType, $form->_paymentProcessors);
         $form->set('type', $form->_ppType);
         $form->set('mode', $form->_mode);
         $form->set('paymentProcessor', $form->_paymentProcessor);
       }
       // Set default payment processor
       else {
-        foreach ($paymentProcessors as $values) {
-          if (!empty($values['is_default']) || count($paymentProcessors) == 1) {
+        foreach ($form->_paymentProcessors as $values) {
+          if (!empty($values['is_default']) || count($form->_paymentProcessors) == 1) {
             $form->_ppType = $values['id'];
             break;
           }
@@ -1369,7 +1368,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       }
 
       //get payPal express id and make it available to template
-      foreach ($paymentProcessors as $ppId => $values) {
+      foreach ($form->_paymentProcessors as $ppId => $values) {
         $payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0;
         $form->assign('payPalExpressId', $payPalExpressId);
         if ($payPalExpressId) {
index b9f97a3640f6c1b33559a1a75601f52bb9da14ed..df56a419a1c60040d7fad296f02b296c5a23ecf9 100644 (file)
@@ -80,18 +80,21 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
   function preProcess() {
     parent::preProcess();
 
-    CRM_Contribute_Form_Contribution_Main::preProcessPaymentOptions($this);
-    if ($this->_snippet) {
-      return;
-    }
-
     //CRM-4320.
     //here we can't use parent $this->_allowWaitlist as user might
     //walk back and we maight set this value in this postProcess.
     //(we set when spaces < group count and want to allow become part of waiting )
-
     $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $this->_values['event']));
 
+    // Get payment processors if appropriate for this event
+    // We hide the payment fields if the event is full or requires approval,
+    // and the current user has not yet been approved CRM-12279
+    $noFees = (($eventFull || $this->_requireApproval) && !$this->_allowConfirmation);
+    CRM_Contribute_Form_Contribution_Main::preProcessPaymentOptions($this, $noFees);
+    if ($this->_snippet) {
+      return;
+    }
+
     $this->_allowWaitlist = FALSE;
     if ($eventFull && !$this->_allowConfirmation &&
       CRM_Utils_Array::value('has_waitlist', $this->_values['event'])
@@ -413,7 +416,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     }
 
     $pps = NULL;
-    $this->_paymentProcessors = $this->get('paymentProcessors');
     if (!empty($this->_paymentProcessors)) {
       $pps = $this->_paymentProcessors;
       foreach ($pps as $key => & $name) {