Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EE_Transaction often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EE_Transaction, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class EE_Transaction extends EE_Base_Class implements EEI_Transaction |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * The length of time in seconds that a lock is applied before being considered expired. |
||
18 | * It is not long because a transaction should only be locked for the duration of the request that locked it |
||
19 | */ |
||
20 | const LOCK_EXPIRATION = 2; |
||
21 | |||
22 | /** |
||
23 | * txn status upon initial construction. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $_old_txn_status; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * @param array $props_n_values incoming values |
||
32 | * @param string $timezone incoming timezone |
||
33 | * (if not set the timezone set for the website will be used.) |
||
34 | * @param array $date_formats incoming date_formats in an array where the first value is the |
||
35 | * date_format and the second value is the time format |
||
36 | * @return EE_Transaction |
||
37 | * @throws EE_Error |
||
38 | * @throws InvalidArgumentException |
||
39 | * @throws InvalidDataTypeException |
||
40 | * @throws InvalidInterfaceException |
||
41 | * @throws ReflectionException |
||
42 | */ |
||
43 | public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
||
54 | |||
55 | |||
56 | /** |
||
57 | * @param array $props_n_values incoming values from the database |
||
58 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
||
59 | * the website will be used. |
||
60 | * @return EE_Transaction |
||
61 | * @throws EE_Error |
||
62 | * @throws InvalidArgumentException |
||
63 | * @throws InvalidDataTypeException |
||
64 | * @throws InvalidInterfaceException |
||
65 | * @throws ReflectionException |
||
66 | */ |
||
67 | public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
||
77 | * If a lock has already been set, then we will attempt to remove it in case it has expired. |
||
78 | * If that also fails, then an exception is thrown. |
||
79 | * |
||
80 | * @throws EE_Error |
||
81 | * @throws InvalidArgumentException |
||
82 | * @throws InvalidDataTypeException |
||
83 | * @throws InvalidInterfaceException |
||
84 | * @throws ReflectionException |
||
85 | */ |
||
86 | public function lock() |
||
108 | |||
109 | |||
110 | /** |
||
111 | * removes transaction lock applied in EE_Transaction::lock() |
||
112 | * |
||
113 | * @return int |
||
114 | * @throws EE_Error |
||
115 | * @throws InvalidArgumentException |
||
116 | * @throws InvalidDataTypeException |
||
117 | * @throws InvalidInterfaceException |
||
118 | * @throws ReflectionException |
||
119 | */ |
||
120 | public function unlock() |
||
124 | |||
125 | |||
126 | /** |
||
127 | * Decides whether or not now is the right time to update the transaction. |
||
128 | * This is useful because we don't always know if it is safe to update the transaction |
||
129 | * and its related data. why? |
||
130 | * because it's possible that the transaction is being used in another |
||
131 | * request and could overwrite anything we save. |
||
132 | * So we want to only update the txn once we know that won't happen. |
||
133 | * We also check that the lock isn't expired, and remove it if it is |
||
134 | * |
||
135 | * @return boolean |
||
136 | * @throws EE_Error |
||
137 | * @throws InvalidArgumentException |
||
138 | * @throws InvalidDataTypeException |
||
139 | * @throws InvalidInterfaceException |
||
140 | * @throws ReflectionException |
||
141 | */ |
||
142 | public function is_locked() |
||
154 | |||
155 | |||
156 | /** |
||
157 | * Gets the meta field indicating that this TXN is locked |
||
158 | * |
||
159 | * @return int |
||
160 | * @throws EE_Error |
||
161 | * @throws InvalidArgumentException |
||
162 | * @throws InvalidDataTypeException |
||
163 | * @throws InvalidInterfaceException |
||
164 | * @throws ReflectionException |
||
165 | */ |
||
166 | protected function _get_lock() |
||
170 | |||
171 | |||
172 | /** |
||
173 | * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
||
174 | * |
||
175 | * @return int |
||
176 | * @throws EE_Error |
||
177 | * @throws InvalidArgumentException |
||
178 | * @throws InvalidDataTypeException |
||
179 | * @throws InvalidInterfaceException |
||
180 | * @throws ReflectionException |
||
181 | */ |
||
182 | protected function _remove_expired_lock() |
||
190 | |||
191 | |||
192 | /** |
||
193 | * Set transaction total |
||
194 | * |
||
195 | * @param float $total total value of transaction |
||
196 | * @throws EE_Error |
||
197 | * @throws InvalidArgumentException |
||
198 | * @throws InvalidDataTypeException |
||
199 | * @throws InvalidInterfaceException |
||
200 | * @throws ReflectionException |
||
201 | */ |
||
202 | public function set_total($total = 0.00) |
||
206 | |||
207 | |||
208 | /** |
||
209 | * Set Total Amount Paid to Date |
||
210 | * |
||
211 | * @param float $total_paid total amount paid to date (sum of all payments) |
||
212 | * @throws EE_Error |
||
213 | * @throws InvalidArgumentException |
||
214 | * @throws InvalidDataTypeException |
||
215 | * @throws InvalidInterfaceException |
||
216 | * @throws ReflectionException |
||
217 | */ |
||
218 | public function set_paid($total_paid = 0.00) |
||
222 | |||
223 | |||
224 | /** |
||
225 | * Set transaction status |
||
226 | * |
||
227 | * @param string $status whether the transaction is open, declined, accepted, |
||
228 | * or any number of custom values that can be set |
||
229 | * @throws EE_Error |
||
230 | * @throws InvalidArgumentException |
||
231 | * @throws InvalidDataTypeException |
||
232 | * @throws InvalidInterfaceException |
||
233 | * @throws ReflectionException |
||
234 | */ |
||
235 | public function set_status($status = '') |
||
239 | |||
240 | |||
241 | /** |
||
242 | * Set hash salt |
||
243 | * |
||
244 | * @param string $hash_salt required for some payment gateways |
||
245 | * @throws EE_Error |
||
246 | * @throws InvalidArgumentException |
||
247 | * @throws InvalidDataTypeException |
||
248 | * @throws InvalidInterfaceException |
||
249 | * @throws ReflectionException |
||
250 | */ |
||
251 | public function set_hash_salt($hash_salt = '') |
||
255 | |||
256 | |||
257 | /** |
||
258 | * Sets TXN_reg_steps array |
||
259 | * |
||
260 | * @param array $txn_reg_steps |
||
261 | * @throws EE_Error |
||
262 | * @throws InvalidArgumentException |
||
263 | * @throws InvalidDataTypeException |
||
264 | * @throws InvalidInterfaceException |
||
265 | * @throws ReflectionException |
||
266 | */ |
||
267 | public function set_reg_steps(array $txn_reg_steps) |
||
271 | |||
272 | |||
273 | /** |
||
274 | * Gets TXN_reg_steps |
||
275 | * |
||
276 | * @return array |
||
277 | * @throws EE_Error |
||
278 | * @throws InvalidArgumentException |
||
279 | * @throws InvalidDataTypeException |
||
280 | * @throws InvalidInterfaceException |
||
281 | * @throws ReflectionException |
||
282 | */ |
||
283 | public function reg_steps() |
||
288 | |||
289 | |||
290 | /** |
||
291 | * @return string of transaction's total cost, with currency symbol and decimal |
||
292 | * @throws EE_Error |
||
293 | * @throws InvalidArgumentException |
||
294 | * @throws InvalidDataTypeException |
||
295 | * @throws InvalidInterfaceException |
||
296 | * @throws ReflectionException |
||
297 | */ |
||
298 | public function pretty_total() |
||
302 | |||
303 | |||
304 | /** |
||
305 | * Gets the amount paid in a pretty string (formatted and with currency symbol) |
||
306 | * |
||
307 | * @return string |
||
308 | * @throws EE_Error |
||
309 | * @throws InvalidArgumentException |
||
310 | * @throws InvalidDataTypeException |
||
311 | * @throws InvalidInterfaceException |
||
312 | * @throws ReflectionException |
||
313 | */ |
||
314 | public function pretty_paid() |
||
318 | |||
319 | |||
320 | /** |
||
321 | * calculate the amount remaining for this transaction and return; |
||
322 | * |
||
323 | * @return float amount remaining |
||
324 | * @throws EE_Error |
||
325 | * @throws InvalidArgumentException |
||
326 | * @throws InvalidDataTypeException |
||
327 | * @throws InvalidInterfaceException |
||
328 | * @throws ReflectionException |
||
329 | */ |
||
330 | public function remaining() |
||
334 | |||
335 | |||
336 | /** |
||
337 | * get Transaction Total |
||
338 | * |
||
339 | * @return float |
||
340 | * @throws EE_Error |
||
341 | * @throws InvalidArgumentException |
||
342 | * @throws InvalidDataTypeException |
||
343 | * @throws InvalidInterfaceException |
||
344 | * @throws ReflectionException |
||
345 | */ |
||
346 | public function total() |
||
350 | |||
351 | |||
352 | /** |
||
353 | * get Total Amount Paid to Date |
||
354 | * |
||
355 | * @return float |
||
356 | * @throws EE_Error |
||
357 | * @throws InvalidArgumentException |
||
358 | * @throws InvalidDataTypeException |
||
359 | * @throws InvalidInterfaceException |
||
360 | * @throws ReflectionException |
||
361 | */ |
||
362 | public function paid() |
||
366 | |||
367 | |||
368 | /** |
||
369 | * @return mixed|null |
||
370 | * @throws EE_Error |
||
371 | * @throws InvalidArgumentException |
||
372 | * @throws InvalidDataTypeException |
||
373 | * @throws InvalidInterfaceException |
||
374 | * @throws ReflectionException |
||
375 | */ |
||
376 | public function get_cart_session() |
||
383 | |||
384 | |||
385 | /** |
||
386 | * get Transaction session data |
||
387 | * |
||
388 | * @return array|mixed |
||
389 | * @throws EE_Error |
||
390 | * @throws InvalidArgumentException |
||
391 | * @throws InvalidDataTypeException |
||
392 | * @throws InvalidInterfaceException |
||
393 | * @throws ReflectionException |
||
394 | */ |
||
395 | public function session_data() |
||
411 | |||
412 | |||
413 | /** |
||
414 | * Set session data within the TXN object |
||
415 | * |
||
416 | * @param EE_Session|array $session_data |
||
417 | * @throws EE_Error |
||
418 | * @throws InvalidArgumentException |
||
419 | * @throws InvalidDataTypeException |
||
420 | * @throws InvalidInterfaceException |
||
421 | * @throws ReflectionException |
||
422 | */ |
||
423 | public function set_txn_session_data($session_data) |
||
431 | |||
432 | |||
433 | /** |
||
434 | * get Transaction hash salt |
||
435 | * |
||
436 | * @return mixed |
||
437 | * @throws EE_Error |
||
438 | * @throws InvalidArgumentException |
||
439 | * @throws InvalidDataTypeException |
||
440 | * @throws InvalidInterfaceException |
||
441 | * @throws ReflectionException |
||
442 | */ |
||
443 | public function hash_salt_() |
||
447 | |||
448 | |||
449 | /** |
||
450 | * Returns the transaction datetime as either: |
||
451 | * - unix timestamp format ($format = false, $gmt = true) |
||
452 | * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
||
453 | * has no affect with this option)), this also may include a timezone abbreviation if the |
||
454 | * set timezone in this class differs from what the timezone is on the blog. |
||
455 | * - formatted date string including the UTC (timezone) offset (default). |
||
456 | * |
||
457 | * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
||
458 | * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
||
459 | * or no UTC offset applied |
||
460 | * @return string | int |
||
461 | * @throws EE_Error |
||
462 | * @throws InvalidArgumentException |
||
463 | * @throws InvalidDataTypeException |
||
464 | * @throws InvalidInterfaceException |
||
465 | * @throws ReflectionException |
||
466 | */ |
||
467 | public function datetime($format = false, $gmt = false) |
||
477 | |||
478 | |||
479 | /** |
||
480 | * Gets registrations on this transaction |
||
481 | * |
||
482 | * @param array $query_params array of query parameters |
||
483 | * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
||
484 | * @return EE_Base_Class[]|EE_Registration[] |
||
485 | * @throws EE_Error |
||
486 | * @throws InvalidArgumentException |
||
487 | * @throws InvalidDataTypeException |
||
488 | * @throws InvalidInterfaceException |
||
489 | * @throws ReflectionException |
||
490 | */ |
||
491 | public function registrations($query_params = array(), $get_cached = false) |
||
505 | |||
506 | |||
507 | /** |
||
508 | * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
||
509 | * function for getting attendees and how many registrations they each have for an event) |
||
510 | * |
||
511 | * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
||
512 | * @throws EE_Error |
||
513 | * @throws InvalidArgumentException |
||
514 | * @throws InvalidDataTypeException |
||
515 | * @throws InvalidInterfaceException |
||
516 | * @throws ReflectionException |
||
517 | */ |
||
518 | public function attendees() |
||
522 | |||
523 | |||
524 | /** |
||
525 | * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
||
526 | * |
||
527 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
528 | * @return EE_Base_Class[]|EE_Payment[] |
||
529 | * @throws EE_Error |
||
530 | * @throws InvalidArgumentException |
||
531 | * @throws InvalidDataTypeException |
||
532 | * @throws InvalidInterfaceException |
||
533 | * @throws ReflectionException |
||
534 | */ |
||
535 | public function payments($query_params = array()) |
||
539 | |||
540 | |||
541 | /** |
||
542 | * gets only approved payments for this transaction |
||
543 | * |
||
544 | * @return EE_Base_Class[]|EE_Payment[] |
||
545 | * @throws EE_Error |
||
546 | * @throws InvalidArgumentException |
||
547 | * @throws ReflectionException |
||
548 | * @throws InvalidDataTypeException |
||
549 | * @throws InvalidInterfaceException |
||
550 | */ |
||
551 | public function approved_payments() |
||
562 | |||
563 | |||
564 | /** |
||
565 | * Gets all payments which have not been approved |
||
566 | * |
||
567 | * @return EE_Base_Class[]|EEI_Payment[] |
||
568 | * @throws EE_Error if a model is misconfigured somehow |
||
569 | * @throws InvalidArgumentException |
||
570 | * @throws InvalidDataTypeException |
||
571 | * @throws InvalidInterfaceException |
||
572 | * @throws ReflectionException |
||
573 | */ |
||
574 | public function pending_payments() |
||
588 | |||
589 | |||
590 | /** |
||
591 | * echoes $this->pretty_status() |
||
592 | * |
||
593 | * @param bool $show_icons |
||
594 | * @throws EE_Error |
||
595 | * @throws InvalidArgumentException |
||
596 | * @throws InvalidDataTypeException |
||
597 | * @throws InvalidInterfaceException |
||
598 | * @throws ReflectionException |
||
599 | */ |
||
600 | public function e_pretty_status($show_icons = false) |
||
604 | |||
605 | |||
606 | /** |
||
607 | * returns a pretty version of the status, good for displaying to users |
||
608 | * |
||
609 | * @param bool $show_icons |
||
610 | * @return string |
||
611 | * @throws EE_Error |
||
612 | * @throws InvalidArgumentException |
||
613 | * @throws InvalidDataTypeException |
||
614 | * @throws InvalidInterfaceException |
||
615 | * @throws ReflectionException |
||
616 | */ |
||
617 | public function pretty_status($show_icons = false) |
||
645 | |||
646 | |||
647 | /** |
||
648 | * get Transaction Status |
||
649 | * |
||
650 | * @return mixed |
||
651 | * @throws EE_Error |
||
652 | * @throws InvalidArgumentException |
||
653 | * @throws InvalidDataTypeException |
||
654 | * @throws InvalidInterfaceException |
||
655 | * @throws ReflectionException |
||
656 | */ |
||
657 | public function status_ID() |
||
661 | |||
662 | |||
663 | /** |
||
664 | * Returns TRUE or FALSE for whether or not this transaction cost any money |
||
665 | * |
||
666 | * @return boolean |
||
667 | * @throws EE_Error |
||
668 | * @throws InvalidArgumentException |
||
669 | * @throws InvalidDataTypeException |
||
670 | * @throws InvalidInterfaceException |
||
671 | * @throws ReflectionException |
||
672 | */ |
||
673 | public function is_free() |
||
677 | |||
678 | |||
679 | /** |
||
680 | * Returns whether this transaction is complete |
||
681 | * Useful in templates and other logic for deciding if we should ask for another payment... |
||
682 | * |
||
683 | * @return boolean |
||
684 | * @throws EE_Error |
||
685 | * @throws InvalidArgumentException |
||
686 | * @throws InvalidDataTypeException |
||
687 | * @throws InvalidInterfaceException |
||
688 | * @throws ReflectionException |
||
689 | */ |
||
690 | public function is_completed() |
||
694 | |||
695 | |||
696 | /** |
||
697 | * Returns whether this transaction is incomplete |
||
698 | * Useful in templates and other logic for deciding if we should ask for another payment... |
||
699 | * |
||
700 | * @return boolean |
||
701 | * @throws EE_Error |
||
702 | * @throws InvalidArgumentException |
||
703 | * @throws InvalidDataTypeException |
||
704 | * @throws InvalidInterfaceException |
||
705 | * @throws ReflectionException |
||
706 | */ |
||
707 | public function is_incomplete() |
||
711 | |||
712 | |||
713 | /** |
||
714 | * Returns whether this transaction is overpaid |
||
715 | * Useful in templates and other logic for deciding if monies need to be refunded |
||
716 | * |
||
717 | * @return boolean |
||
718 | * @throws EE_Error |
||
719 | * @throws InvalidArgumentException |
||
720 | * @throws InvalidDataTypeException |
||
721 | * @throws InvalidInterfaceException |
||
722 | * @throws ReflectionException |
||
723 | */ |
||
724 | public function is_overpaid() |
||
728 | |||
729 | |||
730 | /** |
||
731 | * Returns whether this transaction was abandoned |
||
732 | * meaning that the transaction/registration process was somehow interrupted and never completed |
||
733 | * but that contact information exists for at least one registrant |
||
734 | * |
||
735 | * @return boolean |
||
736 | * @throws EE_Error |
||
737 | * @throws InvalidArgumentException |
||
738 | * @throws InvalidDataTypeException |
||
739 | * @throws InvalidInterfaceException |
||
740 | * @throws ReflectionException |
||
741 | */ |
||
742 | public function is_abandoned() |
||
746 | |||
747 | |||
748 | /** |
||
749 | * Returns whether this transaction failed |
||
750 | * meaning that the transaction/registration process was somehow interrupted and never completed |
||
751 | * and that NO contact information exists for any registrants |
||
752 | * |
||
753 | * @return boolean |
||
754 | * @throws EE_Error |
||
755 | * @throws InvalidArgumentException |
||
756 | * @throws InvalidDataTypeException |
||
757 | * @throws InvalidInterfaceException |
||
758 | * @throws ReflectionException |
||
759 | */ |
||
760 | public function failed() |
||
764 | |||
765 | |||
766 | /** |
||
767 | * This returns the url for the invoice of this transaction |
||
768 | * |
||
769 | * @param string $type 'html' or 'pdf' (default is pdf) |
||
770 | * @return string |
||
771 | * @throws EE_Error |
||
772 | * @throws InvalidArgumentException |
||
773 | * @throws InvalidDataTypeException |
||
774 | * @throws InvalidInterfaceException |
||
775 | * @throws ReflectionException |
||
776 | */ |
||
777 | public function invoice_url($type = 'html') |
||
785 | |||
786 | |||
787 | /** |
||
788 | * Gets the primary registration only |
||
789 | * |
||
790 | * @return EE_Base_Class|EE_Registration |
||
791 | * @throws EE_Error |
||
792 | * @throws InvalidArgumentException |
||
793 | * @throws InvalidDataTypeException |
||
794 | * @throws InvalidInterfaceException |
||
795 | * @throws ReflectionException |
||
796 | */ |
||
797 | public function primary_registration() |
||
814 | |||
815 | |||
816 | /** |
||
817 | * Gets the URL for viewing the receipt |
||
818 | * |
||
819 | * @param string $type 'pdf' or 'html' (default is 'html') |
||
820 | * @return string |
||
821 | * @throws EE_Error |
||
822 | * @throws InvalidArgumentException |
||
823 | * @throws InvalidDataTypeException |
||
824 | * @throws InvalidInterfaceException |
||
825 | * @throws ReflectionException |
||
826 | */ |
||
827 | public function receipt_url($type = 'html') |
||
835 | |||
836 | |||
837 | /** |
||
838 | * Gets the URL of the thank you page with this registration REG_url_link added as |
||
839 | * a query parameter |
||
840 | * |
||
841 | * @return string |
||
842 | * @throws EE_Error |
||
843 | * @throws InvalidArgumentException |
||
844 | * @throws InvalidDataTypeException |
||
845 | * @throws InvalidInterfaceException |
||
846 | * @throws ReflectionException |
||
847 | */ |
||
848 | public function payment_overview_url() |
||
853 | |||
854 | |||
855 | /** |
||
856 | * @return string |
||
857 | * @throws EE_Error |
||
858 | * @throws InvalidArgumentException |
||
859 | * @throws InvalidDataTypeException |
||
860 | * @throws InvalidInterfaceException |
||
861 | * @throws ReflectionException |
||
862 | */ |
||
863 | public function gateway_response_on_transaction() |
||
868 | |||
869 | |||
870 | /** |
||
871 | * Get the status object of this object |
||
872 | * |
||
873 | * @return EE_Base_Class|EE_Status |
||
874 | * @throws EE_Error |
||
875 | * @throws InvalidArgumentException |
||
876 | * @throws InvalidDataTypeException |
||
877 | * @throws InvalidInterfaceException |
||
878 | * @throws ReflectionException |
||
879 | */ |
||
880 | public function status_obj() |
||
884 | |||
885 | |||
886 | /** |
||
887 | * Gets all the extra meta info on this payment |
||
888 | * |
||
889 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
890 | * @return EE_Base_Class[]|EE_Extra_Meta |
||
891 | * @throws EE_Error |
||
892 | * @throws InvalidArgumentException |
||
893 | * @throws InvalidDataTypeException |
||
894 | * @throws InvalidInterfaceException |
||
895 | * @throws ReflectionException |
||
896 | */ |
||
897 | public function extra_meta($query_params = array()) |
||
901 | |||
902 | |||
903 | /** |
||
904 | * Wrapper for _add_relation_to |
||
905 | * |
||
906 | * @param EE_Registration $registration |
||
907 | * @return EE_Base_Class the relation was added to |
||
908 | * @throws EE_Error |
||
909 | * @throws InvalidArgumentException |
||
910 | * @throws InvalidDataTypeException |
||
911 | * @throws InvalidInterfaceException |
||
912 | * @throws ReflectionException |
||
913 | */ |
||
914 | public function add_registration(EE_Registration $registration) |
||
918 | |||
919 | |||
920 | /** |
||
921 | * Removes the given registration from being related (even before saving this transaction). |
||
922 | * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
||
923 | * |
||
924 | * @param int $registration_or_id |
||
925 | * @return EE_Base_Class that was removed from being related |
||
926 | * @throws EE_Error |
||
927 | * @throws InvalidArgumentException |
||
928 | * @throws InvalidDataTypeException |
||
929 | * @throws InvalidInterfaceException |
||
930 | * @throws ReflectionException |
||
931 | */ |
||
932 | public function remove_registration_with_id($registration_or_id) |
||
936 | |||
937 | |||
938 | /** |
||
939 | * Gets all the line items which are for ACTUAL items |
||
940 | * |
||
941 | * @return EE_Line_Item[] |
||
942 | * @throws EE_Error |
||
943 | * @throws InvalidArgumentException |
||
944 | * @throws InvalidDataTypeException |
||
945 | * @throws InvalidInterfaceException |
||
946 | * @throws ReflectionException |
||
947 | */ |
||
948 | public function items_purchased() |
||
952 | |||
953 | |||
954 | /** |
||
955 | * Wrapper for _add_relation_to |
||
956 | * |
||
957 | * @param EE_Line_Item $line_item |
||
958 | * @return EE_Base_Class the relation was added to |
||
959 | * @throws EE_Error |
||
960 | * @throws InvalidArgumentException |
||
961 | * @throws InvalidDataTypeException |
||
962 | * @throws InvalidInterfaceException |
||
963 | * @throws ReflectionException |
||
964 | */ |
||
965 | public function add_line_item(EE_Line_Item $line_item) |
||
969 | |||
970 | |||
971 | /** |
||
972 | * Gets ALL the line items related to this transaction (unstructured) |
||
973 | * |
||
974 | * @param array $query_params |
||
975 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
976 | * @throws EE_Error |
||
977 | * @throws InvalidArgumentException |
||
978 | * @throws InvalidDataTypeException |
||
979 | * @throws InvalidInterfaceException |
||
980 | * @throws ReflectionException |
||
981 | */ |
||
982 | public function line_items($query_params = array()) |
||
986 | |||
987 | |||
988 | /** |
||
989 | * Gets all the line items which are taxes on the total |
||
990 | * |
||
991 | * @return EE_Line_Item[] |
||
992 | * @throws EE_Error |
||
993 | * @throws InvalidArgumentException |
||
994 | * @throws InvalidDataTypeException |
||
995 | * @throws InvalidInterfaceException |
||
996 | * @throws ReflectionException |
||
997 | */ |
||
998 | public function tax_items() |
||
1002 | |||
1003 | |||
1004 | /** |
||
1005 | * Gets the total line item (which is a parent of all other related line items, |
||
1006 | * meaning it takes them all into account on its total) |
||
1007 | * |
||
1008 | * @param bool $create_if_not_found |
||
1009 | * @return \EE_Line_Item |
||
1010 | * @throws EE_Error |
||
1011 | * @throws InvalidArgumentException |
||
1012 | * @throws InvalidDataTypeException |
||
1013 | * @throws InvalidInterfaceException |
||
1014 | * @throws ReflectionException |
||
1015 | */ |
||
1016 | public function total_line_item($create_if_not_found = true) |
||
1024 | |||
1025 | |||
1026 | /** |
||
1027 | * Returns the total amount of tax on this transaction |
||
1028 | * (assumes there's only one tax subtotal line item) |
||
1029 | * |
||
1030 | * @return float |
||
1031 | * @throws EE_Error |
||
1032 | * @throws InvalidArgumentException |
||
1033 | * @throws InvalidDataTypeException |
||
1034 | * @throws InvalidInterfaceException |
||
1035 | * @throws ReflectionException |
||
1036 | */ |
||
1037 | public function tax_total() |
||
1045 | |||
1046 | |||
1047 | /** |
||
1048 | * Gets the tax subtotal line item (assumes there's only one) |
||
1049 | * |
||
1050 | * @return EE_Line_Item |
||
1051 | * @throws EE_Error |
||
1052 | * @throws InvalidArgumentException |
||
1053 | * @throws InvalidDataTypeException |
||
1054 | * @throws InvalidInterfaceException |
||
1055 | * @throws ReflectionException |
||
1056 | */ |
||
1057 | public function tax_total_line_item() |
||
1061 | |||
1062 | |||
1063 | /** |
||
1064 | * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
||
1065 | * |
||
1066 | * @return EE_Form_Section_Proper |
||
1067 | * @throws EE_Error |
||
1068 | * @throws InvalidArgumentException |
||
1069 | * @throws InvalidDataTypeException |
||
1070 | * @throws InvalidInterfaceException |
||
1071 | * @throws ReflectionException |
||
1072 | */ |
||
1073 | public function billing_info() |
||
1116 | |||
1117 | |||
1118 | /** |
||
1119 | * Gets PMD_ID |
||
1120 | * |
||
1121 | * @return int |
||
1122 | * @throws EE_Error |
||
1123 | * @throws InvalidArgumentException |
||
1124 | * @throws InvalidDataTypeException |
||
1125 | * @throws InvalidInterfaceException |
||
1126 | * @throws ReflectionException |
||
1127 | */ |
||
1128 | public function payment_method_ID() |
||
1132 | |||
1133 | |||
1134 | /** |
||
1135 | * Sets PMD_ID |
||
1136 | * |
||
1137 | * @param int $PMD_ID |
||
1138 | * @throws EE_Error |
||
1139 | * @throws InvalidArgumentException |
||
1140 | * @throws InvalidDataTypeException |
||
1141 | * @throws InvalidInterfaceException |
||
1142 | * @throws ReflectionException |
||
1143 | */ |
||
1144 | public function set_payment_method_ID($PMD_ID) |
||
1148 | |||
1149 | |||
1150 | /** |
||
1151 | * Gets the last-used payment method on this transaction |
||
1152 | * (we COULD just use the last-made payment, but some payment methods, namely |
||
1153 | * offline ones, dont' create payments) |
||
1154 | * |
||
1155 | * @return EE_Payment_Method |
||
1156 | * @throws EE_Error |
||
1157 | * @throws InvalidArgumentException |
||
1158 | * @throws InvalidDataTypeException |
||
1159 | * @throws InvalidInterfaceException |
||
1160 | * @throws ReflectionException |
||
1161 | */ |
||
1162 | public function payment_method() |
||
1174 | |||
1175 | |||
1176 | /** |
||
1177 | * Gets the last payment made |
||
1178 | * |
||
1179 | * @return EE_Base_Class|EE_Payment |
||
1180 | * @throws EE_Error |
||
1181 | * @throws InvalidArgumentException |
||
1182 | * @throws InvalidDataTypeException |
||
1183 | * @throws InvalidInterfaceException |
||
1184 | * @throws ReflectionException |
||
1185 | */ |
||
1186 | public function last_payment() |
||
1190 | |||
1191 | |||
1192 | /** |
||
1193 | * Gets all the line items which are unrelated to tickets on this transaction |
||
1194 | * |
||
1195 | * @return EE_Line_Item[] |
||
1196 | * @throws EE_Error |
||
1197 | * @throws InvalidArgumentException |
||
1198 | * @throws InvalidDataTypeException |
||
1199 | * @throws InvalidInterfaceException |
||
1200 | * @throws ReflectionException |
||
1201 | */ |
||
1202 | public function non_ticket_line_items() |
||
1206 | |||
1207 | |||
1208 | /** |
||
1209 | * possibly toggles TXN status |
||
1210 | * |
||
1211 | * @param boolean $update whether to save the TXN |
||
1212 | * @return bool whether the TXN was saved |
||
1213 | * @throws EE_Error |
||
1214 | * @throws InvalidArgumentException |
||
1215 | * @throws InvalidDataTypeException |
||
1216 | * @throws InvalidInterfaceException |
||
1217 | * @throws ReflectionException |
||
1218 | * @throws RuntimeException |
||
1219 | */ |
||
1220 | public function update_status_based_on_total_paid($update = true) |
||
1242 | |||
1243 | |||
1244 | /** |
||
1245 | * Updates the transaction's status and total_paid based on all the payments |
||
1246 | * that apply to it |
||
1247 | * |
||
1248 | * @deprecated |
||
1249 | * @return array|bool |
||
1250 | * @throws EE_Error |
||
1251 | * @throws InvalidArgumentException |
||
1252 | * @throws ReflectionException |
||
1253 | * @throws InvalidDataTypeException |
||
1254 | * @throws InvalidInterfaceException |
||
1255 | */ |
||
1256 | View Code Duplication | public function update_based_on_payments() |
|
1257 | { |
||
1258 | EE_Error::doing_it_wrong( |
||
1259 | __CLASS__ . '::' . __FUNCTION__, |
||
1260 | sprintf( |
||
1261 | __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
||
1262 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
||
1263 | ), |
||
1264 | '4.6.0' |
||
1265 | ); |
||
1266 | /** @type EE_Transaction_Processor $transaction_processor */ |
||
1267 | $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
||
1268 | return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
||
1269 | } |
||
1270 | |||
1271 | |||
1272 | /** |
||
1273 | * @return string |
||
1274 | */ |
||
1275 | public function old_txn_status() |
||
1279 | |||
1280 | |||
1281 | /** |
||
1282 | * @param string $old_txn_status |
||
1283 | */ |
||
1284 | public function set_old_txn_status($old_txn_status) |
||
1291 | |||
1292 | |||
1293 | /** |
||
1294 | * reg_status_updated |
||
1295 | * |
||
1296 | * @return bool |
||
1297 | * @throws EE_Error |
||
1298 | * @throws InvalidArgumentException |
||
1299 | * @throws InvalidDataTypeException |
||
1300 | * @throws InvalidInterfaceException |
||
1301 | * @throws ReflectionException |
||
1302 | */ |
||
1303 | public function txn_status_updated() |
||
1307 | |||
1308 | |||
1309 | /** |
||
1310 | * _reg_steps_completed |
||
1311 | * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
||
1312 | * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
||
1313 | * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
||
1314 | * |
||
1315 | * @param string $reg_step_slug |
||
1316 | * @param bool $check_all |
||
1317 | * @return bool|int |
||
1318 | * @throws EE_Error |
||
1319 | * @throws InvalidArgumentException |
||
1320 | * @throws InvalidDataTypeException |
||
1321 | * @throws InvalidInterfaceException |
||
1322 | * @throws ReflectionException |
||
1323 | */ |
||
1324 | private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
||
1359 | |||
1360 | |||
1361 | /** |
||
1362 | * all_reg_steps_completed |
||
1363 | * returns: |
||
1364 | * true if ALL reg steps have been marked as completed |
||
1365 | * or false if any step is not completed |
||
1366 | * |
||
1367 | * @return bool |
||
1368 | * @throws EE_Error |
||
1369 | * @throws InvalidArgumentException |
||
1370 | * @throws InvalidDataTypeException |
||
1371 | * @throws InvalidInterfaceException |
||
1372 | * @throws ReflectionException |
||
1373 | */ |
||
1374 | public function all_reg_steps_completed() |
||
1378 | |||
1379 | |||
1380 | /** |
||
1381 | * all_reg_steps_completed_except |
||
1382 | * returns: |
||
1383 | * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
||
1384 | * or false if any other step is not completed |
||
1385 | * or false if ALL steps are completed including the exception you are testing !!! |
||
1386 | * |
||
1387 | * @param string $exception |
||
1388 | * @return bool |
||
1389 | * @throws EE_Error |
||
1390 | * @throws InvalidArgumentException |
||
1391 | * @throws InvalidDataTypeException |
||
1392 | * @throws InvalidInterfaceException |
||
1393 | * @throws ReflectionException |
||
1394 | */ |
||
1395 | public function all_reg_steps_completed_except($exception = '') |
||
1399 | |||
1400 | |||
1401 | /** |
||
1402 | * all_reg_steps_completed_except |
||
1403 | * returns: |
||
1404 | * true if ALL reg steps, except the final step, have been marked as completed |
||
1405 | * or false if any step is not completed |
||
1406 | * or false if ALL steps are completed including the final step !!! |
||
1407 | * |
||
1408 | * @return bool |
||
1409 | * @throws EE_Error |
||
1410 | * @throws InvalidArgumentException |
||
1411 | * @throws InvalidDataTypeException |
||
1412 | * @throws InvalidInterfaceException |
||
1413 | * @throws ReflectionException |
||
1414 | */ |
||
1415 | public function all_reg_steps_completed_except_final_step() |
||
1419 | |||
1420 | |||
1421 | /** |
||
1422 | * reg_step_completed |
||
1423 | * returns: |
||
1424 | * true if a specific reg step has been marked as completed |
||
1425 | * a Unix timestamp if it has been initialized but not yet completed, |
||
1426 | * or false if it has not yet been initialized |
||
1427 | * |
||
1428 | * @param string $reg_step_slug |
||
1429 | * @return bool|int |
||
1430 | * @throws EE_Error |
||
1431 | * @throws InvalidArgumentException |
||
1432 | * @throws InvalidDataTypeException |
||
1433 | * @throws InvalidInterfaceException |
||
1434 | * @throws ReflectionException |
||
1435 | */ |
||
1436 | public function reg_step_completed($reg_step_slug) |
||
1440 | |||
1441 | |||
1442 | /** |
||
1443 | * completed_final_reg_step |
||
1444 | * returns: |
||
1445 | * true if the finalize_registration reg step has been marked as completed |
||
1446 | * a Unix timestamp if it has been initialized but not yet completed, |
||
1447 | * or false if it has not yet been initialized |
||
1448 | * |
||
1449 | * @return bool|int |
||
1450 | * @throws EE_Error |
||
1451 | * @throws InvalidArgumentException |
||
1452 | * @throws InvalidDataTypeException |
||
1453 | * @throws InvalidInterfaceException |
||
1454 | * @throws ReflectionException |
||
1455 | */ |
||
1456 | public function final_reg_step_completed() |
||
1460 | |||
1461 | |||
1462 | /** |
||
1463 | * set_reg_step_initiated |
||
1464 | * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
||
1465 | * |
||
1466 | * @param string $reg_step_slug |
||
1467 | * @return boolean |
||
1468 | * @throws EE_Error |
||
1469 | * @throws InvalidArgumentException |
||
1470 | * @throws InvalidDataTypeException |
||
1471 | * @throws InvalidInterfaceException |
||
1472 | * @throws ReflectionException |
||
1473 | */ |
||
1474 | public function set_reg_step_initiated($reg_step_slug) |
||
1478 | |||
1479 | |||
1480 | /** |
||
1481 | * set_reg_step_completed |
||
1482 | * given a valid TXN_reg_step, this sets the step as completed |
||
1483 | * |
||
1484 | * @param string $reg_step_slug |
||
1485 | * @return boolean |
||
1486 | * @throws EE_Error |
||
1487 | * @throws InvalidArgumentException |
||
1488 | * @throws InvalidDataTypeException |
||
1489 | * @throws InvalidInterfaceException |
||
1490 | * @throws ReflectionException |
||
1491 | */ |
||
1492 | public function set_reg_step_completed($reg_step_slug) |
||
1496 | |||
1497 | |||
1498 | /** |
||
1499 | * set_reg_step_completed |
||
1500 | * given a valid TXN_reg_step slug, this sets the step as NOT completed |
||
1501 | * |
||
1502 | * @param string $reg_step_slug |
||
1503 | * @return boolean |
||
1504 | * @throws EE_Error |
||
1505 | * @throws InvalidArgumentException |
||
1506 | * @throws InvalidDataTypeException |
||
1507 | * @throws InvalidInterfaceException |
||
1508 | * @throws ReflectionException |
||
1509 | */ |
||
1510 | public function set_reg_step_not_completed($reg_step_slug) |
||
1514 | |||
1515 | |||
1516 | /** |
||
1517 | * set_reg_step_completed |
||
1518 | * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
||
1519 | * |
||
1520 | * @param string $reg_step_slug |
||
1521 | * @param boolean|int $status |
||
1522 | * @return boolean |
||
1523 | * @throws EE_Error |
||
1524 | * @throws InvalidArgumentException |
||
1525 | * @throws InvalidDataTypeException |
||
1526 | * @throws InvalidInterfaceException |
||
1527 | * @throws ReflectionException |
||
1528 | */ |
||
1529 | private function _set_reg_step_completed_status($reg_step_slug, $status) |
||
1564 | |||
1565 | |||
1566 | /** |
||
1567 | * remove_reg_step |
||
1568 | * given a valid TXN_reg_step slug, this will remove (unset) |
||
1569 | * the reg step from the TXN reg step array |
||
1570 | * |
||
1571 | * @param string $reg_step_slug |
||
1572 | * @return void |
||
1573 | * @throws EE_Error |
||
1574 | * @throws InvalidArgumentException |
||
1575 | * @throws InvalidDataTypeException |
||
1576 | * @throws InvalidInterfaceException |
||
1577 | * @throws ReflectionException |
||
1578 | */ |
||
1579 | public function remove_reg_step($reg_step_slug) |
||
1586 | |||
1587 | |||
1588 | /** |
||
1589 | * toggle_failed_transaction_status |
||
1590 | * upgrades a TXNs status from failed to abandoned, |
||
1591 | * meaning that contact information has been captured for at least one registrant |
||
1592 | * |
||
1593 | * @param bool $save |
||
1594 | * @return bool |
||
1595 | * @throws EE_Error |
||
1596 | * @throws InvalidArgumentException |
||
1597 | * @throws InvalidDataTypeException |
||
1598 | * @throws InvalidInterfaceException |
||
1599 | * @throws ReflectionException |
||
1600 | */ |
||
1601 | public function toggle_failed_transaction_status($save = true) |
||
1613 | |||
1614 | |||
1615 | /** |
||
1616 | * toggle_abandoned_transaction_status |
||
1617 | * upgrades a TXNs status from failed or abandoned to incomplete |
||
1618 | * |
||
1619 | * @return bool |
||
1620 | * @throws EE_Error |
||
1621 | * @throws InvalidArgumentException |
||
1622 | * @throws InvalidDataTypeException |
||
1623 | * @throws InvalidInterfaceException |
||
1624 | * @throws ReflectionException |
||
1625 | */ |
||
1626 | public function toggle_abandoned_transaction_status() |
||
1646 | |||
1647 | |||
1648 | /** |
||
1649 | * checks if an Abandoned TXN has any related payments, and if so, |
||
1650 | * updates the TXN status based on the amount paid |
||
1651 | * |
||
1652 | * @throws EE_Error |
||
1653 | * @throws InvalidDataTypeException |
||
1654 | * @throws InvalidInterfaceException |
||
1655 | * @throws InvalidArgumentException |
||
1656 | * @throws RuntimeException |
||
1657 | * @throws ReflectionException |
||
1658 | */ |
||
1659 | public function verify_abandoned_transaction_status() |
||
1694 | |||
1695 | |||
1696 | /** |
||
1697 | * @since 4.10.4.p |
||
1698 | * @throws EE_Error |
||
1699 | * @throws InvalidArgumentException |
||
1700 | * @throws InvalidDataTypeException |
||
1701 | * @throws InvalidInterfaceException |
||
1702 | * @throws ReflectionException |
||
1703 | * @throws RuntimeException |
||
1704 | */ |
||
1705 | public function recalculateLineItems() |
||
1714 | } |
||
1715 |