fix re-use of variable
[civicrm-core.git] / CRM / Contribute / Form / AdditionalPayment.php
index e2e56864f2eededb3644009f931fa4753b1d5fbc..96aa20b062f476da45305cf235119a9de1f0d70d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -42,15 +42,14 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
   public $_contributeMode = 'direct';
 
   /**
-   * related component whose financial payment is being processed
+   * Related component whose financial payment is being processed
    *
    * @var string
-   * @public
    */
   protected $_component = NULL;
 
   /**
-   * id of the component entity
+   * Id of the component entity
    */
   public $_id = NULL;
 
@@ -138,12 +137,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
 
     list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
 
-    if (!$this->_refund) {
-      $this->assignProcessors();
-      // also check for billing information
-      // get the billing location type
-      $this->assignBillingType();
-    }
+    $this->assignPaymentRelatedVariables();
 
     $this->assign('contributionMode', $this->_mode);
     $this->assign('contactId', $this->_contactId);
@@ -151,8 +145,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
     $this->assign('paymentAmt', abs($paymentAmt));
 
     $this->setPageTitle($this->_refund ? ts('Refund') : ts('Payment'));
-
-    $this->_paymentProcessor = array('billing_mode' => 1);
   }
 
   /**
@@ -161,8 +153,8 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
    *
    * access        public
    *
-   * @return array reference to the array of default values
-   *
+   * @return array
+   *   reference to the array of default values
    */
   /**
    * @return array
@@ -171,7 +163,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
     if ($this->_view == 'transaction' && ($this->_action & CRM_Core_Action::BROWSE)) {
       return;
     }
-    $defaults = array( );
+    $defaults = array();
     if ($this->_mode) {
       $defaults = $this->_values;
 
@@ -192,7 +184,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
     if (empty($defaults['trxn_date']) && empty($defaults['trxn_date_time'])) {
       list($defaults['trxn_date'],
         $defaults['trxn_date_time']
-      ) = CRM_Utils_Date::setDateDefaults(
+        ) = CRM_Utils_Date::setDateDefaults(
         CRM_Utils_Array::value('register_date', $defaults), 'activityDateTime'
       );
     }
@@ -253,17 +245,11 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
         $allPanes[$name] = array(
           'url' => CRM_Utils_System::url('civicrm/payment/add', $urlParams),
           'open' => $open,
-          'id' => $type
+          'id' => $type,
         );
 
-        if ($type == 'CreditCard') {
-          $this->add('hidden', 'hidden_CreditCard', 1);
-          CRM_Core_Payment_Form::buildCreditCard($this, TRUE);
-        }
-        elseif ($type == 'DirectDebit') {
-          $this->add('hidden', 'hidden_DirectDebit', 1);
-          CRM_Core_Payment_Form::buildDirectDebit($this, TRUE);
-        }
+        CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE);
+
         $qfKey = $this->controller->_key;
         $this->assign('qfKey', $qfKey);
         $this->assign('allPanes', $allPanes);
@@ -339,11 +325,11 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
           'type' => 'upload',
           'name' => ts('%1', array(1 => $buttonName)),
           'js' => $js,
-          'isDefault' => TRUE
+          'isDefault' => TRUE,
         ),
         array(
           'type' => 'cancel',
-          'name' => ts('Cancel')
+          'name' => ts('Cancel'),
         ),
       )
     );
@@ -364,7 +350,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
    *
    * @return array
    */
-  static function formRule($fields, $files, $self) {
+  public static function formRule($fields, $files, $self) {
     $errors = array();
     if ($self->_paymentType == 'owed' && $fields['total_amount'] > $self->_owed) {
       $errors['total_amount'] = ts('Payment amount cannot be greater than owed amount');
@@ -415,8 +401,8 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
 
       $session = CRM_Core_Session::singleton();
       $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
-          "reset=1&cid={$this->_contactId}&selectedChild=participant"
-        ));
+        "reset=1&cid={$this->_contactId}&selectedChild=participant"
+      ));
     }
   }
 
@@ -441,11 +427,8 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
     //Get the rquire fields value only.
     $params = $this->_params = $submittedValues;
 
-    $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'],
-      $this->_mode
-    );
-
     //get the payment processor id as per mode.
+    //@todo unclear relevance of mode - seems like a lot of duplicated params here!
     $this->_params['payment_processor'] = $params['payment_processor_id'] =
       $this->_params['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor['id'];
 
@@ -456,7 +439,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
     if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) {
       list($this->userDisplayName,
         $this->userEmail
-      ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
+        ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
       $this->assign('displayName', $this->userDisplayName);
     }
 
@@ -638,17 +621,17 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
 
       CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
       $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
-          "reset=1&cid={$this->_contactId}&selectedChild=participant"
-        ));
+        "reset=1&cid={$this->_contactId}&selectedChild=participant"
+      ));
     }
   }
 
   /**
-   * @param $params
+   * @param array $params
    *
    * @return mixed
    */
-  function emailReceipt(&$params) {
+  public function emailReceipt(&$params) {
     // email receipt sending
     // send message template
     if ($this->_component == 'event') {
@@ -709,7 +692,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
       'groupName' => 'msg_tpl_workflow_contribution',
       'valueName' => 'payment_or_refund_notification',
       'contactId' => $this->_contactId,
-      'PDFFilename' => ts('notification').'.pdf',
+      'PDFFilename' => ts('notification') . '.pdf',
     );
 
     // try to send emails only if email id is present