X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FForm%2FContributionBase.php;h=971479e6332d2b6c896d7208afd96a88fa06ee89;hb=144dacf19067161923f93ddd7178bb938b04c969;hp=821c71d2a9b35e60132a4698e2ee563e7d5f257d;hpb=8282c3dc7b991acb4665546aae5c18e1adaecf95;p=civicrm-core.git diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 821c71d2a9..971479e633 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -92,14 +92,14 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { * * @var array */ - public $_params = array(); + public $_params = []; /** * The fields involved in this contribution page * * @var array */ - public $_fields = array(); + public $_fields = []; /** * The billing location id for this contribution page. @@ -181,9 +181,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { public $_useForMember; /** + * @var bool * @deprecated - * - * @var */ public $_isBillingAddressRequiredForPayLater; @@ -308,8 +307,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { if (!$this->_values) { // get all the values from the dao object - $this->_values = array(); - $this->_fields = array(); + $this->_values = []; + $this->_fields = []; CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values); if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() @@ -362,11 +361,11 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { CRM_Price_BAO_PriceSet::initSet($this, $this->_id, 'civicrm_contribution_page'); // this avoids getting E_NOTICE errors in php - $setNullFields = array( + $setNullFields = [ 'amount_block_is_active', 'is_allow_other_amount', 'footer_text', - ); + ]; foreach ($setNullFields as $f) { if (!isset($this->_values[$f])) { $this->_values[$f] = NULL; @@ -472,16 +471,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values) ); - // assigning title to template in case someone wants to use it, also setting CMS page title - if ($this->_pcpId) { - $this->assign('title', $this->_pcpInfo['title']); - CRM_Utils_System::setTitle($this->_pcpInfo['title']); - } - else { - $this->assign('title', $this->_values['title']); - CRM_Utils_System::setTitle($this->_values['title']); - } - $this->_defaults = array(); + $this->setTitle(($this->_pcpId ? $this->_pcpInfo['title'] : $this->_values['title'])); + $this->_defaults = []; $this->_amount = $this->get('amount'); // Assigning this to the template means it will be passed through to the payment form. @@ -529,23 +520,23 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $this->set('name', $this->assignBillingName($this->_params)); $this->assign('paymentProcessor', $this->_paymentProcessor); - $vars = array( + $vars = [ 'amount', 'currencyID', 'credit_card_type', 'trxn_id', 'amount_level', - ); + ]; $config = CRM_Core_Config::singleton(); if (isset($this->_values['is_recur']) && !empty($this->_paymentProcessor['is_recur'])) { $this->assign('is_recur_enabled', 1); - $vars = array_merge($vars, array( + $vars = array_merge($vars, [ 'is_recur', 'frequency_interval', 'frequency_unit', 'installments', - )); + ]); } if (in_array('CiviPledge', $config->enableComponents) && @@ -553,12 +544,12 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { ) { $this->assign('pledge_enabled', 1); - $vars = array_merge($vars, array( + $vars = array_merge($vars, [ 'is_pledge', 'pledge_frequency_interval', 'pledge_frequency_unit', 'pledge_installments', - )); + ]); } // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel @@ -588,56 +579,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $locTypeId = array_keys($this->_params['onbehalf_location']['email']); $this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']); } - - //fix for CRM-3767 - $isMonetary = FALSE; - if ($this->_amount > 0.0) { - $isMonetary = TRUE; - } - elseif (!empty($this->_params['selectMembership'])) { - $memFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'minimum_fee'); - if ($memFee > 0.0) { - $isMonetary = TRUE; - } - } - - // 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 $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)) - ); - } - elseif ($paymentField === 'credit_card_type') { - $this->assign('credit_card_type', CRM_Core_PseudoConstant::getLabel( - 'CRM_Core_BAO_FinancialTrxn', - 'card_type_id', - CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', $this->_params['credit_card_type']) - )); - } - else { - $this->assign($paymentField, $this->_params[$paymentField]); - } - } - $this->assign('paymentFieldsetLabel', CRM_Core_Payment_Form::getPaymentLabel($paymentProcessorObject)); - $this->assign('paymentFields', $paymentFields); - - } + $this->assignPaymentFields(); $this->assign('email', $this->controller->exportValue('Main', "email-{$this->_bltID}") @@ -664,7 +606,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { // we don't allow conflicting fields to be // configured via profile - CRM 2100 - $fieldsToIgnore = array( + $fieldsToIgnore = [ 'receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, @@ -680,7 +622,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { 'payment_instrument_id' => 1, 'contribution_check_number' => 1, 'financial_type' => 1, - ); + ]; $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL @@ -690,7 +632,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { // determine if email exists in profile so we know if we need to manually insert CRM-2888, CRM-15067 foreach ($fields as $key => $field) { if (substr($key, 0, 6) == 'email-' && - !in_array($profileContactType, array('honor', 'onbehalf')) + !in_array($profileContactType, ['honor', 'onbehalf']) ) { $this->_emailExists = TRUE; $this->set('emailExists', TRUE); @@ -703,14 +645,14 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } //remove common fields only if profile is not configured for onbehalf/honor - if (!in_array($profileContactType, array('honor', 'onbehalf'))) { + if (!in_array($profileContactType, ['honor', 'onbehalf'])) { $fields = array_diff_key($fields, $this->_fields); } CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID); $addCaptcha = FALSE; // fetch file preview when not submitted yet, like in online contribution Confirm and ThankYou page - $viewOnlyFileValues = empty($profileContactType) ? array() : array($profileContactType => array()); + $viewOnlyFileValues = empty($profileContactType) ? [] : [$profileContactType => []]; foreach ($fields as $key => $field) { if ($viewOnly && isset($field['data_type']) && @@ -743,14 +685,14 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { if ($profileContactType) { //Since we are showing honoree name separately so we are removing it from honoree profile just for display if ($profileContactType == 'honor') { - $honoreeNamefields = array( + $honoreeNamefields = [ 'prefix_id', 'first_name', 'last_name', 'suffix_id', 'organization_name', 'household_name', - ); + ]; if (in_array($field['name'], $honoreeNamefields)) { unset($fields[$field['name']]); continue; @@ -814,6 +756,58 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } + public function assignPaymentFields() { + //fix for CRM-3767 + $isMonetary = FALSE; + if ($this->_amount > 0.0) { + $isMonetary = TRUE; + } + elseif (!empty($this->_params['selectMembership'])) { + $memFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'minimum_fee'); + if ($memFee > 0.0) { + $isMonetary = TRUE; + } + } + + // 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 $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)) + ); + } + elseif ($paymentField === 'credit_card_type') { + $this->assign('credit_card_type', CRM_Core_PseudoConstant::getLabel( + 'CRM_Core_BAO_FinancialTrxn', + 'card_type_id', + CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'card_type_id', $this->_params['credit_card_type']) + )); + } + else { + $this->assign($paymentField, $this->_params[$paymentField]); + } + } + $this->assign('paymentFieldsetLabel', CRM_Core_Payment_Form::getPaymentLabel($paymentProcessorObject)); + $this->assign('paymentFields', $paymentFields); + + } + } + /** * Display ReCAPTCHA warning on Contribution form */ @@ -847,7 +841,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $contactID = $this->getContactID(); - foreach (array('soft_credit', 'on_behalf') as $module) { + foreach (['soft_credit', 'on_behalf'] as $module) { if ($module == 'soft_credit') { if (empty($form->_values['honoree_profile_id'])) { continue; @@ -858,17 +852,17 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']); - $requiredProfileFields = array( - 'Individual' => array('first_name', 'last_name'), - 'Organization' => array('organization_name', 'email'), - 'Household' => array('household_name', 'email'), - ); + $requiredProfileFields = [ + 'Individual' => ['first_name', 'last_name'], + 'Organization' => ['organization_name', 'email'], + 'Household' => ['household_name', 'email'], + ]; $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]); if (!$validProfile) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.')); } - foreach (array('honor_block_title', 'honor_block_text') as $name) { + foreach (['honor_block_title', 'honor_block_text'] as $name) { $form->assign($name, $form->_values[$name]); } @@ -915,11 +909,11 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.'); $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']); foreach ( - array( + [ 'Individual', 'Organization', 'Household', - ) as $contactType + ] as $contactType ) { if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || @@ -937,17 +931,17 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { if (count($organizations)) { // Related org url - pass checksum if needed - $args = array( + $args = [ 'ufId' => $form->_values['onbehalf_profile_id'], 'cid' => '', - ); + ]; if (!empty($_GET['cs'])) { - $args = array( + $args = [ 'ufId' => $form->_values['onbehalf_profile_id'], 'uid' => $this->_contactID, 'cs' => $_GET['cs'], 'cid' => '', - ); + ]; } $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE); $form->assign('locDataURL', $locDataURL); @@ -955,12 +949,12 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { if (count($organizations) > 0) { $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations)); - $orgOptions = array( + $orgOptions = [ 0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'), - ); + ]; $form->addRadio('org_option', ts('options'), $orgOptions); - $form->setDefaults(array('org_option' => 0)); + $form->setDefaults(['org_option' => 0]); } } @@ -993,9 +987,9 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $form->assign('submittedOnBehalfInfo', json_encode(str_replace('"', '\"', $form->_submitValues['onbehalf']), JSON_HEX_APOS)); } - $fieldTypes = array('Contact', 'Organization'); + $fieldTypes = ['Contact', 'Organization']; if (!empty($form->_membershipBlock)) { - $fieldTypes = array_merge($fieldTypes, array('Membership')); + $fieldTypes = array_merge($fieldTypes, ['Membership']); } $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); @@ -1003,7 +997,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { foreach ($profileFields as $name => $field) { if (in_array($field['field_type'], $fieldTypes)) { list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); - if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) { + if (in_array($prefixName, ['organization_name', 'email']) && empty($field['is_required'])) { $field['is_required'] = 1; } if (count($form->_submitValues) && @@ -1071,18 +1065,18 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); //get pledge status and contact id - $pledgeValues = array(); - $pledgeParams = array('id' => $this->_values['pledge_id']); - $returnProperties = array('contact_id', 'status_id'); + $pledgeValues = []; + $pledgeParams = ['id' => $this->_values['pledge_id']]; + $returnProperties = ['contact_id', 'status_id']; CRM_Core_DAO::commonRetrieve('CRM_Pledge_DAO_Pledge', $pledgeParams, $pledgeValues, $returnProperties); //get all status $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); - $validStatus = array( + $validStatus = [ array_search('Pending', $allStatus), array_search('In Progress', $allStatus), array_search('Overdue', $allStatus), - ); + ]; $validUser = FALSE; if ($this->_userID && @@ -1107,7 +1101,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { //check for valid pledge status. if (!in_array($pledgeValues['status_id'], $validStatus)) { - CRM_Core_Error::fatal(ts('Oops. You cannot make a payment for this pledge - pledge status is %1.', array(1 => CRM_Utils_Array::value($pledgeValues['status_id'], $allStatus)))); + CRM_Core_Error::fatal(ts('Oops. You cannot make a payment for this pledge - pledge status is %1.', [1 => CRM_Utils_Array::value($pledgeValues['status_id'], $allStatus)])); } } @@ -1161,13 +1155,13 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $separateMembershipPayment = FALSE; if ($this->_membershipBlock) { - $this->_currentMemberships = array(); + $this->_currentMemberships = []; - $membershipTypeIds = $membershipTypes = $radio = array(); + $membershipTypeIds = $membershipTypes = $radio = []; $membershipPriceset = (!empty($this->_priceSetId) && $this->_useForMember) ? TRUE : FALSE; $allowAutoRenewMembership = $autoRenewOption = FALSE; - $autoRenewMembershipTypeOptions = array(); + $autoRenewMembershipTypeOptions = []; $separateMembershipPayment = CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock); @@ -1203,6 +1197,18 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $membershipTypeIds); $this->_membershipTypeValues = $membershipTypeValues; $endDate = NULL; + + // Check if we support auto-renew on this contribution page + // FIXME: If any of the payment processors do NOT support recurring you cannot setup an + // auto-renew payment even if that processor is not selected. + $allowAutoRenewOpt = TRUE; + if (is_array($this->_paymentProcessors)) { + foreach ($this->_paymentProcessors as $id => $val) { + if ($id && !$val['is_recur']) { + $allowAutoRenewOpt = FALSE; + } + } + } foreach ($membershipTypeIds as $value) { $memType = $membershipTypeValues[$value]; if ($selectedMembershipTypeID != NULL) { @@ -1225,23 +1231,16 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } elseif ($memType['is_active']) { - $javascriptMethod = NULL; - $allowAutoRenewOpt = (int) $memType['auto_renew']; - if (is_array($this->_paymentProcessors)) { - foreach ($this->_paymentProcessors as $id => $val) { - if ($id && !$val['is_recur']) { - $allowAutoRenewOpt = 0; - continue; - } - } - } - - $javascriptMethod = array('onclick' => "return showHideAutoRenew( this.value );"); - $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = (int) $allowAutoRenewOpt * CRM_Utils_Array::value($value, CRM_Utils_Array::value('auto_renew', $this->_membershipBlock));; if ($allowAutoRenewOpt) { + $javascriptMethod = ['onclick' => "return showHideAutoRenew( this.value );"]; + $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = (int) $memType['auto_renew'] * CRM_Utils_Array::value($value, CRM_Utils_Array::value('auto_renew', $this->_membershipBlock)); $allowAutoRenewMembership = TRUE; } + else { + $javascriptMethod = NULL; + $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = 0; + } //add membership type. $radio[$memType['id']] = $this->createElement('radio', NULL, NULL, NULL, @@ -1316,7 +1315,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } elseif ($this->_membershipBlock['is_required'] && count($radio) == 1) { $temp = array_keys($radio); - $this->add('hidden', 'selectMembership', $temp[0], array('id' => 'selectMembership')); + $this->add('hidden', 'selectMembership', $temp[0], ['id' => 'selectMembership']); $this->assign('singleMembership', TRUE); $this->assign('showRadio', FALSE); } @@ -1393,4 +1392,16 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } + /** + * Get the payment processor object for the submission, returning the manual one for offline payments. + * + * @return CRM_Core_Payment + */ + protected function getPaymentProcessorObject() { + if (!empty($this->_paymentProcessor)) { + return $this->_paymentProcessor['object']; + } + return new CRM_Core_Payment_Manual(); + } + }