@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | false, |
36 | 36 | 'event', |
37 | 37 | array( |
38 | - 'event' => esc_html__("Event", "event_espresso"),// deprecated |
|
38 | + 'event' => esc_html__("Event", "event_espresso"), // deprecated |
|
39 | 39 | 'registration' => esc_html__("Registration", "event_espresso"), |
40 | 40 | 'transaction' => esc_html__("Transaction", "event_espresso"), |
41 | 41 | 'payment' => esc_html__("Payment", "event_espresso"), |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'Payment' => new EE_Has_Many_Relation(), |
55 | 55 | ); |
56 | 56 | // this model is generally available for reading |
57 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
57 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
58 | 58 | |
59 | 59 | parent::__construct($timezone); |
60 | 60 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array); |
269 | 269 | |
270 | - if (! is_array($statuses)) { |
|
270 | + if ( ! is_array($statuses)) { |
|
271 | 271 | throw new EE_Error(esc_html__( |
272 | 272 | 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code', |
273 | 273 | 'event_espresso' |
@@ -277,22 +277,22 @@ discard block |
||
277 | 277 | $translation = array(); |
278 | 278 | |
279 | 279 | foreach ($statuses as $id => $code) { |
280 | - if (isset($translation_array[ $id ])) { |
|
281 | - $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0]; |
|
280 | + if (isset($translation_array[$id])) { |
|
281 | + $translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0]; |
|
282 | 282 | } else { |
283 | - $translation[ $id ] = $code; |
|
283 | + $translation[$id] = $code; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // schema |
287 | 287 | switch ($schema) { |
288 | 288 | case 'lower': |
289 | - $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter. |
|
289 | + $translation[$id] = strtolower($translation[$id]); // even though these start in lower case, this will catch any statuses added via filter. |
|
290 | 290 | break; |
291 | 291 | case 'sentence': |
292 | - $translation[ $id ] = ucwords($translation[ $id ]); |
|
292 | + $translation[$id] = ucwords($translation[$id]); |
|
293 | 293 | break; |
294 | 294 | case 'upper': |
295 | - $translation[ $id ] = strtoupper($translation[ $id ]); |
|
295 | + $translation[$id] = strtoupper($translation[$id]); |
|
296 | 296 | break; |
297 | 297 | } |
298 | 298 | } |
@@ -10,292 +10,292 @@ |
||
10 | 10 | */ |
11 | 11 | class EEM_Status extends EEM_Base |
12 | 12 | { |
13 | - // private instance of the Attendee object |
|
14 | - protected static $_instance = null; |
|
13 | + // private instance of the Attendee object |
|
14 | + protected static $_instance = null; |
|
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @return EEM_Status |
|
19 | - */ |
|
20 | - protected function __construct($timezone = null) |
|
21 | - { |
|
22 | - $this->singular_item = esc_html__('Status', 'event_espresso'); |
|
23 | - $this->plural_item = esc_html__('Stati', 'event_espresso'); |
|
24 | - $this->_tables = array( |
|
25 | - 'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'), |
|
26 | - ); |
|
27 | - $this->_fields = array( |
|
28 | - 'StatusTable' => array( |
|
29 | - 'STS_ID' => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')), |
|
30 | - 'STS_code' => new EE_Plain_Text_Field('STS_code', esc_html__('Status Code', 'event_espresso'), false, ''), |
|
31 | - 'STS_type' => new EE_Enum_Text_Field( |
|
32 | - 'STS_type', |
|
33 | - esc_html__("Type", "event_espresso"), |
|
34 | - false, |
|
35 | - 'event', |
|
36 | - array( |
|
37 | - 'event' => esc_html__("Event", "event_espresso"),// deprecated |
|
38 | - 'registration' => esc_html__("Registration", "event_espresso"), |
|
39 | - 'transaction' => esc_html__("Transaction", "event_espresso"), |
|
40 | - 'payment' => esc_html__("Payment", "event_espresso"), |
|
41 | - 'email' => esc_html__("Email", "event_espresso"), |
|
42 | - 'message' => esc_html__("Message", "event_espresso"), |
|
43 | - ) |
|
44 | - ), |
|
45 | - 'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', esc_html__('Editable?', 'event_espresso'), false, false), |
|
46 | - 'STS_desc' => new EE_Simple_HTML_Field('STS_desc', esc_html__("Description", "event_espresso"), false, ''), |
|
47 | - 'STS_open' => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false), |
|
48 | - ), |
|
49 | - ); |
|
50 | - $this->_model_relations = array( |
|
51 | - 'Registration' => new EE_Has_Many_Relation(), |
|
52 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
53 | - 'Payment' => new EE_Has_Many_Relation(), |
|
54 | - ); |
|
55 | - // this model is generally available for reading |
|
56 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
17 | + /** |
|
18 | + * @return EEM_Status |
|
19 | + */ |
|
20 | + protected function __construct($timezone = null) |
|
21 | + { |
|
22 | + $this->singular_item = esc_html__('Status', 'event_espresso'); |
|
23 | + $this->plural_item = esc_html__('Stati', 'event_espresso'); |
|
24 | + $this->_tables = array( |
|
25 | + 'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'), |
|
26 | + ); |
|
27 | + $this->_fields = array( |
|
28 | + 'StatusTable' => array( |
|
29 | + 'STS_ID' => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')), |
|
30 | + 'STS_code' => new EE_Plain_Text_Field('STS_code', esc_html__('Status Code', 'event_espresso'), false, ''), |
|
31 | + 'STS_type' => new EE_Enum_Text_Field( |
|
32 | + 'STS_type', |
|
33 | + esc_html__("Type", "event_espresso"), |
|
34 | + false, |
|
35 | + 'event', |
|
36 | + array( |
|
37 | + 'event' => esc_html__("Event", "event_espresso"),// deprecated |
|
38 | + 'registration' => esc_html__("Registration", "event_espresso"), |
|
39 | + 'transaction' => esc_html__("Transaction", "event_espresso"), |
|
40 | + 'payment' => esc_html__("Payment", "event_espresso"), |
|
41 | + 'email' => esc_html__("Email", "event_espresso"), |
|
42 | + 'message' => esc_html__("Message", "event_espresso"), |
|
43 | + ) |
|
44 | + ), |
|
45 | + 'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', esc_html__('Editable?', 'event_espresso'), false, false), |
|
46 | + 'STS_desc' => new EE_Simple_HTML_Field('STS_desc', esc_html__("Description", "event_espresso"), false, ''), |
|
47 | + 'STS_open' => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false), |
|
48 | + ), |
|
49 | + ); |
|
50 | + $this->_model_relations = array( |
|
51 | + 'Registration' => new EE_Has_Many_Relation(), |
|
52 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
53 | + 'Payment' => new EE_Has_Many_Relation(), |
|
54 | + ); |
|
55 | + // this model is generally available for reading |
|
56 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
57 | 57 | |
58 | - parent::__construct($timezone); |
|
59 | - } |
|
58 | + parent::__construct($timezone); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * This method provides the localized singular or plural string for a given status id |
|
64 | - * |
|
65 | - * @param array $statuses This should be an array of statuses in the format array( $status_id, $status_code ). |
|
66 | - * That way if there isn't a translation in the index we'll return the default code. |
|
67 | - * @param boolean $plural Whether to return plural string or not. Note, nearly all of the plural strings are the |
|
68 | - * same as the singular (in English), however, this may NOT be the case with other |
|
69 | - * languages |
|
70 | - * @param string $schema This can be either 'upper', 'lower', or 'sentence'. Basically indicates how we want |
|
71 | - * the status string returned ( UPPER, lower, Sentence) |
|
72 | - * @throws EE_Error |
|
73 | - * @return array an array of translated strings for the incoming status id. |
|
74 | - */ |
|
75 | - public function localized_status($statuses, $plural = false, $schema = 'upper') |
|
76 | - { |
|
77 | - // note these are all in lower case because ucwords() on upper case will NOT convert. |
|
78 | - $translation_array = array( |
|
79 | - EEM_Registration::status_id_pending_payment => array( |
|
80 | - esc_html__('pending payment', 'event_espresso'), // singular |
|
81 | - esc_html__('pending payments', 'event_espresso') // plural |
|
82 | - ), |
|
83 | - EEM_Registration::status_id_approved => array( |
|
84 | - esc_html__('approved', 'event_espresso'), // singular |
|
85 | - esc_html__('approved', 'event_espresso') // plural |
|
86 | - ), |
|
87 | - EEM_Registration::status_id_not_approved => array( |
|
88 | - esc_html__('not approved', 'event_espresso'), |
|
89 | - esc_html__('not approved', 'event_espresso'), |
|
90 | - ), |
|
91 | - EEM_Registration::status_id_cancelled => array( |
|
92 | - esc_html__('cancelled', 'event_espresso'), |
|
93 | - esc_html__('cancelled', 'event_espresso'), |
|
94 | - ), |
|
95 | - EEM_Registration::status_id_incomplete => array( |
|
96 | - esc_html__('incomplete', 'event_espresso'), |
|
97 | - esc_html__('incomplete', 'event_espresso'), |
|
98 | - ), |
|
99 | - EEM_Registration::status_id_declined => array( |
|
100 | - esc_html__('declined', 'event_espresso'), |
|
101 | - esc_html__('declined', 'event_espresso'), |
|
102 | - ), |
|
103 | - EEM_Registration::status_id_wait_list => array( |
|
104 | - esc_html__('wait list', 'event_espresso'), |
|
105 | - esc_html__('wait list', 'event_espresso'), |
|
106 | - ), |
|
107 | - EEM_Transaction::overpaid_status_code => array( |
|
108 | - esc_html__('overpaid', 'event_espresso'), |
|
109 | - esc_html__('overpaid', 'event_espresso'), |
|
110 | - ), |
|
111 | - EEM_Transaction::complete_status_code => array( |
|
112 | - esc_html__('complete', 'event_espresso'), |
|
113 | - esc_html__('complete', 'event_espresso'), |
|
114 | - ), |
|
115 | - EEM_Transaction::incomplete_status_code => array( |
|
116 | - esc_html__('incomplete', 'event_espresso'), |
|
117 | - esc_html__('incomplete', 'event_espresso'), |
|
118 | - ), |
|
119 | - EEM_Transaction::failed_status_code => array( |
|
120 | - esc_html__('failed', 'event_espresso'), |
|
121 | - esc_html__('failed', 'event_espresso'), |
|
122 | - ), |
|
123 | - EEM_Transaction::abandoned_status_code => array( |
|
124 | - esc_html__('abandoned', 'event_espresso'), |
|
125 | - esc_html__('abandoned', 'event_espresso'), |
|
126 | - ), |
|
127 | - EEM_Payment::status_id_approved => array( |
|
128 | - esc_html__('accepted', 'event_espresso'), |
|
129 | - esc_html__('accepted', 'event_espresso'), |
|
130 | - ), |
|
131 | - EEM_Payment::status_id_pending => array( |
|
132 | - esc_html__('pending', 'event_espresso'), |
|
133 | - esc_html__('pending', 'event_espresso'), |
|
134 | - ), |
|
135 | - EEM_Payment::status_id_cancelled => array( |
|
136 | - esc_html__('cancelled', 'event_espresso'), |
|
137 | - esc_html__('cancelled', 'event_espresso'), |
|
138 | - ), |
|
139 | - EEM_Payment::status_id_declined => array( |
|
140 | - esc_html__('declined', 'event_espresso'), |
|
141 | - esc_html__('declined', 'event_espresso'), |
|
142 | - ), |
|
143 | - EEM_Payment::status_id_failed => array( |
|
144 | - esc_html__('failed', 'event_espresso'), |
|
145 | - esc_html__('failed', 'event_espresso'), |
|
146 | - ), |
|
147 | - // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here. |
|
148 | - EEM_Event::sold_out => array( |
|
149 | - esc_html__('sold out', 'event_espresso'), |
|
150 | - esc_html__('sold out', 'event_espresso'), |
|
151 | - ), |
|
152 | - EEM_Event::postponed => array( |
|
153 | - esc_html__('postponed', 'event_espresso'), |
|
154 | - esc_html__('Postponed', 'event_espresso'), |
|
155 | - ), |
|
156 | - EEM_Event::cancelled => array( |
|
157 | - esc_html__('cancelled', 'event_espresso'), |
|
158 | - esc_html__('cancelled', 'event_espresso'), |
|
159 | - ), |
|
160 | - EE_Ticket::archived => array( |
|
161 | - esc_html__('archived', 'event_espresso'), |
|
162 | - esc_html__('archived', 'event_espresso'), |
|
163 | - ), |
|
164 | - EE_Ticket::expired => array( |
|
165 | - esc_html__('expired', 'event_espresso'), |
|
166 | - esc_html__('expired', 'event_espresso'), |
|
167 | - ), |
|
168 | - EE_Ticket::sold_out => array( |
|
169 | - esc_html__('sold out', 'event_espresso'), |
|
170 | - esc_html__('sold out', 'event_espresso'), |
|
171 | - ), |
|
172 | - EE_Ticket::pending => array( |
|
173 | - esc_html__('upcoming', 'event_espresso'), |
|
174 | - esc_html__('upcoming', 'event_espresso'), |
|
175 | - ), |
|
176 | - EE_Ticket::onsale => array( |
|
177 | - esc_html__('on sale', 'event_espresso'), |
|
178 | - esc_html__('on sale', 'event_espresso'), |
|
179 | - ), |
|
180 | - EE_Datetime::cancelled => array( |
|
181 | - esc_html__('cancelled', 'event_espresso'), |
|
182 | - esc_html__('cancelled', 'event_espresso'), |
|
183 | - ), |
|
184 | - EE_Datetime::sold_out => array( |
|
185 | - esc_html__('sold out', 'event_espresso'), |
|
186 | - esc_html__('sold out', 'event_espresso'), |
|
187 | - ), |
|
188 | - EE_Datetime::expired => array( |
|
189 | - esc_html__('expired', 'event_espresso'), |
|
190 | - esc_html__('expired', 'event_espresso'), |
|
191 | - ), |
|
192 | - EE_Datetime::inactive => array( |
|
193 | - esc_html__('inactive', 'event_espresso'), |
|
194 | - esc_html__('inactive', 'event_espresso'), |
|
195 | - ), |
|
196 | - EE_Datetime::upcoming => array( |
|
197 | - esc_html__('upcoming', 'event_espresso'), |
|
198 | - esc_html__('upcoming', 'event_espresso'), |
|
199 | - ), |
|
200 | - EE_Datetime::active => array( |
|
201 | - esc_html__('active', 'event_espresso'), |
|
202 | - esc_html__('active', 'event_espresso'), |
|
203 | - ), |
|
204 | - EE_Datetime::postponed => array( |
|
205 | - esc_html__('postponed', 'event_espresso'), |
|
206 | - esc_html__('postponed', 'event_espresso'), |
|
207 | - ), |
|
208 | - // messages related |
|
209 | - EEM_Message::status_sent => array( |
|
210 | - esc_html__('sent', 'event_espresso'), |
|
211 | - esc_html__('sent', 'event_espresso'), |
|
212 | - ), |
|
213 | - EEM_Message::status_idle => array( |
|
214 | - esc_html__('queued for sending', 'event_espresso'), |
|
215 | - esc_html__('queued for sending', 'event_espresso'), |
|
216 | - ), |
|
217 | - EEM_Message::status_failed => array( |
|
218 | - esc_html__('failed', 'event_espresso'), |
|
219 | - esc_html__('failed', 'event_espresso'), |
|
220 | - ), |
|
221 | - EEM_Message::status_debug_only => array( |
|
222 | - esc_html__('debug only', 'event_espresso'), |
|
223 | - esc_html__('debug only', 'event_espresso'), |
|
224 | - ), |
|
225 | - EEM_Message::status_messenger_executing => array( |
|
226 | - esc_html__('messenger is executing', 'event_espresso'), |
|
227 | - esc_html__('messenger is executing', 'event_espresso'), |
|
228 | - ), |
|
229 | - EEM_Message::status_resend => array( |
|
230 | - esc_html__('queued for resending', 'event_espresso'), |
|
231 | - esc_html__('queued for resending', 'event_espresso'), |
|
232 | - ), |
|
233 | - EEM_Message::status_incomplete => array( |
|
234 | - esc_html__('queued for generating', 'event_espresso'), |
|
235 | - esc_html__('queued for generating', 'event_espresso'), |
|
236 | - ), |
|
237 | - EEM_Message::status_retry => array( |
|
238 | - esc_html__('failed sending, can be retried', 'event_espresso'), |
|
239 | - esc_html__('failed sending, can be retried', 'event_espresso'), |
|
240 | - ), |
|
241 | - EEM_CPT_Base::post_status_publish => array( |
|
242 | - esc_html__('published', 'event_espresso'), |
|
243 | - esc_html__('published', 'event_espresso'), |
|
244 | - ), |
|
245 | - EEM_CPT_Base::post_status_future => array( |
|
246 | - esc_html__('scheduled', 'event_espresso'), |
|
247 | - esc_html__('scheduled', 'event_espresso'), |
|
248 | - ), |
|
249 | - EEM_CPT_Base::post_status_draft => array( |
|
250 | - esc_html__('draft', 'event_espresso'), |
|
251 | - esc_html__('draft', 'event_espresso'), |
|
252 | - ), |
|
253 | - EEM_CPT_Base::post_status_pending => array( |
|
254 | - esc_html__('pending', 'event_espresso'), |
|
255 | - esc_html__('pending', 'event_espresso'), |
|
256 | - ), |
|
257 | - EEM_CPT_Base::post_status_private => array( |
|
258 | - esc_html__('private', 'event_espresso'), |
|
259 | - esc_html__('private', 'event_espresso'), |
|
260 | - ), |
|
261 | - EEM_CPT_Base::post_status_trashed => array( |
|
262 | - esc_html__('trashed', 'event_espresso'), |
|
263 | - esc_html__('trashed', 'event_espresso'), |
|
264 | - ), |
|
265 | - ); |
|
62 | + /** |
|
63 | + * This method provides the localized singular or plural string for a given status id |
|
64 | + * |
|
65 | + * @param array $statuses This should be an array of statuses in the format array( $status_id, $status_code ). |
|
66 | + * That way if there isn't a translation in the index we'll return the default code. |
|
67 | + * @param boolean $plural Whether to return plural string or not. Note, nearly all of the plural strings are the |
|
68 | + * same as the singular (in English), however, this may NOT be the case with other |
|
69 | + * languages |
|
70 | + * @param string $schema This can be either 'upper', 'lower', or 'sentence'. Basically indicates how we want |
|
71 | + * the status string returned ( UPPER, lower, Sentence) |
|
72 | + * @throws EE_Error |
|
73 | + * @return array an array of translated strings for the incoming status id. |
|
74 | + */ |
|
75 | + public function localized_status($statuses, $plural = false, $schema = 'upper') |
|
76 | + { |
|
77 | + // note these are all in lower case because ucwords() on upper case will NOT convert. |
|
78 | + $translation_array = array( |
|
79 | + EEM_Registration::status_id_pending_payment => array( |
|
80 | + esc_html__('pending payment', 'event_espresso'), // singular |
|
81 | + esc_html__('pending payments', 'event_espresso') // plural |
|
82 | + ), |
|
83 | + EEM_Registration::status_id_approved => array( |
|
84 | + esc_html__('approved', 'event_espresso'), // singular |
|
85 | + esc_html__('approved', 'event_espresso') // plural |
|
86 | + ), |
|
87 | + EEM_Registration::status_id_not_approved => array( |
|
88 | + esc_html__('not approved', 'event_espresso'), |
|
89 | + esc_html__('not approved', 'event_espresso'), |
|
90 | + ), |
|
91 | + EEM_Registration::status_id_cancelled => array( |
|
92 | + esc_html__('cancelled', 'event_espresso'), |
|
93 | + esc_html__('cancelled', 'event_espresso'), |
|
94 | + ), |
|
95 | + EEM_Registration::status_id_incomplete => array( |
|
96 | + esc_html__('incomplete', 'event_espresso'), |
|
97 | + esc_html__('incomplete', 'event_espresso'), |
|
98 | + ), |
|
99 | + EEM_Registration::status_id_declined => array( |
|
100 | + esc_html__('declined', 'event_espresso'), |
|
101 | + esc_html__('declined', 'event_espresso'), |
|
102 | + ), |
|
103 | + EEM_Registration::status_id_wait_list => array( |
|
104 | + esc_html__('wait list', 'event_espresso'), |
|
105 | + esc_html__('wait list', 'event_espresso'), |
|
106 | + ), |
|
107 | + EEM_Transaction::overpaid_status_code => array( |
|
108 | + esc_html__('overpaid', 'event_espresso'), |
|
109 | + esc_html__('overpaid', 'event_espresso'), |
|
110 | + ), |
|
111 | + EEM_Transaction::complete_status_code => array( |
|
112 | + esc_html__('complete', 'event_espresso'), |
|
113 | + esc_html__('complete', 'event_espresso'), |
|
114 | + ), |
|
115 | + EEM_Transaction::incomplete_status_code => array( |
|
116 | + esc_html__('incomplete', 'event_espresso'), |
|
117 | + esc_html__('incomplete', 'event_espresso'), |
|
118 | + ), |
|
119 | + EEM_Transaction::failed_status_code => array( |
|
120 | + esc_html__('failed', 'event_espresso'), |
|
121 | + esc_html__('failed', 'event_espresso'), |
|
122 | + ), |
|
123 | + EEM_Transaction::abandoned_status_code => array( |
|
124 | + esc_html__('abandoned', 'event_espresso'), |
|
125 | + esc_html__('abandoned', 'event_espresso'), |
|
126 | + ), |
|
127 | + EEM_Payment::status_id_approved => array( |
|
128 | + esc_html__('accepted', 'event_espresso'), |
|
129 | + esc_html__('accepted', 'event_espresso'), |
|
130 | + ), |
|
131 | + EEM_Payment::status_id_pending => array( |
|
132 | + esc_html__('pending', 'event_espresso'), |
|
133 | + esc_html__('pending', 'event_espresso'), |
|
134 | + ), |
|
135 | + EEM_Payment::status_id_cancelled => array( |
|
136 | + esc_html__('cancelled', 'event_espresso'), |
|
137 | + esc_html__('cancelled', 'event_espresso'), |
|
138 | + ), |
|
139 | + EEM_Payment::status_id_declined => array( |
|
140 | + esc_html__('declined', 'event_espresso'), |
|
141 | + esc_html__('declined', 'event_espresso'), |
|
142 | + ), |
|
143 | + EEM_Payment::status_id_failed => array( |
|
144 | + esc_html__('failed', 'event_espresso'), |
|
145 | + esc_html__('failed', 'event_espresso'), |
|
146 | + ), |
|
147 | + // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here. |
|
148 | + EEM_Event::sold_out => array( |
|
149 | + esc_html__('sold out', 'event_espresso'), |
|
150 | + esc_html__('sold out', 'event_espresso'), |
|
151 | + ), |
|
152 | + EEM_Event::postponed => array( |
|
153 | + esc_html__('postponed', 'event_espresso'), |
|
154 | + esc_html__('Postponed', 'event_espresso'), |
|
155 | + ), |
|
156 | + EEM_Event::cancelled => array( |
|
157 | + esc_html__('cancelled', 'event_espresso'), |
|
158 | + esc_html__('cancelled', 'event_espresso'), |
|
159 | + ), |
|
160 | + EE_Ticket::archived => array( |
|
161 | + esc_html__('archived', 'event_espresso'), |
|
162 | + esc_html__('archived', 'event_espresso'), |
|
163 | + ), |
|
164 | + EE_Ticket::expired => array( |
|
165 | + esc_html__('expired', 'event_espresso'), |
|
166 | + esc_html__('expired', 'event_espresso'), |
|
167 | + ), |
|
168 | + EE_Ticket::sold_out => array( |
|
169 | + esc_html__('sold out', 'event_espresso'), |
|
170 | + esc_html__('sold out', 'event_espresso'), |
|
171 | + ), |
|
172 | + EE_Ticket::pending => array( |
|
173 | + esc_html__('upcoming', 'event_espresso'), |
|
174 | + esc_html__('upcoming', 'event_espresso'), |
|
175 | + ), |
|
176 | + EE_Ticket::onsale => array( |
|
177 | + esc_html__('on sale', 'event_espresso'), |
|
178 | + esc_html__('on sale', 'event_espresso'), |
|
179 | + ), |
|
180 | + EE_Datetime::cancelled => array( |
|
181 | + esc_html__('cancelled', 'event_espresso'), |
|
182 | + esc_html__('cancelled', 'event_espresso'), |
|
183 | + ), |
|
184 | + EE_Datetime::sold_out => array( |
|
185 | + esc_html__('sold out', 'event_espresso'), |
|
186 | + esc_html__('sold out', 'event_espresso'), |
|
187 | + ), |
|
188 | + EE_Datetime::expired => array( |
|
189 | + esc_html__('expired', 'event_espresso'), |
|
190 | + esc_html__('expired', 'event_espresso'), |
|
191 | + ), |
|
192 | + EE_Datetime::inactive => array( |
|
193 | + esc_html__('inactive', 'event_espresso'), |
|
194 | + esc_html__('inactive', 'event_espresso'), |
|
195 | + ), |
|
196 | + EE_Datetime::upcoming => array( |
|
197 | + esc_html__('upcoming', 'event_espresso'), |
|
198 | + esc_html__('upcoming', 'event_espresso'), |
|
199 | + ), |
|
200 | + EE_Datetime::active => array( |
|
201 | + esc_html__('active', 'event_espresso'), |
|
202 | + esc_html__('active', 'event_espresso'), |
|
203 | + ), |
|
204 | + EE_Datetime::postponed => array( |
|
205 | + esc_html__('postponed', 'event_espresso'), |
|
206 | + esc_html__('postponed', 'event_espresso'), |
|
207 | + ), |
|
208 | + // messages related |
|
209 | + EEM_Message::status_sent => array( |
|
210 | + esc_html__('sent', 'event_espresso'), |
|
211 | + esc_html__('sent', 'event_espresso'), |
|
212 | + ), |
|
213 | + EEM_Message::status_idle => array( |
|
214 | + esc_html__('queued for sending', 'event_espresso'), |
|
215 | + esc_html__('queued for sending', 'event_espresso'), |
|
216 | + ), |
|
217 | + EEM_Message::status_failed => array( |
|
218 | + esc_html__('failed', 'event_espresso'), |
|
219 | + esc_html__('failed', 'event_espresso'), |
|
220 | + ), |
|
221 | + EEM_Message::status_debug_only => array( |
|
222 | + esc_html__('debug only', 'event_espresso'), |
|
223 | + esc_html__('debug only', 'event_espresso'), |
|
224 | + ), |
|
225 | + EEM_Message::status_messenger_executing => array( |
|
226 | + esc_html__('messenger is executing', 'event_espresso'), |
|
227 | + esc_html__('messenger is executing', 'event_espresso'), |
|
228 | + ), |
|
229 | + EEM_Message::status_resend => array( |
|
230 | + esc_html__('queued for resending', 'event_espresso'), |
|
231 | + esc_html__('queued for resending', 'event_espresso'), |
|
232 | + ), |
|
233 | + EEM_Message::status_incomplete => array( |
|
234 | + esc_html__('queued for generating', 'event_espresso'), |
|
235 | + esc_html__('queued for generating', 'event_espresso'), |
|
236 | + ), |
|
237 | + EEM_Message::status_retry => array( |
|
238 | + esc_html__('failed sending, can be retried', 'event_espresso'), |
|
239 | + esc_html__('failed sending, can be retried', 'event_espresso'), |
|
240 | + ), |
|
241 | + EEM_CPT_Base::post_status_publish => array( |
|
242 | + esc_html__('published', 'event_espresso'), |
|
243 | + esc_html__('published', 'event_espresso'), |
|
244 | + ), |
|
245 | + EEM_CPT_Base::post_status_future => array( |
|
246 | + esc_html__('scheduled', 'event_espresso'), |
|
247 | + esc_html__('scheduled', 'event_espresso'), |
|
248 | + ), |
|
249 | + EEM_CPT_Base::post_status_draft => array( |
|
250 | + esc_html__('draft', 'event_espresso'), |
|
251 | + esc_html__('draft', 'event_espresso'), |
|
252 | + ), |
|
253 | + EEM_CPT_Base::post_status_pending => array( |
|
254 | + esc_html__('pending', 'event_espresso'), |
|
255 | + esc_html__('pending', 'event_espresso'), |
|
256 | + ), |
|
257 | + EEM_CPT_Base::post_status_private => array( |
|
258 | + esc_html__('private', 'event_espresso'), |
|
259 | + esc_html__('private', 'event_espresso'), |
|
260 | + ), |
|
261 | + EEM_CPT_Base::post_status_trashed => array( |
|
262 | + esc_html__('trashed', 'event_espresso'), |
|
263 | + esc_html__('trashed', 'event_espresso'), |
|
264 | + ), |
|
265 | + ); |
|
266 | 266 | |
267 | - $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array); |
|
267 | + $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array); |
|
268 | 268 | |
269 | - if (! is_array($statuses)) { |
|
270 | - throw new EE_Error(esc_html__( |
|
271 | - 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code', |
|
272 | - 'event_espresso' |
|
273 | - )); |
|
274 | - } |
|
269 | + if (! is_array($statuses)) { |
|
270 | + throw new EE_Error(esc_html__( |
|
271 | + 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code', |
|
272 | + 'event_espresso' |
|
273 | + )); |
|
274 | + } |
|
275 | 275 | |
276 | - $translation = array(); |
|
276 | + $translation = array(); |
|
277 | 277 | |
278 | - foreach ($statuses as $id => $code) { |
|
279 | - if (isset($translation_array[ $id ])) { |
|
280 | - $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0]; |
|
281 | - } else { |
|
282 | - $translation[ $id ] = $code; |
|
283 | - } |
|
278 | + foreach ($statuses as $id => $code) { |
|
279 | + if (isset($translation_array[ $id ])) { |
|
280 | + $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0]; |
|
281 | + } else { |
|
282 | + $translation[ $id ] = $code; |
|
283 | + } |
|
284 | 284 | |
285 | - // schema |
|
286 | - switch ($schema) { |
|
287 | - case 'lower': |
|
288 | - $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter. |
|
289 | - break; |
|
290 | - case 'sentence': |
|
291 | - $translation[ $id ] = ucwords($translation[ $id ]); |
|
292 | - break; |
|
293 | - case 'upper': |
|
294 | - $translation[ $id ] = strtoupper($translation[ $id ]); |
|
295 | - break; |
|
296 | - } |
|
297 | - } |
|
285 | + // schema |
|
286 | + switch ($schema) { |
|
287 | + case 'lower': |
|
288 | + $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter. |
|
289 | + break; |
|
290 | + case 'sentence': |
|
291 | + $translation[ $id ] = ucwords($translation[ $id ]); |
|
292 | + break; |
|
293 | + case 'upper': |
|
294 | + $translation[ $id ] = strtoupper($translation[ $id ]); |
|
295 | + break; |
|
296 | + } |
|
297 | + } |
|
298 | 298 | |
299 | - return $translation; |
|
300 | - } |
|
299 | + return $translation; |
|
300 | + } |
|
301 | 301 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | 'WP_User' => new EE_Belongs_To_Relation() |
49 | 49 | ); |
50 | 50 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
51 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
51 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
52 | 52 | } |
53 | 53 | $this->_caps_slug = 'messages'; |
54 | 54 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $limit = null, |
76 | 76 | $count = false |
77 | 77 | ) { |
78 | - $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
78 | + $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
79 | 79 | return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
80 | 80 | } |
81 | 81 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
94 | 94 | { |
95 | 95 | return $this->get_all_deleted_and_undeleted( |
96 | - array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
96 | + array(array('MTP_messenger' => $messenger), 'order_by' => array($orderby => $order)) |
|
97 | 97 | ); |
98 | 98 | } |
99 | 99 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $global = true, |
146 | 146 | $user_check = false |
147 | 147 | ) { |
148 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
148 | + $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false); |
|
149 | 149 | $_where['MTP_is_active'] = true; |
150 | 150 | $_where = $this->_maybe_mtp_filters($_where); |
151 | 151 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $_where['MTP_user_id'] = get_current_user_id(); |
161 | 161 | } |
162 | 162 | |
163 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
163 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
164 | 164 | |
165 | 165 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
166 | 166 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | { |
182 | 182 | $_where = $this->_maybe_mtp_filters(); |
183 | 183 | |
184 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
184 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
185 | 185 | |
186 | 186 | $r_templates = $count |
187 | 187 | ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
203 | 203 | { |
204 | - $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
204 | + $where = array_merge($query_params, array('Event.EVT_ID' => $EVT_ID)); |
|
205 | 205 | return $this->get_all( |
206 | - array( $where ) |
|
206 | + array($where) |
|
207 | 207 | ); |
208 | 208 | } |
209 | 209 | |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | $count = false, |
229 | 229 | $global = true |
230 | 230 | ) { |
231 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
231 | + $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false); |
|
232 | 232 | $_where['MTP_is_active'] = true; |
233 | 233 | $_where = $this->_maybe_mtp_filters($_where); |
234 | 234 | |
235 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
235 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
236 | 236 | |
237 | 237 | return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
238 | 238 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | 'MTP_is_active' => $active |
271 | 271 | ); |
272 | 272 | |
273 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
273 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
274 | 274 | |
275 | 275 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
276 | 276 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | $_where['MTP_is_active'] = $active; |
311 | 311 | } |
312 | 312 | |
313 | - $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
313 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
314 | 314 | |
315 | 315 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
316 | 316 | } |
@@ -368,19 +368,19 @@ discard block |
||
368 | 368 | // first let's figure out if the value['content'] in the current index is an array. |
369 | 369 | // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
370 | 370 | if (is_array($value['content'])) { |
371 | - $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
371 | + $assembled_fields[$value['name']] = $value['content']['main']; |
|
372 | 372 | // loop through the content and get the other fields. |
373 | 373 | foreach ($value['content'] as $name => $val) { |
374 | 374 | if ($name == 'main') { |
375 | 375 | continue; |
376 | 376 | } |
377 | - $assembled_fields[ $name ] = $val; |
|
377 | + $assembled_fields[$name] = $val; |
|
378 | 378 | } |
379 | 379 | continue; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // okay if we're here then this is just a straight field=>$value arrangement |
383 | - $assembled_fields[ $value['name'] ] = $value['content']; |
|
383 | + $assembled_fields[$value['name']] = $value['content']; |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | // now we've got the assembled_fields. |
@@ -390,9 +390,9 @@ discard block |
||
390 | 390 | $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
391 | 391 | $mt_ref = str_replace(' ', '_', $mt_ref); |
392 | 392 | |
393 | - $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
393 | + $classname = 'EE_Messages_'.$m_ref.'_'.$mt_ref.'_Validator'; |
|
394 | 394 | |
395 | - if (!class_exists($classname)) { |
|
395 | + if ( ! class_exists($classname)) { |
|
396 | 396 | $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
397 | 397 | $msg[] = sprintf( |
398 | 398 | esc_html__( |
@@ -430,12 +430,12 @@ discard block |
||
430 | 430 | if (empty($messenger_names) && empty($message_type_names)) { |
431 | 431 | return 0; |
432 | 432 | } |
433 | - if (! empty($messenger_names)) { |
|
434 | - $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
433 | + if ( ! empty($messenger_names)) { |
|
434 | + $query_args[0]['MTP_messenger'] = array('IN', (array) $messenger_names); |
|
435 | 435 | } |
436 | - if (! empty($message_type_names)) { |
|
437 | - $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
436 | + if ( ! empty($message_type_names)) { |
|
437 | + $query_args[0]['MTP_message_type'] = array('IN', (array) $message_type_names); |
|
438 | 438 | } |
439 | - return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
439 | + return $this->update(array('MTP_is_active' => false), $query_args); |
|
440 | 440 | } |
441 | 441 | } |
@@ -14,427 +14,427 @@ |
||
14 | 14 | */ |
15 | 15 | class EEM_Message_Template_Group extends EEM_Soft_Delete_Base |
16 | 16 | { |
17 | - // private instance of the EEM_Message_Template_Group object |
|
18 | - protected static $_instance = null; |
|
19 | - |
|
20 | - |
|
21 | - |
|
22 | - protected function __construct($timezone = null) |
|
23 | - { |
|
24 | - $this->singular_item = esc_html__('Message Template Group', 'event_espresso'); |
|
25 | - $this->plural_item = esc_html__('Message Template Groups', 'event_espresso'); |
|
26 | - $this->_tables = array( |
|
27 | - 'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID') |
|
28 | - ); |
|
29 | - $this->_fields = array( |
|
30 | - 'Message_Template_Group' => array( |
|
31 | - 'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso')), |
|
32 | - 'MTP_name' => new EE_Plain_Text_Field('MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, ''), |
|
33 | - 'MTP_description' => new EE_Simple_HTML_Field('MTP_description', esc_html__('A brief description about this template.', 'event_espresso'), false, ''), |
|
34 | - 'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', esc_html__('Template Creator ID', 'event_espresso'), false, get_current_user_id()), |
|
35 | - 'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', esc_html__('Messenger Used for Template', 'event_espresso'), false, 'email'), |
|
36 | - 'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', esc_html__('Message Type', 'event_espresso'), false, 'registration'), |
|
37 | - 'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), false, true), |
|
38 | - 'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false), |
|
39 | - 'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), false, false), |
|
40 | - 'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', esc_html__('Flag indicating whether template group is active', 'event_espresso'), false, true) |
|
41 | - ) |
|
42 | - ); |
|
43 | - $this->_model_relations = array( |
|
44 | - 'Message_Template' => new EE_Has_Many_Relation(), |
|
45 | - 'Message' => new EE_Has_Many_Relation(), |
|
46 | - 'Event' => new EE_HABTM_Relation('Event_Message_Template'), |
|
47 | - 'WP_User' => new EE_Belongs_To_Relation() |
|
48 | - ); |
|
49 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
50 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
51 | - } |
|
52 | - $this->_caps_slug = 'messages'; |
|
53 | - |
|
54 | - parent::__construct($timezone); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * get_all_trashed_message_templates_by_event |
|
61 | - * |
|
62 | - * @access public |
|
63 | - * @param int $EVT_ID specific event id |
|
64 | - * @param string $orderby |
|
65 | - * @param string $order |
|
66 | - * @param null $limit |
|
67 | - * @param bool $count |
|
68 | - * @return array message template objects that are attached to a specific event. |
|
69 | - */ |
|
70 | - public function get_all_trashed_message_templates_by_event( |
|
71 | - $EVT_ID, |
|
72 | - $orderby = 'GRP_ID', |
|
73 | - $order = 'ASC', |
|
74 | - $limit = null, |
|
75 | - $count = false |
|
76 | - ) { |
|
77 | - $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
78 | - return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * get_all_message_templates_by_messenger |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @param $messenger |
|
88 | - * @param string $orderby |
|
89 | - * @param string $order |
|
90 | - * @return array all (including trashed or inactive) message template group objects for the given messenger |
|
91 | - */ |
|
92 | - public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
|
93 | - { |
|
94 | - return $this->get_all_deleted_and_undeleted( |
|
95 | - array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * This simply adds on any messenger/message type filters that may be present in the request |
|
102 | - * |
|
103 | - * @param array $_where any existing where conditions to append these to. |
|
104 | - * @return array original where conditions or original with additional filters. |
|
105 | - */ |
|
106 | - protected function _maybe_mtp_filters($_where = array()) |
|
107 | - { |
|
108 | - /** @var RequestInterface $request */ |
|
109 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
110 | - $messenger = $request->getRequestParam('ee_messenger_filter_by'); |
|
111 | - // account for messenger or message type filters |
|
112 | - if ($messenger !== '' && $messenger !== 'none_selected' && $messenger !== 'all') { |
|
113 | - $_where['MTP_messenger'] = $messenger; |
|
114 | - } |
|
115 | - $message_type = $request->getRequestParam('ee_message_type_filter_by'); |
|
116 | - if ( |
|
117 | - $message_type !== '' && $message_type !== 'none_selected' |
|
118 | - ) { |
|
119 | - $_where['MTP_message_type'] = $message_type; |
|
120 | - } |
|
121 | - |
|
122 | - return $_where; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * get_all_active_message_templates groups |
|
129 | - * |
|
130 | - * @access public |
|
131 | - * @param string $orderby |
|
132 | - * @param string $order |
|
133 | - * @param null $limit |
|
134 | - * @param bool $count |
|
135 | - * @param bool $global |
|
136 | - * @param bool $user_check |
|
137 | - * @return array all active (non_trashed, active) message template objects |
|
138 | - */ |
|
139 | - public function get_all_active_message_templates( |
|
140 | - $orderby = 'GRP_ID', |
|
141 | - $order = 'ASC', |
|
142 | - $limit = null, |
|
143 | - $count = false, |
|
144 | - $global = true, |
|
145 | - $user_check = false |
|
146 | - ) { |
|
147 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
148 | - $_where['MTP_is_active'] = true; |
|
149 | - $_where = $this->_maybe_mtp_filters($_where); |
|
150 | - |
|
151 | - if ( |
|
152 | - $user_check |
|
153 | - && ! $global |
|
154 | - && ! EE_Registry::instance()->CAP->current_user_can( |
|
155 | - 'ee_read_others_messages', |
|
156 | - 'get_all_active_message_templates' |
|
157 | - ) |
|
158 | - ) { |
|
159 | - $_where['MTP_user_id'] = get_current_user_id(); |
|
160 | - } |
|
161 | - |
|
162 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
163 | - |
|
164 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * retrieve ALL message_template groups from db regardless of wht |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @param string $orderby |
|
174 | - * @param string $order |
|
175 | - * @param null $limit |
|
176 | - * @param bool $count |
|
177 | - * @return mixed array on success, FALSE on fail |
|
178 | - */ |
|
179 | - public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false) |
|
180 | - { |
|
181 | - $_where = $this->_maybe_mtp_filters(); |
|
182 | - |
|
183 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
184 | - |
|
185 | - $r_templates = $count |
|
186 | - ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
|
187 | - : $this->get_all_deleted_and_undeleted($query_params); |
|
188 | - |
|
189 | - return $r_templates; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * This gets all the custom templates attached to a specific event |
|
197 | - * @param int $EVT_ID event id |
|
198 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
199 | - * @return EE_Message_Template_Group[] |
|
200 | - */ |
|
201 | - public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
|
202 | - { |
|
203 | - $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
204 | - return $this->get_all( |
|
205 | - array( $where ) |
|
206 | - ); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * get_all_trashed_grouped_message_templates |
|
213 | - * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @param string $orderby |
|
217 | - * @param string $order |
|
218 | - * @param null $limit |
|
219 | - * @param bool $count |
|
220 | - * @param bool $global |
|
221 | - * @return \EE_Message_Template_Group[] message template groups. |
|
222 | - */ |
|
223 | - public function get_all_trashed_grouped_message_templates( |
|
224 | - $orderby = 'GRP_ID', |
|
225 | - $order = 'ASC', |
|
226 | - $limit = null, |
|
227 | - $count = false, |
|
228 | - $global = true |
|
229 | - ) { |
|
230 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
231 | - $_where['MTP_is_active'] = true; |
|
232 | - $_where = $this->_maybe_mtp_filters($_where); |
|
233 | - |
|
234 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
235 | - |
|
236 | - return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * this returns the message template group(s) for a given event, messenger, and message template |
|
243 | - * |
|
244 | - * @param string $messenger |
|
245 | - * @param string $message_type |
|
246 | - * @param $evt_id |
|
247 | - * @param string $orderby pointless at this point but still included |
|
248 | - * @param string $order |
|
249 | - * @param mixed (array|null) $limit array($offset, $num) |
|
250 | - * @param bool $count true = just return count, false = objects |
|
251 | - * @param bool $active ignore "active" or not. (default only return active) |
|
252 | - * @return \mixed[]) depending on $count. |
|
253 | - */ |
|
254 | - public function get_event_message_templates_by_m_and_mt_and_evt( |
|
255 | - $messenger, |
|
256 | - $message_type, |
|
257 | - $evt_id, |
|
258 | - $orderby = 'GRP_ID', |
|
259 | - $order = 'ASC', |
|
260 | - $limit = null, |
|
261 | - $count = false, |
|
262 | - $active = true |
|
263 | - ) { |
|
264 | - $_where = array( |
|
265 | - 'MTP_messenger' => $messenger, |
|
266 | - 'MTP_message_type' => $message_type, |
|
267 | - 'Event.EVT_ID' => $evt_id, |
|
268 | - 'MTP_is_global' => true, |
|
269 | - 'MTP_is_active' => $active |
|
270 | - ); |
|
271 | - |
|
272 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
273 | - |
|
274 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * get all GLOBAL message template groups for the given messenger and message type |
|
282 | - * |
|
283 | - * @param string $messenger slug for messenger |
|
284 | - * @param string $message_type slug for message type |
|
285 | - * @param string $orderby what column to orderby |
|
286 | - * @param string $order ASC or DESC |
|
287 | - * @param mixed (array|null) $limit array($offset, $num) |
|
288 | - * @param bool $count true = just return count, false = objects |
|
289 | - * @param bool $active ignore "active" or not. (default only return active) - |
|
290 | - * 'all' means return both inactive AND inactive. |
|
291 | - * @return array message template objects that are global (i.e. non-event) |
|
292 | - */ |
|
293 | - public function get_global_message_template_by_m_and_mt( |
|
294 | - $messenger, |
|
295 | - $message_type, |
|
296 | - $orderby = 'GRP_ID', |
|
297 | - $order = 'ASC', |
|
298 | - $limit = null, |
|
299 | - $count = false, |
|
300 | - $active = true |
|
301 | - ) { |
|
302 | - $_where = array( |
|
303 | - 'MTP_messenger' => $messenger, |
|
304 | - 'MTP_message_type' => $message_type, |
|
305 | - 'MTP_is_global' => true, |
|
306 | - ); |
|
307 | - |
|
308 | - if ($active != 'all') { |
|
309 | - $_where['MTP_is_active'] = $active; |
|
310 | - } |
|
311 | - |
|
312 | - $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
313 | - |
|
314 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * get all custom message template groups for the given messenger and message type |
|
322 | - * @param string $messenger messenger |
|
323 | - * @param string $message_type messagetype |
|
324 | - * @param array $query_params same as EEM_Base->get_all() |
|
325 | - * @return EE_Message_Template_Group[] |
|
326 | - */ |
|
327 | - public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array()) |
|
328 | - { |
|
329 | - return $this->get_all( |
|
330 | - array_merge( |
|
331 | - $query_params, |
|
332 | - array( |
|
333 | - array( |
|
334 | - 'MTP_is_global' => false, |
|
335 | - 'MTP_messenger' => $messenger, |
|
336 | - 'MTP_message_type' => $message_type |
|
337 | - ) |
|
338 | - ) |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * This sends things to the validator for the given messenger and message type. |
|
347 | - * |
|
348 | - * @param array $fields the incoming fields to check. |
|
349 | - * Note this array is in the formatted fields from the form fields setup. |
|
350 | - * So we need to reformat this into an array of expected field refs by the validator. |
|
351 | - * Note also that this is not only the fields for the Message Template Group |
|
352 | - * but ALSO for Message Template. |
|
353 | - * @param string $context The context the fields were obtained from. |
|
354 | - * @param string $messenger The messenger we are validating |
|
355 | - * @param string $message_type The message type we are validating. |
|
356 | - * @return mixed If the fields all check out then we return true otherwise error messages are returned |
|
357 | - * (indexed by field name); |
|
358 | - * @throws \EE_Error |
|
359 | - */ |
|
360 | - public function validate($fields, $context, $messenger, $message_type) |
|
361 | - { |
|
362 | - |
|
363 | - $assembled_fields = array(); |
|
364 | - |
|
365 | - // let's loop through all the fields and set them up in the right format |
|
366 | - foreach ($fields as $index => $value) { |
|
367 | - // first let's figure out if the value['content'] in the current index is an array. |
|
368 | - // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
369 | - if (is_array($value['content'])) { |
|
370 | - $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
371 | - // loop through the content and get the other fields. |
|
372 | - foreach ($value['content'] as $name => $val) { |
|
373 | - if ($name == 'main') { |
|
374 | - continue; |
|
375 | - } |
|
376 | - $assembled_fields[ $name ] = $val; |
|
377 | - } |
|
378 | - continue; |
|
379 | - } |
|
380 | - |
|
381 | - // okay if we're here then this is just a straight field=>$value arrangement |
|
382 | - $assembled_fields[ $value['name'] ] = $value['content']; |
|
383 | - } |
|
384 | - |
|
385 | - // now we've got the assembled_fields. |
|
386 | - // We need to setup the string for the appropriate validator class and call that. |
|
387 | - $m_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
388 | - $m_ref = str_replace(' ', '_', $m_ref); |
|
389 | - $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
390 | - $mt_ref = str_replace(' ', '_', $mt_ref); |
|
391 | - |
|
392 | - $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
393 | - |
|
394 | - if (!class_exists($classname)) { |
|
395 | - $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
396 | - $msg[] = sprintf( |
|
397 | - esc_html__( |
|
398 | - 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
399 | - 'event_espresso' |
|
400 | - ), |
|
401 | - $classname |
|
402 | - ); |
|
403 | - throw new EE_Error(implode('||', $msg)); |
|
404 | - } |
|
405 | - |
|
406 | - $a = new ReflectionClass($classname); |
|
407 | - $_VLD = $a->newInstance($assembled_fields, $context); |
|
408 | - $result = $_VLD->validate(); |
|
409 | - return $result; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Updates all message template groups matching the incoming arguments to inactive status. |
|
416 | - * |
|
417 | - * @param array $messenger_names The messenger slugs. |
|
418 | - * If empty then all templates matching the message types are marked inactive. |
|
419 | - * Otherwise only templates matching the messengers and message types. |
|
420 | - * @param array $message_type_names The message type slugs. |
|
421 | - * If empty then all templates matching the messengers are marked inactive. |
|
422 | - * Otherwise only templates matching the messengers and message types. |
|
423 | - * |
|
424 | - * @return int count of updated records. |
|
425 | - */ |
|
426 | - public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array()) |
|
427 | - { |
|
428 | - $query_args = array(); |
|
429 | - if (empty($messenger_names) && empty($message_type_names)) { |
|
430 | - return 0; |
|
431 | - } |
|
432 | - if (! empty($messenger_names)) { |
|
433 | - $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
434 | - } |
|
435 | - if (! empty($message_type_names)) { |
|
436 | - $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
437 | - } |
|
438 | - return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
439 | - } |
|
17 | + // private instance of the EEM_Message_Template_Group object |
|
18 | + protected static $_instance = null; |
|
19 | + |
|
20 | + |
|
21 | + |
|
22 | + protected function __construct($timezone = null) |
|
23 | + { |
|
24 | + $this->singular_item = esc_html__('Message Template Group', 'event_espresso'); |
|
25 | + $this->plural_item = esc_html__('Message Template Groups', 'event_espresso'); |
|
26 | + $this->_tables = array( |
|
27 | + 'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID') |
|
28 | + ); |
|
29 | + $this->_fields = array( |
|
30 | + 'Message_Template_Group' => array( |
|
31 | + 'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso')), |
|
32 | + 'MTP_name' => new EE_Plain_Text_Field('MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, ''), |
|
33 | + 'MTP_description' => new EE_Simple_HTML_Field('MTP_description', esc_html__('A brief description about this template.', 'event_espresso'), false, ''), |
|
34 | + 'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', esc_html__('Template Creator ID', 'event_espresso'), false, get_current_user_id()), |
|
35 | + 'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', esc_html__('Messenger Used for Template', 'event_espresso'), false, 'email'), |
|
36 | + 'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', esc_html__('Message Type', 'event_espresso'), false, 'registration'), |
|
37 | + 'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), false, true), |
|
38 | + 'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false), |
|
39 | + 'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), false, false), |
|
40 | + 'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', esc_html__('Flag indicating whether template group is active', 'event_espresso'), false, true) |
|
41 | + ) |
|
42 | + ); |
|
43 | + $this->_model_relations = array( |
|
44 | + 'Message_Template' => new EE_Has_Many_Relation(), |
|
45 | + 'Message' => new EE_Has_Many_Relation(), |
|
46 | + 'Event' => new EE_HABTM_Relation('Event_Message_Template'), |
|
47 | + 'WP_User' => new EE_Belongs_To_Relation() |
|
48 | + ); |
|
49 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
50 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
51 | + } |
|
52 | + $this->_caps_slug = 'messages'; |
|
53 | + |
|
54 | + parent::__construct($timezone); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * get_all_trashed_message_templates_by_event |
|
61 | + * |
|
62 | + * @access public |
|
63 | + * @param int $EVT_ID specific event id |
|
64 | + * @param string $orderby |
|
65 | + * @param string $order |
|
66 | + * @param null $limit |
|
67 | + * @param bool $count |
|
68 | + * @return array message template objects that are attached to a specific event. |
|
69 | + */ |
|
70 | + public function get_all_trashed_message_templates_by_event( |
|
71 | + $EVT_ID, |
|
72 | + $orderby = 'GRP_ID', |
|
73 | + $order = 'ASC', |
|
74 | + $limit = null, |
|
75 | + $count = false |
|
76 | + ) { |
|
77 | + $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
78 | + return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * get_all_message_templates_by_messenger |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @param $messenger |
|
88 | + * @param string $orderby |
|
89 | + * @param string $order |
|
90 | + * @return array all (including trashed or inactive) message template group objects for the given messenger |
|
91 | + */ |
|
92 | + public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
|
93 | + { |
|
94 | + return $this->get_all_deleted_and_undeleted( |
|
95 | + array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * This simply adds on any messenger/message type filters that may be present in the request |
|
102 | + * |
|
103 | + * @param array $_where any existing where conditions to append these to. |
|
104 | + * @return array original where conditions or original with additional filters. |
|
105 | + */ |
|
106 | + protected function _maybe_mtp_filters($_where = array()) |
|
107 | + { |
|
108 | + /** @var RequestInterface $request */ |
|
109 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
110 | + $messenger = $request->getRequestParam('ee_messenger_filter_by'); |
|
111 | + // account for messenger or message type filters |
|
112 | + if ($messenger !== '' && $messenger !== 'none_selected' && $messenger !== 'all') { |
|
113 | + $_where['MTP_messenger'] = $messenger; |
|
114 | + } |
|
115 | + $message_type = $request->getRequestParam('ee_message_type_filter_by'); |
|
116 | + if ( |
|
117 | + $message_type !== '' && $message_type !== 'none_selected' |
|
118 | + ) { |
|
119 | + $_where['MTP_message_type'] = $message_type; |
|
120 | + } |
|
121 | + |
|
122 | + return $_where; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * get_all_active_message_templates groups |
|
129 | + * |
|
130 | + * @access public |
|
131 | + * @param string $orderby |
|
132 | + * @param string $order |
|
133 | + * @param null $limit |
|
134 | + * @param bool $count |
|
135 | + * @param bool $global |
|
136 | + * @param bool $user_check |
|
137 | + * @return array all active (non_trashed, active) message template objects |
|
138 | + */ |
|
139 | + public function get_all_active_message_templates( |
|
140 | + $orderby = 'GRP_ID', |
|
141 | + $order = 'ASC', |
|
142 | + $limit = null, |
|
143 | + $count = false, |
|
144 | + $global = true, |
|
145 | + $user_check = false |
|
146 | + ) { |
|
147 | + $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
148 | + $_where['MTP_is_active'] = true; |
|
149 | + $_where = $this->_maybe_mtp_filters($_where); |
|
150 | + |
|
151 | + if ( |
|
152 | + $user_check |
|
153 | + && ! $global |
|
154 | + && ! EE_Registry::instance()->CAP->current_user_can( |
|
155 | + 'ee_read_others_messages', |
|
156 | + 'get_all_active_message_templates' |
|
157 | + ) |
|
158 | + ) { |
|
159 | + $_where['MTP_user_id'] = get_current_user_id(); |
|
160 | + } |
|
161 | + |
|
162 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
163 | + |
|
164 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * retrieve ALL message_template groups from db regardless of wht |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @param string $orderby |
|
174 | + * @param string $order |
|
175 | + * @param null $limit |
|
176 | + * @param bool $count |
|
177 | + * @return mixed array on success, FALSE on fail |
|
178 | + */ |
|
179 | + public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false) |
|
180 | + { |
|
181 | + $_where = $this->_maybe_mtp_filters(); |
|
182 | + |
|
183 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
184 | + |
|
185 | + $r_templates = $count |
|
186 | + ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
|
187 | + : $this->get_all_deleted_and_undeleted($query_params); |
|
188 | + |
|
189 | + return $r_templates; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * This gets all the custom templates attached to a specific event |
|
197 | + * @param int $EVT_ID event id |
|
198 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
199 | + * @return EE_Message_Template_Group[] |
|
200 | + */ |
|
201 | + public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
|
202 | + { |
|
203 | + $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
204 | + return $this->get_all( |
|
205 | + array( $where ) |
|
206 | + ); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * get_all_trashed_grouped_message_templates |
|
213 | + * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @param string $orderby |
|
217 | + * @param string $order |
|
218 | + * @param null $limit |
|
219 | + * @param bool $count |
|
220 | + * @param bool $global |
|
221 | + * @return \EE_Message_Template_Group[] message template groups. |
|
222 | + */ |
|
223 | + public function get_all_trashed_grouped_message_templates( |
|
224 | + $orderby = 'GRP_ID', |
|
225 | + $order = 'ASC', |
|
226 | + $limit = null, |
|
227 | + $count = false, |
|
228 | + $global = true |
|
229 | + ) { |
|
230 | + $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
231 | + $_where['MTP_is_active'] = true; |
|
232 | + $_where = $this->_maybe_mtp_filters($_where); |
|
233 | + |
|
234 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
235 | + |
|
236 | + return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * this returns the message template group(s) for a given event, messenger, and message template |
|
243 | + * |
|
244 | + * @param string $messenger |
|
245 | + * @param string $message_type |
|
246 | + * @param $evt_id |
|
247 | + * @param string $orderby pointless at this point but still included |
|
248 | + * @param string $order |
|
249 | + * @param mixed (array|null) $limit array($offset, $num) |
|
250 | + * @param bool $count true = just return count, false = objects |
|
251 | + * @param bool $active ignore "active" or not. (default only return active) |
|
252 | + * @return \mixed[]) depending on $count. |
|
253 | + */ |
|
254 | + public function get_event_message_templates_by_m_and_mt_and_evt( |
|
255 | + $messenger, |
|
256 | + $message_type, |
|
257 | + $evt_id, |
|
258 | + $orderby = 'GRP_ID', |
|
259 | + $order = 'ASC', |
|
260 | + $limit = null, |
|
261 | + $count = false, |
|
262 | + $active = true |
|
263 | + ) { |
|
264 | + $_where = array( |
|
265 | + 'MTP_messenger' => $messenger, |
|
266 | + 'MTP_message_type' => $message_type, |
|
267 | + 'Event.EVT_ID' => $evt_id, |
|
268 | + 'MTP_is_global' => true, |
|
269 | + 'MTP_is_active' => $active |
|
270 | + ); |
|
271 | + |
|
272 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
273 | + |
|
274 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * get all GLOBAL message template groups for the given messenger and message type |
|
282 | + * |
|
283 | + * @param string $messenger slug for messenger |
|
284 | + * @param string $message_type slug for message type |
|
285 | + * @param string $orderby what column to orderby |
|
286 | + * @param string $order ASC or DESC |
|
287 | + * @param mixed (array|null) $limit array($offset, $num) |
|
288 | + * @param bool $count true = just return count, false = objects |
|
289 | + * @param bool $active ignore "active" or not. (default only return active) - |
|
290 | + * 'all' means return both inactive AND inactive. |
|
291 | + * @return array message template objects that are global (i.e. non-event) |
|
292 | + */ |
|
293 | + public function get_global_message_template_by_m_and_mt( |
|
294 | + $messenger, |
|
295 | + $message_type, |
|
296 | + $orderby = 'GRP_ID', |
|
297 | + $order = 'ASC', |
|
298 | + $limit = null, |
|
299 | + $count = false, |
|
300 | + $active = true |
|
301 | + ) { |
|
302 | + $_where = array( |
|
303 | + 'MTP_messenger' => $messenger, |
|
304 | + 'MTP_message_type' => $message_type, |
|
305 | + 'MTP_is_global' => true, |
|
306 | + ); |
|
307 | + |
|
308 | + if ($active != 'all') { |
|
309 | + $_where['MTP_is_active'] = $active; |
|
310 | + } |
|
311 | + |
|
312 | + $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
313 | + |
|
314 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * get all custom message template groups for the given messenger and message type |
|
322 | + * @param string $messenger messenger |
|
323 | + * @param string $message_type messagetype |
|
324 | + * @param array $query_params same as EEM_Base->get_all() |
|
325 | + * @return EE_Message_Template_Group[] |
|
326 | + */ |
|
327 | + public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array()) |
|
328 | + { |
|
329 | + return $this->get_all( |
|
330 | + array_merge( |
|
331 | + $query_params, |
|
332 | + array( |
|
333 | + array( |
|
334 | + 'MTP_is_global' => false, |
|
335 | + 'MTP_messenger' => $messenger, |
|
336 | + 'MTP_message_type' => $message_type |
|
337 | + ) |
|
338 | + ) |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * This sends things to the validator for the given messenger and message type. |
|
347 | + * |
|
348 | + * @param array $fields the incoming fields to check. |
|
349 | + * Note this array is in the formatted fields from the form fields setup. |
|
350 | + * So we need to reformat this into an array of expected field refs by the validator. |
|
351 | + * Note also that this is not only the fields for the Message Template Group |
|
352 | + * but ALSO for Message Template. |
|
353 | + * @param string $context The context the fields were obtained from. |
|
354 | + * @param string $messenger The messenger we are validating |
|
355 | + * @param string $message_type The message type we are validating. |
|
356 | + * @return mixed If the fields all check out then we return true otherwise error messages are returned |
|
357 | + * (indexed by field name); |
|
358 | + * @throws \EE_Error |
|
359 | + */ |
|
360 | + public function validate($fields, $context, $messenger, $message_type) |
|
361 | + { |
|
362 | + |
|
363 | + $assembled_fields = array(); |
|
364 | + |
|
365 | + // let's loop through all the fields and set them up in the right format |
|
366 | + foreach ($fields as $index => $value) { |
|
367 | + // first let's figure out if the value['content'] in the current index is an array. |
|
368 | + // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
369 | + if (is_array($value['content'])) { |
|
370 | + $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
371 | + // loop through the content and get the other fields. |
|
372 | + foreach ($value['content'] as $name => $val) { |
|
373 | + if ($name == 'main') { |
|
374 | + continue; |
|
375 | + } |
|
376 | + $assembled_fields[ $name ] = $val; |
|
377 | + } |
|
378 | + continue; |
|
379 | + } |
|
380 | + |
|
381 | + // okay if we're here then this is just a straight field=>$value arrangement |
|
382 | + $assembled_fields[ $value['name'] ] = $value['content']; |
|
383 | + } |
|
384 | + |
|
385 | + // now we've got the assembled_fields. |
|
386 | + // We need to setup the string for the appropriate validator class and call that. |
|
387 | + $m_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
388 | + $m_ref = str_replace(' ', '_', $m_ref); |
|
389 | + $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
390 | + $mt_ref = str_replace(' ', '_', $mt_ref); |
|
391 | + |
|
392 | + $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
393 | + |
|
394 | + if (!class_exists($classname)) { |
|
395 | + $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
396 | + $msg[] = sprintf( |
|
397 | + esc_html__( |
|
398 | + 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
399 | + 'event_espresso' |
|
400 | + ), |
|
401 | + $classname |
|
402 | + ); |
|
403 | + throw new EE_Error(implode('||', $msg)); |
|
404 | + } |
|
405 | + |
|
406 | + $a = new ReflectionClass($classname); |
|
407 | + $_VLD = $a->newInstance($assembled_fields, $context); |
|
408 | + $result = $_VLD->validate(); |
|
409 | + return $result; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Updates all message template groups matching the incoming arguments to inactive status. |
|
416 | + * |
|
417 | + * @param array $messenger_names The messenger slugs. |
|
418 | + * If empty then all templates matching the message types are marked inactive. |
|
419 | + * Otherwise only templates matching the messengers and message types. |
|
420 | + * @param array $message_type_names The message type slugs. |
|
421 | + * If empty then all templates matching the messengers are marked inactive. |
|
422 | + * Otherwise only templates matching the messengers and message types. |
|
423 | + * |
|
424 | + * @return int count of updated records. |
|
425 | + */ |
|
426 | + public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array()) |
|
427 | + { |
|
428 | + $query_args = array(); |
|
429 | + if (empty($messenger_names) && empty($message_type_names)) { |
|
430 | + return 0; |
|
431 | + } |
|
432 | + if (! empty($messenger_names)) { |
|
433 | + $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
434 | + } |
|
435 | + if (! empty($message_type_names)) { |
|
436 | + $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
437 | + } |
|
438 | + return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
439 | + } |
|
440 | 440 | } |
@@ -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 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null) |
127 | 127 | { |
128 | 128 | // all payments for a TXN ordered chronologically |
129 | - $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' )); |
|
129 | + $query_params = array(array('TXN_ID' => $TXN_ID), 'order_by' => array('PAY_timestamp' => 'ASC')); |
|
130 | 130 | // if provided with a status, search specifically for that status. Otherwise get them all |
131 | 131 | if ($status_of_payment) { |
132 | 132 | $query_params[0]['STS_ID'] = $status_of_payment; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | { |
169 | 169 | $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
170 | 170 | // if $start_date or $end date, verify $format is included. |
171 | - if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) { |
|
171 | + if (( ! empty($start_date) || ! empty($end_date)) && empty($format)) { |
|
172 | 172 | throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string. The format string is needed for setting up the query', 'event_espresso')); |
173 | 173 | } |
174 | 174 | $now = new DateTime('now'); |
@@ -178,12 +178,12 @@ discard block |
||
178 | 178 | // setup start date |
179 | 179 | $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now; |
180 | 180 | EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone); |
181 | - $start_date = $start_date->format('Y-m-d') . ' 00:00:00'; |
|
181 | + $start_date = $start_date->format('Y-m-d').' 00:00:00'; |
|
182 | 182 | $start_date = strtotime($start_date); |
183 | 183 | // setup end date |
184 | 184 | $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now; |
185 | 185 | EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone); |
186 | - $end_date = $end_date->format('Y-m-d') . ' 23:59:59'; |
|
186 | + $end_date = $end_date->format('Y-m-d').' 23:59:59'; |
|
187 | 187 | $end_date = strtotime($end_date); |
188 | 188 | |
189 | 189 | // make sure our start date is the lowest value and vice versa |
@@ -191,10 +191,10 @@ discard block |
||
191 | 191 | $end = max($start_date, $end_date); |
192 | 192 | |
193 | 193 | // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model. |
194 | - $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone()); |
|
195 | - $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone()); |
|
194 | + $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start).' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone()); |
|
195 | + $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end).' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone()); |
|
196 | 196 | |
197 | - return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date)))); |
|
197 | + return $this->get_all(array(array('PAY_timestamp' => array('>=', $start_date), 'PAY_timestamp*' => array('<=', $end_date)))); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -11,233 +11,233 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Payment extends EEM_Base implements EEMI_Payment |
13 | 13 | { |
14 | - // private instance of the Payment object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the Payment object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | 19 | /** |
20 | - * Status id in esp_status table that represents an approved payment |
|
21 | - */ |
|
22 | - const status_id_approved = 'PAP'; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Status id in esp_status table that represents a pending payment |
|
27 | - */ |
|
28 | - const status_id_pending = 'PPN'; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Status id in esp_status table that represents a cancelled payment (eg, the |
|
33 | - * user went to PayPal, but on the paypal site decided to cancel the payment) |
|
34 | - */ |
|
35 | - const status_id_cancelled = 'PCN'; |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Status id in esp_status table that represents a payment that was declined by |
|
41 | - * the gateway. (eg, the user's card had no funds, or it was a fraudulent card) |
|
42 | - */ |
|
43 | - const status_id_declined = 'PDC'; |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Status id in esp_status table that represents a payment that failed for technical reasons. |
|
49 | - * (Eg, there was some error in communicating with the payment gateway.) |
|
50 | - */ |
|
51 | - const status_id_failed = 'PFL'; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
56 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
57 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
58 | - * timezone in the 'timezone_string' wp option) |
|
59 | - * @throws ReflectionException |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - protected function __construct($timezone) |
|
63 | - { |
|
64 | - $this->singular_item = esc_html__('Payment', 'event_espresso'); |
|
65 | - $this->plural_item = esc_html__('Payments', 'event_espresso'); |
|
66 | - |
|
67 | - $this->_tables = array( |
|
68 | - 'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID') |
|
69 | - ); |
|
70 | - $this->_fields = array( |
|
71 | - 'Payment' => array( |
|
72 | - 'PAY_ID' => new EE_Primary_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso')), |
|
73 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso'), false, 0, 'Transaction'), |
|
74 | - 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'), |
|
75 | - 'PAY_timestamp' => new EE_Datetime_Field('PAY_timestamp', esc_html__('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
76 | - 'PAY_source' => new EE_All_Caps_Text_Field('PAY_source', esc_html__('User-friendly description of payment', 'event_espresso'), false, 'CART'), |
|
77 | - 'PAY_amount' => new EE_Money_Field('PAY_amount', esc_html__('Amount Payment should be for', 'event_espresso'), false, 0), |
|
78 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'), |
|
79 | - 'PAY_gateway_response' => new EE_Plain_Text_Field('PAY_gateway_response', esc_html__('Response from Gateway about the payment', 'event_espresso'), false, ''), |
|
80 | - 'PAY_txn_id_chq_nmbr' => new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''), |
|
81 | - 'PAY_po_number' => new EE_Plain_Text_Field('PAY_po_number', esc_html__('Purchase or Sales Number', 'event_espresso'), true, ''), |
|
82 | - 'PAY_extra_accntng' => new EE_Simple_HTML_Field('PAY_extra_accntng', esc_html__('Extra Account Info', 'event_espresso'), true, ''), |
|
83 | - 'PAY_details' => new EE_Serialized_Text_Field('PAY_details', esc_html__('Full Gateway response about payment', 'event_espresso'), true, ''), |
|
84 | - 'PAY_redirect_url' => new EE_Plain_Text_Field('PAY_redirect_url', esc_html__("Redirect URL", 'event_espresso'), true), |
|
85 | - 'PAY_redirect_args' => new EE_Serialized_Text_Field('PAY_redirect_args', esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'), true) |
|
86 | - ) |
|
87 | - ); |
|
88 | - $this->_model_relations = array( |
|
89 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
90 | - 'Status' => new EE_Belongs_To_Relation(), |
|
91 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
92 | - 'Registration_Payment' => new EE_Has_Many_Relation(), |
|
93 | - 'Registration' => new EE_HABTM_Relation('Registration_Payment'), |
|
94 | - ); |
|
95 | - $this->_model_chain_to_wp_user = 'Payment_Method'; |
|
96 | - $this->_caps_slug = 'transactions'; |
|
97 | - parent::__construct($timezone); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned |
|
105 | - * to the payment. This is handy for verifying an IPN hasn't already been processed. |
|
106 | - * @param string $PAY_txn_id_chq_nmbr |
|
107 | - * @return EE_Payment |
|
108 | - */ |
|
109 | - public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr) |
|
110 | - { |
|
111 | - return $this->get_one(array(array('PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr))); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * retrieve all payments from db for a particular transaction, optionally with |
|
119 | - * a particular status |
|
120 | - * |
|
121 | - * @access public |
|
122 | - * @param $TXN_ID |
|
123 | - * @param string $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status |
|
124 | - * @return EE_Payment[] |
|
125 | - */ |
|
126 | - public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null) |
|
127 | - { |
|
128 | - // all payments for a TXN ordered chronologically |
|
129 | - $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' )); |
|
130 | - // if provided with a status, search specifically for that status. Otherwise get them all |
|
131 | - if ($status_of_payment) { |
|
132 | - $query_params[0]['STS_ID'] = $status_of_payment; |
|
133 | - } |
|
134 | - // retrieve payments |
|
135 | - return $this->get_all($query_params); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Only gets payments which have been approved |
|
142 | - * @param int $TXN_ID |
|
143 | - * @return EE_Payment[] |
|
144 | - */ |
|
145 | - public function get_approved_payments_for_transaction($TXN_ID = 0) |
|
146 | - { |
|
147 | - return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * retrieve all payments from db between two dates, |
|
156 | - * |
|
157 | - * @param string $start_date incoming start date. If empty the beginning of today is used. |
|
158 | - * @param string $end_date incoming end date. If empty the end of today is used. |
|
159 | - * @param string $format If you include $start_date or $end_date then you must include the format string |
|
160 | - * for the format your date is in. |
|
161 | - * @param string $timezone If your range is in a different timezone then the current setting on this |
|
162 | - * WordPress install, then include it here. |
|
163 | - * @throws EE_Error |
|
164 | - * |
|
165 | - * @return EE_Payment[] |
|
166 | - */ |
|
167 | - public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '') |
|
168 | - { |
|
169 | - $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
170 | - // if $start_date or $end date, verify $format is included. |
|
171 | - if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) { |
|
172 | - throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string. The format string is needed for setting up the query', 'event_espresso')); |
|
173 | - } |
|
174 | - $now = new DateTime('now'); |
|
175 | - // setup timezone objects once |
|
176 | - $modelDateTimeZone = new DateTimeZone($this->_timezone); |
|
177 | - $passedDateTimeZone = new DateTimeZone($timezone); |
|
178 | - // setup start date |
|
179 | - $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now; |
|
180 | - EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone); |
|
181 | - $start_date = $start_date->format('Y-m-d') . ' 00:00:00'; |
|
182 | - $start_date = strtotime($start_date); |
|
183 | - // setup end date |
|
184 | - $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now; |
|
185 | - EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone); |
|
186 | - $end_date = $end_date->format('Y-m-d') . ' 23:59:59'; |
|
187 | - $end_date = strtotime($end_date); |
|
188 | - |
|
189 | - // make sure our start date is the lowest value and vice versa |
|
190 | - $start = min($start_date, $end_date); |
|
191 | - $end = max($start_date, $end_date); |
|
192 | - |
|
193 | - // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model. |
|
194 | - $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone()); |
|
195 | - $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone()); |
|
196 | - |
|
197 | - return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date)))); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * methods for EEMI_Payment |
|
202 | - */ |
|
203 | - /** |
|
204 | - * returns a string for the approved status |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function approved_status() |
|
208 | - { |
|
209 | - return self::status_id_approved; |
|
210 | - } |
|
211 | - /** |
|
212 | - * returns a string for the pending status |
|
213 | - * @return string |
|
214 | - */ |
|
215 | - public function pending_status() |
|
216 | - { |
|
217 | - return self::status_id_pending; |
|
218 | - } |
|
219 | - /** |
|
220 | - * returns a string for the cancelled status |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - public function cancelled_status() |
|
224 | - { |
|
225 | - return self::status_id_cancelled; |
|
226 | - } |
|
227 | - /** |
|
228 | - * returns a string for the failed status |
|
229 | - * @return string |
|
230 | - */ |
|
231 | - public function failed_status() |
|
232 | - { |
|
233 | - return self::status_id_failed; |
|
234 | - } |
|
235 | - /** |
|
236 | - * returns a string for the declined status |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - public function declined_status() |
|
240 | - { |
|
241 | - return self::status_id_declined; |
|
242 | - } |
|
20 | + * Status id in esp_status table that represents an approved payment |
|
21 | + */ |
|
22 | + const status_id_approved = 'PAP'; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Status id in esp_status table that represents a pending payment |
|
27 | + */ |
|
28 | + const status_id_pending = 'PPN'; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Status id in esp_status table that represents a cancelled payment (eg, the |
|
33 | + * user went to PayPal, but on the paypal site decided to cancel the payment) |
|
34 | + */ |
|
35 | + const status_id_cancelled = 'PCN'; |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Status id in esp_status table that represents a payment that was declined by |
|
41 | + * the gateway. (eg, the user's card had no funds, or it was a fraudulent card) |
|
42 | + */ |
|
43 | + const status_id_declined = 'PDC'; |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Status id in esp_status table that represents a payment that failed for technical reasons. |
|
49 | + * (Eg, there was some error in communicating with the payment gateway.) |
|
50 | + */ |
|
51 | + const status_id_failed = 'PFL'; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
56 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
57 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
58 | + * timezone in the 'timezone_string' wp option) |
|
59 | + * @throws ReflectionException |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + protected function __construct($timezone) |
|
63 | + { |
|
64 | + $this->singular_item = esc_html__('Payment', 'event_espresso'); |
|
65 | + $this->plural_item = esc_html__('Payments', 'event_espresso'); |
|
66 | + |
|
67 | + $this->_tables = array( |
|
68 | + 'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID') |
|
69 | + ); |
|
70 | + $this->_fields = array( |
|
71 | + 'Payment' => array( |
|
72 | + 'PAY_ID' => new EE_Primary_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso')), |
|
73 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso'), false, 0, 'Transaction'), |
|
74 | + 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'), |
|
75 | + 'PAY_timestamp' => new EE_Datetime_Field('PAY_timestamp', esc_html__('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
76 | + 'PAY_source' => new EE_All_Caps_Text_Field('PAY_source', esc_html__('User-friendly description of payment', 'event_espresso'), false, 'CART'), |
|
77 | + 'PAY_amount' => new EE_Money_Field('PAY_amount', esc_html__('Amount Payment should be for', 'event_espresso'), false, 0), |
|
78 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'), |
|
79 | + 'PAY_gateway_response' => new EE_Plain_Text_Field('PAY_gateway_response', esc_html__('Response from Gateway about the payment', 'event_espresso'), false, ''), |
|
80 | + 'PAY_txn_id_chq_nmbr' => new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''), |
|
81 | + 'PAY_po_number' => new EE_Plain_Text_Field('PAY_po_number', esc_html__('Purchase or Sales Number', 'event_espresso'), true, ''), |
|
82 | + 'PAY_extra_accntng' => new EE_Simple_HTML_Field('PAY_extra_accntng', esc_html__('Extra Account Info', 'event_espresso'), true, ''), |
|
83 | + 'PAY_details' => new EE_Serialized_Text_Field('PAY_details', esc_html__('Full Gateway response about payment', 'event_espresso'), true, ''), |
|
84 | + 'PAY_redirect_url' => new EE_Plain_Text_Field('PAY_redirect_url', esc_html__("Redirect URL", 'event_espresso'), true), |
|
85 | + 'PAY_redirect_args' => new EE_Serialized_Text_Field('PAY_redirect_args', esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'), true) |
|
86 | + ) |
|
87 | + ); |
|
88 | + $this->_model_relations = array( |
|
89 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
90 | + 'Status' => new EE_Belongs_To_Relation(), |
|
91 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
92 | + 'Registration_Payment' => new EE_Has_Many_Relation(), |
|
93 | + 'Registration' => new EE_HABTM_Relation('Registration_Payment'), |
|
94 | + ); |
|
95 | + $this->_model_chain_to_wp_user = 'Payment_Method'; |
|
96 | + $this->_caps_slug = 'transactions'; |
|
97 | + parent::__construct($timezone); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned |
|
105 | + * to the payment. This is handy for verifying an IPN hasn't already been processed. |
|
106 | + * @param string $PAY_txn_id_chq_nmbr |
|
107 | + * @return EE_Payment |
|
108 | + */ |
|
109 | + public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr) |
|
110 | + { |
|
111 | + return $this->get_one(array(array('PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr))); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * retrieve all payments from db for a particular transaction, optionally with |
|
119 | + * a particular status |
|
120 | + * |
|
121 | + * @access public |
|
122 | + * @param $TXN_ID |
|
123 | + * @param string $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status |
|
124 | + * @return EE_Payment[] |
|
125 | + */ |
|
126 | + public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null) |
|
127 | + { |
|
128 | + // all payments for a TXN ordered chronologically |
|
129 | + $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' )); |
|
130 | + // if provided with a status, search specifically for that status. Otherwise get them all |
|
131 | + if ($status_of_payment) { |
|
132 | + $query_params[0]['STS_ID'] = $status_of_payment; |
|
133 | + } |
|
134 | + // retrieve payments |
|
135 | + return $this->get_all($query_params); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Only gets payments which have been approved |
|
142 | + * @param int $TXN_ID |
|
143 | + * @return EE_Payment[] |
|
144 | + */ |
|
145 | + public function get_approved_payments_for_transaction($TXN_ID = 0) |
|
146 | + { |
|
147 | + return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * retrieve all payments from db between two dates, |
|
156 | + * |
|
157 | + * @param string $start_date incoming start date. If empty the beginning of today is used. |
|
158 | + * @param string $end_date incoming end date. If empty the end of today is used. |
|
159 | + * @param string $format If you include $start_date or $end_date then you must include the format string |
|
160 | + * for the format your date is in. |
|
161 | + * @param string $timezone If your range is in a different timezone then the current setting on this |
|
162 | + * WordPress install, then include it here. |
|
163 | + * @throws EE_Error |
|
164 | + * |
|
165 | + * @return EE_Payment[] |
|
166 | + */ |
|
167 | + public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '') |
|
168 | + { |
|
169 | + $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
170 | + // if $start_date or $end date, verify $format is included. |
|
171 | + if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) { |
|
172 | + throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string. The format string is needed for setting up the query', 'event_espresso')); |
|
173 | + } |
|
174 | + $now = new DateTime('now'); |
|
175 | + // setup timezone objects once |
|
176 | + $modelDateTimeZone = new DateTimeZone($this->_timezone); |
|
177 | + $passedDateTimeZone = new DateTimeZone($timezone); |
|
178 | + // setup start date |
|
179 | + $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now; |
|
180 | + EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone); |
|
181 | + $start_date = $start_date->format('Y-m-d') . ' 00:00:00'; |
|
182 | + $start_date = strtotime($start_date); |
|
183 | + // setup end date |
|
184 | + $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now; |
|
185 | + EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone); |
|
186 | + $end_date = $end_date->format('Y-m-d') . ' 23:59:59'; |
|
187 | + $end_date = strtotime($end_date); |
|
188 | + |
|
189 | + // make sure our start date is the lowest value and vice versa |
|
190 | + $start = min($start_date, $end_date); |
|
191 | + $end = max($start_date, $end_date); |
|
192 | + |
|
193 | + // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model. |
|
194 | + $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone()); |
|
195 | + $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone()); |
|
196 | + |
|
197 | + return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date)))); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * methods for EEMI_Payment |
|
202 | + */ |
|
203 | + /** |
|
204 | + * returns a string for the approved status |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public function approved_status() |
|
208 | + { |
|
209 | + return self::status_id_approved; |
|
210 | + } |
|
211 | + /** |
|
212 | + * returns a string for the pending status |
|
213 | + * @return string |
|
214 | + */ |
|
215 | + public function pending_status() |
|
216 | + { |
|
217 | + return self::status_id_pending; |
|
218 | + } |
|
219 | + /** |
|
220 | + * returns a string for the cancelled status |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + public function cancelled_status() |
|
224 | + { |
|
225 | + return self::status_id_cancelled; |
|
226 | + } |
|
227 | + /** |
|
228 | + * returns a string for the failed status |
|
229 | + * @return string |
|
230 | + */ |
|
231 | + public function failed_status() |
|
232 | + { |
|
233 | + return self::status_id_failed; |
|
234 | + } |
|
235 | + /** |
|
236 | + * returns a string for the declined status |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + public function declined_status() |
|
240 | + { |
|
241 | + return self::status_id_declined; |
|
242 | + } |
|
243 | 243 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | public static function instance($registration_query_params = array()) |
54 | 54 | { |
55 | 55 | // check if class object is instantiated |
56 | - if (! self::$_instance instanceof EE_Transaction_Processor) { |
|
56 | + if ( ! self::$_instance instanceof EE_Transaction_Processor) { |
|
57 | 57 | self::$_instance = new self($registration_query_params); |
58 | 58 | } |
59 | 59 | return self::$_instance; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | // these reg statuses should not be considered in any calculations involving monies owing |
312 | 312 | $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
313 | 313 | : EEM_Registration::closed_reg_statuses(); |
314 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
314 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
315 | 315 | return false; |
316 | 316 | } |
317 | 317 | try { |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | public function get_transaction_for_registration(EE_Registration $registration) |
366 | 366 | { |
367 | 367 | $transaction = $registration->transaction(); |
368 | - if (! $transaction instanceof EE_Transaction) { |
|
368 | + if ( ! $transaction instanceof EE_Transaction) { |
|
369 | 369 | throw new EE_Error( |
370 | 370 | sprintf( |
371 | 371 | esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'), |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | $transaction->ID(), |
396 | 396 | $registration->ticket_ID() |
397 | 397 | ); |
398 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
398 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
399 | 399 | throw new EE_Error( |
400 | 400 | sprintf( |
401 | 401 | esc_html__( |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | /** @type EE_Registration_Processor $registration_processor */ |
480 | 480 | $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
481 | 481 | // check that method exists |
482 | - if (! method_exists($registration_processor, $method_name)) { |
|
482 | + if ( ! method_exists($registration_processor, $method_name)) { |
|
483 | 483 | throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso')); |
484 | 484 | } |
485 | 485 | // make sure some query params are set for retrieving registrations |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | $transaction, |
538 | 538 | EEM_Payment_Method::scope_cart |
539 | 539 | ); |
540 | - if (! empty($available_payment_methods)) { |
|
540 | + if ( ! empty($available_payment_methods)) { |
|
541 | 541 | $PMD_ID = 0; |
542 | 542 | foreach ($available_payment_methods as $available_payment_method) { |
543 | 543 | if ( |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | break; |
549 | 549 | } |
550 | 550 | } |
551 | - if (! $PMD_ID) { |
|
551 | + if ( ! $PMD_ID) { |
|
552 | 552 | $first_payment_method = reset($available_payment_methods); |
553 | 553 | if ($first_payment_method instanceof EE_Payment_Method) { |
554 | 554 | $PMD_ID = $first_payment_method->ID(); |
@@ -16,952 +16,952 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Transaction_Processor extends EE_Processor_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * @var EE_Registration_Processor $_instance |
|
21 | - * @access private |
|
22 | - */ |
|
23 | - private static $_instance; |
|
24 | - |
|
25 | - /** |
|
26 | - * array of query WHERE params to use when retrieving cached registrations from a transaction |
|
27 | - * |
|
28 | - * @var array $registration_query_params |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - private $_registration_query_params = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * @deprecated |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $_old_txn_status; |
|
38 | - |
|
39 | - /** |
|
40 | - * @deprecated |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $_new_txn_status; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @singleton method used to instantiate class object |
|
48 | - * @access public |
|
49 | - * @param array $registration_query_params |
|
50 | - * @return EE_Transaction_Processor instance |
|
51 | - */ |
|
52 | - public static function instance($registration_query_params = array()) |
|
53 | - { |
|
54 | - // check if class object is instantiated |
|
55 | - if (! self::$_instance instanceof EE_Transaction_Processor) { |
|
56 | - self::$_instance = new self($registration_query_params); |
|
57 | - } |
|
58 | - return self::$_instance; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @param array $registration_query_params |
|
64 | - */ |
|
65 | - private function __construct($registration_query_params = array()) |
|
66 | - { |
|
67 | - // make sure some query params are set for retrieving registrations |
|
68 | - $this->_set_registration_query_params($registration_query_params); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @access private |
|
74 | - * @param array $registration_query_params |
|
75 | - */ |
|
76 | - private function _set_registration_query_params($registration_query_params) |
|
77 | - { |
|
78 | - $this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params |
|
79 | - : array('order_by' => array('REG_count' => 'ASC')); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * manually_update_registration_statuses |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @param EE_Transaction $transaction |
|
88 | - * @param string $new_reg_status |
|
89 | - * @param array $registration_query_params array of query WHERE params to use |
|
90 | - * when retrieving cached registrations from a transaction |
|
91 | - * @return boolean |
|
92 | - * @throws \EE_Error |
|
93 | - */ |
|
94 | - public function manually_update_registration_statuses( |
|
95 | - EE_Transaction $transaction, |
|
96 | - $new_reg_status = '', |
|
97 | - $registration_query_params = array() |
|
98 | - ) { |
|
99 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
100 | - 'manually_update_registration_status', |
|
101 | - $transaction, |
|
102 | - $registration_query_params, |
|
103 | - $new_reg_status |
|
104 | - ); |
|
105 | - // send messages |
|
106 | - /** @type EE_Registration_Processor $registration_processor */ |
|
107 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
108 | - $registration_processor->trigger_registration_update_notifications( |
|
109 | - $transaction->primary_registration(), |
|
110 | - array('manually_updated' => true) |
|
111 | - ); |
|
112 | - do_action( |
|
113 | - 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
|
114 | - $transaction, |
|
115 | - $status_updates |
|
116 | - ); |
|
117 | - return $status_updates; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * toggle_registration_statuses_for_default_approved_events |
|
123 | - * |
|
124 | - * @access public |
|
125 | - * @param EE_Transaction $transaction |
|
126 | - * @param array $registration_query_params array of query WHERE params to use |
|
127 | - * when retrieving cached registrations from a transaction |
|
128 | - * @return boolean |
|
129 | - * @throws \EE_Error |
|
130 | - */ |
|
131 | - public function toggle_registration_statuses_for_default_approved_events( |
|
132 | - EE_Transaction $transaction, |
|
133 | - $registration_query_params = array() |
|
134 | - ) { |
|
135 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
136 | - 'toggle_registration_status_for_default_approved_events', |
|
137 | - $transaction, |
|
138 | - $registration_query_params |
|
139 | - ); |
|
140 | - do_action( |
|
141 | - 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', |
|
142 | - $transaction, |
|
143 | - $status_updates |
|
144 | - ); |
|
145 | - return $status_updates; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * toggle_registration_statuses_if_no_monies_owing |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param EE_Transaction $transaction |
|
154 | - * @param array $registration_query_params array of query WHERE params to use |
|
155 | - * when retrieving cached registrations from a transaction |
|
156 | - * @return boolean |
|
157 | - * @throws \EE_Error |
|
158 | - */ |
|
159 | - public function toggle_registration_statuses_if_no_monies_owing( |
|
160 | - EE_Transaction $transaction, |
|
161 | - $registration_query_params = array() |
|
162 | - ) { |
|
163 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
164 | - 'toggle_registration_status_if_no_monies_owing', |
|
165 | - $transaction, |
|
166 | - $registration_query_params |
|
167 | - ); |
|
168 | - do_action( |
|
169 | - 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing', |
|
170 | - $transaction, |
|
171 | - $status_updates |
|
172 | - ); |
|
173 | - return $status_updates; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * update_transaction_and_registrations_after_checkout_or_payment |
|
179 | - * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each |
|
180 | - * |
|
181 | - * @param EE_Transaction $transaction |
|
182 | - * @param \EE_Payment | NULL $payment |
|
183 | - * @param array $registration_query_params array of query WHERE params to use |
|
184 | - * when retrieving cached registrations from a transaction |
|
185 | - * @param bool $trigger_notifications whether or not to call |
|
186 | - * \EE_Registration_Processor::trigger_registration_update_notifications() |
|
187 | - * @return array |
|
188 | - * @throws \EE_Error |
|
189 | - */ |
|
190 | - public function update_transaction_and_registrations_after_checkout_or_payment( |
|
191 | - EE_Transaction $transaction, |
|
192 | - $payment = null, |
|
193 | - $registration_query_params = array(), |
|
194 | - $trigger_notifications = true |
|
195 | - ) { |
|
196 | - // make sure some query params are set for retrieving registrations |
|
197 | - $this->_set_registration_query_params($registration_query_params); |
|
198 | - // get final reg step status |
|
199 | - $finalized = $transaction->final_reg_step_completed(); |
|
200 | - // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
201 | - // but has not yet been fully completed (TRUE) |
|
202 | - if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
203 | - $transaction->set_reg_step_completed('finalize_registration'); |
|
204 | - $finalized = true; |
|
205 | - } |
|
206 | - $transaction->save(); |
|
207 | - // array of details to aid in decision making by systems |
|
208 | - $update_params = array( |
|
209 | - 'old_txn_status' => $transaction->old_txn_status(), |
|
210 | - 'new_txn_status' => $transaction->status_ID(), |
|
211 | - 'finalized' => $finalized, |
|
212 | - 'revisit' => $this->_revisit, |
|
213 | - 'payment_updates' => $payment instanceof EE_Payment ? true : false, |
|
214 | - 'last_payment' => $payment, |
|
215 | - ); |
|
216 | - // now update the registrations and add the results to our $update_params |
|
217 | - $update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor( |
|
218 | - 'update_registration_after_checkout_or_payment', |
|
219 | - $transaction, |
|
220 | - $this->_registration_query_params, |
|
221 | - $update_params |
|
222 | - ); |
|
223 | - if ($trigger_notifications) { |
|
224 | - // send messages |
|
225 | - /** @type EE_Registration_Processor $registration_processor */ |
|
226 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
227 | - $registration_processor->trigger_registration_update_notifications( |
|
228 | - $transaction->primary_registration(), |
|
229 | - $update_params |
|
230 | - ); |
|
231 | - } |
|
232 | - do_action( |
|
233 | - 'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment', |
|
234 | - $transaction, |
|
235 | - $update_params |
|
236 | - ); |
|
237 | - return $update_params; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * update_transaction_after_registration_reopened |
|
243 | - * readjusts TXN and Line Item totals after a registration is changed from |
|
244 | - * cancelled or declined to another reg status such as pending payment or approved |
|
245 | - * |
|
246 | - * @param \EE_Registration $registration |
|
247 | - * @param array $closed_reg_statuses |
|
248 | - * @param bool $update_txn |
|
249 | - * @return bool |
|
250 | - * @throws \EE_Error |
|
251 | - */ |
|
252 | - public function update_transaction_after_reinstating_canceled_registration( |
|
253 | - EE_Registration $registration, |
|
254 | - $closed_reg_statuses = array(), |
|
255 | - $update_txn = true |
|
256 | - ) { |
|
257 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
258 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
259 | - : EEM_Registration::closed_reg_statuses(); |
|
260 | - if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
261 | - return false; |
|
262 | - } |
|
263 | - try { |
|
264 | - $transaction = $this->get_transaction_for_registration($registration); |
|
265 | - $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( |
|
266 | - $transaction, |
|
267 | - $registration |
|
268 | - ); |
|
269 | - // un-cancel the ticket |
|
270 | - $success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item); |
|
271 | - } catch (EE_Error $e) { |
|
272 | - EE_Error::add_error( |
|
273 | - sprintf( |
|
274 | - esc_html__( |
|
275 | - 'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', |
|
276 | - 'event_espresso' |
|
277 | - ), |
|
278 | - $registration->ID(), |
|
279 | - '<br />', |
|
280 | - $e->getMessage() |
|
281 | - ), |
|
282 | - __FILE__, |
|
283 | - __FUNCTION__, |
|
284 | - __LINE__ |
|
285 | - ); |
|
286 | - return false; |
|
287 | - } |
|
288 | - if ($update_txn) { |
|
289 | - return $transaction->save() ? $success : false; |
|
290 | - } |
|
291 | - return $success; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * update_transaction_after_canceled_or_declined_registration |
|
297 | - * readjusts TXN and Line Item totals after a registration is cancelled or declined |
|
298 | - * |
|
299 | - * @param \EE_Registration $registration |
|
300 | - * @param array $closed_reg_statuses |
|
301 | - * @param bool $update_txn |
|
302 | - * @return bool |
|
303 | - * @throws \EE_Error |
|
304 | - */ |
|
305 | - public function update_transaction_after_canceled_or_declined_registration( |
|
306 | - EE_Registration $registration, |
|
307 | - $closed_reg_statuses = array(), |
|
308 | - $update_txn = true |
|
309 | - ) { |
|
310 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
311 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
312 | - : EEM_Registration::closed_reg_statuses(); |
|
313 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
314 | - return false; |
|
315 | - } |
|
316 | - try { |
|
317 | - $transaction = $this->get_transaction_for_registration($registration); |
|
318 | - if ( |
|
319 | - apply_filters( |
|
320 | - 'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item', |
|
321 | - true, |
|
322 | - $registration, |
|
323 | - $transaction |
|
324 | - ) |
|
325 | - ) { |
|
326 | - $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( |
|
327 | - $transaction, |
|
328 | - $registration |
|
329 | - ); |
|
330 | - EEH_Line_Item::cancel_ticket_line_item($ticket_line_item); |
|
331 | - } |
|
332 | - } catch (EE_Error $e) { |
|
333 | - EE_Error::add_error( |
|
334 | - sprintf( |
|
335 | - esc_html__( |
|
336 | - 'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', |
|
337 | - 'event_espresso' |
|
338 | - ), |
|
339 | - $registration->ID(), |
|
340 | - '<br />', |
|
341 | - $e->getMessage() |
|
342 | - ), |
|
343 | - __FILE__, |
|
344 | - __FUNCTION__, |
|
345 | - __LINE__ |
|
346 | - ); |
|
347 | - return false; |
|
348 | - } |
|
349 | - if ($update_txn) { |
|
350 | - return $transaction->save() ? true : false; |
|
351 | - } |
|
352 | - return true; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * get_transaction_for_registration |
|
358 | - * |
|
359 | - * @access public |
|
360 | - * @param EE_Registration $registration |
|
361 | - * @return EE_Transaction |
|
362 | - * @throws EE_Error |
|
363 | - */ |
|
364 | - public function get_transaction_for_registration(EE_Registration $registration) |
|
365 | - { |
|
366 | - $transaction = $registration->transaction(); |
|
367 | - if (! $transaction instanceof EE_Transaction) { |
|
368 | - throw new EE_Error( |
|
369 | - sprintf( |
|
370 | - esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'), |
|
371 | - $registration->ID() |
|
372 | - ) |
|
373 | - ); |
|
374 | - } |
|
375 | - return $transaction; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * get_ticket_line_item_for_transaction_registration |
|
381 | - * |
|
382 | - * @access public |
|
383 | - * @param EE_Transaction $transaction |
|
384 | - * @param EE_Registration $registration |
|
385 | - * @return EE_Line_Item |
|
386 | - * @throws EE_Error |
|
387 | - */ |
|
388 | - public function get_ticket_line_item_for_transaction_registration( |
|
389 | - EE_Transaction $transaction, |
|
390 | - EE_Registration $registration |
|
391 | - ) { |
|
392 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
393 | - $ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction( |
|
394 | - $transaction->ID(), |
|
395 | - $registration->ticket_ID() |
|
396 | - ); |
|
397 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
398 | - throw new EE_Error( |
|
399 | - sprintf( |
|
400 | - esc_html__( |
|
401 | - 'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.', |
|
402 | - 'event_espresso' |
|
403 | - ), |
|
404 | - $transaction->ID(), |
|
405 | - $registration->ticket_ID() |
|
406 | - ) |
|
407 | - ); |
|
408 | - } |
|
409 | - return $ticket_line_item; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * cancel_transaction_if_all_registrations_canceled |
|
415 | - * cycles thru related registrations and checks their statuses |
|
416 | - * if ALL registrations are Cancelled or Declined, then this sets the TXN status to |
|
417 | - * |
|
418 | - * @access public |
|
419 | - * @param EE_Transaction $transaction |
|
420 | - * @param string $new_TXN_status |
|
421 | - * @param array $registration_query_params - array of query WHERE params to use when |
|
422 | - * retrieving cached registrations from a transaction |
|
423 | - * @param array $closed_reg_statuses |
|
424 | - * @param bool $update_txn |
|
425 | - * @return bool true if TXN status was updated, false if not |
|
426 | - */ |
|
427 | - public function toggle_transaction_status_if_all_registrations_canceled_or_declined( |
|
428 | - EE_Transaction $transaction, |
|
429 | - $new_TXN_status = '', |
|
430 | - $registration_query_params = array(), |
|
431 | - $closed_reg_statuses = array(), |
|
432 | - $update_txn = true |
|
433 | - ) { |
|
434 | - // make sure some query params are set for retrieving registrations |
|
435 | - $this->_set_registration_query_params($registration_query_params); |
|
436 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
437 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
438 | - : EEM_Registration::closed_reg_statuses(); |
|
439 | - // loop through cached registrations |
|
440 | - foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
441 | - if ( |
|
442 | - $registration instanceof EE_Registration |
|
443 | - && ! in_array($registration->status_ID(), $closed_reg_statuses) |
|
444 | - ) { |
|
445 | - return false; |
|
446 | - } |
|
447 | - } |
|
448 | - if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) { |
|
449 | - $transaction->set_status($new_TXN_status); |
|
450 | - } |
|
451 | - if ($update_txn) { |
|
452 | - return $transaction->save() ? true : false; |
|
453 | - } |
|
454 | - return true; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * _call_method_on_registrations_via_Registration_Processor |
|
460 | - * cycles thru related registrations and calls the requested method on each |
|
461 | - * |
|
462 | - * @access private |
|
463 | - * @param string $method_name |
|
464 | - * @param EE_Transaction $transaction |
|
465 | - * @param array $registration_query_params array of query WHERE params to use |
|
466 | - * when retrieving cached registrations from a transaction |
|
467 | - * @param string $additional_param |
|
468 | - * @throws \EE_Error |
|
469 | - * @return boolean |
|
470 | - */ |
|
471 | - private function _call_method_on_registrations_via_Registration_Processor( |
|
472 | - $method_name, |
|
473 | - EE_Transaction $transaction, |
|
474 | - $registration_query_params = array(), |
|
475 | - $additional_param = null |
|
476 | - ) { |
|
477 | - $response = false; |
|
478 | - /** @type EE_Registration_Processor $registration_processor */ |
|
479 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
480 | - // check that method exists |
|
481 | - if (! method_exists($registration_processor, $method_name)) { |
|
482 | - throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso')); |
|
483 | - } |
|
484 | - // make sure some query params are set for retrieving registrations |
|
485 | - $this->_set_registration_query_params($registration_query_params); |
|
486 | - // loop through cached registrations |
|
487 | - foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
488 | - if ($registration instanceof EE_Registration) { |
|
489 | - if ($additional_param) { |
|
490 | - $response = $registration_processor->{$method_name}($registration, $additional_param) |
|
491 | - ? true |
|
492 | - : $response; |
|
493 | - } else { |
|
494 | - $response = $registration_processor->{$method_name}($registration) |
|
495 | - ? true |
|
496 | - : $response; |
|
497 | - } |
|
498 | - } |
|
499 | - } |
|
500 | - return $response; |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * set_transaction_payment_method_based_on_registration_statuses |
|
506 | - * sets or unsets the PMD_ID field on the TXN based on the related REG statuses |
|
507 | - * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null, |
|
508 | - * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either: |
|
509 | - * the first "default" Payment Method |
|
510 | - * the first active Payment Method |
|
511 | - * whichever is found first. |
|
512 | - * |
|
513 | - * @param EE_Registration $edited_registration |
|
514 | - * @return void |
|
515 | - * @throws \EE_Error |
|
516 | - */ |
|
517 | - public function set_transaction_payment_method_based_on_registration_statuses( |
|
518 | - EE_Registration $edited_registration |
|
519 | - ) { |
|
520 | - if ($edited_registration instanceof EE_Registration) { |
|
521 | - $transaction = $edited_registration->transaction(); |
|
522 | - if ($transaction instanceof EE_Transaction) { |
|
523 | - $all_not_approved = true; |
|
524 | - foreach ($transaction->registrations() as $registration) { |
|
525 | - if ($registration instanceof EE_Registration) { |
|
526 | - // if any REG != "Not Approved" then toggle to false |
|
527 | - $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false; |
|
528 | - } |
|
529 | - } |
|
530 | - // if ALL Registrations are "Not Approved" |
|
531 | - if ($all_not_approved) { |
|
532 | - $transaction->set_payment_method_ID(null); |
|
533 | - $transaction->save(); |
|
534 | - } else { |
|
535 | - $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
536 | - $transaction, |
|
537 | - EEM_Payment_Method::scope_cart |
|
538 | - ); |
|
539 | - if (! empty($available_payment_methods)) { |
|
540 | - $PMD_ID = 0; |
|
541 | - foreach ($available_payment_methods as $available_payment_method) { |
|
542 | - if ( |
|
543 | - $available_payment_method instanceof EE_Payment_Method |
|
544 | - && $available_payment_method->open_by_default() |
|
545 | - ) { |
|
546 | - $PMD_ID = $available_payment_method->ID(); |
|
547 | - break; |
|
548 | - } |
|
549 | - } |
|
550 | - if (! $PMD_ID) { |
|
551 | - $first_payment_method = reset($available_payment_methods); |
|
552 | - if ($first_payment_method instanceof EE_Payment_Method) { |
|
553 | - $PMD_ID = $first_payment_method->ID(); |
|
554 | - } else { |
|
555 | - EE_Error::add_error( |
|
556 | - esc_html__( |
|
557 | - 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', |
|
558 | - 'event_espresso' |
|
559 | - ), |
|
560 | - __FILE__, |
|
561 | - __LINE__, |
|
562 | - __FUNCTION__ |
|
563 | - ); |
|
564 | - } |
|
565 | - } |
|
566 | - $transaction->set_payment_method_ID($PMD_ID); |
|
567 | - $transaction->save(); |
|
568 | - } else { |
|
569 | - EE_Error::add_error( |
|
570 | - esc_html__( |
|
571 | - 'Please activate at least one Payment Method in order for things to operate correctly.', |
|
572 | - 'event_espresso' |
|
573 | - ), |
|
574 | - __FILE__, |
|
575 | - __LINE__, |
|
576 | - __FUNCTION__ |
|
577 | - ); |
|
578 | - } |
|
579 | - } |
|
580 | - } |
|
581 | - } |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - |
|
586 | - /********************************** DEPRECATED METHODS **********************************/ |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * @deprecated 4.9.12 |
|
591 | - * @return string |
|
592 | - */ |
|
593 | - public function old_txn_status() |
|
594 | - { |
|
595 | - EE_Error::doing_it_wrong( |
|
596 | - __METHOD__, |
|
597 | - esc_html__( |
|
598 | - 'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.', |
|
599 | - 'event_espresso' |
|
600 | - ), |
|
601 | - '4.9.12' |
|
602 | - ); |
|
603 | - return $this->_old_txn_status; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * @deprecated 4.9.12 |
|
609 | - * @param string $old_txn_status |
|
610 | - */ |
|
611 | - public function set_old_txn_status($old_txn_status) |
|
612 | - { |
|
613 | - EE_Error::doing_it_wrong( |
|
614 | - __METHOD__, |
|
615 | - esc_html__( |
|
616 | - 'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.', |
|
617 | - 'event_espresso' |
|
618 | - ), |
|
619 | - '4.9.12' |
|
620 | - ); |
|
621 | - // only set the first time |
|
622 | - if ($this->_old_txn_status === null) { |
|
623 | - $this->_old_txn_status = $old_txn_status; |
|
624 | - } |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * @deprecated 4.9.12 |
|
630 | - * @return string |
|
631 | - */ |
|
632 | - public function new_txn_status() |
|
633 | - { |
|
634 | - EE_Error::doing_it_wrong( |
|
635 | - __METHOD__, |
|
636 | - esc_html__( |
|
637 | - 'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.', |
|
638 | - 'event_espresso' |
|
639 | - ), |
|
640 | - '4.9.12' |
|
641 | - ); |
|
642 | - return $this->_new_txn_status; |
|
643 | - } |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * @deprecated 4.9.12 |
|
648 | - * @param string $new_txn_status |
|
649 | - */ |
|
650 | - public function set_new_txn_status($new_txn_status) |
|
651 | - { |
|
652 | - EE_Error::doing_it_wrong( |
|
653 | - __METHOD__, |
|
654 | - esc_html__( |
|
655 | - 'This logic has been removed. Please just use \EE_Transaction::set_status() instead.', |
|
656 | - 'event_espresso' |
|
657 | - ), |
|
658 | - '4.9.12' |
|
659 | - ); |
|
660 | - $this->_new_txn_status = $new_txn_status; |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * reg_status_updated |
|
666 | - * |
|
667 | - * @deprecated 4.9.12 |
|
668 | - * @return bool |
|
669 | - */ |
|
670 | - public function txn_status_updated() |
|
671 | - { |
|
672 | - EE_Error::doing_it_wrong( |
|
673 | - __METHOD__, |
|
674 | - esc_html__( |
|
675 | - 'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.', |
|
676 | - 'event_espresso' |
|
677 | - ), |
|
678 | - '4.9.12' |
|
679 | - ); |
|
680 | - return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false; |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * all_reg_steps_completed |
|
686 | - * returns: |
|
687 | - * true if ALL reg steps have been marked as completed |
|
688 | - * or false if any step is not completed |
|
689 | - * |
|
690 | - * @deprecated 4.9.12 |
|
691 | - * @param EE_Transaction $transaction |
|
692 | - * @return boolean |
|
693 | - */ |
|
694 | - public function all_reg_steps_completed(EE_Transaction $transaction) |
|
695 | - { |
|
696 | - EE_Error::doing_it_wrong( |
|
697 | - __METHOD__, |
|
698 | - esc_html__( |
|
699 | - 'This logic has been moved into \EE_Transaction::all_reg_steps_completed(), please use that method instead.', |
|
700 | - 'event_espresso' |
|
701 | - ), |
|
702 | - '4.9.12', |
|
703 | - '5.0.0' |
|
704 | - ); |
|
705 | - return $transaction->all_reg_steps_completed(); |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * all_reg_steps_completed_except |
|
711 | - * returns: |
|
712 | - * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
713 | - * or false if any other step is not completed |
|
714 | - * or false if ALL steps are completed including the exception you are testing !!! |
|
715 | - * |
|
716 | - * @deprecated 4.9.12 |
|
717 | - * @param EE_Transaction $transaction |
|
718 | - * @param string $exception |
|
719 | - * @return boolean |
|
720 | - */ |
|
721 | - public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '') |
|
722 | - { |
|
723 | - EE_Error::doing_it_wrong( |
|
724 | - __METHOD__, |
|
725 | - esc_html__( |
|
726 | - 'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except(), please use that method instead.', |
|
727 | - 'event_espresso' |
|
728 | - ), |
|
729 | - '4.9.12', |
|
730 | - '5.0.0' |
|
731 | - ); |
|
732 | - return $transaction->all_reg_steps_completed_except($exception); |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * all_reg_steps_completed_except |
|
738 | - * returns: |
|
739 | - * true if ALL reg steps, except the final step, have been marked as completed |
|
740 | - * or false if any step is not completed |
|
741 | - * or false if ALL steps are completed including the final step !!! |
|
742 | - * |
|
743 | - * @deprecated 4.9.12 |
|
744 | - * @param EE_Transaction $transaction |
|
745 | - * @return boolean |
|
746 | - */ |
|
747 | - public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction) |
|
748 | - { |
|
749 | - EE_Error::doing_it_wrong( |
|
750 | - __METHOD__, |
|
751 | - esc_html__( |
|
752 | - 'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except_final_step(), please use that method instead.', |
|
753 | - 'event_espresso' |
|
754 | - ), |
|
755 | - '4.9.12', |
|
756 | - '5.0.0' |
|
757 | - ); |
|
758 | - return $transaction->all_reg_steps_completed_except_final_step(); |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * reg_step_completed |
|
764 | - * returns: |
|
765 | - * true if a specific reg step has been marked as completed |
|
766 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
767 | - * or false if it has not yet been initialized |
|
768 | - * |
|
769 | - * @deprecated 4.9.12 |
|
770 | - * @param EE_Transaction $transaction |
|
771 | - * @param string $reg_step_slug |
|
772 | - * @return boolean | int |
|
773 | - */ |
|
774 | - public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug) |
|
775 | - { |
|
776 | - EE_Error::doing_it_wrong( |
|
777 | - __METHOD__, |
|
778 | - esc_html__( |
|
779 | - 'This logic has been moved into \EE_Transaction::reg_step_completed(), please use that method instead.', |
|
780 | - 'event_espresso' |
|
781 | - ), |
|
782 | - '4.9.12', |
|
783 | - '5.0.0' |
|
784 | - ); |
|
785 | - return $transaction->reg_step_completed($reg_step_slug); |
|
786 | - } |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * completed_final_reg_step |
|
791 | - * returns: |
|
792 | - * true if the finalize_registration reg step has been marked as completed |
|
793 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
794 | - * or false if it has not yet been initialized |
|
795 | - * |
|
796 | - * @deprecated 4.9.12 |
|
797 | - * @param EE_Transaction $transaction |
|
798 | - * @return boolean | int |
|
799 | - */ |
|
800 | - public function final_reg_step_completed(EE_Transaction $transaction) |
|
801 | - { |
|
802 | - EE_Error::doing_it_wrong( |
|
803 | - __METHOD__, |
|
804 | - esc_html__( |
|
805 | - 'This logic has been moved into \EE_Transaction::final_reg_step_completed(), please use that method instead.', |
|
806 | - 'event_espresso' |
|
807 | - ), |
|
808 | - '4.9.12', |
|
809 | - '5.0.0' |
|
810 | - ); |
|
811 | - return $transaction->final_reg_step_completed(); |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - /** |
|
816 | - * set_reg_step_initiated |
|
817 | - * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
818 | - * |
|
819 | - * @deprecated 4.9.12 |
|
820 | - * @access public |
|
821 | - * @param \EE_Transaction $transaction |
|
822 | - * @param string $reg_step_slug |
|
823 | - * @return boolean |
|
824 | - * @throws \EE_Error |
|
825 | - */ |
|
826 | - public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug) |
|
827 | - { |
|
828 | - EE_Error::doing_it_wrong( |
|
829 | - __METHOD__, |
|
830 | - esc_html__( |
|
831 | - 'This logic has been moved into \EE_Transaction::set_reg_step_initiated(), please use that method instead.', |
|
832 | - 'event_espresso' |
|
833 | - ), |
|
834 | - '4.9.12', |
|
835 | - '5.0.0' |
|
836 | - ); |
|
837 | - return $transaction->set_reg_step_initiated($reg_step_slug); |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * set_reg_step_completed |
|
843 | - * given a valid TXN_reg_step, this sets the step as completed |
|
844 | - * |
|
845 | - * @deprecated 4.9.12 |
|
846 | - * @access public |
|
847 | - * @param \EE_Transaction $transaction |
|
848 | - * @param string $reg_step_slug |
|
849 | - * @return boolean |
|
850 | - * @throws \EE_Error |
|
851 | - */ |
|
852 | - public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug) |
|
853 | - { |
|
854 | - EE_Error::doing_it_wrong( |
|
855 | - __METHOD__, |
|
856 | - esc_html__( |
|
857 | - 'This logic has been moved into \EE_Transaction::set_reg_step_completed(), please use that method instead.', |
|
858 | - 'event_espresso' |
|
859 | - ), |
|
860 | - '4.9.12', |
|
861 | - '5.0.0' |
|
862 | - ); |
|
863 | - return $transaction->set_reg_step_completed($reg_step_slug); |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * set_reg_step_completed |
|
869 | - * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
870 | - * |
|
871 | - * @deprecated 4.9.12 |
|
872 | - * @access public |
|
873 | - * @param \EE_Transaction $transaction |
|
874 | - * @param string $reg_step_slug |
|
875 | - * @return boolean |
|
876 | - * @throws \EE_Error |
|
877 | - */ |
|
878 | - public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug) |
|
879 | - { |
|
880 | - EE_Error::doing_it_wrong( |
|
881 | - __METHOD__, |
|
882 | - esc_html__( |
|
883 | - 'This logic has been moved into \EE_Transaction::set_reg_step_not_completed(), please use that method instead.', |
|
884 | - 'event_espresso' |
|
885 | - ), |
|
886 | - '4.9.12', |
|
887 | - '5.0.0' |
|
888 | - ); |
|
889 | - return $transaction->set_reg_step_not_completed($reg_step_slug); |
|
890 | - } |
|
891 | - |
|
892 | - |
|
893 | - /** |
|
894 | - * remove_reg_step |
|
895 | - * given a valid TXN_reg_step slug, this will remove (unset) |
|
896 | - * the reg step from the TXN reg step array |
|
897 | - * |
|
898 | - * @deprecated 4.9.12 |
|
899 | - * @access public |
|
900 | - * @param \EE_Transaction $transaction |
|
901 | - * @param string $reg_step_slug |
|
902 | - * @return void |
|
903 | - */ |
|
904 | - public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug) |
|
905 | - { |
|
906 | - EE_Error::doing_it_wrong( |
|
907 | - __METHOD__, |
|
908 | - esc_html__( |
|
909 | - 'This logic has been moved into \EE_Transaction::remove_reg_step(), please use that method instead.', |
|
910 | - 'event_espresso' |
|
911 | - ), |
|
912 | - '4.9.12', |
|
913 | - '5.0.0' |
|
914 | - ); |
|
915 | - $transaction->remove_reg_step($reg_step_slug); |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * toggle_failed_transaction_status |
|
921 | - * upgrades a TXNs status from failed to abandoned, |
|
922 | - * meaning that contact information has been captured for at least one registrant |
|
923 | - * |
|
924 | - * @deprecated 4.9.12 |
|
925 | - * @access public |
|
926 | - * @param EE_Transaction $transaction |
|
927 | - * @return boolean |
|
928 | - * @throws \EE_Error |
|
929 | - */ |
|
930 | - public function toggle_failed_transaction_status(EE_Transaction $transaction) |
|
931 | - { |
|
932 | - EE_Error::doing_it_wrong( |
|
933 | - __METHOD__, |
|
934 | - esc_html__( |
|
935 | - 'This logic has been moved into \EE_Transaction::toggle_failed_transaction_status(), please use that method instead.', |
|
936 | - 'event_espresso' |
|
937 | - ), |
|
938 | - '4.9.12', |
|
939 | - '5.0.0' |
|
940 | - ); |
|
941 | - return $transaction->toggle_failed_transaction_status(); |
|
942 | - } |
|
943 | - |
|
944 | - |
|
945 | - /** |
|
946 | - * toggle_abandoned_transaction_status |
|
947 | - * upgrades a TXNs status from failed or abandoned to incomplete |
|
948 | - * |
|
949 | - * @deprecated 4.9.12 |
|
950 | - * @access public |
|
951 | - * @param EE_Transaction $transaction |
|
952 | - * @return boolean |
|
953 | - */ |
|
954 | - public function toggle_abandoned_transaction_status(EE_Transaction $transaction) |
|
955 | - { |
|
956 | - EE_Error::doing_it_wrong( |
|
957 | - __METHOD__, |
|
958 | - esc_html__( |
|
959 | - 'This logic has been moved into \EE_Transaction::toggle_abandoned_transaction_status(), please use that method instead.', |
|
960 | - 'event_espresso' |
|
961 | - ), |
|
962 | - '4.9.12', |
|
963 | - '5.0.0' |
|
964 | - ); |
|
965 | - return $transaction->toggle_abandoned_transaction_status(); |
|
966 | - } |
|
19 | + /** |
|
20 | + * @var EE_Registration_Processor $_instance |
|
21 | + * @access private |
|
22 | + */ |
|
23 | + private static $_instance; |
|
24 | + |
|
25 | + /** |
|
26 | + * array of query WHERE params to use when retrieving cached registrations from a transaction |
|
27 | + * |
|
28 | + * @var array $registration_query_params |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + private $_registration_query_params = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * @deprecated |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $_old_txn_status; |
|
38 | + |
|
39 | + /** |
|
40 | + * @deprecated |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $_new_txn_status; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @singleton method used to instantiate class object |
|
48 | + * @access public |
|
49 | + * @param array $registration_query_params |
|
50 | + * @return EE_Transaction_Processor instance |
|
51 | + */ |
|
52 | + public static function instance($registration_query_params = array()) |
|
53 | + { |
|
54 | + // check if class object is instantiated |
|
55 | + if (! self::$_instance instanceof EE_Transaction_Processor) { |
|
56 | + self::$_instance = new self($registration_query_params); |
|
57 | + } |
|
58 | + return self::$_instance; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @param array $registration_query_params |
|
64 | + */ |
|
65 | + private function __construct($registration_query_params = array()) |
|
66 | + { |
|
67 | + // make sure some query params are set for retrieving registrations |
|
68 | + $this->_set_registration_query_params($registration_query_params); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @access private |
|
74 | + * @param array $registration_query_params |
|
75 | + */ |
|
76 | + private function _set_registration_query_params($registration_query_params) |
|
77 | + { |
|
78 | + $this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params |
|
79 | + : array('order_by' => array('REG_count' => 'ASC')); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * manually_update_registration_statuses |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @param EE_Transaction $transaction |
|
88 | + * @param string $new_reg_status |
|
89 | + * @param array $registration_query_params array of query WHERE params to use |
|
90 | + * when retrieving cached registrations from a transaction |
|
91 | + * @return boolean |
|
92 | + * @throws \EE_Error |
|
93 | + */ |
|
94 | + public function manually_update_registration_statuses( |
|
95 | + EE_Transaction $transaction, |
|
96 | + $new_reg_status = '', |
|
97 | + $registration_query_params = array() |
|
98 | + ) { |
|
99 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
100 | + 'manually_update_registration_status', |
|
101 | + $transaction, |
|
102 | + $registration_query_params, |
|
103 | + $new_reg_status |
|
104 | + ); |
|
105 | + // send messages |
|
106 | + /** @type EE_Registration_Processor $registration_processor */ |
|
107 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
108 | + $registration_processor->trigger_registration_update_notifications( |
|
109 | + $transaction->primary_registration(), |
|
110 | + array('manually_updated' => true) |
|
111 | + ); |
|
112 | + do_action( |
|
113 | + 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
|
114 | + $transaction, |
|
115 | + $status_updates |
|
116 | + ); |
|
117 | + return $status_updates; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * toggle_registration_statuses_for_default_approved_events |
|
123 | + * |
|
124 | + * @access public |
|
125 | + * @param EE_Transaction $transaction |
|
126 | + * @param array $registration_query_params array of query WHERE params to use |
|
127 | + * when retrieving cached registrations from a transaction |
|
128 | + * @return boolean |
|
129 | + * @throws \EE_Error |
|
130 | + */ |
|
131 | + public function toggle_registration_statuses_for_default_approved_events( |
|
132 | + EE_Transaction $transaction, |
|
133 | + $registration_query_params = array() |
|
134 | + ) { |
|
135 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
136 | + 'toggle_registration_status_for_default_approved_events', |
|
137 | + $transaction, |
|
138 | + $registration_query_params |
|
139 | + ); |
|
140 | + do_action( |
|
141 | + 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', |
|
142 | + $transaction, |
|
143 | + $status_updates |
|
144 | + ); |
|
145 | + return $status_updates; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * toggle_registration_statuses_if_no_monies_owing |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param EE_Transaction $transaction |
|
154 | + * @param array $registration_query_params array of query WHERE params to use |
|
155 | + * when retrieving cached registrations from a transaction |
|
156 | + * @return boolean |
|
157 | + * @throws \EE_Error |
|
158 | + */ |
|
159 | + public function toggle_registration_statuses_if_no_monies_owing( |
|
160 | + EE_Transaction $transaction, |
|
161 | + $registration_query_params = array() |
|
162 | + ) { |
|
163 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
164 | + 'toggle_registration_status_if_no_monies_owing', |
|
165 | + $transaction, |
|
166 | + $registration_query_params |
|
167 | + ); |
|
168 | + do_action( |
|
169 | + 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing', |
|
170 | + $transaction, |
|
171 | + $status_updates |
|
172 | + ); |
|
173 | + return $status_updates; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * update_transaction_and_registrations_after_checkout_or_payment |
|
179 | + * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each |
|
180 | + * |
|
181 | + * @param EE_Transaction $transaction |
|
182 | + * @param \EE_Payment | NULL $payment |
|
183 | + * @param array $registration_query_params array of query WHERE params to use |
|
184 | + * when retrieving cached registrations from a transaction |
|
185 | + * @param bool $trigger_notifications whether or not to call |
|
186 | + * \EE_Registration_Processor::trigger_registration_update_notifications() |
|
187 | + * @return array |
|
188 | + * @throws \EE_Error |
|
189 | + */ |
|
190 | + public function update_transaction_and_registrations_after_checkout_or_payment( |
|
191 | + EE_Transaction $transaction, |
|
192 | + $payment = null, |
|
193 | + $registration_query_params = array(), |
|
194 | + $trigger_notifications = true |
|
195 | + ) { |
|
196 | + // make sure some query params are set for retrieving registrations |
|
197 | + $this->_set_registration_query_params($registration_query_params); |
|
198 | + // get final reg step status |
|
199 | + $finalized = $transaction->final_reg_step_completed(); |
|
200 | + // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
201 | + // but has not yet been fully completed (TRUE) |
|
202 | + if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
203 | + $transaction->set_reg_step_completed('finalize_registration'); |
|
204 | + $finalized = true; |
|
205 | + } |
|
206 | + $transaction->save(); |
|
207 | + // array of details to aid in decision making by systems |
|
208 | + $update_params = array( |
|
209 | + 'old_txn_status' => $transaction->old_txn_status(), |
|
210 | + 'new_txn_status' => $transaction->status_ID(), |
|
211 | + 'finalized' => $finalized, |
|
212 | + 'revisit' => $this->_revisit, |
|
213 | + 'payment_updates' => $payment instanceof EE_Payment ? true : false, |
|
214 | + 'last_payment' => $payment, |
|
215 | + ); |
|
216 | + // now update the registrations and add the results to our $update_params |
|
217 | + $update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor( |
|
218 | + 'update_registration_after_checkout_or_payment', |
|
219 | + $transaction, |
|
220 | + $this->_registration_query_params, |
|
221 | + $update_params |
|
222 | + ); |
|
223 | + if ($trigger_notifications) { |
|
224 | + // send messages |
|
225 | + /** @type EE_Registration_Processor $registration_processor */ |
|
226 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
227 | + $registration_processor->trigger_registration_update_notifications( |
|
228 | + $transaction->primary_registration(), |
|
229 | + $update_params |
|
230 | + ); |
|
231 | + } |
|
232 | + do_action( |
|
233 | + 'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment', |
|
234 | + $transaction, |
|
235 | + $update_params |
|
236 | + ); |
|
237 | + return $update_params; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * update_transaction_after_registration_reopened |
|
243 | + * readjusts TXN and Line Item totals after a registration is changed from |
|
244 | + * cancelled or declined to another reg status such as pending payment or approved |
|
245 | + * |
|
246 | + * @param \EE_Registration $registration |
|
247 | + * @param array $closed_reg_statuses |
|
248 | + * @param bool $update_txn |
|
249 | + * @return bool |
|
250 | + * @throws \EE_Error |
|
251 | + */ |
|
252 | + public function update_transaction_after_reinstating_canceled_registration( |
|
253 | + EE_Registration $registration, |
|
254 | + $closed_reg_statuses = array(), |
|
255 | + $update_txn = true |
|
256 | + ) { |
|
257 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
258 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
259 | + : EEM_Registration::closed_reg_statuses(); |
|
260 | + if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
261 | + return false; |
|
262 | + } |
|
263 | + try { |
|
264 | + $transaction = $this->get_transaction_for_registration($registration); |
|
265 | + $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( |
|
266 | + $transaction, |
|
267 | + $registration |
|
268 | + ); |
|
269 | + // un-cancel the ticket |
|
270 | + $success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item); |
|
271 | + } catch (EE_Error $e) { |
|
272 | + EE_Error::add_error( |
|
273 | + sprintf( |
|
274 | + esc_html__( |
|
275 | + 'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', |
|
276 | + 'event_espresso' |
|
277 | + ), |
|
278 | + $registration->ID(), |
|
279 | + '<br />', |
|
280 | + $e->getMessage() |
|
281 | + ), |
|
282 | + __FILE__, |
|
283 | + __FUNCTION__, |
|
284 | + __LINE__ |
|
285 | + ); |
|
286 | + return false; |
|
287 | + } |
|
288 | + if ($update_txn) { |
|
289 | + return $transaction->save() ? $success : false; |
|
290 | + } |
|
291 | + return $success; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * update_transaction_after_canceled_or_declined_registration |
|
297 | + * readjusts TXN and Line Item totals after a registration is cancelled or declined |
|
298 | + * |
|
299 | + * @param \EE_Registration $registration |
|
300 | + * @param array $closed_reg_statuses |
|
301 | + * @param bool $update_txn |
|
302 | + * @return bool |
|
303 | + * @throws \EE_Error |
|
304 | + */ |
|
305 | + public function update_transaction_after_canceled_or_declined_registration( |
|
306 | + EE_Registration $registration, |
|
307 | + $closed_reg_statuses = array(), |
|
308 | + $update_txn = true |
|
309 | + ) { |
|
310 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
311 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
312 | + : EEM_Registration::closed_reg_statuses(); |
|
313 | + if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
314 | + return false; |
|
315 | + } |
|
316 | + try { |
|
317 | + $transaction = $this->get_transaction_for_registration($registration); |
|
318 | + if ( |
|
319 | + apply_filters( |
|
320 | + 'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item', |
|
321 | + true, |
|
322 | + $registration, |
|
323 | + $transaction |
|
324 | + ) |
|
325 | + ) { |
|
326 | + $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( |
|
327 | + $transaction, |
|
328 | + $registration |
|
329 | + ); |
|
330 | + EEH_Line_Item::cancel_ticket_line_item($ticket_line_item); |
|
331 | + } |
|
332 | + } catch (EE_Error $e) { |
|
333 | + EE_Error::add_error( |
|
334 | + sprintf( |
|
335 | + esc_html__( |
|
336 | + 'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', |
|
337 | + 'event_espresso' |
|
338 | + ), |
|
339 | + $registration->ID(), |
|
340 | + '<br />', |
|
341 | + $e->getMessage() |
|
342 | + ), |
|
343 | + __FILE__, |
|
344 | + __FUNCTION__, |
|
345 | + __LINE__ |
|
346 | + ); |
|
347 | + return false; |
|
348 | + } |
|
349 | + if ($update_txn) { |
|
350 | + return $transaction->save() ? true : false; |
|
351 | + } |
|
352 | + return true; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * get_transaction_for_registration |
|
358 | + * |
|
359 | + * @access public |
|
360 | + * @param EE_Registration $registration |
|
361 | + * @return EE_Transaction |
|
362 | + * @throws EE_Error |
|
363 | + */ |
|
364 | + public function get_transaction_for_registration(EE_Registration $registration) |
|
365 | + { |
|
366 | + $transaction = $registration->transaction(); |
|
367 | + if (! $transaction instanceof EE_Transaction) { |
|
368 | + throw new EE_Error( |
|
369 | + sprintf( |
|
370 | + esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'), |
|
371 | + $registration->ID() |
|
372 | + ) |
|
373 | + ); |
|
374 | + } |
|
375 | + return $transaction; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * get_ticket_line_item_for_transaction_registration |
|
381 | + * |
|
382 | + * @access public |
|
383 | + * @param EE_Transaction $transaction |
|
384 | + * @param EE_Registration $registration |
|
385 | + * @return EE_Line_Item |
|
386 | + * @throws EE_Error |
|
387 | + */ |
|
388 | + public function get_ticket_line_item_for_transaction_registration( |
|
389 | + EE_Transaction $transaction, |
|
390 | + EE_Registration $registration |
|
391 | + ) { |
|
392 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
393 | + $ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction( |
|
394 | + $transaction->ID(), |
|
395 | + $registration->ticket_ID() |
|
396 | + ); |
|
397 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
398 | + throw new EE_Error( |
|
399 | + sprintf( |
|
400 | + esc_html__( |
|
401 | + 'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.', |
|
402 | + 'event_espresso' |
|
403 | + ), |
|
404 | + $transaction->ID(), |
|
405 | + $registration->ticket_ID() |
|
406 | + ) |
|
407 | + ); |
|
408 | + } |
|
409 | + return $ticket_line_item; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * cancel_transaction_if_all_registrations_canceled |
|
415 | + * cycles thru related registrations and checks their statuses |
|
416 | + * if ALL registrations are Cancelled or Declined, then this sets the TXN status to |
|
417 | + * |
|
418 | + * @access public |
|
419 | + * @param EE_Transaction $transaction |
|
420 | + * @param string $new_TXN_status |
|
421 | + * @param array $registration_query_params - array of query WHERE params to use when |
|
422 | + * retrieving cached registrations from a transaction |
|
423 | + * @param array $closed_reg_statuses |
|
424 | + * @param bool $update_txn |
|
425 | + * @return bool true if TXN status was updated, false if not |
|
426 | + */ |
|
427 | + public function toggle_transaction_status_if_all_registrations_canceled_or_declined( |
|
428 | + EE_Transaction $transaction, |
|
429 | + $new_TXN_status = '', |
|
430 | + $registration_query_params = array(), |
|
431 | + $closed_reg_statuses = array(), |
|
432 | + $update_txn = true |
|
433 | + ) { |
|
434 | + // make sure some query params are set for retrieving registrations |
|
435 | + $this->_set_registration_query_params($registration_query_params); |
|
436 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
437 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
438 | + : EEM_Registration::closed_reg_statuses(); |
|
439 | + // loop through cached registrations |
|
440 | + foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
441 | + if ( |
|
442 | + $registration instanceof EE_Registration |
|
443 | + && ! in_array($registration->status_ID(), $closed_reg_statuses) |
|
444 | + ) { |
|
445 | + return false; |
|
446 | + } |
|
447 | + } |
|
448 | + if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) { |
|
449 | + $transaction->set_status($new_TXN_status); |
|
450 | + } |
|
451 | + if ($update_txn) { |
|
452 | + return $transaction->save() ? true : false; |
|
453 | + } |
|
454 | + return true; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * _call_method_on_registrations_via_Registration_Processor |
|
460 | + * cycles thru related registrations and calls the requested method on each |
|
461 | + * |
|
462 | + * @access private |
|
463 | + * @param string $method_name |
|
464 | + * @param EE_Transaction $transaction |
|
465 | + * @param array $registration_query_params array of query WHERE params to use |
|
466 | + * when retrieving cached registrations from a transaction |
|
467 | + * @param string $additional_param |
|
468 | + * @throws \EE_Error |
|
469 | + * @return boolean |
|
470 | + */ |
|
471 | + private function _call_method_on_registrations_via_Registration_Processor( |
|
472 | + $method_name, |
|
473 | + EE_Transaction $transaction, |
|
474 | + $registration_query_params = array(), |
|
475 | + $additional_param = null |
|
476 | + ) { |
|
477 | + $response = false; |
|
478 | + /** @type EE_Registration_Processor $registration_processor */ |
|
479 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
480 | + // check that method exists |
|
481 | + if (! method_exists($registration_processor, $method_name)) { |
|
482 | + throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso')); |
|
483 | + } |
|
484 | + // make sure some query params are set for retrieving registrations |
|
485 | + $this->_set_registration_query_params($registration_query_params); |
|
486 | + // loop through cached registrations |
|
487 | + foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
488 | + if ($registration instanceof EE_Registration) { |
|
489 | + if ($additional_param) { |
|
490 | + $response = $registration_processor->{$method_name}($registration, $additional_param) |
|
491 | + ? true |
|
492 | + : $response; |
|
493 | + } else { |
|
494 | + $response = $registration_processor->{$method_name}($registration) |
|
495 | + ? true |
|
496 | + : $response; |
|
497 | + } |
|
498 | + } |
|
499 | + } |
|
500 | + return $response; |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * set_transaction_payment_method_based_on_registration_statuses |
|
506 | + * sets or unsets the PMD_ID field on the TXN based on the related REG statuses |
|
507 | + * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null, |
|
508 | + * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either: |
|
509 | + * the first "default" Payment Method |
|
510 | + * the first active Payment Method |
|
511 | + * whichever is found first. |
|
512 | + * |
|
513 | + * @param EE_Registration $edited_registration |
|
514 | + * @return void |
|
515 | + * @throws \EE_Error |
|
516 | + */ |
|
517 | + public function set_transaction_payment_method_based_on_registration_statuses( |
|
518 | + EE_Registration $edited_registration |
|
519 | + ) { |
|
520 | + if ($edited_registration instanceof EE_Registration) { |
|
521 | + $transaction = $edited_registration->transaction(); |
|
522 | + if ($transaction instanceof EE_Transaction) { |
|
523 | + $all_not_approved = true; |
|
524 | + foreach ($transaction->registrations() as $registration) { |
|
525 | + if ($registration instanceof EE_Registration) { |
|
526 | + // if any REG != "Not Approved" then toggle to false |
|
527 | + $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false; |
|
528 | + } |
|
529 | + } |
|
530 | + // if ALL Registrations are "Not Approved" |
|
531 | + if ($all_not_approved) { |
|
532 | + $transaction->set_payment_method_ID(null); |
|
533 | + $transaction->save(); |
|
534 | + } else { |
|
535 | + $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
536 | + $transaction, |
|
537 | + EEM_Payment_Method::scope_cart |
|
538 | + ); |
|
539 | + if (! empty($available_payment_methods)) { |
|
540 | + $PMD_ID = 0; |
|
541 | + foreach ($available_payment_methods as $available_payment_method) { |
|
542 | + if ( |
|
543 | + $available_payment_method instanceof EE_Payment_Method |
|
544 | + && $available_payment_method->open_by_default() |
|
545 | + ) { |
|
546 | + $PMD_ID = $available_payment_method->ID(); |
|
547 | + break; |
|
548 | + } |
|
549 | + } |
|
550 | + if (! $PMD_ID) { |
|
551 | + $first_payment_method = reset($available_payment_methods); |
|
552 | + if ($first_payment_method instanceof EE_Payment_Method) { |
|
553 | + $PMD_ID = $first_payment_method->ID(); |
|
554 | + } else { |
|
555 | + EE_Error::add_error( |
|
556 | + esc_html__( |
|
557 | + 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', |
|
558 | + 'event_espresso' |
|
559 | + ), |
|
560 | + __FILE__, |
|
561 | + __LINE__, |
|
562 | + __FUNCTION__ |
|
563 | + ); |
|
564 | + } |
|
565 | + } |
|
566 | + $transaction->set_payment_method_ID($PMD_ID); |
|
567 | + $transaction->save(); |
|
568 | + } else { |
|
569 | + EE_Error::add_error( |
|
570 | + esc_html__( |
|
571 | + 'Please activate at least one Payment Method in order for things to operate correctly.', |
|
572 | + 'event_espresso' |
|
573 | + ), |
|
574 | + __FILE__, |
|
575 | + __LINE__, |
|
576 | + __FUNCTION__ |
|
577 | + ); |
|
578 | + } |
|
579 | + } |
|
580 | + } |
|
581 | + } |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + |
|
586 | + /********************************** DEPRECATED METHODS **********************************/ |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * @deprecated 4.9.12 |
|
591 | + * @return string |
|
592 | + */ |
|
593 | + public function old_txn_status() |
|
594 | + { |
|
595 | + EE_Error::doing_it_wrong( |
|
596 | + __METHOD__, |
|
597 | + esc_html__( |
|
598 | + 'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.', |
|
599 | + 'event_espresso' |
|
600 | + ), |
|
601 | + '4.9.12' |
|
602 | + ); |
|
603 | + return $this->_old_txn_status; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * @deprecated 4.9.12 |
|
609 | + * @param string $old_txn_status |
|
610 | + */ |
|
611 | + public function set_old_txn_status($old_txn_status) |
|
612 | + { |
|
613 | + EE_Error::doing_it_wrong( |
|
614 | + __METHOD__, |
|
615 | + esc_html__( |
|
616 | + 'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.', |
|
617 | + 'event_espresso' |
|
618 | + ), |
|
619 | + '4.9.12' |
|
620 | + ); |
|
621 | + // only set the first time |
|
622 | + if ($this->_old_txn_status === null) { |
|
623 | + $this->_old_txn_status = $old_txn_status; |
|
624 | + } |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * @deprecated 4.9.12 |
|
630 | + * @return string |
|
631 | + */ |
|
632 | + public function new_txn_status() |
|
633 | + { |
|
634 | + EE_Error::doing_it_wrong( |
|
635 | + __METHOD__, |
|
636 | + esc_html__( |
|
637 | + 'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.', |
|
638 | + 'event_espresso' |
|
639 | + ), |
|
640 | + '4.9.12' |
|
641 | + ); |
|
642 | + return $this->_new_txn_status; |
|
643 | + } |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * @deprecated 4.9.12 |
|
648 | + * @param string $new_txn_status |
|
649 | + */ |
|
650 | + public function set_new_txn_status($new_txn_status) |
|
651 | + { |
|
652 | + EE_Error::doing_it_wrong( |
|
653 | + __METHOD__, |
|
654 | + esc_html__( |
|
655 | + 'This logic has been removed. Please just use \EE_Transaction::set_status() instead.', |
|
656 | + 'event_espresso' |
|
657 | + ), |
|
658 | + '4.9.12' |
|
659 | + ); |
|
660 | + $this->_new_txn_status = $new_txn_status; |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * reg_status_updated |
|
666 | + * |
|
667 | + * @deprecated 4.9.12 |
|
668 | + * @return bool |
|
669 | + */ |
|
670 | + public function txn_status_updated() |
|
671 | + { |
|
672 | + EE_Error::doing_it_wrong( |
|
673 | + __METHOD__, |
|
674 | + esc_html__( |
|
675 | + 'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.', |
|
676 | + 'event_espresso' |
|
677 | + ), |
|
678 | + '4.9.12' |
|
679 | + ); |
|
680 | + return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false; |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * all_reg_steps_completed |
|
686 | + * returns: |
|
687 | + * true if ALL reg steps have been marked as completed |
|
688 | + * or false if any step is not completed |
|
689 | + * |
|
690 | + * @deprecated 4.9.12 |
|
691 | + * @param EE_Transaction $transaction |
|
692 | + * @return boolean |
|
693 | + */ |
|
694 | + public function all_reg_steps_completed(EE_Transaction $transaction) |
|
695 | + { |
|
696 | + EE_Error::doing_it_wrong( |
|
697 | + __METHOD__, |
|
698 | + esc_html__( |
|
699 | + 'This logic has been moved into \EE_Transaction::all_reg_steps_completed(), please use that method instead.', |
|
700 | + 'event_espresso' |
|
701 | + ), |
|
702 | + '4.9.12', |
|
703 | + '5.0.0' |
|
704 | + ); |
|
705 | + return $transaction->all_reg_steps_completed(); |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * all_reg_steps_completed_except |
|
711 | + * returns: |
|
712 | + * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
713 | + * or false if any other step is not completed |
|
714 | + * or false if ALL steps are completed including the exception you are testing !!! |
|
715 | + * |
|
716 | + * @deprecated 4.9.12 |
|
717 | + * @param EE_Transaction $transaction |
|
718 | + * @param string $exception |
|
719 | + * @return boolean |
|
720 | + */ |
|
721 | + public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '') |
|
722 | + { |
|
723 | + EE_Error::doing_it_wrong( |
|
724 | + __METHOD__, |
|
725 | + esc_html__( |
|
726 | + 'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except(), please use that method instead.', |
|
727 | + 'event_espresso' |
|
728 | + ), |
|
729 | + '4.9.12', |
|
730 | + '5.0.0' |
|
731 | + ); |
|
732 | + return $transaction->all_reg_steps_completed_except($exception); |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * all_reg_steps_completed_except |
|
738 | + * returns: |
|
739 | + * true if ALL reg steps, except the final step, have been marked as completed |
|
740 | + * or false if any step is not completed |
|
741 | + * or false if ALL steps are completed including the final step !!! |
|
742 | + * |
|
743 | + * @deprecated 4.9.12 |
|
744 | + * @param EE_Transaction $transaction |
|
745 | + * @return boolean |
|
746 | + */ |
|
747 | + public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction) |
|
748 | + { |
|
749 | + EE_Error::doing_it_wrong( |
|
750 | + __METHOD__, |
|
751 | + esc_html__( |
|
752 | + 'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except_final_step(), please use that method instead.', |
|
753 | + 'event_espresso' |
|
754 | + ), |
|
755 | + '4.9.12', |
|
756 | + '5.0.0' |
|
757 | + ); |
|
758 | + return $transaction->all_reg_steps_completed_except_final_step(); |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * reg_step_completed |
|
764 | + * returns: |
|
765 | + * true if a specific reg step has been marked as completed |
|
766 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
767 | + * or false if it has not yet been initialized |
|
768 | + * |
|
769 | + * @deprecated 4.9.12 |
|
770 | + * @param EE_Transaction $transaction |
|
771 | + * @param string $reg_step_slug |
|
772 | + * @return boolean | int |
|
773 | + */ |
|
774 | + public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug) |
|
775 | + { |
|
776 | + EE_Error::doing_it_wrong( |
|
777 | + __METHOD__, |
|
778 | + esc_html__( |
|
779 | + 'This logic has been moved into \EE_Transaction::reg_step_completed(), please use that method instead.', |
|
780 | + 'event_espresso' |
|
781 | + ), |
|
782 | + '4.9.12', |
|
783 | + '5.0.0' |
|
784 | + ); |
|
785 | + return $transaction->reg_step_completed($reg_step_slug); |
|
786 | + } |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * completed_final_reg_step |
|
791 | + * returns: |
|
792 | + * true if the finalize_registration reg step has been marked as completed |
|
793 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
794 | + * or false if it has not yet been initialized |
|
795 | + * |
|
796 | + * @deprecated 4.9.12 |
|
797 | + * @param EE_Transaction $transaction |
|
798 | + * @return boolean | int |
|
799 | + */ |
|
800 | + public function final_reg_step_completed(EE_Transaction $transaction) |
|
801 | + { |
|
802 | + EE_Error::doing_it_wrong( |
|
803 | + __METHOD__, |
|
804 | + esc_html__( |
|
805 | + 'This logic has been moved into \EE_Transaction::final_reg_step_completed(), please use that method instead.', |
|
806 | + 'event_espresso' |
|
807 | + ), |
|
808 | + '4.9.12', |
|
809 | + '5.0.0' |
|
810 | + ); |
|
811 | + return $transaction->final_reg_step_completed(); |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + /** |
|
816 | + * set_reg_step_initiated |
|
817 | + * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
818 | + * |
|
819 | + * @deprecated 4.9.12 |
|
820 | + * @access public |
|
821 | + * @param \EE_Transaction $transaction |
|
822 | + * @param string $reg_step_slug |
|
823 | + * @return boolean |
|
824 | + * @throws \EE_Error |
|
825 | + */ |
|
826 | + public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug) |
|
827 | + { |
|
828 | + EE_Error::doing_it_wrong( |
|
829 | + __METHOD__, |
|
830 | + esc_html__( |
|
831 | + 'This logic has been moved into \EE_Transaction::set_reg_step_initiated(), please use that method instead.', |
|
832 | + 'event_espresso' |
|
833 | + ), |
|
834 | + '4.9.12', |
|
835 | + '5.0.0' |
|
836 | + ); |
|
837 | + return $transaction->set_reg_step_initiated($reg_step_slug); |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * set_reg_step_completed |
|
843 | + * given a valid TXN_reg_step, this sets the step as completed |
|
844 | + * |
|
845 | + * @deprecated 4.9.12 |
|
846 | + * @access public |
|
847 | + * @param \EE_Transaction $transaction |
|
848 | + * @param string $reg_step_slug |
|
849 | + * @return boolean |
|
850 | + * @throws \EE_Error |
|
851 | + */ |
|
852 | + public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug) |
|
853 | + { |
|
854 | + EE_Error::doing_it_wrong( |
|
855 | + __METHOD__, |
|
856 | + esc_html__( |
|
857 | + 'This logic has been moved into \EE_Transaction::set_reg_step_completed(), please use that method instead.', |
|
858 | + 'event_espresso' |
|
859 | + ), |
|
860 | + '4.9.12', |
|
861 | + '5.0.0' |
|
862 | + ); |
|
863 | + return $transaction->set_reg_step_completed($reg_step_slug); |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * set_reg_step_completed |
|
869 | + * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
870 | + * |
|
871 | + * @deprecated 4.9.12 |
|
872 | + * @access public |
|
873 | + * @param \EE_Transaction $transaction |
|
874 | + * @param string $reg_step_slug |
|
875 | + * @return boolean |
|
876 | + * @throws \EE_Error |
|
877 | + */ |
|
878 | + public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug) |
|
879 | + { |
|
880 | + EE_Error::doing_it_wrong( |
|
881 | + __METHOD__, |
|
882 | + esc_html__( |
|
883 | + 'This logic has been moved into \EE_Transaction::set_reg_step_not_completed(), please use that method instead.', |
|
884 | + 'event_espresso' |
|
885 | + ), |
|
886 | + '4.9.12', |
|
887 | + '5.0.0' |
|
888 | + ); |
|
889 | + return $transaction->set_reg_step_not_completed($reg_step_slug); |
|
890 | + } |
|
891 | + |
|
892 | + |
|
893 | + /** |
|
894 | + * remove_reg_step |
|
895 | + * given a valid TXN_reg_step slug, this will remove (unset) |
|
896 | + * the reg step from the TXN reg step array |
|
897 | + * |
|
898 | + * @deprecated 4.9.12 |
|
899 | + * @access public |
|
900 | + * @param \EE_Transaction $transaction |
|
901 | + * @param string $reg_step_slug |
|
902 | + * @return void |
|
903 | + */ |
|
904 | + public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug) |
|
905 | + { |
|
906 | + EE_Error::doing_it_wrong( |
|
907 | + __METHOD__, |
|
908 | + esc_html__( |
|
909 | + 'This logic has been moved into \EE_Transaction::remove_reg_step(), please use that method instead.', |
|
910 | + 'event_espresso' |
|
911 | + ), |
|
912 | + '4.9.12', |
|
913 | + '5.0.0' |
|
914 | + ); |
|
915 | + $transaction->remove_reg_step($reg_step_slug); |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * toggle_failed_transaction_status |
|
921 | + * upgrades a TXNs status from failed to abandoned, |
|
922 | + * meaning that contact information has been captured for at least one registrant |
|
923 | + * |
|
924 | + * @deprecated 4.9.12 |
|
925 | + * @access public |
|
926 | + * @param EE_Transaction $transaction |
|
927 | + * @return boolean |
|
928 | + * @throws \EE_Error |
|
929 | + */ |
|
930 | + public function toggle_failed_transaction_status(EE_Transaction $transaction) |
|
931 | + { |
|
932 | + EE_Error::doing_it_wrong( |
|
933 | + __METHOD__, |
|
934 | + esc_html__( |
|
935 | + 'This logic has been moved into \EE_Transaction::toggle_failed_transaction_status(), please use that method instead.', |
|
936 | + 'event_espresso' |
|
937 | + ), |
|
938 | + '4.9.12', |
|
939 | + '5.0.0' |
|
940 | + ); |
|
941 | + return $transaction->toggle_failed_transaction_status(); |
|
942 | + } |
|
943 | + |
|
944 | + |
|
945 | + /** |
|
946 | + * toggle_abandoned_transaction_status |
|
947 | + * upgrades a TXNs status from failed or abandoned to incomplete |
|
948 | + * |
|
949 | + * @deprecated 4.9.12 |
|
950 | + * @access public |
|
951 | + * @param EE_Transaction $transaction |
|
952 | + * @return boolean |
|
953 | + */ |
|
954 | + public function toggle_abandoned_transaction_status(EE_Transaction $transaction) |
|
955 | + { |
|
956 | + EE_Error::doing_it_wrong( |
|
957 | + __METHOD__, |
|
958 | + esc_html__( |
|
959 | + 'This logic has been moved into \EE_Transaction::toggle_abandoned_transaction_status(), please use that method instead.', |
|
960 | + 'event_espresso' |
|
961 | + ), |
|
962 | + '4.9.12', |
|
963 | + '5.0.0' |
|
964 | + ); |
|
965 | + return $transaction->toggle_abandoned_transaction_status(); |
|
966 | + } |
|
967 | 967 | } |
@@ -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 | } |