From f926d56f471027946be8abfae8578fb35fbba6c2 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Mon, 3 Dec 2018 15:35:31 +0000 Subject: [PATCH] Display self-service links in email receipts based on payment processor capabilities --- CRM/Core/Payment.php | 6 +++ CRM/Core/Payment/Dummy.php | 10 +++++ CRM/Upgrade/Incremental/MessageTemplates.php | 13 +++++++ .../contribution_online_receipt_html.tpl | 39 ++++++++++--------- .../contribution_online_receipt_text.tpl | 12 +++++- .../contribution_recurring_notify_html.tpl | 20 ++++++---- .../contribution_recurring_notify_text.tpl | 12 +++++- .../membership_online_receipt_html.tpl | 7 ++-- .../membership_online_receipt_text.tpl | 10 +++-- 9 files changed, 95 insertions(+), 34 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 952be8a5f3..779aca3248 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1465,6 +1465,9 @@ abstract class CRM_Core_Payment { // Set URL switch ($action) { case 'cancel': + if (!$this->supports('cancelRecurring')) { + return NULL; + } $url = 'civicrm/contribute/unsubscribe'; break; @@ -1477,6 +1480,9 @@ abstract class CRM_Core_Payment { break; case 'update': + if (!$this->supports('changeSubscriptionAmount') && !$this->supports('editRecurringContribution')) { + return NULL; + } $url = 'civicrm/contribute/updaterecur'; break; } diff --git a/CRM/Core/Payment/Dummy.php b/CRM/Core/Payment/Dummy.php index 1d68efe868..08b5486433 100644 --- a/CRM/Core/Payment/Dummy.php +++ b/CRM/Core/Payment/Dummy.php @@ -198,4 +198,14 @@ class CRM_Core_Payment_Dummy extends CRM_Core_Payment { return array('amount', 'next_sched_contribution_date'); } + /** + * @param string $message + * @param array $params + * + * @return bool|object + */ + public function cancelSubscription(&$message = '', $params = array()) { + return TRUE; + } + } diff --git a/CRM/Upgrade/Incremental/MessageTemplates.php b/CRM/Upgrade/Incremental/MessageTemplates.php index 127fe8ed2d..407cfa7a2f 100644 --- a/CRM/Upgrade/Incremental/MessageTemplates.php +++ b/CRM/Upgrade/Incremental/MessageTemplates.php @@ -89,6 +89,19 @@ class CRM_Upgrade_Incremental_MessageTemplates { 'templates' => [ ['name' => 'contribution_invoice_receipt', 'type' => 'html'], ] + ], + [ + 'version' => '5.10.alpha1', + 'upgrade_descriptor' => ts('Show recurring cancel/update URLs in receipt based on payment processor capabilities'), + 'label' => ts('Receipts - cancel/update subscription URLs'), + 'templates' => [ + ['name' => 'contribution_online_receipt', 'type' => 'text'], + ['name' => 'contribution_online_receipt', 'type' => 'html'], + ['name' => 'contribution_recurring_notify', 'type' => 'text'], + ['name' => 'contribution_recurring_notify', 'type' => 'html'], + ['name' => 'membership_online_receipt', 'type' => 'text'], + ['name' => 'membership_online_receipt', 'type' => 'html'], + ] ] ]; } diff --git a/xml/templates/message_templates/contribution_online_receipt_html.tpl b/xml/templates/message_templates/contribution_online_receipt_html.tpl index 5f3c65aa17..36b1c319b1 100644 --- a/xml/templates/message_templates/contribution_online_receipt_html.tpl +++ b/xml/templates/message_templates/contribution_online_receipt_html.tpl @@ -189,27 +189,30 @@ {/if} - {if $is_recur} - {if $contributeMode eq 'notify' or $contributeMode eq 'directIPN'} - + {if $is_recur} + - {ts 1=$cancelSubscriptionUrl}This is a recurring contribution. You can cancel future contributions by visiting this web page.{/ts} - - {if $updateSubscriptionBillingUrl} - - - - {ts 1=$updateSubscriptionBillingUrl}You can update billing details for this recurring contribution by visiting this web page.{/ts} - - {/if} - - - - {ts 1=$updateSubscriptionUrl}You can update recurring contribution amount or change the number of installments for this recurring contribution by visiting this web page.{/ts} + {ts}This is a recurring contribution.{/ts} + {if $cancelSubscriptionUrl} + {ts 1=$cancelSubscriptionUrl}You can cancel future contributions by visiting this web page.{/ts} + {/if} - + + {if $updateSubscriptionBillingUrl} + + + {ts 1=$updateSubscriptionBillingUrl}You can update billing details for this recurring contribution by visiting this web page.{/ts} + + {/if} - {/if} + {if $updateSubscriptionUrl} + + + {ts 1=$updateSubscriptionUrl}You can update recurring contribution amount or change the number of installments for this recurring contribution by visiting this web page.{/ts} + + + {/if} + {/if} {if $honor_block_is_active} diff --git a/xml/templates/message_templates/contribution_online_receipt_text.tpl b/xml/templates/message_templates/contribution_online_receipt_text.tpl index 7f016a6d2a..f485c953ca 100644 --- a/xml/templates/message_templates/contribution_online_receipt_text.tpl +++ b/xml/templates/message_templates/contribution_online_receipt_text.tpl @@ -65,21 +65,29 @@ {ts}Transaction #{/ts}: {$trxn_id} {/if} -{if $is_recur and ($contributeMode eq 'notify' or $contributeMode eq 'directIPN')} -{ts}This is a recurring contribution. You can cancel future contributions at:{/ts} +{if $is_recur} +{ts}This is a recurring contribution.{/ts} + +{if $cancelSubscriptionUrl} +{ts}You can cancel future contributions at:{/ts} {$cancelSubscriptionUrl} +{/if} + {if $updateSubscriptionBillingUrl} {ts}You can update billing details for this recurring contribution at:{/ts} {$updateSubscriptionBillingUrl} {/if} + +{if $updateSubscriptionUrl} {ts}You can update recurring contribution amount or change the number of installments for this recurring contribution at:{/ts} {$updateSubscriptionUrl} +{/if} {/if} {if $honor_block_is_active} diff --git a/xml/templates/message_templates/contribution_recurring_notify_html.tpl b/xml/templates/message_templates/contribution_recurring_notify_html.tpl index 3ed5eb713e..e2b0924835 100644 --- a/xml/templates/message_templates/contribution_recurring_notify_html.tpl +++ b/xml/templates/message_templates/contribution_recurring_notify_html.tpl @@ -37,11 +37,13 @@

{ts 1=$recur_frequency_interval 2=$recur_frequency_unit}This membership will be automatically renewed every %1 %2(s). {/ts}

+ {if $cancelSubscriptionUrl} - - {ts 1=$cancelSubscriptionUrl}This membership will be renewed automatically. You can cancel the auto-renewal option by visiting this web page.{/ts} - + + {ts 1=$cancelSubscriptionUrl}You can cancel the auto-renewal option by visiting this web page.{/ts} + + {/if} {if $updateSubscriptionBillingUrl} @@ -57,23 +59,27 @@

{ts}Start Date{/ts}: {$recur_start_date|crmDate}

+ {if $cancelSubscriptionUrl} - {ts 1=$cancelSubscriptionUrl} You can cancel the recurring contribution option by visiting this web page.{/ts} + {ts 1=$cancelSubscriptionUrl} You can cancel the recurring contribution option by visiting this web page.{/ts} + {/if} {if $updateSubscriptionBillingUrl} - {ts 1=$updateSubscriptionBillingUrl}You can update billing details for this recurring contribution by visiting this web page.{/ts} + {ts 1=$updateSubscriptionBillingUrl}You can update billing details for this recurring contribution by visiting this web page.{/ts} {/if} + {if $updateSubscriptionUrl} - {ts 1=$updateSubscriptionUrl}You can update recurring contribution amount or change the number of installments details for this recurring contribution by visiting this web page.{/ts} + {ts 1=$updateSubscriptionUrl}You can update recurring contribution amount or change the number of installments details for this recurring contribution by visiting this web page.{/ts} - + + {/if} {/if} {elseif $recur_txnType eq 'END'} diff --git a/xml/templates/message_templates/contribution_recurring_notify_text.tpl b/xml/templates/message_templates/contribution_recurring_notify_text.tpl index 46aa380a37..b0db9b5a31 100644 --- a/xml/templates/message_templates/contribution_recurring_notify_text.tpl +++ b/xml/templates/message_templates/contribution_recurring_notify_text.tpl @@ -7,7 +7,10 @@ {ts 1=$recur_frequency_interval 2=$recur_frequency_unit}This membership will be automatically renewed every %1 %2(s).{/ts} -{ts 1=$cancelSubscriptionUrl}This membership will be renewed automatically. You can cancel the auto-renewal option by visiting this web page.{/ts} +{if $cancelSubscriptionUrl} +{ts 1=$cancelSubscriptionUrl}You can cancel the auto-renewal option by visiting this web page.{/ts} + +{/if} {if $updateSubscriptionBillingUrl} {ts 1=$updateSubscriptionBillingUrl}You can update billing details for this automatically renewed membership by visiting this web page.{/ts} @@ -21,13 +24,20 @@ {ts}Start Date{/ts}: {$recur_start_date|crmDate} +{if $cancelSubscriptionUrl} {ts 1=$cancelSubscriptionUrl}You can cancel the recurring contribution option by visiting this web page.{/ts} +{/if} + {if $updateSubscriptionBillingUrl} {ts 1=$updateSubscriptionBillingUrl}You can update billing details for this recurring contribution by visiting this web page.{/ts} {/if} + +{if $updateSubscriptionUrl} {ts 1=$updateSubscriptionUrl}You can update recurring contribution amount or change the number of installments for this recurring contribution by visiting this web page.{/ts} + +{/if} {/if} {elseif $recur_txnType eq 'END'} diff --git a/xml/templates/message_templates/membership_online_receipt_html.tpl b/xml/templates/message_templates/membership_online_receipt_html.tpl index fbf9fdd460..254de657af 100644 --- a/xml/templates/message_templates/membership_online_receipt_html.tpl +++ b/xml/templates/message_templates/membership_online_receipt_html.tpl @@ -305,10 +305,12 @@ {/if} {if $is_recur} - {if $contributeMode eq 'notify' or $contributeMode eq 'directIPN'} - {ts 1=$cancelSubscriptionUrl}This membership will be renewed automatically. You can cancel the auto-renewal option by visiting this web page.{/ts} + {ts}This membership will be renewed automatically.{/ts} + {if $cancelSubscriptionUrl} + {ts 1=$cancelSubscriptionUrl}You can cancel the auto-renewal option by visiting this web page.{/ts} + {/if} {if $updateSubscriptionBillingUrl} @@ -318,7 +320,6 @@ {/if} - {/if} {/if} {if $honor_block_is_active} diff --git a/xml/templates/message_templates/membership_online_receipt_text.tpl b/xml/templates/message_templates/membership_online_receipt_text.tpl index aa61b62a6c..341a8ac7c9 100644 --- a/xml/templates/message_templates/membership_online_receipt_text.tpl +++ b/xml/templates/message_templates/membership_online_receipt_text.tpl @@ -113,14 +113,18 @@ {/if} {if $is_recur} -{if $contributeMode eq 'notify' or $contributeMode eq 'directIPN'} -{ts 1=$cancelSubscriptionUrl}This membership will be renewed automatically. You can cancel the auto-renewal option by visiting this web page: %1.{/ts} +{ts}This membership will be renewed automatically.{/ts} +{if $cancelSubscriptionUrl} + +{ts 1=$cancelSubscriptionUrl}You can cancel the auto-renewal option by visiting this web page: %1.{/ts} + +{/if} + {if $updateSubscriptionBillingUrl} {ts 1=$updateSubscriptionBillingUrl}You can update billing details for this automatically renewed membership by visiting this web page.{/ts} {/if} {/if} -{/if} {if $honor_block_is_active } =========================================================== -- 2.25.1