@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -23,670 +23,670 @@ discard block |
||
23 | 23 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * Sets some dynamic defaults |
|
28 | - * |
|
29 | - * @param array $fieldValues |
|
30 | - * @param bool $bydb |
|
31 | - * @param string $timezone |
|
32 | - * @param array $date_formats |
|
33 | - */ |
|
34 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
35 | - { |
|
36 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
37 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
38 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
39 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
40 | - } |
|
41 | - if (! isset($fieldValues['ATT_slug'])) { |
|
42 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
43 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
44 | - } |
|
45 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
46 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
47 | - } |
|
48 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @param array $props_n_values incoming values |
|
54 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
55 | - * used.) |
|
56 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
57 | - * date_format and the second value is the time format |
|
58 | - * @return EE_Attendee |
|
59 | - */ |
|
60 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
61 | - { |
|
62 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
63 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @param array $props_n_values incoming values from the database |
|
69 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
70 | - * the website will be used. |
|
71 | - * @return EE_Attendee |
|
72 | - */ |
|
73 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
74 | - { |
|
75 | - return new self($props_n_values, true, $timezone); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Set Attendee First Name |
|
81 | - * |
|
82 | - * @access public |
|
83 | - * @param string $fname |
|
84 | - */ |
|
85 | - public function set_fname($fname = '') |
|
86 | - { |
|
87 | - $this->set('ATT_fname', $fname); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Set Attendee Last Name |
|
93 | - * |
|
94 | - * @access public |
|
95 | - * @param string $lname |
|
96 | - */ |
|
97 | - public function set_lname($lname = '') |
|
98 | - { |
|
99 | - $this->set('ATT_lname', $lname); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Set Attendee Address |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @param string $address |
|
108 | - */ |
|
109 | - public function set_address($address = '') |
|
110 | - { |
|
111 | - $this->set('ATT_address', $address); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Set Attendee Address2 |
|
117 | - * |
|
118 | - * @access public |
|
119 | - * @param string $address2 |
|
120 | - */ |
|
121 | - public function set_address2($address2 = '') |
|
122 | - { |
|
123 | - $this->set('ATT_address2', $address2); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Set Attendee City |
|
129 | - * |
|
130 | - * @access public |
|
131 | - * @param string $city |
|
132 | - */ |
|
133 | - public function set_city($city = '') |
|
134 | - { |
|
135 | - $this->set('ATT_city', $city); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Set Attendee State ID |
|
141 | - * |
|
142 | - * @access public |
|
143 | - * @param int $STA_ID |
|
144 | - */ |
|
145 | - public function set_state($STA_ID = 0) |
|
146 | - { |
|
147 | - $this->set('STA_ID', $STA_ID); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Set Attendee Country ISO Code |
|
153 | - * |
|
154 | - * @access public |
|
155 | - * @param string $CNT_ISO |
|
156 | - */ |
|
157 | - public function set_country($CNT_ISO = '') |
|
158 | - { |
|
159 | - $this->set('CNT_ISO', $CNT_ISO); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Set Attendee Zip/Postal Code |
|
165 | - * |
|
166 | - * @access public |
|
167 | - * @param string $zip |
|
168 | - */ |
|
169 | - public function set_zip($zip = '') |
|
170 | - { |
|
171 | - $this->set('ATT_zip', $zip); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * Set Attendee Email Address |
|
177 | - * |
|
178 | - * @access public |
|
179 | - * @param string $email |
|
180 | - */ |
|
181 | - public function set_email($email = '') |
|
182 | - { |
|
183 | - $this->set('ATT_email', $email); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Set Attendee Phone |
|
189 | - * |
|
190 | - * @access public |
|
191 | - * @param string $phone |
|
192 | - */ |
|
193 | - public function set_phone($phone = '') |
|
194 | - { |
|
195 | - $this->set('ATT_phone', $phone); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * set deleted |
|
201 | - * |
|
202 | - * @access public |
|
203 | - * @param bool $ATT_deleted |
|
204 | - */ |
|
205 | - public function set_deleted($ATT_deleted = false) |
|
206 | - { |
|
207 | - $this->set('ATT_deleted', $ATT_deleted); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Returns the value for the post_author id saved with the cpt |
|
213 | - * |
|
214 | - * @since 4.5.0 |
|
215 | - * @return int |
|
216 | - */ |
|
217 | - public function wp_user() |
|
218 | - { |
|
219 | - return $this->get('ATT_author'); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * get Attendee First Name |
|
225 | - * |
|
226 | - * @access public |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function fname() |
|
230 | - { |
|
231 | - return $this->get('ATT_fname'); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * echoes out the attendee's first name |
|
237 | - * |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function e_full_name() |
|
241 | - { |
|
242 | - echo $this->full_name(); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Returns the first and last name concatenated together with a space. |
|
248 | - * |
|
249 | - * @param bool $apply_html_entities |
|
250 | - * @return string |
|
251 | - */ |
|
252 | - public function full_name($apply_html_entities = false) |
|
253 | - { |
|
254 | - $full_name = array( |
|
255 | - $this->fname(), |
|
256 | - $this->lname() |
|
257 | - ); |
|
258 | - $full_name = array_filter($full_name); |
|
259 | - $full_name = implode(' ', $full_name); |
|
260 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
266 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
267 | - * attendee. |
|
268 | - * |
|
269 | - * @param bool $apply_html_entities |
|
270 | - * @return string |
|
271 | - */ |
|
272 | - public function ATT_full_name($apply_html_entities = false) |
|
273 | - { |
|
274 | - return $apply_html_entities |
|
275 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
276 | - : $this->get('ATT_full_name'); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * get Attendee Last Name |
|
282 | - * |
|
283 | - * @access public |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function lname() |
|
287 | - { |
|
288 | - return $this->get('ATT_lname'); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
294 | - * |
|
295 | - * @return array numerically indexed, with each part of the address that is known. |
|
296 | - * Eg, if the user only responded to state and country, |
|
297 | - * it would be array(0=>'Alabama',1=>'USA') |
|
298 | - * @return array |
|
299 | - */ |
|
300 | - public function full_address_as_array() |
|
301 | - { |
|
302 | - $full_address_array = array(); |
|
303 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
304 | - foreach ($initial_address_fields as $address_field_name) { |
|
305 | - $address_fields_value = $this->get($address_field_name); |
|
306 | - if (! empty($address_fields_value)) { |
|
307 | - $full_address_array[] = $address_fields_value; |
|
308 | - } |
|
309 | - } |
|
310 | - //now handle state and country |
|
311 | - $state_obj = $this->state_obj(); |
|
312 | - if (! empty($state_obj)) { |
|
313 | - $full_address_array[] = $state_obj->name(); |
|
314 | - } |
|
315 | - $country_obj = $this->country_obj(); |
|
316 | - if (! empty($country_obj)) { |
|
317 | - $full_address_array[] = $country_obj->name(); |
|
318 | - } |
|
319 | - //lastly get the xip |
|
320 | - $zip_value = $this->zip(); |
|
321 | - if (! empty($zip_value)) { |
|
322 | - $full_address_array[] = $zip_value; |
|
323 | - } |
|
324 | - return $full_address_array; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * get Attendee Address |
|
330 | - * |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - public function address() |
|
334 | - { |
|
335 | - return $this->get('ATT_address'); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * get Attendee Address2 |
|
341 | - * |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - public function address2() |
|
345 | - { |
|
346 | - return $this->get('ATT_address2'); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * get Attendee City |
|
352 | - * |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function city() |
|
356 | - { |
|
357 | - return $this->get('ATT_city'); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * get Attendee State ID |
|
363 | - * |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - public function state_ID() |
|
367 | - { |
|
368 | - return $this->get('STA_ID'); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @return string |
|
374 | - */ |
|
375 | - public function state_abbrev() |
|
376 | - { |
|
377 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Gets the state set to this attendee |
|
383 | - * |
|
384 | - * @return EE_State |
|
385 | - */ |
|
386 | - public function state_obj() |
|
387 | - { |
|
388 | - return $this->get_first_related('State'); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Returns the state's name, otherwise 'Unknown' |
|
394 | - * |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - public function state_name() |
|
398 | - { |
|
399 | - if ($this->state_obj()) { |
|
400 | - return $this->state_obj()->name(); |
|
401 | - } else { |
|
402 | - return ''; |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * either displays the state abbreviation or the state name, as determined |
|
409 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
410 | - * defaults to abbreviation |
|
411 | - * |
|
412 | - * @return string |
|
413 | - */ |
|
414 | - public function state() |
|
415 | - { |
|
416 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
417 | - return $this->state_abbrev(); |
|
418 | - } else { |
|
419 | - return $this->state_name(); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * get Attendee Country ISO Code |
|
426 | - * |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public function country_ID() |
|
430 | - { |
|
431 | - return $this->get('CNT_ISO'); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Gets country set for this attendee |
|
437 | - * |
|
438 | - * @return EE_Country |
|
439 | - */ |
|
440 | - public function country_obj() |
|
441 | - { |
|
442 | - return $this->get_first_related('Country'); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * Returns the country's name if known, otherwise 'Unknown' |
|
448 | - * |
|
449 | - * @return string |
|
450 | - */ |
|
451 | - public function country_name() |
|
452 | - { |
|
453 | - if ($this->country_obj()) { |
|
454 | - return $this->country_obj()->name(); |
|
455 | - } else { |
|
456 | - return ''; |
|
457 | - } |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * either displays the country ISO2 code or the country name, as determined |
|
463 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
464 | - * defaults to abbreviation |
|
465 | - * |
|
466 | - * @return string |
|
467 | - */ |
|
468 | - public function country() |
|
469 | - { |
|
470 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
471 | - return $this->country_ID(); |
|
472 | - } else { |
|
473 | - return $this->country_name(); |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * get Attendee Zip/Postal Code |
|
480 | - * |
|
481 | - * @return string |
|
482 | - */ |
|
483 | - public function zip() |
|
484 | - { |
|
485 | - return $this->get('ATT_zip'); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * get Attendee Email Address |
|
491 | - * |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function email() |
|
495 | - { |
|
496 | - return $this->get('ATT_email'); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * get Attendee Phone # |
|
502 | - * |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - public function phone() |
|
506 | - { |
|
507 | - return $this->get('ATT_phone'); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * get deleted |
|
513 | - * |
|
514 | - * @return bool |
|
515 | - */ |
|
516 | - public function deleted() |
|
517 | - { |
|
518 | - return $this->get('ATT_deleted'); |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * Gets registrations of this attendee |
|
524 | - * |
|
525 | - * @param array $query_params |
|
526 | - * @return EE_Registration[] |
|
527 | - */ |
|
528 | - public function get_registrations($query_params = array()) |
|
529 | - { |
|
530 | - return $this->get_many_related('Registration', $query_params); |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * Gets the most recent registration of this attendee |
|
536 | - * |
|
537 | - * @return EE_Registration |
|
538 | - */ |
|
539 | - public function get_most_recent_registration() |
|
540 | - { |
|
541 | - return $this->get_first_related('Registration', |
|
542 | - array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Gets the most recent registration for this attend at this event |
|
548 | - * |
|
549 | - * @param int $event_id |
|
550 | - * @return EE_Registration |
|
551 | - */ |
|
552 | - public function get_most_recent_registration_for_event($event_id) |
|
553 | - { |
|
554 | - return $this->get_first_related('Registration', |
|
555 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * returns any events attached to this attendee ($_Event property); |
|
561 | - * |
|
562 | - * @return array |
|
563 | - */ |
|
564 | - public function events() |
|
565 | - { |
|
566 | - return $this->get_many_related('Event'); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
572 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
573 | - * used to save the billing info |
|
574 | - * |
|
575 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
576 | - * @return EE_Form_Section_Proper|null |
|
577 | - */ |
|
578 | - public function billing_info_for_payment_method($payment_method) |
|
579 | - { |
|
580 | - $pm_type = $payment_method->type_obj(); |
|
581 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
582 | - return null; |
|
583 | - } |
|
584 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
585 | - if (! $billing_info) { |
|
586 | - return null; |
|
587 | - } |
|
588 | - $billing_form = $pm_type->billing_form(); |
|
589 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
590 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
591 | - } |
|
592 | - return $billing_form; |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - /** |
|
597 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
598 | - * specified payment method |
|
599 | - * |
|
600 | - * @param EE_Payment_Method $payment_method |
|
601 | - * @return string |
|
602 | - */ |
|
603 | - public function get_billing_info_postmeta_name($payment_method) |
|
604 | - { |
|
605 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
606 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
607 | - } else { |
|
608 | - return null; |
|
609 | - } |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
615 | - * retrieve it |
|
616 | - * |
|
617 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
618 | - * @param EE_Payment_Method $payment_method |
|
619 | - * @return boolean |
|
620 | - */ |
|
621 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
622 | - { |
|
623 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
624 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
625 | - return false; |
|
626 | - } |
|
627 | - $billing_form->clean_sensitive_data(); |
|
628 | - return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method), |
|
629 | - $billing_form->input_values(true)); |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * Return the link to the admin details for the object. |
|
635 | - * |
|
636 | - * @return string |
|
637 | - */ |
|
638 | - public function get_admin_details_link() |
|
639 | - { |
|
640 | - return $this->get_admin_edit_link(); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
646 | - * |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function get_admin_edit_link() |
|
650 | - { |
|
651 | - EE_Registry::instance()->load_helper('URL'); |
|
652 | - return EEH_URL::add_query_args_and_nonce( |
|
653 | - array( |
|
654 | - 'page' => 'espresso_registrations', |
|
655 | - 'action' => 'edit_attendee', |
|
656 | - 'post' => $this->ID(), |
|
657 | - ), |
|
658 | - admin_url('admin.php') |
|
659 | - ); |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * Returns the link to a settings page for the object. |
|
665 | - * |
|
666 | - * @return string |
|
667 | - */ |
|
668 | - public function get_admin_settings_link() |
|
669 | - { |
|
670 | - return $this->get_admin_edit_link(); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
676 | - * |
|
677 | - * @return string |
|
678 | - */ |
|
679 | - public function get_admin_overview_link() |
|
680 | - { |
|
681 | - EE_Registry::instance()->load_helper('URL'); |
|
682 | - return EEH_URL::add_query_args_and_nonce( |
|
683 | - array( |
|
684 | - 'page' => 'espresso_registrations', |
|
685 | - 'action' => 'contact_list', |
|
686 | - ), |
|
687 | - admin_url('admin.php') |
|
688 | - ); |
|
689 | - } |
|
26 | + /** |
|
27 | + * Sets some dynamic defaults |
|
28 | + * |
|
29 | + * @param array $fieldValues |
|
30 | + * @param bool $bydb |
|
31 | + * @param string $timezone |
|
32 | + * @param array $date_formats |
|
33 | + */ |
|
34 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
35 | + { |
|
36 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
37 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
38 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
39 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
40 | + } |
|
41 | + if (! isset($fieldValues['ATT_slug'])) { |
|
42 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
43 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
44 | + } |
|
45 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
46 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
47 | + } |
|
48 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @param array $props_n_values incoming values |
|
54 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
55 | + * used.) |
|
56 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
57 | + * date_format and the second value is the time format |
|
58 | + * @return EE_Attendee |
|
59 | + */ |
|
60 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
61 | + { |
|
62 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
63 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @param array $props_n_values incoming values from the database |
|
69 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
70 | + * the website will be used. |
|
71 | + * @return EE_Attendee |
|
72 | + */ |
|
73 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
74 | + { |
|
75 | + return new self($props_n_values, true, $timezone); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Set Attendee First Name |
|
81 | + * |
|
82 | + * @access public |
|
83 | + * @param string $fname |
|
84 | + */ |
|
85 | + public function set_fname($fname = '') |
|
86 | + { |
|
87 | + $this->set('ATT_fname', $fname); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Set Attendee Last Name |
|
93 | + * |
|
94 | + * @access public |
|
95 | + * @param string $lname |
|
96 | + */ |
|
97 | + public function set_lname($lname = '') |
|
98 | + { |
|
99 | + $this->set('ATT_lname', $lname); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Set Attendee Address |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @param string $address |
|
108 | + */ |
|
109 | + public function set_address($address = '') |
|
110 | + { |
|
111 | + $this->set('ATT_address', $address); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Set Attendee Address2 |
|
117 | + * |
|
118 | + * @access public |
|
119 | + * @param string $address2 |
|
120 | + */ |
|
121 | + public function set_address2($address2 = '') |
|
122 | + { |
|
123 | + $this->set('ATT_address2', $address2); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Set Attendee City |
|
129 | + * |
|
130 | + * @access public |
|
131 | + * @param string $city |
|
132 | + */ |
|
133 | + public function set_city($city = '') |
|
134 | + { |
|
135 | + $this->set('ATT_city', $city); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Set Attendee State ID |
|
141 | + * |
|
142 | + * @access public |
|
143 | + * @param int $STA_ID |
|
144 | + */ |
|
145 | + public function set_state($STA_ID = 0) |
|
146 | + { |
|
147 | + $this->set('STA_ID', $STA_ID); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Set Attendee Country ISO Code |
|
153 | + * |
|
154 | + * @access public |
|
155 | + * @param string $CNT_ISO |
|
156 | + */ |
|
157 | + public function set_country($CNT_ISO = '') |
|
158 | + { |
|
159 | + $this->set('CNT_ISO', $CNT_ISO); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Set Attendee Zip/Postal Code |
|
165 | + * |
|
166 | + * @access public |
|
167 | + * @param string $zip |
|
168 | + */ |
|
169 | + public function set_zip($zip = '') |
|
170 | + { |
|
171 | + $this->set('ATT_zip', $zip); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * Set Attendee Email Address |
|
177 | + * |
|
178 | + * @access public |
|
179 | + * @param string $email |
|
180 | + */ |
|
181 | + public function set_email($email = '') |
|
182 | + { |
|
183 | + $this->set('ATT_email', $email); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Set Attendee Phone |
|
189 | + * |
|
190 | + * @access public |
|
191 | + * @param string $phone |
|
192 | + */ |
|
193 | + public function set_phone($phone = '') |
|
194 | + { |
|
195 | + $this->set('ATT_phone', $phone); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * set deleted |
|
201 | + * |
|
202 | + * @access public |
|
203 | + * @param bool $ATT_deleted |
|
204 | + */ |
|
205 | + public function set_deleted($ATT_deleted = false) |
|
206 | + { |
|
207 | + $this->set('ATT_deleted', $ATT_deleted); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Returns the value for the post_author id saved with the cpt |
|
213 | + * |
|
214 | + * @since 4.5.0 |
|
215 | + * @return int |
|
216 | + */ |
|
217 | + public function wp_user() |
|
218 | + { |
|
219 | + return $this->get('ATT_author'); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * get Attendee First Name |
|
225 | + * |
|
226 | + * @access public |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function fname() |
|
230 | + { |
|
231 | + return $this->get('ATT_fname'); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * echoes out the attendee's first name |
|
237 | + * |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function e_full_name() |
|
241 | + { |
|
242 | + echo $this->full_name(); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Returns the first and last name concatenated together with a space. |
|
248 | + * |
|
249 | + * @param bool $apply_html_entities |
|
250 | + * @return string |
|
251 | + */ |
|
252 | + public function full_name($apply_html_entities = false) |
|
253 | + { |
|
254 | + $full_name = array( |
|
255 | + $this->fname(), |
|
256 | + $this->lname() |
|
257 | + ); |
|
258 | + $full_name = array_filter($full_name); |
|
259 | + $full_name = implode(' ', $full_name); |
|
260 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
266 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
267 | + * attendee. |
|
268 | + * |
|
269 | + * @param bool $apply_html_entities |
|
270 | + * @return string |
|
271 | + */ |
|
272 | + public function ATT_full_name($apply_html_entities = false) |
|
273 | + { |
|
274 | + return $apply_html_entities |
|
275 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
276 | + : $this->get('ATT_full_name'); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * get Attendee Last Name |
|
282 | + * |
|
283 | + * @access public |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function lname() |
|
287 | + { |
|
288 | + return $this->get('ATT_lname'); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
294 | + * |
|
295 | + * @return array numerically indexed, with each part of the address that is known. |
|
296 | + * Eg, if the user only responded to state and country, |
|
297 | + * it would be array(0=>'Alabama',1=>'USA') |
|
298 | + * @return array |
|
299 | + */ |
|
300 | + public function full_address_as_array() |
|
301 | + { |
|
302 | + $full_address_array = array(); |
|
303 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
304 | + foreach ($initial_address_fields as $address_field_name) { |
|
305 | + $address_fields_value = $this->get($address_field_name); |
|
306 | + if (! empty($address_fields_value)) { |
|
307 | + $full_address_array[] = $address_fields_value; |
|
308 | + } |
|
309 | + } |
|
310 | + //now handle state and country |
|
311 | + $state_obj = $this->state_obj(); |
|
312 | + if (! empty($state_obj)) { |
|
313 | + $full_address_array[] = $state_obj->name(); |
|
314 | + } |
|
315 | + $country_obj = $this->country_obj(); |
|
316 | + if (! empty($country_obj)) { |
|
317 | + $full_address_array[] = $country_obj->name(); |
|
318 | + } |
|
319 | + //lastly get the xip |
|
320 | + $zip_value = $this->zip(); |
|
321 | + if (! empty($zip_value)) { |
|
322 | + $full_address_array[] = $zip_value; |
|
323 | + } |
|
324 | + return $full_address_array; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * get Attendee Address |
|
330 | + * |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + public function address() |
|
334 | + { |
|
335 | + return $this->get('ATT_address'); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * get Attendee Address2 |
|
341 | + * |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + public function address2() |
|
345 | + { |
|
346 | + return $this->get('ATT_address2'); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * get Attendee City |
|
352 | + * |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function city() |
|
356 | + { |
|
357 | + return $this->get('ATT_city'); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * get Attendee State ID |
|
363 | + * |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + public function state_ID() |
|
367 | + { |
|
368 | + return $this->get('STA_ID'); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @return string |
|
374 | + */ |
|
375 | + public function state_abbrev() |
|
376 | + { |
|
377 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Gets the state set to this attendee |
|
383 | + * |
|
384 | + * @return EE_State |
|
385 | + */ |
|
386 | + public function state_obj() |
|
387 | + { |
|
388 | + return $this->get_first_related('State'); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Returns the state's name, otherwise 'Unknown' |
|
394 | + * |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + public function state_name() |
|
398 | + { |
|
399 | + if ($this->state_obj()) { |
|
400 | + return $this->state_obj()->name(); |
|
401 | + } else { |
|
402 | + return ''; |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * either displays the state abbreviation or the state name, as determined |
|
409 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
410 | + * defaults to abbreviation |
|
411 | + * |
|
412 | + * @return string |
|
413 | + */ |
|
414 | + public function state() |
|
415 | + { |
|
416 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
417 | + return $this->state_abbrev(); |
|
418 | + } else { |
|
419 | + return $this->state_name(); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * get Attendee Country ISO Code |
|
426 | + * |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public function country_ID() |
|
430 | + { |
|
431 | + return $this->get('CNT_ISO'); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Gets country set for this attendee |
|
437 | + * |
|
438 | + * @return EE_Country |
|
439 | + */ |
|
440 | + public function country_obj() |
|
441 | + { |
|
442 | + return $this->get_first_related('Country'); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * Returns the country's name if known, otherwise 'Unknown' |
|
448 | + * |
|
449 | + * @return string |
|
450 | + */ |
|
451 | + public function country_name() |
|
452 | + { |
|
453 | + if ($this->country_obj()) { |
|
454 | + return $this->country_obj()->name(); |
|
455 | + } else { |
|
456 | + return ''; |
|
457 | + } |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * either displays the country ISO2 code or the country name, as determined |
|
463 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
464 | + * defaults to abbreviation |
|
465 | + * |
|
466 | + * @return string |
|
467 | + */ |
|
468 | + public function country() |
|
469 | + { |
|
470 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
471 | + return $this->country_ID(); |
|
472 | + } else { |
|
473 | + return $this->country_name(); |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * get Attendee Zip/Postal Code |
|
480 | + * |
|
481 | + * @return string |
|
482 | + */ |
|
483 | + public function zip() |
|
484 | + { |
|
485 | + return $this->get('ATT_zip'); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * get Attendee Email Address |
|
491 | + * |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function email() |
|
495 | + { |
|
496 | + return $this->get('ATT_email'); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * get Attendee Phone # |
|
502 | + * |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + public function phone() |
|
506 | + { |
|
507 | + return $this->get('ATT_phone'); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * get deleted |
|
513 | + * |
|
514 | + * @return bool |
|
515 | + */ |
|
516 | + public function deleted() |
|
517 | + { |
|
518 | + return $this->get('ATT_deleted'); |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * Gets registrations of this attendee |
|
524 | + * |
|
525 | + * @param array $query_params |
|
526 | + * @return EE_Registration[] |
|
527 | + */ |
|
528 | + public function get_registrations($query_params = array()) |
|
529 | + { |
|
530 | + return $this->get_many_related('Registration', $query_params); |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * Gets the most recent registration of this attendee |
|
536 | + * |
|
537 | + * @return EE_Registration |
|
538 | + */ |
|
539 | + public function get_most_recent_registration() |
|
540 | + { |
|
541 | + return $this->get_first_related('Registration', |
|
542 | + array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Gets the most recent registration for this attend at this event |
|
548 | + * |
|
549 | + * @param int $event_id |
|
550 | + * @return EE_Registration |
|
551 | + */ |
|
552 | + public function get_most_recent_registration_for_event($event_id) |
|
553 | + { |
|
554 | + return $this->get_first_related('Registration', |
|
555 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * returns any events attached to this attendee ($_Event property); |
|
561 | + * |
|
562 | + * @return array |
|
563 | + */ |
|
564 | + public function events() |
|
565 | + { |
|
566 | + return $this->get_many_related('Event'); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
572 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
573 | + * used to save the billing info |
|
574 | + * |
|
575 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
576 | + * @return EE_Form_Section_Proper|null |
|
577 | + */ |
|
578 | + public function billing_info_for_payment_method($payment_method) |
|
579 | + { |
|
580 | + $pm_type = $payment_method->type_obj(); |
|
581 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
582 | + return null; |
|
583 | + } |
|
584 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
585 | + if (! $billing_info) { |
|
586 | + return null; |
|
587 | + } |
|
588 | + $billing_form = $pm_type->billing_form(); |
|
589 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
590 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
591 | + } |
|
592 | + return $billing_form; |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + /** |
|
597 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
598 | + * specified payment method |
|
599 | + * |
|
600 | + * @param EE_Payment_Method $payment_method |
|
601 | + * @return string |
|
602 | + */ |
|
603 | + public function get_billing_info_postmeta_name($payment_method) |
|
604 | + { |
|
605 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
606 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
607 | + } else { |
|
608 | + return null; |
|
609 | + } |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
615 | + * retrieve it |
|
616 | + * |
|
617 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
618 | + * @param EE_Payment_Method $payment_method |
|
619 | + * @return boolean |
|
620 | + */ |
|
621 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
622 | + { |
|
623 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
624 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
625 | + return false; |
|
626 | + } |
|
627 | + $billing_form->clean_sensitive_data(); |
|
628 | + return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method), |
|
629 | + $billing_form->input_values(true)); |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * Return the link to the admin details for the object. |
|
635 | + * |
|
636 | + * @return string |
|
637 | + */ |
|
638 | + public function get_admin_details_link() |
|
639 | + { |
|
640 | + return $this->get_admin_edit_link(); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
646 | + * |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function get_admin_edit_link() |
|
650 | + { |
|
651 | + EE_Registry::instance()->load_helper('URL'); |
|
652 | + return EEH_URL::add_query_args_and_nonce( |
|
653 | + array( |
|
654 | + 'page' => 'espresso_registrations', |
|
655 | + 'action' => 'edit_attendee', |
|
656 | + 'post' => $this->ID(), |
|
657 | + ), |
|
658 | + admin_url('admin.php') |
|
659 | + ); |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * Returns the link to a settings page for the object. |
|
665 | + * |
|
666 | + * @return string |
|
667 | + */ |
|
668 | + public function get_admin_settings_link() |
|
669 | + { |
|
670 | + return $this->get_admin_edit_link(); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
676 | + * |
|
677 | + * @return string |
|
678 | + */ |
|
679 | + public function get_admin_overview_link() |
|
680 | + { |
|
681 | + EE_Registry::instance()->load_helper('URL'); |
|
682 | + return EEH_URL::add_query_args_and_nonce( |
|
683 | + array( |
|
684 | + 'page' => 'espresso_registrations', |
|
685 | + 'action' => 'contact_list', |
|
686 | + ), |
|
687 | + admin_url('admin.php') |
|
688 | + ); |
|
689 | + } |
|
690 | 690 | |
691 | 691 | |
692 | 692 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | /** |
@@ -33,16 +33,16 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
35 | 35 | { |
36 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
37 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
36 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
37 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
38 | 38 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
39 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
39 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
40 | 40 | } |
41 | - if (! isset($fieldValues['ATT_slug'])) { |
|
41 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
42 | 42 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
43 | 43 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
44 | 44 | } |
45 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
45 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
46 | 46 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
47 | 47 | } |
48 | 48 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -303,22 +303,22 @@ discard block |
||
303 | 303 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
304 | 304 | foreach ($initial_address_fields as $address_field_name) { |
305 | 305 | $address_fields_value = $this->get($address_field_name); |
306 | - if (! empty($address_fields_value)) { |
|
306 | + if ( ! empty($address_fields_value)) { |
|
307 | 307 | $full_address_array[] = $address_fields_value; |
308 | 308 | } |
309 | 309 | } |
310 | 310 | //now handle state and country |
311 | 311 | $state_obj = $this->state_obj(); |
312 | - if (! empty($state_obj)) { |
|
312 | + if ( ! empty($state_obj)) { |
|
313 | 313 | $full_address_array[] = $state_obj->name(); |
314 | 314 | } |
315 | 315 | $country_obj = $this->country_obj(); |
316 | - if (! empty($country_obj)) { |
|
316 | + if ( ! empty($country_obj)) { |
|
317 | 317 | $full_address_array[] = $country_obj->name(); |
318 | 318 | } |
319 | 319 | //lastly get the xip |
320 | 320 | $zip_value = $this->zip(); |
321 | - if (! empty($zip_value)) { |
|
321 | + if ( ! empty($zip_value)) { |
|
322 | 322 | $full_address_array[] = $zip_value; |
323 | 323 | } |
324 | 324 | return $full_address_array; |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | public function get_most_recent_registration_for_event($event_id) |
553 | 553 | { |
554 | 554 | return $this->get_first_related('Registration', |
555 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
555 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))); //, '=', 'OBJECT_K' ); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | |
@@ -578,11 +578,11 @@ discard block |
||
578 | 578 | public function billing_info_for_payment_method($payment_method) |
579 | 579 | { |
580 | 580 | $pm_type = $payment_method->type_obj(); |
581 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
581 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
582 | 582 | return null; |
583 | 583 | } |
584 | 584 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
585 | - if (! $billing_info) { |
|
585 | + if ( ! $billing_info) { |
|
586 | 586 | return null; |
587 | 587 | } |
588 | 588 | $billing_form = $pm_type->billing_form(); |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | public function get_billing_info_postmeta_name($payment_method) |
604 | 604 | { |
605 | 605 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
606 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
606 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
607 | 607 | } else { |
608 | 608 | return null; |
609 | 609 | } |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | */ |
621 | 621 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
622 | 622 | { |
623 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
623 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
624 | 624 | EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
625 | 625 | return false; |
626 | 626 | } |
@@ -14,132 +14,132 @@ |
||
14 | 14 | class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * opening div tag for a form |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function layout_form_begin() |
|
23 | - { |
|
24 | - return EEH_HTML::div( |
|
25 | - '', |
|
26 | - $this->_form_section->html_id(), |
|
27 | - $this->_form_section->html_class(), |
|
28 | - $this->_form_section->html_style() |
|
29 | - ); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Lays out the row for the input, including label and errors |
|
36 | - * |
|
37 | - * @param EE_Form_Input_Base $input |
|
38 | - * @return string |
|
39 | - * @throws \EE_Error |
|
40 | - */ |
|
41 | - public function layout_input($input) |
|
42 | - { |
|
43 | - $html = ''; |
|
44 | - // set something unique for the id |
|
45 | - $html_id = (string)$input->html_id() !== '' |
|
46 | - ? (string)$input->html_id() |
|
47 | - : spl_object_hash($input); |
|
48 | - // and add a generic input type class |
|
49 | - $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
50 | - if ($input instanceof EE_Hidden_Input) { |
|
51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | - } else if ($input instanceof EE_Submit_Input) { |
|
53 | - $html .= EEH_HTML::div( |
|
54 | - $input->get_html_for_input(), |
|
55 | - $html_id . '-submit-dv', |
|
56 | - "{$input->html_class()}-submit-dv {$html_class}" |
|
57 | - ); |
|
58 | - } else if ($input instanceof EE_Select_Input) { |
|
59 | - $html .= EEH_HTML::div( |
|
60 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | - $html_id . '-input-dv', |
|
65 | - "{$input->html_class()}-input-dv {$html_class}" |
|
66 | - ); |
|
67 | - } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
|
68 | - $html .= EEH_HTML::div( |
|
69 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | - $html_id . '-input-dv', |
|
74 | - "{$input->html_class()}-input-dv {$html_class}" |
|
75 | - ); |
|
76 | - } else { |
|
77 | - $html .= EEH_HTML::div( |
|
78 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | - $html_id . '-input-dv', |
|
83 | - "{$input->html_class()}-input-dv {$html_class}" |
|
84 | - ); |
|
85 | - } |
|
86 | - return $html; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * |
|
93 | - * _display_label_for_option_type_question |
|
94 | - * Gets the HTML for the 'label', which is just text for this (because labels |
|
95 | - * should be for each input) |
|
96 | - * |
|
97 | - * @param EE_Form_Input_With_Options_Base $input |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
101 | - { |
|
102 | - if ($input->display_html_label_text()) { |
|
103 | - return EEH_HTML::div( |
|
104 | - $input->required() |
|
105 | - ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk') |
|
106 | - : $input->html_label_text(), |
|
107 | - $input->html_label_id(), |
|
108 | - $input->required() |
|
109 | - ? 'ee-required-label ' . $input->html_label_class() |
|
110 | - : $input->html_label_class(), |
|
111 | - $input->html_label_style(), |
|
112 | - $input->html_other_attributes() |
|
113 | - ); |
|
114 | - } |
|
115 | - return ''; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Lays out a row for the subsection |
|
122 | - * |
|
123 | - * @param EE_Form_Section_Proper $form_section |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public function layout_subsection($form_section) |
|
127 | - { |
|
128 | - // d( $form_section ); |
|
129 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * closing div tag for a form |
|
136 | - * |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function layout_form_end() |
|
140 | - { |
|
141 | - return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
142 | - } |
|
17 | + /** |
|
18 | + * opening div tag for a form |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function layout_form_begin() |
|
23 | + { |
|
24 | + return EEH_HTML::div( |
|
25 | + '', |
|
26 | + $this->_form_section->html_id(), |
|
27 | + $this->_form_section->html_class(), |
|
28 | + $this->_form_section->html_style() |
|
29 | + ); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Lays out the row for the input, including label and errors |
|
36 | + * |
|
37 | + * @param EE_Form_Input_Base $input |
|
38 | + * @return string |
|
39 | + * @throws \EE_Error |
|
40 | + */ |
|
41 | + public function layout_input($input) |
|
42 | + { |
|
43 | + $html = ''; |
|
44 | + // set something unique for the id |
|
45 | + $html_id = (string)$input->html_id() !== '' |
|
46 | + ? (string)$input->html_id() |
|
47 | + : spl_object_hash($input); |
|
48 | + // and add a generic input type class |
|
49 | + $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
50 | + if ($input instanceof EE_Hidden_Input) { |
|
51 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | + } else if ($input instanceof EE_Submit_Input) { |
|
53 | + $html .= EEH_HTML::div( |
|
54 | + $input->get_html_for_input(), |
|
55 | + $html_id . '-submit-dv', |
|
56 | + "{$input->html_class()}-submit-dv {$html_class}" |
|
57 | + ); |
|
58 | + } else if ($input instanceof EE_Select_Input) { |
|
59 | + $html .= EEH_HTML::div( |
|
60 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | + $html_id . '-input-dv', |
|
65 | + "{$input->html_class()}-input-dv {$html_class}" |
|
66 | + ); |
|
67 | + } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
|
68 | + $html .= EEH_HTML::div( |
|
69 | + EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | + $html_id . '-input-dv', |
|
74 | + "{$input->html_class()}-input-dv {$html_class}" |
|
75 | + ); |
|
76 | + } else { |
|
77 | + $html .= EEH_HTML::div( |
|
78 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | + $html_id . '-input-dv', |
|
83 | + "{$input->html_class()}-input-dv {$html_class}" |
|
84 | + ); |
|
85 | + } |
|
86 | + return $html; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * |
|
93 | + * _display_label_for_option_type_question |
|
94 | + * Gets the HTML for the 'label', which is just text for this (because labels |
|
95 | + * should be for each input) |
|
96 | + * |
|
97 | + * @param EE_Form_Input_With_Options_Base $input |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
101 | + { |
|
102 | + if ($input->display_html_label_text()) { |
|
103 | + return EEH_HTML::div( |
|
104 | + $input->required() |
|
105 | + ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk') |
|
106 | + : $input->html_label_text(), |
|
107 | + $input->html_label_id(), |
|
108 | + $input->required() |
|
109 | + ? 'ee-required-label ' . $input->html_label_class() |
|
110 | + : $input->html_label_class(), |
|
111 | + $input->html_label_style(), |
|
112 | + $input->html_other_attributes() |
|
113 | + ); |
|
114 | + } |
|
115 | + return ''; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Lays out a row for the subsection |
|
122 | + * |
|
123 | + * @param EE_Form_Section_Proper $form_section |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public function layout_subsection($form_section) |
|
127 | + { |
|
128 | + // d( $form_section ); |
|
129 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * closing div tag for a form |
|
136 | + * |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function layout_form_end() |
|
140 | + { |
|
141 | + return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | 145 |
@@ -42,44 +42,44 @@ discard block |
||
42 | 42 | { |
43 | 43 | $html = ''; |
44 | 44 | // set something unique for the id |
45 | - $html_id = (string)$input->html_id() !== '' |
|
46 | - ? (string)$input->html_id() |
|
45 | + $html_id = (string) $input->html_id() !== '' |
|
46 | + ? (string) $input->html_id() |
|
47 | 47 | : spl_object_hash($input); |
48 | 48 | // and add a generic input type class |
49 | - $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
49 | + $html_class = sanitize_key(str_replace('_', '-', get_class($input))).'-dv'; |
|
50 | 50 | if ($input instanceof EE_Hidden_Input) { |
51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
51 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
52 | 52 | } else if ($input instanceof EE_Submit_Input) { |
53 | 53 | $html .= EEH_HTML::div( |
54 | 54 | $input->get_html_for_input(), |
55 | - $html_id . '-submit-dv', |
|
55 | + $html_id.'-submit-dv', |
|
56 | 56 | "{$input->html_class()}-submit-dv {$html_class}" |
57 | 57 | ); |
58 | 58 | } else if ($input instanceof EE_Select_Input) { |
59 | 59 | $html .= EEH_HTML::div( |
60 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | - $html_id . '-input-dv', |
|
60 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
61 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
62 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
63 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
64 | + $html_id.'-input-dv', |
|
65 | 65 | "{$input->html_class()}-input-dv {$html_class}" |
66 | 66 | ); |
67 | 67 | } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
68 | 68 | $html .= EEH_HTML::div( |
69 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | - $html_id . '-input-dv', |
|
69 | + EEH_HTML::nl().$this->_display_label_for_option_type_question($input). |
|
70 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
71 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
72 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
73 | + $html_id.'-input-dv', |
|
74 | 74 | "{$input->html_class()}-input-dv {$html_class}" |
75 | 75 | ); |
76 | 76 | } else { |
77 | 77 | $html .= EEH_HTML::div( |
78 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | - $html_id . '-input-dv', |
|
78 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
79 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
80 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
81 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
82 | + $html_id.'-input-dv', |
|
83 | 83 | "{$input->html_class()}-input-dv {$html_class}" |
84 | 84 | ); |
85 | 85 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | if ($input->display_html_label_text()) { |
103 | 103 | return EEH_HTML::div( |
104 | 104 | $input->required() |
105 | - ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk') |
|
105 | + ? $input->html_label_text().EEH_HTML::span('*', '', 'ee-asterisk') |
|
106 | 106 | : $input->html_label_text(), |
107 | 107 | $input->html_label_id(), |
108 | 108 | $input->required() |
109 | - ? 'ee-required-label ' . $input->html_label_class() |
|
109 | + ? 'ee-required-label '.$input->html_label_class() |
|
110 | 110 | : $input->html_label_class(), |
111 | 111 | $input->html_label_style(), |
112 | 112 | $input->html_other_attributes() |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function layout_subsection($form_section) |
127 | 127 | { |
128 | 128 | // d( $form_section ); |
129 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
129 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
439 | 439 | * function for getting attendees and how many registrations they each have for an event) |
440 | 440 | * |
441 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
441 | + * @return EE_Base_Class[] EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
442 | 442 | * @throws EE_Error |
443 | 443 | */ |
444 | 444 | public function attendees() |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | /** |
490 | 490 | * Gets all payments which have not been approved |
491 | 491 | * |
492 | - * @return EE_Base_Class[]|EEI_Payment[] |
|
492 | + * @return EE_Base_Class[] |
|
493 | 493 | * @throws EE_Error if a model is misconfigured somehow |
494 | 494 | */ |
495 | 495 | public function pending_payments() |
@@ -17,1477 +17,1477 @@ |
||
17 | 17 | class EE_Transaction extends EE_Base_Class implements EEI_Transaction |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * The length of time in seconds that a lock is applied before being considered expired. |
|
22 | - * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
23 | - */ |
|
24 | - const LOCK_EXPIRATION = 2; |
|
25 | - |
|
26 | - /** |
|
27 | - * txn status upon initial construction. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_old_txn_status; |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @param array $props_n_values incoming values |
|
37 | - * @param string $timezone incoming timezone |
|
38 | - * (if not set the timezone set for the website will be used.) |
|
39 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
40 | - * date_format and the second value is the time format |
|
41 | - * @return EE_Transaction |
|
42 | - * @throws EE_Error |
|
43 | - */ |
|
44 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
45 | - { |
|
46 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
47 | - $txn = $has_object |
|
48 | - ? $has_object |
|
49 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
50 | - if (! $has_object) { |
|
51 | - $txn->set_old_txn_status($txn->status_ID()); |
|
52 | - } |
|
53 | - return $txn; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param array $props_n_values incoming values from the database |
|
60 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
61 | - * the website will be used. |
|
62 | - * @return EE_Transaction |
|
63 | - * @throws EE_Error |
|
64 | - */ |
|
65 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
66 | - { |
|
67 | - $txn = new self($props_n_values, true, $timezone); |
|
68 | - $txn->set_old_txn_status($txn->status_ID()); |
|
69 | - return $txn; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
76 | - * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
77 | - * If that also fails, then an exception is thrown. |
|
78 | - * |
|
79 | - * @throws EE_Error |
|
80 | - */ |
|
81 | - public function lock() |
|
82 | - { |
|
83 | - // attempt to set lock, but if that fails... |
|
84 | - if (! $this->add_extra_meta('lock', time(), true)) { |
|
85 | - // then attempt to remove the lock in case it is expired |
|
86 | - if ($this->_remove_expired_lock()) { |
|
87 | - // if removal was successful, then try setting lock again |
|
88 | - $this->lock(); |
|
89 | - } else { |
|
90 | - // but if the lock can not be removed, then throw an exception |
|
91 | - throw new EE_Error( |
|
92 | - sprintf( |
|
93 | - __( |
|
94 | - 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
95 | - 'event_espresso' |
|
96 | - ), |
|
97 | - $this->ID() |
|
98 | - ) |
|
99 | - ); |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * removes transaction lock applied in EE_Transaction::lock() |
|
108 | - * |
|
109 | - * @return int |
|
110 | - * @throws EE_Error |
|
111 | - */ |
|
112 | - public function unlock() |
|
113 | - { |
|
114 | - return $this->delete_extra_meta('lock'); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Decides whether or not now is the right time to update the transaction. |
|
121 | - * This is useful because we don't always know if it is safe to update the transaction |
|
122 | - * and its related data. why? |
|
123 | - * because it's possible that the transaction is being used in another |
|
124 | - * request and could overwrite anything we save. |
|
125 | - * So we want to only update the txn once we know that won't happen. |
|
126 | - * We also check that the lock isn't expired, and remove it if it is |
|
127 | - * |
|
128 | - * @return boolean |
|
129 | - * @throws EE_Error |
|
130 | - */ |
|
131 | - public function is_locked() |
|
132 | - { |
|
133 | - // if TXN is not locked, then return false immediately |
|
134 | - if (! $this->_get_lock()) { |
|
135 | - return false; |
|
136 | - } |
|
137 | - // if not, then let's try and remove the lock in case it's expired... |
|
138 | - // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
139 | - // and a positive number if the lock was removed (ie: number of locks deleted), |
|
140 | - // so we need to return the opposite |
|
141 | - return ! $this->_remove_expired_lock() ? true : false; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Gets the meta field indicating that this TXN is locked |
|
148 | - * |
|
149 | - * @return int |
|
150 | - * @throws EE_Error |
|
151 | - */ |
|
152 | - protected function _get_lock() |
|
153 | - { |
|
154 | - return (int)$this->get_extra_meta('lock', true, 0); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
161 | - * |
|
162 | - * @return int |
|
163 | - * @throws EE_Error |
|
164 | - */ |
|
165 | - protected function _remove_expired_lock() |
|
166 | - { |
|
167 | - $locked = $this->_get_lock(); |
|
168 | - if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
169 | - return $this->unlock(); |
|
170 | - } |
|
171 | - return 0; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Set transaction total |
|
178 | - * |
|
179 | - * @param float $total total value of transaction |
|
180 | - * @throws EE_Error |
|
181 | - */ |
|
182 | - public function set_total($total = 0.00) |
|
183 | - { |
|
184 | - $this->set('TXN_total', (float)$total); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Set Total Amount Paid to Date |
|
191 | - * |
|
192 | - * @param float $total_paid total amount paid to date (sum of all payments) |
|
193 | - * @throws EE_Error |
|
194 | - */ |
|
195 | - public function set_paid($total_paid = 0.00) |
|
196 | - { |
|
197 | - $this->set('TXN_paid', (float)$total_paid); |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Set transaction status |
|
204 | - * |
|
205 | - * @param string $status whether the transaction is open, declined, accepted, |
|
206 | - * or any number of custom values that can be set |
|
207 | - * @throws EE_Error |
|
208 | - */ |
|
209 | - public function set_status($status = '') |
|
210 | - { |
|
211 | - $this->set('STS_ID', $status); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Set hash salt |
|
218 | - * |
|
219 | - * @param string $hash_salt required for some payment gateways |
|
220 | - * @throws EE_Error |
|
221 | - */ |
|
222 | - public function set_hash_salt($hash_salt = '') |
|
223 | - { |
|
224 | - $this->set('TXN_hash_salt', $hash_salt); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Sets TXN_reg_steps array |
|
231 | - * |
|
232 | - * @param array $txn_reg_steps |
|
233 | - * @throws EE_Error |
|
234 | - */ |
|
235 | - public function set_reg_steps(array $txn_reg_steps) |
|
236 | - { |
|
237 | - $this->set('TXN_reg_steps', $txn_reg_steps); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Gets TXN_reg_steps |
|
244 | - * |
|
245 | - * @return array |
|
246 | - * @throws EE_Error |
|
247 | - */ |
|
248 | - public function reg_steps() |
|
249 | - { |
|
250 | - $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
251 | - return is_array($TXN_reg_steps) ? (array)$TXN_reg_steps : array(); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return string of transaction's total cost, with currency symbol and decimal |
|
258 | - * @throws EE_Error |
|
259 | - */ |
|
260 | - public function pretty_total() |
|
261 | - { |
|
262 | - return $this->get_pretty('TXN_total'); |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
269 | - * |
|
270 | - * @return string |
|
271 | - * @throws EE_Error |
|
272 | - */ |
|
273 | - public function pretty_paid() |
|
274 | - { |
|
275 | - return $this->get_pretty('TXN_paid'); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * calculate the amount remaining for this transaction and return; |
|
282 | - * |
|
283 | - * @return float amount remaining |
|
284 | - * @throws EE_Error |
|
285 | - */ |
|
286 | - public function remaining() |
|
287 | - { |
|
288 | - return $this->total() - $this->paid(); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * get Transaction Total |
|
295 | - * |
|
296 | - * @return float |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - public function total() |
|
300 | - { |
|
301 | - return (float)$this->get('TXN_total'); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * get Total Amount Paid to Date |
|
308 | - * |
|
309 | - * @return float |
|
310 | - * @throws EE_Error |
|
311 | - */ |
|
312 | - public function paid() |
|
313 | - { |
|
314 | - return (float)$this->get('TXN_paid'); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * @throws EE_Error |
|
321 | - */ |
|
322 | - public function get_cart_session() |
|
323 | - { |
|
324 | - $session_data = (array)$this->get('TXN_session_data'); |
|
325 | - return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
326 | - ? $session_data['cart'] |
|
327 | - : null; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * get Transaction session data |
|
334 | - * |
|
335 | - * @throws EE_Error |
|
336 | - */ |
|
337 | - public function session_data() |
|
338 | - { |
|
339 | - $session_data = $this->get('TXN_session_data'); |
|
340 | - if (empty($session_data)) { |
|
341 | - $session_data = array( |
|
342 | - 'id' => null, |
|
343 | - 'user_id' => null, |
|
344 | - 'ip_address' => null, |
|
345 | - 'user_agent' => null, |
|
346 | - 'init_access' => null, |
|
347 | - 'last_access' => null, |
|
348 | - 'pages_visited' => array(), |
|
349 | - ); |
|
350 | - } |
|
351 | - return $session_data; |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * Set session data within the TXN object |
|
358 | - * |
|
359 | - * @param EE_Session|array $session_data |
|
360 | - * @throws EE_Error |
|
361 | - */ |
|
362 | - public function set_txn_session_data($session_data) |
|
363 | - { |
|
364 | - if ($session_data instanceof EE_Session) { |
|
365 | - $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
366 | - } else { |
|
367 | - $this->set('TXN_session_data', $session_data); |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * get Transaction hash salt |
|
375 | - * |
|
376 | - * @throws EE_Error |
|
377 | - */ |
|
378 | - public function hash_salt_() |
|
379 | - { |
|
380 | - return $this->get('TXN_hash_salt'); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Returns the transaction datetime as either: |
|
387 | - * - unix timestamp format ($format = false, $gmt = true) |
|
388 | - * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
389 | - * has no affect with this option)), this also may include a timezone abbreviation if the |
|
390 | - * set timezone in this class differs from what the timezone is on the blog. |
|
391 | - * - formatted date string including the UTC (timezone) offset (default). |
|
392 | - * |
|
393 | - * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
394 | - * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
395 | - * or no UTC offset applied |
|
396 | - * @return string | int |
|
397 | - * @throws EE_Error |
|
398 | - */ |
|
399 | - public function datetime($format = false, $gmt = false) |
|
400 | - { |
|
401 | - if ($format) { |
|
402 | - return $this->get_pretty('TXN_timestamp'); |
|
403 | - } |
|
404 | - if ($gmt) { |
|
405 | - return $this->get_raw('TXN_timestamp'); |
|
406 | - } |
|
407 | - return $this->get('TXN_timestamp'); |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Gets registrations on this transaction |
|
414 | - * |
|
415 | - * @param array $query_params array of query parameters |
|
416 | - * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
417 | - * @return EE_Base_Class[]|EE_Registration[] |
|
418 | - * @throws EE_Error |
|
419 | - */ |
|
420 | - public function registrations($query_params = array(), $get_cached = false) |
|
421 | - { |
|
422 | - $query_params = (empty($query_params) || ! is_array($query_params)) |
|
423 | - ? array( |
|
424 | - 'order_by' => array( |
|
425 | - 'Event.EVT_name' => 'ASC', |
|
426 | - 'Attendee.ATT_lname' => 'ASC', |
|
427 | - 'Attendee.ATT_fname' => 'ASC', |
|
428 | - ), |
|
429 | - ) |
|
430 | - : $query_params; |
|
431 | - $query_params = $get_cached ? array() : $query_params; |
|
432 | - return $this->get_many_related('Registration', $query_params); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
439 | - * function for getting attendees and how many registrations they each have for an event) |
|
440 | - * |
|
441 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
442 | - * @throws EE_Error |
|
443 | - */ |
|
444 | - public function attendees() |
|
445 | - { |
|
446 | - return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
453 | - * |
|
454 | - * @param array $query_params like EEM_Base::get_all |
|
455 | - * @return EE_Base_Class[]|EE_Payment[] |
|
456 | - * @throws EE_Error |
|
457 | - */ |
|
458 | - public function payments($query_params = array()) |
|
459 | - { |
|
460 | - return $this->get_many_related('Payment', $query_params); |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * gets only approved payments for this transaction |
|
467 | - * |
|
468 | - * @return EE_Base_Class[]|EE_Payment[] |
|
469 | - * @throws EE_Error |
|
470 | - * @throws InvalidArgumentException |
|
471 | - * @throws ReflectionException |
|
472 | - * @throws InvalidDataTypeException |
|
473 | - * @throws InvalidInterfaceException |
|
474 | - */ |
|
475 | - public function approved_payments() |
|
476 | - { |
|
477 | - EE_Registry::instance()->load_model('Payment'); |
|
478 | - return $this->get_many_related( |
|
479 | - 'Payment', |
|
480 | - array( |
|
481 | - array('STS_ID' => EEM_Payment::status_id_approved), |
|
482 | - 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
483 | - ) |
|
484 | - ); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Gets all payments which have not been approved |
|
491 | - * |
|
492 | - * @return EE_Base_Class[]|EEI_Payment[] |
|
493 | - * @throws EE_Error if a model is misconfigured somehow |
|
494 | - */ |
|
495 | - public function pending_payments() |
|
496 | - { |
|
497 | - return $this->get_many_related( |
|
498 | - 'Payment', |
|
499 | - array( |
|
500 | - array( |
|
501 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
502 | - ), |
|
503 | - 'order_by' => array( |
|
504 | - 'PAY_timestamp' => 'DESC', |
|
505 | - ), |
|
506 | - ) |
|
507 | - ); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * echoes $this->pretty_status() |
|
514 | - * |
|
515 | - * @param bool $show_icons |
|
516 | - * @throws EE_Error |
|
517 | - * @throws InvalidArgumentException |
|
518 | - * @throws InvalidDataTypeException |
|
519 | - * @throws InvalidInterfaceException |
|
520 | - */ |
|
521 | - public function e_pretty_status($show_icons = false) |
|
522 | - { |
|
523 | - echo $this->pretty_status($show_icons); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * returns a pretty version of the status, good for displaying to users |
|
530 | - * |
|
531 | - * @param bool $show_icons |
|
532 | - * @return string |
|
533 | - * @throws EE_Error |
|
534 | - * @throws InvalidArgumentException |
|
535 | - * @throws InvalidDataTypeException |
|
536 | - * @throws InvalidInterfaceException |
|
537 | - */ |
|
538 | - public function pretty_status($show_icons = false) |
|
539 | - { |
|
540 | - $status = EEM_Status::instance()->localized_status( |
|
541 | - array($this->status_ID() => __('unknown', 'event_espresso')), |
|
542 | - false, |
|
543 | - 'sentence' |
|
544 | - ); |
|
545 | - $icon = ''; |
|
546 | - switch ($this->status_ID()) { |
|
547 | - case EEM_Transaction::complete_status_code: |
|
548 | - $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
549 | - break; |
|
550 | - case EEM_Transaction::incomplete_status_code: |
|
551 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
552 | - : ''; |
|
553 | - break; |
|
554 | - case EEM_Transaction::abandoned_status_code: |
|
555 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
556 | - break; |
|
557 | - case EEM_Transaction::failed_status_code: |
|
558 | - $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
559 | - break; |
|
560 | - case EEM_Transaction::overpaid_status_code: |
|
561 | - $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
562 | - break; |
|
563 | - } |
|
564 | - return $icon . $status[$this->status_ID()]; |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * get Transaction Status |
|
571 | - * |
|
572 | - * @throws EE_Error |
|
573 | - */ |
|
574 | - public function status_ID() |
|
575 | - { |
|
576 | - return $this->get('STS_ID'); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
583 | - * |
|
584 | - * @return boolean |
|
585 | - * @throws EE_Error |
|
586 | - */ |
|
587 | - public function is_free() |
|
588 | - { |
|
589 | - return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Returns whether this transaction is complete |
|
596 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
597 | - * |
|
598 | - * @return boolean |
|
599 | - * @throws EE_Error |
|
600 | - */ |
|
601 | - public function is_completed() |
|
602 | - { |
|
603 | - return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - |
|
608 | - /** |
|
609 | - * Returns whether this transaction is incomplete |
|
610 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
611 | - * |
|
612 | - * @return boolean |
|
613 | - * @throws EE_Error |
|
614 | - */ |
|
615 | - public function is_incomplete() |
|
616 | - { |
|
617 | - return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * Returns whether this transaction is overpaid |
|
624 | - * Useful in templates and other logic for deciding if monies need to be refunded |
|
625 | - * |
|
626 | - * @return boolean |
|
627 | - * @throws EE_Error |
|
628 | - */ |
|
629 | - public function is_overpaid() |
|
630 | - { |
|
631 | - return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * Returns whether this transaction was abandoned |
|
638 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
639 | - * but that contact information exists for at least one registrant |
|
640 | - * |
|
641 | - * @return boolean |
|
642 | - * @throws EE_Error |
|
643 | - */ |
|
644 | - public function is_abandoned() |
|
645 | - { |
|
646 | - return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * Returns whether this transaction failed |
|
653 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
654 | - * and that NO contact information exists for any registrants |
|
655 | - * |
|
656 | - * @return boolean |
|
657 | - * @throws EE_Error |
|
658 | - */ |
|
659 | - public function failed() |
|
660 | - { |
|
661 | - return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - |
|
666 | - /** |
|
667 | - * This returns the url for the invoice of this transaction |
|
668 | - * |
|
669 | - * @param string $type 'html' or 'pdf' (default is pdf) |
|
670 | - * @return string |
|
671 | - * @throws EE_Error |
|
672 | - */ |
|
673 | - public function invoice_url($type = 'html') |
|
674 | - { |
|
675 | - $REG = $this->primary_registration(); |
|
676 | - if (! $REG instanceof EE_Registration) { |
|
677 | - return ''; |
|
678 | - } |
|
679 | - return $REG->invoice_url($type); |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * Gets the primary registration only |
|
686 | - * |
|
687 | - * @return EE_Base_Class|EE_Registration |
|
688 | - * @throws EE_Error |
|
689 | - */ |
|
690 | - public function primary_registration() |
|
691 | - { |
|
692 | - $registrations = (array)$this->get_many_related( |
|
693 | - 'Registration', |
|
694 | - array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
695 | - ); |
|
696 | - foreach ($registrations as $registration) { |
|
697 | - // valid registration that is NOT cancelled or declined ? |
|
698 | - if ( |
|
699 | - $registration instanceof EE_Registration |
|
700 | - && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
701 | - ) { |
|
702 | - return $registration; |
|
703 | - } |
|
704 | - } |
|
705 | - // nothing valid found, so just return first thing from array of results |
|
706 | - return reset($registrations); |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * Gets the URL for viewing the receipt |
|
713 | - * |
|
714 | - * @param string $type 'pdf' or 'html' (default is 'html') |
|
715 | - * @return string |
|
716 | - * @throws EE_Error |
|
717 | - */ |
|
718 | - public function receipt_url($type = 'html') |
|
719 | - { |
|
720 | - $REG = $this->primary_registration(); |
|
721 | - if (! $REG instanceof EE_Registration) { |
|
722 | - return ''; |
|
723 | - } |
|
724 | - return $REG->receipt_url($type); |
|
725 | - } |
|
726 | - |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
731 | - * a query parameter |
|
732 | - * |
|
733 | - * @return string |
|
734 | - * @throws EE_Error |
|
735 | - */ |
|
736 | - public function payment_overview_url() |
|
737 | - { |
|
738 | - $primary_registration = $this->primary_registration(); |
|
739 | - return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - |
|
744 | - /** |
|
745 | - * @return string |
|
746 | - * @throws EE_Error |
|
747 | - */ |
|
748 | - public function gateway_response_on_transaction() |
|
749 | - { |
|
750 | - $payment = $this->get_first_related('Payment'); |
|
751 | - return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
752 | - } |
|
753 | - |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * Get the status object of this object |
|
758 | - * |
|
759 | - * @return EE_Base_Class|EE_Status |
|
760 | - * @throws EE_Error |
|
761 | - */ |
|
762 | - public function status_obj() |
|
763 | - { |
|
764 | - return $this->get_first_related('Status'); |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * Gets all the extra meta info on this payment |
|
771 | - * |
|
772 | - * @param array $query_params like EEM_Base::get_all |
|
773 | - * @return EE_Base_Class[]|EE_Extra_Meta |
|
774 | - * @throws EE_Error |
|
775 | - */ |
|
776 | - public function extra_meta($query_params = array()) |
|
777 | - { |
|
778 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
779 | - } |
|
780 | - |
|
781 | - |
|
782 | - |
|
783 | - /** |
|
784 | - * Wrapper for _add_relation_to |
|
785 | - * |
|
786 | - * @param EE_Registration $registration |
|
787 | - * @return EE_Base_Class the relation was added to |
|
788 | - * @throws EE_Error |
|
789 | - */ |
|
790 | - public function add_registration(EE_Registration $registration) |
|
791 | - { |
|
792 | - return $this->_add_relation_to($registration, 'Registration'); |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - |
|
797 | - /** |
|
798 | - * Removes the given registration from being related (even before saving this transaction). |
|
799 | - * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
800 | - * |
|
801 | - * @param int $registration_or_id |
|
802 | - * @return EE_Base_Class that was removed from being related |
|
803 | - * @throws EE_Error |
|
804 | - */ |
|
805 | - public function remove_registration_with_id($registration_or_id) |
|
806 | - { |
|
807 | - return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - |
|
812 | - /** |
|
813 | - * Gets all the line items which are for ACTUAL items |
|
814 | - * |
|
815 | - * @return EE_Line_Item[] |
|
816 | - * @throws EE_Error |
|
817 | - */ |
|
818 | - public function items_purchased() |
|
819 | - { |
|
820 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * Wrapper for _add_relation_to |
|
827 | - * |
|
828 | - * @param EE_Line_Item $line_item |
|
829 | - * @return EE_Base_Class the relation was added to |
|
830 | - * @throws EE_Error |
|
831 | - */ |
|
832 | - public function add_line_item(EE_Line_Item $line_item) |
|
833 | - { |
|
834 | - return $this->_add_relation_to($line_item, 'Line_Item'); |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - |
|
839 | - /** |
|
840 | - * Gets ALL the line items related to this transaction (unstructured) |
|
841 | - * |
|
842 | - * @param array $query_params |
|
843 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
844 | - * @throws EE_Error |
|
845 | - */ |
|
846 | - public function line_items($query_params = array()) |
|
847 | - { |
|
848 | - return $this->get_many_related('Line_Item', $query_params); |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * Gets all the line items which are taxes on the total |
|
855 | - * |
|
856 | - * @return EE_Line_Item[] |
|
857 | - * @throws EE_Error |
|
858 | - */ |
|
859 | - public function tax_items() |
|
860 | - { |
|
861 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - |
|
866 | - /** |
|
867 | - * Gets the total line item (which is a parent of all other related line items, |
|
868 | - * meaning it takes them all into account on its total) |
|
869 | - * |
|
870 | - * @param bool $create_if_not_found |
|
871 | - * @return \EE_Line_Item |
|
872 | - * @throws EE_Error |
|
873 | - */ |
|
874 | - public function total_line_item($create_if_not_found = true) |
|
875 | - { |
|
876 | - $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
877 | - if (! $item && $create_if_not_found) { |
|
878 | - $item = EEH_Line_Item::create_total_line_item($this); |
|
879 | - } |
|
880 | - return $item; |
|
881 | - } |
|
882 | - |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * Returns the total amount of tax on this transaction |
|
887 | - * (assumes there's only one tax subtotal line item) |
|
888 | - * |
|
889 | - * @return float |
|
890 | - * @throws EE_Error |
|
891 | - */ |
|
892 | - public function tax_total() |
|
893 | - { |
|
894 | - $tax_line_item = $this->tax_total_line_item(); |
|
895 | - if ($tax_line_item) { |
|
896 | - return (float)$tax_line_item->total(); |
|
897 | - } |
|
898 | - return (float)0; |
|
899 | - } |
|
900 | - |
|
901 | - |
|
902 | - |
|
903 | - /** |
|
904 | - * Gets the tax subtotal line item (assumes there's only one) |
|
905 | - * |
|
906 | - * @return EE_Line_Item |
|
907 | - * @throws EE_Error |
|
908 | - */ |
|
909 | - public function tax_total_line_item() |
|
910 | - { |
|
911 | - return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
912 | - } |
|
913 | - |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
918 | - * |
|
919 | - * @return EE_Form_Section_Proper |
|
920 | - * @throws EE_Error |
|
921 | - */ |
|
922 | - public function billing_info() |
|
923 | - { |
|
924 | - $payment_method = $this->payment_method(); |
|
925 | - if (! $payment_method) { |
|
926 | - EE_Error::add_error( |
|
927 | - __( |
|
928 | - 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
929 | - 'event_espresso' |
|
930 | - ), |
|
931 | - __FILE__, |
|
932 | - __FUNCTION__, |
|
933 | - __LINE__ |
|
934 | - ); |
|
935 | - return null; |
|
936 | - } |
|
937 | - $primary_reg = $this->primary_registration(); |
|
938 | - if (! $primary_reg) { |
|
939 | - EE_Error::add_error( |
|
940 | - __( |
|
941 | - 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
942 | - 'event_espresso' |
|
943 | - ), |
|
944 | - __FILE__, |
|
945 | - __FUNCTION__, |
|
946 | - __LINE__ |
|
947 | - ); |
|
948 | - return null; |
|
949 | - } |
|
950 | - $attendee = $primary_reg->attendee(); |
|
951 | - if (! $attendee) { |
|
952 | - EE_Error::add_error( |
|
953 | - __( |
|
954 | - 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
955 | - 'event_espresso' |
|
956 | - ), |
|
957 | - __FILE__, |
|
958 | - __FUNCTION__, |
|
959 | - __LINE__ |
|
960 | - ); |
|
961 | - return null; |
|
962 | - } |
|
963 | - return $attendee->billing_info_for_payment_method($payment_method); |
|
964 | - } |
|
965 | - |
|
966 | - |
|
967 | - |
|
968 | - /** |
|
969 | - * Gets PMD_ID |
|
970 | - * |
|
971 | - * @return int |
|
972 | - * @throws EE_Error |
|
973 | - */ |
|
974 | - public function payment_method_ID() |
|
975 | - { |
|
976 | - return $this->get('PMD_ID'); |
|
977 | - } |
|
978 | - |
|
979 | - |
|
980 | - |
|
981 | - /** |
|
982 | - * Sets PMD_ID |
|
983 | - * |
|
984 | - * @param int $PMD_ID |
|
985 | - * @throws EE_Error |
|
986 | - */ |
|
987 | - public function set_payment_method_ID($PMD_ID) |
|
988 | - { |
|
989 | - $this->set('PMD_ID', $PMD_ID); |
|
990 | - } |
|
991 | - |
|
992 | - |
|
993 | - |
|
994 | - /** |
|
995 | - * Gets the last-used payment method on this transaction |
|
996 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
997 | - * offline ones, dont' create payments) |
|
998 | - * |
|
999 | - * @return EE_Payment_Method |
|
1000 | - * @throws EE_Error |
|
1001 | - */ |
|
1002 | - public function payment_method() |
|
1003 | - { |
|
1004 | - $pm = $this->get_first_related('Payment_Method'); |
|
1005 | - if ($pm instanceof EE_Payment_Method) { |
|
1006 | - return $pm; |
|
1007 | - } |
|
1008 | - $last_payment = $this->last_payment(); |
|
1009 | - if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
1010 | - return $last_payment->payment_method(); |
|
1011 | - } |
|
1012 | - return null; |
|
1013 | - } |
|
1014 | - |
|
1015 | - |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * Gets the last payment made |
|
1019 | - * |
|
1020 | - * @return EE_Base_Class|EE_Payment |
|
1021 | - * @throws EE_Error |
|
1022 | - */ |
|
1023 | - public function last_payment() |
|
1024 | - { |
|
1025 | - return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
1026 | - } |
|
1027 | - |
|
1028 | - |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * Gets all the line items which are unrelated to tickets on this transaction |
|
1032 | - * |
|
1033 | - * @return EE_Line_Item[] |
|
1034 | - * @throws EE_Error |
|
1035 | - * @throws InvalidArgumentException |
|
1036 | - * @throws InvalidDataTypeException |
|
1037 | - * @throws InvalidInterfaceException |
|
1038 | - */ |
|
1039 | - public function non_ticket_line_items() |
|
1040 | - { |
|
1041 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
1042 | - } |
|
1043 | - |
|
1044 | - |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * possibly toggles TXN status |
|
1048 | - * |
|
1049 | - * @param boolean $update whether to save the TXN |
|
1050 | - * @return bool whether the TXN was saved |
|
1051 | - * @throws EE_Error |
|
1052 | - * @throws RuntimeException |
|
1053 | - */ |
|
1054 | - public function update_status_based_on_total_paid($update = true) |
|
1055 | - { |
|
1056 | - // set transaction status based on comparison of TXN_paid vs TXN_total |
|
1057 | - if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
1058 | - $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
1059 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
1060 | - $new_txn_status = EEM_Transaction::complete_status_code; |
|
1061 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
1062 | - $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
1063 | - } else { |
|
1064 | - throw new RuntimeException( |
|
1065 | - __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
1066 | - ); |
|
1067 | - } |
|
1068 | - if ($new_txn_status !== $this->status_ID()) { |
|
1069 | - $this->set_status($new_txn_status); |
|
1070 | - if ($update) { |
|
1071 | - return $this->save() ? true : false; |
|
1072 | - } |
|
1073 | - } |
|
1074 | - return false; |
|
1075 | - } |
|
1076 | - |
|
1077 | - |
|
1078 | - |
|
1079 | - /** |
|
1080 | - * Updates the transaction's status and total_paid based on all the payments |
|
1081 | - * that apply to it |
|
1082 | - * |
|
1083 | - * @deprecated |
|
1084 | - * @return array|bool |
|
1085 | - * @throws EE_Error |
|
1086 | - * @throws InvalidArgumentException |
|
1087 | - * @throws ReflectionException |
|
1088 | - * @throws InvalidDataTypeException |
|
1089 | - * @throws InvalidInterfaceException |
|
1090 | - */ |
|
1091 | - public function update_based_on_payments() |
|
1092 | - { |
|
1093 | - EE_Error::doing_it_wrong( |
|
1094 | - __CLASS__ . '::' . __FUNCTION__, |
|
1095 | - sprintf( |
|
1096 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
1097 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
1098 | - ), |
|
1099 | - '4.6.0' |
|
1100 | - ); |
|
1101 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
1102 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1103 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
1104 | - } |
|
1105 | - |
|
1106 | - |
|
1107 | - |
|
1108 | - /** |
|
1109 | - * @return string |
|
1110 | - */ |
|
1111 | - public function old_txn_status() |
|
1112 | - { |
|
1113 | - return $this->_old_txn_status; |
|
1114 | - } |
|
1115 | - |
|
1116 | - |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * @param string $old_txn_status |
|
1120 | - */ |
|
1121 | - public function set_old_txn_status($old_txn_status) |
|
1122 | - { |
|
1123 | - // only set the first time |
|
1124 | - if ($this->_old_txn_status === null) { |
|
1125 | - $this->_old_txn_status = $old_txn_status; |
|
1126 | - } |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * reg_status_updated |
|
1133 | - * |
|
1134 | - * @return bool |
|
1135 | - * @throws EE_Error |
|
1136 | - */ |
|
1137 | - public function txn_status_updated() |
|
1138 | - { |
|
1139 | - return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - |
|
1144 | - /** |
|
1145 | - * _reg_steps_completed |
|
1146 | - * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
1147 | - * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
1148 | - * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
1149 | - * |
|
1150 | - * @param string $reg_step_slug |
|
1151 | - * @param bool $check_all |
|
1152 | - * @return bool|int |
|
1153 | - * @throws EE_Error |
|
1154 | - */ |
|
1155 | - private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
1156 | - { |
|
1157 | - $reg_steps = $this->reg_steps(); |
|
1158 | - if (! is_array($reg_steps) || empty($reg_steps)) { |
|
1159 | - return false; |
|
1160 | - } |
|
1161 | - // loop thru reg steps array) |
|
1162 | - foreach ($reg_steps as $slug => $reg_step_completed) { |
|
1163 | - // if NOT checking ALL steps (only checking one step) |
|
1164 | - if (! $check_all) { |
|
1165 | - // and this is the one |
|
1166 | - if ($slug === $reg_step_slug) { |
|
1167 | - return $reg_step_completed; |
|
1168 | - } |
|
1169 | - // skip to next reg step in loop |
|
1170 | - continue; |
|
1171 | - } |
|
1172 | - // $check_all must be true, else we would never have gotten to this point |
|
1173 | - if ($slug === $reg_step_slug) { |
|
1174 | - // if we reach this point, then we are testing either: |
|
1175 | - // all_reg_steps_completed_except() or |
|
1176 | - // all_reg_steps_completed_except_final_step(), |
|
1177 | - // and since this is the reg step EXCEPTION being tested |
|
1178 | - // we want to return true (yes true) if this reg step is NOT completed |
|
1179 | - // ie: "is everything completed except the final step?" |
|
1180 | - // "that is correct... the final step is not completed, but all others are." |
|
1181 | - return $reg_step_completed !== true; |
|
1182 | - } |
|
1183 | - if ($reg_step_completed !== true) { |
|
1184 | - // if any reg step is NOT completed, then ALL steps are not completed |
|
1185 | - return false; |
|
1186 | - } |
|
1187 | - } |
|
1188 | - return true; |
|
1189 | - } |
|
1190 | - |
|
1191 | - |
|
1192 | - |
|
1193 | - /** |
|
1194 | - * all_reg_steps_completed |
|
1195 | - * returns: |
|
1196 | - * true if ALL reg steps have been marked as completed |
|
1197 | - * or false if any step is not completed |
|
1198 | - * |
|
1199 | - * @return bool |
|
1200 | - * @throws EE_Error |
|
1201 | - */ |
|
1202 | - public function all_reg_steps_completed() |
|
1203 | - { |
|
1204 | - return $this->_reg_steps_completed(); |
|
1205 | - } |
|
1206 | - |
|
1207 | - |
|
1208 | - |
|
1209 | - /** |
|
1210 | - * all_reg_steps_completed_except |
|
1211 | - * returns: |
|
1212 | - * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
1213 | - * or false if any other step is not completed |
|
1214 | - * or false if ALL steps are completed including the exception you are testing !!! |
|
1215 | - * |
|
1216 | - * @param string $exception |
|
1217 | - * @return bool |
|
1218 | - * @throws EE_Error |
|
1219 | - */ |
|
1220 | - public function all_reg_steps_completed_except($exception = '') |
|
1221 | - { |
|
1222 | - return $this->_reg_steps_completed($exception); |
|
1223 | - } |
|
1224 | - |
|
1225 | - |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * all_reg_steps_completed_except |
|
1229 | - * returns: |
|
1230 | - * true if ALL reg steps, except the final step, have been marked as completed |
|
1231 | - * or false if any step is not completed |
|
1232 | - * or false if ALL steps are completed including the final step !!! |
|
1233 | - * |
|
1234 | - * @return bool |
|
1235 | - * @throws EE_Error |
|
1236 | - */ |
|
1237 | - public function all_reg_steps_completed_except_final_step() |
|
1238 | - { |
|
1239 | - return $this->_reg_steps_completed('finalize_registration'); |
|
1240 | - } |
|
1241 | - |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * reg_step_completed |
|
1246 | - * returns: |
|
1247 | - * true if a specific reg step has been marked as completed |
|
1248 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
1249 | - * or false if it has not yet been initialized |
|
1250 | - * |
|
1251 | - * @param string $reg_step_slug |
|
1252 | - * @return bool|int |
|
1253 | - * @throws EE_Error |
|
1254 | - */ |
|
1255 | - public function reg_step_completed($reg_step_slug) |
|
1256 | - { |
|
1257 | - return $this->_reg_steps_completed($reg_step_slug, false); |
|
1258 | - } |
|
1259 | - |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * completed_final_reg_step |
|
1264 | - * returns: |
|
1265 | - * true if the finalize_registration reg step has been marked as completed |
|
1266 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
1267 | - * or false if it has not yet been initialized |
|
1268 | - * |
|
1269 | - * @return bool|int |
|
1270 | - * @throws EE_Error |
|
1271 | - */ |
|
1272 | - public function final_reg_step_completed() |
|
1273 | - { |
|
1274 | - return $this->_reg_steps_completed('finalize_registration', false); |
|
1275 | - } |
|
1276 | - |
|
1277 | - |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * set_reg_step_initiated |
|
1281 | - * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
1282 | - * |
|
1283 | - * @param string $reg_step_slug |
|
1284 | - * @return boolean |
|
1285 | - * @throws EE_Error |
|
1286 | - */ |
|
1287 | - public function set_reg_step_initiated($reg_step_slug) |
|
1288 | - { |
|
1289 | - return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
1290 | - } |
|
1291 | - |
|
1292 | - |
|
1293 | - |
|
1294 | - /** |
|
1295 | - * set_reg_step_completed |
|
1296 | - * given a valid TXN_reg_step, this sets the step as completed |
|
1297 | - * |
|
1298 | - * @param string $reg_step_slug |
|
1299 | - * @return boolean |
|
1300 | - * @throws EE_Error |
|
1301 | - */ |
|
1302 | - public function set_reg_step_completed($reg_step_slug) |
|
1303 | - { |
|
1304 | - return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
1305 | - } |
|
1306 | - |
|
1307 | - |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * set_reg_step_completed |
|
1311 | - * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
1312 | - * |
|
1313 | - * @param string $reg_step_slug |
|
1314 | - * @return boolean |
|
1315 | - * @throws EE_Error |
|
1316 | - */ |
|
1317 | - public function set_reg_step_not_completed($reg_step_slug) |
|
1318 | - { |
|
1319 | - return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
1320 | - } |
|
1321 | - |
|
1322 | - |
|
1323 | - |
|
1324 | - /** |
|
1325 | - * set_reg_step_completed |
|
1326 | - * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
1327 | - * |
|
1328 | - * @param string $reg_step_slug |
|
1329 | - * @param boolean|int $status |
|
1330 | - * @return boolean |
|
1331 | - * @throws EE_Error |
|
1332 | - */ |
|
1333 | - private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
1334 | - { |
|
1335 | - // validate status |
|
1336 | - $status = is_bool($status) || is_int($status) ? $status : false; |
|
1337 | - // get reg steps array |
|
1338 | - $txn_reg_steps = $this->reg_steps(); |
|
1339 | - // if reg step does NOT exist |
|
1340 | - if (! isset($txn_reg_steps[$reg_step_slug])) { |
|
1341 | - return false; |
|
1342 | - } |
|
1343 | - // if we're trying to complete a step that is already completed |
|
1344 | - if ($txn_reg_steps[$reg_step_slug] === true) { |
|
1345 | - return true; |
|
1346 | - } |
|
1347 | - // if we're trying to complete a step that hasn't even started |
|
1348 | - if ($status === true && $txn_reg_steps[$reg_step_slug] === false) { |
|
1349 | - return false; |
|
1350 | - } |
|
1351 | - // if current status value matches the incoming value (no change) |
|
1352 | - // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
1353 | - if ((int)$txn_reg_steps[$reg_step_slug] === (int)$status) { |
|
1354 | - // this will happen in cases where multiple AJAX requests occur during the same step |
|
1355 | - return true; |
|
1356 | - } |
|
1357 | - // if we're trying to set a start time, but it has already been set... |
|
1358 | - if (is_numeric($status) && is_numeric($txn_reg_steps[$reg_step_slug])) { |
|
1359 | - // skip the update below, but don't return FALSE so that errors won't be displayed |
|
1360 | - return true; |
|
1361 | - } |
|
1362 | - // update completed status |
|
1363 | - $txn_reg_steps[$reg_step_slug] = $status; |
|
1364 | - $this->set_reg_steps($txn_reg_steps); |
|
1365 | - $this->save(); |
|
1366 | - return true; |
|
1367 | - } |
|
1368 | - |
|
1369 | - |
|
1370 | - |
|
1371 | - /** |
|
1372 | - * remove_reg_step |
|
1373 | - * given a valid TXN_reg_step slug, this will remove (unset) |
|
1374 | - * the reg step from the TXN reg step array |
|
1375 | - * |
|
1376 | - * @param string $reg_step_slug |
|
1377 | - * @return void |
|
1378 | - * @throws EE_Error |
|
1379 | - */ |
|
1380 | - public function remove_reg_step($reg_step_slug) |
|
1381 | - { |
|
1382 | - // get reg steps array |
|
1383 | - $txn_reg_steps = $this->reg_steps(); |
|
1384 | - unset($txn_reg_steps[$reg_step_slug]); |
|
1385 | - $this->set_reg_steps($txn_reg_steps); |
|
1386 | - } |
|
1387 | - |
|
1388 | - |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * toggle_failed_transaction_status |
|
1392 | - * upgrades a TXNs status from failed to abandoned, |
|
1393 | - * meaning that contact information has been captured for at least one registrant |
|
1394 | - * |
|
1395 | - * @param bool $save |
|
1396 | - * @return bool |
|
1397 | - * @throws EE_Error |
|
1398 | - */ |
|
1399 | - public function toggle_failed_transaction_status($save = true) |
|
1400 | - { |
|
1401 | - // if TXN status is still set as "failed"... |
|
1402 | - if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
1403 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1404 | - if ($save) { |
|
1405 | - $this->save(); |
|
1406 | - } |
|
1407 | - return true; |
|
1408 | - } |
|
1409 | - return false; |
|
1410 | - } |
|
1411 | - |
|
1412 | - |
|
1413 | - |
|
1414 | - /** |
|
1415 | - * toggle_abandoned_transaction_status |
|
1416 | - * upgrades a TXNs status from failed or abandoned to incomplete |
|
1417 | - * |
|
1418 | - * @return bool |
|
1419 | - * @throws EE_Error |
|
1420 | - */ |
|
1421 | - public function toggle_abandoned_transaction_status() |
|
1422 | - { |
|
1423 | - // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
1424 | - $txn_status = $this->status_ID(); |
|
1425 | - if ( |
|
1426 | - $txn_status === EEM_Transaction::failed_status_code |
|
1427 | - || $txn_status === EEM_Transaction::abandoned_status_code |
|
1428 | - ) { |
|
1429 | - // if a contact record for the primary registrant has been created |
|
1430 | - if ( |
|
1431 | - $this->primary_registration() instanceof EE_Registration |
|
1432 | - && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
1433 | - ) { |
|
1434 | - $this->set_status(EEM_Transaction::incomplete_status_code); |
|
1435 | - } else { |
|
1436 | - // no contact record? yer abandoned! |
|
1437 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1438 | - } |
|
1439 | - return true; |
|
1440 | - } |
|
1441 | - return false; |
|
1442 | - } |
|
1443 | - |
|
1444 | - |
|
1445 | - |
|
1446 | - /** |
|
1447 | - * checks if an Abandoned TXN has any related payments, and if so, |
|
1448 | - * updates the TXN status based on the amount paid |
|
1449 | - * |
|
1450 | - * @throws EE_Error |
|
1451 | - * @throws InvalidDataTypeException |
|
1452 | - * @throws InvalidInterfaceException |
|
1453 | - * @throws InvalidArgumentException |
|
1454 | - * @throws RuntimeException |
|
1455 | - */ |
|
1456 | - public function verify_abandoned_transaction_status() |
|
1457 | - { |
|
1458 | - if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
1459 | - return; |
|
1460 | - } |
|
1461 | - $payments = $this->get_many_related('Payment'); |
|
1462 | - if (! empty($payments)) { |
|
1463 | - foreach ($payments as $payment) { |
|
1464 | - if ($payment instanceof EE_Payment) { |
|
1465 | - // kk this TXN should NOT be abandoned |
|
1466 | - $this->update_status_based_on_total_paid(); |
|
1467 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1468 | - EE_Error::add_attention( |
|
1469 | - sprintf( |
|
1470 | - esc_html__( |
|
1471 | - 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
1472 | - 'event_espresso' |
|
1473 | - ), |
|
1474 | - $this->ID(), |
|
1475 | - $this->pretty_status() |
|
1476 | - ) |
|
1477 | - ); |
|
1478 | - } |
|
1479 | - // get final reg step status |
|
1480 | - $finalized = $this->final_reg_step_completed(); |
|
1481 | - // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
1482 | - // but has not yet been fully completed (TRUE) |
|
1483 | - if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
1484 | - $this->set_reg_step_completed('finalize_registration'); |
|
1485 | - $this->save(); |
|
1486 | - } |
|
1487 | - } |
|
1488 | - } |
|
1489 | - } |
|
1490 | - } |
|
20 | + /** |
|
21 | + * The length of time in seconds that a lock is applied before being considered expired. |
|
22 | + * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
23 | + */ |
|
24 | + const LOCK_EXPIRATION = 2; |
|
25 | + |
|
26 | + /** |
|
27 | + * txn status upon initial construction. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_old_txn_status; |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @param array $props_n_values incoming values |
|
37 | + * @param string $timezone incoming timezone |
|
38 | + * (if not set the timezone set for the website will be used.) |
|
39 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
40 | + * date_format and the second value is the time format |
|
41 | + * @return EE_Transaction |
|
42 | + * @throws EE_Error |
|
43 | + */ |
|
44 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
45 | + { |
|
46 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
47 | + $txn = $has_object |
|
48 | + ? $has_object |
|
49 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
50 | + if (! $has_object) { |
|
51 | + $txn->set_old_txn_status($txn->status_ID()); |
|
52 | + } |
|
53 | + return $txn; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param array $props_n_values incoming values from the database |
|
60 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
61 | + * the website will be used. |
|
62 | + * @return EE_Transaction |
|
63 | + * @throws EE_Error |
|
64 | + */ |
|
65 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
66 | + { |
|
67 | + $txn = new self($props_n_values, true, $timezone); |
|
68 | + $txn->set_old_txn_status($txn->status_ID()); |
|
69 | + return $txn; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
76 | + * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
77 | + * If that also fails, then an exception is thrown. |
|
78 | + * |
|
79 | + * @throws EE_Error |
|
80 | + */ |
|
81 | + public function lock() |
|
82 | + { |
|
83 | + // attempt to set lock, but if that fails... |
|
84 | + if (! $this->add_extra_meta('lock', time(), true)) { |
|
85 | + // then attempt to remove the lock in case it is expired |
|
86 | + if ($this->_remove_expired_lock()) { |
|
87 | + // if removal was successful, then try setting lock again |
|
88 | + $this->lock(); |
|
89 | + } else { |
|
90 | + // but if the lock can not be removed, then throw an exception |
|
91 | + throw new EE_Error( |
|
92 | + sprintf( |
|
93 | + __( |
|
94 | + 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
95 | + 'event_espresso' |
|
96 | + ), |
|
97 | + $this->ID() |
|
98 | + ) |
|
99 | + ); |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * removes transaction lock applied in EE_Transaction::lock() |
|
108 | + * |
|
109 | + * @return int |
|
110 | + * @throws EE_Error |
|
111 | + */ |
|
112 | + public function unlock() |
|
113 | + { |
|
114 | + return $this->delete_extra_meta('lock'); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Decides whether or not now is the right time to update the transaction. |
|
121 | + * This is useful because we don't always know if it is safe to update the transaction |
|
122 | + * and its related data. why? |
|
123 | + * because it's possible that the transaction is being used in another |
|
124 | + * request and could overwrite anything we save. |
|
125 | + * So we want to only update the txn once we know that won't happen. |
|
126 | + * We also check that the lock isn't expired, and remove it if it is |
|
127 | + * |
|
128 | + * @return boolean |
|
129 | + * @throws EE_Error |
|
130 | + */ |
|
131 | + public function is_locked() |
|
132 | + { |
|
133 | + // if TXN is not locked, then return false immediately |
|
134 | + if (! $this->_get_lock()) { |
|
135 | + return false; |
|
136 | + } |
|
137 | + // if not, then let's try and remove the lock in case it's expired... |
|
138 | + // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
139 | + // and a positive number if the lock was removed (ie: number of locks deleted), |
|
140 | + // so we need to return the opposite |
|
141 | + return ! $this->_remove_expired_lock() ? true : false; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Gets the meta field indicating that this TXN is locked |
|
148 | + * |
|
149 | + * @return int |
|
150 | + * @throws EE_Error |
|
151 | + */ |
|
152 | + protected function _get_lock() |
|
153 | + { |
|
154 | + return (int)$this->get_extra_meta('lock', true, 0); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
161 | + * |
|
162 | + * @return int |
|
163 | + * @throws EE_Error |
|
164 | + */ |
|
165 | + protected function _remove_expired_lock() |
|
166 | + { |
|
167 | + $locked = $this->_get_lock(); |
|
168 | + if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
169 | + return $this->unlock(); |
|
170 | + } |
|
171 | + return 0; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Set transaction total |
|
178 | + * |
|
179 | + * @param float $total total value of transaction |
|
180 | + * @throws EE_Error |
|
181 | + */ |
|
182 | + public function set_total($total = 0.00) |
|
183 | + { |
|
184 | + $this->set('TXN_total', (float)$total); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Set Total Amount Paid to Date |
|
191 | + * |
|
192 | + * @param float $total_paid total amount paid to date (sum of all payments) |
|
193 | + * @throws EE_Error |
|
194 | + */ |
|
195 | + public function set_paid($total_paid = 0.00) |
|
196 | + { |
|
197 | + $this->set('TXN_paid', (float)$total_paid); |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Set transaction status |
|
204 | + * |
|
205 | + * @param string $status whether the transaction is open, declined, accepted, |
|
206 | + * or any number of custom values that can be set |
|
207 | + * @throws EE_Error |
|
208 | + */ |
|
209 | + public function set_status($status = '') |
|
210 | + { |
|
211 | + $this->set('STS_ID', $status); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Set hash salt |
|
218 | + * |
|
219 | + * @param string $hash_salt required for some payment gateways |
|
220 | + * @throws EE_Error |
|
221 | + */ |
|
222 | + public function set_hash_salt($hash_salt = '') |
|
223 | + { |
|
224 | + $this->set('TXN_hash_salt', $hash_salt); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Sets TXN_reg_steps array |
|
231 | + * |
|
232 | + * @param array $txn_reg_steps |
|
233 | + * @throws EE_Error |
|
234 | + */ |
|
235 | + public function set_reg_steps(array $txn_reg_steps) |
|
236 | + { |
|
237 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Gets TXN_reg_steps |
|
244 | + * |
|
245 | + * @return array |
|
246 | + * @throws EE_Error |
|
247 | + */ |
|
248 | + public function reg_steps() |
|
249 | + { |
|
250 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
251 | + return is_array($TXN_reg_steps) ? (array)$TXN_reg_steps : array(); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return string of transaction's total cost, with currency symbol and decimal |
|
258 | + * @throws EE_Error |
|
259 | + */ |
|
260 | + public function pretty_total() |
|
261 | + { |
|
262 | + return $this->get_pretty('TXN_total'); |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
269 | + * |
|
270 | + * @return string |
|
271 | + * @throws EE_Error |
|
272 | + */ |
|
273 | + public function pretty_paid() |
|
274 | + { |
|
275 | + return $this->get_pretty('TXN_paid'); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * calculate the amount remaining for this transaction and return; |
|
282 | + * |
|
283 | + * @return float amount remaining |
|
284 | + * @throws EE_Error |
|
285 | + */ |
|
286 | + public function remaining() |
|
287 | + { |
|
288 | + return $this->total() - $this->paid(); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * get Transaction Total |
|
295 | + * |
|
296 | + * @return float |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + public function total() |
|
300 | + { |
|
301 | + return (float)$this->get('TXN_total'); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * get Total Amount Paid to Date |
|
308 | + * |
|
309 | + * @return float |
|
310 | + * @throws EE_Error |
|
311 | + */ |
|
312 | + public function paid() |
|
313 | + { |
|
314 | + return (float)$this->get('TXN_paid'); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * @throws EE_Error |
|
321 | + */ |
|
322 | + public function get_cart_session() |
|
323 | + { |
|
324 | + $session_data = (array)$this->get('TXN_session_data'); |
|
325 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
326 | + ? $session_data['cart'] |
|
327 | + : null; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * get Transaction session data |
|
334 | + * |
|
335 | + * @throws EE_Error |
|
336 | + */ |
|
337 | + public function session_data() |
|
338 | + { |
|
339 | + $session_data = $this->get('TXN_session_data'); |
|
340 | + if (empty($session_data)) { |
|
341 | + $session_data = array( |
|
342 | + 'id' => null, |
|
343 | + 'user_id' => null, |
|
344 | + 'ip_address' => null, |
|
345 | + 'user_agent' => null, |
|
346 | + 'init_access' => null, |
|
347 | + 'last_access' => null, |
|
348 | + 'pages_visited' => array(), |
|
349 | + ); |
|
350 | + } |
|
351 | + return $session_data; |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * Set session data within the TXN object |
|
358 | + * |
|
359 | + * @param EE_Session|array $session_data |
|
360 | + * @throws EE_Error |
|
361 | + */ |
|
362 | + public function set_txn_session_data($session_data) |
|
363 | + { |
|
364 | + if ($session_data instanceof EE_Session) { |
|
365 | + $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
366 | + } else { |
|
367 | + $this->set('TXN_session_data', $session_data); |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * get Transaction hash salt |
|
375 | + * |
|
376 | + * @throws EE_Error |
|
377 | + */ |
|
378 | + public function hash_salt_() |
|
379 | + { |
|
380 | + return $this->get('TXN_hash_salt'); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Returns the transaction datetime as either: |
|
387 | + * - unix timestamp format ($format = false, $gmt = true) |
|
388 | + * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
389 | + * has no affect with this option)), this also may include a timezone abbreviation if the |
|
390 | + * set timezone in this class differs from what the timezone is on the blog. |
|
391 | + * - formatted date string including the UTC (timezone) offset (default). |
|
392 | + * |
|
393 | + * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
394 | + * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
395 | + * or no UTC offset applied |
|
396 | + * @return string | int |
|
397 | + * @throws EE_Error |
|
398 | + */ |
|
399 | + public function datetime($format = false, $gmt = false) |
|
400 | + { |
|
401 | + if ($format) { |
|
402 | + return $this->get_pretty('TXN_timestamp'); |
|
403 | + } |
|
404 | + if ($gmt) { |
|
405 | + return $this->get_raw('TXN_timestamp'); |
|
406 | + } |
|
407 | + return $this->get('TXN_timestamp'); |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Gets registrations on this transaction |
|
414 | + * |
|
415 | + * @param array $query_params array of query parameters |
|
416 | + * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
417 | + * @return EE_Base_Class[]|EE_Registration[] |
|
418 | + * @throws EE_Error |
|
419 | + */ |
|
420 | + public function registrations($query_params = array(), $get_cached = false) |
|
421 | + { |
|
422 | + $query_params = (empty($query_params) || ! is_array($query_params)) |
|
423 | + ? array( |
|
424 | + 'order_by' => array( |
|
425 | + 'Event.EVT_name' => 'ASC', |
|
426 | + 'Attendee.ATT_lname' => 'ASC', |
|
427 | + 'Attendee.ATT_fname' => 'ASC', |
|
428 | + ), |
|
429 | + ) |
|
430 | + : $query_params; |
|
431 | + $query_params = $get_cached ? array() : $query_params; |
|
432 | + return $this->get_many_related('Registration', $query_params); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
439 | + * function for getting attendees and how many registrations they each have for an event) |
|
440 | + * |
|
441 | + * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
442 | + * @throws EE_Error |
|
443 | + */ |
|
444 | + public function attendees() |
|
445 | + { |
|
446 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
453 | + * |
|
454 | + * @param array $query_params like EEM_Base::get_all |
|
455 | + * @return EE_Base_Class[]|EE_Payment[] |
|
456 | + * @throws EE_Error |
|
457 | + */ |
|
458 | + public function payments($query_params = array()) |
|
459 | + { |
|
460 | + return $this->get_many_related('Payment', $query_params); |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * gets only approved payments for this transaction |
|
467 | + * |
|
468 | + * @return EE_Base_Class[]|EE_Payment[] |
|
469 | + * @throws EE_Error |
|
470 | + * @throws InvalidArgumentException |
|
471 | + * @throws ReflectionException |
|
472 | + * @throws InvalidDataTypeException |
|
473 | + * @throws InvalidInterfaceException |
|
474 | + */ |
|
475 | + public function approved_payments() |
|
476 | + { |
|
477 | + EE_Registry::instance()->load_model('Payment'); |
|
478 | + return $this->get_many_related( |
|
479 | + 'Payment', |
|
480 | + array( |
|
481 | + array('STS_ID' => EEM_Payment::status_id_approved), |
|
482 | + 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
483 | + ) |
|
484 | + ); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Gets all payments which have not been approved |
|
491 | + * |
|
492 | + * @return EE_Base_Class[]|EEI_Payment[] |
|
493 | + * @throws EE_Error if a model is misconfigured somehow |
|
494 | + */ |
|
495 | + public function pending_payments() |
|
496 | + { |
|
497 | + return $this->get_many_related( |
|
498 | + 'Payment', |
|
499 | + array( |
|
500 | + array( |
|
501 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
502 | + ), |
|
503 | + 'order_by' => array( |
|
504 | + 'PAY_timestamp' => 'DESC', |
|
505 | + ), |
|
506 | + ) |
|
507 | + ); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * echoes $this->pretty_status() |
|
514 | + * |
|
515 | + * @param bool $show_icons |
|
516 | + * @throws EE_Error |
|
517 | + * @throws InvalidArgumentException |
|
518 | + * @throws InvalidDataTypeException |
|
519 | + * @throws InvalidInterfaceException |
|
520 | + */ |
|
521 | + public function e_pretty_status($show_icons = false) |
|
522 | + { |
|
523 | + echo $this->pretty_status($show_icons); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * returns a pretty version of the status, good for displaying to users |
|
530 | + * |
|
531 | + * @param bool $show_icons |
|
532 | + * @return string |
|
533 | + * @throws EE_Error |
|
534 | + * @throws InvalidArgumentException |
|
535 | + * @throws InvalidDataTypeException |
|
536 | + * @throws InvalidInterfaceException |
|
537 | + */ |
|
538 | + public function pretty_status($show_icons = false) |
|
539 | + { |
|
540 | + $status = EEM_Status::instance()->localized_status( |
|
541 | + array($this->status_ID() => __('unknown', 'event_espresso')), |
|
542 | + false, |
|
543 | + 'sentence' |
|
544 | + ); |
|
545 | + $icon = ''; |
|
546 | + switch ($this->status_ID()) { |
|
547 | + case EEM_Transaction::complete_status_code: |
|
548 | + $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
549 | + break; |
|
550 | + case EEM_Transaction::incomplete_status_code: |
|
551 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
552 | + : ''; |
|
553 | + break; |
|
554 | + case EEM_Transaction::abandoned_status_code: |
|
555 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
556 | + break; |
|
557 | + case EEM_Transaction::failed_status_code: |
|
558 | + $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
559 | + break; |
|
560 | + case EEM_Transaction::overpaid_status_code: |
|
561 | + $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
562 | + break; |
|
563 | + } |
|
564 | + return $icon . $status[$this->status_ID()]; |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * get Transaction Status |
|
571 | + * |
|
572 | + * @throws EE_Error |
|
573 | + */ |
|
574 | + public function status_ID() |
|
575 | + { |
|
576 | + return $this->get('STS_ID'); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
583 | + * |
|
584 | + * @return boolean |
|
585 | + * @throws EE_Error |
|
586 | + */ |
|
587 | + public function is_free() |
|
588 | + { |
|
589 | + return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Returns whether this transaction is complete |
|
596 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
597 | + * |
|
598 | + * @return boolean |
|
599 | + * @throws EE_Error |
|
600 | + */ |
|
601 | + public function is_completed() |
|
602 | + { |
|
603 | + return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + |
|
608 | + /** |
|
609 | + * Returns whether this transaction is incomplete |
|
610 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
611 | + * |
|
612 | + * @return boolean |
|
613 | + * @throws EE_Error |
|
614 | + */ |
|
615 | + public function is_incomplete() |
|
616 | + { |
|
617 | + return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * Returns whether this transaction is overpaid |
|
624 | + * Useful in templates and other logic for deciding if monies need to be refunded |
|
625 | + * |
|
626 | + * @return boolean |
|
627 | + * @throws EE_Error |
|
628 | + */ |
|
629 | + public function is_overpaid() |
|
630 | + { |
|
631 | + return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * Returns whether this transaction was abandoned |
|
638 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
639 | + * but that contact information exists for at least one registrant |
|
640 | + * |
|
641 | + * @return boolean |
|
642 | + * @throws EE_Error |
|
643 | + */ |
|
644 | + public function is_abandoned() |
|
645 | + { |
|
646 | + return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * Returns whether this transaction failed |
|
653 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
654 | + * and that NO contact information exists for any registrants |
|
655 | + * |
|
656 | + * @return boolean |
|
657 | + * @throws EE_Error |
|
658 | + */ |
|
659 | + public function failed() |
|
660 | + { |
|
661 | + return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + |
|
666 | + /** |
|
667 | + * This returns the url for the invoice of this transaction |
|
668 | + * |
|
669 | + * @param string $type 'html' or 'pdf' (default is pdf) |
|
670 | + * @return string |
|
671 | + * @throws EE_Error |
|
672 | + */ |
|
673 | + public function invoice_url($type = 'html') |
|
674 | + { |
|
675 | + $REG = $this->primary_registration(); |
|
676 | + if (! $REG instanceof EE_Registration) { |
|
677 | + return ''; |
|
678 | + } |
|
679 | + return $REG->invoice_url($type); |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * Gets the primary registration only |
|
686 | + * |
|
687 | + * @return EE_Base_Class|EE_Registration |
|
688 | + * @throws EE_Error |
|
689 | + */ |
|
690 | + public function primary_registration() |
|
691 | + { |
|
692 | + $registrations = (array)$this->get_many_related( |
|
693 | + 'Registration', |
|
694 | + array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
695 | + ); |
|
696 | + foreach ($registrations as $registration) { |
|
697 | + // valid registration that is NOT cancelled or declined ? |
|
698 | + if ( |
|
699 | + $registration instanceof EE_Registration |
|
700 | + && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
701 | + ) { |
|
702 | + return $registration; |
|
703 | + } |
|
704 | + } |
|
705 | + // nothing valid found, so just return first thing from array of results |
|
706 | + return reset($registrations); |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * Gets the URL for viewing the receipt |
|
713 | + * |
|
714 | + * @param string $type 'pdf' or 'html' (default is 'html') |
|
715 | + * @return string |
|
716 | + * @throws EE_Error |
|
717 | + */ |
|
718 | + public function receipt_url($type = 'html') |
|
719 | + { |
|
720 | + $REG = $this->primary_registration(); |
|
721 | + if (! $REG instanceof EE_Registration) { |
|
722 | + return ''; |
|
723 | + } |
|
724 | + return $REG->receipt_url($type); |
|
725 | + } |
|
726 | + |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
731 | + * a query parameter |
|
732 | + * |
|
733 | + * @return string |
|
734 | + * @throws EE_Error |
|
735 | + */ |
|
736 | + public function payment_overview_url() |
|
737 | + { |
|
738 | + $primary_registration = $this->primary_registration(); |
|
739 | + return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + |
|
744 | + /** |
|
745 | + * @return string |
|
746 | + * @throws EE_Error |
|
747 | + */ |
|
748 | + public function gateway_response_on_transaction() |
|
749 | + { |
|
750 | + $payment = $this->get_first_related('Payment'); |
|
751 | + return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
752 | + } |
|
753 | + |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * Get the status object of this object |
|
758 | + * |
|
759 | + * @return EE_Base_Class|EE_Status |
|
760 | + * @throws EE_Error |
|
761 | + */ |
|
762 | + public function status_obj() |
|
763 | + { |
|
764 | + return $this->get_first_related('Status'); |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * Gets all the extra meta info on this payment |
|
771 | + * |
|
772 | + * @param array $query_params like EEM_Base::get_all |
|
773 | + * @return EE_Base_Class[]|EE_Extra_Meta |
|
774 | + * @throws EE_Error |
|
775 | + */ |
|
776 | + public function extra_meta($query_params = array()) |
|
777 | + { |
|
778 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
779 | + } |
|
780 | + |
|
781 | + |
|
782 | + |
|
783 | + /** |
|
784 | + * Wrapper for _add_relation_to |
|
785 | + * |
|
786 | + * @param EE_Registration $registration |
|
787 | + * @return EE_Base_Class the relation was added to |
|
788 | + * @throws EE_Error |
|
789 | + */ |
|
790 | + public function add_registration(EE_Registration $registration) |
|
791 | + { |
|
792 | + return $this->_add_relation_to($registration, 'Registration'); |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + |
|
797 | + /** |
|
798 | + * Removes the given registration from being related (even before saving this transaction). |
|
799 | + * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
800 | + * |
|
801 | + * @param int $registration_or_id |
|
802 | + * @return EE_Base_Class that was removed from being related |
|
803 | + * @throws EE_Error |
|
804 | + */ |
|
805 | + public function remove_registration_with_id($registration_or_id) |
|
806 | + { |
|
807 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + |
|
812 | + /** |
|
813 | + * Gets all the line items which are for ACTUAL items |
|
814 | + * |
|
815 | + * @return EE_Line_Item[] |
|
816 | + * @throws EE_Error |
|
817 | + */ |
|
818 | + public function items_purchased() |
|
819 | + { |
|
820 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * Wrapper for _add_relation_to |
|
827 | + * |
|
828 | + * @param EE_Line_Item $line_item |
|
829 | + * @return EE_Base_Class the relation was added to |
|
830 | + * @throws EE_Error |
|
831 | + */ |
|
832 | + public function add_line_item(EE_Line_Item $line_item) |
|
833 | + { |
|
834 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + |
|
839 | + /** |
|
840 | + * Gets ALL the line items related to this transaction (unstructured) |
|
841 | + * |
|
842 | + * @param array $query_params |
|
843 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
844 | + * @throws EE_Error |
|
845 | + */ |
|
846 | + public function line_items($query_params = array()) |
|
847 | + { |
|
848 | + return $this->get_many_related('Line_Item', $query_params); |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * Gets all the line items which are taxes on the total |
|
855 | + * |
|
856 | + * @return EE_Line_Item[] |
|
857 | + * @throws EE_Error |
|
858 | + */ |
|
859 | + public function tax_items() |
|
860 | + { |
|
861 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + |
|
866 | + /** |
|
867 | + * Gets the total line item (which is a parent of all other related line items, |
|
868 | + * meaning it takes them all into account on its total) |
|
869 | + * |
|
870 | + * @param bool $create_if_not_found |
|
871 | + * @return \EE_Line_Item |
|
872 | + * @throws EE_Error |
|
873 | + */ |
|
874 | + public function total_line_item($create_if_not_found = true) |
|
875 | + { |
|
876 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
877 | + if (! $item && $create_if_not_found) { |
|
878 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
879 | + } |
|
880 | + return $item; |
|
881 | + } |
|
882 | + |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * Returns the total amount of tax on this transaction |
|
887 | + * (assumes there's only one tax subtotal line item) |
|
888 | + * |
|
889 | + * @return float |
|
890 | + * @throws EE_Error |
|
891 | + */ |
|
892 | + public function tax_total() |
|
893 | + { |
|
894 | + $tax_line_item = $this->tax_total_line_item(); |
|
895 | + if ($tax_line_item) { |
|
896 | + return (float)$tax_line_item->total(); |
|
897 | + } |
|
898 | + return (float)0; |
|
899 | + } |
|
900 | + |
|
901 | + |
|
902 | + |
|
903 | + /** |
|
904 | + * Gets the tax subtotal line item (assumes there's only one) |
|
905 | + * |
|
906 | + * @return EE_Line_Item |
|
907 | + * @throws EE_Error |
|
908 | + */ |
|
909 | + public function tax_total_line_item() |
|
910 | + { |
|
911 | + return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
912 | + } |
|
913 | + |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
918 | + * |
|
919 | + * @return EE_Form_Section_Proper |
|
920 | + * @throws EE_Error |
|
921 | + */ |
|
922 | + public function billing_info() |
|
923 | + { |
|
924 | + $payment_method = $this->payment_method(); |
|
925 | + if (! $payment_method) { |
|
926 | + EE_Error::add_error( |
|
927 | + __( |
|
928 | + 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
929 | + 'event_espresso' |
|
930 | + ), |
|
931 | + __FILE__, |
|
932 | + __FUNCTION__, |
|
933 | + __LINE__ |
|
934 | + ); |
|
935 | + return null; |
|
936 | + } |
|
937 | + $primary_reg = $this->primary_registration(); |
|
938 | + if (! $primary_reg) { |
|
939 | + EE_Error::add_error( |
|
940 | + __( |
|
941 | + 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
942 | + 'event_espresso' |
|
943 | + ), |
|
944 | + __FILE__, |
|
945 | + __FUNCTION__, |
|
946 | + __LINE__ |
|
947 | + ); |
|
948 | + return null; |
|
949 | + } |
|
950 | + $attendee = $primary_reg->attendee(); |
|
951 | + if (! $attendee) { |
|
952 | + EE_Error::add_error( |
|
953 | + __( |
|
954 | + 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
955 | + 'event_espresso' |
|
956 | + ), |
|
957 | + __FILE__, |
|
958 | + __FUNCTION__, |
|
959 | + __LINE__ |
|
960 | + ); |
|
961 | + return null; |
|
962 | + } |
|
963 | + return $attendee->billing_info_for_payment_method($payment_method); |
|
964 | + } |
|
965 | + |
|
966 | + |
|
967 | + |
|
968 | + /** |
|
969 | + * Gets PMD_ID |
|
970 | + * |
|
971 | + * @return int |
|
972 | + * @throws EE_Error |
|
973 | + */ |
|
974 | + public function payment_method_ID() |
|
975 | + { |
|
976 | + return $this->get('PMD_ID'); |
|
977 | + } |
|
978 | + |
|
979 | + |
|
980 | + |
|
981 | + /** |
|
982 | + * Sets PMD_ID |
|
983 | + * |
|
984 | + * @param int $PMD_ID |
|
985 | + * @throws EE_Error |
|
986 | + */ |
|
987 | + public function set_payment_method_ID($PMD_ID) |
|
988 | + { |
|
989 | + $this->set('PMD_ID', $PMD_ID); |
|
990 | + } |
|
991 | + |
|
992 | + |
|
993 | + |
|
994 | + /** |
|
995 | + * Gets the last-used payment method on this transaction |
|
996 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
997 | + * offline ones, dont' create payments) |
|
998 | + * |
|
999 | + * @return EE_Payment_Method |
|
1000 | + * @throws EE_Error |
|
1001 | + */ |
|
1002 | + public function payment_method() |
|
1003 | + { |
|
1004 | + $pm = $this->get_first_related('Payment_Method'); |
|
1005 | + if ($pm instanceof EE_Payment_Method) { |
|
1006 | + return $pm; |
|
1007 | + } |
|
1008 | + $last_payment = $this->last_payment(); |
|
1009 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
1010 | + return $last_payment->payment_method(); |
|
1011 | + } |
|
1012 | + return null; |
|
1013 | + } |
|
1014 | + |
|
1015 | + |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * Gets the last payment made |
|
1019 | + * |
|
1020 | + * @return EE_Base_Class|EE_Payment |
|
1021 | + * @throws EE_Error |
|
1022 | + */ |
|
1023 | + public function last_payment() |
|
1024 | + { |
|
1025 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
1026 | + } |
|
1027 | + |
|
1028 | + |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * Gets all the line items which are unrelated to tickets on this transaction |
|
1032 | + * |
|
1033 | + * @return EE_Line_Item[] |
|
1034 | + * @throws EE_Error |
|
1035 | + * @throws InvalidArgumentException |
|
1036 | + * @throws InvalidDataTypeException |
|
1037 | + * @throws InvalidInterfaceException |
|
1038 | + */ |
|
1039 | + public function non_ticket_line_items() |
|
1040 | + { |
|
1041 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
1042 | + } |
|
1043 | + |
|
1044 | + |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * possibly toggles TXN status |
|
1048 | + * |
|
1049 | + * @param boolean $update whether to save the TXN |
|
1050 | + * @return bool whether the TXN was saved |
|
1051 | + * @throws EE_Error |
|
1052 | + * @throws RuntimeException |
|
1053 | + */ |
|
1054 | + public function update_status_based_on_total_paid($update = true) |
|
1055 | + { |
|
1056 | + // set transaction status based on comparison of TXN_paid vs TXN_total |
|
1057 | + if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
1058 | + $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
1059 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
1060 | + $new_txn_status = EEM_Transaction::complete_status_code; |
|
1061 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
1062 | + $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
1063 | + } else { |
|
1064 | + throw new RuntimeException( |
|
1065 | + __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
1066 | + ); |
|
1067 | + } |
|
1068 | + if ($new_txn_status !== $this->status_ID()) { |
|
1069 | + $this->set_status($new_txn_status); |
|
1070 | + if ($update) { |
|
1071 | + return $this->save() ? true : false; |
|
1072 | + } |
|
1073 | + } |
|
1074 | + return false; |
|
1075 | + } |
|
1076 | + |
|
1077 | + |
|
1078 | + |
|
1079 | + /** |
|
1080 | + * Updates the transaction's status and total_paid based on all the payments |
|
1081 | + * that apply to it |
|
1082 | + * |
|
1083 | + * @deprecated |
|
1084 | + * @return array|bool |
|
1085 | + * @throws EE_Error |
|
1086 | + * @throws InvalidArgumentException |
|
1087 | + * @throws ReflectionException |
|
1088 | + * @throws InvalidDataTypeException |
|
1089 | + * @throws InvalidInterfaceException |
|
1090 | + */ |
|
1091 | + public function update_based_on_payments() |
|
1092 | + { |
|
1093 | + EE_Error::doing_it_wrong( |
|
1094 | + __CLASS__ . '::' . __FUNCTION__, |
|
1095 | + sprintf( |
|
1096 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
1097 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
1098 | + ), |
|
1099 | + '4.6.0' |
|
1100 | + ); |
|
1101 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
1102 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1103 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
1104 | + } |
|
1105 | + |
|
1106 | + |
|
1107 | + |
|
1108 | + /** |
|
1109 | + * @return string |
|
1110 | + */ |
|
1111 | + public function old_txn_status() |
|
1112 | + { |
|
1113 | + return $this->_old_txn_status; |
|
1114 | + } |
|
1115 | + |
|
1116 | + |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * @param string $old_txn_status |
|
1120 | + */ |
|
1121 | + public function set_old_txn_status($old_txn_status) |
|
1122 | + { |
|
1123 | + // only set the first time |
|
1124 | + if ($this->_old_txn_status === null) { |
|
1125 | + $this->_old_txn_status = $old_txn_status; |
|
1126 | + } |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * reg_status_updated |
|
1133 | + * |
|
1134 | + * @return bool |
|
1135 | + * @throws EE_Error |
|
1136 | + */ |
|
1137 | + public function txn_status_updated() |
|
1138 | + { |
|
1139 | + return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + |
|
1144 | + /** |
|
1145 | + * _reg_steps_completed |
|
1146 | + * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
1147 | + * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
1148 | + * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
1149 | + * |
|
1150 | + * @param string $reg_step_slug |
|
1151 | + * @param bool $check_all |
|
1152 | + * @return bool|int |
|
1153 | + * @throws EE_Error |
|
1154 | + */ |
|
1155 | + private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
1156 | + { |
|
1157 | + $reg_steps = $this->reg_steps(); |
|
1158 | + if (! is_array($reg_steps) || empty($reg_steps)) { |
|
1159 | + return false; |
|
1160 | + } |
|
1161 | + // loop thru reg steps array) |
|
1162 | + foreach ($reg_steps as $slug => $reg_step_completed) { |
|
1163 | + // if NOT checking ALL steps (only checking one step) |
|
1164 | + if (! $check_all) { |
|
1165 | + // and this is the one |
|
1166 | + if ($slug === $reg_step_slug) { |
|
1167 | + return $reg_step_completed; |
|
1168 | + } |
|
1169 | + // skip to next reg step in loop |
|
1170 | + continue; |
|
1171 | + } |
|
1172 | + // $check_all must be true, else we would never have gotten to this point |
|
1173 | + if ($slug === $reg_step_slug) { |
|
1174 | + // if we reach this point, then we are testing either: |
|
1175 | + // all_reg_steps_completed_except() or |
|
1176 | + // all_reg_steps_completed_except_final_step(), |
|
1177 | + // and since this is the reg step EXCEPTION being tested |
|
1178 | + // we want to return true (yes true) if this reg step is NOT completed |
|
1179 | + // ie: "is everything completed except the final step?" |
|
1180 | + // "that is correct... the final step is not completed, but all others are." |
|
1181 | + return $reg_step_completed !== true; |
|
1182 | + } |
|
1183 | + if ($reg_step_completed !== true) { |
|
1184 | + // if any reg step is NOT completed, then ALL steps are not completed |
|
1185 | + return false; |
|
1186 | + } |
|
1187 | + } |
|
1188 | + return true; |
|
1189 | + } |
|
1190 | + |
|
1191 | + |
|
1192 | + |
|
1193 | + /** |
|
1194 | + * all_reg_steps_completed |
|
1195 | + * returns: |
|
1196 | + * true if ALL reg steps have been marked as completed |
|
1197 | + * or false if any step is not completed |
|
1198 | + * |
|
1199 | + * @return bool |
|
1200 | + * @throws EE_Error |
|
1201 | + */ |
|
1202 | + public function all_reg_steps_completed() |
|
1203 | + { |
|
1204 | + return $this->_reg_steps_completed(); |
|
1205 | + } |
|
1206 | + |
|
1207 | + |
|
1208 | + |
|
1209 | + /** |
|
1210 | + * all_reg_steps_completed_except |
|
1211 | + * returns: |
|
1212 | + * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
1213 | + * or false if any other step is not completed |
|
1214 | + * or false if ALL steps are completed including the exception you are testing !!! |
|
1215 | + * |
|
1216 | + * @param string $exception |
|
1217 | + * @return bool |
|
1218 | + * @throws EE_Error |
|
1219 | + */ |
|
1220 | + public function all_reg_steps_completed_except($exception = '') |
|
1221 | + { |
|
1222 | + return $this->_reg_steps_completed($exception); |
|
1223 | + } |
|
1224 | + |
|
1225 | + |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * all_reg_steps_completed_except |
|
1229 | + * returns: |
|
1230 | + * true if ALL reg steps, except the final step, have been marked as completed |
|
1231 | + * or false if any step is not completed |
|
1232 | + * or false if ALL steps are completed including the final step !!! |
|
1233 | + * |
|
1234 | + * @return bool |
|
1235 | + * @throws EE_Error |
|
1236 | + */ |
|
1237 | + public function all_reg_steps_completed_except_final_step() |
|
1238 | + { |
|
1239 | + return $this->_reg_steps_completed('finalize_registration'); |
|
1240 | + } |
|
1241 | + |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * reg_step_completed |
|
1246 | + * returns: |
|
1247 | + * true if a specific reg step has been marked as completed |
|
1248 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
1249 | + * or false if it has not yet been initialized |
|
1250 | + * |
|
1251 | + * @param string $reg_step_slug |
|
1252 | + * @return bool|int |
|
1253 | + * @throws EE_Error |
|
1254 | + */ |
|
1255 | + public function reg_step_completed($reg_step_slug) |
|
1256 | + { |
|
1257 | + return $this->_reg_steps_completed($reg_step_slug, false); |
|
1258 | + } |
|
1259 | + |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * completed_final_reg_step |
|
1264 | + * returns: |
|
1265 | + * true if the finalize_registration reg step has been marked as completed |
|
1266 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
1267 | + * or false if it has not yet been initialized |
|
1268 | + * |
|
1269 | + * @return bool|int |
|
1270 | + * @throws EE_Error |
|
1271 | + */ |
|
1272 | + public function final_reg_step_completed() |
|
1273 | + { |
|
1274 | + return $this->_reg_steps_completed('finalize_registration', false); |
|
1275 | + } |
|
1276 | + |
|
1277 | + |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * set_reg_step_initiated |
|
1281 | + * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
1282 | + * |
|
1283 | + * @param string $reg_step_slug |
|
1284 | + * @return boolean |
|
1285 | + * @throws EE_Error |
|
1286 | + */ |
|
1287 | + public function set_reg_step_initiated($reg_step_slug) |
|
1288 | + { |
|
1289 | + return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
1290 | + } |
|
1291 | + |
|
1292 | + |
|
1293 | + |
|
1294 | + /** |
|
1295 | + * set_reg_step_completed |
|
1296 | + * given a valid TXN_reg_step, this sets the step as completed |
|
1297 | + * |
|
1298 | + * @param string $reg_step_slug |
|
1299 | + * @return boolean |
|
1300 | + * @throws EE_Error |
|
1301 | + */ |
|
1302 | + public function set_reg_step_completed($reg_step_slug) |
|
1303 | + { |
|
1304 | + return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
1305 | + } |
|
1306 | + |
|
1307 | + |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * set_reg_step_completed |
|
1311 | + * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
1312 | + * |
|
1313 | + * @param string $reg_step_slug |
|
1314 | + * @return boolean |
|
1315 | + * @throws EE_Error |
|
1316 | + */ |
|
1317 | + public function set_reg_step_not_completed($reg_step_slug) |
|
1318 | + { |
|
1319 | + return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
1320 | + } |
|
1321 | + |
|
1322 | + |
|
1323 | + |
|
1324 | + /** |
|
1325 | + * set_reg_step_completed |
|
1326 | + * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
1327 | + * |
|
1328 | + * @param string $reg_step_slug |
|
1329 | + * @param boolean|int $status |
|
1330 | + * @return boolean |
|
1331 | + * @throws EE_Error |
|
1332 | + */ |
|
1333 | + private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
1334 | + { |
|
1335 | + // validate status |
|
1336 | + $status = is_bool($status) || is_int($status) ? $status : false; |
|
1337 | + // get reg steps array |
|
1338 | + $txn_reg_steps = $this->reg_steps(); |
|
1339 | + // if reg step does NOT exist |
|
1340 | + if (! isset($txn_reg_steps[$reg_step_slug])) { |
|
1341 | + return false; |
|
1342 | + } |
|
1343 | + // if we're trying to complete a step that is already completed |
|
1344 | + if ($txn_reg_steps[$reg_step_slug] === true) { |
|
1345 | + return true; |
|
1346 | + } |
|
1347 | + // if we're trying to complete a step that hasn't even started |
|
1348 | + if ($status === true && $txn_reg_steps[$reg_step_slug] === false) { |
|
1349 | + return false; |
|
1350 | + } |
|
1351 | + // if current status value matches the incoming value (no change) |
|
1352 | + // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
1353 | + if ((int)$txn_reg_steps[$reg_step_slug] === (int)$status) { |
|
1354 | + // this will happen in cases where multiple AJAX requests occur during the same step |
|
1355 | + return true; |
|
1356 | + } |
|
1357 | + // if we're trying to set a start time, but it has already been set... |
|
1358 | + if (is_numeric($status) && is_numeric($txn_reg_steps[$reg_step_slug])) { |
|
1359 | + // skip the update below, but don't return FALSE so that errors won't be displayed |
|
1360 | + return true; |
|
1361 | + } |
|
1362 | + // update completed status |
|
1363 | + $txn_reg_steps[$reg_step_slug] = $status; |
|
1364 | + $this->set_reg_steps($txn_reg_steps); |
|
1365 | + $this->save(); |
|
1366 | + return true; |
|
1367 | + } |
|
1368 | + |
|
1369 | + |
|
1370 | + |
|
1371 | + /** |
|
1372 | + * remove_reg_step |
|
1373 | + * given a valid TXN_reg_step slug, this will remove (unset) |
|
1374 | + * the reg step from the TXN reg step array |
|
1375 | + * |
|
1376 | + * @param string $reg_step_slug |
|
1377 | + * @return void |
|
1378 | + * @throws EE_Error |
|
1379 | + */ |
|
1380 | + public function remove_reg_step($reg_step_slug) |
|
1381 | + { |
|
1382 | + // get reg steps array |
|
1383 | + $txn_reg_steps = $this->reg_steps(); |
|
1384 | + unset($txn_reg_steps[$reg_step_slug]); |
|
1385 | + $this->set_reg_steps($txn_reg_steps); |
|
1386 | + } |
|
1387 | + |
|
1388 | + |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * toggle_failed_transaction_status |
|
1392 | + * upgrades a TXNs status from failed to abandoned, |
|
1393 | + * meaning that contact information has been captured for at least one registrant |
|
1394 | + * |
|
1395 | + * @param bool $save |
|
1396 | + * @return bool |
|
1397 | + * @throws EE_Error |
|
1398 | + */ |
|
1399 | + public function toggle_failed_transaction_status($save = true) |
|
1400 | + { |
|
1401 | + // if TXN status is still set as "failed"... |
|
1402 | + if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
1403 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1404 | + if ($save) { |
|
1405 | + $this->save(); |
|
1406 | + } |
|
1407 | + return true; |
|
1408 | + } |
|
1409 | + return false; |
|
1410 | + } |
|
1411 | + |
|
1412 | + |
|
1413 | + |
|
1414 | + /** |
|
1415 | + * toggle_abandoned_transaction_status |
|
1416 | + * upgrades a TXNs status from failed or abandoned to incomplete |
|
1417 | + * |
|
1418 | + * @return bool |
|
1419 | + * @throws EE_Error |
|
1420 | + */ |
|
1421 | + public function toggle_abandoned_transaction_status() |
|
1422 | + { |
|
1423 | + // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
1424 | + $txn_status = $this->status_ID(); |
|
1425 | + if ( |
|
1426 | + $txn_status === EEM_Transaction::failed_status_code |
|
1427 | + || $txn_status === EEM_Transaction::abandoned_status_code |
|
1428 | + ) { |
|
1429 | + // if a contact record for the primary registrant has been created |
|
1430 | + if ( |
|
1431 | + $this->primary_registration() instanceof EE_Registration |
|
1432 | + && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
1433 | + ) { |
|
1434 | + $this->set_status(EEM_Transaction::incomplete_status_code); |
|
1435 | + } else { |
|
1436 | + // no contact record? yer abandoned! |
|
1437 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1438 | + } |
|
1439 | + return true; |
|
1440 | + } |
|
1441 | + return false; |
|
1442 | + } |
|
1443 | + |
|
1444 | + |
|
1445 | + |
|
1446 | + /** |
|
1447 | + * checks if an Abandoned TXN has any related payments, and if so, |
|
1448 | + * updates the TXN status based on the amount paid |
|
1449 | + * |
|
1450 | + * @throws EE_Error |
|
1451 | + * @throws InvalidDataTypeException |
|
1452 | + * @throws InvalidInterfaceException |
|
1453 | + * @throws InvalidArgumentException |
|
1454 | + * @throws RuntimeException |
|
1455 | + */ |
|
1456 | + public function verify_abandoned_transaction_status() |
|
1457 | + { |
|
1458 | + if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
1459 | + return; |
|
1460 | + } |
|
1461 | + $payments = $this->get_many_related('Payment'); |
|
1462 | + if (! empty($payments)) { |
|
1463 | + foreach ($payments as $payment) { |
|
1464 | + if ($payment instanceof EE_Payment) { |
|
1465 | + // kk this TXN should NOT be abandoned |
|
1466 | + $this->update_status_based_on_total_paid(); |
|
1467 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1468 | + EE_Error::add_attention( |
|
1469 | + sprintf( |
|
1470 | + esc_html__( |
|
1471 | + 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
1472 | + 'event_espresso' |
|
1473 | + ), |
|
1474 | + $this->ID(), |
|
1475 | + $this->pretty_status() |
|
1476 | + ) |
|
1477 | + ); |
|
1478 | + } |
|
1479 | + // get final reg step status |
|
1480 | + $finalized = $this->final_reg_step_completed(); |
|
1481 | + // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
1482 | + // but has not yet been fully completed (TRUE) |
|
1483 | + if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
1484 | + $this->set_reg_step_completed('finalize_registration'); |
|
1485 | + $this->save(); |
|
1486 | + } |
|
1487 | + } |
|
1488 | + } |
|
1489 | + } |
|
1490 | + } |
|
1491 | 1491 | |
1492 | 1492 | }/* End of file EE_Transaction.class.php */ |
1493 | 1493 | /* Location: includes/classes/EE_Transaction.class.php */ |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $txn = $has_object |
48 | 48 | ? $has_object |
49 | 49 | : new self($props_n_values, false, $timezone, $date_formats); |
50 | - if (! $has_object) { |
|
50 | + if ( ! $has_object) { |
|
51 | 51 | $txn->set_old_txn_status($txn->status_ID()); |
52 | 52 | } |
53 | 53 | return $txn; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | public function lock() |
82 | 82 | { |
83 | 83 | // attempt to set lock, but if that fails... |
84 | - if (! $this->add_extra_meta('lock', time(), true)) { |
|
84 | + if ( ! $this->add_extra_meta('lock', time(), true)) { |
|
85 | 85 | // then attempt to remove the lock in case it is expired |
86 | 86 | if ($this->_remove_expired_lock()) { |
87 | 87 | // if removal was successful, then try setting lock again |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public function is_locked() |
132 | 132 | { |
133 | 133 | // if TXN is not locked, then return false immediately |
134 | - if (! $this->_get_lock()) { |
|
134 | + if ( ! $this->_get_lock()) { |
|
135 | 135 | return false; |
136 | 136 | } |
137 | 137 | // if not, then let's try and remove the lock in case it's expired... |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | protected function _get_lock() |
153 | 153 | { |
154 | - return (int)$this->get_extra_meta('lock', true, 0); |
|
154 | + return (int) $this->get_extra_meta('lock', true, 0); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function set_total($total = 0.00) |
183 | 183 | { |
184 | - $this->set('TXN_total', (float)$total); |
|
184 | + $this->set('TXN_total', (float) $total); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function set_paid($total_paid = 0.00) |
196 | 196 | { |
197 | - $this->set('TXN_paid', (float)$total_paid); |
|
197 | + $this->set('TXN_paid', (float) $total_paid); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | public function reg_steps() |
249 | 249 | { |
250 | 250 | $TXN_reg_steps = $this->get('TXN_reg_steps'); |
251 | - return is_array($TXN_reg_steps) ? (array)$TXN_reg_steps : array(); |
|
251 | + return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public function total() |
300 | 300 | { |
301 | - return (float)$this->get('TXN_total'); |
|
301 | + return (float) $this->get('TXN_total'); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | */ |
312 | 312 | public function paid() |
313 | 313 | { |
314 | - return (float)$this->get('TXN_paid'); |
|
314 | + return (float) $this->get('TXN_paid'); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function get_cart_session() |
323 | 323 | { |
324 | - $session_data = (array)$this->get('TXN_session_data'); |
|
324 | + $session_data = (array) $this->get('TXN_session_data'); |
|
325 | 325 | return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
326 | 326 | ? $session_data['cart'] |
327 | 327 | : null; |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | false, |
543 | 543 | 'sentence' |
544 | 544 | ); |
545 | - $icon = ''; |
|
545 | + $icon = ''; |
|
546 | 546 | switch ($this->status_ID()) { |
547 | 547 | case EEM_Transaction::complete_status_code: |
548 | 548 | $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
562 | 562 | break; |
563 | 563 | } |
564 | - return $icon . $status[$this->status_ID()]; |
|
564 | + return $icon.$status[$this->status_ID()]; |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | public function invoice_url($type = 'html') |
674 | 674 | { |
675 | 675 | $REG = $this->primary_registration(); |
676 | - if (! $REG instanceof EE_Registration) { |
|
676 | + if ( ! $REG instanceof EE_Registration) { |
|
677 | 677 | return ''; |
678 | 678 | } |
679 | 679 | return $REG->invoice_url($type); |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | */ |
690 | 690 | public function primary_registration() |
691 | 691 | { |
692 | - $registrations = (array)$this->get_many_related( |
|
692 | + $registrations = (array) $this->get_many_related( |
|
693 | 693 | 'Registration', |
694 | 694 | array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
695 | 695 | ); |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | public function receipt_url($type = 'html') |
719 | 719 | { |
720 | 720 | $REG = $this->primary_registration(); |
721 | - if (! $REG instanceof EE_Registration) { |
|
721 | + if ( ! $REG instanceof EE_Registration) { |
|
722 | 722 | return ''; |
723 | 723 | } |
724 | 724 | return $REG->receipt_url($type); |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | public function total_line_item($create_if_not_found = true) |
875 | 875 | { |
876 | 876 | $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
877 | - if (! $item && $create_if_not_found) { |
|
877 | + if ( ! $item && $create_if_not_found) { |
|
878 | 878 | $item = EEH_Line_Item::create_total_line_item($this); |
879 | 879 | } |
880 | 880 | return $item; |
@@ -893,9 +893,9 @@ discard block |
||
893 | 893 | { |
894 | 894 | $tax_line_item = $this->tax_total_line_item(); |
895 | 895 | if ($tax_line_item) { |
896 | - return (float)$tax_line_item->total(); |
|
896 | + return (float) $tax_line_item->total(); |
|
897 | 897 | } |
898 | - return (float)0; |
|
898 | + return (float) 0; |
|
899 | 899 | } |
900 | 900 | |
901 | 901 | |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | public function billing_info() |
923 | 923 | { |
924 | 924 | $payment_method = $this->payment_method(); |
925 | - if (! $payment_method) { |
|
925 | + if ( ! $payment_method) { |
|
926 | 926 | EE_Error::add_error( |
927 | 927 | __( |
928 | 928 | 'Could not find billing info for transaction because no gateway has been used for it yet', |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | return null; |
936 | 936 | } |
937 | 937 | $primary_reg = $this->primary_registration(); |
938 | - if (! $primary_reg) { |
|
938 | + if ( ! $primary_reg) { |
|
939 | 939 | EE_Error::add_error( |
940 | 940 | __( |
941 | 941 | 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | return null; |
949 | 949 | } |
950 | 950 | $attendee = $primary_reg->attendee(); |
951 | - if (! $attendee) { |
|
951 | + if ( ! $attendee) { |
|
952 | 952 | EE_Error::add_error( |
953 | 953 | __( |
954 | 954 | 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
@@ -1091,7 +1091,7 @@ discard block |
||
1091 | 1091 | public function update_based_on_payments() |
1092 | 1092 | { |
1093 | 1093 | EE_Error::doing_it_wrong( |
1094 | - __CLASS__ . '::' . __FUNCTION__, |
|
1094 | + __CLASS__.'::'.__FUNCTION__, |
|
1095 | 1095 | sprintf( |
1096 | 1096 | __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
1097 | 1097 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -1155,13 +1155,13 @@ discard block |
||
1155 | 1155 | private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
1156 | 1156 | { |
1157 | 1157 | $reg_steps = $this->reg_steps(); |
1158 | - if (! is_array($reg_steps) || empty($reg_steps)) { |
|
1158 | + if ( ! is_array($reg_steps) || empty($reg_steps)) { |
|
1159 | 1159 | return false; |
1160 | 1160 | } |
1161 | 1161 | // loop thru reg steps array) |
1162 | 1162 | foreach ($reg_steps as $slug => $reg_step_completed) { |
1163 | 1163 | // if NOT checking ALL steps (only checking one step) |
1164 | - if (! $check_all) { |
|
1164 | + if ( ! $check_all) { |
|
1165 | 1165 | // and this is the one |
1166 | 1166 | if ($slug === $reg_step_slug) { |
1167 | 1167 | return $reg_step_completed; |
@@ -1337,7 +1337,7 @@ discard block |
||
1337 | 1337 | // get reg steps array |
1338 | 1338 | $txn_reg_steps = $this->reg_steps(); |
1339 | 1339 | // if reg step does NOT exist |
1340 | - if (! isset($txn_reg_steps[$reg_step_slug])) { |
|
1340 | + if ( ! isset($txn_reg_steps[$reg_step_slug])) { |
|
1341 | 1341 | return false; |
1342 | 1342 | } |
1343 | 1343 | // if we're trying to complete a step that is already completed |
@@ -1350,7 +1350,7 @@ discard block |
||
1350 | 1350 | } |
1351 | 1351 | // if current status value matches the incoming value (no change) |
1352 | 1352 | // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
1353 | - if ((int)$txn_reg_steps[$reg_step_slug] === (int)$status) { |
|
1353 | + if ((int) $txn_reg_steps[$reg_step_slug] === (int) $status) { |
|
1354 | 1354 | // this will happen in cases where multiple AJAX requests occur during the same step |
1355 | 1355 | return true; |
1356 | 1356 | } |
@@ -1459,12 +1459,12 @@ discard block |
||
1459 | 1459 | return; |
1460 | 1460 | } |
1461 | 1461 | $payments = $this->get_many_related('Payment'); |
1462 | - if (! empty($payments)) { |
|
1462 | + if ( ! empty($payments)) { |
|
1463 | 1463 | foreach ($payments as $payment) { |
1464 | 1464 | if ($payment instanceof EE_Payment) { |
1465 | 1465 | // kk this TXN should NOT be abandoned |
1466 | 1466 | $this->update_status_based_on_total_paid(); |
1467 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1467 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1468 | 1468 | EE_Error::add_attention( |
1469 | 1469 | sprintf( |
1470 | 1470 | esc_html__( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -14,586 +14,586 @@ discard block |
||
14 | 14 | class EE_Cron_Tasks extends EE_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
19 | - * so we'll set our retry time for just over 10 minutes to avoid that |
|
20 | - */ |
|
21 | - const reschedule_timeout = 605; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @var EE_Cron_Tasks |
|
26 | - */ |
|
27 | - private static $_instance; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @return EE_Cron_Tasks |
|
32 | - * @throws \ReflectionException |
|
33 | - * @throws \EE_Error |
|
34 | - * @throws \InvalidArgumentException |
|
35 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
36 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
37 | - */ |
|
38 | - public static function instance() |
|
39 | - { |
|
40 | - if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
41 | - self::$_instance = new self(); |
|
42 | - } |
|
43 | - return self::$_instance; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @access private |
|
49 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
50 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
51 | - * @throws \InvalidArgumentException |
|
52 | - * @throws \EE_Error |
|
53 | - * @throws \ReflectionException |
|
54 | - */ |
|
55 | - private function __construct() |
|
56 | - { |
|
57 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
58 | - // verify that WP Cron is enabled |
|
59 | - if ( |
|
60 | - defined('DISABLE_WP_CRON') |
|
61 | - && DISABLE_WP_CRON |
|
62 | - && is_admin() |
|
63 | - && ! get_option('ee_disabled_wp_cron_check') |
|
64 | - ) { |
|
65 | - /** |
|
66 | - * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
67 | - * config is loaded. |
|
68 | - * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
69 | - * wanting to not have this functionality can just register its own action at a priority after this one to |
|
70 | - * reverse any changes. |
|
71 | - */ |
|
72 | - add_action( |
|
73 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
74 | - function () |
|
75 | - { |
|
76 | - EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
77 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
78 | - add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
79 | - } |
|
80 | - ); |
|
81 | - } |
|
82 | - // UPDATE TRANSACTION WITH PAYMENT |
|
83 | - add_action( |
|
84 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
85 | - array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
86 | - 10, |
|
87 | - 2 |
|
88 | - ); |
|
89 | - // ABANDONED / EXPIRED TRANSACTION CHECK |
|
90 | - add_action( |
|
91 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
92 | - array('EE_Cron_Tasks', 'expired_transaction_check'), |
|
93 | - 10, |
|
94 | - 1 |
|
95 | - ); |
|
96 | - // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
97 | - add_action( |
|
98 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
99 | - array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
100 | - ); |
|
101 | - // logging |
|
102 | - add_action( |
|
103 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
104 | - array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
105 | - ); |
|
106 | - EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
107 | - //clean out old gateway logs |
|
108 | - add_action( |
|
109 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
110 | - array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
111 | - ); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @access protected |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public static function log_scheduled_ee_crons() |
|
120 | - { |
|
121 | - $ee_crons = array( |
|
122 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
123 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
124 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
125 | - ); |
|
126 | - $crons = (array)get_option('cron'); |
|
127 | - if (! is_array($crons)) { |
|
128 | - return; |
|
129 | - } |
|
130 | - foreach ($crons as $timestamp => $cron) { |
|
131 | - foreach ($ee_crons as $ee_cron) { |
|
132 | - if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
133 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
134 | - foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
135 | - if (! empty($ee_cron_details['args'])) { |
|
136 | - do_action( |
|
137 | - 'AHEE_log', |
|
138 | - __CLASS__, |
|
139 | - __FUNCTION__, |
|
140 | - print_r($ee_cron_details['args'], true), |
|
141 | - "{$ee_cron} args" |
|
142 | - ); |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * reschedule_cron_for_transactions_if_maintenance_mode |
|
154 | - * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
155 | - * |
|
156 | - * @param string $cron_task |
|
157 | - * @param array $TXN_IDs |
|
158 | - * @return bool |
|
159 | - * @throws \DomainException |
|
160 | - */ |
|
161 | - public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
|
162 | - { |
|
163 | - if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
164 | - throw new \DomainException( |
|
165 | - sprintf( |
|
166 | - __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
167 | - $cron_task |
|
168 | - ) |
|
169 | - ); |
|
170 | - } |
|
171 | - // reschedule the cron if we can't hit the db right now |
|
172 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
173 | - foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
174 | - // ensure $additional_vars is an array |
|
175 | - $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
176 | - // reset cron job for the TXN |
|
177 | - call_user_func_array( |
|
178 | - array('EE_Cron_Tasks', $cron_task), |
|
179 | - array_merge( |
|
180 | - array( |
|
181 | - time() + (10 * MINUTE_IN_SECONDS), |
|
182 | - $TXN_ID, |
|
183 | - ), |
|
184 | - $additional_vars |
|
185 | - ) |
|
186 | - ); |
|
187 | - } |
|
188 | - return true; |
|
189 | - } |
|
190 | - return false; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - |
|
196 | - /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
197 | - /** |
|
198 | - * array of TXN IDs and the payment |
|
199 | - * |
|
200 | - * @var array |
|
201 | - */ |
|
202 | - protected static $_update_transactions_with_payment = array(); |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * schedule_update_transaction_with_payment |
|
207 | - * sets a wp_schedule_single_event() for updating any TXNs that may |
|
208 | - * require updating due to recently received payments |
|
209 | - * |
|
210 | - * @param int $timestamp |
|
211 | - * @param int $TXN_ID |
|
212 | - * @param int $PAY_ID |
|
213 | - */ |
|
214 | - public static function schedule_update_transaction_with_payment( |
|
215 | - $timestamp, |
|
216 | - $TXN_ID, |
|
217 | - $PAY_ID |
|
218 | - ) { |
|
219 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
220 | - // validate $TXN_ID and $timestamp |
|
221 | - $TXN_ID = absint($TXN_ID); |
|
222 | - $timestamp = absint($timestamp); |
|
223 | - if ($TXN_ID && $timestamp) { |
|
224 | - wp_schedule_single_event( |
|
225 | - $timestamp, |
|
226 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
227 | - array($TXN_ID, $PAY_ID) |
|
228 | - ); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * setup_update_for_transaction_with_payment |
|
235 | - * this is the callback for the action hook: |
|
236 | - * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
237 | - * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
238 | - * The passed TXN_ID and associated payment gets added to an array, and then |
|
239 | - * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
240 | - * 'shutdown' which will actually handle the processing of any |
|
241 | - * transactions requiring updating, because doing so now would be too early |
|
242 | - * and the required resources may not be available |
|
243 | - * |
|
244 | - * @param int $TXN_ID |
|
245 | - * @param int $PAY_ID |
|
246 | - */ |
|
247 | - public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
248 | - { |
|
249 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
250 | - if (absint($TXN_ID)) { |
|
251 | - self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
252 | - add_action( |
|
253 | - 'shutdown', |
|
254 | - array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
255 | - 5 |
|
256 | - ); |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * update_transaction_with_payment |
|
263 | - * loops through the self::$_abandoned_transactions array |
|
264 | - * and attempts to finalize any TXNs that have not been completed |
|
265 | - * but have had their sessions expired, most likely due to a user not |
|
266 | - * returning from an off-site payment gateway |
|
267 | - * |
|
268 | - * @throws \EE_Error |
|
269 | - * @throws \DomainException |
|
270 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
271 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
272 | - * @throws \InvalidArgumentException |
|
273 | - * @throws \ReflectionException |
|
274 | - */ |
|
275 | - public static function update_transaction_with_payment() |
|
276 | - { |
|
277 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
278 | - if ( |
|
279 | - // are there any TXNs that need cleaning up ? |
|
280 | - empty(self::$_update_transactions_with_payment) |
|
281 | - // reschedule the cron if we can't hit the db right now |
|
282 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
283 | - 'schedule_update_transaction_with_payment', |
|
284 | - self::$_update_transactions_with_payment |
|
285 | - ) |
|
286 | - ) { |
|
287 | - return; |
|
288 | - } |
|
289 | - /** @type EE_Payment_Processor $payment_processor */ |
|
290 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
291 | - // set revisit flag for payment processor |
|
292 | - $payment_processor->set_revisit(); |
|
293 | - // load EEM_Transaction |
|
294 | - EE_Registry::instance()->load_model('Transaction'); |
|
295 | - foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
296 | - // reschedule the cron if we can't hit the db right now |
|
297 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
298 | - // reset cron job for updating the TXN |
|
299 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
300 | - time() + EE_Cron_Tasks::reschedule_timeout, |
|
301 | - $TXN_ID, |
|
302 | - $PAY_ID |
|
303 | - ); |
|
304 | - continue; |
|
305 | - } |
|
306 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
307 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
308 | - // verify transaction |
|
309 | - if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
310 | - // now try to update the TXN with any payments |
|
311 | - $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
312 | - } |
|
313 | - unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - |
|
319 | - /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
320 | - /***************** EXPIRED TRANSACTION CHECK *****************/ |
|
321 | - /** |
|
322 | - * array of TXN IDs |
|
323 | - * |
|
324 | - * @var array |
|
325 | - */ |
|
326 | - protected static $_expired_transactions = array(); |
|
327 | - |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * schedule_expired_transaction_check |
|
332 | - * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
333 | - * |
|
334 | - * @param int $timestamp |
|
335 | - * @param int $TXN_ID |
|
336 | - */ |
|
337 | - public static function schedule_expired_transaction_check( |
|
338 | - $timestamp, |
|
339 | - $TXN_ID |
|
340 | - ) { |
|
341 | - // validate $TXN_ID and $timestamp |
|
342 | - $TXN_ID = absint($TXN_ID); |
|
343 | - $timestamp = absint($timestamp); |
|
344 | - if ($TXN_ID && $timestamp) { |
|
345 | - wp_schedule_single_event( |
|
346 | - $timestamp, |
|
347 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
348 | - array($TXN_ID) |
|
349 | - ); |
|
350 | - } |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * expired_transaction_check |
|
357 | - * this is the callback for the action hook: |
|
358 | - * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
359 | - * which is utilized by wp_schedule_single_event() |
|
360 | - * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
361 | - * The passed TXN_ID gets added to an array, and then the |
|
362 | - * process_expired_transactions() function is hooked into |
|
363 | - * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
364 | - * processing of any failed transactions, because doing so now would be |
|
365 | - * too early and the required resources may not be available |
|
366 | - * |
|
367 | - * @param int $TXN_ID |
|
368 | - */ |
|
369 | - public static function expired_transaction_check($TXN_ID = 0) |
|
370 | - { |
|
371 | - if (absint($TXN_ID)) { |
|
372 | - self::$_expired_transactions[$TXN_ID] = $TXN_ID; |
|
373 | - add_action( |
|
374 | - 'shutdown', |
|
375 | - array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
376 | - 5 |
|
377 | - ); |
|
378 | - } |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * process_expired_transactions |
|
385 | - * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
386 | - * |
|
387 | - * @throws \EE_Error |
|
388 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
389 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
390 | - * @throws \InvalidArgumentException |
|
391 | - * @throws \ReflectionException |
|
392 | - * @throws \DomainException |
|
393 | - */ |
|
394 | - public static function process_expired_transactions() |
|
395 | - { |
|
396 | - if ( |
|
397 | - // are there any TXNs that need cleaning up ? |
|
398 | - empty(self::$_expired_transactions) |
|
399 | - // reschedule the cron if we can't hit the db right now |
|
400 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
401 | - 'schedule_expired_transaction_check', |
|
402 | - self::$_expired_transactions |
|
403 | - ) |
|
404 | - ) { |
|
405 | - return; |
|
406 | - } |
|
407 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
408 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
409 | - // set revisit flag for txn processor |
|
410 | - $transaction_processor->set_revisit(); |
|
411 | - // load EEM_Transaction |
|
412 | - EE_Registry::instance()->load_model('Transaction'); |
|
413 | - foreach (self::$_expired_transactions as $TXN_ID) { |
|
414 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
415 | - // verify transaction and whether it is failed or not |
|
416 | - if ($transaction instanceof EE_Transaction) { |
|
417 | - switch ($transaction->status_ID()) { |
|
418 | - // Completed TXNs |
|
419 | - case EEM_Transaction::complete_status_code : |
|
420 | - do_action( |
|
421 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
422 | - $transaction |
|
423 | - ); |
|
424 | - break; |
|
425 | - // Overpaid TXNs |
|
426 | - case EEM_Transaction::overpaid_status_code : |
|
427 | - do_action( |
|
428 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
429 | - $transaction |
|
430 | - ); |
|
431 | - break; |
|
432 | - // Incomplete TXNs |
|
433 | - case EEM_Transaction::incomplete_status_code : |
|
434 | - do_action( |
|
435 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
436 | - $transaction |
|
437 | - ); |
|
438 | - // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
439 | - break; |
|
440 | - // Abandoned TXNs |
|
441 | - case EEM_Transaction::abandoned_status_code : |
|
442 | - // run hook before updating transaction, primarily so |
|
443 | - // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
444 | - do_action( |
|
445 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
446 | - $transaction |
|
447 | - ); |
|
448 | - // don't finalize the TXN if it has already been completed |
|
449 | - if ($transaction->all_reg_steps_completed() !== true) { |
|
450 | - /** @type EE_Payment_Processor $payment_processor */ |
|
451 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
452 | - // let's simulate an IPN here which will trigger any notifications that need to go out |
|
453 | - $payment_processor->update_txn_based_on_payment( |
|
454 | - $transaction, |
|
455 | - $transaction->last_payment(), |
|
456 | - true, |
|
457 | - true |
|
458 | - ); |
|
459 | - } |
|
460 | - break; |
|
461 | - // Failed TXNs |
|
462 | - case EEM_Transaction::failed_status_code : |
|
463 | - do_action( |
|
464 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
465 | - $transaction |
|
466 | - ); |
|
467 | - // todo : perform garbage collection here and remove clean_out_junk_transactions() |
|
468 | - //$registrations = $transaction->registrations(); |
|
469 | - //if ( ! empty( $registrations ) ) { |
|
470 | - // foreach ( $registrations as $registration ) { |
|
471 | - // if ( $registration instanceof EE_Registration ) { |
|
472 | - //$delete_registration = true; |
|
473 | - //if ( $registration->attendee() instanceof EE_Attendee ) { |
|
474 | - // $delete_registration = false; |
|
475 | - //} |
|
476 | - //if ( $delete_registration ) { |
|
477 | - // $registration->delete_permanently(); |
|
478 | - // $registration->delete_related_permanently(); |
|
479 | - //} |
|
480 | - // } |
|
481 | - // } |
|
482 | - //} |
|
483 | - break; |
|
484 | - } |
|
485 | - } |
|
486 | - unset(self::$_expired_transactions[$TXN_ID]); |
|
487 | - } |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /************* END OF EXPIRED TRANSACTION CHECK *************/ |
|
493 | - /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
494 | - |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * when a transaction is initially made, schedule this check. |
|
499 | - * if it has NO REG data by the time it has expired, forget about it |
|
500 | - * |
|
501 | - * @throws EE_Error |
|
502 | - * @throws InvalidArgumentException |
|
503 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
504 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
505 | - */ |
|
506 | - public static function clean_out_junk_transactions() |
|
507 | - { |
|
508 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
509 | - EEM_Transaction::instance('')->delete_junk_transactions(); |
|
510 | - EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
511 | - EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
512 | - } |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
519 | - * |
|
520 | - * @throws \EE_Error |
|
521 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
522 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
523 | - * @throws \InvalidArgumentException |
|
524 | - */ |
|
525 | - public static function clean_out_old_gateway_logs() |
|
526 | - { |
|
527 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
528 | - $time_diff_for_comparison = apply_filters( |
|
529 | - 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
530 | - '-1 week' |
|
531 | - ); |
|
532 | - EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
533 | - } |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
538 | - /** |
|
539 | - * @var array |
|
540 | - */ |
|
541 | - protected static $_abandoned_transactions = array(); |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * @deprecated |
|
546 | - * @param int $timestamp |
|
547 | - * @param int $TXN_ID |
|
548 | - */ |
|
549 | - public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID) |
|
550 | - { |
|
551 | - EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * @deprecated |
|
557 | - * @param int $TXN_ID |
|
558 | - */ |
|
559 | - public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
560 | - { |
|
561 | - EE_Cron_Tasks::expired_transaction_check($TXN_ID); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * @deprecated |
|
567 | - * @throws \EE_Error |
|
568 | - * @throws \DomainException |
|
569 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
570 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
571 | - * @throws \InvalidArgumentException |
|
572 | - * @throws \ReflectionException |
|
573 | - */ |
|
574 | - public static function finalize_abandoned_transactions() |
|
575 | - { |
|
576 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
577 | - if ( |
|
578 | - // are there any TXNs that need cleaning up ? |
|
579 | - empty(self::$_abandoned_transactions) |
|
580 | - // reschedule the cron if we can't hit the db right now |
|
581 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
582 | - 'schedule_expired_transaction_check', |
|
583 | - self::$_abandoned_transactions |
|
584 | - ) |
|
585 | - ) { |
|
586 | - return; |
|
587 | - } |
|
588 | - // combine our arrays of transaction IDs |
|
589 | - self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions; |
|
590 | - // and deal with abandoned transactions here now... |
|
591 | - EE_Cron_Tasks::process_expired_transactions(); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - |
|
596 | - /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
17 | + /** |
|
18 | + * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
19 | + * so we'll set our retry time for just over 10 minutes to avoid that |
|
20 | + */ |
|
21 | + const reschedule_timeout = 605; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @var EE_Cron_Tasks |
|
26 | + */ |
|
27 | + private static $_instance; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @return EE_Cron_Tasks |
|
32 | + * @throws \ReflectionException |
|
33 | + * @throws \EE_Error |
|
34 | + * @throws \InvalidArgumentException |
|
35 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
36 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
37 | + */ |
|
38 | + public static function instance() |
|
39 | + { |
|
40 | + if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
41 | + self::$_instance = new self(); |
|
42 | + } |
|
43 | + return self::$_instance; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @access private |
|
49 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
50 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
51 | + * @throws \InvalidArgumentException |
|
52 | + * @throws \EE_Error |
|
53 | + * @throws \ReflectionException |
|
54 | + */ |
|
55 | + private function __construct() |
|
56 | + { |
|
57 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
58 | + // verify that WP Cron is enabled |
|
59 | + if ( |
|
60 | + defined('DISABLE_WP_CRON') |
|
61 | + && DISABLE_WP_CRON |
|
62 | + && is_admin() |
|
63 | + && ! get_option('ee_disabled_wp_cron_check') |
|
64 | + ) { |
|
65 | + /** |
|
66 | + * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
67 | + * config is loaded. |
|
68 | + * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
69 | + * wanting to not have this functionality can just register its own action at a priority after this one to |
|
70 | + * reverse any changes. |
|
71 | + */ |
|
72 | + add_action( |
|
73 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
74 | + function () |
|
75 | + { |
|
76 | + EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
77 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
78 | + add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
79 | + } |
|
80 | + ); |
|
81 | + } |
|
82 | + // UPDATE TRANSACTION WITH PAYMENT |
|
83 | + add_action( |
|
84 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
85 | + array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
86 | + 10, |
|
87 | + 2 |
|
88 | + ); |
|
89 | + // ABANDONED / EXPIRED TRANSACTION CHECK |
|
90 | + add_action( |
|
91 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
92 | + array('EE_Cron_Tasks', 'expired_transaction_check'), |
|
93 | + 10, |
|
94 | + 1 |
|
95 | + ); |
|
96 | + // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
97 | + add_action( |
|
98 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
99 | + array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
100 | + ); |
|
101 | + // logging |
|
102 | + add_action( |
|
103 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
104 | + array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
105 | + ); |
|
106 | + EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
107 | + //clean out old gateway logs |
|
108 | + add_action( |
|
109 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
110 | + array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
111 | + ); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @access protected |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public static function log_scheduled_ee_crons() |
|
120 | + { |
|
121 | + $ee_crons = array( |
|
122 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
123 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
124 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
125 | + ); |
|
126 | + $crons = (array)get_option('cron'); |
|
127 | + if (! is_array($crons)) { |
|
128 | + return; |
|
129 | + } |
|
130 | + foreach ($crons as $timestamp => $cron) { |
|
131 | + foreach ($ee_crons as $ee_cron) { |
|
132 | + if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
133 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
134 | + foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
135 | + if (! empty($ee_cron_details['args'])) { |
|
136 | + do_action( |
|
137 | + 'AHEE_log', |
|
138 | + __CLASS__, |
|
139 | + __FUNCTION__, |
|
140 | + print_r($ee_cron_details['args'], true), |
|
141 | + "{$ee_cron} args" |
|
142 | + ); |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * reschedule_cron_for_transactions_if_maintenance_mode |
|
154 | + * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
155 | + * |
|
156 | + * @param string $cron_task |
|
157 | + * @param array $TXN_IDs |
|
158 | + * @return bool |
|
159 | + * @throws \DomainException |
|
160 | + */ |
|
161 | + public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
|
162 | + { |
|
163 | + if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
164 | + throw new \DomainException( |
|
165 | + sprintf( |
|
166 | + __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
167 | + $cron_task |
|
168 | + ) |
|
169 | + ); |
|
170 | + } |
|
171 | + // reschedule the cron if we can't hit the db right now |
|
172 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
173 | + foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
174 | + // ensure $additional_vars is an array |
|
175 | + $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
176 | + // reset cron job for the TXN |
|
177 | + call_user_func_array( |
|
178 | + array('EE_Cron_Tasks', $cron_task), |
|
179 | + array_merge( |
|
180 | + array( |
|
181 | + time() + (10 * MINUTE_IN_SECONDS), |
|
182 | + $TXN_ID, |
|
183 | + ), |
|
184 | + $additional_vars |
|
185 | + ) |
|
186 | + ); |
|
187 | + } |
|
188 | + return true; |
|
189 | + } |
|
190 | + return false; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
197 | + /** |
|
198 | + * array of TXN IDs and the payment |
|
199 | + * |
|
200 | + * @var array |
|
201 | + */ |
|
202 | + protected static $_update_transactions_with_payment = array(); |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * schedule_update_transaction_with_payment |
|
207 | + * sets a wp_schedule_single_event() for updating any TXNs that may |
|
208 | + * require updating due to recently received payments |
|
209 | + * |
|
210 | + * @param int $timestamp |
|
211 | + * @param int $TXN_ID |
|
212 | + * @param int $PAY_ID |
|
213 | + */ |
|
214 | + public static function schedule_update_transaction_with_payment( |
|
215 | + $timestamp, |
|
216 | + $TXN_ID, |
|
217 | + $PAY_ID |
|
218 | + ) { |
|
219 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
220 | + // validate $TXN_ID and $timestamp |
|
221 | + $TXN_ID = absint($TXN_ID); |
|
222 | + $timestamp = absint($timestamp); |
|
223 | + if ($TXN_ID && $timestamp) { |
|
224 | + wp_schedule_single_event( |
|
225 | + $timestamp, |
|
226 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
227 | + array($TXN_ID, $PAY_ID) |
|
228 | + ); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * setup_update_for_transaction_with_payment |
|
235 | + * this is the callback for the action hook: |
|
236 | + * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
237 | + * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
238 | + * The passed TXN_ID and associated payment gets added to an array, and then |
|
239 | + * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
240 | + * 'shutdown' which will actually handle the processing of any |
|
241 | + * transactions requiring updating, because doing so now would be too early |
|
242 | + * and the required resources may not be available |
|
243 | + * |
|
244 | + * @param int $TXN_ID |
|
245 | + * @param int $PAY_ID |
|
246 | + */ |
|
247 | + public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
248 | + { |
|
249 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
250 | + if (absint($TXN_ID)) { |
|
251 | + self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
252 | + add_action( |
|
253 | + 'shutdown', |
|
254 | + array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
255 | + 5 |
|
256 | + ); |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * update_transaction_with_payment |
|
263 | + * loops through the self::$_abandoned_transactions array |
|
264 | + * and attempts to finalize any TXNs that have not been completed |
|
265 | + * but have had their sessions expired, most likely due to a user not |
|
266 | + * returning from an off-site payment gateway |
|
267 | + * |
|
268 | + * @throws \EE_Error |
|
269 | + * @throws \DomainException |
|
270 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
271 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
272 | + * @throws \InvalidArgumentException |
|
273 | + * @throws \ReflectionException |
|
274 | + */ |
|
275 | + public static function update_transaction_with_payment() |
|
276 | + { |
|
277 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
278 | + if ( |
|
279 | + // are there any TXNs that need cleaning up ? |
|
280 | + empty(self::$_update_transactions_with_payment) |
|
281 | + // reschedule the cron if we can't hit the db right now |
|
282 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
283 | + 'schedule_update_transaction_with_payment', |
|
284 | + self::$_update_transactions_with_payment |
|
285 | + ) |
|
286 | + ) { |
|
287 | + return; |
|
288 | + } |
|
289 | + /** @type EE_Payment_Processor $payment_processor */ |
|
290 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
291 | + // set revisit flag for payment processor |
|
292 | + $payment_processor->set_revisit(); |
|
293 | + // load EEM_Transaction |
|
294 | + EE_Registry::instance()->load_model('Transaction'); |
|
295 | + foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
296 | + // reschedule the cron if we can't hit the db right now |
|
297 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
298 | + // reset cron job for updating the TXN |
|
299 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
300 | + time() + EE_Cron_Tasks::reschedule_timeout, |
|
301 | + $TXN_ID, |
|
302 | + $PAY_ID |
|
303 | + ); |
|
304 | + continue; |
|
305 | + } |
|
306 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
307 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
308 | + // verify transaction |
|
309 | + if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
310 | + // now try to update the TXN with any payments |
|
311 | + $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
312 | + } |
|
313 | + unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + |
|
319 | + /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
320 | + /***************** EXPIRED TRANSACTION CHECK *****************/ |
|
321 | + /** |
|
322 | + * array of TXN IDs |
|
323 | + * |
|
324 | + * @var array |
|
325 | + */ |
|
326 | + protected static $_expired_transactions = array(); |
|
327 | + |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * schedule_expired_transaction_check |
|
332 | + * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
333 | + * |
|
334 | + * @param int $timestamp |
|
335 | + * @param int $TXN_ID |
|
336 | + */ |
|
337 | + public static function schedule_expired_transaction_check( |
|
338 | + $timestamp, |
|
339 | + $TXN_ID |
|
340 | + ) { |
|
341 | + // validate $TXN_ID and $timestamp |
|
342 | + $TXN_ID = absint($TXN_ID); |
|
343 | + $timestamp = absint($timestamp); |
|
344 | + if ($TXN_ID && $timestamp) { |
|
345 | + wp_schedule_single_event( |
|
346 | + $timestamp, |
|
347 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
348 | + array($TXN_ID) |
|
349 | + ); |
|
350 | + } |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * expired_transaction_check |
|
357 | + * this is the callback for the action hook: |
|
358 | + * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
359 | + * which is utilized by wp_schedule_single_event() |
|
360 | + * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
361 | + * The passed TXN_ID gets added to an array, and then the |
|
362 | + * process_expired_transactions() function is hooked into |
|
363 | + * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
364 | + * processing of any failed transactions, because doing so now would be |
|
365 | + * too early and the required resources may not be available |
|
366 | + * |
|
367 | + * @param int $TXN_ID |
|
368 | + */ |
|
369 | + public static function expired_transaction_check($TXN_ID = 0) |
|
370 | + { |
|
371 | + if (absint($TXN_ID)) { |
|
372 | + self::$_expired_transactions[$TXN_ID] = $TXN_ID; |
|
373 | + add_action( |
|
374 | + 'shutdown', |
|
375 | + array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
376 | + 5 |
|
377 | + ); |
|
378 | + } |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * process_expired_transactions |
|
385 | + * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
386 | + * |
|
387 | + * @throws \EE_Error |
|
388 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
389 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
390 | + * @throws \InvalidArgumentException |
|
391 | + * @throws \ReflectionException |
|
392 | + * @throws \DomainException |
|
393 | + */ |
|
394 | + public static function process_expired_transactions() |
|
395 | + { |
|
396 | + if ( |
|
397 | + // are there any TXNs that need cleaning up ? |
|
398 | + empty(self::$_expired_transactions) |
|
399 | + // reschedule the cron if we can't hit the db right now |
|
400 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
401 | + 'schedule_expired_transaction_check', |
|
402 | + self::$_expired_transactions |
|
403 | + ) |
|
404 | + ) { |
|
405 | + return; |
|
406 | + } |
|
407 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
408 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
409 | + // set revisit flag for txn processor |
|
410 | + $transaction_processor->set_revisit(); |
|
411 | + // load EEM_Transaction |
|
412 | + EE_Registry::instance()->load_model('Transaction'); |
|
413 | + foreach (self::$_expired_transactions as $TXN_ID) { |
|
414 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
415 | + // verify transaction and whether it is failed or not |
|
416 | + if ($transaction instanceof EE_Transaction) { |
|
417 | + switch ($transaction->status_ID()) { |
|
418 | + // Completed TXNs |
|
419 | + case EEM_Transaction::complete_status_code : |
|
420 | + do_action( |
|
421 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
422 | + $transaction |
|
423 | + ); |
|
424 | + break; |
|
425 | + // Overpaid TXNs |
|
426 | + case EEM_Transaction::overpaid_status_code : |
|
427 | + do_action( |
|
428 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
429 | + $transaction |
|
430 | + ); |
|
431 | + break; |
|
432 | + // Incomplete TXNs |
|
433 | + case EEM_Transaction::incomplete_status_code : |
|
434 | + do_action( |
|
435 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
436 | + $transaction |
|
437 | + ); |
|
438 | + // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
439 | + break; |
|
440 | + // Abandoned TXNs |
|
441 | + case EEM_Transaction::abandoned_status_code : |
|
442 | + // run hook before updating transaction, primarily so |
|
443 | + // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
444 | + do_action( |
|
445 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
446 | + $transaction |
|
447 | + ); |
|
448 | + // don't finalize the TXN if it has already been completed |
|
449 | + if ($transaction->all_reg_steps_completed() !== true) { |
|
450 | + /** @type EE_Payment_Processor $payment_processor */ |
|
451 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
452 | + // let's simulate an IPN here which will trigger any notifications that need to go out |
|
453 | + $payment_processor->update_txn_based_on_payment( |
|
454 | + $transaction, |
|
455 | + $transaction->last_payment(), |
|
456 | + true, |
|
457 | + true |
|
458 | + ); |
|
459 | + } |
|
460 | + break; |
|
461 | + // Failed TXNs |
|
462 | + case EEM_Transaction::failed_status_code : |
|
463 | + do_action( |
|
464 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
465 | + $transaction |
|
466 | + ); |
|
467 | + // todo : perform garbage collection here and remove clean_out_junk_transactions() |
|
468 | + //$registrations = $transaction->registrations(); |
|
469 | + //if ( ! empty( $registrations ) ) { |
|
470 | + // foreach ( $registrations as $registration ) { |
|
471 | + // if ( $registration instanceof EE_Registration ) { |
|
472 | + //$delete_registration = true; |
|
473 | + //if ( $registration->attendee() instanceof EE_Attendee ) { |
|
474 | + // $delete_registration = false; |
|
475 | + //} |
|
476 | + //if ( $delete_registration ) { |
|
477 | + // $registration->delete_permanently(); |
|
478 | + // $registration->delete_related_permanently(); |
|
479 | + //} |
|
480 | + // } |
|
481 | + // } |
|
482 | + //} |
|
483 | + break; |
|
484 | + } |
|
485 | + } |
|
486 | + unset(self::$_expired_transactions[$TXN_ID]); |
|
487 | + } |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /************* END OF EXPIRED TRANSACTION CHECK *************/ |
|
493 | + /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
494 | + |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * when a transaction is initially made, schedule this check. |
|
499 | + * if it has NO REG data by the time it has expired, forget about it |
|
500 | + * |
|
501 | + * @throws EE_Error |
|
502 | + * @throws InvalidArgumentException |
|
503 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
504 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
505 | + */ |
|
506 | + public static function clean_out_junk_transactions() |
|
507 | + { |
|
508 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
509 | + EEM_Transaction::instance('')->delete_junk_transactions(); |
|
510 | + EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
511 | + EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
512 | + } |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
519 | + * |
|
520 | + * @throws \EE_Error |
|
521 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
522 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
523 | + * @throws \InvalidArgumentException |
|
524 | + */ |
|
525 | + public static function clean_out_old_gateway_logs() |
|
526 | + { |
|
527 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
528 | + $time_diff_for_comparison = apply_filters( |
|
529 | + 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
530 | + '-1 week' |
|
531 | + ); |
|
532 | + EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
533 | + } |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
538 | + /** |
|
539 | + * @var array |
|
540 | + */ |
|
541 | + protected static $_abandoned_transactions = array(); |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * @deprecated |
|
546 | + * @param int $timestamp |
|
547 | + * @param int $TXN_ID |
|
548 | + */ |
|
549 | + public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID) |
|
550 | + { |
|
551 | + EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * @deprecated |
|
557 | + * @param int $TXN_ID |
|
558 | + */ |
|
559 | + public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
560 | + { |
|
561 | + EE_Cron_Tasks::expired_transaction_check($TXN_ID); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * @deprecated |
|
567 | + * @throws \EE_Error |
|
568 | + * @throws \DomainException |
|
569 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
570 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
571 | + * @throws \InvalidArgumentException |
|
572 | + * @throws \ReflectionException |
|
573 | + */ |
|
574 | + public static function finalize_abandoned_transactions() |
|
575 | + { |
|
576 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
577 | + if ( |
|
578 | + // are there any TXNs that need cleaning up ? |
|
579 | + empty(self::$_abandoned_transactions) |
|
580 | + // reschedule the cron if we can't hit the db right now |
|
581 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
582 | + 'schedule_expired_transaction_check', |
|
583 | + self::$_abandoned_transactions |
|
584 | + ) |
|
585 | + ) { |
|
586 | + return; |
|
587 | + } |
|
588 | + // combine our arrays of transaction IDs |
|
589 | + self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions; |
|
590 | + // and deal with abandoned transactions here now... |
|
591 | + EE_Cron_Tasks::process_expired_transactions(); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + |
|
596 | + /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
597 | 597 | } |
598 | 598 | // End of file EE_Cron_Tasks.core.php |
599 | 599 | // Location: /EE_Cron_Tasks.core.php |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public static function instance() |
39 | 39 | { |
40 | - if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
40 | + if ( ! self::$_instance instanceof EE_Cron_Tasks) { |
|
41 | 41 | self::$_instance = new self(); |
42 | 42 | } |
43 | 43 | return self::$_instance; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | add_action( |
73 | 73 | 'AHEE__EE_System__load_core_configuration__complete', |
74 | - function () |
|
74 | + function() |
|
75 | 75 | { |
76 | 76 | EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
77 | 77 | EE_Registry::instance()->NET_CFG->update_config(true, false); |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
124 | 124 | 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
125 | 125 | ); |
126 | - $crons = (array)get_option('cron'); |
|
127 | - if (! is_array($crons)) { |
|
126 | + $crons = (array) get_option('cron'); |
|
127 | + if ( ! is_array($crons)) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | foreach ($crons as $timestamp => $cron) { |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
133 | 133 | do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
134 | 134 | foreach ($cron[$ee_cron] as $ee_cron_details) { |
135 | - if (! empty($ee_cron_details['args'])) { |
|
135 | + if ( ! empty($ee_cron_details['args'])) { |
|
136 | 136 | do_action( |
137 | 137 | 'AHEE_log', |
138 | 138 | __CLASS__, |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
162 | 162 | { |
163 | - if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
163 | + if ( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
164 | 164 | throw new \DomainException( |
165 | 165 | sprintf( |
166 | 166 | __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ); |
170 | 170 | } |
171 | 171 | // reschedule the cron if we can't hit the db right now |
172 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
172 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
173 | 173 | foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
174 | 174 | // ensure $additional_vars is an array |
175 | 175 | $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | EE_Registry::instance()->load_model('Transaction'); |
295 | 295 | foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
296 | 296 | // reschedule the cron if we can't hit the db right now |
297 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
297 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
298 | 298 | // reset cron job for updating the TXN |
299 | 299 | EE_Cron_Tasks::schedule_update_transaction_with_payment( |
300 | 300 | time() + EE_Cron_Tasks::reschedule_timeout, |
@@ -734,7 +734,7 @@ |
||
734 | 734 | * @since 4.9.1 |
735 | 735 | * @param int $att_nmbr |
736 | 736 | * @param EE_Line_Item | string $item |
737 | - * @return string |
|
737 | + * @return RegUrlLink |
|
738 | 738 | * @throws InvalidArgumentException |
739 | 739 | */ |
740 | 740 | public function generate_reg_url_link($att_nmbr, $item) |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public static function instance() |
75 | 75 | { |
76 | 76 | // check if class object is instantiated |
77 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
77 | + if ( ! self::$_instance instanceof EE_Registration_Processor) { |
|
78 | 78 | self::$_instance = new self(); |
79 | 79 | } |
80 | 80 | return self::$_instance; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | public function set_old_reg_status($REG_ID, $old_reg_status) |
110 | 110 | { |
111 | 111 | // only set the first time |
112 | - if (! isset($this->_old_reg_status[$REG_ID])) { |
|
112 | + if ( ! isset($this->_old_reg_status[$REG_ID])) { |
|
113 | 113 | $this->_old_reg_status[$REG_ID] = $old_reg_status; |
114 | 114 | } |
115 | 115 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | $registration->save(); |
265 | 265 | } |
266 | 266 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
267 | - if (! EE_Processor_Base::$IPN) { |
|
267 | + if ( ! EE_Processor_Base::$IPN) { |
|
268 | 268 | // otherwise, send out notifications |
269 | 269 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
270 | 270 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | $registration->save(); |
321 | 321 | } |
322 | 322 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
323 | - if (! EE_Processor_Base::$IPN) { |
|
323 | + if ( ! EE_Processor_Base::$IPN) { |
|
324 | 324 | // otherwise, send out notifications |
325 | 325 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
326 | 326 | } |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | // set initial REG_Status |
366 | 366 | $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
367 | 367 | // was a payment just made ? |
368 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
368 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
369 | 369 | && $additional_details['payment_updates'] |
370 | 370 | && $additional_details['last_payment'] instanceof EE_Payment |
371 | 371 | ? $additional_details['last_payment'] |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | $registration->save(); |
407 | 407 | } |
408 | 408 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
409 | - if (! EE_Processor_Base::$IPN) { |
|
409 | + if ( ! EE_Processor_Base::$IPN) { |
|
410 | 410 | // otherwise, send out notifications |
411 | 411 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
412 | 412 | } |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | public function trigger_registration_update_notifications($registration, array $additional_details = array()) |
438 | 438 | { |
439 | 439 | try { |
440 | - if (! $registration instanceof EE_Registration) { |
|
440 | + if ( ! $registration instanceof EE_Registration) { |
|
441 | 441 | throw new EE_Error( |
442 | 442 | esc_html__('An invalid registration was received.', 'event_espresso') |
443 | 443 | ); |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | // false, |
452 | 452 | // 'EE_Transaction: ' . $registration->transaction()->ID() |
453 | 453 | // ); |
454 | - if (! $registration->is_primary_registrant()) { |
|
454 | + if ( ! $registration->is_primary_registrant()) { |
|
455 | 455 | return; |
456 | 456 | } |
457 | 457 | do_action( |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | $diff = $transaction->total() - $reg_final_price_sum; |
571 | 571 | //ok then, just grab one of the registrations |
572 | 572 | if ($diff !== 0) { |
573 | - $a_reg = EEM_Registration::instance()->get_one( |
|
573 | + $a_reg = EEM_Registration::instance()->get_one( |
|
574 | 574 | array( |
575 | 575 | array( |
576 | 576 | 'TXN_ID' => $transaction->ID(), |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | $closed_reg_statuses = ! empty($closed_reg_statuses) |
606 | 606 | ? $closed_reg_statuses |
607 | 607 | : EEM_Registration::closed_reg_statuses(); |
608 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
608 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
609 | 609 | return false; |
610 | 610 | } |
611 | 611 | // release a reserved ticket by decrementing ticket and datetime reserved values |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | return false; |
642 | 642 | } |
643 | 643 | $ticket = $registration->ticket(); |
644 | - if (! $ticket instanceof EE_Ticket) { |
|
644 | + if ( ! $ticket instanceof EE_Ticket) { |
|
645 | 645 | throw new EE_Error( |
646 | 646 | sprintf( |
647 | 647 | esc_html__( |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | $total_ticket_count = 1 |
692 | 692 | ) { |
693 | 693 | EE_Error::doing_it_wrong( |
694 | - __CLASS__ . '::' . __FUNCTION__, |
|
694 | + __CLASS__.'::'.__FUNCTION__, |
|
695 | 695 | sprintf( |
696 | 696 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
697 | 697 | '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | ); |
702 | 702 | // grab the related ticket object for this line_item |
703 | 703 | $ticket = $line_item->ticket(); |
704 | - if (! $ticket instanceof EE_Ticket) { |
|
704 | + if ( ! $ticket instanceof EE_Ticket) { |
|
705 | 705 | EE_Error::add_error( |
706 | 706 | sprintf( |
707 | 707 | esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | public function generate_reg_url_link($att_nmbr, $item) |
741 | 741 | { |
742 | 742 | EE_Error::doing_it_wrong( |
743 | - __CLASS__ . '::' . __FUNCTION__, |
|
743 | + __CLASS__.'::'.__FUNCTION__, |
|
744 | 744 | sprintf( |
745 | 745 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
746 | 746 | 'EventEspresso\core\domain\entities\RegUrlLink' |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | public function generate_reg_code(EE_Registration $registration) |
768 | 768 | { |
769 | 769 | EE_Error::doing_it_wrong( |
770 | - __CLASS__ . '::' . __FUNCTION__, |
|
770 | + __CLASS__.'::'.__FUNCTION__, |
|
771 | 771 | sprintf( |
772 | 772 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
773 | 773 | 'EventEspresso\core\domain\entities\RegCode' |
@@ -26,765 +26,765 @@ |
||
26 | 26 | class EE_Registration_Processor extends EE_Processor_Base |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var EE_Registration_Processor $_instance |
|
31 | - * @access private |
|
32 | - */ |
|
33 | - private static $_instance; |
|
34 | - |
|
35 | - /** |
|
36 | - * initial reg status at the beginning of this request. |
|
37 | - * indexed by registration ID |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - protected $_old_reg_status = array(); |
|
42 | - |
|
43 | - /** |
|
44 | - * reg status at the end of the request after all processing. |
|
45 | - * indexed by registration ID |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $_new_reg_status = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * amounts paid at the end of the request after all processing. |
|
53 | - * indexed by registration ID |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - protected static $_amount_paid = array(); |
|
58 | - |
|
59 | - /** |
|
60 | - * Cache of the reg final price for registrations corresponding to a ticket line item |
|
61 | - * |
|
62 | - * @deprecated |
|
63 | - * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
64 | - */ |
|
65 | - protected $_reg_final_price_per_tkt_line_item; |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @singleton method used to instantiate class object |
|
71 | - * @access public |
|
72 | - * @return EE_Registration_Processor instance |
|
73 | - */ |
|
74 | - public static function instance() |
|
75 | - { |
|
76 | - // check if class object is instantiated |
|
77 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
78 | - self::$_instance = new self(); |
|
79 | - } |
|
80 | - return self::$_instance; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * EE_Registration_Processor constructor |
|
87 | - */ |
|
88 | - private function __construct() |
|
89 | - { |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @param int $REG_ID |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function old_reg_status($REG_ID) |
|
99 | - { |
|
100 | - return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param int $REG_ID |
|
107 | - * @param string $old_reg_status |
|
108 | - */ |
|
109 | - public function set_old_reg_status($REG_ID, $old_reg_status) |
|
110 | - { |
|
111 | - // only set the first time |
|
112 | - if (! isset($this->_old_reg_status[$REG_ID])) { |
|
113 | - $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param int $REG_ID |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function new_reg_status($REG_ID) |
|
124 | - { |
|
125 | - return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @param int $REG_ID |
|
132 | - * @param string $new_reg_status |
|
133 | - */ |
|
134 | - public function set_new_reg_status($REG_ID, $new_reg_status) |
|
135 | - { |
|
136 | - $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * reg_status_updated |
|
143 | - * |
|
144 | - * @param int $REG_ID |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function reg_status_updated($REG_ID) |
|
148 | - { |
|
149 | - return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param EE_Registration $registration |
|
156 | - * @throws EE_Error |
|
157 | - * @throws EntityNotFoundException |
|
158 | - * @throws InvalidArgumentException |
|
159 | - * @throws InvalidDataTypeException |
|
160 | - * @throws InvalidInterfaceException |
|
161 | - * @throws ReflectionException |
|
162 | - * @throws RuntimeException |
|
163 | - */ |
|
164 | - public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
165 | - { |
|
166 | - $this->toggle_incomplete_registration_status_to_default($registration, false); |
|
167 | - $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
168 | - $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
169 | - $registration->save(); |
|
170 | - // trigger notifications |
|
171 | - $this->trigger_registration_update_notifications($registration); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * manually_update_registration_status |
|
178 | - * |
|
179 | - * @access public |
|
180 | - * @param EE_Registration $registration |
|
181 | - * @param string $new_reg_status |
|
182 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
183 | - * to client code |
|
184 | - * @return bool |
|
185 | - * @throws EE_Error |
|
186 | - * @throws EntityNotFoundException |
|
187 | - * @throws InvalidArgumentException |
|
188 | - * @throws InvalidDataTypeException |
|
189 | - * @throws InvalidInterfaceException |
|
190 | - * @throws ReflectionException |
|
191 | - * @throws RuntimeException |
|
192 | - */ |
|
193 | - public function manually_update_registration_status( |
|
194 | - EE_Registration $registration, |
|
195 | - $new_reg_status = '', |
|
196 | - $save = true |
|
197 | - ) { |
|
198 | - // set initial REG_Status |
|
199 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
200 | - // set incoming REG_Status |
|
201 | - $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
202 | - // toggle reg status but only if it has changed and the user can do so |
|
203 | - if ( |
|
204 | - $this->reg_status_updated($registration->ID()) |
|
205 | - && EE_Registry::instance()->CAP->current_user_can( |
|
206 | - 'ee_edit_registration', |
|
207 | - 'toggle_registration_status', |
|
208 | - $registration->ID() |
|
209 | - ) |
|
210 | - ) { |
|
211 | - // change status to new value |
|
212 | - $updated = $registration->set_status($this->new_reg_status($registration->ID())); |
|
213 | - if ($updated && $save) { |
|
214 | - $registration->save(); |
|
215 | - } |
|
216 | - return true; |
|
217 | - } |
|
218 | - return false; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * toggle_incomplete_registration_status_to_default |
|
225 | - * changes any incomplete registrations to either the event or global default registration status |
|
226 | - * |
|
227 | - * @access public |
|
228 | - * @param EE_Registration $registration |
|
229 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
230 | - * to client code |
|
231 | - * @param Context|null $context |
|
232 | - * @return void |
|
233 | - * @throws EE_Error |
|
234 | - * @throws InvalidArgumentException |
|
235 | - * @throws ReflectionException |
|
236 | - * @throws RuntimeException |
|
237 | - * @throws EntityNotFoundException |
|
238 | - * @throws InvalidDataTypeException |
|
239 | - * @throws InvalidInterfaceException |
|
240 | - */ |
|
241 | - public function toggle_incomplete_registration_status_to_default( |
|
242 | - EE_Registration $registration, |
|
243 | - $save = true, |
|
244 | - Context $context = null |
|
245 | - ) { |
|
246 | - $existing_reg_status = $registration->status_ID(); |
|
247 | - // set initial REG_Status |
|
248 | - $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
249 | - // is the registration currently incomplete ? |
|
250 | - if ($registration->status_ID() === EEM_Registration::status_id_incomplete) { |
|
251 | - // grab default reg status for the event, if set |
|
252 | - $event_default_registration_status = $registration->event()->default_registration_status(); |
|
253 | - // if no default reg status is set for the event, then use the global value |
|
254 | - $STS_ID = ! empty($event_default_registration_status) |
|
255 | - ? $event_default_registration_status |
|
256 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
257 | - // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
258 | - $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment |
|
259 | - : $STS_ID; |
|
260 | - // set incoming REG_Status |
|
261 | - $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
262 | - $registration->set_status($STS_ID, false, $context); |
|
263 | - if ($save) { |
|
264 | - $registration->save(); |
|
265 | - } |
|
266 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
267 | - if (! EE_Processor_Base::$IPN) { |
|
268 | - // otherwise, send out notifications |
|
269 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
270 | - } |
|
271 | - // DEBUG LOG |
|
272 | - //$this->log( |
|
273 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
274 | - // $registration->transaction(), |
|
275 | - // array( |
|
276 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
277 | - // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
278 | - // ) |
|
279 | - //); |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * toggle_registration_status_for_default_approved_events |
|
287 | - * |
|
288 | - * @access public |
|
289 | - * @param EE_Registration $registration |
|
290 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
291 | - * to client code |
|
292 | - * @return bool |
|
293 | - * @throws EE_Error |
|
294 | - * @throws EntityNotFoundException |
|
295 | - * @throws InvalidArgumentException |
|
296 | - * @throws InvalidDataTypeException |
|
297 | - * @throws InvalidInterfaceException |
|
298 | - * @throws ReflectionException |
|
299 | - * @throws RuntimeException |
|
300 | - */ |
|
301 | - public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
302 | - { |
|
303 | - $reg_status = $registration->status_ID(); |
|
304 | - // set initial REG_Status |
|
305 | - $this->set_old_reg_status($registration->ID(), $reg_status); |
|
306 | - // if not already, toggle reg status to approved IF the event default reg status is approved |
|
307 | - // ( as long as the registration wasn't cancelled or declined at some point ) |
|
308 | - if ( |
|
309 | - $reg_status !== EEM_Registration::status_id_cancelled |
|
310 | - && $reg_status |
|
311 | - !== EEM_Registration::status_id_declined |
|
312 | - && $reg_status !== EEM_Registration::status_id_approved |
|
313 | - && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved |
|
314 | - ) { |
|
315 | - // set incoming REG_Status |
|
316 | - $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
317 | - // toggle status to approved |
|
318 | - $registration->set_status(EEM_Registration::status_id_approved); |
|
319 | - if ($save) { |
|
320 | - $registration->save(); |
|
321 | - } |
|
322 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
323 | - if (! EE_Processor_Base::$IPN) { |
|
324 | - // otherwise, send out notifications |
|
325 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
326 | - } |
|
327 | - // DEBUG LOG |
|
328 | - //$this->log( |
|
329 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
330 | - // $registration->transaction(), |
|
331 | - // array( |
|
332 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
333 | - // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
334 | - // ) |
|
335 | - //); |
|
336 | - return true; |
|
337 | - } |
|
338 | - return false; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * toggle_registration_statuses_if_no_monies_owing |
|
345 | - * |
|
346 | - * @access public |
|
347 | - * @param EE_Registration $registration |
|
348 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
349 | - * to client code |
|
350 | - * @param array $additional_details |
|
351 | - * @return bool |
|
352 | - * @throws EE_Error |
|
353 | - * @throws EntityNotFoundException |
|
354 | - * @throws InvalidArgumentException |
|
355 | - * @throws InvalidDataTypeException |
|
356 | - * @throws InvalidInterfaceException |
|
357 | - * @throws ReflectionException |
|
358 | - * @throws RuntimeException |
|
359 | - */ |
|
360 | - public function toggle_registration_status_if_no_monies_owing( |
|
361 | - EE_Registration $registration, |
|
362 | - $save = true, |
|
363 | - array $additional_details = array() |
|
364 | - ) { |
|
365 | - // set initial REG_Status |
|
366 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
367 | - // was a payment just made ? |
|
368 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
369 | - && $additional_details['payment_updates'] |
|
370 | - && $additional_details['last_payment'] instanceof EE_Payment |
|
371 | - ? $additional_details['last_payment'] |
|
372 | - : null; |
|
373 | - $total_paid = array_sum(self::$_amount_paid); |
|
374 | - // toggle reg status to approved IF |
|
375 | - if ( |
|
376 | - // REG status is pending payment |
|
377 | - $registration->status_ID() === EEM_Registration::status_id_pending_payment |
|
378 | - // AND no monies are owing |
|
379 | - && ( |
|
380 | - ( |
|
381 | - $registration->transaction()->is_completed() |
|
382 | - || $registration->transaction()->is_overpaid() |
|
383 | - || $registration->transaction()->is_free() |
|
384 | - || apply_filters( |
|
385 | - 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
386 | - false, |
|
387 | - $registration |
|
388 | - ) |
|
389 | - ) |
|
390 | - || ( |
|
391 | - $payment instanceof EE_Payment && $payment->is_approved() |
|
392 | - && // this specific registration has not yet been paid for |
|
393 | - ! isset(self::$_amount_paid[$registration->ID()]) |
|
394 | - && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
395 | - $payment->amount() - $total_paid >= $registration->final_price() |
|
396 | - ) |
|
397 | - ) |
|
398 | - ) { |
|
399 | - // mark as paid |
|
400 | - self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
401 | - // track new REG_Status |
|
402 | - $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
403 | - // toggle status to approved |
|
404 | - $registration->set_status(EEM_Registration::status_id_approved); |
|
405 | - if ($save) { |
|
406 | - $registration->save(); |
|
407 | - } |
|
408 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
409 | - if (! EE_Processor_Base::$IPN) { |
|
410 | - // otherwise, send out notifications |
|
411 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
412 | - } |
|
413 | - // DEBUG LOG |
|
414 | - //$this->log( |
|
415 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
416 | - // $registration->transaction(), |
|
417 | - // array( |
|
418 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
419 | - // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
420 | - // ) |
|
421 | - //); |
|
422 | - return true; |
|
423 | - } |
|
424 | - return false; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * registration_status_changed |
|
431 | - * |
|
432 | - * @access public |
|
433 | - * @param EE_Registration $registration |
|
434 | - * @param array $additional_details |
|
435 | - * @return void |
|
436 | - */ |
|
437 | - public function trigger_registration_update_notifications($registration, array $additional_details = array()) |
|
438 | - { |
|
439 | - try { |
|
440 | - if (! $registration instanceof EE_Registration) { |
|
441 | - throw new EE_Error( |
|
442 | - esc_html__('An invalid registration was received.', 'event_espresso') |
|
443 | - ); |
|
444 | - } |
|
445 | - // EE_Registry::instance()->load_helper( 'Debug_Tools' ); |
|
446 | - // EEH_Debug_Tools::log( |
|
447 | - // __CLASS__, |
|
448 | - // __FUNCTION__, |
|
449 | - // __LINE__, |
|
450 | - // array( $registration->transaction(), $additional_details ), |
|
451 | - // false, |
|
452 | - // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
453 | - // ); |
|
454 | - if (! $registration->is_primary_registrant()) { |
|
455 | - return; |
|
456 | - } |
|
457 | - do_action( |
|
458 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
459 | - $registration, |
|
460 | - $additional_details |
|
461 | - ); |
|
462 | - } catch (Exception $e) { |
|
463 | - EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
471 | - * |
|
472 | - * @param EE_Registration $registration |
|
473 | - * @param array $additional_details |
|
474 | - * @return bool |
|
475 | - * @throws EE_Error |
|
476 | - * @throws EntityNotFoundException |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws InvalidDataTypeException |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - * @throws ReflectionException |
|
481 | - * @throws RuntimeException |
|
482 | - */ |
|
483 | - public function update_registration_after_checkout_or_payment( |
|
484 | - EE_Registration $registration, |
|
485 | - array $additional_details = array() |
|
486 | - ) { |
|
487 | - // set initial REG_Status |
|
488 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
489 | - // if the registration status gets updated, then save the registration |
|
490 | - if ( |
|
491 | - $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
492 | - || $this->toggle_registration_status_if_no_monies_owing( |
|
493 | - $registration, |
|
494 | - false, |
|
495 | - $additional_details |
|
496 | - ) |
|
497 | - ) { |
|
498 | - $registration->save(); |
|
499 | - } |
|
500 | - // set new REG_Status |
|
501 | - $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
502 | - return $this->reg_status_updated($registration->ID()) |
|
503 | - && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved; |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * Updates the registration' final prices based on the current line item tree (taking into account |
|
510 | - * discounts, taxes, and other line items unrelated to tickets.) |
|
511 | - * |
|
512 | - * @param EE_Transaction $transaction |
|
513 | - * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
514 | - * @return void |
|
515 | - * @throws EE_Error |
|
516 | - * @throws InvalidArgumentException |
|
517 | - * @throws InvalidDataTypeException |
|
518 | - * @throws InvalidInterfaceException |
|
519 | - * @throws RuntimeException |
|
520 | - */ |
|
521 | - public function update_registration_final_prices($transaction, $save_regs = true) |
|
522 | - { |
|
523 | - $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
524 | - $transaction->total_line_item() |
|
525 | - ); |
|
526 | - foreach ($transaction->registrations() as $registration) { |
|
527 | - /** @var EE_Line_Item $line_item */ |
|
528 | - $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
529 | - if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
530 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
531 | - if ($save_regs) { |
|
532 | - $registration->save(); |
|
533 | - } |
|
534 | - } |
|
535 | - } |
|
536 | - //and make sure there's no rounding problem |
|
537 | - $this->fix_reg_final_price_rounding_issue($transaction); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * Makes sure there is no rounding errors for the REG_final_prices. |
|
544 | - * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
545 | - * they will each be for $0.99333333, which gets rounded to $1 again. |
|
546 | - * So the transaction total will be $2.99, but each registration will be for $1, |
|
547 | - * so if each registrant paid individually they will have overpaid by $0.01. |
|
548 | - * So in order to overcome this, we check for any difference, and if there is a difference |
|
549 | - * we just grab one registrant at random and make them responsible for it. |
|
550 | - * This should be used after setting REG_final_prices (it's done automatically as part of |
|
551 | - * EE_Registration_Processor::update_registration_final_prices()) |
|
552 | - * |
|
553 | - * @param EE_Transaction $transaction |
|
554 | - * @return bool success verifying that there is NO difference after this method is done |
|
555 | - * @throws EE_Error |
|
556 | - * @throws InvalidArgumentException |
|
557 | - * @throws InvalidDataTypeException |
|
558 | - * @throws InvalidInterfaceException |
|
559 | - */ |
|
560 | - public function fix_reg_final_price_rounding_issue($transaction) |
|
561 | - { |
|
562 | - $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
563 | - array( |
|
564 | - array( |
|
565 | - 'TXN_ID' => $transaction->ID(), |
|
566 | - ), |
|
567 | - ), |
|
568 | - 'REG_final_price' |
|
569 | - ); |
|
570 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
571 | - //ok then, just grab one of the registrations |
|
572 | - if ($diff !== 0) { |
|
573 | - $a_reg = EEM_Registration::instance()->get_one( |
|
574 | - array( |
|
575 | - array( |
|
576 | - 'TXN_ID' => $transaction->ID(), |
|
577 | - ), |
|
578 | - ) |
|
579 | - ); |
|
580 | - return $a_reg instanceof EE_Registration |
|
581 | - ? (bool) $a_reg->save(array('REG_final_price' => $a_reg->final_price() + $diff)) |
|
582 | - : false; |
|
583 | - } |
|
584 | - return true; |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * update_registration_after_being_canceled_or_declined |
|
591 | - * |
|
592 | - * @param EE_Registration $registration |
|
593 | - * @param array $closed_reg_statuses |
|
594 | - * @param bool $update_reg |
|
595 | - * @return bool |
|
596 | - * @throws EE_Error |
|
597 | - * @throws RuntimeException |
|
598 | - */ |
|
599 | - public function update_registration_after_being_canceled_or_declined( |
|
600 | - EE_Registration $registration, |
|
601 | - array $closed_reg_statuses = array(), |
|
602 | - $update_reg = true |
|
603 | - ) { |
|
604 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
605 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
606 | - ? $closed_reg_statuses |
|
607 | - : EEM_Registration::closed_reg_statuses(); |
|
608 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
609 | - return false; |
|
610 | - } |
|
611 | - // release a reserved ticket by decrementing ticket and datetime reserved values |
|
612 | - $registration->release_reserved_ticket(true); |
|
613 | - $registration->set_final_price(0); |
|
614 | - if ($update_reg) { |
|
615 | - $registration->save(); |
|
616 | - } |
|
617 | - return true; |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * update_canceled_or_declined_registration_after_being_reinstated |
|
624 | - * |
|
625 | - * @param EE_Registration $registration |
|
626 | - * @param array $closed_reg_statuses |
|
627 | - * @param bool $update_reg |
|
628 | - * @return bool |
|
629 | - * @throws EE_Error |
|
630 | - * @throws RuntimeException |
|
631 | - */ |
|
632 | - public function update_canceled_or_declined_registration_after_being_reinstated( |
|
633 | - EE_Registration $registration, |
|
634 | - array $closed_reg_statuses = array(), |
|
635 | - $update_reg = true |
|
636 | - ) { |
|
637 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
638 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
639 | - : EEM_Registration::closed_reg_statuses(); |
|
640 | - if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
641 | - return false; |
|
642 | - } |
|
643 | - $ticket = $registration->ticket(); |
|
644 | - if (! $ticket instanceof EE_Ticket) { |
|
645 | - throw new EE_Error( |
|
646 | - sprintf( |
|
647 | - esc_html__( |
|
648 | - 'The Ticket for Registration %1$d was not found or is invalid.', |
|
649 | - 'event_espresso' |
|
650 | - ), |
|
651 | - $registration->ticket_ID() |
|
652 | - ) |
|
653 | - ); |
|
654 | - } |
|
655 | - $registration->set_final_price($ticket->price()); |
|
656 | - if ($update_reg) { |
|
657 | - $registration->save(); |
|
658 | - } |
|
659 | - return true; |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * generate_ONE_registration_from_line_item |
|
666 | - * Although a ticket line item may have a quantity greater than 1, |
|
667 | - * this method will ONLY CREATE ONE REGISTRATION !!! |
|
668 | - * Regardless of the ticket line item quantity. |
|
669 | - * This means that any code calling this method is responsible for ensuring |
|
670 | - * that the final registration count matches the ticket line item quantity. |
|
671 | - * This was done to make it easier to match the number of registrations |
|
672 | - * to the number of tickets in the cart, when the cart has been edited |
|
673 | - * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
674 | - * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
675 | - * |
|
676 | - * @deprecated |
|
677 | - * @since 4.9.1 |
|
678 | - * @param EE_Line_Item $line_item |
|
679 | - * @param \EE_Transaction $transaction |
|
680 | - * @param int $att_nmbr |
|
681 | - * @param int $total_ticket_count |
|
682 | - * @return EE_Registration | null |
|
683 | - * @throws \OutOfRangeException |
|
684 | - * @throws \EventEspresso\core\exceptions\UnexpectedEntityException |
|
685 | - * @throws \EE_Error |
|
686 | - */ |
|
687 | - public function generate_ONE_registration_from_line_item( |
|
688 | - EE_Line_Item $line_item, |
|
689 | - EE_Transaction $transaction, |
|
690 | - $att_nmbr = 1, |
|
691 | - $total_ticket_count = 1 |
|
692 | - ) { |
|
693 | - EE_Error::doing_it_wrong( |
|
694 | - __CLASS__ . '::' . __FUNCTION__, |
|
695 | - sprintf( |
|
696 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
697 | - '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
698 | - ), |
|
699 | - '4.9.1', |
|
700 | - '5.0.0' |
|
701 | - ); |
|
702 | - // grab the related ticket object for this line_item |
|
703 | - $ticket = $line_item->ticket(); |
|
704 | - if (! $ticket instanceof EE_Ticket) { |
|
705 | - EE_Error::add_error( |
|
706 | - sprintf( |
|
707 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
708 | - $line_item->ID() |
|
709 | - ), |
|
710 | - __FILE__, |
|
711 | - __FUNCTION__, |
|
712 | - __LINE__ |
|
713 | - ); |
|
714 | - return null; |
|
715 | - } |
|
716 | - $registration_service = new CreateRegistrationService(); |
|
717 | - // then generate a new registration from that |
|
718 | - return $registration_service->create( |
|
719 | - $ticket->get_related_event(), |
|
720 | - $transaction, |
|
721 | - $ticket, |
|
722 | - $line_item, |
|
723 | - $att_nmbr, |
|
724 | - $total_ticket_count |
|
725 | - ); |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * generates reg_url_link |
|
732 | - * |
|
733 | - * @deprecated |
|
734 | - * @since 4.9.1 |
|
735 | - * @param int $att_nmbr |
|
736 | - * @param EE_Line_Item | string $item |
|
737 | - * @return string |
|
738 | - * @throws InvalidArgumentException |
|
739 | - */ |
|
740 | - public function generate_reg_url_link($att_nmbr, $item) |
|
741 | - { |
|
742 | - EE_Error::doing_it_wrong( |
|
743 | - __CLASS__ . '::' . __FUNCTION__, |
|
744 | - sprintf( |
|
745 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
746 | - 'EventEspresso\core\domain\entities\RegUrlLink' |
|
747 | - ), |
|
748 | - '4.9.1', |
|
749 | - '5.0.0' |
|
750 | - ); |
|
751 | - return new RegUrlLink($att_nmbr, $item); |
|
752 | - } |
|
753 | - |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * generates reg code |
|
758 | - * |
|
759 | - * @deprecated |
|
760 | - * @since 4.9.1 |
|
761 | - * @param EE_Registration $registration |
|
762 | - * @return string |
|
763 | - * @throws EE_Error |
|
764 | - * @throws EntityNotFoundException |
|
765 | - * @throws InvalidArgumentException |
|
766 | - */ |
|
767 | - public function generate_reg_code(EE_Registration $registration) |
|
768 | - { |
|
769 | - EE_Error::doing_it_wrong( |
|
770 | - __CLASS__ . '::' . __FUNCTION__, |
|
771 | - sprintf( |
|
772 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
773 | - 'EventEspresso\core\domain\entities\RegCode' |
|
774 | - ), |
|
775 | - '4.9.1', |
|
776 | - '5.0.0' |
|
777 | - ); |
|
778 | - return apply_filters( |
|
779 | - 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
780 | - new RegCode( |
|
781 | - RegUrlLink::fromRegistration($registration), |
|
782 | - $registration->transaction(), |
|
783 | - $registration->ticket() |
|
784 | - ), |
|
785 | - $registration |
|
786 | - ); |
|
787 | - } |
|
29 | + /** |
|
30 | + * @var EE_Registration_Processor $_instance |
|
31 | + * @access private |
|
32 | + */ |
|
33 | + private static $_instance; |
|
34 | + |
|
35 | + /** |
|
36 | + * initial reg status at the beginning of this request. |
|
37 | + * indexed by registration ID |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + protected $_old_reg_status = array(); |
|
42 | + |
|
43 | + /** |
|
44 | + * reg status at the end of the request after all processing. |
|
45 | + * indexed by registration ID |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $_new_reg_status = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * amounts paid at the end of the request after all processing. |
|
53 | + * indexed by registration ID |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + protected static $_amount_paid = array(); |
|
58 | + |
|
59 | + /** |
|
60 | + * Cache of the reg final price for registrations corresponding to a ticket line item |
|
61 | + * |
|
62 | + * @deprecated |
|
63 | + * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
64 | + */ |
|
65 | + protected $_reg_final_price_per_tkt_line_item; |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @singleton method used to instantiate class object |
|
71 | + * @access public |
|
72 | + * @return EE_Registration_Processor instance |
|
73 | + */ |
|
74 | + public static function instance() |
|
75 | + { |
|
76 | + // check if class object is instantiated |
|
77 | + if (! self::$_instance instanceof EE_Registration_Processor) { |
|
78 | + self::$_instance = new self(); |
|
79 | + } |
|
80 | + return self::$_instance; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * EE_Registration_Processor constructor |
|
87 | + */ |
|
88 | + private function __construct() |
|
89 | + { |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @param int $REG_ID |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function old_reg_status($REG_ID) |
|
99 | + { |
|
100 | + return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param int $REG_ID |
|
107 | + * @param string $old_reg_status |
|
108 | + */ |
|
109 | + public function set_old_reg_status($REG_ID, $old_reg_status) |
|
110 | + { |
|
111 | + // only set the first time |
|
112 | + if (! isset($this->_old_reg_status[$REG_ID])) { |
|
113 | + $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param int $REG_ID |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function new_reg_status($REG_ID) |
|
124 | + { |
|
125 | + return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @param int $REG_ID |
|
132 | + * @param string $new_reg_status |
|
133 | + */ |
|
134 | + public function set_new_reg_status($REG_ID, $new_reg_status) |
|
135 | + { |
|
136 | + $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * reg_status_updated |
|
143 | + * |
|
144 | + * @param int $REG_ID |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function reg_status_updated($REG_ID) |
|
148 | + { |
|
149 | + return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param EE_Registration $registration |
|
156 | + * @throws EE_Error |
|
157 | + * @throws EntityNotFoundException |
|
158 | + * @throws InvalidArgumentException |
|
159 | + * @throws InvalidDataTypeException |
|
160 | + * @throws InvalidInterfaceException |
|
161 | + * @throws ReflectionException |
|
162 | + * @throws RuntimeException |
|
163 | + */ |
|
164 | + public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
165 | + { |
|
166 | + $this->toggle_incomplete_registration_status_to_default($registration, false); |
|
167 | + $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
168 | + $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
169 | + $registration->save(); |
|
170 | + // trigger notifications |
|
171 | + $this->trigger_registration_update_notifications($registration); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * manually_update_registration_status |
|
178 | + * |
|
179 | + * @access public |
|
180 | + * @param EE_Registration $registration |
|
181 | + * @param string $new_reg_status |
|
182 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
183 | + * to client code |
|
184 | + * @return bool |
|
185 | + * @throws EE_Error |
|
186 | + * @throws EntityNotFoundException |
|
187 | + * @throws InvalidArgumentException |
|
188 | + * @throws InvalidDataTypeException |
|
189 | + * @throws InvalidInterfaceException |
|
190 | + * @throws ReflectionException |
|
191 | + * @throws RuntimeException |
|
192 | + */ |
|
193 | + public function manually_update_registration_status( |
|
194 | + EE_Registration $registration, |
|
195 | + $new_reg_status = '', |
|
196 | + $save = true |
|
197 | + ) { |
|
198 | + // set initial REG_Status |
|
199 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
200 | + // set incoming REG_Status |
|
201 | + $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
202 | + // toggle reg status but only if it has changed and the user can do so |
|
203 | + if ( |
|
204 | + $this->reg_status_updated($registration->ID()) |
|
205 | + && EE_Registry::instance()->CAP->current_user_can( |
|
206 | + 'ee_edit_registration', |
|
207 | + 'toggle_registration_status', |
|
208 | + $registration->ID() |
|
209 | + ) |
|
210 | + ) { |
|
211 | + // change status to new value |
|
212 | + $updated = $registration->set_status($this->new_reg_status($registration->ID())); |
|
213 | + if ($updated && $save) { |
|
214 | + $registration->save(); |
|
215 | + } |
|
216 | + return true; |
|
217 | + } |
|
218 | + return false; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * toggle_incomplete_registration_status_to_default |
|
225 | + * changes any incomplete registrations to either the event or global default registration status |
|
226 | + * |
|
227 | + * @access public |
|
228 | + * @param EE_Registration $registration |
|
229 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
230 | + * to client code |
|
231 | + * @param Context|null $context |
|
232 | + * @return void |
|
233 | + * @throws EE_Error |
|
234 | + * @throws InvalidArgumentException |
|
235 | + * @throws ReflectionException |
|
236 | + * @throws RuntimeException |
|
237 | + * @throws EntityNotFoundException |
|
238 | + * @throws InvalidDataTypeException |
|
239 | + * @throws InvalidInterfaceException |
|
240 | + */ |
|
241 | + public function toggle_incomplete_registration_status_to_default( |
|
242 | + EE_Registration $registration, |
|
243 | + $save = true, |
|
244 | + Context $context = null |
|
245 | + ) { |
|
246 | + $existing_reg_status = $registration->status_ID(); |
|
247 | + // set initial REG_Status |
|
248 | + $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
249 | + // is the registration currently incomplete ? |
|
250 | + if ($registration->status_ID() === EEM_Registration::status_id_incomplete) { |
|
251 | + // grab default reg status for the event, if set |
|
252 | + $event_default_registration_status = $registration->event()->default_registration_status(); |
|
253 | + // if no default reg status is set for the event, then use the global value |
|
254 | + $STS_ID = ! empty($event_default_registration_status) |
|
255 | + ? $event_default_registration_status |
|
256 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
257 | + // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
258 | + $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment |
|
259 | + : $STS_ID; |
|
260 | + // set incoming REG_Status |
|
261 | + $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
262 | + $registration->set_status($STS_ID, false, $context); |
|
263 | + if ($save) { |
|
264 | + $registration->save(); |
|
265 | + } |
|
266 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
267 | + if (! EE_Processor_Base::$IPN) { |
|
268 | + // otherwise, send out notifications |
|
269 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
270 | + } |
|
271 | + // DEBUG LOG |
|
272 | + //$this->log( |
|
273 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
274 | + // $registration->transaction(), |
|
275 | + // array( |
|
276 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
277 | + // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
278 | + // ) |
|
279 | + //); |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * toggle_registration_status_for_default_approved_events |
|
287 | + * |
|
288 | + * @access public |
|
289 | + * @param EE_Registration $registration |
|
290 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
291 | + * to client code |
|
292 | + * @return bool |
|
293 | + * @throws EE_Error |
|
294 | + * @throws EntityNotFoundException |
|
295 | + * @throws InvalidArgumentException |
|
296 | + * @throws InvalidDataTypeException |
|
297 | + * @throws InvalidInterfaceException |
|
298 | + * @throws ReflectionException |
|
299 | + * @throws RuntimeException |
|
300 | + */ |
|
301 | + public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
302 | + { |
|
303 | + $reg_status = $registration->status_ID(); |
|
304 | + // set initial REG_Status |
|
305 | + $this->set_old_reg_status($registration->ID(), $reg_status); |
|
306 | + // if not already, toggle reg status to approved IF the event default reg status is approved |
|
307 | + // ( as long as the registration wasn't cancelled or declined at some point ) |
|
308 | + if ( |
|
309 | + $reg_status !== EEM_Registration::status_id_cancelled |
|
310 | + && $reg_status |
|
311 | + !== EEM_Registration::status_id_declined |
|
312 | + && $reg_status !== EEM_Registration::status_id_approved |
|
313 | + && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved |
|
314 | + ) { |
|
315 | + // set incoming REG_Status |
|
316 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
317 | + // toggle status to approved |
|
318 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
319 | + if ($save) { |
|
320 | + $registration->save(); |
|
321 | + } |
|
322 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
323 | + if (! EE_Processor_Base::$IPN) { |
|
324 | + // otherwise, send out notifications |
|
325 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
326 | + } |
|
327 | + // DEBUG LOG |
|
328 | + //$this->log( |
|
329 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
330 | + // $registration->transaction(), |
|
331 | + // array( |
|
332 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
333 | + // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
334 | + // ) |
|
335 | + //); |
|
336 | + return true; |
|
337 | + } |
|
338 | + return false; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * toggle_registration_statuses_if_no_monies_owing |
|
345 | + * |
|
346 | + * @access public |
|
347 | + * @param EE_Registration $registration |
|
348 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
349 | + * to client code |
|
350 | + * @param array $additional_details |
|
351 | + * @return bool |
|
352 | + * @throws EE_Error |
|
353 | + * @throws EntityNotFoundException |
|
354 | + * @throws InvalidArgumentException |
|
355 | + * @throws InvalidDataTypeException |
|
356 | + * @throws InvalidInterfaceException |
|
357 | + * @throws ReflectionException |
|
358 | + * @throws RuntimeException |
|
359 | + */ |
|
360 | + public function toggle_registration_status_if_no_monies_owing( |
|
361 | + EE_Registration $registration, |
|
362 | + $save = true, |
|
363 | + array $additional_details = array() |
|
364 | + ) { |
|
365 | + // set initial REG_Status |
|
366 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
367 | + // was a payment just made ? |
|
368 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
369 | + && $additional_details['payment_updates'] |
|
370 | + && $additional_details['last_payment'] instanceof EE_Payment |
|
371 | + ? $additional_details['last_payment'] |
|
372 | + : null; |
|
373 | + $total_paid = array_sum(self::$_amount_paid); |
|
374 | + // toggle reg status to approved IF |
|
375 | + if ( |
|
376 | + // REG status is pending payment |
|
377 | + $registration->status_ID() === EEM_Registration::status_id_pending_payment |
|
378 | + // AND no monies are owing |
|
379 | + && ( |
|
380 | + ( |
|
381 | + $registration->transaction()->is_completed() |
|
382 | + || $registration->transaction()->is_overpaid() |
|
383 | + || $registration->transaction()->is_free() |
|
384 | + || apply_filters( |
|
385 | + 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
386 | + false, |
|
387 | + $registration |
|
388 | + ) |
|
389 | + ) |
|
390 | + || ( |
|
391 | + $payment instanceof EE_Payment && $payment->is_approved() |
|
392 | + && // this specific registration has not yet been paid for |
|
393 | + ! isset(self::$_amount_paid[$registration->ID()]) |
|
394 | + && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
395 | + $payment->amount() - $total_paid >= $registration->final_price() |
|
396 | + ) |
|
397 | + ) |
|
398 | + ) { |
|
399 | + // mark as paid |
|
400 | + self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
401 | + // track new REG_Status |
|
402 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
403 | + // toggle status to approved |
|
404 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
405 | + if ($save) { |
|
406 | + $registration->save(); |
|
407 | + } |
|
408 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
409 | + if (! EE_Processor_Base::$IPN) { |
|
410 | + // otherwise, send out notifications |
|
411 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
412 | + } |
|
413 | + // DEBUG LOG |
|
414 | + //$this->log( |
|
415 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
416 | + // $registration->transaction(), |
|
417 | + // array( |
|
418 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
419 | + // 'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ), |
|
420 | + // ) |
|
421 | + //); |
|
422 | + return true; |
|
423 | + } |
|
424 | + return false; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * registration_status_changed |
|
431 | + * |
|
432 | + * @access public |
|
433 | + * @param EE_Registration $registration |
|
434 | + * @param array $additional_details |
|
435 | + * @return void |
|
436 | + */ |
|
437 | + public function trigger_registration_update_notifications($registration, array $additional_details = array()) |
|
438 | + { |
|
439 | + try { |
|
440 | + if (! $registration instanceof EE_Registration) { |
|
441 | + throw new EE_Error( |
|
442 | + esc_html__('An invalid registration was received.', 'event_espresso') |
|
443 | + ); |
|
444 | + } |
|
445 | + // EE_Registry::instance()->load_helper( 'Debug_Tools' ); |
|
446 | + // EEH_Debug_Tools::log( |
|
447 | + // __CLASS__, |
|
448 | + // __FUNCTION__, |
|
449 | + // __LINE__, |
|
450 | + // array( $registration->transaction(), $additional_details ), |
|
451 | + // false, |
|
452 | + // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
453 | + // ); |
|
454 | + if (! $registration->is_primary_registrant()) { |
|
455 | + return; |
|
456 | + } |
|
457 | + do_action( |
|
458 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
459 | + $registration, |
|
460 | + $additional_details |
|
461 | + ); |
|
462 | + } catch (Exception $e) { |
|
463 | + EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
471 | + * |
|
472 | + * @param EE_Registration $registration |
|
473 | + * @param array $additional_details |
|
474 | + * @return bool |
|
475 | + * @throws EE_Error |
|
476 | + * @throws EntityNotFoundException |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws InvalidDataTypeException |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + * @throws ReflectionException |
|
481 | + * @throws RuntimeException |
|
482 | + */ |
|
483 | + public function update_registration_after_checkout_or_payment( |
|
484 | + EE_Registration $registration, |
|
485 | + array $additional_details = array() |
|
486 | + ) { |
|
487 | + // set initial REG_Status |
|
488 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
489 | + // if the registration status gets updated, then save the registration |
|
490 | + if ( |
|
491 | + $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
492 | + || $this->toggle_registration_status_if_no_monies_owing( |
|
493 | + $registration, |
|
494 | + false, |
|
495 | + $additional_details |
|
496 | + ) |
|
497 | + ) { |
|
498 | + $registration->save(); |
|
499 | + } |
|
500 | + // set new REG_Status |
|
501 | + $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
502 | + return $this->reg_status_updated($registration->ID()) |
|
503 | + && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved; |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * Updates the registration' final prices based on the current line item tree (taking into account |
|
510 | + * discounts, taxes, and other line items unrelated to tickets.) |
|
511 | + * |
|
512 | + * @param EE_Transaction $transaction |
|
513 | + * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
514 | + * @return void |
|
515 | + * @throws EE_Error |
|
516 | + * @throws InvalidArgumentException |
|
517 | + * @throws InvalidDataTypeException |
|
518 | + * @throws InvalidInterfaceException |
|
519 | + * @throws RuntimeException |
|
520 | + */ |
|
521 | + public function update_registration_final_prices($transaction, $save_regs = true) |
|
522 | + { |
|
523 | + $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
524 | + $transaction->total_line_item() |
|
525 | + ); |
|
526 | + foreach ($transaction->registrations() as $registration) { |
|
527 | + /** @var EE_Line_Item $line_item */ |
|
528 | + $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
529 | + if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
530 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
531 | + if ($save_regs) { |
|
532 | + $registration->save(); |
|
533 | + } |
|
534 | + } |
|
535 | + } |
|
536 | + //and make sure there's no rounding problem |
|
537 | + $this->fix_reg_final_price_rounding_issue($transaction); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * Makes sure there is no rounding errors for the REG_final_prices. |
|
544 | + * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
545 | + * they will each be for $0.99333333, which gets rounded to $1 again. |
|
546 | + * So the transaction total will be $2.99, but each registration will be for $1, |
|
547 | + * so if each registrant paid individually they will have overpaid by $0.01. |
|
548 | + * So in order to overcome this, we check for any difference, and if there is a difference |
|
549 | + * we just grab one registrant at random and make them responsible for it. |
|
550 | + * This should be used after setting REG_final_prices (it's done automatically as part of |
|
551 | + * EE_Registration_Processor::update_registration_final_prices()) |
|
552 | + * |
|
553 | + * @param EE_Transaction $transaction |
|
554 | + * @return bool success verifying that there is NO difference after this method is done |
|
555 | + * @throws EE_Error |
|
556 | + * @throws InvalidArgumentException |
|
557 | + * @throws InvalidDataTypeException |
|
558 | + * @throws InvalidInterfaceException |
|
559 | + */ |
|
560 | + public function fix_reg_final_price_rounding_issue($transaction) |
|
561 | + { |
|
562 | + $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
563 | + array( |
|
564 | + array( |
|
565 | + 'TXN_ID' => $transaction->ID(), |
|
566 | + ), |
|
567 | + ), |
|
568 | + 'REG_final_price' |
|
569 | + ); |
|
570 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
571 | + //ok then, just grab one of the registrations |
|
572 | + if ($diff !== 0) { |
|
573 | + $a_reg = EEM_Registration::instance()->get_one( |
|
574 | + array( |
|
575 | + array( |
|
576 | + 'TXN_ID' => $transaction->ID(), |
|
577 | + ), |
|
578 | + ) |
|
579 | + ); |
|
580 | + return $a_reg instanceof EE_Registration |
|
581 | + ? (bool) $a_reg->save(array('REG_final_price' => $a_reg->final_price() + $diff)) |
|
582 | + : false; |
|
583 | + } |
|
584 | + return true; |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * update_registration_after_being_canceled_or_declined |
|
591 | + * |
|
592 | + * @param EE_Registration $registration |
|
593 | + * @param array $closed_reg_statuses |
|
594 | + * @param bool $update_reg |
|
595 | + * @return bool |
|
596 | + * @throws EE_Error |
|
597 | + * @throws RuntimeException |
|
598 | + */ |
|
599 | + public function update_registration_after_being_canceled_or_declined( |
|
600 | + EE_Registration $registration, |
|
601 | + array $closed_reg_statuses = array(), |
|
602 | + $update_reg = true |
|
603 | + ) { |
|
604 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
605 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
606 | + ? $closed_reg_statuses |
|
607 | + : EEM_Registration::closed_reg_statuses(); |
|
608 | + if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
609 | + return false; |
|
610 | + } |
|
611 | + // release a reserved ticket by decrementing ticket and datetime reserved values |
|
612 | + $registration->release_reserved_ticket(true); |
|
613 | + $registration->set_final_price(0); |
|
614 | + if ($update_reg) { |
|
615 | + $registration->save(); |
|
616 | + } |
|
617 | + return true; |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * update_canceled_or_declined_registration_after_being_reinstated |
|
624 | + * |
|
625 | + * @param EE_Registration $registration |
|
626 | + * @param array $closed_reg_statuses |
|
627 | + * @param bool $update_reg |
|
628 | + * @return bool |
|
629 | + * @throws EE_Error |
|
630 | + * @throws RuntimeException |
|
631 | + */ |
|
632 | + public function update_canceled_or_declined_registration_after_being_reinstated( |
|
633 | + EE_Registration $registration, |
|
634 | + array $closed_reg_statuses = array(), |
|
635 | + $update_reg = true |
|
636 | + ) { |
|
637 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
638 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
639 | + : EEM_Registration::closed_reg_statuses(); |
|
640 | + if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
641 | + return false; |
|
642 | + } |
|
643 | + $ticket = $registration->ticket(); |
|
644 | + if (! $ticket instanceof EE_Ticket) { |
|
645 | + throw new EE_Error( |
|
646 | + sprintf( |
|
647 | + esc_html__( |
|
648 | + 'The Ticket for Registration %1$d was not found or is invalid.', |
|
649 | + 'event_espresso' |
|
650 | + ), |
|
651 | + $registration->ticket_ID() |
|
652 | + ) |
|
653 | + ); |
|
654 | + } |
|
655 | + $registration->set_final_price($ticket->price()); |
|
656 | + if ($update_reg) { |
|
657 | + $registration->save(); |
|
658 | + } |
|
659 | + return true; |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * generate_ONE_registration_from_line_item |
|
666 | + * Although a ticket line item may have a quantity greater than 1, |
|
667 | + * this method will ONLY CREATE ONE REGISTRATION !!! |
|
668 | + * Regardless of the ticket line item quantity. |
|
669 | + * This means that any code calling this method is responsible for ensuring |
|
670 | + * that the final registration count matches the ticket line item quantity. |
|
671 | + * This was done to make it easier to match the number of registrations |
|
672 | + * to the number of tickets in the cart, when the cart has been edited |
|
673 | + * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
674 | + * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
675 | + * |
|
676 | + * @deprecated |
|
677 | + * @since 4.9.1 |
|
678 | + * @param EE_Line_Item $line_item |
|
679 | + * @param \EE_Transaction $transaction |
|
680 | + * @param int $att_nmbr |
|
681 | + * @param int $total_ticket_count |
|
682 | + * @return EE_Registration | null |
|
683 | + * @throws \OutOfRangeException |
|
684 | + * @throws \EventEspresso\core\exceptions\UnexpectedEntityException |
|
685 | + * @throws \EE_Error |
|
686 | + */ |
|
687 | + public function generate_ONE_registration_from_line_item( |
|
688 | + EE_Line_Item $line_item, |
|
689 | + EE_Transaction $transaction, |
|
690 | + $att_nmbr = 1, |
|
691 | + $total_ticket_count = 1 |
|
692 | + ) { |
|
693 | + EE_Error::doing_it_wrong( |
|
694 | + __CLASS__ . '::' . __FUNCTION__, |
|
695 | + sprintf( |
|
696 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
697 | + '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
698 | + ), |
|
699 | + '4.9.1', |
|
700 | + '5.0.0' |
|
701 | + ); |
|
702 | + // grab the related ticket object for this line_item |
|
703 | + $ticket = $line_item->ticket(); |
|
704 | + if (! $ticket instanceof EE_Ticket) { |
|
705 | + EE_Error::add_error( |
|
706 | + sprintf( |
|
707 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
708 | + $line_item->ID() |
|
709 | + ), |
|
710 | + __FILE__, |
|
711 | + __FUNCTION__, |
|
712 | + __LINE__ |
|
713 | + ); |
|
714 | + return null; |
|
715 | + } |
|
716 | + $registration_service = new CreateRegistrationService(); |
|
717 | + // then generate a new registration from that |
|
718 | + return $registration_service->create( |
|
719 | + $ticket->get_related_event(), |
|
720 | + $transaction, |
|
721 | + $ticket, |
|
722 | + $line_item, |
|
723 | + $att_nmbr, |
|
724 | + $total_ticket_count |
|
725 | + ); |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * generates reg_url_link |
|
732 | + * |
|
733 | + * @deprecated |
|
734 | + * @since 4.9.1 |
|
735 | + * @param int $att_nmbr |
|
736 | + * @param EE_Line_Item | string $item |
|
737 | + * @return string |
|
738 | + * @throws InvalidArgumentException |
|
739 | + */ |
|
740 | + public function generate_reg_url_link($att_nmbr, $item) |
|
741 | + { |
|
742 | + EE_Error::doing_it_wrong( |
|
743 | + __CLASS__ . '::' . __FUNCTION__, |
|
744 | + sprintf( |
|
745 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
746 | + 'EventEspresso\core\domain\entities\RegUrlLink' |
|
747 | + ), |
|
748 | + '4.9.1', |
|
749 | + '5.0.0' |
|
750 | + ); |
|
751 | + return new RegUrlLink($att_nmbr, $item); |
|
752 | + } |
|
753 | + |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * generates reg code |
|
758 | + * |
|
759 | + * @deprecated |
|
760 | + * @since 4.9.1 |
|
761 | + * @param EE_Registration $registration |
|
762 | + * @return string |
|
763 | + * @throws EE_Error |
|
764 | + * @throws EntityNotFoundException |
|
765 | + * @throws InvalidArgumentException |
|
766 | + */ |
|
767 | + public function generate_reg_code(EE_Registration $registration) |
|
768 | + { |
|
769 | + EE_Error::doing_it_wrong( |
|
770 | + __CLASS__ . '::' . __FUNCTION__, |
|
771 | + sprintf( |
|
772 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
773 | + 'EventEspresso\core\domain\entities\RegCode' |
|
774 | + ), |
|
775 | + '4.9.1', |
|
776 | + '5.0.0' |
|
777 | + ); |
|
778 | + return apply_filters( |
|
779 | + 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
780 | + new RegCode( |
|
781 | + RegUrlLink::fromRegistration($registration), |
|
782 | + $registration->transaction(), |
|
783 | + $registration->ticket() |
|
784 | + ), |
|
785 | + $registration |
|
786 | + ); |
|
787 | + } |
|
788 | 788 | |
789 | 789 | |
790 | 790 |
@@ -21,861 +21,861 @@ |
||
21 | 21 | class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var EE_Payment_Processor $_instance |
|
26 | - * @access private |
|
27 | - */ |
|
28 | - private static $_instance; |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @singleton method used to instantiate class object |
|
34 | - * @access public |
|
35 | - * @return EE_Payment_Processor instance |
|
36 | - */ |
|
37 | - public static function instance() |
|
38 | - { |
|
39 | - // check if class object is instantiated |
|
40 | - if (! self::$_instance instanceof EE_Payment_Processor) { |
|
41 | - self::$_instance = new self(); |
|
42 | - } |
|
43 | - return self::$_instance; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @return EE_Payment_Processor |
|
50 | - */ |
|
51 | - public static function reset() |
|
52 | - { |
|
53 | - self::$_instance = null; |
|
54 | - return self::instance(); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - *private constructor to prevent direct creation |
|
61 | - * |
|
62 | - * @Constructor |
|
63 | - * @access private |
|
64 | - */ |
|
65 | - private function __construct() |
|
66 | - { |
|
67 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
68 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
75 | - * appropriately. Saves the payment that is generated |
|
76 | - * |
|
77 | - * @param EE_Payment_Method $payment_method |
|
78 | - * @param EE_Transaction $transaction |
|
79 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
80 | - * Leave null if payment is for the full amount owing |
|
81 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
82 | - * Receive_form_submission() should have |
|
83 | - * already been called on the billing form |
|
84 | - * (ie, its inputs should have their normalized values set). |
|
85 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
86 | - * where to go AFTER the offsite gateway |
|
87 | - * @param string $method like 'CART', indicates who the client who called this was |
|
88 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
89 | - * @param boolean $update_txn whether or not to call |
|
90 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
91 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
92 | - * @return EE_Payment |
|
93 | - * @throws EE_Error |
|
94 | - * @throws InvalidArgumentException |
|
95 | - * @throws ReflectionException |
|
96 | - * @throws RuntimeException |
|
97 | - * @throws InvalidDataTypeException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - */ |
|
100 | - public function process_payment( |
|
101 | - EE_Payment_Method $payment_method, |
|
102 | - EE_Transaction $transaction, |
|
103 | - $amount = null, |
|
104 | - $billing_form = null, |
|
105 | - $return_url = null, |
|
106 | - $method = 'CART', |
|
107 | - $by_admin = false, |
|
108 | - $update_txn = true, |
|
109 | - $cancel_url = '' |
|
110 | - ) { |
|
111 | - if ((float)$amount < 0) { |
|
112 | - throw new EE_Error( |
|
113 | - sprintf( |
|
114 | - __( |
|
115 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
116 | - 'event_espresso' |
|
117 | - ), |
|
118 | - $amount, |
|
119 | - $transaction->ID() |
|
120 | - ) |
|
121 | - ); |
|
122 | - } |
|
123 | - // verify payment method |
|
124 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
125 | - $payment_method, |
|
126 | - true |
|
127 | - ); |
|
128 | - // verify transaction |
|
129 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
130 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
131 | - // verify payment method type |
|
132 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
133 | - $payment = $payment_method->type_obj()->process_payment( |
|
134 | - $transaction, |
|
135 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
136 | - $billing_form, |
|
137 | - $return_url, |
|
138 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
139 | - $method, |
|
140 | - $by_admin |
|
141 | - ); |
|
142 | - // check if payment method uses an off-site gateway |
|
143 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
144 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
145 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
146 | - } |
|
147 | - return $payment; |
|
148 | - } |
|
149 | - EE_Error::add_error( |
|
150 | - sprintf( |
|
151 | - __( |
|
152 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
153 | - 'event_espresso' |
|
154 | - ), |
|
155 | - '<br/>', |
|
156 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
157 | - ), |
|
158 | - __FILE__, |
|
159 | - __FUNCTION__, |
|
160 | - __LINE__ |
|
161 | - ); |
|
162 | - return null; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @param EE_Transaction|int $transaction |
|
169 | - * @param EE_Payment_Method $payment_method |
|
170 | - * @return string |
|
171 | - * @throws EE_Error |
|
172 | - * @throws InvalidArgumentException |
|
173 | - * @throws InvalidDataTypeException |
|
174 | - * @throws InvalidInterfaceException |
|
175 | - */ |
|
176 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
177 | - { |
|
178 | - /** @type \EE_Transaction $transaction */ |
|
179 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
180 | - $primary_reg = $transaction->primary_registration(); |
|
181 | - if (! $primary_reg instanceof EE_Registration) { |
|
182 | - throw new EE_Error( |
|
183 | - sprintf( |
|
184 | - __( |
|
185 | - 'Cannot get IPN URL for transaction with ID %d because it has no primary registration', |
|
186 | - 'event_espresso' |
|
187 | - ), |
|
188 | - $transaction->ID() |
|
189 | - ) |
|
190 | - ); |
|
191 | - } |
|
192 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
193 | - $payment_method, |
|
194 | - true |
|
195 | - ); |
|
196 | - $url = add_query_arg( |
|
197 | - array( |
|
198 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
199 | - 'ee_payment_method' => $payment_method->slug(), |
|
200 | - ), |
|
201 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
202 | - ); |
|
203 | - return $url; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
210 | - * we can easily find what registration the IPN is for and what payment method. |
|
211 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
212 | - * If a payment is found for the IPN info, it is saved. |
|
213 | - * |
|
214 | - * @param array $_req_data eg $_REQUEST |
|
215 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
216 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
217 | - * @param boolean $update_txn whether or not to call |
|
218 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
219 | - * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
220 | - * or is processed manually ( false like Mijireh ) |
|
221 | - * @throws EE_Error |
|
222 | - * @throws Exception |
|
223 | - * @return EE_Payment |
|
224 | - * @throws \RuntimeException |
|
225 | - * @throws \ReflectionException |
|
226 | - * @throws \InvalidArgumentException |
|
227 | - * @throws InvalidInterfaceException |
|
228 | - * @throws InvalidDataTypeException |
|
229 | - */ |
|
230 | - public function process_ipn( |
|
231 | - $_req_data, |
|
232 | - $transaction = null, |
|
233 | - $payment_method = null, |
|
234 | - $update_txn = true, |
|
235 | - $separate_IPN_request = true |
|
236 | - ) { |
|
237 | - EE_Registry::instance()->load_model('Change_Log'); |
|
238 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
239 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
240 | - $obj_for_log = null; |
|
241 | - if ($transaction instanceof EE_Transaction) { |
|
242 | - $obj_for_log = $transaction; |
|
243 | - if ($payment_method instanceof EE_Payment_Method) { |
|
244 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
245 | - array( |
|
246 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
247 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
248 | - ) |
|
249 | - ); |
|
250 | - } |
|
251 | - } elseif ($payment_method instanceof EE_Payment) { |
|
252 | - $obj_for_log = $payment_method; |
|
253 | - } |
|
254 | - $log = EEM_Change_Log::instance()->log( |
|
255 | - EEM_Change_Log::type_gateway, |
|
256 | - array('IPN data received' => $_req_data), |
|
257 | - $obj_for_log |
|
258 | - ); |
|
259 | - try { |
|
260 | - /** |
|
261 | - * @var EE_Payment $payment |
|
262 | - */ |
|
263 | - $payment = null; |
|
264 | - if ($transaction && $payment_method) { |
|
265 | - /** @type EE_Transaction $transaction */ |
|
266 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
267 | - /** @type EE_Payment_Method $payment_method */ |
|
268 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
269 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
270 | - try { |
|
271 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
272 | - $log->set_object($payment); |
|
273 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
274 | - EEM_Change_Log::instance()->log( |
|
275 | - EEM_Change_Log::type_gateway, |
|
276 | - array( |
|
277 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
278 | - 'current_url' => EEH_URL::current_url(), |
|
279 | - 'payment' => $e->getPaymentProperties(), |
|
280 | - 'IPN_data' => $e->getIpnData(), |
|
281 | - ), |
|
282 | - $obj_for_log |
|
283 | - ); |
|
284 | - return $e->getPayment(); |
|
285 | - } |
|
286 | - } else { |
|
287 | - // not a payment |
|
288 | - EE_Error::add_error( |
|
289 | - sprintf( |
|
290 | - __( |
|
291 | - 'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', |
|
292 | - 'event_espresso' |
|
293 | - ), |
|
294 | - '<br/>', |
|
295 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
296 | - ), |
|
297 | - __FILE__, |
|
298 | - __FUNCTION__, |
|
299 | - __LINE__ |
|
300 | - ); |
|
301 | - } |
|
302 | - } else { |
|
303 | - //that's actually pretty ok. The IPN just wasn't able |
|
304 | - //to identify which transaction or payment method this was for |
|
305 | - // give all active payment methods a chance to claim it |
|
306 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
307 | - foreach ($active_payment_methods as $active_payment_method) { |
|
308 | - try { |
|
309 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
310 | - $payment_method = $active_payment_method; |
|
311 | - EEM_Change_Log::instance()->log( |
|
312 | - EEM_Change_Log::type_gateway, |
|
313 | - array('IPN data' => $_req_data), |
|
314 | - $payment |
|
315 | - ); |
|
316 | - break; |
|
317 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
318 | - EEM_Change_Log::instance()->log( |
|
319 | - EEM_Change_Log::type_gateway, |
|
320 | - array( |
|
321 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
322 | - 'current_url' => EEH_URL::current_url(), |
|
323 | - 'payment' => $e->getPaymentProperties(), |
|
324 | - 'IPN_data' => $e->getIpnData(), |
|
325 | - ), |
|
326 | - $obj_for_log |
|
327 | - ); |
|
328 | - return $e->getPayment(); |
|
329 | - } catch (EE_Error $e) { |
|
330 | - // that's fine- it apparently couldn't handle the IPN |
|
331 | - } |
|
332 | - } |
|
333 | - } |
|
334 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
335 | - if ($payment instanceof EE_Payment) { |
|
336 | - $payment->save(); |
|
337 | - // update the TXN |
|
338 | - $this->update_txn_based_on_payment( |
|
339 | - $transaction, |
|
340 | - $payment, |
|
341 | - $update_txn, |
|
342 | - $separate_IPN_request |
|
343 | - ); |
|
344 | - } else { |
|
345 | - //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
346 | - if ($payment_method) { |
|
347 | - EEM_Change_Log::instance()->log( |
|
348 | - EEM_Change_Log::type_gateway, |
|
349 | - array('IPN data' => $_req_data), |
|
350 | - $payment_method |
|
351 | - ); |
|
352 | - } elseif ($transaction) { |
|
353 | - EEM_Change_Log::instance()->log( |
|
354 | - EEM_Change_Log::type_gateway, |
|
355 | - array('IPN data' => $_req_data), |
|
356 | - $transaction |
|
357 | - ); |
|
358 | - } |
|
359 | - } |
|
360 | - return $payment; |
|
361 | - } catch (EE_Error $e) { |
|
362 | - do_action( |
|
363 | - 'AHEE__log', |
|
364 | - __FILE__, |
|
365 | - __FUNCTION__, |
|
366 | - sprintf( |
|
367 | - __( |
|
368 | - 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', |
|
369 | - 'event_espresso' |
|
370 | - ), |
|
371 | - print_r($transaction, true), |
|
372 | - print_r($_req_data, true), |
|
373 | - $e->getMessage() |
|
374 | - ) |
|
375 | - ); |
|
376 | - throw $e; |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * Removes any non-printable illegal characters from the input, |
|
384 | - * which might cause a raucous when trying to insert into the database |
|
385 | - * |
|
386 | - * @param array $request_data |
|
387 | - * @return array |
|
388 | - */ |
|
389 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
390 | - { |
|
391 | - $return_data = array(); |
|
392 | - foreach ($request_data as $key => $value) { |
|
393 | - $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters( |
|
394 | - $value |
|
395 | - ); |
|
396 | - } |
|
397 | - return $return_data; |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * Removes any non-printable illegal characters from the input, |
|
404 | - * which might cause a raucous when trying to insert into the database |
|
405 | - * |
|
406 | - * @param string $request_data |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - protected function _remove_unusable_characters($request_data) |
|
410 | - { |
|
411 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * Should be called just before displaying the payment attempt results to the user, |
|
418 | - * when the payment attempt has finished. Some payment methods may have special |
|
419 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
420 | - * and then the user is redirected to a page that displays the payment's status, this |
|
421 | - * should be called while loading the page that displays the payment's status. If the user is |
|
422 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
423 | - * provider. |
|
424 | - * |
|
425 | - * @param EE_Transaction|int $transaction |
|
426 | - * @param bool $update_txn whether or not to call |
|
427 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
428 | - * @return EE_Payment |
|
429 | - * @throws EE_Error |
|
430 | - * @throws InvalidArgumentException |
|
431 | - * @throws ReflectionException |
|
432 | - * @throws RuntimeException |
|
433 | - * @throws InvalidDataTypeException |
|
434 | - * @throws InvalidInterfaceException |
|
435 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
436 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
437 | - */ |
|
438 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
439 | - { |
|
440 | - /** @var $transaction EE_Transaction */ |
|
441 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
442 | - $last_payment_method = $transaction->payment_method(); |
|
443 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
444 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
445 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
446 | - return $payment; |
|
447 | - } |
|
448 | - return null; |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
455 | - * |
|
456 | - * @param EE_Payment_Method $payment_method |
|
457 | - * @param EE_Payment $payment_to_refund |
|
458 | - * @param array $refund_info |
|
459 | - * @return EE_Payment |
|
460 | - * @throws EE_Error |
|
461 | - * @throws InvalidArgumentException |
|
462 | - * @throws ReflectionException |
|
463 | - * @throws RuntimeException |
|
464 | - * @throws InvalidDataTypeException |
|
465 | - * @throws InvalidInterfaceException |
|
466 | - */ |
|
467 | - public function process_refund( |
|
468 | - EE_Payment_Method $payment_method, |
|
469 | - EE_Payment $payment_to_refund, |
|
470 | - array $refund_info = array() |
|
471 | - ) { |
|
472 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
473 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
474 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
475 | - } |
|
476 | - return $payment_to_refund; |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * This should be called each time there may have been an update to a |
|
483 | - * payment on a transaction (ie, we asked for a payment to process a |
|
484 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
485 | - * we told a payment method to |
|
486 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
487 | - * process a refund. This should handle firing the correct hooks to |
|
488 | - * indicate |
|
489 | - * what exactly happened and updating the transaction appropriately). This |
|
490 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
491 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
492 | - * of transactions and payments, and to be tied to payment processing. |
|
493 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
494 | - * of previous code to decide whether or not to save (because the payment passed into |
|
495 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
496 | - * in which case we only want that payment object for some temporary usage during this request, |
|
497 | - * but we don't want it to be saved). |
|
498 | - * |
|
499 | - * @param EE_Transaction|int $transaction |
|
500 | - * @param EE_Payment $payment |
|
501 | - * @param boolean $update_txn |
|
502 | - * whether or not to call |
|
503 | - * EE_Transaction_Processor:: |
|
504 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
505 | - * (you can save 1 DB query if you know you're going |
|
506 | - * to save it later instead) |
|
507 | - * @param bool $IPN |
|
508 | - * if processing IPNs or other similar payment |
|
509 | - * related activities that occur in alternate |
|
510 | - * requests than the main one that is processing the |
|
511 | - * TXN, then set this to true to check whether the |
|
512 | - * TXN is locked before updating |
|
513 | - * @throws EE_Error |
|
514 | - * @throws InvalidArgumentException |
|
515 | - * @throws ReflectionException |
|
516 | - * @throws RuntimeException |
|
517 | - * @throws InvalidDataTypeException |
|
518 | - * @throws InvalidInterfaceException |
|
519 | - */ |
|
520 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
521 | - { |
|
522 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
523 | - /** @type EE_Transaction $transaction */ |
|
524 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
525 | - // can we freely update the TXN at this moment? |
|
526 | - if ($IPN && $transaction->is_locked()) { |
|
527 | - // don't update the transaction at this exact moment |
|
528 | - // because the TXN is active in another request |
|
529 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
530 | - time(), |
|
531 | - $transaction->ID(), |
|
532 | - $payment->ID() |
|
533 | - ); |
|
534 | - } else { |
|
535 | - // verify payment and that it has been saved |
|
536 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
537 | - if ( |
|
538 | - $payment->payment_method() instanceof EE_Payment_Method |
|
539 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
540 | - ) { |
|
541 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
542 | - // update TXN registrations with payment info |
|
543 | - $this->process_registration_payments($transaction, $payment); |
|
544 | - } |
|
545 | - $do_action = $payment->just_approved() |
|
546 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
547 | - : $do_action; |
|
548 | - } else { |
|
549 | - // send out notifications |
|
550 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
551 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
552 | - } |
|
553 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
554 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
555 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
556 | - // set new value for total paid |
|
557 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
558 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
559 | - if ($update_txn) { |
|
560 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
561 | - } |
|
562 | - } |
|
563 | - // granular hook for others to use. |
|
564 | - do_action($do_action, $transaction, $payment); |
|
565 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
566 | - //global hook for others to use. |
|
567 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
568 | - } |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
575 | - * |
|
576 | - * @param EE_Transaction $transaction |
|
577 | - * @param EE_Payment $payment |
|
578 | - * @param EE_Registration[] $registrations |
|
579 | - * @throws EE_Error |
|
580 | - * @throws InvalidArgumentException |
|
581 | - * @throws RuntimeException |
|
582 | - * @throws InvalidDataTypeException |
|
583 | - * @throws InvalidInterfaceException |
|
584 | - */ |
|
585 | - public function process_registration_payments( |
|
586 | - EE_Transaction $transaction, |
|
587 | - EE_Payment $payment, |
|
588 | - array $registrations = array() |
|
589 | - ) { |
|
590 | - // only process if payment was successful |
|
591 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
592 | - return; |
|
593 | - } |
|
594 | - //EEM_Registration::instance()->show_next_x_db_queries(); |
|
595 | - if (empty($registrations)) { |
|
596 | - // find registrations with monies owing that can receive a payment |
|
597 | - $registrations = $transaction->registrations( |
|
598 | - array( |
|
599 | - array( |
|
600 | - // only these reg statuses can receive payments |
|
601 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
602 | - 'REG_final_price' => array('!=', 0), |
|
603 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
604 | - ), |
|
605 | - ) |
|
606 | - ); |
|
607 | - } |
|
608 | - // still nothing ??!?? |
|
609 | - if (empty($registrations)) { |
|
610 | - return; |
|
611 | - } |
|
612 | - // todo: break out the following logic into a separate strategy class |
|
613 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
614 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
615 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
616 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
617 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
618 | - $refund = $payment->is_a_refund(); |
|
619 | - // how much is available to apply to registrations? |
|
620 | - $available_payment_amount = abs($payment->amount()); |
|
621 | - foreach ($registrations as $registration) { |
|
622 | - if ($registration instanceof EE_Registration) { |
|
623 | - // nothing left? |
|
624 | - if ($available_payment_amount <= 0) { |
|
625 | - break; |
|
626 | - } |
|
627 | - if ($refund) { |
|
628 | - $available_payment_amount = $this->process_registration_refund( |
|
629 | - $registration, |
|
630 | - $payment, |
|
631 | - $available_payment_amount |
|
632 | - ); |
|
633 | - } else { |
|
634 | - $available_payment_amount = $this->process_registration_payment( |
|
635 | - $registration, |
|
636 | - $payment, |
|
637 | - $available_payment_amount |
|
638 | - ); |
|
639 | - } |
|
640 | - } |
|
641 | - } |
|
642 | - if ($available_payment_amount > 0 |
|
643 | - && apply_filters( |
|
644 | - 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', |
|
645 | - false |
|
646 | - )) { |
|
647 | - EE_Error::add_attention( |
|
648 | - sprintf( |
|
649 | - __( |
|
650 | - 'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
651 | - 'event_espresso' |
|
652 | - ), |
|
653 | - EEH_Template::format_currency($available_payment_amount), |
|
654 | - implode(', ', array_keys($registrations)), |
|
655 | - '<br/>', |
|
656 | - EEH_Template::format_currency($payment->amount()) |
|
657 | - ), |
|
658 | - __FILE__, |
|
659 | - __FUNCTION__, |
|
660 | - __LINE__ |
|
661 | - ); |
|
662 | - } |
|
663 | - } |
|
664 | - |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * update registration REG_paid field after successful payment and link registration with payment |
|
669 | - * |
|
670 | - * @param EE_Registration $registration |
|
671 | - * @param EE_Payment $payment |
|
672 | - * @param float $available_payment_amount |
|
673 | - * @return float |
|
674 | - * @throws EE_Error |
|
675 | - * @throws InvalidArgumentException |
|
676 | - * @throws RuntimeException |
|
677 | - * @throws InvalidDataTypeException |
|
678 | - * @throws InvalidInterfaceException |
|
679 | - */ |
|
680 | - public function process_registration_payment( |
|
681 | - EE_Registration $registration, |
|
682 | - EE_Payment $payment, |
|
683 | - $available_payment_amount = 0.00 |
|
684 | - ) { |
|
685 | - $owing = $registration->final_price() - $registration->paid(); |
|
686 | - if ($owing > 0) { |
|
687 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
688 | - $payment_amount = min($available_payment_amount, $owing); |
|
689 | - // update $available_payment_amount |
|
690 | - $available_payment_amount -= $payment_amount; |
|
691 | - //calculate and set new REG_paid |
|
692 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
693 | - // now save it |
|
694 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
695 | - } |
|
696 | - return $available_payment_amount; |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * update registration REG_paid field after successful payment and link registration with payment |
|
703 | - * |
|
704 | - * @param EE_Registration $registration |
|
705 | - * @param EE_Payment $payment |
|
706 | - * @param float $payment_amount |
|
707 | - * @return void |
|
708 | - * @throws EE_Error |
|
709 | - * @throws InvalidArgumentException |
|
710 | - * @throws InvalidDataTypeException |
|
711 | - * @throws InvalidInterfaceException |
|
712 | - */ |
|
713 | - protected function _apply_registration_payment( |
|
714 | - EE_Registration $registration, |
|
715 | - EE_Payment $payment, |
|
716 | - $payment_amount = 0.00 |
|
717 | - ) { |
|
718 | - // find any existing reg payment records for this registration and payment |
|
719 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
720 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
721 | - ); |
|
722 | - // if existing registration payment exists |
|
723 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
724 | - // then update that record |
|
725 | - $existing_reg_payment->set_amount($payment_amount); |
|
726 | - $existing_reg_payment->save(); |
|
727 | - } else { |
|
728 | - // or add new relation between registration and payment and set amount |
|
729 | - $registration->_add_relation_to( |
|
730 | - $payment, |
|
731 | - 'Payment', |
|
732 | - array('RPY_amount' => $payment_amount) |
|
733 | - ); |
|
734 | - // make it stick |
|
735 | - $registration->save(); |
|
736 | - } |
|
737 | - } |
|
738 | - |
|
739 | - |
|
740 | - |
|
741 | - /** |
|
742 | - * update registration REG_paid field after refund and link registration with payment |
|
743 | - * |
|
744 | - * @param EE_Registration $registration |
|
745 | - * @param EE_Payment $payment |
|
746 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
747 | - * @return float |
|
748 | - * @throws EE_Error |
|
749 | - * @throws InvalidArgumentException |
|
750 | - * @throws RuntimeException |
|
751 | - * @throws InvalidDataTypeException |
|
752 | - * @throws InvalidInterfaceException |
|
753 | - */ |
|
754 | - public function process_registration_refund( |
|
755 | - EE_Registration $registration, |
|
756 | - EE_Payment $payment, |
|
757 | - $available_refund_amount = 0.00 |
|
758 | - ) { |
|
759 | - //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
760 | - if ($registration->paid() > 0) { |
|
761 | - // ensure $available_refund_amount is NOT negative |
|
762 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
763 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
764 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
765 | - // update $available_payment_amount |
|
766 | - $available_refund_amount -= $refund_amount; |
|
767 | - //calculate and set new REG_paid |
|
768 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
769 | - // convert payment amount back to a negative value for storage in the db |
|
770 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
771 | - // now save it |
|
772 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
773 | - } |
|
774 | - return $available_refund_amount; |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - |
|
779 | - /** |
|
780 | - * Process payments and transaction after payment process completed. |
|
781 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
782 | - * if this request happens to be processing an IPN, |
|
783 | - * then we will also set the Payment Options Reg Step to completed, |
|
784 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
785 | - * |
|
786 | - * @param EE_Transaction $transaction |
|
787 | - * @param EE_Payment $payment |
|
788 | - * @param bool $IPN |
|
789 | - * @throws EE_Error |
|
790 | - * @throws InvalidArgumentException |
|
791 | - * @throws ReflectionException |
|
792 | - * @throws RuntimeException |
|
793 | - * @throws InvalidDataTypeException |
|
794 | - * @throws InvalidInterfaceException |
|
795 | - */ |
|
796 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
797 | - { |
|
798 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
799 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
800 | - // is the Payment Options Reg Step completed ? |
|
801 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
802 | - // if the Payment Options Reg Step is completed... |
|
803 | - $revisit = $payment_options_step_completed === true; |
|
804 | - // then this is kinda sorta a revisit with regards to payments at least |
|
805 | - $transaction_processor->set_revisit($revisit); |
|
806 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
807 | - if ( |
|
808 | - $IPN |
|
809 | - && $payment_options_step_completed !== true |
|
810 | - && ($payment->is_approved() || $payment->is_pending()) |
|
811 | - ) { |
|
812 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
813 | - 'payment_options' |
|
814 | - ); |
|
815 | - } |
|
816 | - // maybe update status, but don't save transaction just yet |
|
817 | - $transaction->update_status_based_on_total_paid(false); |
|
818 | - // check if 'finalize_registration' step has been completed... |
|
819 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
820 | - // if this is an IPN and the final step has not been initiated |
|
821 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
822 | - // and if it hasn't already been set as being started... |
|
823 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
824 | - } |
|
825 | - $transaction->save(); |
|
826 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
827 | - if ($IPN && $finalized !== false) { |
|
828 | - // and if we are all good to go, then send out notifications |
|
829 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
830 | - //ok, now process the transaction according to the payment |
|
831 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
832 | - $transaction, |
|
833 | - $payment |
|
834 | - ); |
|
835 | - } |
|
836 | - // DEBUG LOG |
|
837 | - $payment_method = $payment->payment_method(); |
|
838 | - if ($payment_method instanceof EE_Payment_Method) { |
|
839 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
840 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
841 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
842 | - if ($gateway instanceof EE_Gateway) { |
|
843 | - $gateway->log( |
|
844 | - array( |
|
845 | - 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
846 | - 'transaction' => $transaction->model_field_array(), |
|
847 | - 'finalized' => $finalized, |
|
848 | - 'IPN' => $IPN, |
|
849 | - 'deliver_notifications' => has_filter( |
|
850 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
851 | - ), |
|
852 | - ), |
|
853 | - $payment |
|
854 | - ); |
|
855 | - } |
|
856 | - } |
|
857 | - } |
|
858 | - } |
|
859 | - |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * Force posts to PayPal to use TLS v1.2. See: |
|
864 | - * https://core.trac.wordpress.org/ticket/36320 |
|
865 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
866 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
867 | - * This will affect PayPal standard, pro, express, and Payflow. |
|
868 | - * |
|
869 | - * @param $handle |
|
870 | - * @param $r |
|
871 | - * @param $url |
|
872 | - */ |
|
873 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
874 | - { |
|
875 | - if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) { |
|
876 | - //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
877 | - //instead of the constant because it might not be defined |
|
878 | - curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
879 | - } |
|
880 | - } |
|
24 | + /** |
|
25 | + * @var EE_Payment_Processor $_instance |
|
26 | + * @access private |
|
27 | + */ |
|
28 | + private static $_instance; |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @singleton method used to instantiate class object |
|
34 | + * @access public |
|
35 | + * @return EE_Payment_Processor instance |
|
36 | + */ |
|
37 | + public static function instance() |
|
38 | + { |
|
39 | + // check if class object is instantiated |
|
40 | + if (! self::$_instance instanceof EE_Payment_Processor) { |
|
41 | + self::$_instance = new self(); |
|
42 | + } |
|
43 | + return self::$_instance; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @return EE_Payment_Processor |
|
50 | + */ |
|
51 | + public static function reset() |
|
52 | + { |
|
53 | + self::$_instance = null; |
|
54 | + return self::instance(); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + *private constructor to prevent direct creation |
|
61 | + * |
|
62 | + * @Constructor |
|
63 | + * @access private |
|
64 | + */ |
|
65 | + private function __construct() |
|
66 | + { |
|
67 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
68 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
75 | + * appropriately. Saves the payment that is generated |
|
76 | + * |
|
77 | + * @param EE_Payment_Method $payment_method |
|
78 | + * @param EE_Transaction $transaction |
|
79 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
80 | + * Leave null if payment is for the full amount owing |
|
81 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
82 | + * Receive_form_submission() should have |
|
83 | + * already been called on the billing form |
|
84 | + * (ie, its inputs should have their normalized values set). |
|
85 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
86 | + * where to go AFTER the offsite gateway |
|
87 | + * @param string $method like 'CART', indicates who the client who called this was |
|
88 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
89 | + * @param boolean $update_txn whether or not to call |
|
90 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
91 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
92 | + * @return EE_Payment |
|
93 | + * @throws EE_Error |
|
94 | + * @throws InvalidArgumentException |
|
95 | + * @throws ReflectionException |
|
96 | + * @throws RuntimeException |
|
97 | + * @throws InvalidDataTypeException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + */ |
|
100 | + public function process_payment( |
|
101 | + EE_Payment_Method $payment_method, |
|
102 | + EE_Transaction $transaction, |
|
103 | + $amount = null, |
|
104 | + $billing_form = null, |
|
105 | + $return_url = null, |
|
106 | + $method = 'CART', |
|
107 | + $by_admin = false, |
|
108 | + $update_txn = true, |
|
109 | + $cancel_url = '' |
|
110 | + ) { |
|
111 | + if ((float)$amount < 0) { |
|
112 | + throw new EE_Error( |
|
113 | + sprintf( |
|
114 | + __( |
|
115 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
116 | + 'event_espresso' |
|
117 | + ), |
|
118 | + $amount, |
|
119 | + $transaction->ID() |
|
120 | + ) |
|
121 | + ); |
|
122 | + } |
|
123 | + // verify payment method |
|
124 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
125 | + $payment_method, |
|
126 | + true |
|
127 | + ); |
|
128 | + // verify transaction |
|
129 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
130 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
131 | + // verify payment method type |
|
132 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
133 | + $payment = $payment_method->type_obj()->process_payment( |
|
134 | + $transaction, |
|
135 | + min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
136 | + $billing_form, |
|
137 | + $return_url, |
|
138 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
139 | + $method, |
|
140 | + $by_admin |
|
141 | + ); |
|
142 | + // check if payment method uses an off-site gateway |
|
143 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
144 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
145 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
146 | + } |
|
147 | + return $payment; |
|
148 | + } |
|
149 | + EE_Error::add_error( |
|
150 | + sprintf( |
|
151 | + __( |
|
152 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
153 | + 'event_espresso' |
|
154 | + ), |
|
155 | + '<br/>', |
|
156 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
157 | + ), |
|
158 | + __FILE__, |
|
159 | + __FUNCTION__, |
|
160 | + __LINE__ |
|
161 | + ); |
|
162 | + return null; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @param EE_Transaction|int $transaction |
|
169 | + * @param EE_Payment_Method $payment_method |
|
170 | + * @return string |
|
171 | + * @throws EE_Error |
|
172 | + * @throws InvalidArgumentException |
|
173 | + * @throws InvalidDataTypeException |
|
174 | + * @throws InvalidInterfaceException |
|
175 | + */ |
|
176 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
177 | + { |
|
178 | + /** @type \EE_Transaction $transaction */ |
|
179 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
180 | + $primary_reg = $transaction->primary_registration(); |
|
181 | + if (! $primary_reg instanceof EE_Registration) { |
|
182 | + throw new EE_Error( |
|
183 | + sprintf( |
|
184 | + __( |
|
185 | + 'Cannot get IPN URL for transaction with ID %d because it has no primary registration', |
|
186 | + 'event_espresso' |
|
187 | + ), |
|
188 | + $transaction->ID() |
|
189 | + ) |
|
190 | + ); |
|
191 | + } |
|
192 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
193 | + $payment_method, |
|
194 | + true |
|
195 | + ); |
|
196 | + $url = add_query_arg( |
|
197 | + array( |
|
198 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
199 | + 'ee_payment_method' => $payment_method->slug(), |
|
200 | + ), |
|
201 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
202 | + ); |
|
203 | + return $url; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
210 | + * we can easily find what registration the IPN is for and what payment method. |
|
211 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
212 | + * If a payment is found for the IPN info, it is saved. |
|
213 | + * |
|
214 | + * @param array $_req_data eg $_REQUEST |
|
215 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
216 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
217 | + * @param boolean $update_txn whether or not to call |
|
218 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
219 | + * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
220 | + * or is processed manually ( false like Mijireh ) |
|
221 | + * @throws EE_Error |
|
222 | + * @throws Exception |
|
223 | + * @return EE_Payment |
|
224 | + * @throws \RuntimeException |
|
225 | + * @throws \ReflectionException |
|
226 | + * @throws \InvalidArgumentException |
|
227 | + * @throws InvalidInterfaceException |
|
228 | + * @throws InvalidDataTypeException |
|
229 | + */ |
|
230 | + public function process_ipn( |
|
231 | + $_req_data, |
|
232 | + $transaction = null, |
|
233 | + $payment_method = null, |
|
234 | + $update_txn = true, |
|
235 | + $separate_IPN_request = true |
|
236 | + ) { |
|
237 | + EE_Registry::instance()->load_model('Change_Log'); |
|
238 | + $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
239 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
240 | + $obj_for_log = null; |
|
241 | + if ($transaction instanceof EE_Transaction) { |
|
242 | + $obj_for_log = $transaction; |
|
243 | + if ($payment_method instanceof EE_Payment_Method) { |
|
244 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
245 | + array( |
|
246 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
247 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
248 | + ) |
|
249 | + ); |
|
250 | + } |
|
251 | + } elseif ($payment_method instanceof EE_Payment) { |
|
252 | + $obj_for_log = $payment_method; |
|
253 | + } |
|
254 | + $log = EEM_Change_Log::instance()->log( |
|
255 | + EEM_Change_Log::type_gateway, |
|
256 | + array('IPN data received' => $_req_data), |
|
257 | + $obj_for_log |
|
258 | + ); |
|
259 | + try { |
|
260 | + /** |
|
261 | + * @var EE_Payment $payment |
|
262 | + */ |
|
263 | + $payment = null; |
|
264 | + if ($transaction && $payment_method) { |
|
265 | + /** @type EE_Transaction $transaction */ |
|
266 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
267 | + /** @type EE_Payment_Method $payment_method */ |
|
268 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
269 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
270 | + try { |
|
271 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
272 | + $log->set_object($payment); |
|
273 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
274 | + EEM_Change_Log::instance()->log( |
|
275 | + EEM_Change_Log::type_gateway, |
|
276 | + array( |
|
277 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
278 | + 'current_url' => EEH_URL::current_url(), |
|
279 | + 'payment' => $e->getPaymentProperties(), |
|
280 | + 'IPN_data' => $e->getIpnData(), |
|
281 | + ), |
|
282 | + $obj_for_log |
|
283 | + ); |
|
284 | + return $e->getPayment(); |
|
285 | + } |
|
286 | + } else { |
|
287 | + // not a payment |
|
288 | + EE_Error::add_error( |
|
289 | + sprintf( |
|
290 | + __( |
|
291 | + 'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', |
|
292 | + 'event_espresso' |
|
293 | + ), |
|
294 | + '<br/>', |
|
295 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
296 | + ), |
|
297 | + __FILE__, |
|
298 | + __FUNCTION__, |
|
299 | + __LINE__ |
|
300 | + ); |
|
301 | + } |
|
302 | + } else { |
|
303 | + //that's actually pretty ok. The IPN just wasn't able |
|
304 | + //to identify which transaction or payment method this was for |
|
305 | + // give all active payment methods a chance to claim it |
|
306 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
307 | + foreach ($active_payment_methods as $active_payment_method) { |
|
308 | + try { |
|
309 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
310 | + $payment_method = $active_payment_method; |
|
311 | + EEM_Change_Log::instance()->log( |
|
312 | + EEM_Change_Log::type_gateway, |
|
313 | + array('IPN data' => $_req_data), |
|
314 | + $payment |
|
315 | + ); |
|
316 | + break; |
|
317 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
318 | + EEM_Change_Log::instance()->log( |
|
319 | + EEM_Change_Log::type_gateway, |
|
320 | + array( |
|
321 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
322 | + 'current_url' => EEH_URL::current_url(), |
|
323 | + 'payment' => $e->getPaymentProperties(), |
|
324 | + 'IPN_data' => $e->getIpnData(), |
|
325 | + ), |
|
326 | + $obj_for_log |
|
327 | + ); |
|
328 | + return $e->getPayment(); |
|
329 | + } catch (EE_Error $e) { |
|
330 | + // that's fine- it apparently couldn't handle the IPN |
|
331 | + } |
|
332 | + } |
|
333 | + } |
|
334 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
335 | + if ($payment instanceof EE_Payment) { |
|
336 | + $payment->save(); |
|
337 | + // update the TXN |
|
338 | + $this->update_txn_based_on_payment( |
|
339 | + $transaction, |
|
340 | + $payment, |
|
341 | + $update_txn, |
|
342 | + $separate_IPN_request |
|
343 | + ); |
|
344 | + } else { |
|
345 | + //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
346 | + if ($payment_method) { |
|
347 | + EEM_Change_Log::instance()->log( |
|
348 | + EEM_Change_Log::type_gateway, |
|
349 | + array('IPN data' => $_req_data), |
|
350 | + $payment_method |
|
351 | + ); |
|
352 | + } elseif ($transaction) { |
|
353 | + EEM_Change_Log::instance()->log( |
|
354 | + EEM_Change_Log::type_gateway, |
|
355 | + array('IPN data' => $_req_data), |
|
356 | + $transaction |
|
357 | + ); |
|
358 | + } |
|
359 | + } |
|
360 | + return $payment; |
|
361 | + } catch (EE_Error $e) { |
|
362 | + do_action( |
|
363 | + 'AHEE__log', |
|
364 | + __FILE__, |
|
365 | + __FUNCTION__, |
|
366 | + sprintf( |
|
367 | + __( |
|
368 | + 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', |
|
369 | + 'event_espresso' |
|
370 | + ), |
|
371 | + print_r($transaction, true), |
|
372 | + print_r($_req_data, true), |
|
373 | + $e->getMessage() |
|
374 | + ) |
|
375 | + ); |
|
376 | + throw $e; |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * Removes any non-printable illegal characters from the input, |
|
384 | + * which might cause a raucous when trying to insert into the database |
|
385 | + * |
|
386 | + * @param array $request_data |
|
387 | + * @return array |
|
388 | + */ |
|
389 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
390 | + { |
|
391 | + $return_data = array(); |
|
392 | + foreach ($request_data as $key => $value) { |
|
393 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters( |
|
394 | + $value |
|
395 | + ); |
|
396 | + } |
|
397 | + return $return_data; |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * Removes any non-printable illegal characters from the input, |
|
404 | + * which might cause a raucous when trying to insert into the database |
|
405 | + * |
|
406 | + * @param string $request_data |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + protected function _remove_unusable_characters($request_data) |
|
410 | + { |
|
411 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * Should be called just before displaying the payment attempt results to the user, |
|
418 | + * when the payment attempt has finished. Some payment methods may have special |
|
419 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
420 | + * and then the user is redirected to a page that displays the payment's status, this |
|
421 | + * should be called while loading the page that displays the payment's status. If the user is |
|
422 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
423 | + * provider. |
|
424 | + * |
|
425 | + * @param EE_Transaction|int $transaction |
|
426 | + * @param bool $update_txn whether or not to call |
|
427 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
428 | + * @return EE_Payment |
|
429 | + * @throws EE_Error |
|
430 | + * @throws InvalidArgumentException |
|
431 | + * @throws ReflectionException |
|
432 | + * @throws RuntimeException |
|
433 | + * @throws InvalidDataTypeException |
|
434 | + * @throws InvalidInterfaceException |
|
435 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
436 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
437 | + */ |
|
438 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
439 | + { |
|
440 | + /** @var $transaction EE_Transaction */ |
|
441 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
442 | + $last_payment_method = $transaction->payment_method(); |
|
443 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
444 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
445 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
446 | + return $payment; |
|
447 | + } |
|
448 | + return null; |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
455 | + * |
|
456 | + * @param EE_Payment_Method $payment_method |
|
457 | + * @param EE_Payment $payment_to_refund |
|
458 | + * @param array $refund_info |
|
459 | + * @return EE_Payment |
|
460 | + * @throws EE_Error |
|
461 | + * @throws InvalidArgumentException |
|
462 | + * @throws ReflectionException |
|
463 | + * @throws RuntimeException |
|
464 | + * @throws InvalidDataTypeException |
|
465 | + * @throws InvalidInterfaceException |
|
466 | + */ |
|
467 | + public function process_refund( |
|
468 | + EE_Payment_Method $payment_method, |
|
469 | + EE_Payment $payment_to_refund, |
|
470 | + array $refund_info = array() |
|
471 | + ) { |
|
472 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
473 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
474 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
475 | + } |
|
476 | + return $payment_to_refund; |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * This should be called each time there may have been an update to a |
|
483 | + * payment on a transaction (ie, we asked for a payment to process a |
|
484 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
485 | + * we told a payment method to |
|
486 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
487 | + * process a refund. This should handle firing the correct hooks to |
|
488 | + * indicate |
|
489 | + * what exactly happened and updating the transaction appropriately). This |
|
490 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
491 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
492 | + * of transactions and payments, and to be tied to payment processing. |
|
493 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
494 | + * of previous code to decide whether or not to save (because the payment passed into |
|
495 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
496 | + * in which case we only want that payment object for some temporary usage during this request, |
|
497 | + * but we don't want it to be saved). |
|
498 | + * |
|
499 | + * @param EE_Transaction|int $transaction |
|
500 | + * @param EE_Payment $payment |
|
501 | + * @param boolean $update_txn |
|
502 | + * whether or not to call |
|
503 | + * EE_Transaction_Processor:: |
|
504 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
505 | + * (you can save 1 DB query if you know you're going |
|
506 | + * to save it later instead) |
|
507 | + * @param bool $IPN |
|
508 | + * if processing IPNs or other similar payment |
|
509 | + * related activities that occur in alternate |
|
510 | + * requests than the main one that is processing the |
|
511 | + * TXN, then set this to true to check whether the |
|
512 | + * TXN is locked before updating |
|
513 | + * @throws EE_Error |
|
514 | + * @throws InvalidArgumentException |
|
515 | + * @throws ReflectionException |
|
516 | + * @throws RuntimeException |
|
517 | + * @throws InvalidDataTypeException |
|
518 | + * @throws InvalidInterfaceException |
|
519 | + */ |
|
520 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
521 | + { |
|
522 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
523 | + /** @type EE_Transaction $transaction */ |
|
524 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
525 | + // can we freely update the TXN at this moment? |
|
526 | + if ($IPN && $transaction->is_locked()) { |
|
527 | + // don't update the transaction at this exact moment |
|
528 | + // because the TXN is active in another request |
|
529 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
530 | + time(), |
|
531 | + $transaction->ID(), |
|
532 | + $payment->ID() |
|
533 | + ); |
|
534 | + } else { |
|
535 | + // verify payment and that it has been saved |
|
536 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
537 | + if ( |
|
538 | + $payment->payment_method() instanceof EE_Payment_Method |
|
539 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
540 | + ) { |
|
541 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
542 | + // update TXN registrations with payment info |
|
543 | + $this->process_registration_payments($transaction, $payment); |
|
544 | + } |
|
545 | + $do_action = $payment->just_approved() |
|
546 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
547 | + : $do_action; |
|
548 | + } else { |
|
549 | + // send out notifications |
|
550 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
551 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
552 | + } |
|
553 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
554 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
555 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
556 | + // set new value for total paid |
|
557 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
558 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
559 | + if ($update_txn) { |
|
560 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
561 | + } |
|
562 | + } |
|
563 | + // granular hook for others to use. |
|
564 | + do_action($do_action, $transaction, $payment); |
|
565 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
566 | + //global hook for others to use. |
|
567 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
568 | + } |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
575 | + * |
|
576 | + * @param EE_Transaction $transaction |
|
577 | + * @param EE_Payment $payment |
|
578 | + * @param EE_Registration[] $registrations |
|
579 | + * @throws EE_Error |
|
580 | + * @throws InvalidArgumentException |
|
581 | + * @throws RuntimeException |
|
582 | + * @throws InvalidDataTypeException |
|
583 | + * @throws InvalidInterfaceException |
|
584 | + */ |
|
585 | + public function process_registration_payments( |
|
586 | + EE_Transaction $transaction, |
|
587 | + EE_Payment $payment, |
|
588 | + array $registrations = array() |
|
589 | + ) { |
|
590 | + // only process if payment was successful |
|
591 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
592 | + return; |
|
593 | + } |
|
594 | + //EEM_Registration::instance()->show_next_x_db_queries(); |
|
595 | + if (empty($registrations)) { |
|
596 | + // find registrations with monies owing that can receive a payment |
|
597 | + $registrations = $transaction->registrations( |
|
598 | + array( |
|
599 | + array( |
|
600 | + // only these reg statuses can receive payments |
|
601 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
602 | + 'REG_final_price' => array('!=', 0), |
|
603 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
604 | + ), |
|
605 | + ) |
|
606 | + ); |
|
607 | + } |
|
608 | + // still nothing ??!?? |
|
609 | + if (empty($registrations)) { |
|
610 | + return; |
|
611 | + } |
|
612 | + // todo: break out the following logic into a separate strategy class |
|
613 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
614 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
615 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
616 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
617 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
618 | + $refund = $payment->is_a_refund(); |
|
619 | + // how much is available to apply to registrations? |
|
620 | + $available_payment_amount = abs($payment->amount()); |
|
621 | + foreach ($registrations as $registration) { |
|
622 | + if ($registration instanceof EE_Registration) { |
|
623 | + // nothing left? |
|
624 | + if ($available_payment_amount <= 0) { |
|
625 | + break; |
|
626 | + } |
|
627 | + if ($refund) { |
|
628 | + $available_payment_amount = $this->process_registration_refund( |
|
629 | + $registration, |
|
630 | + $payment, |
|
631 | + $available_payment_amount |
|
632 | + ); |
|
633 | + } else { |
|
634 | + $available_payment_amount = $this->process_registration_payment( |
|
635 | + $registration, |
|
636 | + $payment, |
|
637 | + $available_payment_amount |
|
638 | + ); |
|
639 | + } |
|
640 | + } |
|
641 | + } |
|
642 | + if ($available_payment_amount > 0 |
|
643 | + && apply_filters( |
|
644 | + 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', |
|
645 | + false |
|
646 | + )) { |
|
647 | + EE_Error::add_attention( |
|
648 | + sprintf( |
|
649 | + __( |
|
650 | + 'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
651 | + 'event_espresso' |
|
652 | + ), |
|
653 | + EEH_Template::format_currency($available_payment_amount), |
|
654 | + implode(', ', array_keys($registrations)), |
|
655 | + '<br/>', |
|
656 | + EEH_Template::format_currency($payment->amount()) |
|
657 | + ), |
|
658 | + __FILE__, |
|
659 | + __FUNCTION__, |
|
660 | + __LINE__ |
|
661 | + ); |
|
662 | + } |
|
663 | + } |
|
664 | + |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * update registration REG_paid field after successful payment and link registration with payment |
|
669 | + * |
|
670 | + * @param EE_Registration $registration |
|
671 | + * @param EE_Payment $payment |
|
672 | + * @param float $available_payment_amount |
|
673 | + * @return float |
|
674 | + * @throws EE_Error |
|
675 | + * @throws InvalidArgumentException |
|
676 | + * @throws RuntimeException |
|
677 | + * @throws InvalidDataTypeException |
|
678 | + * @throws InvalidInterfaceException |
|
679 | + */ |
|
680 | + public function process_registration_payment( |
|
681 | + EE_Registration $registration, |
|
682 | + EE_Payment $payment, |
|
683 | + $available_payment_amount = 0.00 |
|
684 | + ) { |
|
685 | + $owing = $registration->final_price() - $registration->paid(); |
|
686 | + if ($owing > 0) { |
|
687 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
688 | + $payment_amount = min($available_payment_amount, $owing); |
|
689 | + // update $available_payment_amount |
|
690 | + $available_payment_amount -= $payment_amount; |
|
691 | + //calculate and set new REG_paid |
|
692 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
693 | + // now save it |
|
694 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
695 | + } |
|
696 | + return $available_payment_amount; |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * update registration REG_paid field after successful payment and link registration with payment |
|
703 | + * |
|
704 | + * @param EE_Registration $registration |
|
705 | + * @param EE_Payment $payment |
|
706 | + * @param float $payment_amount |
|
707 | + * @return void |
|
708 | + * @throws EE_Error |
|
709 | + * @throws InvalidArgumentException |
|
710 | + * @throws InvalidDataTypeException |
|
711 | + * @throws InvalidInterfaceException |
|
712 | + */ |
|
713 | + protected function _apply_registration_payment( |
|
714 | + EE_Registration $registration, |
|
715 | + EE_Payment $payment, |
|
716 | + $payment_amount = 0.00 |
|
717 | + ) { |
|
718 | + // find any existing reg payment records for this registration and payment |
|
719 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
720 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
721 | + ); |
|
722 | + // if existing registration payment exists |
|
723 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
724 | + // then update that record |
|
725 | + $existing_reg_payment->set_amount($payment_amount); |
|
726 | + $existing_reg_payment->save(); |
|
727 | + } else { |
|
728 | + // or add new relation between registration and payment and set amount |
|
729 | + $registration->_add_relation_to( |
|
730 | + $payment, |
|
731 | + 'Payment', |
|
732 | + array('RPY_amount' => $payment_amount) |
|
733 | + ); |
|
734 | + // make it stick |
|
735 | + $registration->save(); |
|
736 | + } |
|
737 | + } |
|
738 | + |
|
739 | + |
|
740 | + |
|
741 | + /** |
|
742 | + * update registration REG_paid field after refund and link registration with payment |
|
743 | + * |
|
744 | + * @param EE_Registration $registration |
|
745 | + * @param EE_Payment $payment |
|
746 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
747 | + * @return float |
|
748 | + * @throws EE_Error |
|
749 | + * @throws InvalidArgumentException |
|
750 | + * @throws RuntimeException |
|
751 | + * @throws InvalidDataTypeException |
|
752 | + * @throws InvalidInterfaceException |
|
753 | + */ |
|
754 | + public function process_registration_refund( |
|
755 | + EE_Registration $registration, |
|
756 | + EE_Payment $payment, |
|
757 | + $available_refund_amount = 0.00 |
|
758 | + ) { |
|
759 | + //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
760 | + if ($registration->paid() > 0) { |
|
761 | + // ensure $available_refund_amount is NOT negative |
|
762 | + $available_refund_amount = (float)abs($available_refund_amount); |
|
763 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
764 | + $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
765 | + // update $available_payment_amount |
|
766 | + $available_refund_amount -= $refund_amount; |
|
767 | + //calculate and set new REG_paid |
|
768 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
769 | + // convert payment amount back to a negative value for storage in the db |
|
770 | + $refund_amount = (float)abs($refund_amount) * -1; |
|
771 | + // now save it |
|
772 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
773 | + } |
|
774 | + return $available_refund_amount; |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + |
|
779 | + /** |
|
780 | + * Process payments and transaction after payment process completed. |
|
781 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
782 | + * if this request happens to be processing an IPN, |
|
783 | + * then we will also set the Payment Options Reg Step to completed, |
|
784 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
785 | + * |
|
786 | + * @param EE_Transaction $transaction |
|
787 | + * @param EE_Payment $payment |
|
788 | + * @param bool $IPN |
|
789 | + * @throws EE_Error |
|
790 | + * @throws InvalidArgumentException |
|
791 | + * @throws ReflectionException |
|
792 | + * @throws RuntimeException |
|
793 | + * @throws InvalidDataTypeException |
|
794 | + * @throws InvalidInterfaceException |
|
795 | + */ |
|
796 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
797 | + { |
|
798 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
799 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
800 | + // is the Payment Options Reg Step completed ? |
|
801 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
802 | + // if the Payment Options Reg Step is completed... |
|
803 | + $revisit = $payment_options_step_completed === true; |
|
804 | + // then this is kinda sorta a revisit with regards to payments at least |
|
805 | + $transaction_processor->set_revisit($revisit); |
|
806 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
807 | + if ( |
|
808 | + $IPN |
|
809 | + && $payment_options_step_completed !== true |
|
810 | + && ($payment->is_approved() || $payment->is_pending()) |
|
811 | + ) { |
|
812 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
813 | + 'payment_options' |
|
814 | + ); |
|
815 | + } |
|
816 | + // maybe update status, but don't save transaction just yet |
|
817 | + $transaction->update_status_based_on_total_paid(false); |
|
818 | + // check if 'finalize_registration' step has been completed... |
|
819 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
820 | + // if this is an IPN and the final step has not been initiated |
|
821 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
822 | + // and if it hasn't already been set as being started... |
|
823 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
824 | + } |
|
825 | + $transaction->save(); |
|
826 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
827 | + if ($IPN && $finalized !== false) { |
|
828 | + // and if we are all good to go, then send out notifications |
|
829 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
830 | + //ok, now process the transaction according to the payment |
|
831 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
832 | + $transaction, |
|
833 | + $payment |
|
834 | + ); |
|
835 | + } |
|
836 | + // DEBUG LOG |
|
837 | + $payment_method = $payment->payment_method(); |
|
838 | + if ($payment_method instanceof EE_Payment_Method) { |
|
839 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
840 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
841 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
842 | + if ($gateway instanceof EE_Gateway) { |
|
843 | + $gateway->log( |
|
844 | + array( |
|
845 | + 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
846 | + 'transaction' => $transaction->model_field_array(), |
|
847 | + 'finalized' => $finalized, |
|
848 | + 'IPN' => $IPN, |
|
849 | + 'deliver_notifications' => has_filter( |
|
850 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
851 | + ), |
|
852 | + ), |
|
853 | + $payment |
|
854 | + ); |
|
855 | + } |
|
856 | + } |
|
857 | + } |
|
858 | + } |
|
859 | + |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * Force posts to PayPal to use TLS v1.2. See: |
|
864 | + * https://core.trac.wordpress.org/ticket/36320 |
|
865 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
866 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
867 | + * This will affect PayPal standard, pro, express, and Payflow. |
|
868 | + * |
|
869 | + * @param $handle |
|
870 | + * @param $r |
|
871 | + * @param $url |
|
872 | + */ |
|
873 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
874 | + { |
|
875 | + if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) { |
|
876 | + //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
877 | + //instead of the constant because it might not be defined |
|
878 | + curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
879 | + } |
|
880 | + } |
|
881 | 881 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public static function instance() |
38 | 38 | { |
39 | 39 | // check if class object is instantiated |
40 | - if (! self::$_instance instanceof EE_Payment_Processor) { |
|
40 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
41 | 41 | self::$_instance = new self(); |
42 | 42 | } |
43 | 43 | return self::$_instance; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $update_txn = true, |
109 | 109 | $cancel_url = '' |
110 | 110 | ) { |
111 | - if ((float)$amount < 0) { |
|
111 | + if ((float) $amount < 0) { |
|
112 | 112 | throw new EE_Error( |
113 | 113 | sprintf( |
114 | 114 | __( |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
133 | 133 | $payment = $payment_method->type_obj()->process_payment( |
134 | 134 | $transaction, |
135 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
135 | + min($amount, $transaction->remaining()), //make sure we don't overcharge |
|
136 | 136 | $billing_form, |
137 | 137 | $return_url, |
138 | 138 | add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | /** @type \EE_Transaction $transaction */ |
179 | 179 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
180 | 180 | $primary_reg = $transaction->primary_registration(); |
181 | - if (! $primary_reg instanceof EE_Registration) { |
|
181 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
182 | 182 | throw new EE_Error( |
183 | 183 | sprintf( |
184 | 184 | __( |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $payment_method, |
194 | 194 | true |
195 | 195 | ); |
196 | - $url = add_query_arg( |
|
196 | + $url = add_query_arg( |
|
197 | 197 | array( |
198 | 198 | 'e_reg_url_link' => $primary_reg->reg_url_link(), |
199 | 199 | 'ee_payment_method' => $payment_method->slug(), |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $separate_IPN_request = true |
236 | 236 | ) { |
237 | 237 | EE_Registry::instance()->load_model('Change_Log'); |
238 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
238 | + $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
239 | 239 | EE_Processor_Base::set_IPN($separate_IPN_request); |
240 | 240 | $obj_for_log = null; |
241 | 241 | if ($transaction instanceof EE_Transaction) { |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | EEM_Change_Log::instance()->log( |
275 | 275 | EEM_Change_Log::type_gateway, |
276 | 276 | array( |
277 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
277 | + 'message' => 'IPN Exception: '.$e->getMessage(), |
|
278 | 278 | 'current_url' => EEH_URL::current_url(), |
279 | 279 | 'payment' => $e->getPaymentProperties(), |
280 | 280 | 'IPN_data' => $e->getIpnData(), |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | EEM_Change_Log::instance()->log( |
319 | 319 | EEM_Change_Log::type_gateway, |
320 | 320 | array( |
321 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
321 | + 'message' => 'IPN Exception: '.$e->getMessage(), |
|
322 | 322 | 'current_url' => EEH_URL::current_url(), |
323 | 323 | 'payment' => $e->getPaymentProperties(), |
324 | 324 | 'IPN_data' => $e->getIpnData(), |
@@ -759,15 +759,15 @@ discard block |
||
759 | 759 | //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
760 | 760 | if ($registration->paid() > 0) { |
761 | 761 | // ensure $available_refund_amount is NOT negative |
762 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
762 | + $available_refund_amount = (float) abs($available_refund_amount); |
|
763 | 763 | // don't allow refund amount to exceed the available payment amount, OR the amount paid |
764 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
764 | + $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
765 | 765 | // update $available_payment_amount |
766 | 766 | $available_refund_amount -= $refund_amount; |
767 | 767 | //calculate and set new REG_paid |
768 | 768 | $registration->set_paid($registration->paid() - $refund_amount); |
769 | 769 | // convert payment amount back to a negative value for storage in the db |
770 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
770 | + $refund_amount = (float) abs($refund_amount) * -1; |
|
771 | 771 | // now save it |
772 | 772 | $this->_apply_registration_payment($registration, $payment, $refund_amount); |
773 | 773 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.47.rc.022'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.47.rc.022'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |