Skip to content

Commit

Permalink
Show 'Pay Now' on user dashboard for partially paid contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaphoneJon committed May 27, 2021
1 parent 8be074b commit dbfe939
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CRM/Contribute/Page/UserDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public function listContribution() {
// This is required for tpl logic. We should move away from hard-code this to adding an array of actions to the row
// which the tpl can iterate through - this should allow us to cope with competing attempts to add new buttons
// and allow extensions to assign new ones through the pageRun hook
if ('Pending' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id'])) {
$row['balance_amount'] = CRM_Contribute_BAO_Contribution::getContributionBalance($row['contribution_id']);
$contributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id']);

if (in_array($contributionStatus, ['Pending', 'Partially paid'])) {
$row['buttons']['pay'] = [
'class' => 'button',
'label' => ts('Pay Now'),
Expand Down
10 changes: 6 additions & 4 deletions templates/CRM/Contribute/Page/UserDashboard.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
<th>{ts}Financial Type{/ts}</th>
<th>{ts}Received date{/ts}</th>
<th>{ts}Receipt Sent{/ts}</th>
<th>{ts}Balance{/ts}</th>
<th>{ts}Status{/ts}</th>
{if $isIncludeInvoiceLinks}
<th></th>
{/if}
{foreach from=$row.buttons item=button}
<th></th>
{/foreach}
<th></th>
</tr>

{foreach from=$contribute_rows item=row}
Expand All @@ -39,6 +38,7 @@
<td>{$row.financial_type}</td>
<td>{$row.receive_date|truncate:10:''|crmDate}</td>
<td>{$row.receipt_date|truncate:10:''|crmDate}</td>
<td>{$row.balance_amount|crmMoney:$row.currency}</td>
<td>{$row.contribution_status}</td>
{if $isIncludeInvoiceLinks}
<td>
Expand All @@ -59,9 +59,11 @@
{/if}
</td>
{/if}
<td>
{foreach from=$row.buttons item=button}
<td><a class="{$button.class}" href="{$button.url}"><span class='nowrap'>{$button.label}</span></a></td>
<a class="{$button.class}" href="{$button.url}"><span class='nowrap'>{$button.label}</span></a>
{/foreach}
</td>
</tr>
{/foreach}
</table>
Expand Down
39 changes: 36 additions & 3 deletions tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public function testDashboardContentContributionsWithInvoicingEnabled() {
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th><th></th>',
'<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&amp;reset=1&amp;id=1&amp;cid=' . $this->contactID . '"><i class="crm-i fa-print" aria-hidden="true"></i><span>Print Invoice</span></a></td></tr><tr id=\'rowid2\'',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th><th></th>',
'<td>Completed</td><td><a class="button no-popup nowrap"href="/index.php?q=civicrm/contribute/invoice&amp;reset=1&amp;id=1&amp;cid=' . $this->contactID . '"><i class="crm-i fa-print" aria-hidden="true"></i><span>Print Invoice</span></a></td><td></td></tr><tr id=\'rowid2\'',
'Pay Now',
];

Expand Down Expand Up @@ -149,13 +149,46 @@ public function testDashboardContentContributions() {
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Status</th>',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
'<td>$ 100.00 </td><td>Donation</td>',
'<td>Completed</td>',
];
$this->assertPageContains($expectedStrings);
}

/**
* Test the presence of a "Pay Now" button on partial payments
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testDashboardPartialPayments() {
$contributionId = $this->contributionCreate([
'contact_id' => $this->contactID,
'contribution_status_id' => 'Pending',
'total_amount' => 25,
]);
$result = civicrm_api3('Payment', 'create', [
'contribution_id' => $contributionId,
'total_amount' => 11,
'trxn_date' => "2021-05-11",
]);
$this->contributions[] = civicrm_api3('Contribution', 'get', [
'contact_id' => $this->contactID,
'options' => ['limit' => 12, 'sort' => 'receive_date DESC'],
'sequential' => 1,
])['values'];
$this->runUserDashboard();
$expectedStrings = [
'Your Contribution(s)',
'<table class="selector"><tr class="columnheader"><th>Total Amount</th><th>Financial Type</th><th>Received date</th><th>Receipt Sent</th><th>Balance</th><th>Status</th>',
'<td>$ 25.00 </td><td>Donation</td>',
'<td>$ 14.00</td><td>Partially paid</td>',
'Pay Now',
];
$this->assertPageContains($expectedStrings);
}

/**
* Run the user dashboard.
*/
Expand Down

0 comments on commit dbfe939

Please sign in to comment.