From e589a77b0b806cb9747c4cd8cf495fb6f2df7ff0 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 25 Sep 2021 14:10:37 +1200 Subject: [PATCH] Add workflow template for recurring cancelled 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... --- CRM/Contribute/Form/CancelSubscription.php | 11 ++--- .../WorkflowMessage/RecurringCancelled.php | 28 +++++++++++++ .../WorkflowMessage/RecurringEdit.php | 29 ++----------- .../WorkflowMessage/RecurringTrait.php | 41 +++++++++++++++++++ .../Form/CancelSubscriptionTest.php | 2 +- 5 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 CRM/Contribute/WorkflowMessage/RecurringCancelled.php create mode 100644 CRM/Contribute/WorkflowMessage/RecurringTrait.php diff --git a/CRM/Contribute/Form/CancelSubscription.php b/CRM/Contribute/Form/CancelSubscription.php index 1504cb2db3..4bcf840841 100644 --- a/CRM/Contribute/Form/CancelSubscription.php +++ b/CRM/Contribute/Form/CancelSubscription.php @@ -239,15 +239,11 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib $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'; @@ -262,6 +258,7 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib '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()), diff --git a/CRM/Contribute/WorkflowMessage/RecurringCancelled.php b/CRM/Contribute/WorkflowMessage/RecurringCancelled.php new file mode 100644 index 0000000000..2ffdfc14cd --- /dev/null +++ b/CRM/Contribute/WorkflowMessage/RecurringCancelled.php @@ -0,0 +1,28 @@ +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'; diff --git a/CRM/Contribute/WorkflowMessage/RecurringTrait.php b/CRM/Contribute/WorkflowMessage/RecurringTrait.php new file mode 100644 index 0000000000..4389c8952a --- /dev/null +++ b/CRM/Contribute/WorkflowMessage/RecurringTrait.php @@ -0,0 +1,41 @@ +contributionRecur = $contributionRecur; + if (!empty($contributionRecur['id'])) { + $this->contributionRecurId = $contributionRecur['id']; + } + return $this; + } + +} diff --git a/tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php b/tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php index acdb085eee..6bef624257 100644 --- a/tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/CancelSubscriptionTest.php @@ -49,7 +49,7 @@ class CRM_Contribute_Form_CancelSubscriptionTest extends CRM_Contribute_Form_Rec "Subject: Recurring Contribution Cancellation Notification - Mr. Anthony\n Anderson II", 'Return-Path: bob@example.org', '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', ]; } -- 2.25.1