3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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 $_paymentProcessors;
46 public $_membershipTypeValues;
48 public $_useForMember;
51 * Array of payment related fields to potentially display on this form (generally credit card or debit card fields). This is rendered via billingBlock.tpl
54 public $_paymentFields = array();
56 protected $_paymentProcessorID;
60 * Set variables up before form is built.
62 public function preProcess() {
65 $this->_paymentProcessors
= $this->get('paymentProcessors');
66 $this->preProcessPaymentOptions();
68 $this->assignFormVariablesByContributionID();
70 // Make the contributionPageID available to the template
71 $this->assign('contributionPageID', $this->_id
);
72 $this->assign('ccid', $this->_ccid
);
73 $this->assign('isShare', CRM_Utils_Array
::value('is_share', $this->_values
));
74 $this->assign('isConfirmEnabled', CRM_Utils_Array
::value('is_confirm_enabled', $this->_values
));
76 $this->assign('reset', CRM_Utils_Request
::retrieve('reset', 'Boolean'));
77 $this->assign('mainDisplay', CRM_Utils_Request
::retrieve('_qf_Main_display', 'Boolean',
78 CRM_Core_DAO
::$_nullObject));
80 if (!empty($this->_pcpInfo
['id']) && !empty($this->_pcpInfo
['intro_text'])) {
81 $this->assign('intro_text', $this->_pcpInfo
['intro_text']);
83 elseif (!empty($this->_values
['intro_text'])) {
84 $this->assign('intro_text', $this->_values
['intro_text']);
87 $qParams = "reset=1&id={$this->_id}";
88 if ($pcpId = CRM_Utils_Array
::value('pcp_id', $this->_pcpInfo
)) {
89 $qParams .= "&pcpId={$pcpId}";
91 $this->assign('qParams', $qParams);
93 if (!empty($this->_values
['footer_text'])) {
94 $this->assign('footer_text', $this->_values
['footer_text']);
99 * Set the default values.
101 public function setDefaultValues() {
102 // check if the user is registered and we have a contact ID
103 $contactID = $this->getContactID();
105 if (!empty($contactID)) {
107 $removeCustomFieldTypes = array('Contribution', 'Membership');
108 $contribFields = CRM_Contribute_BAO_Contribution
::getContributionFields();
110 // remove component related fields
111 foreach ($this->_fields
as $name => $dontCare) {
112 //don't set custom data Used for Contribution (CRM-1344)
113 if (substr($name, 0, 7) == 'custom_') {
114 $id = substr($name, 7);
115 if (!CRM_Core_BAO_CustomGroup
::checkCustomField($id, $removeCustomFieldTypes)) {
118 // ignore component fields
120 elseif (array_key_exists($name, $contribFields) ||
(substr($name, 0, 11) == 'membership_') ||
(substr($name, 0, 13) == 'contribution_')) {
126 if (!empty($fields)) {
127 CRM_Core_BAO_UFGroup
::setProfileDefaults($contactID, $fields, $this->_defaults
);
130 $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
131 $this->_defaults
= array_merge($this->_defaults
, $billingDefaults);
133 if (!empty($this->_ccid
) && !empty($this->_pendingAmount
)) {
134 $this->_defaults
['total_amount'] = CRM_Utils_Money
::format($this->_pendingAmount
, NULL, '%a');
138 * hack to simplify credit card entry for testing
140 * $this->_defaults['credit_card_type'] = 'Visa';
141 * $this->_defaults['amount'] = 168;
142 * $this->_defaults['credit_card_number'] = '4111111111111111';
143 * $this->_defaults['cvv2'] = '000';
144 * $this->_defaults['credit_card_exp_date'] = array('Y' => date('Y')+1, 'M' => '05');
145 * // hack to simplify direct debit entry for testing
146 * $this->_defaults['account_holder'] = 'Max Müller';
147 * $this->_defaults['bank_account_number'] = '12345678';
148 * $this->_defaults['bank_identification_number'] = '12030000';
149 * $this->_defaults['bank_name'] = 'Bankname';
152 //build set default for pledge overdue payment.
153 if (!empty($this->_values
['pledge_id'])) {
154 //used to record completed pledge payment ids used later for honor default
155 $completedContributionIds = array();
156 $pledgePayments = CRM_Pledge_BAO_PledgePayment
::getPledgePayments($this->_values
['pledge_id']);
160 foreach ($pledgePayments as $payId => $value) {
161 if ($value['status'] == 'Overdue') {
162 $this->_defaults
['pledge_amount'][$payId] = 1;
163 $paymentAmount +
= $value['scheduled_amount'];
165 elseif (!$duePayment && $value['status'] == 'Pending') {
166 $this->_defaults
['pledge_amount'][$payId] = 1;
167 $paymentAmount +
= $value['scheduled_amount'];
170 elseif ($value['status'] == 'Completed' && $value['contribution_id']) {
171 $completedContributionIds[] = $value['contribution_id'];
174 $this->_defaults
['price_' . $this->_priceSetId
] = $paymentAmount;
176 if (count($completedContributionIds)) {
177 $softCredit = array();
178 foreach ($completedContributionIds as $id) {
179 $softCredit = CRM_Contribute_BAO_ContributionSoft
::getSoftContribution($id);
181 if (isset($softCredit['soft_credit'])) {
182 $this->_defaults
['soft_credit_type_id'] = $softCredit['soft_credit'][1]['soft_credit_type'];
184 //since honoree profile fieldname of fields are prefixed with 'honor'
185 //we need to reformat the fieldname to append prefix during setting default values
186 CRM_Core_BAO_UFGroup
::setProfileDefaults(
187 $softCredit['soft_credit'][1]['contact_id'],
188 CRM_Core_BAO_UFGroup
::getFields($this->_honoreeProfileId
),
191 foreach ($defaults as $fieldName => $value) {
192 $this->_defaults
['honor[' . $fieldName . ']'] = $value;
197 elseif (!empty($this->_values
['pledge_block_id'])) {
198 //set default to one time contribution.
199 $this->_defaults
['is_pledge'] = 0;
202 // to process Custom data that are appended to URL
203 $getDefaults = CRM_Core_BAO_CustomGroup
::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
204 $this->_defaults
= array_merge($this->_defaults
, $getDefaults);
206 $config = CRM_Core_Config
::singleton();
207 // set default country from config if no country set
208 if (empty($this->_defaults
["billing_country_id-{$this->_bltID}"])) {
209 $this->_defaults
["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
212 // set default state/province from config if no state/province set
213 if (empty($this->_defaults
["billing_state_province_id-{$this->_bltID}"])) {
214 $this->_defaults
["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince
;
217 $entityId = $memtypeID = NULL;
218 if ($this->_priceSetId
) {
219 if (($this->_useForMember
&& !empty($this->_currentMemberships
)) ||
$this->_defaultMemTypeId
) {
220 $selectedCurrentMemTypes = array();
221 foreach ($this->_priceSet
['fields'] as $key => $val) {
222 foreach ($val['options'] as $keys => $values) {
223 $opMemTypeId = CRM_Utils_Array
::value('membership_type_id', $values);
224 $priceFieldName = 'price_' . $values['price_field_id'];
225 $priceFieldValue = CRM_Price_BAO_PriceSet
::getPriceFieldValueFromURL($this, $priceFieldName);
226 if (!empty($priceFieldValue)) {
227 CRM_Price_BAO_PriceSet
::setDefaultPriceSetField($priceFieldName, $priceFieldValue, $val['html_type'], $this->_defaults
);
228 // break here to prevent overwriting of default due to 'is_default'
229 // option configuration or setting of current membership or
230 // membership for related organization.
231 // The value sent via URL get's higher priority.
234 elseif ($opMemTypeId &&
235 in_array($opMemTypeId, $this->_currentMemberships
) &&
236 !in_array($opMemTypeId, $selectedCurrentMemTypes)
238 CRM_Price_BAO_PriceSet
::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults
);
239 $memtypeID = $selectedCurrentMemTypes[] = $values['membership_type_id'];
241 elseif (!empty($values['is_default']) &&
243 (!isset($this->_defaults
[$priceFieldName]) ||
244 ($val['html_type'] == 'CheckBox' &&
245 !isset($this->_defaults
[$priceFieldName][$keys]))
247 CRM_Price_BAO_PriceSet
::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults
);
248 $memtypeID = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_defaults
[$priceFieldName], 'membership_type_id');
252 $entityId = CRM_Utils_Array
::value('id', CRM_Member_BAO_Membership
::getContactMembership($contactID, $memtypeID, NULL));
255 CRM_Price_BAO_PriceSet
::setDefaultPriceSet($this, $this->_defaults
);
259 //set custom field defaults set by admin if value is not set
260 if (!empty($this->_fields
)) {
261 //load default campaign from page.
262 if (array_key_exists('contribution_campaign_id', $this->_fields
)) {
263 $this->_defaults
['contribution_campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
);
266 //set custom field defaults
267 foreach ($this->_fields
as $name => $field) {
268 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
269 if (!isset($this->_defaults
[$name])) {
270 CRM_Core_BAO_CustomField
::setProfileDefaults($customFieldID, $name, $this->_defaults
,
271 $entityId, CRM_Profile_Form
::MODE_REGISTER
278 if (!empty($this->_paymentProcessors
)) {
279 foreach ($this->_paymentProcessors
as $pid => $value) {
280 if (!empty($value['is_default'])) {
281 $this->_defaults
['payment_processor_id'] = $pid;
286 return $this->_defaults
;
290 * Build the form object.
292 public function buildQuickForm() {
293 // build profiles first so that we can determine address fields etc
294 // and then show copy address checkbox
295 if (empty($this->_ccid
)) {
296 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre');
297 $this->buildCustom($this->_values
['custom_post_id'], 'customPost');
299 // CRM-18399: used by template to pass pre profile id as a url arg
300 $this->assign('custom_pre_id', $this->_values
['custom_pre_id']);
302 $this->buildComponentForm($this->_id
, $this);
305 // Build payment processor form
306 CRM_Core_Payment_ProcessorForm
::buildQuickForm($this);
308 $config = CRM_Core_Config
::singleton();
310 $contactID = $this->getContactID();
312 $this->assign('contact_id', $contactID);
313 $this->assign('display_name', CRM_Contact_BAO_Contact
::displayName($contactID));
316 $this->applyFilter('__ALL__', 'trim');
317 if (empty($this->_ccid
)) {
318 if ($this->_emailExists
== FALSE) {
319 $this->add('text', "email-{$this->_bltID}",
321 array('size' => 30, 'maxlength' => 60, 'class' => 'email'),
324 $this->assign('showMainEmail', TRUE);
325 $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email');
329 $this->addElement('hidden', "email-{$this->_bltID}", 1);
330 $this->add('text', 'total_amount', ts('Total Amount'), array('readonly' => TRUE), FALSE);
333 //@todo - this should be replaced by a check as to whether billing fields are set
334 $onlinePaymentProcessorEnabled = FALSE;
335 if (!empty($this->_paymentProcessors
)) {
336 foreach ($this->_paymentProcessors
as $key => $name) {
337 if ($name['billing_mode'] == 1) {
338 $onlinePaymentProcessorEnabled = TRUE;
340 $pps[$key] = $name['name'];
343 if (!empty($this->_values
['is_pay_later'])) {
344 $pps[0] = $this->_values
['pay_later_text'];
347 if (count($pps) > 1) {
348 $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
352 elseif (!empty($pps)) {
353 $key = array_keys($pps);
354 $key = array_pop($key);
355 $this->addElement('hidden', 'payment_processor_id', $key);
357 $this->assign('is_pay_later', $this->_values
['is_pay_later']);
358 $this->assign('pay_later_text', $this->_values
['pay_later_text']);
362 $contactID = $this->getContactID();
363 if ($this->getContactID() === 0) {
364 $this->addCidZeroOptions($onlinePaymentProcessorEnabled);
367 //build pledge block.
368 $this->_useForMember
= 0;
369 //don't build membership block when pledge_id is passed
370 if (empty($this->_values
['pledge_id']) && empty($this->_ccid
)) {
371 $this->_separateMembershipPayment
= FALSE;
372 if (in_array('CiviMember', $config->enableComponents
)) {
374 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
378 if ($this->_priceSetId
&&
379 (CRM_Core_Component
::getComponentID('CiviMember') == CRM_Utils_Array
::value('extends', $this->_priceSet
))
381 $this->_useForMember
= 1;
382 $this->set('useForMember', $this->_useForMember
);
385 $this->_separateMembershipPayment
= $this->buildMembershipBlock(
386 $this->_membershipContactID
,
391 $this->set('separateMembershipPayment', $this->_separateMembershipPayment
);
393 $this->assign('useForMember', $this->_useForMember
);
394 // If we configured price set for contribution page
395 // we are not allow membership signup as well as any
396 // other contribution amount field, CRM-5095
397 if (isset($this->_priceSetId
) && $this->_priceSetId
) {
398 $this->add('hidden', 'priceSetId', $this->_priceSetId
);
399 // build price set form.
400 $this->set('priceSetId', $this->_priceSetId
);
401 if (empty($this->_ccid
)) {
402 CRM_Price_BAO_PriceSet
::buildPriceSet($this);
404 if ($this->_values
['is_monetary'] &&
405 $this->_values
['is_recur'] && empty($this->_values
['pledge_id'])
407 self
::buildRecur($this);
411 if ($this->_priceSetId
&& empty($this->_ccid
)) {
412 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
413 if ($is_quick_config) {
414 $this->_useForMember
= 0;
415 $this->set('useForMember', $this->_useForMember
);
419 //we allow premium for pledge during pledge creation only.
420 if (empty($this->_values
['pledge_id']) && empty($this->_ccid
)) {
421 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, TRUE);
424 //don't build pledge block when mid is passed
425 if (!$this->_mid
&& empty($this->_ccid
)) {
426 $config = CRM_Core_Config
::singleton();
427 if (in_array('CiviPledge', $config->enableComponents
) && !empty($this->_values
['pledge_block_id'])) {
428 CRM_Pledge_BAO_PledgeBlock
::buildPledgeBlock($this);
432 //to create an cms user
433 if (!$this->_contactID
&& empty($this->_ccid
)) {
434 $createCMSUser = FALSE;
436 if ($this->_values
['custom_pre_id']) {
437 $profileID = $this->_values
['custom_pre_id'];
438 $createCMSUser = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
441 if (!$createCMSUser &&
442 $this->_values
['custom_post_id']
444 if (!is_array($this->_values
['custom_post_id'])) {
445 $profileIDs = array($this->_values
['custom_post_id']);
448 $profileIDs = $this->_values
['custom_post_id'];
450 foreach ($profileIDs as $pid) {
451 if (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
453 $createCMSUser = TRUE;
459 if ($createCMSUser) {
460 CRM_Core_BAO_CMSUser
::buildForm($this, $profileID, TRUE);
463 if ($this->_pcpId
&& empty($this->_ccid
)) {
464 if ($pcpSupporter = CRM_PCP_BAO_PCP
::displayName($this->_pcpId
)) {
465 $pcp_supporter_text = ts('This contribution is being made thanks to the effort of <strong>%1</strong>, who supports our campaign.', array(1 => $pcpSupporter));
466 // 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.
467 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($this->_id
, 'contribute');
469 $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!");
471 $this->assign('pcpSupporterText', $pcp_supporter_text);
473 $prms = array('id' => $this->_pcpId
);
474 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
475 if ($pcpInfo['is_honor_roll']) {
476 $this->assign('isHonor', TRUE);
477 $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL,
478 array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
480 $extraOption = array('onclick' => "return pcpAnonymous( );");
482 $elements[] = &$this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
483 $elements[] = &$this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
484 $this->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
486 $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
487 $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
490 if (empty($this->_values
['fee']) && empty($this->_ccid
)) {
491 CRM_Core_Error
::fatal(ts('This page does not have any price fields configured or you may not have permission for them. Please contact the site administrator for more details.'));
494 //we have to load confirm contribution button in template
495 //when multiple payment processor as the user
496 //can toggle with payment processor selection
497 $billingModePaymentProcessors = 0;
498 if (!empty($this->_paymentProcessors
)) {
499 foreach ($this->_paymentProcessors
as $key => $values) {
500 if ($values['billing_mode'] == CRM_Core_Payment
::BILLING_MODE_BUTTON
) {
501 $billingModePaymentProcessors++
;
506 if ($billingModePaymentProcessors && count($this->_paymentProcessors
) == $billingModePaymentProcessors) {
507 $allAreBillingModeProcessors = TRUE;
510 $allAreBillingModeProcessors = FALSE;
513 if (!($allAreBillingModeProcessors && !$this->_values
['is_pay_later'])) {
514 $submitButton = array(
516 'name' => CRM_Utils_Array
::value('is_confirm_enabled', $this->_values
) ?
ts('Confirm Contribution') : ts('Contribute'),
517 'spacing' => ' ',
520 // Add submit-once behavior when confirm page disabled
521 if (empty($this->_values
['is_confirm_enabled'])) {
522 $submitButton['js'] = array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');");
524 //change button name for updating contribution
525 if (!empty($this->_ccid
)) {
526 $submitButton['name'] = ts('Confirm Payment');
528 $this->addButtons(array($submitButton));
531 $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
535 * Build elements to collect information for recurring contributions.
538 * @param CRM_Core_Form $form
540 public static function buildRecur(&$form) {
541 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionRecur');
542 $className = get_class($form);
544 $form->assign('is_recur_interval', CRM_Utils_Array
::value('is_recur_interval', $form->_values
));
545 $form->assign('is_recur_installments', CRM_Utils_Array
::value('is_recur_installments', $form->_values
));
546 $paymentObject = $form->getVar('_paymentObject');
547 if ($paymentObject) {
548 $form->assign('recurringHelpText', $paymentObject->getText('contributionPageRecurringHelp', array(
549 'is_recur_installments' => !empty($form->_values
['is_recur_installments']),
550 'is_email_receipt' => !empty($form->_values
['is_email_receipt']),
554 $form->add('checkbox', 'is_recur', ts('I want to contribute this amount'), NULL);
556 if (!empty($form->_values
['is_recur_interval']) ||
$className == 'CRM_Contribute_Form_Contribution') {
557 $form->add('text', 'frequency_interval', ts('Every'), $attributes['frequency_interval']);
558 $form->addRule('frequency_interval', ts('Frequency must be a whole number (EXAMPLE: Every 3 months).'), 'integer');
561 // make sure frequency_interval is submitted as 1 if given no choice to user.
562 $form->add('hidden', 'frequency_interval', 1);
565 $frUnits = CRM_Utils_Array
::value('recur_frequency_unit', $form->_values
);
566 if (empty($frUnits) &&
567 $className == 'CRM_Contribute_Form_Contribution'
569 $frUnits = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
570 CRM_Core_OptionGroup
::values('recur_frequency_units')
574 $unitVals = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $frUnits);
576 // CRM 10860, display text instead of a dropdown if there's only 1 frequency unit
577 if (count($unitVals) == 1) {
578 $form->assign('one_frequency_unit', TRUE);
579 $unit = $unitVals[0];
580 $form->add('hidden', 'frequency_unit', $unit);
581 if (!empty($form->_values
['is_recur_interval']) ||
$className == 'CRM_Contribute_Form_Contribution') {
584 $form->assign('frequency_unit', $unit);
587 $form->assign('one_frequency_unit', FALSE);
589 $frequencyUnits = CRM_Core_OptionGroup
::values('recur_frequency_units', FALSE, FALSE, TRUE);
590 foreach ($unitVals as $key => $val) {
591 if (array_key_exists($val, $frequencyUnits)) {
592 $units[$val] = $frequencyUnits[$val];
593 if (!empty($form->_values
['is_recur_interval']) ||
$className == 'CRM_Contribute_Form_Contribution') {
594 $units[$val] = "{$frequencyUnits[$val]}(s)";
598 $frequencyUnit = &$form->add('select', 'frequency_unit', NULL, $units);
601 // FIXME: Ideally we should freeze select box if there is only
602 // one option but looks there is some problem /w QF freeze.
603 //if ( count( $units ) == 1 ) {
604 //$frequencyUnit->freeze( );
607 $form->add('text', 'installments', ts('installments'),
608 $attributes['installments']
610 $form->addRule('installments', ts('Number of installments must be a whole number.'), 'integer');
616 * @param array $fields
617 * The input form values.
618 * @param array $files
619 * The uploaded files if any.
620 * @param CRM_Core_Form $self
623 * true if no errors, else array of errors
625 public static function formRule($fields, $files, $self) {
627 $amount = self
::computeAmount($fields, $self->_values
);
628 if (CRM_Utils_Array
::value('auto_renew', $fields) &&
629 CRM_Utils_Array
::value('payment_processor_id', $fields) == 0
631 $errors['auto_renew'] = ts('You cannot have auto-renewal on if you are paying later.');
634 if ((!empty($fields['selectMembership']) &&
635 $fields['selectMembership'] != 'no_thanks'
637 (!empty($fields['priceSetId']) &&
641 $isTest = ($self->_action
& CRM_Core_Action
::PREVIEW
) ?
TRUE : FALSE;
642 $lifeMember = CRM_Member_BAO_Membership
::getAllContactMembership($self->_membershipContactID
, $isTest, TRUE);
644 $membershipOrgDetails = CRM_Member_BAO_MembershipType
::getMembershipTypeOrganization();
646 $unallowedOrgs = array();
647 foreach (array_keys($lifeMember) as $memTypeId) {
648 $unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
652 //check for atleast one pricefields should be selected
653 if (!empty($fields['priceSetId']) && empty($self->_ccid
)) {
654 $priceField = new CRM_Price_DAO_PriceField();
655 $priceField->price_set_id
= $fields['priceSetId'];
656 $priceField->orderBy('weight');
660 $membershipIsActive = TRUE;
661 $previousId = $otherAmount = FALSE;
662 while ($priceField->fetch()) {
664 if ($self->_quickConfig
&& ($priceField->name
== 'contribution_amount' ||
$priceField->name
== 'membership_amount')) {
665 $previousId = $priceField->id
;
666 if ($priceField->name
== 'membership_amount' && !$priceField->is_active
) {
667 $membershipIsActive = FALSE;
670 if ($priceField->name
== 'other_amount') {
671 if ($self->_quickConfig
&& empty($fields["price_{$priceField->id}"]) &&
672 array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values
['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])
674 $otherAmount = $priceField->id
;
676 elseif (!empty($fields["price_{$priceField->id}"])) {
677 $otherAmountVal = CRM_Utils_Rule
::cleanMoney($fields["price_{$priceField->id}"]);
678 $min = CRM_Utils_Array
::value('min_amount', $self->_values
);
679 $max = CRM_Utils_Array
::value('max_amount', $self->_values
);
680 if ($min && $otherAmountVal < $min) {
681 $errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1',
685 if ($max && $otherAmountVal > $max) {
686 $errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.',
692 if (!empty($fields["price_{$priceField->id}"]) ||
($previousId == $priceField->id
&& isset($fields["price_{$previousId}"])
693 && empty($fields["price_{$previousId}"]))
695 $check[] = $priceField->id
;
699 $currentMemberships = NULL;
700 if ($membershipIsActive) {
701 $is_test = $self->_mode
!= 'live' ?
1 : 0;
702 $memContactID = $self->_membershipContactID
;
704 // For anonymous user check using dedupe rule
705 // if user has Cancelled Membership
706 if (!$memContactID) {
707 $memContactID = CRM_Contact_BAO_Contact
::getFirstDuplicateContact($fields, 'Individual', 'Unsupervised', array(), FALSE);
709 $currentMemberships = CRM_Member_BAO_Membership
::getContactsCancelledMembership($memContactID,
713 $errorText = 'Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.';
714 foreach ($self->_values
['fee'] as $fieldKey => $fieldValue) {
715 if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array
::value('price_' . $fieldKey, $fields)) {
716 if (!is_array($fields['price_' . $fieldKey]) && isset($fieldValue['options'][$fields['price_' . $fieldKey]])) {
717 if (array_key_exists('membership_type_id', $fieldValue['options'][$fields['price_' . $fieldKey]])
718 && in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships)
720 $errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant
::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])));
724 if (is_array($fields['price_' . $fieldKey])) {
725 foreach (array_keys($fields['price_' . $fieldKey]) as $key) {
726 if (array_key_exists('membership_type_id', $fieldValue['options'][$key])
727 && in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships)
729 $errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant
::membershipType($fieldValue['options'][$key]['membership_type_id'])));
739 if ($membershipIsActive && !$self->_membershipBlock
['is_required']
740 && $self->_values
['amount_block_is_active']
742 $membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
743 foreach ($self->_values
['fee'] as $fieldKey => $fieldValue) {
744 // if 'No thank you' membership is selected then set $membershipFieldId
745 if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array
::value('price_' . $fieldKey, $fields) == 0) {
746 $membershipFieldId = $fieldKey;
748 elseif ($membershipFieldId) {
749 if ($fieldValue['name'] == 'other_amount') {
750 $otherFieldId = $fieldKey;
752 elseif ($fieldValue['name'] == 'contribution_amount') {
753 $contributionFieldId = $fieldKey;
756 if (!$errorKey || CRM_Utils_Array
::value('price_' . $contributionFieldId, $fields) == '0') {
757 $errorKey = $fieldKey;
761 // $membershipFieldId is set and additional amount is 'No thank you' or NULL then throw error
762 if ($membershipFieldId && !(CRM_Utils_Array
::value('price_' . $contributionFieldId, $fields, -1) > 0) && empty($fields['price_' . $otherFieldId])) {
763 $errors["price_{$errorKey}"] = ts('Additional Contribution is required.');
766 if (empty($check) && empty($self->_ccid
)) {
767 if ($self->_useForMember
== 1 && $membershipIsActive) {
768 $errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
771 $errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
774 if ($otherAmount && !empty($check)) {
775 $errors["price_{$otherAmount}"] = ts('Amount is required field.');
778 if ($self->_useForMember
== 1 && !empty($check) && $membershipIsActive) {
779 $priceFieldIDS = array();
780 $priceFieldMemTypes = array();
782 foreach ($self->_priceSet
['fields'] as $priceId => $value) {
783 if (!empty($fields['price_' . $priceId]) ||
($self->_quickConfig
&& $value['name'] == 'membership_amount' && empty($self->_membershipBlock
['is_required']))) {
784 if (!empty($fields['price_' . $priceId]) && is_array($fields['price_' . $priceId])) {
785 foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
787 $priceFieldIDS[] = $priceFldVal;
791 elseif (!$value['is_enter_qty'] && !empty($fields['price_' . $priceId])) {
792 // The check for {!$value['is_enter_qty']} is done since, quantity fields allow entering
793 // quantity. And the quantity can't be conisdered as civicrm_price_field_value.id, CRM-9577
794 $priceFieldIDS[] = $fields['price_' . $priceId];
797 if (!empty($value['options'])) {
798 foreach ($value['options'] as $val) {
799 if (!empty($val['membership_type_id']) && (
800 ($fields['price_' . $priceId] == $val['id']) ||
801 (isset($fields['price_' . $priceId]) && !empty($fields['price_' . $priceId][$val['id']]))
804 $priceFieldMemTypes[] = $val['membership_type_id'];
811 if (!empty($lifeMember)) {
812 foreach ($priceFieldIDS as $priceFieldId) {
813 if (($id = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) &&
814 in_array($membershipOrgDetails[$id], $unallowedOrgs)
816 $errors['_qf_default'] = ts('You already have a lifetime membership and cannot select a membership with a shorter term.');
822 if (!empty($priceFieldIDS)) {
823 $ids = implode(',', $priceFieldIDS);
825 $priceFieldIDS['id'] = $fields['priceSetId'];
826 $self->set('memberPriceFieldIDS', $priceFieldIDS);
827 $count = CRM_Price_BAO_PriceSet
::getMembershipCount($ids);
828 foreach ($count as $id => $occurrence) {
829 if ($occurrence > 1) {
830 $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.');
835 if (empty($priceFieldMemTypes) && $self->_membershipBlock
['is_required'] == 1) {
836 $errors['_qf_default'] = ts('Please select at least one membership option.');
840 CRM_Price_BAO_PriceSet
::processAmount($self->_values
['fee'],
844 $minAmt = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $fields['priceSetId'], 'min_amount');
845 if ($fields['amount'] < 0) {
846 $errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
848 elseif (!empty($minAmt) && $fields['amount'] < $minAmt) {
849 $errors['_qf_default'] = ts('A minimum amount of %1 should be selected from Contribution(s).', array(
850 1 => CRM_Utils_Money
::format($minAmt),
854 $amount = $fields['amount'];
857 if (isset($fields['selectProduct']) &&
858 $fields['selectProduct'] != 'no_thanks'
860 $productDAO = new CRM_Contribute_DAO_Product();
861 $productDAO->id
= $fields['selectProduct'];
862 $productDAO->find(TRUE);
863 $min_amount = $productDAO->min_contribution
;
865 if ($amount < $min_amount) {
866 $errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money
::format($min_amount)));
867 CRM_Core_Session
::setStatus($errors['selectProduct']);
871 //CRM-16285 - Function to handle validation errors on form, for recurring contribution field.
872 CRM_Contribute_BAO_ContributionRecur
::validateRecurContribution($fields, $files, $self, $errors);
874 if (!empty($fields['is_recur']) &&
875 CRM_Utils_Array
::value('payment_processor_id', $fields) == 0
877 $errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
880 // validate PCP fields - if not anonymous, we need a nick name value
881 if ($self->_pcpId
&& !empty($fields['pcp_display_in_roll']) &&
882 (CRM_Utils_Array
::value('pcp_is_anonymous', $fields) == 0) &&
883 CRM_Utils_Array
::value('pcp_roll_nickname', $fields) == ''
885 $errors['pcp_roll_nickname'] = ts('Please enter a name to include in the Honor Roll, or select \'contribute anonymously\'.');
888 // return if this is express mode
889 $config = CRM_Core_Config
::singleton();
890 if ($self->_paymentProcessor
&&
891 $self->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_BUTTON
893 if (!empty($fields[$self->_expressButtonName
. '_x']) ||
!empty($fields[$self->_expressButtonName
. '_y']) ||
894 CRM_Utils_Array
::value($self->_expressButtonName
, $fields)
900 //validate the pledge fields.
901 if (!empty($self->_values
['pledge_block_id'])) {
902 //validation for pledge payment.
903 if (!empty($self->_values
['pledge_id'])) {
904 if (empty($fields['pledge_amount'])) {
905 $errors['pledge_amount'] = ts('At least one payment option needs to be checked.');
908 elseif (!empty($fields['is_pledge'])) {
909 if (CRM_Utils_Rule
::positiveInteger(CRM_Utils_Array
::value('pledge_installments', $fields)) == FALSE) {
910 $errors['pledge_installments'] = ts('Please enter a valid number of pledge installments.');
913 if (CRM_Utils_Array
::value('pledge_installments', $fields) == NULL) {
914 $errors['pledge_installments'] = ts('Pledge Installments is required field.');
916 elseif (CRM_Utils_Array
::value('pledge_installments', $fields) == 1) {
917 $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.');
919 elseif (CRM_Utils_Array
::value('pledge_installments', $fields) == 0) {
920 $errors['pledge_installments'] = ts('Pledge Installments field must be > 1.');
924 //validation for Pledge Frequency Interval.
925 if (CRM_Utils_Rule
::positiveInteger(CRM_Utils_Array
::value('pledge_frequency_interval', $fields)) == FALSE) {
926 $errors['pledge_frequency_interval'] = ts('Please enter a valid Pledge Frequency Interval.');
929 if (CRM_Utils_Array
::value('pledge_frequency_interval', $fields) == NULL) {
930 $errors['pledge_frequency_interval'] = ts('Pledge Frequency Interval. is required field.');
932 elseif (CRM_Utils_Array
::value('pledge_frequency_interval', $fields) == 0) {
933 $errors['pledge_frequency_interval'] = ts('Pledge frequency interval field must be > 0');
939 // if the user has chosen a free membership or the amount is less than zero
940 // i.e. we don't need to validate payment related fields or profiles.
941 if ((float) $amount <= 0.0) {
945 if (CRM_Utils_Array
::value('payment_processor_id', $fields) == NULL) {
946 $errors['payment_processor_id'] = ts('Payment Method is a required field.');
949 CRM_Core_Payment_Form
::validatePaymentInstrument(
950 $fields['payment_processor_id'],
953 (!$self->_isBillingAddressRequiredForPayLater ?
NULL : 'billing')
957 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
958 if ($greetingType = CRM_Utils_Array
::value($greeting, $fields)) {
959 $customizedValue = CRM_Core_OptionGroup
::getValue($greeting, 'Customized', 'name');
960 if ($customizedValue == $greetingType && empty($fielse[$greeting . '_custom'])) {
961 $errors[$greeting . '_custom'] = ts('Custom %1 is a required field if %1 is of type Customized.',
962 array(1 => ucwords(str_replace('_', " ", $greeting)))
968 return empty($errors) ?
TRUE : $errors;
972 * Compute amount to be paid.
974 * @param array $params
975 * @param array $formValues
977 * @return int|mixed|null|string
979 public static function computeAmount($params, $formValues) {
981 // First clean up the other amount field if present.
982 if (isset($params['amount_other'])) {
983 $params['amount_other'] = CRM_Utils_Rule
::cleanMoney($params['amount_other']);
986 if (CRM_Utils_Array
::value('amount', $params) == 'amount_other_radio' ||
!empty($params['amount_other'])) {
987 $amount = $params['amount_other'];
989 elseif (!empty($params['pledge_amount'])) {
990 foreach ($params['pledge_amount'] as $paymentId => $dontCare) {
991 $amount +
= CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount');
995 if (!empty($formValues['amount'])) {
996 $amountID = CRM_Utils_Array
::value('amount', $params);
999 // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
1000 // function to get correct amount level consistently. Remove setting of the amount level in
1001 // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
1002 // to cover all variants.
1003 $params['amount_level'] = CRM_Utils_Array
::value('label', $formValues[$amountID]);
1004 $amount = CRM_Utils_Array
::value('value', $formValues[$amountID]);
1012 * Process the form submission.
1014 public function postProcess() {
1015 // we first reset the confirm page so it accepts new values
1016 $this->controller
->resetPage('Confirm');
1018 // get the submitted form values.
1019 $params = $this->controller
->exportValues($this->_name
);
1020 $this->submit($params);
1022 if (empty($this->_values
['is_confirm_enabled'])) {
1023 $this->skipToThankYouPage();
1031 * This is the guts of the postProcess made also accessible to the test suite.
1033 * @param array $params
1036 public function submit($params) {
1037 //carry campaign from profile.
1038 if (array_key_exists('contribution_campaign_id', $params)) {
1039 $params['campaign_id'] = $params['contribution_campaign_id'];
1042 $params['currencyID'] = CRM_Core_Config
::singleton()->defaultCurrency
;
1044 // @todo refactor this & leverage it from the unit tests.
1045 if (!empty($params['priceSetId'])) {
1046 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
1047 if ($is_quick_config) {
1048 $priceField = new CRM_Price_DAO_PriceField();
1049 $priceField->price_set_id
= $params['priceSetId'];
1050 $priceField->orderBy('weight');
1051 $priceField->find();
1053 $priceOptions = array();
1054 while ($priceField->fetch()) {
1055 CRM_Price_BAO_PriceFieldValue
::getValues($priceField->id
, $priceOptions);
1056 if (($selectedPriceOptionID = CRM_Utils_Array
::value("price_{$priceField->id}", $params)) != FALSE && $selectedPriceOptionID > 0) {
1057 switch ($priceField->name
) {
1058 case 'membership_amount':
1059 $this->_params
['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array
::value('membership_type_id', $priceOptions[$selectedPriceOptionID]);
1060 $this->set('selectMembership', $params['selectMembership']);
1062 case 'contribution_amount':
1063 $params['amount'] = $selectedPriceOptionID;
1064 if ($priceField->name
== 'contribution_amount' ||
1065 ($priceField->name
== 'membership_amount' &&
1066 CRM_Utils_Array
::value('is_separate_payment', $this->_membershipBlock
) == 0)
1068 $this->_values
['amount'] = CRM_Utils_Array
::value('amount', $priceOptions[$selectedPriceOptionID]);
1070 $this->_values
[$selectedPriceOptionID]['value'] = CRM_Utils_Array
::value('amount', $priceOptions[$selectedPriceOptionID]);
1071 $this->_values
[$selectedPriceOptionID]['label'] = CRM_Utils_Array
::value('label', $priceOptions[$selectedPriceOptionID]);
1072 $this->_values
[$selectedPriceOptionID]['amount_id'] = CRM_Utils_Array
::value('id', $priceOptions[$selectedPriceOptionID]);
1073 $this->_values
[$selectedPriceOptionID]['weight'] = CRM_Utils_Array
::value('weight', $priceOptions[$selectedPriceOptionID]);
1076 case 'other_amount':
1077 $params['amount_other'] = $selectedPriceOptionID;
1085 if (!empty($this->_ccid
) && !empty($this->_pendingAmount
)) {
1086 $params['amount'] = $this->_pendingAmount
;
1089 // from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
1090 $params['amount'] = self
::computeAmount($params, $this->_values
);
1093 $params['separate_amount'] = $params['amount'];
1095 if (!empty($params['selectMembership'])) {
1096 if (empty($this->_membershipTypeValues
)) {
1097 $this->_membershipTypeValues
= CRM_Member_BAO_Membership
::buildMembershipTypeValues($this,
1098 (array) $params['selectMembership']
1101 $membershipTypeValues = $this->_membershipTypeValues
[$params['selectMembership']];
1102 $memFee = $membershipTypeValues['minimum_fee'];
1103 if (!$params['amount'] && !$this->_separateMembershipPayment
) {
1104 $params['amount'] = $memFee ?
$memFee : 0;
1107 //If the membership & contribution is used in contribution page & not separate payment
1108 $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
1109 $proceFieldAmount = 0;
1110 if (property_exists($this, '_separateMembershipPayment') && $this->_separateMembershipPayment
== 0) {
1111 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
1112 if ($is_quick_config) {
1113 foreach ($this->_priceSet
['fields'] as $fieldKey => $fieldVal) {
1114 if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
1115 $fieldId = $fieldVal['id'];
1116 $fieldOption = $params['price_' . $fieldId];
1117 $proceFieldAmount +
= $fieldVal['options'][$this->_submitValues
['price_' . $fieldId]]['amount'];
1121 if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' ||
$fieldVal['name'] == 'contribution_amount')) {
1122 $fieldId = $fieldVal['id'];
1123 if ($fieldVal['name'] == 'other_amount') {
1124 $proceFieldAmount +
= $this->_submitValues
['price_' . $fieldId];
1126 elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues
['price_' . $fieldId] > 0) {
1127 $proceFieldAmount +
= $fieldVal['options'][$this->_submitValues
['price_' . $fieldId]]['amount'];
1129 unset($params['price_' . $fieldId]);
1137 if (!isset($params['amount_other'])) {
1138 $this->set('amount_level', CRM_Utils_Array
::value('amount_level', $params));
1141 if (!empty($this->_ccid
)) {
1142 $this->set('lineItem', $this->_lineItem
);
1144 elseif ($priceSetId = CRM_Utils_Array
::value('priceSetId', $params)) {
1145 $lineItem = array();
1146 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
1147 if ($is_quick_config) {
1148 foreach ($this->_values
['fee'] as $key => & $val) {
1149 if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && !empty($params['price_' . $key])) {
1150 // Clean out any currency symbols.
1151 $params['price_' . $key] = CRM_Utils_Rule
::cleanMoney($params['price_' . $key]);
1152 if ($params['price_' . $key] != 0) {
1153 foreach ($val['options'] as $optionKey => & $options) {
1154 $options['amount'] = CRM_Utils_Array
::value('price_' . $key, $params);
1158 $params['price_' . $key] = 1;
1164 if ($this->_membershipBlock
) {
1165 $component = 'membership';
1168 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'], $params, $lineItem[$priceSetId], $component);
1169 if ($params['tax_amount']) {
1170 $this->set('tax_amount', $params['tax_amount']);
1173 if ($proceFieldAmount) {
1174 $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
1175 $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
1176 if (isset($lineItem[$params['priceSetId']][$fieldOption]['tax_amount'])) {
1177 $proceFieldAmount +
= $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
1179 if (!$this->_membershipBlock
['is_separate_payment']) {
1180 //require when separate membership not used
1181 $params['amount'] = $proceFieldAmount;
1184 $this->set('lineItem', $lineItem);
1187 if ($params['amount'] != 0 && (($this->_values
['is_pay_later'] &&
1188 empty($this->_paymentProcessor
) &&
1189 !array_key_exists('hidden_processor', $params)) ||
1190 (CRM_Utils_Array
::value('payment_processor_id', $params) == 0))
1192 $params['is_pay_later'] = 1;
1195 $params['is_pay_later'] = 0;
1198 // Would be nice to someday understand the point of this set.
1199 $this->set('is_pay_later', $params['is_pay_later']);
1200 // assign pay later stuff
1201 $this->_params
['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
1202 $this->assign('is_pay_later', $params['is_pay_later']);
1203 if ($params['is_pay_later']) {
1204 $this->assign('pay_later_text', $this->_values
['pay_later_text']);
1205 $this->assign('pay_later_receipt', CRM_Utils_Array
::value('pay_later_receipt', $this->_values
));
1208 if ($this->_membershipBlock
['is_separate_payment'] && !empty($params['separate_amount'])) {
1209 $this->set('amount', $params['separate_amount']);
1212 $this->set('amount', $params['amount']);
1215 // generate and set an invoiceID for this transaction
1216 $invoiceID = md5(uniqid(rand(), TRUE));
1217 $this->set('invoiceID', $invoiceID);
1218 $params['invoiceID'] = $invoiceID;
1219 $params['description'] = ts('Online Contribution') . ': ' . ((!empty($this->_pcpInfo
['title']) ?
$this->_pcpInfo
['title'] : $this->_values
['title']));
1220 $params['button'] = $this->controller
->getButtonName();
1221 // required only if is_monetary and valid positive amount
1222 // @todo it seems impossible for $memFee to be greater than 0 & $params['amount'] not to
1223 // be & by requiring $memFee down here we make it harder to do a sensible refactoring of the function
1224 // above (ie. extract the amount in a small function).
1225 if ($this->_values
['is_monetary'] &&
1226 !empty($this->_paymentProcessor
) &&
1227 ((float ) $params['amount'] > 0.0 ||
$memFee > 0.0)
1229 // The concept of contributeMode is deprecated - as should be the 'is_monetary' setting.
1230 $this->setContributeMode();
1231 // Really this setting of $this->_params & params within it should be done earlier on in the function
1232 // probably the values determined here should be reused in confirm postProcess as there is no opportunity to alter anything
1233 // on the confirm page. However as we are dealing with a stable release we go as close to where it is used
1235 // In general the form has a lack of clarity of the logic of why things are set on the form in some cases &
1236 // the logic around when $this->_params is used compared to other params arrays.
1237 $this->_params
= array_merge($params, $this->_params
);
1238 $this->setRecurringMembershipParams();
1239 if ($this->_paymentProcessor
&&
1240 $this->_paymentProcessor
['object']->supports('preApproval')
1242 $this->handlePreApproval($this->_params
);
1248 * Assign the billing mode to the template.
1250 * This is required for legacy support for contributeMode in templates.
1252 * The goal is to remove this parameter & use more relevant parameters.
1254 protected function setContributeMode() {
1255 switch ($this->_paymentProcessor
['billing_mode']) {
1256 case CRM_Core_Payment
::BILLING_MODE_FORM
:
1257 $this->set('contributeMode', 'direct');
1260 case CRM_Core_Payment
::BILLING_MODE_BUTTON
:
1261 $this->set('contributeMode', 'express');
1264 case CRM_Core_Payment
::BILLING_MODE_NOTIFY
:
1265 $this->set('contributeMode', 'notify');
1272 * Process confirm function and pass browser to the thank you page.
1274 protected function skipToThankYouPage() {
1275 // call the post process hook for the main page before we switch to confirm
1276 $this->postProcessHook();
1278 // build the confirm page
1279 $confirmForm = &$this->controller
->_pages
['Confirm'];
1280 $confirmForm->preProcess();
1281 $confirmForm->buildQuickForm();
1283 // the confirmation page is valid
1284 $data = &$this->controller
->container();
1285 $data['valid']['Confirm'] = 1;
1287 // confirm the contribution
1288 // mainProcess calls the hook also
1289 $confirmForm->mainProcess();
1290 $qfKey = $this->controller
->_key
;
1292 // redirect to thank you page
1293 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey=$qfKey", TRUE, NULL, FALSE));
1297 * Set form variables if contribution ID is found
1299 public function assignFormVariablesByContributionID() {
1300 if (empty($this->_ccid
)) {
1304 $payment = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_ccid
, 'contribution');
1305 //bounce if the contribution is not pending.
1306 if (empty($payment['balance'])) {
1307 CRM_Core_Error
::statusBounce(ts("Returning since contribution has already been handled."));
1309 if (!empty($payment['total'])) {
1310 $this->_pendingAmount
= $payment['total'];
1311 $this->assign('pendingAmount', $this->_pendingAmount
);
1314 if ($taxAmount = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_ccid
, 'tax_amount')) {
1315 $this->set('tax_amount', $taxAmount);
1316 $this->assign('taxAmount', $taxAmount);
1319 $lineItems = CRM_Price_BAO_LineItem
::getLineItemsByContributionID($this->_ccid
);
1320 foreach (array_keys($lineItems) as $id) {
1321 $lineItems[$id]['id'] = $id;
1323 $itemId = key($lineItems);
1324 if ($itemId && !empty($lineItems[$itemId]['price_field_id'])) {
1325 $this->_priceSetId
= CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id');
1328 if (!empty($lineItems[$itemId]['price_field_id'])) {
1329 $this->_lineItem
[$this->_priceSetId
] = $lineItems;
1331 $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
1332 $this->assign('lineItem', $this->_lineItem
);
1333 $this->assign('is_quick_config', $isQuickConfig);
1334 $this->assign('priceSetID', $this->_priceSetId
);
1338 * Function for unit tests on the postProcess function.
1340 * @param array $params
1342 public function testSubmit($params) {
1343 $_SERVER['REQUEST_METHOD'] = 'GET';
1344 $this->controller
= new CRM_Contribute_Controller_Contribution();
1345 $this->submit($params);