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