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