3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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.
50 * The id of the contribution object that is created when the form is submitted.
54 public $_contributionID;
57 * Set the parameters to be passed to contribution create function.
59 * @param array $params
60 * @param int $contactID
61 * @param int $financialTypeID
63 * @param int $contributionPageId
64 * @param $nonDeductibleAmount
65 * @param int $campaignId
68 * @param $paymentProcessorOutcome
70 * @param int $recurringContributionID
72 * @param int $addressID
73 * @param int $softCreditToID
74 * @param array $lineItems
78 public static function getContributionParams(
79 $params, $contactID, $financialTypeID, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending,
80 $paymentProcessorOutcome, $receiptDate, $recurringContributionID, $isTest, $addressID, $softCreditToID, $lineItems) {
81 $contributionParams = array(
82 'contact_id' => $contactID,
83 'financial_type_id' => $financialTypeID,
84 'contribution_page_id' => $contributionPageId,
85 'receive_date' => (CRM_Utils_Array
::value('receive_date', $params)) ? CRM_Utils_Date
::processDate($params['receive_date']) : date('YmdHis'),
86 'non_deductible_amount' => $nonDeductibleAmount,
87 'total_amount' => $params['amount'],
88 'tax_amount' => CRM_Utils_Array
::value('tax_amount', $params),
89 'amount_level' => CRM_Utils_Array
::value('amount_level', $params),
90 'invoice_id' => $params['invoiceID'],
91 'currency' => $params['currencyID'],
92 'source' => (!$online ||
!empty($params['source'])) ? CRM_Utils_Array
::value('source', $params) : CRM_Utils_Array
::value('description', $params),
93 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
94 //configure cancel reason, cancel date and thankyou date
95 //from 'contribution' type profile if included
96 'cancel_reason' => CRM_Utils_Array
::value('cancel_reason', $params, 0),
97 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date
::format($params['cancel_date']) : NULL,
98 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date
::format($params['thankyou_date']) : NULL,
99 'campaign_id' => $campaignId,
100 'is_test' => $isTest,
101 'address_id' => $addressID,
102 //setting to make available to hook - although seems wrong to set on form for BAO hook availability
103 'soft_credit_to' => $softCreditToID,
104 'line_item' => $lineItems,
105 'skipLineItem' => CRM_Utils_Array
::value('skipLineItem', $params, 0),
107 if (!$online && isset($params['thankyou_date'])) {
108 $contributionParam['thankyou_date'] = $params['thankyou_date'];
110 if (!$online ||
$isMonetary) {
111 if (empty($params['is_pay_later'])) {
112 $contributionParams['payment_instrument_id'] = 1;
115 if ($paymentProcessorOutcome) {
116 $contributionParams['payment_processor'] = CRM_Utils_Array
::value('payment_processor', $paymentProcessorOutcome);
118 if (!$pending && $paymentProcessorOutcome) {
119 $contributionParams +
= array(
120 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $paymentProcessorOutcome),
121 'net_amount' => CRM_Utils_Array
::value('net_amount', $paymentProcessorOutcome, $params['amount']),
122 'trxn_id' => $paymentProcessorOutcome['trxn_id'],
123 'receipt_date' => $receiptDate,
124 // also add financial_trxn details as part of fix for CRM-4724
125 'trxn_result_code' => CRM_Utils_Array
::value('trxn_result_code', $paymentProcessorOutcome),
129 // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
130 $contributionParams['non_deductible_amount'] = trim(CRM_Utils_Money
::format($contributionParams['non_deductible_amount'], ' '));
131 $contributionParams['total_amount'] = trim(CRM_Utils_Money
::format($contributionParams['total_amount'], ' '));
133 if ($recurringContributionID) {
134 $contributionParams['contribution_recur_id'] = $recurringContributionID;
137 $contributionParams['contribution_status_id'] = $pending ?
2 : 1;
138 if (isset($contributionParams['invoice_id'])) {
139 $contributionParams['id'] = CRM_Core_DAO
::getFieldValue(
140 'CRM_Contribute_DAO_Contribution',
141 $contributionParams['invoice_id'],
147 return $contributionParams;
151 * Set variables up before form is built.
155 public function preProcess() {
156 $config = CRM_Core_Config
::singleton();
157 parent
::preProcess();
159 // lineItem isn't set until Register postProcess
160 $this->_lineItem
= $this->get('lineItem');
161 $this->_paymentProcessor
= $this->get('paymentProcessor');
163 if ($this->_contributeMode
== 'express') {
164 // rfp == redirect from paypal
165 $rfp = CRM_Utils_Request
::retrieve('rfp', 'Boolean',
166 CRM_Core_DAO
::$_nullObject, FALSE, NULL, 'GET'
169 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
170 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
172 $this->_params
['payer'] = CRM_Utils_Array
::value('payer', $expressParams);
173 $this->_params
['payer_id'] = $expressParams['payer_id'];
174 $this->_params
['payer_status'] = $expressParams['payer_status'];
176 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $expressParams, $this->_params
, FALSE);
178 // fix state and country id if present
179 if (!empty($this->_params
["billing_state_province_id-{$this->_bltID}"])) {
180 $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
182 if (!empty($this->_params
["billing_country_id-{$this->_bltID}"]) && $this->_params
["billing_country_id-{$this->_bltID}"]) {
183 $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
186 // set a few other parameters for PayPal
187 $this->_params
['token'] = $this->get('token');
189 $this->_params
['amount'] = $this->get('amount');
191 if (!empty($this->_membershipBlock
)) {
192 $this->_params
['selectMembership'] = $this->get('selectMembership');
194 // we use this here to incorporate any changes made by folks in hooks
195 $this->_params
['currencyID'] = $config->defaultCurrency
;
197 $this->_params
['payment_action'] = 'Sale';
199 // also merge all the other values from the profile fields
200 $values = $this->controller
->exportValues('Main');
204 "billing_street_address-{$this->_bltID}",
205 "billing_city-{$this->_bltID}",
206 "billing_state_province_id-{$this->_bltID}",
207 "billing_postal_code-{$this->_bltID}",
208 "billing_country_id-{$this->_bltID}",
210 foreach ($values as $name => $value) {
212 if (!in_array($name, $skipFields)) {
213 $this->_params
[$name] = $value;
216 $this->set('getExpressCheckoutDetails', $this->_params
);
219 $this->_params
= $this->get('getExpressCheckoutDetails');
223 $this->_params
= $this->controller
->exportValues('Main');
225 if (!empty($this->_params
["billing_state_province_id-{$this->_bltID}"])) {
226 $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
228 if (!empty($this->_params
["billing_country_id-{$this->_bltID}"])) {
229 $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
232 if (isset($this->_params
['credit_card_exp_date'])) {
233 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
234 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
237 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
238 $this->_params
['amount'] = $this->get('amount');
239 $this->_params
['tax_amount'] = $this->get('tax_amount');
241 $this->_useForMember
= $this->get('useForMember');
243 if (isset($this->_params
['amount'])) {
244 $this->setFormAmountFields($this->_params
['priceSetId']);
246 $this->_params
['currencyID'] = $config->defaultCurrency
;
247 $this->_params
['payment_action'] = 'Sale';
250 $this->_params
['is_pay_later'] = $this->get('is_pay_later');
251 $this->assign('is_pay_later', $this->_params
['is_pay_later']);
252 if ($this->_params
['is_pay_later']) {
253 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
255 // if onbehalf-of-organization
256 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
258 if (empty($this->_params
['org_option']) && empty($this->_params
['organization_id'])) {
259 if (!empty($this->_params
['onbehalfof_id'])) {
260 $this->_params
['organization_id'] = $this->_params
['onbehalfof_id'];
263 $this->_params
['organization_id'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_params
['onbehalf']['organization_name'], 'id', 'display_name');
267 $this->_params
['organization_name'] = $this->_params
['onbehalf']['organization_name'];
268 $addressBlocks = array(
274 'supplemental_address_1',
275 'supplemental_address_2',
276 'supplemental_address_3',
277 'postal_code_suffix',
283 $blocks = array('email', 'phone', 'im', 'url', 'openid');
284 foreach ($this->_params
['onbehalf'] as $loc => $value) {
285 $field = $typeId = NULL;
286 if (strstr($loc, '-')) {
287 list($field, $locType) = explode('-', $loc);
290 if (in_array($field, $addressBlocks)) {
291 if ($locType == 'Primary') {
292 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
293 $locType = $defaultLocationType->id
;
296 if ($field == 'country') {
297 $value = CRM_Core_PseudoConstant
::countryIsoCode($value);
299 elseif ($field == 'state_province') {
300 $value = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value);
304 if (isset($this->_params
['onbehalf_location']['address'])
305 && count($this->_params
['onbehalf_location']['address']) > 0
310 $this->_params
['onbehalf_location']['address'][$locType][$field] = $value;
311 if (empty($this->_params
['onbehalf_location']['address'][$locType]['is_primary'])) {
312 $this->_params
['onbehalf_location']['address'][$locType]['is_primary'] = $isPrimary;
314 $this->_params
['onbehalf_location']['address'][$locType]['location_type_id'] = $locType;
316 elseif (in_array($field, $blocks)) {
317 if (!$typeId ||
is_numeric($typeId)) {
318 $blockName = $fieldName = $field;
319 $locationType = 'location_type_id';
320 if ($locType == 'Primary') {
321 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
322 $locationValue = $defaultLocationType->id
;
325 $locationValue = $locType;
328 $phoneExtField = array();
330 if ($field == 'url') {
331 $blockName = 'website';
332 $locationType = 'website_type_id';
333 list($field, $locationValue) = explode('-', $loc);
335 elseif ($field == 'im') {
337 $locTypeId = 'provider_id';
338 $typeId = $this->_params
['onbehalf']["{$loc}-provider_id"];
340 elseif ($field == 'phone') {
341 list($field, $locType, $typeId) = explode('-', $loc);
342 $locTypeId = 'phone_type_id';
344 //check if extension field exists
345 $extField = str_replace('phone', 'phone_ext', $loc);
346 if (isset($this->_params
['onbehalf'][$extField])) {
347 $phoneExtField = array('phone_ext' => $this->_params
['onbehalf'][$extField]);
352 if (isset ($this->_params
['onbehalf_location'][$blockName])
353 && count($this->_params
['onbehalf_location'][$blockName]) > 0
357 if ($locationValue) {
358 $blockValues = array(
359 $fieldName => $value,
360 $locationType => $locationValue,
361 'is_primary' => $isPrimary,
365 $blockValues = array_merge($blockValues, array($locTypeId => $typeId));
367 if (!empty($phoneExtField)) {
368 $blockValues = array_merge($blockValues, $phoneExtField);
371 $this->_params
['onbehalf_location'][$blockName][] = $blockValues;
375 elseif (strstr($loc, 'custom')) {
376 if ($value && isset($this->_params
['onbehalf']["{$loc}_id"])) {
377 $value = $this->_params
['onbehalf']["{$loc}_id"];
379 $this->_params
['onbehalf_location']["{$loc}"] = $value;
382 if ($loc == 'contact_sub_type') {
383 $this->_params
['onbehalf_location'][$loc] = $value;
386 $this->_params
['onbehalf_location'][$field] = $value;
391 elseif (!empty($this->_values
['is_for_organization'])) {
392 // no on behalf of an organization, CRM-5519
393 // so reset loc blocks from main params.
399 if (isset($this->_params
[$blk])) {
400 unset($this->_params
[$blk]);
405 // if auto renew checkbox is set, initiate a open-ended recurring membership
406 if ((!empty($this->_params
['selectMembership']) ||
!empty($this->_params
['priceSetId'])) && !empty($this->_paymentProcessor
['is_recur']) &&
407 CRM_Utils_Array
::value('auto_renew', $this->_params
) && empty($this->_params
['is_recur']) && empty($this->_params
['frequency_interval'])
410 $this->_params
['is_recur'] = $this->_values
['is_recur'] = 1;
411 // check if price set is not quick config
412 if (!empty($this->_params
['priceSetId']) && !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params
['priceSetId'], 'is_quick_config')) {
413 list($this->_params
['frequency_interval'], $this->_params
['frequency_unit']) = CRM_Price_BAO_PriceSet
::getRecurDetails($this->_params
['priceSetId']);
416 // FIXME: set interval and unit based on selected membership type
417 $this->_params
['frequency_interval'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
418 $this->_params
['selectMembership'], 'duration_interval'
420 $this->_params
['frequency_unit'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipType',
421 $this->_params
['selectMembership'], 'duration_unit'
427 $params = $this->processPcp($this, $this->_params
);
428 $this->_params
= $params;
430 $this->_params
['invoiceID'] = $this->get('invoiceID');
432 //carry campaign from profile.
433 if (array_key_exists('contribution_campaign_id', $this->_params
)) {
434 $this->_params
['campaign_id'] = $this->_params
['contribution_campaign_id'];
437 // assign contribution page id to the template so we can add css class for it
438 $this->assign('contributionPageID', $this->_id
);
440 $this->set('params', $this->_params
);
444 * Build the form object.
448 public function buildQuickForm() {
449 $this->assignToTemplate();
451 $params = $this->_params
;
452 // make sure we have values for it
453 if ($this->_honor_block_is_active
&& !empty($params['soft_credit_type_id'])) {
455 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
457 $this->assign('honor_block_is_active', $this->_honor_block_is_active
);
458 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
459 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
461 $fieldTypes = array('Contact');
462 $fieldTypes[] = CRM_Core_BAO_UFGroup
::getContactType($params['honoree_profile_id']);
463 $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
465 $this->assign('receiptFromEmail', CRM_Utils_Array
::value('receipt_from_email', $this->_values
));
466 $amount_block_is_active = $this->get('amount_block_is_active');
467 $this->assign('amount_block_is_active', $amount_block_is_active);
469 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
470 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
472 $getTaxDetails = FALSE;
473 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
474 foreach ($this->_lineItem
as $key => $value) {
475 foreach ($value as $v) {
476 if (isset($v['tax_rate'])) {
477 if ($v['tax_rate'] != '') {
478 $getTaxDetails = TRUE;
483 $this->assign('getTaxDetails', $getTaxDetails);
484 $this->assign('taxTerm', $taxTerm);
485 $this->assign('totalTaxAmount', $params['tax_amount']);
487 if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
488 $option = CRM_Utils_Array
::value('options_' . $params['selectProduct'], $params);
489 $productID = $params['selectProduct'];
490 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, FALSE,
493 $this->set('productID', $productID);
494 $this->set('option', $option);
496 $config = CRM_Core_Config
::singleton();
497 if (in_array('CiviMember', $config->enableComponents
)) {
498 if (isset($params['selectMembership']) &&
499 $params['selectMembership'] != 'no_thanks'
501 CRM_Member_BAO_Membership
::buildMembershipBlock($this,
503 $this->_membershipContactID
,
505 $params['selectMembership'],
510 $this->assign('membershipBlock', FALSE);
513 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre', TRUE);
514 $this->buildCustom($this->_values
['custom_post_id'], 'customPost', TRUE);
516 if (!empty($params['hidden_onbehalf_profile'])) {
517 $ufJoinParams = array(
518 'module' => 'onBehalf',
519 'entity_table' => 'civicrm_contribution_page',
520 'entity_id' => $this->_id
,
522 $OnBehalfProfile = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
523 $profileId = $OnBehalfProfile[0];
525 $fieldTypes = array('Contact', 'Organization');
526 $contactSubType = CRM_Contact_BAO_ContactType
::subTypes('Organization');
527 $fieldTypes = array_merge($fieldTypes, $contactSubType);
528 if (is_array($this->_membershipBlock
) && !empty($this->_membershipBlock
)) {
529 $fieldTypes = array_merge($fieldTypes, array('Membership'));
532 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
535 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
538 $this->_separateMembershipPayment
= $this->get('separateMembershipPayment');
539 $this->assign('is_separate_payment', $this->_separateMembershipPayment
);
540 if ($this->_priceSetId
&& !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
541 $this->assign('lineItem', $this->_lineItem
);
544 $this->assign('is_quick_config', 1);
545 $this->_params
['is_quick_config'] = 1;
547 $this->assign('priceSetID', $this->_priceSetId
);
548 $paymentProcessorType = CRM_Core_PseudoConstant
::paymentProcessorType(FALSE, NULL, 'name');
549 if ($this->_paymentProcessor
&&
550 $this->_paymentProcessor
['payment_processor_type_id'] == CRM_Utils_Array
::key('Google_Checkout', $paymentProcessorType)
551 && !$this->_params
['is_pay_later'] && !($this->_amount
== 0)
553 $this->_checkoutButtonName
= $this->getButtonName('next', 'checkout');
555 $this->_checkoutButtonName
,
556 $this->_paymentProcessor
['url_button'],
557 array('class' => 'crm-form-submit')
560 $this->addButtons(array(
563 'name' => ts('Go Back'),
569 if ($this->_contributeMode
== 'notify' ||
!$this->_values
['is_monetary'] ||
570 $this->_amount
<= 0.0 ||
$this->_params
['is_pay_later'] ||
571 ($this->_separateMembershipPayment
&& $this->_amount
<= 0.0)
573 $contribButton = ts('Continue');
574 $this->assign('button', ts('Continue'));
577 $contribButton = ts('Make Contribution');
578 $this->assign('button', ts('Make Contribution'));
580 $this->addButtons(array(
583 'name' => $contribButton,
584 'spacing' => ' ',
586 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"),
590 'name' => ts('Go Back'),
597 $fields = array_fill_keys(array_keys($this->_fields
), 1);
598 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
600 $contact = $this->_params
;
601 foreach ($fields as $name => $dontCare) {
602 // Recursively set defaults for nested fields
603 if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' ||
$name == 'honor')) {
604 foreach ($contact[$name] as $fieldName => $fieldValue) {
605 if (is_array($fieldValue) && !in_array($this->_fields
[$name][$fieldName]['html_type'], array(
610 foreach ($fieldValue as $key => $value) {
611 $defaults["{$name}[{$fieldName}][{$key}]"] = $value;
615 $defaults["{$name}[{$fieldName}]"] = $fieldValue;
619 elseif (isset($contact[$name])) {
620 $defaults[$name] = $contact[$name];
621 if (substr($name, 0, 7) == 'custom_') {
622 $timeField = "{$name}_time";
623 if (isset($contact[$timeField])) {
624 $defaults[$timeField] = $contact[$timeField];
626 if (isset($contact["{$name}_id"])) {
627 $defaults["{$name}_id"] = $contact["{$name}_id"];
630 elseif (in_array($name, array(
634 )) && !empty($contact[$name . '_custom'])
636 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
641 $this->assign('useForMember', $this->get('useForMember'));
643 $this->setDefaults($defaults);
649 * Overwrite action, since we are only showing elements in frozen mode
650 * no help display needed
654 public function getAction() {
655 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
656 return CRM_Core_Action
::VIEW | CRM_Core_Action
::PREVIEW
;
659 return CRM_Core_Action
::VIEW
;
664 * Set default values for the form.
666 * Note that in edit/view mode
667 * the default values are retrieved from the database
671 public function setDefaultValues() {
679 public function postProcess() {
680 $contactID = $this->getContactID();
681 $isPayLater = $this->_params
['is_pay_later'];
682 if (isset($this->_params
['payment_processor']) && $this->_params
['payment_processor'] == 0) {
683 $this->_params
['is_pay_later'] = $isPayLater = TRUE;
685 // add a description field at the very beginning
686 $this->_params
['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo
['title']) ?
$this->_pcpInfo
['title'] : $this->_values
['title']);
688 // also add accounting code
689 $this->_params
['accountingCode'] = CRM_Utils_Array
::value('accountingCode',
694 $this->_params
['currencyID'] = CRM_Core_Config
::singleton()->defaultCurrency
;
696 //carry payment processor id.
697 if ($paymentProcessorId = CRM_Utils_Array
::value('id', $this->_paymentProcessor
)) {
698 $this->_params
['payment_processor_id'] = $paymentProcessorId;
700 if (!empty($params['image_URL'])) {
701 CRM_Contact_BAO_Contact
::processImageParams($params);
703 $premiumParams = $membershipParams = $params = $this->_params
;
704 $fields = array('email-Primary' => 1);
706 // get the add to groups
707 $addToGroups = array();
709 // now set the values for the billing location.
710 foreach ($this->_fields
as $name => $value) {
713 // get the add to groups for uf fields
714 if (!empty($value['add_to_group_id'])) {
715 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
719 if (!array_key_exists('first_name', $fields)) {
720 $nameFields = array('first_name', 'middle_name', 'last_name');
721 foreach ($nameFields as $name) {
723 if (array_key_exists("billing_$name", $params)) {
724 $params[$name] = $params["billing_{$name}"];
725 $params['preserveDBName'] = TRUE;
730 // billing email address
731 $fields["email-{$this->_bltID}"] = 1;
733 //unset the billing parameters if it is pay later mode
734 //to avoid creation of billing location
735 if ($isPayLater && !$this->_isBillingAddressRequiredForPayLater
) {
736 $billingFields = array(
737 'billing_first_name',
738 'billing_middle_name',
740 "billing_street_address-{$this->_bltID}",
741 "billing_city-{$this->_bltID}",
742 "billing_state_province-{$this->_bltID}",
743 "billing_state_province_id-{$this->_bltID}",
744 "billing_postal_code-{$this->_bltID}",
745 "billing_country-{$this->_bltID}",
746 "billing_country_id-{$this->_bltID}",
749 foreach ($billingFields as $value) {
750 unset($params[$value]);
751 unset($fields[$value]);
755 // if onbehalf-of-organization contribution, take out
756 // organization params in a separate variable, to make sure
757 // normal behavior is continued. And use that variable to
758 // process on-behalf-of functionality.
759 if (!empty($this->_params
['hidden_onbehalf_profile'])) {
760 $behalfOrganization = array();
761 $orgFields = array('organization_name', 'organization_id', 'org_option');
762 foreach ($orgFields as $fld) {
763 if (array_key_exists($fld, $params)) {
764 $behalfOrganization[$fld] = $params[$fld];
765 unset($params[$fld]);
769 if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) {
770 foreach ($params['onbehalf'] as $fld => $values) {
771 if (strstr($fld, 'custom_')) {
772 $behalfOrganization[$fld] = $values;
774 elseif (!(strstr($fld, '-'))) {
775 if (in_array($fld, array(
776 'contribution_campaign_id',
777 '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']);
835 if (!empty($dupeParams['honor'])) {
836 unset($dupeParams['honor']);
839 $dedupeParams = CRM_Dedupe_Finder
::formatParams($dupeParams, 'Individual');
840 $dedupeParams['check_permission'] = FALSE;
841 $ids = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual');
843 // if we find more than one contact, use the first one
844 $contactID = CRM_Utils_Array
::value(0, $ids);
846 // Fetch default greeting id's if creating a contact
848 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
849 if (!isset($params[$greeting])) {
850 $params[$greeting] = CRM_Contact_BAO_Contact_Utils
::defaultGreeting('Individual', $greeting);
857 $contactType = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
859 $contactID = CRM_Contact_BAO_Contact
::createProfileContact(
869 // Make the contact ID associated with the contribution available at the Class level.
870 // Also make available to the session.
871 //@todo consider handling this in $this->getContactID();
872 $this->set('contactID', $contactID);
873 $this->_contactID
= $contactID;
875 //get email primary first if exist
876 $subscriptionEmail = array('email' => CRM_Utils_Array
::value('email-Primary', $params));
877 if (!$subscriptionEmail['email']) {
878 $subscriptionEmail['email'] = CRM_Utils_Array
::value("email-{$this->_bltID}", $params);
880 // subscribing contact to groups
881 if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) {
882 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID);
885 // If onbehalf-of-organization contribution / signup, add organization
886 // and it's location.
887 if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) {
889 foreach ($this->_fields
['onbehalf'] as $name => $value) {
890 $ufFields[$name] = 1;
892 self
::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values
,
893 $this->_params
, $ufFields
896 elseif (!empty($this->_membershipContactID
) && $contactID != $this->_membershipContactID
) {
897 // this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household,
898 // store current user id as related contact for later use for mailing / activity..
899 $this->_values
['related_contact'] = $contactID;
900 $this->_params
['related_contact'] = $contactID;
901 // swap contact like we do for on-behalf-org case, so parent/primary membership is affected
902 $contactID = $this->_membershipContactID
;
905 // lets store the contactID in the session
906 // for things like tell a friend
907 $session = CRM_Core_Session
::singleton();
908 if (!$session->get('userID')) {
909 $session->set('transaction.userID', $contactID);
912 $session->set('transaction.userID', NULL);
915 $this->_useForMember
= $this->get('useForMember');
917 // store the fact that this is a membership and membership type is selected
918 $processMembership = FALSE;
919 if ((!empty($membershipParams['selectMembership']) &&
920 $membershipParams['selectMembership'] != 'no_thanks'
924 $processMembership = TRUE;
926 if (!$this->_useForMember
) {
927 $this->assign('membership_assign', TRUE);
928 $this->set('membershipTypeID', $this->_params
['selectMembership']);
931 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
932 $membershipParams['is_test'] = 1;
934 if ($this->_params
['is_pay_later']) {
935 $membershipParams['is_pay_later'] = 1;
939 if ($processMembership) {
940 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $membershipParams, TRUE);
942 // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups
943 if (isset($this->_params
['related_contact'])) {
944 $membershipParams['cms_contactID'] = $this->_params
['related_contact'];
947 $membershipParams['cms_contactID'] = $contactID;
950 //inherit campaign from contribution page.
951 if (!array_key_exists('campaign_id', $membershipParams)) {
952 $membershipParams['campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
);
955 if (!empty($membershipParams['onbehalf']) &&
956 is_array($membershipParams['onbehalf']) && !empty($membershipParams['onbehalf']['member_campaign_id'])
958 $this->_params
['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
961 $customFieldsFormatted = $fieldTypes = array();
962 if (!empty($membershipParams['onbehalf']) &&
963 is_array($membershipParams['onbehalf'])
965 foreach ($membershipParams['onbehalf'] as $key => $value) {
966 if (strstr($key, 'custom_')) {
967 $customFieldId = explode('_', $key);
968 CRM_Core_BAO_CustomField
::formatCustomField(
970 $customFieldsFormatted,
978 $fieldTypes = array('Contact', 'Organization', 'Membership');
981 $priceFieldIds = $this->get('memberPriceFieldIDS');
983 if (!empty($priceFieldIds)) {
984 $contributionTypeID = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $priceFieldIds['id'], 'financial_type_id');
985 unset($priceFieldIds['id']);
986 $membershipTypeIds = array();
987 $membershipTypeTerms = array();
988 foreach ($priceFieldIds as $priceFieldId) {
989 if ($id = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
990 $membershipTypeIds[] = $id;
991 //@todo the value for $term is immediately overwritten. It is unclear from the code whether it was intentional to
992 // do this or a double = was intended (this ambiguity is the reason many IDEs complain about 'assignment in condition'
994 if ($term = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) {
995 $membershipTypeTerms[$id] = ($term > 1) ?
$term : 1;
998 $membershipTypeTerms[$id] = 1;
1002 $membershipParams['selectMembership'] = $membershipTypeIds;
1003 $membershipParams['financial_type_id'] = $contributionTypeID;
1004 $membershipParams['types_terms'] = $membershipTypeTerms;
1006 if (!empty($membershipParams['selectMembership'])) {
1008 $membershipLineItems = array();
1009 if ($this->_separateMembershipPayment
&& $this->_values
['amount_block_is_active']) {
1010 foreach ($this->_values
['fee'] as $key => $feeValues) {
1011 if ($feeValues['name'] == 'membership_amount') {
1012 $fieldId = $this->_params
['price_' . $key];
1013 $membershipLineItems[$this->_priceSetId
][$fieldId] = $this->_lineItem
[$this->_priceSetId
][$fieldId];
1014 unset($this->_lineItem
[$this->_priceSetId
][$fieldId]);
1019 $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater);
1020 if (!$this->_amount
> 0.0 ||
!$membershipParams['amount']) {
1021 // we need to explicitly create a CMS user in case of free memberships
1022 // since it is done under processConfirm for paid memberships
1023 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($membershipParams,
1024 $membershipParams['cms_contactID'],
1025 'email-' . $this->_bltID
1031 // at this point we've created a contact and stored its address etc
1032 // all the payment processors expect the name and address to be in the
1033 // so we copy stuff over to first_name etc.
1034 $paymentParams = $this->_params
;
1035 $contributionTypeId = $this->_values
['financial_type_id'];
1037 $fieldTypes = array();
1038 if (!empty($paymentParams['onbehalf']) &&
1039 is_array($paymentParams['onbehalf'])
1041 foreach ($paymentParams['onbehalf'] as $key => $value) {
1042 if (strstr($key, 'custom_')) {
1043 $this->_params
[$key] = $value;
1046 $fieldTypes = array('Contact', 'Organization', 'Contribution');
1048 $financialTypeID = $this->wrangleFinancialTypeID($contributionTypeId);
1050 CRM_Contribute_BAO_Contribution_Utils
::processConfirm($this, $paymentParams,
1051 $premiumParams, $contactID,
1055 ($this->_mode
== 'test') ?
1 : 0,
1062 * Wrangle financial type ID.
1064 * This wrangling of the financialType ID was happening in a shared function rather than in the form it relates to & hence has been moved to that form
1065 * Pledges are not relevant to the membership code so that portion will not go onto the membership form.
1067 * Comments from previous refactor indicate doubt as to what was going on.
1069 * @param int $contributionTypeId
1071 * @return null|string
1073 public function wrangleFinancialTypeID($contributionTypeId) {
1074 if (isset($paymentParams['financial_type'])) {
1075 $contributionTypeId = $paymentParams['financial_type'];
1077 elseif (!empty($this->_values
['pledge_id'])) {
1078 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_Pledge',
1079 $this->_values
['pledge_id'],
1083 return $contributionTypeId;
1089 * @param array $premiumParams
1090 * @param $contribution
1092 public function postProcessPremium($premiumParams, $contribution) {
1093 $hour = $minute = $second = 0;
1094 // assigning Premium information to receipt tpl
1095 $selectProduct = CRM_Utils_Array
::value('selectProduct', $premiumParams);
1096 if ($selectProduct &&
1097 $selectProduct != 'no_thanks'
1099 $startDate = $endDate = "";
1100 $this->assign('selectPremium', TRUE);
1101 $productDAO = new CRM_Contribute_DAO_Product();
1102 $productDAO->id
= $selectProduct;
1103 $productDAO->find(TRUE);
1104 $this->assign('product_name', $productDAO->name
);
1105 $this->assign('price', $productDAO->price
);
1106 $this->assign('sku', $productDAO->sku
);
1107 $this->assign('option', CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams));
1109 $periodType = $productDAO->period_type
;
1112 $fixed_period_start_day = $productDAO->fixed_period_start_day
;
1113 $duration_unit = $productDAO->duration_unit
;
1114 $duration_interval = $productDAO->duration_interval
;
1115 if ($periodType == 'rolling') {
1116 $startDate = date('Y-m-d');
1118 elseif ($periodType == 'fixed') {
1119 if ($fixed_period_start_day) {
1120 $date = explode('-', date('Y-m-d'));
1121 $month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2);
1122 $day = substr($fixed_period_start_day, -2) . "<br/>";
1124 $startDate = $year . '-' . $month . '-' . $day;
1127 $startDate = date('Y-m-d');
1131 $date = explode('-', $startDate);
1136 switch ($duration_unit) {
1138 $year = $year +
$duration_interval;
1142 $month = $month +
$duration_interval;
1146 $day = $day +
$duration_interval;
1150 $day = $day +
($duration_interval * 7);
1152 $endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year));
1153 $this->assign('start_date', $startDate);
1154 $this->assign('end_date', $endDate);
1157 $dao = new CRM_Contribute_DAO_Premium();
1158 $dao->entity_table
= 'civicrm_contribution_page';
1159 $dao->entity_id
= $this->_id
;
1161 $this->assign('contact_phone', $dao->premiums_contact_phone
);
1162 $this->assign('contact_email', $dao->premiums_contact_email
);
1164 //create Premium record
1166 'product_id' => $premiumParams['selectProduct'],
1167 'contribution_id' => $contribution->id
,
1168 'product_option' => CRM_Utils_Array
::value('options_' . $premiumParams['selectProduct'], $premiumParams),
1170 'start_date' => CRM_Utils_Date
::customFormat($startDate, '%Y%m%d'),
1171 'end_date' => CRM_Utils_Date
::customFormat($endDate, '%Y%m%d'),
1173 if (!empty($premiumParams['selectProduct'])) {
1174 $daoPremiumsProduct = new CRM_Contribute_DAO_PremiumsProduct();
1175 $daoPremiumsProduct->product_id
= $premiumParams['selectProduct'];
1176 $daoPremiumsProduct->premiums_id
= $dao->id
;
1177 $daoPremiumsProduct->find(TRUE);
1178 $params['financial_type_id'] = $daoPremiumsProduct->financial_type_id
;
1180 //Fixed For CRM-3901
1181 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1182 $daoContrProd->contribution_id
= $contribution->id
;
1183 if ($daoContrProd->find(TRUE)) {
1184 $params['id'] = $daoContrProd->id
;
1187 CRM_Contribute_BAO_Contribution
::addPremium($params);
1188 if ($productDAO->cost
&& !empty($params['financial_type_id'])) {
1189 $trxnParams = array(
1190 'cost' => $productDAO->cost
,
1191 'currency' => $productDAO->currency
,
1192 'financial_type_id' => $params['financial_type_id'],
1193 'contributionId' => $contribution->id
,
1195 CRM_Core_BAO_FinancialTrxn
::createPremiumTrxn($trxnParams);
1198 elseif ($selectProduct == 'no_thanks') {
1199 //Fixed For CRM-3901
1200 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1201 $daoContrProd->contribution_id
= $contribution->id
;
1202 if ($daoContrProd->find(TRUE)) {
1203 $daoContrProd->delete();
1209 * Process the contribution.
1211 * @param CRM_Core_Form $form
1212 * @param array $params
1213 * @param array $result
1214 * @param int $contactID
1215 * @param CRM_Financial_DAO_FinancialType $financialType
1216 * @param bool $pending
1217 * @param bool $online
1219 * @param bool $isTest
1220 * @param array $lineItems
1223 * @return CRM_Contribute_DAO_Contribution
1225 public static function processContribution(
1236 $transaction = new CRM_Core_Transaction();
1237 $contribSoftContactId = $addressID = NULL;
1239 // add these values for the recurringContrib function ,CRM-10188
1240 $params['financial_type_id'] = $financialType->id
;
1242 //create an contribution address
1243 if ($form->_contributeMode
!= 'notify' && empty($params['is_pay_later']) && !empty($form->_values
['is_monetary'])) {
1244 $addressID = CRM_Contribute_BAO_Contribution
::createAddress($params, $form->_bltID
);
1247 //@todo - this is being set from the form to resolve CRM-10188 - an
1248 // eNotice caused by it not being set @ the front end
1249 // however, we then get it being over-written with null for backend contributions
1250 // a better fix would be to set the values in the respective forms rather than require
1251 // a function being shared by two forms to deal with their respective values
1252 // moving it to the BAO & not taking the $form as a param would make sense here.
1253 if (!isset($params['is_email_receipt']) && !empty($form->_values
['is_email_receipt'])) {
1254 $params['is_email_receipt'] = CRM_Utils_Array
::value('is_email_receipt', $form->_values
);
1256 $recurringContributionID = self
::processRecurringContribution($form, $params, $contactID, $financialType, $online);
1259 // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it.
1260 if (isset($params['non_deductible_amount']) && (!empty($params['non_deductible_amount']))) {
1261 $nonDeductibleAmount = $params['non_deductible_amount'];
1263 // if non_deductible_amount does NOT exist - then calculate it depending on:
1264 // $contributionType->is_deductible and whether there is a product (premium).
1266 //if ($contributionType->is_deductible && $deductibleMode) {
1267 if ($financialType->is_deductible
) {
1268 if ($online && isset($params['selectProduct'])) {
1269 $selectProduct = CRM_Utils_Array
::value('selectProduct', $params);
1271 if (!$online && isset($params['product_name'][0])) {
1272 $selectProduct = $params['product_name'][0];
1274 // if there is a product - compare the value to the contribution amount
1275 if (isset($selectProduct) &&
1276 $selectProduct != 'no_thanks'
1278 $productDAO = new CRM_Contribute_DAO_Product();
1279 $productDAO->id
= $selectProduct;
1280 $productDAO->find(TRUE);
1281 // product value exceeds contribution amount
1282 if ($params['amount'] < $productDAO->price
) {
1283 $nonDeductibleAmount = $params['amount'];
1285 // product value does NOT exceed contribution amount
1287 $nonDeductibleAmount = $productDAO->price
;
1290 // contribution is deductible - but there is no product
1292 $nonDeductibleAmount = '0.00';
1295 // contribution is NOT deductible
1297 $nonDeductibleAmount = $params['amount'];
1301 $now = date('YmdHis');
1302 $receiptDate = CRM_Utils_Array
::value('receipt_date', $params);
1303 if (!empty($form->_values
['is_email_receipt'])) {
1304 $receiptDate = $now;
1307 //get the contrib page id.
1308 $contributionPageId = NULL;
1310 $contributionPageId = $form->_id
;
1311 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1312 if (!array_key_exists('campaign_id', $params)) {
1313 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1317 //also for offline we do support - CRM-7290
1318 $contributionPageId = CRM_Utils_Array
::value('contribution_page_id', $params);
1319 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1322 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1323 if (!empty($params['pcp_made_through_id']) ||
!empty($params['soft_credit_to'])) {
1324 // if its due to pcp
1325 if (!empty($params['pcp_made_through_id'])) {
1326 $contribSoftContactId = CRM_Core_DAO
::getFieldValue(
1328 $params['pcp_made_through_id'],
1333 $contribSoftContactId = CRM_Utils_Array
::value('soft_credit_to', $params);
1336 // Pass these details onto with the contribution to make them
1337 // available at hook_post_process, CRM-8908
1338 $params['soft_credit_to'] = $contribSoftContactId;
1341 if (isset($params['amount'])) {
1343 if (!empty($form->_values
['is_monetary'])) {
1344 $isMonetary = $form->_values
['is_monetary'];
1346 $contribParams = self
::getContributionParams(
1347 $params, $contactID, $financialType->id
, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending, $result, $receiptDate,
1348 $recurringContributionID, $isTest, $addressID, $contribSoftContactId, $lineItems
1350 $contribution = CRM_Contribute_BAO_Contribution
::add($contribParams);
1352 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
1353 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
1355 $totalTaxAmount = 0;
1356 $dataArray = array();
1357 foreach ($form->_lineItem
as $lineItemKey => $lineItemValue) {
1358 foreach ($lineItemValue as $key => $value) {
1359 if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
1360 if (isset($dataArray[$value['tax_rate']])) {
1361 $dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $value);
1364 $dataArray[$value['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $value);
1369 $smarty = CRM_Core_Smarty
::singleton();
1370 $smarty->assign('dataArray', $dataArray);
1371 $smarty->assign('totalTaxAmount', $params['tax_amount']);
1373 if (is_a($contribution, 'CRM_Core_Error')) {
1374 $message = CRM_Core_Error
::getMessages($contribution);
1375 CRM_Core_Error
::fatal($message);
1378 // lets store it in the form variable so postProcess hook can get to this and use it
1379 $form->_contributionID
= $contribution->id
;
1382 //CRM-13981, processing honor contact into soft-credit contribution
1383 CRM_Contact_Form_ProfileContact
::postProcess($form);
1385 // process soft credit / pcp pages
1386 CRM_Contribute_Form_Contribution_Confirm
::processPcpSoft($params, $contribution);
1388 //handle pledge stuff.
1389 if (empty($form->_params
['separate_membership_payment']) && !empty($form->_values
['pledge_block_id']) &&
1390 (!empty($form->_params
['is_pledge']) ||
!empty($form->_values
['pledge_id']))
1393 if (!empty($form->_values
['pledge_id'])) {
1395 //when user doing pledge payments.
1396 //update the schedule when payment(s) are made
1397 foreach ($form->_params
['pledge_amount'] as $paymentId => $dontCare) {
1398 $scheduledAmount = CRM_Core_DAO
::getFieldValue(
1399 'CRM_Pledge_DAO_PledgePayment',
1405 $pledgePaymentParams = array(
1407 'contribution_id' => $contribution->id
,
1408 'status_id' => $contribution->contribution_status_id
,
1409 'actual_amount' => $scheduledAmount,
1412 CRM_Pledge_BAO_PledgePayment
::add($pledgePaymentParams);
1415 //update pledge status according to the new payment statuses
1416 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($form->_values
['pledge_id']);
1419 //when user creating pledge record.
1420 $pledgeParams = array();
1421 $pledgeParams['contact_id'] = $contribution->contact_id
;
1422 $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount
;
1423 $pledgeParams['contribution_id'] = $contribution->id
;
1424 $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id
;
1425 $pledgeParams['financial_type_id'] = $contribution->financial_type_id
;
1426 $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
1427 $pledgeParams['installments'] = $params['pledge_installments'];
1428 $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
1429 if ($pledgeParams['frequency_unit'] == 'month') {
1430 $pledgeParams['frequency_day'] = intval(date("d"));
1433 $pledgeParams['frequency_day'] = 1;
1435 $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
1436 $pledgeParams['status_id'] = $contribution->contribution_status_id
;
1437 $pledgeParams['max_reminders'] = $form->_values
['max_reminders'];
1438 $pledgeParams['initial_reminder_day'] = $form->_values
['initial_reminder_day'];
1439 $pledgeParams['additional_reminder_day'] = $form->_values
['additional_reminder_day'];
1440 $pledgeParams['is_test'] = $contribution->is_test
;
1441 $pledgeParams['acknowledge_date'] = date('Ymd');
1442 $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
1444 //inherit campaign from contirb page.
1445 $pledgeParams['campaign_id'] = $campaignId;
1447 $pledge = CRM_Pledge_BAO_Pledge
::create($pledgeParams);
1449 $form->_params
['pledge_id'] = $pledge->id
;
1451 //send acknowledgment email. only when pledge is created
1453 //build params to send acknowledgment.
1454 $pledgeParams['id'] = $pledge->id
;
1455 $pledgeParams['receipt_from_name'] = $form->_values
['receipt_from_name'];
1456 $pledgeParams['receipt_from_email'] = $form->_values
['receipt_from_email'];
1458 //scheduled amount will be same as installment_amount.
1459 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
1461 //get total pledge amount.
1462 $pledgeParams['total_pledge_amount'] = $pledge->amount
;
1464 CRM_Pledge_BAO_Pledge
::sendAcknowledgment($form, $pledgeParams);
1469 if ($online && $contribution) {
1470 CRM_Core_BAO_CustomValueTable
::postProcess($form->_params
,
1471 CRM_Core_DAO
::$_nullArray,
1472 'civicrm_contribution',
1477 elseif ($contribution) {
1478 //handle custom data.
1479 $params['contribution_id'] = $contribution->id
;
1480 if (!empty($params['custom']) &&
1481 is_array($params['custom']) &&
1482 !is_a($contribution, 'CRM_Core_Error')
1484 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_contribution', $contribution->id
);
1488 if ($contribution && !empty($params['contribution_note'])) {
1489 $noteParams = array(
1490 'entity_table' => 'civicrm_contribution',
1491 'note' => $params['contribution_note'],
1492 'entity_id' => $contribution->id
,
1493 'contact_id' => $contribution->contact_id
,
1494 'modified_date' => date('Ymd'),
1497 CRM_Core_BAO_Note
::add($noteParams, array());
1500 if (isset($params['related_contact'])) {
1501 $contactID = $params['related_contact'];
1503 elseif (isset($params['cms_contactID'])) {
1504 $contactID = $params['cms_contactID'];
1507 //create contribution activity w/ individual and target
1508 //activity w/ organisation contact id when onbelf, CRM-4027
1509 $targetContactID = NULL;
1510 if (!empty($params['hidden_onbehalf_profile'])) {
1511 $targetContactID = $contribution->contact_id
;
1512 $contribution->contact_id
= $contactID;
1515 // create an activity record
1516 if ($contribution) {
1517 CRM_Activity_BAO_Activity
::addActivity($contribution, NULL, $targetContactID);
1520 $transaction->commit();
1521 // CRM-13074 - create the CMSUser after the transaction is completed as it
1522 // is not appropriate to delete a valid contribution if a user create problem occurs
1523 CRM_Contribute_BAO_Contribution_Utils
::createCMSUser($params,
1525 'email-' . $form->_bltID
1527 return $contribution;
1531 * Create the recurring contribution record.
1533 * @param CRM_Core_Form $form
1534 * @param array $params
1535 * @param int $contactID
1536 * @param string $contributionType
1537 * @param bool $online
1541 public static function processRecurringContribution(&$form, &$params, $contactID, $contributionType, $online = TRUE) {
1542 // return if this page is not set for recurring
1543 // or the user has not chosen the recurring option
1545 //this is online case validation.
1546 if ((empty($form->_values
['is_recur']) && $online) ||
empty($params['is_recur'])) {
1550 $recurParams = array('contact_id' => $contactID);
1551 $recurParams['amount'] = CRM_Utils_Array
::value('amount', $params);
1552 $recurParams['auto_renew'] = CRM_Utils_Array
::value('auto_renew', $params);
1553 $recurParams['frequency_unit'] = CRM_Utils_Array
::value('frequency_unit', $params);
1554 $recurParams['frequency_interval'] = CRM_Utils_Array
::value('frequency_interval', $params);
1555 $recurParams['installments'] = CRM_Utils_Array
::value('installments', $params);
1556 $recurParams['financial_type_id'] = CRM_Utils_Array
::value('financial_type_id', $params);
1557 $recurParams['currency'] = CRM_Utils_Array
::value('currency', $params);
1559 // CRM-14354: For an auto-renewing membership with an additional contribution,
1560 // if separate payments is not enabled, make sure only the membership fee recurs
1561 if (!empty($form->_membershipBlock
)
1562 && $form->_membershipBlock
['is_separate_payment'] === '0'
1563 && isset($params['selectMembership'])
1564 && $form->_values
['is_allow_other_amount'] == '1'
1566 && !empty($form->_membershipTypeValues
)
1567 && !empty($form->_membershipTypeValues
[$params['selectMembership']]['minimum_fee'])
1569 $recurParams['amount'] = $form->_membershipTypeValues
[$params['selectMembership']]['minimum_fee'];
1572 $recurParams['is_test'] = 0;
1573 if (($form->_action
& CRM_Core_Action
::PREVIEW
) ||
1574 (isset($form->_mode
) && ($form->_mode
== 'test'))
1576 $recurParams['is_test'] = 1;
1579 $recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
1580 if (!empty($params['receive_date'])) {
1581 $recurParams['start_date'] = $params['receive_date'];
1583 $recurParams['invoice_id'] = CRM_Utils_Array
::value('invoiceID', $params);
1584 $recurParams['contribution_status_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
1585 $recurParams['payment_processor_id'] = CRM_Utils_Array
::value('payment_processor_id', $params);
1586 $recurParams['is_email_receipt'] = CRM_Utils_Array
::value('is_email_receipt', $params);
1587 // we need to add a unique trxn_id to avoid a unique key error
1588 // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
1589 $recurParams['trxn_id'] = CRM_Utils_Array
::value('trxn_id', $params, $params['invoiceID']);
1590 $recurParams['financial_type_id'] = $contributionType->id
;
1592 if (!$online ||
$form->_values
['is_monetary']) {
1593 $recurParams['payment_instrument_id'] = 1;
1596 $campaignId = CRM_Utils_Array
::value('campaign_id', $params);
1598 if (!array_key_exists('campaign_id', $params)) {
1599 $campaignId = CRM_Utils_Array
::value('campaign_id', $form->_values
);
1602 $recurParams['campaign_id'] = $campaignId;
1604 $recurring = CRM_Contribute_BAO_ContributionRecur
::add($recurParams);
1605 if (is_a($recurring, 'CRM_Core_Error')) {
1606 CRM_Core_Error
::displaySessionError($recurring);
1607 $urlString = 'civicrm/contribute/transact';
1608 $urlParams = '_qf_Main_display=true';
1609 if (get_class($form) == 'CRM_Contribute_Form_Contribution') {
1610 $urlString = 'civicrm/contact/view/contribution';
1611 $urlParams = "action=add&cid={$form->_contactID}";
1613 $urlParams .= "&mode={$form->_mode}";
1616 CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
1619 return $recurring->id
;
1623 * Add on behalf of organization and it's location.
1625 * @param array $behalfOrganization
1626 * array of organization info.
1627 * @param int $contactID
1628 * individual contact id. One.
1629 * who is doing the process of signup / contribution.
1631 * @param array $values
1632 * form values array.
1633 * @param array $params
1634 * @param null $fields
1636 public static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL) {
1637 $isCurrentEmployer = FALSE;
1640 if (!empty($behalfOrganization['organization_id']) && empty($behalfOrganization['org_option'])) {
1641 $orgID = $behalfOrganization['organization_id'];
1642 unset($behalfOrganization['organization_id']);
1643 $isCurrentEmployer = TRUE;
1646 // formalities for creating / editing organization.
1647 $behalfOrganization['contact_type'] = 'Organization';
1649 // get the relationship type id
1650 $relType = new CRM_Contact_DAO_RelationshipType();
1651 $relType->name_a_b
= 'Employee of';
1652 $relType->find(TRUE);
1653 $relTypeId = $relType->id
;
1655 // keep relationship params ready
1656 $relParams['relationship_type_id'] = $relTypeId . '_a_b';
1657 $relParams['is_permission_a_b'] = 1;
1658 $relParams['is_active'] = 1;
1661 // check if matching organization contact exists
1662 $dedupeParams = CRM_Dedupe_Finder
::formatParams($behalfOrganization, 'Organization');
1663 $dedupeParams['check_permission'] = FALSE;
1664 $dupeIDs = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Organization', 'Unsupervised');
1666 // CRM-6243 says to pick the first org even if more than one match
1667 if (count($dupeIDs) >= 1) {
1668 $behalfOrganization['contact_id'] = $orgID = $dupeIDs[0];
1669 // don't allow name edit
1670 unset($behalfOrganization['organization_name']);
1674 // if found permissioned related organization, allow location edit
1675 $behalfOrganization['contact_id'] = $orgID;
1676 // don't allow name edit
1677 unset($behalfOrganization['organization_name']);
1680 // handling for image url
1681 if (!empty($behalfOrganization['image_URL'])) {
1682 CRM_Contact_BAO_Contact
::processImageParams($behalfOrganization);
1685 // create organization, add location
1686 $orgID = CRM_Contact_BAO_Contact
::createProfileContact($behalfOrganization, $fields, $orgID,
1687 NULL, NULL, 'Organization'
1689 // create relationship
1690 $relParams['contact_check'][$orgID] = 1;
1691 $cid = array('contact' => $contactID);
1692 CRM_Contact_BAO_Relationship
::legacyCreateMultiple($relParams, $cid);
1694 // if multiple match - send a duplicate alert
1695 if ($dupeIDs && (count($dupeIDs) > 1)) {
1696 $values['onbehalf_dupe_alert'] = 1;
1698 $params['onbehalf_dupe_alert'] = 1;
1701 // make sure organization-contact-id is considered for recording
1702 // contribution/membership etc..
1703 if ($contactID != $orgID) {
1704 // take a note of contact-id, so we can send the
1705 // receipt to individual contact as well.
1707 // required for mailing/template display ..etc
1708 $values['related_contact'] = $contactID;
1710 $params['related_contact'] = $contactID;
1712 //make this employee of relationship as current
1713 //employer / employee relationship, CRM-3532
1714 if ($isCurrentEmployer &&
1715 ($orgID != CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'))
1717 $isCurrentEmployer = FALSE;
1720 if (!$isCurrentEmployer && $orgID) {
1721 //build current employer params
1722 $currentEmpParams[$contactID] = $orgID;
1723 CRM_Contact_BAO_Contact_Utils
::setCurrentEmployer($currentEmpParams);
1726 // contribution / signup will be done using this
1728 $contactID = $orgID;
1733 * Function used to save pcp / soft credit entry.
1735 * This is used by contribution and also event pcps
1737 * @param array $params
1738 * @param object $contribution
1739 * Contribution object.
1741 public static function processPcpSoft(&$params, &$contribution) {
1742 // Add soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1743 if (!empty($params['soft_credit_to'])) {
1744 $contributionSoftParams = array();
1746 'pcp_display_in_roll',
1747 'pcp_roll_nickname',
1748 'pcp_personal_note',
1751 if (!empty($params[$val])) {
1752 $contributionSoftParams[$val] = $params[$val];
1756 $contributionSoftParams['contact_id'] = $params['soft_credit_to'];
1757 // add contribution id
1758 $contributionSoftParams['contribution_id'] = $contribution->id
;
1760 $contributionSoftParams['pcp_id'] = $params['pcp_made_through_id'];
1762 $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup
::getValue('soft_credit_type', 'pcp', 'name');
1764 $contributionSoft = CRM_Contribute_BAO_ContributionSoft
::add($contributionSoftParams);
1766 //Send notification to owner for PCP
1767 if ($contributionSoft->id
&& $contributionSoft->pcp_id
) {
1768 CRM_Contribute_Form_Contribution_Confirm
::pcpNotifyOwner($contribution, $contributionSoft);
1774 * Function used to send notification mail to pcp owner.
1776 * This is used by contribution and also event PCPs.
1778 * @param object $contribution
1779 * @param object $contributionSoft
1780 * Contribution object.
1782 public static function pcpNotifyOwner($contribution, $contributionSoft) {
1783 $params = array('id' => $contributionSoft->pcp_id
);
1784 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
1785 $ownerNotifyID = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id');
1787 if ($ownerNotifyID != CRM_Core_OptionGroup
::getValue('pcp_owner_notify', 'no_notifications', 'name') &&
1788 (($ownerNotifyID == CRM_Core_OptionGroup
::getValue('pcp_owner_notify', 'owner_chooses', 'name') &&
1789 CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft->pcp_id
, 'is_notify')) ||
1790 $ownerNotifyID == CRM_Core_OptionGroup
::getValue('pcp_owner_notify', 'all_owners', 'name'))) {
1791 $pcpInfoURL = CRM_Utils_System
::url('civicrm/pcp/info',
1792 "reset=1&id={$contributionSoft->pcp_id}",
1793 TRUE, NULL, FALSE, TRUE
1795 // set email in the template here
1796 // get the billing location type
1797 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
1798 $billingLocationTypeId = array_search('Billing', $locationTypes);
1800 if ($billingLocationTypeId) {
1801 list($donorName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contribution->contact_id
, FALSE, $billingLocationTypeId);
1803 // get primary location email if no email exist( for billing location).
1805 list($donorName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contribution->contact_id
);
1807 list($ownerName, $ownerEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contributionSoft->contact_id
);
1809 'page_title' => $pcpInfo['title'],
1810 'receive_date' => $contribution->receive_date
,
1811 'total_amount' => $contributionSoft->amount
,
1812 'donors_display_name' => $donorName,
1813 'donors_email' => $email,
1814 'pcpInfoURL' => $pcpInfoURL,
1815 'is_honor_roll_enabled' => $contributionSoft->pcp_display_in_roll
,
1817 $domainValues = CRM_Core_BAO_Domain
::getNameAndEmail();
1818 $sendTemplateParams = array(
1819 'groupName' => 'msg_tpl_workflow_contribution',
1820 'valueName' => 'pcp_owner_notify',
1821 'contactId' => $contributionSoft->contact_id
,
1822 'toEmail' => $ownerEmail,
1823 'toName' => $ownerName,
1824 'from' => "$domainValues[0] <$domainValues[1]>",
1825 'tplParams' => $tplParams,
1826 'PDFFilename' => 'receipt.pdf',
1828 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1833 * Function used to se pcp related defaults / params.
1835 * This is used by contribution and also event PCPs
1837 * @param CRM_Core_Form $page
1839 * @param array $params
1843 public static function processPcp(&$page, $params) {
1844 $params['pcp_made_through_id'] = $page->_pcpId
;
1845 $page->assign('pcpBlock', TRUE);
1846 if (!empty($params['pcp_display_in_roll']) && empty($params['pcp_roll_nickname'])) {
1847 $params['pcp_roll_nickname'] = ts('Anonymous');
1848 $params['pcp_is_anonymous'] = 1;
1851 $params['pcp_is_anonymous'] = 0;
1854 'pcp_display_in_roll',
1856 'pcp_roll_nickname',
1857 'pcp_personal_note',
1859 if (!empty($params[$val])) {
1860 $page->assign($val, $params[$val]);
1868 * Process membership.
1870 * @param array $membershipParams
1871 * @param int $contactID
1872 * @param array $customFieldsFormatted
1873 * @param array $fieldTypes
1874 * @param array $premiumParams
1875 * @param array $membershipLineItems
1876 * Line items specifically relating to memberships.
1877 * @param $isPayLater
1879 public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater) {
1881 $membershipTypeIDs = (array) $membershipParams['selectMembership'];
1882 $membershipTypes = CRM_Member_BAO_Membership
::buildMembershipTypeValues($this, $membershipTypeIDs);
1883 $membershipType = empty($membershipTypes) ?
array() : reset($membershipTypes);
1884 $this->assign('membership_name', CRM_Utils_Array
::value('name', $membershipType));
1886 $isPaidMembership = FALSE;
1887 if ($this->_amount
>= 0.0 && isset($membershipParams['amount'])) {
1888 //amount must be greater than zero for
1889 //adding contribution record to contribution table.
1890 //this condition arises when separate membership payment is
1891 //enabled and contribution amount is not selected. fix for CRM-3010
1892 $isPaidMembership = TRUE;
1894 $isProcessSeparateMembershipTransaction = $this->isSeparateMembershipTransaction($this->_id
, $this->_values
['amount_block_is_active']);
1896 if ($this->_values
['amount_block_is_active']) {
1897 $contributionTypeId = $this->_values
['financial_type_id'];
1900 $contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $membershipType, CRM_Utils_Array
::value('financial_type_id', $membershipParams));
1903 CRM_Member_BAO_Membership
::postProcessMembership($membershipParams, $contactID,
1904 $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeIDs, $isPaidMembership, $this->_membershipId
, $isProcessSeparateMembershipTransaction, $contributionTypeId,
1905 $membershipLineItems, $isPayLater
1907 $this->assign('membership_assign', TRUE);
1908 $this->set('membershipTypeID', $membershipParams['selectMembership']);
1910 catch (CRM_Core_Exception
$e) {
1911 CRM_Core_Session
::singleton()->setStatus($e->getMessage());
1912 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contribute/transact', "_qf_Main_display=true&qfKey={$this->_params['qfKey']}"));
1917 * Are we going to do 2 financial transactions.
1919 * Ie the membership block supports a separate transactions AND the contribution form has been configured for a
1921 * transaction AND a membership transaction AND the payment processor supports double financial transactions (ie. NOT doTransferPayment style)
1923 * @param int $formID
1924 * @param bool $amountBlockActiveOnForm
1928 public function isSeparateMembershipTransaction($formID, $amountBlockActiveOnForm) {
1929 $memBlockDetails = CRM_Member_BAO_Membership
::getMembershipBlock($formID);
1930 if (!empty($memBlockDetails['is_separate_payment']) && $amountBlockActiveOnForm) {
1937 * This function sets the fields.
1939 * - $this->_params['amount_level']
1940 * - $this->_params['selectMembership']
1941 * And under certain circumstances sets
1942 * $this->_params['amount'] = null;
1944 * @param int $priceSetID
1946 public function setFormAmountFields($priceSetID) {
1947 $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params
['priceSetId'], 'is_quick_config');
1948 $priceField = new CRM_Price_DAO_PriceField();
1949 $priceField->price_set_id
= $priceSetID;
1950 $priceField->orderBy('weight');
1951 $priceField->find();
1952 $paramWeDoNotUnderstand = NULL;
1954 while ($priceField->fetch()) {
1955 if ($priceField->name
== "contribution_amount") {
1956 $paramWeDoNotUnderstand = $priceField->id
;
1958 if ($isQuickConfig && !empty($this->_params
["price_{$priceField->id}"])) {
1959 if ($this->_values
['fee'][$priceField->id
]['html_type'] != 'Text') {
1960 $this->_params
['amount_level'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1961 $this->_params
["price_{$priceField->id}"], 'label');
1963 if ($priceField->name
== "membership_amount") {
1964 $this->_params
['selectMembership'] = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue',
1965 $this->_params
["price_{$priceField->id}"], 'membership_type_id');
1968 // If separate payment we set contribution amount to be null, so that it will not show contribution amount same
1969 // as membership amount.
1970 // @todo - this needs more documentation - it appears the setting to null is tied up with separate membership payments
1971 // but the circumstances are very confusing. Many of these conditions are repeated in the next conditional
1972 // so we should merge them together
1973 // the quick config seems like a red-herring - if this is about a separate membership payment then there
1974 // are 2 types of line items - membership ones & non-membership ones - regardless of whether quick config is set
1976 CRM_Utils_Array
::value('is_separate_payment', $this->_membershipBlock
)
1977 && !empty($this->_values
['fee'][$priceField->id
])
1978 && ($this->_values
['fee'][$priceField->id
]['name'] == "other_amount")
1979 && CRM_Utils_Array
::value("price_{$paramWeDoNotUnderstand}", $this->_params
) < 1
1980 && empty($this->_params
["price_{$priceField->id}"])
1982 $this->_params
['amount'] = NULL;
1985 // Fix for CRM-14375 - If we are using separate payments and "no
1986 // thank you" is selected for the additional contribution, set
1987 // contribution amount to be null, so that it will not show
1988 // contribution amount same as membership amount.
1989 //@todo - merge with section above
1990 if ($this->_membershipBlock
['is_separate_payment']
1991 && !empty($this->_values
['fee'][$priceField->id
])
1992 && CRM_Utils_Array
::value('name', $this->_values
['fee'][$priceField->id
]) == 'contribution_amount'
1993 && CRM_Utils_Array
::value("price_{$priceField->id}", $this->_params
) == '-1'
1995 $this->_params
['amount'] = NULL;
2003 * @param array $params
2005 * @throws CiviCRM_API3_Exception
2007 public static function submit($params) {
2008 $form = new CRM_Contribute_Form_Contribution_Confirm();
2009 $form->_id
= $params['id'];
2010 if (!empty($params['contact_id'])) {
2011 $form->_contactID
= $params['contact_id'];
2013 CRM_Contribute_BAO_ContributionPage
::setValues($form->_id
, $form->_values
);
2014 $form->_separateMembershipPayment
= CRM_Contribute_BAO_ContributionPage
::getIsMembershipPayment($form->_id
);
2015 //this way the mocked up controller ignores the session stuff
2016 $_SERVER['REQUEST_METHOD'] = 'GET';
2017 $form->controller
= new CRM_Contribute_Controller_Contribution();
2018 $params['invoiceID'] = md5(uniqid(rand(), TRUE));
2019 $paramsProcessedForForm = $form->_params
= self
::getFormParams($params['id'], $params);
2020 $form->_amount
= $params['amount'];
2021 $priceSetID = $form->_params
['priceSetId'] = $paramsProcessedForForm['price_set_id'];
2022 $priceFields = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetID);
2023 $priceSetFields = reset($priceFields);
2024 $form->_values
['fee'] = $priceSetFields['fields'];
2025 $form->_priceSetId
= $priceSetID;
2026 $form->setFormAmountFields($priceSetID);
2027 if (!empty($params['payment_processor'])) {
2028 $form->_paymentProcessor
= civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor']));
2029 if ($form->_paymentProcessor
['billing_mode'] == 1) {
2030 $form->_contributeMode
= 'direct';
2033 $form->_contributeMode
= 'notify';
2037 $form->_params
['payment_processor'] = 0;
2039 $priceFields = $priceFields[$priceSetID]['fields'];
2040 CRM_Price_BAO_PriceSet
::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution');
2041 $form->_lineItem
= array($priceSetID => $lineItems);
2042 $form->postProcess();
2046 * Helper function for static submit function - set relevant params - help us to build up an array that we can pass
2050 * @param array $params
2053 * @throws CiviCRM_API3_Exception
2055 public static function getFormParams($id, array $params) {
2056 if (!isset($params['is_pay_later'])) {
2057 if (!empty($params['payment_processor'])) {
2058 $params['is_pay_later'] = 0;
2061 $params['is_pay_later'] = civicrm_api3('contribution_page', 'getvalue', array(
2063 'return' => 'is_pay_later',
2067 if (empty($params['price_set_id'])) {
2068 $params['price_set_id'] = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $params['id']);