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 int $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(
79 $params, $contactID, $financialTypeID, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending,
80 $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');
213 "billing_street_address-{$this->_bltID}",
214 "billing_city-{$this->_bltID}",
215 "billing_state_province_id-{$this->_bltID}",
216 "billing_postal_code-{$this->_bltID}",
217 "billing_country_id-{$this->_bltID}",
219 foreach ($values as $name => $value) {
221 if (!in_array($name, $skipFields)) {
222 $this->_params
[$name] = $value;
225 $this->set('getExpressCheckoutDetails', $this->_params
);
228 $this->_params
= $this->get('getExpressCheckoutDetails');
232 $this->_params
= $this->controller
->exportValues('Main');
234 if (!empty($this->_params
["billing_state_province_id-{$this->_bltID}"])) {
235 $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
237 if (!empty($this->_params
["billing_country_id-{$this->_bltID}"])) {
238 $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
241 if (isset($this->_params
['credit_card_exp_date'])) {
242 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
243 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
246 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
247 $this->_params
['amount'] = $this->get('amount');
248 $this->_params
['tax_amount'] = $this->get('tax_amount');
250 $this->_useForMember
= $this->get('useForMember');
252 if (isset($this->_params
['amount'])) {
253 $this->setFormAmountFields($this->_params
['priceSetId']);
255 $this->_params
['currencyID'] = $config->defaultCurrency
;
256 $this->_params
['payment_action'] = 'Sale';
259 $this->_params
['is_pay_later'] = $this->get('is_pay_later');
260 $this->assign('is_pay_later', $this->_params
['is_pay_later']);
261 if ($this->_params
['is_pay_later']) {
262 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
264 // if onbehalf-of-organization
265 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
267 if (empty($this->_params
['org_option']) && empty($this->_params
['organization_id'])) {
268 if (!empty($this->_params
['onbehalfof_id'])) {
269 $this->_params
['organization_id'] = $this->_params
['onbehalfof_id'];
272 $this->_params
['organization_id'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_params
['onbehalf']['organization_name'], 'id', 'display_name');
276 $this->_params
['organization_name'] = $this->_params
['onbehalf']['organization_name'];
277 $addressBlocks = array(
283 'supplemental_address_1',
284 'supplemental_address_2',
285 'supplemental_address_3',
286 'postal_code_suffix',
292 $blocks = array('email', 'phone', 'im', 'url', 'openid');
293 foreach ($this->_params
['onbehalf'] as $loc => $value) {
294 $field = $typeId = NULL;
295 if (strstr($loc, '-')) {
296 list($field, $locType) = explode('-', $loc);
299 if (in_array($field, $addressBlocks)) {
300 if ($locType == 'Primary') {
301 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
302 $locType = $defaultLocationType->id
;
305 if ($field == 'country') {
306 $value = CRM_Core_PseudoConstant
::countryIsoCode($value);
308 elseif ($field == 'state_province') {
309 $value = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value);
313 if (isset($this->_params
['onbehalf_location']['address'])
314 && count($this->_params
['onbehalf_location']['address']) > 0
319 $this->_params
['onbehalf_location']['address'][$locType][$field] = $value;
320 if (empty($this->_params
['onbehalf_location']['address'][$locType]['is_primary'])) {
321 $this->_params
['onbehalf_location']['address'][$locType]['is_primary'] = $isPrimary;
323 $this->_params
['onbehalf_location']['address'][$locType]['location_type_id'] = $locType;
325 elseif (in_array($field, $blocks)) {
326 if (!$typeId ||
is_numeric($typeId)) {
327 $blockName = $fieldName = $field;
328 $locationType = 'location_type_id';
329 if ($locType == 'Primary') {
330 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
331 $locationValue = $defaultLocationType->id
;
334 $locationValue = $locType;
337 $phoneExtField = array();
339 if ($field == 'url') {
340 $blockName = 'website';
341 $locationType = 'website_type_id';
342 list($field, $locationValue) = explode('-', $loc);
344 elseif ($field == 'im') {
346 $locTypeId = 'provider_id';
347 $typeId = $this->_params
['onbehalf']["{$loc}-provider_id"];
349 elseif ($field == 'phone') {
350 list($field, $locType, $typeId) = explode('-', $loc);
351 $locTypeId = 'phone_type_id';
353 //check if extension field exists
354 $extField = str_replace('phone', 'phone_ext', $loc);
355 if (isset($this->_params
['onbehalf'][$extField])) {
356 $phoneExtField = array('phone_ext' => $this->_params
['onbehalf'][$extField]);
361 if (isset ($this->_params
['onbehalf_location'][$blockName])
362 && count($this->_params
['onbehalf_location'][$blockName]) > 0
366 if ($locationValue) {
367 $blockValues = array(
368 $fieldName => $value,
369 $locationType => $locationValue,
370 'is_primary' => $isPrimary,
374 $blockValues = array_merge($blockValues, array($locTypeId => $typeId));
376 if (!empty($phoneExtField)) {
377 $blockValues = array_merge($blockValues, $phoneExtField);
380 $this->_params
['onbehalf_location'][$blockName][] = $blockValues;
384 elseif (strstr($loc, 'custom')) {
385 if ($value && isset($this->_params
['onbehalf']["{$loc}_id"])) {
386 $value = $this->_params
['onbehalf']["{$loc}_id"];
388 $this->_params
['onbehalf_location']["{$loc}"] = $value;
391 if ($loc == 'contact_sub_type') {
392 $this->_params
['onbehalf_location'][$loc] = $value;
395 $this->_params
['onbehalf_location'][$field] = $value;
400 elseif (!empty($this->_values
['is_for_organization'])) {
401 // no on behalf of an organization, CRM-5519
402 // so reset loc blocks from main params.
408 if (isset($this->_params
[$blk])) {
409 unset($this->_params
[$blk]);
414 // if auto renew checkbox is set, initiate a open-ended recurring membership
415 if ((!empty($this->_params
['selectMembership']) ||
!empty($this->_params
['priceSetId'])) && !empty($this->_paymentProcessor
['is_recur']) &&
416 CRM_Utils_Array
::value('auto_renew', $this->_params
) && empty($this->_params
['is_recur']) && empty($this->_params
['frequency_interval'])
419 $this->_params
['is_recur'] = $this->_values
['is_recur'] = 1;
420 // check if price set is not quick config
421 if (!empty($this->_params
['priceSetId']) && !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params
['priceSetId'], 'is_quick_config')) {
422 list($this->_params
['frequency_interval'], $this->_params
['frequency_unit']) = CRM_Price_BAO_PriceSet
::getRecurDetails($this->_params
['priceSetId']);
425 // FIXME: set interval and unit based on selected membership type
426 $this->_params
['frequency_interval'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
427 $this->_params
['selectMembership'], 'duration_interval'
429 $this->_params
['frequency_unit'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
430 $this->_params
['selectMembership'], 'duration_unit'
436 $params = $this->processPcp($this, $this->_params
);
437 $this->_params
= $params;
439 $this->_params
['invoiceID'] = $this->get('invoiceID');
441 //carry campaign from profile.
442 if (array_key_exists('contribution_campaign_id', $this->_params
)) {
443 $this->_params
['campaign_id'] = $this->_params
['contribution_campaign_id'];
446 // assign contribution page id to the template so we can add css class for it
447 $this->assign('contributionPageID', $this->_id
);
449 $this->set('params', $this->_params
);
453 * Build the form object
457 public function buildQuickForm() {
458 $this->assignToTemplate();
460 $params = $this->_params
;
461 // make sure we have values for it
462 if ($this->_honor_block_is_active
&& !empty($params['soft_credit_type_id'])) {
464 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
466 $this->assign('honor_block_is_active', $this->_honor_block_is_active
);
467 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
468 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
470 $fieldTypes = array('Contact');
471 $fieldTypes[] = CRM_Core_BAO_UFGroup
::getContactType($params['honoree_profile_id']);
472 $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
474 $this->assign('receiptFromEmail', CRM_Utils_Array
::value('receipt_from_email', $this->_values
));
475 $amount_block_is_active = $this->get('amount_block_is_active');
476 $this->assign('amount_block_is_active', $amount_block_is_active);
478 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
479 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
481 $getTaxDetails = FALSE;
482 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
483 foreach ($this->_lineItem
as $key => $value) {
484 foreach ($value as $v) {
485 if (isset($v['tax_rate'])) {
486 if ($v['tax_rate'] != '') {
487 $getTaxDetails = TRUE;
492 $this->assign('getTaxDetails', $getTaxDetails);
493 $this->assign('taxTerm', $taxTerm);
494 $this->assign('totalTaxAmount', $params['tax_amount']);
496 if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
497 $option = CRM_Utils_Array
::value('options_' . $params['selectProduct'], $params);
498 $productID = $params['selectProduct'];
499 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, FALSE,
502 $this->set('productID', $productID);
503 $this->set('option', $option);
505 $config = CRM_Core_Config
::singleton();
506 if (in_array('CiviMember', $config->enableComponents
)) {
507 if (isset($params['selectMembership']) &&
508 $params['selectMembership'] != 'no_thanks'
510 CRM_Member_BAO_Membership
::buildMembershipBlock($this,
512 $this->_membershipContactID
,
514 $params['selectMembership'],
519 $this->assign('membershipBlock', FALSE);
522 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre', TRUE);
523 $this->buildCustom($this->_values
['custom_post_id'], 'customPost', TRUE);
525 if (!empty($params['hidden_onbehalf_profile'])) {
526 $ufJoinParams = array(
527 'module' => 'onBehalf',
528 'entity_table' => 'civicrm_contribution_page',
529 'entity_id' => $this->_id
,
531 $OnBehalfProfile = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
532 $profileId = $OnBehalfProfile[0];
534 $fieldTypes = array('Contact', 'Organization');
535 $contactSubType = CRM_Contact_BAO_ContactType
::subTypes('Organization');
536 $fieldTypes = array_merge($fieldTypes, $contactSubType);
537 if (is_array($this->_membershipBlock
) && !empty($this->_membershipBlock
)) {
538 $fieldTypes = array_merge($fieldTypes, array('Membership'));
541 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
544 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
547 $this->_separateMembershipPayment
= $this->get('separateMembershipPayment');
548 $this->assign('is_separate_payment', $this->_separateMembershipPayment
);
549 if ($this->_priceSetId
&& !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
550 $this->assign('lineItem', $this->_lineItem
);
553 $this->assign('is_quick_config', 1);
554 $this->_params
['is_quick_config'] = 1;
556 $this->assign('priceSetID', $this->_priceSetId
);
557 $paymentProcessorType = CRM_Core_PseudoConstant
::paymentProcessorType(FALSE, NULL, 'name');
558 if ($this->_paymentProcessor
&&
559 $this->_paymentProcessor
['payment_processor_type_id'] == CRM_Utils_Array
::key('Google_Checkout', $paymentProcessorType)
560 && !$this->_params
['is_pay_later'] && !($this->_amount
== 0)
562 $this->_checkoutButtonName
= $this->getButtonName('next', 'checkout');
564 $this->_checkoutButtonName
,
565 $this->_paymentProcessor
['url_button'],
566 array('class' => 'crm-form-submit')
569 $this->addButtons(array(
572 'name' => ts('Go Back'),
578 if ($this->_contributeMode
== 'notify' ||
!$this->_values
['is_monetary'] ||
579 $this->_amount
<= 0.0 ||
$this->_params
['is_pay_later'] ||
580 ($this->_separateMembershipPayment
&& $this->_amount
<= 0.0)
582 $contribButton = ts('Continue');
583 $this->assign('button', ts('Continue'));
586 $contribButton = ts('Make Contribution');
587 $this->assign('button', ts('Make Contribution'));
589 $this->addButtons(array(
592 'name' => $contribButton,
593 'spacing' => ' ',
595 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"),
599 'name' => ts('Go Back'),
606 $fields = array_fill_keys(array_keys($this->_fields
), 1);
607 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
609 $contact = $this->_params
;
610 foreach ($fields as $name => $dontCare) {
611 // Recursively set defaults for nested fields
612 if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' ||
$name == 'honor')) {
613 foreach ($contact[$name] as $fieldName => $fieldValue) {
614 if (is_array($fieldValue) && !in_array($this->_fields
[$name][$fieldName]['html_type'], array(
619 foreach ($fieldValue as $key => $value) {
620 $defaults["{$name}[{$fieldName}][{$key}]"] = $value;
624 $defaults["{$name}[{$fieldName}]"] = $fieldValue;
628 elseif (isset($contact[$name])) {
629 $defaults[$name] = $contact[$name];
630 if (substr($name, 0, 7) == 'custom_') {
631 $timeField = "{$name}_time";
632 if (isset($contact[$timeField])) {
633 $defaults[$timeField] = $contact[$timeField];
635 if (isset($contact["{$name}_id"])) {
636 $defaults["{$name}_id"] = $contact["{$name}_id"];
639 elseif (in_array($name, array(
643 )) && !empty($contact[$name . '_custom'])
645 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
650 $this->assign('useForMember', $this->get('useForMember'));
652 $this->setDefaults($defaults);
658 * Overwrite action, since we are only showing elements in frozen mode
659 * no help display needed
663 public function getAction() {
664 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
665 return CRM_Core_Action
::VIEW | CRM_Core_Action
::PREVIEW
;
668 return CRM_Core_Action
::VIEW
;
673 * Set default values for the form. Note that in edit/view mode
674 * the default values are retrieved from the database
679 public function setDefaultValues() {
687 public function postProcess() {
688 $contactID = $this->getContactID();
689 $isPayLater = $this->_params
['is_pay_later'];
690 if ($this->_params
['payment_processor'] == 0) {
691 $this->_params
['is_pay_later'] = $isPayLater = TRUE;
693 // add a description field at the very beginning
694 $this->_params
['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo
['title']) ?
$this->_pcpInfo
['title'] : $this->_values
['title']);
696 // also add accounting code
697 $this->_params
['accountingCode'] = CRM_Utils_Array
::value('accountingCode',
702 $this->_params
['currencyID'] = CRM_Core_Config
::singleton()->defaultCurrency
;
704 //carry payment processor id.
705 if ($paymentProcessorId = CRM_Utils_Array
::value('id', $this->_paymentProcessor
)) {
706 $this->_params
['payment_processor_id'] = $paymentProcessorId;
708 if (!empty($params['image_URL'])) {
709 CRM_Contact_BAO_Contact
::processImageParams($params);
711 $premiumParams = $membershipParams = $params = $this->_params
;
712 $fields = array('email-Primary' => 1);
714 // get the add to groups
715 $addToGroups = array();
717 // now set the values for the billing location.
718 foreach ($this->_fields
as $name => $value) {
721 // get the add to groups for uf fields
722 if (!empty($value['add_to_group_id'])) {
723 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
727 if (!array_key_exists('first_name', $fields)) {
728 $nameFields = array('first_name', 'middle_name', 'last_name');
729 foreach ($nameFields as $name) {
731 if (array_key_exists("billing_$name", $params)) {
732 $params[$name] = $params["billing_{$name}"];
733 $params['preserveDBName'] = TRUE;
738 // billing email address
739 $fields["email-{$this->_bltID}"] = 1;
741 //unset the billing parameters if it is pay later mode
742 //to avoid creation of billing location
743 if ($isPayLater && !$this->_isBillingAddressRequiredForPayLater
) {
744 $billingFields = array(
745 'billing_first_name',
746 'billing_middle_name',
748 "billing_street_address-{$this->_bltID}",
749 "billing_city-{$this->_bltID}",
750 "billing_state_province-{$this->_bltID}",
751 "billing_state_province_id-{$this->_bltID}",
752 "billing_postal_code-{$this->_bltID}",
753 "billing_country-{$this->_bltID}",
754 "billing_country_id-{$this->_bltID}",
757 foreach ($billingFields as $value) {
758 unset($params[$value]);
759 unset($fields[$value]);
763 // if onbehalf-of-organization contribution, take out
764 // organization params in a separate variable, to make sure
765 // normal behavior is continued. And use that variable to
766 // process on-behalf-of functionality.
767 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
768 $behalfOrganization = array();
769 $orgFields = array('organization_name', 'organization_id', 'org_option');
770 foreach ($orgFields as $fld) {
771 if (array_key_exists($fld, $params)) {
772 $behalfOrganization[$fld] = $params[$fld];
773 unset($params[$fld]);
777 if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) {
778 foreach ($params['onbehalf'] as $fld => $values) {
779 if (strstr($fld, 'custom_')) {
780 $behalfOrganization[$fld] = $values;
782 elseif (!(strstr($fld, '-'))) {
783 if (in_array($fld, array(
784 'contribution_campaign_id',
785 'member_campaign_id',
787 $fld = 'campaign_id';
790 $behalfOrganization[$fld] = $values;
792 $this->_params
[$fld] = $values;
797 if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) {
798 foreach ($params['onbehalf_location'] as $block => $vals) {
799 //fix for custom data (of type checkbox, multi-select)
800 if (substr($block, 0, 7) == 'custom_') {
803 // fix the index of block elements
804 if (is_array($vals)) {
805 foreach ($vals as $key => $val) {
806 //dont adjust the index of address block as
807 //it's index is WRT to location type
808 $newKey = ($block == 'address') ?
$key : ++
$key;
809 $behalfOrganization[$block][$newKey] = $val;
813 unset($params['onbehalf_location']);
815 if (!empty($params['onbehalf[image_URL]'])) {
816 $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]'];
820 // check for profile double opt-in and get groups to be subscribed
821 $subscribeGroupIds = CRM_Core_BAO_UFGroup
::getDoubleOptInGroupIds($params, $contactID);
823 // since we are directly adding contact to group lets unset it from mailing
824 if (!empty($addToGroups)) {
825 foreach ($addToGroups as $groupId) {
826 if (isset($subscribeGroupIds[$groupId])) {
827 unset($subscribeGroupIds[$groupId]);
832 foreach ($addToGroups as $k) {
833 if (array_key_exists($k, $subscribeGroupIds)) {
834 unset($addToGroups[$k]);
838 if (empty($contactID)) {
839 $dupeParams = $params;
840 if (!empty($dupeParams['onbehalf'])) {
841 unset($dupeParams['onbehalf']);
844 $dedupeParams = CRM_Dedupe_Finder
::formatParams($dupeParams, 'Individual');
845 $dedupeParams['check_permission'] = FALSE;
846 $ids = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
848 // if we find more than one contact, use the first one
849 $contactID = CRM_Utils_Array
::value(0, $ids);
851 // Fetch default greeting id's if creating a contact
853 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
854 if (!isset($params[$greeting])) {
855 $params[$greeting] = CRM_Contact_BAO_Contact_Utils
::defaultGreeting('Individual', $greeting);
862 $contactType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
864 $contactID = CRM_Contact_BAO_Contact
::createProfileContact(
874 // Make the contact ID associated with the contribution available at the Class level.
875 // Also make available to the session.
876 //@todo consider handling this in $this->getContactID();
877 $this->set('contactID', $contactID);
878 $this->_contactID
= $contactID;
880 //get email primary first if exist
881 $subscriptionEmail = array('email' => CRM_Utils_Array
::value('email-Primary', $params));
882 if (!$subscriptionEmail['email']) {
883 $subscriptionEmail['email'] = CRM_Utils_Array
::value("email-{$this->_bltID}", $params);
885 // subscribing contact to groups
886 if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) {
887 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID);
890 // If onbehalf-of-organization contribution / signup, add organization
891 // and it's location.
892 if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) {
894 foreach ($this->_fields
['onbehalf'] as $name => $value) {
895 $ufFields[$name] = 1;
897 self
::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values
,
898 $this->_params
, $ufFields
901 elseif (!empty($this->_membershipContactID
) && $contactID != $this->_membershipContactID
) {
902 // this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household,
903 // store current user id as related contact for later use for mailing / activity..
904 $this->_values
['related_contact'] = $contactID;
905 $this->_params
['related_contact'] = $contactID;
906 // swap contact like we do for on-behalf-org case, so parent/primary membership is affected
907 $contactID = $this->_membershipContactID
;
910 // lets store the contactID in the session
911 // for things like tell a friend
912 $session = CRM_Core_Session
::singleton();
913 if (!$session->get('userID')) {
914 $session->set('transaction.userID', $contactID);
917 $session->set('transaction.userID', NULL);
920 $this->_useForMember
= $this->get('useForMember');
922 // store the fact that this is a membership and membership type is selected
923 $processMembership = FALSE;
924 if ((!empty($membershipParams['selectMembership']) &&
925 $membershipParams['selectMembership'] != 'no_thanks'
929 $processMembership = TRUE;
931 if (!$this->_useForMember
) {
932 $this->assign('membership_assign', TRUE);
933 $this->set('membershipTypeID', $this->_params
['selectMembership']);
936 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
937 $membershipParams['is_test'] = 1;
939 if ($this->_params
['is_pay_later']) {
940 $membershipParams['is_pay_later'] = 1;
944 if ($processMembership) {
945 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $membershipParams, TRUE);
947 // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups
948 if (isset($this->_params
['related_contact'])) {
949 $membershipParams['cms_contactID'] = $this->_params
['related_contact'];
952 $membershipParams['cms_contactID'] = $contactID;
955 //inherit campaign from contribution page.
956 if (!array_key_exists('campaign_id', $membershipParams)) {
957 $membershipParams['campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
);
960 if (!empty($membershipParams['onbehalf']) &&
961 is_array($membershipParams['onbehalf']) && !empty($membershipParams['onbehalf']['member_campaign_id'])
963 $this->_params
['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
966 $customFieldsFormatted = $fieldTypes = array();
967 if (!empty($membershipParams['onbehalf']) &&
968 is_array($membershipParams['onbehalf'])
970 foreach ($membershipParams['onbehalf'] as $key => $value) {
971 if (strstr($key, 'custom_')) {
972 $customFieldId = explode('_', $key);
973 CRM_Core_BAO_CustomField
::formatCustomField(
975 $customFieldsFormatted,
983 $fieldTypes = array('Contact', 'Organization', 'Membership');
986 $priceFieldIds = $this->get('memberPriceFieldIDS');
988 if (!empty($priceFieldIds)) {
989 $contributionTypeID = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $priceFieldIds['id'], 'financial_type_id');
990 unset($priceFieldIds['id']);
991 $membershipTypeIds = array();
992 $membershipTypeTerms = array();
993 foreach ($priceFieldIds as $priceFieldId) {
994 if ($id = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
995 $membershipTypeIds[] = $id;
996 //@todo the value for $term is immediately overwritten. It is unclear from the code whether it was intentional to
997 // do this or a double = was intended (this ambiguity is the reason many IDEs complain about 'assignment in condition'
999 if ($term = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) {
1000 $membershipTypeTerms[$id] = ($term > 1) ?
$term : 1;
1003 $membershipTypeTerms[$id] = 1;
1007 $membershipParams['selectMembership'] = $membershipTypeIds;
1008 $membershipParams['financial_type_id'] = $contributionTypeID;
1009 $membershipParams['types_terms'] = $membershipTypeTerms;
1011 if (!empty($membershipParams['selectMembership'])) {
1013 $membershipLineItems = array();
1014 if ($this->_separateMembershipPayment
&& $this->_values
['amount_block_is_active']) {
1015 foreach ($this->_values
['fee'] as $key => $feeValues) {
1016 if ($feeValues['name'] == 'membership_amount') {
1017 $fieldId = $this->_params
['price_' . $key];
1018 $membershipLineItems[$this->_priceSetId
][$fieldId] = $this->_lineItem
[$this->_priceSetId
][$fieldId];
1019 unset($this->_lineItem
[$this->_priceSetId
][$fieldId]);
1024 $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater);
1025 if (!$this->_amount
> 0.0 ||
!$membershipParams['amount']) {
1026 // we need to explicitly create a CMS user in case of free memberships
1027 // since it is done under processConfirm for paid memberships
1028 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($membershipParams,
1029 $membershipParams['cms_contactID'],
1030 'email-' . $this->_bltID
1036 // at this point we've created a contact and stored its address etc
1037 // all the payment processors expect the name and address to be in the
1038 // so we copy stuff over to first_name etc.
1039 $paymentParams = $this->_params
;
1040 $contributionTypeId = $this->_values
['financial_type_id'];
1042 $fieldTypes = array();
1043 if (!empty($paymentParams['onbehalf']) &&
1044 is_array($paymentParams['onbehalf'])
1046 foreach ($paymentParams['onbehalf'] as $key => $value) {
1047 if (strstr($key, 'custom_')) {
1048 $this->_params
[$key] = $value;
1051 $fieldTypes = array('Contact', 'Organization', 'Contribution');
1053 $financialTypeID = $this->wrangleFinancialTypeID($contributionTypeId);
1055 CRM_Contribute_BAO_Contribution_Utils
::processConfirm($this, $paymentParams,
1056 $premiumParams, $contactID,
1060 ($this->_mode
== 'test') ?
1 : 0,
1067 * 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
1068 * Pledges are not relevant to the membership code so that portion will not go onto the membership form.
1070 * Comments from previous refactor indicate doubt as to what was going on
1071 * @param int $contributionTypeId
1073 * @return null|string
1075 public function wrangleFinancialTypeID($contributionTypeId) {
1076 if (isset($paymentParams['financial_type'])) {
1077 $contributionTypeId = $paymentParams['financial_type'];
1079 elseif (!empty($this->_values
['pledge_id'])) {
1080 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_Pledge',
1081 $this->_values
['pledge_id'],
1085 return $contributionTypeId;
1091 * @param array $premiumParams
1092 * @param $contribution
1096 public function postProcessPremium($premiumParams, $contribution) {
1097 $hour = $minute = $second = 0;
1098 // assigning Premium information to receipt tpl
1099 $selectProduct = CRM_Utils_Array
::value('selectProduct', $premiumParams);
1100 if ($selectProduct &&
1101 $selectProduct != 'no_thanks'
1103 $startDate = $endDate = "";
1104 $this->assign('selectPremium', TRUE);
1105 $productDAO = new CRM_Contribute_DAO_Product();
1106 $productDAO->id
= $selectProduct;
1107 $productDAO->find(TRUE);
1108 $this->assign('product_name', $productDAO->name
);
1109 $this->assign('price', $productDAO->price
);
1110 $this->assign('sku', $productDAO->sku
);
1111 $this->assign('option', CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams));
1113 $periodType = $productDAO->period_type
;
1116 $fixed_period_start_day = $productDAO->fixed_period_start_day
;
1117 $duration_unit = $productDAO->duration_unit
;
1118 $duration_interval = $productDAO->duration_interval
;
1119 if ($periodType == 'rolling') {
1120 $startDate = date('Y-m-d');
1122 elseif ($periodType == 'fixed') {
1123 if ($fixed_period_start_day) {
1124 $date = explode('-', date('Y-m-d'));
1125 $month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2);
1126 $day = substr($fixed_period_start_day, -2) . "<br/>";
1128 $startDate = $year . '-' . $month . '-' . $day;
1131 $startDate = date('Y-m-d');
1135 $date = explode('-', $startDate);
1140 switch ($duration_unit) {
1142 $year = $year +
$duration_interval;
1146 $month = $month +
$duration_interval;
1150 $day = $day +
$duration_interval;
1154 $day = $day +
($duration_interval * 7);
1156 $endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year));
1157 $this->assign('start_date', $startDate);
1158 $this->assign('end_date', $endDate);
1161 $dao = new CRM_Contribute_DAO_Premium();
1162 $dao->entity_table
= 'civicrm_contribution_page';
1163 $dao->entity_id
= $this->_id
;
1165 $this->assign('contact_phone', $dao->premiums_contact_phone
);
1166 $this->assign('contact_email', $dao->premiums_contact_email
);
1168 //create Premium record
1170 'product_id' => $premiumParams['selectProduct'],
1171 'contribution_id' => $contribution->id
,
1172 'product_option' => CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams),
1174 'start_date' => CRM_Utils_Date
::customFormat($startDate, '%Y%m%d'),
1175 'end_date' => CRM_Utils_Date
::customFormat($endDate, '%Y%m%d'),
1177 if (!empty($premiumParams['selectProduct'])) {
1178 $daoPremiumsProduct = new CRM_Contribute_DAO_PremiumsProduct();
1179 $daoPremiumsProduct->product_id
= $premiumParams['selectProduct'];
1180 $daoPremiumsProduct->premiums_id
= $dao->id
;
1181 $daoPremiumsProduct->find(TRUE);
1182 $params['financial_type_id'] = $daoPremiumsProduct->financial_type_id
;
1184 //Fixed For CRM-3901
1185 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1186 $daoContrProd->contribution_id
= $contribution->id
;
1187 if ($daoContrProd->find(TRUE)) {
1188 $params['id'] = $daoContrProd->id
;
1191 CRM_Contribute_BAO_Contribution
::addPremium($params);
1192 if ($productDAO->cost
&& !empty($params['financial_type_id'])) {
1193 $trxnParams = array(
1194 'cost' => $productDAO->cost
,
1195 'currency' => $productDAO->currency
,
1196 'financial_type_id' => $params['financial_type_id'],
1197 'contributionId' => $contribution->id
,
1199 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($trxnParams);
1202 elseif ($selectProduct == 'no_thanks') {
1203 //Fixed For CRM-3901
1204 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1205 $daoContrProd->contribution_id
= $contribution->id
;
1206 if ($daoContrProd->find(TRUE)) {
1207 $daoContrProd->delete();
1213 * Process the contribution
1215 * @param CRM_Core_Form $form
1216 * @param array $params
1217 * @param array $result
1218 * @param int $contactID
1219 * @param CRM_Financial_DAO_FinancialType $financialType
1220 * @param bool $pending
1221 * @param bool $online
1223 * @param bool $isTest
1224 * @param array $lineItems
1227 * @return CRM_Contribute_DAO_Contribution
1229 static function processContribution(
1240 $transaction = new CRM_Core_Transaction();
1241 $contribSoftContactId = $addressID = NULL;
1243 // add these values for the recurringContrib function ,CRM-10188
1244 $params['financial_type_id'] = $financialType->id
;
1246 //create an contribution address
1247 if ($form->_contributeMode
!= 'notify' && empty($params['is_pay_later']) && !empty($form->_values
['is_monetary'])) {
1248 $addressID = CRM_Contribute_BAO_Contribution
::createAddress($params, $form->_bltID
);
1251 //@todo - this is being set from the form to resolve CRM-10188 - an
1252 // eNotice caused by it not being set @ the front end
1253 // however, we then get it being over-written with null for backend contributions
1254 // a better fix would be to set the values in the respective forms rather than require
1255 // a function being shared by two forms to deal with their respective values
1256 // moving it to the BAO & not taking the $form as a param would make sense here.
1257 if (!isset($params['is_email_receipt']) && !empty($form->_values
['is_email_receipt'])) {
1258 $params['is_email_receipt'] = CRM_Utils_Array
::value('is_email_receipt', $form->_values
);
1260 $recurringContributionID = self
::processRecurringContribution($form, $params, $contactID, $financialType, $online);
1263 // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it.
1264 if (isset($params['non_deductible_amount']) && (!empty($params['non_deductible_amount']))) {
1265 $nonDeductibleAmount = $params['non_deductible_amount'];
1267 // if non_deductible_amount does NOT exist - then calculate it depending on:
1268 // $contributionType->is_deductible and whether there is a product (premium).
1270 //if ($contributionType->is_deductible && $deductibleMode) {
1271 if ($financialType->is_deductible
) {
1272 if ($online && isset($params['selectProduct'])) {
1273 $selectProduct = CRM_Utils_Array
::value('selectProduct', $params);
1275 if (!$online && isset($params['product_name'][0])) {
1276 $selectProduct = $params['product_name'][0];
1278 // if there is a product - compare the value to the contribution amount
1279 if (isset($selectProduct) &&
1280 $selectProduct != 'no_thanks'
1282 $productDAO = new CRM_Contribute_DAO_Product();
1283 $productDAO->id
= $selectProduct;
1284 $productDAO->find(TRUE);
1285 // product value exceeds contribution amount
1286 if ($params['amount'] < $productDAO->price
) {
1287 $nonDeductibleAmount = $params['amount'];
1289 // product value does NOT exceed contribution amount
1291 $nonDeductibleAmount = $productDAO->price
;
1294 // contribution is deductible - but there is no product
1296 $nonDeductibleAmount = '0.00';
1299 // contribution is NOT deductible
1301 $nonDeductibleAmount = $params['amount'];
1305 $now = date('YmdHis');
1306 $receiptDate = CRM_Utils_Array
::value('receipt_date', $params);
1307 if (!empty($form->_values
['is_email_receipt'])) {
1308 $receiptDate = $now;
1311 //get the contrib page id.
1312 $contributionPageId = NULL;
1314 $contributionPageId = $form->_id
;
1315 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1316 if (!array_key_exists('campaign_id', $params)) {
1317 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1321 //also for offline we do support - CRM-7290
1322 $contributionPageId = CRM_Utils_Array
::value('contribution_page_id', $params);
1323 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1326 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1327 if (!empty($params['pcp_made_through_id']) ||
!empty($params['soft_credit_to'])) {
1328 // if its due to pcp
1329 if (!empty($params['pcp_made_through_id'])) {
1330 $contribSoftContactId = CRM_Core_DAO
::getFieldValue(
1332 $params['pcp_made_through_id'],
1337 $contribSoftContactId = CRM_Utils_Array
::value('soft_credit_to', $params);
1340 // Pass these details onto with the contribution to make them
1341 // available at hook_post_process, CRM-8908
1342 $params['soft_credit_to'] = $contribSoftContactId;
1345 if (isset($params['amount'])) {
1347 if (!empty($form->_values
['is_monetary'])) {
1348 $isMonetary = $form->_values
['is_monetary'];
1350 $contribParams = self
::getContributionParams(
1351 $params, $contactID, $financialType->id
, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending, $result, $receiptDate,
1352 $recurringContributionID, $isTest, $addressID, $contribSoftContactId, $lineItems
1354 $contribution = CRM_Contribute_BAO_Contribution
::add($contribParams);
1356 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
1357 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
1359 $totalTaxAmount = 0;
1360 $dataArray = array();
1361 foreach ($form->_lineItem
as $lineItemKey => $lineItemValue) {
1362 foreach ($lineItemValue as $key => $value) {
1363 if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
1364 if (isset($dataArray[$value['tax_rate']])) {
1365 $dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $value);
1368 $dataArray[$value['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $value);
1373 $smarty = CRM_Core_Smarty
::singleton();
1374 $smarty->assign('dataArray', $dataArray);
1375 $smarty->assign('totalTaxAmount', $params['tax_amount']);
1377 if (is_a($contribution, 'CRM_Core_Error')) {
1378 $message = CRM_Core_Error
::getMessages($contribution);
1379 CRM_Core_Error
::fatal($message);
1382 // lets store it in the form variable so postProcess hook can get to this and use it
1383 $form->_contributionID
= $contribution->id
;
1386 //CRM-13981, processing honor contact into soft-credit contribution
1387 CRM_Contact_Form_ProfileContact
::postProcess($form);
1389 // process soft credit / pcp pages
1390 CRM_Contribute_Form_Contribution_Confirm
::processPcpSoft($params, $contribution);
1392 //handle pledge stuff.
1393 if (empty($form->_params
['separate_membership_payment']) && !empty($form->_values
['pledge_block_id']) &&
1394 (!empty($form->_params
['is_pledge']) ||
!empty($form->_values
['pledge_id']))
1397 if (!empty($form->_values
['pledge_id'])) {
1399 //when user doing pledge payments.
1400 //update the schedule when payment(s) are made
1401 foreach ($form->_params
['pledge_amount'] as $paymentId => $dontCare) {
1402 $scheduledAmount = CRM_Core_DAO
::getFieldValue(
1403 'CRM_Pledge_DAO_PledgePayment',
1409 $pledgePaymentParams = array(
1411 'contribution_id' => $contribution->id
,
1412 'status_id' => $contribution->contribution_status_id
,
1413 'actual_amount' => $scheduledAmount,
1417 CRM_Pledge_BAO_PledgePayment
::add($pledgePaymentParams);
1420 //update pledge status according to the new payment statuses
1421 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($form->_values
['pledge_id']);
1424 //when user creating pledge record.
1425 $pledgeParams = array();
1426 $pledgeParams['contact_id'] = $contribution->contact_id
;
1427 $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount
;
1428 $pledgeParams['contribution_id'] = $contribution->id
;
1429 $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id
;
1430 $pledgeParams['financial_type_id'] = $contribution->financial_type_id
;
1431 $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
1432 $pledgeParams['installments'] = $params['pledge_installments'];
1433 $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
1434 if ($pledgeParams['frequency_unit'] == 'month') {
1435 $pledgeParams['frequency_day'] = intval(date("d"));
1438 $pledgeParams['frequency_day'] = 1;
1440 $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
1441 $pledgeParams['status_id'] = $contribution->contribution_status_id
;
1442 $pledgeParams['max_reminders'] = $form->_values
['max_reminders'];
1443 $pledgeParams['initial_reminder_day'] = $form->_values
['initial_reminder_day'];
1444 $pledgeParams['additional_reminder_day'] = $form->_values
['additional_reminder_day'];
1445 $pledgeParams['is_test'] = $contribution->is_test
;
1446 $pledgeParams['acknowledge_date'] = date('Ymd');
1447 $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
1449 //inherit campaign from contirb page.
1450 $pledgeParams['campaign_id'] = $campaignId;
1452 $pledge = CRM_Pledge_BAO_Pledge
::create($pledgeParams);
1454 $form->_params
['pledge_id'] = $pledge->id
;
1456 //send acknowledgment email. only when pledge is created
1458 //build params to send acknowledgment.
1459 $pledgeParams['id'] = $pledge->id
;
1460 $pledgeParams['receipt_from_name'] = $form->_values
['receipt_from_name'];
1461 $pledgeParams['receipt_from_email'] = $form->_values
['receipt_from_email'];
1463 //scheduled amount will be same as installment_amount.
1464 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
1466 //get total pledge amount.
1467 $pledgeParams['total_pledge_amount'] = $pledge->amount
;
1469 CRM_Pledge_BAO_Pledge
::sendAcknowledgment($form, $pledgeParams);
1474 if ($online && $contribution) {
1475 CRM_Core_BAO_CustomValueTable
::postProcess($form->_params
,
1476 CRM_Core_DAO
::$_nullArray,
1477 'civicrm_contribution',
1482 elseif ($contribution) {
1483 //handle custom data.
1484 $params['contribution_id'] = $contribution->id
;
1485 if (!empty($params['custom']) &&
1486 is_array($params['custom']) &&
1487 !is_a($contribution, 'CRM_Core_Error')
1489 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_contribution', $contribution->id
);
1493 if ($contribution && !empty($params['contribution_note'])) {
1494 $noteParams = array(
1495 'entity_table' => 'civicrm_contribution',
1496 'note' => $params['contribution_note'],
1497 'entity_id' => $contribution->id
,
1498 'contact_id' => $contribution->contact_id
,
1499 'modified_date' => date('Ymd'),
1502 CRM_Core_BAO_Note
::add($noteParams, array());
1506 if (isset($params['related_contact'])) {
1507 $contactID = $params['related_contact'];
1509 elseif (isset($params['cms_contactID'])) {
1510 $contactID = $params['cms_contactID'];
1513 //create contribution activity w/ individual and target
1514 //activity w/ organisation contact id when onbelf, CRM-4027
1515 $targetContactID = NULL;
1516 if (!empty($params['hidden_onbehalf_profile'])) {
1517 $targetContactID = $contribution->contact_id
;
1518 $contribution->contact_id
= $contactID;
1521 // create an activity record
1522 if ($contribution) {
1523 CRM_Activity_BAO_Activity
::addActivity($contribution, NULL, $targetContactID);
1526 $transaction->commit();
1527 // CRM-13074 - create the CMSUser after the transaction is completed as it
1528 // is not appropriate to delete a valid contribution if a user create problem occurs
1529 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($params,
1531 'email-' . $form->_bltID
1533 return $contribution;
1537 * Create the recurring contribution record
1539 * @param CRM_Core_Form $form
1540 * @param array $params
1541 * @param int $contactID
1542 * @param string $contributionType
1543 * @param bool $online
1547 public static function processRecurringContribution(&$form, &$params, $contactID, $contributionType, $online = TRUE) {
1548 // return if this page is not set for recurring
1549 // or the user has not chosen the recurring option
1551 //this is online case validation.
1552 if ((empty($form->_values
['is_recur']) && $online) ||
empty($params['is_recur'])) {
1556 $recurParams = array('contact_id' => $contactID);
1557 $recurParams['amount'] = CRM_Utils_Array
::value('amount', $params);
1558 $recurParams['auto_renew'] = CRM_Utils_Array
::value('auto_renew', $params);
1559 $recurParams['frequency_unit'] = CRM_Utils_Array
::value('frequency_unit', $params);
1560 $recurParams['frequency_interval'] = CRM_Utils_Array
::value('frequency_interval', $params);
1561 $recurParams['installments'] = CRM_Utils_Array
::value('installments', $params);
1562 $recurParams['financial_type_id'] = CRM_Utils_Array
::value('financial_type_id', $params);
1564 // CRM-14354: For an auto-renewing membership with an additional contribution,
1565 // if separate payments is not enabled, make sure only the membership fee recurs
1566 if (!empty($form->_membershipBlock
)
1567 && $form->_membershipBlock
['is_separate_payment'] === '0'
1568 && isset($params['selectMembership'])
1569 && $form->_values
['is_allow_other_amount'] == '1'
1571 $recurParams['amount'] = $form->_membershipTypeValues
[$params['selectMembership']]['minimum_fee'];
1574 $recurParams['is_test'] = 0;
1575 if (($form->_action
& CRM_Core_Action
::PREVIEW
) ||
1576 (isset($form->_mode
) && ($form->_mode
== 'test'))
1578 $recurParams['is_test'] = 1;
1581 $recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
1582 if (!empty($params['receive_date'])) {
1583 $recurParams['start_date'] = $params['receive_date'];
1585 $recurParams['invoice_id'] = CRM_Utils_Array
::value('invoiceID', $params);
1586 $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
1587 $recurParams['payment_processor_id'] = CRM_Utils_Array
::value('payment_processor_id', $params);
1588 $recurParams['is_email_receipt'] = CRM_Utils_Array
::value('is_email_receipt', $params);
1589 // we need to add a unique trxn_id to avoid a unique key error
1590 // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
1591 $recurParams['trxn_id'] = CRM_Utils_Array
::value('trxn_id', $params, $params['invoiceID']);
1592 $recurParams['financial_type_id'] = $contributionType->id
;
1594 if (!$online ||
$form->_values
['is_monetary']) {
1595 $recurParams['payment_instrument_id'] = 1;
1598 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1600 if (!array_key_exists('campaign_id', $params)) {
1601 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1604 $recurParams['campaign_id'] = $campaignId;
1606 $recurring = CRM_Contribute_BAO_ContributionRecur
::add($recurParams);
1607 if (is_a($recurring, 'CRM_Core_Error')) {
1608 CRM_Core_Error
::displaySessionError($recurring);
1609 $urlString = 'civicrm/contribute/transact';
1610 $urlParams = '_qf_Main_display=true';
1611 if (get_class($form) == 'CRM_Contribute_Form_Contribution') {
1612 $urlString = 'civicrm/contact/view/contribution';
1613 $urlParams = "action=add&cid={$form->_contactID}";
1615 $urlParams .= "&mode={$form->_mode}";
1618 CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
1621 return $recurring->id
;
1625 * Add on behalf of organization and it's location
1627 * @param array $behalfOrganization
1628 * array of organization info.
1629 * @param int $contactID
1630 * individual contact id. One.
1631 * who is doing the process of signup / contribution.
1633 * @param array $values
1634 * form values array.
1635 * @param array $params
1636 * @param null $fields
1640 public static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL) {
1641 $isCurrentEmployer = FALSE;
1644 if (!empty($behalfOrganization['organization_id']) && empty($behalfOrganization['org_option'])) {
1645 $orgID = $behalfOrganization['organization_id'];
1646 unset($behalfOrganization['organization_id']);
1647 $isCurrentEmployer = TRUE;
1650 // formalities for creating / editing organization.
1651 $behalfOrganization['contact_type'] = 'Organization';
1653 // get the relationship type id
1654 $relType = new CRM_Contact_DAO_RelationshipType();
1655 $relType->name_a_b
= 'Employee of';
1656 $relType->find(TRUE);
1657 $relTypeId = $relType->id
;
1659 // keep relationship params ready
1660 $relParams['relationship_type_id'] = $relTypeId . '_a_b';
1661 $relParams['is_permission_a_b'] = 1;
1662 $relParams['is_active'] = 1;
1665 // check if matching organization contact exists
1666 $dedupeParams = CRM_Dedupe_Finder
::formatParams($behalfOrganization, 'Organization');
1667 $dedupeParams['check_permission'] = FALSE;
1668 $dupeIDs = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Organization', 'Unsupervised');
1670 // CRM-6243 says to pick the first org even if more than one match
1671 if (count($dupeIDs) >= 1) {
1672 $behalfOrganization['contact_id'] = $orgID = $dupeIDs[0];
1673 // don't allow name edit
1674 unset($behalfOrganization['organization_name']);
1678 // if found permissioned related organization, allow location edit
1679 $behalfOrganization['contact_id'] = $orgID;
1680 // don't allow name edit
1681 unset($behalfOrganization['organization_name']);
1684 // handling for image url
1685 if (!empty($behalfOrganization['image_URL'])) {
1686 CRM_Contact_BAO_Contact
::processImageParams($behalfOrganization);
1689 // create organization, add location
1690 $orgID = CRM_Contact_BAO_Contact
::createProfileContact($behalfOrganization, $fields, $orgID,
1691 NULL, NULL, 'Organization'
1693 // create relationship
1694 $relParams['contact_check'][$orgID] = 1;
1695 $cid = array('contact' => $contactID);
1696 CRM_Contact_BAO_Relationship
::createMultiple($relParams, $cid);
1698 // if multiple match - send a duplicate alert
1699 if ($dupeIDs && (count($dupeIDs) > 1)) {
1700 $values['onbehalf_dupe_alert'] = 1;
1702 $params['onbehalf_dupe_alert'] = 1;
1705 // make sure organization-contact-id is considered for recording
1706 // contribution/membership etc..
1707 if ($contactID != $orgID) {
1708 // take a note of contact-id, so we can send the
1709 // receipt to individual contact as well.
1711 // required for mailing/template display ..etc
1712 $values['related_contact'] = $contactID;
1714 $params['related_contact'] = $contactID;
1716 //make this employee of relationship as current
1717 //employer / employee relationship, CRM-3532
1718 if ($isCurrentEmployer &&
1719 ($orgID != CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'))
1721 $isCurrentEmployer = FALSE;
1724 if (!$isCurrentEmployer && $orgID) {
1725 //build current employer params
1726 $currentEmpParams[$contactID] = $orgID;
1727 CRM_Contact_BAO_Contact_Utils
::setCurrentEmployer($currentEmpParams);
1730 // contribution / signup will be done using this
1732 $contactID = $orgID;
1737 * Function used to save pcp / soft credit entry
1738 * This is used by contribution and also event pcps
1740 * @param array $params
1741 * @param object $contribution
1742 * Contribution object.
1745 public static function processPcpSoft(&$params, &$contribution) {
1746 //add soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1747 if (!empty($params['soft_credit_to'])) {
1748 $contributionSoftParams = array();
1750 'pcp_display_in_roll',
1751 'pcp_roll_nickname',
1752 'pcp_personal_note',
1755 if (!empty($params[$val])) {
1756 $contributionSoftParams[$val] = $params[$val];
1760 $contributionSoftParams['contact_id'] = $params['soft_credit_to'];
1761 // add contribution id
1762 $contributionSoftParams['contribution_id'] = $contribution->id
;
1764 $contributionSoftParams['pcp_id'] = $params['pcp_made_through_id'];
1766 $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup
::getValue('soft_credit_type', 'pcp', 'name');
1768 CRM_Contribute_BAO_ContributionSoft
::add($contributionSoftParams);
1773 * Function used to se pcp related defaults / params
1774 * This is used by contribution and also event pcps
1776 * @param CRM_Core_Form $page
1778 * @param array $params
1782 public static function processPcp(&$page, $params) {
1783 $params['pcp_made_through_id'] = $page->_pcpId
;
1784 $page->assign('pcpBlock', TRUE);
1785 if (!empty($params['pcp_display_in_roll']) && empty($params['pcp_roll_nickname'])) {
1786 $params['pcp_roll_nickname'] = ts('Anonymous');
1787 $params['pcp_is_anonymous'] = 1;
1790 $params['pcp_is_anonymous'] = 0;
1793 'pcp_display_in_roll',
1795 'pcp_roll_nickname',
1796 'pcp_personal_note',
1798 if (!empty($params[$val])) {
1799 $page->assign($val, $params[$val]);
1807 * @param array $membershipParams
1808 * @param int $contactID
1809 * @param array $customFieldsFormatted
1810 * @param array $fieldTypes
1811 * @param array $premiumParams
1812 * @param array $membershipLineItems
1813 * Line items specifically relating to memberships.
1814 * @param $isPayLater
1816 public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater) {
1818 $membershipTypeIDs = (array) $membershipParams['selectMembership'];
1819 $membershipTypes = CRM_Member_BAO_Membership
::buildMembershipTypeValues($this, $membershipTypeIDs);
1820 $membershipType = empty($membershipTypes) ?
array() : reset($membershipTypes);
1821 $this->assign('membership_name', CRM_Utils_Array
::value('name', $membershipType));
1823 $isPaidMembership = FALSE;
1824 if ($this->_amount
>= 0.0 && isset($membershipParams['amount'])) {
1825 //amount must be greater than zero for
1826 //adding contribution record to contribution table.
1827 //this condition arises when separate membership payment is
1828 //enabled and contribution amount is not selected. fix for CRM-3010
1829 $isPaidMembership = TRUE;
1831 $isProcessSeparateMembershipTransaction = $this->isSeparateMembershipTransaction($this->_id
, $this->_values
['amount_block_is_active']);
1833 if ($this->_values
['amount_block_is_active']) {
1834 $contributionTypeId = $this->_values
['financial_type_id'];
1837 $contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $membershipType, CRM_Utils_Array
::value('financial_type_id', $membershipParams));
1840 CRM_Member_BAO_Membership
::postProcessMembership($membershipParams, $contactID,
1841 $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeIDs, $isPaidMembership, $this->_membershipId
, $isProcessSeparateMembershipTransaction, $contributionTypeId,
1842 $membershipLineItems, $isPayLater
1844 $this->assign('membership_assign', TRUE);
1845 $this->set('membershipTypeID', $membershipParams['selectMembership']);
1847 catch (CRM_Core_Exception
$e) {
1848 CRM_Core_Session
::singleton()->setStatus($e->getMessage());
1849 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_Main_display=true&qfKey={$this->_params['qfKey']}"));
1854 * Are we going to do 2 financial transactions?
1855 * ie the membership block supports a separate transactions AND the contribution form has been configured for a contribution
1856 * transaction AND a membership transaction AND the payment processor supports double financial transactions (ie. NOT doTransferPayment style)
1859 * @param int $formID
1860 * @param bool $amountBlockActiveOnForm
1864 public function isSeparateMembershipTransaction($formID, $amountBlockActiveOnForm) {
1865 $memBlockDetails = CRM_Member_BAO_Membership
::getMembershipBlock($formID);
1866 if (!empty($memBlockDetails['is_separate_payment']) && $amountBlockActiveOnForm) {
1873 * This function sets the fields
1874 * - $this->_params['amount_level']
1875 * - $this->_params['selectMembership']
1876 * And under certain circumstances sets
1877 * $this->_params['amount'] = null;
1879 * @param int $priceSetID
1881 public function setFormAmountFields($priceSetID) {
1882 $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params
['priceSetId'], 'is_quick_config');
1883 $priceField = new CRM_Price_DAO_PriceField();
1884 $priceField->price_set_id
= $priceSetID;
1885 $priceField->orderBy('weight');
1886 $priceField->find();
1887 $paramWeDoNotUnderstand = NULL;
1889 while ($priceField->fetch()) {
1890 if ($priceField->name
== "contribution_amount") {
1891 $paramWeDoNotUnderstand = $priceField->id
;
1893 if ($isQuickConfig && !empty($this->_params
["price_{$priceField->id}"])) {
1894 if ($this->_values
['fee'][$priceField->id
]['html_type'] != 'Text') {
1895 $this->_params
['amount_level'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1896 $this->_params
["price_{$priceField->id}"], 'label');
1898 if ($priceField->name
== "membership_amount") {
1899 $this->_params
['selectMembership'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1900 $this->_params
["price_{$priceField->id}"], 'membership_type_id');
1902 } // if separate payment we set contribution amount to be null, so that it will not show contribution amount same as membership amount.
1903 // @todo - this needs more documentation - it appears the setting to null is tied up with separate membership payments
1904 // but the circumstances are very confusing. Many of these conditions are repeated in the next conditional
1905 // so we should merge them together
1906 // the quick config seems like a red-herring - if this is about a separate membership payment then there
1907 // are 2 types of line items - membership ones & non-membership ones - regardless of whether quick config is set
1909 CRM_Utils_Array
::value('is_separate_payment', $this->_membershipBlock
)
1910 && !empty($this->_values
['fee'][$priceField->id
])
1911 && ($this->_values
['fee'][$priceField->id
]['name'] == "other_amount")
1912 && CRM_Utils_Array
::value("price_{$paramWeDoNotUnderstand}", $this->_params
) < 1
1913 && empty($this->_params
["price_{$priceField->id}"])
1915 $this->_params
['amount'] = NULL;
1918 // Fix for CRM-14375 - If we are using separate payments and "no
1919 // thank you" is selected for the additional contribution, set
1920 // contribution amount to be null, so that it will not show
1921 // contribution amount same as membership amount.
1922 //@todo - merge with section above
1923 if ($this->_membershipBlock
['is_separate_payment']
1924 && !empty($this->_values
['fee'][$priceField->id
])
1925 && CRM_Utils_Array
::value('name', $this->_values
['fee'][$priceField->id
]) == 'contribution_amount'
1926 && CRM_Utils_Array
::value("price_{$priceField->id}", $this->_params
) == '-1'
1928 $this->_params
['amount'] = NULL;
1934 * @param array $params
1936 * @throws CiviCRM_API3_Exception
1938 public static function submit($params) {
1939 $form = new CRM_Contribute_Form_Contribution_Confirm();
1940 $form->_id
= $params['id'];
1941 if (!empty($params['contact_id'])) {
1942 $form->_contactID
= $params['contact_id'];
1944 CRM_Contribute_BAO_ContributionPage
::setValues($form->_id
, $form->_values
);
1945 $form->_separateMembershipPayment
= CRM_Contribute_BAO_ContributionPage
::getIsMembershipPayment($form->_id
);
1946 //this way the mocked up controller ignores the session stuff
1947 $_SERVER['REQUEST_METHOD'] = 'GET';
1948 $form->controller
= new CRM_Contribute_Controller_Contribution();
1949 $params['invoiceID'] = md5(uniqid(rand(), TRUE));
1950 $paramsProcessedForForm = $form->_params
= self
::getFormParams($params['id'], $params);
1951 $form->_amount
= $params['amount'];
1952 $priceSetID = $form->_params
['priceSetId'] = $paramsProcessedForForm['price_set_id'];
1953 $priceFields = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetID);
1954 $priceSetFields = reset($priceFields);
1955 $form->_values
['fee'] = $priceSetFields['fields'];
1956 $form->_priceSetId
= $priceSetID;
1957 $form->setFormAmountFields($priceSetID);
1958 if (!empty($params['payment_processor'])) {
1959 $form->_paymentProcessor
= civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor']));
1960 if ($form->_paymentProcessor
['billing_mode'] == 1) {
1961 $form->_contributeMode
= 'direct';
1964 $form->_contributeMode
= 'notify';
1968 $form->_params
['payment_processor'] = 0;
1970 $priceFields = $priceFields[$priceSetID]['fields'];
1971 CRM_Price_BAO_PriceSet
::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution');
1972 $form->_lineItem
= array($priceSetID => $lineItems);
1973 $form->postProcess();
1977 * Helper function for static submit function - set relevant params - help us to build up an array that we can pass in
1979 * @param array $params
1982 * @throws CiviCRM_API3_Exception
1984 public static function getFormParams($id, array $params) {
1985 if (!isset($params['is_pay_later'])) {
1986 if (!empty($params['payment_processor'])) {
1987 $params['is_pay_later'] = 0;
1990 $params['is_pay_later'] = civicrm_api3('contribution_page', 'getvalue', array(
1992 'return' => 'is_pay_later',
1996 if (empty($params['price_set_id'])) {
1997 $params['price_set_id'] = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $params['id']);