From 9f7f8a503cf2a8985ce6d0e96a3e25ed922758f8 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 2 Sep 2017 11:49:00 +1200 Subject: [PATCH] CRM-21134 fix enotices in payment processor code assignment. This is generally a code tidy up to push out the principles we have been implementing (ie. the idea that the processors define their fields. The code can cause e-notices in extensions as is because it is prescriptive about fields. I removed the ANDing in the tpl because actually we are not looking to match numbers like 2 2 is the number we have hard-coded for direct debits (we should be using an option group but that is another story --- CRM/Contribute/Form/ContributionBase.php | 43 ++++++++++++------- CRM/Core/Payment.php | 11 ++++- .../Contribute/Form/Contribution/Confirm.tpl | 14 +++--- .../Contribute/Form/Contribution/ThankYou.tpl | 16 +++---- 4 files changed, 51 insertions(+), 33 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index cffecc784e..fd2b20e11b 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -580,23 +580,36 @@ 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 ($this->_contributeMode == 'direct' && $assignCCInfo) { - if ($this->_paymentProcessor && - $this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT - ) { - $this->assign('account_holder', $this->_params['account_holder']); - $this->assign('bank_identification_number', $this->_params['bank_identification_number']); - $this->assign('bank_name', $this->_params['bank_name']); - $this->assign('bank_account_number', $this->_params['bank_account_number']); + if ($assignCCInfo) { + /** @var $paymentProcessorObject \CRM_Core_Payment */ + $paymentProcessorObject = $this->_paymentProcessor['object']; + $paymentFields = $paymentProcessorObject->getPaymentFormFields(); + foreach ($paymentFields as $index => $paymentField) { + if (!isset($this->_params[$paymentField])) { + unset($paymentFields[$index]); + continue; + } + if ($paymentField === 'credit_card_exp_date') { + $date = CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $this->_params)); + $date = CRM_Utils_Date::mysqlToIso($date); + $this->assign('credit_card_exp_date', $date); + } + elseif ($paymentField === 'credit_card_number') { + $this->assign('credit_card_number', + CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $this->_params)) + ); + } + else { + $this->assign($paymentField, $this->_params[$paymentField]); + } } - else { - $date = CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $this->_params)); - $date = CRM_Utils_Date::mysqlToIso($date); - $this->assign('credit_card_exp_date', $date); - $this->assign('credit_card_number', - CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $this->_params)) - ); + $paymentFieldsetLabel = ts('%1 Information', array($paymentProcessorObject->getPaymentTypeLabel())); + if (empty($paymentFields)) { + $paymentFieldsetLabel = ''; } + $this->assign('paymentFieldsetLabel', $paymentFieldsetLabel); + $this->assign('paymentFields', $paymentFields); + } $this->assign('email', diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 0bfe0c2d2e..822b6bcc88 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -533,8 +533,17 @@ abstract class CRM_Core_Payment { /** * Get array of fields that should be displayed on the payment form. - * @todo make payment type an option value & use it in the function name - currently on debit & credit card work + * + * Common results are + * array('credit_card_type', 'credit_card_number', 'cvv2', 'credit_card_exp_date') + * or + * array('account_holder', 'bank_account_number', 'bank_identification_number', 'bank_name') + * or + * array() + * * @return array + * Array of payment fields appropriate to the payment processor. + * * @throws CiviCRM_API3_Exception */ public function getPaymentFormFields() { diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index 571e708849..b0eb8c4b3e 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -223,14 +223,12 @@ {crmRegion name="contribution-confirm-billing-block"} {if ($credit_card_number or $bank_account_number)}
-
- {if $paymentProcessor.payment_type & 2} - {ts}Direct Debit Information{/ts} - {else} - {ts}Credit Card Information{/ts} + {if $paymentFieldsetLabel} +
+ {$paymentFieldsetLabel} +
{/if} -
- {if $paymentProcessor.payment_type & 2} + {if $paymentProcessor.payment_type == 2}
{ts}Account Holder{/ts}: {$account_holder}
{ts}Bank Account Number{/ts}: {$bank_account_number}
@@ -251,7 +249,7 @@
{$credit_card_type}
{$credit_card_number}
-
{ts}Expires{/ts}: {$credit_card_exp_date|truncate:7:''|crmDate}
+
{if $credit_card_exp_date}{ts}Expires{/ts}: {$credit_card_exp_date|truncate:7:''|crmDate}{/if}
{/if} diff --git a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl index a79b990c35..844225af85 100644 --- a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl +++ b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl @@ -274,14 +274,12 @@ {if $contributeMode eq 'direct' and ! $is_pay_later and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 )} {crmRegion name="contribution-thankyou-billing-block"}
-
- {if $paymentProcessor.payment_type & 2} - {ts}Direct Debit Information{/ts} - {else} - {ts}Credit Card Information{/ts} - {/if} -
- {if $paymentProcessor.payment_type & 2} + {if $paymentFieldsetLabel} +
+ {$paymentFieldsetLabel} +
+ {/if} + {if $paymentProcessor.payment_type == 2}
{ts}Account Holder{/ts}: {$account_holder}
{ts}Bank Identification Number{/ts}: {$bank_identification_number}
@@ -292,7 +290,7 @@
{$credit_card_type}
{$credit_card_number}
-
{ts}Expires{/ts}: {$credit_card_exp_date|truncate:7:''|crmDate}
+
{if $credit_card_exp_date}{ts}Expires{/ts}: {$credit_card_exp_date|truncate:7:''|crmDate}{/if}
{/if} -- 2.25.1