3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 * This class generates form components for processing a Contribution.
37 class CRM_Contribute_Form_Contribution_Main
extends CRM_Contribute_Form_ContributionBase
{
40 * Define default MembershipType Id.
42 public $_defaultMemTypeId;
44 public $_relatedOrganizationFound;
46 public $_onBehalfRequired = FALSE;
47 public $_onbehalf = FALSE;
48 public $_paymentProcessors;
50 public $_membershipTypeValues;
52 public $_useForMember;
55 * Array of payment related fields to potentially display on this form (generally credit card or debit card fields). This is rendered via billingBlock.tpl
58 public $_paymentFields = array();
60 protected $_paymentProcessorID;
64 * Set variables up before form is built.
66 public function preProcess() {
69 $this->_paymentProcessors
= $this->get('paymentProcessors');
70 $this->preProcessPaymentOptions();
72 // Make the contributionPageID available to the template
73 $this->assign('contributionPageID', $this->_id
);
74 $this->assign('isShare', CRM_Utils_Array
::value('is_share', $this->_values
));
75 $this->assign('isConfirmEnabled', CRM_Utils_Array
::value('is_confirm_enabled', $this->_values
));
77 $this->assign('reset', CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject));
78 $this->assign('mainDisplay', CRM_Utils_Request
::retrieve('_qf_Main_display', 'Boolean',
79 CRM_Core_DAO
::$_nullObject));
81 // Possible values for 'is_for_organization':
82 // * 0 - org profile disabled
83 // * 1 - org profile optional
84 // * 2 - org profile required
85 $this->_onbehalf
= FALSE;
86 if (!empty($this->_values
['is_for_organization'])) {
87 if ($this->_values
['is_for_organization'] == 2) {
88 $this->_onBehalfRequired
= TRUE;
90 // Add organization profile if 1 of the following are true:
91 // If the org profile is required
92 if ($this->_onBehalfRequired ||
93 // Or we are building the form for the first time
95 // Or the user has submitted the form and checked the "On Behalf" checkbox
96 !empty($_POST['is_for_organization'])
98 $this->_onbehalf
= TRUE;
99 CRM_Contribute_Form_Contribution_OnBehalfOf
::preProcess($this);
102 $this->assign('onBehalfRequired', $this->_onBehalfRequired
);
104 if ($this->_honor_block_is_active
) {
105 CRM_Contact_Form_ProfileContact
::preprocess($this);
108 if ($this->_snippet
) {
109 $this->assign('isOnBehalfCallback', CRM_Utils_Array
::value('onbehalf', $_GET, FALSE));
113 if (!empty($this->_pcpInfo
['id']) && !empty($this->_pcpInfo
['intro_text'])) {
114 $this->assign('intro_text', $this->_pcpInfo
['intro_text']);
116 elseif (!empty($this->_values
['intro_text'])) {
117 $this->assign('intro_text', $this->_values
['intro_text']);
120 $qParams = "reset=1&id={$this->_id}";
121 if ($pcpId = CRM_Utils_Array
::value('pcp_id', $this->_pcpInfo
)) {
122 $qParams .= "&pcpId={$pcpId}";
124 $this->assign('qParams', $qParams);
126 if (!empty($this->_values
['footer_text'])) {
127 $this->assign('footer_text', $this->_values
['footer_text']);
132 $member = CRM_Member_BAO_Membership
::getMembershipBlock($this->_id
);
133 if (!empty($this->_values
['is_for_organization']) && empty($member['is_active'])) {
134 $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
135 $ufJoinParams = array(
136 'module' => 'onBehalf',
137 'entity_table' => 'civicrm_contribution_page',
138 'entity_id' => $this->_id
,
140 $onBehalfProfileIDs = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
141 // getUFGroupIDs returns an array with the first item being the ID we need
142 $onBehalfProfileID = $onBehalfProfileIDs[0];
143 if ($onBehalfProfileID) {
144 $onBehalfProfile = CRM_Core_BAO_UFGroup
::profileGroups($onBehalfProfileID);
150 if (in_array($contactType, $onBehalfProfile) &&
151 (in_array('Membership', $onBehalfProfile) ||
152 in_array('Contribution', $onBehalfProfile)
155 CRM_Core_Error
::fatal($msg);
160 if ($postID = CRM_Utils_Array
::value('custom_post_id', $this->_values
)) {
161 $postProfile = CRM_Core_BAO_UFGroup
::profileGroups($postID);
167 if (in_array($contactType, $postProfile) &&
168 (in_array('Membership', $postProfile) ||
169 in_array('Contribution', $postProfile)
172 CRM_Core_Error
::fatal($msg);
180 * Set the default values.
182 public function setDefaultValues() {
183 // check if the user is registered and we have a contact ID
184 $contactID = $this->getContactID();
186 if (!empty($contactID)) {
188 $removeCustomFieldTypes = array('Contribution', 'Membership');
189 $contribFields = CRM_Contribute_BAO_Contribution
::getContributionFields();
191 // remove component related fields
192 foreach ($this->_fields
as $name => $dontCare) {
193 //don't set custom data Used for Contribution (CRM-1344)
194 if (substr($name, 0, 7) == 'custom_') {
195 $id = substr($name, 7);
196 if (!CRM_Core_BAO_CustomGroup
::checkCustomField($id, $removeCustomFieldTypes)) {
199 // ignore component fields
201 elseif (array_key_exists($name, $contribFields) ||
(substr($name, 0, 11) == 'membership_') ||
(substr($name, 0, 13) == 'contribution_')) {
207 if (!empty($fields)) {
208 CRM_Core_BAO_UFGroup
::setProfileDefaults($contactID, $fields, $this->_defaults
);
211 $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
212 $this->_defaults
= array_merge($this->_defaults
, $billingDefaults);
215 //set custom field defaults set by admin if value is not set
216 if (!empty($this->_fields
)) {
217 //load default campaign from page.
218 if (array_key_exists('contribution_campaign_id', $this->_fields
)) {
219 $this->_defaults
['contribution_campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
);
222 //set custom field defaults
223 foreach ($this->_fields
as $name => $field) {
224 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
225 if (!isset($this->_defaults
[$name])) {
226 CRM_Core_BAO_CustomField
::setProfileDefaults($customFieldID, $name, $this->_defaults
,
227 NULL, CRM_Profile_Form
::MODE_REGISTER
235 * hack to simplify credit card entry for testing
237 * $this->_defaults['credit_card_type'] = 'Visa';
238 * $this->_defaults['amount'] = 168;
239 * $this->_defaults['credit_card_number'] = '4111111111111111';
240 * $this->_defaults['cvv2'] = '000';
241 * $this->_defaults['credit_card_exp_date'] = array('Y' => date('Y')+1, 'M' => '05');
242 * // hack to simplify direct debit entry for testing
243 * $this->_defaults['account_holder'] = 'Max Müller';
244 * $this->_defaults['bank_account_number'] = '12345678';
245 * $this->_defaults['bank_identification_number'] = '12030000';
246 * $this->_defaults['bank_name'] = 'Bankname';
249 //build set default for pledge overdue payment.
250 if (!empty($this->_values
['pledge_id'])) {
251 //used to record completed pledge payment ids used later for honor default
252 $completedContributionIds = array();
253 $pledgePayments = CRM_Pledge_BAO_PledgePayment
::getPledgePayments($this->_values
['pledge_id']);
256 foreach ($pledgePayments as $payId => $value) {
257 if ($value['status'] == 'Overdue') {
258 $this->_defaults
['pledge_amount'][$payId] = 1;
260 elseif (!$duePayment && $value['status'] == 'Pending') {
261 $this->_defaults
['pledge_amount'][$payId] = 1;
264 elseif ($value['status'] == 'Completed' && $value['contribution_id']) {
265 $completedContributionIds[] = $value['contribution_id'];
269 if ($this->_honor_block_is_active
&& count($completedContributionIds)) {
270 $softCredit = array();
271 foreach ($completedContributionIds as $id) {
272 $softCredit = CRM_Contribute_BAO_ContributionSoft
::getSoftContribution($id);
274 if (isset($softCredit['soft_credit'])) {
275 $this->_defaults
['soft_credit_type_id'] = $softCredit['soft_credit'][1]['soft_credit_type'];
277 //since honoree profile fieldname of fields are prefixed with 'honor'
278 //we need to reformat the fieldname to append prefix during setting default values
279 CRM_Core_BAO_UFGroup
::setProfileDefaults(
280 $softCredit['soft_credit'][1]['contact_id'],
281 CRM_Core_BAO_UFGroup
::getFields($this->_honoreeProfileId
),
284 foreach ($defaults as $fieldName => $value) {
285 $this->_defaults
['honor[' . $fieldName . ']'] = $value;
290 elseif (!empty($this->_values
['pledge_block_id'])) {
291 //set default to one time contribution.
292 $this->_defaults
['is_pledge'] = 0;
295 // to process Custom data that are appended to URL
296 $getDefaults = CRM_Core_BAO_CustomGroup
::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
297 $this->_defaults
= array_merge($this->_defaults
, $getDefaults);
299 $config = CRM_Core_Config
::singleton();
300 // set default country from config if no country set
301 if (empty($this->_defaults
["billing_country_id-{$this->_bltID}"])) {
302 $this->_defaults
["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
305 // set default state/province from config if no state/province set
306 if (empty($this->_defaults
["billing_state_province_id-{$this->_bltID}"])) {
307 $this->_defaults
["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince
;
310 if ($this->_priceSetId
) {
311 if (($this->_useForMember
&& !empty($this->_currentMemberships
)) ||
$this->_defaultMemTypeId
) {
312 $selectedCurrentMemTypes = array();
313 foreach ($this->_priceSet
['fields'] as $key => $val) {
314 foreach ($val['options'] as $keys => $values) {
315 $opMemTypeId = CRM_Utils_Array
::value('membership_type_id', $values);
316 $priceFieldName = 'price_' . $values['price_field_id'];
317 $priceFieldValue = CRM_Price_BAO_PriceSet
::getPriceFieldValueFromURL($this, $priceFieldName);
318 if (!empty($priceFieldValue)) {
319 CRM_Price_BAO_PriceSet
::setDefaultPriceSetField($priceFieldName, $priceFieldValue, $val['html_type'], $this->_defaults
);
320 // break here to prevent overwriting of default due to 'is_default'
321 // option configuration or setting of current membership or
322 // membership for related organization.
323 // The value sent via URL get's higher priority.
326 elseif ($opMemTypeId &&
327 in_array($opMemTypeId, $this->_currentMemberships
) &&
328 !in_array($opMemTypeId, $selectedCurrentMemTypes)
330 CRM_Price_BAO_PriceSet
::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults
);
331 $selectedCurrentMemTypes[] = $values['membership_type_id'];
333 elseif (!empty($values['is_default']) &&
335 (!isset($this->_defaults
[$priceFieldName]) ||
336 ($val['html_type'] == 'CheckBox' &&
337 !isset($this->_defaults
[$priceFieldName][$keys]))
339 CRM_Price_BAO_PriceSet
::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults
);
345 CRM_Price_BAO_PriceSet
::setDefaultPriceSet($this, $this->_defaults
);
349 if (!empty($this->_paymentProcessors
)) {
350 foreach ($this->_paymentProcessors
as $pid => $value) {
351 if (!empty($value['is_default'])) {
352 $this->_defaults
['payment_processor_id'] = $pid;
357 return $this->_defaults
;
361 * Build the form object.
363 public function buildQuickForm() {
364 // build profiles first so that we can determine address fields etc
365 // and then show copy address checkbox
366 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre');
367 $this->buildCustom($this->_values
['custom_post_id'], 'customPost');
369 if (!empty($this->_fields
) && !empty($this->_values
['custom_pre_id'])) {
370 $profileAddressFields = array();
371 foreach ($this->_fields
as $key => $value) {
372 CRM_Core_BAO_UFField
::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $this->_values
['custom_pre_id']));
374 $this->set('profileAddressFields', $profileAddressFields);
377 // Build payment processor form
378 if (empty($_GET['onbehalf'])) {
379 CRM_Core_Payment_ProcessorForm
::buildQuickForm($this);
382 $config = CRM_Core_Config
::singleton();
384 $contactID = $this->getContactID();
386 $this->assign('contact_id', $contactID);
387 $this->assign('display_name', CRM_Contact_BAO_Contact
::displayName($contactID));
390 if ($this->_onbehalf
) {
391 CRM_Contribute_Form_Contribution_OnBehalfOf
::buildQuickForm($this);
392 // Return if we are in an ajax callback
393 if ($this->_snippet
) {
398 $this->applyFilter('__ALL__', 'trim');
399 $this->add('text', "email-{$this->_bltID}",
401 array('size' => 30, 'maxlength' => 60, 'class' => 'email'),
404 $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email');
406 //@todo - this should be replaced by a check as to whether billing fields are set
407 $onlinePaymentProcessorEnabled = FALSE;
408 if (!empty($this->_paymentProcessors
)) {
409 foreach ($this->_paymentProcessors
as $key => $name) {
410 if ($name['billing_mode'] == 1) {
411 $onlinePaymentProcessorEnabled = TRUE;
413 $pps[$key] = $name['name'];
416 if (!empty($this->_values
['is_pay_later'])) {
417 $pps[0] = $this->_values
['pay_later_text'];
420 if (count($pps) > 1) {
421 $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
425 elseif (!empty($pps)) {
426 $key = array_keys($pps);
427 $key = array_pop($key);
428 $this->addElement('hidden', 'payment_processor_id', $key);
430 $this->assign('is_pay_later', $this->_values
['is_pay_later']);
431 $this->assign('pay_later_text', $this->_values
['pay_later_text']);
435 $contactID = $this->getContactID();
436 if ($this->getContactID() === 0) {
437 $this->addCidZeroOptions($onlinePaymentProcessorEnabled);
440 //build pledge block.
441 $this->_useForMember
= 0;
442 //don't build membership block when pledge_id is passed
443 if (empty($this->_values
['pledge_id'])) {
444 $this->_separateMembershipPayment
= FALSE;
445 if (in_array('CiviMember', $config->enableComponents
)) {
447 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
451 if ($this->_priceSetId
&&
452 (CRM_Core_Component
::getComponentID('CiviMember') == CRM_Utils_Array
::value('extends', $this->_priceSet
))
454 $this->_useForMember
= 1;
455 $this->set('useForMember', $this->_useForMember
);
458 $this->_separateMembershipPayment
= $this->buildMembershipBlock(
459 $this->_membershipContactID
,
464 $this->set('separateMembershipPayment', $this->_separateMembershipPayment
);
466 $this->assign('useForMember', $this->_useForMember
);
467 // If we configured price set for contribution page
468 // we are not allow membership signup as well as any
469 // other contribution amount field, CRM-5095
470 if (isset($this->_priceSetId
) && $this->_priceSetId
) {
471 $this->add('hidden', 'priceSetId', $this->_priceSetId
);
472 // build price set form.
473 $this->set('priceSetId', $this->_priceSetId
);
474 CRM_Price_BAO_PriceSet
::buildPriceSet($this);
475 if ($this->_values
['is_monetary'] &&
476 $this->_values
['is_recur'] && empty($this->_values
['pledge_id'])
478 self
::buildRecur($this);
482 if ($this->_priceSetId
) {
483 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
484 if ($is_quick_config) {
485 $this->_useForMember
= 0;
486 $this->set('useForMember', $this->_useForMember
);
490 if ($this->_values
['is_for_organization']) {
491 $this->buildOnBehalfOrganization();
494 //we allow premium for pledge during pledge creation only.
495 if (empty($this->_values
['pledge_id'])) {
496 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, TRUE);
500 if ($this->_honor_block_is_active
) {
501 $this->assign('honor_block_is_active', TRUE);
503 //build soft-credit section
504 CRM_Contribute_Form_SoftCredit
::buildQuickForm($this);
505 //build honoree profile section
506 CRM_Contact_Form_ProfileContact
::buildQuickForm($this);
509 //don't build pledge block when mid is passed
511 $config = CRM_Core_Config
::singleton();
512 if (in_array('CiviPledge', $config->enableComponents
) && !empty($this->_values
['pledge_block_id'])) {
513 CRM_Pledge_BAO_PledgeBlock
::buildPledgeBlock($this);
517 //to create an cms user
518 if (!$this->_contactID
) {
519 $createCMSUser = FALSE;
521 if ($this->_values
['custom_pre_id']) {
522 $profileID = $this->_values
['custom_pre_id'];
523 $createCMSUser = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
526 if (!$createCMSUser &&
527 $this->_values
['custom_post_id']
529 if (!is_array($this->_values
['custom_post_id'])) {
530 $profileIDs = array($this->_values
['custom_post_id']);
533 $profileIDs = $this->_values
['custom_post_id'];
535 foreach ($profileIDs as $pid) {
536 if (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
538 $createCMSUser = TRUE;
544 if ($createCMSUser) {
545 CRM_Core_BAO_CMSUser
::buildForm($this, $profileID, TRUE);
549 if ($pcpSupporter = CRM_PCP_BAO_PCP
::displayName($this->_pcpId
)) {
550 $pcp_supporter_text = ts('This contribution is being made thanks to the effort of <strong>%1</strong>, who supports our campaign.', array(1 => $pcpSupporter));
551 // Only tell people that can also create a PCP if the contribution page has a non-empty value in the "Create Personal Campaign Page link" field.
552 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($this->_id
, 'contribute');
554 $pcp_supporter_text .= ts("You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!");
556 $this->assign('pcpSupporterText', $pcp_supporter_text);
558 $prms = array('id' => $this->_pcpId
);
559 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
560 if ($pcpInfo['is_honor_roll']) {
561 $this->assign('isHonor', TRUE);
562 $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL,
563 array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
565 $extraOption = array('onclick' => "return pcpAnonymous( );");
567 $elements[] = &$this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
568 $elements[] = &$this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
569 $this->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
571 $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
572 $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
576 //we have to load confirm contribution button in template
577 //when multiple payment processor as the user
578 //can toggle with payment processor selection
579 $billingModePaymentProcessors = 0;
580 if (!empty($this->_paymentProcessors
)) {
581 foreach ($this->_paymentProcessors
as $key => $values) {
582 if ($values['billing_mode'] == CRM_Core_Payment
::BILLING_MODE_BUTTON
) {
583 $billingModePaymentProcessors++
;
588 if ($billingModePaymentProcessors && count($this->_paymentProcessors
) == $billingModePaymentProcessors) {
589 $allAreBillingModeProcessors = TRUE;
592 $allAreBillingModeProcessors = FALSE;
595 if (!($allAreBillingModeProcessors && !$this->_values
['is_pay_later'])) {
596 $submitButton = array(
598 'name' => CRM_Utils_Array
::value('is_confirm_enabled', $this->_values
) ?
ts('Confirm Contribution') : ts('Contribute'),
599 'spacing' => ' ',
602 // Add submit-once behavior when confirm page disabled
603 if (empty($this->_values
['is_confirm_enabled'])) {
604 $submitButton['js'] = array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');");
606 $this->addButtons(array($submitButton));
609 $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
613 * Build elements to enable pay on behalf of an organization.
615 public function buildOnBehalfOrganization() {
616 if ($this->_membershipContactID
) {
617 $entityBlock = array('contact_id' => $this->_membershipContactID
);
618 CRM_Core_BAO_Location
::getValues($entityBlock, $this->_defaults
);
621 if (!$this->_onBehalfRequired
) {
622 $this->addElement('checkbox', 'is_for_organization',
623 $this->_values
['for_organization'],
624 NULL, array('onclick' => "showOnBehalf( );")
628 $this->assign('is_for_organization', TRUE);
629 $this->assign('urlPath', 'civicrm/contribute/transact');
633 * Build elements to collect information for recurring contributions.
636 * @param CRM_Core_Form $form
638 public static function buildRecur(&$form) {
639 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionRecur');
640 $className = get_class($form);
642 $form->assign('is_recur_interval', CRM_Utils_Array
::value('is_recur_interval', $form->_values
));
643 $form->assign('is_recur_installments', CRM_Utils_Array
::value('is_recur_installments', $form->_values
));
645 $form->add('checkbox', 'is_recur', ts('I want to contribute this amount'), NULL);
647 if (!empty($form->_values
['is_recur_interval']) ||
$className == 'CRM_Contribute_Form_Contribution') {
648 $form->add('text', 'frequency_interval', ts('Every'), $attributes['frequency_interval']);
649 $form->addRule('frequency_interval', ts('Frequency must be a whole number (EXAMPLE: Every 3 months).'), 'integer');
652 // make sure frequency_interval is submitted as 1 if given no choice to user.
653 $form->add('hidden', 'frequency_interval', 1);
656 $frUnits = CRM_Utils_Array
::value('recur_frequency_unit', $form->_values
);
657 if (empty($frUnits) &&
658 $className == 'CRM_Contribute_Form_Contribution'
660 $frUnits = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
661 CRM_Core_OptionGroup
::values('recur_frequency_units')
665 $unitVals = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $frUnits);
667 // CRM 10860, display text instead of a dropdown if there's only 1 frequency unit
668 if (count($unitVals) == 1) {
669 $form->assign('one_frequency_unit', TRUE);
670 $unit = $unitVals[0];
671 $form->add('hidden', 'frequency_unit', $unit);
672 if (!empty($form->_values
['is_recur_interval']) ||
$className == 'CRM_Contribute_Form_Contribution') {
675 $form->assign('frequency_unit', $unit);
678 $form->assign('one_frequency_unit', FALSE);
680 $frequencyUnits = CRM_Core_OptionGroup
::values('recur_frequency_units', FALSE, FALSE, TRUE);
681 foreach ($unitVals as $key => $val) {
682 if (array_key_exists($val, $frequencyUnits)) {
683 $units[$val] = $frequencyUnits[$val];
684 if (!empty($form->_values
['is_recur_interval']) ||
$className == 'CRM_Contribute_Form_Contribution') {
685 $units[$val] = "{$frequencyUnits[$val]}(s)";
689 $frequencyUnit = &$form->add('select', 'frequency_unit', NULL, $units);
692 // FIXME: Ideally we should freeze select box if there is only
693 // one option but looks there is some problem /w QF freeze.
694 //if ( count( $units ) == 1 ) {
695 //$frequencyUnit->freeze( );
698 $form->add('text', 'installments', ts('installments'),
699 $attributes['installments']
701 $form->addRule('installments', ts('Number of installments must be a whole number.'), 'integer');
707 * @param array $fields
708 * The input form values.
709 * @param array $files
710 * The uploaded files if any.
711 * @param CRM_Core_Form $self
714 * true if no errors, else array of errors
716 public static function formRule($fields, $files, $self) {
718 $amount = self
::computeAmount($fields, $self->_values
);
720 if ((!empty($fields['selectMembership']) &&
721 $fields['selectMembership'] != 'no_thanks'
723 (!empty($fields['priceSetId']) &&
727 $lifeMember = CRM_Member_BAO_Membership
::getAllContactMembership($self->_membershipContactID
, FALSE, TRUE);
729 $membershipOrgDetails = CRM_Member_BAO_MembershipType
::getMembershipTypeOrganization();
731 $unallowedOrgs = array();
732 foreach (array_keys($lifeMember) as $memTypeId) {
733 $unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
737 //check for atleast one pricefields should be selected
738 if (!empty($fields['priceSetId'])) {
739 $priceField = new CRM_Price_DAO_PriceField();
740 $priceField->price_set_id
= $fields['priceSetId'];
741 $priceField->orderBy('weight');
745 $membershipIsActive = TRUE;
746 $previousId = $otherAmount = FALSE;
747 while ($priceField->fetch()) {
749 if ($self->_quickConfig
&& ($priceField->name
== 'contribution_amount' ||
$priceField->name
== 'membership_amount')) {
750 $previousId = $priceField->id
;
751 if ($priceField->name
== 'membership_amount' && !$priceField->is_active
) {
752 $membershipIsActive = FALSE;
755 if ($priceField->name
== 'other_amount') {
756 if ($self->_quickConfig
&& empty($fields["price_{$priceField->id}"]) &&
757 array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values
['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])
759 $otherAmount = $priceField->id
;
761 elseif (!empty($fields["price_{$priceField->id}"])) {
762 $otherAmountVal = CRM_Utils_Rule
::cleanMoney($fields["price_{$priceField->id}"]);
763 $min = CRM_Utils_Array
::value('min_amount', $self->_values
);
764 $max = CRM_Utils_Array
::value('max_amount', $self->_values
);
765 if ($min && $otherAmountVal < $min) {
766 $errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1',
770 if ($max && $otherAmountVal > $max) {
771 $errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.',
777 if (!empty($fields["price_{$priceField->id}"]) ||
($previousId == $priceField->id
&& isset($fields["price_{$previousId}"])
778 && empty($fields["price_{$previousId}"]))
780 $check[] = $priceField->id
;
784 $currentMemberships = NULL;
785 if ($membershipIsActive) {
786 $is_test = $self->_mode
!= 'live' ?
1 : 0;
787 $memContactID = $self->_membershipContactID
;
789 // For anonymous user check using dedupe rule
790 // if user has Cancelled Membership
791 if (!$memContactID) {
792 $dedupeParams = CRM_Dedupe_Finder
::formatParams($fields, 'Individual');
793 $dedupeParams['check_permission'] = FALSE;
794 $ids = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
795 // if we find more than one contact, use the first one
796 $memContactID = CRM_Utils_Array
::value(0, $ids);
798 $currentMemberships = CRM_Member_BAO_Membership
::getContactsCancelledMembership($memContactID,
802 $errorText = 'Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.';
803 foreach ($self->_values
['fee'] as $fieldKey => $fieldValue) {
804 if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array
::value('price_' . $fieldKey, $fields)) {
805 if (!is_array($fields['price_' . $fieldKey])) {
806 if (array_key_exists('membership_type_id', $fieldValue['options'][$fields['price_' . $fieldKey]])
807 && in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships)
809 $errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant
::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])));
813 foreach ($fields['price_' . $fieldKey] as $key => $ignore) {
814 if (array_key_exists('membership_type_id', $fieldValue['options'][$key])
815 && in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships)
817 $errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant
::membershipType($fieldValue['options'][$key]['membership_type_id'])));
826 if ($membershipIsActive && !$self->_membershipBlock
['is_required']
827 && $self->_values
['amount_block_is_active']
829 $membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
830 foreach ($self->_values
['fee'] as $fieldKey => $fieldValue) {
831 // if 'No thank you' membership is selected then set $membershipFieldId
832 if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array
::value('price_' . $fieldKey, $fields) == 0) {
833 $membershipFieldId = $fieldKey;
835 elseif ($membershipFieldId) {
836 if ($fieldValue['name'] == 'other_amount') {
837 $otherFieldId = $fieldKey;
839 elseif ($fieldValue['name'] == 'contribution_amount') {
840 $contributionFieldId = $fieldKey;
843 if (!$errorKey || CRM_Utils_Array
::value('price_' . $contributionFieldId, $fields) == '0') {
844 $errorKey = $fieldKey;
848 // $membershipFieldId is set and additional amount is 'No thank you' or NULL then throw error
849 if ($membershipFieldId && !(CRM_Utils_Array
::value('price_' . $contributionFieldId, $fields, -1) > 0) && empty($fields['price_' . $otherFieldId])) {
850 $errors["price_{$errorKey}"] = ts('Additional Contribution is required.');
854 if ($self->_useForMember
== 1 && $membershipIsActive) {
855 $errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
858 $errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
861 if ($otherAmount && !empty($check)) {
862 $errors["price_{$otherAmount}"] = ts('Amount is required field.');
865 if ($self->_useForMember
== 1 && !empty($check) && $membershipIsActive) {
866 $priceFieldIDS = array();
867 $priceFieldMemTypes = array();
869 foreach ($self->_priceSet
['fields'] as $priceId => $value) {
870 if (!empty($fields['price_' . $priceId]) ||
($self->_quickConfig
&& $value['name'] == 'membership_amount' && empty($self->_membershipBlock
['is_required']))) {
871 if (!empty($fields['price_' . $priceId]) && is_array($fields['price_' . $priceId])) {
872 foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
874 $priceFieldIDS[] = $priceFldVal;
878 elseif (!$value['is_enter_qty'] && !empty($fields['price_' . $priceId])) {
879 // The check for {!$value['is_enter_qty']} is done since, quantity fields allow entering
880 // quantity. And the quantity can't be conisdered as civicrm_price_field_value.id, CRM-9577
881 $priceFieldIDS[] = $fields['price_' . $priceId];
884 if (!empty($value['options'])) {
885 foreach ($value['options'] as $val) {
886 if (!empty($val['membership_type_id']) && (
887 ($fields['price_' . $priceId] == $val['id']) ||
888 (isset($fields['price_' . $priceId]) && !empty($fields['price_' . $priceId][$val['id']]))
891 $priceFieldMemTypes[] = $val['membership_type_id'];
898 if (!empty($lifeMember)) {
899 foreach ($priceFieldIDS as $priceFieldId) {
900 if (($id = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) &&
901 in_array($membershipOrgDetails[$id], $unallowedOrgs)
903 $errors['_qf_default'] = ts('You already have a lifetime membership and cannot select a membership with a shorter term.');
909 if (!empty($priceFieldIDS)) {
910 $ids = implode(',', $priceFieldIDS);
912 $priceFieldIDS['id'] = $fields['priceSetId'];
913 $self->set('memberPriceFieldIDS', $priceFieldIDS);
914 $count = CRM_Price_BAO_PriceSet
::getMembershipCount($ids);
915 foreach ($count as $id => $occurrence) {
916 if ($occurrence > 1) {
917 $errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity. Contact the site administrator if you need assistance.');
922 if (empty($priceFieldMemTypes)) {
923 $errors['_qf_default'] = ts('Please select at least one membership option.');
927 CRM_Price_BAO_PriceSet
::processAmount($self->_values
['fee'],
931 if ($fields['amount'] < 0) {
932 $errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
934 $amount = $fields['amount'];
937 if (isset($fields['selectProduct']) &&
938 $fields['selectProduct'] != 'no_thanks'
940 $productDAO = new CRM_Contribute_DAO_Product();
941 $productDAO->id
= $fields['selectProduct'];
942 $productDAO->find(TRUE);
943 $min_amount = $productDAO->min_contribution
;
945 if ($amount < $min_amount) {
946 $errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money
::format($min_amount)));
947 CRM_Core_Session
::setStatus($errors['selectProduct']);
951 //CRM-16285 - Function to handle validation errors on form, for recurring contribution field.
952 CRM_Contribute_BAO_ContributionRecur
::validateRecurContribution($fields, $files, $self, $errors);
954 if (!empty($fields['is_recur']) &&
955 CRM_Utils_Array
::value('payment_processor_id', $fields) == 0
957 $errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
960 if (!empty($fields['is_for_organization']) &&
961 !property_exists($self, 'organizationName')
964 if (empty($fields['onbehalf']['organization_name'])) {
965 if (!empty($fields['org_option']) && !$fields['onbehalfof_id']) {
966 $errors['organization_id'] = ts('Please select an organization or enter a new one.');
968 elseif (empty($fields['org_option'])) {
969 $errors['onbehalf']['organization_name'] = ts('Please enter the organization name.');
973 foreach ($fields['onbehalf'] as $key => $value) {
974 if (strstr($key, 'email')) {
975 $emailLocType = explode('-', $key);
978 if (empty($fields['onbehalf']["email-{$emailLocType[1]}"])) {
979 $errors['onbehalf']["email-{$emailLocType[1]}"] = ts('Organization email is required.');
983 // validate PCP fields - if not anonymous, we need a nick name value
984 if ($self->_pcpId
&& !empty($fields['pcp_display_in_roll']) &&
985 (CRM_Utils_Array
::value('pcp_is_anonymous', $fields) == 0) &&
986 CRM_Utils_Array
::value('pcp_roll_nickname', $fields) == ''
988 $errors['pcp_roll_nickname'] = ts('Please enter a name to include in the Honor Roll, or select \'contribute anonymously\'.');
991 // return if this is express mode
992 $config = CRM_Core_Config
::singleton();
993 if ($self->_paymentProcessor
&&
994 $self->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_BUTTON
996 if (!empty($fields[$self->_expressButtonName
. '_x']) ||
!empty($fields[$self->_expressButtonName
. '_y']) ||
997 CRM_Utils_Array
::value($self->_expressButtonName
, $fields)
1003 //validate the pledge fields.
1004 if (!empty($self->_values
['pledge_block_id'])) {
1005 //validation for pledge payment.
1006 if (!empty($self->_values
['pledge_id'])) {
1007 if (empty($fields['pledge_amount'])) {
1008 $errors['pledge_amount'] = ts('At least one payment option needs to be checked.');
1011 elseif (!empty($fields['is_pledge'])) {
1012 if (CRM_Utils_Rule
::positiveInteger(CRM_Utils_Array
::value('pledge_installments', $fields)) == FALSE) {
1013 $errors['pledge_installments'] = ts('Please enter a valid number of pledge installments.');
1016 if (CRM_Utils_Array
::value('pledge_installments', $fields) == NULL) {
1017 $errors['pledge_installments'] = ts('Pledge Installments is required field.');
1019 elseif (CRM_Utils_array
::value('pledge_installments', $fields) == 1) {
1020 $errors['pledge_installments'] = ts('Pledges consist of multiple scheduled payments. Select one-time contribution if you want to make your gift in a single payment.');
1022 elseif (CRM_Utils_array
::value('pledge_installments', $fields) == 0) {
1023 $errors['pledge_installments'] = ts('Pledge Installments field must be > 1.');
1027 //validation for Pledge Frequency Interval.
1028 if (CRM_Utils_Rule
::positiveInteger(CRM_Utils_Array
::value('pledge_frequency_interval', $fields)) == FALSE) {
1029 $errors['pledge_frequency_interval'] = ts('Please enter a valid Pledge Frequency Interval.');
1032 if (CRM_Utils_Array
::value('pledge_frequency_interval', $fields) == NULL) {
1033 $errors['pledge_frequency_interval'] = ts('Pledge Frequency Interval. is required field.');
1035 elseif (CRM_Utils_array
::value('pledge_frequency_interval', $fields) == 0) {
1036 $errors['pledge_frequency_interval'] = ts('Pledge frequency interval field must be > 0');
1042 // also return if paylater mode
1043 if (CRM_Utils_Array
::value('payment_processor_id', $fields) == 0 && $self->_isBillingAddressRequiredForPayLater
== 0) {
1044 return empty($errors) ?
TRUE : $errors;
1047 // if the user has chosen a free membership or the amount is less than zero
1048 // i.e. we skip calling the payment processor and hence dont need credit card
1050 if ((float) $amount <= 0.0) {
1054 if (!empty($self->_paymentFields
)) {
1055 CRM_Core_Form
::validateMandatoryFields($self->_paymentFields
, $fields, $errors);
1057 CRM_Core_Payment_Form
::validatePaymentInstrument($fields['payment_processor_id'], $fields, $errors, $self);
1059 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1060 if ($greetingType = CRM_Utils_Array
::value($greeting, $fields)) {
1061 $customizedValue = CRM_Core_OptionGroup
::getValue($greeting, 'Customized', 'name');
1062 if ($customizedValue == $greetingType && empty($fielse[$greeting . '_custom'])) {
1063 $errors[$greeting . '_custom'] = ts('Custom %1 is a required field if %1 is of type Customized.',
1064 array(1 => ucwords(str_replace('_', " ", $greeting)))
1070 return empty($errors) ?
TRUE : $errors;
1074 * Compute amount to be paid.
1076 * @param array $params
1077 * @param array $formValues
1079 * @return int|mixed|null|string
1081 public static function computeAmount($params, $formValues) {
1083 // First clean up the other amount field if present.
1084 if (isset($params['amount_other'])) {
1085 $params['amount_other'] = CRM_Utils_Rule
::cleanMoney($params['amount_other']);
1088 if (CRM_Utils_Array
::value('amount', $params) == 'amount_other_radio' ||
!empty($params['amount_other'])) {
1089 $amount = $params['amount_other'];
1091 elseif (!empty($params['pledge_amount'])) {
1092 foreach ($params['pledge_amount'] as $paymentId => $dontCare) {
1093 $amount +
= CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount');
1097 if (!empty($formValues['amount'])) {
1098 $amountID = CRM_Utils_Array
::value('amount', $params);
1101 $params['amount_level'] = CRM_Utils_Array
::value('label', $formValues[$amountID]);
1102 $amount = CRM_Utils_Array
::value('value', $formValues[$amountID]);
1110 * Process the form submission.
1112 public function postProcess() {
1113 $config = CRM_Core_Config
::singleton();
1114 // we first reset the confirm page so it accepts new values
1115 $this->controller
->resetPage('Confirm');
1117 // get the submitted form values.
1118 $params = $this->controller
->exportValues($this->_name
);
1120 //carry campaign from profile.
1121 if (array_key_exists('contribution_campaign_id', $params)) {
1122 $params['campaign_id'] = $params['contribution_campaign_id'];
1125 if (!empty($params['onbehalfof_id'])) {
1126 $params['organization_id'] = $params['onbehalfof_id'];
1129 $params['currencyID'] = $config->defaultCurrency
;
1131 if (!empty($params['priceSetId'])) {
1132 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
1133 if ($is_quick_config) {
1134 $priceField = new CRM_Price_DAO_PriceField();
1135 $priceField->price_set_id
= $params['priceSetId'];
1136 $priceField->orderBy('weight');
1137 $priceField->find();
1139 $priceOptions = array();
1140 while ($priceField->fetch()) {
1141 CRM_Price_BAO_PriceFieldValue
::getValues($priceField->id
, $priceOptions);
1142 if ($selectedPriceOptionID = CRM_Utils_Array
::value("price_{$priceField->id}", $params)) {
1143 switch ($priceField->name
) {
1144 case 'membership_amount':
1145 $this->_params
['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array
::value('membership_type_id', $priceOptions[$selectedPriceOptionID]);
1146 $this->set('selectMembership', $params['selectMembership']);
1147 if (CRM_Utils_Array
::value('is_separate_payment', $this->_membershipBlock
) == 0) {
1148 $this->_values
['amount'] = CRM_Utils_Array
::value('amount', $priceOptions[$selectedPriceOptionID]);
1152 case 'contribution_amount':
1153 $params['amount'] = $selectedPriceOptionID;
1154 $this->_values
['amount'] = CRM_Utils_Array
::value('amount', $priceOptions[$selectedPriceOptionID]);
1155 $this->_values
[$selectedPriceOptionID]['value'] = CRM_Utils_Array
::value('amount', $priceOptions[$selectedPriceOptionID]);
1156 $this->_values
[$selectedPriceOptionID]['label'] = CRM_Utils_Array
::value('label', $priceOptions[$selectedPriceOptionID]);
1157 $this->_values
[$selectedPriceOptionID]['amount_id'] = CRM_Utils_Array
::value('id', $priceOptions[$selectedPriceOptionID]);
1158 $this->_values
[$selectedPriceOptionID]['weight'] = CRM_Utils_Array
::value('weight', $priceOptions[$selectedPriceOptionID]);
1161 case 'other_amount':
1162 $params['amount_other'] = $selectedPriceOptionID;
1170 if (($this->_values
['is_pay_later'] &&
1171 empty($this->_paymentProcessor
) &&
1172 !array_key_exists('hidden_processor', $params)) ||
1173 (!empty($params['payment_processor_id']) && $params['payment_processor_id'] == 0)
1175 $params['is_pay_later'] = 1;
1178 $params['is_pay_later'] = 0;
1181 $this->set('is_pay_later', $params['is_pay_later']);
1182 // assign pay later stuff
1183 $this->_params
['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
1184 $this->assign('is_pay_later', $params['is_pay_later']);
1185 if ($params['is_pay_later']) {
1186 $this->assign('pay_later_text', $this->_values
['pay_later_text']);
1187 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
1190 // from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
1191 $params['amount'] = self
::computeAmount($params, $this->_values
);
1192 $params['separate_amount'] = $params['amount'];
1194 if (!empty($params['selectMembership'])) {
1195 if (!empty($this->_membershipTypeValues
)) {
1196 $membershipTypeValues = $this->_membershipTypeValues
[$params['selectMembership']];
1199 $membershipTypeValues = CRM_Member_BAO_Membership
::buildMembershipTypeValues($this,
1200 (array) $params['selectMembership']
1203 $memFee = $membershipTypeValues['minimum_fee'];
1204 if (!$params['amount'] && !$this->_separateMembershipPayment
) {
1205 $params['amount'] = $memFee ?
$memFee : 0;
1208 //If the membership & contribution is used in contribution page & not separate payment
1209 $fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
1210 $proceFieldAmount = 0;
1211 if (property_exists($this, '_separateMembershipPayment') && $this->_separateMembershipPayment
== 0) {
1212 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
1213 if ($is_quick_config) {
1214 foreach ($this->_priceSet
['fields'] as $fieldKey => $fieldVal) {
1215 if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
1216 $fieldId = $fieldVal['id'];
1217 $fieldOption = $params['price_' . $fieldId];
1218 $proceFieldAmount +
= $fieldVal['options'][$this->_submitValues
['price_' . $fieldId]]['amount'];
1222 if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' ||
$fieldVal['name'] == 'contribution_amount')) {
1223 $fieldId = $fieldVal['id'];
1224 if ($fieldVal['name'] == 'other_amount') {
1225 $proceFieldAmount +
= $this->_submitValues
['price_' . $fieldId];
1227 elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues
['price_' . $fieldId] > 0) {
1228 $proceFieldAmount +
= $fieldVal['options'][$this->_submitValues
['price_' . $fieldId]]['amount'];
1230 unset($params['price_' . $fieldId]);
1238 if (!isset($params['amount_other'])) {
1239 $this->set('amount_level', CRM_Utils_Array
::value('amount_level', $params));
1242 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $params)) {
1243 $lineItem = array();
1244 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
1245 if ($is_quick_config) {
1246 foreach ($this->_values
['fee'] as $key => & $val) {
1247 if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && !empty($params['price_' . $key])) {
1248 // Clean out any currency symbols.
1249 $params['price_' . $key] = CRM_Utils_Rule
::cleanMoney($params['price_' . $key]);
1250 if ($params['price_' . $key] != 0) {
1251 foreach ($val['options'] as $optionKey => & $options) {
1252 $options['amount'] = CRM_Utils_Array
::value('price_' . $key, $params);
1256 $params['price_' . $key] = 1;
1262 if ($this->_membershipBlock
) {
1263 $component = 'membership';
1266 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'], $params, $lineItem[$priceSetId], $component);
1267 if ($params['tax_amount']) {
1268 $this->set('tax_amount', $params['tax_amount']);
1271 if ($proceFieldAmount) {
1272 $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
1273 $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
1274 if (isset($lineItem[$params['priceSetId']][$fieldOption]['tax_amount'])) {
1275 $proceFieldAmount +
= $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
1277 if (!$this->_membershipBlock
['is_separate_payment']) {
1278 //require when separate membership not used
1279 $params['amount'] = $proceFieldAmount;
1282 $this->set('lineItem', $lineItem);
1285 if ($this->_membershipBlock
['is_separate_payment'] && !empty($params['separate_amount'])) {
1286 $this->set('amount', $params['separate_amount']);
1289 $this->set('amount', $params['amount']);
1292 // generate and set an invoiceID for this transaction
1293 $invoiceID = md5(uniqid(rand(), TRUE));
1294 $this->set('invoiceID', $invoiceID);
1295 $params['invoiceID'] = $invoiceID;
1296 $params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo
['title']) ?
$this->_pcpInfo
['title'] : $this->_values
['title']);
1297 $params['button'] = $this->controller
->getButtonName();
1298 // required only if is_monetary and valid positive amount
1299 if ($this->_values
['is_monetary'] &&
1300 is_array($this->_paymentProcessor
) &&
1301 ((float ) $params['amount'] > 0.0 ||
$memFee > 0.0)
1303 $this->setContributeMode();
1304 // Really this setting of $this->_params & params within it should be done earlier on in the function
1305 // probably the values determined here should be reused in confirm postProcess as there is no opportunity to alter anything
1306 // on the confirm page. However as we are dealing with a stable release we go as close to where it is used
1308 // In general the form has a lack of clarity of the logic of why things are set on the form in some cases &
1309 // the logic around when $this->_params is used compared to other params arrays.
1310 $this->_params
= array_merge($params, $this->_params
);
1311 $this->setRecurringMembershipParams();
1312 if ($this->_paymentProcessor
&&
1313 $this->_paymentProcessor
['object']->supports('preApproval')
1315 $this->handlePreApproval($this->_params
);
1319 if (empty($this->_values
['is_confirm_enabled'])) {
1320 $this->skipToThankYouPage();
1326 * Assign the billing mode to the template.
1328 * This is required for legacy support for contributeMode in templates.
1330 * The goal is to remove this parameter & use more relevant parameters.
1332 protected function setContributeMode() {
1333 switch ($this->_paymentProcessor
['billing_mode']) {
1334 case CRM_Core_Payment
::BILLING_MODE_FORM
:
1335 $this->set('contributeMode', 'direct');
1338 case CRM_Core_Payment
::BILLING_MODE_BUTTON
:
1339 $this->set('contributeMode', 'express');
1342 case CRM_Core_Payment
::BILLING_MODE_NOTIFY
:
1343 $this->set('contributeMode', 'notify');
1350 * Process confirm function and pass browser to the thank you page.
1352 protected function skipToThankYouPage() {
1353 // call the post process hook for the main page before we switch to confirm
1354 $this->postProcessHook();
1356 // build the confirm page
1357 $confirmForm = &$this->controller
->_pages
['Confirm'];
1358 $confirmForm->preProcess();
1359 $confirmForm->buildQuickForm();
1361 // the confirmation page is valid
1362 $data = &$this->controller
->container();
1363 $data['valid']['Confirm'] = 1;
1365 // confirm the contribution
1366 // mainProcess calls the hook also
1367 $confirmForm->mainProcess();
1368 $qfKey = $this->controller
->_key
;
1370 // redirect to thank you page
1371 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey=$qfKey", TRUE, NULL, FALSE));