Merge pull request #4916 from totten/master-casetypetest-cleanup
[civicrm-core.git] / CRM / Financial / BAO / PaymentProcessor.php
index 3797908d43d3760708169e92844536dc0687ff43..eedcf0f643953c90a10a0802626d10b2255f741b 100644 (file)
@@ -36,8 +36,7 @@
 /**
  * This class contains payment processor related functions.
  */
-class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor
-{
+class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor {
   /**
    * Static holder for the default payment processor
    */
@@ -78,7 +77,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
         'entity_table' => 'civicrm_payment_processor',
         'entity_id' => $processor->id,
         'account_relationship' => $relationTypeId,
-        'financial_account_id' => $params['financial_account_id']
+        'financial_account_id' => $params['financial_account_id'],
       );
       CRM_Financial_BAO_FinancialTypeAccount::add($values);
     }
@@ -102,8 +101,8 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @param array $defaults
    *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Financial_DAO_PaymentProcessor object on success, null otherwise
-   * @static
+   * @return CRM_Financial_DAO_PaymentProcessor|null
+   *   object on success, null otherwise
    */
   public static function retrieve(&$params, &$defaults) {
     $paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
@@ -123,9 +122,9 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @param bool $is_active
    *   Value we want to set the is_active field.
    *
-   * @return Object             DAO object on sucess, null otherwise
+   * @return CRM_Financial_DAO_PaymentProcessor|null
+   *   DAO object on success, null otherwise
    *
-   * @static
    */
   public static function setIsActive($id, $is_active) {
     return CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_PaymentProcessor', $id, 'is_active', $is_active);
@@ -136,9 +135,9 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    *
    * @param NULL
    *
-   * @return object           The default payment processor object on success,
-   *                          null otherwise
-   * @static
+   * @return CRM_Financial_DAO_PaymentProcessor|null
+   *   The default payment processor object on success,
+   *   null otherwise
    */
   public static function &getDefault() {
     if (self::$_defaultPaymentProcessor == NULL) {
@@ -150,12 +149,11 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
   }
 
   /**
-   * Function  to delete payment processor
+   * Delete payment processor
    *
    * @param int $paymentProcessorID
    *
    * @return null
-   * @static
    */
   public static function del($paymentProcessorID) {
     if (!$paymentProcessorID) {
@@ -184,26 +182,26 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @param string $mode
    *   Payment mode ie test or live.
    *
-   * @return array  associated array with payment processor related fields
-   * @static
+   * @return array
+   *   associated array with payment processor related fields
    */
   public static function getPayment($paymentProcessorID, $mode) {
     if (!$paymentProcessorID) {
       CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function'));
     }
 
-    $dao            = new CRM_Financial_DAO_PaymentProcessor( );
-    $dao->id        = $paymentProcessorID;
+    $dao = new CRM_Financial_DAO_PaymentProcessor();
+    $dao->id = $paymentProcessorID;
     $dao->is_active = 1;
     if (!$dao->find(TRUE)) {
       return NULL;
     }
 
     if ($mode == 'test') {
-      $testDAO = new CRM_Financial_DAO_PaymentProcessor( );
-      $testDAO->name      = $dao->name;
+      $testDAO = new CRM_Financial_DAO_PaymentProcessor();
+      $testDAO->name = $dao->name;
       $testDAO->is_active = 1;
-      $testDAO->is_test   = 1;
+      $testDAO->is_test = 1;
       if (!$testDAO->find(TRUE)) {
         CRM_Core_Error::fatal(ts('Could not retrieve payment processor details'));
       }
@@ -240,10 +238,10 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * Compare 2 payment processors to see which should go first based on is_default
    * (sort function for sortDefaultFirst)
    * @param array $processor1
-   * @param array_type $processor2
+   * @param array $processor2
    * @return number
    */
-  public static function defaultComparison($processor1, $processor2){
+  public static function defaultComparison($processor1, $processor2) {
     $p1 = CRM_Utils_Array::value('is_default', $processor1);
     $p2 = CRM_Utils_Array::value('is_default', $processor2);
     if ($p1 == $p2) {
@@ -260,15 +258,28 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @param string $mode
    *   Payment mode ie test or live.
    *
-   * @return array  associated array with payment processor related fields
-   * @static
+   * @return array
+   *   associated array with payment processor related fields
    */
   public static function buildPayment($dao, $mode) {
     $fields = array(
-      'id', 'name', 'payment_processor_type_id', 'user_name', 'password',
-      'signature', 'url_site', 'url_api', 'url_recur', 'url_button',
-      'subject', 'class_name', 'is_recur', 'billing_mode', 'is_test',
-      'payment_type', 'is_default',
+      'id',
+      'name',
+      'payment_processor_type_id',
+      'user_name',
+      'password',
+      'signature',
+      'url_site',
+      'url_api',
+      'url_recur',
+      'url_button',
+      'subject',
+      'class_name',
+      'is_recur',
+      'billing_mode',
+      'is_test',
+      'payment_type',
+      'is_default',
     );
     $result = array();
     foreach ($fields as $name) {
@@ -292,16 +303,20 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @return array
    */
   public static function getAllPaymentProcessors($mode, $reset = FALSE) {
-   /**
-   * $cacheKey = 'CRM_Financial_BAO_Payment_Processor_' . ($mode ? 'test' : 'all');
-   if (!$reset) {
-     $processors = CRM_Utils_Cache::singleton()->get($cacheKey);
-     if (!empty($processors)) {
-       return $processors;
-     }
-   }
-     * */
-    $retrievalParameters = array('is_active' => TRUE, 'options' => array('sort' => 'is_default DESC, name'), 'api.payment_processor_type.getsingle' => 1);
+    /*
+     * $cacheKey = 'CRM_Financial_BAO_Payment_Processor_' . ($mode ? 'test' : 'all');
+     * if (!$reset) {
+     *   $processors = CRM_Utils_Cache::singleton()->get($cacheKey);
+     *   if (!empty($processors)) {
+     *     return $processors;
+     *   }
+     * }
+     */
+    $retrievalParameters = array(
+      'is_active' => TRUE,
+      'options' => array('sort' => 'is_default DESC, name'),
+      'api.payment_processor_type.getsingle' => 1
+    );
     if ($mode == 'test') {
       $retrievalParameters['is_test'] = 1;
     }
@@ -333,16 +348,16 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * arguably this could go on the pseudoconstant class
    *
    * @param array $capabilities
-   * capabilities of processor e.g
-   *  - BackOffice
-   *  - TestMode
-   *  - LiveMode
-   *  - FutureStartDate
-   *  include test processors (we want to phase this out in favour of the testMode Capability)
+   *   capabilities of processor e.g
+   *   - BackOffice
+   *   - TestMode
+   *   - LiveMode
+   *   - FutureStartDate
    *
    * @param array $ids
    *
-   * @return array available processors
+   * @return array
+   *   available processors
    */
   public static function getPaymentProcessors($capabilities = array(), $ids = array()) {
     $mode = NULL;
@@ -396,13 +411,16 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @param string $type
    *   Type of payment information to be retrieved.
    *
-   * @return int / array / object based on type
-   * @static
+   * @return int|array|object
    */
   public static function getProcessorForEntity($entityID, $component = 'contribute', $type = 'id') {
     $result = NULL;
     if (!in_array($component, array(
-      'membership', 'contribute', 'recur'))) {
+      'membership',
+      'contribute',
+      'recur'
+    ))
+    ) {
       return $result;
     }
     //FIXME: