From 7931a722dd06cadc74a0b4142e53ec80cb25fbdf Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 24 Mar 2023 12:33:14 +1300 Subject: [PATCH] dev/core#4189 Fix indiscriminate display of direct debit agreement --- CRM/Contribute/Form/ContributionBase.php | 6 +++--- CRM/Core/Payment.php | 16 ++++++++++++++++ .../CRM/Contribute/Form/Contribution/Confirm.tpl | 10 +++++----- .../Contribute/Form/Contribution/ThankYou.tpl | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 902e73fdea..6b3b3b99f4 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -782,10 +782,10 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { // The concept of contributeMode is deprecated. // The payment processor object can provide info about the fields it shows. - if ($isMonetary && is_a($this->_paymentProcessor['object'], 'CRM_Core_Payment')) { - /** @var \CRM_Core_Payment $paymentProcessorObject */ + if ($isMonetary && $this->_paymentProcessor['object'] instanceof \CRM_Core_Payment) { $paymentProcessorObject = $this->_paymentProcessor['object']; - + $this->assign('paymentAgreementTitle', $paymentProcessorObject->getText('agreementTitle', [])); + $this->assign('paymentAgreementText', $paymentProcessorObject->getText('agreementText', [])); $paymentFields = $paymentProcessorObject->getPaymentFormFields(); foreach ($paymentFields as $index => $paymentField) { if (!isset($this->_params[$paymentField])) { diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 84e47800bc..10afed4e59 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -619,6 +619,22 @@ abstract class CRM_Core_Payment { } return ''; + case 'agreementTitle': + if ($this->getPaymentTypeName() !== 'direct_debit' || $this->_paymentProcessor['billing_mode'] != 1) { + return ''; + } + // @todo - 'encourage' processors to override... + // CRM_Core_Error::deprecatedWarning('Payment processors should override getText for agreement text'); + return ts('Agreement'); + + case 'agreementText': + if ($this->getPaymentTypeName() !== 'direct_debit' || $this->_paymentProcessor['billing_mode'] != 1) { + return ''; + } + // @todo - 'encourage' processors to override... + // CRM_Core_Error::deprecatedWarning('Payment processors should override getText for agreement text'); + return ts('Your account data will be used to charge your bank account via direct debit. While submitting this form you agree to the charging of your bank account via direct debit.'); + } CRM_Core_Error::deprecatedFunctionWarning('Calls to getText must use a supported method'); return ''; diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index 9ef4ad93d0..bff0c22270 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -243,25 +243,25 @@ {$paymentFieldsetLabel} {/if} - {if in_array('bank_account_number', $form)} + {if in_array('bank_account_number', $form) && $bank_account_number}
{ts}Account Holder{/ts}: {$account_holder}
{ts}Bank Account Number{/ts}: {$bank_account_number}
{ts}Bank Identification Number{/ts}: {$bank_identification_number}
{ts}Bank Name{/ts}: {$bank_name}
- {if $contributeMode eq 'direct'} + {if $paymentAgreementText}
- {ts}Agreement{/ts} + {$paymentAgreementTitle}
- {ts}Your account data will be used to charge your bank account via direct debit. While submitting this form you agree to the charging of your bank account via direct debit.{/ts} + {$paymentAgreementText}
{/if} {/if} - {if in_array('credit_card_number', $form)} + {if in_array('credit_card_number', $form) && $credit_card_number}
{$credit_card_type}
{$credit_card_number}
diff --git a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl index f119e135ca..697baf22d8 100644 --- a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl +++ b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl @@ -281,7 +281,7 @@ {/if} {/if} - {if $contributeMode eq 'direct' and ! $is_pay_later and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 )} + {if in_array('credit_card_number', $form) || in_array('bank_account_number', $form) && ($amount GT 0 OR $minimum_fee GT 0)} {crmRegion name="contribution-thankyou-billing-block"}
{if $paymentFieldsetLabel} @@ -289,7 +289,7 @@ {$paymentFieldsetLabel}
{/if} - {if $paymentProcessor.payment_type == 2} + {if in_array('bank_account_number', $form) && $bank_account_number}
{ts}Account Holder{/ts}: {$account_holder}
{ts}Bank Identification Number{/ts}: {$bank_identification_number}
-- 2.25.1