@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ); |
75 | 75 | // make sure limit and caps are always set |
76 | 76 | $query_params = array_merge( |
77 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | + array('limit' => 10, 'caps' => EEM_Base::caps_read_admin), |
|
78 | 78 | $query_params |
79 | 79 | ); |
80 | 80 | $this->_value_field_name = EEH_Array::is_set( |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | $values_for_options = (array) $value; |
156 | 156 | $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
157 | 157 | $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
158 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
158 | + $this->_extra_select_columns[] = $value_field->get_qualified_column().' AS '.$this->_value_field_name; |
|
159 | + $this->_extra_select_columns[] = $display_field->get_qualified_column().' AS '.$this->_display_field_name; |
|
160 | 160 | $display_values = $this->_get_model()->get_all_wpdb_results( |
161 | 161 | array( |
162 | 162 | array( |
163 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | + $this->_value_field_name => array('IN', $values_for_options) |
|
164 | 164 | ) |
165 | 165 | ), |
166 | 166 | ARRAY_A, |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | if (is_array($select_options)) { |
171 | 171 | foreach ($display_values as $db_rows) { |
172 | 172 | $db_rows = (array) $db_rows; |
173 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | + $select_options[$db_rows[$this->_value_field_name]] = apply_filters( |
|
174 | 174 | 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
175 | - $db_rows[ $this->_display_field_name ], |
|
175 | + $db_rows[$this->_display_field_name], |
|
176 | 176 | $db_rows |
177 | 177 | ); |
178 | 178 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function _get_model() |
190 | 190 | { |
191 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | + if ( ! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | 192 | throw new EE_Error( |
193 | 193 | sprintf( |
194 | 194 | esc_html__( |
@@ -16,189 +16,189 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string $_model_name |
|
21 | - */ |
|
22 | - protected $_model_name; |
|
19 | + /** |
|
20 | + * @var string $_model_name |
|
21 | + */ |
|
22 | + protected $_model_name; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var string $_display_field_name |
|
26 | - */ |
|
27 | - protected $_display_field_name; |
|
24 | + /** |
|
25 | + * @var string $_display_field_name |
|
26 | + */ |
|
27 | + protected $_display_field_name; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var string $_value_field_name |
|
31 | - */ |
|
32 | - protected $_value_field_name; |
|
29 | + /** |
|
30 | + * @var string $_value_field_name |
|
31 | + */ |
|
32 | + protected $_value_field_name; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var array $_extra_select_columns |
|
36 | - */ |
|
37 | - protected $_extra_select_columns = array(); |
|
34 | + /** |
|
35 | + * @var array $_extra_select_columns |
|
36 | + */ |
|
37 | + protected $_extra_select_columns = array(); |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @param array $input_settings { |
|
42 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
43 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
44 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
45 | - * the string "where") |
|
46 | - * @type string $value_field_name the name of the model field on this model to |
|
47 | - * be used for the HTML select's option's values |
|
48 | - * @type string $display_field_name the name of the model field on this model |
|
49 | - * to be used for the HTML select's option's display text |
|
50 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
51 | - * } |
|
52 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
53 | - * } |
|
54 | - * @throws EE_Error |
|
55 | - * @throws InvalidArgumentException |
|
56 | - * @throws InvalidDataTypeException |
|
57 | - * @throws InvalidInterfaceException |
|
58 | - */ |
|
59 | - public function __construct($input_settings = array()) |
|
60 | - { |
|
61 | - // needed input settings: |
|
62 | - // select2_args |
|
63 | - $this->_model_name = EEH_Array::is_set( |
|
64 | - $input_settings, |
|
65 | - 'model_name', |
|
66 | - null |
|
67 | - ); |
|
68 | - $model = $this->_get_model(); |
|
69 | - $query_params = EEH_Array::is_set( |
|
70 | - $input_settings, |
|
71 | - 'query_params', |
|
72 | - array() |
|
73 | - ); |
|
74 | - // make sure limit and caps are always set |
|
75 | - $query_params = array_merge( |
|
76 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | - $query_params |
|
78 | - ); |
|
79 | - $this->_value_field_name = EEH_Array::is_set( |
|
80 | - $input_settings, |
|
81 | - 'value_field_name', |
|
82 | - $model->primary_key_name() |
|
83 | - ); |
|
84 | - $this->_display_field_name = EEH_Array::is_set( |
|
85 | - $input_settings, |
|
86 | - 'display_field_name', |
|
87 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
88 | - ); |
|
89 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
90 | - $input_settings, |
|
91 | - 'extra_select_columns', |
|
92 | - array() |
|
93 | - ); |
|
94 | - $this->_add_validation_strategy( |
|
95 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
96 | - '', |
|
97 | - $this->_model_name, |
|
98 | - $query_params, |
|
99 | - $this->_value_field_name |
|
100 | - ) |
|
101 | - ); |
|
102 | - // get resource endpoint |
|
103 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
104 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
105 | - ); |
|
106 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
107 | - $default_select2_args = array( |
|
108 | - 'ajax' => array( |
|
109 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
110 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
111 | - ), |
|
112 | - 'dataType' => 'json', |
|
113 | - 'delay' => '250', |
|
114 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
115 | - 'data_interface_args' => array( |
|
116 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
117 | - $query_params, |
|
118 | - $model |
|
119 | - ), |
|
120 | - 'display_field' => $this->_display_field_name, |
|
121 | - 'value_field' => $this->_value_field_name, |
|
122 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
123 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
124 | - ), |
|
125 | - ), |
|
126 | - 'cache' => true, |
|
127 | - 'width' => 'resolve' |
|
128 | - ); |
|
129 | - $select2_args = array_replace_recursive( |
|
130 | - $default_select2_args, |
|
131 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
132 | - ); |
|
133 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
134 | - parent::__construct(array(), $input_settings); |
|
135 | - } |
|
40 | + /** |
|
41 | + * @param array $input_settings { |
|
42 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
43 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
44 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
45 | + * the string "where") |
|
46 | + * @type string $value_field_name the name of the model field on this model to |
|
47 | + * be used for the HTML select's option's values |
|
48 | + * @type string $display_field_name the name of the model field on this model |
|
49 | + * to be used for the HTML select's option's display text |
|
50 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
51 | + * } |
|
52 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
53 | + * } |
|
54 | + * @throws EE_Error |
|
55 | + * @throws InvalidArgumentException |
|
56 | + * @throws InvalidDataTypeException |
|
57 | + * @throws InvalidInterfaceException |
|
58 | + */ |
|
59 | + public function __construct($input_settings = array()) |
|
60 | + { |
|
61 | + // needed input settings: |
|
62 | + // select2_args |
|
63 | + $this->_model_name = EEH_Array::is_set( |
|
64 | + $input_settings, |
|
65 | + 'model_name', |
|
66 | + null |
|
67 | + ); |
|
68 | + $model = $this->_get_model(); |
|
69 | + $query_params = EEH_Array::is_set( |
|
70 | + $input_settings, |
|
71 | + 'query_params', |
|
72 | + array() |
|
73 | + ); |
|
74 | + // make sure limit and caps are always set |
|
75 | + $query_params = array_merge( |
|
76 | + array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | + $query_params |
|
78 | + ); |
|
79 | + $this->_value_field_name = EEH_Array::is_set( |
|
80 | + $input_settings, |
|
81 | + 'value_field_name', |
|
82 | + $model->primary_key_name() |
|
83 | + ); |
|
84 | + $this->_display_field_name = EEH_Array::is_set( |
|
85 | + $input_settings, |
|
86 | + 'display_field_name', |
|
87 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
88 | + ); |
|
89 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
90 | + $input_settings, |
|
91 | + 'extra_select_columns', |
|
92 | + array() |
|
93 | + ); |
|
94 | + $this->_add_validation_strategy( |
|
95 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
96 | + '', |
|
97 | + $this->_model_name, |
|
98 | + $query_params, |
|
99 | + $this->_value_field_name |
|
100 | + ) |
|
101 | + ); |
|
102 | + // get resource endpoint |
|
103 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
104 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
105 | + ); |
|
106 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
107 | + $default_select2_args = array( |
|
108 | + 'ajax' => array( |
|
109 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
110 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
111 | + ), |
|
112 | + 'dataType' => 'json', |
|
113 | + 'delay' => '250', |
|
114 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
115 | + 'data_interface_args' => array( |
|
116 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
117 | + $query_params, |
|
118 | + $model |
|
119 | + ), |
|
120 | + 'display_field' => $this->_display_field_name, |
|
121 | + 'value_field' => $this->_value_field_name, |
|
122 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
123 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
124 | + ), |
|
125 | + ), |
|
126 | + 'cache' => true, |
|
127 | + 'width' => 'resolve' |
|
128 | + ); |
|
129 | + $select2_args = array_replace_recursive( |
|
130 | + $default_select2_args, |
|
131 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
132 | + ); |
|
133 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
134 | + parent::__construct(array(), $input_settings); |
|
135 | + } |
|
136 | 136 | |
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * Before setting the raw value (usually because we're setting the default, |
|
141 | - * or we've received a form submission and this might be re-displayed to the user), |
|
142 | - * sets the options so that the current selections appear on initial display. |
|
143 | - * |
|
144 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
145 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
146 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
147 | - * |
|
148 | - * @param mixed $value |
|
149 | - * @return void |
|
150 | - * @throws \EE_Error |
|
151 | - */ |
|
152 | - public function _set_raw_value($value) |
|
153 | - { |
|
154 | - $values_for_options = (array) $value; |
|
155 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
156 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
157 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
158 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
159 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
160 | - array( |
|
161 | - array( |
|
162 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | - ) |
|
164 | - ), |
|
165 | - ARRAY_A, |
|
166 | - implode(',', $this->_extra_select_columns) |
|
167 | - ); |
|
168 | - $select_options = array(); |
|
169 | - if (is_array($select_options)) { |
|
170 | - foreach ($display_values as $db_rows) { |
|
171 | - $db_rows = (array) $db_rows; |
|
172 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
174 | - $db_rows[ $this->_display_field_name ], |
|
175 | - $db_rows |
|
176 | - ); |
|
177 | - } |
|
178 | - } |
|
179 | - $this->set_select_options($select_options); |
|
180 | - parent::_set_raw_value($value); |
|
181 | - } |
|
139 | + /** |
|
140 | + * Before setting the raw value (usually because we're setting the default, |
|
141 | + * or we've received a form submission and this might be re-displayed to the user), |
|
142 | + * sets the options so that the current selections appear on initial display. |
|
143 | + * |
|
144 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
145 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
146 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
147 | + * |
|
148 | + * @param mixed $value |
|
149 | + * @return void |
|
150 | + * @throws \EE_Error |
|
151 | + */ |
|
152 | + public function _set_raw_value($value) |
|
153 | + { |
|
154 | + $values_for_options = (array) $value; |
|
155 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
156 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
157 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
158 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
159 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
160 | + array( |
|
161 | + array( |
|
162 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | + ) |
|
164 | + ), |
|
165 | + ARRAY_A, |
|
166 | + implode(',', $this->_extra_select_columns) |
|
167 | + ); |
|
168 | + $select_options = array(); |
|
169 | + if (is_array($select_options)) { |
|
170 | + foreach ($display_values as $db_rows) { |
|
171 | + $db_rows = (array) $db_rows; |
|
172 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
174 | + $db_rows[ $this->_display_field_name ], |
|
175 | + $db_rows |
|
176 | + ); |
|
177 | + } |
|
178 | + } |
|
179 | + $this->set_select_options($select_options); |
|
180 | + parent::_set_raw_value($value); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
185 | - * @return EEM_Base |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - protected function _get_model() |
|
189 | - { |
|
190 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | - throw new EE_Error( |
|
192 | - sprintf( |
|
193 | - esc_html__( |
|
194 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $this->_model_name |
|
198 | - ) |
|
199 | - ); |
|
200 | - } else { |
|
201 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
202 | - } |
|
203 | - } |
|
183 | + /** |
|
184 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
185 | + * @return EEM_Base |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + protected function _get_model() |
|
189 | + { |
|
190 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | + throw new EE_Error( |
|
192 | + sprintf( |
|
193 | + esc_html__( |
|
194 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $this->_model_name |
|
198 | + ) |
|
199 | + ); |
|
200 | + } else { |
|
201 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | } |
@@ -120,7 +120,7 @@ |
||
120 | 120 | public function _update_config(EE_Config_Base $config_obj = null) |
121 | 121 | { |
122 | 122 | $config_class = $this->config_class(); |
123 | - if (! $config_obj instanceof $config_class) { |
|
123 | + if ( ! $config_obj instanceof $config_class) { |
|
124 | 124 | throw new EE_Error( |
125 | 125 | sprintf( |
126 | 126 | esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
@@ -9,143 +9,143 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class EE_Configurable extends EE_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @var $_config |
|
14 | - * @type EE_Config_Base |
|
15 | - */ |
|
16 | - protected $_config; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var $_config_section |
|
20 | - * @type string |
|
21 | - */ |
|
22 | - protected $_config_section = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var $_config_class |
|
26 | - * @type string |
|
27 | - */ |
|
28 | - protected $_config_class = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var $_config_name |
|
32 | - * @type string |
|
33 | - */ |
|
34 | - protected $_config_name = ''; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param string $config_section |
|
39 | - */ |
|
40 | - public function set_config_section($config_section = '') |
|
41 | - { |
|
42 | - $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public function config_section() |
|
50 | - { |
|
51 | - return $this->_config_section; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $config_class |
|
57 | - */ |
|
58 | - public function set_config_class($config_class = '') |
|
59 | - { |
|
60 | - $this->_config_class = $config_class; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return mixed |
|
66 | - */ |
|
67 | - public function config_class() |
|
68 | - { |
|
69 | - return $this->_config_class; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param mixed $config_name |
|
75 | - */ |
|
76 | - public function set_config_name($config_name) |
|
77 | - { |
|
78 | - $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public function config_name() |
|
86 | - { |
|
87 | - return $this->_config_name; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * set_config |
|
93 | - * this method integrates directly with EE_Config to set up the config object for this class |
|
94 | - * |
|
95 | - * @access protected |
|
96 | - * @param EE_Config_Base $config_obj |
|
97 | - * @return mixed EE_Config_Base | NULL |
|
98 | - */ |
|
99 | - protected function _set_config(EE_Config_Base $config_obj = null) |
|
100 | - { |
|
101 | - return EE_Config::instance()->set_config( |
|
102 | - $this->config_section(), |
|
103 | - $this->config_name(), |
|
104 | - $this->config_class(), |
|
105 | - $config_obj |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * _update_config |
|
112 | - * this method integrates directly with EE_Config to update an existing config object for this class |
|
113 | - * |
|
114 | - * @access protected |
|
115 | - * @param EE_Config_Base $config_obj |
|
116 | - * @throws \EE_Error |
|
117 | - * @return mixed EE_Config_Base | NULL |
|
118 | - */ |
|
119 | - public function _update_config(EE_Config_Base $config_obj = null) |
|
120 | - { |
|
121 | - $config_class = $this->config_class(); |
|
122 | - if (! $config_obj instanceof $config_class) { |
|
123 | - throw new EE_Error( |
|
124 | - sprintf( |
|
125 | - esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
126 | - print_r($config_obj, true), |
|
127 | - $config_class |
|
128 | - ) |
|
129 | - ); |
|
130 | - } |
|
131 | - return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * gets the class's config object |
|
137 | - * |
|
138 | - * @return EE_Config_Base |
|
139 | - */ |
|
140 | - public function config() |
|
141 | - { |
|
142 | - if (empty($this->_config)) { |
|
143 | - $this->_config = EE_Config::instance()->get_config( |
|
144 | - $this->config_section(), |
|
145 | - $this->config_name(), |
|
146 | - $this->config_class() |
|
147 | - ); |
|
148 | - } |
|
149 | - return $this->_config; |
|
150 | - } |
|
12 | + /** |
|
13 | + * @var $_config |
|
14 | + * @type EE_Config_Base |
|
15 | + */ |
|
16 | + protected $_config; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var $_config_section |
|
20 | + * @type string |
|
21 | + */ |
|
22 | + protected $_config_section = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var $_config_class |
|
26 | + * @type string |
|
27 | + */ |
|
28 | + protected $_config_class = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var $_config_name |
|
32 | + * @type string |
|
33 | + */ |
|
34 | + protected $_config_name = ''; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param string $config_section |
|
39 | + */ |
|
40 | + public function set_config_section($config_section = '') |
|
41 | + { |
|
42 | + $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public function config_section() |
|
50 | + { |
|
51 | + return $this->_config_section; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $config_class |
|
57 | + */ |
|
58 | + public function set_config_class($config_class = '') |
|
59 | + { |
|
60 | + $this->_config_class = $config_class; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return mixed |
|
66 | + */ |
|
67 | + public function config_class() |
|
68 | + { |
|
69 | + return $this->_config_class; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param mixed $config_name |
|
75 | + */ |
|
76 | + public function set_config_name($config_name) |
|
77 | + { |
|
78 | + $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public function config_name() |
|
86 | + { |
|
87 | + return $this->_config_name; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * set_config |
|
93 | + * this method integrates directly with EE_Config to set up the config object for this class |
|
94 | + * |
|
95 | + * @access protected |
|
96 | + * @param EE_Config_Base $config_obj |
|
97 | + * @return mixed EE_Config_Base | NULL |
|
98 | + */ |
|
99 | + protected function _set_config(EE_Config_Base $config_obj = null) |
|
100 | + { |
|
101 | + return EE_Config::instance()->set_config( |
|
102 | + $this->config_section(), |
|
103 | + $this->config_name(), |
|
104 | + $this->config_class(), |
|
105 | + $config_obj |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * _update_config |
|
112 | + * this method integrates directly with EE_Config to update an existing config object for this class |
|
113 | + * |
|
114 | + * @access protected |
|
115 | + * @param EE_Config_Base $config_obj |
|
116 | + * @throws \EE_Error |
|
117 | + * @return mixed EE_Config_Base | NULL |
|
118 | + */ |
|
119 | + public function _update_config(EE_Config_Base $config_obj = null) |
|
120 | + { |
|
121 | + $config_class = $this->config_class(); |
|
122 | + if (! $config_obj instanceof $config_class) { |
|
123 | + throw new EE_Error( |
|
124 | + sprintf( |
|
125 | + esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
126 | + print_r($config_obj, true), |
|
127 | + $config_class |
|
128 | + ) |
|
129 | + ); |
|
130 | + } |
|
131 | + return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * gets the class's config object |
|
137 | + * |
|
138 | + * @return EE_Config_Base |
|
139 | + */ |
|
140 | + public function config() |
|
141 | + { |
|
142 | + if (empty($this->_config)) { |
|
143 | + $this->_config = EE_Config::instance()->get_config( |
|
144 | + $this->config_section(), |
|
145 | + $this->config_name(), |
|
146 | + $this->config_class() |
|
147 | + ); |
|
148 | + } |
|
149 | + return $this->_config; |
|
150 | + } |
|
151 | 151 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | ), |
144 | 144 | ], |
145 | 145 | ]; |
146 | - $this->_model_relations = [ |
|
146 | + $this->_model_relations = [ |
|
147 | 147 | 'Registration' => new EE_Has_Many_Relation(), |
148 | 148 | 'Payment' => new EE_Has_Many_Relation(), |
149 | 149 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | ], |
212 | 212 | OBJECT, |
213 | 213 | [ |
214 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
214 | + 'txnDate' => ['DATE('.$query_interval.')', '%s'], |
|
215 | 215 | 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
216 | 216 | ] |
217 | 217 | ); |
@@ -230,17 +230,17 @@ discard block |
||
230 | 230 | public function get_revenue_per_event_report($period = '-1 month') |
231 | 231 | { |
232 | 232 | global $wpdb; |
233 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
234 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
235 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
233 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
234 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
235 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
236 | 236 | $event_table = $wpdb->posts; |
237 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
237 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
238 | 238 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
239 | 239 | $approved_payment_status = EEM_Payment::status_id_approved; |
240 | 240 | $extra_event_on_join = ''; |
241 | 241 | // exclude events not authored by user if permissions in effect |
242 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
242 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $wpdb->get_results( |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
319 | 319 | { |
320 | 320 | EE_Error::doing_it_wrong( |
321 | - __CLASS__ . '::' . __FUNCTION__, |
|
321 | + __CLASS__.'::'.__FUNCTION__, |
|
322 | 322 | sprintf( |
323 | 323 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
324 | 324 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | $time_to_leave_alone |
391 | 391 | ); |
392 | 392 | // now that we have the ids to delete |
393 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
393 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
394 | 394 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
395 | 395 | EEM_Transaction::unset_locked_transactions($txn_ids); |
396 | 396 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | // let's get deleting... |
404 | 404 | // We got the ids from the original query to get them FROM |
405 | 405 | // the db (which is sanitized) so no need to prepare them again. |
406 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
406 | + $query = $wpdb->prepare("DELETE FROM ".$this->table()." WHERE TXN_ID IN ( $format )", $txn_ids); |
|
407 | 407 | $deleted = $wpdb->query($query); |
408 | 408 | } |
409 | 409 | if ($deleted) { |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | $locked_transactions = get_option('ee_locked_transactions', []); |
428 | 428 | $update = false; |
429 | 429 | foreach ($transaction_IDs as $TXN_ID) { |
430 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
431 | - unset($locked_transactions[ $TXN_ID ]); |
|
430 | + if (isset($locked_transactions[$TXN_ID])) { |
|
431 | + unset($locked_transactions[$TXN_ID]); |
|
432 | 432 | $update = true; |
433 | 433 | } |
434 | 434 | } |
@@ -18,226 +18,226 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class EEM_Transaction extends EEM_Base |
20 | 20 | { |
21 | - // private instance of the Transaction object |
|
22 | - protected static $_instance; |
|
23 | - |
|
24 | - /** |
|
25 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
26 | - * but payment is pending. This is the state for transactions where payment is promised |
|
27 | - * from an offline gateway. |
|
28 | - */ |
|
29 | - // const open_status_code = 'TPN'; |
|
30 | - |
|
31 | - /** |
|
32 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
33 | - * either due to a technical reason (server or computer crash during registration), |
|
34 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
35 | - */ |
|
36 | - const failed_status_code = 'TFL'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
40 | - * either due to a technical reason (server or computer crash during registration), |
|
41 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
42 | - * HOWEVER... |
|
43 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
44 | - * registrant |
|
45 | - */ |
|
46 | - const abandoned_status_code = 'TAB'; |
|
47 | - |
|
48 | - /** |
|
49 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
50 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
51 | - */ |
|
52 | - const incomplete_status_code = 'TIN'; |
|
53 | - |
|
54 | - /** |
|
55 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
56 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
57 | - */ |
|
58 | - const complete_status_code = 'TCM'; |
|
59 | - |
|
60 | - /** |
|
61 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
62 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
63 | - */ |
|
64 | - const overpaid_status_code = 'TOP'; |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * private constructor to prevent direct creation |
|
69 | - * |
|
70 | - * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
71 | - * any incoming timezone data that gets saved). Note this just sends the timezone info |
|
72 | - * to the date time model field objects. Default is NULL (and will be assumed using |
|
73 | - * the set timezone in the 'timezone_string' wp option) |
|
74 | - * @throws EE_Error |
|
75 | - * @throws ReflectionException |
|
76 | - */ |
|
77 | - protected function __construct(?string $timezone = '') |
|
78 | - { |
|
79 | - $this->singular_item = esc_html__('Transaction', 'event_espresso'); |
|
80 | - $this->plural_item = esc_html__('Transactions', 'event_espresso'); |
|
81 | - |
|
82 | - $this->_tables = [ |
|
83 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
84 | - ]; |
|
85 | - $this->_fields = [ |
|
86 | - 'TransactionTable' => [ |
|
87 | - 'TXN_ID' => new EE_Primary_Key_Int_Field( |
|
88 | - 'TXN_ID', esc_html__('Transaction ID', 'event_espresso') |
|
89 | - ), |
|
90 | - 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | - 'TXN_timestamp', |
|
92 | - esc_html__('date when transaction was created', 'event_espresso'), |
|
93 | - false, |
|
94 | - EE_Datetime_Field::now, |
|
95 | - $timezone |
|
96 | - ), |
|
97 | - 'TXN_total' => new EE_Money_Field( |
|
98 | - 'TXN_total', |
|
99 | - esc_html__('Total value of Transaction', 'event_espresso'), |
|
100 | - false, |
|
101 | - 0 |
|
102 | - ), |
|
103 | - 'TXN_paid' => new EE_Money_Field( |
|
104 | - 'TXN_paid', |
|
105 | - esc_html__('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | - false, |
|
107 | - 0 |
|
108 | - ), |
|
109 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | - 'STS_ID', |
|
111 | - esc_html__('Status ID', 'event_espresso'), |
|
112 | - false, |
|
113 | - EEM_Transaction::failed_status_code, |
|
114 | - 'Status' |
|
115 | - ), |
|
116 | - 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | - 'TXN_session_data', |
|
118 | - esc_html__('Serialized session data', 'event_espresso'), |
|
119 | - true, |
|
120 | - '' |
|
121 | - ), |
|
122 | - 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | - 'TXN_hash_salt', |
|
124 | - esc_html__('Transaction Hash Salt', 'event_espresso'), |
|
125 | - true, |
|
126 | - '' |
|
127 | - ), |
|
128 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | - 'PMD_ID', |
|
130 | - esc_html__("Last Used Payment Method", 'event_espresso'), |
|
131 | - true, |
|
132 | - null, |
|
133 | - 'Payment_Method' |
|
134 | - ), |
|
135 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | - 'TXN_reg_steps', |
|
137 | - esc_html__('Registration Steps', 'event_espresso'), |
|
138 | - false, |
|
139 | - [] |
|
140 | - ), |
|
141 | - ], |
|
142 | - ]; |
|
143 | - $this->_model_relations = [ |
|
144 | - 'Registration' => new EE_Has_Many_Relation(), |
|
145 | - 'Payment' => new EE_Has_Many_Relation(), |
|
146 | - 'Status' => new EE_Belongs_To_Relation(), |
|
147 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | - // you can delete a transaction without needing to delete its line items |
|
149 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | - 'Message' => new EE_Has_Many_Relation(), |
|
151 | - ]; |
|
152 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | - parent::__construct($timezone); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * txn_status_array |
|
159 | - * get list of transaction statuses |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public static function txn_status_array() |
|
165 | - { |
|
166 | - return apply_filters( |
|
167 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | - [ |
|
169 | - EEM_Transaction::overpaid_status_code, |
|
170 | - EEM_Transaction::complete_status_code, |
|
171 | - EEM_Transaction::incomplete_status_code, |
|
172 | - EEM_Transaction::abandoned_status_code, |
|
173 | - EEM_Transaction::failed_status_code, |
|
174 | - ] |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
181 | - * |
|
182 | - * @access public |
|
183 | - * @param string $period |
|
184 | - * @return stdClass[] |
|
185 | - * @throws EE_Error |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - public function get_revenue_per_day_report($period = '-1 month') |
|
189 | - { |
|
190 | - $sql_date = $this->convert_datetime_for_query( |
|
191 | - 'TXN_timestamp', |
|
192 | - date('Y-m-d H:i:s', strtotime($period)), |
|
193 | - 'Y-m-d H:i:s', |
|
194 | - 'UTC' |
|
195 | - ); |
|
196 | - |
|
197 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
198 | - |
|
199 | - return $this->_get_all_wpdb_results( |
|
200 | - [ |
|
201 | - [ |
|
202 | - 'TXN_timestamp' => ['>=', $sql_date], |
|
203 | - ], |
|
204 | - 'group_by' => 'txnDate', |
|
205 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
206 | - ], |
|
207 | - OBJECT, |
|
208 | - [ |
|
209 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
210 | - 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
211 | - ] |
|
212 | - ); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
218 | - * |
|
219 | - * @access public |
|
220 | - * @param string $period |
|
221 | - * @return EE_Transaction[] |
|
222 | - */ |
|
223 | - public function get_revenue_per_event_report($period = '-1 month') |
|
224 | - { |
|
225 | - global $wpdb; |
|
226 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
227 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
228 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
229 | - $event_table = $wpdb->posts; |
|
230 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
231 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
232 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
233 | - $extra_event_on_join = ''; |
|
234 | - // exclude events not authored by user if permissions in effect |
|
235 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
236 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
237 | - } |
|
238 | - |
|
239 | - return $wpdb->get_results( |
|
240 | - "SELECT |
|
21 | + // private instance of the Transaction object |
|
22 | + protected static $_instance; |
|
23 | + |
|
24 | + /** |
|
25 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
26 | + * but payment is pending. This is the state for transactions where payment is promised |
|
27 | + * from an offline gateway. |
|
28 | + */ |
|
29 | + // const open_status_code = 'TPN'; |
|
30 | + |
|
31 | + /** |
|
32 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
33 | + * either due to a technical reason (server or computer crash during registration), |
|
34 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
35 | + */ |
|
36 | + const failed_status_code = 'TFL'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
40 | + * either due to a technical reason (server or computer crash during registration), |
|
41 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
42 | + * HOWEVER... |
|
43 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
44 | + * registrant |
|
45 | + */ |
|
46 | + const abandoned_status_code = 'TAB'; |
|
47 | + |
|
48 | + /** |
|
49 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
50 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
51 | + */ |
|
52 | + const incomplete_status_code = 'TIN'; |
|
53 | + |
|
54 | + /** |
|
55 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
56 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
57 | + */ |
|
58 | + const complete_status_code = 'TCM'; |
|
59 | + |
|
60 | + /** |
|
61 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
62 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
63 | + */ |
|
64 | + const overpaid_status_code = 'TOP'; |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * private constructor to prevent direct creation |
|
69 | + * |
|
70 | + * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
71 | + * any incoming timezone data that gets saved). Note this just sends the timezone info |
|
72 | + * to the date time model field objects. Default is NULL (and will be assumed using |
|
73 | + * the set timezone in the 'timezone_string' wp option) |
|
74 | + * @throws EE_Error |
|
75 | + * @throws ReflectionException |
|
76 | + */ |
|
77 | + protected function __construct(?string $timezone = '') |
|
78 | + { |
|
79 | + $this->singular_item = esc_html__('Transaction', 'event_espresso'); |
|
80 | + $this->plural_item = esc_html__('Transactions', 'event_espresso'); |
|
81 | + |
|
82 | + $this->_tables = [ |
|
83 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
84 | + ]; |
|
85 | + $this->_fields = [ |
|
86 | + 'TransactionTable' => [ |
|
87 | + 'TXN_ID' => new EE_Primary_Key_Int_Field( |
|
88 | + 'TXN_ID', esc_html__('Transaction ID', 'event_espresso') |
|
89 | + ), |
|
90 | + 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | + 'TXN_timestamp', |
|
92 | + esc_html__('date when transaction was created', 'event_espresso'), |
|
93 | + false, |
|
94 | + EE_Datetime_Field::now, |
|
95 | + $timezone |
|
96 | + ), |
|
97 | + 'TXN_total' => new EE_Money_Field( |
|
98 | + 'TXN_total', |
|
99 | + esc_html__('Total value of Transaction', 'event_espresso'), |
|
100 | + false, |
|
101 | + 0 |
|
102 | + ), |
|
103 | + 'TXN_paid' => new EE_Money_Field( |
|
104 | + 'TXN_paid', |
|
105 | + esc_html__('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | + false, |
|
107 | + 0 |
|
108 | + ), |
|
109 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | + 'STS_ID', |
|
111 | + esc_html__('Status ID', 'event_espresso'), |
|
112 | + false, |
|
113 | + EEM_Transaction::failed_status_code, |
|
114 | + 'Status' |
|
115 | + ), |
|
116 | + 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | + 'TXN_session_data', |
|
118 | + esc_html__('Serialized session data', 'event_espresso'), |
|
119 | + true, |
|
120 | + '' |
|
121 | + ), |
|
122 | + 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | + 'TXN_hash_salt', |
|
124 | + esc_html__('Transaction Hash Salt', 'event_espresso'), |
|
125 | + true, |
|
126 | + '' |
|
127 | + ), |
|
128 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | + 'PMD_ID', |
|
130 | + esc_html__("Last Used Payment Method", 'event_espresso'), |
|
131 | + true, |
|
132 | + null, |
|
133 | + 'Payment_Method' |
|
134 | + ), |
|
135 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | + 'TXN_reg_steps', |
|
137 | + esc_html__('Registration Steps', 'event_espresso'), |
|
138 | + false, |
|
139 | + [] |
|
140 | + ), |
|
141 | + ], |
|
142 | + ]; |
|
143 | + $this->_model_relations = [ |
|
144 | + 'Registration' => new EE_Has_Many_Relation(), |
|
145 | + 'Payment' => new EE_Has_Many_Relation(), |
|
146 | + 'Status' => new EE_Belongs_To_Relation(), |
|
147 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | + // you can delete a transaction without needing to delete its line items |
|
149 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | + 'Message' => new EE_Has_Many_Relation(), |
|
151 | + ]; |
|
152 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | + parent::__construct($timezone); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * txn_status_array |
|
159 | + * get list of transaction statuses |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public static function txn_status_array() |
|
165 | + { |
|
166 | + return apply_filters( |
|
167 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | + [ |
|
169 | + EEM_Transaction::overpaid_status_code, |
|
170 | + EEM_Transaction::complete_status_code, |
|
171 | + EEM_Transaction::incomplete_status_code, |
|
172 | + EEM_Transaction::abandoned_status_code, |
|
173 | + EEM_Transaction::failed_status_code, |
|
174 | + ] |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
181 | + * |
|
182 | + * @access public |
|
183 | + * @param string $period |
|
184 | + * @return stdClass[] |
|
185 | + * @throws EE_Error |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + public function get_revenue_per_day_report($period = '-1 month') |
|
189 | + { |
|
190 | + $sql_date = $this->convert_datetime_for_query( |
|
191 | + 'TXN_timestamp', |
|
192 | + date('Y-m-d H:i:s', strtotime($period)), |
|
193 | + 'Y-m-d H:i:s', |
|
194 | + 'UTC' |
|
195 | + ); |
|
196 | + |
|
197 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
198 | + |
|
199 | + return $this->_get_all_wpdb_results( |
|
200 | + [ |
|
201 | + [ |
|
202 | + 'TXN_timestamp' => ['>=', $sql_date], |
|
203 | + ], |
|
204 | + 'group_by' => 'txnDate', |
|
205 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
206 | + ], |
|
207 | + OBJECT, |
|
208 | + [ |
|
209 | + 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
210 | + 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
211 | + ] |
|
212 | + ); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
218 | + * |
|
219 | + * @access public |
|
220 | + * @param string $period |
|
221 | + * @return EE_Transaction[] |
|
222 | + */ |
|
223 | + public function get_revenue_per_event_report($period = '-1 month') |
|
224 | + { |
|
225 | + global $wpdb; |
|
226 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
227 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
228 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
229 | + $event_table = $wpdb->posts; |
|
230 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
231 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
232 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
233 | + $extra_event_on_join = ''; |
|
234 | + // exclude events not authored by user if permissions in effect |
|
235 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
236 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
237 | + } |
|
238 | + |
|
239 | + return $wpdb->get_results( |
|
240 | + "SELECT |
|
241 | 241 | Transaction_Event.event_name AS event_name, |
242 | 242 | SUM(Transaction_Event.paid) AS revenue |
243 | 243 | FROM |
@@ -265,232 +265,232 @@ discard block |
||
265 | 265 | $extra_event_on_join |
266 | 266 | ) AS Transaction_Event |
267 | 267 | GROUP BY event_name" |
268 | - ); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
274 | - * request global variable. Either way, tries to find the current transaction (through |
|
275 | - * the registration pointed to by reg_url_link), if not returns null |
|
276 | - * |
|
277 | - * @param string $reg_url_link |
|
278 | - * @return EE_Transaction |
|
279 | - * @throws EE_Error |
|
280 | - */ |
|
281 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
282 | - { |
|
283 | - if (empty($reg_url_link)) { |
|
284 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
285 | - $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
286 | - } |
|
287 | - return $this->get_one( |
|
288 | - [ |
|
289 | - [ |
|
290 | - 'Registration.REG_url_link' => $reg_url_link, |
|
291 | - ], |
|
292 | - ] |
|
293 | - ); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Updates the provided EE_Transaction with all the applicable payments |
|
299 | - * (or fetch the EE_Transaction from its ID) |
|
300 | - * |
|
301 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
302 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
303 | - * @return array |
|
304 | - * @throws EE_Error |
|
305 | - * @throws ReflectionException |
|
306 | - * @deprecated |
|
307 | - */ |
|
308 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
309 | - { |
|
310 | - EE_Error::doing_it_wrong( |
|
311 | - __CLASS__ . '::' . __FUNCTION__, |
|
312 | - sprintf( |
|
313 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
314 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
315 | - ), |
|
316 | - '4.6.0' |
|
317 | - ); |
|
318 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
319 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
320 | - |
|
321 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
322 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
323 | - ); |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | - * and so we only use wpdb directly and only do minimal joins. |
|
331 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | - * it, it's probably not junk (regardless of what status it has). |
|
334 | - * The downside to this approach is that is addons are listening for object deletions |
|
335 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | - * to catch these types of deletions. |
|
337 | - * |
|
338 | - * @return int |
|
339 | - * @throws EE_Error |
|
340 | - * @throws EE_Error |
|
341 | - * @global WPDB $wpdb |
|
342 | - */ |
|
343 | - public function delete_junk_transactions() |
|
344 | - { |
|
345 | - global $wpdb; |
|
346 | - $deleted = false; |
|
347 | - $time_to_leave_alone = (int) apply_filters( |
|
348 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
349 | - WEEK_IN_SECONDS |
|
350 | - ); |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
355 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
356 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
357 | - */ |
|
358 | - $ids_query = apply_filters( |
|
359 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
360 | - [ |
|
361 | - 0 => [ |
|
362 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
363 | - 'Payment.PAY_ID' => ['IS NULL'], |
|
364 | - 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
365 | - ], |
|
366 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
367 | - 'limit' => 1000, |
|
368 | - ], |
|
369 | - $time_to_leave_alone |
|
370 | - ); |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
375 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
376 | - */ |
|
377 | - $txn_ids = apply_filters( |
|
378 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
379 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
380 | - $time_to_leave_alone |
|
381 | - ); |
|
382 | - // now that we have the ids to delete |
|
383 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
384 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
385 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
386 | - |
|
387 | - // Create IDs placeholder. |
|
388 | - $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
389 | - |
|
390 | - // Glue it together to use inside $wpdb->prepare. |
|
391 | - $format = implode(', ', $placeholders); |
|
392 | - |
|
393 | - // let's get deleting... |
|
394 | - // We got the ids from the original query to get them FROM |
|
395 | - // the db (which is sanitized) so no need to prepare them again. |
|
396 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
397 | - $deleted = $wpdb->query($query); |
|
398 | - } |
|
399 | - if ($deleted) { |
|
400 | - /** |
|
401 | - * Allows code to do something after the transactions have been deleted. |
|
402 | - */ |
|
403 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
404 | - } |
|
405 | - |
|
406 | - return $deleted; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * @param array $transaction_IDs |
|
412 | - * @return bool |
|
413 | - */ |
|
414 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
415 | - { |
|
416 | - $locked_transactions = get_option('ee_locked_transactions', []); |
|
417 | - $update = false; |
|
418 | - foreach ($transaction_IDs as $TXN_ID) { |
|
419 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
420 | - unset($locked_transactions[ $TXN_ID ]); |
|
421 | - $update = true; |
|
422 | - } |
|
423 | - } |
|
424 | - if ($update) { |
|
425 | - update_option('ee_locked_transactions', $locked_transactions); |
|
426 | - } |
|
427 | - |
|
428 | - return $update; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
434 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
435 | - * |
|
436 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
437 | - * @throws EE_Error |
|
438 | - * @throws InvalidArgumentException |
|
439 | - * @throws InvalidDataTypeException |
|
440 | - * @throws InvalidInterfaceException |
|
441 | - */ |
|
442 | - public function get_transactions_in_progress() |
|
443 | - { |
|
444 | - return $this->_get_transactions_in_progress(); |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
450 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
451 | - * |
|
452 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
453 | - * @throws EE_Error |
|
454 | - * @throws InvalidArgumentException |
|
455 | - * @throws InvalidDataTypeException |
|
456 | - * @throws InvalidInterfaceException |
|
457 | - */ |
|
458 | - public function get_transactions_not_in_progress() |
|
459 | - { |
|
460 | - return $this->_get_transactions_in_progress('<='); |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * @param string $comparison |
|
466 | - * @return EE_Transaction[] |
|
467 | - * @throws EE_Error |
|
468 | - * @throws InvalidArgumentException |
|
469 | - * @throws InvalidDataTypeException |
|
470 | - * @throws InvalidInterfaceException |
|
471 | - */ |
|
472 | - private function _get_transactions_in_progress($comparison = '>=') |
|
473 | - { |
|
474 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
475 | - ? $comparison |
|
476 | - : '>='; |
|
477 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
478 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
479 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
480 | - ); |
|
481 | - return $this->get_all( |
|
482 | - [ |
|
483 | - [ |
|
484 | - 'TXN_timestamp' => [ |
|
485 | - $comparison, |
|
486 | - $session_lifespan->expiration(), |
|
487 | - ], |
|
488 | - 'STS_ID' => [ |
|
489 | - '!=', |
|
490 | - EEM_Transaction::complete_status_code, |
|
491 | - ], |
|
492 | - ], |
|
493 | - ] |
|
494 | - ); |
|
495 | - } |
|
268 | + ); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
274 | + * request global variable. Either way, tries to find the current transaction (through |
|
275 | + * the registration pointed to by reg_url_link), if not returns null |
|
276 | + * |
|
277 | + * @param string $reg_url_link |
|
278 | + * @return EE_Transaction |
|
279 | + * @throws EE_Error |
|
280 | + */ |
|
281 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
282 | + { |
|
283 | + if (empty($reg_url_link)) { |
|
284 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
285 | + $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
286 | + } |
|
287 | + return $this->get_one( |
|
288 | + [ |
|
289 | + [ |
|
290 | + 'Registration.REG_url_link' => $reg_url_link, |
|
291 | + ], |
|
292 | + ] |
|
293 | + ); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Updates the provided EE_Transaction with all the applicable payments |
|
299 | + * (or fetch the EE_Transaction from its ID) |
|
300 | + * |
|
301 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
302 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
303 | + * @return array |
|
304 | + * @throws EE_Error |
|
305 | + * @throws ReflectionException |
|
306 | + * @deprecated |
|
307 | + */ |
|
308 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
309 | + { |
|
310 | + EE_Error::doing_it_wrong( |
|
311 | + __CLASS__ . '::' . __FUNCTION__, |
|
312 | + sprintf( |
|
313 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
314 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
315 | + ), |
|
316 | + '4.6.0' |
|
317 | + ); |
|
318 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
319 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
320 | + |
|
321 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
322 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
323 | + ); |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | + * and so we only use wpdb directly and only do minimal joins. |
|
331 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | + * it, it's probably not junk (regardless of what status it has). |
|
334 | + * The downside to this approach is that is addons are listening for object deletions |
|
335 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | + * to catch these types of deletions. |
|
337 | + * |
|
338 | + * @return int |
|
339 | + * @throws EE_Error |
|
340 | + * @throws EE_Error |
|
341 | + * @global WPDB $wpdb |
|
342 | + */ |
|
343 | + public function delete_junk_transactions() |
|
344 | + { |
|
345 | + global $wpdb; |
|
346 | + $deleted = false; |
|
347 | + $time_to_leave_alone = (int) apply_filters( |
|
348 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
349 | + WEEK_IN_SECONDS |
|
350 | + ); |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
355 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
356 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
357 | + */ |
|
358 | + $ids_query = apply_filters( |
|
359 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
360 | + [ |
|
361 | + 0 => [ |
|
362 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
363 | + 'Payment.PAY_ID' => ['IS NULL'], |
|
364 | + 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
365 | + ], |
|
366 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
367 | + 'limit' => 1000, |
|
368 | + ], |
|
369 | + $time_to_leave_alone |
|
370 | + ); |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
375 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
376 | + */ |
|
377 | + $txn_ids = apply_filters( |
|
378 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
379 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
380 | + $time_to_leave_alone |
|
381 | + ); |
|
382 | + // now that we have the ids to delete |
|
383 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
384 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
385 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
386 | + |
|
387 | + // Create IDs placeholder. |
|
388 | + $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
389 | + |
|
390 | + // Glue it together to use inside $wpdb->prepare. |
|
391 | + $format = implode(', ', $placeholders); |
|
392 | + |
|
393 | + // let's get deleting... |
|
394 | + // We got the ids from the original query to get them FROM |
|
395 | + // the db (which is sanitized) so no need to prepare them again. |
|
396 | + $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
397 | + $deleted = $wpdb->query($query); |
|
398 | + } |
|
399 | + if ($deleted) { |
|
400 | + /** |
|
401 | + * Allows code to do something after the transactions have been deleted. |
|
402 | + */ |
|
403 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
404 | + } |
|
405 | + |
|
406 | + return $deleted; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * @param array $transaction_IDs |
|
412 | + * @return bool |
|
413 | + */ |
|
414 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
415 | + { |
|
416 | + $locked_transactions = get_option('ee_locked_transactions', []); |
|
417 | + $update = false; |
|
418 | + foreach ($transaction_IDs as $TXN_ID) { |
|
419 | + if (isset($locked_transactions[ $TXN_ID ])) { |
|
420 | + unset($locked_transactions[ $TXN_ID ]); |
|
421 | + $update = true; |
|
422 | + } |
|
423 | + } |
|
424 | + if ($update) { |
|
425 | + update_option('ee_locked_transactions', $locked_transactions); |
|
426 | + } |
|
427 | + |
|
428 | + return $update; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
434 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
435 | + * |
|
436 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
437 | + * @throws EE_Error |
|
438 | + * @throws InvalidArgumentException |
|
439 | + * @throws InvalidDataTypeException |
|
440 | + * @throws InvalidInterfaceException |
|
441 | + */ |
|
442 | + public function get_transactions_in_progress() |
|
443 | + { |
|
444 | + return $this->_get_transactions_in_progress(); |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
450 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
451 | + * |
|
452 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
453 | + * @throws EE_Error |
|
454 | + * @throws InvalidArgumentException |
|
455 | + * @throws InvalidDataTypeException |
|
456 | + * @throws InvalidInterfaceException |
|
457 | + */ |
|
458 | + public function get_transactions_not_in_progress() |
|
459 | + { |
|
460 | + return $this->_get_transactions_in_progress('<='); |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * @param string $comparison |
|
466 | + * @return EE_Transaction[] |
|
467 | + * @throws EE_Error |
|
468 | + * @throws InvalidArgumentException |
|
469 | + * @throws InvalidDataTypeException |
|
470 | + * @throws InvalidInterfaceException |
|
471 | + */ |
|
472 | + private function _get_transactions_in_progress($comparison = '>=') |
|
473 | + { |
|
474 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
475 | + ? $comparison |
|
476 | + : '>='; |
|
477 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
478 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
479 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
480 | + ); |
|
481 | + return $this->get_all( |
|
482 | + [ |
|
483 | + [ |
|
484 | + 'TXN_timestamp' => [ |
|
485 | + $comparison, |
|
486 | + $session_lifespan->expiration(), |
|
487 | + ], |
|
488 | + 'STS_ID' => [ |
|
489 | + '!=', |
|
490 | + EEM_Transaction::complete_status_code, |
|
491 | + ], |
|
492 | + ], |
|
493 | + ] |
|
494 | + ); |
|
495 | + } |
|
496 | 496 | } |
@@ -3,36 +3,36 @@ |
||
3 | 3 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @param string $table_column name fo column for field |
|
8 | - * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
9 | - * @param boolean $nullable |
|
10 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | - * dbe a string |
|
12 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | - * "EEM_" |
|
14 | - */ |
|
15 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | - { |
|
17 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | - $this->setSchemaType('integer'); |
|
19 | - } |
|
6 | + /** |
|
7 | + * @param string $table_column name fo column for field |
|
8 | + * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
9 | + * @param boolean $nullable |
|
10 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | + * dbe a string |
|
12 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | + * "EEM_" |
|
14 | + */ |
|
15 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | + { |
|
17 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | + $this->setSchemaType('integer'); |
|
19 | + } |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | - * @return int |
|
25 | - */ |
|
26 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | - { |
|
28 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | - } |
|
31 | - return absint($value_inputted_for_field_on_model_object); |
|
32 | - } |
|
22 | + /** |
|
23 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | + * @return int |
|
25 | + */ |
|
26 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | + { |
|
28 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | + } |
|
31 | + return absint($value_inputted_for_field_on_model_object); |
|
32 | + } |
|
33 | 33 | |
34 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | - { |
|
36 | - return intval($value_found_in_db_for_model_object); |
|
37 | - } |
|
34 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | + { |
|
36 | + return intval($value_found_in_db_for_model_object); |
|
37 | + } |
|
38 | 38 | } |
@@ -13,39 +13,39 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_WP_User_Field extends EE_Foreign_Key_Int_Field |
15 | 15 | { |
16 | - /** |
|
17 | - * No need to provide a default or the model pointed to- the default is |
|
18 | - * always get_current_user_id() and the model pointed to is always WP_User |
|
19 | - * |
|
20 | - * @param string $table_column name fo column for field |
|
21 | - * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
22 | - * @param boolean $nullable |
|
23 | - */ |
|
24 | - public function __construct($table_column, $nicename, $nullable) |
|
25 | - { |
|
26 | - parent::__construct($table_column, $nicename, $nullable, null, 'WP_User'); |
|
27 | - } |
|
16 | + /** |
|
17 | + * No need to provide a default or the model pointed to- the default is |
|
18 | + * always get_current_user_id() and the model pointed to is always WP_User |
|
19 | + * |
|
20 | + * @param string $table_column name fo column for field |
|
21 | + * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
22 | + * @param boolean $nullable |
|
23 | + */ |
|
24 | + public function __construct($table_column, $nicename, $nullable) |
|
25 | + { |
|
26 | + parent::__construct($table_column, $nicename, $nullable, null, 'WP_User'); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Gets the default which is always the current user. This can't be set when initially |
|
31 | - * constructing the model field because that's done before $current_user is set |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function get_default_value() |
|
36 | - { |
|
37 | - if (did_action('init')) { |
|
38 | - return get_current_user_id(); |
|
39 | - } else { |
|
40 | - EE_Error::doing_it_wrong( |
|
41 | - 'EE_WP_User_Field::get_default_value', |
|
42 | - esc_html__( |
|
43 | - 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '4.6.20' |
|
47 | - ); |
|
48 | - return 1; |
|
49 | - } |
|
50 | - } |
|
29 | + /** |
|
30 | + * Gets the default which is always the current user. This can't be set when initially |
|
31 | + * constructing the model field because that's done before $current_user is set |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function get_default_value() |
|
36 | + { |
|
37 | + if (did_action('init')) { |
|
38 | + return get_current_user_id(); |
|
39 | + } else { |
|
40 | + EE_Error::doing_it_wrong( |
|
41 | + 'EE_WP_User_Field::get_default_value', |
|
42 | + esc_html__( |
|
43 | + 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '4.6.20' |
|
47 | + ); |
|
48 | + return 1; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public static function instance() |
43 | 43 | { |
44 | 44 | // check if class object is instantiated |
45 | - if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
45 | + if ( ! self::$_instance instanceof EE_Transaction_Payments) { |
|
46 | 46 | self::$_instance = new self(); |
47 | 47 | } |
48 | 48 | return self::$_instance; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true) |
62 | 62 | { |
63 | 63 | $total_line_item = $transaction->total_line_item(); |
64 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
64 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
65 | 65 | EE_Error::add_error( |
66 | 66 | sprintf( |
67 | 67 | esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'), |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true) |
101 | 101 | { |
102 | 102 | // verify transaction |
103 | - if (! $transaction instanceof EE_Transaction) { |
|
103 | + if ( ! $transaction instanceof EE_Transaction) { |
|
104 | 104 | EE_Error::add_error( |
105 | 105 | esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
106 | 106 | __FILE__, |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) { |
116 | 116 | $transaction->set_paid($total_paid); |
117 | 117 | // maybe update status, and make sure to save transaction if not done already |
118 | - if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
118 | + if ( ! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
119 | 119 | if ($update_txn) { |
120 | 120 | return $transaction->save() ? true : false; |
121 | 121 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $payment_status = EEM_Payment::status_id_approved |
145 | 145 | ) { |
146 | 146 | // verify transaction |
147 | - if (! $transaction instanceof EE_Transaction) { |
|
147 | + if ( ! $transaction instanceof EE_Transaction) { |
|
148 | 148 | EE_Error::add_error( |
149 | 149 | esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
150 | 150 | __FILE__, |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | public function delete_payment_and_update_transaction(EE_Payment $payment) |
178 | 178 | { |
179 | 179 | // verify payment |
180 | - if (! $payment instanceof EE_Payment) { |
|
180 | + if ( ! $payment instanceof EE_Payment) { |
|
181 | 181 | EE_Error::add_error( |
182 | 182 | esc_html__('A valid Payment object was not received.', 'event_espresso'), |
183 | 183 | __FILE__, |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | ); |
187 | 187 | return false; |
188 | 188 | } |
189 | - if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
189 | + if ( ! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | - if (! $payment->delete()) { |
|
192 | + if ( ! $payment->delete()) { |
|
193 | 193 | EE_Error::add_error( |
194 | 194 | esc_html__('The payment could not be deleted.', 'event_espresso'), |
195 | 195 | __FILE__, |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
215 | 215 | // however the payment was still deleted. |
216 | - if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
216 | + if ( ! $this->calculate_total_payments_and_update_status($transaction)) { |
|
217 | 217 | EE_Error::add_attention( |
218 | 218 | esc_html__( |
219 | 219 | 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params |
256 | 256 | : array(array('PAY_ID' => $payment->ID())); |
257 | 257 | $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
258 | - if (! empty($registration_payments)) { |
|
258 | + if ( ! empty($registration_payments)) { |
|
259 | 259 | foreach ($registration_payments as $registration_payment) { |
260 | 260 | if ($registration_payment instanceof EE_Registration_Payment) { |
261 | 261 | $amount_paid = $registration_payment->amount(); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true) |
322 | 322 | { |
323 | 323 | EE_Error::doing_it_wrong( |
324 | - __CLASS__ . '::' . __FUNCTION__, |
|
324 | + __CLASS__.'::'.__FUNCTION__, |
|
325 | 325 | sprintf( |
326 | 326 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
327 | 327 | 'EE_Transaction::update_status_based_on_total_paid()' |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | '5.0.0' |
331 | 331 | ); |
332 | 332 | // verify transaction |
333 | - if (! $transaction instanceof EE_Transaction) { |
|
333 | + if ( ! $transaction instanceof EE_Transaction) { |
|
334 | 334 | EE_Error::add_error( |
335 | 335 | esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
336 | 336 | __FILE__, |
@@ -14,424 +14,424 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Transaction_Payments |
16 | 16 | { |
17 | - /** |
|
18 | - * @var EE_Transaction_Payments $_instance |
|
19 | - * @access private |
|
20 | - */ |
|
21 | - private static $_instance; |
|
22 | - |
|
23 | - /** |
|
24 | - * @deprecated |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_old_txn_status; |
|
28 | - |
|
29 | - /** |
|
30 | - * @deprecated |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $_new_txn_status; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @singleton method used to instantiate class object |
|
38 | - * @access public |
|
39 | - * @return EE_Transaction_Payments instance |
|
40 | - */ |
|
41 | - public static function instance() |
|
42 | - { |
|
43 | - // check if class object is instantiated |
|
44 | - if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
45 | - self::$_instance = new self(); |
|
46 | - } |
|
47 | - return self::$_instance; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * recalculate_transaction_total |
|
53 | - * |
|
54 | - * @access private |
|
55 | - * @param EE_Transaction $transaction |
|
56 | - * @param bool $update_txn |
|
57 | - * @return bool true if TXN total was updated, false if not |
|
58 | - * @throws \EE_Error |
|
59 | - */ |
|
60 | - public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true) |
|
61 | - { |
|
62 | - $total_line_item = $transaction->total_line_item(); |
|
63 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
64 | - EE_Error::add_error( |
|
65 | - sprintf( |
|
66 | - esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'), |
|
67 | - $transaction->ID() |
|
68 | - ), |
|
69 | - __FILE__, |
|
70 | - __FUNCTION__, |
|
71 | - __LINE__ |
|
72 | - ); |
|
73 | - return false; |
|
74 | - } |
|
75 | - $new_total = $total_line_item->recalculate_total_including_taxes(); |
|
76 | - $transaction->set_total($new_total); |
|
77 | - if ($update_txn) { |
|
78 | - return $transaction->save() ? true : false; |
|
79 | - } |
|
80 | - return false; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Updates the provided EE_Transaction with all the applicable payments |
|
86 | - * returns a boolean for whether the TXN was saved to the db |
|
87 | - * (meaning a status change occurred) |
|
88 | - * or not saved (which could **still** mean that |
|
89 | - * the TXN status changed, but just was not yet saved). |
|
90 | - * So if passing a value of false for the $update_txn param, |
|
91 | - * then client code needs to take responsibility for saving the TXN |
|
92 | - * regardless of what happens within EE_Transaction_Payments; |
|
93 | - * |
|
94 | - * @param EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID |
|
95 | - * @param boolean $update_txn whether to save the TXN |
|
96 | - * @return boolean whether the TXN was saved |
|
97 | - * @throws \EE_Error |
|
98 | - */ |
|
99 | - public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true) |
|
100 | - { |
|
101 | - // verify transaction |
|
102 | - if (! $transaction instanceof EE_Transaction) { |
|
103 | - EE_Error::add_error( |
|
104 | - esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
105 | - __FILE__, |
|
106 | - __FUNCTION__, |
|
107 | - __LINE__ |
|
108 | - ); |
|
109 | - return false; |
|
110 | - } |
|
111 | - // calculate total paid |
|
112 | - $total_paid = $this->recalculate_total_payments_for_transaction($transaction); |
|
113 | - // if total paid has changed |
|
114 | - if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) { |
|
115 | - $transaction->set_paid($total_paid); |
|
116 | - // maybe update status, and make sure to save transaction if not done already |
|
117 | - if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
118 | - if ($update_txn) { |
|
119 | - return $transaction->save() ? true : false; |
|
120 | - } |
|
121 | - } else { |
|
122 | - // the status got updated and was saved by |
|
123 | - // update_transaction_status_based_on_total_paid() |
|
124 | - return true; |
|
125 | - } |
|
126 | - } |
|
127 | - return false; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * recalculate_total_payments_for_transaction |
|
133 | - * |
|
134 | - * @access public |
|
135 | - * @param EE_Transaction $transaction |
|
136 | - * @param string $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved). |
|
137 | - * By default, searches for approved payments |
|
138 | - * @return float|false float on success, false on fail |
|
139 | - * @throws \EE_Error |
|
140 | - */ |
|
141 | - public function recalculate_total_payments_for_transaction( |
|
142 | - EE_Transaction $transaction, |
|
143 | - $payment_status = EEM_Payment::status_id_approved |
|
144 | - ) { |
|
145 | - // verify transaction |
|
146 | - if (! $transaction instanceof EE_Transaction) { |
|
147 | - EE_Error::add_error( |
|
148 | - esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
149 | - __FILE__, |
|
150 | - __FUNCTION__, |
|
151 | - __LINE__ |
|
152 | - ); |
|
153 | - return false; |
|
154 | - } |
|
155 | - // ensure Payment model is loaded |
|
156 | - EE_Registry::instance()->load_model('Payment'); |
|
157 | - // calls EEM_Base::sum() |
|
158 | - return EEM_Payment::instance()->sum( |
|
159 | - // query params |
|
160 | - array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)), |
|
161 | - // field to sum |
|
162 | - 'PAY_amount' |
|
163 | - ); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * delete_payment_and_update_transaction |
|
169 | - * Before deleting the selected payment, we fetch it's transaction, |
|
170 | - * then delete the payment, and update the transactions' amount paid. |
|
171 | - * |
|
172 | - * @param EE_Payment $payment |
|
173 | - * @return boolean |
|
174 | - * @throws \EE_Error |
|
175 | - */ |
|
176 | - public function delete_payment_and_update_transaction(EE_Payment $payment) |
|
177 | - { |
|
178 | - // verify payment |
|
179 | - if (! $payment instanceof EE_Payment) { |
|
180 | - EE_Error::add_error( |
|
181 | - esc_html__('A valid Payment object was not received.', 'event_espresso'), |
|
182 | - __FILE__, |
|
183 | - __FUNCTION__, |
|
184 | - __LINE__ |
|
185 | - ); |
|
186 | - return false; |
|
187 | - } |
|
188 | - if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
189 | - return false; |
|
190 | - } |
|
191 | - if (! $payment->delete()) { |
|
192 | - EE_Error::add_error( |
|
193 | - esc_html__('The payment could not be deleted.', 'event_espresso'), |
|
194 | - __FILE__, |
|
195 | - __FUNCTION__, |
|
196 | - __LINE__ |
|
197 | - ); |
|
198 | - return false; |
|
199 | - } |
|
200 | - |
|
201 | - $transaction = $payment->transaction(); |
|
202 | - $TXN_status = $transaction->status_ID(); |
|
203 | - if ( |
|
204 | - $TXN_status === EEM_Transaction::abandoned_status_code |
|
205 | - || $TXN_status === EEM_Transaction::failed_status_code |
|
206 | - || $payment->amount() === 0 |
|
207 | - ) { |
|
208 | - EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso')); |
|
209 | - return true; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
|
214 | - // however the payment was still deleted. |
|
215 | - if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
216 | - EE_Error::add_attention( |
|
217 | - esc_html__( |
|
218 | - 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - __FILE__, |
|
222 | - __FUNCTION__, |
|
223 | - __LINE__ |
|
224 | - ); |
|
225 | - return true; |
|
226 | - } |
|
227 | - |
|
228 | - EE_Error::add_success( |
|
229 | - esc_html__( |
|
230 | - 'The Payment was successfully deleted, and the Transaction has been updated accordingly.', |
|
231 | - 'event_espresso' |
|
232 | - ) |
|
233 | - ); |
|
234 | - return true; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * delete_registration_payments_and_update_registrations |
|
240 | - * |
|
241 | - * removes all registration payment records associated with a payment |
|
242 | - * and subtracts their amounts from the corresponding registrations REG_paid field |
|
243 | - * |
|
244 | - * @param EE_Payment $payment |
|
245 | - * @param array $reg_payment_query_params |
|
246 | - * @return bool |
|
247 | - * @throws \EE_Error |
|
248 | - */ |
|
249 | - public function delete_registration_payments_and_update_registrations( |
|
250 | - EE_Payment $payment, |
|
251 | - $reg_payment_query_params = array() |
|
252 | - ) { |
|
253 | - $save_payment = false; |
|
254 | - $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params |
|
255 | - : array(array('PAY_ID' => $payment->ID())); |
|
256 | - $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
|
257 | - if (! empty($registration_payments)) { |
|
258 | - foreach ($registration_payments as $registration_payment) { |
|
259 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
260 | - $amount_paid = $registration_payment->amount(); |
|
261 | - $registration = $registration_payment->registration(); |
|
262 | - if ($registration instanceof EE_Registration) { |
|
263 | - $registration->set_paid($registration->paid() - $amount_paid); |
|
264 | - if ($registration->save() !== false) { |
|
265 | - $registration_payment->delete_permanently(); |
|
266 | - $save_payment = true; |
|
267 | - } |
|
268 | - } else { |
|
269 | - EE_Error::add_error( |
|
270 | - sprintf( |
|
271 | - esc_html__( |
|
272 | - 'An invalid Registration object was associated with Registration Payment ID# %1$d.', |
|
273 | - 'event_espresso' |
|
274 | - ), |
|
275 | - $registration_payment->ID() |
|
276 | - ), |
|
277 | - __FILE__, |
|
278 | - __FUNCTION__, |
|
279 | - __LINE__ |
|
280 | - ); |
|
281 | - return false; |
|
282 | - } |
|
283 | - } else { |
|
284 | - EE_Error::add_error( |
|
285 | - sprintf( |
|
286 | - esc_html__( |
|
287 | - 'An invalid Registration Payment object was associated with payment ID# %1$d.', |
|
288 | - 'event_espresso' |
|
289 | - ), |
|
290 | - $payment->ID() |
|
291 | - ), |
|
292 | - __FILE__, |
|
293 | - __FUNCTION__, |
|
294 | - __LINE__ |
|
295 | - ); |
|
296 | - return false; |
|
297 | - } |
|
298 | - } |
|
299 | - } |
|
300 | - if ($save_payment) { |
|
301 | - $payment->save(); |
|
302 | - } |
|
303 | - return true; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - /********************************** DEPRECATED METHODS **********************************/ |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * possibly toggles TXN status |
|
313 | - * |
|
314 | - * @deprecated 4.9.1 |
|
315 | - * @param EE_Transaction $transaction |
|
316 | - * @param boolean $update_txn whether to save the TXN |
|
317 | - * @return boolean whether the TXN was saved |
|
318 | - * @throws \EE_Error |
|
319 | - */ |
|
320 | - public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true) |
|
321 | - { |
|
322 | - EE_Error::doing_it_wrong( |
|
323 | - __CLASS__ . '::' . __FUNCTION__, |
|
324 | - sprintf( |
|
325 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
326 | - 'EE_Transaction::update_status_based_on_total_paid()' |
|
327 | - ), |
|
328 | - '4.9.1', |
|
329 | - '5.0.0' |
|
330 | - ); |
|
331 | - // verify transaction |
|
332 | - if (! $transaction instanceof EE_Transaction) { |
|
333 | - EE_Error::add_error( |
|
334 | - esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
335 | - __FILE__, |
|
336 | - __FUNCTION__, |
|
337 | - __LINE__ |
|
338 | - ); |
|
339 | - return false; |
|
340 | - } |
|
341 | - // set transaction status based on comparison of TXN_paid vs TXN_total |
|
342 | - return $transaction->update_status_based_on_total_paid($update_txn); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @deprecated 4.9.12 |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - public function old_txn_status() |
|
351 | - { |
|
352 | - EE_Error::doing_it_wrong( |
|
353 | - __METHOD__, |
|
354 | - esc_html__( |
|
355 | - 'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.', |
|
356 | - 'event_espresso' |
|
357 | - ), |
|
358 | - '4.9.12' |
|
359 | - ); |
|
360 | - return $this->_old_txn_status; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @deprecated 4.9.12 |
|
366 | - * @param string $old_txn_status |
|
367 | - */ |
|
368 | - public function set_old_txn_status($old_txn_status) |
|
369 | - { |
|
370 | - EE_Error::doing_it_wrong( |
|
371 | - __METHOD__, |
|
372 | - esc_html__( |
|
373 | - 'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.', |
|
374 | - 'event_espresso' |
|
375 | - ), |
|
376 | - '4.9.12' |
|
377 | - ); |
|
378 | - // only set the first time |
|
379 | - if ($this->_old_txn_status === null) { |
|
380 | - $this->_old_txn_status = $old_txn_status; |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * @deprecated 4.9.12 |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function new_txn_status() |
|
390 | - { |
|
391 | - EE_Error::doing_it_wrong( |
|
392 | - __METHOD__, |
|
393 | - esc_html__( |
|
394 | - 'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.', |
|
395 | - 'event_espresso' |
|
396 | - ), |
|
397 | - '4.9.12' |
|
398 | - ); |
|
399 | - return $this->_new_txn_status; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @deprecated 4.9.12 |
|
405 | - * @param string $new_txn_status |
|
406 | - */ |
|
407 | - public function set_new_txn_status($new_txn_status) |
|
408 | - { |
|
409 | - EE_Error::doing_it_wrong( |
|
410 | - __METHOD__, |
|
411 | - esc_html__( |
|
412 | - 'This logic has been removed. Please just use \EE_Transaction::set_status() instead.', |
|
413 | - 'event_espresso' |
|
414 | - ), |
|
415 | - '4.9.12' |
|
416 | - ); |
|
417 | - $this->_new_txn_status = $new_txn_status; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * @deprecated 4.9.12 |
|
423 | - * @return bool |
|
424 | - */ |
|
425 | - public function txn_status_updated() |
|
426 | - { |
|
427 | - EE_Error::doing_it_wrong( |
|
428 | - __METHOD__, |
|
429 | - esc_html__( |
|
430 | - 'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.', |
|
431 | - 'event_espresso' |
|
432 | - ), |
|
433 | - '4.9.12' |
|
434 | - ); |
|
435 | - return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false; |
|
436 | - } |
|
17 | + /** |
|
18 | + * @var EE_Transaction_Payments $_instance |
|
19 | + * @access private |
|
20 | + */ |
|
21 | + private static $_instance; |
|
22 | + |
|
23 | + /** |
|
24 | + * @deprecated |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_old_txn_status; |
|
28 | + |
|
29 | + /** |
|
30 | + * @deprecated |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $_new_txn_status; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @singleton method used to instantiate class object |
|
38 | + * @access public |
|
39 | + * @return EE_Transaction_Payments instance |
|
40 | + */ |
|
41 | + public static function instance() |
|
42 | + { |
|
43 | + // check if class object is instantiated |
|
44 | + if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
45 | + self::$_instance = new self(); |
|
46 | + } |
|
47 | + return self::$_instance; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * recalculate_transaction_total |
|
53 | + * |
|
54 | + * @access private |
|
55 | + * @param EE_Transaction $transaction |
|
56 | + * @param bool $update_txn |
|
57 | + * @return bool true if TXN total was updated, false if not |
|
58 | + * @throws \EE_Error |
|
59 | + */ |
|
60 | + public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true) |
|
61 | + { |
|
62 | + $total_line_item = $transaction->total_line_item(); |
|
63 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
64 | + EE_Error::add_error( |
|
65 | + sprintf( |
|
66 | + esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'), |
|
67 | + $transaction->ID() |
|
68 | + ), |
|
69 | + __FILE__, |
|
70 | + __FUNCTION__, |
|
71 | + __LINE__ |
|
72 | + ); |
|
73 | + return false; |
|
74 | + } |
|
75 | + $new_total = $total_line_item->recalculate_total_including_taxes(); |
|
76 | + $transaction->set_total($new_total); |
|
77 | + if ($update_txn) { |
|
78 | + return $transaction->save() ? true : false; |
|
79 | + } |
|
80 | + return false; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Updates the provided EE_Transaction with all the applicable payments |
|
86 | + * returns a boolean for whether the TXN was saved to the db |
|
87 | + * (meaning a status change occurred) |
|
88 | + * or not saved (which could **still** mean that |
|
89 | + * the TXN status changed, but just was not yet saved). |
|
90 | + * So if passing a value of false for the $update_txn param, |
|
91 | + * then client code needs to take responsibility for saving the TXN |
|
92 | + * regardless of what happens within EE_Transaction_Payments; |
|
93 | + * |
|
94 | + * @param EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID |
|
95 | + * @param boolean $update_txn whether to save the TXN |
|
96 | + * @return boolean whether the TXN was saved |
|
97 | + * @throws \EE_Error |
|
98 | + */ |
|
99 | + public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true) |
|
100 | + { |
|
101 | + // verify transaction |
|
102 | + if (! $transaction instanceof EE_Transaction) { |
|
103 | + EE_Error::add_error( |
|
104 | + esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
105 | + __FILE__, |
|
106 | + __FUNCTION__, |
|
107 | + __LINE__ |
|
108 | + ); |
|
109 | + return false; |
|
110 | + } |
|
111 | + // calculate total paid |
|
112 | + $total_paid = $this->recalculate_total_payments_for_transaction($transaction); |
|
113 | + // if total paid has changed |
|
114 | + if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) { |
|
115 | + $transaction->set_paid($total_paid); |
|
116 | + // maybe update status, and make sure to save transaction if not done already |
|
117 | + if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
118 | + if ($update_txn) { |
|
119 | + return $transaction->save() ? true : false; |
|
120 | + } |
|
121 | + } else { |
|
122 | + // the status got updated and was saved by |
|
123 | + // update_transaction_status_based_on_total_paid() |
|
124 | + return true; |
|
125 | + } |
|
126 | + } |
|
127 | + return false; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * recalculate_total_payments_for_transaction |
|
133 | + * |
|
134 | + * @access public |
|
135 | + * @param EE_Transaction $transaction |
|
136 | + * @param string $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved). |
|
137 | + * By default, searches for approved payments |
|
138 | + * @return float|false float on success, false on fail |
|
139 | + * @throws \EE_Error |
|
140 | + */ |
|
141 | + public function recalculate_total_payments_for_transaction( |
|
142 | + EE_Transaction $transaction, |
|
143 | + $payment_status = EEM_Payment::status_id_approved |
|
144 | + ) { |
|
145 | + // verify transaction |
|
146 | + if (! $transaction instanceof EE_Transaction) { |
|
147 | + EE_Error::add_error( |
|
148 | + esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
149 | + __FILE__, |
|
150 | + __FUNCTION__, |
|
151 | + __LINE__ |
|
152 | + ); |
|
153 | + return false; |
|
154 | + } |
|
155 | + // ensure Payment model is loaded |
|
156 | + EE_Registry::instance()->load_model('Payment'); |
|
157 | + // calls EEM_Base::sum() |
|
158 | + return EEM_Payment::instance()->sum( |
|
159 | + // query params |
|
160 | + array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)), |
|
161 | + // field to sum |
|
162 | + 'PAY_amount' |
|
163 | + ); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * delete_payment_and_update_transaction |
|
169 | + * Before deleting the selected payment, we fetch it's transaction, |
|
170 | + * then delete the payment, and update the transactions' amount paid. |
|
171 | + * |
|
172 | + * @param EE_Payment $payment |
|
173 | + * @return boolean |
|
174 | + * @throws \EE_Error |
|
175 | + */ |
|
176 | + public function delete_payment_and_update_transaction(EE_Payment $payment) |
|
177 | + { |
|
178 | + // verify payment |
|
179 | + if (! $payment instanceof EE_Payment) { |
|
180 | + EE_Error::add_error( |
|
181 | + esc_html__('A valid Payment object was not received.', 'event_espresso'), |
|
182 | + __FILE__, |
|
183 | + __FUNCTION__, |
|
184 | + __LINE__ |
|
185 | + ); |
|
186 | + return false; |
|
187 | + } |
|
188 | + if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
189 | + return false; |
|
190 | + } |
|
191 | + if (! $payment->delete()) { |
|
192 | + EE_Error::add_error( |
|
193 | + esc_html__('The payment could not be deleted.', 'event_espresso'), |
|
194 | + __FILE__, |
|
195 | + __FUNCTION__, |
|
196 | + __LINE__ |
|
197 | + ); |
|
198 | + return false; |
|
199 | + } |
|
200 | + |
|
201 | + $transaction = $payment->transaction(); |
|
202 | + $TXN_status = $transaction->status_ID(); |
|
203 | + if ( |
|
204 | + $TXN_status === EEM_Transaction::abandoned_status_code |
|
205 | + || $TXN_status === EEM_Transaction::failed_status_code |
|
206 | + || $payment->amount() === 0 |
|
207 | + ) { |
|
208 | + EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso')); |
|
209 | + return true; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
|
214 | + // however the payment was still deleted. |
|
215 | + if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
216 | + EE_Error::add_attention( |
|
217 | + esc_html__( |
|
218 | + 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + __FILE__, |
|
222 | + __FUNCTION__, |
|
223 | + __LINE__ |
|
224 | + ); |
|
225 | + return true; |
|
226 | + } |
|
227 | + |
|
228 | + EE_Error::add_success( |
|
229 | + esc_html__( |
|
230 | + 'The Payment was successfully deleted, and the Transaction has been updated accordingly.', |
|
231 | + 'event_espresso' |
|
232 | + ) |
|
233 | + ); |
|
234 | + return true; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * delete_registration_payments_and_update_registrations |
|
240 | + * |
|
241 | + * removes all registration payment records associated with a payment |
|
242 | + * and subtracts their amounts from the corresponding registrations REG_paid field |
|
243 | + * |
|
244 | + * @param EE_Payment $payment |
|
245 | + * @param array $reg_payment_query_params |
|
246 | + * @return bool |
|
247 | + * @throws \EE_Error |
|
248 | + */ |
|
249 | + public function delete_registration_payments_and_update_registrations( |
|
250 | + EE_Payment $payment, |
|
251 | + $reg_payment_query_params = array() |
|
252 | + ) { |
|
253 | + $save_payment = false; |
|
254 | + $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params |
|
255 | + : array(array('PAY_ID' => $payment->ID())); |
|
256 | + $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
|
257 | + if (! empty($registration_payments)) { |
|
258 | + foreach ($registration_payments as $registration_payment) { |
|
259 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
260 | + $amount_paid = $registration_payment->amount(); |
|
261 | + $registration = $registration_payment->registration(); |
|
262 | + if ($registration instanceof EE_Registration) { |
|
263 | + $registration->set_paid($registration->paid() - $amount_paid); |
|
264 | + if ($registration->save() !== false) { |
|
265 | + $registration_payment->delete_permanently(); |
|
266 | + $save_payment = true; |
|
267 | + } |
|
268 | + } else { |
|
269 | + EE_Error::add_error( |
|
270 | + sprintf( |
|
271 | + esc_html__( |
|
272 | + 'An invalid Registration object was associated with Registration Payment ID# %1$d.', |
|
273 | + 'event_espresso' |
|
274 | + ), |
|
275 | + $registration_payment->ID() |
|
276 | + ), |
|
277 | + __FILE__, |
|
278 | + __FUNCTION__, |
|
279 | + __LINE__ |
|
280 | + ); |
|
281 | + return false; |
|
282 | + } |
|
283 | + } else { |
|
284 | + EE_Error::add_error( |
|
285 | + sprintf( |
|
286 | + esc_html__( |
|
287 | + 'An invalid Registration Payment object was associated with payment ID# %1$d.', |
|
288 | + 'event_espresso' |
|
289 | + ), |
|
290 | + $payment->ID() |
|
291 | + ), |
|
292 | + __FILE__, |
|
293 | + __FUNCTION__, |
|
294 | + __LINE__ |
|
295 | + ); |
|
296 | + return false; |
|
297 | + } |
|
298 | + } |
|
299 | + } |
|
300 | + if ($save_payment) { |
|
301 | + $payment->save(); |
|
302 | + } |
|
303 | + return true; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + /********************************** DEPRECATED METHODS **********************************/ |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * possibly toggles TXN status |
|
313 | + * |
|
314 | + * @deprecated 4.9.1 |
|
315 | + * @param EE_Transaction $transaction |
|
316 | + * @param boolean $update_txn whether to save the TXN |
|
317 | + * @return boolean whether the TXN was saved |
|
318 | + * @throws \EE_Error |
|
319 | + */ |
|
320 | + public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true) |
|
321 | + { |
|
322 | + EE_Error::doing_it_wrong( |
|
323 | + __CLASS__ . '::' . __FUNCTION__, |
|
324 | + sprintf( |
|
325 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
326 | + 'EE_Transaction::update_status_based_on_total_paid()' |
|
327 | + ), |
|
328 | + '4.9.1', |
|
329 | + '5.0.0' |
|
330 | + ); |
|
331 | + // verify transaction |
|
332 | + if (! $transaction instanceof EE_Transaction) { |
|
333 | + EE_Error::add_error( |
|
334 | + esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'), |
|
335 | + __FILE__, |
|
336 | + __FUNCTION__, |
|
337 | + __LINE__ |
|
338 | + ); |
|
339 | + return false; |
|
340 | + } |
|
341 | + // set transaction status based on comparison of TXN_paid vs TXN_total |
|
342 | + return $transaction->update_status_based_on_total_paid($update_txn); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @deprecated 4.9.12 |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + public function old_txn_status() |
|
351 | + { |
|
352 | + EE_Error::doing_it_wrong( |
|
353 | + __METHOD__, |
|
354 | + esc_html__( |
|
355 | + 'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.', |
|
356 | + 'event_espresso' |
|
357 | + ), |
|
358 | + '4.9.12' |
|
359 | + ); |
|
360 | + return $this->_old_txn_status; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @deprecated 4.9.12 |
|
366 | + * @param string $old_txn_status |
|
367 | + */ |
|
368 | + public function set_old_txn_status($old_txn_status) |
|
369 | + { |
|
370 | + EE_Error::doing_it_wrong( |
|
371 | + __METHOD__, |
|
372 | + esc_html__( |
|
373 | + 'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.', |
|
374 | + 'event_espresso' |
|
375 | + ), |
|
376 | + '4.9.12' |
|
377 | + ); |
|
378 | + // only set the first time |
|
379 | + if ($this->_old_txn_status === null) { |
|
380 | + $this->_old_txn_status = $old_txn_status; |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * @deprecated 4.9.12 |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function new_txn_status() |
|
390 | + { |
|
391 | + EE_Error::doing_it_wrong( |
|
392 | + __METHOD__, |
|
393 | + esc_html__( |
|
394 | + 'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.', |
|
395 | + 'event_espresso' |
|
396 | + ), |
|
397 | + '4.9.12' |
|
398 | + ); |
|
399 | + return $this->_new_txn_status; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @deprecated 4.9.12 |
|
405 | + * @param string $new_txn_status |
|
406 | + */ |
|
407 | + public function set_new_txn_status($new_txn_status) |
|
408 | + { |
|
409 | + EE_Error::doing_it_wrong( |
|
410 | + __METHOD__, |
|
411 | + esc_html__( |
|
412 | + 'This logic has been removed. Please just use \EE_Transaction::set_status() instead.', |
|
413 | + 'event_espresso' |
|
414 | + ), |
|
415 | + '4.9.12' |
|
416 | + ); |
|
417 | + $this->_new_txn_status = $new_txn_status; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * @deprecated 4.9.12 |
|
423 | + * @return bool |
|
424 | + */ |
|
425 | + public function txn_status_updated() |
|
426 | + { |
|
427 | + EE_Error::doing_it_wrong( |
|
428 | + __METHOD__, |
|
429 | + esc_html__( |
|
430 | + 'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.', |
|
431 | + 'event_espresso' |
|
432 | + ), |
|
433 | + '4.9.12' |
|
434 | + ); |
|
435 | + return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false; |
|
436 | + } |
|
437 | 437 | } |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | if ($TKT_ID) { |
60 | 60 | $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
61 | 61 | if ($ticket instanceof EE_Ticket) { |
62 | - $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
62 | + $ticket_details = '<span class="ee-ticket-name">'.$ticket->name().'</span> '; |
|
63 | 63 | $ticket_details .= ! $ticket->is_free() |
64 | - ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
64 | + ? '<span class="ee-ticket-price">'.$ticket->pretty_price().'</span>' |
|
65 | 65 | : '<span class="reg-overview-free-event-spn">' |
66 | 66 | . esc_html__('free', 'event_espresso') |
67 | 67 | . '</span>'; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $text .= ' '; |
79 | 79 | $text .= '<span class="drk-grey-text" style="font-size:.9em;">'; |
80 | 80 | $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
81 | - $text .= $ticket_details . '</span></h3>'; |
|
81 | + $text .= $ticket_details.'</span></h3>'; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | return $text; |
@@ -22,64 +22,64 @@ |
||
22 | 22 | */ |
23 | 23 | class TicketFilterHeader extends AdminPageHeaderDecorator |
24 | 24 | { |
25 | - /** |
|
26 | - * @var EEM_Ticket $ticket_model |
|
27 | - */ |
|
28 | - private $ticket_model; |
|
25 | + /** |
|
26 | + * @var EEM_Ticket $ticket_model |
|
27 | + */ |
|
28 | + private $ticket_model; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * TicketFilterHeader constructor. |
|
33 | - * |
|
34 | - * @param RequestInterface $request |
|
35 | - * @param EEM_Ticket $ticket_model |
|
36 | - */ |
|
37 | - public function __construct(RequestInterface $request, EEM_Ticket $ticket_model) |
|
38 | - { |
|
39 | - parent::__construct($request); |
|
40 | - $this->ticket_model = $ticket_model; |
|
41 | - } |
|
31 | + /** |
|
32 | + * TicketFilterHeader constructor. |
|
33 | + * |
|
34 | + * @param RequestInterface $request |
|
35 | + * @param EEM_Ticket $ticket_model |
|
36 | + */ |
|
37 | + public function __construct(RequestInterface $request, EEM_Ticket $ticket_model) |
|
38 | + { |
|
39 | + parent::__construct($request); |
|
40 | + $this->ticket_model = $ticket_model; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param string $text |
|
46 | - * @return string |
|
47 | - * @throws EE_Error |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidInterfaceException |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws ReflectionException |
|
52 | - * @since 4.10.2.p |
|
53 | - */ |
|
54 | - public function getHeaderText($text = '') |
|
55 | - { |
|
56 | - $TKT_ID = $this->request->getRequestParam('TKT_ID'); |
|
57 | - $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int'); |
|
58 | - if ($TKT_ID) { |
|
59 | - $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
|
60 | - if ($ticket instanceof EE_Ticket) { |
|
61 | - $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
62 | - $ticket_details .= ! $ticket->is_free() |
|
63 | - ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
64 | - : '<span class="reg-overview-free-event-spn">' |
|
65 | - . esc_html__('free', 'event_espresso') |
|
66 | - . '</span>'; |
|
67 | - // remove the closing h3 heading tag if it exists |
|
68 | - $text = str_replace( |
|
69 | - '</h3>', |
|
70 | - '', |
|
71 | - $text |
|
72 | - ); |
|
73 | - if (empty($text)) { |
|
74 | - $text = '<h3 style="line-height:1.5em;">'; |
|
75 | - $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso'); |
|
76 | - } |
|
77 | - $text .= ' '; |
|
78 | - $text .= '<span class="drk-grey-text" style="font-size:.9em;">'; |
|
79 | - $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
80 | - $text .= $ticket_details . '</span></h3>'; |
|
81 | - } |
|
82 | - } |
|
83 | - return $text; |
|
84 | - } |
|
44 | + /** |
|
45 | + * @param string $text |
|
46 | + * @return string |
|
47 | + * @throws EE_Error |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidInterfaceException |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws ReflectionException |
|
52 | + * @since 4.10.2.p |
|
53 | + */ |
|
54 | + public function getHeaderText($text = '') |
|
55 | + { |
|
56 | + $TKT_ID = $this->request->getRequestParam('TKT_ID'); |
|
57 | + $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int'); |
|
58 | + if ($TKT_ID) { |
|
59 | + $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
|
60 | + if ($ticket instanceof EE_Ticket) { |
|
61 | + $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
62 | + $ticket_details .= ! $ticket->is_free() |
|
63 | + ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
64 | + : '<span class="reg-overview-free-event-spn">' |
|
65 | + . esc_html__('free', 'event_espresso') |
|
66 | + . '</span>'; |
|
67 | + // remove the closing h3 heading tag if it exists |
|
68 | + $text = str_replace( |
|
69 | + '</h3>', |
|
70 | + '', |
|
71 | + $text |
|
72 | + ); |
|
73 | + if (empty($text)) { |
|
74 | + $text = '<h3 style="line-height:1.5em;">'; |
|
75 | + $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso'); |
|
76 | + } |
|
77 | + $text .= ' '; |
|
78 | + $text .= '<span class="drk-grey-text" style="font-size:.9em;">'; |
|
79 | + $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
80 | + $text .= $ticket_details . '</span></h3>'; |
|
81 | + } |
|
82 | + } |
|
83 | + return $text; |
|
84 | + } |
|
85 | 85 | } |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | public function heartbeatResponse($response = array(), $data = array()) |
68 | 68 | { |
69 | 69 | // does this heartbeat contain our data ? |
70 | - if (! isset($data[ $this->heartbeat ])) { |
|
70 | + if ( ! isset($data[$this->heartbeat])) { |
|
71 | 71 | return $response; |
72 | 72 | } |
73 | 73 | // check for reg_url_link in the incoming heartbeat data |
74 | - if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
75 | - $response[ $this->heartbeat ] = array( |
|
74 | + if ( ! isset($data[$this->heartbeat]['e_reg_url_link'])) { |
|
75 | + $response[$this->heartbeat] = array( |
|
76 | 76 | 'errors' => ! empty($notices['errors']) |
77 | 77 | ? $notices['errors'] |
78 | 78 | : esc_html__( |
@@ -85,22 +85,22 @@ discard block |
||
85 | 85 | // kk heartbeat has our data |
86 | 86 | $response = $this->initializeThankYouPageAndTransaction($response, $data); |
87 | 87 | // if something went wrong... |
88 | - if (isset($response[ $this->heartbeat ]['errors'])) { |
|
88 | + if (isset($response[$this->heartbeat]['errors'])) { |
|
89 | 89 | return $response; |
90 | 90 | } |
91 | 91 | // grab transient of Transaction's status |
92 | - $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
93 | - ? $data[ $this->heartbeat ]['txn_status'] |
|
92 | + $txn_status = isset($data[$this->heartbeat]['txn_status']) |
|
93 | + ? $data[$this->heartbeat]['txn_status'] |
|
94 | 94 | : null; |
95 | 95 | $response = $this->getTransactionDetails($txn_status, $response, $data); |
96 | 96 | // no payment data yet? |
97 | - if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
97 | + if (isset($response[$this->heartbeat]['still_waiting'])) { |
|
98 | 98 | return $response; |
99 | 99 | } |
100 | 100 | // TXN is happening so let's get the payments now |
101 | 101 | // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
102 | - $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
103 | - ? $data[ $this->heartbeat ]['get_payments_since'] |
|
102 | + $since = isset($data[$this->heartbeat]['get_payments_since']) |
|
103 | + ? $data[$this->heartbeat]['get_payments_since'] |
|
104 | 104 | : 0; |
105 | 105 | return $this->paymentDetails($response, $since); |
106 | 106 | } |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | */ |
118 | 118 | private function initializeThankYouPageAndTransaction($response, $data) |
119 | 119 | { |
120 | - require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
120 | + require_once EE_MODULES.'thank_you_page/EED_Thank_You_Page.module.php'; |
|
121 | 121 | // set_definitions, instantiate the thank you page class, and get the ball rolling |
122 | 122 | EED_Thank_You_Page::set_definitions(); |
123 | 123 | $this->thank_you_page = EED_Thank_You_Page::instance(); |
124 | - $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
124 | + $this->thank_you_page->set_reg_url_link($data[$this->heartbeat]['e_reg_url_link']); |
|
125 | 125 | $this->thank_you_page->init(); |
126 | 126 | // get TXN |
127 | 127 | $transaction = $this->thank_you_page->get_txn(); |
128 | 128 | // no TXN? then get out |
129 | - if (! $transaction instanceof EE_Transaction) { |
|
129 | + if ( ! $transaction instanceof EE_Transaction) { |
|
130 | 130 | $notices = EE_Error::get_notices(); |
131 | - $response[ $this->heartbeat ] = array( |
|
131 | + $response[$this->heartbeat] = array( |
|
132 | 132 | 'errors' => ! empty($notices['errors']) |
133 | 133 | ? $notices['errors'] |
134 | 134 | : sprintf( |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | case EEM_Transaction::failed_status_code: |
174 | 174 | default: |
175 | 175 | // keep on waiting... |
176 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
176 | + return $this->updateServerWaitTime($data[$this->heartbeat]); |
|
177 | 177 | } |
178 | 178 | // or is the TXN still failed (never been updated) ??? |
179 | 179 | } elseif ($this->transaction->failed()) { |
180 | 180 | // keep on waiting... |
181 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
181 | + return $this->updateServerWaitTime($data[$this->heartbeat]); |
|
182 | 182 | } |
183 | 183 | return $response; |
184 | 184 | } |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | */ |
197 | 197 | private function setTransactionDetails($response, $status_only = false) |
198 | 198 | { |
199 | - if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
200 | - $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
199 | + if ( ! $status_only && ! isset($response[$this->heartbeat]['transaction_details'])) { |
|
200 | + $response[$this->heartbeat]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
201 | 201 | } |
202 | - if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
203 | - $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
202 | + if ( ! isset($response[$this->heartbeat]['txn_status'])) { |
|
203 | + $response[$this->heartbeat]['txn_status'] = $this->transaction->status_ID(); |
|
204 | 204 | } |
205 | 205 | return $response; |
206 | 206 | } |
@@ -221,19 +221,19 @@ discard block |
||
221 | 221 | // then check for payments |
222 | 222 | $payments = $this->thank_you_page->get_txn_payments($since); |
223 | 223 | // has a payment been processed ? |
224 | - if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
224 | + if ( ! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
225 | 225 | if ($since) { |
226 | - $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
226 | + $response[$this->heartbeat]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
227 | 227 | $response = $this->setTransactionDetails($response); |
228 | 228 | } else { |
229 | - $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
229 | + $response[$this->heartbeat]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
230 | 230 | $payments |
231 | 231 | ); |
232 | 232 | } |
233 | 233 | // reset time to check for payments |
234 | - $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
234 | + $response[$this->heartbeat]['get_payments_since'] = time(); |
|
235 | 235 | } else { |
236 | - $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
236 | + $response[$this->heartbeat]['get_payments_since'] = $since; |
|
237 | 237 | } |
238 | 238 | return $response; |
239 | 239 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | */ |
252 | 252 | private function updateServerWaitTime($thank_you_page_data) |
253 | 253 | { |
254 | - $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
254 | + $response[$this->heartbeat]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
255 | 255 | ? time() - $thank_you_page_data['initial_access'] |
256 | 256 | : 0; |
257 | 257 | $response = $this->setTransactionDetails($response, true); |
@@ -21,239 +21,239 @@ |
||
21 | 21 | */ |
22 | 22 | class ThankYouPageIpnMonitor |
23 | 23 | { |
24 | - /** |
|
25 | - * @var string $heartbeat |
|
26 | - */ |
|
27 | - private $heartbeat; |
|
24 | + /** |
|
25 | + * @var string $heartbeat |
|
26 | + */ |
|
27 | + private $heartbeat; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var EED_Thank_You_Page $thank_you_page |
|
31 | - */ |
|
32 | - private $thank_you_page; |
|
29 | + /** |
|
30 | + * @var EED_Thank_You_Page $thank_you_page |
|
31 | + */ |
|
32 | + private $thank_you_page; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var EE_Transaction $transaction |
|
36 | - */ |
|
37 | - private $transaction; |
|
34 | + /** |
|
35 | + * @var EE_Transaction $transaction |
|
36 | + */ |
|
37 | + private $transaction; |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * EventEditorHeartbeat constructor. |
|
42 | - */ |
|
43 | - public function __construct() |
|
44 | - { |
|
45 | - $this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE; |
|
46 | - add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3); |
|
47 | - add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3); |
|
48 | - } |
|
40 | + /** |
|
41 | + * EventEditorHeartbeat constructor. |
|
42 | + */ |
|
43 | + public function __construct() |
|
44 | + { |
|
45 | + $this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE; |
|
46 | + add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3); |
|
47 | + add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * thank_you_page_IPN_monitor |
|
53 | - * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
54 | - * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
55 | - * it also calculates the IPN wait time since the Thank You page was first loaded |
|
56 | - * |
|
57 | - * @param array $response |
|
58 | - * @param array $data |
|
59 | - * @return array |
|
60 | - * @throws EE_Error |
|
61 | - * @throws InvalidArgumentException |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - * @throws ReflectionException |
|
65 | - */ |
|
66 | - public function heartbeatResponse($response = array(), $data = array()) |
|
67 | - { |
|
68 | - // does this heartbeat contain our data ? |
|
69 | - if (! isset($data[ $this->heartbeat ])) { |
|
70 | - return $response; |
|
71 | - } |
|
72 | - // check for reg_url_link in the incoming heartbeat data |
|
73 | - if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
74 | - $response[ $this->heartbeat ] = array( |
|
75 | - 'errors' => ! empty($notices['errors']) |
|
76 | - ? $notices['errors'] |
|
77 | - : esc_html__( |
|
78 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - ); |
|
82 | - return $response; |
|
83 | - } |
|
84 | - // kk heartbeat has our data |
|
85 | - $response = $this->initializeThankYouPageAndTransaction($response, $data); |
|
86 | - // if something went wrong... |
|
87 | - if (isset($response[ $this->heartbeat ]['errors'])) { |
|
88 | - return $response; |
|
89 | - } |
|
90 | - // grab transient of Transaction's status |
|
91 | - $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
92 | - ? $data[ $this->heartbeat ]['txn_status'] |
|
93 | - : null; |
|
94 | - $response = $this->getTransactionDetails($txn_status, $response, $data); |
|
95 | - // no payment data yet? |
|
96 | - if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
97 | - return $response; |
|
98 | - } |
|
99 | - // TXN is happening so let's get the payments now |
|
100 | - // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
101 | - $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
102 | - ? $data[ $this->heartbeat ]['get_payments_since'] |
|
103 | - : 0; |
|
104 | - return $this->paymentDetails($response, $since); |
|
105 | - } |
|
51 | + /** |
|
52 | + * thank_you_page_IPN_monitor |
|
53 | + * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
54 | + * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
55 | + * it also calculates the IPN wait time since the Thank You page was first loaded |
|
56 | + * |
|
57 | + * @param array $response |
|
58 | + * @param array $data |
|
59 | + * @return array |
|
60 | + * @throws EE_Error |
|
61 | + * @throws InvalidArgumentException |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + * @throws ReflectionException |
|
65 | + */ |
|
66 | + public function heartbeatResponse($response = array(), $data = array()) |
|
67 | + { |
|
68 | + // does this heartbeat contain our data ? |
|
69 | + if (! isset($data[ $this->heartbeat ])) { |
|
70 | + return $response; |
|
71 | + } |
|
72 | + // check for reg_url_link in the incoming heartbeat data |
|
73 | + if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
74 | + $response[ $this->heartbeat ] = array( |
|
75 | + 'errors' => ! empty($notices['errors']) |
|
76 | + ? $notices['errors'] |
|
77 | + : esc_html__( |
|
78 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + ); |
|
82 | + return $response; |
|
83 | + } |
|
84 | + // kk heartbeat has our data |
|
85 | + $response = $this->initializeThankYouPageAndTransaction($response, $data); |
|
86 | + // if something went wrong... |
|
87 | + if (isset($response[ $this->heartbeat ]['errors'])) { |
|
88 | + return $response; |
|
89 | + } |
|
90 | + // grab transient of Transaction's status |
|
91 | + $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
92 | + ? $data[ $this->heartbeat ]['txn_status'] |
|
93 | + : null; |
|
94 | + $response = $this->getTransactionDetails($txn_status, $response, $data); |
|
95 | + // no payment data yet? |
|
96 | + if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
97 | + return $response; |
|
98 | + } |
|
99 | + // TXN is happening so let's get the payments now |
|
100 | + // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
101 | + $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
102 | + ? $data[ $this->heartbeat ]['get_payments_since'] |
|
103 | + : 0; |
|
104 | + return $this->paymentDetails($response, $since); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * @param array $response |
|
110 | - * @param array $data |
|
111 | - * @return array |
|
112 | - * @throws EE_Error |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidInterfaceException |
|
116 | - */ |
|
117 | - private function initializeThankYouPageAndTransaction($response, $data) |
|
118 | - { |
|
119 | - require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
120 | - // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
121 | - EED_Thank_You_Page::set_definitions(); |
|
122 | - $this->thank_you_page = EED_Thank_You_Page::instance(); |
|
123 | - $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
124 | - $this->thank_you_page->init(); |
|
125 | - // get TXN |
|
126 | - $transaction = $this->thank_you_page->get_txn(); |
|
127 | - // no TXN? then get out |
|
128 | - if (! $transaction instanceof EE_Transaction) { |
|
129 | - $notices = EE_Error::get_notices(); |
|
130 | - $response[ $this->heartbeat ] = array( |
|
131 | - 'errors' => ! empty($notices['errors']) |
|
132 | - ? $notices['errors'] |
|
133 | - : sprintf( |
|
134 | - esc_html__( |
|
135 | - 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
136 | - 'event_espresso' |
|
137 | - ), |
|
138 | - __LINE__ |
|
139 | - ), |
|
140 | - ); |
|
141 | - return $response; |
|
142 | - } |
|
143 | - $this->transaction = $transaction; |
|
144 | - return $response; |
|
145 | - } |
|
108 | + /** |
|
109 | + * @param array $response |
|
110 | + * @param array $data |
|
111 | + * @return array |
|
112 | + * @throws EE_Error |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + */ |
|
117 | + private function initializeThankYouPageAndTransaction($response, $data) |
|
118 | + { |
|
119 | + require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
120 | + // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
121 | + EED_Thank_You_Page::set_definitions(); |
|
122 | + $this->thank_you_page = EED_Thank_You_Page::instance(); |
|
123 | + $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
124 | + $this->thank_you_page->init(); |
|
125 | + // get TXN |
|
126 | + $transaction = $this->thank_you_page->get_txn(); |
|
127 | + // no TXN? then get out |
|
128 | + if (! $transaction instanceof EE_Transaction) { |
|
129 | + $notices = EE_Error::get_notices(); |
|
130 | + $response[ $this->heartbeat ] = array( |
|
131 | + 'errors' => ! empty($notices['errors']) |
|
132 | + ? $notices['errors'] |
|
133 | + : sprintf( |
|
134 | + esc_html__( |
|
135 | + 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + __LINE__ |
|
139 | + ), |
|
140 | + ); |
|
141 | + return $response; |
|
142 | + } |
|
143 | + $this->transaction = $transaction; |
|
144 | + return $response; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | |
148 | - /** |
|
149 | - * @param string $txn_status |
|
150 | - * @param array $response |
|
151 | - * @param array $data |
|
152 | - * @return array |
|
153 | - * @throws EE_Error |
|
154 | - * @throws InvalidArgumentException |
|
155 | - * @throws InvalidDataTypeException |
|
156 | - * @throws InvalidInterfaceException |
|
157 | - * @throws ReflectionException |
|
158 | - */ |
|
159 | - private function getTransactionDetails($txn_status, $response, $data) |
|
160 | - { |
|
161 | - // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
162 | - if ($txn_status !== $this->transaction->status_ID()) { |
|
163 | - // switch between two possible basic outcomes |
|
164 | - switch ($this->transaction->status_ID()) { |
|
165 | - // TXN has been updated in some way |
|
166 | - case EEM_Transaction::overpaid_status_code: |
|
167 | - case EEM_Transaction::complete_status_code: |
|
168 | - case EEM_Transaction::incomplete_status_code: |
|
169 | - // send updated TXN results back to client, |
|
170 | - return $this->setTransactionDetails($response); |
|
171 | - // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
172 | - case EEM_Transaction::failed_status_code: |
|
173 | - default: |
|
174 | - // keep on waiting... |
|
175 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
176 | - } |
|
177 | - // or is the TXN still failed (never been updated) ??? |
|
178 | - } elseif ($this->transaction->failed()) { |
|
179 | - // keep on waiting... |
|
180 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
181 | - } |
|
182 | - return $response; |
|
183 | - } |
|
148 | + /** |
|
149 | + * @param string $txn_status |
|
150 | + * @param array $response |
|
151 | + * @param array $data |
|
152 | + * @return array |
|
153 | + * @throws EE_Error |
|
154 | + * @throws InvalidArgumentException |
|
155 | + * @throws InvalidDataTypeException |
|
156 | + * @throws InvalidInterfaceException |
|
157 | + * @throws ReflectionException |
|
158 | + */ |
|
159 | + private function getTransactionDetails($txn_status, $response, $data) |
|
160 | + { |
|
161 | + // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
162 | + if ($txn_status !== $this->transaction->status_ID()) { |
|
163 | + // switch between two possible basic outcomes |
|
164 | + switch ($this->transaction->status_ID()) { |
|
165 | + // TXN has been updated in some way |
|
166 | + case EEM_Transaction::overpaid_status_code: |
|
167 | + case EEM_Transaction::complete_status_code: |
|
168 | + case EEM_Transaction::incomplete_status_code: |
|
169 | + // send updated TXN results back to client, |
|
170 | + return $this->setTransactionDetails($response); |
|
171 | + // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
172 | + case EEM_Transaction::failed_status_code: |
|
173 | + default: |
|
174 | + // keep on waiting... |
|
175 | + return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
176 | + } |
|
177 | + // or is the TXN still failed (never been updated) ??? |
|
178 | + } elseif ($this->transaction->failed()) { |
|
179 | + // keep on waiting... |
|
180 | + return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
181 | + } |
|
182 | + return $response; |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * @param array $response |
|
188 | - * @param boolean $status_only |
|
189 | - * @return array |
|
190 | - * @throws EE_Error |
|
191 | - * @throws InvalidArgumentException |
|
192 | - * @throws InvalidDataTypeException |
|
193 | - * @throws InvalidInterfaceException |
|
194 | - * @throws ReflectionException |
|
195 | - */ |
|
196 | - private function setTransactionDetails($response, $status_only = false) |
|
197 | - { |
|
198 | - if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
199 | - $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
200 | - } |
|
201 | - if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
202 | - $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
203 | - } |
|
204 | - return $response; |
|
205 | - } |
|
186 | + /** |
|
187 | + * @param array $response |
|
188 | + * @param boolean $status_only |
|
189 | + * @return array |
|
190 | + * @throws EE_Error |
|
191 | + * @throws InvalidArgumentException |
|
192 | + * @throws InvalidDataTypeException |
|
193 | + * @throws InvalidInterfaceException |
|
194 | + * @throws ReflectionException |
|
195 | + */ |
|
196 | + private function setTransactionDetails($response, $status_only = false) |
|
197 | + { |
|
198 | + if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
199 | + $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
200 | + } |
|
201 | + if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
202 | + $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
203 | + } |
|
204 | + return $response; |
|
205 | + } |
|
206 | 206 | |
207 | 207 | |
208 | - /** |
|
209 | - * @param array $response |
|
210 | - * @param int $since |
|
211 | - * @return array |
|
212 | - * @throws EE_Error |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws InvalidDataTypeException |
|
215 | - * @throws InvalidInterfaceException |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - private function paymentDetails($response, $since) |
|
219 | - { |
|
220 | - // then check for payments |
|
221 | - $payments = $this->thank_you_page->get_txn_payments($since); |
|
222 | - // has a payment been processed ? |
|
223 | - if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
224 | - if ($since) { |
|
225 | - $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
226 | - $response = $this->setTransactionDetails($response); |
|
227 | - } else { |
|
228 | - $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
229 | - $payments |
|
230 | - ); |
|
231 | - } |
|
232 | - // reset time to check for payments |
|
233 | - $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
234 | - } else { |
|
235 | - $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
236 | - } |
|
237 | - return $response; |
|
238 | - } |
|
208 | + /** |
|
209 | + * @param array $response |
|
210 | + * @param int $since |
|
211 | + * @return array |
|
212 | + * @throws EE_Error |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws InvalidDataTypeException |
|
215 | + * @throws InvalidInterfaceException |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + private function paymentDetails($response, $since) |
|
219 | + { |
|
220 | + // then check for payments |
|
221 | + $payments = $this->thank_you_page->get_txn_payments($since); |
|
222 | + // has a payment been processed ? |
|
223 | + if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
224 | + if ($since) { |
|
225 | + $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
226 | + $response = $this->setTransactionDetails($response); |
|
227 | + } else { |
|
228 | + $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
229 | + $payments |
|
230 | + ); |
|
231 | + } |
|
232 | + // reset time to check for payments |
|
233 | + $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
234 | + } else { |
|
235 | + $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
236 | + } |
|
237 | + return $response; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | |
241 | - /** |
|
242 | - * @param array $thank_you_page_data thank you page portion of the incoming JSON array |
|
243 | - * from the WP heartbeat data |
|
244 | - * @return array |
|
245 | - * @throws EE_Error |
|
246 | - * @throws InvalidArgumentException |
|
247 | - * @throws InvalidDataTypeException |
|
248 | - * @throws InvalidInterfaceException |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - private function updateServerWaitTime($thank_you_page_data) |
|
252 | - { |
|
253 | - $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
254 | - ? time() - $thank_you_page_data['initial_access'] |
|
255 | - : 0; |
|
256 | - $response = $this->setTransactionDetails($response, true); |
|
257 | - return $response; |
|
258 | - } |
|
241 | + /** |
|
242 | + * @param array $thank_you_page_data thank you page portion of the incoming JSON array |
|
243 | + * from the WP heartbeat data |
|
244 | + * @return array |
|
245 | + * @throws EE_Error |
|
246 | + * @throws InvalidArgumentException |
|
247 | + * @throws InvalidDataTypeException |
|
248 | + * @throws InvalidInterfaceException |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + private function updateServerWaitTime($thank_you_page_data) |
|
252 | + { |
|
253 | + $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
254 | + ? time() - $thank_you_page_data['initial_access'] |
|
255 | + : 0; |
|
256 | + $response = $this->setTransactionDetails($response, true); |
|
257 | + return $response; |
|
258 | + } |
|
259 | 259 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | ); |
89 | 89 | $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
90 | 90 | } |
91 | - if (! $success) { |
|
91 | + if ( ! $success) { |
|
92 | 92 | throw new \RuntimeException( |
93 | 93 | sprintf( |
94 | 94 | esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | break; |
126 | 126 | } |
127 | 127 | } |
128 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
128 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
129 | 129 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
130 | 130 | } |
131 | 131 | return $line_item; |
@@ -18,114 +18,114 @@ |
||
18 | 18 | */ |
19 | 19 | class CancelTicketLineItemService extends DomainService |
20 | 20 | { |
21 | - /** |
|
22 | - * @param \EE_Registration $registration |
|
23 | - * @param int $quantity |
|
24 | - * @return bool|int |
|
25 | - */ |
|
26 | - public function forRegistration(\EE_Registration $registration, $quantity = 1) |
|
27 | - { |
|
28 | - return $this->cancel( |
|
29 | - $registration->transaction(), |
|
30 | - $registration->ticket(), |
|
31 | - $quantity, |
|
32 | - $registration->ticket_line_item() |
|
33 | - ); |
|
34 | - } |
|
21 | + /** |
|
22 | + * @param \EE_Registration $registration |
|
23 | + * @param int $quantity |
|
24 | + * @return bool|int |
|
25 | + */ |
|
26 | + public function forRegistration(\EE_Registration $registration, $quantity = 1) |
|
27 | + { |
|
28 | + return $this->cancel( |
|
29 | + $registration->transaction(), |
|
30 | + $registration->ticket(), |
|
31 | + $quantity, |
|
32 | + $registration->ticket_line_item() |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @param \EE_Transaction $transaction |
|
39 | - * @param \EE_Ticket $ticket |
|
40 | - * @param int $quantity |
|
41 | - * @param \EE_Line_Item $ticket_line_item |
|
42 | - * @return bool|int |
|
43 | - */ |
|
44 | - public function cancel( |
|
45 | - \EE_Transaction $transaction, |
|
46 | - \EE_Ticket $ticket, |
|
47 | - $quantity = 1, |
|
48 | - \EE_Line_Item $ticket_line_item = null |
|
49 | - ) { |
|
50 | - $ticket_line_item = $ticket_line_item instanceof \EE_Line_Item |
|
51 | - ? $ticket_line_item |
|
52 | - : $this->getTicketLineItem($transaction, $ticket); |
|
53 | - // first we need to decrement the ticket quantity |
|
54 | - \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity); |
|
55 | - // no tickets left for this line item ? |
|
56 | - if ((int) $ticket_line_item->quantity() === 0) { |
|
57 | - // then just set this line item as cancelled, save, and get out |
|
58 | - $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation); |
|
59 | - $success = $ticket_line_item->save(); |
|
60 | - } else { |
|
61 | - // otherwise create a new cancelled line item, so that we have a record of the cancellation |
|
62 | - $items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal( |
|
63 | - \EEH_Line_Item::get_event_line_item_for_ticket( |
|
64 | - $transaction->total_line_item(), |
|
65 | - $ticket |
|
66 | - ) |
|
67 | - ); |
|
68 | - $cancelled_line_item = \EE_Line_Item::new_instance( |
|
69 | - array( |
|
70 | - 'LIN_name' => $ticket_line_item->name(), |
|
71 | - 'LIN_desc' => sprintf( |
|
72 | - esc_html__('%1$s Cancelled: %2$s', 'event_espresso'), |
|
73 | - $ticket_line_item->desc(), |
|
74 | - date('Y-m-d h:i a') |
|
75 | - ), |
|
76 | - 'LIN_unit_price' => (float) $ticket_line_item->unit_price(), |
|
77 | - 'LIN_quantity' => $quantity, |
|
78 | - 'LIN_percent' => null, |
|
79 | - 'LIN_is_taxable' => false, |
|
80 | - 'LIN_order' => $items_subtotal instanceof \EE_Line_Item |
|
81 | - ? count($items_subtotal->children()) |
|
82 | - : 0, |
|
83 | - 'LIN_total' => (float) $ticket_line_item->unit_price(), |
|
84 | - 'LIN_type' => \EEM_Line_Item::type_cancellation, |
|
85 | - ) |
|
86 | - ); |
|
87 | - $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
|
88 | - } |
|
89 | - if (! $success) { |
|
90 | - throw new \RuntimeException( |
|
91 | - sprintf( |
|
92 | - esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
|
93 | - $ticket_line_item->ID() |
|
94 | - ) |
|
95 | - ); |
|
96 | - } |
|
97 | - return $success; |
|
98 | - } |
|
37 | + /** |
|
38 | + * @param \EE_Transaction $transaction |
|
39 | + * @param \EE_Ticket $ticket |
|
40 | + * @param int $quantity |
|
41 | + * @param \EE_Line_Item $ticket_line_item |
|
42 | + * @return bool|int |
|
43 | + */ |
|
44 | + public function cancel( |
|
45 | + \EE_Transaction $transaction, |
|
46 | + \EE_Ticket $ticket, |
|
47 | + $quantity = 1, |
|
48 | + \EE_Line_Item $ticket_line_item = null |
|
49 | + ) { |
|
50 | + $ticket_line_item = $ticket_line_item instanceof \EE_Line_Item |
|
51 | + ? $ticket_line_item |
|
52 | + : $this->getTicketLineItem($transaction, $ticket); |
|
53 | + // first we need to decrement the ticket quantity |
|
54 | + \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity); |
|
55 | + // no tickets left for this line item ? |
|
56 | + if ((int) $ticket_line_item->quantity() === 0) { |
|
57 | + // then just set this line item as cancelled, save, and get out |
|
58 | + $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation); |
|
59 | + $success = $ticket_line_item->save(); |
|
60 | + } else { |
|
61 | + // otherwise create a new cancelled line item, so that we have a record of the cancellation |
|
62 | + $items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal( |
|
63 | + \EEH_Line_Item::get_event_line_item_for_ticket( |
|
64 | + $transaction->total_line_item(), |
|
65 | + $ticket |
|
66 | + ) |
|
67 | + ); |
|
68 | + $cancelled_line_item = \EE_Line_Item::new_instance( |
|
69 | + array( |
|
70 | + 'LIN_name' => $ticket_line_item->name(), |
|
71 | + 'LIN_desc' => sprintf( |
|
72 | + esc_html__('%1$s Cancelled: %2$s', 'event_espresso'), |
|
73 | + $ticket_line_item->desc(), |
|
74 | + date('Y-m-d h:i a') |
|
75 | + ), |
|
76 | + 'LIN_unit_price' => (float) $ticket_line_item->unit_price(), |
|
77 | + 'LIN_quantity' => $quantity, |
|
78 | + 'LIN_percent' => null, |
|
79 | + 'LIN_is_taxable' => false, |
|
80 | + 'LIN_order' => $items_subtotal instanceof \EE_Line_Item |
|
81 | + ? count($items_subtotal->children()) |
|
82 | + : 0, |
|
83 | + 'LIN_total' => (float) $ticket_line_item->unit_price(), |
|
84 | + 'LIN_type' => \EEM_Line_Item::type_cancellation, |
|
85 | + ) |
|
86 | + ); |
|
87 | + $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
|
88 | + } |
|
89 | + if (! $success) { |
|
90 | + throw new \RuntimeException( |
|
91 | + sprintf( |
|
92 | + esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
|
93 | + $ticket_line_item->ID() |
|
94 | + ) |
|
95 | + ); |
|
96 | + } |
|
97 | + return $success; |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * @param \EE_Transaction $transaction |
|
103 | - * @param \EE_Ticket $ticket |
|
104 | - * @return \EE_Line_Item |
|
105 | - * @throws EntityNotFoundException |
|
106 | - * @throws \EE_Error |
|
107 | - */ |
|
108 | - protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket) |
|
109 | - { |
|
110 | - $line_item = null; |
|
111 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
112 | - $transaction->total_line_item(), |
|
113 | - 'Ticket', |
|
114 | - array($ticket->ID()) |
|
115 | - ); |
|
116 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
117 | - if ( |
|
118 | - $ticket_line_item instanceof \EE_Line_Item |
|
119 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
120 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
121 | - ) { |
|
122 | - $line_item = $ticket_line_item; |
|
123 | - break; |
|
124 | - } |
|
125 | - } |
|
126 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
127 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
128 | - } |
|
129 | - return $line_item; |
|
130 | - } |
|
101 | + /** |
|
102 | + * @param \EE_Transaction $transaction |
|
103 | + * @param \EE_Ticket $ticket |
|
104 | + * @return \EE_Line_Item |
|
105 | + * @throws EntityNotFoundException |
|
106 | + * @throws \EE_Error |
|
107 | + */ |
|
108 | + protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket) |
|
109 | + { |
|
110 | + $line_item = null; |
|
111 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
112 | + $transaction->total_line_item(), |
|
113 | + 'Ticket', |
|
114 | + array($ticket->ID()) |
|
115 | + ); |
|
116 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
117 | + if ( |
|
118 | + $ticket_line_item instanceof \EE_Line_Item |
|
119 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
120 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
121 | + ) { |
|
122 | + $line_item = $ticket_line_item; |
|
123 | + break; |
|
124 | + } |
|
125 | + } |
|
126 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
127 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
128 | + } |
|
129 | + return $line_item; |
|
130 | + } |
|
131 | 131 | } |