X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FFinancial%2FBAO%2FPaymentProcessor.php;h=f5cb848d13971c0026ba30d420f6b6faffad8728;hb=cb5962bd23bde819fcfcd391649e39aacf957bbc;hp=58a669ac5f31790aceb2e33a1c9ea820d5d2adaf;hpb=ecb7ec329750b135b1539d4ca711ac3ee000545e;p=civicrm-core.git diff --git a/CRM/Financial/BAO/PaymentProcessor.php b/CRM/Financial/BAO/PaymentProcessor.php index 58a669ac5f..f5cb848d13 100644 --- a/CRM/Financial/BAO/PaymentProcessor.php +++ b/CRM/Financial/BAO/PaymentProcessor.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 4.7 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2015 | + | Copyright CiviCRM LLC (c) 2004-2016 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -28,7 +28,7 @@ /** * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 + * @copyright CiviCRM LLC (c) 2004-2016 */ /** @@ -50,7 +50,6 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces * @throws Exception */ public static function create($params) { - // FIXME Reconcile with CRM_Admin_Form_PaymentProcessor::updatePaymentProcessor $processor = new CRM_Financial_DAO_PaymentProcessor(); $processor->copyValues($params); @@ -79,6 +78,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces ); CRM_Financial_BAO_FinancialTypeAccount::add($values); } + Civi\Payment\System::singleton()->flushProcessors(); return $processor; } @@ -90,6 +90,22 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces parent::__construct(); } + /** + * Retieve array of allowed credit cards for this payment processor. + * @param interger|null $paymentProcessorID id of processor. + * @return array + */ + public static function getCreditCards($paymentProcessorID = NULL) { + if (!empty($paymentProcessorID)) { + $processor = new CRM_Financial_DAO_PaymentProcessor(); + $processor->id = $paymentProcessorID; + $processor->find(TRUE); + $cards = json_decode($processor->accepted_credit_cards, TRUE); + return $cards; + } + return array(); + } + /** * Retrieve DB object based on input parameters. * @@ -346,16 +362,15 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces public static function getPaymentProcessors($capabilities = array(), $ids = FALSE) { $mode = NULL; $testProcessors = in_array('TestMode', $capabilities) ? self::getAllPaymentProcessors('test') : array(); - $processors = $liveProcessors = self::getAllPaymentProcessors('all'); - - if (in_array('TestMode', $capabilities)) { - if ($ids) { - foreach ($testProcessors as $testProcessor) { - if (!in_array($testProcessor['id'], $ids)) { - foreach ($liveProcessors as $liveProcessor) { - if ($liveProcessor['name'] == $testProcessor['name']) { - $ids[] = $testProcessor['id']; - } + $processors = self::getAllPaymentProcessors('all'); + + if (in_array('TestMode', $capabilities) && is_array($ids)) { + $possibleLiveIDs = array_diff($ids, array_keys($testProcessors)); + foreach ($possibleLiveIDs as $possibleLiveID) { + if (isset($processors[$possibleLiveID]) && ($liveProcessorName = $processors[$possibleLiveID]['name']) != FALSE) { + foreach ($testProcessors as $index => $testProcessor) { + if ($testProcessor['name'] == $liveProcessorName) { + $ids[] = $testProcessor['id']; } } } @@ -364,7 +379,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces } foreach ($processors as $index => $processor) { - if ($ids && !in_array($processor['id'], $ids)) { + if (is_array($ids) && !in_array($processor['id'], $ids)) { unset ($processors[$index]); continue; }