From 0dc4ef42bbbe96bbbe5a810c9396772ec50ab011 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 20 Apr 2017 09:46:08 +1200 Subject: [PATCH] CRM-20264 make pan_truncation save on event form. note that this PR should be testable & mergeable as making 'no change' without the changes to Core_Payment_Manual as it is primarily code consolidation --- CRM/Contribute/Form/AbstractEditPayment.php | 14 ++++++++++ CRM/Contribute/Form/AdditionalPayment.php | 9 ++++--- CRM/Contribute/Form/Contribution.php | 14 ---------- CRM/Core/Payment/Manual.php | 2 +- CRM/Event/Form/EventFees.php | 22 +++++++++++++--- CRM/Event/Form/Participant.php | 26 +++++++++++-------- CRM/Member/Form.php | 5 +--- templates/CRM/Event/Form/EventFees.tpl | 17 ++---------- .../CRM/Member/Form/MembershipTest.php | 5 +++- 9 files changed, 61 insertions(+), 53 deletions(-) diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index fcf663822e..ffab96701a 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -221,6 +221,7 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { CRM_Core_Resources::singleton()->addVars('coreForm', array('contact_id' => (int) $this->_contactID)); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); $this->_mode = empty($this->_mode) ? CRM_Utils_Request::retrieve('mode', 'String', $this) : $this->_mode; + $this->assignPaymentRelatedVariables(); } /** @@ -645,4 +646,17 @@ WHERE contribution_id = {$id} return array_merge($defaults, $billingDefaults); } + /** + * 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/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index 0fc8076afb..5f41e672d1 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -53,6 +53,11 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract protected $_refund = NULL; + /** + * @deprecated - use parent $this->contactID + * + * @var int + */ protected $_contactId = NULL; protected $_contributorDisplayName = NULL; @@ -77,10 +82,10 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract parent::preProcess(); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); + // @todo don't set this - rely on parent $this->contactID $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $this->_component = CRM_Utils_Request::retrieve('component', 'String', $this, TRUE); $this->_view = CRM_Utils_Request::retrieve('view', 'String', $this, FALSE); - $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); $this->assign('component', $this->_component); $this->assign('id', $this->_id); $this->assign('suppressPaymentFormButtons', $this->isBeingCalledFromSelectorContext()); @@ -137,8 +142,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId); - $this->assignPaymentRelatedVariables(); - $this->assign('contributionMode', $this->_mode); $this->assign('contactId', $this->_contactId); $this->assign('paymentType', $this->_paymentType); diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index e693a3797d..7034a131a3 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -253,7 +253,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->assign('showCheckNumber', TRUE); $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); - $this->assignPaymentRelatedVariables(); if (in_array('CiviPledge', CRM_Core_Config::singleton()->enableComponents) && !$this->_formType) { $this->preProcessPledge(); @@ -1899,17 +1898,4 @@ 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/Manual.php b/CRM/Core/Payment/Manual.php index f43fca15f1..13657435c3 100644 --- a/CRM/Core/Payment/Manual.php +++ b/CRM/Core/Payment/Manual.php @@ -181,7 +181,7 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment { * @return string */ public function getPaymentTypeLabel() { - return 'Payment'; + return CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID()); } /** diff --git a/CRM/Event/Form/EventFees.php b/CRM/Event/Form/EventFees.php index 036165c28a..ba7aa9ccd8 100644 --- a/CRM/Event/Form/EventFees.php +++ b/CRM/Event/Form/EventFees.php @@ -410,10 +410,9 @@ SELECT id, html_type CRM_Core_Session::setStatus(ts('You do not have all the permissions needed for this page.'), 'Permission Denied', 'error'); return FALSE; } - if ($form->_mode) { - CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE, TRUE); - } - elseif (!$form->_mode) { + + CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE, TRUE, self::getDefaultPaymentInstrumentId()); + if (!$form->_mode) { $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL, array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);") ); @@ -512,4 +511,19 @@ SELECT id, html_type $form->assign('hasPayment', $form->_paymentId); } + /** + * Get the default payment instrument id. + * + * @todo resolve relationship between this form & abstractEdit -which should be it's parent. + * + * @return int + */ + protected static 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/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 06216727c8..07160eed32 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -85,6 +85,10 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment protected $_noteId = NULL; /** + * @deprecated + * + * Use parent $this->contactID + * * The id of the contact associated with this participation. * * @var int @@ -204,20 +208,19 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * @return void */ public function preProcess() { + parent::preProcess(); $this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET); $this->assign('showFeeBlock', FALSE); $this->assign('feeBlockPaid', FALSE); - $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); - $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); + // @todo eliminate this duplication. + $this->_contactId = $this->_contactID; $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); - if ($this->_contactId) { - $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); - $this->assign('displayName', $displayName); - $this->setPageTitle(ts('Event Registration for %1', array(1 => $displayName))); + if ($this->_contactID) { + $this->setPageTitle(ts('Event Registration for %1', array(1 => $this->userDisplayName))); } else { $this->setPageTitle(ts('Event Registration')); @@ -271,7 +274,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment if ($this->_mode) { $this->assign('participantMode', $this->_mode); - $this->assignPaymentRelatedVariables(); } if ($this->_showFeeBlock) { @@ -935,7 +937,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $participantStatus = CRM_Event_PseudoConstant::participantStatus(); // set the contact, when contact is selected if (!empty($params['contact_id'])) { - $this->_contactId = $params['contact_id']; + $this->_contactID = $this->_contactId = $params['contact_id']; } if ($this->_priceSetId && $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { $this->_quickConfig = $isQuickConfig; @@ -1340,20 +1342,22 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $contributionParams['currency'] = $config->defaultCurrency; $contributionParams['non_deductible_amount'] = 'null'; $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array::value('receive_date', $params) : 'null'; + $contributionParams['contact_id'] = $this->_contactID; + // @todo change receive_date to datepicker field. Strip out all wrangling. + $contributionParams['receive_date'] = $params['receive_date']; $recordContribution = array( - 'contact_id', 'financial_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', - 'receive_date', 'check_number', 'campaign_id', + 'pan_truncation', ); foreach ($recordContribution as $f) { - $contributionParams[$f] = CRM_Utils_Array::value($f, $params); + $contributionParams[$f] = CRM_Utils_Array::value($f, $this->_params); if ($f == 'trxn_id') { $this->assign('trxn_id', $contributionParams[$f]); } diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 178b4420f0..7c4196cf7f 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -167,9 +167,8 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { $this->_processors, TRUE, array('onChange' => "buildAutoRenew( null, this.value, '{$this->_mode}');") ); - CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE); } - + CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE, $this->getDefaultPaymentInstrumentId()); // Build the form for auto renew. This is displayed when in credit card mode or update mode. // The reason for showing it in update mode is not that clear. if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) { @@ -303,8 +302,6 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { } } - $this->assignPaymentRelatedVariables(); - if ($this->_id) { $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id'); $this->_membershipIDs[] = $this->_id; diff --git a/templates/CRM/Event/Form/EventFees.tpl b/templates/CRM/Event/Form/EventFees.tpl index 002f24e41b..bdbad615eb 100644 --- a/templates/CRM/Event/Form/EventFees.tpl +++ b/templates/CRM/Event/Form/EventFees.tpl @@ -97,26 +97,13 @@ - - {* Record contribution field only present if we are NOT in submit credit card mode (! participantMode). *} - {include file="CRM/common/showHideByFieldValue.tpl" - trigger_field_id ="record_contribution" - trigger_value ="" - target_element_id ="payment_information" - target_element_type ="table-row" - field_type ="radio" - invert = 0 - } {/if} {/if} -{* credit card block when it is live or test mode*} -{if $participantMode and $paid} -
- {include file='CRM/Core/BillingBlockWrapper.tpl'} -{/if} +{include file='CRM/Core/BillingBlockWrapper.tpl'} + {if ($email OR $batchEmail) and $outBound_option != 2}
{if $paid}{ts}Registration Confirmation and Receipt{/ts}{else}{ts}Registration Confirmation{/ts}{/if} diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index ece15f506f..ec6e7c8270 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -431,6 +431,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { */ public function testSubmit() { $form = $this->getForm(); + $form->preProcess(); $this->mut = new CiviMailUtils($this, TRUE); $form->_mode = 'test'; $this->createLoggedInUser(); @@ -538,6 +539,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { */ public function testFormStatusUpdate() { $form = $this->getForm(); + $form->preProcess(); $this->_individualId = $this->createLoggedInUser(); $memParams = array( 'contact_id' => $this->_individualId, @@ -580,6 +582,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { */ public function testSubmitPayLaterWithBilling() { $form = $this->getForm(NULL); + $form->preProcess(); $this->createLoggedInUser(); $params = array( 'cid' => $this->_individualId, @@ -706,6 +709,7 @@ Expires: ', */ public function testFormWithFailedContribution() { $form = $this->getForm(); + $form->preProcess(); $this->createLoggedInUser(); $params = $this->getBaseSubmitParams(); unset($params['price_set_id']); @@ -739,7 +743,6 @@ Expires: ', $form = new CRM_Member_Form_Membership(); $_SERVER['REQUEST_METHOD'] = 'GET'; $form->controller = new CRM_Core_Controller(); - $form->_bltID = 5; return $form; } -- 2.25.1