<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
/**
* 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
+ * Static holder for the default payment processor
*/
static $_defaultPaymentProcessor = NULL;
/**
* Create Payment Processor
*
- * @param array $params parameters for Processor entity
+ * @param array $params
+ * Parameters for Processor entity.
*
* @return CRM_Financial_DAO_PaymentProcessor
* @throws Exception
*/
- static function create($params) {
+ public static function create($params) {
// FIXME Reconcile with CRM_Admin_Form_PaymentProcessor::updatePaymentProcessor
$processor = new CRM_Financial_DAO_PaymentProcessor();
$processor->copyValues($params);
'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);
}
}
/**
- * class constructor
+ * Class constructor
*/
- function __construct() {
+ public function __construct() {
parent::__construct();
}
* retrieves the relevant objects. It also stores all the retrieved
* values in the default array
*
- * @param array $params (reference ) an assoc array of name/value pairs
- * @param array $defaults (reference ) an assoc array to hold the flattened values
+ * @param array $params
+ * (reference ) an assoc array of name/value pairs.
+ * @param array $defaults
+ * (reference ) an assoc array to hold the flattened values.
*
- * @return CRM_Financial_DAO_PaymentProcessor object on success, null otherwise
- * @access public
- * @static
+ * @return CRM_Financial_DAO_PaymentProcessor|null
+ * object on success, null otherwise
*/
- static function retrieve(&$params, &$defaults) {
+ public static function retrieve(&$params, &$defaults) {
$paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
$paymentProcessor->copyValues($params);
if ($paymentProcessor->find(TRUE)) {
}
/**
- * update the is_active flag in the db
+ * Update the is_active flag in the db
*
- * @param int $id id of the database record
- * @param boolean $is_active value we want to set the is_active field
+ * @param int $id
+ * Id of the database record.
+ * @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
*
- * @access public
- * @static
*/
- static function setIsActive($id, $is_active) {
+ public static function setIsActive($id, $is_active) {
return CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_PaymentProcessor', $id, 'is_active', $is_active);
}
/**
- * retrieve the default payment processor
+ * Retrieve the default payment processor
*
* @param NULL
*
- * @return object The default payment processor object on success,
- * null otherwise
- * @static
- * @access public
+ * @return CRM_Financial_DAO_PaymentProcessor|null
+ * The default payment processor object on success,
+ * null otherwise
*/
- static function &getDefault() {
+ public static function &getDefault() {
if (self::$_defaultPaymentProcessor == NULL) {
$params = array('is_default' => 1);
$defaults = array();
}
/**
- * Function to delete payment processor
+ * Delete payment processor
*
* @param int $paymentProcessorID
*
* @return null
- * @access public
- * @static
*/
- static function del($paymentProcessorID) {
+ public static function del($paymentProcessorID) {
if (!$paymentProcessorID) {
CRM_Core_Error::fatal(ts('Invalid value passed to delete function.'));
}
}
/**
- * get the payment processor details
+ * Get the payment processor details
*
- * @param int $paymentProcessorID payment processor id
- * @param string $mode payment mode ie test or live
+ * @param int $paymentProcessorID
+ * Payment processor id.
+ * @param string $mode
+ * Payment mode ie test or live.
*
- * @return array associated array with payment processor related fields
- * @static
- * @access public
+ * @return array
+ * associated array with payment processor related fields
*/
- static function getPayment($paymentProcessorID, $mode) {
+ 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'));
}
* @return array
* @throws Exception
*/
- static function getPayments($paymentProcessorIDs, $mode) {
+ public static function getPayments($paymentProcessorIDs, $mode) {
if (!$paymentProcessorIDs) {
CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function'));
}
- $payments = array( );
+ $payments = array();
foreach ($paymentProcessorIDs as $paymentProcessorID) {
$payment = self::getPayment($paymentProcessorID, $mode);
$payments[$payment['id']] = $payment;
}
/**
- * compare 2 payment processors to see which should go first based on is_default
+ * 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
*/
- static function defaultComparison($processor1, $processor2){
- $p1 = CRM_Utils_Array::value('is_default', $processor1);
- $p2 = CRM_Utils_Array::value('is_default', $processor2);
- if ($p1 == $p2) {
- return 0;
- }
- return ($p1 > $p2) ? -1 : 1;
+ 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) {
+ return 0;
}
+ return ($p1 > $p2) ? -1 : 1;
+ }
/**
- * build payment processor details
+ * Build payment processor details
*
- * @param object $dao payment processor object
- * @param string $mode payment mode ie test or live
+ * @param object $dao
+ * Payment processor object.
+ * @param string $mode
+ * Payment mode ie test or live.
*
- * @return array associated array with payment processor related fields
- * @static
- * @access public
+ * @return array
+ * associated array with payment processor related fields
*/
- static function buildPayment($dao, $mode) {
+ 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) {
}
/**
- * get all payment processors as an array of objects.
+ * Get all payment processors as an array of objects.
*
- * @param $isExcludeTest
+ * @param string|NULL $mode
+ * only return this mode - test|live or NULL for all
* @param bool $reset
*
* @throws CiviCRM_API3_Exception
* @return array
*/
- static function getAllPaymentProcessors($isExcludeTest, $reset = FALSE) {
- /**
- * $cacheKey = 'CRM_Financial_BAO_Payment_Processor_' . ($isExcludeTest ? 'test' : 'all');
- if (!$reset) {
- $processors = CRM_Utils_Cache::singleton()->get($cacheKey);
- if (!empty($processors)) {
- return $processors;
- }
+ 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
+ );
+ if ($mode == 'test') {
+ $retrievalParameters['is_test'] = 1;
}
- * */
- $retrievalParameters = array('is_active' => TRUE, 'options' => array('sort' => 'is_default DESC, name'), 'api.payment_processor_type.getsingle' => 1);
- if ($isExcludeTest) {
+ elseif ($mode == 'live') {
$retrievalParameters['is_test'] = 0;
}
$processors = civicrm_api3('payment_processor', 'get', $retrievalParameters);
foreach ($processors['values'] as $processor) {
+ $fieldsToProvide = array('user_name', 'password', 'signature', 'subject');
+ foreach ($fieldsToProvide as $field) {
+ //prevent e-notices in processor classes when not configured
+ if (!isset($processor[$field])) {
+ $processor[$field] = NULL;
+ }
+ }
$processors['values'][$processor['id']]['payment_processor_type'] = $processor['payment_processor_type'] = $processors['values'][$processor['id']]['api.payment_processor_type.getsingle']['name'];
- $processors['values'][$processor['id']]['object'] = CRM_Core_Payment::singleton(empty($processor['is_test']) ? 'live' : 'test', $processor);
+ $mode = empty($processor['is_test']) ? 'live' : 'test';
+ $processors['values'][$processor['id']]['object'] = CRM_Core_Payment::singleton($mode, $processor);
}
/*
CRM_Utils_Cache::singleton()->set($cacheKey, $processors);
}
/**
- * get Payment processors with specified capabilities.
+ * Get Payment processors with specified capabilities.
* Note that both the singleton & the pseudoconstant function have caching so we don't add
* arguably this could go on the pseudoconstant class
*
* @param array $capabilities
- * @param bool $isIncludeTest
+ * capabilities of processor e.g
+ * - BackOffice
+ * - TestMode
+ * - LiveMode
+ * - FutureStartDate
*
* @param array $ids
*
- * @return array available processors
+ * @return array
+ * available processors
*/
- static function getPaymentProcessors($capabilities = array(), $isIncludeTest = FALSE, $ids = array()) {
- $processors = self::getAllPaymentProcessors(!$isIncludeTest);
+ public static function getPaymentProcessors($capabilities = array(), $ids = array()) {
+ $mode = NULL;
+ if (in_array('TestMode', $capabilities)) {
+ $mode = 'test';
+ }
+ elseif (in_array('LiveMode', $capabilities)) {
+ $mode = 'live';
+ }
+ $processors = self::getAllPaymentProcessors($mode);
if ($capabilities) {
foreach ($processors as $index => $processor) {
if (!empty($ids) && !in_array($processor['id'], $ids)) {
*
* @return bool
*/
- static function hasPaymentProcessorSupporting($capabilities = array(), $isIncludeTest = FALSE) {
- $result = self::getPaymentProcessors($capabilities, $isIncludeTest);
+ public static function hasPaymentProcessorSupporting($capabilities = array(), $isIncludeTest = FALSE) {
+ $mode = $isIncludeTest ? 'Test' : 'Live';
+ $capabilities[] = $mode . 'Mode';
+ $result = self::getPaymentProcessors($capabilities);
return (!empty($result)) ? TRUE : FALSE;
}
/**
- * retrieve payment processor id / info/ object based on component-id.
+ * Retrieve payment processor id / info/ object based on component-id.
*
- * @param $entityID
- * @param string $component component
- * @param string $type type of payment information to be retrieved
+ * @param int $entityID
+ * @param string $component
+ * Component.
+ * @param string $type
+ * Type of payment information to be retrieved.
*
- * @return int / array / object based on type
- * @static
- * @access public
+ * @return int|array|object
*/
- static function getProcessorForEntity($entityID, $component = 'contribute', $type = 'id') {
+ 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:
return $result;
}
}
-