INFRA-132 - CRM/Contribute - Misc
[civicrm-core.git] / CRM / Core / Payment.php
index eb5a78e6f9bba7879e820bce504a71e8764d3527..7345ab67bf7f84d3a7a48b3ce412b6021e202bd6 100644 (file)
@@ -86,14 +86,19 @@ abstract class CRM_Core_Payment {
   /**
    * Singleton function used to manage this object
    *
-   * @param string  $mode the mode of operation: live or test
-   * @param array  $paymentProcessor the details of the payment processor being invoked
-   * @param object $paymentForm deprecated - avoid referring to this if possible. If you have to use it document why as this is scary interaction
-   * @param boolean $force            should we force a reload of this payment object
+   * @param string $mode
+   *   The mode of operation: live or test.
+   * @param array $paymentProcessor
+   *   The details of the payment processor being invoked.
+   * @param object $paymentForm
+   *   Deprecated - avoid referring to this if possible. If you have to use it document why as this is scary interaction.
+   * @param bool $force
+   *   Should we force a reload of this payment object.
    *
    * @return CRM_Core_Payment
+   * @return \CRM_Core_Payment
+   * @throws \CRM_Core_Exception
    * @static
-   *
    */
   public static function &singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
     // make sure paymentProcessor is not empty
@@ -102,21 +107,21 @@ abstract class CRM_Core_Payment {
       return CRM_Core_DAO::$_nullObject;
     }
 
-    $cacheKey = "{$mode}_{$paymentProcessor['id']}_" . (int)isset($paymentForm);
+    $cacheKey = "{$mode}_{$paymentProcessor['id']}_" . (int) isset($paymentForm);
 
     if (!isset(self::$_singleton[$cacheKey]) || $force) {
       $config = CRM_Core_Config::singleton();
       $ext = CRM_Extension_System::singleton()->getMapper();
       if ($ext->isExtensionKey($paymentProcessor['class_name'])) {
         $paymentClass = $ext->keyToClass($paymentProcessor['class_name'], 'payment');
-        require_once ($ext->classToPath($paymentClass));
+        require_once $ext->classToPath($paymentClass);
       }
       else {
         $paymentClass = 'CRM_Core_' . $paymentProcessor['class_name'];
         if (empty($paymentClass)) {
           throw new CRM_Core_Exception('no class provided');
         }
-        require_once (str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php');
+        require_once str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php';
       }
 
       //load the object.
@@ -125,7 +130,7 @@ abstract class CRM_Core_Payment {
 
     //load the payment form for required processor.
     //if ($paymentForm !== NULL) {
-      //self::$_singleton[$cacheKey]->setForm($paymentForm);
+    //self::$_singleton[$cacheKey]->setForm($paymentForm);
     //}
 
     return self::$_singleton[$cacheKey];
@@ -151,7 +156,8 @@ abstract class CRM_Core_Payment {
 
   /**
    * Check if capability is supported
-   * @param string $capability e.g BackOffice, LiveMode, FutureRecurStartDate
+   * @param string $capability
+   *   E.g BackOffice, LiveMode, FutureRecurStartDate.
    *
    * @return bool
    */
@@ -178,13 +184,21 @@ abstract class CRM_Core_Payment {
   }
 
   /**
-   * Are back office payments supported - e.g paypal standard won't permit you to enter a credit card associated with someone else's login
+   * Are live payments supported - e.g dummy doesn't support this
    * @return bool
    */
   protected function supportsLiveMode() {
     return TRUE;
   }
 
+  /**
+   * Are test payments supported
+   * @return bool
+   */
+  protected function supportsTestMode() {
+    return TRUE;
+  }
+
   /**
    * Should the first payment date be configurable when setting up back office recurring payments
    * We set this to false for historical consistency but in fact most new processors use tokens for recurring and can support this
@@ -419,7 +433,8 @@ abstract class CRM_Core_Payment {
    * This function collects all the information from a web/api form and invokes
    * the relevant payment processor specific functions to perform the transaction
    *
-   * @param  array $params assoc array of input parameters for this transaction
+   * @param array $params
+   *   Assoc array of input parameters for this transaction.
    *
    * @return array the result in an nice formatted array (or an error object)
    * @abstract
@@ -581,10 +596,11 @@ abstract class CRM_Core_Payment {
       $extension_instance_found = TRUE;
     }
 
-    if (!$extension_instance_found) CRM_Core_Error::fatal(
+    if (!$extension_instance_found) CRM_Core_Error::fatal(
       "No extension instances of the '{$params['processor_name']}' payment processor were found.<br />" .
       "$method method is unsupported in legacy payment processors."
-    );
+      );
+    }
 
     // Exit here on web requests, allowing just the plain text response to be echoed
     if ($method == 'handlePaymentNotification') {
@@ -595,7 +611,8 @@ abstract class CRM_Core_Payment {
   /**
    * Check whether a method is present ( & supported ) by the payment processor object.
    *
-   * @param  string $method method to check for.
+   * @param string $method
+   *   Method to check for.
    *
    * @return boolean
    */
@@ -613,17 +630,19 @@ abstract class CRM_Core_Payment {
   public function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'cancel') {
     // Set URL
     switch ($action) {
-      case 'cancel' :
+      case 'cancel':
         $url = 'civicrm/contribute/unsubscribe';
         break;
-      case 'billing' :
+
+      case 'billing':
         //in notify mode don't return the update billing url
         if (!$this->isSupported('updateSubscriptionBillingInfo')) {
           return NULL;
         }
         $url = 'civicrm/contribute/updatebilling';
         break;
-      case 'update' :
+
+      case 'update':
         $url = 'civicrm/contribute/updaterecur';
         break;
     }
@@ -637,17 +656,17 @@ abstract class CRM_Core_Payment {
     // Find related Contact
     if ($entityID) {
       switch ($entity) {
-        case 'membership' :
+        case 'membership':
           $contactID = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $entityID, "contact_id");
           $entityArg = 'mid';
           break;
 
-        case 'contribution' :
+        case 'contribution':
           $contactID = CRM_Core_DAO::getFieldValue("CRM_Contribute_DAO_Contribution", $entityID, "contact_id");
           $entityArg = 'coid';
           break;
 
-        case 'recur' :
+        case 'recur':
           $sql = "
     SELECT con.contact_id
       FROM civicrm_contribution_recur rec