3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * This class generates form components for processing a ontribution
40 class CRM_Contribute_Form_Contribution_Main
extends CRM_Contribute_Form_ContributionBase
{
43 *Define default MembershipType Id
46 public $_defaultMemTypeId;
48 public $_relatedOrganizationFound;
50 public $_onBehalfRequired = FALSE;
51 public $_onbehalf = FALSE;
52 public $_paymentProcessors;
55 public $_membershipTypeValues;
57 public $_useForMember;
63 * Function to set variables up before form is built
68 public function preProcess() {
71 self
::preProcessPaymentOptions($this);
72 if ($this->_snippet
) {
76 // Make the contributionPageID avilable to the template
77 $this->assign('contributionPageID', $this->_id
);
78 $this->assign('isShare', CRM_Utils_Array
::value('is_share', $this->_values
));
79 $this->assign('isConfirmEnabled', CRM_Utils_Array
::value('is_confirm_enabled', $this->_values
));
81 // make sure we have right permission to edit this user
82 $csContactID = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, $this->_userID
);
83 $reset = CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
84 $mainDisplay = CRM_Utils_Request
::retrieve('_qf_Main_display', 'Boolean', CRM_Core_DAO
::$_nullObject);
86 if ($csContactID != $this->_userID
) {
87 if (CRM_Contact_BAO_Contact_Permission
::validateChecksumContact($csContactID, $this)) {
88 $session = CRM_Core_Session
::singleton();
89 $session->set('userID', $csContactID);
90 $this->_userID
= $csContactID;
95 $this->assign('reset', $reset);
99 $this->assign('mainDisplay', $mainDisplay);
102 // Possible values for 'is_for_organization':
103 // * 0 - org profile disabled
104 // * 1 - org profile optional
105 // * 2 - org profile required
106 $this->_onbehalf
= FALSE;
107 if (!empty($this->_values
['is_for_organization'])) {
108 if ($this->_values
['is_for_organization'] == 2) {
109 $this->_onBehalfRequired
= TRUE;
111 // Add organization profile if 1 of the following are true:
112 // If the org profile is required
113 if ($this->_onBehalfRequired ||
114 // Or we are building the form for the first time
116 // Or the user has submitted the form and checked the "On Behalf" checkbox
117 !empty($_POST['is_for_organization'])
119 $this->_onbehalf
= TRUE;
120 CRM_Contribute_Form_Contribution_OnBehalfOf
::preProcess($this);
123 $this->assign('onBehalfRequired', $this->_onBehalfRequired
);
125 if (!empty($this->_pcpInfo
['id']) && !empty($this->_pcpInfo
['intro_text'])) {
126 $this->assign('intro_text', $this->_pcpInfo
['intro_text']);
128 elseif (!empty($this->_values
['intro_text'])) {
129 $this->assign('intro_text', $this->_values
['intro_text']);
132 $qParams = "reset=1&id={$this->_id}";
133 if ($pcpId = CRM_Utils_Array
::value('pcp_id', $this->_pcpInfo
)) {
134 $qParams .= "&pcpId={$pcpId}";
136 $this->assign('qParams', $qParams);
138 if (!empty($this->_values
['footer_text'])) {
139 $this->assign('footer_text', $this->_values
['footer_text']);
143 if (CRM_Utils_Array
::value('is_for_organization', $this->_values
)) {
144 $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
145 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $this->_values
)) {
146 $preProfile = CRM_Core_BAO_UFGroup
::profileGroups($preID);
148 'Individual', 'Organization', 'Household') as $contactType) {
149 if (in_array($contactType, $preProfile) &&
150 (in_array('Membership', $preProfile) ||
151 in_array('Contribution', $preProfile)
154 CRM_Core_Error
::fatal($msg);
159 if ($postID = CRM_Utils_Array
::value('custom_post_id', $this->_values
)) {
160 $postProfile = CRM_Core_BAO_UFGroup
::profileGroups($postID);
162 'Individual', 'Organization', 'Household') as $contactType) {
163 if (in_array($contactType, $postProfile) &&
164 (in_array('Membership', $postProfile) ||
165 in_array('Contribution', $postProfile)
168 CRM_Core_Error
::fatal($msg);
175 function setDefaultValues() {
176 // check if the user is registered and we have a contact ID
177 $contactID = $this->_userID
;
181 $removeCustomFieldTypes = array('Contribution', 'Membership');
182 $contribFields = CRM_Contribute_BAO_Contribution
::getContributionFields();
184 // remove component related fields
185 foreach ($this->_fields
as $name => $dontCare) {
186 //don't set custom data Used for Contribution (CRM-1344)
187 if (substr($name, 0, 7) == 'custom_') {
188 $id = substr($name, 7);
189 if (!CRM_Core_BAO_CustomGroup
::checkCustomField($id, $removeCustomFieldTypes)) {
192 // ignore component fields
194 elseif (array_key_exists($name, $contribFields) ||
(substr($name, 0, 11) == 'membership_') ||
(substr($name, 0, 13) == 'contribution_')) {
201 'first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}",
202 "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}",
204 foreach ($names as $name) {
207 $fields["state_province-{$this->_bltID}"] = 1;
208 $fields["country-{$this->_bltID}"] = 1;
209 $fields["email-{$this->_bltID}"] = 1;
210 $fields['email-Primary'] = 1;
212 CRM_Core_BAO_UFGroup
::setProfileDefaults($contactID, $fields, $this->_defaults
);
214 // use primary email address if billing email address is empty
215 if (empty($this->_defaults
["email-{$this->_bltID}"]) &&
216 !empty($this->_defaults
['email-Primary'])
218 $this->_defaults
["email-{$this->_bltID}"] = $this->_defaults
['email-Primary'];
221 foreach ($names as $name) {
222 if (!empty($this->_defaults
[$name])) {
223 $this->_defaults
['billing_' . $name] = $this->_defaults
[$name];
228 //set custom field defaults set by admin if value is not set
229 if (!empty($this->_fields
)) {
230 //load default campaign from page.
231 if (array_key_exists('contribution_campaign_id', $this->_fields
)) {
232 $this->_defaults
['contribution_campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
);
235 //set custom field defaults
236 foreach ($this->_fields
as $name => $field) {
237 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
238 if (!isset($this->_defaults
[$name])) {
239 CRM_Core_BAO_CustomField
::setProfileDefaults($customFieldID, $name, $this->_defaults
,
240 NULL, CRM_Profile_Form
::MODE_REGISTER
247 //set default membership for membershipship block
248 if ($this->_membershipBlock
) {
249 $this->_defaults
['selectMembership'] = $defaultMemType = $this->_defaultMemTypeId ?
$this->_defaultMemTypeId
: CRM_Utils_Array
::value('membership_type_default', $this->_membershipBlock
);
252 // // hack to simplify credit card entry for testing
253 // $this->_defaults['credit_card_type'] = 'Visa';
254 // $this->_defaults['amount'] = 168;
255 // $this->_defaults['credit_card_number'] = '4111111111111111';
256 // $this->_defaults['cvv2'] = '000';
257 // $this->_defaults['credit_card_exp_date'] = array('Y' => '2014', 'M' => '05');
259 // // hack to simplify direct debit entry for testing
260 // $this->_defaults['account_holder'] = 'Max Müller';
261 // $this->_defaults['bank_account_number'] = '12345678';
262 // $this->_defaults['bank_identification_number'] = '12030000';
263 // $this->_defaults['bank_name'] = 'Bankname';
265 //build set default for pledge overdue payment.
266 if (CRM_Utils_Array
::value('pledge_id', $this->_values
)) {
267 //get all payment statuses.
269 $returnProperties = array('status_id');
270 CRM_Core_DAO
::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $this->_values
['pledge_id'],
271 $statuses, $returnProperties
274 $paymentStatusTypes = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
276 foreach ($statuses as $payId => $value) {
277 if ($paymentStatusTypes[$value['status_id']] == 'Overdue') {
278 $this->_defaults
['pledge_amount'][$payId] = 1;
280 elseif (!$duePayment && $paymentStatusTypes[$value['status_id']] == 'Pending') {
281 $this->_defaults
['pledge_amount'][$payId] = 1;
286 elseif (CRM_Utils_Array
::value('pledge_block_id', $this->_values
)) {
287 //set default to one time contribution.
288 $this->_defaults
['is_pledge'] = 0;
291 // to process Custom data that are appended to URL
292 $getDefaults = CRM_Core_BAO_CustomGroup
::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
293 if (!empty($getDefaults)) {
294 $this->_defaults
= array_merge($this->_defaults
, $getDefaults);
297 $config = CRM_Core_Config
::singleton();
298 // set default country from config if no country set
299 if (!CRM_Utils_Array
::value("billing_country_id-{$this->_bltID}", $this->_defaults
)) {
300 $this->_defaults
["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
303 // set default state/province from config if no state/province set
304 if (!CRM_Utils_Array
::value("billing_state_province_id-{$this->_bltID}", $this->_defaults
)) {
305 $this->_defaults
["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince
;
308 // now fix all state country selectors
309 CRM_Core_BAO_Address
::fixAllStateSelects($this, $this->_defaults
);
311 if ($this->_priceSetId
) {
312 if ($this->_useForMember
&& !empty($this->_currentMemberships
)) {
313 $selectedCurrentMemTypes = array();
314 foreach ($this->_priceSet
['fields'] as $key => $val) {
315 foreach ($val['options'] as $keys => $values) {
316 $opMemTypeId = CRM_Utils_Array
::value('membership_type_id', $values);
318 in_array($opMemTypeId, $this->_currentMemberships
) &&
319 !in_array($opMemTypeId, $selectedCurrentMemTypes)
321 if ($val['html_type'] == 'CheckBox') {
322 $this->_defaults
["price_{$key}"][$keys] = 1;
325 $this->_defaults
["price_{$key}"] = $keys;
327 $selectedCurrentMemTypes[] = $values['membership_type_id'];
329 elseif (CRM_Utils_Array
::value('is_default', $values) &&
331 (!isset($this->_defaults
["price_{$key}"]) ||
332 ($val['html_type'] == 'CheckBox' && !isset($this->_defaults
["price_{$key}"][$keys]))
335 if ($val['html_type'] == 'CheckBox') {
336 $this->_defaults
["price_{$key}"][$keys] = 1;
339 $this->_defaults
["price_{$key}"] = $keys;
346 CRM_Price_BAO_Set
::setDefaultPriceSet($this, $this->_defaults
);
350 if (!empty($this->_paymentProcessors
)) {
351 foreach ($this->_paymentProcessors
as $pid => $value) {
352 if (CRM_Utils_Array
::value('is_default', $value)) {
353 $this->_defaults
['payment_processor'] = $pid;
358 return $this->_defaults
;
362 * Function to build the form
367 public function buildQuickForm() {
368 // Build payment processor form
369 if ($this->_ppType
) {
370 CRM_Core_Payment_ProcessorForm
::buildQuickForm($this);
371 // Return if we are in an ajax callback
372 if ($this->_snippet
) {
377 $config = CRM_Core_Config
::singleton();
379 if ($this->_onbehalf
) {
380 CRM_Contribute_Form_Contribution_OnBehalfOf
::buildQuickForm($this);
383 $this->applyFilter('__ALL__', 'trim');
384 $this->add('text', "email-{$this->_bltID}",
386 array('size' => 30, 'maxlength' => 60, 'class' => 'email'),
389 $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email');
391 if (!empty($this->_paymentProcessors
)) {
392 $pps = $this->_paymentProcessors
;
393 foreach ($pps as $key => & $name) {
394 $pps[$key] = $name['name'];
397 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
)) {
398 $pps[0] = $this->_values
['pay_later_text'];
401 if (count($pps) > 1) {
402 $this->addRadio('payment_processor', ts('Payment Method'), $pps,
406 elseif (!empty($pps)) {
407 $key = array_keys($pps);
408 $key = array_pop($key);
409 $this->addElement('hidden', 'payment_processor', $key);
411 $this->assign('is_pay_later', $this->_values
['is_pay_later']);
412 $this->assign('pay_later_text', $this->_values
['pay_later_text']);
415 //build pledge block.
416 $this->_useForMember
= 0;
417 //don't build membership block when pledge_id is passed
418 if (!CRM_Utils_Array
::value('pledge_id', $this->_values
)) {
419 $this->_separateMembershipPayment
= FALSE;
420 if (in_array('CiviMember', $config->enableComponents
)) {
422 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
426 if ($this->_priceSetId
&&
427 (CRM_Core_Component
::getComponentID('CiviMember') == CRM_Utils_Array
::value('extends', $this->_priceSet
))
429 $this->_useForMember
= 1;
430 $this->set('useForMember', $this->_useForMember
);
433 $this->_separateMembershipPayment
= CRM_Member_BAO_Membership
::buildMembershipBlock($this,
436 $isTest, $this->_membershipContactID
439 $this->set('separateMembershipPayment', $this->_separateMembershipPayment
);
441 $this->assign('useForMember', $this->_useForMember
);
442 // If we configured price set for contribution page
443 // we are not allow membership signup as well as any
444 // other contribution amount field, CRM-5095
445 if (isset($this->_priceSetId
) && $this->_priceSetId
) {
446 $this->add('hidden', 'priceSetId', $this->_priceSetId
);
447 // build price set form.
448 $this->set('priceSetId', $this->_priceSetId
);
449 CRM_Price_BAO_Set
::buildPriceSet($this);
450 if ($this->_values
['is_monetary'] &&
451 $this->_values
['is_recur'] && !CRM_Utils_Array
::value('pledge_id', $this->_values
)
453 self
::buildRecur($this);
457 if ($this->_priceSetId
) {
458 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId
, 'is_quick_config');
459 if ($is_quick_config) {
460 $this->_useForMember
= 0;
461 $this->set('useForMember', $this->_useForMember
);
465 if ($this->_values
['is_for_organization']) {
466 $this->buildOnBehalfOrganization();
469 //we allow premium for pledge during pledge creation only.
470 if (!CRM_Utils_Array
::value('pledge_id', $this->_values
)) {
471 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, TRUE);
474 if ($this->_values
['honor_block_is_active']) {
475 $this->buildHonorBlock();
479 //don't build pledge block when mid is passed
481 $config = CRM_Core_Config
::singleton();
482 if (in_array('CiviPledge', $config->enableComponents
)
483 && CRM_Utils_Array
::value('pledge_block_id', $this->_values
)
485 CRM_Pledge_BAO_PledgeBlock
::buildPledgeBlock($this);
489 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre');
490 $this->buildCustom($this->_values
['custom_post_id'], 'customPost');
492 if ( !empty( $this->_fields
) ) {
493 $profileAddressFields = array();
494 foreach( $this->_fields
as $key => $value ) {
495 CRM_Core_BAO_UFField
::assignAddressField($key, $profileAddressFields);
497 $this->set('profileAddressFields', $profileAddressFields);
500 //to create an cms user
501 if (!$this->_userID
) {
502 $createCMSUser = FALSE;
504 if ($this->_values
['custom_pre_id']) {
505 $profileID = $this->_values
['custom_pre_id'];
506 $createCMSUser = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
509 if (!$createCMSUser &&
510 $this->_values
['custom_post_id']
512 if (!is_array($this->_values
['custom_post_id'])) {
513 $profileIDs = array($this->_values
['custom_post_id']);
516 $profileIDs = $this->_values
['custom_post_id'];
518 foreach ($profileIDs as $pid) {
519 if (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
521 $createCMSUser = TRUE;
527 if ($createCMSUser) {
528 CRM_Core_BAO_CMSUser
::buildForm($this, $profileID, TRUE);
532 if ($pcpSupporter = CRM_PCP_BAO_PCP
::displayName($this->_pcpId
)) {
533 $this->assign('pcpSupporterText', ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!', array(1 => $pcpSupporter)));
535 $this->assign('pcp', TRUE);
536 $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL,
537 array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
539 $extraOption = array('onclick' => "return pcpAnonymous( );");
541 $elements[] = &$this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
542 $elements[] = &$this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
543 $this->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
544 $this->_defaults
['pcp_is_anonymous'] = 0;
546 $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
547 $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
550 //we have to load confirm contribution button in template
551 //when multiple payment processor as the user
552 //can toggle with payment processor selection
553 $billingModePaymentProcessors = 0;
554 if ( !empty( $this->_paymentProcessors
) ) {
555 foreach ($this->_paymentProcessors
as $key => $values) {
556 if ($values['billing_mode'] == CRM_Core_Payment
::BILLING_MODE_BUTTON
) {
557 $billingModePaymentProcessors++
;
562 if ($billingModePaymentProcessors && count($this->_paymentProcessors
) == $billingModePaymentProcessors) {
563 $allAreBillingModeProcessors = TRUE;
565 $allAreBillingModeProcessors = FALSE;
568 if (!($allAreBillingModeProcessors && !$this->_values
['is_pay_later'])) {
569 $this->addButtons(array(
572 'name' => ts('Contribute'),
573 'spacing' => ' ',
580 $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
584 * Function to add the honor block
589 function buildHonorBlock() {
590 $this->assign('honor_block_is_active', TRUE);
591 $this->set('honor_block_is_active', TRUE);
593 $this->assign('honor_block_title', CRM_Utils_Array
::value('honor_block_title', $this->_values
));
594 $this->assign('honor_block_text', CRM_Utils_Array
::value('honor_block_text', $this->_values
));
596 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact');
597 $extraOption = array('onclick' => "enableHonorType();");
598 // radio button for Honor Type
599 $honorOptions = array();
600 $honor = CRM_Core_PseudoConstant
::honor();
601 foreach ($honor as $key => $var) {
602 $honorTypes[$key] = $this->createElement('radio', NULL, NULL, $var, $key, $extraOption);
604 $this->addGroup($honorTypes, 'honor_type_id', NULL);
607 $this->addElement('select', 'honor_prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant
::individualPrefix());
609 $this->addElement('text', 'honor_first_name', ts('First Name'), $attributes['first_name']);
612 $this->addElement('text', 'honor_last_name', ts('Last Name'), $attributes['last_name']);
615 $this->addElement('text', 'honor_email', ts('Email Address'), array('class' => 'email'));
616 $this->addRule('honor_email', ts('Honoree Email is not valid.'), 'email');
620 * build elements to enable pay on behalf of an organization.
624 function buildOnBehalfOrganization() {
625 if ($this->_membershipContactID
) {
626 $entityBlock = array('contact_id' => $this->_membershipContactID
);
627 CRM_Core_BAO_Location
::getValues($entityBlock, $this->_defaults
);
630 if (!$this->_onBehalfRequired
) {
631 $this->addElement('checkbox', 'is_for_organization',
632 $this->_values
['for_organization'],
633 NULL, array('onclick' => "showOnBehalf( );")
637 $this->assign('is_for_organization', TRUE);
638 $this->assign('urlPath', 'civicrm/contribute/transact');
642 * build elements to collect information for recurring contributions
646 function buildRecur($form) {
647 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionRecur');
648 $className = get_class($form);
650 $this->assign('is_recur_interval', CRM_Utils_Array
::value('is_recur_interval', $this->_values
));
651 $this->assign('is_recur_installments', CRM_Utils_Array
::value('is_recur_installments', $this->_values
));
653 $form->add('checkbox', 'is_recur', ts('I want to contribute this amount'), NULL);
655 if (CRM_Utils_Array
::value('is_recur_interval', $form->_values
) ||
$className == 'CRM_Contribute_Form_Contribution') {
656 $form->add('text', 'frequency_interval', ts('Every'), $attributes['frequency_interval']);
657 $form->addRule('frequency_interval', ts('Frequency must be a whole number (EXAMPLE: Every 3 months).'), 'integer');
660 // make sure frequency_interval is submitted as 1 if given no choice to user.
661 $form->add('hidden', 'frequency_interval', 1);
664 $frUnits = CRM_Utils_Array
::value('recur_frequency_unit', $form->_values
);
665 if (empty($frUnits) &&
666 $className == 'CRM_Contribute_Form_Contribution'
668 $frUnits = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
669 CRM_Core_OptionGroup
::values('recur_frequency_units')
673 $unitVals = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $frUnits);
675 // CRM 10860, display text instead of a dropdown if there's only 1 frequency unit
676 if(sizeof($unitVals) == 1) {
677 $this->assign('one_frequency_unit', true);
678 $unit = $unitVals[0];
679 $form->add('hidden', 'frequency_unit', $unit);
680 if (CRM_Utils_Array
::value('is_recur_interval', $form->_values
) ||
$className == 'CRM_Contribute_Form_Contribution') {
683 $this->assign('frequency_unit', $unit);
685 $this->assign('one_frequency_unit', false);
687 $frequencyUnits = CRM_Core_OptionGroup
::values('recur_frequency_units');
688 foreach ($unitVals as $key => $val) {
689 if (array_key_exists($val, $frequencyUnits)) {
690 $units[$val] = $frequencyUnits[$val];
691 if (CRM_Utils_Array
::value('is_recur_interval', $form->_values
) ||
$className == 'CRM_Contribute_Form_Contribution') {
692 $units[$val] = "{$frequencyUnits[$val]}(s)";
696 $frequencyUnit = &$form->add('select', 'frequency_unit', NULL, $units);
700 // FIXME: Ideally we should freeze select box if there is only
701 // one option but looks there is some problem /w QF freeze.
702 //if ( count( $units ) == 1 ) {
703 //$frequencyUnit->freeze( );
706 $form->add('text', 'installments', ts('installments'),
707 $attributes['installments']
709 $form->addRule('installments', ts('Number of installments must be a whole number.'), 'integer');
715 * @param array $fields the input form values
716 * @param array $files the uploaded files if any
717 * @param array $options additional user data
719 * @return true if no errors, else array of errors
723 static function formRule($fields, $files, $self) {
725 $amount = self
::computeAmount($fields, $self);
727 if ((CRM_Utils_Array
::value('selectMembership', $fields) &&
728 $fields['selectMembership'] != 'no_thanks'
730 (CRM_Utils_Array
::value('priceSetId', $fields) &&
734 $lifeMember = CRM_Member_BAO_Membership
::getAllContactMembership($self->_userID
, FALSE, TRUE);
736 $membershipOrgDetails = CRM_Member_BAO_MembershipType
::getMembershipTypeOrganization();
738 $unallowedOrgs = array();
739 foreach (array_keys($lifeMember) as $memTypeId) {
740 $unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
744 //check for atleast one pricefields should be selected
745 if (CRM_Utils_Array
::value('priceSetId', $fields)) {
746 $priceField = new CRM_Price_DAO_Field();
747 $priceField->price_set_id
= $fields['priceSetId'];
748 $priceField->orderBy('weight');
752 $membershipIsActive = TRUE;
753 $previousId = $otherAmount = FALSE;
754 while ($priceField->fetch()) {
756 if ($self->_quickConfig
&& ($priceField->name
== 'contribution_amount' ||
$priceField->name
== 'membership_amount')) {
757 $previousId = $priceField->id
;
758 if ($priceField->name
== 'membership_amount' && !$priceField->is_active
) {
759 $membershipIsActive = FALSE;
762 if ($priceField->name
== 'other_amount') {
763 if ($self->_quickConfig
&& !CRM_Utils_Array
::value("price_{$priceField->id}", $fields) &&
764 array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values
['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])) {
765 $otherAmount = $priceField->id
;
767 elseif (!empty($fields["price_{$priceField->id}"])) {
768 $otherAmountVal = $fields["price_{$priceField->id}"];
769 $min = CRM_Utils_Array
::value('min_amount', $self->_values
);
770 $max = CRM_Utils_Array
::value('max_amount', $self->_values
);
771 if ($min && $otherAmountVal < $min) {
772 $errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1',
776 if ($max && $otherAmountVal > $max) {
777 $errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.',
783 if (!empty($fields["price_{$priceField->id}"]) ||
($previousId == $priceField->id
&& isset($fields["price_{$previousId}"])
784 && empty($fields["price_{$previousId}"]))) {
785 $check[] = $priceField->id
;
790 if ($membershipIsActive && !$self->_membershipBlock
['is_required']
791 && $self->_values
['amount_block_is_active']) {
792 $membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
793 foreach ($self->_values
['fee'] as $fieldKey => $fieldValue) {
794 // if 'No thank you' membership is selected then set $membershipFieldId
795 if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array
::value('price_' . $fieldKey, $fields) == 0) {
796 $membershipFieldId = $fieldKey;
798 elseif ($membershipFieldId) {
799 if ($fieldValue['name'] == 'other_amount') {
800 $otherFieldId = $fieldKey;
802 elseif ($fieldValue['name'] == 'contribution_amount') {
803 $contributionFieldId = $fieldKey;
806 if (!$errorKey || CRM_Utils_Array
::value('price_' . $contributionFieldId, $fields) == '0') {
807 $errorKey = $fieldKey;
811 // $membershipFieldId is set and additional amount is 'No thank you' or NULL then throw error
812 if ($membershipFieldId && !(CRM_Utils_Array
::value('price_' . $contributionFieldId, $fields, -1) > 0)
813 && !CRM_Utils_Array
::value('price_' . $otherFieldId, $fields)) {
814 $errors["price_{$errorKey}"] = ts('Additional Contribution is required.');
818 if ($self->_useForMember
== 1 && $membershipIsActive) {
819 $errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
822 $errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
825 if($otherAmount && !empty($check)) {
826 $errors["price_{$otherAmount}"] = ts('Amount is required field.');
829 if ($self->_useForMember
== 1 && !empty($check) && $membershipIsActive) {
830 $priceFieldIDS = array();
831 $priceFieldMemTypes = array();
833 foreach ($self->_priceSet
['fields'] as $priceId => $value) {
834 if (!empty($fields['price_' . $priceId]) ||
($self->_quickConfig
&& $value['name'] == 'membership_amount' && !CRM_Utils_Array
::value('is_required', $self->_membershipBlock
))) {
835 if (CRM_Utils_Array
::value('price_' . $priceId, $fields) && is_array($fields['price_' . $priceId])) {
836 foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
838 $priceFieldIDS[] = $priceFldVal;
842 elseif (!$value['is_enter_qty'] && CRM_Utils_Array
::value('price_' . $priceId, $fields)) {
843 // The check for {!$value['is_enter_qty']} is done since, quantity fields allow entering
844 // quantity. And the quantity can't be conisdered as civicrm_price_field_value.id, CRM-9577
845 $priceFieldIDS[] = $fields['price_' . $priceId];
848 if (CRM_Utils_Array
::value('options', $value)) {
849 foreach ($value['options'] as $val) {
850 if (CRM_Utils_Array
::value('membership_type_id', $val)) {
851 $priceFieldMemTypes[] = $val['membership_type_id'];
858 if (!empty($lifeMember)) {
859 foreach ($priceFieldIDS as $priceFieldId) {
860 if (($id = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_FieldValue', $priceFieldId, 'membership_type_id')) &&
861 in_array($membershipOrgDetails[$id], $unallowedOrgs)
863 $errors['_qf_default'] = ts('You already have a lifetime membership and cannot select a membership with a shorter term.');
869 if (!empty($priceFieldIDS)) {
870 $ids = implode(',', $priceFieldIDS);
872 $priceFieldIDS['id'] = $fields['priceSetId'];
873 $self->set('memberPriceFieldIDS', $priceFieldIDS);
874 $count = CRM_Price_BAO_Set
::getMembershipCount($ids);
875 foreach ($count as $id => $occurance) {
876 if ($occurance > 1) {
877 $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.');
882 if (empty($priceFieldMemTypes)) {
883 $errors['_qf_default'] = ts('Please select at least one membership option.');
887 CRM_Price_BAO_Set
::processAmount($self->_values
['fee'],
891 if ($fields['amount'] < 0) {
892 $errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
894 $amount = $fields['amount'];
897 if (isset($fields['selectProduct']) &&
898 $fields['selectProduct'] != 'no_thanks' &&
899 $self->_values
['amount_block_is_active']
901 $productDAO = new CRM_Contribute_DAO_Product();
902 $productDAO->id
= $fields['selectProduct'];
903 $productDAO->find(TRUE);
904 $min_amount = $productDAO->min_contribution
;
906 if ($amount < $min_amount) {
907 $errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money
::format($min_amount)));
908 CRM_Core_Session
::setStatus($errors['selectProduct']);
912 if ($self->_values
['honor_block_is_active'] && CRM_Utils_Array
::value('honor_type_id', $fields)) {
913 // make sure there is a first name and last name if email is not there
914 if (!CRM_Utils_Array
::value('honor_email', $fields)) {
915 if (!CRM_Utils_Array
::value('honor_first_name', $fields) ||
916 !CRM_Utils_Array
::value('honor_last_name', $fields)
918 $errors['honor_last_name'] = ts('In Honor Of - First Name and Last Name, OR an Email Address is required.');
923 if ( CRM_Utils_Array
::value( 'is_recur', $fields ) ) {
924 if ($fields['frequency_interval'] <= 0) {
925 $errors['frequency_interval'] = ts('Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months).');
927 if ($fields['frequency_unit'] == '0') {
928 $errors['frequency_unit'] = ts('Please select a period (e.g. months, years ...) for how often you want to make this recurring contribution (EXAMPLE: Every 3 MONTHS).');
932 if (CRM_Utils_Array
::value('is_recur', $fields) &&
933 CRM_Utils_Array
::value('payment_processor', $fields) == 0) {
934 $errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
937 if (CRM_Utils_Array
::value('is_for_organization', $fields) &&
938 !property_exists($self, 'organizationName')
941 if (!CRM_Utils_Array
::value('organization_name', $fields['onbehalf'])) {
942 if (CRM_Utils_Array
::value('org_option', $fields) && !$fields['onbehalfof_id']) {
943 $errors['organization_id'] = ts('Please select an organization or enter a new one.');
945 elseif (!CRM_Utils_Array
::value('org_option', $fields)) {
946 $errors['onbehalf']['organization_name'] = ts('Please enter the organization name.');
950 foreach ($fields['onbehalf'] as $key => $value) {
951 if (strstr($key, 'email')) {
952 $emailLocType = explode('-', $key);
955 if (!CRM_Utils_Array
::value("email-{$emailLocType[1]}", $fields['onbehalf'])) {
956 $errors['onbehalf']["email-{$emailLocType[1]}"] = ts('Organization email is required.');
960 // validate PCP fields - if not anonymous, we need a nick name value
961 if ($self->_pcpId
&& CRM_Utils_Array
::value('pcp_display_in_roll', $fields) &&
962 (CRM_Utils_Array
::value('pcp_is_anonymous', $fields) == 0) &&
963 CRM_Utils_Array
::value('pcp_roll_nickname', $fields) == ''
965 $errors['pcp_roll_nickname'] = ts('Please enter a name to include in the Honor Roll, or select \'contribute anonymously\'.');
968 // return if this is express mode
969 $config = CRM_Core_Config
::singleton();
970 if ($self->_paymentProcessor
&&
971 $self->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_BUTTON
973 if (CRM_Utils_Array
::value($self->_expressButtonName
. '_x', $fields) ||
974 CRM_Utils_Array
::value($self->_expressButtonName
. '_y', $fields) ||
975 CRM_Utils_Array
::value($self->_expressButtonName
, $fields)
981 //validate the pledge fields.
982 if (CRM_Utils_Array
::value('pledge_block_id', $self->_values
)) {
983 //validation for pledge payment.
984 if (CRM_Utils_Array
::value('pledge_id', $self->_values
)) {
985 if (empty($fields['pledge_amount'])) {
986 $errors['pledge_amount'] = ts('At least one payment option needs to be checked.');
989 elseif (CRM_Utils_Array
::value('is_pledge', $fields)) {
990 if (CRM_Utils_Rule
::positiveInteger(CRM_Utils_Array
::value('pledge_installments', $fields)) == FALSE) {
991 $errors['pledge_installments'] = ts('Please enter a valid pledge installment.');
994 if (CRM_Utils_Array
::value('pledge_installments', $fields) == NULL) {
995 $errors['pledge_installments'] = ts('Pledge Installments is required field.');
997 elseif (CRM_Utils_array
::value('pledge_installments', $fields) == 1) {
998 $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.');
1000 elseif (CRM_Utils_array
::value('pledge_installments', $fields) == 0) {
1001 $errors['pledge_installments'] = ts('Pledge Installments field must be > 1.');
1005 //validation for Pledge Frequency Interval.
1006 if (CRM_Utils_Rule
::positiveInteger(CRM_Utils_Array
::value('pledge_frequency_interval', $fields)) == FALSE) {
1007 $errors['pledge_frequency_interval'] = ts('Please enter a valid Pledge Frequency Interval.');
1010 if (CRM_Utils_Array
::value('pledge_frequency_interval', $fields) == NULL) {
1011 $errors['pledge_frequency_interval'] = ts('Pledge Frequency Interval. is required field.');
1013 elseif (CRM_Utils_array
::value('pledge_frequency_interval', $fields) == 0) {
1014 $errors['pledge_frequency_interval'] = ts('Pledge frequency interval field must be > 0');
1020 // also return if paylater mode
1021 if (CRM_Utils_Array
::value('payment_processor', $fields) == 0) {
1022 return empty($errors) ?
TRUE : $errors;
1025 // if the user has chosen a free membership or the amount is less than zero
1026 // i.e. we skip calling the payment processor and hence dont need credit card
1028 if ((float) $amount <= 0.0) {
1032 if (!empty($self->_paymentFields
)) {
1033 CRM_Core_Form
::validateMandatoryFields($self->_paymentFields
, $fields, $errors);
1035 CRM_Core_Payment_Form
::validateCreditCard($fields, $errors);
1037 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1038 if ($greetingType = CRM_Utils_Array
::value($greeting, $fields)) {
1039 $customizedValue = CRM_Core_OptionGroup
::getValue($greeting, 'Customized', 'name');
1040 if ($customizedValue == $greetingType && empty($fielse[$greeting . '_custom'])) {
1041 $errors[$greeting . '_custom'] = ts('Custom %1 is a required field if %1 is of type Customized.',
1042 array(1 => ucwords(str_replace('_', " ", $greeting)))
1048 return empty($errors) ?
TRUE : $errors;
1051 public static function computeAmount(&$params, &$form) {
1054 // first clean up the other amount field if present
1055 if (isset($params['amount_other'])) {
1056 $params['amount_other'] = CRM_Utils_Rule
::cleanMoney($params['amount_other']);
1059 if (CRM_Utils_Array
::value('amount', $params) == 'amount_other_radio' ||
1060 CRM_Utils_Array
::value('amount_other', $params)
1062 $amount = $params['amount_other'];
1064 elseif (!empty($params['pledge_amount'])) {
1066 foreach ($params['pledge_amount'] as $paymentId => $dontCare) {
1067 $amount +
= CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount');
1071 if (CRM_Utils_Array
::value('amount', $form->_values
)) {
1072 $amountID = CRM_Utils_Array
::value('amount', $params);
1075 $params['amount_level'] = CRM_Utils_Array
::value('label', $form->_values
[$amountID]);
1076 $amount = CRM_Utils_Array
::value('value', $form->_values
[$amountID]);
1084 * Function to process the form
1090 public function postProcess() {
1091 $config = CRM_Core_Config
::singleton();
1093 // we first reset the confirm page so it accepts new values
1094 $this->controller
->resetPage('Confirm');
1096 // get the submitted form values.
1097 $params = $this->controller
->exportValues($this->_name
);
1098 if (CRM_Utils_Array
::value('priceSetId', $params)) {
1099 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId
, 'is_quick_config');
1100 $formValue = array();
1101 if ($is_quick_config) {
1102 $priceField = new CRM_Price_DAO_Field();
1103 $priceField->price_set_id
= $params['priceSetId'];
1104 $priceField->orderBy('weight');
1105 $priceField->find();
1108 $otherAmount = FALSE;
1109 while ($priceField->fetch()) {
1110 CRM_Price_BAO_FieldValue
::getValues($priceField->id
, $values);
1111 if ($priceField->name
== 'membership_amount') {
1112 if ($priceFiledID = CRM_Utils_Array
::value("price_{$priceField->id}", $params)) {
1113 $this->_params
['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array
::value('membership_type_id', $values[$priceFiledID]);
1114 $this->set('selectMembership',CRM_Utils_Array
::value('selectMembership', $params));
1115 if (CRM_Utils_Array
::value('is_separate_payment', $this->_membershipBlock
) == 0) {
1116 $this->_values
['amount'] = CRM_Utils_Array
::value('amount', $values[$priceFiledID]);
1120 if ($priceField->name
== 'contribution_amount') {
1121 $priceFiledID = CRM_Utils_Array
::value("price_{$priceField->id}", $params);
1122 if ($priceFiledID > 0 && !empty($priceFiledID)) {
1123 $params['amount'] = $priceFiledID;
1124 $this->_values
['amount'] = CRM_Utils_Array
::value('amount', $values[$priceFiledID]);
1125 $this->_values
[$priceFiledID]['value'] = CRM_Utils_Array
::value('amount', $values[$priceFiledID]);
1126 $this->_values
[$priceFiledID]['label'] = CRM_Utils_Array
::value('label', $values[$priceFiledID]);
1127 $this->_values
[$priceFiledID]['amount_id'] = CRM_Utils_Array
::value('id', $values[$priceFiledID]);
1128 $this->_values
[$priceFiledID]['weight'] = CRM_Utils_Array
::value('weight', $values[$priceFiledID]);
1131 if ($priceField->name
== 'other_amount' && $priceFiledID = CRM_Utils_Array
::value("price_{$priceField->id}", $params)) {
1132 $params['amount_other'] = $priceFiledID;
1138 if (($this->_values
['is_pay_later'] &&
1139 empty($this->_paymentProcessor
) &&
1140 !array_key_exists('hidden_processor', $params)) ||
1141 CRM_Utils_Array
::value('payment_processor', $params) == 0) {
1142 $params['is_pay_later'] = 1;
1145 $params['is_pay_later'] = 0;
1148 $this->set('is_pay_later', $params['is_pay_later']);
1149 // assign pay later stuff
1150 $this->_params
['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
1151 $this->assign('is_pay_later', $params['is_pay_later']);
1152 if ($params['is_pay_later']) {
1153 $this->assign('pay_later_text', $this->_values
['pay_later_text']);
1154 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
1157 //carry campaign from profile.
1158 if (array_key_exists('contribution_campaign_id', $params)) {
1159 $params['campaign_id'] = $params['contribution_campaign_id'];
1162 if (CRM_Utils_Array
::value('onbehalfof_id', $params)) {
1163 $params['organization_id'] = $params['onbehalfof_id'];
1166 $params['currencyID'] = $config->defaultCurrency
;
1167 $params['amount'] = self
::computeAmount($params, $this);
1168 $params['separate_amount'] = $params['amount'];
1170 if (CRM_Utils_Array
::value('selectMembership', $params)) {
1171 if (!empty($this->_membershipTypeValues
)) {
1172 $membershipTypeValues = $this->_membershipTypeValues
[$params['selectMembership']];
1175 $membershipTypeValues = CRM_Member_BAO_Membership
::buildMembershipTypeValues($this,
1176 $params['selectMembership']
1179 $memFee = $membershipTypeValues['minimum_fee'];
1180 if (!$params['amount'] && !$this->_separateMembershipPayment
) {
1181 $params['amount'] = $memFee ?
$memFee : 0;
1185 //If the membership & contribution is used in contribution page & not seperate payment
1186 $fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
1187 $proceFieldAmount = 0;
1188 if ($this->_separateMembershipPayment
== 0) {
1189 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId
, 'is_quick_config');
1190 if ($is_quick_config) {
1191 foreach ($this->_priceSet
['fields'] as $fieldKey => $fieldVal) {
1192 if ($fieldVal['name'] == 'membership_amount' && CRM_Utils_Array
::value('price_' . $fieldKey , $params)) {
1193 $fieldId = $fieldVal['id'];
1194 $fieldOption = $params['price_' . $fieldId];
1195 $proceFieldAmount +
= $fieldVal['options'][$this->_submitValues
['price_' . $fieldId]]['amount'];
1199 if (CRM_Utils_Array
::value('price_' . $fieldKey, $params) && $memPresent && ($fieldVal['name'] == 'other_amount' ||
$fieldVal['name'] == 'contribution_amount')) {
1200 $fieldId = $fieldVal['id'];
1201 if ($fieldVal['name'] == 'other_amount') {
1202 $proceFieldAmount +
= $this->_submitValues
['price_' . $fieldId];
1204 elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues
['price_' . $fieldId] > 0) {
1205 $proceFieldAmount +
= $fieldVal['options'][$this->_submitValues
['price_' . $fieldId]]['amount'];
1207 unset($params['price_' . $fieldId]);
1215 if (!isset($params['amount_other'])) {
1216 $this->set('amount_level', CRM_Utils_Array
::value('amount_level', $params));
1219 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $params)) {
1220 $lineItem = array();
1221 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config' );
1222 if ( $is_quick_config ) {
1223 foreach ( $this->_values
['fee'] as $key => & $val ) {
1224 if ( $val['name'] == 'other_amount' && $val['html_type'] == 'Text' && array_key_exists( 'price_'.$key, $params ) && $params['price_'.$key] != 0 ) {
1225 foreach ( $val['options'] as $optionKey => & $options ) {
1226 $options['amount'] = CRM_Utils_Array
::value( 'price_'.$key, $params );
1229 $params['price_'.$key] = 1;
1236 if ($this->_membershipBlock
) {
1237 $component = 'membership';
1239 CRM_Price_BAO_Set
::processAmount($this->_values
['fee'], $params, $lineItem[$priceSetId], $component);
1241 if ($proceFieldAmount) {
1242 $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
1243 $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
1244 if (!$this->_membershipBlock
['is_separate_payment']) {
1245 $params['amount'] = $proceFieldAmount; //require when separate membership not used
1248 $this->set('lineItem', $lineItem);
1251 if ($this->_membershipBlock
['is_separate_payment'] && CRM_Utils_Array
::value('separate_amount', $params)) {
1252 $this->set('amount', $params['separate_amount']);
1254 $this->set('amount', $params['amount']);
1257 // generate and set an invoiceID for this transaction
1258 $invoiceID = md5(uniqid(rand(), TRUE));
1259 $this->set('invoiceID', $invoiceID);
1261 // required only if is_monetary and valid postive amount
1262 if ($this->_values
['is_monetary'] &&
1263 is_array($this->_paymentProcessor
) &&
1264 ((float ) $params['amount'] > 0.0 ||
$memFee > 0.0)
1267 // default mode is direct
1268 $this->set('contributeMode', 'direct');
1270 if ($this->_paymentProcessor
&&
1271 $this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_BUTTON
1273 //get the button name
1274 $buttonName = $this->controller
->getButtonName();
1275 if (in_array($buttonName,
1276 array($this->_expressButtonName
, $this->_expressButtonName
. '_x', $this->_expressButtonName
. '_y')
1278 !CRM_Utils_Array
::value('is_pay_later', $params)
1280 $this->set('contributeMode', 'express');
1282 $donateURL = CRM_Utils_System
::url('civicrm/contribute', '_qf_Contribute_display=1');
1283 $params['cancelURL'] = CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_Main_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
1284 $params['returnURL'] = CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_Confirm_display=1&rfp=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
1285 $params['invoiceID'] = $invoiceID;
1287 //default action is Sale
1288 $params['payment_action'] = 'Sale';
1290 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1291 $token = $payment->setExpressCheckout($params);
1292 if (is_a($token, 'CRM_Core_Error')) {
1293 CRM_Core_Error
::displaySessionError($token);
1294 CRM_Utils_System
::redirect($params['cancelURL']);
1297 $this->set('token', $token);
1299 $paymentURL = $this->_paymentProcessor
['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token=$token";
1300 CRM_Utils_System
::redirect($paymentURL);
1303 elseif ($this->_paymentProcessor
&&
1304 $this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_NOTIFY
1306 $this->set('contributeMode', 'notify');
1310 // should we skip the confirm page?
1311 if (!CRM_Utils_Array
::value('is_confirm_enabled', $this->_values
)) {
1312 // call the post process hook for the main page before we switch to confirm
1313 $this->postProcessHook();
1315 // build the confirm page
1316 $confirmForm = &$this->controller
->_pages
['Confirm'];
1317 $confirmForm->preProcess();
1318 $confirmForm->buildQuickForm();
1320 // the confirmation page is valid
1321 $data = &$this->controller
->container();
1322 $data['valid']['Confirm'] = 1;
1324 // confirm the contribution
1325 // mainProcess calls the hook also
1326 $confirmForm->mainProcess();
1327 $qfKey = $this->controller
->_key
;
1329 // redirect to thank you page
1330 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey=$qfKey", TRUE, NULL, FALSE));
1335 * Handle Payment Processor switching
1336 * For contribution and event registration forms
1338 static function preProcessPaymentOptions(&$form, $noFees = FALSE) {
1339 $form->_snippet
= CRM_Utils_Array
::value('snippet', $_GET);
1340 $form->assign('snippet', $form->_snippet
);
1342 $form->_paymentProcessors
= $noFees ?
array() : $form->get('paymentProcessors');
1343 $form->_ppType
= NULL;
1344 if ($form->_paymentProcessors
) {
1345 // Fetch type during ajax request
1346 if (isset($_GET['type']) && $form->_snippet
) {
1347 $form->_ppType
= $_GET['type'];
1349 // Remember type during form post
1350 elseif (!empty($form->_submitValues
)) {
1351 $form->_ppType
= CRM_Utils_Array
::value('payment_processor', $form->_submitValues
);
1352 $form->_paymentProcessor
= CRM_Utils_Array
::value($form->_ppType
, $form->_paymentProcessors
);
1353 $form->set('type', $form->_ppType
);
1354 $form->set('mode', $form->_mode
);
1355 $form->set('paymentProcessor', $form->_paymentProcessor
);
1357 // Set default payment processor
1359 foreach ($form->_paymentProcessors
as $values) {
1360 if (!empty($values['is_default']) ||
count($form->_paymentProcessors
) == 1) {
1361 $form->_ppType
= $values['id'];
1366 if ($form->_ppType
) {
1367 CRM_Core_Payment_ProcessorForm
::preProcess($form);
1370 //get payPal express id and make it available to template
1371 foreach ($form->_paymentProcessors
as $ppId => $values) {
1372 $payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ?
$values['id'] : 0;
1373 $form->assign('payPalExpressId', $payPalExpressId);
1374 if ($payPalExpressId) {
1379 $form->assign('ppType', $form->_ppType
);