Skip to content

Commit

Permalink
Issue#521: Send notification after successful contribution payment
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant-bhorodia committed Dec 15, 2020
1 parent 69be620 commit fbba50e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
12 changes: 12 additions & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4255,6 +4255,18 @@ public static function completeOrder($input, $ids, $contribution, $isPostPayment
$contribution->contribution_status_id = $contributionParams['contribution_status_id'];

CRM_Core_Error::debug_log_message('Contribution record updated successfully');
$contributionSoft = civicrm_api4('ContributionSoft', 'get', [
'where' => [
['contribution_id', '=', $contributionID],
],
'checkPermissions' => FALSE,
]);
if(!empty($contributionSoft)) {
//Send notification to owner for PCP
if ($contributionSoft->column('pcp_id')) {
CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft[0]);
}
}
$transaction->commit();

// @todo - check if Contribution::create does this, test, remove.
Expand Down
4 changes: 0 additions & 4 deletions CRM/Contribute/BAO/ContributionSoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,6 @@ 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)) {
CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
}
}
//Delete PCP against this contribution and create new on submitted PCP information
elseif ($pcpId) {
Expand Down
20 changes: 10 additions & 10 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1240,21 +1240,21 @@ public static function processOnBehalfOrganization(&$behalfOrganization, &$conta
* This is used by contribution and also event PCPs.
*
* @param object $contribution
* @param object $contributionSoft
* Contribution object.
* @param array $contributionSoft
* Contribution array.
*/
public static function pcpNotifyOwner($contribution, $contributionSoft) {
$params = ['id' => $contributionSoft->pcp_id];
$params = ['id' => $contributionSoft['pcp_id']];
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
$ownerNotifyID = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id');
$ownerNotifyOption = CRM_Core_PseudoConstant::getName('CRM_PCP_DAO_PCPBlock', 'owner_notify_id', $ownerNotifyID);

if ($ownerNotifyOption != 'no_notifications' &&
(($ownerNotifyOption == 'owner_chooses' &&
CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft->pcp_id, 'is_notify')) ||
CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft['pcp_id'], 'is_notify')) ||
$ownerNotifyOption == 'all_owners')) {
$pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info',
"reset=1&id={$contributionSoft->pcp_id}",
"reset=1&id={$contributionSoft['pcp_id']}",
TRUE, NULL, FALSE, TRUE
);
// set email in the template here
Expand All @@ -1267,22 +1267,22 @@ public static function pcpNotifyOwner($contribution, $contributionSoft) {
if (!$email) {
[$donorName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id);
}
[$ownerName, $ownerEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contributionSoft->contact_id);
[$ownerName, $ownerEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($contributionSoft['contact_id']);
$tplParams = [
'page_title' => $pcpInfo['title'],
'receive_date' => $contribution->receive_date,
'total_amount' => $contributionSoft->amount,
'total_amount' => $contributionSoft['amount'],
'donors_display_name' => $donorName,
'donors_email' => $email,
'pcpInfoURL' => $pcpInfoURL,
'is_honor_roll_enabled' => $contributionSoft->pcp_display_in_roll,
'currency' => $contributionSoft->currency,
'is_honor_roll_enabled' => $contributionSoft['pcp_display_in_roll'],
'currency' => $contributionSoft['currency'],
];
$domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
$sendTemplateParams = [
'groupName' => 'msg_tpl_workflow_contribution',
'valueName' => 'pcp_owner_notify',
'contactId' => $contributionSoft->contact_id,
'contactId' => $contributionSoft['contact_id'],
'toEmail' => $ownerEmail,
'toName' => $ownerName,
'from' => "$domainValues[0] <$domainValues[1]>",
Expand Down

0 comments on commit fbba50e

Please sign in to comment.