CRM-16357 (Back office contribution page) don't take ignored parameter as a reference
[civicrm-core.git] / CRM / Contribute / Form / Contribution / Confirm.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * form to process actions on the group aspect of Custom Data
38 */
39class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_ContributionBase {
40
41 /**
fe482240 42 * The id of the contact associated with this contribution.
6a488035
TO
43 *
44 * @var int
6a488035
TO
45 */
46 public $_contactID;
47
1f1740fe
DL
48
49 /**
fe482240 50 * The id of the contribution object that is created when the form is submitted.
1f1740fe
DL
51 *
52 * @var int
1f1740fe
DL
53 */
54 public $_contributionID;
55
c8bde7ea 56 /**
fe482240 57 * Set the parameters to be passed to contribution create function.
c8bde7ea
EM
58 *
59 * @param array $params
014c4014 60 * @param int $contactID
100fef9d 61 * @param int $financialTypeID
c8bde7ea 62 * @param $online
100fef9d 63 * @param int $contributionPageId
c8bde7ea 64 * @param $nonDeductibleAmount
100fef9d 65 * @param int $campaignId
c8bde7ea 66 * @param $isMonetary
c8bde7ea
EM
67 * @param $pending
68 * @param $paymentProcessorOutcome
69 * @param $receiptDate
100fef9d 70 * @param int $recurringContributionID
c8bde7ea 71 * @param $isTest
100fef9d
CW
72 * @param int $addressID
73 * @param int $softCreditToID
74 * @param array $lineItems
c8bde7ea 75 *
c8bde7ea
EM
76 * @return array
77 */
a13f3d8c
TO
78 public static function getContributionParams(
79 $params, $contactID, $financialTypeID, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending,
80 $paymentProcessorOutcome, $receiptDate, $recurringContributionID, $isTest, $addressID, $softCreditToID, $lineItems) {
c8bde7ea
EM
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'],
17ab42dd 88 'tax_amount' => CRM_Utils_Array::value('tax_amount', $params),
c8bde7ea
EM
89 'amount_level' => CRM_Utils_Array::value('amount_level', $params),
90 'invoice_id' => $params['invoiceID'],
91 'currency' => $params['currencyID'],
a1a2a83d 92 'source' => (!$online || !empty($params['source'])) ? CRM_Utils_Array::value('source', $params) : CRM_Utils_Array::value('description', $params),
c8bde7ea
EM
93 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
94 //configure cancel reason, cancel date and thankyou date
95 //from 'contribution' type profile if included
96 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0),
a1a2a83d
TO
97 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL,
98 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL,
c8bde7ea
EM
99 'campaign_id' => $campaignId,
100 'is_test' => $isTest,
101 'address_id' => $addressID,
102 //setting to make available to hook - although seems wrong to set on form for BAO hook availability
103 'soft_credit_to' => $softCreditToID,
b205ce09 104 'line_item' => $lineItems,
21dfd5f5 105 'skipLineItem' => CRM_Utils_Array::value('skipLineItem', $params, 0),
c8bde7ea
EM
106 );
107 if (!$online && isset($params['thankyou_date'])) {
108 $contributionParam['thankyou_date'] = $params['thankyou_date'];
109 }
110 if (!$online || $isMonetary) {
111 if (empty($params['is_pay_later'])) {
112 $contributionParams['payment_instrument_id'] = 1;
113 }
114 }
a7a33651
EM
115 if ($paymentProcessorOutcome) {
116 $contributionParams['payment_processor'] = CRM_Utils_Array::value('payment_processor', $paymentProcessorOutcome);
117 }
c8bde7ea
EM
118 if (!$pending && $paymentProcessorOutcome) {
119 $contributionParams += array(
120 'fee_amount' => CRM_Utils_Array::value('fee_amount', $paymentProcessorOutcome),
121 'net_amount' => CRM_Utils_Array::value('net_amount', $paymentProcessorOutcome, $params['amount']),
122 'trxn_id' => $paymentProcessorOutcome['trxn_id'],
123 'receipt_date' => $receiptDate,
124 // also add financial_trxn details as part of fix for CRM-4724
125 'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $paymentProcessorOutcome),
c8bde7ea
EM
126 );
127 }
128
129 // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
130 $contributionParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contributionParams['non_deductible_amount'], ' '));
131 $contributionParams['total_amount'] = trim(CRM_Utils_Money::format($contributionParams['total_amount'], ' '));
132
133 if ($recurringContributionID) {
134 $contributionParams['contribution_recur_id'] = $recurringContributionID;
135 }
136
137 $contributionParams['contribution_status_id'] = $pending ? 2 : 1;
138 if (isset($contributionParams['invoice_id'])) {
139 $contributionParams['id'] = CRM_Core_DAO::getFieldValue(
140 'CRM_Contribute_DAO_Contribution',
141 $contributionParams['invoice_id'],
142 'id',
143 'invoice_id'
144 );
145 }
146
147 return $contributionParams;
148 }
149
6a488035 150 /**
fe482240 151 * Set variables up before form is built.
6a488035
TO
152 *
153 * @return void
6a488035
TO
154 */
155 public function preProcess() {
156 $config = CRM_Core_Config::singleton();
157 parent::preProcess();
cde484fd 158
6a488035
TO
159 // lineItem isn't set until Register postProcess
160 $this->_lineItem = $this->get('lineItem');
161 $this->_paymentProcessor = $this->get('paymentProcessor');
cde484fd 162
6a488035
TO
163 if ($this->_contributeMode == 'express') {
164 // rfp == redirect from paypal
165 $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean',
166 CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'
167 );
168 if ($rfp) {
169 $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
170 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
171
ebf695c3 172 $this->_params['payer'] = CRM_Utils_Array::value('payer', $expressParams);
6a488035
TO
173 $this->_params['payer_id'] = $expressParams['payer_id'];
174 $this->_params['payer_status'] = $expressParams['payer_status'];
175
176 CRM_Core_Payment_Form::mapParams($this->_bltID, $expressParams, $this->_params, FALSE);
cde484fd 177
6a488035 178 // fix state and country id if present
f0bf6c15 179 if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) {
6a488035
TO
180 $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
181 }
182 if (!empty($this->_params["billing_country_id-{$this->_bltID}"]) && $this->_params["billing_country_id-{$this->_bltID}"]) {
183 $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
184 }
185
186 // set a few other parameters for PayPal
187 $this->_params['token'] = $this->get('token');
188
189 $this->_params['amount'] = $this->get('amount');
190
a13f3d8c 191 if (!empty($this->_membershipBlock)) {
6a488035
TO
192 $this->_params['selectMembership'] = $this->get('selectMembership');
193 }
194 // we use this here to incorporate any changes made by folks in hooks
195 $this->_params['currencyID'] = $config->defaultCurrency;
196
197 $this->_params['payment_action'] = 'Sale';
198
199 // also merge all the other values from the profile fields
200 $values = $this->controller->exportValues('Main');
201 $skipFields = array(
a13f3d8c
TO
202 'amount',
203 'amount_other',
6a488035
TO
204 "billing_street_address-{$this->_bltID}",
205 "billing_city-{$this->_bltID}",
206 "billing_state_province_id-{$this->_bltID}",
207 "billing_postal_code-{$this->_bltID}",
208 "billing_country_id-{$this->_bltID}",
209 );
210 foreach ($values as $name => $value) {
211 // skip amount field
212 if (!in_array($name, $skipFields)) {
213 $this->_params[$name] = $value;
214 }
215 }
216 $this->set('getExpressCheckoutDetails', $this->_params);
217 }
218 else {
219 $this->_params = $this->get('getExpressCheckoutDetails');
220 }
221 }
222 else {
223 $this->_params = $this->controller->exportValues('Main');
224
225 if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) {
226 $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
227 }
228 if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) {
229 $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
230 }
231
232 if (isset($this->_params['credit_card_exp_date'])) {
233 $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
234 $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
235 }
5df36634
PJ
236
237 $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
6a488035 238 $this->_params['amount'] = $this->get('amount');
d91b8b33 239 $this->_params['tax_amount'] = $this->get('tax_amount');
6a488035
TO
240
241 $this->_useForMember = $this->get('useForMember');
cde484fd 242
6a488035 243 if (isset($this->_params['amount'])) {
df6c4f28 244 $this->setFormAmountFields($this->_params['priceSetId']);
6a488035
TO
245 }
246 $this->_params['currencyID'] = $config->defaultCurrency;
247 $this->_params['payment_action'] = 'Sale';
248 }
249
250 $this->_params['is_pay_later'] = $this->get('is_pay_later');
251 $this->assign('is_pay_later', $this->_params['is_pay_later']);
252 if ($this->_params['is_pay_later']) {
253 $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
254 }
255 // if onbehalf-of-organization
a7488080 256 if (!empty($this->_params['hidden_onbehalf_profile'])) {
c8fa0a31 257 // CRM-15182
258 if (empty($this->_params['org_option']) && empty($this->_params['organization_id'])) {
a7488080 259 if (!empty($this->_params['onbehalfof_id'])) {
6a488035
TO
260 $this->_params['organization_id'] = $this->_params['onbehalfof_id'];
261 }
c8fa0a31 262 else {
263 $this->_params['organization_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_params['onbehalf']['organization_name'], 'id', 'display_name');
264 }
6a488035
TO
265 }
266
267 $this->_params['organization_name'] = $this->_params['onbehalf']['organization_name'];
268 $addressBlocks = array(
a13f3d8c
TO
269 'street_address',
270 'city',
271 'state_province',
272 'postal_code',
273 'country',
274 'supplemental_address_1',
275 'supplemental_address_2',
276 'supplemental_address_3',
277 'postal_code_suffix',
278 'geo_code_1',
279 'geo_code_2',
280 'address_name',
6a488035
TO
281 );
282
283 $blocks = array('email', 'phone', 'im', 'url', 'openid');
284 foreach ($this->_params['onbehalf'] as $loc => $value) {
285 $field = $typeId = NULL;
286 if (strstr($loc, '-')) {
287 list($field, $locType) = explode('-', $loc);
288 }
289
290 if (in_array($field, $addressBlocks)) {
291 if ($locType == 'Primary') {
292 $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
293 $locType = $defaultLocationType->id;
cde484fd
DL
294 }
295
6a488035
TO
296 if ($field == 'country') {
297 $value = CRM_Core_PseudoConstant::countryIsoCode($value);
298 }
299 elseif ($field == 'state_province') {
300 $value = CRM_Core_PseudoConstant::stateProvinceAbbreviation($value);
301 }
cde484fd 302
6a488035
TO
303 $isPrimary = 1;
304 if (isset($this->_params['onbehalf_location']['address'])
a13f3d8c
TO
305 && count($this->_params['onbehalf_location']['address']) > 0
306 ) {
6a488035
TO
307 $isPrimary = 0;
308 }
cde484fd 309
6a488035 310 $this->_params['onbehalf_location']['address'][$locType][$field] = $value;
a7488080 311 if (empty($this->_params['onbehalf_location']['address'][$locType]['is_primary'])) {
6a488035 312 $this->_params['onbehalf_location']['address'][$locType]['is_primary'] = $isPrimary;
a13f3d8c 313 }
6a488035
TO
314 $this->_params['onbehalf_location']['address'][$locType]['location_type_id'] = $locType;
315 }
316 elseif (in_array($field, $blocks)) {
317 if (!$typeId || is_numeric($typeId)) {
a13f3d8c
TO
318 $blockName = $fieldName = $field;
319 $locationType = 'location_type_id';
320 if ($locType == 'Primary') {
6a488035
TO
321 $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
322 $locationValue = $defaultLocationType->id;
323 }
324 else {
325 $locationValue = $locType;
326 }
a13f3d8c 327 $locTypeId = '';
6a488035
TO
328 $phoneExtField = array();
329
330 if ($field == 'url') {
a13f3d8c 331 $blockName = 'website';
887e764d
PN
332 $locationType = 'website_type_id';
333 list($field, $locationValue) = explode('-', $loc);
6a488035
TO
334 }
335 elseif ($field == 'im') {
336 $fieldName = 'name';
337 $locTypeId = 'provider_id';
a13f3d8c 338 $typeId = $this->_params['onbehalf']["{$loc}-provider_id"];
6a488035
TO
339 }
340 elseif ($field == 'phone') {
341 list($field, $locType, $typeId) = explode('-', $loc);
342 $locTypeId = 'phone_type_id';
343
344 //check if extension field exists
a13f3d8c 345 $extField = str_replace('phone', 'phone_ext', $loc);
6a488035
TO
346 if (isset($this->_params['onbehalf'][$extField])) {
347 $phoneExtField = array('phone_ext' => $this->_params['onbehalf'][$extField]);
348 }
349 }
350
351 $isPrimary = 1;
a13f3d8c
TO
352 if (isset ($this->_params['onbehalf_location'][$blockName])
353 && count($this->_params['onbehalf_location'][$blockName]) > 0
354 ) {
355 $isPrimary = 0;
6a488035
TO
356 }
357 if ($locationValue) {
358 $blockValues = array(
a13f3d8c 359 $fieldName => $value,
6a488035 360 $locationType => $locationValue,
a13f3d8c 361 'is_primary' => $isPrimary,
6a488035
TO
362 );
363
364 if ($locTypeId) {
a13f3d8c 365 $blockValues = array_merge($blockValues, array($locTypeId => $typeId));
6a488035
TO
366 }
367 if (!empty($phoneExtField)) {
368 $blockValues = array_merge($blockValues, $phoneExtField);
369 }
370
371 $this->_params['onbehalf_location'][$blockName][] = $blockValues;
372 }
373 }
374 }
375 elseif (strstr($loc, 'custom')) {
376 if ($value && isset($this->_params['onbehalf']["{$loc}_id"])) {
377 $value = $this->_params['onbehalf']["{$loc}_id"];
378 }
379 $this->_params['onbehalf_location']["{$loc}"] = $value;
380 }
381 else {
382 if ($loc == 'contact_sub_type') {
383 $this->_params['onbehalf_location'][$loc] = $value;
384 }
385 else {
386 $this->_params['onbehalf_location'][$field] = $value;
387 }
388 }
389 }
390 }
a7488080 391 elseif (!empty($this->_values['is_for_organization'])) {
6a488035
TO
392 // no on behalf of an organization, CRM-5519
393 // so reset loc blocks from main params.
394 foreach (array(
a13f3d8c
TO
395 'phone',
396 'email',
21dfd5f5 397 'address',
a13f3d8c 398 ) as $blk) {
6a488035
TO
399 if (isset($this->_params[$blk])) {
400 unset($this->_params[$blk]);
401 }
402 }
403 }
404
405 // if auto renew checkbox is set, initiate a open-ended recurring membership
8cc574cf 406 if ((!empty($this->_params['selectMembership']) || !empty($this->_params['priceSetId'])) && !empty($this->_paymentProcessor['is_recur']) &&
a13f3d8c
TO
407 CRM_Utils_Array::value('auto_renew', $this->_params) && empty($this->_params['is_recur']) && empty($this->_params['frequency_interval'])
408 ) {
6a488035
TO
409
410 $this->_params['is_recur'] = $this->_values['is_recur'] = 1;
411 // check if price set is not quick config
d80f2618 412 if (!empty($this->_params['priceSetId']) && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config')) {
9da8dc8c 413 list($this->_params['frequency_interval'], $this->_params['frequency_unit']) = CRM_Price_BAO_PriceSet::getRecurDetails($this->_params['priceSetId']);
6a488035
TO
414 }
415 else {
416 // FIXME: set interval and unit based on selected membership type
417 $this->_params['frequency_interval'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
418 $this->_params['selectMembership'], 'duration_interval'
419 );
420 $this->_params['frequency_unit'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
421 $this->_params['selectMembership'], 'duration_unit'
422 );
423 }
424 }
425
426 if ($this->_pcpId) {
427 $params = $this->processPcp($this, $this->_params);
428 $this->_params = $params;
429 }
430 $this->_params['invoiceID'] = $this->get('invoiceID');
431
432 //carry campaign from profile.
433 if (array_key_exists('contribution_campaign_id', $this->_params)) {
434 $this->_params['campaign_id'] = $this->_params['contribution_campaign_id'];
435 }
436
569df8ec
DG
437 // assign contribution page id to the template so we can add css class for it
438 $this->assign('contributionPageID', $this->_id);
439
6a488035
TO
440 $this->set('params', $this->_params);
441 }
442
443 /**
fe482240 444 * Build the form object.
6a488035
TO
445 *
446 * @return void
6a488035
TO
447 */
448 public function buildQuickForm() {
449 $this->assignToTemplate();
450
451 $params = $this->_params;
6a488035 452 // make sure we have values for it
8af73472 453 if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) {
a13f3d8c 454 $honorName = NULL;
133e2c99 455 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
456
8af73472 457 $this->assign('honor_block_is_active', $this->_honor_block_is_active);
133e2c99 458 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
1421174e 459 CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
6a488035 460
133e2c99 461 $fieldTypes = array('Contact');
a13f3d8c 462 $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
133e2c99 463 $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
6a488035
TO
464 }
465 $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
466 $amount_block_is_active = $this->get('amount_block_is_active');
467 $this->assign('amount_block_is_active', $amount_block_is_active);
468
a13f3d8c 469 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
03b412ae
PB
470 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
471 if ($invoicing) {
472 $getTaxDetails = FALSE;
473 $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
474 foreach ($this->_lineItem as $key => $value) {
475 foreach ($value as $v) {
476 if (isset($v['tax_rate'])) {
477 if ($v['tax_rate'] != '') {
478 $getTaxDetails = TRUE;
479 }
480 }
481 }
482 }
483 $this->assign('getTaxDetails', $getTaxDetails);
484 $this->assign('taxTerm', $taxTerm);
485 $this->assign('totalTaxAmount', $params['tax_amount']);
486 }
a7488080 487 if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
6a488035
TO
488 $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
489 $productID = $params['selectProduct'];
490 CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE,
491 $productID, $option
492 );
493 $this->set('productID', $productID);
494 $this->set('option', $option);
495 }
496 $config = CRM_Core_Config::singleton();
497 if (in_array('CiviMember', $config->enableComponents)) {
498 if (isset($params['selectMembership']) &&
499 $params['selectMembership'] != 'no_thanks'
500 ) {
501 CRM_Member_BAO_Membership::buildMembershipBlock($this,
502 $this->_id,
5b757295 503 $this->_membershipContactID,
6a488035
TO
504 FALSE,
505 $params['selectMembership'],
5b757295 506 FALSE
6a488035
TO
507 );
508 }
509 else {
510 $this->assign('membershipBlock', FALSE);
511 }
512 }
513 $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
514 $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
515
a7488080 516 if (!empty($params['hidden_onbehalf_profile'])) {
6a488035
TO
517 $ufJoinParams = array(
518 'module' => 'onBehalf',
519 'entity_table' => 'civicrm_contribution_page',
520 'entity_id' => $this->_id,
521 );
522 $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
523 $profileId = $OnBehalfProfile[0];
524
a13f3d8c 525 $fieldTypes = array('Contact', 'Organization');
6a488035 526 $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
a13f3d8c 527 $fieldTypes = array_merge($fieldTypes, $contactSubType);
6a488035
TO
528 if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
529 $fieldTypes = array_merge($fieldTypes, array('Membership'));
530 }
531 else {
532 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
533 }
534
133e2c99 535 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
6a488035
TO
536 }
537
538 $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
539 $this->assign('is_separate_payment', $this->_separateMembershipPayment);
9da8dc8c 540 if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
6a488035 541 $this->assign('lineItem', $this->_lineItem);
a13f3d8c
TO
542 }
543 else {
6a488035
TO
544 $this->assign('is_quick_config', 1);
545 $this->_params['is_quick_config'] = 1;
546 }
547 $this->assign('priceSetID', $this->_priceSetId);
a13f3d8c 548 $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name');
f92fc7eb
CW
549 if ($this->_paymentProcessor &&
550 $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType)
6a488035
TO
551 && !$this->_params['is_pay_later'] && !($this->_amount == 0)
552 ) {
553 $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
554 $this->add('image',
555 $this->_checkoutButtonName,
556 $this->_paymentProcessor['url_button'],
97e557d7 557 array('class' => 'crm-form-submit')
6a488035
TO
558 );
559
560 $this->addButtons(array(
561 array(
562 'type' => 'back',
f212d37d 563 'name' => ts('Go Back'),
6a488035
TO
564 ),
565 )
566 );
567 }
568 else {
569 if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] ||
570 $this->_amount <= 0.0 || $this->_params['is_pay_later'] ||
571 ($this->_separateMembershipPayment && $this->_amount <= 0.0)
572 ) {
f212d37d 573 $contribButton = ts('Continue');
6a488035
TO
574 $this->assign('button', ts('Continue'));
575 }
576 else {
577 $contribButton = ts('Make Contribution');
578 $this->assign('button', ts('Make Contribution'));
579 }
580 $this->addButtons(array(
581 array(
582 'type' => 'next',
583 'name' => $contribButton,
584 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
585 'isDefault' => TRUE,
c6edd786 586 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"),
6a488035
TO
587 ),
588 array(
589 'type' => 'back',
590 'name' => ts('Go Back'),
591 ),
592 )
593 );
594 }
595
596 $defaults = array();
9c80939e 597 $fields = array_fill_keys(array_keys($this->_fields), 1);
6a488035
TO
598 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
599
600 $contact = $this->_params;
601 foreach ($fields as $name => $dontCare) {
9c80939e
CW
602 // Recursively set defaults for nested fields
603 if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' || $name == 'honor')) {
604 foreach ($contact[$name] as $fieldName => $fieldValue) {
a13f3d8c
TO
605 if (is_array($fieldValue) && !in_array($this->_fields[$name][$fieldName]['html_type'], array(
606 'Multi-Select',
21dfd5f5 607 'AdvMulti-Select',
a13f3d8c
TO
608 ))
609 ) {
38b95e0f 610 foreach ($fieldValue as $key => $value) {
611 $defaults["{$name}[{$fieldName}][{$key}]"] = $value;
612 }
613 }
614 else {
615 $defaults["{$name}[{$fieldName}]"] = $fieldValue;
616 }
9c80939e
CW
617 }
618 }
619 elseif (isset($contact[$name])) {
6a488035
TO
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];
625 }
626 if (isset($contact["{$name}_id"])) {
627 $defaults["{$name}_id"] = $contact["{$name}_id"];
628 }
629 }
a13f3d8c
TO
630 elseif (in_array($name, array(
631 'addressee',
632 'email_greeting',
21dfd5f5 633 'postal_greeting',
a13f3d8c
TO
634 )) && !empty($contact[$name . '_custom'])
635 ) {
6a488035
TO
636 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
637 }
638 }
639 }
640
641 $this->assign('useForMember', $this->get('useForMember'));
642
6a488035
TO
643 $this->setDefaults($defaults);
644
645 $this->freeze();
646 }
647
648 /**
100fef9d 649 * Overwrite action, since we are only showing elements in frozen mode
6a488035
TO
650 * no help display needed
651 *
652 * @return int
6a488035 653 */
00be9182 654 public function getAction() {
6a488035
TO
655 if ($this->_action & CRM_Core_Action::PREVIEW) {
656 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
657 }
658 else {
659 return CRM_Core_Action::VIEW;
660 }
661 }
662
663 /**
5e4f7f74 664 * Set default values for the form.
6a488035 665 *
5e4f7f74
EM
666 * Note that in edit/view mode
667 * the default values are retrieved from the database
6a488035
TO
668 *
669 * @return void
670 */
a13f3d8c
TO
671 public function setDefaultValues() {
672 }
6a488035
TO
673
674 /**
fe482240 675 * Process the form.
6a488035
TO
676 *
677 * @return void
6a488035
TO
678 */
679 public function postProcess() {
da8d9879 680 $contactID = $this->getContactID();
cc789d46 681 $isPayLater = $this->_params['is_pay_later'];
4da07767 682 if (isset($this->_params['payment_processor']) && $this->_params['payment_processor'] == 0) {
cc789d46
EM
683 $this->_params['is_pay_later'] = $isPayLater = TRUE;
684 }
6a488035
TO
685 // add a description field at the very beginning
686 $this->_params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
687
688 // also add accounting code
689 $this->_params['accountingCode'] = CRM_Utils_Array::value('accountingCode',
690 $this->_values
691 );
692
693 // fix currency ID
dbddfb08 694 $this->_params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency;
6a488035 695
6a488035
TO
696 //carry payment processor id.
697 if ($paymentProcessorId = CRM_Utils_Array::value('id', $this->_paymentProcessor)) {
698 $this->_params['payment_processor_id'] = $paymentProcessorId;
6a488035 699 }
a7488080 700 if (!empty($params['image_URL'])) {
6a488035
TO
701 CRM_Contact_BAO_Contact::processImageParams($params);
702 }
e9599dfa 703 $premiumParams = $membershipParams = $params = $this->_params;
99fffb1f 704 $fields = array('email-Primary' => 1);
6a488035
TO
705
706 // get the add to groups
707 $addToGroups = array();
708
709 // now set the values for the billing location.
710 foreach ($this->_fields as $name => $value) {
711 $fields[$name] = 1;
712
713 // get the add to groups for uf fields
a7488080 714 if (!empty($value['add_to_group_id'])) {
6a488035
TO
715 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
716 }
717 }
718
719 if (!array_key_exists('first_name', $fields)) {
720 $nameFields = array('first_name', 'middle_name', 'last_name');
721 foreach ($nameFields as $name) {
722 $fields[$name] = 1;
723 if (array_key_exists("billing_$name", $params)) {
724 $params[$name] = $params["billing_{$name}"];
725 $params['preserveDBName'] = TRUE;
726 }
727 }
728 }
729
730 // billing email address
731 $fields["email-{$this->_bltID}"] = 1;
732
733 //unset the billing parameters if it is pay later mode
734 //to avoid creation of billing location
cc789d46 735 if ($isPayLater && !$this->_isBillingAddressRequiredForPayLater) {
6a488035
TO
736 $billingFields = array(
737 'billing_first_name',
738 'billing_middle_name',
739 'billing_last_name',
740 "billing_street_address-{$this->_bltID}",
741 "billing_city-{$this->_bltID}",
742 "billing_state_province-{$this->_bltID}",
743 "billing_state_province_id-{$this->_bltID}",
744 "billing_postal_code-{$this->_bltID}",
745 "billing_country-{$this->_bltID}",
746 "billing_country_id-{$this->_bltID}",
747 );
748
749 foreach ($billingFields as $value) {
750 unset($params[$value]);
751 unset($fields[$value]);
752 }
753 }
754
755 // if onbehalf-of-organization contribution, take out
756 // organization params in a separate variable, to make sure
757 // normal behavior is continued. And use that variable to
758 // process on-behalf-of functionality.
a7488080 759 if (!empty($this->_params['hidden_onbehalf_profile'])) {
6a488035
TO
760 $behalfOrganization = array();
761 $orgFields = array('organization_name', 'organization_id', 'org_option');
762 foreach ($orgFields as $fld) {
763 if (array_key_exists($fld, $params)) {
764 $behalfOrganization[$fld] = $params[$fld];
765 unset($params[$fld]);
766 }
767 }
768
769 if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) {
770 foreach ($params['onbehalf'] as $fld => $values) {
771 if (strstr($fld, 'custom_')) {
772 $behalfOrganization[$fld] = $values;
cde484fd 773 }
6a488035
TO
774 elseif (!(strstr($fld, '-'))) {
775 if (in_array($fld, array(
a13f3d8c 776 'contribution_campaign_id',
21dfd5f5 777 'member_campaign_id',
a13f3d8c 778 ))) {
6a488035
TO
779 $fld = 'campaign_id';
780 }
781 else {
782 $behalfOrganization[$fld] = $values;
cde484fd 783 }
6a488035
TO
784 $this->_params[$fld] = $values;
785 }
786 }
787 }
788
789 if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) {
790 foreach ($params['onbehalf_location'] as $block => $vals) {
791 //fix for custom data (of type checkbox, multi-select)
a13f3d8c 792 if (substr($block, 0, 7) == 'custom_') {
6a488035
TO
793 continue;
794 }
795 // fix the index of block elements
a13f3d8c
TO
796 if (is_array($vals)) {
797 foreach ($vals as $key => $val) {
6a488035
TO
798 //dont adjust the index of address block as
799 //it's index is WRT to location type
800 $newKey = ($block == 'address') ? $key : ++$key;
801 $behalfOrganization[$block][$newKey] = $val;
802 }
803 }
804 }
805 unset($params['onbehalf_location']);
806 }
a7488080 807 if (!empty($params['onbehalf[image_URL]'])) {
6a488035
TO
808 $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]'];
809 }
810 }
811
812 // check for profile double opt-in and get groups to be subscribed
813 $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
814
815 // since we are directly adding contact to group lets unset it from mailing
816 if (!empty($addToGroups)) {
817 foreach ($addToGroups as $groupId) {
818 if (isset($subscribeGroupIds[$groupId])) {
819 unset($subscribeGroupIds[$groupId]);
820 }
821 }
822 }
823
824 foreach ($addToGroups as $k) {
825 if (array_key_exists($k, $subscribeGroupIds)) {
826 unset($addToGroups[$k]);
827 }
828 }
829
da8d9879 830 if (empty($contactID)) {
6a488035 831 $dupeParams = $params;
a7488080 832 if (!empty($dupeParams['onbehalf'])) {
6a488035
TO
833 unset($dupeParams['onbehalf']);
834 }
5cc5ea9f 835 if (!empty($dupeParams['honor'])) {
836 unset($dupeParams['honor']);
837 }
6a488035
TO
838
839 $dedupeParams = CRM_Dedupe_Finder::formatParams($dupeParams, 'Individual');
840 $dedupeParams['check_permission'] = FALSE;
841 $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
842
843 // if we find more than one contact, use the first one
99fffb1f 844 $contactID = CRM_Utils_Array::value(0, $ids);
6a488035
TO
845
846 // Fetch default greeting id's if creating a contact
99fffb1f 847 if (!$contactID) {
6a488035
TO
848 foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
849 if (!isset($params[$greeting])) {
850 $params[$greeting] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting);
851 }
852 }
853 }
99fffb1f 854 $contactType = NULL;
6a488035
TO
855 }
856 else {
99fffb1f 857 $contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
6a488035 858 }
99fffb1f
EM
859 $contactID = CRM_Contact_BAO_Contact::createProfileContact(
860 $params,
861 $fields,
862 $contactID,
863 $addToGroups,
864 NULL,
865 $contactType,
866 TRUE
867 );
6a488035
TO
868
869 // Make the contact ID associated with the contribution available at the Class level.
870 // Also make available to the session.
596bff78 871 //@todo consider handling this in $this->getContactID();
6a488035
TO
872 $this->set('contactID', $contactID);
873 $this->_contactID = $contactID;
874
875 //get email primary first if exist
b288b9c2
EM
876 $subscriptionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
877 if (!$subscriptionEmail['email']) {
878 $subscriptionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params);
6a488035
TO
879 }
880 // subscribing contact to groups
b288b9c2
EM
881 if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) {
882 CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID);
6a488035
TO
883 }
884
885 // If onbehalf-of-organization contribution / signup, add organization
886 // and it's location.
887 if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) {
888 $ufFields = array();
889 foreach ($this->_fields['onbehalf'] as $name => $value) {
890 $ufFields[$name] = 1;
891 }
892 self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values,
893 $this->_params, $ufFields
894 );
a13f3d8c 895 }
4c9b6178 896 elseif (!empty($this->_membershipContactID) && $contactID != $this->_membershipContactID) {
51fa20cb 897 // this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household,
51e89def
DS
898 // store current user id as related contact for later use for mailing / activity..
899 $this->_values['related_contact'] = $contactID;
900 $this->_params['related_contact'] = $contactID;
901 // swap contact like we do for on-behalf-org case, so parent/primary membership is affected
902 $contactID = $this->_membershipContactID;
903 }
904
6a488035
TO
905 // lets store the contactID in the session
906 // for things like tell a friend
907 $session = CRM_Core_Session::singleton();
908 if (!$session->get('userID')) {
909 $session->set('transaction.userID', $contactID);
910 }
911 else {
912 $session->set('transaction.userID', NULL);
913 }
914
915 $this->_useForMember = $this->get('useForMember');
916
917 // store the fact that this is a membership and membership type is selected
918 $processMembership = FALSE;
8cc574cf 919 if ((!empty($membershipParams['selectMembership']) &&
6a488035
TO
920 $membershipParams['selectMembership'] != 'no_thanks'
921 ) ||
922 $this->_useForMember
923 ) {
924 $processMembership = TRUE;
925
926 if (!$this->_useForMember) {
927 $this->assign('membership_assign', TRUE);
928 $this->set('membershipTypeID', $this->_params['selectMembership']);
929 }
930
931 if ($this->_action & CRM_Core_Action::PREVIEW) {
932 $membershipParams['is_test'] = 1;
933 }
934 if ($this->_params['is_pay_later']) {
935 $membershipParams['is_pay_later'] = 1;
936 }
937 }
938
939 if ($processMembership) {
940 CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, TRUE);
941
942 // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups
943 if (isset($this->_params['related_contact'])) {
944 $membershipParams['cms_contactID'] = $this->_params['related_contact'];
945 }
946 else {
947 $membershipParams['cms_contactID'] = $contactID;
948 }
949
f64a217a 950 //inherit campaign from contribution page.
6a488035
TO
951 if (!array_key_exists('campaign_id', $membershipParams)) {
952 $membershipParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
953 }
954
955 if (!empty($membershipParams['onbehalf']) &&
a13f3d8c
TO
956 is_array($membershipParams['onbehalf']) && !empty($membershipParams['onbehalf']['member_campaign_id'])
957 ) {
6a488035
TO
958 $this->_params['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
959 }
960
961 $customFieldsFormatted = $fieldTypes = array();
962 if (!empty($membershipParams['onbehalf']) &&
a13f3d8c
TO
963 is_array($membershipParams['onbehalf'])
964 ) {
6a488035
TO
965 foreach ($membershipParams['onbehalf'] as $key => $value) {
966 if (strstr($key, 'custom_')) {
967 $customFieldId = explode('_', $key);
968 CRM_Core_BAO_CustomField::formatCustomField(
969 $customFieldId[1],
970 $customFieldsFormatted,
971 $value,
972 'Membership',
973 NULL,
974 $contactID
975 );
976 }
977 }
978 $fieldTypes = array('Contact', 'Organization', 'Membership');
979 }
980
981 $priceFieldIds = $this->get('memberPriceFieldIDS');
982
983 if (!empty($priceFieldIds)) {
9da8dc8c 984 $contributionTypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceFieldIds['id'], 'financial_type_id');
6a488035
TO
985 unset($priceFieldIds['id']);
986 $membershipTypeIds = array();
987 $membershipTypeTerms = array();
988 foreach ($priceFieldIds as $priceFieldId) {
9da8dc8c 989 if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
6a488035 990 $membershipTypeIds[] = $id;
dbddfb08
EM
991 //@todo the value for $term is immediately overwritten. It is unclear from the code whether it was intentional to
992 // do this or a double = was intended (this ambiguity is the reason many IDEs complain about 'assignment in condition'
6a488035 993 $term = 1;
9da8dc8c 994 if ($term = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) {
6a488035
TO
995 $membershipTypeTerms[$id] = ($term > 1) ? $term : 1;
996 }
997 else {
998 $membershipTypeTerms[$id] = 1;
999 }
1000 }
1001 }
1002 $membershipParams['selectMembership'] = $membershipTypeIds;
9ce8bcfc 1003 $membershipParams['financial_type_id'] = $contributionTypeID;
6a488035
TO
1004 $membershipParams['types_terms'] = $membershipTypeTerms;
1005 }
a7488080 1006 if (!empty($membershipParams['selectMembership'])) {
9ce8bcfc 1007 // CRM-12233
5624f515 1008 $membershipLineItems = array();
9ce8bcfc
PN
1009 if ($this->_separateMembershipPayment && $this->_values['amount_block_is_active']) {
1010 foreach ($this->_values['fee'] as $key => $feeValues) {
a13f3d8c 1011 if ($feeValues['name'] == 'membership_amount') {
9ce8bcfc 1012 $fieldId = $this->_params['price_' . $key];
5624f515 1013 $membershipLineItems[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId];
9ce8bcfc
PN
1014 unset($this->_lineItem[$this->_priceSetId][$fieldId]);
1015 break;
1016 }
1017 }
1018 }
cc789d46 1019 $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater);
fa9d0451
EM
1020 if (!$this->_amount > 0.0 || !$membershipParams['amount']) {
1021 // we need to explicitly create a CMS user in case of free memberships
1022 // since it is done under processConfirm for paid memberships
1023 CRM_Contribute_BAO_Contribution_Utils::createCMSUser($membershipParams,
1024 $membershipParams['cms_contactID'],
1025 'email-' . $this->_bltID
1026 );
1027 }
9ce8bcfc 1028 }
6a488035
TO
1029 }
1030 else {
1031 // at this point we've created a contact and stored its address etc
1032 // all the payment processors expect the name and address to be in the
1033 // so we copy stuff over to first_name etc.
1034 $paymentParams = $this->_params;
157b21d8 1035 $contributionTypeId = $this->_values['financial_type_id'];
6a488035
TO
1036
1037 $fieldTypes = array();
1038 if (!empty($paymentParams['onbehalf']) &&
1039 is_array($paymentParams['onbehalf'])
1040 ) {
1041 foreach ($paymentParams['onbehalf'] as $key => $value) {
1042 if (strstr($key, 'custom_')) {
1043 $this->_params[$key] = $value;
1044 }
1045 }
1046 $fieldTypes = array('Contact', 'Organization', 'Contribution');
1047 }
cc789d46 1048 $financialTypeID = $this->wrangleFinancialTypeID($contributionTypeId);
6a488035
TO
1049
1050 CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams,
1051 $premiumParams, $contactID,
cc789d46 1052 $financialTypeID,
6a488035 1053 'contribution',
cc789d46
EM
1054 $fieldTypes,
1055 ($this->_mode == 'test') ? 1 : 0,
1056 $isPayLater
1057 );
1058 }
1059 }
1060
1061 /**
5e4f7f74
EM
1062 * Wrangle financial type ID.
1063 *
cc789d46
EM
1064 * 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
1065 * Pledges are not relevant to the membership code so that portion will not go onto the membership form.
1066 *
5e4f7f74
EM
1067 * Comments from previous refactor indicate doubt as to what was going on.
1068 *
100fef9d 1069 * @param int $contributionTypeId
cc789d46
EM
1070 *
1071 * @return null|string
1072 */
00be9182 1073 public function wrangleFinancialTypeID($contributionTypeId) {
cc789d46
EM
1074 if (isset($paymentParams['financial_type'])) {
1075 $contributionTypeId = $paymentParams['financial_type'];
1076 }
1077 elseif (!empty($this->_values['pledge_id'])) {
1078 $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge',
1079 $this->_values['pledge_id'],
1080 'financial_type_id'
6a488035
TO
1081 );
1082 }
cc789d46 1083 return $contributionTypeId;
6a488035
TO
1084 }
1085
1086 /**
5e4f7f74 1087 * Process the form.
6a488035 1088 *
100fef9d 1089 * @param array $premiumParams
cd6994fc 1090 * @param $contribution
6a488035
TO
1091 */
1092 public function postProcessPremium($premiumParams, $contribution) {
62c4420e 1093 $hour = $minute = $second = 0;
6a488035
TO
1094 // assigning Premium information to receipt tpl
1095 $selectProduct = CRM_Utils_Array::value('selectProduct', $premiumParams);
1096 if ($selectProduct &&
1097 $selectProduct != 'no_thanks'
1098 ) {
1099 $startDate = $endDate = "";
1100 $this->assign('selectPremium', TRUE);
1101 $productDAO = new CRM_Contribute_DAO_Product();
1102 $productDAO->id = $selectProduct;
1103 $productDAO->find(TRUE);
1104 $this->assign('product_name', $productDAO->name);
1105 $this->assign('price', $productDAO->price);
1106 $this->assign('sku', $productDAO->sku);
1107 $this->assign('option', CRM_Utils_Array::value('options_' . $premiumParams['selectProduct'], $premiumParams));
1108
1109 $periodType = $productDAO->period_type;
cde484fd 1110
6a488035
TO
1111 if ($periodType) {
1112 $fixed_period_start_day = $productDAO->fixed_period_start_day;
1113 $duration_unit = $productDAO->duration_unit;
1114 $duration_interval = $productDAO->duration_interval;
1115 if ($periodType == 'rolling') {
1116 $startDate = date('Y-m-d');
1117 }
1118 elseif ($periodType == 'fixed') {
1119 if ($fixed_period_start_day) {
a13f3d8c
TO
1120 $date = explode('-', date('Y-m-d'));
1121 $month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2);
d3e86119 1122 $day = substr($fixed_period_start_day, -2) . "<br/>";
a13f3d8c 1123 $year = $date[0];
6a488035
TO
1124 $startDate = $year . '-' . $month . '-' . $day;
1125 }
1126 else {
1127 $startDate = date('Y-m-d');
1128 }
1129 }
1130
a13f3d8c
TO
1131 $date = explode('-', $startDate);
1132 $year = $date[0];
6a488035 1133 $month = $date[1];
a13f3d8c 1134 $day = $date[2];
6a488035
TO
1135
1136 switch ($duration_unit) {
1137 case 'year':
1138 $year = $year + $duration_interval;
1139 break;
1140
1141 case 'month':
1142 $month = $month + $duration_interval;
1143 break;
1144
1145 case 'day':
1146 $day = $day + $duration_interval;
1147 break;
1148
1149 case 'week':
1150 $day = $day + ($duration_interval * 7);
1151 }
1152 $endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year));
1153 $this->assign('start_date', $startDate);
1154 $this->assign('end_date', $endDate);
1155 }
1156
a13f3d8c 1157 $dao = new CRM_Contribute_DAO_Premium();
6a488035 1158 $dao->entity_table = 'civicrm_contribution_page';
a13f3d8c 1159 $dao->entity_id = $this->_id;
6a488035
TO
1160 $dao->find(TRUE);
1161 $this->assign('contact_phone', $dao->premiums_contact_phone);
1162 $this->assign('contact_email', $dao->premiums_contact_email);
1163
1164 //create Premium record
1165 $params = array(
1166 'product_id' => $premiumParams['selectProduct'],
1167 'contribution_id' => $contribution->id,
1168 'product_option' => CRM_Utils_Array::value('options_' . $premiumParams['selectProduct'], $premiumParams),
1169 'quantity' => 1,
1170 'start_date' => CRM_Utils_Date::customFormat($startDate, '%Y%m%d'),
1171 'end_date' => CRM_Utils_Date::customFormat($endDate, '%Y%m%d'),
1172 );
a13f3d8c
TO
1173 if (!empty($premiumParams['selectProduct'])) {
1174 $daoPremiumsProduct = new CRM_Contribute_DAO_PremiumsProduct();
6a488035
TO
1175 $daoPremiumsProduct->product_id = $premiumParams['selectProduct'];
1176 $daoPremiumsProduct->premiums_id = $dao->id;
a13f3d8c 1177 $daoPremiumsProduct->find(TRUE);
6a488035
TO
1178 $params['financial_type_id'] = $daoPremiumsProduct->financial_type_id;
1179 }
1180 //Fixed For CRM-3901
1181 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1182 $daoContrProd->contribution_id = $contribution->id;
1183 if ($daoContrProd->find(TRUE)) {
1184 $params['id'] = $daoContrProd->id;
1185 }
cde484fd 1186
6a488035 1187 CRM_Contribute_BAO_Contribution::addPremium($params);
8cc574cf 1188 if ($productDAO->cost && !empty($params['financial_type_id'])) {
6a488035
TO
1189 $trxnParams = array(
1190 'cost' => $productDAO->cost,
1191 'currency' => $productDAO->currency,
1192 'financial_type_id' => $params['financial_type_id'],
21dfd5f5 1193 'contributionId' => $contribution->id,
6a488035
TO
1194 );
1195 CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($trxnParams);
1196 }
1197 }
1198 elseif ($selectProduct == 'no_thanks') {
1199 //Fixed For CRM-3901
1200 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1201 $daoContrProd->contribution_id = $contribution->id;
1202 if ($daoContrProd->find(TRUE)) {
1203 $daoContrProd->delete();
1204 }
1205 }
1206 }
1207
1208 /**
5e4f7f74 1209 * Process the contribution.
6a488035 1210 *
c490a46a 1211 * @param CRM_Core_Form $form
4ce4a928
EM
1212 * @param array $params
1213 * @param array $result
014c4014 1214 * @param int $contactID
a1a94e61 1215 * @param CRM_Financial_DAO_FinancialType $financialType
cd6994fc
E
1216 * @param bool $pending
1217 * @param bool $online
1218 *
a1a94e61
EM
1219 * @param bool $isTest
1220 * @param array $lineItems
1221 *
4ce4a928 1222 * @throws Exception
6a488035 1223 * @return CRM_Contribute_DAO_Contribution
6a488035 1224 */
2da40d21 1225 public static function processContribution(
1f1740fe 1226 &$form,
6a488035
TO
1227 $params,
1228 $result,
1229 $contactID,
637b4757 1230 $financialType,
4ce4a928 1231 $pending,
4bd318e0
EM
1232 $online,
1233 $isTest,
1234 $lineItems
6a488035
TO
1235 ) {
1236 $transaction = new CRM_Core_Transaction();
4625312e 1237 $contribSoftContactId = $addressID = NULL;
6a488035
TO
1238
1239 // add these values for the recurringContrib function ,CRM-10188
637b4757 1240 $params['financial_type_id'] = $financialType->id;
c8bde7ea
EM
1241
1242 //create an contribution address
5785931e 1243 if ($form->_contributeMode != 'notify' && empty($params['is_pay_later']) && !empty($form->_values['is_monetary'])) {
c8bde7ea
EM
1244 $addressID = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
1245 }
1246
e34dd94b 1247 //@todo - this is being set from the form to resolve CRM-10188 - an
1248 // eNotice caused by it not being set @ the front end
1249 // however, we then get it being over-written with null for backend contributions
1250 // a better fix would be to set the values in the respective forms rather than require
1251 // a function being shared by two forms to deal with their respective values
1252 // moving it to the BAO & not taking the $form as a param would make sense here.
a13f3d8c
TO
1253 if (!isset($params['is_email_receipt']) && !empty($form->_values['is_email_receipt'])) {
1254 $params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $form->_values);
e34dd94b 1255 }
637b4757 1256 $recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $financialType, $online);
6a488035 1257
6a488035
TO
1258 // CRM-11885
1259 // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it.
1260 if (isset($params['non_deductible_amount']) && (!empty($params['non_deductible_amount']))) {
1261 $nonDeductibleAmount = $params['non_deductible_amount'];
1262 }
1263 // if non_deductible_amount does NOT exist - then calculate it depending on:
1264 // $contributionType->is_deductible and whether there is a product (premium).
1265 else {
1266 //if ($contributionType->is_deductible && $deductibleMode) {
637b4757 1267 if ($financialType->is_deductible) {
6a488035
TO
1268 if ($online && isset($params['selectProduct'])) {
1269 $selectProduct = CRM_Utils_Array::value('selectProduct', $params);
1270 }
1271 if (!$online && isset($params['product_name'][0])) {
1272 $selectProduct = $params['product_name'][0];
1273 }
1274 // if there is a product - compare the value to the contribution amount
1275 if (isset($selectProduct) &&
1276 $selectProduct != 'no_thanks'
1277 ) {
1278 $productDAO = new CRM_Contribute_DAO_Product();
1279 $productDAO->id = $selectProduct;
1280 $productDAO->find(TRUE);
1281 // product value exceeds contribution amount
1282 if ($params['amount'] < $productDAO->price) {
1283 $nonDeductibleAmount = $params['amount'];
1284 }
1285 // product value does NOT exceed contribution amount
1286 else {
1287 $nonDeductibleAmount = $productDAO->price;
1288 }
1289 }
1290 // contribution is deductible - but there is no product
1291 else {
1292 $nonDeductibleAmount = '0.00';
1293 }
1294 }
1295 // contribution is NOT deductible
1296 else {
1297 $nonDeductibleAmount = $params['amount'];
1298 }
1299 }
1300
1301 $now = date('YmdHis');
1302 $receiptDate = CRM_Utils_Array::value('receipt_date', $params);
a7488080 1303 if (!empty($form->_values['is_email_receipt'])) {
6a488035
TO
1304 $receiptDate = $now;
1305 }
1306
1307 //get the contrib page id.
dbddfb08 1308 $contributionPageId = NULL;
6a488035
TO
1309 if ($online) {
1310 $contributionPageId = $form->_id;
1311 $campaignId = CRM_Utils_Array::value('campaign_id', $params);
1312 if (!array_key_exists('campaign_id', $params)) {
1313 $campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
1314 }
1315 }
1316 else {
1317 //also for offline we do support - CRM-7290
1318 $contributionPageId = CRM_Utils_Array::value('contribution_page_id', $params);
1319 $campaignId = CRM_Utils_Array::value('campaign_id', $params);
1320 }
1321
6a488035 1322 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
8cc574cf 1323 if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
6a488035 1324 // if its due to pcp
a7488080 1325 if (!empty($params['pcp_made_through_id'])) {
6a488035
TO
1326 $contribSoftContactId = CRM_Core_DAO::getFieldValue(
1327 'CRM_PCP_DAO_PCP',
1328 $params['pcp_made_through_id'],
1329 'contact_id'
1330 );
1331 }
1332 else {
1333 $contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
1334 }
1335
1336 // Pass these details onto with the contribution to make them
1337 // available at hook_post_process, CRM-8908
c8bde7ea 1338 $params['soft_credit_to'] = $contribSoftContactId;
6a488035
TO
1339 }
1340
92acf33d 1341 if (isset($params['amount'])) {
396e62d8 1342 $isMonetary = NULL;
1343 if (!empty($form->_values['is_monetary'])) {
1344 $isMonetary = $form->_values['is_monetary'];
1345 }
c8bde7ea 1346 $contribParams = self::getContributionParams(
a13f3d8c 1347 $params, $contactID, $financialType->id, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending, $result, $receiptDate,
c8bde7ea
EM
1348 $recurringContributionID, $isTest, $addressID, $contribSoftContactId, $lineItems
1349 );
1350 $contribution = CRM_Contribute_BAO_Contribution::add($contribParams);
24f81279 1351
a13f3d8c 1352 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
03b412ae
PB
1353 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
1354 if ($invoicing) {
1355 $totalTaxAmount = 0;
1356 $dataArray = array();
1357 foreach ($form->_lineItem as $lineItemKey => $lineItemValue) {
1358 foreach ($lineItemValue as $key => $value) {
1359 if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
1360 if (isset($dataArray[$value['tax_rate']])) {
1361 $dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
1362 }
1363 else {
1364 $dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
1365 }
79d001a2
PB
1366 }
1367 }
1368 }
03b412ae
PB
1369 $smarty = CRM_Core_Smarty::singleton();
1370 $smarty->assign('dataArray', $dataArray);
1371 $smarty->assign('totalTaxAmount', $params['tax_amount']);
79d001a2 1372 }
9879aeb8
DL
1373 if (is_a($contribution, 'CRM_Core_Error')) {
1374 $message = CRM_Core_Error::getMessages($contribution);
1375 CRM_Core_Error::fatal($message);
1376 }
1f1740fe
DL
1377
1378 // lets store it in the form variable so postProcess hook can get to this and use it
1379 $form->_contributionID = $contribution->id;
6a488035 1380 }
cde484fd 1381
1421174e 1382 //CRM-13981, processing honor contact into soft-credit contribution
1383 CRM_Contact_Form_ProfileContact::postProcess($form);
1384
6a488035
TO
1385 // process soft credit / pcp pages
1386 CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
cde484fd 1387
6a488035 1388 //handle pledge stuff.
8cc574cf
CW
1389 if (empty($form->_params['separate_membership_payment']) && !empty($form->_values['pledge_block_id']) &&
1390 (!empty($form->_params['is_pledge']) || !empty($form->_values['pledge_id']))
6a488035
TO
1391 ) {
1392
a7488080 1393 if (!empty($form->_values['pledge_id'])) {
6a488035
TO
1394
1395 //when user doing pledge payments.
1396 //update the schedule when payment(s) are made
1397 foreach ($form->_params['pledge_amount'] as $paymentId => $dontCare) {
1398 $scheduledAmount = CRM_Core_DAO::getFieldValue(
1399 'CRM_Pledge_DAO_PledgePayment',
1400 $paymentId,
1401 'scheduled_amount',
1402 'id'
1403 );
1404
1405 $pledgePaymentParams = array(
1406 'id' => $paymentId,
1407 'contribution_id' => $contribution->id,
1408 'status_id' => $contribution->contribution_status_id,
1409 'actual_amount' => $scheduledAmount,
1410 );
1411
6a488035
TO
1412 CRM_Pledge_BAO_PledgePayment::add($pledgePaymentParams);
1413 }
1414
1415 //update pledge status according to the new payment statuses
1416 CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($form->_values['pledge_id']);
1417 }
1418 else {
1419 //when user creating pledge record.
1420 $pledgeParams = array();
1421 $pledgeParams['contact_id'] = $contribution->contact_id;
1422 $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
1423 $pledgeParams['contribution_id'] = $contribution->id;
1424 $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
1425 $pledgeParams['financial_type_id'] = $contribution->financial_type_id;
1426 $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
1427 $pledgeParams['installments'] = $params['pledge_installments'];
1428 $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
1429 if ($pledgeParams['frequency_unit'] == 'month') {
1430 $pledgeParams['frequency_day'] = intval(date("d"));
1431 }
1432 else {
1433 $pledgeParams['frequency_day'] = 1;
1434 }
1435 $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
1436 $pledgeParams['status_id'] = $contribution->contribution_status_id;
1437 $pledgeParams['max_reminders'] = $form->_values['max_reminders'];
1438 $pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
1439 $pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
1440 $pledgeParams['is_test'] = $contribution->is_test;
1441 $pledgeParams['acknowledge_date'] = date('Ymd');
1442 $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
1443
1444 //inherit campaign from contirb page.
1445 $pledgeParams['campaign_id'] = $campaignId;
1446
1447 $pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
1448
1449 $form->_params['pledge_id'] = $pledge->id;
1450
1451 //send acknowledgment email. only when pledge is created
1452 if ($pledge->id) {
1453 //build params to send acknowledgment.
1454 $pledgeParams['id'] = $pledge->id;
1455 $pledgeParams['receipt_from_name'] = $form->_values['receipt_from_name'];
1456 $pledgeParams['receipt_from_email'] = $form->_values['receipt_from_email'];
1457
1458 //scheduled amount will be same as installment_amount.
1459 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
1460
1461 //get total pledge amount.
1462 $pledgeParams['total_pledge_amount'] = $pledge->amount;
1463
1464 CRM_Pledge_BAO_Pledge::sendAcknowledgment($form, $pledgeParams);
1465 }
1466 }
1467 }
1468
1469 if ($online && $contribution) {
1470 CRM_Core_BAO_CustomValueTable::postProcess($form->_params,
1471 CRM_Core_DAO::$_nullArray,
1472 'civicrm_contribution',
1473 $contribution->id,
1474 'Contribution'
1475 );
1476 }
1477 elseif ($contribution) {
1478 //handle custom data.
1479 $params['contribution_id'] = $contribution->id;
a7488080 1480 if (!empty($params['custom']) &&
6a488035
TO
1481 is_array($params['custom']) &&
1482 !is_a($contribution, 'CRM_Core_Error')
1483 ) {
1484 CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
1485 }
1486 }
1487 // Save note
1488 if ($contribution && !empty($params['contribution_note'])) {
1489 $noteParams = array(
1490 'entity_table' => 'civicrm_contribution',
1491 'note' => $params['contribution_note'],
1492 'entity_id' => $contribution->id,
1493 'contact_id' => $contribution->contact_id,
1494 'modified_date' => date('Ymd'),
1495 );
1496
1497 CRM_Core_BAO_Note::add($noteParams, array());
1498 }
1499
6a488035
TO
1500 if (isset($params['related_contact'])) {
1501 $contactID = $params['related_contact'];
1502 }
1503 elseif (isset($params['cms_contactID'])) {
1504 $contactID = $params['cms_contactID'];
1505 }
cde484fd 1506
6a488035
TO
1507 //create contribution activity w/ individual and target
1508 //activity w/ organisation contact id when onbelf, CRM-4027
1509 $targetContactID = NULL;
a7488080 1510 if (!empty($params['hidden_onbehalf_profile'])) {
6a488035
TO
1511 $targetContactID = $contribution->contact_id;
1512 $contribution->contact_id = $contactID;
1513 }
1514
1515 // create an activity record
1516 if ($contribution) {
9879aeb8 1517 CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
6a488035
TO
1518 }
1519
1520 $transaction->commit();
4ab1a3a3 1521 // CRM-13074 - create the CMSUser after the transaction is completed as it
1522 // is not appropriate to delete a valid contribution if a user create problem occurs
1523 CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params,
a13f3d8c
TO
1524 $contactID,
1525 'email-' . $form->_bltID
4ab1a3a3 1526 );
6a488035
TO
1527 return $contribution;
1528 }
1529
1530 /**
7fe37828 1531 * Create the recurring contribution record.
6a488035 1532 *
03110609
EM
1533 * @param CRM_Core_Form $form
1534 * @param array $params
014c4014 1535 * @param int $contactID
03110609
EM
1536 * @param string $contributionType
1537 * @param bool $online
1538 *
1539 * @return mixed
6a488035 1540 */
00be9182 1541 public static function processRecurringContribution(&$form, &$params, $contactID, $contributionType, $online = TRUE) {
6a488035
TO
1542 // return if this page is not set for recurring
1543 // or the user has not chosen the recurring option
1544
1545 //this is online case validation.
8cc574cf 1546 if ((empty($form->_values['is_recur']) && $online) || empty($params['is_recur'])) {
6a488035
TO
1547 return NULL;
1548 }
1549
dbddfb08 1550 $recurParams = array('contact_id' => $contactID);
6a488035
TO
1551 $recurParams['amount'] = CRM_Utils_Array::value('amount', $params);
1552 $recurParams['auto_renew'] = CRM_Utils_Array::value('auto_renew', $params);
1553 $recurParams['frequency_unit'] = CRM_Utils_Array::value('frequency_unit', $params);
1554 $recurParams['frequency_interval'] = CRM_Utils_Array::value('frequency_interval', $params);
1555 $recurParams['installments'] = CRM_Utils_Array::value('installments', $params);
1556 $recurParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
8df022ad 1557 $recurParams['currency'] = CRM_Utils_Array::value('currency', $params);
6a488035 1558
d8a20b17
FG
1559 // CRM-14354: For an auto-renewing membership with an additional contribution,
1560 // if separate payments is not enabled, make sure only the membership fee recurs
396e62d8 1561 if (!empty($form->_membershipBlock)
1562 && $form->_membershipBlock['is_separate_payment'] === '0'
d8a20b17
FG
1563 && isset($params['selectMembership'])
1564 && $form->_values['is_allow_other_amount'] == '1'
5ae0815f 1565 // CRM-16331
377ef421 1566 && !empty($form->_membershipTypeValues)
5ae0815f 1567 && !empty($form->_membershipTypeValues[$params['selectMembership']]['minimum_fee'])
d8a20b17
FG
1568 ) {
1569 $recurParams['amount'] = $form->_membershipTypeValues[$params['selectMembership']]['minimum_fee'];
1570 }
1571
6a488035
TO
1572 $recurParams['is_test'] = 0;
1573 if (($form->_action & CRM_Core_Action::PREVIEW) ||
1574 (isset($form->_mode) && ($form->_mode == 'test'))
1575 ) {
1576 $recurParams['is_test'] = 1;
1577 }
1578
1579 $recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
a7488080 1580 if (!empty($params['receive_date'])) {
6a488035
TO
1581 $recurParams['start_date'] = $params['receive_date'];
1582 }
1583 $recurParams['invoice_id'] = CRM_Utils_Array::value('invoiceID', $params);
4f8dce1b 1584 $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
6a488035
TO
1585 $recurParams['payment_processor_id'] = CRM_Utils_Array::value('payment_processor_id', $params);
1586 $recurParams['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params);
1587 // we need to add a unique trxn_id to avoid a unique key error
1588 // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
1589 $recurParams['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params, $params['invoiceID']);
1590 $recurParams['financial_type_id'] = $contributionType->id;
1591
1592 if (!$online || $form->_values['is_monetary']) {
1593 $recurParams['payment_instrument_id'] = 1;
1594 }
1595
1596 $campaignId = CRM_Utils_Array::value('campaign_id', $params);
1597 if ($online) {
1598 if (!array_key_exists('campaign_id', $params)) {
1599 $campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
1600 }
1601 }
1602 $recurParams['campaign_id'] = $campaignId;
1603
1604 $recurring = CRM_Contribute_BAO_ContributionRecur::add($recurParams);
1605 if (is_a($recurring, 'CRM_Core_Error')) {
bd0bfdec 1606 CRM_Core_Error::displaySessionError($recurring);
6a488035
TO
1607 $urlString = 'civicrm/contribute/transact';
1608 $urlParams = '_qf_Main_display=true';
e8ab1184 1609 if (get_class($form) == 'CRM_Contribute_Form_Contribution') {
6a488035
TO
1610 $urlString = 'civicrm/contact/view/contribution';
1611 $urlParams = "action=add&cid={$form->_contactID}";
1612 if ($form->_mode) {
1613 $urlParams .= "&mode={$form->_mode}";
1614 }
1615 }
1616 CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams));
1617 }
1618
1619 return $recurring->id;
1620 }
1621
6a488035 1622 /**
7fe37828 1623 * Add on behalf of organization and it's location.
6a488035 1624 *
62118c6d
EM
1625 * This situation occurs when on behalf of is enabled for the contribution page and the person
1626 * signing up does so on behalf of an organization.
1627 *
5a4f6742
CW
1628 * @param array $behalfOrganization
1629 * array of organization info.
1630 * @param int $contactID
1631 * individual contact id. One.
16b10e64 1632 * who is doing the process of signup / contribution.
6a488035 1633 *
5a4f6742
CW
1634 * @param array $values
1635 * form values array.
c490a46a 1636 * @param array $params
62118c6d
EM
1637 * @param array $fields
1638 * Array of fields from the onbehalf profile relevant to the organization.
6a488035 1639 */
00be9182 1640 public static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL) {
6a488035 1641 $isCurrentEmployer = FALSE;
dbddfb08 1642 $dupeIDs = array();
6a488035 1643 $orgID = NULL;
96904d4d 1644 if (!empty($behalfOrganization['organization_id']) && empty($behalfOrganization['org_option'])) {
6a488035
TO
1645 $orgID = $behalfOrganization['organization_id'];
1646 unset($behalfOrganization['organization_id']);
1647 $isCurrentEmployer = TRUE;
1648 }
1649
1650 // formalities for creating / editing organization.
1651 $behalfOrganization['contact_type'] = 'Organization';
1652
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;
1658
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;
1663
1664 if (!$orgID) {
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');
1669
1670 // CRM-6243 says to pick the first org even if more than one match
1671 if (count($dupeIDs) >= 1) {
34eea47c 1672 $behalfOrganization['contact_id'] = $orgID = $dupeIDs[0];
6a488035
TO
1673 // don't allow name edit
1674 unset($behalfOrganization['organization_name']);
1675 }
1676 }
1677 else {
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']);
1682 }
1683
1684 // handling for image url
a7488080 1685 if (!empty($behalfOrganization['image_URL'])) {
6a488035
TO
1686 CRM_Contact_BAO_Contact::processImageParams($behalfOrganization);
1687 }
1688
1689 // create organization, add location
1690 $orgID = CRM_Contact_BAO_Contact::createProfileContact($behalfOrganization, $fields, $orgID,
1691 NULL, NULL, 'Organization'
1692 );
1693 // create relationship
1694 $relParams['contact_check'][$orgID] = 1;
1695 $cid = array('contact' => $contactID);
2da59b29 1696 CRM_Contact_BAO_Relationship::legacyCreateMultiple($relParams, $cid);
6a488035
TO
1697
1698 // if multiple match - send a duplicate alert
1699 if ($dupeIDs && (count($dupeIDs) > 1)) {
1700 $values['onbehalf_dupe_alert'] = 1;
1701 // required for IPN
1702 $params['onbehalf_dupe_alert'] = 1;
1703 }
1704
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.
1710
1711 // required for mailing/template display ..etc
1712 $values['related_contact'] = $contactID;
1713 // required for IPN
1714 $params['related_contact'] = $contactID;
1715
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'))
1720 ) {
1721 $isCurrentEmployer = FALSE;
1722 }
1723
1724 if (!$isCurrentEmployer && $orgID) {
1725 //build current employer params
1726 $currentEmpParams[$contactID] = $orgID;
1727 CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
1728 }
1729
1730 // contribution / signup will be done using this
1731 // organization id.
1732 $contactID = $orgID;
1733 }
1734 }
1735
1736 /**
7fe37828
EM
1737 * Function used to save pcp / soft credit entry.
1738 *
6a488035
TO
1739 * This is used by contribution and also event pcps
1740 *
014c4014 1741 * @param array $params
014c4014
TO
1742 * @param object $contribution
1743 * Contribution object.
6a488035 1744 */
00be9182 1745 public static function processPcpSoft(&$params, &$contribution) {
7fe37828 1746 // Add soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
a7488080 1747 if (!empty($params['soft_credit_to'])) {
dbddfb08 1748 $contributionSoftParams = array();
6a488035 1749 foreach (array(
12f92dbd
N
1750 'pcp_display_in_roll',
1751 'pcp_roll_nickname',
1752 'pcp_personal_note',
1753 'amount',
1754 ) as $val) {
a7488080 1755 if (!empty($params[$val])) {
dbddfb08 1756 $contributionSoftParams[$val] = $params[$val];
6a488035
TO
1757 }
1758 }
1759
dbddfb08 1760 $contributionSoftParams['contact_id'] = $params['soft_credit_to'];
6a488035 1761 // add contribution id
dbddfb08 1762 $contributionSoftParams['contribution_id'] = $contribution->id;
6a488035 1763 // add pcp id
dbddfb08 1764 $contributionSoftParams['pcp_id'] = $params['pcp_made_through_id'];
6a488035 1765
dbddfb08 1766 $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name');
51fa20cb 1767
12f92dbd
N
1768 $contributionSoft = CRM_Contribute_BAO_ContributionSoft::add($contributionSoftParams);
1769
1770 //Send notification to owner for PCP
1771 if ($contributionSoft->id && $contributionSoft->pcp_id) {
1772 CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft);
1773 }
1774 }
1775 }
1776
1777 /**
96cca285
EM
1778 * Function used to send notification mail to pcp owner.
1779 *
1780 * This is used by contribution and also event PCPs.
12f92dbd
N
1781 *
1782 * @param object $contribution
1783 * @param object $contributionSoft
1784 * Contribution object.
12f92dbd 1785 */
12f92dbd 1786 public static function pcpNotifyOwner($contribution, $contributionSoft) {
5fe87df6
N
1787 $params = array('id' => $contributionSoft->pcp_id);
1788 CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
1789 $ownerNotifyID = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id');
1790
1791 if ($ownerNotifyID != CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'no_notifications', 'name') &&
1792 (($ownerNotifyID == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name') &&
1793 CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft->pcp_id, 'is_notify')) ||
1794 $ownerNotifyID == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'all_owners', 'name'))) {
1795 $pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info',
1796 "reset=1&id={$contributionSoft->pcp_id}",
1797 TRUE, NULL, FALSE, TRUE
1798 );
12f92dbd 1799 // set email in the template here
5fe87df6
N
1800 // get the billing location type
1801 $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
1802 $billingLocationTypeId = array_search('Billing', $locationTypes);
1803
1804 if ($billingLocationTypeId) {
1805 list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id, FALSE, $billingLocationTypeId);
1806 }
1807 // get primary location email if no email exist( for billing location).
1808 if (!$email) {
1809 list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id);
1810 }
1811 list($ownerName, $ownerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contributionSoft->contact_id);
12f92dbd 1812 $tplParams = array(
5fe87df6 1813 'page_title' => $pcpInfo['title'],
12f92dbd
N
1814 'receive_date' => $contribution->receive_date,
1815 'total_amount' => $contributionSoft->amount,
1816 'donors_display_name' => $donorName,
5fe87df6
N
1817 'donors_email' => $email,
1818 'pcpInfoURL' => $pcpInfoURL,
12f92dbd
N
1819 'is_honor_roll_enabled' => $contributionSoft->pcp_display_in_roll,
1820 );
1821 $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
1822 $sendTemplateParams = array(
1823 'groupName' => 'msg_tpl_workflow_contribution',
1824 'valueName' => 'pcp_owner_notify',
1825 'contactId' => $contributionSoft->contact_id,
5fe87df6
N
1826 'toEmail' => $ownerEmail,
1827 'toName' => $ownerName,
12f92dbd
N
1828 'from' => "$domainValues[0] <$domainValues[1]>",
1829 'tplParams' => $tplParams,
1830 'PDFFilename' => 'receipt.pdf',
1831 );
1832 CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
6a488035
TO
1833 }
1834 }
1835
1836 /**
5e4f7f74
EM
1837 * Function used to se pcp related defaults / params.
1838 *
1839 * This is used by contribution and also event PCPs
6a488035 1840 *
014c4014
TO
1841 * @param CRM_Core_Form $page
1842 * Form object.
1843 * @param array $params
6a488035 1844 *
cd6994fc 1845 * @return array
6a488035 1846 */
00be9182 1847 public static function processPcp(&$page, $params) {
547206bc 1848 $params['pcp_made_through_id'] = $page->_pcpId;
6a488035 1849 $page->assign('pcpBlock', TRUE);
8cc574cf 1850 if (!empty($params['pcp_display_in_roll']) && empty($params['pcp_roll_nickname'])) {
6a488035
TO
1851 $params['pcp_roll_nickname'] = ts('Anonymous');
1852 $params['pcp_is_anonymous'] = 1;
1853 }
1854 else {
1855 $params['pcp_is_anonymous'] = 0;
1856 }
1857 foreach (array(
547206bc 1858 'pcp_display_in_roll',
1859 'pcp_is_anonymous',
1860 'pcp_roll_nickname',
21dfd5f5 1861 'pcp_personal_note',
547206bc 1862 ) as $val) {
a7488080 1863 if (!empty($params[$val])) {
6a488035
TO
1864 $page->assign($val, $params[$val]);
1865 }
1866 }
1867
1868 return $params;
1869 }
705b4205
EM
1870
1871 /**
5e4f7f74
EM
1872 * Process membership.
1873 *
5624f515 1874 * @param array $membershipParams
014c4014 1875 * @param int $contactID
5624f515
EM
1876 * @param array $customFieldsFormatted
1877 * @param array $fieldTypes
1878 * @param array $premiumParams
014c4014
TO
1879 * @param array $membershipLineItems
1880 * Line items specifically relating to memberships.
cc789d46 1881 * @param $isPayLater
705b4205 1882 */
cc789d46 1883 public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater) {
705b4205 1884 try {
d25e4224
DG
1885 $membershipTypeIDs = (array) $membershipParams['selectMembership'];
1886 $membershipTypes = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $membershipTypeIDs);
5624f515
EM
1887 $membershipType = empty($membershipTypes) ? array() : reset($membershipTypes);
1888 $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipType));
1889
fa9d0451 1890 $isPaidMembership = FALSE;
a13f3d8c 1891 if ($this->_amount >= 0.0 && isset($membershipParams['amount'])) {
fa9d0451
EM
1892 //amount must be greater than zero for
1893 //adding contribution record to contribution table.
1894 //this condition arises when separate membership payment is
1895 //enabled and contribution amount is not selected. fix for CRM-3010
1896 $isPaidMembership = TRUE;
1897 }
fb49fa48 1898 $isProcessSeparateMembershipTransaction = $this->isSeparateMembershipTransaction($this->_id, $this->_values['amount_block_is_active']);
fa9d0451 1899
c98997b9 1900 if ($this->_values['amount_block_is_active']) {
246e7293 1901 $contributionTypeId = $this->_values['financial_type_id'];
236a2274
EM
1902 }
1903 else {
a13f3d8c 1904 $contributionTypeId = CRM_Utils_Array::value('financial_type_id', $membershipType, CRM_Utils_Array::value('financial_type_id', $membershipParams));
236a2274
EM
1905 }
1906
705b4205 1907 CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID,
a13f3d8c 1908 $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeIDs, $isPaidMembership, $this->_membershipId, $isProcessSeparateMembershipTransaction, $contributionTypeId,
cc789d46 1909 $membershipLineItems, $isPayLater
705b4205
EM
1910 );
1911 $this->assign('membership_assign', TRUE);
1912 $this->set('membershipTypeID', $membershipParams['selectMembership']);
1913 }
1914 catch (CRM_Core_Exception $e) {
1915 CRM_Core_Session::singleton()->setStatus($e->getMessage());
1916 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Main_display=true&qfKey={$this->_params['qfKey']}"));
1917 }
1918 }
fb49fa48
EM
1919
1920 /**
5e4f7f74 1921 * Are we going to do 2 financial transactions.
fb49fa48 1922 *
5e4f7f74
EM
1923 * Ie the membership block supports a separate transactions AND the contribution form has been configured for a
1924 * contribution
1925 * transaction AND a membership transaction AND the payment processor supports double financial transactions (ie. NOT doTransferPayment style)
fb49fa48 1926 *
014c4014 1927 * @param int $formID
fb49fa48
EM
1928 * @param bool $amountBlockActiveOnForm
1929 *
1930 * @return bool
1931 */
1932 public function isSeparateMembershipTransaction($formID, $amountBlockActiveOnForm) {
1933 $memBlockDetails = CRM_Member_BAO_Membership::getMembershipBlock($formID);
1934 if (!empty($memBlockDetails['is_separate_payment']) && $amountBlockActiveOnForm) {
1935 return TRUE;
1936 }
1937 return FALSE;
1938 }
df6c4f28
EM
1939
1940 /**
5e4f7f74
EM
1941 * This function sets the fields.
1942 *
df6c4f28
EM
1943 * - $this->_params['amount_level']
1944 * - $this->_params['selectMembership']
1945 * And under certain circumstances sets
1946 * $this->_params['amount'] = null;
1947 *
100fef9d 1948 * @param int $priceSetID
df6c4f28
EM
1949 */
1950 public function setFormAmountFields($priceSetID) {
1951 $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config');
1952 $priceField = new CRM_Price_DAO_PriceField();
1953 $priceField->price_set_id = $priceSetID;
1954 $priceField->orderBy('weight');
1955 $priceField->find();
06b4ee3e 1956 $paramWeDoNotUnderstand = NULL;
df6c4f28
EM
1957
1958 while ($priceField->fetch()) {
df6c4f28
EM
1959 if ($priceField->name == "contribution_amount") {
1960 $paramWeDoNotUnderstand = $priceField->id;
1961 }
1962 if ($isQuickConfig && !empty($this->_params["price_{$priceField->id}"])) {
1963 if ($this->_values['fee'][$priceField->id]['html_type'] != 'Text') {
1964 $this->_params['amount_level'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1965 $this->_params["price_{$priceField->id}"], 'label');
1966 }
1967 if ($priceField->name == "membership_amount") {
1968 $this->_params['selectMembership'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1969 $this->_params["price_{$priceField->id}"], 'membership_type_id');
1970 }
5e4f7f74
EM
1971 }
1972 // If separate payment we set contribution amount to be null, so that it will not show contribution amount same
1973 // as membership amount.
df6c4f28
EM
1974 // @todo - this needs more documentation - it appears the setting to null is tied up with separate membership payments
1975 // but the circumstances are very confusing. Many of these conditions are repeated in the next conditional
1976 // so we should merge them together
1977 // the quick config seems like a red-herring - if this is about a separate membership payment then there
f64a217a 1978 // are 2 types of line items - membership ones & non-membership ones - regardless of whether quick config is set
df6c4f28
EM
1979 elseif (
1980 CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock)
1981 && !empty($this->_values['fee'][$priceField->id])
1982 && ($this->_values['fee'][$priceField->id]['name'] == "other_amount")
1983 && CRM_Utils_Array::value("price_{$paramWeDoNotUnderstand}", $this->_params) < 1
1984 && empty($this->_params["price_{$priceField->id}"])
1985 ) {
a13f3d8c 1986 $this->_params['amount'] = NULL;
df6c4f28
EM
1987 }
1988
1989 // Fix for CRM-14375 - If we are using separate payments and "no
1990 // thank you" is selected for the additional contribution, set
1991 // contribution amount to be null, so that it will not show
1992 // contribution amount same as membership amount.
1993 //@todo - merge with section above
1994 if ($this->_membershipBlock['is_separate_payment']
3c0201c9 1995 && !empty($this->_values['fee'][$priceField->id])
df6c4f28
EM
1996 && CRM_Utils_Array::value('name', $this->_values['fee'][$priceField->id]) == 'contribution_amount'
1997 && CRM_Utils_Array::value("price_{$priceField->id}", $this->_params) == '-1'
1998 ) {
a13f3d8c 1999 $this->_params['amount'] = NULL;
df6c4f28
EM
2000 }
2001 }
2002 }
be26f3e0 2003
03110609 2004 /**
5e4f7f74
EM
2005 * Submit function.
2006 *
03110609
EM
2007 * @param array $params
2008 *
2009 * @throws CiviCRM_API3_Exception
2010 */
00be9182 2011 public static function submit($params) {
be26f3e0
EM
2012 $form = new CRM_Contribute_Form_Contribution_Confirm();
2013 $form->_id = $params['id'];
e6fa4056
EM
2014 if (!empty($params['contact_id'])) {
2015 $form->_contactID = $params['contact_id'];
2016 }
f64a217a
EM
2017 CRM_Contribute_BAO_ContributionPage::setValues($form->_id, $form->_values);
2018 $form->_separateMembershipPayment = CRM_Contribute_BAO_ContributionPage::getIsMembershipPayment($form->_id);
be26f3e0
EM
2019 //this way the mocked up controller ignores the session stuff
2020 $_SERVER['REQUEST_METHOD'] = 'GET';
2021 $form->controller = new CRM_Contribute_Controller_Contribution();
2022 $params['invoiceID'] = md5(uniqid(rand(), TRUE));
2023 $paramsProcessedForForm = $form->_params = self::getFormParams($params['id'], $params);
f64a217a 2024 $form->_amount = $params['amount'];
be26f3e0
EM
2025 $priceSetID = $form->_params['priceSetId'] = $paramsProcessedForForm['price_set_id'];
2026 $priceFields = CRM_Price_BAO_PriceSet::getSetDetail($priceSetID);
f64a217a
EM
2027 $priceSetFields = reset($priceFields);
2028 $form->_values['fee'] = $priceSetFields['fields'];
5624f515 2029 $form->_priceSetId = $priceSetID;
be26f3e0 2030 $form->setFormAmountFields($priceSetID);
d25e4224
DG
2031 if (!empty($params['payment_processor'])) {
2032 $form->_paymentProcessor = civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor']));
a13f3d8c 2033 if ($form->_paymentProcessor['billing_mode'] == 1) {
e6fa4056
EM
2034 $form->_contributeMode = 'direct';
2035 }
2036 else {
2037 $form->_contributeMode = 'notify';
2038 }
d25e4224 2039 }
07102c2c
EM
2040 else {
2041 $form->_params['payment_processor'] = 0;
2042 }
be26f3e0
EM
2043 $priceFields = $priceFields[$priceSetID]['fields'];
2044 CRM_Price_BAO_PriceSet::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution');
2045 $form->_lineItem = array($priceSetID => $lineItems);
2046 $form->postProcess();
2047 }
2048
2049 /**
5e4f7f74
EM
2050 * Helper function for static submit function - set relevant params - help us to build up an array that we can pass
2051 * in.
2052 *
100fef9d 2053 * @param int $id
be26f3e0
EM
2054 * @param array $params
2055 *
2056 * @return array
2057 * @throws CiviCRM_API3_Exception
2058 */
00be9182 2059 public static function getFormParams($id, array $params) {
a13f3d8c 2060 if (!isset($params['is_pay_later'])) {
d25e4224
DG
2061 if (!empty($params['payment_processor'])) {
2062 $params['is_pay_later'] = 0;
2063 }
2064 else {
2065 $params['is_pay_later'] = civicrm_api3('contribution_page', 'getvalue', array(
a13f3d8c 2066 'id' => $id,
21dfd5f5 2067 'return' => 'is_pay_later',
a13f3d8c 2068 ));
d25e4224 2069 }
be26f3e0 2070 }
a13f3d8c 2071 if (empty($params['price_set_id'])) {
be26f3e0
EM
2072 $params['price_set_id'] = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id']);
2073 }
2074 return $params;
2075 }
96025800 2076
6a488035 2077}