3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 Contribution
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 = $this->getContactID();
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);
87 $this->assign('reset', $reset);
91 $this->assign('mainDisplay', $mainDisplay);
94 // Possible values for 'is_for_organization':
95 // * 0 - org profile disabled
96 // * 1 - org profile optional
97 // * 2 - org profile required
98 $this->_onbehalf
= FALSE;
99 if (!empty($this->_values
['is_for_organization'])) {
100 if ($this->_values
['is_for_organization'] == 2) {
101 $this->_onBehalfRequired
= TRUE;
103 // Add organization profile if 1 of the following are true:
104 // If the org profile is required
105 if ($this->_onBehalfRequired ||
106 // Or we are building the form for the first time
108 // Or the user has submitted the form and checked the "On Behalf" checkbox
109 !empty($_POST['is_for_organization'])
111 $this->_onbehalf
= TRUE;
112 CRM_Contribute_Form_Contribution_OnBehalfOf
::preProcess($this);
115 $this->assign('onBehalfRequired', $this->_onBehalfRequired
);
117 if (!empty($this->_pcpInfo
['id']) && !empty($this->_pcpInfo
['intro_text'])) {
118 $this->assign('intro_text', $this->_pcpInfo
['intro_text']);
120 elseif (!empty($this->_values
['intro_text'])) {
121 $this->assign('intro_text', $this->_values
['intro_text']);
124 $qParams = "reset=1&id={$this->_id}";
125 if ($pcpId = CRM_Utils_Array
::value('pcp_id', $this->_pcpInfo
)) {
126 $qParams .= "&pcpId={$pcpId}";
128 $this->assign('qParams', $qParams);
130 if (!empty($this->_values
['footer_text'])) {
131 $this->assign('footer_text', $this->_values
['footer_text']);
135 if (CRM_Utils_Array
::value('is_for_organization', $this->_values
)) {
136 $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
137 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $this->_values
)) {
138 $preProfile = CRM_Core_BAO_UFGroup
::profileGroups($preID);
140 'Individual', 'Organization', 'Household') as $contactType) {
141 if (in_array($contactType, $preProfile) &&
142 (in_array('Membership', $preProfile) ||
143 in_array('Contribution', $preProfile)
146 CRM_Core_Error
::fatal($msg);
151 if ($postID = CRM_Utils_Array
::value('custom_post_id', $this->_values
)) {
152 $postProfile = CRM_Core_BAO_UFGroup
::profileGroups($postID);
154 'Individual', 'Organization', 'Household') as $contactType) {
155 if (in_array($contactType, $postProfile) &&
156 (in_array('Membership', $postProfile) ||
157 in_array('Contribution', $postProfile)
160 CRM_Core_Error
::fatal($msg);
167 function setDefaultValues() {
168 // check if the user is registered and we have a contact ID
169 $contactID = $this->getContactID();
171 if (!empty($contactID)) {
173 $removeCustomFieldTypes = array('Contribution', 'Membership');
174 $contribFields = CRM_Contribute_BAO_Contribution
::getContributionFields();
176 // remove component related fields
177 foreach ($this->_fields
as $name => $dontCare) {
178 //don't set custom data Used for Contribution (CRM-1344)
179 if (substr($name, 0, 7) == 'custom_') {
180 $id = substr($name, 7);
181 if (!CRM_Core_BAO_CustomGroup
::checkCustomField($id, $removeCustomFieldTypes)) {
184 // ignore component fields
186 elseif (array_key_exists($name, $contribFields) ||
(substr($name, 0, 11) == 'membership_') ||
(substr($name, 0, 13) == 'contribution_')) {
192 if (!empty($fields)) {
193 CRM_Core_BAO_UFGroup
::setProfileDefaults($contactID, $fields, $this->_defaults
);
196 $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
197 $this->_defaults
= array_merge($this->_defaults
, $billingDefaults);
200 //set custom field defaults set by admin if value is not set
201 if (!empty($this->_fields
)) {
202 //load default campaign from page.
203 if (array_key_exists('contribution_campaign_id', $this->_fields
)) {
204 $this->_defaults
['contribution_campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
);
207 //set custom field defaults
208 foreach ($this->_fields
as $name => $field) {
209 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
210 if (!isset($this->_defaults
[$name])) {
211 CRM_Core_BAO_CustomField
::setProfileDefaults($customFieldID, $name, $this->_defaults
,
212 NULL, CRM_Profile_Form
::MODE_REGISTER
219 // // hack to simplify credit card entry for testing
220 // $this->_defaults['credit_card_type'] = 'Visa';
221 // $this->_defaults['amount'] = 168;
222 // $this->_defaults['credit_card_number'] = '4111111111111111';
223 // $this->_defaults['cvv2'] = '000';
224 // $this->_defaults['credit_card_exp_date'] = array('Y' => '2014', 'M' => '05');
226 // // hack to simplify direct debit entry for testing
227 // $this->_defaults['account_holder'] = 'Max Müller';
228 // $this->_defaults['bank_account_number'] = '12345678';
229 // $this->_defaults['bank_identification_number'] = '12030000';
230 // $this->_defaults['bank_name'] = 'Bankname';
232 //build set default for pledge overdue payment.
233 if (CRM_Utils_Array
::value('pledge_id', $this->_values
)) {
234 //get all payment statuses.
236 $returnProperties = array('status_id');
237 CRM_Core_DAO
::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $this->_values
['pledge_id'],
238 $statuses, $returnProperties
241 $paymentStatusTypes = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
243 foreach ($statuses as $payId => $value) {
244 if ($paymentStatusTypes[$value['status_id']] == 'Overdue') {
245 $this->_defaults
['pledge_amount'][$payId] = 1;
247 elseif (!$duePayment && $paymentStatusTypes[$value['status_id']] == 'Pending') {
248 $this->_defaults
['pledge_amount'][$payId] = 1;
253 elseif (CRM_Utils_Array
::value('pledge_block_id', $this->_values
)) {
254 //set default to one time contribution.
255 $this->_defaults
['is_pledge'] = 0;
258 // to process Custom data that are appended to URL
259 $getDefaults = CRM_Core_BAO_CustomGroup
::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
260 if (!empty($getDefaults)) {
261 $this->_defaults
= array_merge($this->_defaults
, $getDefaults);
264 $config = CRM_Core_Config
::singleton();
265 // set default country from config if no country set
266 if (!CRM_Utils_Array
::value("billing_country_id-{$this->_bltID}", $this->_defaults
)) {
267 $this->_defaults
["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
270 // set default state/province from config if no state/province set
271 if (!CRM_Utils_Array
::value("billing_state_province_id-{$this->_bltID}", $this->_defaults
)) {
272 $this->_defaults
["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince
;
275 // now fix all state country selectors
276 CRM_Core_BAO_Address
::fixAllStateSelects($this, $this->_defaults
);
278 if ($this->_priceSetId
) {
279 if (($this->_useForMember
&& !empty($this->_currentMemberships
)) ||
$this->_defaultMemTypeId
) {
280 $selectedCurrentMemTypes = array();
281 foreach ($this->_priceSet
['fields'] as $key => $val) {
282 foreach ($val['options'] as $keys => $values) {
283 $opMemTypeId = CRM_Utils_Array
::value('membership_type_id', $values);
285 in_array($opMemTypeId, $this->_currentMemberships
) &&
286 !in_array($opMemTypeId, $selectedCurrentMemTypes)
288 if ($val['html_type'] == 'CheckBox') {
289 $this->_defaults
["price_{$key}"][$keys] = 1;
292 $this->_defaults
["price_{$key}"] = $keys;
294 $selectedCurrentMemTypes[] = $values['membership_type_id'];
296 elseif (CRM_Utils_Array
::value('is_default', $values) &&
298 (!isset($this->_defaults
["price_{$key}"]) ||
299 ($val['html_type'] == 'CheckBox' && !isset($this->_defaults
["price_{$key}"][$keys]))
302 if ($val['html_type'] == 'CheckBox') {
303 $this->_defaults
["price_{$key}"][$keys] = 1;
306 $this->_defaults
["price_{$key}"] = $keys;
313 CRM_Price_BAO_PriceSet
::setDefaultPriceSet($this, $this->_defaults
);
317 if (!empty($this->_paymentProcessors
)) {
318 foreach ($this->_paymentProcessors
as $pid => $value) {
319 if (CRM_Utils_Array
::value('is_default', $value)) {
320 $this->_defaults
['payment_processor'] = $pid;
325 return $this->_defaults
;
329 * Function to build the form
334 public function buildQuickForm() {
335 // build profiles first so that we can determine address fields etc
336 // and then show copy address checkbox
337 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre');
338 $this->buildCustom($this->_values
['custom_post_id'], 'customPost');
340 if (!empty($this->_fields
)) {
341 $profileAddressFields = array();
342 foreach ($this->_fields
as $key => $value) {
343 CRM_Core_BAO_UFField
::assignAddressField($key, $profileAddressFields);
345 $this->set('profileAddressFields', $profileAddressFields);
348 // Build payment processor form
349 if ($this->_ppType
) {
350 CRM_Core_Payment_ProcessorForm
::buildQuickForm($this);
351 // Return if we are in an ajax callback
352 if ($this->_snippet
) {
357 $config = CRM_Core_Config
::singleton();
359 if ($this->_onbehalf
) {
360 CRM_Contribute_Form_Contribution_OnBehalfOf
::buildQuickForm($this);
363 $this->applyFilter('__ALL__', 'trim');
364 $this->add('text', "email-{$this->_bltID}",
366 array('size' => 30, 'maxlength' => 60, 'class' => 'email'),
369 $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email');
371 $onlinePaymentProcessorEnabled = FALSE;
372 if (!empty($this->_paymentProcessors
)) {
373 foreach ($this->_paymentProcessors
as $key => $name) {
374 if($name['billing_mode'] == 1) {
375 $onlinePaymentProcessorEnabled = TRUE;
377 $pps[$key] = $name['name'];
380 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
)) {
381 $pps[0] = $this->_values
['pay_later_text'];
384 if (count($pps) > 1) {
385 $this->addRadio('payment_processor', ts('Payment Method'), $pps,
389 elseif (!empty($pps)) {
390 $key = array_keys($pps);
391 $key = array_pop($key);
392 $this->addElement('hidden', 'payment_processor', $key);
394 $this->assign('is_pay_later', $this->_values
['is_pay_later']);
395 $this->assign('pay_later_text', $this->_values
['pay_later_text']);
399 $contactID = $this->getContactID();
400 if($this->getContactID() === '0') {
401 $this->addCidZeroOptions($onlinePaymentProcessorEnabled);
403 //build pledge block.
404 $this->_useForMember
= 0;
405 //don't build membership block when pledge_id is passed
406 if (!CRM_Utils_Array
::value('pledge_id', $this->_values
)) {
407 $this->_separateMembershipPayment
= FALSE;
408 if (in_array('CiviMember', $config->enableComponents
)) {
410 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
414 if ($this->_priceSetId
&&
415 (CRM_Core_Component
::getComponentID('CiviMember') == CRM_Utils_Array
::value('extends', $this->_priceSet
))
417 $this->_useForMember
= 1;
418 $this->set('useForMember', $this->_useForMember
);
421 $this->_separateMembershipPayment
= CRM_Member_BAO_Membership
::buildMembershipBlock($this,
423 $this->_membershipContactID
,
428 $this->set('separateMembershipPayment', $this->_separateMembershipPayment
);
430 $this->assign('useForMember', $this->_useForMember
);
431 // If we configured price set for contribution page
432 // we are not allow membership signup as well as any
433 // other contribution amount field, CRM-5095
434 if (isset($this->_priceSetId
) && $this->_priceSetId
) {
435 $this->add('hidden', 'priceSetId', $this->_priceSetId
);
436 // build price set form.
437 $this->set('priceSetId', $this->_priceSetId
);
438 CRM_Price_BAO_PriceSet
::buildPriceSet($this);
439 if ($this->_values
['is_monetary'] &&
440 $this->_values
['is_recur'] && !CRM_Utils_Array
::value('pledge_id', $this->_values
)
442 self
::buildRecur($this);
446 if ($this->_priceSetId
) {
447 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
448 if ($is_quick_config) {
449 $this->_useForMember
= 0;
450 $this->set('useForMember', $this->_useForMember
);
454 if ($this->_values
['is_for_organization']) {
455 $this->buildOnBehalfOrganization();
458 //we allow premium for pledge during pledge creation only.
459 if (!CRM_Utils_Array
::value('pledge_id', $this->_values
)) {
460 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, TRUE);
463 if ($this->_values
['honor_block_is_active']) {
464 $this->buildHonorBlock();
468 //don't build pledge block when mid is passed
470 $config = CRM_Core_Config
::singleton();
471 if (in_array('CiviPledge', $config->enableComponents
)
472 && CRM_Utils_Array
::value('pledge_block_id', $this->_values
)
474 CRM_Pledge_BAO_PledgeBlock
::buildPledgeBlock($this);
478 //to create an cms user
479 if (!$this->_userID
) {
480 $createCMSUser = FALSE;
482 if ($this->_values
['custom_pre_id']) {
483 $profileID = $this->_values
['custom_pre_id'];
484 $createCMSUser = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
487 if (!$createCMSUser &&
488 $this->_values
['custom_post_id']
490 if (!is_array($this->_values
['custom_post_id'])) {
491 $profileIDs = array($this->_values
['custom_post_id']);
494 $profileIDs = $this->_values
['custom_post_id'];
496 foreach ($profileIDs as $pid) {
497 if (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
499 $createCMSUser = TRUE;
505 if ($createCMSUser) {
506 CRM_Core_BAO_CMSUser
::buildForm($this, $profileID, TRUE);
510 if ($pcpSupporter = CRM_PCP_BAO_PCP
::displayName($this->_pcpId
)) {
511 $pcp_supporter_text = ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
512 // 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.
513 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($this->_id
, 'contribute');
515 $pcp_supporter_text .= "You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!";
517 $this->assign('pcpSupporterText', $pcp_supporter_text);
519 $prms = array('id' => $this->_pcpId
);
520 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
521 if ($pcpInfo['is_honor_roll']) {
522 $this->assign('isHonor', TRUE);
523 $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL,
524 array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
526 $extraOption = array('onclick' => "return pcpAnonymous( );");
528 $elements[] = &$this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
529 $elements[] = &$this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
530 $this->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
531 $this->setDefaults(array('pcp_display_in_roll' => 1));
532 $this->setDefaults(array('pcp_is_anonymous' => 1));
534 $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
535 $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
539 //we have to load confirm contribution button in template
540 //when multiple payment processor as the user
541 //can toggle with payment processor selection
542 $billingModePaymentProcessors = 0;
543 if ( !empty( $this->_paymentProcessors
) ) {
544 foreach ($this->_paymentProcessors
as $key => $values) {
545 if ($values['billing_mode'] == CRM_Core_Payment
::BILLING_MODE_BUTTON
) {
546 $billingModePaymentProcessors++
;
551 if ($billingModePaymentProcessors && count($this->_paymentProcessors
) == $billingModePaymentProcessors) {
552 $allAreBillingModeProcessors = TRUE;
554 $allAreBillingModeProcessors = FALSE;
557 if (!($allAreBillingModeProcessors && !$this->_values
['is_pay_later'])) {
558 $submitButton = array(
560 'name' => ts('Contribute'),
561 'spacing' => ' ',
564 // Add submit-once behavior when confirm page disabled
565 if (empty($this->_values
['is_confirm_enabled'])) {
566 $submitButton['js'] = array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');");
568 $this->addButtons(array($submitButton));
571 $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
575 * Function to add the honor block
580 function buildHonorBlock() {
581 $this->assign('honor_block_is_active', TRUE);
582 $this->set('honor_block_is_active', TRUE);
584 $this->assign('honor_block_title', CRM_Utils_Array
::value('honor_block_title', $this->_values
));
585 $this->assign('honor_block_text', CRM_Utils_Array
::value('honor_block_text', $this->_values
));
587 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact');
588 $extraOption = array('onclick' => "enableHonorType();");
589 // radio button for Honor Type
590 $honorOptions = array();
591 $honor = CRM_Core_PseudoConstant
::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
592 foreach ($honor as $key => $var) {
593 $honorTypes[$key] = $this->createElement('radio', NULL, NULL, $var, $key, $extraOption);
595 $this->addGroup($honorTypes, 'honor_type_id', NULL);
598 $this->addElement('select', 'honor_prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'prefix_id'));
600 $this->addElement('text', 'honor_first_name', ts('First Name'), $attributes['first_name']);
603 $this->addElement('text', 'honor_last_name', ts('Last Name'), $attributes['last_name']);
606 $this->addElement('text', 'honor_email', ts('Email Address'), array('class' => 'email'));
607 $this->addRule('honor_email', ts('Honoree Email is not valid.'), 'email');
611 * build elements to enable pay on behalf of an organization.
615 function buildOnBehalfOrganization() {
616 if ($this->_membershipContactID
) {
617 $entityBlock = array('contact_id' => $this->_membershipContactID
);
618 CRM_Core_BAO_Location
::getValues($entityBlock, $this->_defaults
);
621 if (!$this->_onBehalfRequired
) {
622 $this->addElement('checkbox', 'is_for_organization',
623 $this->_values
['for_organization'],
624 NULL, array('onclick' => "showOnBehalf( );")
628 $this->assign('is_for_organization', TRUE);
629 $this->assign('urlPath', 'civicrm/contribute/transact');
633 * build elements to collect information for recurring contributions
637 public static function buildRecur(&$form) {
638 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionRecur');
639 $className = get_class($form);
641 $form->assign('is_recur_interval', CRM_Utils_Array
::value('is_recur_interval', $form->_values
));
642 $form->assign('is_recur_installments', CRM_Utils_Array
::value('is_recur_installments', $form->_values
));
644 $form->add('checkbox', 'is_recur', ts('I want to contribute this amount'), NULL);
646 if (CRM_Utils_Array
::value('is_recur_interval', $form->_values
) ||
$className == 'CRM_Contribute_Form_Contribution') {
647 $form->add('text', 'frequency_interval', ts('Every'), $attributes['frequency_interval']);
648 $form->addRule('frequency_interval', ts('Frequency must be a whole number (EXAMPLE: Every 3 months).'), 'integer');
651 // make sure frequency_interval is submitted as 1 if given no choice to user.
652 $form->add('hidden', 'frequency_interval', 1);
655 $frUnits = CRM_Utils_Array
::value('recur_frequency_unit', $form->_values
);
656 if (empty($frUnits) &&
657 $className == 'CRM_Contribute_Form_Contribution'
659 $frUnits = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
660 CRM_Core_OptionGroup
::values('recur_frequency_units')
664 $unitVals = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $frUnits);
666 // CRM 10860, display text instead of a dropdown if there's only 1 frequency unit
667 if(sizeof($unitVals) == 1) {
668 $form->assign('one_frequency_unit', true);
669 $unit = $unitVals[0];
670 $form->add('hidden', 'frequency_unit', $unit);
671 if (CRM_Utils_Array
::value('is_recur_interval', $form->_values
) ||
$className == 'CRM_Contribute_Form_Contribution') {
674 $form->assign('frequency_unit', $unit);
676 $form->assign('one_frequency_unit', false);
678 $frequencyUnits = CRM_Core_OptionGroup
::values('recur_frequency_units');
679 foreach ($unitVals as $key => $val) {
680 if (array_key_exists($val, $frequencyUnits)) {
681 $units[$val] = $frequencyUnits[$val];
682 if (CRM_Utils_Array
::value('is_recur_interval', $form->_values
) ||
$className == 'CRM_Contribute_Form_Contribution') {
683 $units[$val] = "{$frequencyUnits[$val]}(s)";
687 $frequencyUnit = &$form->add('select', 'frequency_unit', NULL, $units);
691 // FIXME: Ideally we should freeze select box if there is only
692 // one option but looks there is some problem /w QF freeze.
693 //if ( count( $units ) == 1 ) {
694 //$frequencyUnit->freeze( );
697 $form->add('text', 'installments', ts('installments'),
698 $attributes['installments']
700 $form->addRule('installments', ts('Number of installments must be a whole number.'), 'integer');
706 * @param array $fields the input form values
707 * @param array $files the uploaded files if any
708 * @param array $options additional user data
710 * @return true if no errors, else array of errors
714 static function formRule($fields, $files, $self) {
716 $amount = self
::computeAmount($fields, $self);
718 if ((CRM_Utils_Array
::value('selectMembership', $fields) &&
719 $fields['selectMembership'] != 'no_thanks'
721 (CRM_Utils_Array
::value('priceSetId', $fields) &&
725 $lifeMember = CRM_Member_BAO_Membership
::getAllContactMembership($self->_userID
, FALSE, TRUE);
727 $membershipOrgDetails = CRM_Member_BAO_MembershipType
::getMembershipTypeOrganization();
729 $unallowedOrgs = array();
730 foreach (array_keys($lifeMember) as $memTypeId) {
731 $unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
735 //check for atleast one pricefields should be selected
736 if (CRM_Utils_Array
::value('priceSetId', $fields)) {
737 $priceField = new CRM_Price_DAO_PriceField();
738 $priceField->price_set_id
= $fields['priceSetId'];
739 $priceField->orderBy('weight');
743 $membershipIsActive = TRUE;
744 $previousId = $otherAmount = FALSE;
745 while ($priceField->fetch()) {
747 if ($self->_quickConfig
&& ($priceField->name
== 'contribution_amount' ||
$priceField->name
== 'membership_amount')) {
748 $previousId = $priceField->id
;
749 if ($priceField->name
== 'membership_amount' && !$priceField->is_active
) {
750 $membershipIsActive = FALSE;
753 if ($priceField->name
== 'other_amount') {
754 if ($self->_quickConfig
&& !CRM_Utils_Array
::value("price_{$priceField->id}", $fields) &&
755 array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values
['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])) {
756 $otherAmount = $priceField->id
;
758 elseif (!empty($fields["price_{$priceField->id}"])) {
759 $otherAmountVal = $fields["price_{$priceField->id}"];
760 $min = CRM_Utils_Array
::value('min_amount', $self->_values
);
761 $max = CRM_Utils_Array
::value('max_amount', $self->_values
);
762 if ($min && $otherAmountVal < $min) {
763 $errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1',
767 if ($max && $otherAmountVal > $max) {
768 $errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.',
774 if (!empty($fields["price_{$priceField->id}"]) ||
($previousId == $priceField->id
&& isset($fields["price_{$previousId}"])
775 && empty($fields["price_{$previousId}"]))) {
776 $check[] = $priceField->id
;
781 if ($membershipIsActive && !$self->_membershipBlock
['is_required']
782 && $self->_values
['amount_block_is_active']) {
783 $membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
784 foreach ($self->_values
['fee'] as $fieldKey => $fieldValue) {
785 // if 'No thank you' membership is selected then set $membershipFieldId
786 if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array
::value('price_' . $fieldKey, $fields) == 0) {
787 $membershipFieldId = $fieldKey;
789 elseif ($membershipFieldId) {
790 if ($fieldValue['name'] == 'other_amount') {
791 $otherFieldId = $fieldKey;
793 elseif ($fieldValue['name'] == 'contribution_amount') {
794 $contributionFieldId = $fieldKey;
797 if (!$errorKey || CRM_Utils_Array
::value('price_' . $contributionFieldId, $fields) == '0') {
798 $errorKey = $fieldKey;
802 // $membershipFieldId is set and additional amount is 'No thank you' or NULL then throw error
803 if ($membershipFieldId && !(CRM_Utils_Array
::value('price_' . $contributionFieldId, $fields, -1) > 0)
804 && !CRM_Utils_Array
::value('price_' . $otherFieldId, $fields)) {
805 $errors["price_{$errorKey}"] = ts('Additional Contribution is required.');
809 if ($self->_useForMember
== 1 && $membershipIsActive) {
810 $errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
813 $errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
816 if($otherAmount && !empty($check)) {
817 $errors["price_{$otherAmount}"] = ts('Amount is required field.');
820 if ($self->_useForMember
== 1 && !empty($check) && $membershipIsActive) {
821 $priceFieldIDS = array();
822 $priceFieldMemTypes = array();
824 foreach ($self->_priceSet
['fields'] as $priceId => $value) {
825 if (!empty($fields['price_' . $priceId]) ||
($self->_quickConfig
&& $value['name'] == 'membership_amount' && !CRM_Utils_Array
::value('is_required', $self->_membershipBlock
))) {
826 if (CRM_Utils_Array
::value('price_' . $priceId, $fields) && is_array($fields['price_' . $priceId])) {
827 foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
829 $priceFieldIDS[] = $priceFldVal;
833 elseif (!$value['is_enter_qty'] && CRM_Utils_Array
::value('price_' . $priceId, $fields)) {
834 // The check for {!$value['is_enter_qty']} is done since, quantity fields allow entering
835 // quantity. And the quantity can't be conisdered as civicrm_price_field_value.id, CRM-9577
836 $priceFieldIDS[] = $fields['price_' . $priceId];
839 if (CRM_Utils_Array
::value('options', $value)) {
840 foreach ($value['options'] as $val) {
841 if (CRM_Utils_Array
::value('membership_type_id', $val)) {
842 $priceFieldMemTypes[] = $val['membership_type_id'];
849 if (!empty($lifeMember)) {
850 foreach ($priceFieldIDS as $priceFieldId) {
851 if (($id = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) &&
852 in_array($membershipOrgDetails[$id], $unallowedOrgs)
854 $errors['_qf_default'] = ts('You already have a lifetime membership and cannot select a membership with a shorter term.');
860 if (!empty($priceFieldIDS)) {
861 $ids = implode(',', $priceFieldIDS);
863 $priceFieldIDS['id'] = $fields['priceSetId'];
864 $self->set('memberPriceFieldIDS', $priceFieldIDS);
865 $count = CRM_Price_BAO_PriceSet
::getMembershipCount($ids);
866 foreach ($count as $id => $occurance) {
867 if ($occurance > 1) {
868 $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.');
873 if (empty($priceFieldMemTypes)) {
874 $errors['_qf_default'] = ts('Please select at least one membership option.');
878 CRM_Price_BAO_PriceSet
::processAmount($self->_values
['fee'],
882 if ($fields['amount'] < 0) {
883 $errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
885 $amount = $fields['amount'];
888 if (isset($fields['selectProduct']) &&
889 $fields['selectProduct'] != 'no_thanks') {
890 $productDAO = new CRM_Contribute_DAO_Product();
891 $productDAO->id
= $fields['selectProduct'];
892 $productDAO->find(TRUE);
893 $min_amount = $productDAO->min_contribution
;
895 if ($amount < $min_amount) {
896 $errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money
::format($min_amount)));
897 CRM_Core_Session
::setStatus($errors['selectProduct']);
901 if ($self->_values
['honor_block_is_active'] && CRM_Utils_Array
::value('honor_type_id', $fields)) {
902 // make sure there is a first name and last name if email is not there
903 if (!CRM_Utils_Array
::value('honor_email', $fields)) {
904 if (!CRM_Utils_Array
::value('honor_first_name', $fields) ||
905 !CRM_Utils_Array
::value('honor_last_name', $fields)
907 $errors['honor_last_name'] = ts('In Honor Of - First Name and Last Name, OR an Email Address is required.');
912 if ( CRM_Utils_Array
::value( 'is_recur', $fields ) ) {
913 if ($fields['frequency_interval'] <= 0) {
914 $errors['frequency_interval'] = ts('Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months).');
916 if ($fields['frequency_unit'] == '0') {
917 $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).');
921 if (CRM_Utils_Array
::value('is_recur', $fields) &&
922 CRM_Utils_Array
::value('payment_processor', $fields) == 0) {
923 $errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
926 if (CRM_Utils_Array
::value('is_for_organization', $fields) &&
927 !property_exists($self, 'organizationName')
930 if (!CRM_Utils_Array
::value('organization_name', $fields['onbehalf'])) {
931 if (CRM_Utils_Array
::value('org_option', $fields) && !$fields['onbehalfof_id']) {
932 $errors['organization_id'] = ts('Please select an organization or enter a new one.');
934 elseif (!CRM_Utils_Array
::value('org_option', $fields)) {
935 $errors['onbehalf']['organization_name'] = ts('Please enter the organization name.');
939 foreach ($fields['onbehalf'] as $key => $value) {
940 if (strstr($key, 'email')) {
941 $emailLocType = explode('-', $key);
944 if (!CRM_Utils_Array
::value("email-{$emailLocType[1]}", $fields['onbehalf'])) {
945 $errors['onbehalf']["email-{$emailLocType[1]}"] = ts('Organization email is required.');
949 // validate PCP fields - if not anonymous, we need a nick name value
950 if ($self->_pcpId
&& CRM_Utils_Array
::value('pcp_display_in_roll', $fields) &&
951 (CRM_Utils_Array
::value('pcp_is_anonymous', $fields) == 0) &&
952 CRM_Utils_Array
::value('pcp_roll_nickname', $fields) == ''
954 $errors['pcp_roll_nickname'] = ts('Please enter a name to include in the Honor Roll, or select \'contribute anonymously\'.');
957 // return if this is express mode
958 $config = CRM_Core_Config
::singleton();
959 if ($self->_paymentProcessor
&&
960 $self->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_BUTTON
962 if (CRM_Utils_Array
::value($self->_expressButtonName
. '_x', $fields) ||
963 CRM_Utils_Array
::value($self->_expressButtonName
. '_y', $fields) ||
964 CRM_Utils_Array
::value($self->_expressButtonName
, $fields)
970 //validate the pledge fields.
971 if (CRM_Utils_Array
::value('pledge_block_id', $self->_values
)) {
972 //validation for pledge payment.
973 if (CRM_Utils_Array
::value('pledge_id', $self->_values
)) {
974 if (empty($fields['pledge_amount'])) {
975 $errors['pledge_amount'] = ts('At least one payment option needs to be checked.');
978 elseif (CRM_Utils_Array
::value('is_pledge', $fields)) {
979 if (CRM_Utils_Rule
::positiveInteger(CRM_Utils_Array
::value('pledge_installments', $fields)) == FALSE) {
980 $errors['pledge_installments'] = ts('Please enter a valid pledge installment.');
983 if (CRM_Utils_Array
::value('pledge_installments', $fields) == NULL) {
984 $errors['pledge_installments'] = ts('Pledge Installments is required field.');
986 elseif (CRM_Utils_array
::value('pledge_installments', $fields) == 1) {
987 $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.');
989 elseif (CRM_Utils_array
::value('pledge_installments', $fields) == 0) {
990 $errors['pledge_installments'] = ts('Pledge Installments field must be > 1.');
994 //validation for Pledge Frequency Interval.
995 if (CRM_Utils_Rule
::positiveInteger(CRM_Utils_Array
::value('pledge_frequency_interval', $fields)) == FALSE) {
996 $errors['pledge_frequency_interval'] = ts('Please enter a valid Pledge Frequency Interval.');
999 if (CRM_Utils_Array
::value('pledge_frequency_interval', $fields) == NULL) {
1000 $errors['pledge_frequency_interval'] = ts('Pledge Frequency Interval. is required field.');
1002 elseif (CRM_Utils_array
::value('pledge_frequency_interval', $fields) == 0) {
1003 $errors['pledge_frequency_interval'] = ts('Pledge frequency interval field must be > 0');
1009 // also return if paylater mode
1010 if (CRM_Utils_Array
::value('payment_processor', $fields) == 0) {
1011 return empty($errors) ?
TRUE : $errors;
1014 // if the user has chosen a free membership or the amount is less than zero
1015 // i.e. we skip calling the payment processor and hence dont need credit card
1017 if ((float) $amount <= 0.0) {
1021 if (!empty($self->_paymentFields
)) {
1022 CRM_Core_Form
::validateMandatoryFields($self->_paymentFields
, $fields, $errors);
1024 CRM_Core_Payment_Form
::validateCreditCard($fields, $errors);
1026 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1027 if ($greetingType = CRM_Utils_Array
::value($greeting, $fields)) {
1028 $customizedValue = CRM_Core_OptionGroup
::getValue($greeting, 'Customized', 'name');
1029 if ($customizedValue == $greetingType && empty($fielse[$greeting . '_custom'])) {
1030 $errors[$greeting . '_custom'] = ts('Custom %1 is a required field if %1 is of type Customized.',
1031 array(1 => ucwords(str_replace('_', " ", $greeting)))
1037 return empty($errors) ?
TRUE : $errors;
1040 public static function computeAmount(&$params, &$form) {
1043 // first clean up the other amount field if present
1044 if (isset($params['amount_other'])) {
1045 $params['amount_other'] = CRM_Utils_Rule
::cleanMoney($params['amount_other']);
1048 if (CRM_Utils_Array
::value('amount', $params) == 'amount_other_radio' ||
1049 CRM_Utils_Array
::value('amount_other', $params)
1051 $amount = $params['amount_other'];
1053 elseif (!empty($params['pledge_amount'])) {
1055 foreach ($params['pledge_amount'] as $paymentId => $dontCare) {
1056 $amount +
= CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount');
1060 if (CRM_Utils_Array
::value('amount', $form->_values
)) {
1061 $amountID = CRM_Utils_Array
::value('amount', $params);
1064 $params['amount_level'] = CRM_Utils_Array
::value('label', $form->_values
[$amountID]);
1065 $amount = CRM_Utils_Array
::value('value', $form->_values
[$amountID]);
1073 * Function to process the form
1079 public function postProcess() {
1080 $config = CRM_Core_Config
::singleton();
1082 // we first reset the confirm page so it accepts new values
1083 $this->controller
->resetPage('Confirm');
1085 // get the submitted form values.
1086 $params = $this->controller
->exportValues($this->_name
);
1088 if (CRM_Utils_Array
::value('priceSetId', $params)) {
1089 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
1090 $formValue = array();
1091 if ($is_quick_config) {
1092 $priceField = new CRM_Price_DAO_PriceField();
1093 $priceField->price_set_id
= $params['priceSetId'];
1094 $priceField->orderBy('weight');
1095 $priceField->find();
1098 $otherAmount = FALSE;
1099 while ($priceField->fetch()) {
1100 CRM_Price_BAO_PriceFieldValue
::getValues($priceField->id
, $values);
1101 if ($priceField->name
== 'membership_amount') {
1102 if ($priceFiledID = CRM_Utils_Array
::value("price_{$priceField->id}", $params)) {
1103 $this->_params
['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array
::value('membership_type_id', $values[$priceFiledID]);
1104 $this->set('selectMembership',CRM_Utils_Array
::value('selectMembership', $params));
1105 if (CRM_Utils_Array
::value('is_separate_payment', $this->_membershipBlock
) == 0) {
1106 $this->_values
['amount'] = CRM_Utils_Array
::value('amount', $values[$priceFiledID]);
1110 if ($priceField->name
== 'contribution_amount') {
1111 $priceFiledID = CRM_Utils_Array
::value("price_{$priceField->id}", $params);
1112 if ($priceFiledID > 0 && !empty($priceFiledID)) {
1113 $params['amount'] = $priceFiledID;
1114 $this->_values
['amount'] = CRM_Utils_Array
::value('amount', $values[$priceFiledID]);
1115 $this->_values
[$priceFiledID]['value'] = CRM_Utils_Array
::value('amount', $values[$priceFiledID]);
1116 $this->_values
[$priceFiledID]['label'] = CRM_Utils_Array
::value('label', $values[$priceFiledID]);
1117 $this->_values
[$priceFiledID]['amount_id'] = CRM_Utils_Array
::value('id', $values[$priceFiledID]);
1118 $this->_values
[$priceFiledID]['weight'] = CRM_Utils_Array
::value('weight', $values[$priceFiledID]);
1121 if ($priceField->name
== 'other_amount' && $priceFiledID = CRM_Utils_Array
::value("price_{$priceField->id}", $params)) {
1122 $params['amount_other'] = $priceFiledID;
1128 if (($this->_values
['is_pay_later'] &&
1129 empty($this->_paymentProcessor
) &&
1130 !array_key_exists('hidden_processor', $params)) ||
1131 CRM_Utils_Array
::value('payment_processor', $params) == 0) {
1132 $params['is_pay_later'] = 1;
1135 $params['is_pay_later'] = 0;
1138 $this->set('is_pay_later', $params['is_pay_later']);
1139 // assign pay later stuff
1140 $this->_params
['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
1141 $this->assign('is_pay_later', $params['is_pay_later']);
1142 if ($params['is_pay_later']) {
1143 $this->assign('pay_later_text', $this->_values
['pay_later_text']);
1144 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
1147 //carry campaign from profile.
1148 if (array_key_exists('contribution_campaign_id', $params)) {
1149 $params['campaign_id'] = $params['contribution_campaign_id'];
1152 if (CRM_Utils_Array
::value('onbehalfof_id', $params)) {
1153 $params['organization_id'] = $params['onbehalfof_id'];
1156 $params['currencyID'] = $config->defaultCurrency
;
1157 $params['amount'] = self
::computeAmount($params, $this);
1158 $params['separate_amount'] = $params['amount'];
1160 if (CRM_Utils_Array
::value('selectMembership', $params)) {
1161 if (!empty($this->_membershipTypeValues
)) {
1162 $membershipTypeValues = $this->_membershipTypeValues
[$params['selectMembership']];
1165 $membershipTypeValues = CRM_Member_BAO_Membership
::buildMembershipTypeValues($this,
1166 $params['selectMembership']
1169 $memFee = $membershipTypeValues['minimum_fee'];
1170 if (!$params['amount'] && !$this->_separateMembershipPayment
) {
1171 $params['amount'] = $memFee ?
$memFee : 0;
1175 //If the membership & contribution is used in contribution page & not seperate payment
1176 $fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
1177 $proceFieldAmount = 0;
1178 if ($this->_separateMembershipPayment
== 0) {
1179 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config');
1180 if ($is_quick_config) {
1181 foreach ($this->_priceSet
['fields'] as $fieldKey => $fieldVal) {
1182 if ($fieldVal['name'] == 'membership_amount' && CRM_Utils_Array
::value('price_' . $fieldKey , $params)) {
1183 $fieldId = $fieldVal['id'];
1184 $fieldOption = $params['price_' . $fieldId];
1185 $proceFieldAmount +
= $fieldVal['options'][$this->_submitValues
['price_' . $fieldId]]['amount'];
1189 if (CRM_Utils_Array
::value('price_' . $fieldKey, $params) && $memPresent && ($fieldVal['name'] == 'other_amount' ||
$fieldVal['name'] == 'contribution_amount')) {
1190 $fieldId = $fieldVal['id'];
1191 if ($fieldVal['name'] == 'other_amount') {
1192 $proceFieldAmount +
= $this->_submitValues
['price_' . $fieldId];
1194 elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues
['price_' . $fieldId] > 0) {
1195 $proceFieldAmount +
= $fieldVal['options'][$this->_submitValues
['price_' . $fieldId]]['amount'];
1197 unset($params['price_' . $fieldId]);
1205 if (!isset($params['amount_other'])) {
1206 $this->set('amount_level', CRM_Utils_Array
::value('amount_level', $params));
1209 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $params)) {
1210 $lineItem = array();
1211 $is_quick_config = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config' );
1212 if ( $is_quick_config ) {
1213 foreach ( $this->_values
['fee'] as $key => & $val ) {
1214 if ( $val['name'] == 'other_amount' && $val['html_type'] == 'Text' && array_key_exists( 'price_'.$key, $params ) && $params['price_'.$key] != 0 ) {
1215 foreach ( $val['options'] as $optionKey => & $options ) {
1216 $options['amount'] = CRM_Utils_Array
::value( 'price_'.$key, $params );
1219 $params['price_'.$key] = 1;
1226 if ($this->_membershipBlock
) {
1227 $component = 'membership';
1229 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'], $params, $lineItem[$priceSetId], $component);
1231 if ($proceFieldAmount) {
1232 $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
1233 $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
1234 if (!$this->_membershipBlock
['is_separate_payment']) {
1235 $params['amount'] = $proceFieldAmount; //require when separate membership not used
1238 $this->set('lineItem', $lineItem);
1241 if ($this->_membershipBlock
['is_separate_payment'] && CRM_Utils_Array
::value('separate_amount', $params)) {
1242 $this->set('amount', $params['separate_amount']);
1244 $this->set('amount', $params['amount']);
1247 // generate and set an invoiceID for this transaction
1248 $invoiceID = md5(uniqid(rand(), TRUE));
1249 $this->set('invoiceID', $invoiceID);
1251 // required only if is_monetary and valid postive amount
1252 if ($this->_values
['is_monetary'] &&
1253 is_array($this->_paymentProcessor
) &&
1254 ((float ) $params['amount'] > 0.0 ||
$memFee > 0.0)
1257 // default mode is direct
1258 $this->set('contributeMode', 'direct');
1260 if ($this->_paymentProcessor
&&
1261 $this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_BUTTON
1263 //get the button name
1264 $buttonName = $this->controller
->getButtonName();
1265 if (in_array($buttonName,
1266 array($this->_expressButtonName
, $this->_expressButtonName
. '_x', $this->_expressButtonName
. '_y')
1268 !CRM_Utils_Array
::value('is_pay_later', $params)
1270 $this->set('contributeMode', 'express');
1272 $donateURL = CRM_Utils_System
::url('civicrm/contribute', '_qf_Contribute_display=1');
1273 $params['cancelURL'] = CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_Main_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
1274 $params['returnURL'] = CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_Confirm_display=1&rfp=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
1275 $params['invoiceID'] = $invoiceID;
1277 //default action is Sale
1278 $params['payment_action'] = 'Sale';
1280 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1281 $token = $payment->setExpressCheckout($params);
1282 if (is_a($token, 'CRM_Core_Error')) {
1283 CRM_Core_Error
::displaySessionError($token);
1284 CRM_Utils_System
::redirect($params['cancelURL']);
1287 $this->set('token', $token);
1289 $paymentURL = $this->_paymentProcessor
['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token=$token";
1290 CRM_Utils_System
::redirect($paymentURL);
1293 elseif ($this->_paymentProcessor
&&
1294 $this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_NOTIFY
1296 $this->set('contributeMode', 'notify');
1300 // should we skip the confirm page?
1301 if (!CRM_Utils_Array
::value('is_confirm_enabled', $this->_values
)) {
1302 // call the post process hook for the main page before we switch to confirm
1303 $this->postProcessHook();
1305 // build the confirm page
1306 $confirmForm = &$this->controller
->_pages
['Confirm'];
1307 $confirmForm->preProcess();
1308 $confirmForm->buildQuickForm();
1310 // the confirmation page is valid
1311 $data = &$this->controller
->container();
1312 $data['valid']['Confirm'] = 1;
1314 // confirm the contribution
1315 // mainProcess calls the hook also
1316 $confirmForm->mainProcess();
1317 $qfKey = $this->controller
->_key
;
1319 // redirect to thank you page
1320 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey=$qfKey", TRUE, NULL, FALSE));
1325 * Handle Payment Processor switching
1326 * For contribution and event registration forms
1328 static function preProcessPaymentOptions(&$form, $noFees = FALSE) {
1329 $form->_snippet
= CRM_Utils_Array
::value('snippet', $_GET);
1330 $form->assign('snippet', $form->_snippet
);
1332 $form->_paymentProcessors
= $noFees ?
array() : $form->get('paymentProcessors');
1333 $form->_ppType
= NULL;
1334 if ($form->_paymentProcessors
) {
1335 // Fetch type during ajax request
1336 if (isset($_GET['type']) && $form->_snippet
) {
1337 $form->_ppType
= $_GET['type'];
1339 // Remember type during form post
1340 elseif (!empty($form->_submitValues
)) {
1341 $form->_ppType
= CRM_Utils_Array
::value('payment_processor', $form->_submitValues
);
1342 $form->_paymentProcessor
= CRM_Utils_Array
::value($form->_ppType
, $form->_paymentProcessors
);
1343 $form->set('type', $form->_ppType
);
1344 $form->set('mode', $form->_mode
);
1345 $form->set('paymentProcessor', $form->_paymentProcessor
);
1347 // Set default payment processor
1349 foreach ($form->_paymentProcessors
as $values) {
1350 if (!empty($values['is_default']) ||
count($form->_paymentProcessors
) == 1) {
1351 $form->_ppType
= $values['id'];
1356 if ($form->_ppType
) {
1357 CRM_Core_Payment_ProcessorForm
::preProcess($form);
1360 //get payPal express id and make it available to template
1361 foreach ($form->_paymentProcessors
as $ppId => $values) {
1362 $payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ?
$values['id'] : 0;
1363 $form->assign('payPalExpressId', $payPalExpressId);
1364 if ($payPalExpressId) {
1368 if (!$form->_snippet
) {
1369 // Add JS to show icons for the accepted credit cards
1370 $creditCardTypes = CRM_Core_Payment_Form
::getCreditCardCSSNames();
1371 CRM_Core_Resources
::singleton()
1372 ->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10)
1373 // workaround for CRM-13634
1374 // ->addSetting(array('config' => array('creditCardTypes' => $creditCardTypes)));
1375 ->addScript('CRM.config.creditCardTypes = ' . json_encode($creditCardTypes) . ';');
1378 $form->assign('ppType', $form->_ppType
);