<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
abstract class CRM_Core_Payment {
/**
- * how are we getting billing information?
+ * How are we getting billing information?
*
* FORM - we collect it on the same page
* BUTTON - the processor collects it and sends it back to us via some protocol
*/
- CONST
+ const
BILLING_MODE_FORM = 1,
BILLING_MODE_BUTTON = 2,
BILLING_MODE_NOTIFY = 4;
/**
- * which payment type(s) are we using?
+ * Which payment type(s) are we using?
*
* credit card
* direct debit
* or both
*
*/
- CONST
+ const
PAYMENT_TYPE_CREDIT_CARD = 1,
PAYMENT_TYPE_DIRECT_DEBIT = 2;
* START, END
*
*/
- CONST
+ const
RECURRING_PAYMENT_START = 'START',
RECURRING_PAYMENT_END = 'END';
protected $_paymentForm = NULL;
/**
- * singleton function used to manage this object
+ * 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
- *
*/
- static function &singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
+ public static function &singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
// make sure paymentProcessor is not empty
// CRM-7424
if (empty($paymentProcessor)) {
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.
//load the payment form for required processor.
//if ($paymentForm !== NULL) {
- //self::$_singleton[$cacheKey]->setForm($paymentForm);
+ //self::$_singleton[$cacheKey]->setForm($paymentForm);
//}
return self::$_singleton[$cacheKey];
}
/**
- * @param $params
+ * @param array $params
*
* @return mixed
*/
}
/**
- * check if capability is supported
- * @param string $capability e.g BackOffice, LiveMode, FutureRecurStartDate
+ * Check if capability is supported
+ * @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 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
*/
}
/**
- * 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() {
}
/**
- * should the first payment date be configurable when setting up back office recurring payments
+ * 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
* @return bool
*/
* @param CRM_Core_Form $paymentForm
*
*/
- function setForm(&$paymentForm) {
+ public function setForm(&$paymentForm) {
$this->_paymentForm = $paymentForm;
}
*
* @return CRM_Core_Form A form object
*/
- function getForm() {
+ public function getForm() {
return $this->_paymentForm;
}
/**
* Getter for accessing member vars
*
- * @param $name
+ * @param string $name
*
* @return null
*/
- function getVar($name) {
+ public function getVar($name) {
return isset($this->$name) ? $this->$name : NULL;
}
/**
- * get name for the payment information type
+ * Get name for the payment information type
*
* @return string
*/
}
/**
- * get label for the payment information type
+ * Get label for the payment information type
*
* @return string
*/
}
/**
- * 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
}
/**
- * 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
*/
}
/**
- * 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
*/
}
/**
- * 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 field metadata
* 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
abstract function doDirectPayment(&$params);
/**
- * process payment - this function wraps around both doTransferPayment and doDirectPayment
+ * Process payment - this function wraps around both doTransferPayment and doDirectPayment
* it ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms more agnostic
*
* @param array $params
if (is_a($result, 'CRM_Core_Error')) {
throw new CRM_Core_Exception(CRM_Core_Error::getMessages($result));
}
+ //CRM-15767 - Submit Credit Card Contribution not being saved
+ return $result;
}
/**
* This function checks to see if we have the right config values
*
- * @internal param string $mode the mode we are operating in (live or test)
- *
* @return string the error message if any
- * @public
*/
abstract function checkConfig();
*
* @return bool
*/
- static function paypalRedirect(&$paymentProcessor) {
+ public static function paypalRedirect(&$paymentProcessor) {
if (!$paymentProcessor) {
return FALSE;
}
/**
* Page callback for civicrm/payment/ipn
- * @public
*/
- static function handleIPN() {
+ public static function handleIPN() {
self::handlePaymentMethod(
'PaymentNotification',
array(
* processor & ideally the processor will be validating the results
* Load requested payment processor and call that processor's handle<$method> method
*
- * @public
* @param $method
* @param array $params
*/
- static function handlePaymentMethod($method, $params = array()) {
+ public static function handlePaymentMethod($method, $params = array()) {
if (!isset($params['processor_id']) && !isset($params['processor_name'])) {
CRM_Core_Error::fatal("Either 'processor_id' or 'processor_name' param is required for payment callback");
}
$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') {
}
/**
- * Function to check whether a method is present ( & supported ) by the payment processor object.
+ * 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
- * @public
*/
- function isSupported($method = 'cancelSubscription') {
+ public function isSupported($method = 'cancelSubscription') {
return method_exists(CRM_Utils_System::getClassName($this), $method);
}
/**
- * @param null $entityID
+ * @param int $entityID
* @param null $entity
* @param string $action
*
* @return string
*/
- function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'cancel') {
+ 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;
}
// 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