3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 usefusul, 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-2013
37 * This class generates form components for processing a contribution
40 class CRM_Contribute_Form_Contribution
extends CRM_Contribute_Form_AbstractEditPayment
{
42 * the id of the contribution that we are proceessing
50 * the id of the premium that we are proceessing
55 public $_premiumID = NULL;
56 public $_productDAO = NULL;
67 * the id of the contact associated with this contribution
75 * the id of the pledge payment that we are processing
83 * the id of the pledge that we are processing
91 * is this contribution associated with an online
92 * financial transaction
97 public $_online = FALSE;
100 * Stores all product option
108 * stores the honor id
113 public $_honorID = NULL;
116 * Store the contribution Type ID
120 public $_contributionType;
123 * The contribution values if an existing contribution
128 * The pledge values if this contribution is associated with pledge
130 public $_pledgeValues;
132 public $_contributeMode = 'direct';
139 * Store the line items if price set used.
143 protected $_formType;
147 * Function to set variables up before form is built
152 public function preProcess() {
153 //check permission for action.
154 if (!CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
155 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
158 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
160 $this->assign('cdType', FALSE);
161 if ($this->_cdType
) {
162 $this->assign('cdType', TRUE);
163 CRM_Custom_Form_CustomData
::preProcess($this);
167 $this->_formType
= CRM_Utils_Array
::value('formType', $_GET);
170 $this->_priceSetId
= CRM_Utils_Array
::value('priceSetId', $_GET);
171 $this->set('priceSetId', $this->_priceSetId
);
172 $this->assign('priceSetId', $this->_priceSetId
);
174 //get the pledge payment id
175 $this->_ppID
= CRM_Utils_Request
::retrieve('ppid', 'Positive', $this);
178 $this->_contactID
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
181 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
182 $this->assign('action', $this->_action
);
184 //get the contribution id if update
185 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
186 if (!empty($this->_id
)) {
187 $this->assign('contribID', $this->_id
);
190 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
191 $this->assign('context', $this->_context
);
193 $this->_compId
= CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
195 $this->_compContext
= CRM_Utils_Request
::retrieve('compContext', 'String', $this);
197 //set the contribution mode.
198 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
200 $this->assign('contributionMode', $this->_mode
);
202 $this->_paymentProcessor
= array('billing_mode' => 1);
204 $this->assign('showCheckNumber', TRUE);
206 $this->_fromEmails
= CRM_Core_BAO_Email
::getFromEmail();
207 $this->assignProcessors();
209 if ($this->_contactID
) {
210 list($this->userDisplayName
, $this->userEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactID
);
211 $this->assign('displayName', $this->userDisplayName
);
214 // also check for billing information
215 // get the billing location type
216 $this->assignBillingType();
218 $this->_fields
= array();
220 CRM_Core_Payment_Form
::setPaymentFieldsByType(CRM_Utils_Array
::value('payment_type', $this->_processors
), $this);
222 if ($this->_action
& CRM_Core_Action
::DELETE
) {
226 $config = CRM_Core_Config
::singleton();
227 if (in_array('CiviPledge', $config->enableComponents
) && !$this->_formType
) {
228 $this->preProcessPledge();
231 $this->_values
= array();
233 // current contribution id
235 $this->assignPremiumProduct($this->_id
);
236 $this->buildValuesAndAssignOnline_Note_Type($this->_id
, $this->_values
);
239 // when custom data is included in this page
240 if (CRM_Utils_Array
::value('hidden_custom', $_POST)) {
241 $this->applyCustomData('Contribution', CRM_Utils_Array
::value('financial_type_id', $_POST), $this->_id
);
244 $this->_lineItems
= array();
246 if (!empty($this->_compId
) && $this->_compContext
== 'participant') {
247 $this->assign('compId', $this->_compId
);
248 $lineItem = CRM_Price_BAO_LineItem
::getLineItems($this->_compId
);
251 $lineItem = CRM_Price_BAO_LineItem
::getLineItems($this->_id
, 'contribution',1);
253 empty($lineItem) ?
NULL : $this->_lineItems
[] = $lineItem;
256 $this->assign('lineItem', empty($this->_lineItems
) ?
FALSE : $this->_lineItems
);
259 if ($this->_contactID
) {
260 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactID
);
262 // Check if this is default domain contact CRM-10482
263 if (CRM_Contact_BAO_Contact
::checkDomainContact($this->_contactID
)) {
264 $displayName .= ' (' . ts('default organization') . ')';
267 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
268 CRM_Utils_System
::setTitle(ts('Contribution from') . ' ' . $displayName);
273 function setDefaultValues() {
274 if ($this->_cdType
) {
275 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
278 $defaults = $this->_values
;
280 //set defaults for pledge payment.
282 $defaults['total_amount'] = CRM_Utils_Array
::value('scheduled_amount', $this->_pledgeValues
['pledgePayment']);
283 $defaults['honor_type_id'] = CRM_Utils_Array
::value('honor_type_id', $this->_pledgeValues
);
284 $defaults['honor_contact_id'] = CRM_Utils_Array
::value('honor_contact_id', $this->_pledgeValues
);
285 $defaults['financial_type_id'] = CRM_Utils_Array
::value('financial_type_id', $this->_pledgeValues
);
286 $defaults['currency'] = CRM_Utils_Array
::value('currency', $this->_pledgeValues
);
287 $defaults['option_type'] = 1;
291 if ($this->_action
& CRM_Core_Action
::DELETE
) {
296 $config = CRM_Core_Config
::singleton();
297 // set default country from config if no country set
298 if (!CRM_Utils_Array
::value("billing_country_id-{$this->_bltID}", $defaults)) {
299 $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
302 if (!CRM_Utils_Array
::value("billing_state_province_id-{$this->_bltID}", $defaults)) {
303 $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince
;
307 'first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}",
308 "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}",
309 "state_province-{$this->_bltID}", "country-{$this->_bltID}"
312 foreach ($names as $name) {
316 if ($this->_contactID
) {
317 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactID
, $fields, $defaults);
320 foreach ($names as $name) {
321 if (!empty($defaults[$name])) {
322 $defaults['billing_' . $name] = $defaults[$name];
326 // now fix all state country selectors
327 CRM_Core_BAO_Address
::fixAllStateSelects($this, $defaults);
331 $this->_contactID
= $defaults['contact_id'];
334 // Set $newCredit variable in template to control whether link to credit card mode is included
335 CRM_Core_Payment
::allowBackofficeCreditCard($this);
337 // fix the display of the monetary value, CRM-4038
338 if (isset($defaults['total_amount'])) {
339 $defaults['total_amount'] = CRM_Utils_Money
::format($defaults['total_amount'], NULL, '%a');
342 if (isset($defaults['non_deductible_amount'])) {
343 $defaults['non_deductible_amount'] = CRM_Utils_Money
::format($defaults['non_deductible_amount'], NULL, '%a');
346 if (isset($defaults['fee_amount'])) {
347 $defaults['fee_amount'] = CRM_Utils_Money
::format($defaults['fee_amount'], NULL, '%a');
350 if (isset($defaults['net_amount'])) {
351 $defaults['net_amount'] = CRM_Utils_Money
::format($defaults['net_amount'], NULL, '%a');
354 if ($this->_contributionType
) {
355 $defaults['financial_type_id'] = $this->_contributionType
;
358 if (CRM_Utils_Array
::value('is_test', $defaults)) {
359 $this->assign('is_test', TRUE);
362 if (isset($defaults['honor_contact_id'])) {
363 $honorDefault = $ids = array();
364 $this->_honorID
= $defaults['honor_contact_id'];
365 $honorType = CRM_Core_PseudoConstant
::honor();
367 'id' => $defaults['honor_contact_id'],
368 'contact_id' => $defaults['honor_contact_id'],
370 CRM_Contact_BAO_Contact
::retrieve($idParams, $honorDefault, $ids);
372 $defaults['honor_prefix_id'] = CRM_Utils_Array
::value('prefix_id', $honorDefault);
373 $defaults['honor_first_name'] = CRM_Utils_Array
::value('first_name', $honorDefault);
374 $defaults['honor_last_name'] = CRM_Utils_Array
::value('last_name', $honorDefault);
375 $defaults['honor_email'] = CRM_Utils_Array
::value('email', $honorDefault['email'][1]);
376 $defaults['honor_type'] = $honorType[$defaults['honor_type_id']];
379 $this->assign('showOption', TRUE);
380 // for Premium section
381 if ($this->_premiumID
) {
382 $this->assign('showOption', FALSE);
383 $options = isset($this->_options
[$this->_productDAO
->product_id
]) ?
$this->_options
[$this->_productDAO
->product_id
] : "";
385 $this->assign('showOption', TRUE);
387 $options_key = CRM_Utils_Array
::key($this->_productDAO
->product_option
, $options);
389 $defaults['product_name'] = array($this->_productDAO
->product_id
, trim($options_key));
392 $defaults['product_name'] = array($this->_productDAO
->product_id
);
394 if ($this->_productDAO
->fulfilled_date
) {
395 list($defaults['fulfilled_date']) = CRM_Utils_Date
::setDateDefaults($this->_productDAO
->fulfilled_date
);
399 if (isset($this->userEmail
)) {
400 $this->assign('email', $this->userEmail
);
403 if (CRM_Utils_Array
::value('is_pay_later', $defaults)) {
404 $this->assign('is_pay_later', TRUE);
406 $this->assign('contribution_status_id', CRM_Utils_Array
::value('contribution_status_id', $defaults));
408 $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date');
409 foreach ($dates as $key) {
410 if (CRM_Utils_Array
::value($key, $defaults)) {
411 list($defaults[$key],
412 $defaults[$key . '_time']
413 ) = CRM_Utils_Date
::setDateDefaults(CRM_Utils_Array
::value($key, $defaults),
419 if (!$this->_id
&& !CRM_Utils_Array
::value('receive_date', $defaults)) {
420 list($defaults['receive_date'],
421 $defaults['receive_date_time']
422 ) = CRM_Utils_Date
::setDateDefaults(NULL, 'activityDateTime');
425 $this->assign('receive_date', CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $defaults),
426 CRM_Utils_Array
::value('receive_date_time', $defaults)
428 $currency = CRM_Utils_Array
::value('currency', $defaults);
429 $this->assign('currency', $currency);
430 // Hack to get currency info to the js layer. CRM-11440
431 CRM_Utils_Money
::format(1);
432 $this->assign('currencySymbol', CRM_Utils_Array
::value($currency, CRM_Utils_Money
::$_currencySymbols));
433 $this->assign('totalAmount', CRM_Utils_Array
::value('total_amount', $defaults));
435 //inherit campaign from pledge.
436 if ($this->_ppID
&& CRM_Utils_Array
::value('campaign_id', $this->_pledgeValues
)) {
437 $defaults['campaign_id'] = $this->_pledgeValues
['campaign_id'];
440 $this->_defaults
= $defaults;
445 * Function to build the form
450 public function buildQuickForm() {
451 if ($this->_cdType
) {
452 CRM_Custom_Form_CustomData
::buildQuickForm($this);
456 // build price set form.
457 $buildPriceSet = FALSE;
458 if (empty($this->_lineItems
) &&
459 ($this->_priceSetId || CRM_Utils_Array
::value('price_set_id', $_POST))
461 $buildPriceSet = TRUE;
462 $getOnlyPriceSetElements = TRUE;
463 if (!$this->_priceSetId
) {
464 $this->_priceSetId
= $_POST['price_set_id'];
465 $getOnlyPriceSetElements = FALSE;
468 $this->set('priceSetId', $this->_priceSetId
);
469 CRM_Price_BAO_Set
::buildPriceSet($this);
471 // get only price set form elements.
472 if ($getOnlyPriceSetElements) {
476 // use to build form during form rule.
477 $this->assign('buildPriceSet', $buildPriceSet);
479 $showAdditionalInfo = FALSE;
482 $defaults = $this->_values
;
483 $additionalDetailFields = array(
487 'non_deductible_amount',
491 foreach ($additionalDetailFields as $key) {
492 if (!empty($defaults[$key])) {
493 $defaults['hidden_AdditionalDetail'] = 1;
498 $honorFields = array(
505 foreach ($honorFields as $key) {
506 if (!empty($defaults[$key])) {
507 $defaults['hidden_Honoree'] = 1;
512 //check for honoree pane.
513 if ($this->_ppID
&& CRM_Utils_Array
::value('honor_contact_id', $this->_pledgeValues
)) {
514 $defaults['hidden_Honoree'] = 1;
517 if ($this->_productDAO
) {
518 if ($this->_productDAO
->product_id
) {
519 $defaults['hidden_Premium'] = 1;
523 if ($this->_noteID
&&
524 isset($this->_values
['note'])
526 $defaults['hidden_AdditionalDetail'] = 1;
530 ts('Additional Details') => 'AdditionalDetail',
531 ts('Honoree Information') => 'Honoree'
534 //Add Premium pane only if Premium is exists.
535 $dao = new CRM_Contribute_DAO_Product();
538 if ($dao->find(TRUE)) {
539 $paneNames[ts('Premium Information')] = 'Premium';
544 if (CRM_Utils_Array
::value('payment_type', $this->_processors
) & CRM_Core_Payment
::PAYMENT_TYPE_DIRECT_DEBIT
546 $ccPane = array(ts('Direct Debit Information') => 'DirectDebit');
549 $ccPane = array(ts('Credit Card Information') => 'CreditCard');
552 if (is_array($ccPane)) {
553 $paneNames = array_merge($ccPane, $paneNames);
556 $buildRecurBlock = FALSE;
557 foreach ($paneNames as $name => $type) {
558 $urlParams = "snippet=4&formType={$type}";
560 $urlParams .= "&mode={$this->_mode}";
564 if ($type == 'CreditCard' ||
565 $type == 'DirectDebit'
570 $allPanes[$name] = array(
571 'url' => CRM_Utils_System
::url('civicrm/contact/view/contribution', $urlParams),
576 // see if we need to include this paneName in the current form
577 if ($this->_formType
== $type ||
578 CRM_Utils_Array
::value("hidden_{$type}", $_POST) ||
579 CRM_Utils_Array
::value("hidden_{$type}", $defaults)
581 $showAdditionalInfo = TRUE;
582 $allPanes[$name]['open'] = 'true';
585 if ($type == 'CreditCard') {
586 $buildRecurBlock = TRUE;
587 $this->add('hidden', 'hidden_CreditCard', 1);
588 CRM_Core_Payment_Form
::buildCreditCard($this, TRUE);
590 elseif ($type == 'DirectDebit') {
591 $buildRecurBlock = TRUE;
592 $this->add('hidden', 'hidden_DirectDebit', 1);
593 CRM_Core_Payment_Form
::buildDirectDebit($this, TRUE);
596 eval('CRM_Contribute_Form_AdditionalInfo::build' . $type . '( $this );');
599 if (empty($this->_recurPaymentProcessors
)) {
600 $buildRecurBlock = FALSE;
602 if ($buildRecurBlock) {
603 CRM_Contribute_Form_Contribution_Main
::buildRecur($this);
604 $this->setDefaults(array('is_recur' => 0));
606 $this->assign('buildRecurBlock', $buildRecurBlock);
607 $qfKey = $this->controller
->_key
;
608 $this->assign('qfKey', $qfKey);
609 $this->assign('allPanes', $allPanes);
610 $this->assign('showAdditionalInfo', $showAdditionalInfo);
612 if ($this->_formType
) {
613 $this->assign('formType', $this->_formType
);
617 $this->applyFilter('__ALL__', 'trim');
619 if ($this->_action
& CRM_Core_Action
::DELETE
) {
620 $this->addButtons(array(
623 'name' => ts('Delete'),
624 'spacing' => ' ',
629 'name' => ts('Cancel')
636 //need to assign custom data type and subtype to the template
637 $this->assign('customDataType', 'Contribution');
638 $this->assign('customDataSubType', $this->_contributionType
);
639 $this->assign('entityID', $this->_id
);
641 if ($this->_context
== 'standalone') {
642 CRM_Contact_Form_NewContact
::buildQuickForm($this);
645 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Contribution');
647 $financialType = $this->add('select', 'financial_type_id',
648 ts('Financial Type'),
649 array('' => ts('- select -')) + CRM_Contribute_PseudoConstant
::financialType(),
651 array('onChange' => "CRM.buildCustomData( 'Contribution', this.value );")
655 $paymentInstrument = $this->add('select', 'payment_instrument_id',
657 array('' => ts('- select -')) + CRM_Contribute_PseudoConstant
::paymentInstrument(),
658 FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
662 $trxnId = $this->add('text', 'trxn_id', ts('Transaction ID'), $attributes['trxn_id']);
664 //add receipt for offline contribution
665 $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
667 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails
);
669 $status = CRM_Contribute_PseudoConstant
::contributionStatus();
671 // suppressing contribution statuses that are NOT relevant to pledges (CRM-5169)
672 $statusName = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
679 unset($status[CRM_Utils_Array
::key($suppress, $statusName)]);
682 elseif ((!$this->_ppID
&& $this->_id
) ||
!$this->_id
) {
687 unset($status[CRM_Utils_Array
::key($suppress, $statusName)]);
691 $contributionStatus = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id
, 'contribution_status_id');
692 $name = CRM_Utils_Array
::value($contributionStatus, $statusName);
697 unset($status[CRM_Utils_Array
::key('Pending', $statusName)]);
698 unset($status[CRM_Utils_Array
::key('Failed', $statusName)]);
701 unset($status[CRM_Utils_Array
::key('Refunded', $statusName)]);
710 unset($status[CRM_Utils_Array
::key($suppress, $statusName)]);
715 unset($status[CRM_Utils_Array
::key('Refunded', $statusName)]);
718 $this->add('select', 'contribution_status_id',
719 ts('Contribution Status'),
725 $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
727 if ($this->_online
) {
728 $this->assign('hideCalender', TRUE);
730 $checkNumber = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']);
732 $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
733 $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
735 $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
738 if ($buildRecurBlock) {
739 $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
741 $element = $this->add('select',
742 'payment_processor_id',
743 ts('Payment Processor'),
749 if ($this->_online
) {
753 if (empty($this->_lineItems
)) {
754 $buildPriceSet = FALSE;
755 $priceSets = CRM_Price_BAO_Set
::getAssoc(FALSE, 'CiviContribute');
756 if (!empty($priceSets) && !$this->_ppID
) {
757 $buildPriceSet = TRUE;
760 // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
761 // and if we already have line items for that participant. CRM-5095
762 if ($buildPriceSet && $this->_id
) {
763 $componentDetails = CRM_Contribute_BAO_Contribution
::getComponentDetails($this->_id
);
764 $pledgePaymentId = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_PledgePayment',
769 if ($pledgePaymentId) {
770 $buildPriceSet = FALSE;
772 if ($participantID = CRM_Utils_Array
::value('participant', $componentDetails)) {
773 $participantLI = CRM_Price_BAO_LineItem
::getLineItems($participantID);
774 if (!CRM_Utils_System
::isNull($participantLI)) {
775 $buildPriceSet = FALSE;
780 $hasPriceSets = FALSE;
781 if ($buildPriceSet) {
782 $hasPriceSets = TRUE;
783 $element = $this->add('select', 'price_set_id', ts('Choose price set'),
785 '' => ts('Choose price set')
787 NULL, array('onchange' => "buildAmount( this.value );")
789 if ($this->_online
&& !($this->_action
& CRM_Core_Action
::UPDATE
)) {
793 $this->assign('hasPriceSets', $hasPriceSets);
794 $currencyFreeze = FALSE;
795 if (!($this->_action
& CRM_Core_Action
::UPDATE
)) {
796 if ($this->_online ||
$this->_ppID
) {
797 $attributes['total_amount'] = array_merge($attributes['total_amount'], array(
799 'style' => "background-color:#EBECE4"
801 $optionTypes = array(
802 '1' => ts('Adjust Pledge Payment Schedule?'),
803 '2' => ts('Adjust Total Pledge Amount?'),
805 $this->addRadio('option_type',
811 $currencyFreeze = TRUE;
815 $totalAmount = $this->addMoney('total_amount',
817 ($hasPriceSets) ?
FALSE : TRUE,
818 $attributes['total_amount'],
819 TRUE, 'currency', NULL, $currencyFreeze
823 $this->add('text', 'source', ts('Source'), CRM_Utils_Array
::value('source', $attributes));
825 //CRM-7362 --add campaigns.
826 CRM_Campaign_BAO_Campaign
::addCampaign($this, CRM_Utils_Array
::value('campaign_id', $this->_values
));
828 // CRM-7368 allow user to set or edit PCP link for contributions
829 $siteHasPCPs = CRM_Contribute_PseudoConstant
::pcPage();
830 if (!CRM_Utils_Array
::crmIsEmptyArray($siteHasPCPs)) {
831 $this->assign('siteHasPCPs', 1);
832 $pcpDataUrl = CRM_Utils_System
::url('civicrm/ajax/rest',
833 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1',
836 $this->assign('pcpDataUrl', $pcpDataUrl);
837 $this->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page'));
838 $this->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id'));
839 $this->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
840 $this->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
841 $this->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
844 // If we have a contact for this contribution, pass cid= to the dataUrl to exclude current contact from autocomplete results
845 if ($this->_contactID
) {
846 $dataUrl = CRM_Utils_System
::url('civicrm/ajax/rest',
847 "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1&context=softcredit&cid={$this->_contactID}",
851 $dataUrl = CRM_Utils_System
::url('civicrm/ajax/rest',
852 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1&context=softcredit',
856 $this->assign('dataUrl', $dataUrl);
857 $this->addElement('text', 'soft_credit_to', ts('Soft Credit To'));
858 // Tell tpl to hide Soft Credit field if contribution is linked directly to a PCP Page
859 if (CRM_Utils_Array
::value('pcp_made_through_id', $this->_values
)) {
860 $this->assign('pcpLinked', 1);
862 $this->addElement('hidden', 'soft_contact_id', '', array('id' => 'soft_contact_id'));
866 $js = array('onclick' => "return verify( );");
869 $mailingInfo = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
,
872 $this->assign('outBound_option', $mailingInfo['outBound_option']);
874 $this->addButtons(array(
877 'name' => ts('Save'),
883 'name' => ts('Save and New'),
889 'name' => ts('Cancel')
894 // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
895 // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
896 if ($this->_id
&& $this->_values
['contribution_status_id'] == array_search('Cancelled', $statusName)) {
898 $totalAmount->freeze();
900 $checkNumber->freeze();
901 $paymentInstrument->freeze();
903 $financialType->freeze();
906 $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
908 if ($this->_action
& CRM_Core_Action
::VIEW
) {
916 * @param array $fields the input form values
917 * @param array $files the uploaded files if any
918 * @param array $options additional user data
920 * @return true if no errors, else array of errors
924 static function formRule($fields, $files, $self) {
927 //check if contact is selected in standalone mode
928 if (isset($fields['contact_select_id'][1]) && !$fields['contact_select_id'][1]) {
929 $errors['contact[1]'] = ts('Please select a contact or create new contact');
932 if (isset($fields['honor_type_id'])) {
933 if (!((CRM_Utils_Array
::value('honor_first_name', $fields) &&
934 CRM_Utils_Array
::value('honor_last_name', $fields)
936 CRM_Utils_Array
::value('honor_email', $fields)
939 $errors['honor_first_name'] = ts('Honor First Name and Last Name OR an email should be set.');
943 //check for Credit Card Contribution.
945 if (empty($fields['payment_processor_id'])) {
946 $errors['payment_processor_id'] = ts('Payment Processor is a required field.');
950 // do the amount validations.
951 if (!CRM_Utils_Array
::value('total_amount', $fields) && empty($self->_lineItems
)) {
952 if ($priceSetId = CRM_Utils_Array
::value('price_set_id', $fields)) {
953 CRM_Price_BAO_Field
::priceSetValidation($priceSetId, $fields, $errors);
957 // if honor roll fields are populated but no PCP is selected
958 if (!CRM_Utils_Array
::value('pcp_made_through_id', $fields)) {
959 if (CRM_Utils_Array
::value('pcp_display_in_roll', $fields) ||
960 CRM_Utils_Array
::value('pcp_roll_nickname', $fields) ||
961 CRM_Utils_Array
::value('pcp_personal_note', $fields)
963 $errors['pcp_made_through'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.');
967 if (CRM_Utils_Array
::value('total_amount', $fields) && (CRM_Utils_Array
::value('net_amount', $fields) || CRM_Utils_Array
::value('fee_amount', $fields))){
968 $sum = CRM_Utils_Rule
::cleanMoney($fields['net_amount']) + CRM_Utils_Rule
::cleanMoney($fields['fee_amount']);
969 if (CRM_Utils_Rule
::cleanMoney($fields['total_amount']) != $sum) {
970 $errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount');
973 //form rule for status http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
974 if ($self->_id
&& $self->_values
['contribution_status_id'] != $fields['contribution_status_id']) {
975 CRM_Contribute_BAO_Contribution
::checkStatusValidation($self->_values
, $fields, $errors);
978 //FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
979 if (CRM_Utils_Array
::value('fee_amount', $fields)) {
980 $financialAccount = array();
981 CRM_Core_PseudoConstant
::populate($financialAccount,
982 'CRM_Financial_DAO_EntityFinancialAccount',
984 $retrieve = 'financial_account_id',
986 " account_relationship = 5 AND entity_id = {$fields['financial_type_id']} ");
987 if (!current($financialAccount)) {
988 $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for this Financial Type");
995 * Function to process the form
1001 public function postProcess() {
1002 $session = CRM_Core_Session
::singleton();
1003 if ($this->_action
& CRM_Core_Action
::DELETE
) {
1004 CRM_Contribute_BAO_Contribution
::deleteContribution($this->_id
);
1005 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1006 "reset=1&cid={$this->_contactID}&selectedChild=contribute"
1011 // get the submitted form values.
1012 $submittedValues = $this->controller
->exportValues($this->_name
);
1013 if (CRM_Utils_Array
::value('price_set_id', $submittedValues) && $this->_action
& CRM_Core_Action
::UPDATE
) {
1014 $line = CRM_Price_BAO_LineItem
::getLineItems($this->_id
, 'contribution');
1015 $lineID = key($line);
1016 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array
::value('price_field_id', $line[$lineID]), 'price_set_id');
1017 $quickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config');
1019 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_contribution');
1023 // process price set and get total amount and line items.
1024 $lineItem = array();
1025 $priceSetId = $pId = NULL;
1026 $priceSetId = CRM_Utils_Array
::value('price_set_id', $submittedValues);
1027 if (empty($priceSetId) && !$this->_id
) {
1028 $this->_priceSetId
= $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Set', 'default_contribution_amount', 'id', 'name');
1029 $this->_priceSet
= current(CRM_Price_BAO_Set
::getSetDetail($priceSetId));
1030 $fieldID = key($this->_priceSet
['fields']);
1031 $fieldValueId = key($this->_priceSet
['fields'][$fieldID]['options']);
1032 $this->_priceSet
['fields'][$fieldID]['options'][$fieldValueId]['amount'] = $submittedValues['total_amount'];
1033 $submittedValues['price_' . $fieldID] = 1;
1037 CRM_Price_BAO_Set
::processAmount($this->_priceSet
['fields'],
1038 $submittedValues, $lineItem[$priceSetId]);
1040 $submittedValues['total_amount'] = CRM_Utils_Array
::value('amount', $submittedValues);
1044 $pId = ($this->_compId
&& $this->_context
== 'participant') ?
$this->_compId
: CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id
, 'participant_id', 'contribution_id');
1046 if (!$priceSetId && CRM_Utils_Array
::value('total_amount', $submittedValues) && $this->_id
) {
1047 // 10117 update th line items for participants
1049 $entityTable = 'participant';
1051 $participantParams = array(
1052 'fee_amount' => $submittedValues['total_amount'],
1055 CRM_Event_BAO_Participant
::add($participantParams);
1056 if (empty($this->_lineItems
)) {
1057 $this->_lineItems
= CRM_Price_BAO_LineItem
::getLineItems($entityID, 'participant',1);
1060 $entityTable = 'contribution';
1061 $entityID = $this->_id
;
1064 $lineItems = CRM_Price_BAO_LineItem
::getLineItems($entityID, $entityTable);
1065 $itemId = key($lineItems);
1067 if ($itemId && CRM_Utils_Array
::value('price_field_id', $lineItems[$itemId])) {
1068 $fieldType = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Field', $lineItems[$itemId]['price_field_id'], 'html_type');
1070 $lineItems[$itemId]['unit_price'] = $lineItems[$itemId]['line_total'] = CRM_Utils_Rule
::cleanMoney(CRM_Utils_Array
::value('total_amount', $submittedValues));
1071 $lineItems[$itemId]['id'] = $itemId;
1072 // 10117 update th line items for participants
1073 $this->_priceSetId
= CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Field', $lineItems[$itemId]['price_field_id'], 'price_set_id');
1074 $lineItem[$this->_priceSetId
] = $lineItems;
1077 if ($this->_priceSetId
&& CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId
, 'is_quick_config')) {
1080 //CRM-11529 for quick config backoffice transactions
1081 //when financial_type_id is passed in form, update the
1082 //lineitems with the financial type selected in form
1083 if ($isQuickConfig && CRM_Utils_Array
::value('financial_type_id', $submittedValues)
1084 && CRM_Utils_Array
::value($this->_priceSetId
, $lineItem)) {
1085 foreach ($lineItem[$this->_priceSetId
] as &$values) {
1086 $values['financial_type_id'] = $submittedValues['financial_type_id'];
1090 if (!isset($submittedValues['total_amount'])) {
1091 $submittedValues['total_amount'] = CRM_Utils_Array
::value('total_amount', $this->_values
);
1093 $this->assign('lineItem', !empty($lineItem) && !$isQuickConfig ?
$lineItem : FALSE);
1095 if (CRM_Utils_Array
::value('soft_credit_to', $submittedValues)) {
1096 $submittedValues['soft_credit_to'] = $submittedValues['soft_contact_id'];
1099 // set the contact, when contact is selected
1100 if (CRM_Utils_Array
::value('contact_select_id', $submittedValues)) {
1101 $this->_contactID
= $submittedValues['contact_select_id'][1];
1104 $config = CRM_Core_Config
::singleton();
1106 //Credit Card Contribution.
1108 $this->processCreditCard($submittedValues, $config, $session, $pId, $lineItem);
1111 //Offline Contribution.
1112 $submittedValues = $this->unsetCreditCardFields($submittedValues);
1114 // get the required field value only.
1115 $formValues = $submittedValues;
1116 $params = $ids = array();
1118 $params['contact_id'] = $this->_contactID
;
1120 $params['currency'] = $this->getCurrency($submittedValues);
1123 'financial_type_id',
1124 'contribution_status_id',
1125 'payment_instrument_id',
1130 'pcp_made_through_id',
1131 'pcp_display_in_roll',
1132 'pcp_roll_nickname',
1133 'pcp_personal_note',
1135 foreach ($fields as $f) {
1136 $params[$f] = CRM_Utils_Array
::value($f, $formValues);
1139 if ($softID = CRM_Utils_Array
::value('softID', $this->_values
)) {
1140 $params['softID'] = $softID;
1142 //if priceset is used, no need to cleanup money
1145 $params['skipCleanMoney'] = 1;
1154 foreach ($dates as $d) {
1155 $params[$d] = CRM_Utils_Date
::processDate($formValues[$d], $formValues[$d . '_time'], TRUE);
1158 if (CRM_Utils_Array
::value('is_email_receipt', $formValues)) {
1159 $params['receipt_date'] = date("Y-m-d");
1162 if ($params['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Cancelled', 'name')
1163 ||
$params['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Refunded', 'name')) {
1164 if (CRM_Utils_System
::isNull(CRM_Utils_Array
::value('cancel_date', $params))) {
1165 $params['cancel_date'] = date("Y-m-d");
1169 $params['cancel_date'] = $params['cancel_reason'] = 'null';
1172 // Set is_pay_later flag for back-office offline Pending status contributions CRM-8996
1173 if ($params['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1174 $params['is_pay_later'] = 1;
1177 $ids['contribution'] = $params['id'] = $this->_id
;
1179 //Add Additional common information to formatted params
1180 CRM_Contribute_Form_AdditionalInfo
::postProcessCommon($formValues, $params, $this);
1182 $params['contribution_mode'] = 'participant';
1183 $params['participant_id'] = $pId;
1184 $params['skipLineItem'] = 1;
1186 $params['line_item'] = $lineItem;
1187 $params['payment_processor_id'] = $params['payment_processor'] = CRM_Utils_Array
::value('id', $this->_paymentProcessor
);
1188 //create contribution.
1189 if ($isQuickConfig) {
1190 $params['is_quick_config'] = 1;
1194 // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it.
1195 if (isset($params['non_deductible_amount']) && (!empty($params['non_deductible_amount']))) {
1196 $params['non_deductible_amount'] = $params['non_deductible_amount'];
1198 // if non_deductible_amount does NOT exist - then calculate it depending on:
1199 // $ContributionType->is_deductible and whether there is a product (premium).
1201 $contributionType = new CRM_Financial_DAO_FinancialType();
1202 $contributionType->id
= $params['financial_type_id'];
1203 if (!$contributionType->find(TRUE)) {
1204 CRM_Core_Error
::fatal('Could not find a system table');
1206 if ($contributionType->is_deductible
) {
1208 if (isset($formValues['product_name'][0])) {
1209 $selectProduct = $formValues['product_name'][0];
1211 // if there is a product - compare the value to the contribution amount
1212 if (isset($selectProduct))
1214 $productDAO = new CRM_Contribute_DAO_Product();
1215 $productDAO->id
= $selectProduct;
1216 $productDAO->find(TRUE);
1217 // product value exceeds contribution amount
1218 if ($params['total_amount'] < $productDAO->price
) {
1219 $params['non_deductible_amount'] = $params['total_amount'];
1221 // product value does NOT exceed contribution amount
1223 $params['non_deductible_amount'] = $productDAO->price
;
1226 // contribution is deductible - but there is no product
1228 $params['non_deductible_amount'] = '0.00';
1231 // contribution is NOT deductible
1233 $params['non_deductible_amount'] = $params['total_amount'];
1237 $contribution = CRM_Contribute_BAO_Contribution
::create($params, $ids);
1239 // process associated membership / participant, CRM-4395
1240 $relatedComponentStatusMsg = NULL;
1241 if ($contribution->id
&& $this->_action
& CRM_Core_Action
::UPDATE
) {
1242 $relatedComponentStatusMsg = $this->updateRelatedComponent($contribution->id
,
1243 $contribution->contribution_status_id
,
1244 CRM_Utils_Array
::value('contribution_status_id',
1251 if ($contribution->id
&& isset($formValues['note'])) {
1252 CRM_Contribute_Form_AdditionalInfo
::processNote($formValues, $this->_contactID
, $contribution->id
, $this->_noteID
);
1256 if ($contribution->id
&& isset($formValues['product_name'][0])) {
1257 CRM_Contribute_Form_AdditionalInfo
::processPremium($formValues, $contribution->id
,
1258 $this->_premiumID
, $this->_options
1262 //send receipt mail.
1263 if ($contribution->id
&& CRM_Utils_Array
::value('is_email_receipt', $formValues)) {
1264 $formValues['contact_id'] = $this->_contactID
;
1265 $formValues['contribution_id'] = $contribution->id
;
1267 // to get 'from email id' for send receipt
1268 $this->fromEmailId
= $formValues['from_email_address'];
1269 $sendReceipt = CRM_Contribute_Form_AdditionalInfo
::emailReceipt($this, $formValues);
1272 $pledgePaymentId = CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_PledgePayment',
1278 //update pledge payment status.
1279 if ((($this->_ppID
&& $contribution->id
) && $this->_action
& CRM_Core_Action
::ADD
) ||
1280 (($pledgePaymentId) && $this->_action
& CRM_Core_Action
::UPDATE
)
1284 //store contribution id in payment record.
1285 CRM_Core_DAO
::setFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_ppID
, 'contribution_id', $contribution->id
);
1288 $this->_ppID
= CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_PledgePayment',
1293 $this->_pledgeID
= CRM_Core_DAO
::getFieldValue('CRM_Pledge_DAO_PledgePayment',
1300 $adjustTotalAmount = FALSE;
1301 if (CRM_Utils_Array
::value('option_type', $formValues) == 2) {
1302 $adjustTotalAmount = TRUE;
1305 $updatePledgePaymentStatus = FALSE;
1306 //do only if either the status or the amount has changed
1307 if ($this->_action
& CRM_Core_Action
::ADD
) {
1308 $updatePledgePaymentStatus = TRUE;
1310 elseif ($this->_action
& CRM_Core_Action
::UPDATE
&& (($this->_defaults
['contribution_status_id'] != $formValues['contribution_status_id']) ||
1311 ($this->_defaults
['total_amount'] != $formValues['total_amount']))
1313 $updatePledgePaymentStatus = TRUE;
1316 if ($updatePledgePaymentStatus) {
1317 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($this->_pledgeID
,
1318 array($this->_ppID
),
1319 $contribution->contribution_status_id
,
1321 $contribution->total_amount
,
1327 $statusMsg = ts('The contribution record has been saved.');
1328 if (CRM_Utils_Array
::value('is_email_receipt', $formValues) && $sendReceipt) {
1329 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
1332 if ($relatedComponentStatusMsg) {
1333 $statusMsg .= ' ' . $relatedComponentStatusMsg;
1336 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1337 //Offline Contribution ends.
1339 $buttonName = $this->controller
->getButtonName();
1340 if ($this->_context
== 'standalone') {
1341 if ($buttonName == $this->getButtonName('upload', 'new')) {
1342 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contribute/add',
1343 'reset=1&action=add&context=standalone'
1347 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1348 "reset=1&cid={$this->_contactID}&selectedChild=contribute"
1352 elseif ($this->_context
== 'contribution' && $this->_mode
&& $buttonName == $this->getButtonName('upload', 'new')) {
1353 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/contribution',
1354 "reset=1&action=add&context={$this->_context}&cid={$this->_contactID}&mode={$this->_mode}"
1357 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1358 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/contribution',
1359 "reset=1&action=add&context={$this->_context}&cid={$this->_contactID}"
1364 public function processCreditCard($submittedValues, $config, $session, $pId, $lineItem) {
1365 $unsetParams = array(
1367 'payment_instrument_id',
1368 'contribution_status_id',
1372 foreach ($unsetParams as $key) {
1373 if (isset($submittedValues[$key])) {
1374 unset($submittedValues[$key]);
1378 // CRM-12680 set $_lineItem if its not set
1379 if (empty($this->_lineItem
) && !empty($lineItem)) {
1380 $this->_lineItem
= $lineItem;
1383 //Get the rquire fields value only.
1384 $params = $this->_params
= $submittedValues;
1386 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1390 //get the payment processor id as per mode.
1391 $this->_params
['payment_processor'] = $params['payment_processor_id'] =
1392 $this->_params
['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor
['id'];
1394 $now = date('YmdHis');
1397 // we need to retrieve email address
1398 if ($this->_context
== 'standalone' && CRM_Utils_Array
::value('is_email_receipt', $submittedValues)) {
1399 list($this->userDisplayName
,
1401 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactID
);
1402 $this->assign('displayName', $this->userDisplayName
);
1405 //set email for primary location.
1406 $fields['email-Primary'] = 1;
1407 $params['email-Primary'] = $this->userEmail
;
1409 // now set the values for the billing location.
1410 foreach ($this->_fields
as $name => $dontCare) {
1414 // also add location name to the array
1415 $params["address_name-{$this->_bltID}"] = CRM_Utils_Array
::value('billing_first_name', $params) . ' ' . CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array
::value('billing_last_name', $params);
1416 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1417 $fields["address_name-{$this->_bltID}"] = 1;
1419 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
1424 $nameFields = array('first_name', 'middle_name', 'last_name');
1425 foreach ($nameFields as $name) {
1427 if (array_key_exists("billing_$name", $params)) {
1428 $params[$name] = $params["billing_{$name}"];
1429 $params['preserveDBName'] = TRUE;
1433 if (CRM_Utils_Array
::value('source', $params)) {
1434 unset($params['source']);
1436 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields,
1442 // add all the additioanl payment params we need
1443 $this->_params
["state_province-{$this->_bltID}"] = $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
1444 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1446 if ($this->_paymentProcessor
['payment_type'] & CRM_Core_Payment
::PAYMENT_TYPE_CREDIT_CARD
) {
1447 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1448 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1450 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1451 $this->_params
['amount'] = $this->_params
['total_amount'];
1452 $this->_params
['amount_level'] = 0;
1453 $this->_params
['currencyID'] = CRM_Utils_Array
::value('currency',
1455 $config->defaultCurrency
1457 $this->_params
['payment_action'] = 'Sale';
1458 if (CRM_Utils_Array
::value('receive_date', $this->_params
)) {
1459 $this->_params
['receive_date'] = CRM_Utils_Date
::processDate($this->_params
['receive_date'], $this->_params
['receive_date_time']);
1462 if (CRM_Utils_Array
::value('soft_credit_to', $params)) {
1463 $this->_params
['soft_credit_to'] = $params['soft_credit_to'];
1464 $this->_params
['pcp_made_through_id'] = $params['pcp_made_through_id'];
1467 $this->_params
['pcp_display_in_roll'] = CRM_Utils_Array
::value('pcp_display_in_roll', $params);
1468 $this->_params
['pcp_roll_nickname'] = CRM_Utils_Array
::value('pcp_roll_nickname', $params);
1469 $this->_params
['pcp_personal_note'] = CRM_Utils_Array
::value('pcp_personal_note', $params);
1471 //Add common data to formatted params
1472 CRM_Contribute_Form_AdditionalInfo
::postProcessCommon($params, $this->_params
, $this);
1474 if (empty($this->_params
['invoice_id'])) {
1475 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1478 $this->_params
['invoiceID'] = $this->_params
['invoice_id'];
1481 // at this point we've created a contact and stored its address etc
1482 // all the payment processors expect the name and address to be in the
1483 // so we copy stuff over to first_name etc.
1484 $paymentParams = $this->_params
;
1485 $paymentParams['contactID'] = $this->_contactID
;
1486 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1488 $contributionType = new CRM_Financial_DAO_FinancialType();
1489 $contributionType->id
= $params['financial_type_id'];
1490 if (!$contributionType->find(TRUE)) {
1491 CRM_Core_Error
::fatal('Could not find a system table');
1494 // add some financial type details to the params list
1495 // if folks need to use it
1496 $paymentParams['contributionType_name'] = $this->_params
['contributionType_name'] = $contributionType->name
;
1497 $paymentParams['contributionPageID'] = NULL;
1498 if (CRM_Utils_Array
::value('is_email_receipt', $this->_params
)) {
1499 $paymentParams['email'] = $this->userEmail
;
1500 $paymentParams['is_email_receipt'] = 1;
1503 $paymentParams['is_email_receipt'] = 0;
1504 $this->_params
['is_email_receipt'] = 0;
1506 if (CRM_Utils_Array
::value('receive_date', $this->_params
)) {
1507 $paymentParams['receive_date'] = $this->_params
['receive_date'];
1509 if (CRM_Utils_Array
::value('receive_date', $this->_params
)) {
1510 $paymentParams['receive_date'] = $this->_params
['receive_date'];
1515 // For recurring contribution, create Contribution Record first.
1516 // Contribution ID, Recurring ID and Contact ID needed
1517 // When we get a callback from the payment processor, CRM-7115
1518 if (CRM_Utils_Array
::value('is_recur', $paymentParams)) {
1519 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processContribution($this,
1528 $paymentParams['contributionID'] = $contribution->id
;
1529 $paymentParams['contributionTypeID'] = $contribution->financial_type_id
;
1530 $paymentParams['contributionPageID'] = $contribution->contribution_page_id
;
1531 $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id
;
1534 if ($paymentParams['amount'] > 0.0) {
1535 // force a reget of the payment processor in case the form changed it, CRM-7179
1536 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this, TRUE);
1537 $result = $payment->doDirectPayment($paymentParams);
1540 if (is_a($result, 'CRM_Core_Error')) {
1541 //make sure to cleanup db for recurring case.
1542 if (CRM_Utils_Array
::value('contributionID', $paymentParams)) {
1543 CRM_Core_Error
::debug_log_message(CRM_Core_Error
::getMessages($result) . "contact id={$this->_contactID} (deleting contribution {$paymentParams['contributionID']}");
1544 CRM_Contribute_BAO_Contribution
::deleteContribution($paymentParams['contributionID']);
1546 if (CRM_Utils_Array
::value('contributionRecurID', $paymentParams)) {
1547 CRM_Core_Error
::debug_log_message(CRM_Core_Error
::getMessages($result) . "contact id={$this->_contactID} (deleting recurring contribution {$paymentParams['contributionRecurID']}");
1548 CRM_Contribute_BAO_ContributionRecur
::deleteRecurContribution($paymentParams['contributionRecurID']);
1551 //set the contribution mode.
1552 $urlParams = "action=add&cid={$this->_contactID}";
1554 $urlParams .= "&mode={$this->_mode}";
1556 if (!empty($this->_ppID
)) {
1557 $urlParams .= "&context=pledge&ppid={$this->_ppID}";
1559 CRM_Core_Error
::displaySessionError($result);
1560 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/contribution', $urlParams));
1564 $this->_params
= array_merge($this->_params
, $result);
1567 $this->_params
['receive_date'] = $now;
1569 if (CRM_Utils_Array
::value('is_email_receipt', $this->_params
)) {
1570 $this->_params
['receipt_date'] = $now;
1573 $this->_params
['receipt_date'] = CRM_Utils_Date
::processDate($this->_params
['receipt_date'],
1574 $params['receipt_date_time'], TRUE
1578 $this->set('params', $this->_params
);
1579 $this->assign('trxn_id', $result['trxn_id']);
1580 $this->assign('receive_date', $this->_params
['receive_date']);
1582 // result has all the stuff we need
1583 // lets archive it to a financial transaction
1584 if ($contributionType->is_deductible
) {
1585 $this->assign('is_deductible', TRUE);
1586 $this->set('is_deductible', TRUE);
1589 // set source if not set
1590 if (empty($this->_params
['source'])) {
1591 $userID = $session->get('userID');
1592 $userSortName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $userID,
1595 $this->_params
['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
1598 // build custom data getFields array
1599 $customFieldsContributionType = CRM_Core_BAO_CustomField
::getFields('Contribution', FALSE, FALSE,
1600 CRM_Utils_Array
::value('financial_type_id', $params)
1602 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsContributionType,
1603 CRM_Core_BAO_CustomField
::getFields('Contribution', FALSE, FALSE, NULL, NULL, TRUE)
1605 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1612 if (!CRM_Utils_Array
::value('is_recur', $paymentParams)) {
1613 $contribution = CRM_Contribute_Form_Contribution_Confirm
::processContribution($this,
1622 //send receipt mail.
1623 if ($contribution->id
&&
1624 CRM_Utils_Array
::value('is_email_receipt', $this->_params
)
1626 $this->_params
['trxn_id'] = CRM_Utils_Array
::value('trxn_id', $result);
1627 $this->_params
['contact_id'] = $this->_contactID
;
1628 $this->_params
['contribution_id'] = $contribution->id
;
1629 $sendReceipt = CRM_Contribute_Form_AdditionalInfo
::emailReceipt($this, $this->_params
, TRUE);
1633 if ($contribution->id
&& isset($params['note'])) {
1634 CRM_Contribute_Form_AdditionalInfo
::processNote($params, $contactID, $contribution->id
, NULL);
1637 if ($contribution->id
&& isset($params['product_name'][0])) {
1638 CRM_Contribute_Form_AdditionalInfo
::processPremium($params, $contribution->id
, NULL, $this->_options
);
1641 //update pledge payment status.
1642 if ($this->_ppID
&& $contribution->id
) {
1643 //store contribution id in payment record.
1644 CRM_Core_DAO
::setFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_ppID
, 'contribution_id', $contribution->id
);
1646 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($this->_pledgeID
,
1647 array($this->_ppID
),
1648 $contribution->contribution_status_id
,
1650 $contribution->total_amount
1654 if ($contribution->id
) {
1655 $statusMsg = ts('The contribution record has been processed.');
1656 if (CRM_Utils_Array
::value('is_email_receipt', $this->_params
) && $sendReceipt) {
1657 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
1659 CRM_Core_Session
::setStatus($statusMsg, ts('Complete'), 'success');