From 0bd096e8498d606a87b125582ad85862c36383b5 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Wed, 5 Aug 2015 11:08:21 +1200 Subject: [PATCH] CRM-16965 deal with membership processor not loading properly --- CRM/Financial/BAO/PaymentProcessor.php | 33 ++++++++++++++++++++++---- CRM/Member/Page/Tab.php | 6 +++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CRM/Financial/BAO/PaymentProcessor.php b/CRM/Financial/BAO/PaymentProcessor.php index 7f5535adc7..4eb174139b 100644 --- a/CRM/Financial/BAO/PaymentProcessor.php +++ b/CRM/Financial/BAO/PaymentProcessor.php @@ -381,6 +381,25 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces /** * Retrieve payment processor id / info/ object based on component-id. * + * @todo function needs revisiting. The whole 'info / obj' thing is an overload. Recommend creating new functions + * that are entity specific as there is little shared code specific to obj or info + * + * Also, it does not accurately derive the processor - for a completed contribution the best place to look is in the + * relevant financial_trxn record. For a recurring contribution it is in the contribution_recur table. + * + * For a membership the relevant contribution_recur should be derived & then resolved as above. The contribution page + * is never a reliable place to look as there can be more than one configured. For a pending contribution there is + * no way to derive the processor - but hey - what processor? it didn't go through! + * + * Query for membership might look something like: + * SELECT fte.payment_processor_id + * FROM civicrm_membership mem + * INNER JOIN civicrm_line_item li ON ( mem.id = li.entity_id AND li.entity_table = 'civicrm_membership') + * INNER JOIN civicrm_contribution con ON ( li.contribution_id = con.id ) + * LEFT JOIN civicrm_entity_financial_trxn ft ON ft.entity_id = con.id AND ft.entity_table = + * 'civicrm_contribution' + * LEFT JOIN civicrm_financial_trxn fte ON fte.id = ft.financial_trxn_id + * * @param int $entityID * @param string $component * Component. @@ -445,11 +464,17 @@ INNER JOIN civicrm_contribution con ON ( mp.contribution_id = con.id ) elseif ($type == 'info') { $result = self::getPayment($ppID, $mode); } - elseif ($type == 'obj') { - $payment = self::getPayment($ppID, $mode); - $result = Civi\Payment\System::singleton()->getByProcessor($payment); + elseif ($type == 'obj' && is_numeric($ppID)) { + try { + $paymentProcessor = civicrm_api3('PaymentProcessor', 'getsingle', array('id' => $ppID)); + } + catch (API_Exception $e) { + // Unable to load the processor because this function uses an unreliable method to derive it. + // The function looks to load the payment processor ID from the contribution page, which + // can support multiple processors. + } + $result = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor); } - return $result; } diff --git a/CRM/Member/Page/Tab.php b/CRM/Member/Page/Tab.php index cf1d10f3d6..9e3156a8dc 100644 --- a/CRM/Member/Page/Tab.php +++ b/CRM/Member/Page/Tab.php @@ -99,12 +99,18 @@ class CRM_Member_Page_Tab extends CRM_Core_Page { } $isUpdateBilling = FALSE; + // It would be better to determine if there is a recurring contribution & + // is so get the entity for the recurring contribution (& skip if not). $paymentObject = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity( $membership[$dao->id]['membership_id'], 'membership', 'obj'); if (!empty($paymentObject)) { + // @todo - get this working with syntax style $paymentObject->supports(array + //('updateSubscriptionBillingInfo')); $isUpdateBilling = $paymentObject->isSupported('updateSubscriptionBillingInfo'); } + // @todo - get this working with syntax style $paymentObject->supports(array + //('CancelSubscriptionSupported')); $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported( $membership[$dao->id]['membership_id']); -- 2.25.1