Skip to content

Commit

Permalink
Send pcp notification only when the contribution is completed
Browse files Browse the repository at this point in the history
This is a reviewer's cut of civicrm#19096
the only substantive difference is the check around the contribution_status_id
in this line https://github.com/civicrm/civicrm-core/pull/19096/files#diff-9f33a2073e9f844dbb842e0737b7df4bce13db31eabe13b9bdd10e1035dbf6d3R612
has had the empty(->contribution_page_id) bit removed - I can
't think why that would be added in & I think it was discussed out but not removed
  • Loading branch information
eileenmcnaughton committed Jun 7, 2021
1 parent 7b2383e commit a085d22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Civi\Api4\Contribution;
use Civi\Api4\ContributionRecur;
use Civi\Api4\LineItem;
use Civi\Api4\ContributionSoft;
use Civi\Api4\PaymentProcessor;
use Civi\Api4\PledgePayment;

Expand Down Expand Up @@ -4206,6 +4207,14 @@ public static function completeOrder($input, $recurringContributionID, $contribu
$transaction->commit();
\Civi::log()->info("Contribution {$contributionParams['id']} updated successfully");

$contributionSoft = ContributionSoft::get(FALSE)
->addWhere('contribution_id', '=', $contributionID)
->addWhere('pcp_id', '>', 0)
->addSelect('*')
->execute()->first();
if (!empty($contributionSoft)) {
CRM_Contribute_BAO_ContributionSoft::pcpNotifyOwner($contributionID, $contributionSoft);
}
// @todo - check if Contribution::create does this, test, remove.
CRM_Contribute_BAO_ContributionRecur::updateRecurLinkedPledge($contributionID, $recurringContributionID,
$contributionParams['contribution_status_id'], $input['amount']);
Expand Down
6 changes: 4 additions & 2 deletions CRM/Contribute/BAO/ContributionSoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,10 @@ protected static function processPCP($pcp, $contribution) {
$softParams['pcp_personal_note'] = $pcp['pcp_personal_note'] ?? NULL;
$softParams['soft_credit_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', 'pcp');
$contributionSoft = self::add($softParams);
//Send notification to owner for PCP
if ($contributionSoft->pcp_id && empty($pcpId)) {
//Send notification to owner for PCP if the contribution is already completed.
if ($contributionSoft->pcp_id && empty($pcpId)
&& 'Completed' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution->contribution_status_id)
) {
self::pcpNotifyOwner($contribution->id, (array) $contributionSoft);
}
}
Expand Down

0 comments on commit a085d22

Please sign in to comment.