3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Form for thank-you / success page - 3rd step of online contribution process.
21 class CRM_Contribute_Form_Contribution_ThankYou
extends CRM_Contribute_Form_ContributionBase
{
24 * Membership price set status.
27 public $_useForMember;
30 * Tranxaaction Id of the current contribution
36 * Set variables up before form is built.
38 public function preProcess() {
41 $this->_params
= $this->get('params');
42 $this->_lineItem
= $this->get('lineItem');
43 $this->_useForMember
= $this->get('useForMember');
44 $is_deductible = $this->get('is_deductible');
45 $this->assign('is_deductible', $is_deductible);
46 $this->assign('thankyou_title', CRM_Utils_Array
::value('thankyou_title', $this->_values
));
47 $this->assign('thankyou_text', CRM_Utils_Array
::value('thankyou_text', $this->_values
));
48 $this->assign('thankyou_footer', CRM_Utils_Array
::value('thankyou_footer', $this->_values
));
49 $this->assign('max_reminders', CRM_Utils_Array
::value('max_reminders', $this->_values
));
50 $this->assign('initial_reminder_day', CRM_Utils_Array
::value('initial_reminder_day', $this->_values
));
51 CRM_Utils_System
::setTitle(CRM_Utils_Array
::value('thankyou_title', $this->_values
));
52 // Make the contributionPageID available to the template
53 $this->assign('contributionPageID', $this->_id
);
54 $this->assign('isShare', $this->_values
['is_share']);
56 $this->_params
['is_pay_later'] = $this->get('is_pay_later');
57 $this->assign('is_pay_later', $this->_params
['is_pay_later']);
58 if ($this->_params
['is_pay_later']) {
59 $this->assign('pay_later_receipt', $this->_values
['pay_later_receipt']);
61 $this->assign('is_for_organization', CRM_Utils_Array
::value('is_for_organization', $this->_params
));
65 * Overwrite action, since we are only showing elements in frozen mode
66 * no help display needed
70 public function getAction() {
71 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
72 return CRM_Core_Action
::VIEW | CRM_Core_Action
::PREVIEW
;
75 return CRM_Core_Action
::VIEW
;
80 * Build the form object.
82 public function buildQuickForm() {
83 // FIXME: Some of this code is identical to Confirm.php and should be broken out into a shared function
84 $this->assignToTemplate();
85 $this->_ccid
= $this->get('ccid');
86 $productID = $this->get('productID');
87 $option = $this->get('option');
88 $membershipTypeID = $this->get('membershipTypeID');
89 $this->assign('receiptFromEmail', CRM_Utils_Array
::value('receipt_from_email', $this->_values
));
92 CRM_Contribute_BAO_Premium
::buildPremiumBlock($this, $this->_id
, FALSE, $productID, $option);
95 $params = $this->_params
;
96 $invoicing = CRM_Invoicing_Utils
::isInvoicingEnabled();
97 // Make a copy of line items array to use for display only
98 $tplLineItems = $this->_lineItem
;
100 $getTaxDetails = FALSE;
101 foreach ($this->_lineItem
as $key => $value) {
102 foreach ($value as $k => $v) {
103 if (isset($v['tax_rate'])) {
104 if ($v['tax_rate'] != '') {
105 $getTaxDetails = TRUE;
106 // Cast to float to display without trailing zero decimals
107 $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate'];
112 $this->assign('getTaxDetails', $getTaxDetails);
113 $this->assign('taxTerm', CRM_Invoicing_Utils
::getTaxTerm());
114 $this->assign('totalTaxAmount', $params['tax_amount']);
117 if ($this->_priceSetId
&& !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
118 $this->assign('lineItem', $tplLineItems);
121 if (is_array($membershipTypeID)) {
122 $membershipTypeID = current($membershipTypeID);
124 $this->assign('is_quick_config', 1);
125 $this->_params
['is_quick_config'] = 1;
127 $this->assign('priceSetID', $this->_priceSetId
);
128 $this->assign('useForMember', $this->get('useForMember'));
130 if (!empty($this->_values
['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) {
131 $softCreditTypes = CRM_Core_OptionGroup
::values("soft_credit_type", FALSE);
133 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
134 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields($this, $params['honor']);
136 $fieldTypes = ['Contact'];
137 $fieldTypes[] = CRM_Core_BAO_UFGroup
::getContactType($this->_values
['honoree_profile_id']);
138 $this->buildCustom($this->_values
['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
141 $qParams = "reset=1&id={$this->_id}";
144 $qParams .= "&pcpId={$this->_pcpId}";
145 $this->assign('pcpBlock', TRUE);
147 'pcp_display_in_roll',
152 if (!empty($this->_params
[$val])) {
153 $this->assign($val, $this->_params
[$val]);
158 $this->assign('qParams', $qParams);
160 if ($membershipTypeID) {
161 $transactionID = $this->get('membership_trx_id');
162 $membershipAmount = $this->get('membership_amount');
163 $renewalMode = $this->get('renewal_mode');
164 $this->assign('membership_trx_id', $transactionID);
165 $this->assign('membership_amount', $membershipAmount);
166 $this->assign('renewal_mode', $renewalMode);
168 $this->buildMembershipBlock(
169 $this->_membershipContactID
,
176 if (!empty($params['auto_renew'])) {
177 $this->assign('auto_renew', TRUE);
181 $this->_separateMembershipPayment
= $this->get('separateMembershipPayment');
182 $this->assign("is_separate_payment", $this->_separateMembershipPayment
);
184 if (empty($this->_ccid
)) {
185 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre', TRUE);
186 $this->buildCustom($this->_values
['custom_post_id'], 'customPost', TRUE);
188 if (!empty($this->_values
['onbehalf_profile_id']) &&
189 !empty($params['onbehalf']) &&
190 ($this->_values
['is_for_organization'] == 2 ||
191 !empty($params['is_for_organization'])
192 ) && empty($this->_ccid
)
194 $fieldTypes = ['Contact', 'Organization'];
195 $contactSubType = CRM_Contact_BAO_ContactType
::subTypes('Organization');
196 $fieldTypes = array_merge($fieldTypes, $contactSubType);
197 if (is_array($this->_membershipBlock
) && !empty($this->_membershipBlock
)) {
198 $fieldTypes = array_merge($fieldTypes, ['Membership']);
201 $fieldTypes = array_merge($fieldTypes, ['Contribution']);
204 $this->buildCustom($this->_values
['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
207 $this->_trxnId
= $this->_params
['trxn_id'] ??
NULL;
209 $this->assign('trxn_id', $this->_trxnId
);
211 $this->assign('receive_date',
212 CRM_Utils_Date
::mysqlToIso(CRM_Utils_Array
::value('receive_date', $this->_params
))
217 foreach ($this->_fields
as $name => $dontCare) {
218 if ($name != 'onbehalf' ||
$name != 'honor') {
222 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
223 $contact = $this->_params
= $this->controller
->exportValues('Main');
225 foreach ($fields as $name => $dontCare) {
226 if (isset($contact[$name])) {
227 $defaults[$name] = $contact[$name];
228 if (substr($name, 0, 7) == 'custom_') {
229 $timeField = "{$name}_time";
230 if (isset($contact[$timeField])) {
231 $defaults[$timeField] = $contact[$timeField];
234 elseif (in_array($name, [
238 ]) && !empty($contact[$name . '_custom'])
240 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
245 $this->_submitValues
= array_merge($this->_submitValues
, $defaults);
247 $this->setDefaults($defaults);
249 $values['entity_id'] = $this->_id
;
250 $values['entity_table'] = 'civicrm_contribution_page';
252 CRM_Friend_BAO_Friend
::retrieve($values, $data);
253 $tellAFriend = FALSE;
255 if ($this->_pcpBlock
['is_tellfriend_enabled']) {
256 $this->assign('friendText', ts('Tell a Friend'));
257 $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
261 elseif (!empty($data['is_active'])) {
262 $friendText = $data['title'];
263 $this->assign('friendText', $friendText);
264 $subUrl = "eid={$this->_id}&pcomponent=contribute";
269 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
270 $url = CRM_Utils_System
::url("civicrm/friend",
271 "reset=1&action=preview&{$subUrl}"
275 $url = CRM_Utils_System
::url("civicrm/friend",
279 $this->assign('friendURL', $url);
282 $isPendingOutcome = TRUE;
284 // A payment notification update could have come in at any time. Check at the last minute.
285 $contributionStatusID = civicrm_api3('Contribution', 'getvalue', [
286 'id' => $params['contributionID'] ??
NULL,
287 'return' => 'contribution_status_id',
288 'is_test' => ($this->_mode
== 'test') ?
1 : 0,
289 'invoice_id' => $params['invoiceID'] ??
NULL,
291 if (CRM_Core_PseudoConstant
::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID) === 'Pending'
292 && !empty($params['payment_processor_id'])
294 $isPendingOutcome = TRUE;
297 $isPendingOutcome = FALSE;
300 catch (CiviCRM_API3_Exception
$e) {
303 $this->assign('isPendingOutcome', $isPendingOutcome);
307 // can we blow away the session now to prevent hackery
309 $this->controller
->reset();