diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index 063ad1934a4c..126cf8f67d95 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -173,14 +173,7 @@ public static function checkDuplicate($params, &$duplicates) { * @return array|null */ public static function getPaymentProcessor($id, $mode = NULL) { - $sql = " -SELECT r.payment_processor_id - FROM civicrm_contribution_recur r - WHERE r.id = %1"; - $params = array(1 => array($id, 'Integer')); - $paymentProcessorID = CRM_Core_DAO::singleValueQuery($sql, - $params - ); + $paymentProcessorID = self::getPaymentProcessorID($id); if (!$paymentProcessorID) { return NULL; } @@ -188,6 +181,23 @@ public static function getPaymentProcessor($id, $mode = NULL) { return CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode); } + /** + * Get the payment processor for the given recurring contribution. + * + * @param int $recurID + * + * @return int + * Payment processor id. If none found return 0 which represents the + * pseudo processor used for pay-later. + */ + public static function getPaymentProcessorID($recurID) { + $recur = civicrm_api3('ContributionRecur', 'getsingle', [ + 'id' => $recurID, + 'return' => ['payment_processor_id'] + ]); + return (int) CRM_Utils_Array::value('payment_processor_id', $recur, 0); + } + /** * Get the number of installment done/completed for each recurring contribution. * diff --git a/CRM/Contribute/Page/UserDashboard.php b/CRM/Contribute/Page/UserDashboard.php index 608d0060bcbe..9b4e614c389f 100644 --- a/CRM/Contribute/Page/UserDashboard.php +++ b/CRM/Contribute/Page/UserDashboard.php @@ -83,11 +83,9 @@ public function listContribution() { $recurRow = array(); $recurIDs = array(); while ($recur->fetch()) { - $mode = $recur->is_test ? 'test' : 'live'; - $paymentProcessor = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessor($recur->id, - $mode - ); - if (!$paymentProcessor) { + if (empty($recur->payment_processor_id)) { + // it's not clear why we continue here as any without a processor id would likely + // be imported from another system & still seem valid. continue; } @@ -121,10 +119,6 @@ public function listContribution() { ); $recurIDs[] = $values['id']; - - //reset $paymentObject for checking other paymenet processor - //recurring url - $paymentObject = NULL; } if (is_array($recurIDs) && !empty($recurIDs)) { $getCount = CRM_Contribute_BAO_ContributionRecur::getCount($recurIDs);