3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
51 * The id of the contribution object that is created when the form is submitted
56 public $_contributionID;
59 * Set the parameters to be passed to contribution create function
61 * @param array $params
62 * @param integer $contactID
63 * @param $financialTypeID
65 * @param $contributionPageId
66 * @param $nonDeductibleAmount
72 * @param $paymentProcessorOutcome
75 * @param $recurringContributionID
80 * @param $softCreditToID
84 * @internal param $financialType
87 public static function getContributionParams($params, $contactID, $financialTypeID, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending,
88 $paymentProcessorOutcome, $receiptDate, $recurringContributionID, $isTest, $addressID, $softCreditToID, $lineItems)
90 $contributionParams = array(
91 'contact_id' => $contactID,
92 'financial_type_id' => $financialTypeID,
93 'contribution_page_id' => $contributionPageId,
94 'receive_date' => (CRM_Utils_Array
::value('receive_date', $params)) ? CRM_Utils_Date
::processDate($params['receive_date']) : date('YmdHis'),
95 'non_deductible_amount' => $nonDeductibleAmount,
96 'total_amount' => $params['amount'],
97 'tax_amount' => CRM_Utils_Array
::value('tax_amount', $params),
98 'amount_level' => CRM_Utils_Array
::value('amount_level', $params),
99 'invoice_id' => $params['invoiceID'],
100 'currency' => $params['currencyID'],
102 (!$online ||
!empty($params['source'])) ?
103 CRM_Utils_Array
::value('source', $params) :
104 CRM_Utils_Array
::value('description', $params),
105 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
106 //configure cancel reason, cancel date and thankyou date
107 //from 'contribution' type profile if included
108 'cancel_reason' => CRM_Utils_Array
::value('cancel_reason', $params, 0),
110 isset($params['cancel_date']) ?
111 CRM_Utils_Date
::format($params['cancel_date']) :
114 isset($params['thankyou_date']) ?
115 CRM_Utils_Date
::format($params['thankyou_date']) :
117 'campaign_id' => $campaignId,
118 'is_test' => $isTest,
119 'address_id' => $addressID,
120 //setting to make available to hook - although seems wrong to set on form for BAO hook availability
121 'soft_credit_to' => $softCreditToID,
122 'line_item' => $lineItems,
123 'skipLineItem' => CRM_Utils_Array
::value('skipLineItem', $params, 0)
125 if (!$online && isset($params['thankyou_date'])) {
126 $contributionParam['thankyou_date'] = $params['thankyou_date'];
128 if (!$online ||
$isMonetary) {
129 if (empty($params['is_pay_later'])) {
130 $contributionParams['payment_instrument_id'] = 1;
133 if ($paymentProcessorOutcome) {
134 $contributionParams['payment_processor'] = CRM_Utils_Array
::value('payment_processor', $paymentProcessorOutcome);
136 if (!$pending && $paymentProcessorOutcome) {
137 $contributionParams +
= array(
138 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $paymentProcessorOutcome),
139 'net_amount' => CRM_Utils_Array
::value('net_amount', $paymentProcessorOutcome, $params['amount']),
140 'trxn_id' => $paymentProcessorOutcome['trxn_id'],
141 'receipt_date' => $receiptDate,
142 // also add financial_trxn details as part of fix for CRM-4724
143 'trxn_result_code' => CRM_Utils_Array
::value('trxn_result_code', $paymentProcessorOutcome),
147 // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
148 $contributionParams['non_deductible_amount'] = trim(CRM_Utils_Money
::format($contributionParams['non_deductible_amount'], ' '));
149 $contributionParams['total_amount'] = trim(CRM_Utils_Money
::format($contributionParams['total_amount'], ' '));
151 if ($recurringContributionID) {
152 $contributionParams['contribution_recur_id'] = $recurringContributionID;
155 $contributionParams['contribution_status_id'] = $pending ?
2 : 1;
156 if (isset($contributionParams['invoice_id'])) {
157 $contributionParams['id'] = CRM_Core_DAO
::getFieldValue(
158 'CRM_Contribute_DAO_Contribution',
159 $contributionParams['invoice_id'],
165 return $contributionParams;
169 * Function to set variables up before form is built
174 public function preProcess() {
175 $config = CRM_Core_Config
::singleton();
176 parent
::preProcess();
178 // lineItem isn't set until Register postProcess
179 $this->_lineItem
= $this->get('lineItem');
180 $this->_paymentProcessor
= $this->get('paymentProcessor');
182 if ($this->_contributeMode
== 'express') {
183 // rfp == redirect from paypal
184 $rfp = CRM_Utils_Request
::retrieve('rfp', 'Boolean',
185 CRM_Core_DAO
::$_nullObject, FALSE, NULL, 'GET'
188 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
189 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
191 $this->_params
['payer'] = $expressParams['payer'];
192 $this->_params
['payer_id'] = $expressParams['payer_id'];
193 $this->_params
['payer_status'] = $expressParams['payer_status'];
195 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $expressParams, $this->_params
, FALSE);
197 // fix state and country id if present
198 if (!empty($this->_params
["billing_state_province_id-{$this->_bltID}"])) {
199 $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
201 if (!empty($this->_params
["billing_country_id-{$this->_bltID}"]) && $this->_params
["billing_country_id-{$this->_bltID}"]) {
202 $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
205 // set a few other parameters for PayPal
206 $this->_params
['token'] = $this->get('token');
208 $this->_params
['amount'] = $this->get('amount');
210 if (!empty($this->_membershipBlock
)){
211 $this->_params
['selectMembership'] = $this->get('selectMembership');
213 // we use this here to incorporate any changes made by folks in hooks
214 $this->_params
['currencyID'] = $config->defaultCurrency
;
216 $this->_params
['payment_action'] = 'Sale';
218 // also merge all the other values from the profile fields
219 $values = $this->controller
->exportValues('Main');
221 'amount', 'amount_other',
222 "billing_street_address-{$this->_bltID}",
223 "billing_city-{$this->_bltID}",
224 "billing_state_province_id-{$this->_bltID}",
225 "billing_postal_code-{$this->_bltID}",
226 "billing_country_id-{$this->_bltID}",
228 foreach ($values as $name => $value) {
230 if (!in_array($name, $skipFields)) {
231 $this->_params
[$name] = $value;
234 $this->set('getExpressCheckoutDetails', $this->_params
);
237 $this->_params
= $this->get('getExpressCheckoutDetails');
241 $this->_params
= $this->controller
->exportValues('Main');
243 if (!empty($this->_params
["billing_state_province_id-{$this->_bltID}"])) {
244 $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
246 if (!empty($this->_params
["billing_country_id-{$this->_bltID}"])) {
247 $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
250 if (isset($this->_params
['credit_card_exp_date'])) {
251 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
252 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
255 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
256 $this->_params
['amount'] = $this->get('amount');
257 $this->_params
['tax_amount'] = $this->get('tax_amount');
259 $this->_useForMember
= $this->get('useForMember');
261 if (isset($this->_params
['amount'])) {
262 $this->setFormAmountFields($this->_params
['priceSetId']);
264 $this->_params
['currencyID'] = $config->defaultCurrency
;
265 $this->_params
['payment_action'] = 'Sale';
268 $this->_params
['is_pay_later'] = $this->get('is_pay_later');
269 $this->assign('is_pay_later', $this->_params
['is_pay_later']);
270 if ($this->_params
['is_pay_later']) {
271 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
273 // if onbehalf-of-organization
274 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
276 if (empty($this->_params
['org_option']) && empty($this->_params
['organization_id'])) {
277 if (!empty($this->_params
['onbehalfof_id'])) {
278 $this->_params
['organization_id'] = $this->_params
['onbehalfof_id'];
281 $this->_params
['organization_id'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_params
['onbehalf']['organization_name'], 'id', 'display_name');
285 $this->_params
['organization_name'] = $this->_params
['onbehalf']['organization_name'];
286 $addressBlocks = array(
287 'street_address', 'city', 'state_province',
288 'postal_code', 'country', 'supplemental_address_1',
289 'supplemental_address_2', 'supplemental_address_3',
290 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'address_name',
293 $blocks = array('email', 'phone', 'im', 'url', 'openid');
294 foreach ($this->_params
['onbehalf'] as $loc => $value) {
295 $field = $typeId = NULL;
296 if (strstr($loc, '-')) {
297 list($field, $locType) = explode('-', $loc);
300 if (in_array($field, $addressBlocks)) {
301 if ($locType == 'Primary') {
302 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
303 $locType = $defaultLocationType->id
;
306 if ($field == 'country') {
307 $value = CRM_Core_PseudoConstant
::countryIsoCode($value);
309 elseif ($field == 'state_province') {
310 $value = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value);
314 if (isset($this->_params
['onbehalf_location']['address'])
315 && 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 ) {
365 if ($locationValue) {
366 $blockValues = array(
367 $fieldName => $value,
368 $locationType => $locationValue,
369 'is_primary' => $isPrimary,
373 $blockValues = array_merge($blockValues, array($locTypeId => $typeId));
375 if (!empty($phoneExtField)) {
376 $blockValues = array_merge($blockValues, $phoneExtField);
379 $this->_params
['onbehalf_location'][$blockName][] = $blockValues;
383 elseif (strstr($loc, 'custom')) {
384 if ($value && isset($this->_params
['onbehalf']["{$loc}_id"])) {
385 $value = $this->_params
['onbehalf']["{$loc}_id"];
387 $this->_params
['onbehalf_location']["{$loc}"] = $value;
390 if ($loc == 'contact_sub_type') {
391 $this->_params
['onbehalf_location'][$loc] = $value;
394 $this->_params
['onbehalf_location'][$field] = $value;
399 elseif (!empty($this->_values
['is_for_organization'])) {
400 // no on behalf of an organization, CRM-5519
401 // so reset loc blocks from main params.
403 'phone', 'email', 'address') as $blk) {
404 if (isset($this->_params
[$blk])) {
405 unset($this->_params
[$blk]);
410 // if auto renew checkbox is set, initiate a open-ended recurring membership
411 if ((!empty($this->_params
['selectMembership']) ||
!empty($this->_params
['priceSetId'])) && !empty($this->_paymentProcessor
['is_recur']) &&
412 CRM_Utils_Array
::value('auto_renew', $this->_params
) && empty($this->_params
['is_recur']) && empty($this->_params
['frequency_interval'])) {
414 $this->_params
['is_recur'] = $this->_values
['is_recur'] = 1;
415 // check if price set is not quick config
416 if (!empty($this->_params
['priceSetId']) && !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params
['priceSetId'], 'is_quick_config')) {
417 list($this->_params
['frequency_interval'], $this->_params
['frequency_unit']) = CRM_Price_BAO_PriceSet
::getRecurDetails($this->_params
['priceSetId']);
420 // FIXME: set interval and unit based on selected membership type
421 $this->_params
['frequency_interval'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
422 $this->_params
['selectMembership'], 'duration_interval'
424 $this->_params
['frequency_unit'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
425 $this->_params
['selectMembership'], 'duration_unit'
431 $params = $this->processPcp($this, $this->_params
);
432 $this->_params
= $params;
434 $this->_params
['invoiceID'] = $this->get('invoiceID');
436 //carry campaign from profile.
437 if (array_key_exists('contribution_campaign_id', $this->_params
)) {
438 $this->_params
['campaign_id'] = $this->_params
['contribution_campaign_id'];
441 // assign contribution page id to the template so we can add css class for it
442 $this->assign('contributionPageID', $this->_id
);
444 $this->set('params', $this->_params
);
448 * Function to actually build the form
453 public function buildQuickForm() {
454 $this->assignToTemplate();
456 $params = $this->_params
;
457 // make sure we have values for it
458 if ($this->_honor_block_is_active
&& !empty($params['soft_credit_type_id'])) {
460 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
462 $this->assign('honor_block_is_active', $this->_honor_block_is_active
);
463 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
464 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
466 $fieldTypes = array('Contact');
467 $fieldTypes[] = CRM_Core_BAO_UFGroup
::getContactType($params['honoree_profile_id']);
468 $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
470 $this->assign('receiptFromEmail', CRM_Utils_Array
::value('receipt_from_email', $this->_values
));
471 $amount_block_is_active = $this->get('amount_block_is_active');
472 $this->assign('amount_block_is_active', $amount_block_is_active);
474 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,'contribution_invoice_settings');
475 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
477 $getTaxDetails = FALSE;
478 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
479 foreach ($this->_lineItem
as $key => $value) {
480 foreach ($value as $v) {
481 if (isset($v['tax_rate'])) {
482 if ($v['tax_rate'] != '') {
483 $getTaxDetails = TRUE;
488 $this->assign('getTaxDetails', $getTaxDetails);
489 $this->assign('taxTerm', $taxTerm);
490 $this->assign('totalTaxAmount', $params['tax_amount']);
492 if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
493 $option = CRM_Utils_Array
::value('options_' . $params['selectProduct'], $params);
494 $productID = $params['selectProduct'];
495 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, FALSE,
498 $this->set('productID', $productID);
499 $this->set('option', $option);
501 $config = CRM_Core_Config
::singleton();
502 if (in_array('CiviMember', $config->enableComponents
)) {
503 if (isset($params['selectMembership']) &&
504 $params['selectMembership'] != 'no_thanks'
506 CRM_Member_BAO_Membership
::buildMembershipBlock($this,
508 $this->_membershipContactID
,
510 $params['selectMembership'],
515 $this->assign('membershipBlock', FALSE);
518 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre', TRUE);
519 $this->buildCustom($this->_values
['custom_post_id'], 'customPost', TRUE);
521 if (!empty($params['hidden_onbehalf_profile'])) {
522 $ufJoinParams = array(
523 'module' => 'onBehalf',
524 'entity_table' => 'civicrm_contribution_page',
525 'entity_id' => $this->_id
,
527 $OnBehalfProfile = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
528 $profileId = $OnBehalfProfile[0];
530 $fieldTypes = array('Contact', 'Organization');
531 $contactSubType = CRM_Contact_BAO_ContactType
::subTypes('Organization');
532 $fieldTypes = array_merge($fieldTypes, $contactSubType);
533 if (is_array($this->_membershipBlock
) && !empty($this->_membershipBlock
)) {
534 $fieldTypes = array_merge($fieldTypes, array('Membership'));
537 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
540 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
543 $this->_separateMembershipPayment
= $this->get('separateMembershipPayment');
544 $this->assign('is_separate_payment', $this->_separateMembershipPayment
);
545 if ($this->_priceSetId
&& !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
546 $this->assign('lineItem', $this->_lineItem
);
548 $this->assign('is_quick_config', 1);
549 $this->_params
['is_quick_config'] = 1;
551 $this->assign('priceSetID', $this->_priceSetId
);
552 $paymentProcessorType = CRM_Core_PseudoConstant
::paymentProcessorType(false, null, 'name');
553 if ($this->_paymentProcessor
&&
554 $this->_paymentProcessor
['payment_processor_type_id'] == CRM_Utils_Array
::key('Google_Checkout', $paymentProcessorType)
555 && !$this->_params
['is_pay_later'] && !($this->_amount
== 0)
557 $this->_checkoutButtonName
= $this->getButtonName('next', 'checkout');
559 $this->_checkoutButtonName
,
560 $this->_paymentProcessor
['url_button'],
561 array('class' => 'crm-form-submit')
564 $this->addButtons(array(
567 'name' => ts('<< Go Back'),
573 if ($this->_contributeMode
== 'notify' ||
!$this->_values
['is_monetary'] ||
574 $this->_amount
<= 0.0 ||
$this->_params
['is_pay_later'] ||
575 ($this->_separateMembershipPayment
&& $this->_amount
<= 0.0)
577 $contribButton = ts('Continue >>');
578 $this->assign('button', ts('Continue'));
581 $contribButton = ts('Make Contribution');
582 $this->assign('button', ts('Make Contribution'));
584 $this->addButtons(array(
587 'name' => $contribButton,
588 'spacing' => ' ',
590 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"),
594 'name' => ts('Go Back'),
601 $fields = array_fill_keys(array_keys($this->_fields
), 1);
602 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
604 $contact = $this->_params
;
605 foreach ($fields as $name => $dontCare) {
606 // Recursively set defaults for nested fields
607 if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' ||
$name == 'honor')) {
608 foreach ($contact[$name] as $fieldName => $fieldValue) {
609 if (is_array($fieldValue) && !in_array($this->_fields
[$name][$fieldName]['html_type'], array('Multi-Select','AdvMulti-Select'))) {
610 foreach ($fieldValue as $key => $value) {
611 $defaults["{$name}[{$fieldName}][{$key}]"] = $value;
615 $defaults["{$name}[{$fieldName}]"] = $fieldValue;
619 elseif (isset($contact[$name])) {
620 $defaults[$name] = $contact[$name];
621 if (substr($name, 0, 7) == 'custom_') {
622 $timeField = "{$name}_time";
623 if (isset($contact[$timeField])) {
624 $defaults[$timeField] = $contact[$timeField];
626 if (isset($contact["{$name}_id"])) {
627 $defaults["{$name}_id"] = $contact["{$name}_id"];
630 elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
631 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
636 $this->assign('useForMember', $this->get('useForMember'));
638 $this->setDefaults($defaults);
644 * overwrite action, since we are only showing elements in frozen mode
645 * no help display needed
650 function getAction() {
651 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
652 return CRM_Core_Action
::VIEW | CRM_Core_Action
::PREVIEW
;
655 return CRM_Core_Action
::VIEW
;
660 * This function sets the default values for the form. Note that in edit/view mode
661 * the default values are retrieved from the database
667 function setDefaultValues() {}
675 public function postProcess() {
676 $contactID = $this->getContactID();
677 $isPayLater = $this->_params
['is_pay_later'];
678 if ($this->_params
['payment_processor'] == 0) {
679 $this->_params
['is_pay_later'] = $isPayLater = TRUE;
681 // add a description field at the very beginning
682 $this->_params
['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo
['title']) ?
$this->_pcpInfo
['title'] : $this->_values
['title']);
684 // also add accounting code
685 $this->_params
['accountingCode'] = CRM_Utils_Array
::value('accountingCode',
690 $this->_params
['currencyID'] = CRM_Core_Config
::singleton()->defaultCurrency
;
692 //carry payment processor id.
693 if ($paymentProcessorId = CRM_Utils_Array
::value('id', $this->_paymentProcessor
)) {
694 $this->_params
['payment_processor_id'] = $paymentProcessorId;
696 if (!empty($params['image_URL'])) {
697 CRM_Contact_BAO_Contact
::processImageParams($params);
699 $premiumParams = $membershipParams = $params = $this->_params
;
700 $fields = array('email-Primary' => 1);
702 // get the add to groups
703 $addToGroups = array();
705 // now set the values for the billing location.
706 foreach ($this->_fields
as $name => $value) {
709 // get the add to groups for uf fields
710 if (!empty($value['add_to_group_id'])) {
711 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
715 if (!array_key_exists('first_name', $fields)) {
716 $nameFields = array('first_name', 'middle_name', 'last_name');
717 foreach ($nameFields as $name) {
719 if (array_key_exists("billing_$name", $params)) {
720 $params[$name] = $params["billing_{$name}"];
721 $params['preserveDBName'] = TRUE;
726 // billing email address
727 $fields["email-{$this->_bltID}"] = 1;
729 //unset the billing parameters if it is pay later mode
730 //to avoid creation of billing location
731 if ($isPayLater && !$this->_isBillingAddressRequiredForPayLater
) {
732 $billingFields = array(
733 'billing_first_name',
734 'billing_middle_name',
736 "billing_street_address-{$this->_bltID}",
737 "billing_city-{$this->_bltID}",
738 "billing_state_province-{$this->_bltID}",
739 "billing_state_province_id-{$this->_bltID}",
740 "billing_postal_code-{$this->_bltID}",
741 "billing_country-{$this->_bltID}",
742 "billing_country_id-{$this->_bltID}",
745 foreach ($billingFields as $value) {
746 unset($params[$value]);
747 unset($fields[$value]);
751 // if onbehalf-of-organization contribution, take out
752 // organization params in a separate variable, to make sure
753 // normal behavior is continued. And use that variable to
754 // process on-behalf-of functionality.
755 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
756 $behalfOrganization = array();
757 $orgFields = array('organization_name', 'organization_id', 'org_option');
758 foreach ($orgFields as $fld) {
759 if (array_key_exists($fld, $params)) {
760 $behalfOrganization[$fld] = $params[$fld];
761 unset($params[$fld]);
765 if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) {
766 foreach ($params['onbehalf'] as $fld => $values) {
767 if (strstr($fld, 'custom_')) {
768 $behalfOrganization[$fld] = $values;
770 elseif (!(strstr($fld, '-'))) {
771 if (in_array($fld, array(
772 'contribution_campaign_id', 'member_campaign_id'))) {
773 $fld = 'campaign_id';
776 $behalfOrganization[$fld] = $values;
778 $this->_params
[$fld] = $values;
783 if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) {
784 foreach ($params['onbehalf_location'] as $block => $vals) {
785 //fix for custom data (of type checkbox, multi-select)
786 if ( substr($block, 0, 7) == 'custom_' ) {
789 // fix the index of block elements
790 if (is_array($vals) ) {
791 foreach ( $vals as $key => $val ) {
792 //dont adjust the index of address block as
793 //it's index is WRT to location type
794 $newKey = ($block == 'address') ?
$key : ++
$key;
795 $behalfOrganization[$block][$newKey] = $val;
799 unset($params['onbehalf_location']);
801 if (!empty($params['onbehalf[image_URL]'])) {
802 $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]'];
806 // check for profile double opt-in and get groups to be subscribed
807 $subscribeGroupIds = CRM_Core_BAO_UFGroup
::getDoubleOptInGroupIds($params, $contactID);
809 // since we are directly adding contact to group lets unset it from mailing
810 if (!empty($addToGroups)) {
811 foreach ($addToGroups as $groupId) {
812 if (isset($subscribeGroupIds[$groupId])) {
813 unset($subscribeGroupIds[$groupId]);
818 foreach ($addToGroups as $k) {
819 if (array_key_exists($k, $subscribeGroupIds)) {
820 unset($addToGroups[$k]);
824 if (empty($contactID)) {
825 $dupeParams = $params;
826 if (!empty($dupeParams['onbehalf'])) {
827 unset($dupeParams['onbehalf']);
830 $dedupeParams = CRM_Dedupe_Finder
::formatParams($dupeParams, 'Individual');
831 $dedupeParams['check_permission'] = FALSE;
832 $ids = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
834 // if we find more than one contact, use the first one
835 $contactID = CRM_Utils_Array
::value(0, $ids);
837 // Fetch default greeting id's if creating a contact
839 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
840 if (!isset($params[$greeting])) {
841 $params[$greeting] = CRM_Contact_BAO_Contact_Utils
::defaultGreeting('Individual', $greeting);
848 $contactType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
850 $contactID = CRM_Contact_BAO_Contact
::createProfileContact(
860 // Make the contact ID associated with the contribution available at the Class level.
861 // Also make available to the session.
862 //@todo consider handling this in $this->getContactID();
863 $this->set('contactID', $contactID);
864 $this->_contactID
= $contactID;
866 //get email primary first if exist
867 $subscriptionEmail = array('email' => CRM_Utils_Array
::value('email-Primary', $params));
868 if (!$subscriptionEmail['email']) {
869 $subscriptionEmail['email'] = CRM_Utils_Array
::value("email-{$this->_bltID}", $params);
871 // subscribing contact to groups
872 if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) {
873 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID);
876 // If onbehalf-of-organization contribution / signup, add organization
877 // and it's location.
878 if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) {
880 foreach ($this->_fields
['onbehalf'] as $name => $value) {
881 $ufFields[$name] = 1;
883 self
::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values
,
884 $this->_params
, $ufFields
886 } else if (!empty($this->_membershipContactID
) && $contactID != $this->_membershipContactID
) {
887 // this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household,
888 // store current user id as related contact for later use for mailing / activity..
889 $this->_values
['related_contact'] = $contactID;
890 $this->_params
['related_contact'] = $contactID;
891 // swap contact like we do for on-behalf-org case, so parent/primary membership is affected
892 $contactID = $this->_membershipContactID
;
895 // lets store the contactID in the session
896 // for things like tell a friend
897 $session = CRM_Core_Session
::singleton();
898 if (!$session->get('userID')) {
899 $session->set('transaction.userID', $contactID);
902 $session->set('transaction.userID', NULL);
905 $this->_useForMember
= $this->get('useForMember');
907 // store the fact that this is a membership and membership type is selected
908 $processMembership = FALSE;
909 if ((!empty($membershipParams['selectMembership']) &&
910 $membershipParams['selectMembership'] != 'no_thanks'
914 $processMembership = TRUE;
916 if (!$this->_useForMember
) {
917 $this->assign('membership_assign', TRUE);
918 $this->set('membershipTypeID', $this->_params
['selectMembership']);
921 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
922 $membershipParams['is_test'] = 1;
924 if ($this->_params
['is_pay_later']) {
925 $membershipParams['is_pay_later'] = 1;
929 if ($processMembership) {
930 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $membershipParams, TRUE);
932 // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups
933 if (isset($this->_params
['related_contact'])) {
934 $membershipParams['cms_contactID'] = $this->_params
['related_contact'];
937 $membershipParams['cms_contactID'] = $contactID;
940 //inherit campaign from contribution page.
941 if (!array_key_exists('campaign_id', $membershipParams)) {
942 $membershipParams['campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
);
945 if (!empty($membershipParams['onbehalf']) &&
946 is_array($membershipParams['onbehalf']) && !empty($membershipParams['onbehalf']['member_campaign_id'])) {
947 $this->_params
['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
950 $customFieldsFormatted = $fieldTypes = array();
951 if (!empty($membershipParams['onbehalf']) &&
952 is_array($membershipParams['onbehalf'])) {
953 foreach ($membershipParams['onbehalf'] as $key => $value) {
954 if (strstr($key, 'custom_')) {
955 $customFieldId = explode('_', $key);
956 CRM_Core_BAO_CustomField
::formatCustomField(
958 $customFieldsFormatted,
966 $fieldTypes = array('Contact', 'Organization', 'Membership');
969 $priceFieldIds = $this->get('memberPriceFieldIDS');
971 if (!empty($priceFieldIds)) {
972 $contributionTypeID = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $priceFieldIds['id'], 'financial_type_id');
973 unset($priceFieldIds['id']);
974 $membershipTypeIds = array();
975 $membershipTypeTerms = array();
976 foreach ($priceFieldIds as $priceFieldId) {
977 if ($id = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
978 $membershipTypeIds[] = $id;
979 //@todo the value for $term is immediately overwritten. It is unclear from the code whether it was intentional to
980 // do this or a double = was intended (this ambiguity is the reason many IDEs complain about 'assignment in condition'
982 if ($term = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) {
983 $membershipTypeTerms[$id] = ($term > 1) ?
$term : 1;
986 $membershipTypeTerms[$id] = 1;
990 $membershipParams['selectMembership'] = $membershipTypeIds;
991 $membershipParams['financial_type_id'] = $contributionTypeID;
992 $membershipParams['types_terms'] = $membershipTypeTerms;
994 if (!empty($membershipParams['selectMembership'])) {
996 $membershipLineItems = array();
997 if ($this->_separateMembershipPayment
&& $this->_values
['amount_block_is_active']) {
998 foreach ($this->_values
['fee'] as $key => $feeValues) {
999 if ($feeValues['name'] == 'membership_amount') {
1000 $fieldId = $this->_params
['price_' . $key];
1001 $membershipLineItems[$this->_priceSetId
][$fieldId] = $this->_lineItem
[$this->_priceSetId
][$fieldId];
1002 unset($this->_lineItem
[$this->_priceSetId
][$fieldId]);
1007 $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater);
1008 if (!$this->_amount
> 0.0 ||
!$membershipParams['amount']) {
1009 // we need to explicitly create a CMS user in case of free memberships
1010 // since it is done under processConfirm for paid memberships
1011 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($membershipParams,
1012 $membershipParams['cms_contactID'],
1013 'email-' . $this->_bltID
1019 // at this point we've created a contact and stored its address etc
1020 // all the payment processors expect the name and address to be in the
1021 // so we copy stuff over to first_name etc.
1022 $paymentParams = $this->_params
;
1023 $contributionTypeId = $this->_values
['financial_type_id'];
1025 $fieldTypes = array();
1026 if (!empty($paymentParams['onbehalf']) &&
1027 is_array($paymentParams['onbehalf'])
1029 foreach ($paymentParams['onbehalf'] as $key => $value) {
1030 if (strstr($key, 'custom_')) {
1031 $this->_params
[$key] = $value;
1034 $fieldTypes = array('Contact', 'Organization', 'Contribution');
1036 $financialTypeID = $this->wrangleFinancialTypeID($contributionTypeId);
1038 CRM_Contribute_BAO_Contribution_Utils
::processConfirm($this, $paymentParams,
1039 $premiumParams, $contactID,
1043 ($this->_mode
== 'test') ?
1 : 0,
1050 * 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
1051 * Pledges are not relevant to the membership code so that portion will not go onto the membership form.
1053 * Comments from previous refactor indicate doubt as to what was going on
1054 * @param $contributionTypeId
1056 * @return null|string
1058 function wrangleFinancialTypeID($contributionTypeId) {
1059 if (isset($paymentParams['financial_type'])) {
1060 $contributionTypeId = $paymentParams['financial_type'];
1062 elseif (!empty($this->_values
['pledge_id'])) {
1063 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_Pledge',
1064 $this->_values
['pledge_id'],
1068 return $contributionTypeId;
1074 * @param $premiumParams
1075 * @param $contribution
1080 public function postProcessPremium($premiumParams, $contribution) {
1081 $hour = $minute = $second = 0;
1082 // assigning Premium information to receipt tpl
1083 $selectProduct = CRM_Utils_Array
::value('selectProduct', $premiumParams);
1084 if ($selectProduct &&
1085 $selectProduct != 'no_thanks'
1087 $startDate = $endDate = "";
1088 $this->assign('selectPremium', TRUE);
1089 $productDAO = new CRM_Contribute_DAO_Product();
1090 $productDAO->id
= $selectProduct;
1091 $productDAO->find(TRUE);
1092 $this->assign('product_name', $productDAO->name
);
1093 $this->assign('price', $productDAO->price
);
1094 $this->assign('sku', $productDAO->sku
);
1095 $this->assign('option', CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams));
1097 $periodType = $productDAO->period_type
;
1100 $fixed_period_start_day = $productDAO->fixed_period_start_day
;
1101 $duration_unit = $productDAO->duration_unit
;
1102 $duration_interval = $productDAO->duration_interval
;
1103 if ($periodType == 'rolling') {
1104 $startDate = date('Y-m-d');
1106 elseif ($periodType == 'fixed') {
1107 if ($fixed_period_start_day) {
1108 $date = explode('-', date('Y-m-d'));
1109 $month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2);
1110 $day = substr($fixed_period_start_day, -2) . "<br>";
1112 $startDate = $year . '-' . $month . '-' . $day;
1115 $startDate = date('Y-m-d');
1119 $date = explode('-', $startDate);
1124 switch ($duration_unit) {
1126 $year = $year +
$duration_interval;
1130 $month = $month +
$duration_interval;
1134 $day = $day +
$duration_interval;
1138 $day = $day +
($duration_interval * 7);
1140 $endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year));
1141 $this->assign('start_date', $startDate);
1142 $this->assign('end_date', $endDate);
1145 $dao = new CRM_Contribute_DAO_Premium();
1146 $dao->entity_table
= 'civicrm_contribution_page';
1147 $dao->entity_id
= $this->_id
;
1149 $this->assign('contact_phone', $dao->premiums_contact_phone
);
1150 $this->assign('contact_email', $dao->premiums_contact_email
);
1152 //create Premium record
1154 'product_id' => $premiumParams['selectProduct'],
1155 'contribution_id' => $contribution->id
,
1156 'product_option' => CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams),
1158 'start_date' => CRM_Utils_Date
::customFormat($startDate, '%Y%m%d'),
1159 'end_date' => CRM_Utils_Date
::customFormat($endDate, '%Y%m%d'),
1161 if (!empty($premiumParams['selectProduct'])){
1162 $daoPremiumsProduct = new CRM_Contribute_DAO_PremiumsProduct();
1163 $daoPremiumsProduct->product_id
= $premiumParams['selectProduct'];
1164 $daoPremiumsProduct->premiums_id
= $dao->id
;
1165 $daoPremiumsProduct->find(true);
1166 $params['financial_type_id'] = $daoPremiumsProduct->financial_type_id
;
1168 //Fixed For CRM-3901
1169 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1170 $daoContrProd->contribution_id
= $contribution->id
;
1171 if ($daoContrProd->find(TRUE)) {
1172 $params['id'] = $daoContrProd->id
;
1175 CRM_Contribute_BAO_Contribution
::addPremium($params);
1176 if ($productDAO->cost
&& !empty($params['financial_type_id'])) {
1177 $trxnParams = array(
1178 'cost' => $productDAO->cost
,
1179 'currency' => $productDAO->currency
,
1180 'financial_type_id' => $params['financial_type_id'],
1181 'contributionId' => $contribution->id
1183 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($trxnParams);
1186 elseif ($selectProduct == 'no_thanks') {
1187 //Fixed For CRM-3901
1188 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1189 $daoContrProd->contribution_id
= $contribution->id
;
1190 if ($daoContrProd->find(TRUE)) {
1191 $daoContrProd->delete();
1197 * Process the contribution
1200 * @param array $params
1201 * @param array $result
1202 * @param integer $contactID
1203 * @param CRM_Financial_DAO_FinancialType $financialType
1204 * @param bool $pending
1205 * @param bool $online
1207 * @param bool $isTest
1208 * @param array $lineItems
1211 * @return CRM_Contribute_DAO_Contribution
1214 static function processContribution(
1225 $transaction = new CRM_Core_Transaction();
1226 $contribSoftContactId = $addressID = NULL;
1228 // add these values for the recurringContrib function ,CRM-10188
1229 $params['financial_type_id'] = $financialType->id
;
1231 //create an contribution address
1232 if ($form->_contributeMode
!= 'notify' && empty($params['is_pay_later']) && !empty($form->_values
['is_monetary'])) {
1233 $addressID = CRM_Contribute_BAO_Contribution
::createAddress($params, $form->_bltID
);
1236 //@todo - this is being set from the form to resolve CRM-10188 - an
1237 // eNotice caused by it not being set @ the front end
1238 // however, we then get it being over-written with null for backend contributions
1239 // a better fix would be to set the values in the respective forms rather than require
1240 // a function being shared by two forms to deal with their respective values
1241 // moving it to the BAO & not taking the $form as a param would make sense here.
1242 if(!isset($params['is_email_receipt']) && !empty($form->_values
['is_email_receipt'])){
1243 $params['is_email_receipt'] = CRM_Utils_Array
::value( 'is_email_receipt', $form->_values
);
1245 $recurringContributionID = self
::processRecurringContribution($form, $params, $contactID, $financialType, $online);
1248 // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it.
1249 if (isset($params['non_deductible_amount']) && (!empty($params['non_deductible_amount']))) {
1250 $nonDeductibleAmount = $params['non_deductible_amount'];
1252 // if non_deductible_amount does NOT exist - then calculate it depending on:
1253 // $contributionType->is_deductible and whether there is a product (premium).
1255 //if ($contributionType->is_deductible && $deductibleMode) {
1256 if ($financialType->is_deductible
) {
1257 if ($online && isset($params['selectProduct'])) {
1258 $selectProduct = CRM_Utils_Array
::value('selectProduct', $params);
1260 if (!$online && isset($params['product_name'][0])) {
1261 $selectProduct = $params['product_name'][0];
1263 // if there is a product - compare the value to the contribution amount
1264 if (isset($selectProduct) &&
1265 $selectProduct != 'no_thanks'
1267 $productDAO = new CRM_Contribute_DAO_Product();
1268 $productDAO->id
= $selectProduct;
1269 $productDAO->find(TRUE);
1270 // product value exceeds contribution amount
1271 if ($params['amount'] < $productDAO->price
) {
1272 $nonDeductibleAmount = $params['amount'];
1274 // product value does NOT exceed contribution amount
1276 $nonDeductibleAmount = $productDAO->price
;
1279 // contribution is deductible - but there is no product
1281 $nonDeductibleAmount = '0.00';
1284 // contribution is NOT deductible
1286 $nonDeductibleAmount = $params['amount'];
1290 $now = date('YmdHis');
1291 $receiptDate = CRM_Utils_Array
::value('receipt_date', $params);
1292 if (!empty($form->_values
['is_email_receipt'])) {
1293 $receiptDate = $now;
1296 //get the contrib page id.
1297 $contributionPageId = NULL;
1299 $contributionPageId = $form->_id
;
1300 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1301 if (!array_key_exists('campaign_id', $params)) {
1302 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1306 //also for offline we do support - CRM-7290
1307 $contributionPageId = CRM_Utils_Array
::value('contribution_page_id', $params);
1308 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1311 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1312 if (!empty($params['pcp_made_through_id']) ||
!empty($params['soft_credit_to'])) {
1313 // if its due to pcp
1314 if (!empty($params['pcp_made_through_id'])) {
1315 $contribSoftContactId = CRM_Core_DAO
::getFieldValue(
1317 $params['pcp_made_through_id'],
1322 $contribSoftContactId = CRM_Utils_Array
::value('soft_credit_to', $params);
1325 // Pass these details onto with the contribution to make them
1326 // available at hook_post_process, CRM-8908
1327 $params['soft_credit_to'] = $contribSoftContactId;
1330 if (isset($params['amount'])) {
1332 if (!empty($form->_values
['is_monetary'])) {
1333 $isMonetary = $form->_values
['is_monetary'];
1335 $contribParams = self
::getContributionParams(
1336 $params, $contactID, $financialType->id
, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending, $result, $receiptDate,
1337 $recurringContributionID, $isTest, $addressID, $contribSoftContactId, $lineItems
1339 $contribution = CRM_Contribute_BAO_Contribution
::add($contribParams);
1341 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,'contribution_invoice_settings');
1342 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
1344 $totalTaxAmount = 0;
1345 $dataArray = array();
1346 foreach ($form->_lineItem
as $lineItemKey => $lineItemValue) {
1347 foreach ($lineItemValue as $key => $value) {
1348 if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
1349 if (isset($dataArray[$value['tax_rate']])) {
1350 $dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $value);
1353 $dataArray[$value['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $value);
1358 $smarty = CRM_Core_Smarty
::singleton();
1359 $smarty->assign('dataArray', $dataArray);
1360 $smarty->assign('totalTaxAmount', $params['tax_amount']);
1362 if (is_a($contribution, 'CRM_Core_Error')) {
1363 $message = CRM_Core_Error
::getMessages($contribution);
1364 CRM_Core_Error
::fatal($message);
1367 // lets store it in the form variable so postProcess hook can get to this and use it
1368 $form->_contributionID
= $contribution->id
;
1371 //CRM-13981, processing honor contact into soft-credit contribution
1372 CRM_Contact_Form_ProfileContact
::postProcess($form);
1374 // process soft credit / pcp pages
1375 CRM_Contribute_Form_Contribution_Confirm
::processPcpSoft($params, $contribution);
1377 //handle pledge stuff.
1378 if (empty($form->_params
['separate_membership_payment']) && !empty($form->_values
['pledge_block_id']) &&
1379 (!empty($form->_params
['is_pledge']) ||
!empty($form->_values
['pledge_id']))
1382 if (!empty($form->_values
['pledge_id'])) {
1384 //when user doing pledge payments.
1385 //update the schedule when payment(s) are made
1386 foreach ($form->_params
['pledge_amount'] as $paymentId => $dontCare) {
1387 $scheduledAmount = CRM_Core_DAO
::getFieldValue(
1388 'CRM_Pledge_DAO_PledgePayment',
1394 $pledgePaymentParams = array(
1396 'contribution_id' => $contribution->id
,
1397 'status_id' => $contribution->contribution_status_id
,
1398 'actual_amount' => $scheduledAmount,
1402 CRM_Pledge_BAO_PledgePayment
::add($pledgePaymentParams);
1405 //update pledge status according to the new payment statuses
1406 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($form->_values
['pledge_id']);
1409 //when user creating pledge record.
1410 $pledgeParams = array();
1411 $pledgeParams['contact_id'] = $contribution->contact_id
;
1412 $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount
;
1413 $pledgeParams['contribution_id'] = $contribution->id
;
1414 $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id
;
1415 $pledgeParams['financial_type_id'] = $contribution->financial_type_id
;
1416 $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
1417 $pledgeParams['installments'] = $params['pledge_installments'];
1418 $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
1419 if ($pledgeParams['frequency_unit'] == 'month') {
1420 $pledgeParams['frequency_day'] = intval(date("d"));
1423 $pledgeParams['frequency_day'] = 1;
1425 $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
1426 $pledgeParams['status_id'] = $contribution->contribution_status_id
;
1427 $pledgeParams['max_reminders'] = $form->_values
['max_reminders'];
1428 $pledgeParams['initial_reminder_day'] = $form->_values
['initial_reminder_day'];
1429 $pledgeParams['additional_reminder_day'] = $form->_values
['additional_reminder_day'];
1430 $pledgeParams['is_test'] = $contribution->is_test
;
1431 $pledgeParams['acknowledge_date'] = date('Ymd');
1432 $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
1434 //inherit campaign from contirb page.
1435 $pledgeParams['campaign_id'] = $campaignId;
1437 $pledge = CRM_Pledge_BAO_Pledge
::create($pledgeParams);
1439 $form->_params
['pledge_id'] = $pledge->id
;
1441 //send acknowledgment email. only when pledge is created
1443 //build params to send acknowledgment.
1444 $pledgeParams['id'] = $pledge->id
;
1445 $pledgeParams['receipt_from_name'] = $form->_values
['receipt_from_name'];
1446 $pledgeParams['receipt_from_email'] = $form->_values
['receipt_from_email'];
1448 //scheduled amount will be same as installment_amount.
1449 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
1451 //get total pledge amount.
1452 $pledgeParams['total_pledge_amount'] = $pledge->amount
;
1454 CRM_Pledge_BAO_Pledge
::sendAcknowledgment($form, $pledgeParams);
1459 if ($online && $contribution) {
1460 CRM_Core_BAO_CustomValueTable
::postProcess($form->_params
,
1461 CRM_Core_DAO
::$_nullArray,
1462 'civicrm_contribution',
1467 elseif ($contribution) {
1468 //handle custom data.
1469 $params['contribution_id'] = $contribution->id
;
1470 if (!empty($params['custom']) &&
1471 is_array($params['custom']) &&
1472 !is_a($contribution, 'CRM_Core_Error')
1474 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_contribution', $contribution->id
);
1478 if ($contribution && !empty($params['contribution_note'])) {
1479 $noteParams = array(
1480 'entity_table' => 'civicrm_contribution',
1481 'note' => $params['contribution_note'],
1482 'entity_id' => $contribution->id
,
1483 'contact_id' => $contribution->contact_id
,
1484 'modified_date' => date('Ymd'),
1487 CRM_Core_BAO_Note
::add($noteParams, array());
1491 if (isset($params['related_contact'])) {
1492 $contactID = $params['related_contact'];
1494 elseif (isset($params['cms_contactID'])) {
1495 $contactID = $params['cms_contactID'];
1498 //create contribution activity w/ individual and target
1499 //activity w/ organisation contact id when onbelf, CRM-4027
1500 $targetContactID = NULL;
1501 if (!empty($params['hidden_onbehalf_profile'])) {
1502 $targetContactID = $contribution->contact_id
;
1503 $contribution->contact_id
= $contactID;
1506 // create an activity record
1507 if ($contribution) {
1508 CRM_Activity_BAO_Activity
::addActivity($contribution, NULL, $targetContactID);
1511 $transaction->commit();
1512 // CRM-13074 - create the CMSUser after the transaction is completed as it
1513 // is not appropriate to delete a valid contribution if a user create problem occurs
1514 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($params,
1516 'email-' . $form->_bltID
1518 return $contribution;
1522 * Create the recurring contribution record
1524 * @param CRM_Core_Form $form
1525 * @param array $params
1526 * @param integer $contactID
1527 * @param string $contributionType
1528 * @param bool $online
1532 static function processRecurringContribution(&$form, &$params, $contactID, $contributionType, $online = TRUE) {
1533 // return if this page is not set for recurring
1534 // or the user has not chosen the recurring option
1536 //this is online case validation.
1537 if ((empty($form->_values
['is_recur']) && $online) ||
empty($params['is_recur'])) {
1541 $recurParams = array('contact_id' => $contactID);
1542 $recurParams['amount'] = CRM_Utils_Array
::value('amount', $params);
1543 $recurParams['auto_renew'] = CRM_Utils_Array
::value('auto_renew', $params);
1544 $recurParams['frequency_unit'] = CRM_Utils_Array
::value('frequency_unit', $params);
1545 $recurParams['frequency_interval'] = CRM_Utils_Array
::value('frequency_interval', $params);
1546 $recurParams['installments'] = CRM_Utils_Array
::value('installments', $params);
1547 $recurParams['financial_type_id'] = CRM_Utils_Array
::value('financial_type_id', $params);
1549 // CRM-14354: For an auto-renewing membership with an additional contribution,
1550 // if separate payments is not enabled, make sure only the membership fee recurs
1551 if (!empty($form->_membershipBlock
)
1552 && $form->_membershipBlock
['is_separate_payment'] === '0'
1553 && isset($params['selectMembership'])
1554 && $form->_values
['is_allow_other_amount'] == '1'
1556 $recurParams['amount'] = $form->_membershipTypeValues
[$params['selectMembership']]['minimum_fee'];
1559 $recurParams['is_test'] = 0;
1560 if (($form->_action
& CRM_Core_Action
::PREVIEW
) ||
1561 (isset($form->_mode
) && ($form->_mode
== 'test'))
1563 $recurParams['is_test'] = 1;
1566 $recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
1567 if (!empty($params['receive_date'])) {
1568 $recurParams['start_date'] = $params['receive_date'];
1570 $recurParams['invoice_id'] = CRM_Utils_Array
::value('invoiceID', $params);
1571 $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
1572 $recurParams['payment_processor_id'] = CRM_Utils_Array
::value('payment_processor_id', $params);
1573 $recurParams['is_email_receipt'] = CRM_Utils_Array
::value('is_email_receipt', $params);
1574 // we need to add a unique trxn_id to avoid a unique key error
1575 // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
1576 $recurParams['trxn_id'] = CRM_Utils_Array
::value('trxn_id', $params, $params['invoiceID']);
1577 $recurParams['financial_type_id'] = $contributionType->id
;
1579 if (!$online ||
$form->_values
['is_monetary']) {
1580 $recurParams['payment_instrument_id'] = 1;
1583 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1585 if (!array_key_exists('campaign_id', $params)) {
1586 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1589 $recurParams['campaign_id'] = $campaignId;
1591 $recurring = CRM_Contribute_BAO_ContributionRecur
::add($recurParams);
1592 if (is_a($recurring, 'CRM_Core_Error')) {
1593 CRM_Core_Error
::displaySessionError($recurring);
1594 $urlString = 'civicrm/contribute/transact';
1595 $urlParams = '_qf_Main_display=true';
1596 if (get_class($form) == 'CRM_Contribute_Form_Contribution') {
1597 $urlString = 'civicrm/contact/view/contribution';
1598 $urlParams = "action=add&cid={$form->_contactID}";
1600 $urlParams .= "&mode={$form->_mode}";
1603 CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
1606 return $recurring->id
;
1610 * Function to add on behalf of organization and it's location
1612 * @param $behalfOrganization array array of organization info
1613 * @param $contactID int individual contact id. One
1614 * who is doing the process of signup / contribution.
1616 * @param $values array form values array
1618 * @param null $fields
1623 static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL) {
1624 $isCurrentEmployer = FALSE;
1627 if (!empty($behalfOrganization['organization_id']) && empty($behalfOrganization['org_option'])) {
1628 $orgID = $behalfOrganization['organization_id'];
1629 unset($behalfOrganization['organization_id']);
1630 $isCurrentEmployer = TRUE;
1633 // formalities for creating / editing organization.
1634 $behalfOrganization['contact_type'] = 'Organization';
1636 // get the relationship type id
1637 $relType = new CRM_Contact_DAO_RelationshipType();
1638 $relType->name_a_b
= 'Employee of';
1639 $relType->find(TRUE);
1640 $relTypeId = $relType->id
;
1642 // keep relationship params ready
1643 $relParams['relationship_type_id'] = $relTypeId . '_a_b';
1644 $relParams['is_permission_a_b'] = 1;
1645 $relParams['is_active'] = 1;
1648 // check if matching organization contact exists
1649 $dedupeParams = CRM_Dedupe_Finder
::formatParams($behalfOrganization, 'Organization');
1650 $dedupeParams['check_permission'] = FALSE;
1651 $dupeIDs = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Organization', 'Unsupervised');
1653 // CRM-6243 says to pick the first org even if more than one match
1654 if (count($dupeIDs) >= 1) {
1655 $behalfOrganization['contact_id'] = $orgID = $dupeIDs[0];
1656 // don't allow name edit
1657 unset($behalfOrganization['organization_name']);
1661 // if found permissioned related organization, allow location edit
1662 $behalfOrganization['contact_id'] = $orgID;
1663 // don't allow name edit
1664 unset($behalfOrganization['organization_name']);
1667 // handling for image url
1668 if (!empty($behalfOrganization['image_URL'])) {
1669 CRM_Contact_BAO_Contact
::processImageParams($behalfOrganization);
1672 // create organization, add location
1673 $orgID = CRM_Contact_BAO_Contact
::createProfileContact($behalfOrganization, $fields, $orgID,
1674 NULL, NULL, 'Organization'
1676 // create relationship
1677 $relParams['contact_check'][$orgID] = 1;
1678 $cid = array('contact' => $contactID);
1679 CRM_Contact_BAO_Relationship
::create($relParams, $cid);
1681 // if multiple match - send a duplicate alert
1682 if ($dupeIDs && (count($dupeIDs) > 1)) {
1683 $values['onbehalf_dupe_alert'] = 1;
1685 $params['onbehalf_dupe_alert'] = 1;
1688 // make sure organization-contact-id is considered for recording
1689 // contribution/membership etc..
1690 if ($contactID != $orgID) {
1691 // take a note of contact-id, so we can send the
1692 // receipt to individual contact as well.
1694 // required for mailing/template display ..etc
1695 $values['related_contact'] = $contactID;
1697 $params['related_contact'] = $contactID;
1699 //make this employee of relationship as current
1700 //employer / employee relationship, CRM-3532
1701 if ($isCurrentEmployer &&
1702 ($orgID != CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'))
1704 $isCurrentEmployer = FALSE;
1707 if (!$isCurrentEmployer && $orgID) {
1708 //build current employer params
1709 $currentEmpParams[$contactID] = $orgID;
1710 CRM_Contact_BAO_Contact_Utils
::setCurrentEmployer($currentEmpParams);
1713 // contribution / signup will be done using this
1715 $contactID = $orgID;
1720 * Function used to save pcp / soft credit entry
1721 * This is used by contribution and also event pcps
1723 * @param array $params associated array
1724 * @param object $contribution contribution object
1729 static function processPcpSoft(&$params, &$contribution) {
1730 //add soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1731 if (!empty($params['soft_credit_to'])) {
1732 $contributionSoftParams = array();
1734 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note', 'amount') as $val) {
1735 if (!empty($params[$val])) {
1736 $contributionSoftParams[$val] = $params[$val];
1740 $contributionSoftParams['contact_id'] = $params['soft_credit_to'];
1741 // add contribution id
1742 $contributionSoftParams['contribution_id'] = $contribution->id
;
1744 $contributionSoftParams['pcp_id'] = $params['pcp_made_through_id'];
1746 $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup
::getValue('soft_credit_type', 'pcp', 'name');
1748 CRM_Contribute_BAO_ContributionSoft
::add($contributionSoftParams);
1753 * Function used to se pcp related defaults / params
1754 * This is used by contribution and also event pcps
1756 * @param object $page form object
1757 * @param array $params associated array
1763 static function processPcp(&$page, $params) {
1764 $params['pcp_made_through_id'] = $page->_pcpId
;
1765 $page->assign('pcpBlock', TRUE);
1766 if (!empty($params['pcp_display_in_roll']) && empty($params['pcp_roll_nickname'])) {
1767 $params['pcp_roll_nickname'] = ts('Anonymous');
1768 $params['pcp_is_anonymous'] = 1;
1771 $params['pcp_is_anonymous'] = 0;
1774 'pcp_display_in_roll',
1776 'pcp_roll_nickname',
1779 if (!empty($params[$val])) {
1780 $page->assign($val, $params[$val]);
1788 * @param array $membershipParams
1789 * @param integer $contactID
1790 * @param array $customFieldsFormatted
1791 * @param array $fieldTypes
1792 * @param array $premiumParams
1793 * @param array $membershipLineItems line items specifically relating to memberships
1794 * @param $isPayLater
1796 public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater) {
1798 $membershipTypeIDs = (array) $membershipParams['selectMembership'];
1799 $membershipTypes = CRM_Member_BAO_Membership
::buildMembershipTypeValues($this, $membershipTypeIDs);
1800 $membershipType = empty($membershipTypes) ?
array() : reset($membershipTypes);
1801 $this->assign('membership_name', CRM_Utils_Array
::value('name', $membershipType));
1803 $isPaidMembership = FALSE;
1804 if($this->_amount
>= 0.0 && isset($membershipParams['amount'])) {
1805 //amount must be greater than zero for
1806 //adding contribution record to contribution table.
1807 //this condition arises when separate membership payment is
1808 //enabled and contribution amount is not selected. fix for CRM-3010
1809 $isPaidMembership = TRUE;
1811 $isProcessSeparateMembershipTransaction = $this->isSeparateMembershipTransaction($this->_id
, $this->_values
['amount_block_is_active']);
1813 if ($this->_values
['amount_block_is_active']) {
1814 $contributionTypeId = $this->_values
['financial_type_id'];
1817 $contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $membershipType, CRM_Utils_Array
::value('financial_type_id' ,$membershipParams));
1820 CRM_Member_BAO_Membership
::postProcessMembership($membershipParams, $contactID,
1821 $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeIDs, $isPaidMembership, $this->_membershipId
, $isProcessSeparateMembershipTransaction, $contributionTypeId,
1822 $membershipLineItems, $isPayLater
1824 $this->assign('membership_assign', TRUE);
1825 $this->set('membershipTypeID', $membershipParams['selectMembership']);
1827 catch (CRM_Core_Exception
$e) {
1828 CRM_Core_Session
::singleton()->setStatus($e->getMessage());
1829 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_Main_display=true&qfKey={$this->_params['qfKey']}"));
1834 * Are we going to do 2 financial transactions?
1835 * ie the membership block supports a separate transactions AND the contribution form has been configured for a contribution
1836 * transaction AND a membership transaction AND the payment processor supports double financial transactions (ie. NOT doTransferPayment style)
1839 * @param integer $formID
1840 * @param bool $amountBlockActiveOnForm
1844 public function isSeparateMembershipTransaction($formID, $amountBlockActiveOnForm) {
1845 $memBlockDetails = CRM_Member_BAO_Membership
::getMembershipBlock($formID);
1846 if (!empty($memBlockDetails['is_separate_payment']) && $amountBlockActiveOnForm) {
1853 * This function sets the fields
1854 * - $this->_params['amount_level']
1855 * - $this->_params['selectMembership']
1856 * And under certain circumstances sets
1857 * $this->_params['amount'] = null;
1859 * @param $priceSetID
1861 * @internal param $isQuickConfig
1862 * @internal param $priceField
1864 public function setFormAmountFields($priceSetID) {
1865 $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params
['priceSetId'], 'is_quick_config');
1866 $priceField = new CRM_Price_DAO_PriceField();
1867 $priceField->price_set_id
= $priceSetID;
1868 $priceField->orderBy('weight');
1869 $priceField->find();
1870 $paramWeDoNotUnderstand = NULL;
1872 while ($priceField->fetch()) {
1873 if ($priceField->name
== "contribution_amount") {
1874 $paramWeDoNotUnderstand = $priceField->id
;
1876 if ($isQuickConfig && !empty($this->_params
["price_{$priceField->id}"])) {
1877 if ($this->_values
['fee'][$priceField->id
]['html_type'] != 'Text') {
1878 $this->_params
['amount_level'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1879 $this->_params
["price_{$priceField->id}"], 'label');
1881 if ($priceField->name
== "membership_amount") {
1882 $this->_params
['selectMembership'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1883 $this->_params
["price_{$priceField->id}"], 'membership_type_id');
1885 } // if separate payment we set contribution amount to be null, so that it will not show contribution amount same as membership amount.
1886 // @todo - this needs more documentation - it appears the setting to null is tied up with separate membership payments
1887 // but the circumstances are very confusing. Many of these conditions are repeated in the next conditional
1888 // so we should merge them together
1889 // the quick config seems like a red-herring - if this is about a separate membership payment then there
1890 // are 2 types of line items - membership ones & non-membership ones - regardless of whether quick config is set
1892 CRM_Utils_Array
::value('is_separate_payment', $this->_membershipBlock
)
1893 && !empty($this->_values
['fee'][$priceField->id
])
1894 && ($this->_values
['fee'][$priceField->id
]['name'] == "other_amount")
1895 && CRM_Utils_Array
::value("price_{$paramWeDoNotUnderstand}", $this->_params
) < 1
1896 && empty($this->_params
["price_{$priceField->id}"])
1898 $this->_params
['amount'] = null;
1901 // Fix for CRM-14375 - If we are using separate payments and "no
1902 // thank you" is selected for the additional contribution, set
1903 // contribution amount to be null, so that it will not show
1904 // contribution amount same as membership amount.
1905 //@todo - merge with section above
1906 if ($this->_membershipBlock
['is_separate_payment']
1907 && !empty($this->_values
['fee'][$priceField->id
])
1908 && CRM_Utils_Array
::value('name', $this->_values
['fee'][$priceField->id
]) == 'contribution_amount'
1909 && CRM_Utils_Array
::value("price_{$priceField->id}", $this->_params
) == '-1'
1911 $this->_params
['amount'] = null;
1917 * @param array $params
1919 * @throws CiviCRM_API3_Exception
1921 static function submit($params) {
1922 $form = new CRM_Contribute_Form_Contribution_Confirm();
1923 $form->_id
= $params['id'];
1924 if (!empty($params['contact_id'])) {
1925 $form->_contactID
= $params['contact_id'];
1927 CRM_Contribute_BAO_ContributionPage
::setValues($form->_id
, $form->_values
);
1928 $form->_separateMembershipPayment
= CRM_Contribute_BAO_ContributionPage
::getIsMembershipPayment($form->_id
);
1929 //this way the mocked up controller ignores the session stuff
1930 $_SERVER['REQUEST_METHOD'] = 'GET';
1931 $form->controller
= new CRM_Contribute_Controller_Contribution();
1932 $params['invoiceID'] = md5(uniqid(rand(), TRUE));
1933 $paramsProcessedForForm = $form->_params
= self
::getFormParams($params['id'], $params);
1934 $form->_amount
= $params['amount'];
1935 $priceSetID = $form->_params
['priceSetId'] = $paramsProcessedForForm['price_set_id'];
1936 $priceFields = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetID);
1937 $priceSetFields = reset($priceFields);
1938 $form->_values
['fee'] = $priceSetFields['fields'];
1939 $form->_priceSetId
= $priceSetID;
1940 $form->setFormAmountFields($priceSetID);
1941 if (!empty($params['payment_processor'])) {
1942 $form->_paymentProcessor
= civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor']));
1943 if ($form->_paymentProcessor
['billing_mode'] ==1) {
1944 $form->_contributeMode
= 'direct';
1947 $form->_contributeMode
= 'notify';
1951 $form->_params
['payment_processor'] = 0;
1953 $priceFields = $priceFields[$priceSetID]['fields'];
1954 CRM_Price_BAO_PriceSet
::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution');
1955 $form->_lineItem
= array($priceSetID => $lineItems);
1956 $form->postProcess();
1960 * Helper function for static submit function - set relevant params - help us to build up an array that we can pass in
1962 * @param array $params
1965 * @throws CiviCRM_API3_Exception
1967 static function getFormParams($id, array $params) {
1968 if(!isset($params['is_pay_later'])) {
1969 if (!empty($params['payment_processor'])) {
1970 $params['is_pay_later'] = 0;
1973 $params['is_pay_later'] = civicrm_api3('contribution_page', 'getvalue', array(
1975 'return' => 'is_pay_later'
1979 if(empty($params['price_set_id'])) {
1980 $params['price_set_id'] = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $params['id']);