Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow template for recurring cancelled #21611

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions CRM/Contribute/Form/CancelSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,11 @@ public function postProcess() {
$msgType = 'info';
}
else {
$tplParams['recur_frequency_interval'] = $this->getSubscriptionDetails()->frequency_interval;
$tplParams['recur_frequency_unit'] = $this->getSubscriptionDetails()->frequency_unit;
$tplParams['amount'] = CRM_Utils_Money::format($this->getSubscriptionDetails()->amount, $this->getSubscriptionDetails()->currency);
$tplParams['contact'] = ['display_name' => $this->_donorDisplayName];
$status = ts('The recurring contribution of %1, every %2 %3 has been cancelled.',
[
1 => $tplParams['amount'],
2 => $tplParams['recur_frequency_interval'],
3 => $tplParams['recur_frequency_unit'],
1 => CRM_Utils_Money::format($this->getSubscriptionDetails()->amount, $this->getSubscriptionDetails()->currency),
2 => $this->getSubscriptionDetails()->frequency_interval,
3 => $this->getSubscriptionDetails()->frequency_unit,
]
);
$msgTitle = 'Contribution Cancelled';
Expand All @@ -262,6 +258,7 @@ public function postProcess() {
'valueName' => $this->_mode == 'auto_renew' ? 'membership_autorenew_cancelled' : 'contribution_recurring_cancelled',
'contactId' => $this->getSubscriptionDetails()->contact_id,
'tplParams' => $tplParams,
'tokenContext' => ['contribution_recurId' => $this->getContributionRecurID()],
//'isTest' => $isTest, set this from _objects
'PDFFilename' => 'receipt.pdf',
'from' => CRM_Contribute_BAO_ContributionRecur::getRecurFromAddress($this->getContributionRecurID()),
Expand Down
28 changes: 28 additions & 0 deletions CRM/Contribute/WorkflowMessage/RecurringCancelled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* @support template-only
*/
class CRM_Contribute_WorkflowMessage_RecurringCancelled extends Civi\WorkflowMessage\GenericWorkflowMessage {
use CRM_Contribute_WorkflowMessage_RecurringTrait;

public const WORKFLOW = 'contribution_recurring_cancelled';

/**
* The recurring contribution contact.
*
* @var array|null
*
* @scope tokenContext
*
* @required
*/
public $contact;

protected function exportExtraTokenContext(array &$export): void {
$export['smartyTokenAlias']['amount'] = 'contribution_recur.amount';
$export['smartyTokenAlias']['recur_frequency_unit'] = 'contribution_recur.frequency_unit:label';
$export['smartyTokenAlias']['recur_frequency_interval'] = 'contribution_recur.frequency_interval';
}

}
29 changes: 3 additions & 26 deletions CRM/Contribute/WorkflowMessage/RecurringEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* @method array getContributionRecur()
*/
class CRM_Contribute_WorkflowMessage_RecurringEdit extends Civi\WorkflowMessage\GenericWorkflowMessage {
const WORKFLOW = 'contribution_recurring_edit';
use CRM_Contribute_WorkflowMessage_RecurringTrait;

public const WORKFLOW = 'contribution_recurring_edit';

/**
* The recurring contribution contact.
Expand All @@ -20,23 +22,6 @@ class CRM_Contribute_WorkflowMessage_RecurringEdit extends Civi\WorkflowMessage\
*/
public $contact;

/**
* The recurring contribution.
*
* @var array|null
*
* @scope tokenContext as contribution_recur
*
* @required
*/
public $contributionRecur;

/**
* @var int
* @scope tokenContext as contribution_recurId
*/
public $contributionRecurId;

/**
* Smarty template historically defined a property 'receipt_from_email'.
* (Note the asymmetric lack of 'receipt_from_name'.)
Expand All @@ -48,14 +33,6 @@ class CRM_Contribute_WorkflowMessage_RecurringEdit extends Civi\WorkflowMessage\
*/
public $receiptFromEmail;

public function setContributionRecur(array $contributionRecur) {
$this->contributionRecur = $contributionRecur;
if (!empty($contributionRecur['id'])) {
$this->contributionRecurId = $contributionRecur['id'];
}
return $this;
}

protected function exportExtraTokenContext(array &$export): void {
$export['smartyTokenAlias']['installments'] = 'contribution_recur.installments';
$export['smartyTokenAlias']['amount'] = 'contribution_recur.amount';
Expand Down
41 changes: 41 additions & 0 deletions CRM/Contribute/WorkflowMessage/RecurringTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @method array getContributionRecur()
* @method array getContact()
* @method $this setContact(array $contact)
*/
trait CRM_Contribute_WorkflowMessage_RecurringTrait {
/**
* The recurring contribution.
*
* @var array|null
*
* @scope tokenContext as contribution_recur
*
* @required
*/
public $contributionRecur;

/**
* @var int
* @scope tokenContext as contribution_recurId
*/
public $contributionRecurId;

/**
* Set recurring contribution object.
*
* @param array $contributionRecur
*
* @return $this
*/
public function setContributionRecur(array $contributionRecur): self {
$this->contributionRecur = $contributionRecur;
if (!empty($contributionRecur['id'])) {
$this->contributionRecurId = $contributionRecur['id'];
}
return $this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getExpectedMailStrings(): array {
"Subject: Recurring Contribution Cancellation Notification - Mr. Anthony\n Anderson II",
'Return-Path: [email protected]',
'Dear Anthony,',
'Your recurring contribution of $ 10.00, every 1 month has been cancelled as requested',
'Your recurring contribution of $10.00, every 1 month has been cancelled as requested',
];
}

Expand Down