* @param bool $reset
* @param bool $isCurrentDomainOnly
* Do we only want to load payment processors associated with the current domain.
+ * @param bool|NULL $isActive
+ * Do we only want active processors, only inactive (FALSE) or all processors (NULL)
*
* @throws CiviCRM_API3_Exception
* @return array
*/
- public static function getAllPaymentProcessors($mode = 'all', $reset = FALSE, $isCurrentDomainOnly = TRUE) {
+ public static function getAllPaymentProcessors($mode = 'all', $reset = FALSE, $isCurrentDomainOnly = TRUE, $isActive = TRUE) {
$cacheKey = 'CRM_Financial_BAO_Payment_Processor_' . $mode . '_' . $isCurrentDomainOnly . '_' . CRM_Core_Config::domainID();
if (!$reset) {
}
$retrievalParameters = [
- 'is_active' => TRUE,
'options' => ['sort' => 'is_default DESC, name', 'limit' => 0],
'api.payment_processor_type.getsingle' => 1,
];
+ if (isset($isActive)) {
+ // We use isset because we don't want to set the is_active parameter at all is $isActive is NULL
+ $retrievalParameters['is_active'] = $isActive;
+ }
if ($isCurrentDomainOnly) {
$retrievalParameters['domain_id'] = CRM_Core_Config::domainID();
}
*
* @return array
* available processors
+ *
+ * @throws \CiviCRM_API3_Exception
*/
public static function getPaymentProcessors($capabilities = [], $ids = FALSE) {
if (is_array($ids)) {
- $testProcessors = in_array('TestMode', $capabilities) ? self::getAllPaymentProcessors('test') : [];
- $processors = self::getAllPaymentProcessors('all', FALSE, FALSE);
- if (in_array('TestMode', $capabilities)) {
+ if (in_array('TestMode', $capabilities, TRUE)) {
+ $testProcessors = in_array('TestMode', $capabilities) ? self::getAllPaymentProcessors('test') : [];
+ $allProcessors = self::getAllPaymentProcessors('all', FALSE, FALSE, NULL);
$possibleLiveIDs = array_diff($ids, array_keys($testProcessors));
foreach ($possibleLiveIDs as $possibleLiveID) {
- if (isset($processors[$possibleLiveID]) && ($liveProcessorName = $processors[$possibleLiveID]['name']) != FALSE) {
+ if (isset($allProcessors[$possibleLiveID]) && ($liveProcessorName = $allProcessors[$possibleLiveID]['name']) != FALSE) {
foreach ($testProcessors as $index => $testProcessor) {
- if ($testProcessor['name'] == $liveProcessorName) {
+ if ($testProcessor['name'] === $liveProcessorName) {
$ids[] = $testProcessor['id'];
}
}
}
$processors = $testProcessors;
}
+ else {
+ $processors = self::getAllPaymentProcessors('all', FALSE, FALSE);
+ }
}
else {
$processors = self::getAllPaymentProcessors('all');
}
// Invalid processors will store a null value in 'object' (e.g. if not all required config fields are present).
// This is determined by calling when loading the processor via the $processorObject->checkConfig() function.
- if (!is_a($processor['object'], 'CRM_Core_Payment')) {
+ if (!$processor['object'] instanceof \CRM_Core_Payment) {
unset($processors[$index]);
continue;
}