Skip to content

Commit

Permalink
Fix issues with retrieving supportsTestMode/supportsLiveMode for paym…
Browse files Browse the repository at this point in the history
…ent processors
  • Loading branch information
mattwire committed Oct 7, 2019
1 parent ffadd26 commit 5612bb0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 43 deletions.
19 changes: 6 additions & 13 deletions CRM/Contribute/Form/AbstractEditPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,12 @@ public function assignProcessors() {
}
$this->_processors = [];
foreach ($this->_paymentProcessors as $id => $processor) {
// @todo review this. The inclusion of this IF was to address test processors being incorrectly loaded.
// However the function $this->getValidProcessors() is expected to only return the processors relevant
// to the mode (using the actual id - ie. the id of the test processor for the test processor).
// for some reason there was a need to filter here per commit history - but this indicates a problem
// somewhere else.
if ($processor['is_test'] == ($this->_mode == 'test')) {
$this->_processors[$id] = $processor['name'];
if (!empty($processor['description'])) {
$this->_processors[$id] .= ' : ' . $processor['description'];
}
if ($processor['is_recur']) {
$this->_recurPaymentProcessors[$id] = $this->_processors[$id];
}
$this->_processors[$id] = $processor['name'];
if (!empty($processor['description'])) {
$this->_processors[$id] .= ' : ' . $processor['description'];
}
if ($processor['is_recur']) {
$this->_recurPaymentProcessors[$id] = $this->_processors[$id];
}
}
// CRM-21002: pass the default payment processor ID whose credit card type icons should be populated first
Expand Down
5 changes: 1 addition & 4 deletions CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,7 @@ public function getPaymentProcessorID() {
* @throws \CRM_Core_Exception
*/
protected function assignPaymentProcessor($isPayLaterEnabled) {
$this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(
[ucfirst($this->_mode) . 'Mode'],
$this->_paymentProcessorIDs
);
$this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors([ucfirst($this->_mode) . 'Mode'], $this->_paymentProcessorIDs);
if ($isPayLaterEnabled) {
$this->_paymentProcessors[0] = CRM_Financial_BAO_PaymentProcessor::getPayment(0);
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ protected function supportsMultipleConcurrentPayments() {
* @return bool
*/
protected function supportsLiveMode() {
return TRUE;
return empty($this->_paymentProcessor['is_test']) ? TRUE : FALSE;
}

/**
Expand All @@ -343,7 +343,7 @@ protected function supportsLiveMode() {
* @return bool
*/
protected function supportsTestMode() {
return TRUE;
return empty($this->_paymentProcessor['is_test']) ? FALSE : TRUE;
}

/**
Expand Down
11 changes: 0 additions & 11 deletions CRM/Core/Payment/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,6 @@ public function doDirectPayment(&$params) {
return $params;
}

/**
* Are back office payments supported.
*
* E.g paypal standard won't permit you to enter a credit card associated with someone else's login.
*
* @return bool
*/
protected function supportsLiveMode() {
return TRUE;
}

/**
* Does this payment processor support refund?
*
Expand Down
26 changes: 13 additions & 13 deletions CRM/Financial/BAO/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,26 +368,26 @@ public static function getAllPaymentProcessors($mode = 'all', $reset = FALSE, $i
* available processors
*/
public static function getPaymentProcessors($capabilities = [], $ids = FALSE) {
$testProcessors = in_array('TestMode', $capabilities) ? self::getAllPaymentProcessors('test') : [];
if (is_array($ids)) {
$testProcessors = in_array('TestMode', $capabilities) ? self::getAllPaymentProcessors('test') : [];
$processors = self::getAllPaymentProcessors('all', FALSE, FALSE);
}
else {
$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'];
if (in_array('TestMode', $capabilities)) {
$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'];
}
}
}
}
$processors = $testProcessors;
}
$processors = $testProcessors;
}
else {
$processors = self::getAllPaymentProcessors('all');
}

foreach ($processors as $index => $processor) {
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ public function processorCreate($params = array()) {
*/
public function dummyProcessorCreate($processorParams = array()) {
$paymentProcessorID = $this->processorCreate($processorParams);
// For the tests we don't need a live processor, but as core ALWAYS creates a processor in live mode and one in test mode we do need to create both
// Otherwise we are testing a scenario that only exists in tests (and some tests fail because the live processor has not been defined).
$processorParams['is_test'] = FALSE;
$this->processorCreate($processorParams);
return System::singleton()->getById($paymentProcessorID);
}

Expand Down

0 comments on commit 5612bb0

Please sign in to comment.