Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
95cdcc0f | 19 | * Form for thank-you / success page - 3rd step of online contribution process. |
6a488035 TO |
20 | */ |
21 | class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_ContributionBase { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Membership price set status. |
1330f57a | 25 | * @var bool |
6a488035 TO |
26 | */ |
27 | public $_useForMember; | |
28 | ||
507a7734 SL |
29 | /** |
30 | * Tranxaaction Id of the current contribution | |
1330f57a | 31 | * @var string |
507a7734 SL |
32 | */ |
33 | public $_trxnId; | |
34 | ||
6a488035 | 35 | /** |
fe482240 | 36 | * Set variables up before form is built. |
6a488035 TO |
37 | */ |
38 | public function preProcess() { | |
39 | parent::preProcess(); | |
40 | ||
353ffa53 | 41 | $this->_params = $this->get('params'); |
6a488035 | 42 | $this->_lineItem = $this->get('lineItem'); |
376b971e | 43 | $this->_useForMember = $this->get('useForMember'); |
353ffa53 | 44 | $is_deductible = $this->get('is_deductible'); |
6a488035 TO |
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)); | |
f4aaa82a | 52 | // Make the contributionPageID available to the template |
6a488035 TO |
53 | $this->assign('contributionPageID', $this->_id); |
54 | $this->assign('isShare', $this->_values['is_share']); | |
55 | ||
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']); | |
60 | } | |
de5ce535 | 61 | $this->assign('is_for_organization', CRM_Utils_Array::value('is_for_organization', $this->_params)); |
6a488035 TO |
62 | } |
63 | ||
64 | /** | |
100fef9d | 65 | * Overwrite action, since we are only showing elements in frozen mode |
6a488035 TO |
66 | * no help display needed |
67 | * | |
68 | * @return int | |
6a488035 | 69 | */ |
00be9182 | 70 | public function getAction() { |
6a488035 TO |
71 | if ($this->_action & CRM_Core_Action::PREVIEW) { |
72 | return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW; | |
73 | } | |
74 | else { | |
75 | return CRM_Core_Action::VIEW; | |
76 | } | |
77 | } | |
78 | ||
79 | /** | |
fe482240 | 80 | * Build the form object. |
6a488035 TO |
81 | */ |
82 | public function buildQuickForm() { | |
8684f612 | 83 | // FIXME: Some of this code is identical to Confirm.php and should be broken out into a shared function |
6a488035 | 84 | $this->assignToTemplate(); |
2f44fc96 | 85 | $this->_ccid = $this->get('ccid'); |
353ffa53 TO |
86 | $productID = $this->get('productID'); |
87 | $option = $this->get('option'); | |
6a488035 TO |
88 | $membershipTypeID = $this->get('membershipTypeID'); |
89 | $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); | |
90 | ||
91 | if ($productID) { | |
92 | CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); | |
93 | } | |
6a488035 | 94 | |
e77a5a36 | 95 | $params = $this->_params; |
ec5e7bcf | 96 | $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled(); |
147b56dc MW |
97 | // Make a copy of line items array to use for display only |
98 | $tplLineItems = $this->_lineItem; | |
03b412ae PB |
99 | if ($invoicing) { |
100 | $getTaxDetails = FALSE; | |
147b56dc MW |
101 | foreach ($this->_lineItem as $key => $value) { |
102 | foreach ($value as $k => $v) { | |
03b412ae PB |
103 | if (isset($v['tax_rate'])) { |
104 | if ($v['tax_rate'] != '') { | |
105 | $getTaxDetails = TRUE; | |
147b56dc MW |
106 | // Cast to float to display without trailing zero decimals |
107 | $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate']; | |
03b412ae PB |
108 | } |
109 | } | |
110 | } | |
111 | } | |
112 | $this->assign('getTaxDetails', $getTaxDetails); | |
ec5e7bcf | 113 | $this->assign('taxTerm', CRM_Invoicing_Utils::getTaxTerm()); |
03b412ae PB |
114 | $this->assign('totalTaxAmount', $params['tax_amount']); |
115 | } | |
147b56dc MW |
116 | |
117 | if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { | |
118 | $this->assign('lineItem', $tplLineItems); | |
119 | } | |
120 | else { | |
121 | if (is_array($membershipTypeID)) { | |
122 | $membershipTypeID = current($membershipTypeID); | |
123 | } | |
124 | $this->assign('is_quick_config', 1); | |
125 | $this->_params['is_quick_config'] = 1; | |
126 | } | |
127 | $this->assign('priceSetID', $this->_priceSetId); | |
128 | $this->assign('useForMember', $this->get('useForMember')); | |
129 | ||
4779abb3 | 130 | if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) { |
133e2c99 | 131 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); |
132 | ||
133e2c99 | 133 | $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); |
4779abb3 | 134 | CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor']); |
6a488035 | 135 | |
be2fb01f | 136 | $fieldTypes = ['Contact']; |
4779abb3 | 137 | $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($this->_values['honoree_profile_id']); |
138 | $this->buildCustom($this->_values['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); | |
6a488035 TO |
139 | } |
140 | ||
141 | $qParams = "reset=1&id={$this->_id}"; | |
142 | //pcp elements | |
143 | if ($this->_pcpId) { | |
144 | $qParams .= "&pcpId={$this->_pcpId}"; | |
145 | $this->assign('pcpBlock', TRUE); | |
be2fb01f | 146 | foreach ([ |
1330f57a SL |
147 | 'pcp_display_in_roll', |
148 | 'pcp_is_anonymous', | |
149 | 'pcp_roll_nickname', | |
150 | 'pcp_personal_note', | |
151 | ] as $val) { | |
a7488080 | 152 | if (!empty($this->_params[$val])) { |
6a488035 TO |
153 | $this->assign($val, $this->_params[$val]); |
154 | } | |
155 | } | |
156 | } | |
157 | ||
481a74f4 | 158 | $this->assign('qParams', $qParams); |
6a488035 TO |
159 | |
160 | if ($membershipTypeID) { | |
353ffa53 | 161 | $transactionID = $this->get('membership_trx_id'); |
6a488035 | 162 | $membershipAmount = $this->get('membership_amount'); |
353ffa53 | 163 | $renewalMode = $this->get('renewal_mode'); |
6a488035 TO |
164 | $this->assign('membership_trx_id', $transactionID); |
165 | $this->assign('membership_amount', $membershipAmount); | |
166 | $this->assign('renewal_mode', $renewalMode); | |
167 | ||
42e3a033 | 168 | $this->buildMembershipBlock( |
5b757295 | 169 | $this->_membershipContactID, |
6a488035 TO |
170 | FALSE, |
171 | $membershipTypeID, | |
5b757295 | 172 | TRUE, |
173 | NULL | |
6a488035 | 174 | ); |
9cc96227 | 175 | |
176 | if (!empty($params['auto_renew'])) { | |
177 | $this->assign('auto_renew', TRUE); | |
178 | } | |
6a488035 TO |
179 | } |
180 | ||
181 | $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); | |
182 | $this->assign("is_separate_payment", $this->_separateMembershipPayment); | |
183 | ||
2f44fc96 | 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); | |
187 | } | |
2454bb63 | 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']) | |
2f44fc96 | 192 | ) && empty($this->_ccid) |
2454bb63 | 193 | ) { |
be2fb01f | 194 | $fieldTypes = ['Contact', 'Organization']; |
6a488035 | 195 | $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); |
353ffa53 | 196 | $fieldTypes = array_merge($fieldTypes, $contactSubType); |
6a488035 | 197 | if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { |
be2fb01f | 198 | $fieldTypes = array_merge($fieldTypes, ['Membership']); |
6a488035 TO |
199 | } |
200 | else { | |
be2fb01f | 201 | $fieldTypes = array_merge($fieldTypes, ['Contribution']); |
6a488035 TO |
202 | } |
203 | ||
4779abb3 | 204 | $this->buildCustom($this->_values['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); |
6a488035 TO |
205 | } |
206 | ||
9c1bc317 | 207 | $this->_trxnId = $this->_params['trxn_id'] ?? NULL; |
507a7734 SL |
208 | |
209 | $this->assign('trxn_id', $this->_trxnId); | |
210 | ||
6a488035 TO |
211 | $this->assign('receive_date', |
212 | CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)) | |
213 | ); | |
214 | ||
be2fb01f CW |
215 | $defaults = []; |
216 | $fields = []; | |
6a488035 | 217 | foreach ($this->_fields as $name => $dontCare) { |
133e2c99 | 218 | if ($name != 'onbehalf' || $name != 'honor') { |
6a488035 TO |
219 | $fields[$name] = 1; |
220 | } | |
221 | } | |
222 | $fields['state_province'] = $fields['country'] = $fields['email'] = 1; | |
223 | $contact = $this->_params = $this->controller->exportValues('Main'); | |
224 | ||
225 | foreach ($fields as $name => $dontCare) { | |
133e2c99 | 226 | if (isset($contact[$name])) { |
6a488035 TO |
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]; | |
232 | } | |
233 | } | |
be2fb01f | 234 | elseif (in_array($name, [ |
1330f57a SL |
235 | 'addressee', |
236 | 'email_greeting', | |
237 | 'postal_greeting', | |
238 | ]) && !empty($contact[$name . '_custom']) | |
353ffa53 | 239 | ) { |
6a488035 TO |
240 | $defaults[$name . '_custom'] = $contact[$name . '_custom']; |
241 | } | |
242 | } | |
243 | } | |
244 | ||
6a488035 | 245 | $this->_submitValues = array_merge($this->_submitValues, $defaults); |
6cc679d2 | 246 | |
6a488035 | 247 | $this->setDefaults($defaults); |
eea16664 | 248 | |
6a488035 TO |
249 | $values['entity_id'] = $this->_id; |
250 | $values['entity_table'] = 'civicrm_contribution_page'; | |
251 | ||
252 | CRM_Friend_BAO_Friend::retrieve($values, $data); | |
253 | $tellAFriend = FALSE; | |
254 | if ($this->_pcpId) { | |
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"; | |
258 | $tellAFriend = TRUE; | |
259 | } | |
260 | } | |
a7488080 | 261 | elseif (!empty($data['is_active'])) { |
6a488035 TO |
262 | $friendText = $data['title']; |
263 | $this->assign('friendText', $friendText); | |
264 | $subUrl = "eid={$this->_id}&pcomponent=contribute"; | |
265 | $tellAFriend = TRUE; | |
266 | } | |
267 | ||
268 | if ($tellAFriend) { | |
269 | if ($this->_action & CRM_Core_Action::PREVIEW) { | |
270 | $url = CRM_Utils_System::url("civicrm/friend", | |
271 | "reset=1&action=preview&{$subUrl}" | |
272 | ); | |
273 | } | |
274 | else { | |
275 | $url = CRM_Utils_System::url("civicrm/friend", | |
276 | "reset=1&{$subUrl}" | |
277 | ); | |
278 | } | |
279 | $this->assign('friendURL', $url); | |
280 | } | |
281 | ||
7a666802 | 282 | $isPendingOutcome = TRUE; |
283 | try { | |
284 | // A payment notification update could have come in at any time. Check at the last minute. | |
be2fb01f | 285 | $contributionStatusID = civicrm_api3('Contribution', 'getvalue', [ |
6b409353 | 286 | 'id' => $params['contributionID'] ?? NULL, |
7a666802 | 287 | 'return' => 'contribution_status_id', |
9483c881 | 288 | 'is_test' => ($this->_mode == 'test') ? 1 : 0, |
6b409353 | 289 | 'invoice_id' => $params['invoiceID'] ?? NULL, |
be2fb01f | 290 | ]); |
7a666802 | 291 | if (CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID) === 'Pending' |
292 | && !empty($params['payment_processor_id']) | |
293 | ) { | |
294 | $isPendingOutcome = TRUE; | |
295 | } | |
296 | else { | |
297 | $isPendingOutcome = FALSE; | |
298 | } | |
299 | } | |
300 | catch (CiviCRM_API3_Exception $e) { | |
301 | ||
302 | } | |
303 | $this->assign('isPendingOutcome', $isPendingOutcome); | |
304 | ||
6a488035 TO |
305 | $this->freeze(); |
306 | ||
307 | // can we blow away the session now to prevent hackery | |
308 | // CRM-9491 | |
309 | $this->controller->reset(); | |
310 | } | |
96025800 | 311 | |
6a488035 | 312 | } |