| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
+
+use Civi\Payment\System;
/**
*
* $Id$
*
*/
-
abstract class CRM_Core_Payment {
/**
* credit card
* direct debit
* or both
- *
+ * @todo create option group - nb omnipay uses a 3rd type - transparent redirect cc
*/
const
PAYMENT_TYPE_CREDIT_CARD = 1,
/**
* Subscription / Recurring payment Status
* START, END
- *
*/
const
RECURRING_PAYMENT_START = 'START',
RECURRING_PAYMENT_END = 'END';
- /**
- * We only need one instance of this object. So we use the singleton
- * pattern and cache the instance in this variable
- *
- * @var object
- * @static
- */
- static private $_singleton = NULL;
-
protected $_paymentProcessor;
- /**
- * @var CRM_Core_Form
- */
- protected $_paymentForm = NULL;
-
/**
* 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
*
- * @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
- * @static
- *
+ * @throws \CRM_Core_Exception
*/
public static function &singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
// make sure paymentProcessor is not empty
if (empty($paymentProcessor)) {
return CRM_Core_DAO::$_nullObject;
}
-
- $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));
- }
- 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');
- }
-
- //load the object.
- self::$_singleton[$cacheKey] = $paymentClass::singleton($mode, $paymentProcessor);
- }
-
- //load the payment form for required processor.
- //if ($paymentForm !== NULL) {
- //self::$_singleton[$cacheKey]->setForm($paymentForm);
- //}
-
- return self::$_singleton[$cacheKey];
+ //we use two lines because we can't remove the '&singleton' without risking breakage
+ //of extension classes that extend this one
+ $object = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor);
+ return $object;
}
/**
* @param array $params
- *
+ * @todo move to factory class \Civi\Payment\System (or similar)
* @return mixed
*/
public static function logPaymentNotification($params) {
/**
* Check if capability is supported
- * @param string $capability e.g BackOffice, LiveMode, FutureRecurStartDate
+ * @param string $capability
+ * E.g BackOffice, LiveMode, FutureRecurStartDate.
*
* @return bool
*/
}
/**
- * 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
/**
* Setter for the payment form that wants to use the processor
- *
+ * @deprecated
* @param CRM_Core_Form $paymentForm
- *
*/
public function setForm(&$paymentForm) {
$this->_paymentForm = $paymentForm;
/**
* Getter for payment form that is using the processor
- *
- * @return CRM_Core_Form A form object
+ * @deprecated
+ * @return CRM_Core_Form
+ * A form object
*/
public function getForm() {
return $this->_paymentForm;
/**
* Getter for accessing member vars
- *
+ * @todo believe this is unused
* @param string $name
*
* @return null
/**
* Get name for the payment information type
- *
+ * @todo - use option group + name field (like Omnipay does)
* @return string
*/
public function getPaymentTypeName() {
/**
* Get label for the payment information type
- *
+ * @todo - use option group + labels (like Omnipay does)
* @return string
*/
public function getPaymentTypeLabel() {
* 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 field metadata
+ * @return array
+ * field metadata
*/
public function getPaymentFormFieldsMetadata() {
//@todo convert credit card type into an option value
'attributes' => array(
'size' => 20,
'maxlength' => 20,
- 'autocomplete' => 'off'
+ 'autocomplete' => 'off',
),
'is_required' => TRUE,
),
'attributes' => array(
'size' => 5,
'maxlength' => 10,
- 'autocomplete' => 'off'
+ 'autocomplete' => 'off',
),
'is_required' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'cvv_backoffice_required',
'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(
'htmlType' => 'date',
'rule_message' => ts('Card expiration date cannot be a past date.'),
'rule_name' => 'currentDate',
'rule_parameters' => TRUE,
- )),
+ ),
+ ),
),
'credit_card_type' => array(
'htmlType' => 'select',
'attributes' => array(
'size' => 20,
'maxlength' => 34,
- 'autocomplete' => 'on'
+ 'autocomplete' => 'on',
),
'is_required' => TRUE,
),
'attributes' => array(
'size' => 20,
'maxlength' => 34,
- 'autocomplete' => 'off'
+ 'autocomplete' => 'off',
),
'rules' => array(
array(
'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,
),
//e.g. SWIFT-BIC can have maxlength of 11 digits
'attributes' => array(
'size' => 20,
'maxlength' => 11,
- 'autocomplete' => 'off'
+ 'autocomplete' => 'off',
),
'is_required' => TRUE,
'rules' => array(
'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(
'htmlType' => 'text',
'attributes' => array(
'size' => 20,
'maxlength' => 64,
- 'autocomplete' => 'off'
+ 'autocomplete' => 'off',
),
'is_required' => TRUE,
- )
+ ),
);
}
* 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)
+ * @return array
+ * 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
*
* @param $component
*
+ * @return array
+ * (modified)
* @throws CRM_Core_Exception
*/
public function doPayment(&$params, $component) {
/**
* This function checks to see if we have the right config values
*
- * @return string the error message if any
+ * @return string
+ * the error message if any
*/
- abstract function checkConfig();
+ abstract protected function checkConfig();
/**
* @param $paymentProcessor
- *
+ * @todo move to paypal class or remover
* @return bool
*/
public static function paypalRedirect(&$paymentProcessor) {
}
/**
+ * @todo move to0 \Civi\Payment\System factory method
* Page callback for civicrm/payment/ipn
*/
public static function handleIPN() {
* 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
* @param array $params
}
// Instantiate PP
- $processorInstance = $paymentClass::singleton($mode, $paymentProcessor);
+ $processorInstance = new $paymentClass($mode, $paymentProcessor);
// Does PP implement this method, and can we call it?
if (!method_exists($processorInstance, $method) ||
$extension_instance_found = TRUE;
}
- 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."
- );
+ 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') {
/**
* 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
+ * @return bool
*/
public function isSupported($method = 'cancelSubscription') {
return method_exists(CRM_Utils_System::getClassName($this), $method);
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;
}
- $session = CRM_Core_Session::singleton();
- $userId = $session->get('userID');
- $contactID = 0;
+ $session = CRM_Core_Session::singleton();
+ $userId = $session->get('userID');
+ $contactID = 0;
$checksumValue = '';
- $entityArg = '';
+ $entityArg = '';
// 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
// Else default
return $this->_paymentProcessor['url_recur'];
}
+
}