From dd793ad1198993ef009a1eaf61cf73e77a649ae2 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Mon, 9 Mar 2020 12:34:39 +0000 Subject: [PATCH] Generate text for cancelSubscription form in payment class --- CRM/Contribute/Form/CancelSubscription.php | 37 +++++++++++-------- CRM/Core/Payment.php | 27 ++++++++++++++ .../Contribute/Form/CancelSubscription.tpl | 14 +------ 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/CRM/Contribute/Form/CancelSubscription.php b/CRM/Contribute/Form/CancelSubscription.php index f3720baa23..b500c4235a 100644 --- a/CRM/Contribute/Form/CancelSubscription.php +++ b/CRM/Contribute/Form/CancelSubscription.php @@ -45,12 +45,17 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib */ public function preProcess() { parent::preProcess(); - if ($this->_crid) { - $this->assign('frequency_unit', $this->getSubscriptionDetails()->frequency_unit); - $this->assign('frequency_interval', $this->getSubscriptionDetails()->frequency_interval); - $this->assign('amount', $this->getSubscriptionDetails()->amount); - $this->assign('installments', $this->getSubscriptionDetails()->installments); + $cancelRecurTextParams = [ + 'mode' => $this->_mode, + 'amount' => $this->getSubscriptionDetails()->amount, + 'currency' => $this->getSubscriptionDetails()->currency, + 'frequency_interval' => $this->getSubscriptionDetails()->frequency_interval, + 'frequency_unit' => $this->getSubscriptionDetails()->frequency_unit, + 'installments' => $this->getSubscriptionDetails()->installments, + ]; + + if ($this->_crid) { // Are we cancelling a recurring contribution that is linked to an auto-renew membership? if ($this->getSubscriptionDetails()->membership_id) { $this->_mid = $this->getSubscriptionDetails()->membership_id; @@ -64,7 +69,9 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib $membershipTypes = CRM_Member_PseudoConstant::membershipType(); $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_mid, 'membership_type_id'); - $this->assign('membershipType', CRM_Utils_Array::value($membershipTypeId, $membershipTypes)); + $membershipType = $membershipTypes[$membershipTypeId] ?? ''; + $this->assign('membershipType', $membershipType); + $cancelRecurTextParams['membershipType'] = $membershipType; } if ($this->_coid) { @@ -72,11 +79,6 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib CRM_Core_Error::statusBounce(ts('The recurring contribution looks to have been cancelled already.')); } $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'obj'); - - $this->assign('frequency_unit', $this->getSubscriptionDetails()->frequency_unit); - $this->assign('frequency_interval', $this->getSubscriptionDetails()->frequency_interval); - $this->assign('amount', $this->getSubscriptionDetails()->amount); - $this->assign('installments', $this->getSubscriptionDetails()->installments); } if ( @@ -86,6 +88,8 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib CRM_Core_Error::statusBounce('Required information missing.'); } + $this->assign('cancelRecurDetailText', $this->_paymentProcessorObj->getText('cancelRecurDetailText', $cancelRecurTextParams)); + // handle context redirection CRM_Contribute_BAO_ContributionRecur::setSubscriptionContext(); @@ -140,6 +144,9 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib [1 => $this->_paymentProcessorObj->_processorName]) ); } + else { + $this->assign('cancelRecurNotSupportedText', $this->_paymentProcessorObj->getText('cancelRecurNotSupportedText', [])); + } $this->assign('cancelSupported', $cancelSupported); if ($this->_donorEmail) { @@ -239,13 +246,13 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib else { $tplParams['recur_frequency_interval'] = $this->getSubscriptionDetails()->frequency_interval; $tplParams['recur_frequency_unit'] = $this->getSubscriptionDetails()->frequency_unit; - $tplParams['amount'] = $this->getSubscriptionDetails()->amount; + $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 => $this->getSubscriptionDetails()->amount, - 2 => $this->getSubscriptionDetails()->frequency_interval, - 3 => $this->getSubscriptionDetails()->frequency_unit, + 1 => $tplParams['amount'], + 2 => $tplParams['recur_frequency_interval'], + 3 => $tplParams['recur_frequency_unit'], ] ); $msgTitle = 'Contribution Cancelled'; diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index b1df8ec53a..9bbc1f3f45 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -551,6 +551,9 @@ abstract class CRM_Core_Payment { * Only explicitly supported contexts are handled without error. * Currently supported: * - contributionPageRecurringHelp (params: is_recur_installments, is_email_receipt) + * - contributionPageContinueText (params: amount, is_payment_to_existing) + * - cancelRecurDetailText (params: mode, amount, currency, frequency_interval, frequency_unit, installments, {membershipType|only if mode=auto_renew}) + * - cancelRecurNotSupportedText * * @param array $params * Parameters for the field, context specific. @@ -590,6 +593,30 @@ abstract class CRM_Core_Payment { } return ts('To complete your contribution, click the Continue button below.'); + case 'cancelRecurDetailText': + if ($params['mode'] === 'auto_renew') { + return ts('Click the button below if you want to cancel the auto-renewal option for your %1 membership. This will not cancel your membership. However you will need to arrange payment for renewal when your membership expires.', + [1 => $params['membershipType']] + ); + } + else { + $text = ts('Recurring Contribution Details: %1 every %2 %3', [ + 1 => CRM_Utils_Money::format($params['amount'], $params['currency']), + 2 => $params['frequency_interval'], + 3 => $params['frequency_unit'], + ]); + if (!empty($params['installments'])) { + $text .= ' ' . ts('for %1 installments', [1 => $params['installments']]) . '.'; + } + $text = "{$text}
"; + $text .= ts('Click the button below to cancel this commitment and stop future transactions. This does not affect contributions which have already been completed.'); + $text .= '
'; + return $text; + } + + case 'cancelRecurNotSupportedText': + return ts('Automatic cancellation is not supported for this payment processor. You or the contributor will need to manually cancel this recurring contribution using the payment processor website.'); + } CRM_Core_Error::deprecatedFunctionWarning('Calls to getText must use a supported method'); return ''; diff --git a/templates/CRM/Contribute/Form/CancelSubscription.tpl b/templates/CRM/Contribute/Form/CancelSubscription.tpl index 5ed29e5ca0..74e5e2f186 100644 --- a/templates/CRM/Contribute/Form/CancelSubscription.tpl +++ b/templates/CRM/Contribute/Form/CancelSubscription.tpl @@ -11,19 +11,9 @@
  - {if $mode eq 'auto_renew'} - {ts}Click the button below if you want to cancel the auto-renewal option for your {$membershipType} membership. This will not cancel your membership. However you will need to arrange payment for renewal when your membership expires.{/ts} - {else} - {ts 1=$amount|crmMoney 2=$frequency_interval 3=$frequency_unit}Recurring Contribution Details: %1 every %2 %3{/ts} - {if $installments} - {ts 1=$installments}for %1 installments{/ts}. - {/if} -
{ts}Click the button below to cancel this commitment and stop future transactions. This does not affect contributions which have already been completed.{/ts}
- {/if} + {$cancelRecurDetailText} {if !$cancelSupported} -
- {ts}Automatic cancellation is not supported for this payment processor. You or the contributor will need to manually cancel this recurring contribution using the payment processor website.{/ts} -
+
{$cancelRecurNotSupportedText}
{/if}
{include file="CRM/Core/Form/EntityForm.tpl"} -- 2.25.1