3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * form to process actions on the group aspect of Custom Data
39 class CRM_Contribute_Form_Contribution_Confirm
extends CRM_Contribute_Form_ContributionBase
{
42 * The id of the contact associated with this contribution
50 * The id of the contribution object that is created when the form is submitted
54 public $_contributionID;
57 * Set the parameters to be passed to contribution create function
59 * @param array $params
60 * @param integer $contactID
61 * @param int $financialTypeID
63 * @param int $contributionPageId
64 * @param $nonDeductibleAmount
65 * @param int $campaignId
68 * @param $paymentProcessorOutcome
70 * @param int $recurringContributionID
72 * @param int $addressID
73 * @param int $softCreditToID
74 * @param array $lineItems
78 public static function getContributionParams($params, $contactID, $financialTypeID, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending,
79 $paymentProcessorOutcome, $receiptDate, $recurringContributionID, $isTest, $addressID, $softCreditToID, $lineItems)
81 $contributionParams = array(
82 'contact_id' => $contactID,
83 'financial_type_id' => $financialTypeID,
84 'contribution_page_id' => $contributionPageId,
85 'receive_date' => (CRM_Utils_Array
::value('receive_date', $params)) ? CRM_Utils_Date
::processDate($params['receive_date']) : date('YmdHis'),
86 'non_deductible_amount' => $nonDeductibleAmount,
87 'total_amount' => $params['amount'],
88 'tax_amount' => CRM_Utils_Array
::value('tax_amount', $params),
89 'amount_level' => CRM_Utils_Array
::value('amount_level', $params),
90 'invoice_id' => $params['invoiceID'],
91 'currency' => $params['currencyID'],
93 (!$online ||
!empty($params['source'])) ?
94 CRM_Utils_Array
::value('source', $params) :
95 CRM_Utils_Array
::value('description', $params),
96 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
97 //configure cancel reason, cancel date and thankyou date
98 //from 'contribution' type profile if included
99 'cancel_reason' => CRM_Utils_Array
::value('cancel_reason', $params, 0),
101 isset($params['cancel_date']) ?
102 CRM_Utils_Date
::format($params['cancel_date']) :
105 isset($params['thankyou_date']) ?
106 CRM_Utils_Date
::format($params['thankyou_date']) :
108 'campaign_id' => $campaignId,
109 'is_test' => $isTest,
110 'address_id' => $addressID,
111 //setting to make available to hook - although seems wrong to set on form for BAO hook availability
112 'soft_credit_to' => $softCreditToID,
113 'line_item' => $lineItems,
114 'skipLineItem' => CRM_Utils_Array
::value('skipLineItem', $params, 0)
116 if (!$online && isset($params['thankyou_date'])) {
117 $contributionParam['thankyou_date'] = $params['thankyou_date'];
119 if (!$online ||
$isMonetary) {
120 if (empty($params['is_pay_later'])) {
121 $contributionParams['payment_instrument_id'] = 1;
124 if ($paymentProcessorOutcome) {
125 $contributionParams['payment_processor'] = CRM_Utils_Array
::value('payment_processor', $paymentProcessorOutcome);
127 if (!$pending && $paymentProcessorOutcome) {
128 $contributionParams +
= array(
129 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $paymentProcessorOutcome),
130 'net_amount' => CRM_Utils_Array
::value('net_amount', $paymentProcessorOutcome, $params['amount']),
131 'trxn_id' => $paymentProcessorOutcome['trxn_id'],
132 'receipt_date' => $receiptDate,
133 // also add financial_trxn details as part of fix for CRM-4724
134 'trxn_result_code' => CRM_Utils_Array
::value('trxn_result_code', $paymentProcessorOutcome),
138 // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
139 $contributionParams['non_deductible_amount'] = trim(CRM_Utils_Money
::format($contributionParams['non_deductible_amount'], ' '));
140 $contributionParams['total_amount'] = trim(CRM_Utils_Money
::format($contributionParams['total_amount'], ' '));
142 if ($recurringContributionID) {
143 $contributionParams['contribution_recur_id'] = $recurringContributionID;
146 $contributionParams['contribution_status_id'] = $pending ?
2 : 1;
147 if (isset($contributionParams['invoice_id'])) {
148 $contributionParams['id'] = CRM_Core_DAO
::getFieldValue(
149 'CRM_Contribute_DAO_Contribution',
150 $contributionParams['invoice_id'],
156 return $contributionParams;
160 * Set variables up before form is built
164 public function preProcess() {
165 $config = CRM_Core_Config
::singleton();
166 parent
::preProcess();
168 // lineItem isn't set until Register postProcess
169 $this->_lineItem
= $this->get('lineItem');
170 $this->_paymentProcessor
= $this->get('paymentProcessor');
172 if ($this->_contributeMode
== 'express') {
173 // rfp == redirect from paypal
174 $rfp = CRM_Utils_Request
::retrieve('rfp', 'Boolean',
175 CRM_Core_DAO
::$_nullObject, FALSE, NULL, 'GET'
178 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
179 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
181 $this->_params
['payer'] = $expressParams['payer'];
182 $this->_params
['payer_id'] = $expressParams['payer_id'];
183 $this->_params
['payer_status'] = $expressParams['payer_status'];
185 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $expressParams, $this->_params
, FALSE);
187 // fix state and country id if present
188 if (!empty($this->_params
["billing_state_province_id-{$this->_bltID}"])) {
189 $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
191 if (!empty($this->_params
["billing_country_id-{$this->_bltID}"]) && $this->_params
["billing_country_id-{$this->_bltID}"]) {
192 $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
195 // set a few other parameters for PayPal
196 $this->_params
['token'] = $this->get('token');
198 $this->_params
['amount'] = $this->get('amount');
200 if (!empty($this->_membershipBlock
)){
201 $this->_params
['selectMembership'] = $this->get('selectMembership');
203 // we use this here to incorporate any changes made by folks in hooks
204 $this->_params
['currencyID'] = $config->defaultCurrency
;
206 $this->_params
['payment_action'] = 'Sale';
208 // also merge all the other values from the profile fields
209 $values = $this->controller
->exportValues('Main');
211 'amount', 'amount_other',
212 "billing_street_address-{$this->_bltID}",
213 "billing_city-{$this->_bltID}",
214 "billing_state_province_id-{$this->_bltID}",
215 "billing_postal_code-{$this->_bltID}",
216 "billing_country_id-{$this->_bltID}",
218 foreach ($values as $name => $value) {
220 if (!in_array($name, $skipFields)) {
221 $this->_params
[$name] = $value;
224 $this->set('getExpressCheckoutDetails', $this->_params
);
227 $this->_params
= $this->get('getExpressCheckoutDetails');
231 $this->_params
= $this->controller
->exportValues('Main');
233 if (!empty($this->_params
["billing_state_province_id-{$this->_bltID}"])) {
234 $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
236 if (!empty($this->_params
["billing_country_id-{$this->_bltID}"])) {
237 $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
240 if (isset($this->_params
['credit_card_exp_date'])) {
241 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
242 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
245 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
246 $this->_params
['amount'] = $this->get('amount');
247 $this->_params
['tax_amount'] = $this->get('tax_amount');
249 $this->_useForMember
= $this->get('useForMember');
251 if (isset($this->_params
['amount'])) {
252 $this->setFormAmountFields($this->_params
['priceSetId']);
254 $this->_params
['currencyID'] = $config->defaultCurrency
;
255 $this->_params
['payment_action'] = 'Sale';
258 $this->_params
['is_pay_later'] = $this->get('is_pay_later');
259 $this->assign('is_pay_later', $this->_params
['is_pay_later']);
260 if ($this->_params
['is_pay_later']) {
261 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
263 // if onbehalf-of-organization
264 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
266 if (empty($this->_params
['org_option']) && empty($this->_params
['organization_id'])) {
267 if (!empty($this->_params
['onbehalfof_id'])) {
268 $this->_params
['organization_id'] = $this->_params
['onbehalfof_id'];
271 $this->_params
['organization_id'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_params
['onbehalf']['organization_name'], 'id', 'display_name');
275 $this->_params
['organization_name'] = $this->_params
['onbehalf']['organization_name'];
276 $addressBlocks = array(
277 'street_address', 'city', 'state_province',
278 'postal_code', 'country', 'supplemental_address_1',
279 'supplemental_address_2', 'supplemental_address_3',
280 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'address_name',
283 $blocks = array('email', 'phone', 'im', 'url', 'openid');
284 foreach ($this->_params
['onbehalf'] as $loc => $value) {
285 $field = $typeId = NULL;
286 if (strstr($loc, '-')) {
287 list($field, $locType) = explode('-', $loc);
290 if (in_array($field, $addressBlocks)) {
291 if ($locType == 'Primary') {
292 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
293 $locType = $defaultLocationType->id
;
296 if ($field == 'country') {
297 $value = CRM_Core_PseudoConstant
::countryIsoCode($value);
299 elseif ($field == 'state_province') {
300 $value = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value);
304 if (isset($this->_params
['onbehalf_location']['address'])
305 && count($this->_params
['onbehalf_location']['address']) > 0) {
309 $this->_params
['onbehalf_location']['address'][$locType][$field] = $value;
310 if (empty($this->_params
['onbehalf_location']['address'][$locType]['is_primary'])) {
311 $this->_params
['onbehalf_location']['address'][$locType]['is_primary'] = $isPrimary;
313 $this->_params
['onbehalf_location']['address'][$locType]['location_type_id'] = $locType;
315 elseif (in_array($field, $blocks)) {
316 if (!$typeId ||
is_numeric($typeId)) {
317 $blockName = $fieldName = $field;
318 $locationType = 'location_type_id';
319 if ( $locType == 'Primary' ) {
320 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
321 $locationValue = $defaultLocationType->id
;
324 $locationValue = $locType;
327 $phoneExtField = array();
329 if ($field == 'url') {
330 $blockName = 'website';
331 $locationType = 'website_type_id';
332 list($field, $locationValue) = explode('-', $loc);
334 elseif ($field == 'im') {
336 $locTypeId = 'provider_id';
337 $typeId = $this->_params
['onbehalf']["{$loc}-provider_id"];
339 elseif ($field == 'phone') {
340 list($field, $locType, $typeId) = explode('-', $loc);
341 $locTypeId = 'phone_type_id';
343 //check if extension field exists
344 $extField = str_replace('phone','phone_ext', $loc);
345 if (isset($this->_params
['onbehalf'][$extField])) {
346 $phoneExtField = array('phone_ext' => $this->_params
['onbehalf'][$extField]);
351 if ( isset ($this->_params
['onbehalf_location'][$blockName] )
352 && count( $this->_params
['onbehalf_location'][$blockName] ) > 0 ) {
355 if ($locationValue) {
356 $blockValues = array(
357 $fieldName => $value,
358 $locationType => $locationValue,
359 'is_primary' => $isPrimary,
363 $blockValues = array_merge($blockValues, array($locTypeId => $typeId));
365 if (!empty($phoneExtField)) {
366 $blockValues = array_merge($blockValues, $phoneExtField);
369 $this->_params
['onbehalf_location'][$blockName][] = $blockValues;
373 elseif (strstr($loc, 'custom')) {
374 if ($value && isset($this->_params
['onbehalf']["{$loc}_id"])) {
375 $value = $this->_params
['onbehalf']["{$loc}_id"];
377 $this->_params
['onbehalf_location']["{$loc}"] = $value;
380 if ($loc == 'contact_sub_type') {
381 $this->_params
['onbehalf_location'][$loc] = $value;
384 $this->_params
['onbehalf_location'][$field] = $value;
389 elseif (!empty($this->_values
['is_for_organization'])) {
390 // no on behalf of an organization, CRM-5519
391 // so reset loc blocks from main params.
393 'phone', 'email', 'address') as $blk) {
394 if (isset($this->_params
[$blk])) {
395 unset($this->_params
[$blk]);
400 // if auto renew checkbox is set, initiate a open-ended recurring membership
401 if ((!empty($this->_params
['selectMembership']) ||
!empty($this->_params
['priceSetId'])) && !empty($this->_paymentProcessor
['is_recur']) &&
402 CRM_Utils_Array
::value('auto_renew', $this->_params
) && empty($this->_params
['is_recur']) && empty($this->_params
['frequency_interval'])) {
404 $this->_params
['is_recur'] = $this->_values
['is_recur'] = 1;
405 // check if price set is not quick config
406 if (!empty($this->_params
['priceSetId']) && !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params
['priceSetId'], 'is_quick_config')) {
407 list($this->_params
['frequency_interval'], $this->_params
['frequency_unit']) = CRM_Price_BAO_PriceSet
::getRecurDetails($this->_params
['priceSetId']);
410 // FIXME: set interval and unit based on selected membership type
411 $this->_params
['frequency_interval'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
412 $this->_params
['selectMembership'], 'duration_interval'
414 $this->_params
['frequency_unit'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
415 $this->_params
['selectMembership'], 'duration_unit'
421 $params = $this->processPcp($this, $this->_params
);
422 $this->_params
= $params;
424 $this->_params
['invoiceID'] = $this->get('invoiceID');
426 //carry campaign from profile.
427 if (array_key_exists('contribution_campaign_id', $this->_params
)) {
428 $this->_params
['campaign_id'] = $this->_params
['contribution_campaign_id'];
431 // assign contribution page id to the template so we can add css class for it
432 $this->assign('contributionPageID', $this->_id
);
434 $this->set('params', $this->_params
);
438 * Build the form object
442 public function buildQuickForm() {
443 $this->assignToTemplate();
445 $params = $this->_params
;
446 // make sure we have values for it
447 if ($this->_honor_block_is_active
&& !empty($params['soft_credit_type_id'])) {
449 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
451 $this->assign('honor_block_is_active', $this->_honor_block_is_active
);
452 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
453 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
455 $fieldTypes = array('Contact');
456 $fieldTypes[] = CRM_Core_BAO_UFGroup
::getContactType($params['honoree_profile_id']);
457 $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
459 $this->assign('receiptFromEmail', CRM_Utils_Array
::value('receipt_from_email', $this->_values
));
460 $amount_block_is_active = $this->get('amount_block_is_active');
461 $this->assign('amount_block_is_active', $amount_block_is_active);
463 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,'contribution_invoice_settings');
464 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
466 $getTaxDetails = FALSE;
467 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
468 foreach ($this->_lineItem
as $key => $value) {
469 foreach ($value as $v) {
470 if (isset($v['tax_rate'])) {
471 if ($v['tax_rate'] != '') {
472 $getTaxDetails = TRUE;
477 $this->assign('getTaxDetails', $getTaxDetails);
478 $this->assign('taxTerm', $taxTerm);
479 $this->assign('totalTaxAmount', $params['tax_amount']);
481 if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
482 $option = CRM_Utils_Array
::value('options_' . $params['selectProduct'], $params);
483 $productID = $params['selectProduct'];
484 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, FALSE,
487 $this->set('productID', $productID);
488 $this->set('option', $option);
490 $config = CRM_Core_Config
::singleton();
491 if (in_array('CiviMember', $config->enableComponents
)) {
492 if (isset($params['selectMembership']) &&
493 $params['selectMembership'] != 'no_thanks'
495 CRM_Member_BAO_Membership
::buildMembershipBlock($this,
497 $this->_membershipContactID
,
499 $params['selectMembership'],
504 $this->assign('membershipBlock', FALSE);
507 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre', TRUE);
508 $this->buildCustom($this->_values
['custom_post_id'], 'customPost', TRUE);
510 if (!empty($params['hidden_onbehalf_profile'])) {
511 $ufJoinParams = array(
512 'module' => 'onBehalf',
513 'entity_table' => 'civicrm_contribution_page',
514 'entity_id' => $this->_id
,
516 $OnBehalfProfile = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
517 $profileId = $OnBehalfProfile[0];
519 $fieldTypes = array('Contact', 'Organization');
520 $contactSubType = CRM_Contact_BAO_ContactType
::subTypes('Organization');
521 $fieldTypes = array_merge($fieldTypes, $contactSubType);
522 if (is_array($this->_membershipBlock
) && !empty($this->_membershipBlock
)) {
523 $fieldTypes = array_merge($fieldTypes, array('Membership'));
526 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
529 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
532 $this->_separateMembershipPayment
= $this->get('separateMembershipPayment');
533 $this->assign('is_separate_payment', $this->_separateMembershipPayment
);
534 if ($this->_priceSetId
&& !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
535 $this->assign('lineItem', $this->_lineItem
);
537 $this->assign('is_quick_config', 1);
538 $this->_params
['is_quick_config'] = 1;
540 $this->assign('priceSetID', $this->_priceSetId
);
541 $paymentProcessorType = CRM_Core_PseudoConstant
::paymentProcessorType(false, null, 'name');
542 if ($this->_paymentProcessor
&&
543 $this->_paymentProcessor
['payment_processor_type_id'] == CRM_Utils_Array
::key('Google_Checkout', $paymentProcessorType)
544 && !$this->_params
['is_pay_later'] && !($this->_amount
== 0)
546 $this->_checkoutButtonName
= $this->getButtonName('next', 'checkout');
548 $this->_checkoutButtonName
,
549 $this->_paymentProcessor
['url_button'],
550 array('class' => 'crm-form-submit')
553 $this->addButtons(array(
556 'name' => ts('<< Go Back'),
562 if ($this->_contributeMode
== 'notify' ||
!$this->_values
['is_monetary'] ||
563 $this->_amount
<= 0.0 ||
$this->_params
['is_pay_later'] ||
564 ($this->_separateMembershipPayment
&& $this->_amount
<= 0.0)
566 $contribButton = ts('Continue >>');
567 $this->assign('button', ts('Continue'));
570 $contribButton = ts('Make Contribution');
571 $this->assign('button', ts('Make Contribution'));
573 $this->addButtons(array(
576 'name' => $contribButton,
577 'spacing' => ' ',
579 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"),
583 'name' => ts('Go Back'),
590 $fields = array_fill_keys(array_keys($this->_fields
), 1);
591 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
593 $contact = $this->_params
;
594 foreach ($fields as $name => $dontCare) {
595 // Recursively set defaults for nested fields
596 if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' ||
$name == 'honor')) {
597 foreach ($contact[$name] as $fieldName => $fieldValue) {
598 if (is_array($fieldValue) && !in_array($this->_fields
[$name][$fieldName]['html_type'], array('Multi-Select','AdvMulti-Select'))) {
599 foreach ($fieldValue as $key => $value) {
600 $defaults["{$name}[{$fieldName}][{$key}]"] = $value;
604 $defaults["{$name}[{$fieldName}]"] = $fieldValue;
608 elseif (isset($contact[$name])) {
609 $defaults[$name] = $contact[$name];
610 if (substr($name, 0, 7) == 'custom_') {
611 $timeField = "{$name}_time";
612 if (isset($contact[$timeField])) {
613 $defaults[$timeField] = $contact[$timeField];
615 if (isset($contact["{$name}_id"])) {
616 $defaults["{$name}_id"] = $contact["{$name}_id"];
619 elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
620 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
625 $this->assign('useForMember', $this->get('useForMember'));
627 $this->setDefaults($defaults);
633 * Overwrite action, since we are only showing elements in frozen mode
634 * no help display needed
638 public function getAction() {
639 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
640 return CRM_Core_Action
::VIEW | CRM_Core_Action
::PREVIEW
;
643 return CRM_Core_Action
::VIEW
;
648 * Set default values for the form. Note that in edit/view mode
649 * the default values are retrieved from the database
654 public function setDefaultValues() {}
661 public function postProcess() {
662 $contactID = $this->getContactID();
663 $isPayLater = $this->_params
['is_pay_later'];
664 if ($this->_params
['payment_processor'] == 0) {
665 $this->_params
['is_pay_later'] = $isPayLater = TRUE;
667 // add a description field at the very beginning
668 $this->_params
['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo
['title']) ?
$this->_pcpInfo
['title'] : $this->_values
['title']);
670 // also add accounting code
671 $this->_params
['accountingCode'] = CRM_Utils_Array
::value('accountingCode',
676 $this->_params
['currencyID'] = CRM_Core_Config
::singleton()->defaultCurrency
;
678 //carry payment processor id.
679 if ($paymentProcessorId = CRM_Utils_Array
::value('id', $this->_paymentProcessor
)) {
680 $this->_params
['payment_processor_id'] = $paymentProcessorId;
682 if (!empty($params['image_URL'])) {
683 CRM_Contact_BAO_Contact
::processImageParams($params);
685 $premiumParams = $membershipParams = $params = $this->_params
;
686 $fields = array('email-Primary' => 1);
688 // get the add to groups
689 $addToGroups = array();
691 // now set the values for the billing location.
692 foreach ($this->_fields
as $name => $value) {
695 // get the add to groups for uf fields
696 if (!empty($value['add_to_group_id'])) {
697 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
701 if (!array_key_exists('first_name', $fields)) {
702 $nameFields = array('first_name', 'middle_name', 'last_name');
703 foreach ($nameFields as $name) {
705 if (array_key_exists("billing_$name", $params)) {
706 $params[$name] = $params["billing_{$name}"];
707 $params['preserveDBName'] = TRUE;
712 // billing email address
713 $fields["email-{$this->_bltID}"] = 1;
715 //unset the billing parameters if it is pay later mode
716 //to avoid creation of billing location
717 if ($isPayLater && !$this->_isBillingAddressRequiredForPayLater
) {
718 $billingFields = array(
719 'billing_first_name',
720 'billing_middle_name',
722 "billing_street_address-{$this->_bltID}",
723 "billing_city-{$this->_bltID}",
724 "billing_state_province-{$this->_bltID}",
725 "billing_state_province_id-{$this->_bltID}",
726 "billing_postal_code-{$this->_bltID}",
727 "billing_country-{$this->_bltID}",
728 "billing_country_id-{$this->_bltID}",
731 foreach ($billingFields as $value) {
732 unset($params[$value]);
733 unset($fields[$value]);
737 // if onbehalf-of-organization contribution, take out
738 // organization params in a separate variable, to make sure
739 // normal behavior is continued. And use that variable to
740 // process on-behalf-of functionality.
741 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
742 $behalfOrganization = array();
743 $orgFields = array('organization_name', 'organization_id', 'org_option');
744 foreach ($orgFields as $fld) {
745 if (array_key_exists($fld, $params)) {
746 $behalfOrganization[$fld] = $params[$fld];
747 unset($params[$fld]);
751 if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) {
752 foreach ($params['onbehalf'] as $fld => $values) {
753 if (strstr($fld, 'custom_')) {
754 $behalfOrganization[$fld] = $values;
756 elseif (!(strstr($fld, '-'))) {
757 if (in_array($fld, array(
758 'contribution_campaign_id', 'member_campaign_id'))) {
759 $fld = 'campaign_id';
762 $behalfOrganization[$fld] = $values;
764 $this->_params
[$fld] = $values;
769 if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) {
770 foreach ($params['onbehalf_location'] as $block => $vals) {
771 //fix for custom data (of type checkbox, multi-select)
772 if ( substr($block, 0, 7) == 'custom_' ) {
775 // fix the index of block elements
776 if (is_array($vals) ) {
777 foreach ( $vals as $key => $val ) {
778 //dont adjust the index of address block as
779 //it's index is WRT to location type
780 $newKey = ($block == 'address') ?
$key : ++
$key;
781 $behalfOrganization[$block][$newKey] = $val;
785 unset($params['onbehalf_location']);
787 if (!empty($params['onbehalf[image_URL]'])) {
788 $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]'];
792 // check for profile double opt-in and get groups to be subscribed
793 $subscribeGroupIds = CRM_Core_BAO_UFGroup
::getDoubleOptInGroupIds($params, $contactID);
795 // since we are directly adding contact to group lets unset it from mailing
796 if (!empty($addToGroups)) {
797 foreach ($addToGroups as $groupId) {
798 if (isset($subscribeGroupIds[$groupId])) {
799 unset($subscribeGroupIds[$groupId]);
804 foreach ($addToGroups as $k) {
805 if (array_key_exists($k, $subscribeGroupIds)) {
806 unset($addToGroups[$k]);
810 if (empty($contactID)) {
811 $dupeParams = $params;
812 if (!empty($dupeParams['onbehalf'])) {
813 unset($dupeParams['onbehalf']);
816 $dedupeParams = CRM_Dedupe_Finder
::formatParams($dupeParams, 'Individual');
817 $dedupeParams['check_permission'] = FALSE;
818 $ids = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
820 // if we find more than one contact, use the first one
821 $contactID = CRM_Utils_Array
::value(0, $ids);
823 // Fetch default greeting id's if creating a contact
825 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
826 if (!isset($params[$greeting])) {
827 $params[$greeting] = CRM_Contact_BAO_Contact_Utils
::defaultGreeting('Individual', $greeting);
834 $contactType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
836 $contactID = CRM_Contact_BAO_Contact
::createProfileContact(
846 // Make the contact ID associated with the contribution available at the Class level.
847 // Also make available to the session.
848 //@todo consider handling this in $this->getContactID();
849 $this->set('contactID', $contactID);
850 $this->_contactID
= $contactID;
852 //get email primary first if exist
853 $subscriptionEmail = array('email' => CRM_Utils_Array
::value('email-Primary', $params));
854 if (!$subscriptionEmail['email']) {
855 $subscriptionEmail['email'] = CRM_Utils_Array
::value("email-{$this->_bltID}", $params);
857 // subscribing contact to groups
858 if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) {
859 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID);
862 // If onbehalf-of-organization contribution / signup, add organization
863 // and it's location.
864 if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) {
866 foreach ($this->_fields
['onbehalf'] as $name => $value) {
867 $ufFields[$name] = 1;
869 self
::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values
,
870 $this->_params
, $ufFields
872 } else if (!empty($this->_membershipContactID
) && $contactID != $this->_membershipContactID
) {
873 // this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household,
874 // store current user id as related contact for later use for mailing / activity..
875 $this->_values
['related_contact'] = $contactID;
876 $this->_params
['related_contact'] = $contactID;
877 // swap contact like we do for on-behalf-org case, so parent/primary membership is affected
878 $contactID = $this->_membershipContactID
;
881 // lets store the contactID in the session
882 // for things like tell a friend
883 $session = CRM_Core_Session
::singleton();
884 if (!$session->get('userID')) {
885 $session->set('transaction.userID', $contactID);
888 $session->set('transaction.userID', NULL);
891 $this->_useForMember
= $this->get('useForMember');
893 // store the fact that this is a membership and membership type is selected
894 $processMembership = FALSE;
895 if ((!empty($membershipParams['selectMembership']) &&
896 $membershipParams['selectMembership'] != 'no_thanks'
900 $processMembership = TRUE;
902 if (!$this->_useForMember
) {
903 $this->assign('membership_assign', TRUE);
904 $this->set('membershipTypeID', $this->_params
['selectMembership']);
907 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
908 $membershipParams['is_test'] = 1;
910 if ($this->_params
['is_pay_later']) {
911 $membershipParams['is_pay_later'] = 1;
915 if ($processMembership) {
916 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $membershipParams, TRUE);
918 // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups
919 if (isset($this->_params
['related_contact'])) {
920 $membershipParams['cms_contactID'] = $this->_params
['related_contact'];
923 $membershipParams['cms_contactID'] = $contactID;
926 //inherit campaign from contribution page.
927 if (!array_key_exists('campaign_id', $membershipParams)) {
928 $membershipParams['campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
);
931 if (!empty($membershipParams['onbehalf']) &&
932 is_array($membershipParams['onbehalf']) && !empty($membershipParams['onbehalf']['member_campaign_id'])) {
933 $this->_params
['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
936 $customFieldsFormatted = $fieldTypes = array();
937 if (!empty($membershipParams['onbehalf']) &&
938 is_array($membershipParams['onbehalf'])) {
939 foreach ($membershipParams['onbehalf'] as $key => $value) {
940 if (strstr($key, 'custom_')) {
941 $customFieldId = explode('_', $key);
942 CRM_Core_BAO_CustomField
::formatCustomField(
944 $customFieldsFormatted,
952 $fieldTypes = array('Contact', 'Organization', 'Membership');
955 $priceFieldIds = $this->get('memberPriceFieldIDS');
957 if (!empty($priceFieldIds)) {
958 $contributionTypeID = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $priceFieldIds['id'], 'financial_type_id');
959 unset($priceFieldIds['id']);
960 $membershipTypeIds = array();
961 $membershipTypeTerms = array();
962 foreach ($priceFieldIds as $priceFieldId) {
963 if ($id = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
964 $membershipTypeIds[] = $id;
965 //@todo the value for $term is immediately overwritten. It is unclear from the code whether it was intentional to
966 // do this or a double = was intended (this ambiguity is the reason many IDEs complain about 'assignment in condition'
968 if ($term = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) {
969 $membershipTypeTerms[$id] = ($term > 1) ?
$term : 1;
972 $membershipTypeTerms[$id] = 1;
976 $membershipParams['selectMembership'] = $membershipTypeIds;
977 $membershipParams['financial_type_id'] = $contributionTypeID;
978 $membershipParams['types_terms'] = $membershipTypeTerms;
980 if (!empty($membershipParams['selectMembership'])) {
982 $membershipLineItems = array();
983 if ($this->_separateMembershipPayment
&& $this->_values
['amount_block_is_active']) {
984 foreach ($this->_values
['fee'] as $key => $feeValues) {
985 if ($feeValues['name'] == 'membership_amount') {
986 $fieldId = $this->_params
['price_' . $key];
987 $membershipLineItems[$this->_priceSetId
][$fieldId] = $this->_lineItem
[$this->_priceSetId
][$fieldId];
988 unset($this->_lineItem
[$this->_priceSetId
][$fieldId]);
993 $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater);
994 if (!$this->_amount
> 0.0 ||
!$membershipParams['amount']) {
995 // we need to explicitly create a CMS user in case of free memberships
996 // since it is done under processConfirm for paid memberships
997 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($membershipParams,
998 $membershipParams['cms_contactID'],
999 'email-' . $this->_bltID
1005 // at this point we've created a contact and stored its address etc
1006 // all the payment processors expect the name and address to be in the
1007 // so we copy stuff over to first_name etc.
1008 $paymentParams = $this->_params
;
1009 $contributionTypeId = $this->_values
['financial_type_id'];
1011 $fieldTypes = array();
1012 if (!empty($paymentParams['onbehalf']) &&
1013 is_array($paymentParams['onbehalf'])
1015 foreach ($paymentParams['onbehalf'] as $key => $value) {
1016 if (strstr($key, 'custom_')) {
1017 $this->_params
[$key] = $value;
1020 $fieldTypes = array('Contact', 'Organization', 'Contribution');
1022 $financialTypeID = $this->wrangleFinancialTypeID($contributionTypeId);
1024 CRM_Contribute_BAO_Contribution_Utils
::processConfirm($this, $paymentParams,
1025 $premiumParams, $contactID,
1029 ($this->_mode
== 'test') ?
1 : 0,
1036 * This wrangling of the financialType ID was happening in a shared function rather than in the form it relates to & hence has been moved to that form
1037 * Pledges are not relevant to the membership code so that portion will not go onto the membership form.
1039 * Comments from previous refactor indicate doubt as to what was going on
1040 * @param int $contributionTypeId
1042 * @return null|string
1044 public function wrangleFinancialTypeID($contributionTypeId) {
1045 if (isset($paymentParams['financial_type'])) {
1046 $contributionTypeId = $paymentParams['financial_type'];
1048 elseif (!empty($this->_values
['pledge_id'])) {
1049 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_Pledge',
1050 $this->_values
['pledge_id'],
1054 return $contributionTypeId;
1060 * @param array $premiumParams
1061 * @param $contribution
1065 public function postProcessPremium($premiumParams, $contribution) {
1066 $hour = $minute = $second = 0;
1067 // assigning Premium information to receipt tpl
1068 $selectProduct = CRM_Utils_Array
::value('selectProduct', $premiumParams);
1069 if ($selectProduct &&
1070 $selectProduct != 'no_thanks'
1072 $startDate = $endDate = "";
1073 $this->assign('selectPremium', TRUE);
1074 $productDAO = new CRM_Contribute_DAO_Product();
1075 $productDAO->id
= $selectProduct;
1076 $productDAO->find(TRUE);
1077 $this->assign('product_name', $productDAO->name
);
1078 $this->assign('price', $productDAO->price
);
1079 $this->assign('sku', $productDAO->sku
);
1080 $this->assign('option', CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams));
1082 $periodType = $productDAO->period_type
;
1085 $fixed_period_start_day = $productDAO->fixed_period_start_day
;
1086 $duration_unit = $productDAO->duration_unit
;
1087 $duration_interval = $productDAO->duration_interval
;
1088 if ($periodType == 'rolling') {
1089 $startDate = date('Y-m-d');
1091 elseif ($periodType == 'fixed') {
1092 if ($fixed_period_start_day) {
1093 $date = explode('-', date('Y-m-d'));
1094 $month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2);
1095 $day = substr($fixed_period_start_day, -2) . "<br>";
1097 $startDate = $year . '-' . $month . '-' . $day;
1100 $startDate = date('Y-m-d');
1104 $date = explode('-', $startDate);
1109 switch ($duration_unit) {
1111 $year = $year +
$duration_interval;
1115 $month = $month +
$duration_interval;
1119 $day = $day +
$duration_interval;
1123 $day = $day +
($duration_interval * 7);
1125 $endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year));
1126 $this->assign('start_date', $startDate);
1127 $this->assign('end_date', $endDate);
1130 $dao = new CRM_Contribute_DAO_Premium();
1131 $dao->entity_table
= 'civicrm_contribution_page';
1132 $dao->entity_id
= $this->_id
;
1134 $this->assign('contact_phone', $dao->premiums_contact_phone
);
1135 $this->assign('contact_email', $dao->premiums_contact_email
);
1137 //create Premium record
1139 'product_id' => $premiumParams['selectProduct'],
1140 'contribution_id' => $contribution->id
,
1141 'product_option' => CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams),
1143 'start_date' => CRM_Utils_Date
::customFormat($startDate, '%Y%m%d'),
1144 'end_date' => CRM_Utils_Date
::customFormat($endDate, '%Y%m%d'),
1146 if (!empty($premiumParams['selectProduct'])){
1147 $daoPremiumsProduct = new CRM_Contribute_DAO_PremiumsProduct();
1148 $daoPremiumsProduct->product_id
= $premiumParams['selectProduct'];
1149 $daoPremiumsProduct->premiums_id
= $dao->id
;
1150 $daoPremiumsProduct->find(true);
1151 $params['financial_type_id'] = $daoPremiumsProduct->financial_type_id
;
1153 //Fixed For CRM-3901
1154 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1155 $daoContrProd->contribution_id
= $contribution->id
;
1156 if ($daoContrProd->find(TRUE)) {
1157 $params['id'] = $daoContrProd->id
;
1160 CRM_Contribute_BAO_Contribution
::addPremium($params);
1161 if ($productDAO->cost
&& !empty($params['financial_type_id'])) {
1162 $trxnParams = array(
1163 'cost' => $productDAO->cost
,
1164 'currency' => $productDAO->currency
,
1165 'financial_type_id' => $params['financial_type_id'],
1166 'contributionId' => $contribution->id
1168 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($trxnParams);
1171 elseif ($selectProduct == 'no_thanks') {
1172 //Fixed For CRM-3901
1173 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1174 $daoContrProd->contribution_id
= $contribution->id
;
1175 if ($daoContrProd->find(TRUE)) {
1176 $daoContrProd->delete();
1182 * Process the contribution
1184 * @param CRM_Core_Form $form
1185 * @param array $params
1186 * @param array $result
1187 * @param integer $contactID
1188 * @param CRM_Financial_DAO_FinancialType $financialType
1189 * @param bool $pending
1190 * @param bool $online
1192 * @param bool $isTest
1193 * @param array $lineItems
1196 * @return CRM_Contribute_DAO_Contribution
1198 static function processContribution(
1209 $transaction = new CRM_Core_Transaction();
1210 $contribSoftContactId = $addressID = NULL;
1212 // add these values for the recurringContrib function ,CRM-10188
1213 $params['financial_type_id'] = $financialType->id
;
1215 //create an contribution address
1216 if ($form->_contributeMode
!= 'notify' && empty($params['is_pay_later']) && !empty($form->_values
['is_monetary'])) {
1217 $addressID = CRM_Contribute_BAO_Contribution
::createAddress($params, $form->_bltID
);
1220 //@todo - this is being set from the form to resolve CRM-10188 - an
1221 // eNotice caused by it not being set @ the front end
1222 // however, we then get it being over-written with null for backend contributions
1223 // a better fix would be to set the values in the respective forms rather than require
1224 // a function being shared by two forms to deal with their respective values
1225 // moving it to the BAO & not taking the $form as a param would make sense here.
1226 if(!isset($params['is_email_receipt']) && !empty($form->_values
['is_email_receipt'])){
1227 $params['is_email_receipt'] = CRM_Utils_Array
::value( 'is_email_receipt', $form->_values
);
1229 $recurringContributionID = self
::processRecurringContribution($form, $params, $contactID, $financialType, $online);
1232 // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it.
1233 if (isset($params['non_deductible_amount']) && (!empty($params['non_deductible_amount']))) {
1234 $nonDeductibleAmount = $params['non_deductible_amount'];
1236 // if non_deductible_amount does NOT exist - then calculate it depending on:
1237 // $contributionType->is_deductible and whether there is a product (premium).
1239 //if ($contributionType->is_deductible && $deductibleMode) {
1240 if ($financialType->is_deductible
) {
1241 if ($online && isset($params['selectProduct'])) {
1242 $selectProduct = CRM_Utils_Array
::value('selectProduct', $params);
1244 if (!$online && isset($params['product_name'][0])) {
1245 $selectProduct = $params['product_name'][0];
1247 // if there is a product - compare the value to the contribution amount
1248 if (isset($selectProduct) &&
1249 $selectProduct != 'no_thanks'
1251 $productDAO = new CRM_Contribute_DAO_Product();
1252 $productDAO->id
= $selectProduct;
1253 $productDAO->find(TRUE);
1254 // product value exceeds contribution amount
1255 if ($params['amount'] < $productDAO->price
) {
1256 $nonDeductibleAmount = $params['amount'];
1258 // product value does NOT exceed contribution amount
1260 $nonDeductibleAmount = $productDAO->price
;
1263 // contribution is deductible - but there is no product
1265 $nonDeductibleAmount = '0.00';
1268 // contribution is NOT deductible
1270 $nonDeductibleAmount = $params['amount'];
1274 $now = date('YmdHis');
1275 $receiptDate = CRM_Utils_Array
::value('receipt_date', $params);
1276 if (!empty($form->_values
['is_email_receipt'])) {
1277 $receiptDate = $now;
1280 //get the contrib page id.
1281 $contributionPageId = NULL;
1283 $contributionPageId = $form->_id
;
1284 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1285 if (!array_key_exists('campaign_id', $params)) {
1286 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1290 //also for offline we do support - CRM-7290
1291 $contributionPageId = CRM_Utils_Array
::value('contribution_page_id', $params);
1292 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1295 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1296 if (!empty($params['pcp_made_through_id']) ||
!empty($params['soft_credit_to'])) {
1297 // if its due to pcp
1298 if (!empty($params['pcp_made_through_id'])) {
1299 $contribSoftContactId = CRM_Core_DAO
::getFieldValue(
1301 $params['pcp_made_through_id'],
1306 $contribSoftContactId = CRM_Utils_Array
::value('soft_credit_to', $params);
1309 // Pass these details onto with the contribution to make them
1310 // available at hook_post_process, CRM-8908
1311 $params['soft_credit_to'] = $contribSoftContactId;
1314 if (isset($params['amount'])) {
1316 if (!empty($form->_values
['is_monetary'])) {
1317 $isMonetary = $form->_values
['is_monetary'];
1319 $contribParams = self
::getContributionParams(
1320 $params, $contactID, $financialType->id
, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending, $result, $receiptDate,
1321 $recurringContributionID, $isTest, $addressID, $contribSoftContactId, $lineItems
1323 $contribution = CRM_Contribute_BAO_Contribution
::add($contribParams);
1325 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,'contribution_invoice_settings');
1326 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
1328 $totalTaxAmount = 0;
1329 $dataArray = array();
1330 foreach ($form->_lineItem
as $lineItemKey => $lineItemValue) {
1331 foreach ($lineItemValue as $key => $value) {
1332 if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
1333 if (isset($dataArray[$value['tax_rate']])) {
1334 $dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $value);
1337 $dataArray[$value['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $value);
1342 $smarty = CRM_Core_Smarty
::singleton();
1343 $smarty->assign('dataArray', $dataArray);
1344 $smarty->assign('totalTaxAmount', $params['tax_amount']);
1346 if (is_a($contribution, 'CRM_Core_Error')) {
1347 $message = CRM_Core_Error
::getMessages($contribution);
1348 CRM_Core_Error
::fatal($message);
1351 // lets store it in the form variable so postProcess hook can get to this and use it
1352 $form->_contributionID
= $contribution->id
;
1355 //CRM-13981, processing honor contact into soft-credit contribution
1356 CRM_Contact_Form_ProfileContact
::postProcess($form);
1358 // process soft credit / pcp pages
1359 CRM_Contribute_Form_Contribution_Confirm
::processPcpSoft($params, $contribution);
1361 //handle pledge stuff.
1362 if (empty($form->_params
['separate_membership_payment']) && !empty($form->_values
['pledge_block_id']) &&
1363 (!empty($form->_params
['is_pledge']) ||
!empty($form->_values
['pledge_id']))
1366 if (!empty($form->_values
['pledge_id'])) {
1368 //when user doing pledge payments.
1369 //update the schedule when payment(s) are made
1370 foreach ($form->_params
['pledge_amount'] as $paymentId => $dontCare) {
1371 $scheduledAmount = CRM_Core_DAO
::getFieldValue(
1372 'CRM_Pledge_DAO_PledgePayment',
1378 $pledgePaymentParams = array(
1380 'contribution_id' => $contribution->id
,
1381 'status_id' => $contribution->contribution_status_id
,
1382 'actual_amount' => $scheduledAmount,
1386 CRM_Pledge_BAO_PledgePayment
::add($pledgePaymentParams);
1389 //update pledge status according to the new payment statuses
1390 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($form->_values
['pledge_id']);
1393 //when user creating pledge record.
1394 $pledgeParams = array();
1395 $pledgeParams['contact_id'] = $contribution->contact_id
;
1396 $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount
;
1397 $pledgeParams['contribution_id'] = $contribution->id
;
1398 $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id
;
1399 $pledgeParams['financial_type_id'] = $contribution->financial_type_id
;
1400 $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
1401 $pledgeParams['installments'] = $params['pledge_installments'];
1402 $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
1403 if ($pledgeParams['frequency_unit'] == 'month') {
1404 $pledgeParams['frequency_day'] = intval(date("d"));
1407 $pledgeParams['frequency_day'] = 1;
1409 $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
1410 $pledgeParams['status_id'] = $contribution->contribution_status_id
;
1411 $pledgeParams['max_reminders'] = $form->_values
['max_reminders'];
1412 $pledgeParams['initial_reminder_day'] = $form->_values
['initial_reminder_day'];
1413 $pledgeParams['additional_reminder_day'] = $form->_values
['additional_reminder_day'];
1414 $pledgeParams['is_test'] = $contribution->is_test
;
1415 $pledgeParams['acknowledge_date'] = date('Ymd');
1416 $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
1418 //inherit campaign from contirb page.
1419 $pledgeParams['campaign_id'] = $campaignId;
1421 $pledge = CRM_Pledge_BAO_Pledge
::create($pledgeParams);
1423 $form->_params
['pledge_id'] = $pledge->id
;
1425 //send acknowledgment email. only when pledge is created
1427 //build params to send acknowledgment.
1428 $pledgeParams['id'] = $pledge->id
;
1429 $pledgeParams['receipt_from_name'] = $form->_values
['receipt_from_name'];
1430 $pledgeParams['receipt_from_email'] = $form->_values
['receipt_from_email'];
1432 //scheduled amount will be same as installment_amount.
1433 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
1435 //get total pledge amount.
1436 $pledgeParams['total_pledge_amount'] = $pledge->amount
;
1438 CRM_Pledge_BAO_Pledge
::sendAcknowledgment($form, $pledgeParams);
1443 if ($online && $contribution) {
1444 CRM_Core_BAO_CustomValueTable
::postProcess($form->_params
,
1445 CRM_Core_DAO
::$_nullArray,
1446 'civicrm_contribution',
1451 elseif ($contribution) {
1452 //handle custom data.
1453 $params['contribution_id'] = $contribution->id
;
1454 if (!empty($params['custom']) &&
1455 is_array($params['custom']) &&
1456 !is_a($contribution, 'CRM_Core_Error')
1458 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_contribution', $contribution->id
);
1462 if ($contribution && !empty($params['contribution_note'])) {
1463 $noteParams = array(
1464 'entity_table' => 'civicrm_contribution',
1465 'note' => $params['contribution_note'],
1466 'entity_id' => $contribution->id
,
1467 'contact_id' => $contribution->contact_id
,
1468 'modified_date' => date('Ymd'),
1471 CRM_Core_BAO_Note
::add($noteParams, array());
1475 if (isset($params['related_contact'])) {
1476 $contactID = $params['related_contact'];
1478 elseif (isset($params['cms_contactID'])) {
1479 $contactID = $params['cms_contactID'];
1482 //create contribution activity w/ individual and target
1483 //activity w/ organisation contact id when onbelf, CRM-4027
1484 $targetContactID = NULL;
1485 if (!empty($params['hidden_onbehalf_profile'])) {
1486 $targetContactID = $contribution->contact_id
;
1487 $contribution->contact_id
= $contactID;
1490 // create an activity record
1491 if ($contribution) {
1492 CRM_Activity_BAO_Activity
::addActivity($contribution, NULL, $targetContactID);
1495 $transaction->commit();
1496 // CRM-13074 - create the CMSUser after the transaction is completed as it
1497 // is not appropriate to delete a valid contribution if a user create problem occurs
1498 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($params,
1500 'email-' . $form->_bltID
1502 return $contribution;
1506 * Create the recurring contribution record
1508 * @param CRM_Core_Form $form
1509 * @param array $params
1510 * @param integer $contactID
1511 * @param string $contributionType
1512 * @param bool $online
1516 public static function processRecurringContribution(&$form, &$params, $contactID, $contributionType, $online = TRUE) {
1517 // return if this page is not set for recurring
1518 // or the user has not chosen the recurring option
1520 //this is online case validation.
1521 if ((empty($form->_values
['is_recur']) && $online) ||
empty($params['is_recur'])) {
1525 $recurParams = array('contact_id' => $contactID);
1526 $recurParams['amount'] = CRM_Utils_Array
::value('amount', $params);
1527 $recurParams['auto_renew'] = CRM_Utils_Array
::value('auto_renew', $params);
1528 $recurParams['frequency_unit'] = CRM_Utils_Array
::value('frequency_unit', $params);
1529 $recurParams['frequency_interval'] = CRM_Utils_Array
::value('frequency_interval', $params);
1530 $recurParams['installments'] = CRM_Utils_Array
::value('installments', $params);
1531 $recurParams['financial_type_id'] = CRM_Utils_Array
::value('financial_type_id', $params);
1533 // CRM-14354: For an auto-renewing membership with an additional contribution,
1534 // if separate payments is not enabled, make sure only the membership fee recurs
1535 if (!empty($form->_membershipBlock
)
1536 && $form->_membershipBlock
['is_separate_payment'] === '0'
1537 && isset($params['selectMembership'])
1538 && $form->_values
['is_allow_other_amount'] == '1'
1540 $recurParams['amount'] = $form->_membershipTypeValues
[$params['selectMembership']]['minimum_fee'];
1543 $recurParams['is_test'] = 0;
1544 if (($form->_action
& CRM_Core_Action
::PREVIEW
) ||
1545 (isset($form->_mode
) && ($form->_mode
== 'test'))
1547 $recurParams['is_test'] = 1;
1550 $recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
1551 if (!empty($params['receive_date'])) {
1552 $recurParams['start_date'] = $params['receive_date'];
1554 $recurParams['invoice_id'] = CRM_Utils_Array
::value('invoiceID', $params);
1555 $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
1556 $recurParams['payment_processor_id'] = CRM_Utils_Array
::value('payment_processor_id', $params);
1557 $recurParams['is_email_receipt'] = CRM_Utils_Array
::value('is_email_receipt', $params);
1558 // we need to add a unique trxn_id to avoid a unique key error
1559 // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
1560 $recurParams['trxn_id'] = CRM_Utils_Array
::value('trxn_id', $params, $params['invoiceID']);
1561 $recurParams['financial_type_id'] = $contributionType->id
;
1563 if (!$online ||
$form->_values
['is_monetary']) {
1564 $recurParams['payment_instrument_id'] = 1;
1567 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1569 if (!array_key_exists('campaign_id', $params)) {
1570 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1573 $recurParams['campaign_id'] = $campaignId;
1575 $recurring = CRM_Contribute_BAO_ContributionRecur
::add($recurParams);
1576 if (is_a($recurring, 'CRM_Core_Error')) {
1577 CRM_Core_Error
::displaySessionError($recurring);
1578 $urlString = 'civicrm/contribute/transact';
1579 $urlParams = '_qf_Main_display=true';
1580 if (get_class($form) == 'CRM_Contribute_Form_Contribution') {
1581 $urlString = 'civicrm/contact/view/contribution';
1582 $urlParams = "action=add&cid={$form->_contactID}";
1584 $urlParams .= "&mode={$form->_mode}";
1587 CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
1590 return $recurring->id
;
1594 * Add on behalf of organization and it's location
1596 * @param $behalfOrganization array array of organization info
1597 * @param $contactID int individual contact id. One
1598 * who is doing the process of signup / contribution.
1600 * @param $values array form values array
1601 * @param array $params
1602 * @param null $fields
1606 public static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL) {
1607 $isCurrentEmployer = FALSE;
1610 if (!empty($behalfOrganization['organization_id']) && empty($behalfOrganization['org_option'])) {
1611 $orgID = $behalfOrganization['organization_id'];
1612 unset($behalfOrganization['organization_id']);
1613 $isCurrentEmployer = TRUE;
1616 // formalities for creating / editing organization.
1617 $behalfOrganization['contact_type'] = 'Organization';
1619 // get the relationship type id
1620 $relType = new CRM_Contact_DAO_RelationshipType();
1621 $relType->name_a_b
= 'Employee of';
1622 $relType->find(TRUE);
1623 $relTypeId = $relType->id
;
1625 // keep relationship params ready
1626 $relParams['relationship_type_id'] = $relTypeId . '_a_b';
1627 $relParams['is_permission_a_b'] = 1;
1628 $relParams['is_active'] = 1;
1631 // check if matching organization contact exists
1632 $dedupeParams = CRM_Dedupe_Finder
::formatParams($behalfOrganization, 'Organization');
1633 $dedupeParams['check_permission'] = FALSE;
1634 $dupeIDs = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Organization', 'Unsupervised');
1636 // CRM-6243 says to pick the first org even if more than one match
1637 if (count($dupeIDs) >= 1) {
1638 $behalfOrganization['contact_id'] = $orgID = $dupeIDs[0];
1639 // don't allow name edit
1640 unset($behalfOrganization['organization_name']);
1644 // if found permissioned related organization, allow location edit
1645 $behalfOrganization['contact_id'] = $orgID;
1646 // don't allow name edit
1647 unset($behalfOrganization['organization_name']);
1650 // handling for image url
1651 if (!empty($behalfOrganization['image_URL'])) {
1652 CRM_Contact_BAO_Contact
::processImageParams($behalfOrganization);
1655 // create organization, add location
1656 $orgID = CRM_Contact_BAO_Contact
::createProfileContact($behalfOrganization, $fields, $orgID,
1657 NULL, NULL, 'Organization'
1659 // create relationship
1660 $relParams['contact_check'][$orgID] = 1;
1661 $cid = array('contact' => $contactID);
1662 CRM_Contact_BAO_Relationship
::create($relParams, $cid);
1664 // if multiple match - send a duplicate alert
1665 if ($dupeIDs && (count($dupeIDs) > 1)) {
1666 $values['onbehalf_dupe_alert'] = 1;
1668 $params['onbehalf_dupe_alert'] = 1;
1671 // make sure organization-contact-id is considered for recording
1672 // contribution/membership etc..
1673 if ($contactID != $orgID) {
1674 // take a note of contact-id, so we can send the
1675 // receipt to individual contact as well.
1677 // required for mailing/template display ..etc
1678 $values['related_contact'] = $contactID;
1680 $params['related_contact'] = $contactID;
1682 //make this employee of relationship as current
1683 //employer / employee relationship, CRM-3532
1684 if ($isCurrentEmployer &&
1685 ($orgID != CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'))
1687 $isCurrentEmployer = FALSE;
1690 if (!$isCurrentEmployer && $orgID) {
1691 //build current employer params
1692 $currentEmpParams[$contactID] = $orgID;
1693 CRM_Contact_BAO_Contact_Utils
::setCurrentEmployer($currentEmpParams);
1696 // contribution / signup will be done using this
1698 $contactID = $orgID;
1703 * Function used to save pcp / soft credit entry
1704 * This is used by contribution and also event pcps
1706 * @param array $params associated array
1707 * @param object $contribution contribution object
1711 public static function processPcpSoft(&$params, &$contribution) {
1712 //add soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1713 if (!empty($params['soft_credit_to'])) {
1714 $contributionSoftParams = array();
1716 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note', 'amount') as $val) {
1717 if (!empty($params[$val])) {
1718 $contributionSoftParams[$val] = $params[$val];
1722 $contributionSoftParams['contact_id'] = $params['soft_credit_to'];
1723 // add contribution id
1724 $contributionSoftParams['contribution_id'] = $contribution->id
;
1726 $contributionSoftParams['pcp_id'] = $params['pcp_made_through_id'];
1728 $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup
::getValue('soft_credit_type', 'pcp', 'name');
1730 CRM_Contribute_BAO_ContributionSoft
::add($contributionSoftParams);
1735 * Function used to se pcp related defaults / params
1736 * This is used by contribution and also event pcps
1738 * @param CRM_Core_Form $page form object
1739 * @param array $params associated array
1744 public static function processPcp(&$page, $params) {
1745 $params['pcp_made_through_id'] = $page->_pcpId
;
1746 $page->assign('pcpBlock', TRUE);
1747 if (!empty($params['pcp_display_in_roll']) && empty($params['pcp_roll_nickname'])) {
1748 $params['pcp_roll_nickname'] = ts('Anonymous');
1749 $params['pcp_is_anonymous'] = 1;
1752 $params['pcp_is_anonymous'] = 0;
1755 'pcp_display_in_roll',
1757 'pcp_roll_nickname',
1760 if (!empty($params[$val])) {
1761 $page->assign($val, $params[$val]);
1769 * @param array $membershipParams
1770 * @param integer $contactID
1771 * @param array $customFieldsFormatted
1772 * @param array $fieldTypes
1773 * @param array $premiumParams
1774 * @param array $membershipLineItems line items specifically relating to memberships
1775 * @param $isPayLater
1777 public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater) {
1779 $membershipTypeIDs = (array) $membershipParams['selectMembership'];
1780 $membershipTypes = CRM_Member_BAO_Membership
::buildMembershipTypeValues($this, $membershipTypeIDs);
1781 $membershipType = empty($membershipTypes) ?
array() : reset($membershipTypes);
1782 $this->assign('membership_name', CRM_Utils_Array
::value('name', $membershipType));
1784 $isPaidMembership = FALSE;
1785 if($this->_amount
>= 0.0 && isset($membershipParams['amount'])) {
1786 //amount must be greater than zero for
1787 //adding contribution record to contribution table.
1788 //this condition arises when separate membership payment is
1789 //enabled and contribution amount is not selected. fix for CRM-3010
1790 $isPaidMembership = TRUE;
1792 $isProcessSeparateMembershipTransaction = $this->isSeparateMembershipTransaction($this->_id
, $this->_values
['amount_block_is_active']);
1794 if ($this->_values
['amount_block_is_active']) {
1795 $contributionTypeId = $this->_values
['financial_type_id'];
1798 $contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $membershipType, CRM_Utils_Array
::value('financial_type_id' ,$membershipParams));
1801 CRM_Member_BAO_Membership
::postProcessMembership($membershipParams, $contactID,
1802 $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeIDs, $isPaidMembership, $this->_membershipId
, $isProcessSeparateMembershipTransaction, $contributionTypeId,
1803 $membershipLineItems, $isPayLater
1805 $this->assign('membership_assign', TRUE);
1806 $this->set('membershipTypeID', $membershipParams['selectMembership']);
1808 catch (CRM_Core_Exception
$e) {
1809 CRM_Core_Session
::singleton()->setStatus($e->getMessage());
1810 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_Main_display=true&qfKey={$this->_params['qfKey']}"));
1815 * Are we going to do 2 financial transactions?
1816 * ie the membership block supports a separate transactions AND the contribution form has been configured for a contribution
1817 * transaction AND a membership transaction AND the payment processor supports double financial transactions (ie. NOT doTransferPayment style)
1820 * @param integer $formID
1821 * @param bool $amountBlockActiveOnForm
1825 public function isSeparateMembershipTransaction($formID, $amountBlockActiveOnForm) {
1826 $memBlockDetails = CRM_Member_BAO_Membership
::getMembershipBlock($formID);
1827 if (!empty($memBlockDetails['is_separate_payment']) && $amountBlockActiveOnForm) {
1834 * This function sets the fields
1835 * - $this->_params['amount_level']
1836 * - $this->_params['selectMembership']
1837 * And under certain circumstances sets
1838 * $this->_params['amount'] = null;
1840 * @param int $priceSetID
1843 public function setFormAmountFields($priceSetID) {
1844 $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params
['priceSetId'], 'is_quick_config');
1845 $priceField = new CRM_Price_DAO_PriceField();
1846 $priceField->price_set_id
= $priceSetID;
1847 $priceField->orderBy('weight');
1848 $priceField->find();
1849 $paramWeDoNotUnderstand = NULL;
1851 while ($priceField->fetch()) {
1852 if ($priceField->name
== "contribution_amount") {
1853 $paramWeDoNotUnderstand = $priceField->id
;
1855 if ($isQuickConfig && !empty($this->_params
["price_{$priceField->id}"])) {
1856 if ($this->_values
['fee'][$priceField->id
]['html_type'] != 'Text') {
1857 $this->_params
['amount_level'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1858 $this->_params
["price_{$priceField->id}"], 'label');
1860 if ($priceField->name
== "membership_amount") {
1861 $this->_params
['selectMembership'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1862 $this->_params
["price_{$priceField->id}"], 'membership_type_id');
1864 } // if separate payment we set contribution amount to be null, so that it will not show contribution amount same as membership amount.
1865 // @todo - this needs more documentation - it appears the setting to null is tied up with separate membership payments
1866 // but the circumstances are very confusing. Many of these conditions are repeated in the next conditional
1867 // so we should merge them together
1868 // the quick config seems like a red-herring - if this is about a separate membership payment then there
1869 // are 2 types of line items - membership ones & non-membership ones - regardless of whether quick config is set
1871 CRM_Utils_Array
::value('is_separate_payment', $this->_membershipBlock
)
1872 && !empty($this->_values
['fee'][$priceField->id
])
1873 && ($this->_values
['fee'][$priceField->id
]['name'] == "other_amount")
1874 && CRM_Utils_Array
::value("price_{$paramWeDoNotUnderstand}", $this->_params
) < 1
1875 && empty($this->_params
["price_{$priceField->id}"])
1877 $this->_params
['amount'] = null;
1880 // Fix for CRM-14375 - If we are using separate payments and "no
1881 // thank you" is selected for the additional contribution, set
1882 // contribution amount to be null, so that it will not show
1883 // contribution amount same as membership amount.
1884 //@todo - merge with section above
1885 if ($this->_membershipBlock
['is_separate_payment']
1886 && !empty($this->_values
['fee'][$priceField->id
])
1887 && CRM_Utils_Array
::value('name', $this->_values
['fee'][$priceField->id
]) == 'contribution_amount'
1888 && CRM_Utils_Array
::value("price_{$priceField->id}", $this->_params
) == '-1'
1890 $this->_params
['amount'] = null;
1896 * @param array $params
1898 * @throws CiviCRM_API3_Exception
1900 public static function submit($params) {
1901 $form = new CRM_Contribute_Form_Contribution_Confirm();
1902 $form->_id
= $params['id'];
1903 if (!empty($params['contact_id'])) {
1904 $form->_contactID
= $params['contact_id'];
1906 CRM_Contribute_BAO_ContributionPage
::setValues($form->_id
, $form->_values
);
1907 $form->_separateMembershipPayment
= CRM_Contribute_BAO_ContributionPage
::getIsMembershipPayment($form->_id
);
1908 //this way the mocked up controller ignores the session stuff
1909 $_SERVER['REQUEST_METHOD'] = 'GET';
1910 $form->controller
= new CRM_Contribute_Controller_Contribution();
1911 $params['invoiceID'] = md5(uniqid(rand(), TRUE));
1912 $paramsProcessedForForm = $form->_params
= self
::getFormParams($params['id'], $params);
1913 $form->_amount
= $params['amount'];
1914 $priceSetID = $form->_params
['priceSetId'] = $paramsProcessedForForm['price_set_id'];
1915 $priceFields = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetID);
1916 $priceSetFields = reset($priceFields);
1917 $form->_values
['fee'] = $priceSetFields['fields'];
1918 $form->_priceSetId
= $priceSetID;
1919 $form->setFormAmountFields($priceSetID);
1920 if (!empty($params['payment_processor'])) {
1921 $form->_paymentProcessor
= civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor']));
1922 if ($form->_paymentProcessor
['billing_mode'] ==1) {
1923 $form->_contributeMode
= 'direct';
1926 $form->_contributeMode
= 'notify';
1930 $form->_params
['payment_processor'] = 0;
1932 $priceFields = $priceFields[$priceSetID]['fields'];
1933 CRM_Price_BAO_PriceSet
::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution');
1934 $form->_lineItem
= array($priceSetID => $lineItems);
1935 $form->postProcess();
1939 * Helper function for static submit function - set relevant params - help us to build up an array that we can pass in
1941 * @param array $params
1944 * @throws CiviCRM_API3_Exception
1946 public static function getFormParams($id, array $params) {
1947 if(!isset($params['is_pay_later'])) {
1948 if (!empty($params['payment_processor'])) {
1949 $params['is_pay_later'] = 0;
1952 $params['is_pay_later'] = civicrm_api3('contribution_page', 'getvalue', array(
1954 'return' => 'is_pay_later'
1958 if(empty($params['price_set_id'])) {
1959 $params['price_set_id'] = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $params['id']);