Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-12-01-14-40-22
[civicrm-core.git] / CRM / Core / Payment / ProcessorForm.php
index 2975e1959d9490027116dda71d849e7fc2723a15..7b3d5cfb4de4b7a9900de2efbef4f9e0546ca93c 100644 (file)
  */
 class CRM_Core_Payment_ProcessorForm {
 
+  /**
+   * @param CRM_Core_Form $form
+   * @param null $type
+   * @param null $mode
+   *
+   * @throws Exception
+   */
   static function preProcess(&$form, $type = NULL, $mode = NULL ) {
     if ($type) {
       $form->_type = $type;
@@ -61,19 +68,13 @@ class CRM_Core_Payment_ProcessorForm {
     //checks after setting $form->_paymentProcessor
     // we do this outside of the above conditional to avoid
     // saving the country/state list in the session (which could be huge)
+    CRM_Core_Payment_Form::setPaymentFieldsByProcessor($form, $form->_paymentProcessor);
 
-    if (($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) && !empty($form->_values['is_monetary'])) {
-      if ($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
-        CRM_Core_Payment_Form::setDirectDebitFields($form);
-      }
-      else {
-        CRM_Core_Payment_Form::setCreditCardFields($form);
-      }
-    }
 
     $form->assign_by_ref('paymentProcessor', $form->_paymentProcessor);
 
     // check if this is a paypal auto return and redirect accordingly
+    //@todo - determine if this is legacy and remove
     if (CRM_Core_Payment::paypalRedirect($form->_paymentProcessor)) {
       $url = CRM_Utils_System::url('civicrm/contribute/transact',
         "_qf_ThankYou_display=1&qfKey={$form->controller->_key}"
@@ -100,35 +101,13 @@ class CRM_Core_Payment_ProcessorForm {
     }
   }
 
+  /**
+   * @param $form
+   */
   static function buildQuickform(&$form) {
+    //@todo document why this addHidden is here
     $form->addElement('hidden', 'hidden_processor', 1);
-
-    $profileAddressFields = $form->get('profileAddressFields');
-    if (!empty($profileAddressFields)) {
-      $form->assign('profileAddressFields', $profileAddressFields);
-    }
-
-    // check if show billing setting is enabled
-    if ($form->getVar( '_ppType' ) == 0 && $form->_isBillingAddressRequiredForPayLater) {
-      CRM_Core_Payment_Form::buildAddressBlock($form);
-      return;
-    }
-
-    // before we do this lets see if the payment processor has implemented a buildForm method
-    if (method_exists($form->_paymentProcessor['instance'], 'buildForm') &&
-      is_callable(array($form->_paymentProcessor['instance'], 'buildForm'))) {
-      // the payment processor implements the buildForm function, let the payment
-      // processor do the work
-      $form->_paymentProcessor['instance']->buildForm($form);
-      return;
-    }
-
-    if (($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT)) {
-      CRM_Core_Payment_Form::buildDirectDebit($form);
-    }
-    elseif (($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_CREDIT_CARD)) {
-      CRM_Core_Payment_Form::buildCreditCard($form);
-    }
+    CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, empty($form->_isBillingAddressRequiredForPayLater));
   }
 }