@@ -8,99 +8,99 @@ |
||
8 | 8 | interface EEI_Base |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * gets the unique ID of the model object. If it hasn't been saved yet |
|
13 | - * to the database, this should be 0 or NULL |
|
14 | - */ |
|
15 | - public function ID(); |
|
16 | - |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * Returns an array where keys are field names and values are their values |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function model_field_array(); |
|
25 | - |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Saves the thing to the database and returns success (or an ID) |
|
30 | - * |
|
31 | - * @return boolean success on insert; or int on update (ID of newly inserted thing) |
|
32 | - */ |
|
33 | - public function save(); |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
39 | - * A $previous_value can be specified in case there are many meta rows with the same key |
|
40 | - * |
|
41 | - * @param string $meta_key |
|
42 | - * @param string $meta_value |
|
43 | - * @param string $previous_value |
|
44 | - * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
45 | - * NOTE: if the values haven't changed, returns 0 |
|
46 | - */ |
|
47 | - public function update_extra_meta($meta_key, $meta_value, $previous_value = null); |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
53 | - * no other extra meta for this model object have the same key. Returns TRUE if the |
|
54 | - * extra meta row was entered, false if not |
|
55 | - * |
|
56 | - * @param string $meta_key |
|
57 | - * @param string $meta_value |
|
58 | - * @param boolean $unique |
|
59 | - * @return boolean |
|
60 | - */ |
|
61 | - public function add_extra_meta($meta_key, $meta_value, $unique = false); |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
67 | - * is specified, only deletes extra meta records with that value. |
|
68 | - * |
|
69 | - * @param string $meta_key |
|
70 | - * @param string $meta_value |
|
71 | - * @return int number of extra meta rows deleted |
|
72 | - */ |
|
73 | - public function delete_extra_meta($meta_key, $meta_value = null); |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
79 | - * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
80 | - * You can specify $default is case you haven't found the extra meta |
|
81 | - * |
|
82 | - * @param string $meta_key |
|
83 | - * @param boolean $single |
|
84 | - * @param mixed $default if we don't find anything, what should we return? |
|
85 | - * @return mixed single value if $single; array if ! $single |
|
86 | - */ |
|
87 | - public function get_extra_meta($meta_key, $single = false, $default = NULL); |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this. |
|
93 | - * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
|
94 | - * to see what options are available. |
|
95 | - * |
|
96 | - * @param string $field_name |
|
97 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
98 | - * (in cases where the same property may be used for different outputs |
|
99 | - * - i.e. datetime, money etc.) |
|
100 | - * @return mixed |
|
101 | - * @throws \EE_Error |
|
102 | - */ |
|
103 | - public function get_pretty($field_name, $extra_cache_ref); |
|
11 | + /** |
|
12 | + * gets the unique ID of the model object. If it hasn't been saved yet |
|
13 | + * to the database, this should be 0 or NULL |
|
14 | + */ |
|
15 | + public function ID(); |
|
16 | + |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * Returns an array where keys are field names and values are their values |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function model_field_array(); |
|
25 | + |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Saves the thing to the database and returns success (or an ID) |
|
30 | + * |
|
31 | + * @return boolean success on insert; or int on update (ID of newly inserted thing) |
|
32 | + */ |
|
33 | + public function save(); |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
39 | + * A $previous_value can be specified in case there are many meta rows with the same key |
|
40 | + * |
|
41 | + * @param string $meta_key |
|
42 | + * @param string $meta_value |
|
43 | + * @param string $previous_value |
|
44 | + * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
45 | + * NOTE: if the values haven't changed, returns 0 |
|
46 | + */ |
|
47 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = null); |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
53 | + * no other extra meta for this model object have the same key. Returns TRUE if the |
|
54 | + * extra meta row was entered, false if not |
|
55 | + * |
|
56 | + * @param string $meta_key |
|
57 | + * @param string $meta_value |
|
58 | + * @param boolean $unique |
|
59 | + * @return boolean |
|
60 | + */ |
|
61 | + public function add_extra_meta($meta_key, $meta_value, $unique = false); |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
67 | + * is specified, only deletes extra meta records with that value. |
|
68 | + * |
|
69 | + * @param string $meta_key |
|
70 | + * @param string $meta_value |
|
71 | + * @return int number of extra meta rows deleted |
|
72 | + */ |
|
73 | + public function delete_extra_meta($meta_key, $meta_value = null); |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
79 | + * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
80 | + * You can specify $default is case you haven't found the extra meta |
|
81 | + * |
|
82 | + * @param string $meta_key |
|
83 | + * @param boolean $single |
|
84 | + * @param mixed $default if we don't find anything, what should we return? |
|
85 | + * @return mixed single value if $single; array if ! $single |
|
86 | + */ |
|
87 | + public function get_extra_meta($meta_key, $single = false, $default = NULL); |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this. |
|
93 | + * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
|
94 | + * to see what options are available. |
|
95 | + * |
|
96 | + * @param string $field_name |
|
97 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
98 | + * (in cases where the same property may be used for different outputs |
|
99 | + * - i.e. datetime, money etc.) |
|
100 | + * @return mixed |
|
101 | + * @throws \EE_Error |
|
102 | + */ |
|
103 | + public function get_pretty($field_name, $extra_cache_ref); |
|
104 | 104 | |
105 | 105 | |
106 | 106 |
@@ -9,13 +9,13 @@ |
||
9 | 9 | interface EEI_Request_Stack_Core_App |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * gives the core app a chance to handle the response after the request stack has fully processed |
|
14 | - * |
|
15 | - * @param EE_Request $request |
|
16 | - * @param EE_Response $response |
|
17 | - */ |
|
18 | - public function handle_response(EE_Request $request, EE_Response $response); |
|
12 | + /** |
|
13 | + * gives the core app a chance to handle the response after the request stack has fully processed |
|
14 | + * |
|
15 | + * @param EE_Request $request |
|
16 | + * @param EE_Response $response |
|
17 | + */ |
|
18 | + public function handle_response(EE_Request $request, EE_Response $response); |
|
19 | 19 | |
20 | 20 | } |
21 | 21 | // End of file EEI_Request_Stack_Core_App.interface.php |
@@ -9,27 +9,27 @@ |
||
9 | 9 | interface EEHI_File |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * ensure_file_exists_and_is_writable |
|
14 | - * ensures that a file exists and is writable, will attempt to create file if it does not exist |
|
15 | - * |
|
16 | - * @param string $full_file_path |
|
17 | - * @throws EE_Error |
|
18 | - * @return bool |
|
19 | - */ |
|
20 | - public static function ensure_file_exists_and_is_writable($full_file_path = ''); |
|
12 | + /** |
|
13 | + * ensure_file_exists_and_is_writable |
|
14 | + * ensures that a file exists and is writable, will attempt to create file if it does not exist |
|
15 | + * |
|
16 | + * @param string $full_file_path |
|
17 | + * @throws EE_Error |
|
18 | + * @return bool |
|
19 | + */ |
|
20 | + public static function ensure_file_exists_and_is_writable($full_file_path = ''); |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * ensure_folder_exists_and_is_writable |
|
26 | - * ensures that a folder exists and is writable, will attempt to create folder if it does not exist |
|
27 | - * |
|
28 | - * @param string $folder |
|
29 | - * @throws EE_Error |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public static function ensure_folder_exists_and_is_writable($folder = ''); |
|
24 | + /** |
|
25 | + * ensure_folder_exists_and_is_writable |
|
26 | + * ensures that a folder exists and is writable, will attempt to create folder if it does not exist |
|
27 | + * |
|
28 | + * @param string $folder |
|
29 | + * @throws EE_Error |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public static function ensure_folder_exists_and_is_writable($folder = ''); |
|
33 | 33 | } |
34 | 34 | // End of file EEHI_File.interface.php |
35 | 35 | // Location: core/interfaces/EEHI_File.interface.php |
36 | 36 | \ No newline at end of file |
@@ -9,18 +9,18 @@ |
||
9 | 9 | interface EEHI_Money |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
14 | - * This should be used to compare floats instead of normal '==' because floats |
|
15 | - * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
16 | - * but actually differ by 0.00000001. |
|
17 | - * |
|
18 | - * @param float $float1 |
|
19 | - * @param float $float2 |
|
20 | - * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
21 | - * @return boolean whether the equation is true or false |
|
22 | - */ |
|
23 | - public function compare_floats($float1, $float2, $operator = '='); |
|
12 | + /** |
|
13 | + * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
14 | + * This should be used to compare floats instead of normal '==' because floats |
|
15 | + * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
16 | + * but actually differ by 0.00000001. |
|
17 | + * |
|
18 | + * @param float $float1 |
|
19 | + * @param float $float2 |
|
20 | + * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
21 | + * @return boolean whether the equation is true or false |
|
22 | + */ |
|
23 | + public function compare_floats($float1, $float2, $operator = '='); |
|
24 | 24 | } |
25 | 25 | // End of file EEHI_Money.interface.php |
26 | 26 | // Location: core/interfaces/EEHI_Money.interface.php |
27 | 27 | \ No newline at end of file |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\exceptions; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @param \Exception $exception |
24 | 24 | */ |
25 | - public function __construct( \Exception $exception ) { |
|
26 | - if ( WP_DEBUG ) { |
|
27 | - $this->displayException( $exception ); |
|
25 | + public function __construct(\Exception $exception) { |
|
26 | + if (WP_DEBUG) { |
|
27 | + $this->displayException($exception); |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
@@ -34,27 +34,27 @@ discard block |
||
34 | 34 | * @access protected |
35 | 35 | * @param \Exception $exception |
36 | 36 | */ |
37 | - protected function displayException( \Exception $exception ) { |
|
37 | + protected function displayException(\Exception $exception) { |
|
38 | 38 | |
39 | 39 | $error_code = ''; |
40 | 40 | $trace_details = ''; |
41 | 41 | $time = time(); |
42 | 42 | $trace = $exception->getTrace(); |
43 | 43 | // get separate user and developer messages if they exist |
44 | - $msg = explode( '||', $exception->getMessage() ); |
|
44 | + $msg = explode('||', $exception->getMessage()); |
|
45 | 45 | $user_msg = $msg[0]; |
46 | - $dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0]; |
|
46 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
47 | 47 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
48 | 48 | // start gathering output |
49 | 49 | $output = $this->exceptionStyles(); |
50 | 50 | $output .= ' |
51 | 51 | <div id="ee-error-message" class="error">'; |
52 | - if ( ! WP_DEBUG ) { |
|
52 | + if ( ! WP_DEBUG) { |
|
53 | 53 | $output .= ' |
54 | 54 | <p>'; |
55 | 55 | } |
56 | 56 | // process trace info |
57 | - if ( empty( $trace ) ) { |
|
57 | + if (empty($trace)) { |
|
58 | 58 | $trace_details .= __( |
59 | 59 | 'Sorry, but no trace information was available for this exception.', |
60 | 60 | 'event_espresso' |
@@ -67,47 +67,47 @@ discard block |
||
67 | 67 | <th scope="col" align="right" style="width:2.5%;">#</th> |
68 | 68 | <th scope="col" align="right" style="width:3.5%;">Line</th> |
69 | 69 | <th scope="col" align="left" style="width:40%;">File</th> |
70 | - <th scope="col" align="left">' . __( 'Class', 'event_espresso' ) . '->' . __( 'Method( arguments )', 'event_espresso' ) . '</th> |
|
70 | + <th scope="col" align="left">' . __('Class', 'event_espresso').'->'.__('Method( arguments )', 'event_espresso').'</th> |
|
71 | 71 | </tr>'; |
72 | - $last_on_stack = count( $trace ) - 1; |
|
72 | + $last_on_stack = count($trace) - 1; |
|
73 | 73 | // reverse array so that stack is in proper chronological order |
74 | - $sorted_trace = array_reverse( $trace ); |
|
75 | - foreach ( $sorted_trace as $nmbr => $trace ) { |
|
76 | - $file = isset( $trace['file'] ) ? $trace['file'] : ''; |
|
77 | - $class = isset( $trace['class'] ) ? $trace['class'] : ''; |
|
78 | - $type = isset( $trace['type'] ) ? $trace['type'] : ''; |
|
79 | - $function = isset( $trace['function'] ) ? $trace['function'] : ''; |
|
80 | - $args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : ''; |
|
81 | - $args = isset( $trace['args'] ) && count( $trace['args'] ) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
82 | - $line = isset( $trace['line'] ) ? $trace['line'] : ''; |
|
74 | + $sorted_trace = array_reverse($trace); |
|
75 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
76 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
77 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
78 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
79 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
80 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
81 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args; |
|
82 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
83 | 83 | $zebra = $nmbr % 2 !== 0 ? ' odd' : ''; |
84 | - if ( empty( $file ) && ! empty( $class ) ) { |
|
85 | - $a = new \ReflectionClass( $class ); |
|
84 | + if (empty($file) && ! empty($class)) { |
|
85 | + $a = new \ReflectionClass($class); |
|
86 | 86 | $file = $a->getFileName(); |
87 | - if ( empty( $line ) && ! empty( $function ) ) { |
|
88 | - $b = new \ReflectionMethod( $class, $function ); |
|
87 | + if (empty($line) && ! empty($function)) { |
|
88 | + $b = new \ReflectionMethod($class, $function); |
|
89 | 89 | $line = $b->getStartLine(); |
90 | 90 | } |
91 | 91 | } |
92 | - if ( $nmbr === $last_on_stack ) { |
|
92 | + if ($nmbr === $last_on_stack) { |
|
93 | 93 | $file = $exception->getFile() !== '' ? $exception->getFile() : $file; |
94 | 94 | $line = $exception->getLine() !== '' ? $exception->getLine() : $line; |
95 | - $error_code = $this->generate_error_code( $file, $trace['function'], $line ); |
|
95 | + $error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
96 | 96 | } |
97 | - $file = \EEH_File::standardise_directory_separators( $file ); |
|
98 | - $nmbr = ! empty( $nmbr ) ? $nmbr : ' '; |
|
99 | - $line = ! empty( $line ) ? $line : ' '; |
|
100 | - $file = ! empty( $file ) ? $file : ' '; |
|
101 | - $class_display = ! empty( $class ) ? $class : ''; |
|
102 | - $type = ! empty( $type ) ? $type : ''; |
|
103 | - $function = ! empty( $function ) ? $function : ''; |
|
104 | - $args = ! empty( $args ) ? '( ' . $args . ' )' : '()'; |
|
97 | + $file = \EEH_File::standardise_directory_separators($file); |
|
98 | + $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
99 | + $line = ! empty($line) ? $line : ' '; |
|
100 | + $file = ! empty($file) ? $file : ' '; |
|
101 | + $class_display = ! empty($class) ? $class : ''; |
|
102 | + $type = ! empty($type) ? $type : ''; |
|
103 | + $function = ! empty($function) ? $function : ''; |
|
104 | + $args = ! empty($args) ? '( '.$args.' )' : '()'; |
|
105 | 105 | $trace_details .= ' |
106 | 106 | <tr> |
107 | - <td align="right" valign="top" class="' . $zebra . '">' . $nmbr . '</td> |
|
108 | - <td align="right" valign="top" class="' . $zebra . '">' . $line . '</td> |
|
109 | - <td align="left" valign="top" class="' . $zebra . '">' . $file . '</td> |
|
110 | - <td align="left" valign="top" class="' . $zebra . '">' . $class_display . $type . $function . $args . '</td> |
|
107 | + <td align="right" valign="top" class="' . $zebra.'">'.$nmbr.'</td> |
|
108 | + <td align="right" valign="top" class="' . $zebra.'">'.$line.'</td> |
|
109 | + <td align="left" valign="top" class="' . $zebra.'">'.$file.'</td> |
|
110 | + <td align="left" valign="top" class="' . $zebra.'">'.$class_display.$type.$function.$args.'</td> |
|
111 | 111 | </tr>'; |
112 | 112 | } |
113 | 113 | $trace_details .= ' |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | } |
117 | 117 | $code = $exception->getCode() ? $exception->getCode() : $error_code; |
118 | 118 | // add generic non-identifying messages for non-privileged users |
119 | - if ( ! WP_DEBUG ) { |
|
119 | + if ( ! WP_DEBUG) { |
|
120 | 120 | $output .= '<span class="ee-error-user-msg-spn">' |
121 | - . trim( $msg ) |
|
121 | + . trim($msg) |
|
122 | 122 | . '</span> <sup>' |
123 | 123 | . $code |
124 | 124 | . '</sup><br />'; |
@@ -129,15 +129,15 @@ discard block |
||
129 | 129 | <p class="ee-error-dev-msg-pg"> |
130 | 130 | ' |
131 | 131 | . sprintf( |
132 | - __( '%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso' ), |
|
132 | + __('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
133 | 133 | '<strong class="ee-error-dev-msg-str">', |
134 | - get_class( $exception ), |
|
134 | + get_class($exception), |
|
135 | 135 | '</strong> <span>', |
136 | - $code . '</span>' |
|
136 | + $code.'</span>' |
|
137 | 137 | ) |
138 | 138 | . '<br /> |
139 | 139 | <span class="big-text">"' |
140 | - . trim( $msg ) |
|
140 | + . trim($msg) |
|
141 | 141 | . '"</span><br/> |
142 | 142 | <a id="display-ee-error-trace-1' |
143 | 143 | . $time |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | . $time |
146 | 146 | . '"> |
147 | 147 | ' |
148 | - . __( 'click to view backtrace and class/method details', 'event_espresso' ) |
|
148 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
149 | 149 | . ' |
150 | 150 | </a><br /> |
151 | 151 | ' |
152 | 152 | . $exception->getFile() |
153 | 153 | . sprintf( |
154 | - __( '%1$s( line no: %2$s )%3$s', 'event_espresso' ), |
|
154 | + __('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
155 | 155 | ' <span class="small-text lt-grey-text">', |
156 | 156 | $exception->getLine(), |
157 | 157 | '</span>' |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
164 | 164 | ' |
165 | 165 | . $trace_details; |
166 | - if ( ! empty( $class ) ) { |
|
166 | + if ( ! empty($class)) { |
|
167 | 167 | $output .= ' |
168 | 168 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
169 | 169 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
170 | - <h3>' . __( 'Class Details', 'event_espresso' ) . '</h3>'; |
|
171 | - $a = new \ReflectionClass( $class ); |
|
170 | + <h3>' . __('Class Details', 'event_espresso').'</h3>'; |
|
171 | + $a = new \ReflectionClass($class); |
|
172 | 172 | $output .= ' |
173 | - <pre>' . $a . '</pre> |
|
173 | + <pre>' . $a.'</pre> |
|
174 | 174 | </div> |
175 | 175 | </div>'; |
176 | 176 | } |
@@ -180,16 +180,16 @@ discard block |
||
180 | 180 | <br />'; |
181 | 181 | } |
182 | 182 | // remove last linebreak |
183 | - $output = substr( $output, 0, -7 ); |
|
184 | - if ( ! WP_DEBUG ) { |
|
183 | + $output = substr($output, 0, -7); |
|
184 | + if ( ! WP_DEBUG) { |
|
185 | 185 | $output .= ' |
186 | 186 | </p>'; |
187 | 187 | } |
188 | 188 | $output .= ' |
189 | 189 | </div>'; |
190 | - $output .= $this->printScripts( true ); |
|
191 | - if ( defined( 'DOING_AJAX' ) ) { |
|
192 | - echo wp_json_encode( array( 'error' => $output ) ); |
|
190 | + $output .= $this->printScripts(true); |
|
191 | + if (defined('DOING_AJAX')) { |
|
192 | + echo wp_json_encode(array('error' => $output)); |
|
193 | 193 | exit(); |
194 | 194 | } |
195 | 195 | echo $output; |
@@ -206,56 +206,56 @@ discard block |
||
206 | 206 | * @param bool $array |
207 | 207 | * @return string |
208 | 208 | */ |
209 | - private function _convert_args_to_string( $arguments = array(), $indent = 0, $array = false ) { |
|
209 | + private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) { |
|
210 | 210 | $args = array(); |
211 | - $args_count = count( $arguments ); |
|
212 | - if ( $args_count > 2 ) { |
|
211 | + $args_count = count($arguments); |
|
212 | + if ($args_count > 2) { |
|
213 | 213 | $indent++; |
214 | 214 | $args[] = '<br />'; |
215 | 215 | } |
216 | 216 | $x = 0; |
217 | - foreach ( $arguments as $arg ) { |
|
217 | + foreach ($arguments as $arg) { |
|
218 | 218 | $x++; |
219 | - for( $i = 0; $i < $indent; $i++ ) { |
|
219 | + for ($i = 0; $i < $indent; $i++) { |
|
220 | 220 | $args[] = ' '; |
221 | 221 | } |
222 | - if ( is_string( $arg ) ) { |
|
223 | - if ( ! $array && strlen( $arg ) > 75 ) { |
|
222 | + if (is_string($arg)) { |
|
223 | + if ( ! $array && strlen($arg) > 75) { |
|
224 | 224 | $args[] = "<br />"; |
225 | - for ( $i = 0; $i <= $indent; $i++ ) { |
|
225 | + for ($i = 0; $i <= $indent; $i++) { |
|
226 | 226 | $args[] = ' '; |
227 | 227 | } |
228 | - $args[] = "'" . $arg . "'<br />"; |
|
228 | + $args[] = "'".$arg."'<br />"; |
|
229 | 229 | } else { |
230 | - $args[] = " '" . $arg . "'"; |
|
230 | + $args[] = " '".$arg."'"; |
|
231 | 231 | } |
232 | - } elseif ( is_array( $arg ) ) { |
|
233 | - $arg_count = count( $arg ); |
|
234 | - if ( $arg_count > 2 ) { |
|
232 | + } elseif (is_array($arg)) { |
|
233 | + $arg_count = count($arg); |
|
234 | + if ($arg_count > 2) { |
|
235 | 235 | $indent++; |
236 | - $args[] = " array(" . $this->_convert_args_to_string( $arg, $indent, true ) . ")"; |
|
236 | + $args[] = " array(".$this->_convert_args_to_string($arg, $indent, true).")"; |
|
237 | 237 | $indent--; |
238 | - } else if ( $arg_count === 0 ) { |
|
238 | + } else if ($arg_count === 0) { |
|
239 | 239 | $args[] = " array()"; |
240 | 240 | } else { |
241 | - $args[] = " array( " . $this->_convert_args_to_string( $arg ) . " )"; |
|
241 | + $args[] = " array( ".$this->_convert_args_to_string($arg)." )"; |
|
242 | 242 | } |
243 | - } elseif ( $arg === null ) { |
|
243 | + } elseif ($arg === null) { |
|
244 | 244 | $args[] = ' null'; |
245 | - } elseif ( is_bool( $arg ) ) { |
|
245 | + } elseif (is_bool($arg)) { |
|
246 | 246 | $args[] = $arg ? ' true' : ' false'; |
247 | - } elseif ( is_object( $arg ) ) { |
|
248 | - $args[] = get_class( $arg ); |
|
249 | - } elseif ( is_resource( $arg ) ) { |
|
250 | - $args[] = get_resource_type( $arg ); |
|
247 | + } elseif (is_object($arg)) { |
|
248 | + $args[] = get_class($arg); |
|
249 | + } elseif (is_resource($arg)) { |
|
250 | + $args[] = get_resource_type($arg); |
|
251 | 251 | } else { |
252 | 252 | $args[] = $arg; |
253 | 253 | } |
254 | - if ( $x === $args_count ) { |
|
255 | - if ( $args_count > 2 ) { |
|
254 | + if ($x === $args_count) { |
|
255 | + if ($args_count > 2) { |
|
256 | 256 | $args[] = "<br />"; |
257 | 257 | $indent--; |
258 | - for ( $i = 1; $i < $indent; $i++ ) { |
|
258 | + for ($i = 1; $i < $indent; $i++) { |
|
259 | 259 | $args[] = ' '; |
260 | 260 | } |
261 | 261 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $args[] = $args_count > 2 ? ",<br />" : ', '; |
264 | 264 | } |
265 | 265 | } |
266 | - return implode( '', $args ); |
|
266 | + return implode('', $args); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | |
@@ -278,11 +278,11 @@ discard block |
||
278 | 278 | * @param string $line |
279 | 279 | * @return string |
280 | 280 | */ |
281 | - protected function generate_error_code( $file = '', $func = '', $line = '' ) { |
|
282 | - $file_bits = explode( '.', basename( $file ) ); |
|
283 | - $error_code = ! empty( $file_bits[0] ) ? $file_bits[0] : ''; |
|
284 | - $error_code .= ! empty( $func ) ? ' - ' . $func : ''; |
|
285 | - $error_code .= ! empty( $line ) ? ' - ' . $line : ''; |
|
281 | + protected function generate_error_code($file = '', $func = '', $line = '') { |
|
282 | + $file_bits = explode('.', basename($file)); |
|
283 | + $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
284 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
285 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
286 | 286 | return $error_code; |
287 | 287 | } |
288 | 288 | |
@@ -366,26 +366,26 @@ discard block |
||
366 | 366 | * @param bool $force_print |
367 | 367 | * @return string |
368 | 368 | */ |
369 | - private function printScripts( $force_print = false ) { |
|
370 | - if ( ! $force_print && ( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) ) ) { |
|
371 | - if ( wp_script_is( 'ee_error_js', 'enqueued' ) ) { |
|
369 | + private function printScripts($force_print = false) { |
|
370 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
371 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
372 | 372 | return ''; |
373 | - } else if ( wp_script_is( 'ee_error_js', 'registered' ) ) { |
|
374 | - add_filter( 'FHEE_load_css', '__return_true' ); |
|
375 | - add_filter( 'FHEE_load_js', '__return_true' ); |
|
376 | - wp_enqueue_script( 'ee_error_js' ); |
|
377 | - wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) ); |
|
373 | + } else if (wp_script_is('ee_error_js', 'registered')) { |
|
374 | + add_filter('FHEE_load_css', '__return_true'); |
|
375 | + add_filter('FHEE_load_js', '__return_true'); |
|
376 | + wp_enqueue_script('ee_error_js'); |
|
377 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
378 | 378 | } |
379 | 379 | } else { |
380 | 380 | return ' |
381 | 381 | <script> |
382 | 382 | /* <![CDATA[ */ |
383 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
383 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
384 | 384 | /* ]]> */ |
385 | 385 | </script> |
386 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
387 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
388 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
386 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
387 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
388 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
389 | 389 | '; |
390 | 390 | } |
391 | 391 | return ''; |
@@ -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 | |
@@ -15,737 +15,737 @@ discard block |
||
15 | 15 | class EE_Payment_Processor extends EE_Processor_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var EE_Payment_Processor $_instance |
|
20 | - * @access private |
|
21 | - */ |
|
22 | - private static $_instance; |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * @singleton method used to instantiate class object |
|
28 | - * @access public |
|
29 | - * @return EE_Payment_Processor instance |
|
30 | - */ |
|
31 | - public static function instance() |
|
32 | - { |
|
33 | - // check if class object is instantiated |
|
34 | - if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
35 | - self::$_instance = new self(); |
|
36 | - } |
|
37 | - return self::$_instance; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - *private constructor to prevent direct creation |
|
44 | - * |
|
45 | - * @Constructor |
|
46 | - * @access private |
|
47 | - */ |
|
48 | - private function __construct() |
|
49 | - { |
|
50 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
51 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
58 | - * appropriately. Saves the payment that is generated |
|
59 | - * |
|
60 | - * @param EE_Payment_Method $payment_method |
|
61 | - * @param EE_Transaction $transaction |
|
62 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
63 | - * Leave null if payment is for the full amount owing |
|
64 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
65 | - * Receive_form_submission() should have |
|
66 | - * already been called on the billing form |
|
67 | - * (ie, its inputs should have their normalized values set). |
|
68 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
69 | - * where to go AFTER the offsite gateway |
|
70 | - * @param string $method like 'CART', indicates who the client who called this was |
|
71 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
72 | - * @param boolean $update_txn whether or not to call |
|
73 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
74 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
75 | - * @return \EE_Payment |
|
76 | - * @throws \EE_Error |
|
77 | - */ |
|
78 | - public function process_payment( |
|
79 | - EE_Payment_Method $payment_method, |
|
80 | - EE_Transaction $transaction, |
|
81 | - $amount = null, |
|
82 | - $billing_form = null, |
|
83 | - $return_url = null, |
|
84 | - $method = 'CART', |
|
85 | - $by_admin = false, |
|
86 | - $update_txn = true, |
|
87 | - $cancel_url = '' |
|
88 | - ) { |
|
89 | - if ((float)$amount < 0) { |
|
90 | - throw new EE_Error( |
|
91 | - sprintf( |
|
92 | - __( |
|
93 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
94 | - 'event_espresso' |
|
95 | - ), |
|
96 | - $amount, |
|
97 | - $transaction->ID() |
|
98 | - ) |
|
99 | - ); |
|
100 | - } |
|
101 | - // verify payment method |
|
102 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
103 | - // verify transaction |
|
104 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
105 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
106 | - // verify payment method type |
|
107 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
108 | - $payment = $payment_method->type_obj()->process_payment( |
|
109 | - $transaction, |
|
110 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
111 | - $billing_form, |
|
112 | - $return_url, |
|
113 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
114 | - $method, |
|
115 | - $by_admin |
|
116 | - ); |
|
117 | - // check if payment method uses an off-site gateway |
|
118 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
119 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
120 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
121 | - } |
|
122 | - return $payment; |
|
123 | - } else { |
|
124 | - EE_Error::add_error( |
|
125 | - sprintf( |
|
126 | - __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
127 | - '<br/>', |
|
128 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
129 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
130 | - ); |
|
131 | - return null; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param EE_Transaction|int $transaction |
|
139 | - * @param EE_Payment_Method $payment_method |
|
140 | - * @throws EE_Error |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
144 | - { |
|
145 | - /** @type \EE_Transaction $transaction */ |
|
146 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
147 | - $primary_reg = $transaction->primary_registration(); |
|
148 | - if ( ! $primary_reg instanceof EE_Registration) { |
|
149 | - throw new EE_Error( |
|
150 | - sprintf( |
|
151 | - __( |
|
152 | - "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
153 | - "event_espresso" |
|
154 | - ), |
|
155 | - $transaction->ID() |
|
156 | - ) |
|
157 | - ); |
|
158 | - } |
|
159 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
160 | - $url = add_query_arg( |
|
161 | - array( |
|
162 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
163 | - 'ee_payment_method' => $payment_method->slug(), |
|
164 | - ), |
|
165 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
166 | - ); |
|
167 | - return $url; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
174 | - * we can easily find what registration the IPN is for and what payment method. |
|
175 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
176 | - * If a payment is found for the IPN info, it is saved. |
|
177 | - * |
|
178 | - * @param array $_req_data eg $_REQUEST |
|
179 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
180 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
181 | - * @param boolean $update_txn whether or not to call |
|
182 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
183 | - * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
184 | - * or is processed manually ( false like Mijireh ) |
|
185 | - * @throws EE_Error |
|
186 | - * @throws Exception |
|
187 | - * @return EE_Payment |
|
188 | - */ |
|
189 | - public function process_ipn( |
|
190 | - $_req_data, |
|
191 | - $transaction = null, |
|
192 | - $payment_method = null, |
|
193 | - $update_txn = true, |
|
194 | - $separate_IPN_request = true |
|
195 | - ) { |
|
196 | - EE_Registry::instance()->load_model('Change_Log'); |
|
197 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
198 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
199 | - $obj_for_log = null; |
|
200 | - if ($transaction instanceof EE_Transaction) { |
|
201 | - $obj_for_log = $transaction; |
|
202 | - if ($payment_method instanceof EE_Payment_Method) { |
|
203 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
204 | - array( |
|
205 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
206 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
207 | - ) |
|
208 | - ); |
|
209 | - } |
|
210 | - } else if ($payment_method instanceof EE_Payment) { |
|
211 | - $obj_for_log = $payment_method; |
|
212 | - } |
|
213 | - $log = EEM_Change_Log::instance()->log( |
|
214 | - EEM_Change_Log::type_gateway, |
|
215 | - array('IPN data received' => $_req_data), |
|
216 | - $obj_for_log |
|
217 | - ); |
|
218 | - try { |
|
219 | - /** |
|
220 | - * @var EE_Payment $payment |
|
221 | - */ |
|
222 | - $payment = null; |
|
223 | - if ($transaction && $payment_method) { |
|
224 | - /** @type EE_Transaction $transaction */ |
|
225 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
226 | - /** @type EE_Payment_Method $payment_method */ |
|
227 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
228 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
229 | - try { |
|
230 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
231 | - $log->set_object($payment); |
|
232 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
233 | - EEM_Change_Log::instance()->log( |
|
234 | - EEM_Change_Log::type_gateway, |
|
235 | - array( |
|
236 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
237 | - 'current_url' => EEH_URL::current_url(), |
|
238 | - 'payment' => $e->getPaymentProperties(), |
|
239 | - 'IPN_data' => $e->getIpnData(), |
|
240 | - ), |
|
241 | - $obj_for_log |
|
242 | - ); |
|
243 | - return $e->getPayment(); |
|
244 | - } |
|
245 | - } else { |
|
246 | - // not a payment |
|
247 | - EE_Error::add_error( |
|
248 | - sprintf( |
|
249 | - __('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.', 'event_espresso'), |
|
250 | - '<br/>', |
|
251 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
252 | - ), |
|
253 | - __FILE__, __FUNCTION__, __LINE__ |
|
254 | - ); |
|
255 | - } |
|
256 | - } else { |
|
257 | - //that's actually pretty ok. The IPN just wasn't able |
|
258 | - //to identify which transaction or payment method this was for |
|
259 | - // give all active payment methods a chance to claim it |
|
260 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
261 | - foreach ($active_payment_methods as $active_payment_method) { |
|
262 | - try { |
|
263 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
264 | - $payment_method = $active_payment_method; |
|
265 | - EEM_Change_Log::instance()->log( |
|
266 | - EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
267 | - ); |
|
268 | - break; |
|
269 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
270 | - EEM_Change_Log::instance()->log( |
|
271 | - EEM_Change_Log::type_gateway, |
|
272 | - array( |
|
273 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
274 | - 'current_url' => EEH_URL::current_url(), |
|
275 | - 'payment' => $e->getPaymentProperties(), |
|
276 | - 'IPN_data' => $e->getIpnData(), |
|
277 | - ), |
|
278 | - $obj_for_log |
|
279 | - ); |
|
280 | - return $e->getPayment(); |
|
281 | - } catch (EE_Error $e) { |
|
282 | - //that's fine- it apparently couldn't handle the IPN |
|
283 | - } |
|
284 | - } |
|
285 | - } |
|
286 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
287 | - if ($payment instanceof EE_Payment) { |
|
288 | - $payment->save(); |
|
289 | - // update the TXN |
|
290 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
291 | - } else { |
|
292 | - //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
293 | - if ($payment_method) { |
|
294 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
295 | - } elseif ($transaction) { |
|
296 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
297 | - } |
|
298 | - } |
|
299 | - return $payment; |
|
300 | - } catch (EE_Error $e) { |
|
301 | - do_action( |
|
302 | - 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
303 | - __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
304 | - print_r($transaction, true), |
|
305 | - print_r($_req_data, true), |
|
306 | - $e->getMessage() |
|
307 | - ) |
|
308 | - ); |
|
309 | - throw $e; |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Removes any non-printable illegal characters from the input, |
|
317 | - * which might cause a raucous when trying to insert into the database |
|
318 | - * |
|
319 | - * @param array $request_data |
|
320 | - * @return array |
|
321 | - */ |
|
322 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
323 | - { |
|
324 | - $return_data = array(); |
|
325 | - foreach ($request_data as $key => $value) { |
|
326 | - $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
327 | - } |
|
328 | - return $return_data; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Removes any non-printable illegal characters from the input, |
|
335 | - * which might cause a raucous when trying to insert into the database |
|
336 | - * |
|
337 | - * @param string $request_data |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - protected function _remove_unusable_characters($request_data) |
|
341 | - { |
|
342 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Should be called just before displaying the payment attempt results to the user, |
|
349 | - * when the payment attempt has finished. Some payment methods may have special |
|
350 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
351 | - * and then the user is redirected to a page that displays the payment's status, this |
|
352 | - * should be called while loading the page that displays the payment's status. If the user is |
|
353 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
354 | - * provider. |
|
355 | - * |
|
356 | - * @param EE_Transaction|int $transaction |
|
357 | - * @param bool $update_txn whether or not to call |
|
358 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
359 | - * @throws \EE_Error |
|
360 | - * @return EE_Payment |
|
361 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
362 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
363 | - */ |
|
364 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
365 | - { |
|
366 | - /** @var $transaction EE_Transaction */ |
|
367 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
368 | - $last_payment_method = $transaction->payment_method(); |
|
369 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
370 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
371 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
372 | - return $payment; |
|
373 | - } else { |
|
374 | - return null; |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
382 | - * |
|
383 | - * @param EE_Payment_Method $payment_method |
|
384 | - * @param EE_Payment $payment_to_refund |
|
385 | - * @param array $refund_info |
|
386 | - * @return EE_Payment |
|
387 | - * @throws \EE_Error |
|
388 | - */ |
|
389 | - public function process_refund( |
|
390 | - EE_Payment_Method $payment_method, |
|
391 | - EE_Payment $payment_to_refund, |
|
392 | - $refund_info = array() |
|
393 | - ) { |
|
394 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
395 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
396 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
397 | - } |
|
398 | - return $payment_to_refund; |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * This should be called each time there may have been an update to a |
|
405 | - * payment on a transaction (ie, we asked for a payment to process a |
|
406 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
407 | - * we told a payment method to |
|
408 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
409 | - * process a refund. This should handle firing the correct hooks to |
|
410 | - * indicate |
|
411 | - * what exactly happened and updating the transaction appropriately). This |
|
412 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
413 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
414 | - * of transactions and payments, and to be tied to payment processing. |
|
415 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
416 | - * of previous code to decide whether or not to save (because the payment passed into |
|
417 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
418 | - * in which case we only want that payment object for some temporary usage during this request, |
|
419 | - * but we don't want it to be saved). |
|
420 | - * |
|
421 | - * @param EE_Transaction|int $transaction |
|
422 | - * @param EE_Payment $payment |
|
423 | - * @param boolean $update_txn |
|
424 | - * whether or not to call |
|
425 | - * EE_Transaction_Processor:: |
|
426 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
427 | - * (you can save 1 DB query if you know you're going |
|
428 | - * to save it later instead) |
|
429 | - * @param bool $IPN |
|
430 | - * if processing IPNs or other similar payment |
|
431 | - * related activities that occur in alternate |
|
432 | - * requests than the main one that is processing the |
|
433 | - * TXN, then set this to true to check whether the |
|
434 | - * TXN is locked before updating |
|
435 | - * @throws \EE_Error |
|
436 | - */ |
|
437 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
438 | - { |
|
439 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
440 | - /** @type EE_Transaction $transaction */ |
|
441 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
442 | - // can we freely update the TXN at this moment? |
|
443 | - if ($IPN && $transaction->is_locked()) { |
|
444 | - // don't update the transaction at this exact moment |
|
445 | - // because the TXN is active in another request |
|
446 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
447 | - time(), |
|
448 | - $transaction->ID(), |
|
449 | - $payment->ID() |
|
450 | - ); |
|
451 | - } else { |
|
452 | - // verify payment and that it has been saved |
|
453 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
454 | - if ( |
|
455 | - $payment->payment_method() instanceof EE_Payment_Method |
|
456 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
457 | - ) { |
|
458 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
459 | - // update TXN registrations with payment info |
|
460 | - $this->process_registration_payments($transaction, $payment); |
|
461 | - } |
|
462 | - $do_action = $payment->just_approved() |
|
463 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
464 | - : $do_action; |
|
465 | - } else { |
|
466 | - // send out notifications |
|
467 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
468 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
469 | - } |
|
470 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
471 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
472 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
473 | - // set new value for total paid |
|
474 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
475 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
476 | - if ($update_txn) { |
|
477 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
478 | - } |
|
479 | - } |
|
480 | - // granular hook for others to use. |
|
481 | - do_action($do_action, $transaction, $payment); |
|
482 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
483 | - //global hook for others to use. |
|
484 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
485 | - } |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
492 | - * |
|
493 | - * @param EE_Transaction $transaction |
|
494 | - * @param EE_Payment $payment |
|
495 | - * @param EE_Registration[] $registrations |
|
496 | - * @throws \EE_Error |
|
497 | - */ |
|
498 | - public function process_registration_payments( |
|
499 | - EE_Transaction $transaction, |
|
500 | - EE_Payment $payment, |
|
501 | - $registrations = array() |
|
502 | - ) { |
|
503 | - // only process if payment was successful |
|
504 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
505 | - return; |
|
506 | - } |
|
507 | - //EEM_Registration::instance()->show_next_x_db_queries(); |
|
508 | - if (empty($registrations)) { |
|
509 | - // find registrations with monies owing that can receive a payment |
|
510 | - $registrations = $transaction->registrations( |
|
511 | - array( |
|
512 | - array( |
|
513 | - // only these reg statuses can receive payments |
|
514 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
515 | - 'REG_final_price' => array('!=', 0), |
|
516 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
517 | - ), |
|
518 | - ) |
|
519 | - ); |
|
520 | - } |
|
521 | - // still nothing ??!?? |
|
522 | - if (empty($registrations)) { |
|
523 | - return; |
|
524 | - } |
|
525 | - // todo: break out the following logic into a separate strategy class |
|
526 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
527 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
528 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
529 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
530 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
531 | - $refund = $payment->is_a_refund(); |
|
532 | - // how much is available to apply to registrations? |
|
533 | - $available_payment_amount = abs($payment->amount()); |
|
534 | - foreach ($registrations as $registration) { |
|
535 | - if ($registration instanceof EE_Registration) { |
|
536 | - // nothing left? |
|
537 | - if ($available_payment_amount <= 0) { |
|
538 | - break; |
|
539 | - } |
|
540 | - if ($refund) { |
|
541 | - $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
542 | - } else { |
|
543 | - $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
544 | - } |
|
545 | - } |
|
546 | - } |
|
547 | - if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
548 | - EE_Error::add_attention( |
|
549 | - sprintf( |
|
550 | - __('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).', |
|
551 | - 'event_espresso'), |
|
552 | - EEH_Template::format_currency($available_payment_amount), |
|
553 | - implode(', ', array_keys($registrations)), |
|
554 | - '<br/>', |
|
555 | - EEH_Template::format_currency($payment->amount()) |
|
556 | - ), |
|
557 | - __FILE__, __FUNCTION__, __LINE__ |
|
558 | - ); |
|
559 | - } |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * update registration REG_paid field after successful payment and link registration with payment |
|
566 | - * |
|
567 | - * @param EE_Registration $registration |
|
568 | - * @param EE_Payment $payment |
|
569 | - * @param float $available_payment_amount |
|
570 | - * @return float |
|
571 | - * @throws \EE_Error |
|
572 | - */ |
|
573 | - public function process_registration_payment( |
|
574 | - EE_Registration $registration, |
|
575 | - EE_Payment $payment, |
|
576 | - $available_payment_amount = 0.00 |
|
577 | - ) { |
|
578 | - $owing = $registration->final_price() - $registration->paid(); |
|
579 | - if ($owing > 0) { |
|
580 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
581 | - $payment_amount = min($available_payment_amount, $owing); |
|
582 | - // update $available_payment_amount |
|
583 | - $available_payment_amount -= $payment_amount; |
|
584 | - //calculate and set new REG_paid |
|
585 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
586 | - // now save it |
|
587 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
588 | - } |
|
589 | - return $available_payment_amount; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * update registration REG_paid field after successful payment and link registration with payment |
|
596 | - * |
|
597 | - * @param EE_Registration $registration |
|
598 | - * @param EE_Payment $payment |
|
599 | - * @param float $payment_amount |
|
600 | - * @return void |
|
601 | - * @throws \EE_Error |
|
602 | - */ |
|
603 | - protected function _apply_registration_payment( |
|
604 | - EE_Registration $registration, |
|
605 | - EE_Payment $payment, |
|
606 | - $payment_amount = 0.00 |
|
607 | - ) { |
|
608 | - // find any existing reg payment records for this registration and payment |
|
609 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
610 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
611 | - ); |
|
612 | - // if existing registration payment exists |
|
613 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
614 | - // then update that record |
|
615 | - $existing_reg_payment->set_amount($payment_amount); |
|
616 | - $existing_reg_payment->save(); |
|
617 | - } else { |
|
618 | - // or add new relation between registration and payment and set amount |
|
619 | - $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
620 | - // make it stick |
|
621 | - $registration->save(); |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * update registration REG_paid field after refund and link registration with payment |
|
629 | - * |
|
630 | - * @param EE_Registration $registration |
|
631 | - * @param EE_Payment $payment |
|
632 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
633 | - * @return float |
|
634 | - * @throws \EE_Error |
|
635 | - */ |
|
636 | - public function process_registration_refund( |
|
637 | - EE_Registration $registration, |
|
638 | - EE_Payment $payment, |
|
639 | - $available_refund_amount = 0.00 |
|
640 | - ) { |
|
641 | - //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
642 | - if ($registration->paid() > 0) { |
|
643 | - // ensure $available_refund_amount is NOT negative |
|
644 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
645 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
646 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
647 | - // update $available_payment_amount |
|
648 | - $available_refund_amount -= $refund_amount; |
|
649 | - //calculate and set new REG_paid |
|
650 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
651 | - // convert payment amount back to a negative value for storage in the db |
|
652 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
653 | - // now save it |
|
654 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
655 | - } |
|
656 | - return $available_refund_amount; |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * Process payments and transaction after payment process completed. |
|
663 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
664 | - * if this request happens to be processing an IPN, |
|
665 | - * then we will also set the Payment Options Reg Step to completed, |
|
666 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
667 | - * |
|
668 | - * @param EE_Transaction $transaction |
|
669 | - * @param EE_Payment $payment |
|
670 | - * @param bool $IPN |
|
671 | - * @throws \EE_Error |
|
672 | - */ |
|
673 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
674 | - { |
|
675 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
676 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
677 | - // is the Payment Options Reg Step completed ? |
|
678 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
679 | - // if the Payment Options Reg Step is completed... |
|
680 | - $revisit = $payment_options_step_completed === true ? true : false; |
|
681 | - // then this is kinda sorta a revisit with regards to payments at least |
|
682 | - $transaction_processor->set_revisit($revisit); |
|
683 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
684 | - if ( |
|
685 | - $IPN |
|
686 | - && $payment_options_step_completed !== true |
|
687 | - && ($payment->is_approved() || $payment->is_pending()) |
|
688 | - ) { |
|
689 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
690 | - 'payment_options' |
|
691 | - ); |
|
692 | - } |
|
693 | - // maybe update status, but don't save transaction just yet |
|
694 | - $transaction->update_status_based_on_total_paid(false); |
|
695 | - // check if 'finalize_registration' step has been completed... |
|
696 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
697 | - // if this is an IPN and the final step has not been initiated |
|
698 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
699 | - // and if it hasn't already been set as being started... |
|
700 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
701 | - } |
|
702 | - $transaction->save(); |
|
703 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
704 | - if ($IPN && $finalized !== false) { |
|
705 | - // and if we are all good to go, then send out notifications |
|
706 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
707 | - //ok, now process the transaction according to the payment |
|
708 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
709 | - } |
|
710 | - // DEBUG LOG |
|
711 | - $payment_method = $payment->payment_method(); |
|
712 | - if ($payment_method instanceof EE_Payment_Method) { |
|
713 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
714 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
715 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
716 | - if ($gateway instanceof EE_Gateway) { |
|
717 | - $gateway->log( |
|
718 | - array( |
|
719 | - 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
720 | - 'transaction' => $transaction->model_field_array(), |
|
721 | - 'finalized' => $finalized, |
|
722 | - 'IPN' => $IPN, |
|
723 | - 'deliver_notifications' => has_filter( |
|
724 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
725 | - ), |
|
726 | - ), |
|
727 | - $payment |
|
728 | - ); |
|
729 | - } |
|
730 | - } |
|
731 | - } |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * Force posts to PayPal to use TLS v1.2. See: |
|
738 | - * https://core.trac.wordpress.org/ticket/36320 |
|
739 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
740 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
741 | - * This will affect paypal standard, pro, express, and payflow. |
|
742 | - */ |
|
743 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
744 | - { |
|
745 | - if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
746 | - //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
747 | - //instead of the constant because it might not be defined |
|
748 | - curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
749 | - } |
|
750 | - } |
|
18 | + /** |
|
19 | + * @var EE_Payment_Processor $_instance |
|
20 | + * @access private |
|
21 | + */ |
|
22 | + private static $_instance; |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * @singleton method used to instantiate class object |
|
28 | + * @access public |
|
29 | + * @return EE_Payment_Processor instance |
|
30 | + */ |
|
31 | + public static function instance() |
|
32 | + { |
|
33 | + // check if class object is instantiated |
|
34 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
35 | + self::$_instance = new self(); |
|
36 | + } |
|
37 | + return self::$_instance; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + *private constructor to prevent direct creation |
|
44 | + * |
|
45 | + * @Constructor |
|
46 | + * @access private |
|
47 | + */ |
|
48 | + private function __construct() |
|
49 | + { |
|
50 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
51 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
58 | + * appropriately. Saves the payment that is generated |
|
59 | + * |
|
60 | + * @param EE_Payment_Method $payment_method |
|
61 | + * @param EE_Transaction $transaction |
|
62 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
63 | + * Leave null if payment is for the full amount owing |
|
64 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
65 | + * Receive_form_submission() should have |
|
66 | + * already been called on the billing form |
|
67 | + * (ie, its inputs should have their normalized values set). |
|
68 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
69 | + * where to go AFTER the offsite gateway |
|
70 | + * @param string $method like 'CART', indicates who the client who called this was |
|
71 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
72 | + * @param boolean $update_txn whether or not to call |
|
73 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
74 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
75 | + * @return \EE_Payment |
|
76 | + * @throws \EE_Error |
|
77 | + */ |
|
78 | + public function process_payment( |
|
79 | + EE_Payment_Method $payment_method, |
|
80 | + EE_Transaction $transaction, |
|
81 | + $amount = null, |
|
82 | + $billing_form = null, |
|
83 | + $return_url = null, |
|
84 | + $method = 'CART', |
|
85 | + $by_admin = false, |
|
86 | + $update_txn = true, |
|
87 | + $cancel_url = '' |
|
88 | + ) { |
|
89 | + if ((float)$amount < 0) { |
|
90 | + throw new EE_Error( |
|
91 | + sprintf( |
|
92 | + __( |
|
93 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
94 | + 'event_espresso' |
|
95 | + ), |
|
96 | + $amount, |
|
97 | + $transaction->ID() |
|
98 | + ) |
|
99 | + ); |
|
100 | + } |
|
101 | + // verify payment method |
|
102 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
103 | + // verify transaction |
|
104 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
105 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
106 | + // verify payment method type |
|
107 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
108 | + $payment = $payment_method->type_obj()->process_payment( |
|
109 | + $transaction, |
|
110 | + min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
111 | + $billing_form, |
|
112 | + $return_url, |
|
113 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
114 | + $method, |
|
115 | + $by_admin |
|
116 | + ); |
|
117 | + // check if payment method uses an off-site gateway |
|
118 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
119 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
120 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
121 | + } |
|
122 | + return $payment; |
|
123 | + } else { |
|
124 | + EE_Error::add_error( |
|
125 | + sprintf( |
|
126 | + __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
127 | + '<br/>', |
|
128 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
129 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
130 | + ); |
|
131 | + return null; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param EE_Transaction|int $transaction |
|
139 | + * @param EE_Payment_Method $payment_method |
|
140 | + * @throws EE_Error |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
144 | + { |
|
145 | + /** @type \EE_Transaction $transaction */ |
|
146 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
147 | + $primary_reg = $transaction->primary_registration(); |
|
148 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
149 | + throw new EE_Error( |
|
150 | + sprintf( |
|
151 | + __( |
|
152 | + "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
153 | + "event_espresso" |
|
154 | + ), |
|
155 | + $transaction->ID() |
|
156 | + ) |
|
157 | + ); |
|
158 | + } |
|
159 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
160 | + $url = add_query_arg( |
|
161 | + array( |
|
162 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
163 | + 'ee_payment_method' => $payment_method->slug(), |
|
164 | + ), |
|
165 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
166 | + ); |
|
167 | + return $url; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
174 | + * we can easily find what registration the IPN is for and what payment method. |
|
175 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
176 | + * If a payment is found for the IPN info, it is saved. |
|
177 | + * |
|
178 | + * @param array $_req_data eg $_REQUEST |
|
179 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
180 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
181 | + * @param boolean $update_txn whether or not to call |
|
182 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
183 | + * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
184 | + * or is processed manually ( false like Mijireh ) |
|
185 | + * @throws EE_Error |
|
186 | + * @throws Exception |
|
187 | + * @return EE_Payment |
|
188 | + */ |
|
189 | + public function process_ipn( |
|
190 | + $_req_data, |
|
191 | + $transaction = null, |
|
192 | + $payment_method = null, |
|
193 | + $update_txn = true, |
|
194 | + $separate_IPN_request = true |
|
195 | + ) { |
|
196 | + EE_Registry::instance()->load_model('Change_Log'); |
|
197 | + $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
198 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
199 | + $obj_for_log = null; |
|
200 | + if ($transaction instanceof EE_Transaction) { |
|
201 | + $obj_for_log = $transaction; |
|
202 | + if ($payment_method instanceof EE_Payment_Method) { |
|
203 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
204 | + array( |
|
205 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
206 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
207 | + ) |
|
208 | + ); |
|
209 | + } |
|
210 | + } else if ($payment_method instanceof EE_Payment) { |
|
211 | + $obj_for_log = $payment_method; |
|
212 | + } |
|
213 | + $log = EEM_Change_Log::instance()->log( |
|
214 | + EEM_Change_Log::type_gateway, |
|
215 | + array('IPN data received' => $_req_data), |
|
216 | + $obj_for_log |
|
217 | + ); |
|
218 | + try { |
|
219 | + /** |
|
220 | + * @var EE_Payment $payment |
|
221 | + */ |
|
222 | + $payment = null; |
|
223 | + if ($transaction && $payment_method) { |
|
224 | + /** @type EE_Transaction $transaction */ |
|
225 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
226 | + /** @type EE_Payment_Method $payment_method */ |
|
227 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
228 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
229 | + try { |
|
230 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
231 | + $log->set_object($payment); |
|
232 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
233 | + EEM_Change_Log::instance()->log( |
|
234 | + EEM_Change_Log::type_gateway, |
|
235 | + array( |
|
236 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
237 | + 'current_url' => EEH_URL::current_url(), |
|
238 | + 'payment' => $e->getPaymentProperties(), |
|
239 | + 'IPN_data' => $e->getIpnData(), |
|
240 | + ), |
|
241 | + $obj_for_log |
|
242 | + ); |
|
243 | + return $e->getPayment(); |
|
244 | + } |
|
245 | + } else { |
|
246 | + // not a payment |
|
247 | + EE_Error::add_error( |
|
248 | + sprintf( |
|
249 | + __('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.', 'event_espresso'), |
|
250 | + '<br/>', |
|
251 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
252 | + ), |
|
253 | + __FILE__, __FUNCTION__, __LINE__ |
|
254 | + ); |
|
255 | + } |
|
256 | + } else { |
|
257 | + //that's actually pretty ok. The IPN just wasn't able |
|
258 | + //to identify which transaction or payment method this was for |
|
259 | + // give all active payment methods a chance to claim it |
|
260 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
261 | + foreach ($active_payment_methods as $active_payment_method) { |
|
262 | + try { |
|
263 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
264 | + $payment_method = $active_payment_method; |
|
265 | + EEM_Change_Log::instance()->log( |
|
266 | + EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
267 | + ); |
|
268 | + break; |
|
269 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
270 | + EEM_Change_Log::instance()->log( |
|
271 | + EEM_Change_Log::type_gateway, |
|
272 | + array( |
|
273 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
274 | + 'current_url' => EEH_URL::current_url(), |
|
275 | + 'payment' => $e->getPaymentProperties(), |
|
276 | + 'IPN_data' => $e->getIpnData(), |
|
277 | + ), |
|
278 | + $obj_for_log |
|
279 | + ); |
|
280 | + return $e->getPayment(); |
|
281 | + } catch (EE_Error $e) { |
|
282 | + //that's fine- it apparently couldn't handle the IPN |
|
283 | + } |
|
284 | + } |
|
285 | + } |
|
286 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
287 | + if ($payment instanceof EE_Payment) { |
|
288 | + $payment->save(); |
|
289 | + // update the TXN |
|
290 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
291 | + } else { |
|
292 | + //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
293 | + if ($payment_method) { |
|
294 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
295 | + } elseif ($transaction) { |
|
296 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
297 | + } |
|
298 | + } |
|
299 | + return $payment; |
|
300 | + } catch (EE_Error $e) { |
|
301 | + do_action( |
|
302 | + 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
303 | + __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
304 | + print_r($transaction, true), |
|
305 | + print_r($_req_data, true), |
|
306 | + $e->getMessage() |
|
307 | + ) |
|
308 | + ); |
|
309 | + throw $e; |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Removes any non-printable illegal characters from the input, |
|
317 | + * which might cause a raucous when trying to insert into the database |
|
318 | + * |
|
319 | + * @param array $request_data |
|
320 | + * @return array |
|
321 | + */ |
|
322 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
323 | + { |
|
324 | + $return_data = array(); |
|
325 | + foreach ($request_data as $key => $value) { |
|
326 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
327 | + } |
|
328 | + return $return_data; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Removes any non-printable illegal characters from the input, |
|
335 | + * which might cause a raucous when trying to insert into the database |
|
336 | + * |
|
337 | + * @param string $request_data |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + protected function _remove_unusable_characters($request_data) |
|
341 | + { |
|
342 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Should be called just before displaying the payment attempt results to the user, |
|
349 | + * when the payment attempt has finished. Some payment methods may have special |
|
350 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
351 | + * and then the user is redirected to a page that displays the payment's status, this |
|
352 | + * should be called while loading the page that displays the payment's status. If the user is |
|
353 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
354 | + * provider. |
|
355 | + * |
|
356 | + * @param EE_Transaction|int $transaction |
|
357 | + * @param bool $update_txn whether or not to call |
|
358 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
359 | + * @throws \EE_Error |
|
360 | + * @return EE_Payment |
|
361 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
362 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
363 | + */ |
|
364 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
365 | + { |
|
366 | + /** @var $transaction EE_Transaction */ |
|
367 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
368 | + $last_payment_method = $transaction->payment_method(); |
|
369 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
370 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
371 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
372 | + return $payment; |
|
373 | + } else { |
|
374 | + return null; |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
382 | + * |
|
383 | + * @param EE_Payment_Method $payment_method |
|
384 | + * @param EE_Payment $payment_to_refund |
|
385 | + * @param array $refund_info |
|
386 | + * @return EE_Payment |
|
387 | + * @throws \EE_Error |
|
388 | + */ |
|
389 | + public function process_refund( |
|
390 | + EE_Payment_Method $payment_method, |
|
391 | + EE_Payment $payment_to_refund, |
|
392 | + $refund_info = array() |
|
393 | + ) { |
|
394 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
395 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
396 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
397 | + } |
|
398 | + return $payment_to_refund; |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * This should be called each time there may have been an update to a |
|
405 | + * payment on a transaction (ie, we asked for a payment to process a |
|
406 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
407 | + * we told a payment method to |
|
408 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
409 | + * process a refund. This should handle firing the correct hooks to |
|
410 | + * indicate |
|
411 | + * what exactly happened and updating the transaction appropriately). This |
|
412 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
413 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
414 | + * of transactions and payments, and to be tied to payment processing. |
|
415 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
416 | + * of previous code to decide whether or not to save (because the payment passed into |
|
417 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
418 | + * in which case we only want that payment object for some temporary usage during this request, |
|
419 | + * but we don't want it to be saved). |
|
420 | + * |
|
421 | + * @param EE_Transaction|int $transaction |
|
422 | + * @param EE_Payment $payment |
|
423 | + * @param boolean $update_txn |
|
424 | + * whether or not to call |
|
425 | + * EE_Transaction_Processor:: |
|
426 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
427 | + * (you can save 1 DB query if you know you're going |
|
428 | + * to save it later instead) |
|
429 | + * @param bool $IPN |
|
430 | + * if processing IPNs or other similar payment |
|
431 | + * related activities that occur in alternate |
|
432 | + * requests than the main one that is processing the |
|
433 | + * TXN, then set this to true to check whether the |
|
434 | + * TXN is locked before updating |
|
435 | + * @throws \EE_Error |
|
436 | + */ |
|
437 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
438 | + { |
|
439 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
440 | + /** @type EE_Transaction $transaction */ |
|
441 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
442 | + // can we freely update the TXN at this moment? |
|
443 | + if ($IPN && $transaction->is_locked()) { |
|
444 | + // don't update the transaction at this exact moment |
|
445 | + // because the TXN is active in another request |
|
446 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
447 | + time(), |
|
448 | + $transaction->ID(), |
|
449 | + $payment->ID() |
|
450 | + ); |
|
451 | + } else { |
|
452 | + // verify payment and that it has been saved |
|
453 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
454 | + if ( |
|
455 | + $payment->payment_method() instanceof EE_Payment_Method |
|
456 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
457 | + ) { |
|
458 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
459 | + // update TXN registrations with payment info |
|
460 | + $this->process_registration_payments($transaction, $payment); |
|
461 | + } |
|
462 | + $do_action = $payment->just_approved() |
|
463 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
464 | + : $do_action; |
|
465 | + } else { |
|
466 | + // send out notifications |
|
467 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
468 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
469 | + } |
|
470 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
471 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
472 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
473 | + // set new value for total paid |
|
474 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
475 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
476 | + if ($update_txn) { |
|
477 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
478 | + } |
|
479 | + } |
|
480 | + // granular hook for others to use. |
|
481 | + do_action($do_action, $transaction, $payment); |
|
482 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
483 | + //global hook for others to use. |
|
484 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
485 | + } |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
492 | + * |
|
493 | + * @param EE_Transaction $transaction |
|
494 | + * @param EE_Payment $payment |
|
495 | + * @param EE_Registration[] $registrations |
|
496 | + * @throws \EE_Error |
|
497 | + */ |
|
498 | + public function process_registration_payments( |
|
499 | + EE_Transaction $transaction, |
|
500 | + EE_Payment $payment, |
|
501 | + $registrations = array() |
|
502 | + ) { |
|
503 | + // only process if payment was successful |
|
504 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
505 | + return; |
|
506 | + } |
|
507 | + //EEM_Registration::instance()->show_next_x_db_queries(); |
|
508 | + if (empty($registrations)) { |
|
509 | + // find registrations with monies owing that can receive a payment |
|
510 | + $registrations = $transaction->registrations( |
|
511 | + array( |
|
512 | + array( |
|
513 | + // only these reg statuses can receive payments |
|
514 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
515 | + 'REG_final_price' => array('!=', 0), |
|
516 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
517 | + ), |
|
518 | + ) |
|
519 | + ); |
|
520 | + } |
|
521 | + // still nothing ??!?? |
|
522 | + if (empty($registrations)) { |
|
523 | + return; |
|
524 | + } |
|
525 | + // todo: break out the following logic into a separate strategy class |
|
526 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
527 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
528 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
529 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
530 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
531 | + $refund = $payment->is_a_refund(); |
|
532 | + // how much is available to apply to registrations? |
|
533 | + $available_payment_amount = abs($payment->amount()); |
|
534 | + foreach ($registrations as $registration) { |
|
535 | + if ($registration instanceof EE_Registration) { |
|
536 | + // nothing left? |
|
537 | + if ($available_payment_amount <= 0) { |
|
538 | + break; |
|
539 | + } |
|
540 | + if ($refund) { |
|
541 | + $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
542 | + } else { |
|
543 | + $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
544 | + } |
|
545 | + } |
|
546 | + } |
|
547 | + if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
548 | + EE_Error::add_attention( |
|
549 | + sprintf( |
|
550 | + __('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).', |
|
551 | + 'event_espresso'), |
|
552 | + EEH_Template::format_currency($available_payment_amount), |
|
553 | + implode(', ', array_keys($registrations)), |
|
554 | + '<br/>', |
|
555 | + EEH_Template::format_currency($payment->amount()) |
|
556 | + ), |
|
557 | + __FILE__, __FUNCTION__, __LINE__ |
|
558 | + ); |
|
559 | + } |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * update registration REG_paid field after successful payment and link registration with payment |
|
566 | + * |
|
567 | + * @param EE_Registration $registration |
|
568 | + * @param EE_Payment $payment |
|
569 | + * @param float $available_payment_amount |
|
570 | + * @return float |
|
571 | + * @throws \EE_Error |
|
572 | + */ |
|
573 | + public function process_registration_payment( |
|
574 | + EE_Registration $registration, |
|
575 | + EE_Payment $payment, |
|
576 | + $available_payment_amount = 0.00 |
|
577 | + ) { |
|
578 | + $owing = $registration->final_price() - $registration->paid(); |
|
579 | + if ($owing > 0) { |
|
580 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
581 | + $payment_amount = min($available_payment_amount, $owing); |
|
582 | + // update $available_payment_amount |
|
583 | + $available_payment_amount -= $payment_amount; |
|
584 | + //calculate and set new REG_paid |
|
585 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
586 | + // now save it |
|
587 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
588 | + } |
|
589 | + return $available_payment_amount; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * update registration REG_paid field after successful payment and link registration with payment |
|
596 | + * |
|
597 | + * @param EE_Registration $registration |
|
598 | + * @param EE_Payment $payment |
|
599 | + * @param float $payment_amount |
|
600 | + * @return void |
|
601 | + * @throws \EE_Error |
|
602 | + */ |
|
603 | + protected function _apply_registration_payment( |
|
604 | + EE_Registration $registration, |
|
605 | + EE_Payment $payment, |
|
606 | + $payment_amount = 0.00 |
|
607 | + ) { |
|
608 | + // find any existing reg payment records for this registration and payment |
|
609 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
610 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
611 | + ); |
|
612 | + // if existing registration payment exists |
|
613 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
614 | + // then update that record |
|
615 | + $existing_reg_payment->set_amount($payment_amount); |
|
616 | + $existing_reg_payment->save(); |
|
617 | + } else { |
|
618 | + // or add new relation between registration and payment and set amount |
|
619 | + $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
620 | + // make it stick |
|
621 | + $registration->save(); |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * update registration REG_paid field after refund and link registration with payment |
|
629 | + * |
|
630 | + * @param EE_Registration $registration |
|
631 | + * @param EE_Payment $payment |
|
632 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
633 | + * @return float |
|
634 | + * @throws \EE_Error |
|
635 | + */ |
|
636 | + public function process_registration_refund( |
|
637 | + EE_Registration $registration, |
|
638 | + EE_Payment $payment, |
|
639 | + $available_refund_amount = 0.00 |
|
640 | + ) { |
|
641 | + //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
642 | + if ($registration->paid() > 0) { |
|
643 | + // ensure $available_refund_amount is NOT negative |
|
644 | + $available_refund_amount = (float)abs($available_refund_amount); |
|
645 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
646 | + $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
647 | + // update $available_payment_amount |
|
648 | + $available_refund_amount -= $refund_amount; |
|
649 | + //calculate and set new REG_paid |
|
650 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
651 | + // convert payment amount back to a negative value for storage in the db |
|
652 | + $refund_amount = (float)abs($refund_amount) * -1; |
|
653 | + // now save it |
|
654 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
655 | + } |
|
656 | + return $available_refund_amount; |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * Process payments and transaction after payment process completed. |
|
663 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
664 | + * if this request happens to be processing an IPN, |
|
665 | + * then we will also set the Payment Options Reg Step to completed, |
|
666 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
667 | + * |
|
668 | + * @param EE_Transaction $transaction |
|
669 | + * @param EE_Payment $payment |
|
670 | + * @param bool $IPN |
|
671 | + * @throws \EE_Error |
|
672 | + */ |
|
673 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
674 | + { |
|
675 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
676 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
677 | + // is the Payment Options Reg Step completed ? |
|
678 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
679 | + // if the Payment Options Reg Step is completed... |
|
680 | + $revisit = $payment_options_step_completed === true ? true : false; |
|
681 | + // then this is kinda sorta a revisit with regards to payments at least |
|
682 | + $transaction_processor->set_revisit($revisit); |
|
683 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
684 | + if ( |
|
685 | + $IPN |
|
686 | + && $payment_options_step_completed !== true |
|
687 | + && ($payment->is_approved() || $payment->is_pending()) |
|
688 | + ) { |
|
689 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
690 | + 'payment_options' |
|
691 | + ); |
|
692 | + } |
|
693 | + // maybe update status, but don't save transaction just yet |
|
694 | + $transaction->update_status_based_on_total_paid(false); |
|
695 | + // check if 'finalize_registration' step has been completed... |
|
696 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
697 | + // if this is an IPN and the final step has not been initiated |
|
698 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
699 | + // and if it hasn't already been set as being started... |
|
700 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
701 | + } |
|
702 | + $transaction->save(); |
|
703 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
704 | + if ($IPN && $finalized !== false) { |
|
705 | + // and if we are all good to go, then send out notifications |
|
706 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
707 | + //ok, now process the transaction according to the payment |
|
708 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
709 | + } |
|
710 | + // DEBUG LOG |
|
711 | + $payment_method = $payment->payment_method(); |
|
712 | + if ($payment_method instanceof EE_Payment_Method) { |
|
713 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
714 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
715 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
716 | + if ($gateway instanceof EE_Gateway) { |
|
717 | + $gateway->log( |
|
718 | + array( |
|
719 | + 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
720 | + 'transaction' => $transaction->model_field_array(), |
|
721 | + 'finalized' => $finalized, |
|
722 | + 'IPN' => $IPN, |
|
723 | + 'deliver_notifications' => has_filter( |
|
724 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
725 | + ), |
|
726 | + ), |
|
727 | + $payment |
|
728 | + ); |
|
729 | + } |
|
730 | + } |
|
731 | + } |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * Force posts to PayPal to use TLS v1.2. See: |
|
738 | + * https://core.trac.wordpress.org/ticket/36320 |
|
739 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
740 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
741 | + * This will affect paypal standard, pro, express, and payflow. |
|
742 | + */ |
|
743 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
744 | + { |
|
745 | + if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
746 | + //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
747 | + //instead of the constant because it might not be defined |
|
748 | + curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
749 | + } |
|
750 | + } |
|
751 | 751 | } |
@@ -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 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
5 | 5 | |
@@ -20,418 +20,418 @@ discard block |
||
20 | 20 | class EE_Cart |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * instance of the EE_Cart object |
|
25 | - * |
|
26 | - * @access private |
|
27 | - * @var EE_Cart $_instance |
|
28 | - */ |
|
29 | - private static $_instance; |
|
30 | - |
|
31 | - /** |
|
32 | - * instance of the EE_Session object |
|
33 | - * |
|
34 | - * @access protected |
|
35 | - * @var EE_Session $_session |
|
36 | - */ |
|
37 | - protected $_session; |
|
38 | - |
|
39 | - /** |
|
40 | - * The total Line item which comprises all the children line-item subtotals, |
|
41 | - * which in turn each have their line items. |
|
42 | - * Typically, the line item structure will look like: |
|
43 | - * grand total |
|
44 | - * -tickets-sub-total |
|
45 | - * --ticket1 |
|
46 | - * --ticket2 |
|
47 | - * --... |
|
48 | - * -taxes-sub-total |
|
49 | - * --tax1 |
|
50 | - * --tax2 |
|
51 | - * |
|
52 | - * @var EE_Line_Item |
|
53 | - */ |
|
54 | - private $_grand_total; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @singleton method used to instantiate class object |
|
60 | - * @access public |
|
61 | - * @param EE_Line_Item $grand_total |
|
62 | - * @param EE_Session $session |
|
63 | - * @return \EE_Cart |
|
64 | - * @throws \EE_Error |
|
65 | - */ |
|
66 | - public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
67 | - { |
|
68 | - if ( ! empty($grand_total)) { |
|
69 | - self::$_instance = new self($grand_total, $session); |
|
70 | - } |
|
71 | - // or maybe retrieve an existing one ? |
|
72 | - if ( ! self::$_instance instanceof EE_Cart) { |
|
73 | - // try getting the cart out of the session |
|
74 | - $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
75 | - self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
76 | - unset($saved_cart); |
|
77 | - } |
|
78 | - // verify that cart is ok and grand total line item exists |
|
79 | - if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
80 | - self::$_instance = new self($grand_total, $session); |
|
81 | - } |
|
82 | - self::$_instance->get_grand_total(); |
|
83 | - // once everything is all said and done, save the cart to the EE_Session |
|
84 | - add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
85 | - return self::$_instance; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * private constructor to prevent direct creation |
|
92 | - * |
|
93 | - * @Constructor |
|
94 | - * @access private |
|
95 | - * @param EE_Line_Item $grand_total |
|
96 | - * @param EE_Session $session |
|
97 | - */ |
|
98 | - private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
99 | - { |
|
100 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
101 | - $this->set_session($session); |
|
102 | - if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
103 | - $this->set_grand_total_line_item($grand_total); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * Resets the cart completely (whereas empty_cart |
|
111 | - * |
|
112 | - * @param EE_Line_Item $grand_total |
|
113 | - * @param EE_Session $session |
|
114 | - * @return EE_Cart |
|
115 | - * @throws \EE_Error |
|
116 | - */ |
|
117 | - public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
118 | - { |
|
119 | - remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
120 | - if ($session instanceof EE_Session) { |
|
121 | - $session->reset_cart(); |
|
122 | - } |
|
123 | - self::$_instance = null; |
|
124 | - return self::instance($grand_total, $session); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @return \EE_Session |
|
131 | - */ |
|
132 | - public function session() |
|
133 | - { |
|
134 | - if ( ! $this->_session instanceof EE_Session) { |
|
135 | - $this->set_session(); |
|
136 | - } |
|
137 | - return $this->_session; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param EE_Session $session |
|
144 | - */ |
|
145 | - public function set_session(EE_Session $session = null) |
|
146 | - { |
|
147 | - $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
154 | - * know the grand total line item on it |
|
155 | - * |
|
156 | - * @param EE_Line_Item $line_item |
|
157 | - */ |
|
158 | - public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
159 | - { |
|
160 | - $this->_grand_total = $line_item; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * get_cart_from_reg_url_link |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @param EE_Transaction $transaction |
|
170 | - * @param EE_Session $session |
|
171 | - * @return \EE_Cart |
|
172 | - * @throws \EE_Error |
|
173 | - */ |
|
174 | - public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
175 | - { |
|
176 | - $grand_total = $transaction->total_line_item(); |
|
177 | - $grand_total->get_items(); |
|
178 | - $grand_total->tax_descendants(); |
|
179 | - return EE_Cart::instance($grand_total, $session); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
186 | - * |
|
187 | - * @return EE_Line_Item |
|
188 | - * @throws \EE_Error |
|
189 | - */ |
|
190 | - private function _create_grand_total() |
|
191 | - { |
|
192 | - $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
193 | - return $this->_grand_total; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Gets all the line items of object type Ticket |
|
200 | - * |
|
201 | - * @access public |
|
202 | - * @return \EE_Line_Item[] |
|
203 | - */ |
|
204 | - public function get_tickets() |
|
205 | - { |
|
206 | - if ($this->_grand_total === null ) { |
|
207 | - return array(); |
|
208 | - } |
|
209 | - return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * returns the total quantity of tickets in the cart |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @return int |
|
219 | - * @throws \EE_Error |
|
220 | - */ |
|
221 | - public function all_ticket_quantity_count() |
|
222 | - { |
|
223 | - $tickets = $this->get_tickets(); |
|
224 | - if (empty($tickets)) { |
|
225 | - return 0; |
|
226 | - } |
|
227 | - $count = 0; |
|
228 | - foreach ($tickets as $ticket) { |
|
229 | - $count += $ticket->get('LIN_quantity'); |
|
230 | - } |
|
231 | - return $count; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Gets all the tax line items |
|
238 | - * |
|
239 | - * @return \EE_Line_Item[] |
|
240 | - * @throws \EE_Error |
|
241 | - */ |
|
242 | - public function get_taxes() |
|
243 | - { |
|
244 | - return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Gets the total line item (which is a parent of all other line items) on this cart |
|
251 | - * |
|
252 | - * @return EE_Line_Item |
|
253 | - * @throws \EE_Error |
|
254 | - */ |
|
255 | - public function get_grand_total() |
|
256 | - { |
|
257 | - return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @process items for adding to cart |
|
264 | - * @access public |
|
265 | - * @param EE_Ticket $ticket |
|
266 | - * @param int $qty |
|
267 | - * @return TRUE on success, FALSE on fail |
|
268 | - * @throws \EE_Error |
|
269 | - */ |
|
270 | - public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
271 | - { |
|
272 | - EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
273 | - return $this->save_cart() ? true : false; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * get_cart_total_before_tax |
|
280 | - * |
|
281 | - * @access public |
|
282 | - * @return float |
|
283 | - * @throws \EE_Error |
|
284 | - */ |
|
285 | - public function get_cart_total_before_tax() |
|
286 | - { |
|
287 | - return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * gets the total amount of tax paid for items in this cart |
|
294 | - * |
|
295 | - * @access public |
|
296 | - * @return float |
|
297 | - * @throws \EE_Error |
|
298 | - */ |
|
299 | - public function get_applied_taxes() |
|
300 | - { |
|
301 | - return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
308 | - * |
|
309 | - * @access public |
|
310 | - * @return float |
|
311 | - * @throws \EE_Error |
|
312 | - */ |
|
313 | - public function get_cart_grand_total() |
|
314 | - { |
|
315 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
316 | - return $this->get_grand_total()->total(); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
323 | - * |
|
324 | - * @access public |
|
325 | - * @return float |
|
326 | - * @throws \EE_Error |
|
327 | - */ |
|
328 | - public function recalculate_all_cart_totals() |
|
329 | - { |
|
330 | - $pre_tax_total = $this->get_cart_total_before_tax(); |
|
331 | - $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
332 | - $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
333 | - $this->_grand_total->save_this_and_descendants_to_txn(); |
|
334 | - return $this->get_grand_total()->total(); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * deletes an item from the cart |
|
341 | - * |
|
342 | - * @access public |
|
343 | - * @param array|bool|string $line_item_codes |
|
344 | - * @return int on success, FALSE on fail |
|
345 | - * @throws \EE_Error |
|
346 | - */ |
|
347 | - public function delete_items($line_item_codes = false) |
|
348 | - { |
|
349 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
350 | - return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * @remove ALL items from cart and zero ALL totals |
|
357 | - * @access public |
|
358 | - * @return bool |
|
359 | - * @throws \EE_Error |
|
360 | - */ |
|
361 | - public function empty_cart() |
|
362 | - { |
|
363 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
364 | - $this->_grand_total = $this->_create_grand_total(); |
|
365 | - return $this->save_cart(true); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @remove ALL items from cart and delete total as well |
|
372 | - * @access public |
|
373 | - * @return bool |
|
374 | - * @throws \EE_Error |
|
375 | - */ |
|
376 | - public function delete_cart() |
|
377 | - { |
|
378 | - $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
379 | - if ($deleted) { |
|
380 | - $deleted += $this->_grand_total->delete(); |
|
381 | - $this->_grand_total = null; |
|
382 | - } |
|
383 | - return $deleted; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * @save cart to session |
|
390 | - * @access public |
|
391 | - * @param bool $apply_taxes |
|
392 | - * @return TRUE on success, FALSE on fail |
|
393 | - * @throws \EE_Error |
|
394 | - */ |
|
395 | - public function save_cart($apply_taxes = true) |
|
396 | - { |
|
397 | - if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
398 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
399 | - //make sure we don't cache the transaction because it can get stale |
|
400 | - if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
401 | - && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
402 | - ) { |
|
403 | - $this->_grand_total->clear_cache('Transaction', null, true); |
|
404 | - } |
|
405 | - } |
|
406 | - if ($this->session() instanceof EE_Session) { |
|
407 | - return $this->session()->set_cart($this); |
|
408 | - } else { |
|
409 | - return false; |
|
410 | - } |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - |
|
415 | - public function __wakeup() |
|
416 | - { |
|
417 | - if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
418 | - // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
419 | - $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * @return array |
|
427 | - */ |
|
428 | - public function __sleep() |
|
429 | - { |
|
430 | - if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
431 | - $this->_grand_total = $this->_grand_total->ID(); |
|
432 | - } |
|
433 | - return array('_grand_total'); |
|
434 | - } |
|
23 | + /** |
|
24 | + * instance of the EE_Cart object |
|
25 | + * |
|
26 | + * @access private |
|
27 | + * @var EE_Cart $_instance |
|
28 | + */ |
|
29 | + private static $_instance; |
|
30 | + |
|
31 | + /** |
|
32 | + * instance of the EE_Session object |
|
33 | + * |
|
34 | + * @access protected |
|
35 | + * @var EE_Session $_session |
|
36 | + */ |
|
37 | + protected $_session; |
|
38 | + |
|
39 | + /** |
|
40 | + * The total Line item which comprises all the children line-item subtotals, |
|
41 | + * which in turn each have their line items. |
|
42 | + * Typically, the line item structure will look like: |
|
43 | + * grand total |
|
44 | + * -tickets-sub-total |
|
45 | + * --ticket1 |
|
46 | + * --ticket2 |
|
47 | + * --... |
|
48 | + * -taxes-sub-total |
|
49 | + * --tax1 |
|
50 | + * --tax2 |
|
51 | + * |
|
52 | + * @var EE_Line_Item |
|
53 | + */ |
|
54 | + private $_grand_total; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @singleton method used to instantiate class object |
|
60 | + * @access public |
|
61 | + * @param EE_Line_Item $grand_total |
|
62 | + * @param EE_Session $session |
|
63 | + * @return \EE_Cart |
|
64 | + * @throws \EE_Error |
|
65 | + */ |
|
66 | + public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
67 | + { |
|
68 | + if ( ! empty($grand_total)) { |
|
69 | + self::$_instance = new self($grand_total, $session); |
|
70 | + } |
|
71 | + // or maybe retrieve an existing one ? |
|
72 | + if ( ! self::$_instance instanceof EE_Cart) { |
|
73 | + // try getting the cart out of the session |
|
74 | + $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
75 | + self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
76 | + unset($saved_cart); |
|
77 | + } |
|
78 | + // verify that cart is ok and grand total line item exists |
|
79 | + if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
80 | + self::$_instance = new self($grand_total, $session); |
|
81 | + } |
|
82 | + self::$_instance->get_grand_total(); |
|
83 | + // once everything is all said and done, save the cart to the EE_Session |
|
84 | + add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
85 | + return self::$_instance; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * private constructor to prevent direct creation |
|
92 | + * |
|
93 | + * @Constructor |
|
94 | + * @access private |
|
95 | + * @param EE_Line_Item $grand_total |
|
96 | + * @param EE_Session $session |
|
97 | + */ |
|
98 | + private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
99 | + { |
|
100 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
101 | + $this->set_session($session); |
|
102 | + if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
103 | + $this->set_grand_total_line_item($grand_total); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * Resets the cart completely (whereas empty_cart |
|
111 | + * |
|
112 | + * @param EE_Line_Item $grand_total |
|
113 | + * @param EE_Session $session |
|
114 | + * @return EE_Cart |
|
115 | + * @throws \EE_Error |
|
116 | + */ |
|
117 | + public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
118 | + { |
|
119 | + remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
120 | + if ($session instanceof EE_Session) { |
|
121 | + $session->reset_cart(); |
|
122 | + } |
|
123 | + self::$_instance = null; |
|
124 | + return self::instance($grand_total, $session); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @return \EE_Session |
|
131 | + */ |
|
132 | + public function session() |
|
133 | + { |
|
134 | + if ( ! $this->_session instanceof EE_Session) { |
|
135 | + $this->set_session(); |
|
136 | + } |
|
137 | + return $this->_session; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param EE_Session $session |
|
144 | + */ |
|
145 | + public function set_session(EE_Session $session = null) |
|
146 | + { |
|
147 | + $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
154 | + * know the grand total line item on it |
|
155 | + * |
|
156 | + * @param EE_Line_Item $line_item |
|
157 | + */ |
|
158 | + public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
159 | + { |
|
160 | + $this->_grand_total = $line_item; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * get_cart_from_reg_url_link |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @param EE_Transaction $transaction |
|
170 | + * @param EE_Session $session |
|
171 | + * @return \EE_Cart |
|
172 | + * @throws \EE_Error |
|
173 | + */ |
|
174 | + public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
175 | + { |
|
176 | + $grand_total = $transaction->total_line_item(); |
|
177 | + $grand_total->get_items(); |
|
178 | + $grand_total->tax_descendants(); |
|
179 | + return EE_Cart::instance($grand_total, $session); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
186 | + * |
|
187 | + * @return EE_Line_Item |
|
188 | + * @throws \EE_Error |
|
189 | + */ |
|
190 | + private function _create_grand_total() |
|
191 | + { |
|
192 | + $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
193 | + return $this->_grand_total; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Gets all the line items of object type Ticket |
|
200 | + * |
|
201 | + * @access public |
|
202 | + * @return \EE_Line_Item[] |
|
203 | + */ |
|
204 | + public function get_tickets() |
|
205 | + { |
|
206 | + if ($this->_grand_total === null ) { |
|
207 | + return array(); |
|
208 | + } |
|
209 | + return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * returns the total quantity of tickets in the cart |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @return int |
|
219 | + * @throws \EE_Error |
|
220 | + */ |
|
221 | + public function all_ticket_quantity_count() |
|
222 | + { |
|
223 | + $tickets = $this->get_tickets(); |
|
224 | + if (empty($tickets)) { |
|
225 | + return 0; |
|
226 | + } |
|
227 | + $count = 0; |
|
228 | + foreach ($tickets as $ticket) { |
|
229 | + $count += $ticket->get('LIN_quantity'); |
|
230 | + } |
|
231 | + return $count; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Gets all the tax line items |
|
238 | + * |
|
239 | + * @return \EE_Line_Item[] |
|
240 | + * @throws \EE_Error |
|
241 | + */ |
|
242 | + public function get_taxes() |
|
243 | + { |
|
244 | + return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Gets the total line item (which is a parent of all other line items) on this cart |
|
251 | + * |
|
252 | + * @return EE_Line_Item |
|
253 | + * @throws \EE_Error |
|
254 | + */ |
|
255 | + public function get_grand_total() |
|
256 | + { |
|
257 | + return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @process items for adding to cart |
|
264 | + * @access public |
|
265 | + * @param EE_Ticket $ticket |
|
266 | + * @param int $qty |
|
267 | + * @return TRUE on success, FALSE on fail |
|
268 | + * @throws \EE_Error |
|
269 | + */ |
|
270 | + public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
271 | + { |
|
272 | + EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
273 | + return $this->save_cart() ? true : false; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * get_cart_total_before_tax |
|
280 | + * |
|
281 | + * @access public |
|
282 | + * @return float |
|
283 | + * @throws \EE_Error |
|
284 | + */ |
|
285 | + public function get_cart_total_before_tax() |
|
286 | + { |
|
287 | + return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * gets the total amount of tax paid for items in this cart |
|
294 | + * |
|
295 | + * @access public |
|
296 | + * @return float |
|
297 | + * @throws \EE_Error |
|
298 | + */ |
|
299 | + public function get_applied_taxes() |
|
300 | + { |
|
301 | + return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
308 | + * |
|
309 | + * @access public |
|
310 | + * @return float |
|
311 | + * @throws \EE_Error |
|
312 | + */ |
|
313 | + public function get_cart_grand_total() |
|
314 | + { |
|
315 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
316 | + return $this->get_grand_total()->total(); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
323 | + * |
|
324 | + * @access public |
|
325 | + * @return float |
|
326 | + * @throws \EE_Error |
|
327 | + */ |
|
328 | + public function recalculate_all_cart_totals() |
|
329 | + { |
|
330 | + $pre_tax_total = $this->get_cart_total_before_tax(); |
|
331 | + $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
332 | + $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
333 | + $this->_grand_total->save_this_and_descendants_to_txn(); |
|
334 | + return $this->get_grand_total()->total(); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * deletes an item from the cart |
|
341 | + * |
|
342 | + * @access public |
|
343 | + * @param array|bool|string $line_item_codes |
|
344 | + * @return int on success, FALSE on fail |
|
345 | + * @throws \EE_Error |
|
346 | + */ |
|
347 | + public function delete_items($line_item_codes = false) |
|
348 | + { |
|
349 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
350 | + return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * @remove ALL items from cart and zero ALL totals |
|
357 | + * @access public |
|
358 | + * @return bool |
|
359 | + * @throws \EE_Error |
|
360 | + */ |
|
361 | + public function empty_cart() |
|
362 | + { |
|
363 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
364 | + $this->_grand_total = $this->_create_grand_total(); |
|
365 | + return $this->save_cart(true); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @remove ALL items from cart and delete total as well |
|
372 | + * @access public |
|
373 | + * @return bool |
|
374 | + * @throws \EE_Error |
|
375 | + */ |
|
376 | + public function delete_cart() |
|
377 | + { |
|
378 | + $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
379 | + if ($deleted) { |
|
380 | + $deleted += $this->_grand_total->delete(); |
|
381 | + $this->_grand_total = null; |
|
382 | + } |
|
383 | + return $deleted; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * @save cart to session |
|
390 | + * @access public |
|
391 | + * @param bool $apply_taxes |
|
392 | + * @return TRUE on success, FALSE on fail |
|
393 | + * @throws \EE_Error |
|
394 | + */ |
|
395 | + public function save_cart($apply_taxes = true) |
|
396 | + { |
|
397 | + if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
398 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
399 | + //make sure we don't cache the transaction because it can get stale |
|
400 | + if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
401 | + && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
402 | + ) { |
|
403 | + $this->_grand_total->clear_cache('Transaction', null, true); |
|
404 | + } |
|
405 | + } |
|
406 | + if ($this->session() instanceof EE_Session) { |
|
407 | + return $this->session()->set_cart($this); |
|
408 | + } else { |
|
409 | + return false; |
|
410 | + } |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + |
|
415 | + public function __wakeup() |
|
416 | + { |
|
417 | + if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
418 | + // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
419 | + $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * @return array |
|
427 | + */ |
|
428 | + public function __sleep() |
|
429 | + { |
|
430 | + if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
431 | + $this->_grand_total = $this->_grand_total->ID(); |
|
432 | + } |
|
433 | + return array('_grand_total'); |
|
434 | + } |
|
435 | 435 | |
436 | 436 | |
437 | 437 | } |
@@ -29,18 +29,18 @@ |
||
29 | 29 | * @return \EventEspresso\core\Psr4Autoloader |
30 | 30 | */ |
31 | 31 | public function initializeAutoloader() { |
32 | - static $initialized = false; |
|
33 | - if ( ! $initialized) { |
|
34 | - // instantiate PSR4 autoloader |
|
35 | - EE_Psr4AutoloaderInit::$psr4_loader = new \EventEspresso\core\Psr4Autoloader(); |
|
36 | - // register the autoloader |
|
37 | - EE_Psr4AutoloaderInit::$psr4_loader->register(); |
|
38 | - // register the base directories for the namespace prefix |
|
39 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
|
40 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
41 | - $initialized = true; |
|
42 | - } |
|
43 | - } |
|
32 | + static $initialized = false; |
|
33 | + if ( ! $initialized) { |
|
34 | + // instantiate PSR4 autoloader |
|
35 | + EE_Psr4AutoloaderInit::$psr4_loader = new \EventEspresso\core\Psr4Autoloader(); |
|
36 | + // register the autoloader |
|
37 | + EE_Psr4AutoloaderInit::$psr4_loader->register(); |
|
38 | + // register the base directories for the namespace prefix |
|
39 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
|
40 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
41 | + $initialized = true; |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | 46 |
@@ -37,7 +37,7 @@ |
||
37 | 37 | EE_Psr4AutoloaderInit::$psr4_loader->register(); |
38 | 38 | // register the base directories for the namespace prefix |
39 | 39 | EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
40 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
40 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch'); |
|
41 | 41 | $initialized = true; |
42 | 42 | } |
43 | 43 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * @access public |
52 | 52 | */ |
53 | 53 | public function __construct() { |
54 | - // deprecated functions |
|
55 | - espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
56 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
57 | - } |
|
54 | + // deprecated functions |
|
55 | + espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
56 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | 60 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | ); |
89 | 89 | // workarounds for PHP < 5.3 |
90 | 90 | $this->_load_class_tools(); |
91 | - // WP cron jobs |
|
91 | + // WP cron jobs |
|
92 | 92 | $this->registry->load_core( 'Cron_Tasks' ); |
93 | 93 | $this->registry->load_core( 'EE_Request_Handler' ); |
94 | 94 | $this->registry->load_core( 'EE_System' ); |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function __construct() { |
54 | 54 | // deprecated functions |
55 | - espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
56 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
55 | + espresso_load_required('EE_Base', EE_CORE.'EE_Base.core.php'); |
|
56 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | |
@@ -69,29 +69,29 @@ discard block |
||
69 | 69 | * @param EE_Response $response |
70 | 70 | * @return EE_Response |
71 | 71 | */ |
72 | - public function handle_request( EE_Request $request, EE_Response $response ) { |
|
72 | + public function handle_request(EE_Request $request, EE_Response $response) { |
|
73 | 73 | $this->request = $request; |
74 | 74 | $this->response = $response; |
75 | 75 | // info about how to load classes required by other classes |
76 | 76 | $this->dependency_map = $this->_load_dependency_map(); |
77 | 77 | // central repository for classes |
78 | 78 | $this->registry = $this->_load_registry(); |
79 | - do_action( 'EE_Load_Espresso_Core__handle_request__initialize_core_loading' ); |
|
79 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
80 | 80 | // create and cache the CommandBus, and also add the CapChecker middleware |
81 | 81 | $this->registry->create( |
82 | 82 | 'CommandBusInterface', |
83 | 83 | array( |
84 | 84 | null, |
85 | - $this->registry->create( 'CapChecker' ) |
|
85 | + $this->registry->create('CapChecker') |
|
86 | 86 | ), |
87 | 87 | true |
88 | 88 | ); |
89 | 89 | // workarounds for PHP < 5.3 |
90 | 90 | $this->_load_class_tools(); |
91 | 91 | // WP cron jobs |
92 | - $this->registry->load_core( 'Cron_Tasks' ); |
|
93 | - $this->registry->load_core( 'EE_Request_Handler' ); |
|
94 | - $this->registry->load_core( 'EE_System' ); |
|
92 | + $this->registry->load_core('Cron_Tasks'); |
|
93 | + $this->registry->load_core('EE_Request_Handler'); |
|
94 | + $this->registry->load_core('EE_System'); |
|
95 | 95 | |
96 | 96 | return $this->response; |
97 | 97 | } |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | * @throws \EE_Error |
122 | 122 | */ |
123 | 123 | public function dependency_map() { |
124 | - if ( ! $this->dependency_map instanceof EE_Dependency_Map ) { |
|
124 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
125 | 125 | throw new EE_Error( |
126 | 126 | sprintf( |
127 | - __( 'Invalid EE_Dependency_Map: "%1$s"', 'event_espresso' ), |
|
128 | - print_r( $this->dependency_map, true ) |
|
127 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
128 | + print_r($this->dependency_map, true) |
|
129 | 129 | ) |
130 | 130 | ); |
131 | 131 | } |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | * @throws \EE_Error |
140 | 140 | */ |
141 | 141 | public function registry() { |
142 | - if ( ! $this->registry instanceof EE_Registry ) { |
|
142 | + if ( ! $this->registry instanceof EE_Registry) { |
|
143 | 143 | throw new EE_Error( |
144 | 144 | sprintf( |
145 | - __( 'Invalid EE_Registry: "%1$s"', 'event_espresso' ), |
|
146 | - print_r( $this->registry, true ) |
|
145 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
146 | + print_r($this->registry, true) |
|
147 | 147 | ) |
148 | 148 | ); |
149 | 149 | } |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | * @return EE_Dependency_Map |
160 | 160 | */ |
161 | 161 | private function _load_dependency_map() { |
162 | - if ( ! is_readable( EE_CORE . 'EE_Dependency_Map.core.php' ) ) { |
|
162 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
163 | 163 | EE_Error::add_error( |
164 | - __( 'The EE_Dependency_Map core class could not be loaded.', 'event_espresso' ), |
|
164 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
165 | 165 | __FILE__, __FUNCTION__, __LINE__ |
166 | 166 | ); |
167 | - wp_die( EE_Error::get_notices() ); |
|
167 | + wp_die(EE_Error::get_notices()); |
|
168 | 168 | } |
169 | - require_once( EE_CORE . 'EE_Dependency_Map.core.php' ); |
|
170 | - return EE_Dependency_Map::instance( $this->request, $this->response ); |
|
169 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); |
|
170 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | |
@@ -179,15 +179,15 @@ discard block |
||
179 | 179 | * @return EE_Registry |
180 | 180 | */ |
181 | 181 | private function _load_registry() { |
182 | - if ( ! is_readable( EE_CORE . 'EE_Registry.core.php' )) { |
|
182 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
183 | 183 | EE_Error::add_error( |
184 | - __( 'The EE_Registry core class could not be loaded.', 'event_espresso' ), |
|
184 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
185 | 185 | __FILE__, __FUNCTION__, __LINE__ |
186 | 186 | ); |
187 | - wp_die( EE_Error::get_notices() ); |
|
187 | + wp_die(EE_Error::get_notices()); |
|
188 | 188 | } |
189 | - require_once( EE_CORE . 'EE_Registry.core.php' ); |
|
190 | - return EE_Registry::instance( $this->dependency_map ); |
|
189 | + require_once(EE_CORE.'EE_Registry.core.php'); |
|
190 | + return EE_Registry::instance($this->dependency_map); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | * @return void |
199 | 199 | */ |
200 | 200 | private function _load_class_tools() { |
201 | - if ( ! is_readable( EE_HELPERS . 'EEH_Class_Tools.helper.php' )) { |
|
201 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
202 | 202 | EE_Error::add_error( |
203 | - __( 'The EEH_Class_Tools helper could not be loaded.', 'event_espresso' ), |
|
203 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
204 | 204 | __FILE__, __FUNCTION__, __LINE__ |
205 | 205 | ); |
206 | 206 | } |
207 | - require_once( EE_HELPERS . 'EEH_Class_Tools.helper.php' ); |
|
207 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | |
@@ -218,13 +218,13 @@ discard block |
||
218 | 218 | * @param \EE_Request $request |
219 | 219 | * @param \EE_Response $response |
220 | 220 | */ |
221 | - public function handle_response( EE_Request $request, EE_Response $response ) { |
|
221 | + public function handle_response(EE_Request $request, EE_Response $response) { |
|
222 | 222 | //\EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
223 | 223 | //EEH_Debug_Tools::printr( $request, '$request', __FILE__, __LINE__ ); |
224 | 224 | //EEH_Debug_Tools::printr( $response, '$response', __FILE__, __LINE__ ); |
225 | 225 | //die(); |
226 | - if ( $response->plugin_deactivated() ) { |
|
227 | - espresso_deactivate_plugin( EE_PLUGIN_BASENAME ); |
|
226 | + if ($response->plugin_deactivated()) { |
|
227 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 |