3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * form to process actions on the group aspect of Custom Data
39 class CRM_Contribute_Form_Contribution_Confirm
extends CRM_Contribute_Form_ContributionBase
{
42 * the id of the contact associated with this contribution
51 * The id of the contribution object that is created when the form is submitted
56 public $_contributionID;
59 * Set the parameters to be passed to contribution create function
61 * @param array $params
62 * @param integer $contactID
63 * @param $financialTypeID
65 * @param $contributionPageId
66 * @param $nonDeductibleAmount
72 * @param $paymentProcessorOutcome
75 * @param $recurringContributionID
80 * @param $softCreditToID
84 * @internal param $financialType
87 public static function getContributionParams($params, $contactID, $financialTypeID, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending,
88 $paymentProcessorOutcome, $receiptDate, $recurringContributionID, $isTest, $addressID, $softCreditToID, $lineItems)
90 $contributionParams = array(
91 'contact_id' => $contactID,
92 'financial_type_id' => $financialTypeID,
93 'contribution_page_id' => $contributionPageId,
94 'receive_date' => (CRM_Utils_Array
::value('receive_date', $params)) ? CRM_Utils_Date
::processDate($params['receive_date']) : date('YmdHis'),
95 'non_deductible_amount' => $nonDeductibleAmount,
96 'total_amount' => $params['amount'],
97 'amount_level' => CRM_Utils_Array
::value('amount_level', $params),
98 'invoice_id' => $params['invoiceID'],
99 'currency' => $params['currencyID'],
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),
109 isset($params['cancel_date']) ?
110 CRM_Utils_Date
::format($params['cancel_date']) :
113 isset($params['thankyou_date']) ?
114 CRM_Utils_Date
::format($params['thankyou_date']) :
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
123 if (!$online && isset($params['thankyou_date'])) {
124 $contributionParam['thankyou_date'] = $params['thankyou_date'];
126 if (!$online ||
$isMonetary) {
127 if (empty($params['is_pay_later'])) {
128 $contributionParams['payment_instrument_id'] = 1;
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),
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'], ' '));
147 if ($recurringContributionID) {
148 $contributionParams['contribution_recur_id'] = $recurringContributionID;
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'],
161 return $contributionParams;
165 * Function to set variables up before form is built
170 public function preProcess() {
171 $config = CRM_Core_Config
::singleton();
172 parent
::preProcess();
174 // lineItem isn't set until Register postProcess
175 $this->_lineItem
= $this->get('lineItem');
176 $this->_paymentProcessor
= $this->get('paymentProcessor');
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'
184 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
185 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
187 $this->_params
['payer'] = $expressParams['payer'];
188 $this->_params
['payer_id'] = $expressParams['payer_id'];
189 $this->_params
['payer_status'] = $expressParams['payer_status'];
191 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $expressParams, $this->_params
, FALSE);
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}"]);
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}"]);
201 // set a few other parameters for PayPal
202 $this->_params
['token'] = $this->get('token');
204 $this->_params
['amount'] = $this->get('amount');
206 if (!empty($this->_membershipBlock
)){
207 $this->_params
['selectMembership'] = $this->get('selectMembership');
209 // we use this here to incorporate any changes made by folks in hooks
210 $this->_params
['currencyID'] = $config->defaultCurrency
;
212 $this->_params
['payment_action'] = 'Sale';
214 // also merge all the other values from the profile fields
215 $values = $this->controller
->exportValues('Main');
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}",
224 foreach ($values as $name => $value) {
226 if (!in_array($name, $skipFields)) {
227 $this->_params
[$name] = $value;
230 $this->set('getExpressCheckoutDetails', $this->_params
);
233 $this->_params
= $this->get('getExpressCheckoutDetails');
237 $this->_params
= $this->controller
->exportValues('Main');
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}"]);
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}"]);
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
);
251 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
252 $this->_params
['amount'] = $this->get('amount');
254 $this->_useForMember
= $this->get('useForMember');
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');
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
;
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');
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');
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;
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'
290 $this->_params
['amount'] = null;
294 $this->_params
['currencyID'] = $config->defaultCurrency
;
295 $this->_params
['payment_action'] = 'Sale';
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']);
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'];
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',
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);
326 if (in_array($field, $addressBlocks)) {
327 if ($locType == 'Primary') {
328 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
329 $locType = $defaultLocationType->id
;
332 if ($field == 'country') {
333 $value = CRM_Core_PseudoConstant
::countryIsoCode($value);
335 elseif ($field == 'state_province') {
336 $value = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value);
340 if (isset($this->_params
['onbehalf_location']['address'])
341 && count($this->_params
['onbehalf_location']['address']) > 0) {
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;
349 $this->_params
['onbehalf_location']['address'][$locType]['location_type_id'] = $locType;
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
;
360 $locationValue = $locType;
363 $phoneExtField = array();
365 if ($field == 'url') {
366 $blockName = 'website';
367 $locationType = 'website_type_id';
368 list($field, $locationValue) = explode('-', $loc);
370 elseif ($field == 'im') {
372 $locTypeId = 'provider_id';
373 $typeId = $this->_params
['onbehalf']["{$loc}-provider_id"];
375 elseif ($field == 'phone') {
376 list($field, $locType, $typeId) = explode('-', $loc);
377 $locTypeId = 'phone_type_id';
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]);
387 if ( isset ($this->_params
['onbehalf_location'][$blockName] )
388 && count( $this->_params
['onbehalf_location'][$blockName] ) > 0 ) {
391 if ($locationValue) {
392 $blockValues = array(
393 $fieldName => $value,
394 $locationType => $locationValue,
395 'is_primary' => $isPrimary,
399 $blockValues = array_merge($blockValues, array($locTypeId => $typeId));
401 if (!empty($phoneExtField)) {
402 $blockValues = array_merge($blockValues, $phoneExtField);
405 $this->_params
['onbehalf_location'][$blockName][] = $blockValues;
409 elseif (strstr($loc, 'custom')) {
410 if ($value && isset($this->_params
['onbehalf']["{$loc}_id"])) {
411 $value = $this->_params
['onbehalf']["{$loc}_id"];
413 $this->_params
['onbehalf_location']["{$loc}"] = $value;
416 if ($loc == 'contact_sub_type') {
417 $this->_params
['onbehalf_location'][$loc] = $value;
420 $this->_params
['onbehalf_location'][$field] = $value;
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.
429 'phone', 'email', 'address') as $blk) {
430 if (isset($this->_params
[$blk])) {
431 unset($this->_params
[$blk]);
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'])) {
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']);
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'
450 $this->_params
['frequency_unit'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
451 $this->_params
['selectMembership'], 'duration_unit'
457 $params = $this->processPcp($this, $this->_params
);
458 $this->_params
= $params;
460 $this->_params
['invoiceID'] = $this->get('invoiceID');
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'];
467 // assign contribution page id to the template so we can add css class for it
468 $this->assign('contributionPageID', $this->_id
);
470 $this->set('params', $this->_params
);
474 * Function to actually build the form
479 public function buildQuickForm() {
480 $this->assignToTemplate();
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'])) {
486 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
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']);
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);
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);
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,
506 $this->set('productID', $productID);
507 $this->set('option', $option);
509 $config = CRM_Core_Config
::singleton();
510 if (in_array('CiviMember', $config->enableComponents
)) {
511 if (isset($params['selectMembership']) &&
512 $params['selectMembership'] != 'no_thanks'
514 CRM_Member_BAO_Membership
::buildMembershipBlock($this,
516 $this->_membershipContactID
,
518 $params['selectMembership'],
523 $this->assign('membershipBlock', FALSE);
526 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre', TRUE);
527 $this->buildCustom($this->_values
['custom_post_id'], 'customPost', TRUE);
529 if (!empty($params['hidden_onbehalf_profile'])) {
530 $ufJoinParams = array(
531 'module' => 'onBehalf',
532 'entity_table' => 'civicrm_contribution_page',
533 'entity_id' => $this->_id
,
535 $OnBehalfProfile = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
536 $profileId = $OnBehalfProfile[0];
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'));
545 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
548 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
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
);
556 $this->assign('is_quick_config', 1);
557 $this->_params
['is_quick_config'] = 1;
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)
565 $this->_checkoutButtonName
= $this->getButtonName('next', 'checkout');
567 $this->_checkoutButtonName
,
568 $this->_paymentProcessor
['url_button'],
569 array('class' => 'form-submit')
572 $this->addButtons(array(
575 'name' => ts('<< Go Back'),
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)
585 $contribButton = ts('Continue >>');
586 $this->assign('button', ts('Continue'));
589 $contribButton = ts('Make Contribution');
590 $this->assign('button', ts('Make Contribution'));
592 $this->addButtons(array(
595 'name' => $contribButton,
596 'spacing' => ' ',
598 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"),
602 'name' => ts('Go Back'),
610 foreach ($this->_fields
as $name => $dontCare) {
611 if ($name != 'onbehalf' ||
$name != 'honor') {
615 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
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];
626 if (isset($contact["{$name}_id"])) {
627 $defaults["{$name}_id"] = $contact["{$name}_id"];
630 elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
631 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
636 $this->assign('useForMember', $this->get('useForMember'));
638 // now fix all state country selectors
639 CRM_Core_BAO_Address
::fixAllStateSelects($this, $defaults);
641 $this->setDefaults($defaults);
647 * overwrite action, since we are only showing elements in frozen mode
648 * no help display needed
653 function getAction() {
654 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
655 return CRM_Core_Action
::VIEW | CRM_Core_Action
::PREVIEW
;
658 return CRM_Core_Action
::VIEW
;
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
670 function setDefaultValues() {}
678 public function postProcess() {
679 $contactID = $this->getContactID();
681 // add a description field at the very beginning
682 $this->_params
['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo
['title']) ?
$this->_pcpInfo
['title'] : $this->_values
['title']);
684 // also add accounting code
685 $this->_params
['accountingCode'] = CRM_Utils_Array
::value('accountingCode',
690 $this->_params
['currencyID'] = CRM_Core_Config
::singleton()->defaultCurrency
;
692 $premiumParams = $membershipParams = $params = $this->_params
;
694 //carry payment processor id.
695 if ($paymentProcessorId = CRM_Utils_Array
::value('id', $this->_paymentProcessor
)) {
696 $this->_params
['payment_processor_id'] = $paymentProcessorId;
698 'premiumParams', 'membershipParams', 'tempParams', 'params') as $p) {
699 $
{$p}['payment_processor_id'] = $paymentProcessorId;
702 if (!empty($params['image_URL'])) {
703 CRM_Contact_BAO_Contact
::processImageParams($params);
706 $fields = array('email-Primary' => 1);
708 // get the add to groups
709 $addToGroups = array();
711 // now set the values for the billing location.
712 foreach ($this->_fields
as $name => $value) {
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'];
721 if (!array_key_exists('first_name', $fields)) {
722 $nameFields = array('first_name', 'middle_name', 'last_name');
723 foreach ($nameFields as $name) {
725 if (array_key_exists("billing_$name", $params)) {
726 $params[$name] = $params["billing_{$name}"];
727 $params['preserveDBName'] = TRUE;
732 // billing email address
733 $fields["email-{$this->_bltID}"] = 1;
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',
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}",
751 foreach ($billingFields as $value) {
752 unset($params[$value]);
753 unset($fields[$value]);
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]);
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;
776 elseif (!(strstr($fld, '-'))) {
777 if (in_array($fld, array(
778 'contribution_campaign_id', 'member_campaign_id'))) {
779 $fld = 'campaign_id';
782 $behalfOrganization[$fld] = $values;
784 $this->_params
[$fld] = $values;
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_' ) {
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;
805 unset($params['onbehalf_location']);
807 if (!empty($params['onbehalf[image_URL]'])) {
808 $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]'];
812 // check for profile double opt-in and get groups to be subscribed
813 $subscribeGroupIds = CRM_Core_BAO_UFGroup
::getDoubleOptInGroupIds($params, $contactID);
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]);
824 foreach ($addToGroups as $k) {
825 if (array_key_exists($k, $subscribeGroupIds)) {
826 unset($addToGroups[$k]);
830 if (empty($contactID)) {
831 $dupeParams = $params;
832 if (!empty($dupeParams['onbehalf'])) {
833 unset($dupeParams['onbehalf']);
836 $dedupeParams = CRM_Dedupe_Finder
::formatParams($dupeParams, 'Individual');
837 $dedupeParams['check_permission'] = FALSE;
838 $ids = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
840 // if we find more than one contact, use the first one
841 $contactID = CRM_Utils_Array
::value(0, $ids);
843 // Fetch default greeting id's if creating a contact
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);
854 $contactType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
856 $contactID = CRM_Contact_BAO_Contact
::createProfileContact(
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;
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);
877 // subscribing contact to groups
878 if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) {
879 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID);
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'])) {
886 foreach ($this->_fields
['onbehalf'] as $name => $value) {
887 $ufFields[$name] = 1;
889 self
::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values
,
890 $this->_params
, $ufFields
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
;
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);
908 $session->set('transaction.userID', NULL);
911 $this->_useForMember
= $this->get('useForMember');
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'
920 $processMembership = TRUE;
922 if (!$this->_useForMember
) {
923 $this->assign('membership_assign', TRUE);
924 $this->set('membershipTypeID', $this->_params
['selectMembership']);
927 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
928 $membershipParams['is_test'] = 1;
930 if ($this->_params
['is_pay_later']) {
931 $membershipParams['is_pay_later'] = 1;
935 if ($processMembership) {
936 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $membershipParams, TRUE);
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'];
943 $membershipParams['cms_contactID'] = $contactID;
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
);
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'];
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(
964 $customFieldsFormatted,
972 $fieldTypes = array('Contact', 'Organization', 'Membership');
975 $priceFieldIds = $this->get('memberPriceFieldIDS');
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'
988 if ($term = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) {
989 $membershipTypeTerms[$id] = ($term > 1) ?
$term : 1;
992 $membershipTypeTerms[$id] = 1;
996 $membershipParams['selectMembership'] = $membershipTypeIds;
997 $membershipParams['financial_type_id'] = $contributionTypeID;
998 $membershipParams['types_terms'] = $membershipTypeTerms;
1000 if (!empty($membershipParams['selectMembership'])) {
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]);
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
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'];
1030 $fieldTypes = array();
1031 if (!empty($paymentParams['onbehalf']) &&
1032 is_array($paymentParams['onbehalf'])
1034 foreach ($paymentParams['onbehalf'] as $key => $value) {
1035 if (strstr($key, 'custom_')) {
1036 $this->_params
[$key] = $value;
1039 $fieldTypes = array('Contact', 'Organization', 'Contribution');
1042 CRM_Contribute_BAO_Contribution_Utils
::processConfirm($this, $paymentParams,
1043 $premiumParams, $contactID,
1044 $contributionTypeId,
1054 * @param $premiumParams
1055 * @param $contribution
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'
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));
1077 $periodType = $productDAO->period_type
;
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');
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>";
1092 $startDate = $year . '-' . $month . '-' . $day;
1095 $startDate = date('Y-m-d');
1099 $date = explode('-', $startDate);
1104 switch ($duration_unit) {
1106 $year = $year +
$duration_interval;
1110 $month = $month +
$duration_interval;
1114 $day = $day +
$duration_interval;
1118 $day = $day +
($duration_interval * 7);
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);
1125 $dao = new CRM_Contribute_DAO_Premium();
1126 $dao->entity_table
= 'civicrm_contribution_page';
1127 $dao->entity_id
= $this->_id
;
1129 $this->assign('contact_phone', $dao->premiums_contact_phone
);
1130 $this->assign('contact_email', $dao->premiums_contact_email
);
1132 //create Premium record
1134 'product_id' => $premiumParams['selectProduct'],
1135 'contribution_id' => $contribution->id
,
1136 'product_option' => CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams),
1138 'start_date' => CRM_Utils_Date
::customFormat($startDate, '%Y%m%d'),
1139 'end_date' => CRM_Utils_Date
::customFormat($endDate, '%Y%m%d'),
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
;
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
;
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
1163 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($trxnParams);
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();
1177 * Process the contribution
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
1187 * @param bool $isTest
1188 * @param array $lineItems
1191 * @internal param bool $deductibleMode
1192 * @return CRM_Contribute_DAO_Contribution
1195 static function processContribution(
1206 $transaction = new CRM_Core_Transaction();
1207 $recurringContributionID = $contribSoftContactId = $addressID = NULL;
1209 // add these values for the recurringContrib function ,CRM-10188
1210 $params['financial_type_id'] = $financialType->id
;
1212 //create an contribution address
1214 $form->_contributeMode
!= 'notify' && empty($params['is_pay_later']) && !empty($form->_values
['is_monetary'])) {
1215 $addressID = CRM_Contribute_BAO_Contribution
::createAddress($params, $form->_bltID
);
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
);
1227 $recurringContributionID = self
::processRecurringContribution($form, $params, $contactID, $financialType, $online);
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'];
1234 // if non_deductible_amount does NOT exist - then calculate it depending on:
1235 // $contributionType->is_deductible and whether there is a product (premium).
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);
1242 if (!$online && isset($params['product_name'][0])) {
1243 $selectProduct = $params['product_name'][0];
1245 // if there is a product - compare the value to the contribution amount
1246 if (isset($selectProduct) &&
1247 $selectProduct != 'no_thanks'
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'];
1256 // product value does NOT exceed contribution amount
1258 $nonDeductibleAmount = $productDAO->price
;
1261 // contribution is deductible - but there is no product
1263 $nonDeductibleAmount = '0.00';
1266 // contribution is NOT deductible
1268 $nonDeductibleAmount = $params['amount'];
1272 $now = date('YmdHis');
1273 $receiptDate = CRM_Utils_Array
::value('receipt_date', $params);
1274 if (!empty($form->_values
['is_email_receipt'])) {
1275 $receiptDate = $now;
1278 //get the contrib page id.
1279 $contributionPageId = NULL;
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
);
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);
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(
1299 $params['pcp_made_through_id'],
1304 $contribSoftContactId = CRM_Utils_Array
::value('soft_credit_to', $params);
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;
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
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);
1323 // lets store it in the form variable so postProcess hook can get to this and use it
1324 $form->_contributionID
= $contribution->id
;
1327 //CRM-13981, processing honor contact into soft-credit contribution
1328 CRM_Contact_Form_ProfileContact
::postProcess($form);
1330 // process soft credit / pcp pages
1331 CRM_Contribute_Form_Contribution_Confirm
::processPcpSoft($params, $contribution);
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']))
1338 if (!empty($form->_values
['pledge_id'])) {
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',
1350 $pledgePaymentParams = array(
1352 'contribution_id' => $contribution->id
,
1353 'status_id' => $contribution->contribution_status_id
,
1354 'actual_amount' => $scheduledAmount,
1358 CRM_Pledge_BAO_PledgePayment
::add($pledgePaymentParams);
1361 //update pledge status according to the new payment statuses
1362 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($form->_values
['pledge_id']);
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"));
1379 $pledgeParams['frequency_day'] = 1;
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'];
1390 //inherit campaign from contirb page.
1391 $pledgeParams['campaign_id'] = $campaignId;
1393 $pledge = CRM_Pledge_BAO_Pledge
::create($pledgeParams);
1395 $form->_params
['pledge_id'] = $pledge->id
;
1397 //send acknowledgment email. only when pledge is created
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'];
1404 //scheduled amount will be same as installment_amount.
1405 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
1407 //get total pledge amount.
1408 $pledgeParams['total_pledge_amount'] = $pledge->amount
;
1410 CRM_Pledge_BAO_Pledge
::sendAcknowledgment($form, $pledgeParams);
1415 if ($online && $contribution) {
1416 CRM_Core_BAO_CustomValueTable
::postProcess($form->_params
,
1417 CRM_Core_DAO
::$_nullArray,
1418 'civicrm_contribution',
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')
1430 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_contribution', $contribution->id
);
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'),
1443 CRM_Core_BAO_Note
::add($noteParams, array());
1447 if (isset($params['related_contact'])) {
1448 $contactID = $params['related_contact'];
1450 elseif (isset($params['cms_contactID'])) {
1451 $contactID = $params['cms_contactID'];
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;
1462 // create an activity record
1463 if ($contribution) {
1464 CRM_Activity_BAO_Activity
::addActivity($contribution, NULL, $targetContactID);
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,
1472 'email-' . $form->_bltID
1474 return $contribution;
1478 * Create the recurring contribution record
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
1485 //this is online case validation.
1486 if ((empty($form->_values
['is_recur']) && $online) ||
empty($params['is_recur'])) {
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);
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'
1504 $recurParams['amount'] = $form->_membershipTypeValues
[$params['selectMembership']]['minimum_fee'];
1507 $recurParams['is_test'] = 0;
1508 if (($form->_action
& CRM_Core_Action
::PREVIEW
) ||
1509 (isset($form->_mode
) && ($form->_mode
== 'test'))
1511 $recurParams['is_test'] = 1;
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'];
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
;
1527 if (!$online ||
$form->_values
['is_monetary']) {
1528 $recurParams['payment_instrument_id'] = 1;
1531 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1533 if (!array_key_exists('campaign_id', $params)) {
1534 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1537 $recurParams['campaign_id'] = $campaignId;
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}";
1548 $urlParams .= "&mode={$form->_mode}";
1551 CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
1554 return $recurring->id
;
1558 * Function to add on behalf of organization and it's location
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.
1564 * @param $values array form values array
1566 * @param null $fields
1571 static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL) {
1572 $isCurrentEmployer = FALSE;
1575 if (!empty($behalfOrganization['organization_id']) && !empty($behalfOrganization['org_option'])) {
1576 $orgID = $behalfOrganization['organization_id'];
1577 unset($behalfOrganization['organization_id']);
1578 $isCurrentEmployer = TRUE;
1581 // formalities for creating / editing organization.
1582 $behalfOrganization['contact_type'] = 'Organization';
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
;
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;
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');
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']);
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']);
1615 // handling for image url
1616 if (!empty($behalfOrganization['image_URL'])) {
1617 CRM_Contact_BAO_Contact
::processImageParams($behalfOrganization);
1620 // create organization, add location
1621 $orgID = CRM_Contact_BAO_Contact
::createProfileContact($behalfOrganization, $fields, $orgID,
1622 NULL, NULL, 'Organization'
1624 // create relationship
1625 $relParams['contact_check'][$orgID] = 1;
1626 $cid = array('contact' => $contactID);
1627 CRM_Contact_BAO_Relationship
::create($relParams, $cid);
1629 // if multiple match - send a duplicate alert
1630 if ($dupeIDs && (count($dupeIDs) > 1)) {
1631 $values['onbehalf_dupe_alert'] = 1;
1633 $params['onbehalf_dupe_alert'] = 1;
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.
1642 // required for mailing/template display ..etc
1643 $values['related_contact'] = $contactID;
1645 $params['related_contact'] = $contactID;
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'))
1652 $isCurrentEmployer = FALSE;
1655 if (!$isCurrentEmployer && $orgID) {
1656 //build current employer params
1657 $currentEmpParams[$contactID] = $orgID;
1658 CRM_Contact_BAO_Contact_Utils
::setCurrentEmployer($currentEmpParams);
1661 // contribution / signup will be done using this
1663 $contactID = $orgID;
1668 * Function used to save pcp / soft credit entry
1669 * This is used by contribution and also event pcps
1671 * @param array $params associated array
1672 * @param object $contribution contribution object
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();
1682 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note', 'amount') as $val) {
1683 if (!empty($params[$val])) {
1684 $contributionSoftParams[$val] = $params[$val];
1688 $contributionSoftParams['contact_id'] = $params['soft_credit_to'];
1689 // add contribution id
1690 $contributionSoftParams['contribution_id'] = $contribution->id
;
1692 $contributionSoftParams['pcp_id'] = $params['pcp_made_through_id'];
1694 $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup
::getValue('soft_credit_type', 'pcp', 'name');
1696 CRM_Contribute_BAO_ContributionSoft
::add($contributionSoftParams);
1701 * Function used to se pcp related defaults / params
1702 * This is used by contribution and also event pcps
1704 * @param object $page form object
1705 * @param array $params associated array
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;
1719 $params['pcp_is_anonymous'] = 0;
1722 'pcp_display_in_roll',
1724 'pcp_roll_nickname',
1727 if (!empty($params[$val])) {
1728 $page->assign($val, $params[$val]);
1736 * @param $membershipParams
1738 * @param $customFieldsFormatted
1739 * @param $fieldTypes
1740 * @param $premiumParams
1742 public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams)
1746 $membershipTypeID = $membershipParams['selectMembership'];
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;
1758 $isProcessSeparateMembershipTransaction = $this->isSeparateMembershipTransaction($this->_id
, $this->_values
['amount_block_is_active']);
1760 if ($this->_values
['amount_block_is_active']) {
1761 $contributionTypeId = $form->_values
['financial_type_id'];
1764 $contributionTypeId = CRM_Utils_Array
::value( 'financial_type_id', $membershipDetails );
1765 if (!$contributionTypeId) {
1766 $contributionTypeId = CRM_Utils_Array
::value('financial_type_id' ,$membershipParams);
1770 CRM_Member_BAO_Membership
::postProcessMembership($membershipParams, $contactID,
1771 $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipDetails, $membershipTypeID, $isPaidMembership, $this->_membershipId
, $isProcessSeparateMembershipTransaction, $contributionTypeId
1773 $this->assign('membership_assign', TRUE);
1774 $this->set('membershipTypeID', $membershipParams['selectMembership']);
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']}"));
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)
1788 * @param integer $formID
1789 * @param bool $amountBlockActiveOnForm
1793 public function isSeparateMembershipTransaction($formID, $amountBlockActiveOnForm) {
1794 $memBlockDetails = CRM_Member_BAO_Membership
::getMembershipBlock($formID);
1795 if (!empty($memBlockDetails['is_separate_payment']) && $amountBlockActiveOnForm) {