Skip to content

Commit

Permalink
Merge pull request #13643 from eileenmcnaughton/recur
Browse files Browse the repository at this point in the history
[REF] minor refactor around retrieving processor id for recur
  • Loading branch information
eileenmcnaughton authored Feb 25, 2019
2 parents bad045b + 1a18d24 commit baa6938
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
26 changes: 18 additions & 8 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,31 @@ 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;
}

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.
*
Expand Down
12 changes: 3 additions & 9 deletions CRM/Contribute/Page/UserDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit baa6938

Please sign in to comment.