/**
* 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.
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;
}
}
$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']);