X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FPayment.php;h=60a6e3550934774222d075c3d6e269400f5ea86f;hb=81ebda7b3f14105c999036936cf9fd150579c7b6;hp=ab50f68298fd1b6aa750e376d912f2044caf32cb;hpb=8ea180b7e15f28bc58a8cffa5378fb6337cb955c;p=civicrm-core.git diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index ab50f68298..60a6e35509 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -23,16 +23,17 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ use Civi\Payment\System; /** + * Class CRM_Core_Payment. * - * @package CRM - * @copyright CiviCRM LLC (c) 2004-2014 - * $Id$ + * This class is the main class for the payment processor subsystem. * + * It is the parent class for payment processors. It also holds some IPN related functions + * that need to be moved. In particular handlePaymentMethod should be moved to a factory class. */ abstract class CRM_Core_Payment { @@ -70,7 +71,8 @@ abstract class CRM_Core_Payment { protected $_paymentProcessor; /** - * Singleton function used to manage this object + * Singleton function used to manage this object. + * * We will migrate to calling Civi\Payment\System::singleton()->getByProcessor($paymentProcessor) * & Civi\Payment\System::singleton()->getById($paymentProcessor) directly as the main access methods & work * to remove this function all together @@ -100,8 +102,12 @@ abstract class CRM_Core_Payment { } /** - * @param array $params + * Log payment notification message to forensic system log. + * * @todo move to factory class \Civi\Payment\System (or similar) + * + * @param array $params + * * @return mixed */ public static function logPaymentNotification($params) { @@ -118,7 +124,12 @@ abstract class CRM_Core_Payment { } /** - * Check if capability is supported + * Check if capability is supported. + * + * Capabilities have a one to one relationship with capability-related functions on this class. + * + * Payment processor classes should over-ride the capability-specific function rather than this one. + * * @param string $capability * E.g BackOffice, LiveMode, FutureRecurStartDate. * @@ -133,8 +144,13 @@ 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 - * The intention is to support off-site (other than paypal) & direct debit but that is not all working yet so to reach a 'stable' point we disable + * Are back office payments supported. + * + * e.g paypal standard won't permit you to enter a credit card associated + * with someone else's login. + * The intention is to support off-site (other than paypal) & direct debit but that is not all working yet so to + * reach a 'stable' point we disable. + * * @return bool */ protected function supportsBackOffice() { @@ -147,7 +163,8 @@ abstract class CRM_Core_Payment { } /** - * Are live payments supported - e.g dummy doesn't support this + * Are live payments supported - e.g dummy doesn't support this. + * * @return bool */ protected function supportsLiveMode() { @@ -155,7 +172,8 @@ abstract class CRM_Core_Payment { } /** - * Are test payments supported + * Are test payments supported. + * * @return bool */ protected function supportsTestMode() { @@ -163,8 +181,10 @@ abstract class CRM_Core_Payment { } /** - * Should the first payment date be configurable when setting up back office recurring payments + * 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 + * * @return bool */ protected function supportsFutureRecurStartDate() { @@ -172,8 +192,25 @@ abstract class CRM_Core_Payment { } /** - * Setter for the payment form that wants to use the processor + * Default payment instrument validation. + * + * Implement the usual Luhn algorithm via a static function in the CRM_Core_Payment_Form if it's a credit card + * Not a static function, because I need to check for payment_type. + * + * @param array $values + * @param array $errors + */ + public function validatePaymentInstrument($values, &$errors) { + if ($this->_paymentProcessor['payment_type'] == 1) { + CRM_Core_Payment_Form::validateCreditCard($values, $errors); + } + } + + /** + * Setter for the payment form that wants to use the processor. + * * @deprecated + * * @param CRM_Core_Form $paymentForm */ public function setForm(&$paymentForm) { @@ -181,7 +218,7 @@ abstract class CRM_Core_Payment { } /** - * Getter for payment form that is using the processor + * Getter for payment form that is using the processor. * @deprecated * @return CRM_Core_Form * A form object @@ -191,7 +228,7 @@ abstract class CRM_Core_Payment { } /** - * Getter for accessing member vars + * Getter for accessing member vars. * @todo believe this is unused * @param string $name * @@ -202,7 +239,7 @@ abstract class CRM_Core_Payment { } /** - * Get name for the payment information type + * Get name for the payment information type. * @todo - use option group + name field (like Omnipay does) * @return string */ @@ -211,7 +248,7 @@ abstract class CRM_Core_Payment { } /** - * Get label for the payment information type + * Get label for the payment information type. * @todo - use option group + labels (like Omnipay does) * @return string */ @@ -220,7 +257,7 @@ abstract class CRM_Core_Payment { } /** - * Get array of fields that should be displayed on the payment form + * Get array of fields that should be displayed on the payment form. * @todo make payment type an option value & use it in the function name - currently on debit & credit card work * @return array * @throws CiviCRM_API3_Exception @@ -233,7 +270,7 @@ abstract class CRM_Core_Payment { } /** - * Get array of fields that should be displayed on the payment form for credit cards + * Get array of fields that should be displayed on the payment form for credit cards. * * @return array */ @@ -247,7 +284,7 @@ abstract class CRM_Core_Payment { } /** - * Get array of fields that should be displayed on the payment form for direct debits + * Get array of fields that should be displayed on the payment form for direct debits. * * @return array */ @@ -261,7 +298,8 @@ abstract class CRM_Core_Payment { } /** - * Return an array of all the details about the fields potentially required for payment fields + * Return an array of all the details about the fields potentially required for payment fields. + * * Only those determined by getPaymentFormFields will actually be assigned to the form * * @return array @@ -303,7 +341,7 @@ abstract class CRM_Core_Payment { 'rule_message' => ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'), 'rule_name' => 'integer', 'rule_parameters' => NULL, - ) + ), ), ), 'credit_card_exp_date' => array( @@ -318,7 +356,7 @@ abstract class CRM_Core_Payment { 'rule_message' => ts('Card expiration date cannot be a past date.'), 'rule_name' => 'currentDate', 'rule_parameters' => TRUE, - ) + ), ), ), 'credit_card_type' => array( @@ -357,7 +395,7 @@ abstract class CRM_Core_Payment { 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'), 'rule_name' => 'nopunctuation', 'rule_parameters' => NULL, - ) + ), ), 'is_required' => TRUE, ), @@ -378,7 +416,7 @@ abstract class CRM_Core_Payment { 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'), 'rule_name' => 'nopunctuation', 'rule_parameters' => NULL, - ) + ), ), ), 'bank_name' => array( @@ -398,8 +436,11 @@ 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 + * Calling this from outside the payment subsystem is deprecated - use doPayment. + * + * Does a server to server payment transaction. + * + * Note that doPayment will throw an exception so the code may need to be modified * * @param array $params * Assoc array of input parameters for this transaction. @@ -408,7 +449,7 @@ abstract class CRM_Core_Payment { * the result in an nice formatted array (or an error object) * @abstract */ - abstract function doDirectPayment(&$params); + abstract protected function doDirectPayment(&$params); /** * Process payment - this function wraps around both doTransferPayment and doDirectPayment @@ -422,7 +463,7 @@ abstract class CRM_Core_Payment { * (modified) * @throws CRM_Core_Exception */ - public function doPayment(&$params, $component) { + public function doPayment(&$params, $component = 'contribute') { if ($this->_paymentProcessor['billing_mode'] == 4) { $result = $this->doTransferCheckout($params, $component); } @@ -437,12 +478,12 @@ abstract class CRM_Core_Payment { } /** - * This function checks to see if we have the right config values + * This function checks to see if we have the right config values. * * @return string * the error message if any */ - abstract function checkConfig(); + abstract protected function checkConfig(); /** * @param $paymentProcessor @@ -478,16 +519,21 @@ abstract class CRM_Core_Payment { 'mode' => @$_GET['mode'], ) ); + CRM_Utils_System::civiExit(); } /** - * Payment callback handler. The processor_name or processor_id is passed in. + * Payment callback handler. + * + * The processor_name or processor_id is passed in. * Note that processor_id is more reliable as one site may have more than one instance of a * processor & ideally the processor will be validating the results * Load requested payment processor and call that processor's handle<$method> method - * @todo move to0 \Civi\Payment\System factory method * - * @param $method + * @todo move to \Civi\Payment\System factory method + * + * @param string $method + * 'PaymentNotification' or 'PaymentCron' * @param array $params */ public static function handlePaymentMethod($method, $params = array()) { @@ -496,33 +542,30 @@ abstract class CRM_Core_Payment { } self::logPaymentNotification($params); - // Query db for processor .. - $mode = @$params['mode']; - $sql = "SELECT ppt.class_name, ppt.name as processor_name, pp.id AS processor_id FROM civicrm_payment_processor_type ppt INNER JOIN civicrm_payment_processor pp ON pp.payment_processor_type_id = ppt.id - AND pp.is_active - AND pp.is_test = %1"; - $args[1] = array($mode == 'test' ? 1 : 0, 'Integer'); + AND pp.is_active"; if (isset($params['processor_id'])) { $sql .= " WHERE pp.id = %2"; $args[2] = array($params['processor_id'], 'Integer'); - $notfound = "No active instances of payment processor ID#'{$params['processor_id']}' were found."; + $notFound = "No active instances of payment processor ID#'{$params['processor_id']}' were found."; } else { - $sql .= " WHERE ppt.name = %2"; + // This is called when processor_name is passed - passing processor_id instead is recommended. + $sql .= " WHERE ppt.name = %2 AND pp.is_test = %1"; + $args[1] = array((CRM_Utils_Array::value('mode', $params) == 'test') ? 1 : 0, 'Integer'); $args[2] = array($params['processor_name'], 'String'); - $notfound = "No active instances of the '{$params['processor_name']}' payment processor were found."; + $notFound = "No active instances of the '{$params['processor_name']}' payment processor were found."; } $dao = CRM_Core_DAO::executeQuery($sql, $args); - // Check whether we found anything at all .. + // Check whether we found anything at all. if (!$dao->N) { - CRM_Core_Error::fatal($notfound); + CRM_Core_Error::fatal($notFound); } $method = 'handle' . $method; @@ -546,16 +589,13 @@ abstract class CRM_Core_Payment { } } - $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($dao->processor_id, $mode); + $processorInstance = $processorInstance = Civi\Payment\System::singleton()->getById($dao->processor_id); // Should never be empty - we already established this processor_id exists and is active. - if (empty($paymentProcessor)) { + if (empty($processorInstance)) { continue; } - // Instantiate PP - $processorInstance = new $paymentClass($mode, $paymentProcessor); - // Does PP implement this method, and can we call it? if (!method_exists($processorInstance, $method) || !is_callable(array($processorInstance, $method)) @@ -576,11 +616,6 @@ abstract class CRM_Core_Payment { "$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') { - CRM_Utils_System::civiExit(); - } } /** @@ -589,13 +624,15 @@ abstract class CRM_Core_Payment { * @param string $method * Method to check for. * - * @return boolean + * @return bool */ public function isSupported($method = 'cancelSubscription') { return method_exists(CRM_Utils_System::getClassName($this), $method); } /** + * Get url for users to manage this recurring contribution for this processor. + * * @param int $entityID * @param null $entity * @param string $action @@ -671,4 +708,5 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) // Else default return $this->_paymentProcessor['url_recur']; } + }