Remember payment processor during form reload, fix notices CRM-12149
authorColeman Watts <coleman@civicrm.org>
Thu, 4 Apr 2013 00:45:17 +0000 (17:45 -0700)
committerColeman Watts <coleman@civicrm.org>
Thu, 4 Apr 2013 00:48:43 +0000 (17:48 -0700)
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionBase.php
CRM/Event/Form/Registration/Register.php
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Event/Form/Registration/Register.tpl

index 2064bc3cbaa261b870dbc60eed50cfa19fdf1bca..6d2f76c4b1d741289f1e4c823b149611e5817ffd 100644 (file)
@@ -448,7 +448,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
-    if ($this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType)
+    if ($this->_paymentProcessor &&
+      $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType)
       && !$this->_params['is_pay_later'] && !($this->_amount == 0)
     ) {
       $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
index 11fd190048d6a1332720520af734e06a197f49d6..6c82532b3366c6ab16a6eee3f1d46d4cd761507b 100644 (file)
@@ -968,7 +968,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
 
     // return if this is express mode
     $config = CRM_Core_Config::singleton();
-    if ($self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
+    if ($self->_paymentProcessor &&
+      $self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON
+    ) {
       if (CRM_Utils_Array::value($self->_expressButtonName . '_x', $fields) ||
         CRM_Utils_Array::value($self->_expressButtonName . '_y', $fields) ||
         CRM_Utils_Array::value($self->_expressButtonName, $fields)
@@ -1024,7 +1026,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     // if the user has chosen a free membership or the amount is less than zero
     // i.e. we skip calling the payment processor and hence dont need credit card
     // info
-    if ((float ) $amount <= 0.0) {
+    if ((float) $amount <= 0.0) {
       return $errors;
     }
 
@@ -1285,7 +1287,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       // default mode is direct
       $this->set('contributeMode', 'direct');
 
-      if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
+      if ($this->_paymentProcessor &&
+        $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON
+      ) {
         //get the button name
         $buttonName = $this->controller->getButtonName();
         if (in_array($buttonName,
@@ -1316,7 +1320,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
           CRM_Utils_System::redirect($paymentURL);
         }
       }
-      elseif ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY) {
+      elseif ($this->_paymentProcessor &&
+        $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY
+      ) {
         $this->set('contributeMode', 'notify');
       }
     }
@@ -1356,26 +1362,24 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     $paymentProcessors = $form->get('paymentProcessors');
     $form->_ppType = NULL;
     if ($paymentProcessors) {
-      // Fetch type during form post
-      if (CRM_Utils_Array::value('hidden_processor', $_POST)) {
-        $form->_ppType = CRM_Utils_Array::value('payment_processor', $_POST);
-        $form->set('type', $form->_ppType);
-        $form->set('mode', $form->_mode);
-        $form->set('paymentProcessor', $form->_paymentProcessor);
+      // Fetch type during ajax request
+      if (isset($_GET['type']) && $form->_snippet) {
+        $form->_ppType = $_GET['type'];
       }
-      // When user presses the back button
+      // Remember type during form post
       elseif (!empty($form->_submitValues)) {
         $form->_ppType = CRM_Utils_Array::value('payment_processor', $form->_submitValues);
-      }
-      // Fetch type during ajax request
-      elseif (isset($_GET['type']) && $form->_snippet) {
-        $form->_ppType = $_GET['type'];
+        $form->_paymentProcessor = CRM_Utils_Array::value($form->_ppType, $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) {
             $form->_ppType = $values['id'];
+            break;
           }
         }
       }
index c316601bb79cb9dcc24a52af79431c4aa45e019a..901527e0980009a79c3de6ede965d5a7842d0ce9 100644 (file)
@@ -510,7 +510,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
 
     $config = CRM_Core_Config::singleton();
     if (isset($this->_values['is_recur']) &&
-      $this->_paymentProcessor['is_recur']
+      CRM_Utils_Array::value('is_recur', $this->_paymentProcessor)
     ) {
       $this->assign('is_recur_enabled', 1);
       $vars = array_merge($vars, array(
@@ -584,7 +584,9 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
     }
 
     if ($this->_contributeMode == 'direct' && $assignCCInfo) {
-      if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
+      if ($this->_paymentProcessor &&
+        $this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT
+      ) {
         $this->assign('payment_type', $this->_paymentProcessor['payment_type']);
         $this->assign('account_holder', $this->_params['account_holder']);
         $this->assign('bank_identification_number', $this->_params['bank_identification_number']);
index 5a4f0336b92d9da53d240128ce80868582c4b084..fe7d17ad6f0d0358186e8c9d1867cd2cdda671a3 100644 (file)
@@ -847,7 +847,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
       }
       // return if this is express mode
       $config = CRM_Core_Config::singleton();
-      if ($self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
+      if ($self->_paymentProcessor &&
+        $self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON
+      ) {
         if (CRM_Utils_Array::value($self->_expressButtonName . '_x', $fields) ||
           CRM_Utils_Array::value($self->_expressButtonName . '_y', $fields) ||
           CRM_Utils_Array::value($self->_expressButtonName, $fields)
@@ -1099,7 +1101,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
       $this->_params[] = $params;
       $this->set('params', $this->_params);
 
-      if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
+      if ($this->_paymentProcessor &&
+        $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON
+      ) {
         //get the button name
         $buttonName = $this->controller->getButtonName();
         if (in_array($buttonName,
@@ -1151,7 +1155,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
           CRM_Utils_System::redirect($paymentURL);
         }
       }
-      elseif ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY) {
+      elseif ($this->_paymentProcessor &&
+        $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY
+      ) {
         $this->set('contributeMode', 'notify');
       }
     }
index c1cf62401ad21498bc514ed349dcc1b9b37acca5..aa017296b2a7f4e95b8f4d364c4bf916d8d010f1 100644 (file)
@@ -24,7 +24,7 @@
  +--------------------------------------------------------------------+
 *}
 {* Callback snippet: Load payment processor *}
-{if $ppType and $snippet}
+{if $snippet}
 {include file="CRM/Core/BillingBlock.tpl" context="front-end"}
   {if $is_monetary}
   {* Put PayPal Express button after customPost block since it's the submit button in this case. *}
index 059bdbc4d3b0ef4adfeee0e687fa6506a71f8bc1..0d64804faed9bd19baeabf66504e4d2ce428781d 100644 (file)
@@ -24,7 +24,7 @@
  +--------------------------------------------------------------------+
 *}
 {* Callback snippet: Load payment processor *}
-{if $ppType and $snippet}
+{if $snippet}
   {include file="CRM/Core/BillingBlock.tpl" context="front-end"}
 
 <div id="paypalExpress">