* View details of a recurring contribution.
*/
public function view() {
- $recur = new CRM_Contribute_DAO_ContributionRecur();
- $recur->id = $this->_id;
- if ($recur->find(TRUE)) {
- $values = array();
- CRM_Core_DAO::storeValues($recur, $values);
- // if there is a payment processor ID, get the name of the payment processor
- if (!empty($values['payment_processor_id'])) {
- $values['payment_processor'] = CRM_Core_DAO::getFieldValue(
- 'CRM_Financial_DAO_PaymentProcessor',
- $values['payment_processor_id'],
- 'name'
- );
- }
- $idFields = array('contribution_status_id', 'campaign_id');
- if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($values['id'])) {
- $idFields[] = 'financial_type_id';
- }
- foreach ($idFields as $idField) {
- if (!empty($values[$idField])) {
- $values[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $values[$idField]);
- }
- }
+ if (empty($this->_id)) {
+ CRM_Core_Error::statusBounce('Recurring contribution not found');
+ }
- // Add linked membership
- $membership = civicrm_api3('Membership', 'get', array(
- 'contribution_recur_id' => $recur->id,
+ try {
+ $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', array(
+ 'id' => $this->_id,
));
- if (!empty($membership['count'])) {
- $membershipDetails = reset($membership['values']);
- $values['membership_id'] = $membershipDetails['id'];
- $values['membership_name'] = $membershipDetails['membership_name'];
+ }
+ catch (Exception $e) {
+ CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->_id);
+ }
+
+ $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName($contributionRecur['payment_processor_id']);
+ $idFields = array('contribution_status_id', 'campaign_id', 'financial_type_id');
+ foreach ($idFields as $idField) {
+ if (!empty($contributionRecur[$idField])) {
+ $contributionRecur[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $contributionRecur[$idField]);
}
+ }
- $this->assign('recur', $values);
+ // Add linked membership
+ $membership = civicrm_api3('Membership', 'get', array(
+ 'contribution_recur_id' => $contributionRecur['id'],
+ ));
+ if (!empty($membership['count'])) {
+ $membershipDetails = reset($membership['values']);
+ $contributionRecur['membership_id'] = $membershipDetails['id'];
+ $contributionRecur['membership_name'] = $membershipDetails['membership_name'];
}
+
+ $this->assign('recur', $contributionRecur);
}
public function preProcess() {
- $context = CRM_Utils_Request::retrieve('context', 'String', $this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view');
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$controller->run();
// add recurring block
+ $this->addRecurringContributionsBlock();
+
+ // enable/disable soft credit records for test contribution
+ $isTest = 0;
+ if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
+ $isTest = 1;
+ }
+ $this->assign('isTest', $isTest);
+
+ $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, NULL, $isTest);
+
+ if (!empty($softCreditList)) {
+ $softCreditTotals = array();
+
+ list($softCreditTotals['amount'],
+ $softCreditTotals['avg'],
+ $softCreditTotals['currency'],
+ $softCreditTotals['cancelAmount'] // to get cancel amount
+ ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest);
+
+ $this->assign('softCredit', TRUE);
+ $this->assign('softCreditRows', $softCreditList);
+ $this->assign('softCreditTotals', $softCreditTotals);
+ }
+
+ if ($this->_contactId) {
+ $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
+ $this->assign('displayName', $displayName);
+ $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
+ }
+ }
+
+ /**
+ * Get all the recurring contribution information and assign to the template
+ */
+ private function addRecurringContributionsBlock() {
try {
$contributionRecurResult = civicrm_api3('ContributionRecur', 'get', array(
'contact_id' => $this->_contactId,
// no action allowed if it's not active
$recurContributions[$recurId]['is_active'] = (!CRM_Contribute_BAO_Contribution::isContributionStatusNegative($recurDetail['contribution_status_id']));
+ // Get the name of the payment processor
+ if (!empty($recurDetail['payment_processor_id'])) {
+ $recurContributions[$recurId]['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName($recurDetail['payment_processor_id']);
+ }
+ // Get the label for the contribution status
+ if (!empty($recurDetail['contribution_status_id'])) {
+ $recurContributions[$recurId]['contribution_status'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', $recurDetail['contribution_status_id']);
+ }
+
if ($recurContributions[$recurId]['is_active']) {
$details = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($recurContributions[$recurId]['id'], 'recur');
$hideUpdate = $details->membership_id & $details->auto_renew;
$this->assign('recurRows', $recurContributions);
$this->assign('recur', TRUE);
}
-
- // enable/disable soft credit records for test contribution
- $isTest = 0;
- if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
- $isTest = 1;
- }
- $this->assign('isTest', $isTest);
-
- $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, NULL, $isTest);
-
- if (!empty($softCreditList)) {
- $softCreditTotals = array();
-
- list($softCreditTotals['amount'],
- $softCreditTotals['avg'],
- $softCreditTotals['currency'],
- $softCreditTotals['cancelAmount'] // to get cancel amount
- ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest);
-
- $this->assign('softCredit', TRUE);
- $this->assign('softCreditRows', $softCreditList);
- $this->assign('softCreditTotals', $softCreditTotals);
- }
-
- if ($this->_contactId) {
- $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
- $this->assign('displayName', $displayName);
- $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
- }
}
/**
return Civi\Payment\System::singleton()->getById($paymentProcessorId);
}
+ /**
+ * Get the name of the payment processor
+ *
+ * @param $paymentProcessorId
+ *
+ * @return null|string
+ */
+ public static function getPaymentProcessorName($paymentProcessorId) {
+ try {
+ $paymentProcessor = civicrm_api3('PaymentProcessor', 'getsingle', array(
+ 'return' => array('name'),
+ 'id' => $paymentProcessorId,
+ ));
+ return $paymentProcessor['name'];
+ }
+ catch (Exception $e) {
+ return ts('Unknown') . ' (' . $paymentProcessorId . ')';
+ }
+ }
+
/**
* Generate and assign an arbitrary value to a field of a test object.
*