CRM-16402 instantiate payment object in new way
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 12 May 2015 09:38:35 +0000 (21:38 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Thu, 14 May 2015 22:16:37 +0000 (10:16 +1200)
CRM/Contribute/Form/ContributionBase.php
Civi/Payment/System.php

index e78c9eb830fac7a3216b6bcd887a5eadf203b69e..67c6877df7520cd6b993c14f21328aa3a84e95dd 100644 (file)
@@ -33,6 +33,8 @@
  *
  */
 
+use Civi\Payment\System;
+
 /**
  * This class generates form components for processing a contribution
  *
@@ -346,7 +348,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
         }
 
         if (isset($defaultProcessorId)) {
-          $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode);
+          $this->_paymentProcessor = Civi\Payment\System::singleton()->getByProcessor($defaultProcessorId, $this->_mode);
           $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
         }
 
@@ -357,12 +359,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
               CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
             }
 
-            // ensure that processor has a valid config
-            $this->_paymentObject = &CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this);
-            $error = $this->_paymentObject->checkConfig();
-            if (!empty($error)) {
-              CRM_Core_Error::fatal($error);
-            }
+            $this->_paymentObject = Civi\Payment\System::singleton()->getByProcessor($eachPaymentProcessor);
           }
         }
       }
index a32a319c544e7ff0b76a9f5f50f11be471171b84..1f552f605f924ef16b7a7b7e793513d71897ca3e 100644 (file)
@@ -53,6 +53,9 @@ class System {
         }
 
         $this->cache[$id] = new $paymentClass(!empty($processor['is_test']) ? 'test' : 'live', $processor);
+        if ($this->cache[$id]->checkConfig()) {
+          $this->cache[$id] = NULL;
+        }
       }
     }
     return $this->cache[$id];