3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
35 * Form for thank-you / success page - 3rd step of online contribution process.
37 class CRM_Contribute_Form_Contribution_ThankYou
extends CRM_Contribute_Form_ContributionBase
{
40 * Membership price set status.
43 public $_useForMember;
46 * Tranxaaction Id of the current contribution
52 * Set variables up before form is built.
54 public function preProcess() {
57 $this->_params
= $this->get('params');
58 $this->_lineItem
= $this->get('lineItem');
59 $this->_useForMember
= $this->get('useForMember');
60 $is_deductible = $this->get('is_deductible');
61 $this->assign('is_deductible', $is_deductible);
62 $this->assign('thankyou_title', CRM_Utils_Array
::value('thankyou_title', $this->_values
));
63 $this->assign('thankyou_text', CRM_Utils_Array
::value('thankyou_text', $this->_values
));
64 $this->assign('thankyou_footer', CRM_Utils_Array
::value('thankyou_footer', $this->_values
));
65 $this->assign('max_reminders', CRM_Utils_Array
::value('max_reminders', $this->_values
));
66 $this->assign('initial_reminder_day', CRM_Utils_Array
::value('initial_reminder_day', $this->_values
));
67 CRM_Utils_System
::setTitle(CRM_Utils_Array
::value('thankyou_title', $this->_values
));
68 // Make the contributionPageID available to the template
69 $this->assign('contributionPageID', $this->_id
);
70 $this->assign('isShare', $this->_values
['is_share']);
72 $this->_params
['is_pay_later'] = $this->get('is_pay_later');
73 $this->assign('is_pay_later', $this->_params
['is_pay_later']);
74 if ($this->_params
['is_pay_later']) {
75 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
77 $this->assign('is_for_organization', CRM_Utils_Array
::value('is_for_organization', $this->_params
));
81 * Overwrite action, since we are only showing elements in frozen mode
82 * no help display needed
86 public function getAction() {
87 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
88 return CRM_Core_Action
::VIEW | CRM_Core_Action
::PREVIEW
;
91 return CRM_Core_Action
::VIEW
;
96 * Build the form object.
98 public function buildQuickForm() {
99 // FIXME: Some of this code is identical to Confirm.php and should be broken out into a shared function
100 $this->assignToTemplate();
101 $this->_ccid
= $this->get('ccid');
102 $productID = $this->get('productID');
103 $option = $this->get('option');
104 $membershipTypeID = $this->get('membershipTypeID');
105 $this->assign('receiptFromEmail', CRM_Utils_Array
::value('receipt_from_email', $this->_values
));
108 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, FALSE, $productID, $option);
111 $params = $this->_params
;
112 $invoicing = CRM_Invoicing_Utils
::isInvoicingEnabled();
113 // Make a copy of line items array to use for display only
114 $tplLineItems = $this->_lineItem
;
116 $getTaxDetails = FALSE;
117 foreach ($this->_lineItem
as $key => $value) {
118 foreach ($value as $k => $v) {
119 if (isset($v['tax_rate'])) {
120 if ($v['tax_rate'] != '') {
121 $getTaxDetails = TRUE;
122 // Cast to float to display without trailing zero decimals
123 $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate'];
128 $this->assign('getTaxDetails', $getTaxDetails);
129 $this->assign('taxTerm', CRM_Invoicing_Utils
::getTaxTerm());
130 $this->assign('totalTaxAmount', $params['tax_amount']);
133 if ($this->_priceSetId
&& !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
134 $this->assign('lineItem', $tplLineItems);
137 if (is_array($membershipTypeID)) {
138 $membershipTypeID = current($membershipTypeID);
140 $this->assign('is_quick_config', 1);
141 $this->_params
['is_quick_config'] = 1;
143 $this->assign('priceSetID', $this->_priceSetId
);
144 $this->assign('useForMember', $this->get('useForMember'));
146 if (!empty($this->_values
['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) {
147 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
149 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
150 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields($this, $params['honor']);
152 $fieldTypes = ['Contact'];
153 $fieldTypes[] = CRM_Core_BAO_UFGroup
::getContactType($this->_values
['honoree_profile_id']);
154 $this->buildCustom($this->_values
['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
157 $qParams = "reset=1&id={$this->_id}";
160 $qParams .= "&pcpId={$this->_pcpId}";
161 $this->assign('pcpBlock', TRUE);
163 'pcp_display_in_roll',
168 if (!empty($this->_params
[$val])) {
169 $this->assign($val, $this->_params
[$val]);
174 $this->assign('qParams', $qParams);
176 if ($membershipTypeID) {
177 $transactionID = $this->get('membership_trx_id');
178 $membershipAmount = $this->get('membership_amount');
179 $renewalMode = $this->get('renewal_mode');
180 $this->assign('membership_trx_id', $transactionID);
181 $this->assign('membership_amount', $membershipAmount);
182 $this->assign('renewal_mode', $renewalMode);
184 $this->buildMembershipBlock(
185 $this->_membershipContactID
,
192 if (!empty($params['auto_renew'])) {
193 $this->assign('auto_renew', TRUE);
197 $this->_separateMembershipPayment
= $this->get('separateMembershipPayment');
198 $this->assign("is_separate_payment", $this->_separateMembershipPayment
);
200 if (empty($this->_ccid
)) {
201 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre', TRUE);
202 $this->buildCustom($this->_values
['custom_post_id'], 'customPost', TRUE);
204 if (!empty($this->_values
['onbehalf_profile_id']) &&
205 !empty($params['onbehalf']) &&
206 ($this->_values
['is_for_organization'] == 2 ||
207 !empty($params['is_for_organization'])
208 ) && empty($this->_ccid
)
210 $fieldTypes = ['Contact', 'Organization'];
211 $contactSubType = CRM_Contact_BAO_ContactType
::subTypes('Organization');
212 $fieldTypes = array_merge($fieldTypes, $contactSubType);
213 if (is_array($this->_membershipBlock
) && !empty($this->_membershipBlock
)) {
214 $fieldTypes = array_merge($fieldTypes, ['Membership']);
217 $fieldTypes = array_merge($fieldTypes, ['Contribution']);
220 $this->buildCustom($this->_values
['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
223 $this->_trxnId
= CRM_Utils_Array
::value('trxn_id', $this->_params
);
225 $this->assign('trxn_id', $this->_trxnId
);
227 $this->assign('receive_date',
228 CRM_Utils_Date
::mysqlToIso(CRM_Utils_Array
::value('receive_date', $this->_params
))
233 foreach ($this->_fields
as $name => $dontCare) {
234 if ($name != 'onbehalf' ||
$name != 'honor') {
238 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
239 $contact = $this->_params
= $this->controller
->exportValues('Main');
241 foreach ($fields as $name => $dontCare) {
242 if (isset($contact[$name])) {
243 $defaults[$name] = $contact[$name];
244 if (substr($name, 0, 7) == 'custom_') {
245 $timeField = "{$name}_time";
246 if (isset($contact[$timeField])) {
247 $defaults[$timeField] = $contact[$timeField];
250 elseif (in_array($name, [
254 ]) && !empty($contact[$name . '_custom'])
256 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
261 $this->_submitValues
= array_merge($this->_submitValues
, $defaults);
263 $this->setDefaults($defaults);
265 $values['entity_id'] = $this->_id
;
266 $values['entity_table'] = 'civicrm_contribution_page';
268 CRM_Friend_BAO_Friend
::retrieve($values, $data);
269 $tellAFriend = FALSE;
271 if ($this->_pcpBlock
['is_tellfriend_enabled']) {
272 $this->assign('friendText', ts('Tell a Friend'));
273 $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
277 elseif (!empty($data['is_active'])) {
278 $friendText = $data['title'];
279 $this->assign('friendText', $friendText);
280 $subUrl = "eid={$this->_id}&pcomponent=contribute";
285 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
286 $url = CRM_Utils_System
::url("civicrm/friend",
287 "reset=1&action=preview&{$subUrl}"
291 $url = CRM_Utils_System
::url("civicrm/friend",
295 $this->assign('friendURL', $url);
298 $isPendingOutcome = TRUE;
300 // A payment notification update could have come in at any time. Check at the last minute.
301 $contributionStatusID = civicrm_api3('Contribution', 'getvalue', [
302 'id' => CRM_Utils_Array
::value('contributionID', $params),
303 'return' => 'contribution_status_id',
304 'is_test' => ($this->_mode
== 'test') ?
1 : 0,
305 'invoice_id' => CRM_Utils_Array
::value('invoiceID', $params),
307 if (CRM_Core_PseudoConstant
::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID) === 'Pending'
308 && !empty($params['payment_processor_id'])
310 $isPendingOutcome = TRUE;
313 $isPendingOutcome = FALSE;
316 catch (CiviCRM_API3_Exception
$e) {
319 $this->assign('isPendingOutcome', $isPendingOutcome);
323 // can we blow away the session now to prevent hackery
325 $this->controller
->reset();