Skip to content

Commit

Permalink
Add workflow template for recurring cancelled
Browse files Browse the repository at this point in the history
This is a simple template, with a slightly smaller subset of values than the exisiting one.

It pulls out the recurring part to a trait...
  • Loading branch information
eileenmcnaughton committed Sep 25, 2021
1 parent a3a940e commit 3f739a7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 33 deletions.
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';
$export['smartyTokenAlias']['recur_frequency_interval'] = 'contribution_recur.frequency_interval';
}

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

/**
* The recurring contribution contact.
Expand All @@ -20,23 +20,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 +31,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;
}

}

0 comments on commit 3f739a7

Please sign in to comment.