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