CRM-16755 fix loading of payment processors (exclude invalid & regression on event
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 28 Jun 2015 13:29:47 +0000 (01:29 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sun, 28 Jun 2015 13:29:47 +0000 (01:29 +1200)
CRM/Event/Form/Registration.php
CRM/Financial/BAO/PaymentProcessor.php
templates/CRM/Event/Form/Registration/Register.tpl

index 55566e1b3ad17bf99c04325a99439c6b397849a5..af456ab853c17f741d84f76c4da87ba6e273990e 100644 (file)
@@ -288,51 +288,14 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       // check for is_monetary status
       $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']);
       $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'is_pay_later');
-      //check for variour combination for paylater, payment
+      //check for various combinations for paylater, payment
       //process with paid event.
       if ($isMonetary && (!$isPayLater || !empty($this->_values['event']['payment_processor']))) {
-        $ppID = CRM_Utils_Array::value('payment_processor',
+        $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor',
           $this->_values['event']
-        );
-        if (!$ppID) {
-          CRM_Core_Error::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl);
-        }
-        $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID);
-        $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds,
-          $this->_mode
-        );
-        $this->set('paymentProcessors', $this->_paymentProcessors);
-
-        //set default payment processor
-        if (!empty($this->_paymentProcessors) && empty($this->_paymentProcessor)) {
-          foreach ($this->_paymentProcessors as $ppId => $values) {
-            if ($values['is_default'] == 1 || (count($this->_paymentProcessors) == 1)) {
-              $defaultProcessorId = $ppId;
-              break;
-            }
-          }
-        }
+        ));
+        $this->assignPaymentProcessor();
 
-        if (isset($defaultProcessorId)) {
-          $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode);
-        }
-        // make sure we have a valid payment class, else abort
-        if ($this->_values['event']['is_monetary']) {
-          if (!CRM_Utils_System::isNull($this->_paymentProcessors)) {
-            foreach ($this->_paymentProcessors as $eachPaymentProcessor) {
-              // check selected payment processor is active
-              if (!$eachPaymentProcessor) {
-                CRM_Core_Error::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.'));
-              }
-              // ensure that processor has a valid config
-              $payment = CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this);
-              $error = $payment->checkConfig();
-              if (!empty($error)) {
-                CRM_Core_Error::fatal($error);
-              }
-            }
-          }
-        }
       }
       //init event fee.
       self::initEventFee($this, $this->_eventId);
index dab67d793bc8a329cb93194f570b8f21ee256b66..edbd08aa5035fd6a18bf5a0fffa2f6f697138ad1 100644 (file)
@@ -175,6 +175,8 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
   /**
    * Get the payment processor details.
    *
+   * @deprecated Use Civi\Payment\System::singleton->getByID();
+   *
    * @param int $paymentProcessorID
    *   Payment processor id.
    * @param string $mode
@@ -230,32 +232,6 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
     ));
   }
 
-  /**
-   * User getPaymentProcessors.
-   *
-   * @deprecated
-   *
-   * @param $paymentProcessorIDs
-   * @param $mode
-   *
-   * @return array
-   * @throws Exception
-   */
-  public static function getPayments($paymentProcessorIDs, $mode) {
-    if (!$paymentProcessorIDs) {
-      CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function'));
-    }
-
-    $payments = array();
-    foreach ($paymentProcessorIDs as $paymentProcessorID) {
-      $payment = self::getPayment($paymentProcessorID, $mode);
-      $payments[$payment['id']] = $payment;
-    }
-
-    uasort($payments, 'self::defaultComparison');
-    return $payments;
-  }
-
   /**
    * Compare 2 payment processors to see which should go first based on is_default
    * (sort function for sortDefaultFirst)
@@ -276,6 +252,8 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
   /**
    * Build payment processor details.
    *
+   * @deprecated
+   *
    * @param object $dao
    *   Payment processor object.
    * @param string $mode
@@ -284,7 +262,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @return array
    *   associated array with payment processor related fields
    */
-  public static function buildPayment($dao, $mode) {
+  protected static function buildPayment($dao, $mode) {
     $fields = array(
       'id',
       'name',
index 93ac090e2b1e82c2cfa1189846a5dcb09a870dee..cb8f1db4590d85246698979a653430f0088a2837 100644 (file)
     <div id="billing-payment-block">
       {* If we have a payment processor, load it - otherwise it happens via ajax *}
       {if $paymentProcessorID or $isBillingAddressRequiredForPayLater}
-        {include file="CRM/Event/Form/Registration/Register.tpl" snippet=4}
+        {include file="CRM/Financial/Form/Payment.tpl" snippet=4}
       {/if}
     </div>
     {include file="CRM/common/paymentBlock.tpl"}
 
     {/literal}
   </script>
-{/if}
+
 {literal}
 <script type="text/javascript">
   {/literal}{if $pcp && $is_honor_roll }pcpAnonymous();
     {/literal}{/if}{literal}
   }
 
-  {/literal}{if $pcp && $is_honor_roll }{literal}
+  {/literal}
+  {if $pcp && $is_honor_roll }{literal}
   function pcpAnonymous() {
     // clear nickname field if anonymous is true
     if (document.getElementsByName("pcp_is_anonymous")[1].checked) {
       }
     }
   }
-  {/literal}{literal}
+  {/literal}
+  {/if}
+  {literal}
 
 </script>
 {/literal}