From c42f1a190fa92b8f341bbb206d84d439f0649b1f Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 18 Jun 2018 22:19:39 +1200 Subject: [PATCH] Add support for hidden fields in general and 'token' specifically on payment form. It is common enough for payment processors to store a hidden token on the form that we should specifically support it. In general the processor can add other fields of type hidden and they should show up. --- CRM/Contribute/Form/ContributionBase.php | 6 +-- CRM/Core/Payment.php | 17 ++++---- CRM/Core/Payment/Form.php | 50 ++++++++++++++++-------- templates/CRM/Core/BillingBlock.tpl | 2 +- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 352395daf5..561adfe00d 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -614,11 +614,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $this->assign($paymentField, $this->_params[$paymentField]); } } - $paymentFieldsetLabel = ts('%1 Information', array($paymentProcessorObject->getPaymentTypeLabel())); - if (empty($paymentFields)) { - $paymentFieldsetLabel = ''; - } - $this->assign('paymentFieldsetLabel', $paymentFieldsetLabel); + $this->assign('paymentFieldsetLabel', CRM_Core_Payment_Form::getPaymentLabel($paymentProcessorObject)); $this->assign('paymentFields', $paymentFields); } diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 8626cd790d..832a444da5 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -682,7 +682,6 @@ abstract class CRM_Core_Payment { 'htmlType' => 'text', 'name' => 'credit_card_number', 'title' => ts('Card Number'), - 'cc_field' => TRUE, 'attributes' => array( 'size' => 20, 'maxlength' => 20, @@ -695,7 +694,6 @@ abstract class CRM_Core_Payment { 'htmlType' => 'text', 'name' => 'cvv2', 'title' => ts('Security Code'), - 'cc_field' => TRUE, 'attributes' => array( 'size' => 5, 'maxlength' => 10, @@ -714,7 +712,6 @@ abstract class CRM_Core_Payment { 'htmlType' => 'date', 'name' => 'credit_card_exp_date', 'title' => ts('Expiration Date'), - 'cc_field' => TRUE, 'attributes' => CRM_Core_SelectValues::date('creditCard'), 'is_required' => TRUE, 'rules' => array( @@ -729,7 +726,6 @@ abstract class CRM_Core_Payment { 'htmlType' => 'select', 'name' => 'credit_card_type', 'title' => ts('Card Type'), - 'cc_field' => TRUE, 'attributes' => $creditCardType, 'is_required' => FALSE, ), @@ -737,7 +733,6 @@ abstract class CRM_Core_Payment { 'htmlType' => 'text', 'name' => 'account_holder', 'title' => ts('Account Holder'), - 'cc_field' => TRUE, 'attributes' => array( 'size' => 20, 'maxlength' => 34, @@ -750,7 +745,6 @@ abstract class CRM_Core_Payment { 'htmlType' => 'text', 'name' => 'bank_account_number', 'title' => ts('Bank Account Number'), - 'cc_field' => TRUE, 'attributes' => array( 'size' => 20, 'maxlength' => 34, @@ -770,7 +764,6 @@ abstract class CRM_Core_Payment { 'htmlType' => 'text', 'name' => 'bank_identification_number', 'title' => ts('Bank Identification Number'), - 'cc_field' => TRUE, 'attributes' => array( 'size' => 20, 'maxlength' => 11, @@ -789,7 +782,6 @@ abstract class CRM_Core_Payment { 'htmlType' => 'text', 'name' => 'bank_name', 'title' => ts('Bank Name'), - 'cc_field' => TRUE, 'attributes' => array( 'size' => 20, 'maxlength' => 64, @@ -803,7 +795,6 @@ abstract class CRM_Core_Payment { 'name' => 'check_number', 'title' => ts('Check Number'), 'is_required' => FALSE, - 'cc_field' => TRUE, 'attributes' => NULL, ), 'pan_truncation' => array( @@ -811,7 +802,6 @@ abstract class CRM_Core_Payment { 'name' => 'pan_truncation', 'title' => ts('Last 4 digits of the card'), 'is_required' => FALSE, - 'cc_field' => TRUE, 'attributes' => array( 'size' => 4, 'maxlength' => 4, @@ -826,6 +816,13 @@ abstract class CRM_Core_Payment { ), ), ), + 'payment_token' => array( + 'htmlType' => 'hidden', + 'name' => 'payment_token', + 'title' => ts('Authorization token'), + 'is_required' => FALSE, + 'attributes' => ['size' => 10, 'autocomplete' => 'off'], + ), ); } diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 05de148e82..60e946d7dd 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -68,8 +68,7 @@ class CRM_Core_Payment_Form { $processor['object']->setPaymentInstrumentID($paymentInstrumentID); $paymentTypeName = self::getPaymentTypeName($processor); $form->assign('paymentTypeName', $paymentTypeName); - $paymentTypeLabel = self::getPaymentTypeLabel($processor); - $form->assign('paymentTypeLabel', $paymentTypeLabel); + $form->assign('paymentTypeLabel', self::getPaymentLabel($processor['object'])); $form->assign('isBackOffice', $isBackOffice); $form->_paymentFields = $form->billingFieldSets[$paymentTypeName]['fields'] = self::getPaymentFieldMetadata($processor); $form->_paymentFields = array_merge($form->_paymentFields, self::getBillingAddressMetadata($processor, $form->_bltID)); @@ -116,24 +115,22 @@ class CRM_Core_Payment_Form { protected static function addCommonFields(&$form, $paymentFields) { $requiredPaymentFields = array(); foreach ($paymentFields as $name => $field) { - // @todo - remove the cc_field check - no longer useful. - if (!empty($field['cc_field'])) { - if ($field['htmlType'] == 'chainSelect') { - $form->addChainSelect($field['name'], array('required' => FALSE)); - } - else { - $form->add($field['htmlType'], - $field['name'], - $field['title'], - $field['attributes'], - FALSE - ); - } + if ($field['htmlType'] == 'chainSelect') { + $form->addChainSelect($field['name'], array('required' => FALSE)); + } + else { + $form->add($field['htmlType'], + $field['name'], + $field['title'], + $field['attributes'], + FALSE + ); } // This will cause the fields to be marked as required - but it is up to the payment processor to // validate it. $requiredPaymentFields[$field['name']] = $field['is_required']; } + $form->assign('requiredPaymentFields', $requiredPaymentFields); } @@ -207,7 +204,7 @@ class CRM_Core_Payment_Form { * @return string */ public static function getPaymentTypeLabel($paymentProcessor) { - return ts(($paymentProcessor['object']->getPaymentTypeLabel()) . ' Information'); + return ts('%1 Information', [$paymentProcessor->getPaymentTypeLabel()]); } /** @@ -426,4 +423,25 @@ class CRM_Core_Payment_Form { return CRM_Utils_Array::value('Y', $src['credit_card_exp_date']); } + /** + * Get the label for the processor. + * + * We do not use a label if there are no enterable fields. + * + * @param \CRM_Core_Payment $processor + * + * @return string + */ + public static function getPaymentLabel($processor) { + $isVisible = FALSE; + $paymentTypeLabel = self::getPaymentTypeLabel($processor); + foreach (self::getPaymentFieldMetadata(['object' => $processor]) as $paymentField) { + if ($paymentField['htmlType'] !== 'hidden') { + $isVisible = TRUE; + } + } + return $isVisible ? $paymentTypeLabel : ''; + + } + } diff --git a/templates/CRM/Core/BillingBlock.tpl b/templates/CRM/Core/BillingBlock.tpl index 1e7c56782e..02f2a4377c 100644 --- a/templates/CRM/Core/BillingBlock.tpl +++ b/templates/CRM/Core/BillingBlock.tpl @@ -39,7 +39,7 @@
{$form.$paymentField.label} {if $requiredPaymentFields.$name}*{/if}
-
{$form.$paymentField.html} +
{if $form.$paymentField.html}{$form.$paymentField.html}{else}{/if} {if $paymentField == 'cvv2'}{* @todo move to form assignment*} {/if} -- 2.25.1