Skip to content

Commit

Permalink
Merge pull request #12818 from mattwire/contributionsearch_byrecurtrx…
Browse files Browse the repository at this point in the history
…nprocessor

Allow contribution search by recurring payment processor ID / Transaction ID
  • Loading branch information
seamuslee001 authored Nov 2, 2018
2 parents a5270b6 + 64127e0 commit 7649c95
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
17 changes: 17 additions & 0 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,14 @@ public static function recurringContribution(&$form) {
}
}

// If values have been supplied for recurring contribution fields, open the recurring contributions pane.
foreach (array('contribution_status_id', 'payment_processor_id', 'processor_id', 'trxn_id') as $fieldName) {
if (!empty($form->_formValues['contribution_recur_' . $fieldName])) {
$form->assign('contribution_recur_pane_open', TRUE);
break;
}
}

// Add field to check if payment is made for recurring contribution
$recurringPaymentOptions = array(
1 => ts('All recurring contributions'),
Expand All @@ -783,6 +791,15 @@ public static function recurringContribution(&$form) {
$form->addElement('text', 'contribution_recur_processor_id', ts('Processor ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'processor_id'));
$form->addElement('text', 'contribution_recur_trxn_id', ts('Transaction ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'trxn_id'));

$paymentProcessorParams = [
'return' => ["id", "name", 'is_test'],
];
$paymentProcessors = civicrm_api3('PaymentProcessor', 'get', $paymentProcessorParams);
foreach ($paymentProcessors['values'] as $key => $value) {
$paymentProcessorOpts[$key] = $value['name'] . ($value['is_test'] ? ' (Test)' : '');
}
$form->add('select', 'contribution_recur_payment_processor_id', ts('Payment Processor ID'), $paymentProcessorOpts, FALSE, ['class' => 'crm-select2', 'multiple' => 'multiple']);

CRM_Core_BAO_Query::addCustomFormFields($form, array('ContributionRecur'));

}
Expand Down
13 changes: 13 additions & 0 deletions CRM/Contribute/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,25 @@ public static function whereClauseSingle(&$values, &$query) {
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;

case 'contribution_recur_payment_processor_id':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution_recur.payment_processor_id", $op, $value, "String");
$paymentProcessors = civicrm_api3('PaymentProcessor', 'get', array());
$paymentProcessorNames = array();
foreach ($value as $paymentProcessorId) {
$paymentProcessorNames[] = $paymentProcessors['values'][$paymentProcessorId]['name'];
}
$query->_qill[$grouping][] = ts("Recurring Contribution Payment Processor %1 %2", array(1 => $op, 2 => implode(', ', $paymentProcessorNames)));
$query->_tables['civicrm_contribution_recur'] = $query->_whereTables['civicrm_contribution_recur'] = 1;
return;

case 'contribution_recur_processor_id':
case 'contribution_recur_trxn_id':
$fieldName = str_replace('contribution_recur_', '', $name);
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution_recur.{$fieldName}",
$op, $value, "String"
);
$recurFields = CRM_Contribute_DAO_ContributionRecur::fields();
$query->_qill[$grouping][] = ts("Recurring Contribution %1 %2 '%3'", array(1 => $recurFields[$fieldName]['title'], 2 => $op, 3 => $value));
$query->_tables['civicrm_contribution_recur'] = $query->_whereTables['civicrm_contribution_recur'] = 1;
return;

Expand Down
14 changes: 14 additions & 0 deletions templates/CRM/Contact/Form/Search/Advanced.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,17 @@
<p>{ts}In the process of setting up CiviCRM components or configuring pages and profiles, you might have created test contributions, activities, participants, pledges, etc.{/ts}</p>
<p>{ts}Once you have finished your testing, it is a good idea to clean up by finding your test records and deleting them.{/ts}</p>
{/htxt}

{htxt id="processor-id-title"}
{ts}Processor ID{/ts}
{/htxt}
{htxt id="processor-id"}
<p>{ts}This is the payment processor's own ID for the recurring contribution. Ideally it should be unique, but in practice may not be.{/ts}</p>
{/htxt}

{htxt id="transaction-id-title"}
{ts}Transaction ID{/ts}
{/htxt}
{htxt id="transaction-id"}
<p>{ts}Unique reference for the recurring contribution. May be made up of other fields, e.g. bank ID, account number, etc.{/ts}</p>
{/htxt}
23 changes: 22 additions & 1 deletion templates/CRM/Contribute/Form/Search/ContributionRecur.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,33 @@
</td>
</tr>
<tr>
<td>{ts}Recurring Contribution Status{/ts}</td>
<td>{ts}Status{/ts}</td>
<td></td>
<td col='span2'>
{$form.contribution_recur_contribution_status_id.html|crmAddClass:twenty}
</td>
</tr>
<tr>
<td>{ts}Payment Processor{/ts}</td>
<td></td>
<td col='span2'>
{$form.contribution_recur_payment_processor_id.html}
</td>
</tr>
<tr>
<td>{ts}Processor ID{/ts} {help id="processor-id" file="CRM/Contact/Form/Search/Advanced"}</td>
<td></td>
<td col='span2'>
{$form.contribution_recur_processor_id.html}
</td>
</tr>
<tr>
<td>{ts}Transaction ID{/ts} {help id="transaction-id" file="CRM/Contact/Form/Search/Advanced"}</td>
<td></td>
<td col='span2'>
{$form.contribution_recur_trxn_id.html}
</td>
</tr>
{if $contributionRecurGroupTree}
<tr>
<td colspan="4">
Expand Down

0 comments on commit 7649c95

Please sign in to comment.