From 794d4fc06bd35653bbca108095055f9469bd02cf Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 13 Apr 2017 21:43:03 +1200 Subject: [PATCH] CRM-20264, Added Card type and Pan Truncation form fields on Payment form I deliberately excluded card_type because I think we need to review the appropriateness of the field first. My issue is that the wrangling wound up really wierd & it was apparent the issue is that card_type is 'Visa' whereas card_type_id is 1 - we should either rename the field or store the word. --- CRM/Contribute/BAO/Contribution.php | 2 + CRM/Contribute/Form/Contribution.php | 49 ++++++++++++------- CRM/Core/Payment.php | 20 ++++++++ CRM/Core/Payment/Manual.php | 22 ++++++++- .../CRM/Contribute/Form/AdditionalPayment.tpl | 3 ++ .../CRM/Contribute/Form/Contribution.tpl | 7 --- templates/CRM/common/paymentBlock.tpl | 4 ++ 7 files changed, 80 insertions(+), 27 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 16169a4fa8..23b2f9d317 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3381,6 +3381,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac // records finanical trxn and entity financial trxn // also make it available as return value self::recordAlwaysAccountsReceivable($trxnParams, $params); + $trxnParams['pan_truncation'] = CRM_Utils_Array::value('pan_truncation', $params); $return = $financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams); $params['entity_id'] = $financialTxn->id; if (empty($params['partial_payment_total']) && empty($params['partial_amount_pay'])) { @@ -3803,6 +3804,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $params['partial_payment_total'] = $contributionDAO->total_amount; $params['partial_amount_pay'] = $trxnsData['total_amount']; $trxnsData['net_amount'] = !empty($trxnsData['net_amount']) ? $trxnsData['net_amount'] : $trxnsData['total_amount']; + $params['pan_truncation'] = CRM_Utils_Array::value('pan_truncation', $trxnsData); // record the entry $financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData); diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 95c8e4cc91..e693a3797d 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -384,7 +384,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } if (empty($defaults['payment_instrument_id'])) { - $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); + $defaults['payment_instrument_id'] = $this->getDefaultPaymentInstrumentId(); } if (!empty($defaults['is_test'])) { @@ -561,26 +561,24 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $paneNames[ts('Premium Information')] = 'Premium'; } - if ($this->_mode) { - if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE) == TRUE) { - if (!empty($this->_recurPaymentProcessors)) { - $buildRecurBlock = TRUE; - if ($this->_ppID) { - // ppID denotes a pledge payment. - foreach ($this->_paymentProcessors as $processor) { - if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('recurContributionsForPledges')) { - $buildRecurBlock = TRUE; - break; - } - $buildRecurBlock = FALSE; + if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE, $this->getDefaultPaymentInstrumentId()) == TRUE) { + if (!empty($this->_recurPaymentProcessors)) { + $buildRecurBlock = TRUE; + if ($this->_ppID) { + // ppID denotes a pledge payment. + foreach ($this->_paymentProcessors as $processor) { + if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('recurContributionsForPledges')) { + $buildRecurBlock = TRUE; + break; } + $buildRecurBlock = FALSE; } - if ($buildRecurBlock) { - CRM_Contribute_Form_Contribution_Main::buildRecur($this); - $this->setDefaults(array('is_recur' => 0)); - $this->assign('buildRecurBlock', TRUE); - $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;"); - } + } + if ($buildRecurBlock) { + CRM_Contribute_Form_Contribution_Main::buildRecur($this); + $this->setDefaults(array('is_recur' => 0)); + $this->assign('buildRecurBlock', TRUE); + $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;"); } } } @@ -1901,4 +1899,17 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return 0; } + /** + * Get the default payment instrument id. + * + * @return int + */ + protected function getDefaultPaymentInstrumentId() { + $paymentInstrumentID = CRM_Utils_Request::retrieve('payment_instrument_id', 'Integer'); + if ($paymentInstrumentID) { + return $paymentInstrumentID; + } + return key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); + } + } diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 3138d1f95b..c88aad8f56 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -774,6 +774,26 @@ abstract class CRM_Core_Payment { 'is_required' => TRUE, ), + 'check_number' => array( + 'htmlType' => 'text', + 'name' => 'check_number', + 'title' => ts('Check Number'), + 'is_required' => FALSE, + 'cc_field' => TRUE, + 'attributes' => NULL, + ), + 'pan_truncation' => array( + 'htmlType' => 'text', + 'name' => 'pan_truncation', + 'title' => ts('Last 4 digits of the card'), + 'is_required' => FALSE, + 'cc_field' => TRUE, + 'attributes' => array( + 'size' => 4, + 'maxlength' => 4, + 'autocomplete' => 'off', + ), + ), ); } diff --git a/CRM/Core/Payment/Manual.php b/CRM/Core/Payment/Manual.php index 55bae03df2..f43fca15f1 100644 --- a/CRM/Core/Payment/Manual.php +++ b/CRM/Core/Payment/Manual.php @@ -84,8 +84,28 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment { * @return array */ public function getPaymentFormFields() { + if (!$this->isBackOffice()) { + return array(); + } + + $paymentInstrument = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID()); + if ($paymentInstrument === 'Credit Card') { + // @todo - return credit_card_type field once the underlying code works to extract this field. + // Note the problem is this should be stored in civicrm_financial_trxn.credit_card_type. + // However there is an ambiguity as that field is an integer & should hence be called + // credit_card_type_id, or it should store 'visa' It probably makes sense to fix that before going much + // further as the code I've seen makes it clear that it will require work arounds. + return array('pan_truncation'); + } + elseif ($paymentInstrument === 'Check') { + // Really we should render check_number here, but we need to review how we edit + // check_numebr since we expose it as editable on the contribution form, + // even though it should only be editable from a transation specific form. + return array(); + } return array(); } + /** * Process payment. * @@ -161,7 +181,7 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment { * @return string */ public function getPaymentTypeLabel() { - return ''; + return 'Payment'; } /** diff --git a/templates/CRM/Contribute/Form/AdditionalPayment.tpl b/templates/CRM/Contribute/Form/AdditionalPayment.tpl index 84ecc66ae1..9a18a9c9e1 100644 --- a/templates/CRM/Contribute/Form/AdditionalPayment.tpl +++ b/templates/CRM/Contribute/Form/AdditionalPayment.tpl @@ -99,7 +99,9 @@ +
+ {if !$contributionMode}
{if $paymentType EQ 'refund'}{ts}Refund Details{/ts}{else}{ts}Payment Details{/ts}{/if}
@@ -152,6 +154,7 @@ {ts}Net value of the payment (Total Amount minus Fee).{/ts}
+ {/if} {include file='CRM/Core/BillingBlockWrapper.tpl'} diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 1b4a2f35ca..3191ccf6e9 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -235,11 +235,6 @@ {if !$contributionMode} -
-
- {ts}Payment Details{/ts} -
-
@@ -287,8 +282,6 @@
{$form.receive_date.label}{$form.from_email_address.html}
-
-
{/if} {include file='CRM/Core/BillingBlockWrapper.tpl'} diff --git a/templates/CRM/common/paymentBlock.tpl b/templates/CRM/common/paymentBlock.tpl index c2e74f96cb..acbafb5ca3 100644 --- a/templates/CRM/common/paymentBlock.tpl +++ b/templates/CRM/common/paymentBlock.tpl @@ -133,6 +133,10 @@ buildPaymentBlock($(this).val()); }); + $('#payment_instrument_id').on('change.paymentBlock', function() { + buildPaymentBlock(0); + }); + $('#billing-payment-block').on('crmLoad', function() { $('.crm-submit-buttons input').prop('disabled', false); }) -- 2.25.1