Skip to content

Commit

Permalink
dev/core#704 Fix loss of links for recurrings with no payment_process…
Browse files Browse the repository at this point in the history
…or_id

In 5.8 changes were made that remove the cancel links from recurring payments where the payment processor object
doesn't load. This is appropriate for cases where there IS a processor but it's disabled. However, it is not
unknown for sites to import contribution_recur records from elsewhere as data records rather than 'functional
records' & it is appropriate to be able to edit those.

We already have a relevant patter - loading payment processor 0 loads the manual processor
(class is CRM_Core_Manual) which has functionality appropriate to non-automated flows
(also known as the paylater processor).

This PR switches to the function CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorObject
which is a skinny wrapper on CRM_Contribute_BAO_ContributionRecur::getPaymentProcessor - which itself
was not actually called from core prior to this change (we didn't remove it as it was better than
functions in play & hence intended to start using it again). No processor is loaded
for an inactive processor so links do not appear there.
  • Loading branch information
eileenmcnaughton committed Apr 2, 2019
1 parent 50f4b85 commit 8701115
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
24 changes: 17 additions & 7 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,28 @@ public static function checkDuplicate($params, &$duplicates) {
* Get the payment processor (array) for a recurring processor.
*
* @param int $id
* @param string $mode
* - Test or NULL - all other variants are ignored.
*
* @return array|null
*/
public static function getPaymentProcessor($id, $mode = NULL) {
public static function getPaymentProcessor($id) {
$paymentProcessorID = self::getPaymentProcessorID($id);
if (!$paymentProcessorID) {
return NULL;
}
return CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID);
}

return CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode);

/**
* Get the processor object for the recurring contribution record.
*
* @param int $id
*
* @return CRM_Core_Payment|NULL
* Returns a processor object or NULL if the processor is disabled.
* Note this returns the 'Manual' processor object if no processor is attached
* (since it still makes sense to update / cancel
*/
public static function getPaymentProcessorObject($id) {
$processor = self::getPaymentProcessor($id);
return is_array($processor) ? $processor['object'] : NULL;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Page/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public static function &recurLinks($recurID = FALSE, $context = 'contribution')

if ($recurID) {
$links = self::$_links;
$paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($recurID, 'recur', 'obj');
if (!is_object($paymentProcessorObj)) {
$paymentProcessorObj = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorObject($recurID);
if (!$paymentProcessorObj) {
unset($links[CRM_Core_Action::DISABLE]);
unset($links[CRM_Core_Action::UPDATE]);
return $links;
Expand Down

0 comments on commit 8701115

Please sign in to comment.