@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | |
146 | 146 | |
147 | 147 | /** |
148 | - * @return null |
|
148 | + * @return EE_Line_Item_Display |
|
149 | 149 | */ |
150 | 150 | public function line_item_display() |
151 | 151 | { |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | |
156 | 156 | /** |
157 | - * @param null $line_item_display |
|
157 | + * @param EE_Line_Item_Display $line_item_display |
|
158 | 158 | */ |
159 | 159 | public function set_line_item_display($line_item_display) |
160 | 160 | { |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | * _apply_registration_payments_to_amount_owing |
883 | 883 | * |
884 | 884 | * @access protected |
885 | - * @param array $registrations |
|
885 | + * @param EE_Base_Class[] $registrations |
|
886 | 886 | * @throws EE_Error |
887 | 887 | */ |
888 | 888 | protected function _apply_registration_payments_to_amount_owing(array $registrations) |
@@ -1188,7 +1188,7 @@ discard block |
||
1188 | 1188 | * get_billing_form_html_for_payment_method |
1189 | 1189 | * |
1190 | 1190 | * @access public |
1191 | - * @return string |
|
1191 | + * @return boolean |
|
1192 | 1192 | * @throws EE_Error |
1193 | 1193 | * @throws InvalidArgumentException |
1194 | 1194 | * @throws ReflectionException |
@@ -1255,7 +1255,7 @@ discard block |
||
1255 | 1255 | * |
1256 | 1256 | * @access private |
1257 | 1257 | * @param EE_Payment_Method $payment_method |
1258 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1258 | + * @return EE_Billing_Info_Form |
|
1259 | 1259 | * @throws EE_Error |
1260 | 1260 | * @throws InvalidArgumentException |
1261 | 1261 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -1364,7 +1364,7 @@ discard block |
||
1364 | 1364 | * switch_payment_method |
1365 | 1365 | * |
1366 | 1366 | * @access public |
1367 | - * @return string |
|
1367 | + * @return boolean |
|
1368 | 1368 | * @throws EE_Error |
1369 | 1369 | * @throws InvalidArgumentException |
1370 | 1370 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -1643,7 +1643,7 @@ discard block |
||
1643 | 1643 | /** |
1644 | 1644 | * process_reg_step |
1645 | 1645 | * |
1646 | - * @return bool |
|
1646 | + * @return null|boolean |
|
1647 | 1647 | * @throws EE_Error |
1648 | 1648 | * @throws InvalidArgumentException |
1649 | 1649 | * @throws ReflectionException |
@@ -1774,7 +1774,7 @@ discard block |
||
1774 | 1774 | * update_reg_step |
1775 | 1775 | * this is the final step after a user revisits the site to retry a payment |
1776 | 1776 | * |
1777 | - * @return bool |
|
1777 | + * @return null|boolean |
|
1778 | 1778 | * @throws EE_Error |
1779 | 1779 | * @throws InvalidArgumentException |
1780 | 1780 | * @throws ReflectionException |
@@ -2221,7 +2221,7 @@ discard block |
||
2221 | 2221 | * |
2222 | 2222 | * @access private |
2223 | 2223 | * @type EE_Payment_Method $payment_method |
2224 | - * @return mixed EE_Payment | boolean |
|
2224 | + * @return EE_Payment|null EE_Payment | boolean |
|
2225 | 2225 | * @throws EE_Error |
2226 | 2226 | * @throws InvalidArgumentException |
2227 | 2227 | * @throws ReflectionException |
@@ -2546,7 +2546,7 @@ discard block |
||
2546 | 2546 | * or present the payment options again |
2547 | 2547 | * |
2548 | 2548 | * @access private |
2549 | - * @return EE_Payment|FALSE |
|
2549 | + * @return boolean |
|
2550 | 2550 | * @throws EE_Error |
2551 | 2551 | * @throws InvalidArgumentException |
2552 | 2552 | * @throws ReflectionException |
@@ -2686,8 +2686,8 @@ discard block |
||
2686 | 2686 | * _redirect_wayward_request |
2687 | 2687 | * |
2688 | 2688 | * @access private |
2689 | - * @param \EE_Registration|null $primary_registrant |
|
2690 | - * @return bool |
|
2689 | + * @param EE_Registration $primary_registrant |
|
2690 | + * @return false|null |
|
2691 | 2691 | * @throws EE_Error |
2692 | 2692 | * @throws InvalidArgumentException |
2693 | 2693 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -12,2889 +12,2889 @@ |
||
12 | 12 | class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @access protected |
|
17 | - * @var EE_Line_Item_Display $Line_Item_Display |
|
18 | - */ |
|
19 | - protected $line_item_display; |
|
20 | - |
|
21 | - /** |
|
22 | - * @access protected |
|
23 | - * @var boolean $handle_IPN_in_this_request |
|
24 | - */ |
|
25 | - protected $handle_IPN_in_this_request = false; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
30 | - * |
|
31 | - * @access public |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function set_hooks() |
|
35 | - { |
|
36 | - add_filter( |
|
37 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
38 | - array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
39 | - ); |
|
40 | - add_action( |
|
41 | - 'wp_ajax_switch_spco_billing_form', |
|
42 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
43 | - ); |
|
44 | - add_action( |
|
45 | - 'wp_ajax_nopriv_switch_spco_billing_form', |
|
46 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
47 | - ); |
|
48 | - add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
49 | - add_action( |
|
50 | - 'wp_ajax_nopriv_save_payer_details', |
|
51 | - array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
52 | - ); |
|
53 | - add_action( |
|
54 | - 'wp_ajax_get_transaction_details_for_gateways', |
|
55 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
56 | - ); |
|
57 | - add_action( |
|
58 | - 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
59 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
60 | - ); |
|
61 | - add_filter( |
|
62 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
63 | - array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
64 | - 10, |
|
65 | - 1 |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * ajax switch_spco_billing_form |
|
72 | - * |
|
73 | - * @throws \EE_Error |
|
74 | - */ |
|
75 | - public static function switch_spco_billing_form() |
|
76 | - { |
|
77 | - EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * ajax save_payer_details |
|
83 | - * |
|
84 | - * @throws \EE_Error |
|
85 | - */ |
|
86 | - public static function save_payer_details() |
|
87 | - { |
|
88 | - EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * ajax get_transaction_details |
|
94 | - * |
|
95 | - * @throws \EE_Error |
|
96 | - */ |
|
97 | - public static function get_transaction_details() |
|
98 | - { |
|
99 | - EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * bypass_recaptcha_for_load_payment_method |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @return array |
|
108 | - * @throws InvalidArgumentException |
|
109 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
110 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
111 | - */ |
|
112 | - public static function bypass_recaptcha_for_load_payment_method() |
|
113 | - { |
|
114 | - return array( |
|
115 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
116 | - 'step' => 'payment_options', |
|
117 | - 'action' => 'spco_billing_form', |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * class constructor |
|
124 | - * |
|
125 | - * @access public |
|
126 | - * @param EE_Checkout $checkout |
|
127 | - */ |
|
128 | - public function __construct(EE_Checkout $checkout) |
|
129 | - { |
|
130 | - $this->_slug = 'payment_options'; |
|
131 | - $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
133 | - $this->checkout = $checkout; |
|
134 | - $this->_reset_success_message(); |
|
135 | - $this->set_instructions( |
|
136 | - esc_html__( |
|
137 | - 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
138 | - 'event_espresso' |
|
139 | - ) |
|
140 | - ); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return null |
|
146 | - */ |
|
147 | - public function line_item_display() |
|
148 | - { |
|
149 | - return $this->line_item_display; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param null $line_item_display |
|
155 | - */ |
|
156 | - public function set_line_item_display($line_item_display) |
|
157 | - { |
|
158 | - $this->line_item_display = $line_item_display; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @return boolean |
|
164 | - */ |
|
165 | - public function handle_IPN_in_this_request() |
|
166 | - { |
|
167 | - return $this->handle_IPN_in_this_request; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param boolean $handle_IPN_in_this_request |
|
173 | - */ |
|
174 | - public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
175 | - { |
|
176 | - $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * translate_js_strings |
|
182 | - * |
|
183 | - * @return void |
|
184 | - */ |
|
185 | - public function translate_js_strings() |
|
186 | - { |
|
187 | - EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
188 | - 'Please select a method of payment in order to continue.', |
|
189 | - 'event_espresso' |
|
190 | - ); |
|
191 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
192 | - 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
193 | - 'event_espresso' |
|
194 | - ); |
|
195 | - EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
196 | - 'Forwarding to Secure Payment Provider.', |
|
197 | - 'event_espresso' |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * enqueue_styles_and_scripts |
|
204 | - * |
|
205 | - * @return void |
|
206 | - * @throws EE_Error |
|
207 | - * @throws InvalidArgumentException |
|
208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
210 | - */ |
|
211 | - public function enqueue_styles_and_scripts() |
|
212 | - { |
|
213 | - $transaction = $this->checkout->transaction; |
|
214 | - // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
216 | - return; |
|
217 | - } |
|
218 | - foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
219 | - $transaction, |
|
220 | - EEM_Payment_Method::scope_cart |
|
221 | - ) as $payment_method) { |
|
222 | - $type_obj = $payment_method->type_obj(); |
|
223 | - if ($type_obj instanceof EE_PMT_Base) { |
|
224 | - $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
225 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
226 | - $billing_form->enqueue_js(); |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * initialize_reg_step |
|
235 | - * |
|
236 | - * @return bool |
|
237 | - * @throws EE_Error |
|
238 | - * @throws InvalidArgumentException |
|
239 | - * @throws ReflectionException |
|
240 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
241 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
242 | - */ |
|
243 | - public function initialize_reg_step() |
|
244 | - { |
|
245 | - // TODO: if /when we implement donations, then this will need overriding |
|
246 | - if (// don't need payment options for: |
|
247 | - // registrations made via the admin |
|
248 | - // completed transactions |
|
249 | - // overpaid transactions |
|
250 | - // $ 0.00 transactions(no payment required) |
|
251 | - ! $this->checkout->payment_required() |
|
252 | - // but do NOT remove if current action being called belongs to this reg step |
|
253 | - && ! is_callable(array($this, $this->checkout->action)) |
|
254 | - && ! $this->completed() |
|
255 | - ) { |
|
256 | - // and if so, then we no longer need the Payment Options step |
|
257 | - if ($this->is_current_step()) { |
|
258 | - $this->checkout->generate_reg_form = false; |
|
259 | - } |
|
260 | - $this->checkout->remove_reg_step($this->_slug); |
|
261 | - // DEBUG LOG |
|
262 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
263 | - return false; |
|
264 | - } |
|
265 | - // load EEM_Payment_Method |
|
266 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
267 | - // get all active payment methods |
|
268 | - $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
269 | - $this->checkout->transaction, |
|
270 | - EEM_Payment_Method::scope_cart |
|
271 | - ); |
|
272 | - return true; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * @return EE_Form_Section_Proper |
|
278 | - * @throws EE_Error |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws ReflectionException |
|
281 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
282 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
283 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
284 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
285 | - */ |
|
286 | - public function generate_reg_form() |
|
287 | - { |
|
288 | - // reset in case someone changes their mind |
|
289 | - $this->_reset_selected_method_of_payment(); |
|
290 | - // set some defaults |
|
291 | - $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
292 | - $registrations_requiring_payment = array(); |
|
293 | - $registrations_for_free_events = array(); |
|
294 | - $registrations_requiring_pre_approval = array(); |
|
295 | - $sold_out_events = array(); |
|
296 | - $insufficient_spaces_available = array(); |
|
297 | - $no_payment_required = true; |
|
298 | - // loop thru registrations to gather info |
|
299 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
300 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
301 | - $registrations, |
|
302 | - $this->checkout->revisit |
|
303 | - ); |
|
304 | - foreach ($registrations as $REG_ID => $registration) { |
|
305 | - /** @var $registration EE_Registration */ |
|
306 | - // has this registration lost it's space ? |
|
307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
308 | - if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
310 | - } else { |
|
311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
312 | - } |
|
313 | - continue; |
|
314 | - } |
|
315 | - // event requires admin approval |
|
316 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
317 | - // add event to list of events with pre-approval reg status |
|
318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
319 | - do_action( |
|
320 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
321 | - $registration->event(), |
|
322 | - $this |
|
323 | - ); |
|
324 | - continue; |
|
325 | - } |
|
326 | - if ($this->checkout->revisit |
|
327 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
328 | - && ( |
|
329 | - $registration->event()->is_sold_out() |
|
330 | - || $registration->event()->is_sold_out(true) |
|
331 | - ) |
|
332 | - ) { |
|
333 | - // add event to list of events that are sold out |
|
334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
335 | - do_action( |
|
336 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
337 | - $registration->event(), |
|
338 | - $this |
|
339 | - ); |
|
340 | - continue; |
|
341 | - } |
|
342 | - // are they allowed to pay now and is there monies owing? |
|
343 | - if ($registration->owes_monies_and_can_pay()) { |
|
344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
345 | - do_action( |
|
346 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
347 | - $registration->event(), |
|
348 | - $this |
|
349 | - ); |
|
350 | - } elseif (! $this->checkout->revisit |
|
351 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
352 | - && $registration->ticket()->is_free() |
|
353 | - ) { |
|
354 | - $registrations_for_free_events[ $registration->event()->ID() ] = $registration; |
|
355 | - } |
|
356 | - } |
|
357 | - $subsections = array(); |
|
358 | - // now decide which template to load |
|
359 | - if (! empty($sold_out_events)) { |
|
360 | - $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
361 | - } |
|
362 | - if (! empty($insufficient_spaces_available)) { |
|
363 | - $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
364 | - $insufficient_spaces_available |
|
365 | - ); |
|
366 | - } |
|
367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
368 | - $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
369 | - $registrations_requiring_pre_approval |
|
370 | - ); |
|
371 | - } |
|
372 | - if (! empty($registrations_for_free_events)) { |
|
373 | - $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
374 | - } |
|
375 | - if (! empty($registrations_requiring_payment)) { |
|
376 | - if ($this->checkout->amount_owing > 0) { |
|
377 | - // autoload Line_Item_Display classes |
|
378 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
379 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
380 | - apply_filters( |
|
381 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
382 | - new EE_Line_Item_Filter_Collection() |
|
383 | - ), |
|
384 | - $this->checkout->cart->get_grand_total() |
|
385 | - ); |
|
386 | - /** @var EE_Line_Item $filtered_line_item_tree */ |
|
387 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
388 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
389 | - $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
390 | - $subsections['payment_options'] = $this->_display_payment_options( |
|
391 | - $this->line_item_display->display_line_item( |
|
392 | - $filtered_line_item_tree, |
|
393 | - array('registrations' => $registrations) |
|
394 | - ) |
|
395 | - ); |
|
396 | - $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
397 | - $this->_apply_registration_payments_to_amount_owing($registrations); |
|
398 | - } |
|
399 | - $no_payment_required = false; |
|
400 | - } else { |
|
401 | - $this->_hide_reg_step_submit_button_if_revisit(); |
|
402 | - } |
|
403 | - $this->_save_selected_method_of_payment(); |
|
404 | - |
|
405 | - $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
406 | - $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
407 | - |
|
408 | - return new EE_Form_Section_Proper( |
|
409 | - array( |
|
410 | - 'name' => $this->reg_form_name(), |
|
411 | - 'html_id' => $this->reg_form_name(), |
|
412 | - 'subsections' => $subsections, |
|
413 | - 'layout_strategy' => new EE_No_Layout(), |
|
414 | - ) |
|
415 | - ); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * add line item filters required for this reg step |
|
421 | - * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
422 | - * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
423 | - * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
424 | - * payment options reg step, can apply these filters via the following: apply_filters( |
|
425 | - * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
426 | - * filter collection by passing that instead of instantiating a new collection |
|
427 | - * |
|
428 | - * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
429 | - * @return EE_Line_Item_Filter_Collection |
|
430 | - * @throws EE_Error |
|
431 | - * @throws InvalidArgumentException |
|
432 | - * @throws ReflectionException |
|
433 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
434 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
435 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
436 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
437 | - */ |
|
438 | - public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
439 | - { |
|
440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
441 | - return $line_item_filter_collection; |
|
442 | - } |
|
443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
444 | - return $line_item_filter_collection; |
|
445 | - } |
|
446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
447 | - return $line_item_filter_collection; |
|
448 | - } |
|
449 | - $line_item_filter_collection->add( |
|
450 | - new EE_Billable_Line_Item_Filter( |
|
451 | - EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
452 | - EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
453 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
454 | - ) |
|
455 | - ) |
|
456 | - ) |
|
457 | - ); |
|
458 | - $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
459 | - return $line_item_filter_collection; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * remove_ejected_registrations |
|
465 | - * if a registrant has lost their potential space at an event due to lack of payment, |
|
466 | - * then this method removes them from the list of registrations being paid for during this request |
|
467 | - * |
|
468 | - * @param \EE_Registration[] $registrations |
|
469 | - * @return EE_Registration[] |
|
470 | - * @throws EE_Error |
|
471 | - * @throws InvalidArgumentException |
|
472 | - * @throws ReflectionException |
|
473 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
474 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
475 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
476 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
477 | - */ |
|
478 | - public static function remove_ejected_registrations(array $registrations) |
|
479 | - { |
|
480 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
481 | - $registrations, |
|
482 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
483 | - ); |
|
484 | - foreach ($registrations as $REG_ID => $registration) { |
|
485 | - // has this registration lost it's space ? |
|
486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
487 | - unset($registrations[ $REG_ID ]); |
|
488 | - continue; |
|
489 | - } |
|
490 | - } |
|
491 | - return $registrations; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * find_registrations_that_lost_their_space |
|
497 | - * If a registrant chooses an offline payment method like Invoice, |
|
498 | - * then no space is reserved for them at the event until they fully pay fo that site |
|
499 | - * (unless the event's default reg status is set to APPROVED) |
|
500 | - * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
501 | - * then this method will determine which registrations have lost the ability to complete the reg process. |
|
502 | - * |
|
503 | - * @param \EE_Registration[] $registrations |
|
504 | - * @param bool $revisit |
|
505 | - * @return array |
|
506 | - * @throws EE_Error |
|
507 | - * @throws InvalidArgumentException |
|
508 | - * @throws ReflectionException |
|
509 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
510 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
511 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
512 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
513 | - */ |
|
514 | - public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
515 | - { |
|
516 | - // registrations per event |
|
517 | - $event_reg_count = array(); |
|
518 | - // spaces left per event |
|
519 | - $event_spaces_remaining = array(); |
|
520 | - // tickets left sorted by ID |
|
521 | - $tickets_remaining = array(); |
|
522 | - // registrations that have lost their space |
|
523 | - $ejected_registrations = array(); |
|
524 | - foreach ($registrations as $REG_ID => $registration) { |
|
525 | - if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
526 | - || apply_filters( |
|
527 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
528 | - false, |
|
529 | - $registration, |
|
530 | - $revisit |
|
531 | - ) |
|
532 | - ) { |
|
533 | - continue; |
|
534 | - } |
|
535 | - $EVT_ID = $registration->event_ID(); |
|
536 | - $ticket = $registration->ticket(); |
|
537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
539 | - } |
|
540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
543 | - } |
|
544 | - $event_reg_count[ $EVT_ID ]++; |
|
545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
547 | - } |
|
548 | - } |
|
549 | - if ($revisit |
|
550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
552 | - ) |
|
553 | - ) { |
|
554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
555 | - if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
556 | - /** @type EE_Registration_Processor $registration_processor */ |
|
557 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
558 | - // at this point, we should have enough details about the registrant to consider the registration |
|
559 | - // NOT incomplete |
|
560 | - $registration_processor->manually_update_registration_status( |
|
561 | - $registration, |
|
562 | - EEM_Registration::status_id_wait_list |
|
563 | - ); |
|
564 | - } |
|
565 | - } |
|
566 | - } |
|
567 | - return $ejected_registrations; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * _hide_reg_step_submit_button |
|
573 | - * removes the html for the reg step submit button |
|
574 | - * by replacing it with an empty string via filter callback |
|
575 | - * |
|
576 | - * @return void |
|
577 | - */ |
|
578 | - protected function _adjust_registration_status_if_event_old_sold() |
|
579 | - { |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * _hide_reg_step_submit_button |
|
585 | - * removes the html for the reg step submit button |
|
586 | - * by replacing it with an empty string via filter callback |
|
587 | - * |
|
588 | - * @return void |
|
589 | - */ |
|
590 | - protected function _hide_reg_step_submit_button_if_revisit() |
|
591 | - { |
|
592 | - if ($this->checkout->revisit) { |
|
593 | - add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
594 | - } |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * sold_out_events |
|
600 | - * displays notices regarding events that have sold out since hte registrant first signed up |
|
601 | - * |
|
602 | - * @param \EE_Event[] $sold_out_events_array |
|
603 | - * @return \EE_Form_Section_Proper |
|
604 | - * @throws \EE_Error |
|
605 | - */ |
|
606 | - private function _sold_out_events($sold_out_events_array = array()) |
|
607 | - { |
|
608 | - // set some defaults |
|
609 | - $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
610 | - $sold_out_events = ''; |
|
611 | - foreach ($sold_out_events_array as $sold_out_event) { |
|
612 | - $sold_out_events .= EEH_HTML::li( |
|
613 | - EEH_HTML::span( |
|
614 | - ' ' . $sold_out_event->name(), |
|
615 | - '', |
|
616 | - 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
617 | - ) |
|
618 | - ); |
|
619 | - } |
|
620 | - return new EE_Form_Section_Proper( |
|
621 | - array( |
|
622 | - 'layout_strategy' => new EE_Template_Layout( |
|
623 | - array( |
|
624 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
625 | - . $this->_slug |
|
626 | - . DS |
|
627 | - . 'sold_out_events.template.php', |
|
628 | - 'template_args' => apply_filters( |
|
629 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
630 | - array( |
|
631 | - 'sold_out_events' => $sold_out_events, |
|
632 | - 'sold_out_events_msg' => apply_filters( |
|
633 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
634 | - sprintf( |
|
635 | - esc_html__( |
|
636 | - 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
637 | - 'event_espresso' |
|
638 | - ), |
|
639 | - '<strong>', |
|
640 | - '</strong>', |
|
641 | - '<br />' |
|
642 | - ) |
|
643 | - ), |
|
644 | - ) |
|
645 | - ), |
|
646 | - ) |
|
647 | - ), |
|
648 | - ) |
|
649 | - ); |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * _insufficient_spaces_available |
|
655 | - * displays notices regarding events that do not have enough remaining spaces |
|
656 | - * to satisfy the current number of registrations looking to pay |
|
657 | - * |
|
658 | - * @param \EE_Event[] $insufficient_spaces_events_array |
|
659 | - * @return \EE_Form_Section_Proper |
|
660 | - * @throws \EE_Error |
|
661 | - */ |
|
662 | - private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
663 | - { |
|
664 | - // set some defaults |
|
665 | - $this->checkout->selected_method_of_payment = 'invoice'; |
|
666 | - $insufficient_space_events = ''; |
|
667 | - foreach ($insufficient_spaces_events_array as $event) { |
|
668 | - if ($event instanceof EE_Event) { |
|
669 | - $insufficient_space_events .= EEH_HTML::li( |
|
670 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
671 | - ); |
|
672 | - } |
|
673 | - } |
|
674 | - return new EE_Form_Section_Proper( |
|
675 | - array( |
|
676 | - 'subsections' => array( |
|
677 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
678 | - 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
679 | - ), |
|
680 | - 'layout_strategy' => new EE_Template_Layout( |
|
681 | - array( |
|
682 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
683 | - . $this->_slug |
|
684 | - . DS |
|
685 | - . 'sold_out_events.template.php', |
|
686 | - 'template_args' => apply_filters( |
|
687 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
688 | - array( |
|
689 | - 'sold_out_events' => $insufficient_space_events, |
|
690 | - 'sold_out_events_msg' => apply_filters( |
|
691 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
692 | - esc_html__( |
|
693 | - 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
694 | - 'event_espresso' |
|
695 | - ) |
|
696 | - ), |
|
697 | - ) |
|
698 | - ), |
|
699 | - ) |
|
700 | - ), |
|
701 | - ) |
|
702 | - ); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * registrations_requiring_pre_approval |
|
708 | - * |
|
709 | - * @param array $registrations_requiring_pre_approval |
|
710 | - * @return EE_Form_Section_Proper |
|
711 | - * @throws EE_Error |
|
712 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
713 | - */ |
|
714 | - private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
715 | - { |
|
716 | - $events_requiring_pre_approval = ''; |
|
717 | - foreach ($registrations_requiring_pre_approval as $registration) { |
|
718 | - if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
719 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
720 | - EEH_HTML::span( |
|
721 | - '', |
|
722 | - '', |
|
723 | - 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
724 | - ) |
|
725 | - . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
726 | - ); |
|
727 | - } |
|
728 | - } |
|
729 | - return new EE_Form_Section_Proper( |
|
730 | - array( |
|
731 | - 'layout_strategy' => new EE_Template_Layout( |
|
732 | - array( |
|
733 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
734 | - . $this->_slug |
|
735 | - . DS |
|
736 | - . 'events_requiring_pre_approval.template.php', // layout_template |
|
737 | - 'template_args' => apply_filters( |
|
738 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
739 | - array( |
|
740 | - 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
741 | - 'events_requiring_pre_approval_msg' => apply_filters( |
|
742 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
743 | - esc_html__( |
|
744 | - 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
745 | - 'event_espresso' |
|
746 | - ) |
|
747 | - ), |
|
748 | - ) |
|
749 | - ), |
|
750 | - ) |
|
751 | - ), |
|
752 | - ) |
|
753 | - ); |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _no_payment_required |
|
759 | - * |
|
760 | - * @param \EE_Event[] $registrations_for_free_events |
|
761 | - * @return \EE_Form_Section_Proper |
|
762 | - * @throws \EE_Error |
|
763 | - */ |
|
764 | - private function _no_payment_required($registrations_for_free_events = array()) |
|
765 | - { |
|
766 | - // set some defaults |
|
767 | - $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
768 | - // generate no_payment_required form |
|
769 | - return new EE_Form_Section_Proper( |
|
770 | - array( |
|
771 | - 'layout_strategy' => new EE_Template_Layout( |
|
772 | - array( |
|
773 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
774 | - . $this->_slug |
|
775 | - . DS |
|
776 | - . 'no_payment_required.template.php', // layout_template |
|
777 | - 'template_args' => apply_filters( |
|
778 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
779 | - array( |
|
780 | - 'revisit' => $this->checkout->revisit, |
|
781 | - 'registrations' => array(), |
|
782 | - 'ticket_count' => array(), |
|
783 | - 'registrations_for_free_events' => $registrations_for_free_events, |
|
784 | - 'no_payment_required_msg' => EEH_HTML::p( |
|
785 | - esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
786 | - ), |
|
787 | - ) |
|
788 | - ), |
|
789 | - ) |
|
790 | - ), |
|
791 | - ) |
|
792 | - ); |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * _display_payment_options |
|
798 | - * |
|
799 | - * @param string $transaction_details |
|
800 | - * @return EE_Form_Section_Proper |
|
801 | - * @throws EE_Error |
|
802 | - * @throws InvalidArgumentException |
|
803 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
804 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
805 | - */ |
|
806 | - private function _display_payment_options($transaction_details = '') |
|
807 | - { |
|
808 | - // has method_of_payment been set by no-js user? |
|
809 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
810 | - // build payment options form |
|
811 | - return apply_filters( |
|
812 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
813 | - new EE_Form_Section_Proper( |
|
814 | - array( |
|
815 | - 'subsections' => array( |
|
816 | - 'before_payment_options' => apply_filters( |
|
817 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
818 | - new EE_Form_Section_Proper( |
|
819 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
820 | - ) |
|
821 | - ), |
|
822 | - 'payment_options' => $this->_setup_payment_options(), |
|
823 | - 'after_payment_options' => apply_filters( |
|
824 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
825 | - new EE_Form_Section_Proper( |
|
826 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
827 | - ) |
|
828 | - ), |
|
829 | - ), |
|
830 | - 'layout_strategy' => new EE_Template_Layout( |
|
831 | - array( |
|
832 | - 'layout_template_file' => $this->_template, |
|
833 | - 'template_args' => apply_filters( |
|
834 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
835 | - array( |
|
836 | - 'reg_count' => $this->line_item_display->total_items(), |
|
837 | - 'transaction_details' => $transaction_details, |
|
838 | - 'available_payment_methods' => array(), |
|
839 | - ) |
|
840 | - ), |
|
841 | - ) |
|
842 | - ), |
|
843 | - ) |
|
844 | - ) |
|
845 | - ); |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - /** |
|
850 | - * _extra_hidden_inputs |
|
851 | - * |
|
852 | - * @param bool $no_payment_required |
|
853 | - * @return \EE_Form_Section_Proper |
|
854 | - * @throws \EE_Error |
|
855 | - */ |
|
856 | - private function _extra_hidden_inputs($no_payment_required = true) |
|
857 | - { |
|
858 | - return new EE_Form_Section_Proper( |
|
859 | - array( |
|
860 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
861 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
862 | - 'subsections' => array( |
|
863 | - 'spco_no_payment_required' => new EE_Hidden_Input( |
|
864 | - array( |
|
865 | - 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
866 | - 'html_name' => 'spco_no_payment_required', |
|
867 | - 'html_id' => 'spco-no-payment-required-payment_options', |
|
868 | - 'default' => $no_payment_required, |
|
869 | - ) |
|
870 | - ), |
|
871 | - 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
872 | - array( |
|
873 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
874 | - 'html_name' => 'spco_transaction_id', |
|
875 | - 'html_id' => 'spco-transaction-id', |
|
876 | - 'default' => $this->checkout->transaction->ID(), |
|
877 | - ) |
|
878 | - ), |
|
879 | - ), |
|
880 | - ) |
|
881 | - ); |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * _apply_registration_payments_to_amount_owing |
|
887 | - * |
|
888 | - * @access protected |
|
889 | - * @param array $registrations |
|
890 | - * @throws EE_Error |
|
891 | - */ |
|
892 | - protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
893 | - { |
|
894 | - $payments = array(); |
|
895 | - foreach ($registrations as $registration) { |
|
896 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
897 | - $payments += $registration->registration_payments(); |
|
898 | - } |
|
899 | - } |
|
900 | - if (! empty($payments)) { |
|
901 | - foreach ($payments as $payment) { |
|
902 | - if ($payment instanceof EE_Registration_Payment) { |
|
903 | - $this->checkout->amount_owing -= $payment->amount(); |
|
904 | - } |
|
905 | - } |
|
906 | - } |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * _reset_selected_method_of_payment |
|
912 | - * |
|
913 | - * @access private |
|
914 | - * @param bool $force_reset |
|
915 | - * @return void |
|
916 | - * @throws InvalidArgumentException |
|
917 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
918 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
919 | - */ |
|
920 | - private function _reset_selected_method_of_payment($force_reset = false) |
|
921 | - { |
|
922 | - $reset_payment_method = $force_reset |
|
923 | - ? true |
|
924 | - : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
925 | - if ($reset_payment_method) { |
|
926 | - $this->checkout->selected_method_of_payment = null; |
|
927 | - $this->checkout->payment_method = null; |
|
928 | - $this->checkout->billing_form = null; |
|
929 | - $this->_save_selected_method_of_payment(); |
|
930 | - } |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * _save_selected_method_of_payment |
|
936 | - * stores the selected_method_of_payment in the session |
|
937 | - * so that it's available for all subsequent requests including AJAX |
|
938 | - * |
|
939 | - * @access private |
|
940 | - * @param string $selected_method_of_payment |
|
941 | - * @return void |
|
942 | - * @throws InvalidArgumentException |
|
943 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
944 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
945 | - */ |
|
946 | - private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
947 | - { |
|
948 | - $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
949 | - ? $selected_method_of_payment |
|
950 | - : $this->checkout->selected_method_of_payment; |
|
951 | - EE_Registry::instance()->SSN->set_session_data( |
|
952 | - array('selected_method_of_payment' => $selected_method_of_payment) |
|
953 | - ); |
|
954 | - } |
|
955 | - |
|
956 | - |
|
957 | - /** |
|
958 | - * _setup_payment_options |
|
959 | - * |
|
960 | - * @return EE_Form_Section_Proper |
|
961 | - * @throws EE_Error |
|
962 | - * @throws InvalidArgumentException |
|
963 | - * @throws ReflectionException |
|
964 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
965 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
966 | - */ |
|
967 | - public function _setup_payment_options() |
|
968 | - { |
|
969 | - // load payment method classes |
|
970 | - $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
971 | - if (empty($this->checkout->available_payment_methods)) { |
|
972 | - EE_Error::add_error( |
|
973 | - apply_filters( |
|
974 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
975 | - sprintf( |
|
976 | - esc_html__( |
|
977 | - 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
978 | - 'event_espresso' |
|
979 | - ), |
|
980 | - '<br>', |
|
981 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
982 | - ) |
|
983 | - ), |
|
984 | - __FILE__, |
|
985 | - __FUNCTION__, |
|
986 | - __LINE__ |
|
987 | - ); |
|
988 | - } |
|
989 | - // switch up header depending on number of available payment methods |
|
990 | - $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
991 | - ? apply_filters( |
|
992 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
993 | - esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
994 | - ) |
|
995 | - : apply_filters( |
|
996 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
997 | - esc_html__('Method of Payment', 'event_espresso') |
|
998 | - ); |
|
999 | - $available_payment_methods = array( |
|
1000 | - // display the "Payment Method" header |
|
1001 | - 'payment_method_header' => new EE_Form_Section_HTML( |
|
1002 | - EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr') |
|
1003 | - ), |
|
1004 | - ); |
|
1005 | - // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
1006 | - $available_payment_method_options = array(); |
|
1007 | - $default_payment_method_option = array(); |
|
1008 | - // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
1009 | - $payment_methods_billing_info = array( |
|
1010 | - new EE_Form_Section_HTML( |
|
1011 | - EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
1012 | - ), |
|
1013 | - ); |
|
1014 | - // loop through payment methods |
|
1015 | - foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
1016 | - if ($payment_method instanceof EE_Payment_Method) { |
|
1017 | - $payment_method_button = EEH_HTML::img( |
|
1018 | - $payment_method->button_url(), |
|
1019 | - $payment_method->name(), |
|
1020 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1021 | - 'spco-payment-method-btn-img' |
|
1022 | - ); |
|
1023 | - // check if any payment methods are set as default |
|
1024 | - // if payment method is already selected OR nothing is selected and this payment method should be |
|
1025 | - // open_by_default |
|
1026 | - if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
1027 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1028 | - ) { |
|
1029 | - $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
1030 | - $this->_save_selected_method_of_payment(); |
|
1031 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1032 | - } else { |
|
1033 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1034 | - } |
|
1035 | - $payment_methods_billing_info[ $payment_method->slug( |
|
1036 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
1037 | - $payment_method |
|
1038 | - ); |
|
1039 | - } |
|
1040 | - } |
|
1041 | - // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
1042 | - // of PMs |
|
1043 | - $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
1044 | - // now generate the actual form inputs |
|
1045 | - $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
1046 | - $available_payment_method_options |
|
1047 | - ); |
|
1048 | - $available_payment_methods += $payment_methods_billing_info; |
|
1049 | - // build the available payment methods form |
|
1050 | - return new EE_Form_Section_Proper( |
|
1051 | - array( |
|
1052 | - 'html_id' => 'spco-available-methods-of-payment-dv', |
|
1053 | - 'subsections' => $available_payment_methods, |
|
1054 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1055 | - ) |
|
1056 | - ); |
|
1057 | - } |
|
1058 | - |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * _get_available_payment_methods |
|
1062 | - * |
|
1063 | - * @return EE_Payment_Method[] |
|
1064 | - * @throws EE_Error |
|
1065 | - * @throws InvalidArgumentException |
|
1066 | - * @throws ReflectionException |
|
1067 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1068 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1069 | - */ |
|
1070 | - protected function _get_available_payment_methods() |
|
1071 | - { |
|
1072 | - if (! empty($this->checkout->available_payment_methods)) { |
|
1073 | - return $this->checkout->available_payment_methods; |
|
1074 | - } |
|
1075 | - $available_payment_methods = array(); |
|
1076 | - // load EEM_Payment_Method |
|
1077 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
1078 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
1079 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
1080 | - // get all active payment methods |
|
1081 | - $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
1082 | - $this->checkout->transaction, |
|
1083 | - EEM_Payment_Method::scope_cart |
|
1084 | - ); |
|
1085 | - foreach ($payment_methods as $payment_method) { |
|
1086 | - if ($payment_method instanceof EE_Payment_Method) { |
|
1087 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1088 | - } |
|
1089 | - } |
|
1090 | - return $available_payment_methods; |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * _available_payment_method_inputs |
|
1096 | - * |
|
1097 | - * @access private |
|
1098 | - * @param array $available_payment_method_options |
|
1099 | - * @return \EE_Form_Section_Proper |
|
1100 | - */ |
|
1101 | - private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
1102 | - { |
|
1103 | - // generate inputs |
|
1104 | - return new EE_Form_Section_Proper( |
|
1105 | - array( |
|
1106 | - 'html_id' => 'ee-available-payment-method-inputs', |
|
1107 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1108 | - 'subsections' => array( |
|
1109 | - '' => new EE_Radio_Button_Input( |
|
1110 | - $available_payment_method_options, |
|
1111 | - array( |
|
1112 | - 'html_name' => 'selected_method_of_payment', |
|
1113 | - 'html_class' => 'spco-payment-method', |
|
1114 | - 'default' => $this->checkout->selected_method_of_payment, |
|
1115 | - 'label_size' => 11, |
|
1116 | - 'enforce_label_size' => true, |
|
1117 | - ) |
|
1118 | - ), |
|
1119 | - ), |
|
1120 | - ) |
|
1121 | - ); |
|
1122 | - } |
|
1123 | - |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * _payment_method_billing_info |
|
1127 | - * |
|
1128 | - * @access private |
|
1129 | - * @param EE_Payment_Method $payment_method |
|
1130 | - * @return EE_Form_Section_Proper |
|
1131 | - * @throws EE_Error |
|
1132 | - * @throws InvalidArgumentException |
|
1133 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1134 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1135 | - */ |
|
1136 | - private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
1137 | - { |
|
1138 | - $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
1139 | - ? true |
|
1140 | - : false; |
|
1141 | - // generate the billing form for payment method |
|
1142 | - $billing_form = $currently_selected |
|
1143 | - ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1144 | - : new EE_Form_Section_HTML(); |
|
1145 | - $this->checkout->billing_form = $currently_selected |
|
1146 | - ? $billing_form |
|
1147 | - : $this->checkout->billing_form; |
|
1148 | - // it's all in the details |
|
1149 | - $info_html = EEH_HTML::h3( |
|
1150 | - esc_html__('Important information regarding your payment', 'event_espresso'), |
|
1151 | - '', |
|
1152 | - 'spco-payment-method-hdr' |
|
1153 | - ); |
|
1154 | - // add some info regarding the step, either from what's saved in the admin, |
|
1155 | - // or a default string depending on whether the PM has a billing form or not |
|
1156 | - if ($payment_method->description()) { |
|
1157 | - $payment_method_info = $payment_method->description(); |
|
1158 | - } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1159 | - $payment_method_info = sprintf( |
|
1160 | - esc_html__( |
|
1161 | - 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
1162 | - 'event_espresso' |
|
1163 | - ), |
|
1164 | - $this->submit_button_text() |
|
1165 | - ); |
|
1166 | - } else { |
|
1167 | - $payment_method_info = sprintf( |
|
1168 | - esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1169 | - $this->submit_button_text() |
|
1170 | - ); |
|
1171 | - } |
|
1172 | - $info_html .= EEH_HTML::p( |
|
1173 | - apply_filters( |
|
1174 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
1175 | - $payment_method_info |
|
1176 | - ), |
|
1177 | - '', |
|
1178 | - 'spco-payment-method-desc ee-attention' |
|
1179 | - ); |
|
1180 | - return new EE_Form_Section_Proper( |
|
1181 | - array( |
|
1182 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1183 | - 'html_class' => 'spco-payment-method-info-dv', |
|
1184 | - // only display the selected or default PM |
|
1185 | - 'html_style' => $currently_selected ? '' : 'display:none;', |
|
1186 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1187 | - 'subsections' => array( |
|
1188 | - 'info' => new EE_Form_Section_HTML($info_html), |
|
1189 | - 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
1190 | - ), |
|
1191 | - ) |
|
1192 | - ); |
|
1193 | - } |
|
1194 | - |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * get_billing_form_html_for_payment_method |
|
1198 | - * |
|
1199 | - * @access public |
|
1200 | - * @return string |
|
1201 | - * @throws EE_Error |
|
1202 | - * @throws InvalidArgumentException |
|
1203 | - * @throws ReflectionException |
|
1204 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1205 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1206 | - */ |
|
1207 | - public function get_billing_form_html_for_payment_method() |
|
1208 | - { |
|
1209 | - // how have they chosen to pay? |
|
1210 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1211 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1212 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1213 | - return false; |
|
1214 | - } |
|
1215 | - if (apply_filters( |
|
1216 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1217 | - false |
|
1218 | - )) { |
|
1219 | - EE_Error::add_success( |
|
1220 | - apply_filters( |
|
1221 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1222 | - sprintf( |
|
1223 | - esc_html__( |
|
1224 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1225 | - 'event_espresso' |
|
1226 | - ), |
|
1227 | - $this->checkout->payment_method->name() |
|
1228 | - ) |
|
1229 | - ) |
|
1230 | - ); |
|
1231 | - } |
|
1232 | - // now generate billing form for selected method of payment |
|
1233 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1234 | - // fill form with attendee info if applicable |
|
1235 | - if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1236 | - && $this->checkout->transaction_has_primary_registrant() |
|
1237 | - ) { |
|
1238 | - $payment_method_billing_form->populate_from_attendee( |
|
1239 | - $this->checkout->transaction->primary_registration()->attendee() |
|
1240 | - ); |
|
1241 | - } |
|
1242 | - // and debug content |
|
1243 | - if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
1244 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1245 | - ) { |
|
1246 | - $payment_method_billing_form = |
|
1247 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1248 | - $payment_method_billing_form |
|
1249 | - ); |
|
1250 | - } |
|
1251 | - $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
1252 | - ? $payment_method_billing_form->get_html() |
|
1253 | - : ''; |
|
1254 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
1255 | - // localize validation rules for main form |
|
1256 | - $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
1257 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1258 | - return true; |
|
1259 | - } |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * _get_billing_form_for_payment_method |
|
1264 | - * |
|
1265 | - * @access private |
|
1266 | - * @param EE_Payment_Method $payment_method |
|
1267 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1268 | - * @throws EE_Error |
|
1269 | - * @throws InvalidArgumentException |
|
1270 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1271 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1272 | - */ |
|
1273 | - private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
1274 | - { |
|
1275 | - $billing_form = $payment_method->type_obj()->billing_form( |
|
1276 | - $this->checkout->transaction, |
|
1277 | - array('amount_owing' => $this->checkout->amount_owing) |
|
1278 | - ); |
|
1279 | - if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1280 | - if (apply_filters( |
|
1281 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1282 | - false |
|
1283 | - ) |
|
1284 | - && EE_Registry::instance()->REQ->is_set('payment_method') |
|
1285 | - ) { |
|
1286 | - EE_Error::add_success( |
|
1287 | - apply_filters( |
|
1288 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1289 | - sprintf( |
|
1290 | - esc_html__( |
|
1291 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1292 | - 'event_espresso' |
|
1293 | - ), |
|
1294 | - $payment_method->name() |
|
1295 | - ) |
|
1296 | - ) |
|
1297 | - ); |
|
1298 | - } |
|
1299 | - return apply_filters( |
|
1300 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
1301 | - $billing_form, |
|
1302 | - $payment_method |
|
1303 | - ); |
|
1304 | - } |
|
1305 | - // no actual billing form, so return empty HTML form section |
|
1306 | - return new EE_Form_Section_HTML(); |
|
1307 | - } |
|
1308 | - |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * _get_selected_method_of_payment |
|
1312 | - * |
|
1313 | - * @access private |
|
1314 | - * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
1315 | - * is not found in the incoming request |
|
1316 | - * @param string $request_param |
|
1317 | - * @return NULL|string |
|
1318 | - * @throws EE_Error |
|
1319 | - * @throws InvalidArgumentException |
|
1320 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1321 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1322 | - */ |
|
1323 | - private function _get_selected_method_of_payment( |
|
1324 | - $required = false, |
|
1325 | - $request_param = 'selected_method_of_payment' |
|
1326 | - ) { |
|
1327 | - // is selected_method_of_payment set in the request ? |
|
1328 | - $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
1329 | - if ($selected_method_of_payment) { |
|
1330 | - // sanitize it |
|
1331 | - $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1332 | - ? array_shift($selected_method_of_payment) |
|
1333 | - : $selected_method_of_payment; |
|
1334 | - $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1335 | - // store it in the session so that it's available for all subsequent requests including AJAX |
|
1336 | - $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1337 | - } else { |
|
1338 | - // or is is set in the session ? |
|
1339 | - $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
1340 | - 'selected_method_of_payment' |
|
1341 | - ); |
|
1342 | - } |
|
1343 | - // do ya really really gotta have it? |
|
1344 | - if (empty($selected_method_of_payment) && $required) { |
|
1345 | - EE_Error::add_error( |
|
1346 | - sprintf( |
|
1347 | - esc_html__( |
|
1348 | - 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
1349 | - 'event_espresso' |
|
1350 | - ), |
|
1351 | - '<br/>', |
|
1352 | - '<br/>', |
|
1353 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1354 | - ), |
|
1355 | - __FILE__, |
|
1356 | - __FUNCTION__, |
|
1357 | - __LINE__ |
|
1358 | - ); |
|
1359 | - return null; |
|
1360 | - } |
|
1361 | - return $selected_method_of_payment; |
|
1362 | - } |
|
1363 | - |
|
1364 | - |
|
1365 | - |
|
1366 | - |
|
1367 | - |
|
1368 | - |
|
1369 | - /********************************************************************************************************/ |
|
1370 | - /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
1371 | - /********************************************************************************************************/ |
|
1372 | - /** |
|
1373 | - * switch_payment_method |
|
1374 | - * |
|
1375 | - * @access public |
|
1376 | - * @return string |
|
1377 | - * @throws EE_Error |
|
1378 | - * @throws InvalidArgumentException |
|
1379 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1380 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1381 | - */ |
|
1382 | - public function switch_payment_method() |
|
1383 | - { |
|
1384 | - if (! $this->_verify_payment_method_is_set()) { |
|
1385 | - return false; |
|
1386 | - } |
|
1387 | - if (apply_filters( |
|
1388 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1389 | - false |
|
1390 | - )) { |
|
1391 | - EE_Error::add_success( |
|
1392 | - apply_filters( |
|
1393 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1394 | - sprintf( |
|
1395 | - esc_html__( |
|
1396 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1397 | - 'event_espresso' |
|
1398 | - ), |
|
1399 | - $this->checkout->payment_method->name() |
|
1400 | - ) |
|
1401 | - ) |
|
1402 | - ); |
|
1403 | - } |
|
1404 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1405 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1406 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1407 | - $this->checkout->payment_method |
|
1408 | - ); |
|
1409 | - } |
|
1410 | - // fill form with attendee info if applicable |
|
1411 | - if (apply_filters( |
|
1412 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
1413 | - ( |
|
1414 | - $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1415 | - && $this->checkout->transaction_has_primary_registrant() |
|
1416 | - ), |
|
1417 | - $this->checkout->billing_form, |
|
1418 | - $this->checkout->transaction |
|
1419 | - ) |
|
1420 | - ) { |
|
1421 | - $this->checkout->billing_form->populate_from_attendee( |
|
1422 | - $this->checkout->transaction->primary_registration()->attendee() |
|
1423 | - ); |
|
1424 | - } |
|
1425 | - // and debug content |
|
1426 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1427 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1428 | - ) { |
|
1429 | - $this->checkout->billing_form = |
|
1430 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1431 | - $this->checkout->billing_form |
|
1432 | - ); |
|
1433 | - } |
|
1434 | - // get html and validation rules for form |
|
1435 | - if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1436 | - $this->checkout->json_response->set_return_data( |
|
1437 | - array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
1438 | - ); |
|
1439 | - // localize validation rules for main form |
|
1440 | - $this->checkout->billing_form->localize_validation_rules(true); |
|
1441 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1442 | - } else { |
|
1443 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
1444 | - } |
|
1445 | - // prevents advancement to next step |
|
1446 | - $this->checkout->continue_reg = false; |
|
1447 | - return true; |
|
1448 | - } |
|
1449 | - |
|
1450 | - |
|
1451 | - /** |
|
1452 | - * _verify_payment_method_is_set |
|
1453 | - * |
|
1454 | - * @return bool |
|
1455 | - * @throws EE_Error |
|
1456 | - * @throws InvalidArgumentException |
|
1457 | - * @throws ReflectionException |
|
1458 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1459 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1460 | - */ |
|
1461 | - protected function _verify_payment_method_is_set() |
|
1462 | - { |
|
1463 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1464 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
1465 | - // how have they chosen to pay? |
|
1466 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1467 | - } else { |
|
1468 | - // choose your own adventure based on method_of_payment |
|
1469 | - switch ($this->checkout->selected_method_of_payment) { |
|
1470 | - case 'events_sold_out': |
|
1471 | - EE_Error::add_attention( |
|
1472 | - apply_filters( |
|
1473 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
1474 | - esc_html__( |
|
1475 | - 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1476 | - 'event_espresso' |
|
1477 | - ) |
|
1478 | - ), |
|
1479 | - __FILE__, |
|
1480 | - __FUNCTION__, |
|
1481 | - __LINE__ |
|
1482 | - ); |
|
1483 | - return false; |
|
1484 | - break; |
|
1485 | - case 'payments_closed': |
|
1486 | - EE_Error::add_attention( |
|
1487 | - apply_filters( |
|
1488 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
1489 | - esc_html__( |
|
1490 | - 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
1491 | - 'event_espresso' |
|
1492 | - ) |
|
1493 | - ), |
|
1494 | - __FILE__, |
|
1495 | - __FUNCTION__, |
|
1496 | - __LINE__ |
|
1497 | - ); |
|
1498 | - return false; |
|
1499 | - break; |
|
1500 | - case 'no_payment_required': |
|
1501 | - EE_Error::add_attention( |
|
1502 | - apply_filters( |
|
1503 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
1504 | - esc_html__( |
|
1505 | - 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
1506 | - 'event_espresso' |
|
1507 | - ) |
|
1508 | - ), |
|
1509 | - __FILE__, |
|
1510 | - __FUNCTION__, |
|
1511 | - __LINE__ |
|
1512 | - ); |
|
1513 | - return false; |
|
1514 | - break; |
|
1515 | - default: |
|
1516 | - } |
|
1517 | - } |
|
1518 | - // verify payment method |
|
1519 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1520 | - // get payment method for selected method of payment |
|
1521 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1522 | - } |
|
1523 | - return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
1524 | - } |
|
1525 | - |
|
1526 | - |
|
1527 | - |
|
1528 | - /********************************************************************************************************/ |
|
1529 | - /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
1530 | - /********************************************************************************************************/ |
|
1531 | - /** |
|
1532 | - * save_payer_details_via_ajax |
|
1533 | - * |
|
1534 | - * @return void |
|
1535 | - * @throws EE_Error |
|
1536 | - * @throws InvalidArgumentException |
|
1537 | - * @throws ReflectionException |
|
1538 | - * @throws RuntimeException |
|
1539 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1540 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1541 | - */ |
|
1542 | - public function save_payer_details_via_ajax() |
|
1543 | - { |
|
1544 | - if (! $this->_verify_payment_method_is_set()) { |
|
1545 | - return; |
|
1546 | - } |
|
1547 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1548 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1549 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1550 | - $this->checkout->payment_method |
|
1551 | - ); |
|
1552 | - } |
|
1553 | - // generate primary attendee from payer info if applicable |
|
1554 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1555 | - $attendee = $this->_create_attendee_from_request_data(); |
|
1556 | - if ($attendee instanceof EE_Attendee) { |
|
1557 | - foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1558 | - if ($registration->is_primary_registrant()) { |
|
1559 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1560 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1561 | - $registration->set_attendee_id($attendee->ID()); |
|
1562 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1563 | - } |
|
1564 | - } |
|
1565 | - } |
|
1566 | - } |
|
1567 | - } |
|
1568 | - |
|
1569 | - |
|
1570 | - /** |
|
1571 | - * create_attendee_from_request_data |
|
1572 | - * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
1573 | - * |
|
1574 | - * @return EE_Attendee |
|
1575 | - * @throws EE_Error |
|
1576 | - * @throws InvalidArgumentException |
|
1577 | - * @throws ReflectionException |
|
1578 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1579 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1580 | - */ |
|
1581 | - protected function _create_attendee_from_request_data() |
|
1582 | - { |
|
1583 | - // get State ID |
|
1584 | - $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
1585 | - if (! empty($STA_ID)) { |
|
1586 | - // can we get state object from name ? |
|
1587 | - EE_Registry::instance()->load_model('State'); |
|
1588 | - $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
1589 | - $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1590 | - } |
|
1591 | - // get Country ISO |
|
1592 | - $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
1593 | - if (! empty($CNT_ISO)) { |
|
1594 | - // can we get country object from name ? |
|
1595 | - EE_Registry::instance()->load_model('Country'); |
|
1596 | - $country = EEM_Country::instance()->get_col( |
|
1597 | - array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
1598 | - 'CNT_ISO' |
|
1599 | - ); |
|
1600 | - $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1601 | - } |
|
1602 | - // grab attendee data |
|
1603 | - $attendee_data = array( |
|
1604 | - 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
1605 | - 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
1606 | - 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
1607 | - 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
1608 | - 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
1609 | - 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
1610 | - 'STA_ID' => $STA_ID, |
|
1611 | - 'CNT_ISO' => $CNT_ISO, |
|
1612 | - 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
1613 | - 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
1614 | - ); |
|
1615 | - // validate the email address since it is the most important piece of info |
|
1616 | - if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
1617 | - EE_Error::add_error( |
|
1618 | - esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
1619 | - __FILE__, |
|
1620 | - __FUNCTION__, |
|
1621 | - __LINE__ |
|
1622 | - ); |
|
1623 | - } |
|
1624 | - // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
1625 | - // AND email address |
|
1626 | - if (! empty($attendee_data['ATT_fname']) |
|
1627 | - && ! empty($attendee_data['ATT_lname']) |
|
1628 | - && ! empty($attendee_data['ATT_email']) |
|
1629 | - ) { |
|
1630 | - $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
1631 | - array( |
|
1632 | - 'ATT_fname' => $attendee_data['ATT_fname'], |
|
1633 | - 'ATT_lname' => $attendee_data['ATT_lname'], |
|
1634 | - 'ATT_email' => $attendee_data['ATT_email'], |
|
1635 | - ) |
|
1636 | - ); |
|
1637 | - if ($existing_attendee instanceof EE_Attendee) { |
|
1638 | - return $existing_attendee; |
|
1639 | - } |
|
1640 | - } |
|
1641 | - // no existing attendee? kk let's create a new one |
|
1642 | - // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
1643 | - // don't exist |
|
1644 | - $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1645 | - ? $attendee_data['ATT_fname'] |
|
1646 | - : $attendee_data['ATT_email']; |
|
1647 | - $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1648 | - ? $attendee_data['ATT_lname'] |
|
1649 | - : $attendee_data['ATT_email']; |
|
1650 | - return EE_Attendee::new_instance($attendee_data); |
|
1651 | - } |
|
1652 | - |
|
1653 | - |
|
1654 | - |
|
1655 | - /********************************************************************************************************/ |
|
1656 | - /**************************************** PROCESS REG STEP *****************************************/ |
|
1657 | - /********************************************************************************************************/ |
|
1658 | - /** |
|
1659 | - * process_reg_step |
|
1660 | - * |
|
1661 | - * @return bool |
|
1662 | - * @throws EE_Error |
|
1663 | - * @throws InvalidArgumentException |
|
1664 | - * @throws ReflectionException |
|
1665 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1666 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1667 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1668 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1669 | - */ |
|
1670 | - public function process_reg_step() |
|
1671 | - { |
|
1672 | - // how have they chosen to pay? |
|
1673 | - $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
1674 | - ? 'no_payment_required' |
|
1675 | - : $this->_get_selected_method_of_payment(true); |
|
1676 | - // choose your own adventure based on method_of_payment |
|
1677 | - switch ($this->checkout->selected_method_of_payment) { |
|
1678 | - case 'events_sold_out': |
|
1679 | - $this->checkout->redirect = true; |
|
1680 | - $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
1681 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1682 | - // mark this reg step as completed |
|
1683 | - $this->set_completed(); |
|
1684 | - return false; |
|
1685 | - break; |
|
1686 | - |
|
1687 | - case 'payments_closed': |
|
1688 | - if (apply_filters( |
|
1689 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
1690 | - false |
|
1691 | - )) { |
|
1692 | - EE_Error::add_success( |
|
1693 | - esc_html__('no payment required at this time.', 'event_espresso'), |
|
1694 | - __FILE__, |
|
1695 | - __FUNCTION__, |
|
1696 | - __LINE__ |
|
1697 | - ); |
|
1698 | - } |
|
1699 | - // mark this reg step as completed |
|
1700 | - $this->set_completed(); |
|
1701 | - return true; |
|
1702 | - break; |
|
1703 | - |
|
1704 | - case 'no_payment_required': |
|
1705 | - if (apply_filters( |
|
1706 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
1707 | - false |
|
1708 | - )) { |
|
1709 | - EE_Error::add_success( |
|
1710 | - esc_html__('no payment required.', 'event_espresso'), |
|
1711 | - __FILE__, |
|
1712 | - __FUNCTION__, |
|
1713 | - __LINE__ |
|
1714 | - ); |
|
1715 | - } |
|
1716 | - // mark this reg step as completed |
|
1717 | - $this->set_completed(); |
|
1718 | - return true; |
|
1719 | - break; |
|
1720 | - |
|
1721 | - default: |
|
1722 | - $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
1723 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
1724 | - ); |
|
1725 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
1726 | - $registrations, |
|
1727 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
1728 | - ); |
|
1729 | - // calculate difference between the two arrays |
|
1730 | - $registrations = array_diff($registrations, $ejected_registrations); |
|
1731 | - if (empty($registrations)) { |
|
1732 | - $this->_redirect_because_event_sold_out(); |
|
1733 | - return false; |
|
1734 | - } |
|
1735 | - $payment_successful = $this->_process_payment(); |
|
1736 | - if ($payment_successful) { |
|
1737 | - $this->checkout->continue_reg = true; |
|
1738 | - $this->_maybe_set_completed($this->checkout->payment_method); |
|
1739 | - } else { |
|
1740 | - $this->checkout->continue_reg = false; |
|
1741 | - } |
|
1742 | - return $payment_successful; |
|
1743 | - } |
|
1744 | - } |
|
1745 | - |
|
1746 | - |
|
1747 | - /** |
|
1748 | - * _redirect_because_event_sold_out |
|
1749 | - * |
|
1750 | - * @access protected |
|
1751 | - * @return void |
|
1752 | - */ |
|
1753 | - protected function _redirect_because_event_sold_out() |
|
1754 | - { |
|
1755 | - $this->checkout->continue_reg = false; |
|
1756 | - // set redirect URL |
|
1757 | - $this->checkout->redirect_url = add_query_arg( |
|
1758 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1759 | - $this->checkout->current_step->reg_step_url() |
|
1760 | - ); |
|
1761 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1762 | - } |
|
1763 | - |
|
1764 | - |
|
1765 | - /** |
|
1766 | - * _maybe_set_completed |
|
1767 | - * |
|
1768 | - * @access protected |
|
1769 | - * @param \EE_Payment_Method $payment_method |
|
1770 | - * @return void |
|
1771 | - * @throws \EE_Error |
|
1772 | - */ |
|
1773 | - protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
1774 | - { |
|
1775 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
1776 | - case EE_PMT_Base::offsite: |
|
1777 | - break; |
|
1778 | - case EE_PMT_Base::onsite: |
|
1779 | - case EE_PMT_Base::offline: |
|
1780 | - // mark this reg step as completed |
|
1781 | - $this->set_completed(); |
|
1782 | - break; |
|
1783 | - } |
|
1784 | - } |
|
1785 | - |
|
1786 | - |
|
1787 | - /** |
|
1788 | - * update_reg_step |
|
1789 | - * this is the final step after a user revisits the site to retry a payment |
|
1790 | - * |
|
1791 | - * @return bool |
|
1792 | - * @throws EE_Error |
|
1793 | - * @throws InvalidArgumentException |
|
1794 | - * @throws ReflectionException |
|
1795 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1796 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1797 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1798 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1799 | - */ |
|
1800 | - public function update_reg_step() |
|
1801 | - { |
|
1802 | - $success = true; |
|
1803 | - // if payment required |
|
1804 | - if ($this->checkout->transaction->total() > 0) { |
|
1805 | - do_action( |
|
1806 | - 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
1807 | - $this->checkout->transaction |
|
1808 | - ); |
|
1809 | - // attempt payment via payment method |
|
1810 | - $success = $this->process_reg_step(); |
|
1811 | - } |
|
1812 | - if ($success && ! $this->checkout->redirect) { |
|
1813 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
1814 | - $this->checkout->transaction->ID() |
|
1815 | - ); |
|
1816 | - // set return URL |
|
1817 | - $this->checkout->redirect_url = add_query_arg( |
|
1818 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1819 | - $this->checkout->thank_you_page_url |
|
1820 | - ); |
|
1821 | - } |
|
1822 | - return $success; |
|
1823 | - } |
|
1824 | - |
|
1825 | - |
|
1826 | - /** |
|
1827 | - * _process_payment |
|
1828 | - * |
|
1829 | - * @access private |
|
1830 | - * @return bool |
|
1831 | - * @throws EE_Error |
|
1832 | - * @throws InvalidArgumentException |
|
1833 | - * @throws ReflectionException |
|
1834 | - * @throws RuntimeException |
|
1835 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1836 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1837 | - */ |
|
1838 | - private function _process_payment() |
|
1839 | - { |
|
1840 | - // basically confirm that the event hasn't sold out since they hit the page |
|
1841 | - if (! $this->_last_second_ticket_verifications()) { |
|
1842 | - return false; |
|
1843 | - } |
|
1844 | - // ya gotta make a choice man |
|
1845 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
1846 | - $this->checkout->json_response->set_plz_select_method_of_payment( |
|
1847 | - esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
1848 | - ); |
|
1849 | - return false; |
|
1850 | - } |
|
1851 | - // get EE_Payment_Method object |
|
1852 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1853 | - return false; |
|
1854 | - } |
|
1855 | - // setup billing form |
|
1856 | - if ($this->checkout->payment_method->is_on_site()) { |
|
1857 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1858 | - $this->checkout->payment_method |
|
1859 | - ); |
|
1860 | - // bad billing form ? |
|
1861 | - if (! $this->_billing_form_is_valid()) { |
|
1862 | - return false; |
|
1863 | - } |
|
1864 | - } |
|
1865 | - // ensure primary registrant has been fully processed |
|
1866 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1867 | - return false; |
|
1868 | - } |
|
1869 | - // if session is close to expiring (under 10 minutes by default) |
|
1870 | - if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
1871 | - // add some time to session expiration so that payment can be completed |
|
1872 | - EE_Registry::instance()->SSN->extend_expiration(); |
|
1873 | - } |
|
1874 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
1875 | - // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
1876 | - // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
1877 | - // for events with a default reg status of Approved |
|
1878 | - // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
1879 | - // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
1880 | - // ); |
|
1881 | - // attempt payment |
|
1882 | - $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
1883 | - // process results |
|
1884 | - $payment = $this->_validate_payment($payment); |
|
1885 | - $payment = $this->_post_payment_processing($payment); |
|
1886 | - // verify payment |
|
1887 | - if ($payment instanceof EE_Payment) { |
|
1888 | - // store that for later |
|
1889 | - $this->checkout->payment = $payment; |
|
1890 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
1891 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1892 | - $payment_status = $payment->status(); |
|
1893 | - if ($payment_status === EEM_Payment::status_id_approved |
|
1894 | - || $payment_status === EEM_Payment::status_id_pending |
|
1895 | - ) { |
|
1896 | - return true; |
|
1897 | - } else { |
|
1898 | - return false; |
|
1899 | - } |
|
1900 | - } elseif ($payment === true) { |
|
1901 | - // please note that offline payment methods will NOT make a payment, |
|
1902 | - // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
1903 | - $this->checkout->payment = $payment; |
|
1904 | - return true; |
|
1905 | - } |
|
1906 | - // where's my money? |
|
1907 | - return false; |
|
1908 | - } |
|
1909 | - |
|
1910 | - |
|
1911 | - /** |
|
1912 | - * _last_second_ticket_verifications |
|
1913 | - * |
|
1914 | - * @access public |
|
1915 | - * @return bool |
|
1916 | - * @throws EE_Error |
|
1917 | - */ |
|
1918 | - protected function _last_second_ticket_verifications() |
|
1919 | - { |
|
1920 | - // don't bother re-validating if not a return visit |
|
1921 | - if (! $this->checkout->revisit) { |
|
1922 | - return true; |
|
1923 | - } |
|
1924 | - $registrations = $this->checkout->transaction->registrations(); |
|
1925 | - if (empty($registrations)) { |
|
1926 | - return false; |
|
1927 | - } |
|
1928 | - foreach ($registrations as $registration) { |
|
1929 | - if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
1930 | - $event = $registration->event_obj(); |
|
1931 | - if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
1932 | - EE_Error::add_error( |
|
1933 | - apply_filters( |
|
1934 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
1935 | - sprintf( |
|
1936 | - esc_html__( |
|
1937 | - 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
1938 | - 'event_espresso' |
|
1939 | - ), |
|
1940 | - $event->name() |
|
1941 | - ) |
|
1942 | - ), |
|
1943 | - __FILE__, |
|
1944 | - __FUNCTION__, |
|
1945 | - __LINE__ |
|
1946 | - ); |
|
1947 | - return false; |
|
1948 | - } |
|
1949 | - } |
|
1950 | - } |
|
1951 | - return true; |
|
1952 | - } |
|
1953 | - |
|
1954 | - |
|
1955 | - /** |
|
1956 | - * redirect_form |
|
1957 | - * |
|
1958 | - * @access public |
|
1959 | - * @return bool |
|
1960 | - * @throws EE_Error |
|
1961 | - * @throws InvalidArgumentException |
|
1962 | - * @throws ReflectionException |
|
1963 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1964 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1965 | - */ |
|
1966 | - public function redirect_form() |
|
1967 | - { |
|
1968 | - $payment_method_billing_info = $this->_payment_method_billing_info( |
|
1969 | - $this->_get_payment_method_for_selected_method_of_payment() |
|
1970 | - ); |
|
1971 | - $html = $payment_method_billing_info->get_html(); |
|
1972 | - $html .= $this->checkout->redirect_form; |
|
1973 | - EE_Registry::instance()->REQ->add_output($html); |
|
1974 | - return true; |
|
1975 | - } |
|
1976 | - |
|
1977 | - |
|
1978 | - /** |
|
1979 | - * _billing_form_is_valid |
|
1980 | - * |
|
1981 | - * @access private |
|
1982 | - * @return bool |
|
1983 | - * @throws \EE_Error |
|
1984 | - */ |
|
1985 | - private function _billing_form_is_valid() |
|
1986 | - { |
|
1987 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1988 | - return true; |
|
1989 | - } |
|
1990 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
1991 | - if ($this->checkout->billing_form->was_submitted()) { |
|
1992 | - $this->checkout->billing_form->receive_form_submission(); |
|
1993 | - if ($this->checkout->billing_form->is_valid()) { |
|
1994 | - return true; |
|
1995 | - } |
|
1996 | - $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
1997 | - $error_strings = array(); |
|
1998 | - foreach ($validation_errors as $validation_error) { |
|
1999 | - if ($validation_error instanceof EE_Validation_Error) { |
|
2000 | - $form_section = $validation_error->get_form_section(); |
|
2001 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
2002 | - $label = $form_section->html_label_text(); |
|
2003 | - } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
2004 | - $label = $form_section->name(); |
|
2005 | - } else { |
|
2006 | - $label = esc_html__('Validation Error', 'event_espresso'); |
|
2007 | - } |
|
2008 | - $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
2009 | - } |
|
2010 | - } |
|
2011 | - EE_Error::add_error( |
|
2012 | - sprintf( |
|
2013 | - esc_html__( |
|
2014 | - 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
2015 | - 'event_espresso' |
|
2016 | - ), |
|
2017 | - '<br/>', |
|
2018 | - implode('<br/>', $error_strings) |
|
2019 | - ), |
|
2020 | - __FILE__, |
|
2021 | - __FUNCTION__, |
|
2022 | - __LINE__ |
|
2023 | - ); |
|
2024 | - } else { |
|
2025 | - EE_Error::add_error( |
|
2026 | - esc_html__( |
|
2027 | - 'The billing form was not submitted or something prevented it\'s submission.', |
|
2028 | - 'event_espresso' |
|
2029 | - ), |
|
2030 | - __FILE__, |
|
2031 | - __FUNCTION__, |
|
2032 | - __LINE__ |
|
2033 | - ); |
|
2034 | - } |
|
2035 | - } else { |
|
2036 | - EE_Error::add_error( |
|
2037 | - esc_html__( |
|
2038 | - 'The submitted billing form is invalid possibly due to a technical reason.', |
|
2039 | - 'event_espresso' |
|
2040 | - ), |
|
2041 | - __FILE__, |
|
2042 | - __FUNCTION__, |
|
2043 | - __LINE__ |
|
2044 | - ); |
|
2045 | - } |
|
2046 | - return false; |
|
2047 | - } |
|
2048 | - |
|
2049 | - |
|
2050 | - /** |
|
2051 | - * _setup_primary_registrant_prior_to_payment |
|
2052 | - * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
2053 | - * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
2054 | - * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
2055 | - * yet) |
|
2056 | - * |
|
2057 | - * @access private |
|
2058 | - * @return bool |
|
2059 | - * @throws EE_Error |
|
2060 | - * @throws InvalidArgumentException |
|
2061 | - * @throws ReflectionException |
|
2062 | - * @throws RuntimeException |
|
2063 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2064 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2065 | - */ |
|
2066 | - private function _setup_primary_registrant_prior_to_payment() |
|
2067 | - { |
|
2068 | - // check if transaction has a primary registrant and that it has a related Attendee object |
|
2069 | - // if not, then we need to at least gather some primary registrant data before attempting payment |
|
2070 | - if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
2071 | - && ! $this->checkout->transaction_has_primary_registrant() |
|
2072 | - && ! $this->_capture_primary_registration_data_from_billing_form() |
|
2073 | - ) { |
|
2074 | - return false; |
|
2075 | - } |
|
2076 | - // because saving an object clears it's cache, we need to do the chevy shuffle |
|
2077 | - // grab the primary_registration object |
|
2078 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2079 | - // at this point we'll consider a TXN to not have been failed |
|
2080 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
2081 | - // save the TXN ( which clears cached copy of primary_registration) |
|
2082 | - $this->checkout->transaction->save(); |
|
2083 | - // grab TXN ID and save it to the primary_registration |
|
2084 | - $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
2085 | - // save what we have so far |
|
2086 | - $primary_registration->save(); |
|
2087 | - return true; |
|
2088 | - } |
|
2089 | - |
|
2090 | - |
|
2091 | - /** |
|
2092 | - * _capture_primary_registration_data_from_billing_form |
|
2093 | - * |
|
2094 | - * @access private |
|
2095 | - * @return bool |
|
2096 | - * @throws EE_Error |
|
2097 | - * @throws InvalidArgumentException |
|
2098 | - * @throws ReflectionException |
|
2099 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2100 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2101 | - */ |
|
2102 | - private function _capture_primary_registration_data_from_billing_form() |
|
2103 | - { |
|
2104 | - // convert billing form data into an attendee |
|
2105 | - $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
2106 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2107 | - EE_Error::add_error( |
|
2108 | - sprintf( |
|
2109 | - esc_html__( |
|
2110 | - 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2111 | - 'event_espresso' |
|
2112 | - ), |
|
2113 | - '<br/>', |
|
2114 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2115 | - ), |
|
2116 | - __FILE__, |
|
2117 | - __FUNCTION__, |
|
2118 | - __LINE__ |
|
2119 | - ); |
|
2120 | - return false; |
|
2121 | - } |
|
2122 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2123 | - if (! $primary_registration instanceof EE_Registration) { |
|
2124 | - EE_Error::add_error( |
|
2125 | - sprintf( |
|
2126 | - esc_html__( |
|
2127 | - 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2128 | - 'event_espresso' |
|
2129 | - ), |
|
2130 | - '<br/>', |
|
2131 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2132 | - ), |
|
2133 | - __FILE__, |
|
2134 | - __FUNCTION__, |
|
2135 | - __LINE__ |
|
2136 | - ); |
|
2137 | - return false; |
|
2138 | - } |
|
2139 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2140 | - instanceof |
|
2141 | - EE_Attendee |
|
2142 | - ) { |
|
2143 | - EE_Error::add_error( |
|
2144 | - sprintf( |
|
2145 | - esc_html__( |
|
2146 | - 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2147 | - 'event_espresso' |
|
2148 | - ), |
|
2149 | - '<br/>', |
|
2150 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2151 | - ), |
|
2152 | - __FILE__, |
|
2153 | - __FUNCTION__, |
|
2154 | - __LINE__ |
|
2155 | - ); |
|
2156 | - return false; |
|
2157 | - } |
|
2158 | - /** @type EE_Registration_Processor $registration_processor */ |
|
2159 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
2160 | - // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
2161 | - $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
2162 | - return true; |
|
2163 | - } |
|
2164 | - |
|
2165 | - |
|
2166 | - /** |
|
2167 | - * _get_payment_method_for_selected_method_of_payment |
|
2168 | - * retrieves a valid payment method |
|
2169 | - * |
|
2170 | - * @access public |
|
2171 | - * @return EE_Payment_Method |
|
2172 | - * @throws EE_Error |
|
2173 | - * @throws InvalidArgumentException |
|
2174 | - * @throws ReflectionException |
|
2175 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2176 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2177 | - */ |
|
2178 | - private function _get_payment_method_for_selected_method_of_payment() |
|
2179 | - { |
|
2180 | - if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2181 | - $this->_redirect_because_event_sold_out(); |
|
2182 | - return null; |
|
2183 | - } |
|
2184 | - // get EE_Payment_Method object |
|
2185 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2186 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2187 | - } else { |
|
2188 | - // load EEM_Payment_Method |
|
2189 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
2190 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
2191 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
2192 | - $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2193 | - } |
|
2194 | - // verify $payment_method |
|
2195 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
2196 | - // not a payment |
|
2197 | - EE_Error::add_error( |
|
2198 | - sprintf( |
|
2199 | - esc_html__( |
|
2200 | - 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2201 | - 'event_espresso' |
|
2202 | - ), |
|
2203 | - '<br/>', |
|
2204 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2205 | - ), |
|
2206 | - __FILE__, |
|
2207 | - __FUNCTION__, |
|
2208 | - __LINE__ |
|
2209 | - ); |
|
2210 | - return null; |
|
2211 | - } |
|
2212 | - // and verify it has a valid Payment_Method Type object |
|
2213 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2214 | - // not a payment |
|
2215 | - EE_Error::add_error( |
|
2216 | - sprintf( |
|
2217 | - esc_html__( |
|
2218 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2219 | - 'event_espresso' |
|
2220 | - ), |
|
2221 | - '<br/>', |
|
2222 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2223 | - ), |
|
2224 | - __FILE__, |
|
2225 | - __FUNCTION__, |
|
2226 | - __LINE__ |
|
2227 | - ); |
|
2228 | - return null; |
|
2229 | - } |
|
2230 | - return $payment_method; |
|
2231 | - } |
|
2232 | - |
|
2233 | - |
|
2234 | - /** |
|
2235 | - * _attempt_payment |
|
2236 | - * |
|
2237 | - * @access private |
|
2238 | - * @type EE_Payment_Method $payment_method |
|
2239 | - * @return mixed EE_Payment | boolean |
|
2240 | - * @throws EE_Error |
|
2241 | - * @throws InvalidArgumentException |
|
2242 | - * @throws ReflectionException |
|
2243 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2244 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2245 | - */ |
|
2246 | - private function _attempt_payment(EE_Payment_Method $payment_method) |
|
2247 | - { |
|
2248 | - $payment = null; |
|
2249 | - $this->checkout->transaction->save(); |
|
2250 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2251 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2252 | - return false; |
|
2253 | - } |
|
2254 | - try { |
|
2255 | - $payment_processor->set_revisit($this->checkout->revisit); |
|
2256 | - // generate payment object |
|
2257 | - $payment = $payment_processor->process_payment( |
|
2258 | - $payment_method, |
|
2259 | - $this->checkout->transaction, |
|
2260 | - $this->checkout->amount_owing, |
|
2261 | - $this->checkout->billing_form, |
|
2262 | - $this->_get_return_url($payment_method), |
|
2263 | - 'CART', |
|
2264 | - $this->checkout->admin_request, |
|
2265 | - true, |
|
2266 | - $this->reg_step_url() |
|
2267 | - ); |
|
2268 | - } catch (Exception $e) { |
|
2269 | - $this->_handle_payment_processor_exception($e); |
|
2270 | - } |
|
2271 | - return $payment; |
|
2272 | - } |
|
2273 | - |
|
2274 | - |
|
2275 | - /** |
|
2276 | - * _handle_payment_processor_exception |
|
2277 | - * |
|
2278 | - * @access protected |
|
2279 | - * @param \Exception $e |
|
2280 | - * @return void |
|
2281 | - * @throws EE_Error |
|
2282 | - * @throws InvalidArgumentException |
|
2283 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2284 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2285 | - */ |
|
2286 | - protected function _handle_payment_processor_exception(Exception $e) |
|
2287 | - { |
|
2288 | - EE_Error::add_error( |
|
2289 | - sprintf( |
|
2290 | - esc_html__( |
|
2291 | - 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
2292 | - 'event_espresso' |
|
2293 | - ), |
|
2294 | - '<br/>', |
|
2295 | - EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2296 | - $e->getMessage(), |
|
2297 | - $e->getFile(), |
|
2298 | - $e->getLine() |
|
2299 | - ), |
|
2300 | - __FILE__, |
|
2301 | - __FUNCTION__, |
|
2302 | - __LINE__ |
|
2303 | - ); |
|
2304 | - } |
|
2305 | - |
|
2306 | - |
|
2307 | - /** |
|
2308 | - * _get_return_url |
|
2309 | - * |
|
2310 | - * @access protected |
|
2311 | - * @param \EE_Payment_Method $payment_method |
|
2312 | - * @return string |
|
2313 | - * @throws \EE_Error |
|
2314 | - */ |
|
2315 | - protected function _get_return_url(EE_Payment_Method $payment_method) |
|
2316 | - { |
|
2317 | - $return_url = ''; |
|
2318 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
2319 | - case EE_PMT_Base::offsite: |
|
2320 | - $return_url = add_query_arg( |
|
2321 | - array( |
|
2322 | - 'action' => 'process_gateway_response', |
|
2323 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2324 | - 'spco_txn' => $this->checkout->transaction->ID(), |
|
2325 | - ), |
|
2326 | - $this->reg_step_url() |
|
2327 | - ); |
|
2328 | - break; |
|
2329 | - case EE_PMT_Base::onsite: |
|
2330 | - case EE_PMT_Base::offline: |
|
2331 | - $return_url = $this->checkout->next_step->reg_step_url(); |
|
2332 | - break; |
|
2333 | - } |
|
2334 | - return $return_url; |
|
2335 | - } |
|
2336 | - |
|
2337 | - |
|
2338 | - /** |
|
2339 | - * _validate_payment |
|
2340 | - * |
|
2341 | - * @access private |
|
2342 | - * @param EE_Payment $payment |
|
2343 | - * @return EE_Payment|FALSE |
|
2344 | - * @throws EE_Error |
|
2345 | - * @throws InvalidArgumentException |
|
2346 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2347 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2348 | - */ |
|
2349 | - private function _validate_payment($payment = null) |
|
2350 | - { |
|
2351 | - if ($this->checkout->payment_method->is_off_line()) { |
|
2352 | - return true; |
|
2353 | - } |
|
2354 | - // verify payment object |
|
2355 | - if (! $payment instanceof EE_Payment) { |
|
2356 | - // not a payment |
|
2357 | - EE_Error::add_error( |
|
2358 | - sprintf( |
|
2359 | - esc_html__( |
|
2360 | - 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
2361 | - 'event_espresso' |
|
2362 | - ), |
|
2363 | - '<br/>', |
|
2364 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2365 | - ), |
|
2366 | - __FILE__, |
|
2367 | - __FUNCTION__, |
|
2368 | - __LINE__ |
|
2369 | - ); |
|
2370 | - return false; |
|
2371 | - } |
|
2372 | - return $payment; |
|
2373 | - } |
|
2374 | - |
|
2375 | - |
|
2376 | - /** |
|
2377 | - * _post_payment_processing |
|
2378 | - * |
|
2379 | - * @access private |
|
2380 | - * @param EE_Payment|bool $payment |
|
2381 | - * @return bool |
|
2382 | - * @throws EE_Error |
|
2383 | - * @throws InvalidArgumentException |
|
2384 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2385 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2386 | - */ |
|
2387 | - private function _post_payment_processing($payment = null) |
|
2388 | - { |
|
2389 | - // Off-Line payment? |
|
2390 | - if ($payment === true) { |
|
2391 | - // $this->_setup_redirect_for_next_step(); |
|
2392 | - return true; |
|
2393 | - // On-Site payment? |
|
2394 | - } elseif ($this->checkout->payment_method->is_on_site()) { |
|
2395 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2396 | - // $this->_setup_redirect_for_next_step(); |
|
2397 | - $this->checkout->continue_reg = false; |
|
2398 | - } |
|
2399 | - // Off-Site payment? |
|
2400 | - } elseif ($this->checkout->payment_method->is_off_site()) { |
|
2401 | - // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
2402 | - if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
2403 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2404 | - $this->checkout->redirect = true; |
|
2405 | - $this->checkout->redirect_form = $payment->redirect_form(); |
|
2406 | - $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2407 | - // set JSON response |
|
2408 | - $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2409 | - // and lastly, let's bump the payment status to pending |
|
2410 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
2411 | - $payment->save(); |
|
2412 | - } else { |
|
2413 | - // not a payment |
|
2414 | - $this->checkout->continue_reg = false; |
|
2415 | - EE_Error::add_error( |
|
2416 | - sprintf( |
|
2417 | - esc_html__( |
|
2418 | - 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
2419 | - 'event_espresso' |
|
2420 | - ), |
|
2421 | - '<br/>', |
|
2422 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2423 | - ), |
|
2424 | - __FILE__, |
|
2425 | - __FUNCTION__, |
|
2426 | - __LINE__ |
|
2427 | - ); |
|
2428 | - } |
|
2429 | - } else { |
|
2430 | - // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
2431 | - $this->checkout->continue_reg = false; |
|
2432 | - return false; |
|
2433 | - } |
|
2434 | - return $payment; |
|
2435 | - } |
|
2436 | - |
|
2437 | - |
|
2438 | - /** |
|
2439 | - * _process_payment_status |
|
2440 | - * |
|
2441 | - * @access private |
|
2442 | - * @type EE_Payment $payment |
|
2443 | - * @param string $payment_occurs |
|
2444 | - * @return bool |
|
2445 | - * @throws EE_Error |
|
2446 | - * @throws InvalidArgumentException |
|
2447 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2448 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2449 | - */ |
|
2450 | - private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
2451 | - { |
|
2452 | - // off-line payment? carry on |
|
2453 | - if ($payment_occurs === EE_PMT_Base::offline) { |
|
2454 | - return true; |
|
2455 | - } |
|
2456 | - // verify payment validity |
|
2457 | - if ($payment instanceof EE_Payment) { |
|
2458 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2459 | - $msg = $payment->gateway_response(); |
|
2460 | - // check results |
|
2461 | - switch ($payment->status()) { |
|
2462 | - // good payment |
|
2463 | - case EEM_Payment::status_id_approved: |
|
2464 | - EE_Error::add_success( |
|
2465 | - esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
2466 | - __FILE__, |
|
2467 | - __FUNCTION__, |
|
2468 | - __LINE__ |
|
2469 | - ); |
|
2470 | - return true; |
|
2471 | - break; |
|
2472 | - // slow payment |
|
2473 | - case EEM_Payment::status_id_pending: |
|
2474 | - if (empty($msg)) { |
|
2475 | - $msg = esc_html__( |
|
2476 | - 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
2477 | - 'event_espresso' |
|
2478 | - ); |
|
2479 | - } |
|
2480 | - EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2481 | - return true; |
|
2482 | - break; |
|
2483 | - // don't wanna payment |
|
2484 | - case EEM_Payment::status_id_cancelled: |
|
2485 | - if (empty($msg)) { |
|
2486 | - $msg = _n( |
|
2487 | - 'Payment cancelled. Please try again.', |
|
2488 | - 'Payment cancelled. Please try again or select another method of payment.', |
|
2489 | - count($this->checkout->available_payment_methods), |
|
2490 | - 'event_espresso' |
|
2491 | - ); |
|
2492 | - } |
|
2493 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2494 | - return false; |
|
2495 | - break; |
|
2496 | - // not enough payment |
|
2497 | - case EEM_Payment::status_id_declined: |
|
2498 | - if (empty($msg)) { |
|
2499 | - $msg = _n( |
|
2500 | - 'We\'re sorry but your payment was declined. Please try again.', |
|
2501 | - 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
2502 | - count($this->checkout->available_payment_methods), |
|
2503 | - 'event_espresso' |
|
2504 | - ); |
|
2505 | - } |
|
2506 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2507 | - return false; |
|
2508 | - break; |
|
2509 | - // bad payment |
|
2510 | - case EEM_Payment::status_id_failed: |
|
2511 | - if (! empty($msg)) { |
|
2512 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2513 | - return false; |
|
2514 | - } |
|
2515 | - // default to error below |
|
2516 | - break; |
|
2517 | - } |
|
2518 | - } |
|
2519 | - // off-site payment gateway responses are too unreliable, so let's just assume that |
|
2520 | - // the payment processing is just running slower than the registrant's request |
|
2521 | - if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2522 | - return true; |
|
2523 | - } |
|
2524 | - EE_Error::add_error( |
|
2525 | - sprintf( |
|
2526 | - esc_html__( |
|
2527 | - 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2528 | - 'event_espresso' |
|
2529 | - ), |
|
2530 | - '<br/>', |
|
2531 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2532 | - ), |
|
2533 | - __FILE__, |
|
2534 | - __FUNCTION__, |
|
2535 | - __LINE__ |
|
2536 | - ); |
|
2537 | - return false; |
|
2538 | - } |
|
2539 | - |
|
2540 | - |
|
2541 | - |
|
2542 | - |
|
2543 | - |
|
2544 | - |
|
2545 | - /********************************************************************************************************/ |
|
2546 | - /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
2547 | - /********************************************************************************************************/ |
|
2548 | - /** |
|
2549 | - * process_gateway_response |
|
2550 | - * this is the return point for Off-Site Payment Methods |
|
2551 | - * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
2552 | - * otherwise, it will load up the last payment made for the TXN. |
|
2553 | - * If the payment retrieved looks good, it will then either: |
|
2554 | - * complete the current step and allow advancement to the next reg step |
|
2555 | - * or present the payment options again |
|
2556 | - * |
|
2557 | - * @access private |
|
2558 | - * @return EE_Payment|FALSE |
|
2559 | - * @throws EE_Error |
|
2560 | - * @throws InvalidArgumentException |
|
2561 | - * @throws ReflectionException |
|
2562 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2563 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2564 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2565 | - */ |
|
2566 | - public function process_gateway_response() |
|
2567 | - { |
|
2568 | - $payment = null; |
|
2569 | - // how have they chosen to pay? |
|
2570 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2571 | - // get EE_Payment_Method object |
|
2572 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2573 | - $this->checkout->continue_reg = false; |
|
2574 | - return false; |
|
2575 | - } |
|
2576 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
2577 | - return false; |
|
2578 | - } |
|
2579 | - $this->_validate_offsite_return(); |
|
2580 | - // DEBUG LOG |
|
2581 | - // $this->checkout->log( |
|
2582 | - // __CLASS__, |
|
2583 | - // __FUNCTION__, |
|
2584 | - // __LINE__, |
|
2585 | - // array( |
|
2586 | - // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2587 | - // 'payment_method' => $this->checkout->payment_method, |
|
2588 | - // ), |
|
2589 | - // true |
|
2590 | - // ); |
|
2591 | - // verify TXN |
|
2592 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2593 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
2594 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2595 | - $this->checkout->continue_reg = false; |
|
2596 | - return false; |
|
2597 | - } |
|
2598 | - $payment = $this->_process_off_site_payment($gateway); |
|
2599 | - $payment = $this->_process_cancelled_payments($payment); |
|
2600 | - $payment = $this->_validate_payment($payment); |
|
2601 | - // if payment was not declined by the payment gateway or cancelled by the registrant |
|
2602 | - if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2603 | - // $this->_setup_redirect_for_next_step(); |
|
2604 | - // store that for later |
|
2605 | - $this->checkout->payment = $payment; |
|
2606 | - // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
2607 | - // because we will complete this step during the IPN processing then |
|
2608 | - if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
2609 | - $this->set_completed(); |
|
2610 | - } |
|
2611 | - return true; |
|
2612 | - } |
|
2613 | - } |
|
2614 | - // DEBUG LOG |
|
2615 | - // $this->checkout->log( |
|
2616 | - // __CLASS__, |
|
2617 | - // __FUNCTION__, |
|
2618 | - // __LINE__, |
|
2619 | - // array('payment' => $payment) |
|
2620 | - // ); |
|
2621 | - $this->checkout->continue_reg = false; |
|
2622 | - return false; |
|
2623 | - } |
|
2624 | - |
|
2625 | - |
|
2626 | - /** |
|
2627 | - * _validate_return |
|
2628 | - * |
|
2629 | - * @access private |
|
2630 | - * @return void |
|
2631 | - * @throws EE_Error |
|
2632 | - * @throws InvalidArgumentException |
|
2633 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2634 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2635 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2636 | - */ |
|
2637 | - private function _validate_offsite_return() |
|
2638 | - { |
|
2639 | - $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
2640 | - if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2641 | - // Houston... we might have a problem |
|
2642 | - $invalid_TXN = false; |
|
2643 | - // first gather some info |
|
2644 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2645 | - $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
2646 | - ? $valid_TXN->primary_registration() |
|
2647 | - : null; |
|
2648 | - // let's start by retrieving the cart for this TXN |
|
2649 | - $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2650 | - if ($cart instanceof EE_Cart) { |
|
2651 | - // verify that the current cart has tickets |
|
2652 | - $tickets = $cart->get_tickets(); |
|
2653 | - if (empty($tickets)) { |
|
2654 | - $invalid_TXN = true; |
|
2655 | - } |
|
2656 | - } else { |
|
2657 | - $invalid_TXN = true; |
|
2658 | - } |
|
2659 | - $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
2660 | - ? $primary_registrant->session_ID() |
|
2661 | - : null; |
|
2662 | - // validate current Session ID and compare against valid TXN session ID |
|
2663 | - if ($invalid_TXN // if this is already true, then skip other checks |
|
2664 | - || EE_Session::instance()->id() === null |
|
2665 | - || ( |
|
2666 | - // WARNING !!! |
|
2667 | - // this could be PayPal sending back duplicate requests (ya they do that) |
|
2668 | - // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2669 | - // so now we need to determine if this current TXN looks valid or not |
|
2670 | - // and whether this reg step has even been started ? |
|
2671 | - EE_Session::instance()->id() === $valid_TXN_SID |
|
2672 | - // really? you're half way through this reg step, but you never started it ? |
|
2673 | - && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2674 | - ) |
|
2675 | - ) { |
|
2676 | - $invalid_TXN = true; |
|
2677 | - } |
|
2678 | - if ($invalid_TXN) { |
|
2679 | - // is the valid TXN completed ? |
|
2680 | - if ($valid_TXN instanceof EE_Transaction) { |
|
2681 | - // has this step even been started ? |
|
2682 | - $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2683 | - if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2684 | - // so it **looks** like this is a double request from PayPal |
|
2685 | - // so let's try to pick up where we left off |
|
2686 | - $this->checkout->transaction = $valid_TXN; |
|
2687 | - $this->checkout->refresh_all_entities(true); |
|
2688 | - return; |
|
2689 | - } |
|
2690 | - } |
|
2691 | - // you appear to be lost? |
|
2692 | - $this->_redirect_wayward_request($primary_registrant); |
|
2693 | - } |
|
2694 | - } |
|
2695 | - } |
|
2696 | - |
|
2697 | - |
|
2698 | - /** |
|
2699 | - * _redirect_wayward_request |
|
2700 | - * |
|
2701 | - * @access private |
|
2702 | - * @param \EE_Registration|null $primary_registrant |
|
2703 | - * @return bool |
|
2704 | - * @throws EE_Error |
|
2705 | - * @throws InvalidArgumentException |
|
2706 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2707 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2708 | - */ |
|
2709 | - private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
2710 | - { |
|
2711 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2712 | - // try redirecting based on the current TXN |
|
2713 | - $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
2714 | - ? $this->checkout->transaction->primary_registration() |
|
2715 | - : null; |
|
2716 | - } |
|
2717 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2718 | - EE_Error::add_error( |
|
2719 | - sprintf( |
|
2720 | - esc_html__( |
|
2721 | - 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
2722 | - 'event_espresso' |
|
2723 | - ), |
|
2724 | - '<br/>', |
|
2725 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2726 | - ), |
|
2727 | - __FILE__, |
|
2728 | - __FUNCTION__, |
|
2729 | - __LINE__ |
|
2730 | - ); |
|
2731 | - return false; |
|
2732 | - } |
|
2733 | - // make sure transaction is not locked |
|
2734 | - $this->checkout->transaction->unlock(); |
|
2735 | - wp_safe_redirect( |
|
2736 | - add_query_arg( |
|
2737 | - array( |
|
2738 | - 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
2739 | - ), |
|
2740 | - $this->checkout->thank_you_page_url |
|
2741 | - ) |
|
2742 | - ); |
|
2743 | - exit(); |
|
2744 | - } |
|
2745 | - |
|
2746 | - |
|
2747 | - /** |
|
2748 | - * _process_off_site_payment |
|
2749 | - * |
|
2750 | - * @access private |
|
2751 | - * @param \EE_Offsite_Gateway $gateway |
|
2752 | - * @return EE_Payment |
|
2753 | - * @throws EE_Error |
|
2754 | - * @throws InvalidArgumentException |
|
2755 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2756 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2757 | - */ |
|
2758 | - private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
2759 | - { |
|
2760 | - try { |
|
2761 | - $request_data = \EE_Registry::instance()->REQ->params(); |
|
2762 | - // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
2763 | - $this->set_handle_IPN_in_this_request( |
|
2764 | - $gateway->handle_IPN_in_this_request($request_data, false) |
|
2765 | - ); |
|
2766 | - if ($this->handle_IPN_in_this_request()) { |
|
2767 | - // get payment details and process results |
|
2768 | - /** @type EE_Payment_Processor $payment_processor */ |
|
2769 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2770 | - $payment = $payment_processor->process_ipn( |
|
2771 | - $request_data, |
|
2772 | - $this->checkout->transaction, |
|
2773 | - $this->checkout->payment_method, |
|
2774 | - true, |
|
2775 | - false |
|
2776 | - ); |
|
2777 | - // $payment_source = 'process_ipn'; |
|
2778 | - } else { |
|
2779 | - $payment = $this->checkout->transaction->last_payment(); |
|
2780 | - // $payment_source = 'last_payment'; |
|
2781 | - } |
|
2782 | - } catch (Exception $e) { |
|
2783 | - // let's just eat the exception and try to move on using any previously set payment info |
|
2784 | - $payment = $this->checkout->transaction->last_payment(); |
|
2785 | - // $payment_source = 'last_payment after Exception'; |
|
2786 | - // but if we STILL don't have a payment object |
|
2787 | - if (! $payment instanceof EE_Payment) { |
|
2788 | - // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
2789 | - $this->_handle_payment_processor_exception($e); |
|
2790 | - } |
|
2791 | - } |
|
2792 | - // DEBUG LOG |
|
2793 | - // $this->checkout->log( |
|
2794 | - // __CLASS__, |
|
2795 | - // __FUNCTION__, |
|
2796 | - // __LINE__, |
|
2797 | - // array( |
|
2798 | - // 'process_ipn_payment' => $payment, |
|
2799 | - // 'payment_source' => $payment_source, |
|
2800 | - // ) |
|
2801 | - // ); |
|
2802 | - return $payment; |
|
2803 | - } |
|
2804 | - |
|
2805 | - |
|
2806 | - /** |
|
2807 | - * _process_cancelled_payments |
|
2808 | - * just makes sure that the payment status gets updated correctly |
|
2809 | - * so tha tan error isn't generated during payment validation |
|
2810 | - * |
|
2811 | - * @access private |
|
2812 | - * @param EE_Payment $payment |
|
2813 | - * @return EE_Payment | FALSE |
|
2814 | - * @throws \EE_Error |
|
2815 | - */ |
|
2816 | - private function _process_cancelled_payments($payment = null) |
|
2817 | - { |
|
2818 | - if ($payment instanceof EE_Payment |
|
2819 | - && isset($_REQUEST['ee_cancel_payment']) |
|
2820 | - && $payment->status() === EEM_Payment::status_id_failed |
|
2821 | - ) { |
|
2822 | - $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2823 | - } |
|
2824 | - return $payment; |
|
2825 | - } |
|
2826 | - |
|
2827 | - |
|
2828 | - /** |
|
2829 | - * get_transaction_details_for_gateways |
|
2830 | - * |
|
2831 | - * @access public |
|
2832 | - * @return int |
|
2833 | - * @throws EE_Error |
|
2834 | - * @throws InvalidArgumentException |
|
2835 | - * @throws ReflectionException |
|
2836 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2837 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2838 | - */ |
|
2839 | - public function get_transaction_details_for_gateways() |
|
2840 | - { |
|
2841 | - $txn_details = array(); |
|
2842 | - // ya gotta make a choice man |
|
2843 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
2844 | - $txn_details = array( |
|
2845 | - 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
2846 | - ); |
|
2847 | - } |
|
2848 | - // get EE_Payment_Method object |
|
2849 | - if (empty($txn_details) |
|
2850 | - && |
|
2851 | - ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
2852 | - ) { |
|
2853 | - $txn_details = array( |
|
2854 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2855 | - 'error' => esc_html__( |
|
2856 | - 'A valid Payment Method could not be determined.', |
|
2857 | - 'event_espresso' |
|
2858 | - ), |
|
2859 | - ); |
|
2860 | - } |
|
2861 | - if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2862 | - $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2863 | - $txn_details = array( |
|
2864 | - 'TXN_ID' => $this->checkout->transaction->ID(), |
|
2865 | - 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
2866 | - 'TXN_total' => $this->checkout->transaction->total(), |
|
2867 | - 'TXN_paid' => $this->checkout->transaction->paid(), |
|
2868 | - 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
2869 | - 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
2870 | - 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
2871 | - 'payment_amount' => $this->checkout->amount_owing, |
|
2872 | - 'return_url' => $return_url, |
|
2873 | - 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
2874 | - 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
2875 | - array( |
|
2876 | - 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
2877 | - 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
2878 | - ) |
|
2879 | - ), |
|
2880 | - ); |
|
2881 | - } |
|
2882 | - echo wp_json_encode($txn_details); |
|
2883 | - exit(); |
|
2884 | - } |
|
2885 | - |
|
2886 | - |
|
2887 | - /** |
|
2888 | - * __sleep |
|
2889 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
2890 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
2891 | - * reg form, because if needed, it will be regenerated anyways |
|
2892 | - * |
|
2893 | - * @return array |
|
2894 | - */ |
|
2895 | - public function __sleep() |
|
2896 | - { |
|
2897 | - // remove the reg form and the checkout |
|
2898 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
2899 | - } |
|
15 | + /** |
|
16 | + * @access protected |
|
17 | + * @var EE_Line_Item_Display $Line_Item_Display |
|
18 | + */ |
|
19 | + protected $line_item_display; |
|
20 | + |
|
21 | + /** |
|
22 | + * @access protected |
|
23 | + * @var boolean $handle_IPN_in_this_request |
|
24 | + */ |
|
25 | + protected $handle_IPN_in_this_request = false; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
30 | + * |
|
31 | + * @access public |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function set_hooks() |
|
35 | + { |
|
36 | + add_filter( |
|
37 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
38 | + array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
39 | + ); |
|
40 | + add_action( |
|
41 | + 'wp_ajax_switch_spco_billing_form', |
|
42 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
43 | + ); |
|
44 | + add_action( |
|
45 | + 'wp_ajax_nopriv_switch_spco_billing_form', |
|
46 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
47 | + ); |
|
48 | + add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
49 | + add_action( |
|
50 | + 'wp_ajax_nopriv_save_payer_details', |
|
51 | + array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
52 | + ); |
|
53 | + add_action( |
|
54 | + 'wp_ajax_get_transaction_details_for_gateways', |
|
55 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
56 | + ); |
|
57 | + add_action( |
|
58 | + 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
59 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
60 | + ); |
|
61 | + add_filter( |
|
62 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
63 | + array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
64 | + 10, |
|
65 | + 1 |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * ajax switch_spco_billing_form |
|
72 | + * |
|
73 | + * @throws \EE_Error |
|
74 | + */ |
|
75 | + public static function switch_spco_billing_form() |
|
76 | + { |
|
77 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * ajax save_payer_details |
|
83 | + * |
|
84 | + * @throws \EE_Error |
|
85 | + */ |
|
86 | + public static function save_payer_details() |
|
87 | + { |
|
88 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * ajax get_transaction_details |
|
94 | + * |
|
95 | + * @throws \EE_Error |
|
96 | + */ |
|
97 | + public static function get_transaction_details() |
|
98 | + { |
|
99 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * bypass_recaptcha_for_load_payment_method |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @return array |
|
108 | + * @throws InvalidArgumentException |
|
109 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
110 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
111 | + */ |
|
112 | + public static function bypass_recaptcha_for_load_payment_method() |
|
113 | + { |
|
114 | + return array( |
|
115 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
116 | + 'step' => 'payment_options', |
|
117 | + 'action' => 'spco_billing_form', |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * class constructor |
|
124 | + * |
|
125 | + * @access public |
|
126 | + * @param EE_Checkout $checkout |
|
127 | + */ |
|
128 | + public function __construct(EE_Checkout $checkout) |
|
129 | + { |
|
130 | + $this->_slug = 'payment_options'; |
|
131 | + $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
132 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
133 | + $this->checkout = $checkout; |
|
134 | + $this->_reset_success_message(); |
|
135 | + $this->set_instructions( |
|
136 | + esc_html__( |
|
137 | + 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
138 | + 'event_espresso' |
|
139 | + ) |
|
140 | + ); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return null |
|
146 | + */ |
|
147 | + public function line_item_display() |
|
148 | + { |
|
149 | + return $this->line_item_display; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param null $line_item_display |
|
155 | + */ |
|
156 | + public function set_line_item_display($line_item_display) |
|
157 | + { |
|
158 | + $this->line_item_display = $line_item_display; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @return boolean |
|
164 | + */ |
|
165 | + public function handle_IPN_in_this_request() |
|
166 | + { |
|
167 | + return $this->handle_IPN_in_this_request; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param boolean $handle_IPN_in_this_request |
|
173 | + */ |
|
174 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
175 | + { |
|
176 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * translate_js_strings |
|
182 | + * |
|
183 | + * @return void |
|
184 | + */ |
|
185 | + public function translate_js_strings() |
|
186 | + { |
|
187 | + EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
188 | + 'Please select a method of payment in order to continue.', |
|
189 | + 'event_espresso' |
|
190 | + ); |
|
191 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
192 | + 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
193 | + 'event_espresso' |
|
194 | + ); |
|
195 | + EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
196 | + 'Forwarding to Secure Payment Provider.', |
|
197 | + 'event_espresso' |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * enqueue_styles_and_scripts |
|
204 | + * |
|
205 | + * @return void |
|
206 | + * @throws EE_Error |
|
207 | + * @throws InvalidArgumentException |
|
208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
210 | + */ |
|
211 | + public function enqueue_styles_and_scripts() |
|
212 | + { |
|
213 | + $transaction = $this->checkout->transaction; |
|
214 | + // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
215 | + if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
216 | + return; |
|
217 | + } |
|
218 | + foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
219 | + $transaction, |
|
220 | + EEM_Payment_Method::scope_cart |
|
221 | + ) as $payment_method) { |
|
222 | + $type_obj = $payment_method->type_obj(); |
|
223 | + if ($type_obj instanceof EE_PMT_Base) { |
|
224 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
225 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
226 | + $billing_form->enqueue_js(); |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * initialize_reg_step |
|
235 | + * |
|
236 | + * @return bool |
|
237 | + * @throws EE_Error |
|
238 | + * @throws InvalidArgumentException |
|
239 | + * @throws ReflectionException |
|
240 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
241 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
242 | + */ |
|
243 | + public function initialize_reg_step() |
|
244 | + { |
|
245 | + // TODO: if /when we implement donations, then this will need overriding |
|
246 | + if (// don't need payment options for: |
|
247 | + // registrations made via the admin |
|
248 | + // completed transactions |
|
249 | + // overpaid transactions |
|
250 | + // $ 0.00 transactions(no payment required) |
|
251 | + ! $this->checkout->payment_required() |
|
252 | + // but do NOT remove if current action being called belongs to this reg step |
|
253 | + && ! is_callable(array($this, $this->checkout->action)) |
|
254 | + && ! $this->completed() |
|
255 | + ) { |
|
256 | + // and if so, then we no longer need the Payment Options step |
|
257 | + if ($this->is_current_step()) { |
|
258 | + $this->checkout->generate_reg_form = false; |
|
259 | + } |
|
260 | + $this->checkout->remove_reg_step($this->_slug); |
|
261 | + // DEBUG LOG |
|
262 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
263 | + return false; |
|
264 | + } |
|
265 | + // load EEM_Payment_Method |
|
266 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
267 | + // get all active payment methods |
|
268 | + $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
269 | + $this->checkout->transaction, |
|
270 | + EEM_Payment_Method::scope_cart |
|
271 | + ); |
|
272 | + return true; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * @return EE_Form_Section_Proper |
|
278 | + * @throws EE_Error |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws ReflectionException |
|
281 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
282 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
283 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
284 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
285 | + */ |
|
286 | + public function generate_reg_form() |
|
287 | + { |
|
288 | + // reset in case someone changes their mind |
|
289 | + $this->_reset_selected_method_of_payment(); |
|
290 | + // set some defaults |
|
291 | + $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
292 | + $registrations_requiring_payment = array(); |
|
293 | + $registrations_for_free_events = array(); |
|
294 | + $registrations_requiring_pre_approval = array(); |
|
295 | + $sold_out_events = array(); |
|
296 | + $insufficient_spaces_available = array(); |
|
297 | + $no_payment_required = true; |
|
298 | + // loop thru registrations to gather info |
|
299 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
300 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
301 | + $registrations, |
|
302 | + $this->checkout->revisit |
|
303 | + ); |
|
304 | + foreach ($registrations as $REG_ID => $registration) { |
|
305 | + /** @var $registration EE_Registration */ |
|
306 | + // has this registration lost it's space ? |
|
307 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
308 | + if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
309 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
310 | + } else { |
|
311 | + $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
312 | + } |
|
313 | + continue; |
|
314 | + } |
|
315 | + // event requires admin approval |
|
316 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
317 | + // add event to list of events with pre-approval reg status |
|
318 | + $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
319 | + do_action( |
|
320 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
321 | + $registration->event(), |
|
322 | + $this |
|
323 | + ); |
|
324 | + continue; |
|
325 | + } |
|
326 | + if ($this->checkout->revisit |
|
327 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
328 | + && ( |
|
329 | + $registration->event()->is_sold_out() |
|
330 | + || $registration->event()->is_sold_out(true) |
|
331 | + ) |
|
332 | + ) { |
|
333 | + // add event to list of events that are sold out |
|
334 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
335 | + do_action( |
|
336 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
337 | + $registration->event(), |
|
338 | + $this |
|
339 | + ); |
|
340 | + continue; |
|
341 | + } |
|
342 | + // are they allowed to pay now and is there monies owing? |
|
343 | + if ($registration->owes_monies_and_can_pay()) { |
|
344 | + $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
345 | + do_action( |
|
346 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
347 | + $registration->event(), |
|
348 | + $this |
|
349 | + ); |
|
350 | + } elseif (! $this->checkout->revisit |
|
351 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
352 | + && $registration->ticket()->is_free() |
|
353 | + ) { |
|
354 | + $registrations_for_free_events[ $registration->event()->ID() ] = $registration; |
|
355 | + } |
|
356 | + } |
|
357 | + $subsections = array(); |
|
358 | + // now decide which template to load |
|
359 | + if (! empty($sold_out_events)) { |
|
360 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
361 | + } |
|
362 | + if (! empty($insufficient_spaces_available)) { |
|
363 | + $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
364 | + $insufficient_spaces_available |
|
365 | + ); |
|
366 | + } |
|
367 | + if (! empty($registrations_requiring_pre_approval)) { |
|
368 | + $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
369 | + $registrations_requiring_pre_approval |
|
370 | + ); |
|
371 | + } |
|
372 | + if (! empty($registrations_for_free_events)) { |
|
373 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
374 | + } |
|
375 | + if (! empty($registrations_requiring_payment)) { |
|
376 | + if ($this->checkout->amount_owing > 0) { |
|
377 | + // autoload Line_Item_Display classes |
|
378 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
379 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
380 | + apply_filters( |
|
381 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
382 | + new EE_Line_Item_Filter_Collection() |
|
383 | + ), |
|
384 | + $this->checkout->cart->get_grand_total() |
|
385 | + ); |
|
386 | + /** @var EE_Line_Item $filtered_line_item_tree */ |
|
387 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
388 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
389 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
390 | + $subsections['payment_options'] = $this->_display_payment_options( |
|
391 | + $this->line_item_display->display_line_item( |
|
392 | + $filtered_line_item_tree, |
|
393 | + array('registrations' => $registrations) |
|
394 | + ) |
|
395 | + ); |
|
396 | + $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
397 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
398 | + } |
|
399 | + $no_payment_required = false; |
|
400 | + } else { |
|
401 | + $this->_hide_reg_step_submit_button_if_revisit(); |
|
402 | + } |
|
403 | + $this->_save_selected_method_of_payment(); |
|
404 | + |
|
405 | + $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
406 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
407 | + |
|
408 | + return new EE_Form_Section_Proper( |
|
409 | + array( |
|
410 | + 'name' => $this->reg_form_name(), |
|
411 | + 'html_id' => $this->reg_form_name(), |
|
412 | + 'subsections' => $subsections, |
|
413 | + 'layout_strategy' => new EE_No_Layout(), |
|
414 | + ) |
|
415 | + ); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * add line item filters required for this reg step |
|
421 | + * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
422 | + * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
423 | + * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
424 | + * payment options reg step, can apply these filters via the following: apply_filters( |
|
425 | + * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
426 | + * filter collection by passing that instead of instantiating a new collection |
|
427 | + * |
|
428 | + * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
429 | + * @return EE_Line_Item_Filter_Collection |
|
430 | + * @throws EE_Error |
|
431 | + * @throws InvalidArgumentException |
|
432 | + * @throws ReflectionException |
|
433 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
434 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
435 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
436 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
437 | + */ |
|
438 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
439 | + { |
|
440 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
441 | + return $line_item_filter_collection; |
|
442 | + } |
|
443 | + if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
444 | + return $line_item_filter_collection; |
|
445 | + } |
|
446 | + if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
447 | + return $line_item_filter_collection; |
|
448 | + } |
|
449 | + $line_item_filter_collection->add( |
|
450 | + new EE_Billable_Line_Item_Filter( |
|
451 | + EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
452 | + EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
453 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
454 | + ) |
|
455 | + ) |
|
456 | + ) |
|
457 | + ); |
|
458 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
459 | + return $line_item_filter_collection; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * remove_ejected_registrations |
|
465 | + * if a registrant has lost their potential space at an event due to lack of payment, |
|
466 | + * then this method removes them from the list of registrations being paid for during this request |
|
467 | + * |
|
468 | + * @param \EE_Registration[] $registrations |
|
469 | + * @return EE_Registration[] |
|
470 | + * @throws EE_Error |
|
471 | + * @throws InvalidArgumentException |
|
472 | + * @throws ReflectionException |
|
473 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
474 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
475 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
476 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
477 | + */ |
|
478 | + public static function remove_ejected_registrations(array $registrations) |
|
479 | + { |
|
480 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
481 | + $registrations, |
|
482 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
483 | + ); |
|
484 | + foreach ($registrations as $REG_ID => $registration) { |
|
485 | + // has this registration lost it's space ? |
|
486 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
487 | + unset($registrations[ $REG_ID ]); |
|
488 | + continue; |
|
489 | + } |
|
490 | + } |
|
491 | + return $registrations; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * find_registrations_that_lost_their_space |
|
497 | + * If a registrant chooses an offline payment method like Invoice, |
|
498 | + * then no space is reserved for them at the event until they fully pay fo that site |
|
499 | + * (unless the event's default reg status is set to APPROVED) |
|
500 | + * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
501 | + * then this method will determine which registrations have lost the ability to complete the reg process. |
|
502 | + * |
|
503 | + * @param \EE_Registration[] $registrations |
|
504 | + * @param bool $revisit |
|
505 | + * @return array |
|
506 | + * @throws EE_Error |
|
507 | + * @throws InvalidArgumentException |
|
508 | + * @throws ReflectionException |
|
509 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
510 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
511 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
512 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
513 | + */ |
|
514 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
515 | + { |
|
516 | + // registrations per event |
|
517 | + $event_reg_count = array(); |
|
518 | + // spaces left per event |
|
519 | + $event_spaces_remaining = array(); |
|
520 | + // tickets left sorted by ID |
|
521 | + $tickets_remaining = array(); |
|
522 | + // registrations that have lost their space |
|
523 | + $ejected_registrations = array(); |
|
524 | + foreach ($registrations as $REG_ID => $registration) { |
|
525 | + if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
526 | + || apply_filters( |
|
527 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
528 | + false, |
|
529 | + $registration, |
|
530 | + $revisit |
|
531 | + ) |
|
532 | + ) { |
|
533 | + continue; |
|
534 | + } |
|
535 | + $EVT_ID = $registration->event_ID(); |
|
536 | + $ticket = $registration->ticket(); |
|
537 | + if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
538 | + $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
539 | + } |
|
540 | + if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
541 | + if (! isset($event_reg_count[ $EVT_ID ])) { |
|
542 | + $event_reg_count[ $EVT_ID ] = 0; |
|
543 | + } |
|
544 | + $event_reg_count[ $EVT_ID ]++; |
|
545 | + if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
546 | + $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
547 | + } |
|
548 | + } |
|
549 | + if ($revisit |
|
550 | + && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
551 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
552 | + ) |
|
553 | + ) { |
|
554 | + $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
555 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
556 | + /** @type EE_Registration_Processor $registration_processor */ |
|
557 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
558 | + // at this point, we should have enough details about the registrant to consider the registration |
|
559 | + // NOT incomplete |
|
560 | + $registration_processor->manually_update_registration_status( |
|
561 | + $registration, |
|
562 | + EEM_Registration::status_id_wait_list |
|
563 | + ); |
|
564 | + } |
|
565 | + } |
|
566 | + } |
|
567 | + return $ejected_registrations; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * _hide_reg_step_submit_button |
|
573 | + * removes the html for the reg step submit button |
|
574 | + * by replacing it with an empty string via filter callback |
|
575 | + * |
|
576 | + * @return void |
|
577 | + */ |
|
578 | + protected function _adjust_registration_status_if_event_old_sold() |
|
579 | + { |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * _hide_reg_step_submit_button |
|
585 | + * removes the html for the reg step submit button |
|
586 | + * by replacing it with an empty string via filter callback |
|
587 | + * |
|
588 | + * @return void |
|
589 | + */ |
|
590 | + protected function _hide_reg_step_submit_button_if_revisit() |
|
591 | + { |
|
592 | + if ($this->checkout->revisit) { |
|
593 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
594 | + } |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * sold_out_events |
|
600 | + * displays notices regarding events that have sold out since hte registrant first signed up |
|
601 | + * |
|
602 | + * @param \EE_Event[] $sold_out_events_array |
|
603 | + * @return \EE_Form_Section_Proper |
|
604 | + * @throws \EE_Error |
|
605 | + */ |
|
606 | + private function _sold_out_events($sold_out_events_array = array()) |
|
607 | + { |
|
608 | + // set some defaults |
|
609 | + $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
610 | + $sold_out_events = ''; |
|
611 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
612 | + $sold_out_events .= EEH_HTML::li( |
|
613 | + EEH_HTML::span( |
|
614 | + ' ' . $sold_out_event->name(), |
|
615 | + '', |
|
616 | + 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
617 | + ) |
|
618 | + ); |
|
619 | + } |
|
620 | + return new EE_Form_Section_Proper( |
|
621 | + array( |
|
622 | + 'layout_strategy' => new EE_Template_Layout( |
|
623 | + array( |
|
624 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
625 | + . $this->_slug |
|
626 | + . DS |
|
627 | + . 'sold_out_events.template.php', |
|
628 | + 'template_args' => apply_filters( |
|
629 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
630 | + array( |
|
631 | + 'sold_out_events' => $sold_out_events, |
|
632 | + 'sold_out_events_msg' => apply_filters( |
|
633 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
634 | + sprintf( |
|
635 | + esc_html__( |
|
636 | + 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
637 | + 'event_espresso' |
|
638 | + ), |
|
639 | + '<strong>', |
|
640 | + '</strong>', |
|
641 | + '<br />' |
|
642 | + ) |
|
643 | + ), |
|
644 | + ) |
|
645 | + ), |
|
646 | + ) |
|
647 | + ), |
|
648 | + ) |
|
649 | + ); |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * _insufficient_spaces_available |
|
655 | + * displays notices regarding events that do not have enough remaining spaces |
|
656 | + * to satisfy the current number of registrations looking to pay |
|
657 | + * |
|
658 | + * @param \EE_Event[] $insufficient_spaces_events_array |
|
659 | + * @return \EE_Form_Section_Proper |
|
660 | + * @throws \EE_Error |
|
661 | + */ |
|
662 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
663 | + { |
|
664 | + // set some defaults |
|
665 | + $this->checkout->selected_method_of_payment = 'invoice'; |
|
666 | + $insufficient_space_events = ''; |
|
667 | + foreach ($insufficient_spaces_events_array as $event) { |
|
668 | + if ($event instanceof EE_Event) { |
|
669 | + $insufficient_space_events .= EEH_HTML::li( |
|
670 | + EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
671 | + ); |
|
672 | + } |
|
673 | + } |
|
674 | + return new EE_Form_Section_Proper( |
|
675 | + array( |
|
676 | + 'subsections' => array( |
|
677 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
678 | + 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
679 | + ), |
|
680 | + 'layout_strategy' => new EE_Template_Layout( |
|
681 | + array( |
|
682 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
683 | + . $this->_slug |
|
684 | + . DS |
|
685 | + . 'sold_out_events.template.php', |
|
686 | + 'template_args' => apply_filters( |
|
687 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
688 | + array( |
|
689 | + 'sold_out_events' => $insufficient_space_events, |
|
690 | + 'sold_out_events_msg' => apply_filters( |
|
691 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
692 | + esc_html__( |
|
693 | + 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
694 | + 'event_espresso' |
|
695 | + ) |
|
696 | + ), |
|
697 | + ) |
|
698 | + ), |
|
699 | + ) |
|
700 | + ), |
|
701 | + ) |
|
702 | + ); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * registrations_requiring_pre_approval |
|
708 | + * |
|
709 | + * @param array $registrations_requiring_pre_approval |
|
710 | + * @return EE_Form_Section_Proper |
|
711 | + * @throws EE_Error |
|
712 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
713 | + */ |
|
714 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
715 | + { |
|
716 | + $events_requiring_pre_approval = ''; |
|
717 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
718 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
719 | + $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
720 | + EEH_HTML::span( |
|
721 | + '', |
|
722 | + '', |
|
723 | + 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
724 | + ) |
|
725 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
726 | + ); |
|
727 | + } |
|
728 | + } |
|
729 | + return new EE_Form_Section_Proper( |
|
730 | + array( |
|
731 | + 'layout_strategy' => new EE_Template_Layout( |
|
732 | + array( |
|
733 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
734 | + . $this->_slug |
|
735 | + . DS |
|
736 | + . 'events_requiring_pre_approval.template.php', // layout_template |
|
737 | + 'template_args' => apply_filters( |
|
738 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
739 | + array( |
|
740 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
741 | + 'events_requiring_pre_approval_msg' => apply_filters( |
|
742 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
743 | + esc_html__( |
|
744 | + 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
745 | + 'event_espresso' |
|
746 | + ) |
|
747 | + ), |
|
748 | + ) |
|
749 | + ), |
|
750 | + ) |
|
751 | + ), |
|
752 | + ) |
|
753 | + ); |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _no_payment_required |
|
759 | + * |
|
760 | + * @param \EE_Event[] $registrations_for_free_events |
|
761 | + * @return \EE_Form_Section_Proper |
|
762 | + * @throws \EE_Error |
|
763 | + */ |
|
764 | + private function _no_payment_required($registrations_for_free_events = array()) |
|
765 | + { |
|
766 | + // set some defaults |
|
767 | + $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
768 | + // generate no_payment_required form |
|
769 | + return new EE_Form_Section_Proper( |
|
770 | + array( |
|
771 | + 'layout_strategy' => new EE_Template_Layout( |
|
772 | + array( |
|
773 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
774 | + . $this->_slug |
|
775 | + . DS |
|
776 | + . 'no_payment_required.template.php', // layout_template |
|
777 | + 'template_args' => apply_filters( |
|
778 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
779 | + array( |
|
780 | + 'revisit' => $this->checkout->revisit, |
|
781 | + 'registrations' => array(), |
|
782 | + 'ticket_count' => array(), |
|
783 | + 'registrations_for_free_events' => $registrations_for_free_events, |
|
784 | + 'no_payment_required_msg' => EEH_HTML::p( |
|
785 | + esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
786 | + ), |
|
787 | + ) |
|
788 | + ), |
|
789 | + ) |
|
790 | + ), |
|
791 | + ) |
|
792 | + ); |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * _display_payment_options |
|
798 | + * |
|
799 | + * @param string $transaction_details |
|
800 | + * @return EE_Form_Section_Proper |
|
801 | + * @throws EE_Error |
|
802 | + * @throws InvalidArgumentException |
|
803 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
804 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
805 | + */ |
|
806 | + private function _display_payment_options($transaction_details = '') |
|
807 | + { |
|
808 | + // has method_of_payment been set by no-js user? |
|
809 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
810 | + // build payment options form |
|
811 | + return apply_filters( |
|
812 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
813 | + new EE_Form_Section_Proper( |
|
814 | + array( |
|
815 | + 'subsections' => array( |
|
816 | + 'before_payment_options' => apply_filters( |
|
817 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
818 | + new EE_Form_Section_Proper( |
|
819 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
820 | + ) |
|
821 | + ), |
|
822 | + 'payment_options' => $this->_setup_payment_options(), |
|
823 | + 'after_payment_options' => apply_filters( |
|
824 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
825 | + new EE_Form_Section_Proper( |
|
826 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
827 | + ) |
|
828 | + ), |
|
829 | + ), |
|
830 | + 'layout_strategy' => new EE_Template_Layout( |
|
831 | + array( |
|
832 | + 'layout_template_file' => $this->_template, |
|
833 | + 'template_args' => apply_filters( |
|
834 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
835 | + array( |
|
836 | + 'reg_count' => $this->line_item_display->total_items(), |
|
837 | + 'transaction_details' => $transaction_details, |
|
838 | + 'available_payment_methods' => array(), |
|
839 | + ) |
|
840 | + ), |
|
841 | + ) |
|
842 | + ), |
|
843 | + ) |
|
844 | + ) |
|
845 | + ); |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + /** |
|
850 | + * _extra_hidden_inputs |
|
851 | + * |
|
852 | + * @param bool $no_payment_required |
|
853 | + * @return \EE_Form_Section_Proper |
|
854 | + * @throws \EE_Error |
|
855 | + */ |
|
856 | + private function _extra_hidden_inputs($no_payment_required = true) |
|
857 | + { |
|
858 | + return new EE_Form_Section_Proper( |
|
859 | + array( |
|
860 | + 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
861 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
862 | + 'subsections' => array( |
|
863 | + 'spco_no_payment_required' => new EE_Hidden_Input( |
|
864 | + array( |
|
865 | + 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
866 | + 'html_name' => 'spco_no_payment_required', |
|
867 | + 'html_id' => 'spco-no-payment-required-payment_options', |
|
868 | + 'default' => $no_payment_required, |
|
869 | + ) |
|
870 | + ), |
|
871 | + 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
872 | + array( |
|
873 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
874 | + 'html_name' => 'spco_transaction_id', |
|
875 | + 'html_id' => 'spco-transaction-id', |
|
876 | + 'default' => $this->checkout->transaction->ID(), |
|
877 | + ) |
|
878 | + ), |
|
879 | + ), |
|
880 | + ) |
|
881 | + ); |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * _apply_registration_payments_to_amount_owing |
|
887 | + * |
|
888 | + * @access protected |
|
889 | + * @param array $registrations |
|
890 | + * @throws EE_Error |
|
891 | + */ |
|
892 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
893 | + { |
|
894 | + $payments = array(); |
|
895 | + foreach ($registrations as $registration) { |
|
896 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
897 | + $payments += $registration->registration_payments(); |
|
898 | + } |
|
899 | + } |
|
900 | + if (! empty($payments)) { |
|
901 | + foreach ($payments as $payment) { |
|
902 | + if ($payment instanceof EE_Registration_Payment) { |
|
903 | + $this->checkout->amount_owing -= $payment->amount(); |
|
904 | + } |
|
905 | + } |
|
906 | + } |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * _reset_selected_method_of_payment |
|
912 | + * |
|
913 | + * @access private |
|
914 | + * @param bool $force_reset |
|
915 | + * @return void |
|
916 | + * @throws InvalidArgumentException |
|
917 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
918 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
919 | + */ |
|
920 | + private function _reset_selected_method_of_payment($force_reset = false) |
|
921 | + { |
|
922 | + $reset_payment_method = $force_reset |
|
923 | + ? true |
|
924 | + : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
925 | + if ($reset_payment_method) { |
|
926 | + $this->checkout->selected_method_of_payment = null; |
|
927 | + $this->checkout->payment_method = null; |
|
928 | + $this->checkout->billing_form = null; |
|
929 | + $this->_save_selected_method_of_payment(); |
|
930 | + } |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * _save_selected_method_of_payment |
|
936 | + * stores the selected_method_of_payment in the session |
|
937 | + * so that it's available for all subsequent requests including AJAX |
|
938 | + * |
|
939 | + * @access private |
|
940 | + * @param string $selected_method_of_payment |
|
941 | + * @return void |
|
942 | + * @throws InvalidArgumentException |
|
943 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
944 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
945 | + */ |
|
946 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
947 | + { |
|
948 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
949 | + ? $selected_method_of_payment |
|
950 | + : $this->checkout->selected_method_of_payment; |
|
951 | + EE_Registry::instance()->SSN->set_session_data( |
|
952 | + array('selected_method_of_payment' => $selected_method_of_payment) |
|
953 | + ); |
|
954 | + } |
|
955 | + |
|
956 | + |
|
957 | + /** |
|
958 | + * _setup_payment_options |
|
959 | + * |
|
960 | + * @return EE_Form_Section_Proper |
|
961 | + * @throws EE_Error |
|
962 | + * @throws InvalidArgumentException |
|
963 | + * @throws ReflectionException |
|
964 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
965 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
966 | + */ |
|
967 | + public function _setup_payment_options() |
|
968 | + { |
|
969 | + // load payment method classes |
|
970 | + $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
971 | + if (empty($this->checkout->available_payment_methods)) { |
|
972 | + EE_Error::add_error( |
|
973 | + apply_filters( |
|
974 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
975 | + sprintf( |
|
976 | + esc_html__( |
|
977 | + 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
978 | + 'event_espresso' |
|
979 | + ), |
|
980 | + '<br>', |
|
981 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
982 | + ) |
|
983 | + ), |
|
984 | + __FILE__, |
|
985 | + __FUNCTION__, |
|
986 | + __LINE__ |
|
987 | + ); |
|
988 | + } |
|
989 | + // switch up header depending on number of available payment methods |
|
990 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
991 | + ? apply_filters( |
|
992 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
993 | + esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
994 | + ) |
|
995 | + : apply_filters( |
|
996 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
997 | + esc_html__('Method of Payment', 'event_espresso') |
|
998 | + ); |
|
999 | + $available_payment_methods = array( |
|
1000 | + // display the "Payment Method" header |
|
1001 | + 'payment_method_header' => new EE_Form_Section_HTML( |
|
1002 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr') |
|
1003 | + ), |
|
1004 | + ); |
|
1005 | + // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
1006 | + $available_payment_method_options = array(); |
|
1007 | + $default_payment_method_option = array(); |
|
1008 | + // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
1009 | + $payment_methods_billing_info = array( |
|
1010 | + new EE_Form_Section_HTML( |
|
1011 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
1012 | + ), |
|
1013 | + ); |
|
1014 | + // loop through payment methods |
|
1015 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
1016 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1017 | + $payment_method_button = EEH_HTML::img( |
|
1018 | + $payment_method->button_url(), |
|
1019 | + $payment_method->name(), |
|
1020 | + 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1021 | + 'spco-payment-method-btn-img' |
|
1022 | + ); |
|
1023 | + // check if any payment methods are set as default |
|
1024 | + // if payment method is already selected OR nothing is selected and this payment method should be |
|
1025 | + // open_by_default |
|
1026 | + if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
1027 | + || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1028 | + ) { |
|
1029 | + $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
1030 | + $this->_save_selected_method_of_payment(); |
|
1031 | + $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1032 | + } else { |
|
1033 | + $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1034 | + } |
|
1035 | + $payment_methods_billing_info[ $payment_method->slug( |
|
1036 | + ) . '-info' ] = $this->_payment_method_billing_info( |
|
1037 | + $payment_method |
|
1038 | + ); |
|
1039 | + } |
|
1040 | + } |
|
1041 | + // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
1042 | + // of PMs |
|
1043 | + $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
1044 | + // now generate the actual form inputs |
|
1045 | + $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
1046 | + $available_payment_method_options |
|
1047 | + ); |
|
1048 | + $available_payment_methods += $payment_methods_billing_info; |
|
1049 | + // build the available payment methods form |
|
1050 | + return new EE_Form_Section_Proper( |
|
1051 | + array( |
|
1052 | + 'html_id' => 'spco-available-methods-of-payment-dv', |
|
1053 | + 'subsections' => $available_payment_methods, |
|
1054 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1055 | + ) |
|
1056 | + ); |
|
1057 | + } |
|
1058 | + |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * _get_available_payment_methods |
|
1062 | + * |
|
1063 | + * @return EE_Payment_Method[] |
|
1064 | + * @throws EE_Error |
|
1065 | + * @throws InvalidArgumentException |
|
1066 | + * @throws ReflectionException |
|
1067 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1068 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1069 | + */ |
|
1070 | + protected function _get_available_payment_methods() |
|
1071 | + { |
|
1072 | + if (! empty($this->checkout->available_payment_methods)) { |
|
1073 | + return $this->checkout->available_payment_methods; |
|
1074 | + } |
|
1075 | + $available_payment_methods = array(); |
|
1076 | + // load EEM_Payment_Method |
|
1077 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
1078 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
1079 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
1080 | + // get all active payment methods |
|
1081 | + $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
1082 | + $this->checkout->transaction, |
|
1083 | + EEM_Payment_Method::scope_cart |
|
1084 | + ); |
|
1085 | + foreach ($payment_methods as $payment_method) { |
|
1086 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1087 | + $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1088 | + } |
|
1089 | + } |
|
1090 | + return $available_payment_methods; |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * _available_payment_method_inputs |
|
1096 | + * |
|
1097 | + * @access private |
|
1098 | + * @param array $available_payment_method_options |
|
1099 | + * @return \EE_Form_Section_Proper |
|
1100 | + */ |
|
1101 | + private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
1102 | + { |
|
1103 | + // generate inputs |
|
1104 | + return new EE_Form_Section_Proper( |
|
1105 | + array( |
|
1106 | + 'html_id' => 'ee-available-payment-method-inputs', |
|
1107 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1108 | + 'subsections' => array( |
|
1109 | + '' => new EE_Radio_Button_Input( |
|
1110 | + $available_payment_method_options, |
|
1111 | + array( |
|
1112 | + 'html_name' => 'selected_method_of_payment', |
|
1113 | + 'html_class' => 'spco-payment-method', |
|
1114 | + 'default' => $this->checkout->selected_method_of_payment, |
|
1115 | + 'label_size' => 11, |
|
1116 | + 'enforce_label_size' => true, |
|
1117 | + ) |
|
1118 | + ), |
|
1119 | + ), |
|
1120 | + ) |
|
1121 | + ); |
|
1122 | + } |
|
1123 | + |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * _payment_method_billing_info |
|
1127 | + * |
|
1128 | + * @access private |
|
1129 | + * @param EE_Payment_Method $payment_method |
|
1130 | + * @return EE_Form_Section_Proper |
|
1131 | + * @throws EE_Error |
|
1132 | + * @throws InvalidArgumentException |
|
1133 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1134 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1135 | + */ |
|
1136 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
1137 | + { |
|
1138 | + $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
1139 | + ? true |
|
1140 | + : false; |
|
1141 | + // generate the billing form for payment method |
|
1142 | + $billing_form = $currently_selected |
|
1143 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1144 | + : new EE_Form_Section_HTML(); |
|
1145 | + $this->checkout->billing_form = $currently_selected |
|
1146 | + ? $billing_form |
|
1147 | + : $this->checkout->billing_form; |
|
1148 | + // it's all in the details |
|
1149 | + $info_html = EEH_HTML::h3( |
|
1150 | + esc_html__('Important information regarding your payment', 'event_espresso'), |
|
1151 | + '', |
|
1152 | + 'spco-payment-method-hdr' |
|
1153 | + ); |
|
1154 | + // add some info regarding the step, either from what's saved in the admin, |
|
1155 | + // or a default string depending on whether the PM has a billing form or not |
|
1156 | + if ($payment_method->description()) { |
|
1157 | + $payment_method_info = $payment_method->description(); |
|
1158 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1159 | + $payment_method_info = sprintf( |
|
1160 | + esc_html__( |
|
1161 | + 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
1162 | + 'event_espresso' |
|
1163 | + ), |
|
1164 | + $this->submit_button_text() |
|
1165 | + ); |
|
1166 | + } else { |
|
1167 | + $payment_method_info = sprintf( |
|
1168 | + esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1169 | + $this->submit_button_text() |
|
1170 | + ); |
|
1171 | + } |
|
1172 | + $info_html .= EEH_HTML::p( |
|
1173 | + apply_filters( |
|
1174 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
1175 | + $payment_method_info |
|
1176 | + ), |
|
1177 | + '', |
|
1178 | + 'spco-payment-method-desc ee-attention' |
|
1179 | + ); |
|
1180 | + return new EE_Form_Section_Proper( |
|
1181 | + array( |
|
1182 | + 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1183 | + 'html_class' => 'spco-payment-method-info-dv', |
|
1184 | + // only display the selected or default PM |
|
1185 | + 'html_style' => $currently_selected ? '' : 'display:none;', |
|
1186 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1187 | + 'subsections' => array( |
|
1188 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
1189 | + 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
1190 | + ), |
|
1191 | + ) |
|
1192 | + ); |
|
1193 | + } |
|
1194 | + |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * get_billing_form_html_for_payment_method |
|
1198 | + * |
|
1199 | + * @access public |
|
1200 | + * @return string |
|
1201 | + * @throws EE_Error |
|
1202 | + * @throws InvalidArgumentException |
|
1203 | + * @throws ReflectionException |
|
1204 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1205 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1206 | + */ |
|
1207 | + public function get_billing_form_html_for_payment_method() |
|
1208 | + { |
|
1209 | + // how have they chosen to pay? |
|
1210 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1211 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1212 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1213 | + return false; |
|
1214 | + } |
|
1215 | + if (apply_filters( |
|
1216 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1217 | + false |
|
1218 | + )) { |
|
1219 | + EE_Error::add_success( |
|
1220 | + apply_filters( |
|
1221 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1222 | + sprintf( |
|
1223 | + esc_html__( |
|
1224 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1225 | + 'event_espresso' |
|
1226 | + ), |
|
1227 | + $this->checkout->payment_method->name() |
|
1228 | + ) |
|
1229 | + ) |
|
1230 | + ); |
|
1231 | + } |
|
1232 | + // now generate billing form for selected method of payment |
|
1233 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1234 | + // fill form with attendee info if applicable |
|
1235 | + if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1236 | + && $this->checkout->transaction_has_primary_registrant() |
|
1237 | + ) { |
|
1238 | + $payment_method_billing_form->populate_from_attendee( |
|
1239 | + $this->checkout->transaction->primary_registration()->attendee() |
|
1240 | + ); |
|
1241 | + } |
|
1242 | + // and debug content |
|
1243 | + if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
1244 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1245 | + ) { |
|
1246 | + $payment_method_billing_form = |
|
1247 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1248 | + $payment_method_billing_form |
|
1249 | + ); |
|
1250 | + } |
|
1251 | + $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
1252 | + ? $payment_method_billing_form->get_html() |
|
1253 | + : ''; |
|
1254 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
1255 | + // localize validation rules for main form |
|
1256 | + $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
1257 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1258 | + return true; |
|
1259 | + } |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * _get_billing_form_for_payment_method |
|
1264 | + * |
|
1265 | + * @access private |
|
1266 | + * @param EE_Payment_Method $payment_method |
|
1267 | + * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1268 | + * @throws EE_Error |
|
1269 | + * @throws InvalidArgumentException |
|
1270 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1271 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1272 | + */ |
|
1273 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
1274 | + { |
|
1275 | + $billing_form = $payment_method->type_obj()->billing_form( |
|
1276 | + $this->checkout->transaction, |
|
1277 | + array('amount_owing' => $this->checkout->amount_owing) |
|
1278 | + ); |
|
1279 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1280 | + if (apply_filters( |
|
1281 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1282 | + false |
|
1283 | + ) |
|
1284 | + && EE_Registry::instance()->REQ->is_set('payment_method') |
|
1285 | + ) { |
|
1286 | + EE_Error::add_success( |
|
1287 | + apply_filters( |
|
1288 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1289 | + sprintf( |
|
1290 | + esc_html__( |
|
1291 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1292 | + 'event_espresso' |
|
1293 | + ), |
|
1294 | + $payment_method->name() |
|
1295 | + ) |
|
1296 | + ) |
|
1297 | + ); |
|
1298 | + } |
|
1299 | + return apply_filters( |
|
1300 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
1301 | + $billing_form, |
|
1302 | + $payment_method |
|
1303 | + ); |
|
1304 | + } |
|
1305 | + // no actual billing form, so return empty HTML form section |
|
1306 | + return new EE_Form_Section_HTML(); |
|
1307 | + } |
|
1308 | + |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * _get_selected_method_of_payment |
|
1312 | + * |
|
1313 | + * @access private |
|
1314 | + * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
1315 | + * is not found in the incoming request |
|
1316 | + * @param string $request_param |
|
1317 | + * @return NULL|string |
|
1318 | + * @throws EE_Error |
|
1319 | + * @throws InvalidArgumentException |
|
1320 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1321 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1322 | + */ |
|
1323 | + private function _get_selected_method_of_payment( |
|
1324 | + $required = false, |
|
1325 | + $request_param = 'selected_method_of_payment' |
|
1326 | + ) { |
|
1327 | + // is selected_method_of_payment set in the request ? |
|
1328 | + $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
1329 | + if ($selected_method_of_payment) { |
|
1330 | + // sanitize it |
|
1331 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1332 | + ? array_shift($selected_method_of_payment) |
|
1333 | + : $selected_method_of_payment; |
|
1334 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1335 | + // store it in the session so that it's available for all subsequent requests including AJAX |
|
1336 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1337 | + } else { |
|
1338 | + // or is is set in the session ? |
|
1339 | + $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
1340 | + 'selected_method_of_payment' |
|
1341 | + ); |
|
1342 | + } |
|
1343 | + // do ya really really gotta have it? |
|
1344 | + if (empty($selected_method_of_payment) && $required) { |
|
1345 | + EE_Error::add_error( |
|
1346 | + sprintf( |
|
1347 | + esc_html__( |
|
1348 | + 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
1349 | + 'event_espresso' |
|
1350 | + ), |
|
1351 | + '<br/>', |
|
1352 | + '<br/>', |
|
1353 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1354 | + ), |
|
1355 | + __FILE__, |
|
1356 | + __FUNCTION__, |
|
1357 | + __LINE__ |
|
1358 | + ); |
|
1359 | + return null; |
|
1360 | + } |
|
1361 | + return $selected_method_of_payment; |
|
1362 | + } |
|
1363 | + |
|
1364 | + |
|
1365 | + |
|
1366 | + |
|
1367 | + |
|
1368 | + |
|
1369 | + /********************************************************************************************************/ |
|
1370 | + /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
1371 | + /********************************************************************************************************/ |
|
1372 | + /** |
|
1373 | + * switch_payment_method |
|
1374 | + * |
|
1375 | + * @access public |
|
1376 | + * @return string |
|
1377 | + * @throws EE_Error |
|
1378 | + * @throws InvalidArgumentException |
|
1379 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1380 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1381 | + */ |
|
1382 | + public function switch_payment_method() |
|
1383 | + { |
|
1384 | + if (! $this->_verify_payment_method_is_set()) { |
|
1385 | + return false; |
|
1386 | + } |
|
1387 | + if (apply_filters( |
|
1388 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1389 | + false |
|
1390 | + )) { |
|
1391 | + EE_Error::add_success( |
|
1392 | + apply_filters( |
|
1393 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1394 | + sprintf( |
|
1395 | + esc_html__( |
|
1396 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1397 | + 'event_espresso' |
|
1398 | + ), |
|
1399 | + $this->checkout->payment_method->name() |
|
1400 | + ) |
|
1401 | + ) |
|
1402 | + ); |
|
1403 | + } |
|
1404 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1405 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1406 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1407 | + $this->checkout->payment_method |
|
1408 | + ); |
|
1409 | + } |
|
1410 | + // fill form with attendee info if applicable |
|
1411 | + if (apply_filters( |
|
1412 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
1413 | + ( |
|
1414 | + $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1415 | + && $this->checkout->transaction_has_primary_registrant() |
|
1416 | + ), |
|
1417 | + $this->checkout->billing_form, |
|
1418 | + $this->checkout->transaction |
|
1419 | + ) |
|
1420 | + ) { |
|
1421 | + $this->checkout->billing_form->populate_from_attendee( |
|
1422 | + $this->checkout->transaction->primary_registration()->attendee() |
|
1423 | + ); |
|
1424 | + } |
|
1425 | + // and debug content |
|
1426 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1427 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1428 | + ) { |
|
1429 | + $this->checkout->billing_form = |
|
1430 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1431 | + $this->checkout->billing_form |
|
1432 | + ); |
|
1433 | + } |
|
1434 | + // get html and validation rules for form |
|
1435 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1436 | + $this->checkout->json_response->set_return_data( |
|
1437 | + array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
1438 | + ); |
|
1439 | + // localize validation rules for main form |
|
1440 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
1441 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1442 | + } else { |
|
1443 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
1444 | + } |
|
1445 | + // prevents advancement to next step |
|
1446 | + $this->checkout->continue_reg = false; |
|
1447 | + return true; |
|
1448 | + } |
|
1449 | + |
|
1450 | + |
|
1451 | + /** |
|
1452 | + * _verify_payment_method_is_set |
|
1453 | + * |
|
1454 | + * @return bool |
|
1455 | + * @throws EE_Error |
|
1456 | + * @throws InvalidArgumentException |
|
1457 | + * @throws ReflectionException |
|
1458 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1459 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1460 | + */ |
|
1461 | + protected function _verify_payment_method_is_set() |
|
1462 | + { |
|
1463 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1464 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1465 | + // how have they chosen to pay? |
|
1466 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1467 | + } else { |
|
1468 | + // choose your own adventure based on method_of_payment |
|
1469 | + switch ($this->checkout->selected_method_of_payment) { |
|
1470 | + case 'events_sold_out': |
|
1471 | + EE_Error::add_attention( |
|
1472 | + apply_filters( |
|
1473 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
1474 | + esc_html__( |
|
1475 | + 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1476 | + 'event_espresso' |
|
1477 | + ) |
|
1478 | + ), |
|
1479 | + __FILE__, |
|
1480 | + __FUNCTION__, |
|
1481 | + __LINE__ |
|
1482 | + ); |
|
1483 | + return false; |
|
1484 | + break; |
|
1485 | + case 'payments_closed': |
|
1486 | + EE_Error::add_attention( |
|
1487 | + apply_filters( |
|
1488 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
1489 | + esc_html__( |
|
1490 | + 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
1491 | + 'event_espresso' |
|
1492 | + ) |
|
1493 | + ), |
|
1494 | + __FILE__, |
|
1495 | + __FUNCTION__, |
|
1496 | + __LINE__ |
|
1497 | + ); |
|
1498 | + return false; |
|
1499 | + break; |
|
1500 | + case 'no_payment_required': |
|
1501 | + EE_Error::add_attention( |
|
1502 | + apply_filters( |
|
1503 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
1504 | + esc_html__( |
|
1505 | + 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
1506 | + 'event_espresso' |
|
1507 | + ) |
|
1508 | + ), |
|
1509 | + __FILE__, |
|
1510 | + __FUNCTION__, |
|
1511 | + __LINE__ |
|
1512 | + ); |
|
1513 | + return false; |
|
1514 | + break; |
|
1515 | + default: |
|
1516 | + } |
|
1517 | + } |
|
1518 | + // verify payment method |
|
1519 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1520 | + // get payment method for selected method of payment |
|
1521 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1522 | + } |
|
1523 | + return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
1524 | + } |
|
1525 | + |
|
1526 | + |
|
1527 | + |
|
1528 | + /********************************************************************************************************/ |
|
1529 | + /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
1530 | + /********************************************************************************************************/ |
|
1531 | + /** |
|
1532 | + * save_payer_details_via_ajax |
|
1533 | + * |
|
1534 | + * @return void |
|
1535 | + * @throws EE_Error |
|
1536 | + * @throws InvalidArgumentException |
|
1537 | + * @throws ReflectionException |
|
1538 | + * @throws RuntimeException |
|
1539 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1540 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1541 | + */ |
|
1542 | + public function save_payer_details_via_ajax() |
|
1543 | + { |
|
1544 | + if (! $this->_verify_payment_method_is_set()) { |
|
1545 | + return; |
|
1546 | + } |
|
1547 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1548 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1549 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1550 | + $this->checkout->payment_method |
|
1551 | + ); |
|
1552 | + } |
|
1553 | + // generate primary attendee from payer info if applicable |
|
1554 | + if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1555 | + $attendee = $this->_create_attendee_from_request_data(); |
|
1556 | + if ($attendee instanceof EE_Attendee) { |
|
1557 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1558 | + if ($registration->is_primary_registrant()) { |
|
1559 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1560 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1561 | + $registration->set_attendee_id($attendee->ID()); |
|
1562 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1563 | + } |
|
1564 | + } |
|
1565 | + } |
|
1566 | + } |
|
1567 | + } |
|
1568 | + |
|
1569 | + |
|
1570 | + /** |
|
1571 | + * create_attendee_from_request_data |
|
1572 | + * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
1573 | + * |
|
1574 | + * @return EE_Attendee |
|
1575 | + * @throws EE_Error |
|
1576 | + * @throws InvalidArgumentException |
|
1577 | + * @throws ReflectionException |
|
1578 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1579 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1580 | + */ |
|
1581 | + protected function _create_attendee_from_request_data() |
|
1582 | + { |
|
1583 | + // get State ID |
|
1584 | + $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
1585 | + if (! empty($STA_ID)) { |
|
1586 | + // can we get state object from name ? |
|
1587 | + EE_Registry::instance()->load_model('State'); |
|
1588 | + $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
1589 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1590 | + } |
|
1591 | + // get Country ISO |
|
1592 | + $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
1593 | + if (! empty($CNT_ISO)) { |
|
1594 | + // can we get country object from name ? |
|
1595 | + EE_Registry::instance()->load_model('Country'); |
|
1596 | + $country = EEM_Country::instance()->get_col( |
|
1597 | + array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
1598 | + 'CNT_ISO' |
|
1599 | + ); |
|
1600 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1601 | + } |
|
1602 | + // grab attendee data |
|
1603 | + $attendee_data = array( |
|
1604 | + 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
1605 | + 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
1606 | + 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
1607 | + 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
1608 | + 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
1609 | + 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
1610 | + 'STA_ID' => $STA_ID, |
|
1611 | + 'CNT_ISO' => $CNT_ISO, |
|
1612 | + 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
1613 | + 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
1614 | + ); |
|
1615 | + // validate the email address since it is the most important piece of info |
|
1616 | + if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
1617 | + EE_Error::add_error( |
|
1618 | + esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
1619 | + __FILE__, |
|
1620 | + __FUNCTION__, |
|
1621 | + __LINE__ |
|
1622 | + ); |
|
1623 | + } |
|
1624 | + // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
1625 | + // AND email address |
|
1626 | + if (! empty($attendee_data['ATT_fname']) |
|
1627 | + && ! empty($attendee_data['ATT_lname']) |
|
1628 | + && ! empty($attendee_data['ATT_email']) |
|
1629 | + ) { |
|
1630 | + $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
1631 | + array( |
|
1632 | + 'ATT_fname' => $attendee_data['ATT_fname'], |
|
1633 | + 'ATT_lname' => $attendee_data['ATT_lname'], |
|
1634 | + 'ATT_email' => $attendee_data['ATT_email'], |
|
1635 | + ) |
|
1636 | + ); |
|
1637 | + if ($existing_attendee instanceof EE_Attendee) { |
|
1638 | + return $existing_attendee; |
|
1639 | + } |
|
1640 | + } |
|
1641 | + // no existing attendee? kk let's create a new one |
|
1642 | + // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
1643 | + // don't exist |
|
1644 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1645 | + ? $attendee_data['ATT_fname'] |
|
1646 | + : $attendee_data['ATT_email']; |
|
1647 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1648 | + ? $attendee_data['ATT_lname'] |
|
1649 | + : $attendee_data['ATT_email']; |
|
1650 | + return EE_Attendee::new_instance($attendee_data); |
|
1651 | + } |
|
1652 | + |
|
1653 | + |
|
1654 | + |
|
1655 | + /********************************************************************************************************/ |
|
1656 | + /**************************************** PROCESS REG STEP *****************************************/ |
|
1657 | + /********************************************************************************************************/ |
|
1658 | + /** |
|
1659 | + * process_reg_step |
|
1660 | + * |
|
1661 | + * @return bool |
|
1662 | + * @throws EE_Error |
|
1663 | + * @throws InvalidArgumentException |
|
1664 | + * @throws ReflectionException |
|
1665 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1666 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1667 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1668 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1669 | + */ |
|
1670 | + public function process_reg_step() |
|
1671 | + { |
|
1672 | + // how have they chosen to pay? |
|
1673 | + $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
1674 | + ? 'no_payment_required' |
|
1675 | + : $this->_get_selected_method_of_payment(true); |
|
1676 | + // choose your own adventure based on method_of_payment |
|
1677 | + switch ($this->checkout->selected_method_of_payment) { |
|
1678 | + case 'events_sold_out': |
|
1679 | + $this->checkout->redirect = true; |
|
1680 | + $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
1681 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1682 | + // mark this reg step as completed |
|
1683 | + $this->set_completed(); |
|
1684 | + return false; |
|
1685 | + break; |
|
1686 | + |
|
1687 | + case 'payments_closed': |
|
1688 | + if (apply_filters( |
|
1689 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
1690 | + false |
|
1691 | + )) { |
|
1692 | + EE_Error::add_success( |
|
1693 | + esc_html__('no payment required at this time.', 'event_espresso'), |
|
1694 | + __FILE__, |
|
1695 | + __FUNCTION__, |
|
1696 | + __LINE__ |
|
1697 | + ); |
|
1698 | + } |
|
1699 | + // mark this reg step as completed |
|
1700 | + $this->set_completed(); |
|
1701 | + return true; |
|
1702 | + break; |
|
1703 | + |
|
1704 | + case 'no_payment_required': |
|
1705 | + if (apply_filters( |
|
1706 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
1707 | + false |
|
1708 | + )) { |
|
1709 | + EE_Error::add_success( |
|
1710 | + esc_html__('no payment required.', 'event_espresso'), |
|
1711 | + __FILE__, |
|
1712 | + __FUNCTION__, |
|
1713 | + __LINE__ |
|
1714 | + ); |
|
1715 | + } |
|
1716 | + // mark this reg step as completed |
|
1717 | + $this->set_completed(); |
|
1718 | + return true; |
|
1719 | + break; |
|
1720 | + |
|
1721 | + default: |
|
1722 | + $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
1723 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
1724 | + ); |
|
1725 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
1726 | + $registrations, |
|
1727 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
1728 | + ); |
|
1729 | + // calculate difference between the two arrays |
|
1730 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
1731 | + if (empty($registrations)) { |
|
1732 | + $this->_redirect_because_event_sold_out(); |
|
1733 | + return false; |
|
1734 | + } |
|
1735 | + $payment_successful = $this->_process_payment(); |
|
1736 | + if ($payment_successful) { |
|
1737 | + $this->checkout->continue_reg = true; |
|
1738 | + $this->_maybe_set_completed($this->checkout->payment_method); |
|
1739 | + } else { |
|
1740 | + $this->checkout->continue_reg = false; |
|
1741 | + } |
|
1742 | + return $payment_successful; |
|
1743 | + } |
|
1744 | + } |
|
1745 | + |
|
1746 | + |
|
1747 | + /** |
|
1748 | + * _redirect_because_event_sold_out |
|
1749 | + * |
|
1750 | + * @access protected |
|
1751 | + * @return void |
|
1752 | + */ |
|
1753 | + protected function _redirect_because_event_sold_out() |
|
1754 | + { |
|
1755 | + $this->checkout->continue_reg = false; |
|
1756 | + // set redirect URL |
|
1757 | + $this->checkout->redirect_url = add_query_arg( |
|
1758 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1759 | + $this->checkout->current_step->reg_step_url() |
|
1760 | + ); |
|
1761 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1762 | + } |
|
1763 | + |
|
1764 | + |
|
1765 | + /** |
|
1766 | + * _maybe_set_completed |
|
1767 | + * |
|
1768 | + * @access protected |
|
1769 | + * @param \EE_Payment_Method $payment_method |
|
1770 | + * @return void |
|
1771 | + * @throws \EE_Error |
|
1772 | + */ |
|
1773 | + protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
1774 | + { |
|
1775 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
1776 | + case EE_PMT_Base::offsite: |
|
1777 | + break; |
|
1778 | + case EE_PMT_Base::onsite: |
|
1779 | + case EE_PMT_Base::offline: |
|
1780 | + // mark this reg step as completed |
|
1781 | + $this->set_completed(); |
|
1782 | + break; |
|
1783 | + } |
|
1784 | + } |
|
1785 | + |
|
1786 | + |
|
1787 | + /** |
|
1788 | + * update_reg_step |
|
1789 | + * this is the final step after a user revisits the site to retry a payment |
|
1790 | + * |
|
1791 | + * @return bool |
|
1792 | + * @throws EE_Error |
|
1793 | + * @throws InvalidArgumentException |
|
1794 | + * @throws ReflectionException |
|
1795 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1796 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1797 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1798 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1799 | + */ |
|
1800 | + public function update_reg_step() |
|
1801 | + { |
|
1802 | + $success = true; |
|
1803 | + // if payment required |
|
1804 | + if ($this->checkout->transaction->total() > 0) { |
|
1805 | + do_action( |
|
1806 | + 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
1807 | + $this->checkout->transaction |
|
1808 | + ); |
|
1809 | + // attempt payment via payment method |
|
1810 | + $success = $this->process_reg_step(); |
|
1811 | + } |
|
1812 | + if ($success && ! $this->checkout->redirect) { |
|
1813 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
1814 | + $this->checkout->transaction->ID() |
|
1815 | + ); |
|
1816 | + // set return URL |
|
1817 | + $this->checkout->redirect_url = add_query_arg( |
|
1818 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1819 | + $this->checkout->thank_you_page_url |
|
1820 | + ); |
|
1821 | + } |
|
1822 | + return $success; |
|
1823 | + } |
|
1824 | + |
|
1825 | + |
|
1826 | + /** |
|
1827 | + * _process_payment |
|
1828 | + * |
|
1829 | + * @access private |
|
1830 | + * @return bool |
|
1831 | + * @throws EE_Error |
|
1832 | + * @throws InvalidArgumentException |
|
1833 | + * @throws ReflectionException |
|
1834 | + * @throws RuntimeException |
|
1835 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1836 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1837 | + */ |
|
1838 | + private function _process_payment() |
|
1839 | + { |
|
1840 | + // basically confirm that the event hasn't sold out since they hit the page |
|
1841 | + if (! $this->_last_second_ticket_verifications()) { |
|
1842 | + return false; |
|
1843 | + } |
|
1844 | + // ya gotta make a choice man |
|
1845 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1846 | + $this->checkout->json_response->set_plz_select_method_of_payment( |
|
1847 | + esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
1848 | + ); |
|
1849 | + return false; |
|
1850 | + } |
|
1851 | + // get EE_Payment_Method object |
|
1852 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1853 | + return false; |
|
1854 | + } |
|
1855 | + // setup billing form |
|
1856 | + if ($this->checkout->payment_method->is_on_site()) { |
|
1857 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1858 | + $this->checkout->payment_method |
|
1859 | + ); |
|
1860 | + // bad billing form ? |
|
1861 | + if (! $this->_billing_form_is_valid()) { |
|
1862 | + return false; |
|
1863 | + } |
|
1864 | + } |
|
1865 | + // ensure primary registrant has been fully processed |
|
1866 | + if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1867 | + return false; |
|
1868 | + } |
|
1869 | + // if session is close to expiring (under 10 minutes by default) |
|
1870 | + if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
1871 | + // add some time to session expiration so that payment can be completed |
|
1872 | + EE_Registry::instance()->SSN->extend_expiration(); |
|
1873 | + } |
|
1874 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
1875 | + // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
1876 | + // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
1877 | + // for events with a default reg status of Approved |
|
1878 | + // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
1879 | + // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
1880 | + // ); |
|
1881 | + // attempt payment |
|
1882 | + $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
1883 | + // process results |
|
1884 | + $payment = $this->_validate_payment($payment); |
|
1885 | + $payment = $this->_post_payment_processing($payment); |
|
1886 | + // verify payment |
|
1887 | + if ($payment instanceof EE_Payment) { |
|
1888 | + // store that for later |
|
1889 | + $this->checkout->payment = $payment; |
|
1890 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
1891 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1892 | + $payment_status = $payment->status(); |
|
1893 | + if ($payment_status === EEM_Payment::status_id_approved |
|
1894 | + || $payment_status === EEM_Payment::status_id_pending |
|
1895 | + ) { |
|
1896 | + return true; |
|
1897 | + } else { |
|
1898 | + return false; |
|
1899 | + } |
|
1900 | + } elseif ($payment === true) { |
|
1901 | + // please note that offline payment methods will NOT make a payment, |
|
1902 | + // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
1903 | + $this->checkout->payment = $payment; |
|
1904 | + return true; |
|
1905 | + } |
|
1906 | + // where's my money? |
|
1907 | + return false; |
|
1908 | + } |
|
1909 | + |
|
1910 | + |
|
1911 | + /** |
|
1912 | + * _last_second_ticket_verifications |
|
1913 | + * |
|
1914 | + * @access public |
|
1915 | + * @return bool |
|
1916 | + * @throws EE_Error |
|
1917 | + */ |
|
1918 | + protected function _last_second_ticket_verifications() |
|
1919 | + { |
|
1920 | + // don't bother re-validating if not a return visit |
|
1921 | + if (! $this->checkout->revisit) { |
|
1922 | + return true; |
|
1923 | + } |
|
1924 | + $registrations = $this->checkout->transaction->registrations(); |
|
1925 | + if (empty($registrations)) { |
|
1926 | + return false; |
|
1927 | + } |
|
1928 | + foreach ($registrations as $registration) { |
|
1929 | + if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
1930 | + $event = $registration->event_obj(); |
|
1931 | + if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
1932 | + EE_Error::add_error( |
|
1933 | + apply_filters( |
|
1934 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
1935 | + sprintf( |
|
1936 | + esc_html__( |
|
1937 | + 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
1938 | + 'event_espresso' |
|
1939 | + ), |
|
1940 | + $event->name() |
|
1941 | + ) |
|
1942 | + ), |
|
1943 | + __FILE__, |
|
1944 | + __FUNCTION__, |
|
1945 | + __LINE__ |
|
1946 | + ); |
|
1947 | + return false; |
|
1948 | + } |
|
1949 | + } |
|
1950 | + } |
|
1951 | + return true; |
|
1952 | + } |
|
1953 | + |
|
1954 | + |
|
1955 | + /** |
|
1956 | + * redirect_form |
|
1957 | + * |
|
1958 | + * @access public |
|
1959 | + * @return bool |
|
1960 | + * @throws EE_Error |
|
1961 | + * @throws InvalidArgumentException |
|
1962 | + * @throws ReflectionException |
|
1963 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1964 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1965 | + */ |
|
1966 | + public function redirect_form() |
|
1967 | + { |
|
1968 | + $payment_method_billing_info = $this->_payment_method_billing_info( |
|
1969 | + $this->_get_payment_method_for_selected_method_of_payment() |
|
1970 | + ); |
|
1971 | + $html = $payment_method_billing_info->get_html(); |
|
1972 | + $html .= $this->checkout->redirect_form; |
|
1973 | + EE_Registry::instance()->REQ->add_output($html); |
|
1974 | + return true; |
|
1975 | + } |
|
1976 | + |
|
1977 | + |
|
1978 | + /** |
|
1979 | + * _billing_form_is_valid |
|
1980 | + * |
|
1981 | + * @access private |
|
1982 | + * @return bool |
|
1983 | + * @throws \EE_Error |
|
1984 | + */ |
|
1985 | + private function _billing_form_is_valid() |
|
1986 | + { |
|
1987 | + if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1988 | + return true; |
|
1989 | + } |
|
1990 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
1991 | + if ($this->checkout->billing_form->was_submitted()) { |
|
1992 | + $this->checkout->billing_form->receive_form_submission(); |
|
1993 | + if ($this->checkout->billing_form->is_valid()) { |
|
1994 | + return true; |
|
1995 | + } |
|
1996 | + $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
1997 | + $error_strings = array(); |
|
1998 | + foreach ($validation_errors as $validation_error) { |
|
1999 | + if ($validation_error instanceof EE_Validation_Error) { |
|
2000 | + $form_section = $validation_error->get_form_section(); |
|
2001 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
2002 | + $label = $form_section->html_label_text(); |
|
2003 | + } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
2004 | + $label = $form_section->name(); |
|
2005 | + } else { |
|
2006 | + $label = esc_html__('Validation Error', 'event_espresso'); |
|
2007 | + } |
|
2008 | + $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
2009 | + } |
|
2010 | + } |
|
2011 | + EE_Error::add_error( |
|
2012 | + sprintf( |
|
2013 | + esc_html__( |
|
2014 | + 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
2015 | + 'event_espresso' |
|
2016 | + ), |
|
2017 | + '<br/>', |
|
2018 | + implode('<br/>', $error_strings) |
|
2019 | + ), |
|
2020 | + __FILE__, |
|
2021 | + __FUNCTION__, |
|
2022 | + __LINE__ |
|
2023 | + ); |
|
2024 | + } else { |
|
2025 | + EE_Error::add_error( |
|
2026 | + esc_html__( |
|
2027 | + 'The billing form was not submitted or something prevented it\'s submission.', |
|
2028 | + 'event_espresso' |
|
2029 | + ), |
|
2030 | + __FILE__, |
|
2031 | + __FUNCTION__, |
|
2032 | + __LINE__ |
|
2033 | + ); |
|
2034 | + } |
|
2035 | + } else { |
|
2036 | + EE_Error::add_error( |
|
2037 | + esc_html__( |
|
2038 | + 'The submitted billing form is invalid possibly due to a technical reason.', |
|
2039 | + 'event_espresso' |
|
2040 | + ), |
|
2041 | + __FILE__, |
|
2042 | + __FUNCTION__, |
|
2043 | + __LINE__ |
|
2044 | + ); |
|
2045 | + } |
|
2046 | + return false; |
|
2047 | + } |
|
2048 | + |
|
2049 | + |
|
2050 | + /** |
|
2051 | + * _setup_primary_registrant_prior_to_payment |
|
2052 | + * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
2053 | + * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
2054 | + * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
2055 | + * yet) |
|
2056 | + * |
|
2057 | + * @access private |
|
2058 | + * @return bool |
|
2059 | + * @throws EE_Error |
|
2060 | + * @throws InvalidArgumentException |
|
2061 | + * @throws ReflectionException |
|
2062 | + * @throws RuntimeException |
|
2063 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2064 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2065 | + */ |
|
2066 | + private function _setup_primary_registrant_prior_to_payment() |
|
2067 | + { |
|
2068 | + // check if transaction has a primary registrant and that it has a related Attendee object |
|
2069 | + // if not, then we need to at least gather some primary registrant data before attempting payment |
|
2070 | + if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
2071 | + && ! $this->checkout->transaction_has_primary_registrant() |
|
2072 | + && ! $this->_capture_primary_registration_data_from_billing_form() |
|
2073 | + ) { |
|
2074 | + return false; |
|
2075 | + } |
|
2076 | + // because saving an object clears it's cache, we need to do the chevy shuffle |
|
2077 | + // grab the primary_registration object |
|
2078 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2079 | + // at this point we'll consider a TXN to not have been failed |
|
2080 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
2081 | + // save the TXN ( which clears cached copy of primary_registration) |
|
2082 | + $this->checkout->transaction->save(); |
|
2083 | + // grab TXN ID and save it to the primary_registration |
|
2084 | + $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
2085 | + // save what we have so far |
|
2086 | + $primary_registration->save(); |
|
2087 | + return true; |
|
2088 | + } |
|
2089 | + |
|
2090 | + |
|
2091 | + /** |
|
2092 | + * _capture_primary_registration_data_from_billing_form |
|
2093 | + * |
|
2094 | + * @access private |
|
2095 | + * @return bool |
|
2096 | + * @throws EE_Error |
|
2097 | + * @throws InvalidArgumentException |
|
2098 | + * @throws ReflectionException |
|
2099 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2100 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2101 | + */ |
|
2102 | + private function _capture_primary_registration_data_from_billing_form() |
|
2103 | + { |
|
2104 | + // convert billing form data into an attendee |
|
2105 | + $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
2106 | + if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2107 | + EE_Error::add_error( |
|
2108 | + sprintf( |
|
2109 | + esc_html__( |
|
2110 | + 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2111 | + 'event_espresso' |
|
2112 | + ), |
|
2113 | + '<br/>', |
|
2114 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2115 | + ), |
|
2116 | + __FILE__, |
|
2117 | + __FUNCTION__, |
|
2118 | + __LINE__ |
|
2119 | + ); |
|
2120 | + return false; |
|
2121 | + } |
|
2122 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2123 | + if (! $primary_registration instanceof EE_Registration) { |
|
2124 | + EE_Error::add_error( |
|
2125 | + sprintf( |
|
2126 | + esc_html__( |
|
2127 | + 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2128 | + 'event_espresso' |
|
2129 | + ), |
|
2130 | + '<br/>', |
|
2131 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2132 | + ), |
|
2133 | + __FILE__, |
|
2134 | + __FUNCTION__, |
|
2135 | + __LINE__ |
|
2136 | + ); |
|
2137 | + return false; |
|
2138 | + } |
|
2139 | + if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2140 | + instanceof |
|
2141 | + EE_Attendee |
|
2142 | + ) { |
|
2143 | + EE_Error::add_error( |
|
2144 | + sprintf( |
|
2145 | + esc_html__( |
|
2146 | + 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2147 | + 'event_espresso' |
|
2148 | + ), |
|
2149 | + '<br/>', |
|
2150 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2151 | + ), |
|
2152 | + __FILE__, |
|
2153 | + __FUNCTION__, |
|
2154 | + __LINE__ |
|
2155 | + ); |
|
2156 | + return false; |
|
2157 | + } |
|
2158 | + /** @type EE_Registration_Processor $registration_processor */ |
|
2159 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
2160 | + // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
2161 | + $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
2162 | + return true; |
|
2163 | + } |
|
2164 | + |
|
2165 | + |
|
2166 | + /** |
|
2167 | + * _get_payment_method_for_selected_method_of_payment |
|
2168 | + * retrieves a valid payment method |
|
2169 | + * |
|
2170 | + * @access public |
|
2171 | + * @return EE_Payment_Method |
|
2172 | + * @throws EE_Error |
|
2173 | + * @throws InvalidArgumentException |
|
2174 | + * @throws ReflectionException |
|
2175 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2176 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2177 | + */ |
|
2178 | + private function _get_payment_method_for_selected_method_of_payment() |
|
2179 | + { |
|
2180 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2181 | + $this->_redirect_because_event_sold_out(); |
|
2182 | + return null; |
|
2183 | + } |
|
2184 | + // get EE_Payment_Method object |
|
2185 | + if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2186 | + $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2187 | + } else { |
|
2188 | + // load EEM_Payment_Method |
|
2189 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
2190 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
2191 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
2192 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2193 | + } |
|
2194 | + // verify $payment_method |
|
2195 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
2196 | + // not a payment |
|
2197 | + EE_Error::add_error( |
|
2198 | + sprintf( |
|
2199 | + esc_html__( |
|
2200 | + 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2201 | + 'event_espresso' |
|
2202 | + ), |
|
2203 | + '<br/>', |
|
2204 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2205 | + ), |
|
2206 | + __FILE__, |
|
2207 | + __FUNCTION__, |
|
2208 | + __LINE__ |
|
2209 | + ); |
|
2210 | + return null; |
|
2211 | + } |
|
2212 | + // and verify it has a valid Payment_Method Type object |
|
2213 | + if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2214 | + // not a payment |
|
2215 | + EE_Error::add_error( |
|
2216 | + sprintf( |
|
2217 | + esc_html__( |
|
2218 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2219 | + 'event_espresso' |
|
2220 | + ), |
|
2221 | + '<br/>', |
|
2222 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2223 | + ), |
|
2224 | + __FILE__, |
|
2225 | + __FUNCTION__, |
|
2226 | + __LINE__ |
|
2227 | + ); |
|
2228 | + return null; |
|
2229 | + } |
|
2230 | + return $payment_method; |
|
2231 | + } |
|
2232 | + |
|
2233 | + |
|
2234 | + /** |
|
2235 | + * _attempt_payment |
|
2236 | + * |
|
2237 | + * @access private |
|
2238 | + * @type EE_Payment_Method $payment_method |
|
2239 | + * @return mixed EE_Payment | boolean |
|
2240 | + * @throws EE_Error |
|
2241 | + * @throws InvalidArgumentException |
|
2242 | + * @throws ReflectionException |
|
2243 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2244 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2245 | + */ |
|
2246 | + private function _attempt_payment(EE_Payment_Method $payment_method) |
|
2247 | + { |
|
2248 | + $payment = null; |
|
2249 | + $this->checkout->transaction->save(); |
|
2250 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2251 | + if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2252 | + return false; |
|
2253 | + } |
|
2254 | + try { |
|
2255 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
2256 | + // generate payment object |
|
2257 | + $payment = $payment_processor->process_payment( |
|
2258 | + $payment_method, |
|
2259 | + $this->checkout->transaction, |
|
2260 | + $this->checkout->amount_owing, |
|
2261 | + $this->checkout->billing_form, |
|
2262 | + $this->_get_return_url($payment_method), |
|
2263 | + 'CART', |
|
2264 | + $this->checkout->admin_request, |
|
2265 | + true, |
|
2266 | + $this->reg_step_url() |
|
2267 | + ); |
|
2268 | + } catch (Exception $e) { |
|
2269 | + $this->_handle_payment_processor_exception($e); |
|
2270 | + } |
|
2271 | + return $payment; |
|
2272 | + } |
|
2273 | + |
|
2274 | + |
|
2275 | + /** |
|
2276 | + * _handle_payment_processor_exception |
|
2277 | + * |
|
2278 | + * @access protected |
|
2279 | + * @param \Exception $e |
|
2280 | + * @return void |
|
2281 | + * @throws EE_Error |
|
2282 | + * @throws InvalidArgumentException |
|
2283 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2284 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2285 | + */ |
|
2286 | + protected function _handle_payment_processor_exception(Exception $e) |
|
2287 | + { |
|
2288 | + EE_Error::add_error( |
|
2289 | + sprintf( |
|
2290 | + esc_html__( |
|
2291 | + 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
2292 | + 'event_espresso' |
|
2293 | + ), |
|
2294 | + '<br/>', |
|
2295 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2296 | + $e->getMessage(), |
|
2297 | + $e->getFile(), |
|
2298 | + $e->getLine() |
|
2299 | + ), |
|
2300 | + __FILE__, |
|
2301 | + __FUNCTION__, |
|
2302 | + __LINE__ |
|
2303 | + ); |
|
2304 | + } |
|
2305 | + |
|
2306 | + |
|
2307 | + /** |
|
2308 | + * _get_return_url |
|
2309 | + * |
|
2310 | + * @access protected |
|
2311 | + * @param \EE_Payment_Method $payment_method |
|
2312 | + * @return string |
|
2313 | + * @throws \EE_Error |
|
2314 | + */ |
|
2315 | + protected function _get_return_url(EE_Payment_Method $payment_method) |
|
2316 | + { |
|
2317 | + $return_url = ''; |
|
2318 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
2319 | + case EE_PMT_Base::offsite: |
|
2320 | + $return_url = add_query_arg( |
|
2321 | + array( |
|
2322 | + 'action' => 'process_gateway_response', |
|
2323 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2324 | + 'spco_txn' => $this->checkout->transaction->ID(), |
|
2325 | + ), |
|
2326 | + $this->reg_step_url() |
|
2327 | + ); |
|
2328 | + break; |
|
2329 | + case EE_PMT_Base::onsite: |
|
2330 | + case EE_PMT_Base::offline: |
|
2331 | + $return_url = $this->checkout->next_step->reg_step_url(); |
|
2332 | + break; |
|
2333 | + } |
|
2334 | + return $return_url; |
|
2335 | + } |
|
2336 | + |
|
2337 | + |
|
2338 | + /** |
|
2339 | + * _validate_payment |
|
2340 | + * |
|
2341 | + * @access private |
|
2342 | + * @param EE_Payment $payment |
|
2343 | + * @return EE_Payment|FALSE |
|
2344 | + * @throws EE_Error |
|
2345 | + * @throws InvalidArgumentException |
|
2346 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2347 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2348 | + */ |
|
2349 | + private function _validate_payment($payment = null) |
|
2350 | + { |
|
2351 | + if ($this->checkout->payment_method->is_off_line()) { |
|
2352 | + return true; |
|
2353 | + } |
|
2354 | + // verify payment object |
|
2355 | + if (! $payment instanceof EE_Payment) { |
|
2356 | + // not a payment |
|
2357 | + EE_Error::add_error( |
|
2358 | + sprintf( |
|
2359 | + esc_html__( |
|
2360 | + 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
2361 | + 'event_espresso' |
|
2362 | + ), |
|
2363 | + '<br/>', |
|
2364 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2365 | + ), |
|
2366 | + __FILE__, |
|
2367 | + __FUNCTION__, |
|
2368 | + __LINE__ |
|
2369 | + ); |
|
2370 | + return false; |
|
2371 | + } |
|
2372 | + return $payment; |
|
2373 | + } |
|
2374 | + |
|
2375 | + |
|
2376 | + /** |
|
2377 | + * _post_payment_processing |
|
2378 | + * |
|
2379 | + * @access private |
|
2380 | + * @param EE_Payment|bool $payment |
|
2381 | + * @return bool |
|
2382 | + * @throws EE_Error |
|
2383 | + * @throws InvalidArgumentException |
|
2384 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2385 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2386 | + */ |
|
2387 | + private function _post_payment_processing($payment = null) |
|
2388 | + { |
|
2389 | + // Off-Line payment? |
|
2390 | + if ($payment === true) { |
|
2391 | + // $this->_setup_redirect_for_next_step(); |
|
2392 | + return true; |
|
2393 | + // On-Site payment? |
|
2394 | + } elseif ($this->checkout->payment_method->is_on_site()) { |
|
2395 | + if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2396 | + // $this->_setup_redirect_for_next_step(); |
|
2397 | + $this->checkout->continue_reg = false; |
|
2398 | + } |
|
2399 | + // Off-Site payment? |
|
2400 | + } elseif ($this->checkout->payment_method->is_off_site()) { |
|
2401 | + // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
2402 | + if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
2403 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2404 | + $this->checkout->redirect = true; |
|
2405 | + $this->checkout->redirect_form = $payment->redirect_form(); |
|
2406 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2407 | + // set JSON response |
|
2408 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2409 | + // and lastly, let's bump the payment status to pending |
|
2410 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
2411 | + $payment->save(); |
|
2412 | + } else { |
|
2413 | + // not a payment |
|
2414 | + $this->checkout->continue_reg = false; |
|
2415 | + EE_Error::add_error( |
|
2416 | + sprintf( |
|
2417 | + esc_html__( |
|
2418 | + 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
2419 | + 'event_espresso' |
|
2420 | + ), |
|
2421 | + '<br/>', |
|
2422 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2423 | + ), |
|
2424 | + __FILE__, |
|
2425 | + __FUNCTION__, |
|
2426 | + __LINE__ |
|
2427 | + ); |
|
2428 | + } |
|
2429 | + } else { |
|
2430 | + // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
2431 | + $this->checkout->continue_reg = false; |
|
2432 | + return false; |
|
2433 | + } |
|
2434 | + return $payment; |
|
2435 | + } |
|
2436 | + |
|
2437 | + |
|
2438 | + /** |
|
2439 | + * _process_payment_status |
|
2440 | + * |
|
2441 | + * @access private |
|
2442 | + * @type EE_Payment $payment |
|
2443 | + * @param string $payment_occurs |
|
2444 | + * @return bool |
|
2445 | + * @throws EE_Error |
|
2446 | + * @throws InvalidArgumentException |
|
2447 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2448 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2449 | + */ |
|
2450 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
2451 | + { |
|
2452 | + // off-line payment? carry on |
|
2453 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
2454 | + return true; |
|
2455 | + } |
|
2456 | + // verify payment validity |
|
2457 | + if ($payment instanceof EE_Payment) { |
|
2458 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2459 | + $msg = $payment->gateway_response(); |
|
2460 | + // check results |
|
2461 | + switch ($payment->status()) { |
|
2462 | + // good payment |
|
2463 | + case EEM_Payment::status_id_approved: |
|
2464 | + EE_Error::add_success( |
|
2465 | + esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
2466 | + __FILE__, |
|
2467 | + __FUNCTION__, |
|
2468 | + __LINE__ |
|
2469 | + ); |
|
2470 | + return true; |
|
2471 | + break; |
|
2472 | + // slow payment |
|
2473 | + case EEM_Payment::status_id_pending: |
|
2474 | + if (empty($msg)) { |
|
2475 | + $msg = esc_html__( |
|
2476 | + 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
2477 | + 'event_espresso' |
|
2478 | + ); |
|
2479 | + } |
|
2480 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2481 | + return true; |
|
2482 | + break; |
|
2483 | + // don't wanna payment |
|
2484 | + case EEM_Payment::status_id_cancelled: |
|
2485 | + if (empty($msg)) { |
|
2486 | + $msg = _n( |
|
2487 | + 'Payment cancelled. Please try again.', |
|
2488 | + 'Payment cancelled. Please try again or select another method of payment.', |
|
2489 | + count($this->checkout->available_payment_methods), |
|
2490 | + 'event_espresso' |
|
2491 | + ); |
|
2492 | + } |
|
2493 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2494 | + return false; |
|
2495 | + break; |
|
2496 | + // not enough payment |
|
2497 | + case EEM_Payment::status_id_declined: |
|
2498 | + if (empty($msg)) { |
|
2499 | + $msg = _n( |
|
2500 | + 'We\'re sorry but your payment was declined. Please try again.', |
|
2501 | + 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
2502 | + count($this->checkout->available_payment_methods), |
|
2503 | + 'event_espresso' |
|
2504 | + ); |
|
2505 | + } |
|
2506 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2507 | + return false; |
|
2508 | + break; |
|
2509 | + // bad payment |
|
2510 | + case EEM_Payment::status_id_failed: |
|
2511 | + if (! empty($msg)) { |
|
2512 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2513 | + return false; |
|
2514 | + } |
|
2515 | + // default to error below |
|
2516 | + break; |
|
2517 | + } |
|
2518 | + } |
|
2519 | + // off-site payment gateway responses are too unreliable, so let's just assume that |
|
2520 | + // the payment processing is just running slower than the registrant's request |
|
2521 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2522 | + return true; |
|
2523 | + } |
|
2524 | + EE_Error::add_error( |
|
2525 | + sprintf( |
|
2526 | + esc_html__( |
|
2527 | + 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2528 | + 'event_espresso' |
|
2529 | + ), |
|
2530 | + '<br/>', |
|
2531 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2532 | + ), |
|
2533 | + __FILE__, |
|
2534 | + __FUNCTION__, |
|
2535 | + __LINE__ |
|
2536 | + ); |
|
2537 | + return false; |
|
2538 | + } |
|
2539 | + |
|
2540 | + |
|
2541 | + |
|
2542 | + |
|
2543 | + |
|
2544 | + |
|
2545 | + /********************************************************************************************************/ |
|
2546 | + /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
2547 | + /********************************************************************************************************/ |
|
2548 | + /** |
|
2549 | + * process_gateway_response |
|
2550 | + * this is the return point for Off-Site Payment Methods |
|
2551 | + * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
2552 | + * otherwise, it will load up the last payment made for the TXN. |
|
2553 | + * If the payment retrieved looks good, it will then either: |
|
2554 | + * complete the current step and allow advancement to the next reg step |
|
2555 | + * or present the payment options again |
|
2556 | + * |
|
2557 | + * @access private |
|
2558 | + * @return EE_Payment|FALSE |
|
2559 | + * @throws EE_Error |
|
2560 | + * @throws InvalidArgumentException |
|
2561 | + * @throws ReflectionException |
|
2562 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2563 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2564 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2565 | + */ |
|
2566 | + public function process_gateway_response() |
|
2567 | + { |
|
2568 | + $payment = null; |
|
2569 | + // how have they chosen to pay? |
|
2570 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2571 | + // get EE_Payment_Method object |
|
2572 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2573 | + $this->checkout->continue_reg = false; |
|
2574 | + return false; |
|
2575 | + } |
|
2576 | + if (! $this->checkout->payment_method->is_off_site()) { |
|
2577 | + return false; |
|
2578 | + } |
|
2579 | + $this->_validate_offsite_return(); |
|
2580 | + // DEBUG LOG |
|
2581 | + // $this->checkout->log( |
|
2582 | + // __CLASS__, |
|
2583 | + // __FUNCTION__, |
|
2584 | + // __LINE__, |
|
2585 | + // array( |
|
2586 | + // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2587 | + // 'payment_method' => $this->checkout->payment_method, |
|
2588 | + // ), |
|
2589 | + // true |
|
2590 | + // ); |
|
2591 | + // verify TXN |
|
2592 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2593 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
2594 | + if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2595 | + $this->checkout->continue_reg = false; |
|
2596 | + return false; |
|
2597 | + } |
|
2598 | + $payment = $this->_process_off_site_payment($gateway); |
|
2599 | + $payment = $this->_process_cancelled_payments($payment); |
|
2600 | + $payment = $this->_validate_payment($payment); |
|
2601 | + // if payment was not declined by the payment gateway or cancelled by the registrant |
|
2602 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2603 | + // $this->_setup_redirect_for_next_step(); |
|
2604 | + // store that for later |
|
2605 | + $this->checkout->payment = $payment; |
|
2606 | + // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
2607 | + // because we will complete this step during the IPN processing then |
|
2608 | + if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
2609 | + $this->set_completed(); |
|
2610 | + } |
|
2611 | + return true; |
|
2612 | + } |
|
2613 | + } |
|
2614 | + // DEBUG LOG |
|
2615 | + // $this->checkout->log( |
|
2616 | + // __CLASS__, |
|
2617 | + // __FUNCTION__, |
|
2618 | + // __LINE__, |
|
2619 | + // array('payment' => $payment) |
|
2620 | + // ); |
|
2621 | + $this->checkout->continue_reg = false; |
|
2622 | + return false; |
|
2623 | + } |
|
2624 | + |
|
2625 | + |
|
2626 | + /** |
|
2627 | + * _validate_return |
|
2628 | + * |
|
2629 | + * @access private |
|
2630 | + * @return void |
|
2631 | + * @throws EE_Error |
|
2632 | + * @throws InvalidArgumentException |
|
2633 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2634 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2635 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2636 | + */ |
|
2637 | + private function _validate_offsite_return() |
|
2638 | + { |
|
2639 | + $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
2640 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2641 | + // Houston... we might have a problem |
|
2642 | + $invalid_TXN = false; |
|
2643 | + // first gather some info |
|
2644 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2645 | + $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
2646 | + ? $valid_TXN->primary_registration() |
|
2647 | + : null; |
|
2648 | + // let's start by retrieving the cart for this TXN |
|
2649 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2650 | + if ($cart instanceof EE_Cart) { |
|
2651 | + // verify that the current cart has tickets |
|
2652 | + $tickets = $cart->get_tickets(); |
|
2653 | + if (empty($tickets)) { |
|
2654 | + $invalid_TXN = true; |
|
2655 | + } |
|
2656 | + } else { |
|
2657 | + $invalid_TXN = true; |
|
2658 | + } |
|
2659 | + $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
2660 | + ? $primary_registrant->session_ID() |
|
2661 | + : null; |
|
2662 | + // validate current Session ID and compare against valid TXN session ID |
|
2663 | + if ($invalid_TXN // if this is already true, then skip other checks |
|
2664 | + || EE_Session::instance()->id() === null |
|
2665 | + || ( |
|
2666 | + // WARNING !!! |
|
2667 | + // this could be PayPal sending back duplicate requests (ya they do that) |
|
2668 | + // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2669 | + // so now we need to determine if this current TXN looks valid or not |
|
2670 | + // and whether this reg step has even been started ? |
|
2671 | + EE_Session::instance()->id() === $valid_TXN_SID |
|
2672 | + // really? you're half way through this reg step, but you never started it ? |
|
2673 | + && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2674 | + ) |
|
2675 | + ) { |
|
2676 | + $invalid_TXN = true; |
|
2677 | + } |
|
2678 | + if ($invalid_TXN) { |
|
2679 | + // is the valid TXN completed ? |
|
2680 | + if ($valid_TXN instanceof EE_Transaction) { |
|
2681 | + // has this step even been started ? |
|
2682 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2683 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2684 | + // so it **looks** like this is a double request from PayPal |
|
2685 | + // so let's try to pick up where we left off |
|
2686 | + $this->checkout->transaction = $valid_TXN; |
|
2687 | + $this->checkout->refresh_all_entities(true); |
|
2688 | + return; |
|
2689 | + } |
|
2690 | + } |
|
2691 | + // you appear to be lost? |
|
2692 | + $this->_redirect_wayward_request($primary_registrant); |
|
2693 | + } |
|
2694 | + } |
|
2695 | + } |
|
2696 | + |
|
2697 | + |
|
2698 | + /** |
|
2699 | + * _redirect_wayward_request |
|
2700 | + * |
|
2701 | + * @access private |
|
2702 | + * @param \EE_Registration|null $primary_registrant |
|
2703 | + * @return bool |
|
2704 | + * @throws EE_Error |
|
2705 | + * @throws InvalidArgumentException |
|
2706 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2707 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2708 | + */ |
|
2709 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
2710 | + { |
|
2711 | + if (! $primary_registrant instanceof EE_Registration) { |
|
2712 | + // try redirecting based on the current TXN |
|
2713 | + $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
2714 | + ? $this->checkout->transaction->primary_registration() |
|
2715 | + : null; |
|
2716 | + } |
|
2717 | + if (! $primary_registrant instanceof EE_Registration) { |
|
2718 | + EE_Error::add_error( |
|
2719 | + sprintf( |
|
2720 | + esc_html__( |
|
2721 | + 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
2722 | + 'event_espresso' |
|
2723 | + ), |
|
2724 | + '<br/>', |
|
2725 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2726 | + ), |
|
2727 | + __FILE__, |
|
2728 | + __FUNCTION__, |
|
2729 | + __LINE__ |
|
2730 | + ); |
|
2731 | + return false; |
|
2732 | + } |
|
2733 | + // make sure transaction is not locked |
|
2734 | + $this->checkout->transaction->unlock(); |
|
2735 | + wp_safe_redirect( |
|
2736 | + add_query_arg( |
|
2737 | + array( |
|
2738 | + 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
2739 | + ), |
|
2740 | + $this->checkout->thank_you_page_url |
|
2741 | + ) |
|
2742 | + ); |
|
2743 | + exit(); |
|
2744 | + } |
|
2745 | + |
|
2746 | + |
|
2747 | + /** |
|
2748 | + * _process_off_site_payment |
|
2749 | + * |
|
2750 | + * @access private |
|
2751 | + * @param \EE_Offsite_Gateway $gateway |
|
2752 | + * @return EE_Payment |
|
2753 | + * @throws EE_Error |
|
2754 | + * @throws InvalidArgumentException |
|
2755 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2756 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2757 | + */ |
|
2758 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
2759 | + { |
|
2760 | + try { |
|
2761 | + $request_data = \EE_Registry::instance()->REQ->params(); |
|
2762 | + // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
2763 | + $this->set_handle_IPN_in_this_request( |
|
2764 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
2765 | + ); |
|
2766 | + if ($this->handle_IPN_in_this_request()) { |
|
2767 | + // get payment details and process results |
|
2768 | + /** @type EE_Payment_Processor $payment_processor */ |
|
2769 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2770 | + $payment = $payment_processor->process_ipn( |
|
2771 | + $request_data, |
|
2772 | + $this->checkout->transaction, |
|
2773 | + $this->checkout->payment_method, |
|
2774 | + true, |
|
2775 | + false |
|
2776 | + ); |
|
2777 | + // $payment_source = 'process_ipn'; |
|
2778 | + } else { |
|
2779 | + $payment = $this->checkout->transaction->last_payment(); |
|
2780 | + // $payment_source = 'last_payment'; |
|
2781 | + } |
|
2782 | + } catch (Exception $e) { |
|
2783 | + // let's just eat the exception and try to move on using any previously set payment info |
|
2784 | + $payment = $this->checkout->transaction->last_payment(); |
|
2785 | + // $payment_source = 'last_payment after Exception'; |
|
2786 | + // but if we STILL don't have a payment object |
|
2787 | + if (! $payment instanceof EE_Payment) { |
|
2788 | + // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
2789 | + $this->_handle_payment_processor_exception($e); |
|
2790 | + } |
|
2791 | + } |
|
2792 | + // DEBUG LOG |
|
2793 | + // $this->checkout->log( |
|
2794 | + // __CLASS__, |
|
2795 | + // __FUNCTION__, |
|
2796 | + // __LINE__, |
|
2797 | + // array( |
|
2798 | + // 'process_ipn_payment' => $payment, |
|
2799 | + // 'payment_source' => $payment_source, |
|
2800 | + // ) |
|
2801 | + // ); |
|
2802 | + return $payment; |
|
2803 | + } |
|
2804 | + |
|
2805 | + |
|
2806 | + /** |
|
2807 | + * _process_cancelled_payments |
|
2808 | + * just makes sure that the payment status gets updated correctly |
|
2809 | + * so tha tan error isn't generated during payment validation |
|
2810 | + * |
|
2811 | + * @access private |
|
2812 | + * @param EE_Payment $payment |
|
2813 | + * @return EE_Payment | FALSE |
|
2814 | + * @throws \EE_Error |
|
2815 | + */ |
|
2816 | + private function _process_cancelled_payments($payment = null) |
|
2817 | + { |
|
2818 | + if ($payment instanceof EE_Payment |
|
2819 | + && isset($_REQUEST['ee_cancel_payment']) |
|
2820 | + && $payment->status() === EEM_Payment::status_id_failed |
|
2821 | + ) { |
|
2822 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2823 | + } |
|
2824 | + return $payment; |
|
2825 | + } |
|
2826 | + |
|
2827 | + |
|
2828 | + /** |
|
2829 | + * get_transaction_details_for_gateways |
|
2830 | + * |
|
2831 | + * @access public |
|
2832 | + * @return int |
|
2833 | + * @throws EE_Error |
|
2834 | + * @throws InvalidArgumentException |
|
2835 | + * @throws ReflectionException |
|
2836 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2837 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2838 | + */ |
|
2839 | + public function get_transaction_details_for_gateways() |
|
2840 | + { |
|
2841 | + $txn_details = array(); |
|
2842 | + // ya gotta make a choice man |
|
2843 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
2844 | + $txn_details = array( |
|
2845 | + 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
2846 | + ); |
|
2847 | + } |
|
2848 | + // get EE_Payment_Method object |
|
2849 | + if (empty($txn_details) |
|
2850 | + && |
|
2851 | + ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
2852 | + ) { |
|
2853 | + $txn_details = array( |
|
2854 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2855 | + 'error' => esc_html__( |
|
2856 | + 'A valid Payment Method could not be determined.', |
|
2857 | + 'event_espresso' |
|
2858 | + ), |
|
2859 | + ); |
|
2860 | + } |
|
2861 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2862 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2863 | + $txn_details = array( |
|
2864 | + 'TXN_ID' => $this->checkout->transaction->ID(), |
|
2865 | + 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
2866 | + 'TXN_total' => $this->checkout->transaction->total(), |
|
2867 | + 'TXN_paid' => $this->checkout->transaction->paid(), |
|
2868 | + 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
2869 | + 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
2870 | + 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
2871 | + 'payment_amount' => $this->checkout->amount_owing, |
|
2872 | + 'return_url' => $return_url, |
|
2873 | + 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
2874 | + 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
2875 | + array( |
|
2876 | + 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
2877 | + 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
2878 | + ) |
|
2879 | + ), |
|
2880 | + ); |
|
2881 | + } |
|
2882 | + echo wp_json_encode($txn_details); |
|
2883 | + exit(); |
|
2884 | + } |
|
2885 | + |
|
2886 | + |
|
2887 | + /** |
|
2888 | + * __sleep |
|
2889 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
2890 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
2891 | + * reg form, because if needed, it will be regenerated anyways |
|
2892 | + * |
|
2893 | + * @return array |
|
2894 | + */ |
|
2895 | + public function __sleep() |
|
2896 | + { |
|
2897 | + // remove the reg form and the checkout |
|
2898 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
2899 | + } |
|
2900 | 2900 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | $this->_slug = 'payment_options'; |
131 | 131 | $this->_name = esc_html__('Payment Options', 'event_espresso'); |
132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
132 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'payment_options_main.template.php'; |
|
133 | 133 | $this->checkout = $checkout; |
134 | 134 | $this->_reset_success_message(); |
135 | 135 | $this->set_instructions( |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | { |
213 | 213 | $transaction = $this->checkout->transaction; |
214 | 214 | // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
215 | + if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
@@ -304,18 +304,18 @@ discard block |
||
304 | 304 | foreach ($registrations as $REG_ID => $registration) { |
305 | 305 | /** @var $registration EE_Registration */ |
306 | 306 | // has this registration lost it's space ? |
307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
307 | + if (isset($ejected_registrations[$REG_ID])) { |
|
308 | 308 | if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
309 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
310 | 310 | } else { |
311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
311 | + $insufficient_spaces_available[$registration->event()->ID()] = $registration->event(); |
|
312 | 312 | } |
313 | 313 | continue; |
314 | 314 | } |
315 | 315 | // event requires admin approval |
316 | 316 | if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
317 | 317 | // add event to list of events with pre-approval reg status |
318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
318 | + $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
319 | 319 | do_action( |
320 | 320 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
321 | 321 | $registration->event(), |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | ) |
332 | 332 | ) { |
333 | 333 | // add event to list of events that are sold out |
334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
334 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
335 | 335 | do_action( |
336 | 336 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
337 | 337 | $registration->event(), |
@@ -341,38 +341,38 @@ discard block |
||
341 | 341 | } |
342 | 342 | // are they allowed to pay now and is there monies owing? |
343 | 343 | if ($registration->owes_monies_and_can_pay()) { |
344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
344 | + $registrations_requiring_payment[$REG_ID] = $registration; |
|
345 | 345 | do_action( |
346 | 346 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
347 | 347 | $registration->event(), |
348 | 348 | $this |
349 | 349 | ); |
350 | - } elseif (! $this->checkout->revisit |
|
350 | + } elseif ( ! $this->checkout->revisit |
|
351 | 351 | && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
352 | 352 | && $registration->ticket()->is_free() |
353 | 353 | ) { |
354 | - $registrations_for_free_events[ $registration->event()->ID() ] = $registration; |
|
354 | + $registrations_for_free_events[$registration->event()->ID()] = $registration; |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | $subsections = array(); |
358 | 358 | // now decide which template to load |
359 | - if (! empty($sold_out_events)) { |
|
359 | + if ( ! empty($sold_out_events)) { |
|
360 | 360 | $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
361 | 361 | } |
362 | - if (! empty($insufficient_spaces_available)) { |
|
362 | + if ( ! empty($insufficient_spaces_available)) { |
|
363 | 363 | $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
364 | 364 | $insufficient_spaces_available |
365 | 365 | ); |
366 | 366 | } |
367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
367 | + if ( ! empty($registrations_requiring_pre_approval)) { |
|
368 | 368 | $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
369 | 369 | $registrations_requiring_pre_approval |
370 | 370 | ); |
371 | 371 | } |
372 | - if (! empty($registrations_for_free_events)) { |
|
372 | + if ( ! empty($registrations_for_free_events)) { |
|
373 | 373 | $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
374 | 374 | } |
375 | - if (! empty($registrations_requiring_payment)) { |
|
375 | + if ( ! empty($registrations_requiring_payment)) { |
|
376 | 376 | if ($this->checkout->amount_owing > 0) { |
377 | 377 | // autoload Line_Item_Display classes |
378 | 378 | EEH_Autoloader::register_line_item_filter_autoloaders(); |
@@ -437,13 +437,13 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
439 | 439 | { |
440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
440 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
441 | 441 | return $line_item_filter_collection; |
442 | 442 | } |
443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
443 | + if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
444 | 444 | return $line_item_filter_collection; |
445 | 445 | } |
446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
446 | + if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
447 | 447 | return $line_item_filter_collection; |
448 | 448 | } |
449 | 449 | $line_item_filter_collection->add( |
@@ -483,8 +483,8 @@ discard block |
||
483 | 483 | ); |
484 | 484 | foreach ($registrations as $REG_ID => $registration) { |
485 | 485 | // has this registration lost it's space ? |
486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
487 | - unset($registrations[ $REG_ID ]); |
|
486 | + if (isset($ejected_registrations[$REG_ID])) { |
|
487 | + unset($registrations[$REG_ID]); |
|
488 | 488 | continue; |
489 | 489 | } |
490 | 490 | } |
@@ -534,24 +534,24 @@ discard block |
||
534 | 534 | } |
535 | 535 | $EVT_ID = $registration->event_ID(); |
536 | 536 | $ticket = $registration->ticket(); |
537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
537 | + if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
538 | + $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
539 | 539 | } |
540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
540 | + if ($tickets_remaining[$ticket->ID()] > 0) { |
|
541 | + if ( ! isset($event_reg_count[$EVT_ID])) { |
|
542 | + $event_reg_count[$EVT_ID] = 0; |
|
543 | 543 | } |
544 | - $event_reg_count[ $EVT_ID ]++; |
|
545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
544 | + $event_reg_count[$EVT_ID]++; |
|
545 | + if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
546 | + $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | if ($revisit |
550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
550 | + && ($tickets_remaining[$ticket->ID()] === 0 |
|
551 | + || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID] |
|
552 | 552 | ) |
553 | 553 | ) { |
554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
554 | + $ejected_registrations[$REG_ID] = $registration->event(); |
|
555 | 555 | if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
556 | 556 | /** @type EE_Registration_Processor $registration_processor */ |
557 | 557 | $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | foreach ($sold_out_events_array as $sold_out_event) { |
612 | 612 | $sold_out_events .= EEH_HTML::li( |
613 | 613 | EEH_HTML::span( |
614 | - ' ' . $sold_out_event->name(), |
|
614 | + ' '.$sold_out_event->name(), |
|
615 | 615 | '', |
616 | 616 | 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
617 | 617 | ) |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | foreach ($insufficient_spaces_events_array as $event) { |
668 | 668 | if ($event instanceof EE_Event) { |
669 | 669 | $insufficient_space_events .= EEH_HTML::li( |
670 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
670 | + EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
671 | 671 | ); |
672 | 672 | } |
673 | 673 | } |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | $events_requiring_pre_approval = ''; |
717 | 717 | foreach ($registrations_requiring_pre_approval as $registration) { |
718 | 718 | if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
719 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
719 | + $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li( |
|
720 | 720 | EEH_HTML::span( |
721 | 721 | '', |
722 | 722 | '', |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | { |
858 | 858 | return new EE_Form_Section_Proper( |
859 | 859 | array( |
860 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
860 | + 'html_id' => 'ee-'.$this->slug().'-extra-hidden-inputs', |
|
861 | 861 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
862 | 862 | 'subsections' => array( |
863 | 863 | 'spco_no_payment_required' => new EE_Hidden_Input( |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | $payments += $registration->registration_payments(); |
898 | 898 | } |
899 | 899 | } |
900 | - if (! empty($payments)) { |
|
900 | + if ( ! empty($payments)) { |
|
901 | 901 | foreach ($payments as $payment) { |
902 | 902 | if ($payment instanceof EE_Registration_Payment) { |
903 | 903 | $this->checkout->amount_owing -= $payment->amount(); |
@@ -1017,23 +1017,23 @@ discard block |
||
1017 | 1017 | $payment_method_button = EEH_HTML::img( |
1018 | 1018 | $payment_method->button_url(), |
1019 | 1019 | $payment_method->name(), |
1020 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1020 | + 'spco-payment-method-'.$payment_method->slug().'-btn-img', |
|
1021 | 1021 | 'spco-payment-method-btn-img' |
1022 | 1022 | ); |
1023 | 1023 | // check if any payment methods are set as default |
1024 | 1024 | // if payment method is already selected OR nothing is selected and this payment method should be |
1025 | 1025 | // open_by_default |
1026 | 1026 | if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
1027 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1027 | + || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1028 | 1028 | ) { |
1029 | 1029 | $this->checkout->selected_method_of_payment = $payment_method->slug(); |
1030 | 1030 | $this->_save_selected_method_of_payment(); |
1031 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1031 | + $default_payment_method_option[$payment_method->slug()] = $payment_method_button; |
|
1032 | 1032 | } else { |
1033 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1033 | + $available_payment_method_options[$payment_method->slug()] = $payment_method_button; |
|
1034 | 1034 | } |
1035 | - $payment_methods_billing_info[ $payment_method->slug( |
|
1036 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
1035 | + $payment_methods_billing_info[$payment_method->slug( |
|
1036 | + ).'-info'] = $this->_payment_method_billing_info( |
|
1037 | 1037 | $payment_method |
1038 | 1038 | ); |
1039 | 1039 | } |
@@ -1069,7 +1069,7 @@ discard block |
||
1069 | 1069 | */ |
1070 | 1070 | protected function _get_available_payment_methods() |
1071 | 1071 | { |
1072 | - if (! empty($this->checkout->available_payment_methods)) { |
|
1072 | + if ( ! empty($this->checkout->available_payment_methods)) { |
|
1073 | 1073 | return $this->checkout->available_payment_methods; |
1074 | 1074 | } |
1075 | 1075 | $available_payment_methods = array(); |
@@ -1084,7 +1084,7 @@ discard block |
||
1084 | 1084 | ); |
1085 | 1085 | foreach ($payment_methods as $payment_method) { |
1086 | 1086 | if ($payment_method instanceof EE_Payment_Method) { |
1087 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1087 | + $available_payment_methods[$payment_method->slug()] = $payment_method; |
|
1088 | 1088 | } |
1089 | 1089 | } |
1090 | 1090 | return $available_payment_methods; |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | ); |
1180 | 1180 | return new EE_Form_Section_Proper( |
1181 | 1181 | array( |
1182 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1182 | + 'html_id' => 'spco-payment-method-info-'.$payment_method->slug(), |
|
1183 | 1183 | 'html_class' => 'spco-payment-method-info-dv', |
1184 | 1184 | // only display the selected or default PM |
1185 | 1185 | 'html_style' => $currently_selected ? '' : 'display:none;', |
@@ -1209,7 +1209,7 @@ discard block |
||
1209 | 1209 | // how have they chosen to pay? |
1210 | 1210 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
1211 | 1211 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1212 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1212 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1213 | 1213 | return false; |
1214 | 1214 | } |
1215 | 1215 | if (apply_filters( |
@@ -1381,7 +1381,7 @@ discard block |
||
1381 | 1381 | */ |
1382 | 1382 | public function switch_payment_method() |
1383 | 1383 | { |
1384 | - if (! $this->_verify_payment_method_is_set()) { |
|
1384 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1385 | 1385 | return false; |
1386 | 1386 | } |
1387 | 1387 | if (apply_filters( |
@@ -1516,7 +1516,7 @@ discard block |
||
1516 | 1516 | } |
1517 | 1517 | } |
1518 | 1518 | // verify payment method |
1519 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1519 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1520 | 1520 | // get payment method for selected method of payment |
1521 | 1521 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1522 | 1522 | } |
@@ -1541,7 +1541,7 @@ discard block |
||
1541 | 1541 | */ |
1542 | 1542 | public function save_payer_details_via_ajax() |
1543 | 1543 | { |
1544 | - if (! $this->_verify_payment_method_is_set()) { |
|
1544 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1545 | 1545 | return; |
1546 | 1546 | } |
1547 | 1547 | // generate billing form for selected method of payment if it hasn't been done already |
@@ -1551,7 +1551,7 @@ discard block |
||
1551 | 1551 | ); |
1552 | 1552 | } |
1553 | 1553 | // generate primary attendee from payer info if applicable |
1554 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1554 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
1555 | 1555 | $attendee = $this->_create_attendee_from_request_data(); |
1556 | 1556 | if ($attendee instanceof EE_Attendee) { |
1557 | 1557 | foreach ($this->checkout->transaction->registrations() as $registration) { |
@@ -1582,7 +1582,7 @@ discard block |
||
1582 | 1582 | { |
1583 | 1583 | // get State ID |
1584 | 1584 | $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
1585 | - if (! empty($STA_ID)) { |
|
1585 | + if ( ! empty($STA_ID)) { |
|
1586 | 1586 | // can we get state object from name ? |
1587 | 1587 | EE_Registry::instance()->load_model('State'); |
1588 | 1588 | $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
@@ -1590,7 +1590,7 @@ discard block |
||
1590 | 1590 | } |
1591 | 1591 | // get Country ISO |
1592 | 1592 | $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
1593 | - if (! empty($CNT_ISO)) { |
|
1593 | + if ( ! empty($CNT_ISO)) { |
|
1594 | 1594 | // can we get country object from name ? |
1595 | 1595 | EE_Registry::instance()->load_model('Country'); |
1596 | 1596 | $country = EEM_Country::instance()->get_col( |
@@ -1623,7 +1623,7 @@ discard block |
||
1623 | 1623 | } |
1624 | 1624 | // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
1625 | 1625 | // AND email address |
1626 | - if (! empty($attendee_data['ATT_fname']) |
|
1626 | + if ( ! empty($attendee_data['ATT_fname']) |
|
1627 | 1627 | && ! empty($attendee_data['ATT_lname']) |
1628 | 1628 | && ! empty($attendee_data['ATT_email']) |
1629 | 1629 | ) { |
@@ -1838,7 +1838,7 @@ discard block |
||
1838 | 1838 | private function _process_payment() |
1839 | 1839 | { |
1840 | 1840 | // basically confirm that the event hasn't sold out since they hit the page |
1841 | - if (! $this->_last_second_ticket_verifications()) { |
|
1841 | + if ( ! $this->_last_second_ticket_verifications()) { |
|
1842 | 1842 | return false; |
1843 | 1843 | } |
1844 | 1844 | // ya gotta make a choice man |
@@ -1849,7 +1849,7 @@ discard block |
||
1849 | 1849 | return false; |
1850 | 1850 | } |
1851 | 1851 | // get EE_Payment_Method object |
1852 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1852 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1853 | 1853 | return false; |
1854 | 1854 | } |
1855 | 1855 | // setup billing form |
@@ -1858,12 +1858,12 @@ discard block |
||
1858 | 1858 | $this->checkout->payment_method |
1859 | 1859 | ); |
1860 | 1860 | // bad billing form ? |
1861 | - if (! $this->_billing_form_is_valid()) { |
|
1861 | + if ( ! $this->_billing_form_is_valid()) { |
|
1862 | 1862 | return false; |
1863 | 1863 | } |
1864 | 1864 | } |
1865 | 1865 | // ensure primary registrant has been fully processed |
1866 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1866 | + if ( ! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1867 | 1867 | return false; |
1868 | 1868 | } |
1869 | 1869 | // if session is close to expiring (under 10 minutes by default) |
@@ -1918,7 +1918,7 @@ discard block |
||
1918 | 1918 | protected function _last_second_ticket_verifications() |
1919 | 1919 | { |
1920 | 1920 | // don't bother re-validating if not a return visit |
1921 | - if (! $this->checkout->revisit) { |
|
1921 | + if ( ! $this->checkout->revisit) { |
|
1922 | 1922 | return true; |
1923 | 1923 | } |
1924 | 1924 | $registrations = $this->checkout->transaction->registrations(); |
@@ -1984,7 +1984,7 @@ discard block |
||
1984 | 1984 | */ |
1985 | 1985 | private function _billing_form_is_valid() |
1986 | 1986 | { |
1987 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1987 | + if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1988 | 1988 | return true; |
1989 | 1989 | } |
1990 | 1990 | if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
@@ -2103,7 +2103,7 @@ discard block |
||
2103 | 2103 | { |
2104 | 2104 | // convert billing form data into an attendee |
2105 | 2105 | $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
2106 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2106 | + if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2107 | 2107 | EE_Error::add_error( |
2108 | 2108 | sprintf( |
2109 | 2109 | esc_html__( |
@@ -2120,7 +2120,7 @@ discard block |
||
2120 | 2120 | return false; |
2121 | 2121 | } |
2122 | 2122 | $primary_registration = $this->checkout->transaction->primary_registration(); |
2123 | - if (! $primary_registration instanceof EE_Registration) { |
|
2123 | + if ( ! $primary_registration instanceof EE_Registration) { |
|
2124 | 2124 | EE_Error::add_error( |
2125 | 2125 | sprintf( |
2126 | 2126 | esc_html__( |
@@ -2136,7 +2136,7 @@ discard block |
||
2136 | 2136 | ); |
2137 | 2137 | return false; |
2138 | 2138 | } |
2139 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2139 | + if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2140 | 2140 | instanceof |
2141 | 2141 | EE_Attendee |
2142 | 2142 | ) { |
@@ -2182,8 +2182,8 @@ discard block |
||
2182 | 2182 | return null; |
2183 | 2183 | } |
2184 | 2184 | // get EE_Payment_Method object |
2185 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2186 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2185 | + if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) { |
|
2186 | + $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment]; |
|
2187 | 2187 | } else { |
2188 | 2188 | // load EEM_Payment_Method |
2189 | 2189 | EE_Registry::instance()->load_model('Payment_Method'); |
@@ -2192,7 +2192,7 @@ discard block |
||
2192 | 2192 | $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
2193 | 2193 | } |
2194 | 2194 | // verify $payment_method |
2195 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
2195 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
2196 | 2196 | // not a payment |
2197 | 2197 | EE_Error::add_error( |
2198 | 2198 | sprintf( |
@@ -2210,7 +2210,7 @@ discard block |
||
2210 | 2210 | return null; |
2211 | 2211 | } |
2212 | 2212 | // and verify it has a valid Payment_Method Type object |
2213 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2213 | + if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2214 | 2214 | // not a payment |
2215 | 2215 | EE_Error::add_error( |
2216 | 2216 | sprintf( |
@@ -2248,7 +2248,7 @@ discard block |
||
2248 | 2248 | $payment = null; |
2249 | 2249 | $this->checkout->transaction->save(); |
2250 | 2250 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
2251 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2251 | + if ( ! $payment_processor instanceof EE_Payment_Processor) { |
|
2252 | 2252 | return false; |
2253 | 2253 | } |
2254 | 2254 | try { |
@@ -2352,7 +2352,7 @@ discard block |
||
2352 | 2352 | return true; |
2353 | 2353 | } |
2354 | 2354 | // verify payment object |
2355 | - if (! $payment instanceof EE_Payment) { |
|
2355 | + if ( ! $payment instanceof EE_Payment) { |
|
2356 | 2356 | // not a payment |
2357 | 2357 | EE_Error::add_error( |
2358 | 2358 | sprintf( |
@@ -2392,7 +2392,7 @@ discard block |
||
2392 | 2392 | return true; |
2393 | 2393 | // On-Site payment? |
2394 | 2394 | } elseif ($this->checkout->payment_method->is_on_site()) { |
2395 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2395 | + if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2396 | 2396 | // $this->_setup_redirect_for_next_step(); |
2397 | 2397 | $this->checkout->continue_reg = false; |
2398 | 2398 | } |
@@ -2508,7 +2508,7 @@ discard block |
||
2508 | 2508 | break; |
2509 | 2509 | // bad payment |
2510 | 2510 | case EEM_Payment::status_id_failed: |
2511 | - if (! empty($msg)) { |
|
2511 | + if ( ! empty($msg)) { |
|
2512 | 2512 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
2513 | 2513 | return false; |
2514 | 2514 | } |
@@ -2569,11 +2569,11 @@ discard block |
||
2569 | 2569 | // how have they chosen to pay? |
2570 | 2570 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
2571 | 2571 | // get EE_Payment_Method object |
2572 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2572 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2573 | 2573 | $this->checkout->continue_reg = false; |
2574 | 2574 | return false; |
2575 | 2575 | } |
2576 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
2576 | + if ( ! $this->checkout->payment_method->is_off_site()) { |
|
2577 | 2577 | return false; |
2578 | 2578 | } |
2579 | 2579 | $this->_validate_offsite_return(); |
@@ -2591,7 +2591,7 @@ discard block |
||
2591 | 2591 | // verify TXN |
2592 | 2592 | if ($this->checkout->transaction instanceof EE_Transaction) { |
2593 | 2593 | $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
2594 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2594 | + if ( ! $gateway instanceof EE_Offsite_Gateway) { |
|
2595 | 2595 | $this->checkout->continue_reg = false; |
2596 | 2596 | return false; |
2597 | 2597 | } |
@@ -2708,13 +2708,13 @@ discard block |
||
2708 | 2708 | */ |
2709 | 2709 | private function _redirect_wayward_request(EE_Registration $primary_registrant) |
2710 | 2710 | { |
2711 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2711 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2712 | 2712 | // try redirecting based on the current TXN |
2713 | 2713 | $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
2714 | 2714 | ? $this->checkout->transaction->primary_registration() |
2715 | 2715 | : null; |
2716 | 2716 | } |
2717 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2717 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2718 | 2718 | EE_Error::add_error( |
2719 | 2719 | sprintf( |
2720 | 2720 | esc_html__( |
@@ -2784,7 +2784,7 @@ discard block |
||
2784 | 2784 | $payment = $this->checkout->transaction->last_payment(); |
2785 | 2785 | // $payment_source = 'last_payment after Exception'; |
2786 | 2786 | // but if we STILL don't have a payment object |
2787 | - if (! $payment instanceof EE_Payment) { |
|
2787 | + if ( ! $payment instanceof EE_Payment) { |
|
2788 | 2788 | // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
2789 | 2789 | $this->_handle_payment_processor_exception($e); |
2790 | 2790 | } |
@@ -211,7 +211,7 @@ |
||
211 | 211 | * appropriately. |
212 | 212 | * |
213 | 213 | * @throws EE_Error |
214 | - * @return EE_message_type|false if exception thrown. |
|
214 | + * @return null|EE_message_type if exception thrown. |
|
215 | 215 | */ |
216 | 216 | public function message_type_obj() |
217 | 217 | { |
@@ -13,487 +13,487 @@ |
||
13 | 13 | class EE_Message_Template_Group extends EE_Soft_Delete_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
18 | - */ |
|
19 | - const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
20 | - |
|
21 | - /** |
|
22 | - * @param array $props_n_values |
|
23 | - * @param string $timezone |
|
24 | - * @return EE_Message_Template_Group|mixed |
|
25 | - * @throws EE_Error |
|
26 | - */ |
|
27 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
28 | - { |
|
29 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
30 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @param array $props_n_values |
|
36 | - * @param string $timezone |
|
37 | - * @return EE_Message_Template_Group |
|
38 | - */ |
|
39 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
40 | - { |
|
41 | - return new self($props_n_values, true, $timezone); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @param bool $message_type |
|
47 | - * @throws EE_Error |
|
48 | - */ |
|
49 | - public function set_message_type($message_type = false) |
|
50 | - { |
|
51 | - if (! $message_type) { |
|
52 | - throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
53 | - } |
|
54 | - $this->set('MTP_message_type', $message_type); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param bool $messenger |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public function set_messenger($messenger = false) |
|
63 | - { |
|
64 | - if (! $messenger) { |
|
65 | - throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
66 | - } |
|
67 | - $this->set('MTP_messenger', $messenger); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param bool $GRP_ID |
|
73 | - * @throws EE_Error |
|
74 | - */ |
|
75 | - public function set_group_template_id($GRP_ID = false) |
|
76 | - { |
|
77 | - if (! $GRP_ID) { |
|
78 | - throw new EE_Error( |
|
79 | - esc_html__( |
|
80 | - 'Missing required value for the message template group id', |
|
81 | - 'event_espresso' |
|
82 | - ) |
|
83 | - ); |
|
84 | - } |
|
85 | - $this->set('GRP_ID', $GRP_ID); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * get Group ID |
|
91 | - * |
|
92 | - * @access public |
|
93 | - * @return int |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - public function GRP_ID() |
|
97 | - { |
|
98 | - return $this->get('GRP_ID'); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * get User ID |
|
104 | - * |
|
105 | - * @access public |
|
106 | - * @return int |
|
107 | - * @throws EE_Error |
|
108 | - */ |
|
109 | - public function user() |
|
110 | - { |
|
111 | - $user_id = $this->get('MTP_user_id'); |
|
112 | - return empty($user_id) ? get_current_user_id() : $user_id; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * Wrapper for the user function() (preserve backward compat) |
|
118 | - * |
|
119 | - * @since 4.5.0 |
|
120 | - * @return int |
|
121 | - * @throws EE_Error |
|
122 | - */ |
|
123 | - public function wp_user() |
|
124 | - { |
|
125 | - return $this->user(); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * This simply returns a count of all related events to this message template group |
|
131 | - * |
|
132 | - * @return int |
|
133 | - */ |
|
134 | - public function count_events() |
|
135 | - { |
|
136 | - return $this->count_related('Event'); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * returns the name saved in the db for this template |
|
142 | - * |
|
143 | - * @return string |
|
144 | - * @throws EE_Error |
|
145 | - */ |
|
146 | - public function name() |
|
147 | - { |
|
148 | - return $this->get('MTP_name'); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Returns the description saved in the db for this template group |
|
154 | - * |
|
155 | - * @return string |
|
156 | - * @throws EE_Error |
|
157 | - */ |
|
158 | - public function description() |
|
159 | - { |
|
160 | - return $this->get('MTP_description'); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * returns all related EE_Message_Template objects |
|
166 | - * |
|
167 | - * @param array $query_params like EEM_Base::get_all() |
|
168 | - * @return EE_Message_Template[] |
|
169 | - * @throws EE_Error |
|
170 | - */ |
|
171 | - public function message_templates($query_params = array()) |
|
172 | - { |
|
173 | - return $this->get_many_related('Message_Template', $query_params); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * get Message Messenger |
|
179 | - * |
|
180 | - * @access public |
|
181 | - * @return string |
|
182 | - * @throws EE_Error |
|
183 | - */ |
|
184 | - public function messenger() |
|
185 | - { |
|
186 | - return $this->get('MTP_messenger'); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * get Message Messenger OBJECT |
|
192 | - * If an attempt to get the corresponding messenger object fails, then we set this message |
|
193 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
194 | - * appropriately. |
|
195 | - * |
|
196 | - * @return EE_messenger |
|
197 | - * @throws EE_Error |
|
198 | - */ |
|
199 | - public function messenger_obj() |
|
200 | - { |
|
201 | - $messenger = $this->messenger(); |
|
202 | - try { |
|
203 | - $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
206 | - // class for this messenger in this group. |
|
207 | - $this->set('MTP_is_active', false); |
|
208 | - $this->save(); |
|
209 | - return null; |
|
210 | - } |
|
211 | - return $messenger; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get Message Type |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @return string |
|
220 | - * @throws EE_Error |
|
221 | - */ |
|
222 | - public function message_type() |
|
223 | - { |
|
224 | - return $this->get('MTP_message_type'); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * get Message type OBJECT |
|
230 | - * If an attempt to get the corresponding message type object fails, then we set this message |
|
231 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
232 | - * appropriately. |
|
233 | - * |
|
234 | - * @throws EE_Error |
|
235 | - * @return EE_message_type|false if exception thrown. |
|
236 | - */ |
|
237 | - public function message_type_obj() |
|
238 | - { |
|
239 | - $message_type = $this->message_type(); |
|
240 | - try { |
|
241 | - $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
242 | - } catch (EE_Error $e) { |
|
243 | - // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
244 | - // class for the message type in this group. |
|
245 | - $this->set('MTP_is_active', false); |
|
246 | - $this->save(); |
|
247 | - return null; |
|
248 | - } |
|
249 | - return $message_type; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @return array |
|
255 | - * @throws EE_Error |
|
256 | - */ |
|
257 | - public function contexts_config() |
|
258 | - { |
|
259 | - return $this->message_type_obj()->get_contexts(); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * This returns the context_label for contexts as set in the message type object |
|
265 | - * Note this is an array with singular and plural keys |
|
266 | - * |
|
267 | - * @access public |
|
268 | - * @return array labels for "context" |
|
269 | - * @throws EE_Error |
|
270 | - */ |
|
271 | - public function context_label() |
|
272 | - { |
|
273 | - $obj = $this->message_type_obj(); |
|
274 | - return $obj->get_context_label(); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * This returns an array of EE_Message_Template objects indexed by context and field. |
|
280 | - * |
|
281 | - * @return array () |
|
282 | - * @throws EE_Error |
|
283 | - */ |
|
284 | - public function context_templates() |
|
285 | - { |
|
286 | - $mtps_arr = array(); |
|
287 | - $mtps = $this->get_many_related('Message_Template'); |
|
288 | - if (empty($mtps)) { |
|
289 | - return array(); |
|
290 | - } |
|
291 | - // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
292 | - foreach ($mtps as $mtp) { |
|
293 | - $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
294 | - } |
|
295 | - return $mtps_arr; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * this returns if the template group this template belongs to is global |
|
301 | - * |
|
302 | - * @return bool true if it is, false if it isn't |
|
303 | - * @throws EE_Error |
|
304 | - */ |
|
305 | - public function is_global() |
|
306 | - { |
|
307 | - return $this->get('MTP_is_global'); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
313 | - * |
|
314 | - * @return bool true if it is, false if it isn't |
|
315 | - * @throws EE_Error |
|
316 | - */ |
|
317 | - public function is_active() |
|
318 | - { |
|
319 | - return $this->get('MTP_is_active'); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
325 | - * this template. |
|
326 | - * |
|
327 | - * @since 4.3.0 |
|
328 | - * @uses EEH_MSG_Template::get_shortcodes() |
|
329 | - * @param string $context what context we're going to return shortcodes for |
|
330 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
331 | - * to be returned. |
|
332 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
333 | - * unique shortcodes for all the given (or all) fields. |
|
334 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
335 | - * shortcodes found. |
|
336 | - * @throws EE_Error |
|
337 | - */ |
|
338 | - public function get_shortcodes($context, $fields = array(), $merged = false) |
|
339 | - { |
|
340 | - $messenger = $this->messenger(); |
|
341 | - $message_type = $this->message_type(); |
|
342 | - return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
348 | - * use the default template pack. |
|
349 | - * |
|
350 | - * @since 4.5.0 |
|
351 | - * @return string |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - public function get_template_pack_name() |
|
355 | - { |
|
356 | - return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * This returns the specific template pack object referenced by the template pack name attached to this message |
|
362 | - * template group. If no template pack is assigned then the default template pack is retrieved. |
|
363 | - * |
|
364 | - * @since 4.5.0 |
|
365 | - * @return EE_Messages_Template_Pack |
|
366 | - * @throws EE_Error |
|
367 | - * @throws InvalidArgumentException |
|
368 | - * @throws ReflectionException |
|
369 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
370 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
371 | - */ |
|
372 | - public function get_template_pack() |
|
373 | - { |
|
374 | - $pack_name = $this->get_template_pack_name(); |
|
375 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
376 | - return EEH_MSG_Template::get_template_pack($pack_name); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
382 | - * use the default template variation. |
|
383 | - * |
|
384 | - * @since 4.5.0 |
|
385 | - * @return string |
|
386 | - * @throws EE_Error |
|
387 | - */ |
|
388 | - public function get_template_pack_variation() |
|
389 | - { |
|
390 | - return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * This just sets the template pack name attached to this message template group. |
|
396 | - * |
|
397 | - * @since 4.5.0 |
|
398 | - * @param string $template_pack_name What message template pack is assigned. |
|
399 | - * @return int |
|
400 | - * @throws EE_Error |
|
401 | - */ |
|
402 | - public function set_template_pack_name($template_pack_name) |
|
403 | - { |
|
404 | - return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * This just sets the template pack variation attached to this message template group. |
|
410 | - * |
|
411 | - * @since 4.5.0 |
|
412 | - * @param string $variation What variation is being set on the message template group. |
|
413 | - * @return int |
|
414 | - * @throws EE_Error |
|
415 | - */ |
|
416 | - public function set_template_pack_variation($variation) |
|
417 | - { |
|
418 | - return $this->update_extra_meta('MTP_variation', $variation); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Deactivates the given context. |
|
424 | - * |
|
425 | - * @param $context |
|
426 | - * @return bool|int |
|
427 | - * @throws EE_Error |
|
428 | - * @throws InvalidIdentifierException |
|
429 | - */ |
|
430 | - public function deactivate_context($context) |
|
431 | - { |
|
432 | - $this->validate_context($context); |
|
433 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * Activates the given context. |
|
439 | - * |
|
440 | - * @param $context |
|
441 | - * @return bool|int |
|
442 | - * @throws EE_Error |
|
443 | - * @throws InvalidIdentifierException |
|
444 | - */ |
|
445 | - public function activate_context($context) |
|
446 | - { |
|
447 | - $this->validate_context($context); |
|
448 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Returns whether the context is active or not. |
|
454 | - * Note, this will default to true if the extra meta record doesn't exist. |
|
455 | - * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
456 | - * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
457 | - * whether a context is "active" or not. |
|
458 | - * |
|
459 | - * @param $context |
|
460 | - * @return bool |
|
461 | - * @throws EE_Error |
|
462 | - * @throws InvalidIdentifierException |
|
463 | - */ |
|
464 | - public function is_context_active($context) |
|
465 | - { |
|
466 | - $this->validate_context($context); |
|
467 | - return filter_var( |
|
468 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
469 | - FILTER_VALIDATE_BOOLEAN |
|
470 | - ); |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * Validates the incoming context to verify it matches a registered context for the related message type. |
|
476 | - * |
|
477 | - * @param string $context |
|
478 | - * @throws EE_Error |
|
479 | - * @throws InvalidIdentifierException |
|
480 | - */ |
|
481 | - public function validate_context($context) |
|
482 | - { |
|
483 | - $contexts = $this->contexts_config(); |
|
484 | - if (! isset($contexts[ $context ])) { |
|
485 | - throw new InvalidIdentifierException( |
|
486 | - '', |
|
487 | - '', |
|
488 | - sprintf( |
|
489 | - esc_html__( |
|
490 | - 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
491 | - 'event_espresso' |
|
492 | - ), |
|
493 | - $context, |
|
494 | - implode(',', array_keys($contexts)) |
|
495 | - ) |
|
496 | - ); |
|
497 | - } |
|
498 | - } |
|
16 | + /** |
|
17 | + * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
18 | + */ |
|
19 | + const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
20 | + |
|
21 | + /** |
|
22 | + * @param array $props_n_values |
|
23 | + * @param string $timezone |
|
24 | + * @return EE_Message_Template_Group|mixed |
|
25 | + * @throws EE_Error |
|
26 | + */ |
|
27 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
28 | + { |
|
29 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
30 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @param array $props_n_values |
|
36 | + * @param string $timezone |
|
37 | + * @return EE_Message_Template_Group |
|
38 | + */ |
|
39 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
40 | + { |
|
41 | + return new self($props_n_values, true, $timezone); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @param bool $message_type |
|
47 | + * @throws EE_Error |
|
48 | + */ |
|
49 | + public function set_message_type($message_type = false) |
|
50 | + { |
|
51 | + if (! $message_type) { |
|
52 | + throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
53 | + } |
|
54 | + $this->set('MTP_message_type', $message_type); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param bool $messenger |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public function set_messenger($messenger = false) |
|
63 | + { |
|
64 | + if (! $messenger) { |
|
65 | + throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
66 | + } |
|
67 | + $this->set('MTP_messenger', $messenger); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param bool $GRP_ID |
|
73 | + * @throws EE_Error |
|
74 | + */ |
|
75 | + public function set_group_template_id($GRP_ID = false) |
|
76 | + { |
|
77 | + if (! $GRP_ID) { |
|
78 | + throw new EE_Error( |
|
79 | + esc_html__( |
|
80 | + 'Missing required value for the message template group id', |
|
81 | + 'event_espresso' |
|
82 | + ) |
|
83 | + ); |
|
84 | + } |
|
85 | + $this->set('GRP_ID', $GRP_ID); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * get Group ID |
|
91 | + * |
|
92 | + * @access public |
|
93 | + * @return int |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + public function GRP_ID() |
|
97 | + { |
|
98 | + return $this->get('GRP_ID'); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * get User ID |
|
104 | + * |
|
105 | + * @access public |
|
106 | + * @return int |
|
107 | + * @throws EE_Error |
|
108 | + */ |
|
109 | + public function user() |
|
110 | + { |
|
111 | + $user_id = $this->get('MTP_user_id'); |
|
112 | + return empty($user_id) ? get_current_user_id() : $user_id; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * Wrapper for the user function() (preserve backward compat) |
|
118 | + * |
|
119 | + * @since 4.5.0 |
|
120 | + * @return int |
|
121 | + * @throws EE_Error |
|
122 | + */ |
|
123 | + public function wp_user() |
|
124 | + { |
|
125 | + return $this->user(); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * This simply returns a count of all related events to this message template group |
|
131 | + * |
|
132 | + * @return int |
|
133 | + */ |
|
134 | + public function count_events() |
|
135 | + { |
|
136 | + return $this->count_related('Event'); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * returns the name saved in the db for this template |
|
142 | + * |
|
143 | + * @return string |
|
144 | + * @throws EE_Error |
|
145 | + */ |
|
146 | + public function name() |
|
147 | + { |
|
148 | + return $this->get('MTP_name'); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Returns the description saved in the db for this template group |
|
154 | + * |
|
155 | + * @return string |
|
156 | + * @throws EE_Error |
|
157 | + */ |
|
158 | + public function description() |
|
159 | + { |
|
160 | + return $this->get('MTP_description'); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * returns all related EE_Message_Template objects |
|
166 | + * |
|
167 | + * @param array $query_params like EEM_Base::get_all() |
|
168 | + * @return EE_Message_Template[] |
|
169 | + * @throws EE_Error |
|
170 | + */ |
|
171 | + public function message_templates($query_params = array()) |
|
172 | + { |
|
173 | + return $this->get_many_related('Message_Template', $query_params); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * get Message Messenger |
|
179 | + * |
|
180 | + * @access public |
|
181 | + * @return string |
|
182 | + * @throws EE_Error |
|
183 | + */ |
|
184 | + public function messenger() |
|
185 | + { |
|
186 | + return $this->get('MTP_messenger'); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * get Message Messenger OBJECT |
|
192 | + * If an attempt to get the corresponding messenger object fails, then we set this message |
|
193 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
194 | + * appropriately. |
|
195 | + * |
|
196 | + * @return EE_messenger |
|
197 | + * @throws EE_Error |
|
198 | + */ |
|
199 | + public function messenger_obj() |
|
200 | + { |
|
201 | + $messenger = $this->messenger(); |
|
202 | + try { |
|
203 | + $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
206 | + // class for this messenger in this group. |
|
207 | + $this->set('MTP_is_active', false); |
|
208 | + $this->save(); |
|
209 | + return null; |
|
210 | + } |
|
211 | + return $messenger; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get Message Type |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @return string |
|
220 | + * @throws EE_Error |
|
221 | + */ |
|
222 | + public function message_type() |
|
223 | + { |
|
224 | + return $this->get('MTP_message_type'); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * get Message type OBJECT |
|
230 | + * If an attempt to get the corresponding message type object fails, then we set this message |
|
231 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
232 | + * appropriately. |
|
233 | + * |
|
234 | + * @throws EE_Error |
|
235 | + * @return EE_message_type|false if exception thrown. |
|
236 | + */ |
|
237 | + public function message_type_obj() |
|
238 | + { |
|
239 | + $message_type = $this->message_type(); |
|
240 | + try { |
|
241 | + $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
242 | + } catch (EE_Error $e) { |
|
243 | + // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
244 | + // class for the message type in this group. |
|
245 | + $this->set('MTP_is_active', false); |
|
246 | + $this->save(); |
|
247 | + return null; |
|
248 | + } |
|
249 | + return $message_type; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @return array |
|
255 | + * @throws EE_Error |
|
256 | + */ |
|
257 | + public function contexts_config() |
|
258 | + { |
|
259 | + return $this->message_type_obj()->get_contexts(); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * This returns the context_label for contexts as set in the message type object |
|
265 | + * Note this is an array with singular and plural keys |
|
266 | + * |
|
267 | + * @access public |
|
268 | + * @return array labels for "context" |
|
269 | + * @throws EE_Error |
|
270 | + */ |
|
271 | + public function context_label() |
|
272 | + { |
|
273 | + $obj = $this->message_type_obj(); |
|
274 | + return $obj->get_context_label(); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * This returns an array of EE_Message_Template objects indexed by context and field. |
|
280 | + * |
|
281 | + * @return array () |
|
282 | + * @throws EE_Error |
|
283 | + */ |
|
284 | + public function context_templates() |
|
285 | + { |
|
286 | + $mtps_arr = array(); |
|
287 | + $mtps = $this->get_many_related('Message_Template'); |
|
288 | + if (empty($mtps)) { |
|
289 | + return array(); |
|
290 | + } |
|
291 | + // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
292 | + foreach ($mtps as $mtp) { |
|
293 | + $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
294 | + } |
|
295 | + return $mtps_arr; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * this returns if the template group this template belongs to is global |
|
301 | + * |
|
302 | + * @return bool true if it is, false if it isn't |
|
303 | + * @throws EE_Error |
|
304 | + */ |
|
305 | + public function is_global() |
|
306 | + { |
|
307 | + return $this->get('MTP_is_global'); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
313 | + * |
|
314 | + * @return bool true if it is, false if it isn't |
|
315 | + * @throws EE_Error |
|
316 | + */ |
|
317 | + public function is_active() |
|
318 | + { |
|
319 | + return $this->get('MTP_is_active'); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
325 | + * this template. |
|
326 | + * |
|
327 | + * @since 4.3.0 |
|
328 | + * @uses EEH_MSG_Template::get_shortcodes() |
|
329 | + * @param string $context what context we're going to return shortcodes for |
|
330 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
331 | + * to be returned. |
|
332 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
333 | + * unique shortcodes for all the given (or all) fields. |
|
334 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
335 | + * shortcodes found. |
|
336 | + * @throws EE_Error |
|
337 | + */ |
|
338 | + public function get_shortcodes($context, $fields = array(), $merged = false) |
|
339 | + { |
|
340 | + $messenger = $this->messenger(); |
|
341 | + $message_type = $this->message_type(); |
|
342 | + return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
348 | + * use the default template pack. |
|
349 | + * |
|
350 | + * @since 4.5.0 |
|
351 | + * @return string |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + public function get_template_pack_name() |
|
355 | + { |
|
356 | + return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * This returns the specific template pack object referenced by the template pack name attached to this message |
|
362 | + * template group. If no template pack is assigned then the default template pack is retrieved. |
|
363 | + * |
|
364 | + * @since 4.5.0 |
|
365 | + * @return EE_Messages_Template_Pack |
|
366 | + * @throws EE_Error |
|
367 | + * @throws InvalidArgumentException |
|
368 | + * @throws ReflectionException |
|
369 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
370 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
371 | + */ |
|
372 | + public function get_template_pack() |
|
373 | + { |
|
374 | + $pack_name = $this->get_template_pack_name(); |
|
375 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
376 | + return EEH_MSG_Template::get_template_pack($pack_name); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
382 | + * use the default template variation. |
|
383 | + * |
|
384 | + * @since 4.5.0 |
|
385 | + * @return string |
|
386 | + * @throws EE_Error |
|
387 | + */ |
|
388 | + public function get_template_pack_variation() |
|
389 | + { |
|
390 | + return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * This just sets the template pack name attached to this message template group. |
|
396 | + * |
|
397 | + * @since 4.5.0 |
|
398 | + * @param string $template_pack_name What message template pack is assigned. |
|
399 | + * @return int |
|
400 | + * @throws EE_Error |
|
401 | + */ |
|
402 | + public function set_template_pack_name($template_pack_name) |
|
403 | + { |
|
404 | + return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * This just sets the template pack variation attached to this message template group. |
|
410 | + * |
|
411 | + * @since 4.5.0 |
|
412 | + * @param string $variation What variation is being set on the message template group. |
|
413 | + * @return int |
|
414 | + * @throws EE_Error |
|
415 | + */ |
|
416 | + public function set_template_pack_variation($variation) |
|
417 | + { |
|
418 | + return $this->update_extra_meta('MTP_variation', $variation); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Deactivates the given context. |
|
424 | + * |
|
425 | + * @param $context |
|
426 | + * @return bool|int |
|
427 | + * @throws EE_Error |
|
428 | + * @throws InvalidIdentifierException |
|
429 | + */ |
|
430 | + public function deactivate_context($context) |
|
431 | + { |
|
432 | + $this->validate_context($context); |
|
433 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * Activates the given context. |
|
439 | + * |
|
440 | + * @param $context |
|
441 | + * @return bool|int |
|
442 | + * @throws EE_Error |
|
443 | + * @throws InvalidIdentifierException |
|
444 | + */ |
|
445 | + public function activate_context($context) |
|
446 | + { |
|
447 | + $this->validate_context($context); |
|
448 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Returns whether the context is active or not. |
|
454 | + * Note, this will default to true if the extra meta record doesn't exist. |
|
455 | + * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
456 | + * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
457 | + * whether a context is "active" or not. |
|
458 | + * |
|
459 | + * @param $context |
|
460 | + * @return bool |
|
461 | + * @throws EE_Error |
|
462 | + * @throws InvalidIdentifierException |
|
463 | + */ |
|
464 | + public function is_context_active($context) |
|
465 | + { |
|
466 | + $this->validate_context($context); |
|
467 | + return filter_var( |
|
468 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
469 | + FILTER_VALIDATE_BOOLEAN |
|
470 | + ); |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * Validates the incoming context to verify it matches a registered context for the related message type. |
|
476 | + * |
|
477 | + * @param string $context |
|
478 | + * @throws EE_Error |
|
479 | + * @throws InvalidIdentifierException |
|
480 | + */ |
|
481 | + public function validate_context($context) |
|
482 | + { |
|
483 | + $contexts = $this->contexts_config(); |
|
484 | + if (! isset($contexts[ $context ])) { |
|
485 | + throw new InvalidIdentifierException( |
|
486 | + '', |
|
487 | + '', |
|
488 | + sprintf( |
|
489 | + esc_html__( |
|
490 | + 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
491 | + 'event_espresso' |
|
492 | + ), |
|
493 | + $context, |
|
494 | + implode(',', array_keys($contexts)) |
|
495 | + ) |
|
496 | + ); |
|
497 | + } |
|
498 | + } |
|
499 | 499 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function set_message_type($message_type = false) |
50 | 50 | { |
51 | - if (! $message_type) { |
|
51 | + if ( ! $message_type) { |
|
52 | 52 | throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
53 | 53 | } |
54 | 54 | $this->set('MTP_message_type', $message_type); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function set_messenger($messenger = false) |
63 | 63 | { |
64 | - if (! $messenger) { |
|
64 | + if ( ! $messenger) { |
|
65 | 65 | throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
66 | 66 | } |
67 | 67 | $this->set('MTP_messenger', $messenger); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function set_group_template_id($GRP_ID = false) |
76 | 76 | { |
77 | - if (! $GRP_ID) { |
|
77 | + if ( ! $GRP_ID) { |
|
78 | 78 | throw new EE_Error( |
79 | 79 | esc_html__( |
80 | 80 | 'Missing required value for the message template group id', |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | } |
291 | 291 | // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
292 | 292 | foreach ($mtps as $mtp) { |
293 | - $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
293 | + $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp; |
|
294 | 294 | } |
295 | 295 | return $mtps_arr; |
296 | 296 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | public function deactivate_context($context) |
431 | 431 | { |
432 | 432 | $this->validate_context($context); |
433 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
433 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, false); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | public function activate_context($context) |
446 | 446 | { |
447 | 447 | $this->validate_context($context); |
448 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
448 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | { |
466 | 466 | $this->validate_context($context); |
467 | 467 | return filter_var( |
468 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
468 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true, true), |
|
469 | 469 | FILTER_VALIDATE_BOOLEAN |
470 | 470 | ); |
471 | 471 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | public function validate_context($context) |
482 | 482 | { |
483 | 483 | $contexts = $this->contexts_config(); |
484 | - if (! isset($contexts[ $context ])) { |
|
484 | + if ( ! isset($contexts[$context])) { |
|
485 | 485 | throw new InvalidIdentifierException( |
486 | 486 | '', |
487 | 487 | '', |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | * there's a single shared message template group among all the events. Otherwise it returns null. |
460 | 460 | * |
461 | 461 | * @param array $event_ids |
462 | - * @return EE_Message_Template_Group|null |
|
462 | + * @return null|EE_Base_Class |
|
463 | 463 | * @throws EE_Error |
464 | 464 | * @throws InvalidArgumentException |
465 | 465 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | /** |
496 | 496 | * Retrieves the global message template group for the current messenger and message type. |
497 | 497 | * |
498 | - * @return EE_Message_Template_Group|null |
|
498 | + * @return null|EE_Base_Class |
|
499 | 499 | * @throws EE_Error |
500 | 500 | * @throws InvalidArgumentException |
501 | 501 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | * @param EE_Messages_Addressee $recipient |
642 | 642 | * @param array $templates formatted array of templates used for parsing data. |
643 | 643 | * @param EE_Message_Template_Group $message_template_group |
644 | - * @return bool|EE_Message |
|
644 | + * @return EE_Message |
|
645 | 645 | * @throws EE_Error |
646 | 646 | */ |
647 | 647 | protected function _setup_message_object( |
@@ -12,973 +12,973 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * @type EE_Messages_Data_Handler_Collection |
|
17 | - */ |
|
18 | - protected $_data_handler_collection; |
|
19 | - |
|
20 | - /** |
|
21 | - * @type EE_Message_Template_Group_Collection |
|
22 | - */ |
|
23 | - protected $_template_collection; |
|
24 | - |
|
25 | - /** |
|
26 | - * This will hold the data handler for the current EE_Message being generated. |
|
27 | - * |
|
28 | - * @type EE_Messages_incoming_data |
|
29 | - */ |
|
30 | - protected $_current_data_handler; |
|
31 | - |
|
32 | - /** |
|
33 | - * This holds the EE_Messages_Queue that contains the messages to generate. |
|
34 | - * |
|
35 | - * @type EE_Messages_Queue |
|
36 | - */ |
|
37 | - protected $_generation_queue; |
|
38 | - |
|
39 | - /** |
|
40 | - * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
41 | - * |
|
42 | - * @type EE_Messages_Queue |
|
43 | - */ |
|
44 | - protected $_ready_queue; |
|
45 | - |
|
46 | - /** |
|
47 | - * This is a container for any error messages that get created through the generation |
|
48 | - * process. |
|
49 | - * |
|
50 | - * @type array |
|
51 | - */ |
|
52 | - protected $_error_msg = array(); |
|
53 | - |
|
54 | - /** |
|
55 | - * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
56 | - * |
|
57 | - * @type bool |
|
58 | - */ |
|
59 | - protected $_verified = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
63 | - * |
|
64 | - * @type EE_messenger |
|
65 | - */ |
|
66 | - protected $_current_messenger; |
|
67 | - |
|
68 | - /** |
|
69 | - * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
70 | - * |
|
71 | - * @type EE_message_type |
|
72 | - */ |
|
73 | - protected $_current_message_type; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type EEH_Parse_Shortcodes |
|
77 | - */ |
|
78 | - protected $_shortcode_parser; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param EE_Messages_Queue $generation_queue |
|
83 | - * @param \EE_Messages_Queue $ready_queue |
|
84 | - * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
85 | - * @param \EE_Message_Template_Group_Collection $template_collection |
|
86 | - * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
87 | - */ |
|
88 | - public function __construct( |
|
89 | - EE_Messages_Queue $generation_queue, |
|
90 | - EE_Messages_Queue $ready_queue, |
|
91 | - EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
92 | - EE_Message_Template_Group_Collection $template_collection, |
|
93 | - EEH_Parse_Shortcodes $shortcode_parser |
|
94 | - ) { |
|
95 | - $this->_generation_queue = $generation_queue; |
|
96 | - $this->_ready_queue = $ready_queue; |
|
97 | - $this->_data_handler_collection = $data_handler_collection; |
|
98 | - $this->_template_collection = $template_collection; |
|
99 | - $this->_shortcode_parser = $shortcode_parser; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return EE_Messages_Queue |
|
105 | - */ |
|
106 | - public function generation_queue() |
|
107 | - { |
|
108 | - return $this->_generation_queue; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * This iterates through the provided queue and generates the EE_Message objects. |
|
114 | - * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
115 | - * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
116 | - * for the caller to decide what to do with it. |
|
117 | - * |
|
118 | - * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
119 | - * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
120 | - * @throws EE_Error |
|
121 | - * @throws ReflectionException |
|
122 | - */ |
|
123 | - public function generate($save = true) |
|
124 | - { |
|
125 | - // iterate through the messages in the queue, generate, and add to new queue. |
|
126 | - $this->_generation_queue->get_message_repository()->rewind(); |
|
127 | - while ($this->_generation_queue->get_message_repository()->valid()) { |
|
128 | - // reset "current" properties |
|
129 | - $this->_reset_current_properties(); |
|
130 | - |
|
131 | - /** @type EE_Message $msg */ |
|
132 | - $msg = $this->_generation_queue->get_message_repository()->current(); |
|
133 | - |
|
134 | - /** |
|
135 | - * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
136 | - * an object is removed from the repo then valid for the next object will fail. |
|
137 | - */ |
|
138 | - $this->_generation_queue->get_message_repository()->next(); |
|
139 | - $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
140 | - // restore pointer to current item |
|
141 | - $this->_generation_queue->get_message_repository()->set_current($msg); |
|
142 | - |
|
143 | - // skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
144 | - if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
145 | - // we keep this item in the db just remove from the repo. |
|
146 | - $this->_generation_queue->get_message_repository()->remove($msg); |
|
147 | - // next item |
|
148 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
149 | - continue; |
|
150 | - } |
|
151 | - |
|
152 | - if ($this->_verify()) { |
|
153 | - // let's get generating! |
|
154 | - $this->_generate(); |
|
155 | - } |
|
156 | - |
|
157 | - // don't persist debug_only messages if the messages system is not in debug mode. |
|
158 | - if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
159 | - && ! EEM_Message::debug() |
|
160 | - ) { |
|
161 | - do_action( |
|
162 | - 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
163 | - $msg, |
|
164 | - $this->_error_msg, |
|
165 | - $this->_current_messenger, |
|
166 | - $this->_current_message_type, |
|
167 | - $this->_current_data_handler |
|
168 | - ); |
|
169 | - $this->_generation_queue->get_message_repository()->delete(); |
|
170 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
171 | - continue; |
|
172 | - } |
|
173 | - |
|
174 | - // if there are error messages then let's set the status and the error message. |
|
175 | - if ($this->_error_msg) { |
|
176 | - // if the status is already debug only, then let's leave it at that. |
|
177 | - if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
178 | - $msg->set_STS_ID(EEM_Message::status_failed); |
|
179 | - } |
|
180 | - do_action( |
|
181 | - 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
182 | - $msg, |
|
183 | - $this->_error_msg, |
|
184 | - $this->_current_messenger, |
|
185 | - $this->_current_message_type, |
|
186 | - $this->_current_data_handler |
|
187 | - ); |
|
188 | - $msg->set_error_message( |
|
189 | - esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
190 | - . "\n" |
|
191 | - . implode("\n", $this->_error_msg) |
|
192 | - ); |
|
193 | - $msg->set_modified(time()); |
|
194 | - } else { |
|
195 | - do_action( |
|
196 | - 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
197 | - $msg, |
|
198 | - $this->_error_msg, |
|
199 | - $this->_current_messenger, |
|
200 | - $this->_current_message_type, |
|
201 | - $this->_current_data_handler |
|
202 | - ); |
|
203 | - // remove from db |
|
204 | - $this->_generation_queue->get_message_repository()->delete(); |
|
205 | - } |
|
206 | - // next item |
|
207 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
208 | - } |
|
209 | - |
|
210 | - // generation queue is ALWAYS saved to record any errors in the generation process. |
|
211 | - $this->_generation_queue->save(); |
|
212 | - |
|
213 | - /** |
|
214 | - * save _ready_queue if flag set. |
|
215 | - * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
216 | - * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
217 | - * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
218 | - * irrelevant. |
|
219 | - */ |
|
220 | - if ($save) { |
|
221 | - $this->_ready_queue->save(); |
|
222 | - } |
|
223 | - |
|
224 | - // final reset of properties |
|
225 | - $this->_reset_current_properties(); |
|
226 | - |
|
227 | - return $this->_ready_queue; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
233 | - * in the generation queue. |
|
234 | - */ |
|
235 | - protected function _reset_current_properties() |
|
236 | - { |
|
237 | - $this->_verified = false; |
|
238 | - // make sure any _data value in the current message type is reset |
|
239 | - if ($this->_current_message_type instanceof EE_message_type) { |
|
240 | - $this->_current_message_type->reset_data(); |
|
241 | - } |
|
242 | - $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
248 | - * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
249 | - * _generating_queue. |
|
250 | - * |
|
251 | - * @return bool Whether the message was successfully generated or not. |
|
252 | - * @throws EE_Error |
|
253 | - * @throws InvalidArgumentException |
|
254 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
255 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
256 | - */ |
|
257 | - protected function _generate() |
|
258 | - { |
|
259 | - // double check verification has run and that everything is ready to work with (saves us having to validate |
|
260 | - // everything again). |
|
261 | - if (! $this->_verified) { |
|
262 | - return false; // get out because we don't have a valid setup to work with. |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - try { |
|
267 | - $addressees = $this->_current_message_type->get_addressees( |
|
268 | - $this->_current_data_handler, |
|
269 | - $this->_generation_queue->get_message_repository()->current()->context() |
|
270 | - ); |
|
271 | - } catch (EE_Error $e) { |
|
272 | - $this->_error_msg[] = $e->getMessage(); |
|
273 | - return false; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - // if no addressees then get out because there is nothing to generation (possible bad data). |
|
278 | - if (! $this->_valid_addressees($addressees)) { |
|
279 | - do_action( |
|
280 | - 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
281 | - $this->_generation_queue->get_message_repository()->current(), |
|
282 | - $addressees, |
|
283 | - $this->_current_messenger, |
|
284 | - $this->_current_message_type, |
|
285 | - $this->_current_data_handler |
|
286 | - ); |
|
287 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
288 | - EEM_Message::status_debug_only |
|
289 | - ); |
|
290 | - $this->_error_msg[] = esc_html__( |
|
291 | - 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
292 | - 'event_espresso' |
|
293 | - ); |
|
294 | - return false; |
|
295 | - } |
|
296 | - |
|
297 | - $message_template_group = $this->_get_message_template_group(); |
|
298 | - |
|
299 | - // in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
300 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
301 | - $this->_error_msg[] = esc_html__( |
|
302 | - 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
303 | - 'event_espresso' |
|
304 | - ); |
|
305 | - return false; |
|
306 | - } |
|
307 | - |
|
308 | - // get formatted templates for using to parse and setup EE_Message objects. |
|
309 | - $templates = $this->_get_templates($message_template_group); |
|
310 | - |
|
311 | - |
|
312 | - // setup new EE_Message objects (and add to _ready_queue) |
|
313 | - return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * Retrieves the message template group being used for generating messages. |
|
319 | - * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
320 | - * |
|
321 | - * @return EE_Message_Template_Group|null |
|
322 | - * @throws EE_Error |
|
323 | - * @throws InvalidArgumentException |
|
324 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
325 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
326 | - */ |
|
327 | - protected function _get_message_template_group() |
|
328 | - { |
|
329 | - // first see if there is a specific message template group requested (current message in the queue has a specific |
|
330 | - // GRP_ID |
|
331 | - $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
332 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
333 | - return $message_template_group; |
|
334 | - } |
|
335 | - |
|
336 | - // get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
337 | - // in the collection. |
|
338 | - $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
339 | - $message_template_group = $this->_template_collection->get_by_key( |
|
340 | - $this->_template_collection->getKey( |
|
341 | - $this->_current_messenger->name, |
|
342 | - $this->_current_message_type->name, |
|
343 | - $event_ids |
|
344 | - ) |
|
345 | - ); |
|
346 | - |
|
347 | - // if we have a message template group then no need to hit the database, just return it. |
|
348 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
349 | - return $message_template_group; |
|
350 | - } |
|
351 | - |
|
352 | - // okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
353 | - // there is no override set. |
|
354 | - $global_message_template_group = |
|
355 | - $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
356 | - |
|
357 | - if ($global_message_template_group instanceof EE_Message_Template_Group |
|
358 | - && $global_message_template_group->get('MTP_is_override') |
|
359 | - ) { |
|
360 | - return $global_message_template_group; |
|
361 | - } |
|
362 | - |
|
363 | - // if we're still here, that means there was no message template group for the events in the collection and |
|
364 | - // the global message template group for the messenger and message type is not set for override. So next step is |
|
365 | - // to see if there is a common shared custom message template group for this set of events. |
|
366 | - $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
367 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
368 | - return $message_template_group; |
|
369 | - } |
|
370 | - |
|
371 | - // STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
372 | - // So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
373 | - // and return it. |
|
374 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
375 | - $this->_template_collection->add( |
|
376 | - $global_message_template_group, |
|
377 | - $event_ids |
|
378 | - ); |
|
379 | - return $global_message_template_group; |
|
380 | - } |
|
381 | - |
|
382 | - // if we land here that means there's NO active message template group for this set. |
|
383 | - // TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
384 | - // template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
385 | - // this should likely bit hit rarely enough that it's not a significant issue. |
|
386 | - return null; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
392 | - * requested for that message. |
|
393 | - * |
|
394 | - * @return EE_Message_Template_Group|null |
|
395 | - * @throws EE_Error |
|
396 | - * @throws InvalidArgumentException |
|
397 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
398 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
399 | - */ |
|
400 | - protected function _specific_message_template_group_from_queue() |
|
401 | - { |
|
402 | - // is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
403 | - // so let's use that. |
|
404 | - $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
405 | - |
|
406 | - if ($GRP_ID) { |
|
407 | - // attempt to retrieve from repo first |
|
408 | - $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
409 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
410 | - return $message_template_group; // got it! |
|
411 | - } |
|
412 | - |
|
413 | - // nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
414 | - // is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
415 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
416 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
417 | - $this->_template_collection->add($message_template_group); |
|
418 | - return $message_template_group; |
|
419 | - } |
|
420 | - } |
|
421 | - return null; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * Returns whether the event ids passed in all share the same message template group for the current message type |
|
427 | - * and messenger. |
|
428 | - * |
|
429 | - * @param array $event_ids |
|
430 | - * @return bool true means they DO share the same message template group, false means they don't. |
|
431 | - * @throws EE_Error |
|
432 | - * @throws InvalidArgumentException |
|
433 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
434 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
435 | - */ |
|
436 | - protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
437 | - { |
|
438 | - foreach ($this->_current_data_handler->events as $event) { |
|
439 | - $event_ids[ $event['ID'] ] = $event['ID']; |
|
440 | - } |
|
441 | - $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
442 | - array( |
|
443 | - array( |
|
444 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
445 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
446 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
447 | - ), |
|
448 | - ), |
|
449 | - 'GRP_ID', |
|
450 | - true |
|
451 | - ); |
|
452 | - return $count_of_message_template_groups === 1; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
458 | - * there's a single shared message template group among all the events. Otherwise it returns null. |
|
459 | - * |
|
460 | - * @param array $event_ids |
|
461 | - * @return EE_Message_Template_Group|null |
|
462 | - * @throws EE_Error |
|
463 | - * @throws InvalidArgumentException |
|
464 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
465 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
466 | - */ |
|
467 | - protected function _get_shared_message_template_for_events(array $event_ids) |
|
468 | - { |
|
469 | - $message_template_group = null; |
|
470 | - if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
471 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
472 | - array( |
|
473 | - array( |
|
474 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
475 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
476 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
477 | - 'MTP_is_active' => true, |
|
478 | - ), |
|
479 | - 'group_by' => 'GRP_ID', |
|
480 | - ) |
|
481 | - ); |
|
482 | - // store this in the collection if its valid |
|
483 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
484 | - $this->_template_collection->add( |
|
485 | - $message_template_group, |
|
486 | - $event_ids |
|
487 | - ); |
|
488 | - } |
|
489 | - } |
|
490 | - return $message_template_group; |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * Retrieves the global message template group for the current messenger and message type. |
|
496 | - * |
|
497 | - * @return EE_Message_Template_Group|null |
|
498 | - * @throws EE_Error |
|
499 | - * @throws InvalidArgumentException |
|
500 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
501 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
502 | - */ |
|
503 | - protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
504 | - { |
|
505 | - // first check the collection (we use an array with 0 in it to represent global groups). |
|
506 | - $global_message_template_group = $this->_template_collection->get_by_key( |
|
507 | - $this->_template_collection->getKey( |
|
508 | - $this->_current_messenger->name, |
|
509 | - $this->_current_message_type->name, |
|
510 | - array(0) |
|
511 | - ) |
|
512 | - ); |
|
513 | - |
|
514 | - // if we don't have a group lets hit the db. |
|
515 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
516 | - $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
517 | - array( |
|
518 | - array( |
|
519 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
520 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
521 | - 'MTP_is_active' => true, |
|
522 | - 'MTP_is_global' => true, |
|
523 | - ), |
|
524 | - ) |
|
525 | - ); |
|
526 | - // if we have a group, add it to the collection. |
|
527 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
528 | - $this->_template_collection->add( |
|
529 | - $global_message_template_group, |
|
530 | - array(0) |
|
531 | - ); |
|
532 | - } |
|
533 | - } |
|
534 | - return $global_message_template_group; |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * Returns an array of event ids for all the events within the current data handler. |
|
540 | - * |
|
541 | - * @return array |
|
542 | - */ |
|
543 | - protected function _get_event_ids_from_current_data_handler() |
|
544 | - { |
|
545 | - $event_ids = array(); |
|
546 | - foreach ($this->_current_data_handler->events as $event) { |
|
547 | - $event_ids[ $event['ID'] ] = $event['ID']; |
|
548 | - } |
|
549 | - return $event_ids; |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * Retrieves formatted array of template information for each context specific to the given |
|
555 | - * EE_Message_Template_Group |
|
556 | - * |
|
557 | - * @param EE_Message_Template_Group $message_template_group |
|
558 | - * @return array The returned array is in this structure: |
|
559 | - * array( |
|
560 | - * 'field_name' => array( |
|
561 | - * 'context' => 'content' |
|
562 | - * ) |
|
563 | - * ) |
|
564 | - * @throws EE_Error |
|
565 | - */ |
|
566 | - protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
567 | - { |
|
568 | - $templates = array(); |
|
569 | - $context_templates = $message_template_group->context_templates(); |
|
570 | - foreach ($context_templates as $context => $template_fields) { |
|
571 | - foreach ($template_fields as $template_field => $template_obj) { |
|
572 | - if (! $template_obj instanceof EE_Message_Template) { |
|
573 | - continue; |
|
574 | - } |
|
575 | - $templates[ $template_field ][ $context ] = $template_obj->get('MTP_content'); |
|
576 | - } |
|
577 | - } |
|
578 | - return $templates; |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
584 | - * |
|
585 | - * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
586 | - * context. |
|
587 | - * @param array $templates formatted array of templates used for parsing data. |
|
588 | - * @param EE_Message_Template_Group $message_template_group |
|
589 | - * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
590 | - * method will attempt to generate ALL EE_Message objects and add to |
|
591 | - * the _ready_queue. Successfully generated messages get added to the |
|
592 | - * queue with EEM_Message::status_idle, unsuccessfully generated |
|
593 | - * messages will get added to the queue as EEM_Message::status_failed. |
|
594 | - * Very rarely should "false" be returned from this method. |
|
595 | - * @throws EE_Error |
|
596 | - */ |
|
597 | - protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
598 | - { |
|
599 | - |
|
600 | - // if templates are empty then get out because we can't generate anything. |
|
601 | - if (! $templates) { |
|
602 | - $this->_error_msg[] = esc_html__( |
|
603 | - 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
604 | - 'event_espresso' |
|
605 | - ); |
|
606 | - return false; |
|
607 | - } |
|
608 | - |
|
609 | - // We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
610 | - // generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
611 | - $generated_count = 0; |
|
612 | - foreach ($addressees as $context => $recipients) { |
|
613 | - foreach ($recipients as $recipient) { |
|
614 | - $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
615 | - if ($message instanceof EE_Message) { |
|
616 | - $this->_ready_queue->add( |
|
617 | - $message, |
|
618 | - array(), |
|
619 | - $this->_generation_queue->get_message_repository()->is_preview(), |
|
620 | - $this->_generation_queue->get_message_repository()->is_test_send() |
|
621 | - ); |
|
622 | - $generated_count++; |
|
623 | - } |
|
624 | - |
|
625 | - // if the current MSG being generated is for a test send then we'll only use ONE message in the |
|
626 | - // generation. |
|
627 | - if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
628 | - break 2; |
|
629 | - } |
|
630 | - } |
|
631 | - } |
|
632 | - |
|
633 | - // if there are no generated messages then something else fatal went wrong. |
|
634 | - return $generated_count > 0; |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * @param string $context The context for the generated message. |
|
640 | - * @param EE_Messages_Addressee $recipient |
|
641 | - * @param array $templates formatted array of templates used for parsing data. |
|
642 | - * @param EE_Message_Template_Group $message_template_group |
|
643 | - * @return bool|EE_Message |
|
644 | - * @throws EE_Error |
|
645 | - */ |
|
646 | - protected function _setup_message_object( |
|
647 | - $context, |
|
648 | - EE_Messages_Addressee $recipient, |
|
649 | - $templates, |
|
650 | - EE_Message_Template_Group $message_template_group |
|
651 | - ) { |
|
652 | - // stuff we already know |
|
653 | - $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
654 | - $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
655 | - ? $this->_current_data_handler->txn->ID() |
|
656 | - : $transaction_id; |
|
657 | - $message_fields = array( |
|
658 | - 'GRP_ID' => $message_template_group->ID(), |
|
659 | - 'TXN_ID' => $transaction_id, |
|
660 | - 'MSG_messenger' => $this->_current_messenger->name, |
|
661 | - 'MSG_message_type' => $this->_current_message_type->name, |
|
662 | - 'MSG_context' => $context, |
|
663 | - ); |
|
664 | - |
|
665 | - // recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
666 | - // the info from the att_obj found in the EE_Messages_Addressee object. |
|
667 | - if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
668 | - $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
669 | - ? $recipient->att_obj->ID() |
|
670 | - : 0; |
|
671 | - $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
672 | - } else { |
|
673 | - $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
674 | - $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
675 | - } |
|
676 | - $message = EE_Message_Factory::create($message_fields); |
|
677 | - |
|
678 | - // grab valid shortcodes for shortcode parser |
|
679 | - $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
680 | - $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
681 | - |
|
682 | - // if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
|
683 | - if (( |
|
684 | - ( |
|
685 | - empty($templates['to'][ $context ]) |
|
686 | - && ! $this->_current_messenger->allow_empty_to_field() |
|
687 | - ) |
|
688 | - || ! $message_template_group->is_context_active($context) |
|
689 | - ) |
|
690 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
691 | - ) { |
|
692 | - // we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
693 | - // field. |
|
694 | - return false; |
|
695 | - } |
|
696 | - $error_msg = array(); |
|
697 | - foreach ($templates as $field => $field_context) { |
|
698 | - $error_msg = array(); |
|
699 | - // let's setup the valid shortcodes for the incoming context. |
|
700 | - $valid_shortcodes = $mt_shortcodes[ $context ]; |
|
701 | - // merge in valid shortcodes for the field. |
|
702 | - $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes; |
|
703 | - if (isset($templates[ $field ][ $context ])) { |
|
704 | - // prefix field. |
|
705 | - $column_name = 'MSG_' . $field; |
|
706 | - try { |
|
707 | - $content = $this->_shortcode_parser->parse_message_template( |
|
708 | - $templates[ $field ][ $context ], |
|
709 | - $recipient, |
|
710 | - $shortcodes, |
|
711 | - $this->_current_message_type, |
|
712 | - $this->_current_messenger, |
|
713 | - $message |
|
714 | - ); |
|
715 | - // the model field removes slashes when setting (usually necessary when the input is from the |
|
716 | - // request) but this value is from another model and has no slashes. So add them so it matchces |
|
717 | - // what the field expected (otherwise slashes will have been stripped from this an extra time) |
|
718 | - $message->set_field_or_extra_meta($column_name, addslashes($content)); |
|
719 | - } catch (EE_Error $e) { |
|
720 | - $error_msg[] = sprintf( |
|
721 | - esc_html__( |
|
722 | - 'There was a problem generating the content for the field %s: %s', |
|
723 | - 'event_espresso' |
|
724 | - ), |
|
725 | - $field, |
|
726 | - $e->getMessage() |
|
727 | - ); |
|
728 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
729 | - } |
|
730 | - } |
|
731 | - } |
|
732 | - |
|
733 | - if ($message->STS_ID() === EEM_Message::status_failed) { |
|
734 | - $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
735 | - . "\n" |
|
736 | - . implode("\n", $error_msg); |
|
737 | - $message->set_error_message($error_msg); |
|
738 | - } else { |
|
739 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
740 | - } |
|
741 | - return $message; |
|
742 | - } |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
747 | - * error message if either is missing. |
|
748 | - * |
|
749 | - * @return bool true means there were no errors, false means there were errors. |
|
750 | - * @throws EE_Error |
|
751 | - * @throws ReflectionException |
|
752 | - */ |
|
753 | - protected function _verify() |
|
754 | - { |
|
755 | - // reset error message to an empty array. |
|
756 | - $this->_error_msg = array(); |
|
757 | - $valid = true; |
|
758 | - $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
759 | - $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
760 | - |
|
761 | - // set the verified flag so we know everything has been validated. |
|
762 | - $this->_verified = $valid; |
|
763 | - |
|
764 | - return $valid; |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
770 | - * EE_Messages_Addressee objects. |
|
771 | - * |
|
772 | - * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
773 | - * @return bool |
|
774 | - */ |
|
775 | - protected function _valid_addressees($addressees) |
|
776 | - { |
|
777 | - if (! $addressees || ! is_array($addressees)) { |
|
778 | - return false; |
|
779 | - } |
|
780 | - |
|
781 | - foreach ($addressees as $addressee_array) { |
|
782 | - foreach ($addressee_array as $addressee) { |
|
783 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
784 | - return false; |
|
785 | - } |
|
786 | - } |
|
787 | - } |
|
788 | - return true; |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - /** |
|
793 | - * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
794 | - * queue. This process sets error messages if something is wrong. |
|
795 | - * |
|
796 | - * @return bool true is if there are no errors. false is if there is. |
|
797 | - */ |
|
798 | - protected function _validate_messenger_and_message_type() |
|
799 | - { |
|
800 | - |
|
801 | - // first are there any existing error messages? If so then return. |
|
802 | - if ($this->_error_msg) { |
|
803 | - return false; |
|
804 | - } |
|
805 | - /** @type EE_Message $message */ |
|
806 | - $message = $this->_generation_queue->get_message_repository()->current(); |
|
807 | - try { |
|
808 | - $this->_current_messenger = $message->valid_messenger(true) |
|
809 | - ? $message->messenger_object() |
|
810 | - : null; |
|
811 | - } catch (Exception $e) { |
|
812 | - $this->_error_msg[] = $e->getMessage(); |
|
813 | - } |
|
814 | - try { |
|
815 | - $this->_current_message_type = $message->valid_message_type(true) |
|
816 | - ? $message->message_type_object() |
|
817 | - : null; |
|
818 | - } catch (Exception $e) { |
|
819 | - $this->_error_msg[] = $e->getMessage(); |
|
820 | - } |
|
821 | - |
|
822 | - /** |
|
823 | - * Check if there is any generation data, but only if this is not for a preview. |
|
824 | - */ |
|
825 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
826 | - && ( |
|
827 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
828 | - && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
829 | - !== 'EE_Messages_Preview_incoming_data' |
|
830 | - ) |
|
831 | - ) { |
|
832 | - $this->_error_msg[] = esc_html__( |
|
833 | - 'There is no generation data for this message. Unable to generate.', |
|
834 | - 'event_espresso' |
|
835 | - ); |
|
836 | - } |
|
837 | - |
|
838 | - return empty($this->_error_msg); |
|
839 | - } |
|
840 | - |
|
841 | - |
|
842 | - /** |
|
843 | - * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
844 | - * data handler. |
|
845 | - * |
|
846 | - * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
847 | - * @throws EE_Error |
|
848 | - * @throws ReflectionException |
|
849 | - */ |
|
850 | - protected function _validate_and_setup_data() |
|
851 | - { |
|
852 | - |
|
853 | - // First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
854 | - // be used anyways. |
|
855 | - if ($this->_error_msg) { |
|
856 | - return false; |
|
857 | - } |
|
858 | - |
|
859 | - $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
860 | - |
|
861 | - /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
|
862 | - $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
863 | - ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
864 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
865 | - |
|
866 | - // If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
867 | - if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
868 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
869 | - } |
|
870 | - |
|
871 | - // First get the class name for the data handler (and also verifies it exists. |
|
872 | - if (! class_exists($data_handler_class_name)) { |
|
873 | - $this->_error_msg[] = sprintf( |
|
874 | - esc_html__( |
|
875 | - 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
876 | - 'event_espresso' |
|
877 | - ), |
|
878 | - 'EE_Messages_incoming_data', |
|
879 | - $data_handler_class_name |
|
880 | - ); |
|
881 | - return false; |
|
882 | - } |
|
883 | - |
|
884 | - // convert generation_data for data_handler_instantiation. |
|
885 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
886 | - |
|
887 | - // note, this may set error messages as well. |
|
888 | - $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
889 | - |
|
890 | - return empty($this->_error_msg); |
|
891 | - } |
|
892 | - |
|
893 | - |
|
894 | - /** |
|
895 | - * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
896 | - * adds it to the _data repository. |
|
897 | - * |
|
898 | - * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
899 | - * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
900 | - * instantiated. |
|
901 | - * @return void . |
|
902 | - * @throws EE_Error |
|
903 | - * @throws ReflectionException |
|
904 | - */ |
|
905 | - protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
906 | - { |
|
907 | - // valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
908 | - // is already a ready data handler in the repository. |
|
909 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
910 | - $this->_data_handler_collection->get_key( |
|
911 | - $data_handler_class_name, |
|
912 | - $generating_data |
|
913 | - ) |
|
914 | - ); |
|
915 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
916 | - // no saved data_handler in the repo so let's set one up and add it to the repo. |
|
917 | - try { |
|
918 | - $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
919 | - $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
920 | - } catch (EE_Error $e) { |
|
921 | - $this->_error_msg[] = $e->get_error(); |
|
922 | - } |
|
923 | - } |
|
924 | - } |
|
925 | - |
|
926 | - |
|
927 | - /** |
|
928 | - * The queued EE_Message for generation does not save the data used for generation as objects |
|
929 | - * because serialization of those objects could be problematic if the data is saved to the db. |
|
930 | - * So this method calls the static method on the associated data_handler for the given message_type |
|
931 | - * and that preps the data for later instantiation when generating. |
|
932 | - * |
|
933 | - * @param EE_Message_To_Generate $message_to_generate |
|
934 | - * @param bool $preview Indicate whether this is being used for a preview or not. |
|
935 | - * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
936 | - */ |
|
937 | - protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
938 | - { |
|
939 | - /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
940 | - $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
941 | - if (! $message_to_generate->valid()) { |
|
942 | - return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
943 | - } |
|
944 | - return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
945 | - } |
|
946 | - |
|
947 | - |
|
948 | - /** |
|
949 | - * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
950 | - * |
|
951 | - * @param EE_Message_To_Generate $message_to_generate |
|
952 | - * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
953 | - * @throws InvalidArgumentException |
|
954 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
955 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
956 | - */ |
|
957 | - public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
958 | - { |
|
959 | - // prep data |
|
960 | - $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
961 | - |
|
962 | - $message = $message_to_generate->get_EE_Message(); |
|
963 | - |
|
964 | - // is there a GRP_ID in the request? |
|
965 | - if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
966 | - $message->set_GRP_ID($GRP_ID); |
|
967 | - } |
|
968 | - |
|
969 | - if ($data === false) { |
|
970 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
971 | - $message->set_error_message( |
|
972 | - esc_html__( |
|
973 | - 'Unable to prepare data for persistence to the database.', |
|
974 | - 'event_espresso' |
|
975 | - ) |
|
976 | - ); |
|
977 | - } else { |
|
978 | - // make sure that the data handler is cached on the message as well |
|
979 | - $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
980 | - } |
|
981 | - |
|
982 | - $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
983 | - } |
|
15 | + /** |
|
16 | + * @type EE_Messages_Data_Handler_Collection |
|
17 | + */ |
|
18 | + protected $_data_handler_collection; |
|
19 | + |
|
20 | + /** |
|
21 | + * @type EE_Message_Template_Group_Collection |
|
22 | + */ |
|
23 | + protected $_template_collection; |
|
24 | + |
|
25 | + /** |
|
26 | + * This will hold the data handler for the current EE_Message being generated. |
|
27 | + * |
|
28 | + * @type EE_Messages_incoming_data |
|
29 | + */ |
|
30 | + protected $_current_data_handler; |
|
31 | + |
|
32 | + /** |
|
33 | + * This holds the EE_Messages_Queue that contains the messages to generate. |
|
34 | + * |
|
35 | + * @type EE_Messages_Queue |
|
36 | + */ |
|
37 | + protected $_generation_queue; |
|
38 | + |
|
39 | + /** |
|
40 | + * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
41 | + * |
|
42 | + * @type EE_Messages_Queue |
|
43 | + */ |
|
44 | + protected $_ready_queue; |
|
45 | + |
|
46 | + /** |
|
47 | + * This is a container for any error messages that get created through the generation |
|
48 | + * process. |
|
49 | + * |
|
50 | + * @type array |
|
51 | + */ |
|
52 | + protected $_error_msg = array(); |
|
53 | + |
|
54 | + /** |
|
55 | + * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
56 | + * |
|
57 | + * @type bool |
|
58 | + */ |
|
59 | + protected $_verified = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
63 | + * |
|
64 | + * @type EE_messenger |
|
65 | + */ |
|
66 | + protected $_current_messenger; |
|
67 | + |
|
68 | + /** |
|
69 | + * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
70 | + * |
|
71 | + * @type EE_message_type |
|
72 | + */ |
|
73 | + protected $_current_message_type; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type EEH_Parse_Shortcodes |
|
77 | + */ |
|
78 | + protected $_shortcode_parser; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param EE_Messages_Queue $generation_queue |
|
83 | + * @param \EE_Messages_Queue $ready_queue |
|
84 | + * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
85 | + * @param \EE_Message_Template_Group_Collection $template_collection |
|
86 | + * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
87 | + */ |
|
88 | + public function __construct( |
|
89 | + EE_Messages_Queue $generation_queue, |
|
90 | + EE_Messages_Queue $ready_queue, |
|
91 | + EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
92 | + EE_Message_Template_Group_Collection $template_collection, |
|
93 | + EEH_Parse_Shortcodes $shortcode_parser |
|
94 | + ) { |
|
95 | + $this->_generation_queue = $generation_queue; |
|
96 | + $this->_ready_queue = $ready_queue; |
|
97 | + $this->_data_handler_collection = $data_handler_collection; |
|
98 | + $this->_template_collection = $template_collection; |
|
99 | + $this->_shortcode_parser = $shortcode_parser; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return EE_Messages_Queue |
|
105 | + */ |
|
106 | + public function generation_queue() |
|
107 | + { |
|
108 | + return $this->_generation_queue; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * This iterates through the provided queue and generates the EE_Message objects. |
|
114 | + * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
115 | + * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
116 | + * for the caller to decide what to do with it. |
|
117 | + * |
|
118 | + * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
119 | + * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
120 | + * @throws EE_Error |
|
121 | + * @throws ReflectionException |
|
122 | + */ |
|
123 | + public function generate($save = true) |
|
124 | + { |
|
125 | + // iterate through the messages in the queue, generate, and add to new queue. |
|
126 | + $this->_generation_queue->get_message_repository()->rewind(); |
|
127 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
128 | + // reset "current" properties |
|
129 | + $this->_reset_current_properties(); |
|
130 | + |
|
131 | + /** @type EE_Message $msg */ |
|
132 | + $msg = $this->_generation_queue->get_message_repository()->current(); |
|
133 | + |
|
134 | + /** |
|
135 | + * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
136 | + * an object is removed from the repo then valid for the next object will fail. |
|
137 | + */ |
|
138 | + $this->_generation_queue->get_message_repository()->next(); |
|
139 | + $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
140 | + // restore pointer to current item |
|
141 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
142 | + |
|
143 | + // skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
144 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
145 | + // we keep this item in the db just remove from the repo. |
|
146 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
147 | + // next item |
|
148 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
149 | + continue; |
|
150 | + } |
|
151 | + |
|
152 | + if ($this->_verify()) { |
|
153 | + // let's get generating! |
|
154 | + $this->_generate(); |
|
155 | + } |
|
156 | + |
|
157 | + // don't persist debug_only messages if the messages system is not in debug mode. |
|
158 | + if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
159 | + && ! EEM_Message::debug() |
|
160 | + ) { |
|
161 | + do_action( |
|
162 | + 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
163 | + $msg, |
|
164 | + $this->_error_msg, |
|
165 | + $this->_current_messenger, |
|
166 | + $this->_current_message_type, |
|
167 | + $this->_current_data_handler |
|
168 | + ); |
|
169 | + $this->_generation_queue->get_message_repository()->delete(); |
|
170 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
171 | + continue; |
|
172 | + } |
|
173 | + |
|
174 | + // if there are error messages then let's set the status and the error message. |
|
175 | + if ($this->_error_msg) { |
|
176 | + // if the status is already debug only, then let's leave it at that. |
|
177 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
178 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
179 | + } |
|
180 | + do_action( |
|
181 | + 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
182 | + $msg, |
|
183 | + $this->_error_msg, |
|
184 | + $this->_current_messenger, |
|
185 | + $this->_current_message_type, |
|
186 | + $this->_current_data_handler |
|
187 | + ); |
|
188 | + $msg->set_error_message( |
|
189 | + esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
190 | + . "\n" |
|
191 | + . implode("\n", $this->_error_msg) |
|
192 | + ); |
|
193 | + $msg->set_modified(time()); |
|
194 | + } else { |
|
195 | + do_action( |
|
196 | + 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
197 | + $msg, |
|
198 | + $this->_error_msg, |
|
199 | + $this->_current_messenger, |
|
200 | + $this->_current_message_type, |
|
201 | + $this->_current_data_handler |
|
202 | + ); |
|
203 | + // remove from db |
|
204 | + $this->_generation_queue->get_message_repository()->delete(); |
|
205 | + } |
|
206 | + // next item |
|
207 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
208 | + } |
|
209 | + |
|
210 | + // generation queue is ALWAYS saved to record any errors in the generation process. |
|
211 | + $this->_generation_queue->save(); |
|
212 | + |
|
213 | + /** |
|
214 | + * save _ready_queue if flag set. |
|
215 | + * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
216 | + * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
217 | + * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
218 | + * irrelevant. |
|
219 | + */ |
|
220 | + if ($save) { |
|
221 | + $this->_ready_queue->save(); |
|
222 | + } |
|
223 | + |
|
224 | + // final reset of properties |
|
225 | + $this->_reset_current_properties(); |
|
226 | + |
|
227 | + return $this->_ready_queue; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
233 | + * in the generation queue. |
|
234 | + */ |
|
235 | + protected function _reset_current_properties() |
|
236 | + { |
|
237 | + $this->_verified = false; |
|
238 | + // make sure any _data value in the current message type is reset |
|
239 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
240 | + $this->_current_message_type->reset_data(); |
|
241 | + } |
|
242 | + $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
248 | + * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
249 | + * _generating_queue. |
|
250 | + * |
|
251 | + * @return bool Whether the message was successfully generated or not. |
|
252 | + * @throws EE_Error |
|
253 | + * @throws InvalidArgumentException |
|
254 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
255 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
256 | + */ |
|
257 | + protected function _generate() |
|
258 | + { |
|
259 | + // double check verification has run and that everything is ready to work with (saves us having to validate |
|
260 | + // everything again). |
|
261 | + if (! $this->_verified) { |
|
262 | + return false; // get out because we don't have a valid setup to work with. |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + try { |
|
267 | + $addressees = $this->_current_message_type->get_addressees( |
|
268 | + $this->_current_data_handler, |
|
269 | + $this->_generation_queue->get_message_repository()->current()->context() |
|
270 | + ); |
|
271 | + } catch (EE_Error $e) { |
|
272 | + $this->_error_msg[] = $e->getMessage(); |
|
273 | + return false; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + // if no addressees then get out because there is nothing to generation (possible bad data). |
|
278 | + if (! $this->_valid_addressees($addressees)) { |
|
279 | + do_action( |
|
280 | + 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
281 | + $this->_generation_queue->get_message_repository()->current(), |
|
282 | + $addressees, |
|
283 | + $this->_current_messenger, |
|
284 | + $this->_current_message_type, |
|
285 | + $this->_current_data_handler |
|
286 | + ); |
|
287 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
288 | + EEM_Message::status_debug_only |
|
289 | + ); |
|
290 | + $this->_error_msg[] = esc_html__( |
|
291 | + 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
292 | + 'event_espresso' |
|
293 | + ); |
|
294 | + return false; |
|
295 | + } |
|
296 | + |
|
297 | + $message_template_group = $this->_get_message_template_group(); |
|
298 | + |
|
299 | + // in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
300 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
301 | + $this->_error_msg[] = esc_html__( |
|
302 | + 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
303 | + 'event_espresso' |
|
304 | + ); |
|
305 | + return false; |
|
306 | + } |
|
307 | + |
|
308 | + // get formatted templates for using to parse and setup EE_Message objects. |
|
309 | + $templates = $this->_get_templates($message_template_group); |
|
310 | + |
|
311 | + |
|
312 | + // setup new EE_Message objects (and add to _ready_queue) |
|
313 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * Retrieves the message template group being used for generating messages. |
|
319 | + * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
320 | + * |
|
321 | + * @return EE_Message_Template_Group|null |
|
322 | + * @throws EE_Error |
|
323 | + * @throws InvalidArgumentException |
|
324 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
325 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
326 | + */ |
|
327 | + protected function _get_message_template_group() |
|
328 | + { |
|
329 | + // first see if there is a specific message template group requested (current message in the queue has a specific |
|
330 | + // GRP_ID |
|
331 | + $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
332 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
333 | + return $message_template_group; |
|
334 | + } |
|
335 | + |
|
336 | + // get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
337 | + // in the collection. |
|
338 | + $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
339 | + $message_template_group = $this->_template_collection->get_by_key( |
|
340 | + $this->_template_collection->getKey( |
|
341 | + $this->_current_messenger->name, |
|
342 | + $this->_current_message_type->name, |
|
343 | + $event_ids |
|
344 | + ) |
|
345 | + ); |
|
346 | + |
|
347 | + // if we have a message template group then no need to hit the database, just return it. |
|
348 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
349 | + return $message_template_group; |
|
350 | + } |
|
351 | + |
|
352 | + // okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
353 | + // there is no override set. |
|
354 | + $global_message_template_group = |
|
355 | + $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
356 | + |
|
357 | + if ($global_message_template_group instanceof EE_Message_Template_Group |
|
358 | + && $global_message_template_group->get('MTP_is_override') |
|
359 | + ) { |
|
360 | + return $global_message_template_group; |
|
361 | + } |
|
362 | + |
|
363 | + // if we're still here, that means there was no message template group for the events in the collection and |
|
364 | + // the global message template group for the messenger and message type is not set for override. So next step is |
|
365 | + // to see if there is a common shared custom message template group for this set of events. |
|
366 | + $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
367 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
368 | + return $message_template_group; |
|
369 | + } |
|
370 | + |
|
371 | + // STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
372 | + // So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
373 | + // and return it. |
|
374 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
375 | + $this->_template_collection->add( |
|
376 | + $global_message_template_group, |
|
377 | + $event_ids |
|
378 | + ); |
|
379 | + return $global_message_template_group; |
|
380 | + } |
|
381 | + |
|
382 | + // if we land here that means there's NO active message template group for this set. |
|
383 | + // TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
384 | + // template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
385 | + // this should likely bit hit rarely enough that it's not a significant issue. |
|
386 | + return null; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
392 | + * requested for that message. |
|
393 | + * |
|
394 | + * @return EE_Message_Template_Group|null |
|
395 | + * @throws EE_Error |
|
396 | + * @throws InvalidArgumentException |
|
397 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
398 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
399 | + */ |
|
400 | + protected function _specific_message_template_group_from_queue() |
|
401 | + { |
|
402 | + // is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
403 | + // so let's use that. |
|
404 | + $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
405 | + |
|
406 | + if ($GRP_ID) { |
|
407 | + // attempt to retrieve from repo first |
|
408 | + $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
409 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
410 | + return $message_template_group; // got it! |
|
411 | + } |
|
412 | + |
|
413 | + // nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
414 | + // is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
415 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
416 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
417 | + $this->_template_collection->add($message_template_group); |
|
418 | + return $message_template_group; |
|
419 | + } |
|
420 | + } |
|
421 | + return null; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * Returns whether the event ids passed in all share the same message template group for the current message type |
|
427 | + * and messenger. |
|
428 | + * |
|
429 | + * @param array $event_ids |
|
430 | + * @return bool true means they DO share the same message template group, false means they don't. |
|
431 | + * @throws EE_Error |
|
432 | + * @throws InvalidArgumentException |
|
433 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
434 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
435 | + */ |
|
436 | + protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
437 | + { |
|
438 | + foreach ($this->_current_data_handler->events as $event) { |
|
439 | + $event_ids[ $event['ID'] ] = $event['ID']; |
|
440 | + } |
|
441 | + $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
442 | + array( |
|
443 | + array( |
|
444 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
445 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
446 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
447 | + ), |
|
448 | + ), |
|
449 | + 'GRP_ID', |
|
450 | + true |
|
451 | + ); |
|
452 | + return $count_of_message_template_groups === 1; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
458 | + * there's a single shared message template group among all the events. Otherwise it returns null. |
|
459 | + * |
|
460 | + * @param array $event_ids |
|
461 | + * @return EE_Message_Template_Group|null |
|
462 | + * @throws EE_Error |
|
463 | + * @throws InvalidArgumentException |
|
464 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
465 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
466 | + */ |
|
467 | + protected function _get_shared_message_template_for_events(array $event_ids) |
|
468 | + { |
|
469 | + $message_template_group = null; |
|
470 | + if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
471 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
472 | + array( |
|
473 | + array( |
|
474 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
475 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
476 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
477 | + 'MTP_is_active' => true, |
|
478 | + ), |
|
479 | + 'group_by' => 'GRP_ID', |
|
480 | + ) |
|
481 | + ); |
|
482 | + // store this in the collection if its valid |
|
483 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
484 | + $this->_template_collection->add( |
|
485 | + $message_template_group, |
|
486 | + $event_ids |
|
487 | + ); |
|
488 | + } |
|
489 | + } |
|
490 | + return $message_template_group; |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * Retrieves the global message template group for the current messenger and message type. |
|
496 | + * |
|
497 | + * @return EE_Message_Template_Group|null |
|
498 | + * @throws EE_Error |
|
499 | + * @throws InvalidArgumentException |
|
500 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
501 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
502 | + */ |
|
503 | + protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
504 | + { |
|
505 | + // first check the collection (we use an array with 0 in it to represent global groups). |
|
506 | + $global_message_template_group = $this->_template_collection->get_by_key( |
|
507 | + $this->_template_collection->getKey( |
|
508 | + $this->_current_messenger->name, |
|
509 | + $this->_current_message_type->name, |
|
510 | + array(0) |
|
511 | + ) |
|
512 | + ); |
|
513 | + |
|
514 | + // if we don't have a group lets hit the db. |
|
515 | + if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
516 | + $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
517 | + array( |
|
518 | + array( |
|
519 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
520 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
521 | + 'MTP_is_active' => true, |
|
522 | + 'MTP_is_global' => true, |
|
523 | + ), |
|
524 | + ) |
|
525 | + ); |
|
526 | + // if we have a group, add it to the collection. |
|
527 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
528 | + $this->_template_collection->add( |
|
529 | + $global_message_template_group, |
|
530 | + array(0) |
|
531 | + ); |
|
532 | + } |
|
533 | + } |
|
534 | + return $global_message_template_group; |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * Returns an array of event ids for all the events within the current data handler. |
|
540 | + * |
|
541 | + * @return array |
|
542 | + */ |
|
543 | + protected function _get_event_ids_from_current_data_handler() |
|
544 | + { |
|
545 | + $event_ids = array(); |
|
546 | + foreach ($this->_current_data_handler->events as $event) { |
|
547 | + $event_ids[ $event['ID'] ] = $event['ID']; |
|
548 | + } |
|
549 | + return $event_ids; |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * Retrieves formatted array of template information for each context specific to the given |
|
555 | + * EE_Message_Template_Group |
|
556 | + * |
|
557 | + * @param EE_Message_Template_Group $message_template_group |
|
558 | + * @return array The returned array is in this structure: |
|
559 | + * array( |
|
560 | + * 'field_name' => array( |
|
561 | + * 'context' => 'content' |
|
562 | + * ) |
|
563 | + * ) |
|
564 | + * @throws EE_Error |
|
565 | + */ |
|
566 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
567 | + { |
|
568 | + $templates = array(); |
|
569 | + $context_templates = $message_template_group->context_templates(); |
|
570 | + foreach ($context_templates as $context => $template_fields) { |
|
571 | + foreach ($template_fields as $template_field => $template_obj) { |
|
572 | + if (! $template_obj instanceof EE_Message_Template) { |
|
573 | + continue; |
|
574 | + } |
|
575 | + $templates[ $template_field ][ $context ] = $template_obj->get('MTP_content'); |
|
576 | + } |
|
577 | + } |
|
578 | + return $templates; |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
584 | + * |
|
585 | + * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
586 | + * context. |
|
587 | + * @param array $templates formatted array of templates used for parsing data. |
|
588 | + * @param EE_Message_Template_Group $message_template_group |
|
589 | + * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
590 | + * method will attempt to generate ALL EE_Message objects and add to |
|
591 | + * the _ready_queue. Successfully generated messages get added to the |
|
592 | + * queue with EEM_Message::status_idle, unsuccessfully generated |
|
593 | + * messages will get added to the queue as EEM_Message::status_failed. |
|
594 | + * Very rarely should "false" be returned from this method. |
|
595 | + * @throws EE_Error |
|
596 | + */ |
|
597 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
598 | + { |
|
599 | + |
|
600 | + // if templates are empty then get out because we can't generate anything. |
|
601 | + if (! $templates) { |
|
602 | + $this->_error_msg[] = esc_html__( |
|
603 | + 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
604 | + 'event_espresso' |
|
605 | + ); |
|
606 | + return false; |
|
607 | + } |
|
608 | + |
|
609 | + // We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
610 | + // generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
611 | + $generated_count = 0; |
|
612 | + foreach ($addressees as $context => $recipients) { |
|
613 | + foreach ($recipients as $recipient) { |
|
614 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
615 | + if ($message instanceof EE_Message) { |
|
616 | + $this->_ready_queue->add( |
|
617 | + $message, |
|
618 | + array(), |
|
619 | + $this->_generation_queue->get_message_repository()->is_preview(), |
|
620 | + $this->_generation_queue->get_message_repository()->is_test_send() |
|
621 | + ); |
|
622 | + $generated_count++; |
|
623 | + } |
|
624 | + |
|
625 | + // if the current MSG being generated is for a test send then we'll only use ONE message in the |
|
626 | + // generation. |
|
627 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
628 | + break 2; |
|
629 | + } |
|
630 | + } |
|
631 | + } |
|
632 | + |
|
633 | + // if there are no generated messages then something else fatal went wrong. |
|
634 | + return $generated_count > 0; |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * @param string $context The context for the generated message. |
|
640 | + * @param EE_Messages_Addressee $recipient |
|
641 | + * @param array $templates formatted array of templates used for parsing data. |
|
642 | + * @param EE_Message_Template_Group $message_template_group |
|
643 | + * @return bool|EE_Message |
|
644 | + * @throws EE_Error |
|
645 | + */ |
|
646 | + protected function _setup_message_object( |
|
647 | + $context, |
|
648 | + EE_Messages_Addressee $recipient, |
|
649 | + $templates, |
|
650 | + EE_Message_Template_Group $message_template_group |
|
651 | + ) { |
|
652 | + // stuff we already know |
|
653 | + $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
654 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
655 | + ? $this->_current_data_handler->txn->ID() |
|
656 | + : $transaction_id; |
|
657 | + $message_fields = array( |
|
658 | + 'GRP_ID' => $message_template_group->ID(), |
|
659 | + 'TXN_ID' => $transaction_id, |
|
660 | + 'MSG_messenger' => $this->_current_messenger->name, |
|
661 | + 'MSG_message_type' => $this->_current_message_type->name, |
|
662 | + 'MSG_context' => $context, |
|
663 | + ); |
|
664 | + |
|
665 | + // recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
666 | + // the info from the att_obj found in the EE_Messages_Addressee object. |
|
667 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
668 | + $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
669 | + ? $recipient->att_obj->ID() |
|
670 | + : 0; |
|
671 | + $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
672 | + } else { |
|
673 | + $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
674 | + $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
675 | + } |
|
676 | + $message = EE_Message_Factory::create($message_fields); |
|
677 | + |
|
678 | + // grab valid shortcodes for shortcode parser |
|
679 | + $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
680 | + $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
681 | + |
|
682 | + // if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
|
683 | + if (( |
|
684 | + ( |
|
685 | + empty($templates['to'][ $context ]) |
|
686 | + && ! $this->_current_messenger->allow_empty_to_field() |
|
687 | + ) |
|
688 | + || ! $message_template_group->is_context_active($context) |
|
689 | + ) |
|
690 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
691 | + ) { |
|
692 | + // we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
693 | + // field. |
|
694 | + return false; |
|
695 | + } |
|
696 | + $error_msg = array(); |
|
697 | + foreach ($templates as $field => $field_context) { |
|
698 | + $error_msg = array(); |
|
699 | + // let's setup the valid shortcodes for the incoming context. |
|
700 | + $valid_shortcodes = $mt_shortcodes[ $context ]; |
|
701 | + // merge in valid shortcodes for the field. |
|
702 | + $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes; |
|
703 | + if (isset($templates[ $field ][ $context ])) { |
|
704 | + // prefix field. |
|
705 | + $column_name = 'MSG_' . $field; |
|
706 | + try { |
|
707 | + $content = $this->_shortcode_parser->parse_message_template( |
|
708 | + $templates[ $field ][ $context ], |
|
709 | + $recipient, |
|
710 | + $shortcodes, |
|
711 | + $this->_current_message_type, |
|
712 | + $this->_current_messenger, |
|
713 | + $message |
|
714 | + ); |
|
715 | + // the model field removes slashes when setting (usually necessary when the input is from the |
|
716 | + // request) but this value is from another model and has no slashes. So add them so it matchces |
|
717 | + // what the field expected (otherwise slashes will have been stripped from this an extra time) |
|
718 | + $message->set_field_or_extra_meta($column_name, addslashes($content)); |
|
719 | + } catch (EE_Error $e) { |
|
720 | + $error_msg[] = sprintf( |
|
721 | + esc_html__( |
|
722 | + 'There was a problem generating the content for the field %s: %s', |
|
723 | + 'event_espresso' |
|
724 | + ), |
|
725 | + $field, |
|
726 | + $e->getMessage() |
|
727 | + ); |
|
728 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
729 | + } |
|
730 | + } |
|
731 | + } |
|
732 | + |
|
733 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
734 | + $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
735 | + . "\n" |
|
736 | + . implode("\n", $error_msg); |
|
737 | + $message->set_error_message($error_msg); |
|
738 | + } else { |
|
739 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
740 | + } |
|
741 | + return $message; |
|
742 | + } |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
747 | + * error message if either is missing. |
|
748 | + * |
|
749 | + * @return bool true means there were no errors, false means there were errors. |
|
750 | + * @throws EE_Error |
|
751 | + * @throws ReflectionException |
|
752 | + */ |
|
753 | + protected function _verify() |
|
754 | + { |
|
755 | + // reset error message to an empty array. |
|
756 | + $this->_error_msg = array(); |
|
757 | + $valid = true; |
|
758 | + $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
759 | + $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
760 | + |
|
761 | + // set the verified flag so we know everything has been validated. |
|
762 | + $this->_verified = $valid; |
|
763 | + |
|
764 | + return $valid; |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
770 | + * EE_Messages_Addressee objects. |
|
771 | + * |
|
772 | + * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
773 | + * @return bool |
|
774 | + */ |
|
775 | + protected function _valid_addressees($addressees) |
|
776 | + { |
|
777 | + if (! $addressees || ! is_array($addressees)) { |
|
778 | + return false; |
|
779 | + } |
|
780 | + |
|
781 | + foreach ($addressees as $addressee_array) { |
|
782 | + foreach ($addressee_array as $addressee) { |
|
783 | + if (! $addressee instanceof EE_Messages_Addressee) { |
|
784 | + return false; |
|
785 | + } |
|
786 | + } |
|
787 | + } |
|
788 | + return true; |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + /** |
|
793 | + * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
794 | + * queue. This process sets error messages if something is wrong. |
|
795 | + * |
|
796 | + * @return bool true is if there are no errors. false is if there is. |
|
797 | + */ |
|
798 | + protected function _validate_messenger_and_message_type() |
|
799 | + { |
|
800 | + |
|
801 | + // first are there any existing error messages? If so then return. |
|
802 | + if ($this->_error_msg) { |
|
803 | + return false; |
|
804 | + } |
|
805 | + /** @type EE_Message $message */ |
|
806 | + $message = $this->_generation_queue->get_message_repository()->current(); |
|
807 | + try { |
|
808 | + $this->_current_messenger = $message->valid_messenger(true) |
|
809 | + ? $message->messenger_object() |
|
810 | + : null; |
|
811 | + } catch (Exception $e) { |
|
812 | + $this->_error_msg[] = $e->getMessage(); |
|
813 | + } |
|
814 | + try { |
|
815 | + $this->_current_message_type = $message->valid_message_type(true) |
|
816 | + ? $message->message_type_object() |
|
817 | + : null; |
|
818 | + } catch (Exception $e) { |
|
819 | + $this->_error_msg[] = $e->getMessage(); |
|
820 | + } |
|
821 | + |
|
822 | + /** |
|
823 | + * Check if there is any generation data, but only if this is not for a preview. |
|
824 | + */ |
|
825 | + if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
826 | + && ( |
|
827 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
828 | + && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
829 | + !== 'EE_Messages_Preview_incoming_data' |
|
830 | + ) |
|
831 | + ) { |
|
832 | + $this->_error_msg[] = esc_html__( |
|
833 | + 'There is no generation data for this message. Unable to generate.', |
|
834 | + 'event_espresso' |
|
835 | + ); |
|
836 | + } |
|
837 | + |
|
838 | + return empty($this->_error_msg); |
|
839 | + } |
|
840 | + |
|
841 | + |
|
842 | + /** |
|
843 | + * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
844 | + * data handler. |
|
845 | + * |
|
846 | + * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
847 | + * @throws EE_Error |
|
848 | + * @throws ReflectionException |
|
849 | + */ |
|
850 | + protected function _validate_and_setup_data() |
|
851 | + { |
|
852 | + |
|
853 | + // First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
854 | + // be used anyways. |
|
855 | + if ($this->_error_msg) { |
|
856 | + return false; |
|
857 | + } |
|
858 | + |
|
859 | + $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
860 | + |
|
861 | + /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
|
862 | + $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
863 | + ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
864 | + : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
865 | + |
|
866 | + // If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
867 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
868 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
869 | + } |
|
870 | + |
|
871 | + // First get the class name for the data handler (and also verifies it exists. |
|
872 | + if (! class_exists($data_handler_class_name)) { |
|
873 | + $this->_error_msg[] = sprintf( |
|
874 | + esc_html__( |
|
875 | + 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
876 | + 'event_espresso' |
|
877 | + ), |
|
878 | + 'EE_Messages_incoming_data', |
|
879 | + $data_handler_class_name |
|
880 | + ); |
|
881 | + return false; |
|
882 | + } |
|
883 | + |
|
884 | + // convert generation_data for data_handler_instantiation. |
|
885 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
886 | + |
|
887 | + // note, this may set error messages as well. |
|
888 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
889 | + |
|
890 | + return empty($this->_error_msg); |
|
891 | + } |
|
892 | + |
|
893 | + |
|
894 | + /** |
|
895 | + * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
896 | + * adds it to the _data repository. |
|
897 | + * |
|
898 | + * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
899 | + * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
900 | + * instantiated. |
|
901 | + * @return void . |
|
902 | + * @throws EE_Error |
|
903 | + * @throws ReflectionException |
|
904 | + */ |
|
905 | + protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
906 | + { |
|
907 | + // valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
908 | + // is already a ready data handler in the repository. |
|
909 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
910 | + $this->_data_handler_collection->get_key( |
|
911 | + $data_handler_class_name, |
|
912 | + $generating_data |
|
913 | + ) |
|
914 | + ); |
|
915 | + if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
916 | + // no saved data_handler in the repo so let's set one up and add it to the repo. |
|
917 | + try { |
|
918 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
919 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
920 | + } catch (EE_Error $e) { |
|
921 | + $this->_error_msg[] = $e->get_error(); |
|
922 | + } |
|
923 | + } |
|
924 | + } |
|
925 | + |
|
926 | + |
|
927 | + /** |
|
928 | + * The queued EE_Message for generation does not save the data used for generation as objects |
|
929 | + * because serialization of those objects could be problematic if the data is saved to the db. |
|
930 | + * So this method calls the static method on the associated data_handler for the given message_type |
|
931 | + * and that preps the data for later instantiation when generating. |
|
932 | + * |
|
933 | + * @param EE_Message_To_Generate $message_to_generate |
|
934 | + * @param bool $preview Indicate whether this is being used for a preview or not. |
|
935 | + * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
936 | + */ |
|
937 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
938 | + { |
|
939 | + /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
940 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
941 | + if (! $message_to_generate->valid()) { |
|
942 | + return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
943 | + } |
|
944 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
945 | + } |
|
946 | + |
|
947 | + |
|
948 | + /** |
|
949 | + * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
950 | + * |
|
951 | + * @param EE_Message_To_Generate $message_to_generate |
|
952 | + * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
953 | + * @throws InvalidArgumentException |
|
954 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
955 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
956 | + */ |
|
957 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
958 | + { |
|
959 | + // prep data |
|
960 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
961 | + |
|
962 | + $message = $message_to_generate->get_EE_Message(); |
|
963 | + |
|
964 | + // is there a GRP_ID in the request? |
|
965 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
966 | + $message->set_GRP_ID($GRP_ID); |
|
967 | + } |
|
968 | + |
|
969 | + if ($data === false) { |
|
970 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
971 | + $message->set_error_message( |
|
972 | + esc_html__( |
|
973 | + 'Unable to prepare data for persistence to the database.', |
|
974 | + 'event_espresso' |
|
975 | + ) |
|
976 | + ); |
|
977 | + } else { |
|
978 | + // make sure that the data handler is cached on the message as well |
|
979 | + $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
980 | + } |
|
981 | + |
|
982 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
983 | + } |
|
984 | 984 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | { |
259 | 259 | // double check verification has run and that everything is ready to work with (saves us having to validate |
260 | 260 | // everything again). |
261 | - if (! $this->_verified) { |
|
261 | + if ( ! $this->_verified) { |
|
262 | 262 | return false; // get out because we don't have a valid setup to work with. |
263 | 263 | } |
264 | 264 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | |
277 | 277 | // if no addressees then get out because there is nothing to generation (possible bad data). |
278 | - if (! $this->_valid_addressees($addressees)) { |
|
278 | + if ( ! $this->_valid_addressees($addressees)) { |
|
279 | 279 | do_action( |
280 | 280 | 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
281 | 281 | $this->_generation_queue->get_message_repository()->current(), |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | $message_template_group = $this->_get_message_template_group(); |
298 | 298 | |
299 | 299 | // in the unlikely event there is no EE_Message_Template_Group available, get out! |
300 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
300 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
301 | 301 | $this->_error_msg[] = esc_html__( |
302 | 302 | 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
303 | 303 | 'event_espresso' |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | // attempt to retrieve from repo first |
408 | 408 | $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
409 | 409 | if ($message_template_group instanceof EE_Message_Template_Group) { |
410 | - return $message_template_group; // got it! |
|
410 | + return $message_template_group; // got it! |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | // nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
437 | 437 | { |
438 | 438 | foreach ($this->_current_data_handler->events as $event) { |
439 | - $event_ids[ $event['ID'] ] = $event['ID']; |
|
439 | + $event_ids[$event['ID']] = $event['ID']; |
|
440 | 440 | } |
441 | 441 | $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
442 | 442 | array( |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | ); |
513 | 513 | |
514 | 514 | // if we don't have a group lets hit the db. |
515 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
515 | + if ( ! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
516 | 516 | $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
517 | 517 | array( |
518 | 518 | array( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | { |
545 | 545 | $event_ids = array(); |
546 | 546 | foreach ($this->_current_data_handler->events as $event) { |
547 | - $event_ids[ $event['ID'] ] = $event['ID']; |
|
547 | + $event_ids[$event['ID']] = $event['ID']; |
|
548 | 548 | } |
549 | 549 | return $event_ids; |
550 | 550 | } |
@@ -569,10 +569,10 @@ discard block |
||
569 | 569 | $context_templates = $message_template_group->context_templates(); |
570 | 570 | foreach ($context_templates as $context => $template_fields) { |
571 | 571 | foreach ($template_fields as $template_field => $template_obj) { |
572 | - if (! $template_obj instanceof EE_Message_Template) { |
|
572 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
573 | 573 | continue; |
574 | 574 | } |
575 | - $templates[ $template_field ][ $context ] = $template_obj->get('MTP_content'); |
|
575 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
576 | 576 | } |
577 | 577 | } |
578 | 578 | return $templates; |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | { |
599 | 599 | |
600 | 600 | // if templates are empty then get out because we can't generate anything. |
601 | - if (! $templates) { |
|
601 | + if ( ! $templates) { |
|
602 | 602 | $this->_error_msg[] = esc_html__( |
603 | 603 | 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
604 | 604 | 'event_espresso' |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | // if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
683 | 683 | if (( |
684 | 684 | ( |
685 | - empty($templates['to'][ $context ]) |
|
685 | + empty($templates['to'][$context]) |
|
686 | 686 | && ! $this->_current_messenger->allow_empty_to_field() |
687 | 687 | ) |
688 | 688 | || ! $message_template_group->is_context_active($context) |
@@ -697,15 +697,15 @@ discard block |
||
697 | 697 | foreach ($templates as $field => $field_context) { |
698 | 698 | $error_msg = array(); |
699 | 699 | // let's setup the valid shortcodes for the incoming context. |
700 | - $valid_shortcodes = $mt_shortcodes[ $context ]; |
|
700 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
701 | 701 | // merge in valid shortcodes for the field. |
702 | - $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes; |
|
703 | - if (isset($templates[ $field ][ $context ])) { |
|
702 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
703 | + if (isset($templates[$field][$context])) { |
|
704 | 704 | // prefix field. |
705 | - $column_name = 'MSG_' . $field; |
|
705 | + $column_name = 'MSG_'.$field; |
|
706 | 706 | try { |
707 | 707 | $content = $this->_shortcode_parser->parse_message_template( |
708 | - $templates[ $field ][ $context ], |
|
708 | + $templates[$field][$context], |
|
709 | 709 | $recipient, |
710 | 710 | $shortcodes, |
711 | 711 | $this->_current_message_type, |
@@ -774,13 +774,13 @@ discard block |
||
774 | 774 | */ |
775 | 775 | protected function _valid_addressees($addressees) |
776 | 776 | { |
777 | - if (! $addressees || ! is_array($addressees)) { |
|
777 | + if ( ! $addressees || ! is_array($addressees)) { |
|
778 | 778 | return false; |
779 | 779 | } |
780 | 780 | |
781 | 781 | foreach ($addressees as $addressee_array) { |
782 | 782 | foreach ($addressee_array as $addressee) { |
783 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
783 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
784 | 784 | return false; |
785 | 785 | } |
786 | 786 | } |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | /** |
823 | 823 | * Check if there is any generation data, but only if this is not for a preview. |
824 | 824 | */ |
825 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
825 | + if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
826 | 826 | && ( |
827 | 827 | ! $this->_generation_queue->get_message_repository()->is_preview() |
828 | 828 | && $this->_generation_queue->get_message_repository()->get_data_handler() |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
862 | 862 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
863 | 863 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
864 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
864 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
865 | 865 | |
866 | 866 | // If this EE_Message is for a preview, then let's switch out to the preview data handler. |
867 | 867 | if ($this->_generation_queue->get_message_repository()->is_preview()) { |
@@ -869,7 +869,7 @@ discard block |
||
869 | 869 | } |
870 | 870 | |
871 | 871 | // First get the class name for the data handler (and also verifies it exists. |
872 | - if (! class_exists($data_handler_class_name)) { |
|
872 | + if ( ! class_exists($data_handler_class_name)) { |
|
873 | 873 | $this->_error_msg[] = sprintf( |
874 | 874 | esc_html__( |
875 | 875 | 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | $generating_data |
913 | 913 | ) |
914 | 914 | ); |
915 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
915 | + if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
916 | 916 | // no saved data_handler in the repo so let's set one up and add it to the repo. |
917 | 917 | try { |
918 | 918 | $this->_current_data_handler = new $data_handler_class_name($generating_data); |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | { |
939 | 939 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
940 | 940 | $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
941 | - if (! $message_to_generate->valid()) { |
|
941 | + if ( ! $message_to_generate->valid()) { |
|
942 | 942 | return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
943 | 943 | } |
944 | 944 | return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
@@ -10,22 +10,22 @@ discard block |
||
10 | 10 | * @var int $message_template_group_id The ID for the message template group this context belongs to. |
11 | 11 | */ |
12 | 12 | $active_message = sprintf( |
13 | - esc_html__( |
|
14 | - 'The template for %1$s is currently %2$sactive%3$s.', |
|
15 | - 'event_espresso' |
|
16 | - ), |
|
17 | - $context_label, |
|
18 | - '<strong>', |
|
19 | - '</strong>' |
|
13 | + esc_html__( |
|
14 | + 'The template for %1$s is currently %2$sactive%3$s.', |
|
15 | + 'event_espresso' |
|
16 | + ), |
|
17 | + $context_label, |
|
18 | + '<strong>', |
|
19 | + '</strong>' |
|
20 | 20 | ); |
21 | 21 | $inactive_message = sprintf( |
22 | - esc_html__( |
|
23 | - 'The template for %1$s is currently %2$sinactive%3$s.', |
|
24 | - 'event_espresso' |
|
25 | - ), |
|
26 | - $context_label, |
|
27 | - '<strong>', |
|
28 | - '</strong>' |
|
22 | + esc_html__( |
|
23 | + 'The template for %1$s is currently %2$sinactive%3$s.', |
|
24 | + 'event_espresso' |
|
25 | + ), |
|
26 | + $context_label, |
|
27 | + '<strong>', |
|
28 | + '</strong>' |
|
29 | 29 | ); |
30 | 30 | ?> |
31 | 31 | <div class="context-active-control-container"> |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span> |
35 | 35 | <span class="ee-on-off-toggle-label"> |
36 | 36 | <?php |
37 | - echo $is_active ? $active_message : $inactive_message; |
|
38 | - ?> |
|
37 | + echo $is_active ? $active_message : $inactive_message; |
|
38 | + ?> |
|
39 | 39 | </span> |
40 | 40 | <div class="hidden js-data"> |
41 | 41 | <span class="ee-active-message"><?php echo $active_message; ?></span> |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | </div> |
44 | 44 | <div class="switch"> |
45 | 45 | <?php |
46 | - $checked = $is_active ? ' checked="checked"' : ''; |
|
47 | - ?> |
|
46 | + $checked = $is_active ? ' checked="checked"' : ''; |
|
47 | + ?> |
|
48 | 48 | <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>"> |
49 | 49 | <label for="ee-on-off-toggle-<?php echo $context; ?>"></label> |
50 | 50 | </div> |
@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | $event_label = 'Testing Context Deactivation'; |
9 | 9 | |
10 | 10 | $I->wantTo( |
11 | - 'Test that the context activation toggle for turning on or off specific contexts for message sending works as' |
|
12 | - . ' expected' |
|
11 | + 'Test that the context activation toggle for turning on or off specific contexts for message sending works as' |
|
12 | + . ' expected' |
|
13 | 13 | ); |
14 | 14 | |
15 | 15 | $I->loginAsAdmin(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $I->see('The template for Primary Registrant Recipient is currently inactive.'); |
35 | 35 | |
36 | 36 | $I->amGoingTo( |
37 | - 'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.' |
|
37 | + 'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.' |
|
38 | 38 | ); |
39 | 39 | $I->amOnDefaultEventsListTablePage(); |
40 | 40 | $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR); |
45 | 45 | $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR); |
46 | 46 | $test_registration_details = array( |
47 | - 'fname' => 'ContextTestGuy', |
|
48 | - 'lname' => 'ContextTestDude', |
|
49 | - 'email' => '[email protected]', |
|
47 | + 'fname' => 'ContextTestGuy', |
|
48 | + 'lname' => 'ContextTestDude', |
|
49 | + 'email' => '[email protected]', |
|
50 | 50 | ); |
51 | 51 | $I->logOut(); |
52 | 52 | $I->amOnUrl($event_link); |
@@ -63,48 +63,48 @@ discard block |
||
63 | 63 | $I->amOnMessagesActivityListTablePage(); |
64 | 64 | //verify registrant context |
65 | 65 | $I->see( |
66 | - $test_registration_details['email'], |
|
67 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
68 | - 'to', |
|
69 | - 'Registration Approved', |
|
70 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
71 | - '', |
|
72 | - 'Registrant' |
|
73 | - ) |
|
66 | + $test_registration_details['email'], |
|
67 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
68 | + 'to', |
|
69 | + 'Registration Approved', |
|
70 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
71 | + '', |
|
72 | + 'Registrant' |
|
73 | + ) |
|
74 | 74 | ); |
75 | 75 | $I->deleteMessageInMessagesListTableFor( |
76 | - 'Registration Approved', |
|
77 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
78 | - 'Email', |
|
79 | - 'Registrant' |
|
76 | + 'Registration Approved', |
|
77 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
78 | + 'Email', |
|
79 | + 'Registrant' |
|
80 | 80 | ); |
81 | 81 | //verify admin context |
82 | 82 | $I->see( |
83 | - '[email protected]', |
|
84 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
85 | - 'to', |
|
86 | - 'Registration Approved', |
|
87 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
88 | - ) |
|
83 | + '[email protected]', |
|
84 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
85 | + 'to', |
|
86 | + 'Registration Approved', |
|
87 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
88 | + ) |
|
89 | 89 | ); |
90 | 90 | $I->deleteMessageInMessagesListTableFor( |
91 | - 'Registration Approved' |
|
91 | + 'Registration Approved' |
|
92 | 92 | ); |
93 | 93 | //verify primary registrant context is NOT present. |
94 | 94 | $I->dontSee( |
95 | - $test_registration_details['email'], |
|
96 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
97 | - 'to', |
|
98 | - 'Registration Approved', |
|
99 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
100 | - '', |
|
101 | - 'Primary Registrant' |
|
102 | - ) |
|
95 | + $test_registration_details['email'], |
|
96 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
97 | + 'to', |
|
98 | + 'Registration Approved', |
|
99 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
100 | + '', |
|
101 | + 'Primary Registrant' |
|
102 | + ) |
|
103 | 103 | ); |
104 | 104 | |
105 | 105 | $I->amGoingTo( |
106 | - 'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"' |
|
107 | - . ' field to an empty string to verify the message does not send for that context.' |
|
106 | + 'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"' |
|
107 | + . ' field to an empty string to verify the message does not send for that context.' |
|
108 | 108 | ); |
109 | 109 | $I->amOnDefaultMessageTemplateListTablePage(); |
110 | 110 | $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee'); |
@@ -128,41 +128,41 @@ discard block |
||
128 | 128 | $I->amOnMessagesActivityListTablePage(); |
129 | 129 | //verify registrant context |
130 | 130 | $I->see( |
131 | - $test_registration_details['email'], |
|
132 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
133 | - 'to', |
|
134 | - 'Registration Approved', |
|
135 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
136 | - '', |
|
137 | - 'Registrant' |
|
138 | - ) |
|
131 | + $test_registration_details['email'], |
|
132 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
133 | + 'to', |
|
134 | + 'Registration Approved', |
|
135 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
136 | + '', |
|
137 | + 'Registrant' |
|
138 | + ) |
|
139 | 139 | ); |
140 | 140 | $I->deleteMessageInMessagesListTableFor( |
141 | - 'Registration Approved', |
|
142 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
143 | - 'Email', |
|
144 | - 'Registrant' |
|
141 | + 'Registration Approved', |
|
142 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
143 | + 'Email', |
|
144 | + 'Registrant' |
|
145 | 145 | ); |
146 | 146 | //verify admin context |
147 | 147 | $I->see( |
148 | - '[email protected]', |
|
149 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
150 | - 'to', |
|
151 | - 'Registration Approved', |
|
152 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
153 | - ) |
|
148 | + '[email protected]', |
|
149 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
150 | + 'to', |
|
151 | + 'Registration Approved', |
|
152 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
153 | + ) |
|
154 | 154 | ); |
155 | 155 | $I->deleteMessageInMessagesListTableFor( |
156 | - 'Registration Approved' |
|
156 | + 'Registration Approved' |
|
157 | 157 | ); |
158 | 158 | //verify primary registrant context is NOT present. |
159 | 159 | $I->dontSee( |
160 | - $test_registration_details['email'], |
|
161 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
162 | - 'to', |
|
163 | - 'Registration Approved', |
|
164 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
165 | - '', |
|
166 | - 'Primary Registrant' |
|
167 | - ) |
|
160 | + $test_registration_details['email'], |
|
161 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
162 | + 'to', |
|
163 | + 'Registration Approved', |
|
164 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
165 | + '', |
|
166 | + 'Primary Registrant' |
|
167 | + ) |
|
168 | 168 | ); |
169 | 169 | \ No newline at end of file |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | * @ link http://www.eventespresso.com |
10 | 10 | * @ version 4+ |
11 | 11 | */ |
12 | -define( 'EE_THEME_FUNCTIONS_LOADED', TRUE ); |
|
12 | +define('EE_THEME_FUNCTIONS_LOADED', TRUE); |
|
13 | 13 | |
14 | -if ( ! function_exists( 'espresso_pagination' ) ) { |
|
14 | +if ( ! function_exists('espresso_pagination')) { |
|
15 | 15 | /** |
16 | 16 | * espresso_pagination |
17 | 17 | * |
@@ -23,21 +23,21 @@ discard block |
||
23 | 23 | $big = 999999999; // need an unlikely integer |
24 | 24 | $pagination = paginate_links( |
25 | 25 | array( |
26 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
26 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
27 | 27 | 'format' => '?paged=%#%', |
28 | - 'current' => max( 1, get_query_var( 'paged' ) ), |
|
28 | + 'current' => max(1, get_query_var('paged')), |
|
29 | 29 | 'total' => $wp_query->max_num_pages, |
30 | 30 | 'show_all' => true, |
31 | 31 | 'end_size' => 10, |
32 | 32 | 'mid_size' => 6, |
33 | 33 | 'prev_next' => true, |
34 | - 'prev_text' => __( '‹ PREV', 'event_espresso' ), |
|
35 | - 'next_text' => __( 'NEXT ›', 'event_espresso' ), |
|
34 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
35 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
36 | 36 | 'type' => 'plain', |
37 | 37 | 'add_args' => false, |
38 | 38 | 'add_fragment' => '' |
39 | 39 | ) |
40 | 40 | ); |
41 | - echo ! empty( $pagination ) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
41 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -3,79 +3,79 @@ |
||
3 | 3 | </p> |
4 | 4 | <p> |
5 | 5 | <?php esc_html_e( |
6 | - 'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab. When you click one of those tabs it will display that messenger.', |
|
7 | - 'event_espresso' |
|
8 | - ); ?> |
|
6 | + 'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab. When you click one of those tabs it will display that messenger.', |
|
7 | + 'event_espresso' |
|
8 | + ); ?> |
|
9 | 9 | </p> |
10 | 10 | <p> |
11 | 11 | <?php esc_html_e( |
12 | - 'There are two ways to determine whether a messenger is active or not. The first way is via the messenger tab itself.', |
|
13 | - 'event_espresso' |
|
14 | - ); ?> |
|
12 | + 'There are two ways to determine whether a messenger is active or not. The first way is via the messenger tab itself.', |
|
13 | + 'event_espresso' |
|
14 | + ); ?> |
|
15 | 15 | </p> |
16 | 16 | <p> |
17 | 17 | <?php printf( |
18 | - esc_html__( |
|
19 | - 'The green colored gear %s indicates that this messenger is currently active.', |
|
20 | - 'event_espresso' |
|
21 | - ), |
|
22 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | - . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
24 | - ); |
|
25 | - printf( |
|
26 | - esc_html__( |
|
27 | - ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
|
28 | - 'event_espresso' |
|
29 | - ), |
|
30 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
32 | - ); ?> |
|
18 | + esc_html__( |
|
19 | + 'The green colored gear %s indicates that this messenger is currently active.', |
|
20 | + 'event_espresso' |
|
21 | + ), |
|
22 | + '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | + . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
24 | + ); |
|
25 | + printf( |
|
26 | + esc_html__( |
|
27 | + ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
|
28 | + 'event_espresso' |
|
29 | + ), |
|
30 | + '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
32 | + ); ?> |
|
33 | 33 | </p> |
34 | 34 | <p> |
35 | 35 | <?php esc_html_e( |
36 | - 'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:', |
|
37 | - 'event_espresso' |
|
38 | - ); ?> |
|
36 | + 'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:', |
|
37 | + 'event_espresso' |
|
38 | + ); ?> |
|
39 | 39 | </p> |
40 | 40 | <p> |
41 | 41 | <?php printf( |
42 | - esc_html__( |
|
43 | - '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '<div class="switch">' |
|
47 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>' |
|
48 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
49 | - . '</div>', |
|
50 | - '<div class="switch">' |
|
51 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>' |
|
52 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
53 | - . '</div>' |
|
54 | - ); ?> |
|
42 | + esc_html__( |
|
43 | + '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '<div class="switch">' |
|
47 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>' |
|
48 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
49 | + . '</div>', |
|
50 | + '<div class="switch">' |
|
51 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>' |
|
52 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
53 | + . '</div>' |
|
54 | + ); ?> |
|
55 | 55 | </p> |
56 | 56 | <p> |
57 | 57 | <?php |
58 | - esc_html_e( |
|
59 | - 'The on/off toggle is also what you use to activate or deactivate a messenger.', |
|
60 | - 'event_espresso' |
|
61 | - ); ?> |
|
58 | + esc_html_e( |
|
59 | + 'The on/off toggle is also what you use to activate or deactivate a messenger.', |
|
60 | + 'event_espresso' |
|
61 | + ); ?> |
|
62 | 62 | </p> |
63 | 63 | <p> |
64 | 64 | <?php esc_html_e( |
65 | - 'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger. Then, if there are any default settings for either the messenger or message types those settings are saved. Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated). Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.', |
|
66 | - 'event_espresso' |
|
67 | - ); ?> |
|
65 | + 'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger. Then, if there are any default settings for either the messenger or message types those settings are saved. Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated). Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.', |
|
66 | + 'event_espresso' |
|
67 | + ); ?> |
|
68 | 68 | </p> |
69 | 69 | <p> |
70 | 70 | <?php esc_html_e( |
71 | - 'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate. If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.', |
|
72 | - 'event_espresso' |
|
73 | - ); ?> |
|
71 | + 'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate. If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.', |
|
72 | + 'event_espresso' |
|
73 | + ); ?> |
|
74 | 74 | </p> |
75 | 75 | <p> |
76 | 76 | <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br/> |
77 | 77 | <?php esc_html_e( |
78 | - 'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation. Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.', |
|
79 | - 'event_espresso' |
|
80 | - ); ?> |
|
78 | + 'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation. Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.', |
|
79 | + 'event_espresso' |
|
80 | + ); ?> |
|
81 | 81 | </p> |
@@ -19,16 +19,16 @@ |
||
19 | 19 | 'The green colored gear %s indicates that this messenger is currently active.', |
20 | 20 | 'event_espresso' |
21 | 21 | ), |
22 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | - . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
22 | + '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'"' |
|
23 | + . ' alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />' |
|
24 | 24 | ); |
25 | 25 | printf( |
26 | 26 | esc_html__( |
27 | 27 | ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
28 | 28 | 'event_espresso' |
29 | 29 | ), |
30 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
30 | + '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png' |
|
31 | + . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />' |
|
32 | 32 | ); ?> |
33 | 33 | </p> |
34 | 34 | <p> |
@@ -176,7 +176,7 @@ |
||
176 | 176 | /** |
177 | 177 | * This retrieves the EE_Venue from the available data object. |
178 | 178 | * |
179 | - * @return EE_Venue|null |
|
179 | + * @return EE_Base_Class|null |
|
180 | 180 | * @throws EE_Error |
181 | 181 | * @throws EntityNotFoundException |
182 | 182 | */ |
@@ -17,315 +17,315 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * Will hold the EE_Event if available |
|
22 | - * |
|
23 | - * @var EE_Event |
|
24 | - */ |
|
25 | - protected $_event; |
|
26 | - |
|
27 | - /** |
|
28 | - * Will hold the EE_Venue if available |
|
29 | - * |
|
30 | - * @var EE_Venue |
|
31 | - */ |
|
32 | - protected $_venue; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Initialize properties |
|
37 | - */ |
|
38 | - protected function _init_props() |
|
39 | - { |
|
40 | - $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
41 | - $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
42 | - $this->_shortcodes = array( |
|
43 | - '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
44 | - '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
45 | - '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
46 | - '[VENUE_DETAILS_URL]' => sprintf( |
|
47 | - esc_html__( |
|
48 | - 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
49 | - 'event_espresso' |
|
50 | - ), |
|
51 | - '[VENUE_URL]' |
|
52 | - ), |
|
53 | - '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
54 | - '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
55 | - '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
56 | - '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
57 | - '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
58 | - '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
59 | - '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
60 | - '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
61 | - 'This just outputs the venue address in a semantic address format.', |
|
62 | - 'event_espresso' |
|
63 | - ), |
|
64 | - '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
65 | - '[VENUE_META_*]' => esc_html__( |
|
66 | - 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
67 | - 'event_espresso' |
|
68 | - ), |
|
69 | - '[GOOGLE_MAP_URL]' => esc_html__( |
|
70 | - 'URL for the google map associated with the venue.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
74 | - '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Parse incoming shortcode |
|
81 | - * |
|
82 | - * @param string $shortcode |
|
83 | - * @return string |
|
84 | - * @throws EE_Error |
|
85 | - * @throws EntityNotFoundException |
|
86 | - */ |
|
87 | - protected function _parser($shortcode) |
|
88 | - { |
|
89 | - $this->_venue = $this->_get_venue(); |
|
90 | - // If there is no venue object by now then get out. |
|
91 | - if (! $this->_venue instanceof EE_Venue) { |
|
92 | - return ''; |
|
93 | - } |
|
94 | - |
|
95 | - switch ($shortcode) { |
|
96 | - case '[VENUE_TITLE]': |
|
97 | - return $this->_venue('title'); |
|
98 | - break; |
|
99 | - |
|
100 | - case '[VENUE_DESCRIPTION]': |
|
101 | - return $this->_venue('description'); |
|
102 | - break; |
|
103 | - |
|
104 | - case '[VENUE_URL]': |
|
105 | - return $this->_venue('url'); |
|
106 | - break; |
|
107 | - |
|
108 | - case '[VENUE_IMAGE]': |
|
109 | - return $this->_venue('image'); |
|
110 | - break; |
|
111 | - |
|
112 | - case '[VENUE_PHONE]': |
|
113 | - return $this->_venue('phone'); |
|
114 | - break; |
|
115 | - |
|
116 | - case '[VENUE_ADDRESS]': |
|
117 | - return $this->_venue('address'); |
|
118 | - break; |
|
119 | - |
|
120 | - case '[VENUE_ADDRESS2]': |
|
121 | - return $this->_venue('address2'); |
|
122 | - break; |
|
123 | - |
|
124 | - case '[VENUE_CITY]': |
|
125 | - return $this->_venue('city'); |
|
126 | - break; |
|
127 | - |
|
128 | - case '[VENUE_COUNTRY]': |
|
129 | - return $this->_venue('country'); |
|
130 | - break; |
|
131 | - |
|
132 | - case '[VENUE_STATE]': |
|
133 | - return $this->_venue('state'); |
|
134 | - break; |
|
135 | - |
|
136 | - case '[VENUE_ZIP]': |
|
137 | - return $this->_venue('zip'); |
|
138 | - break; |
|
139 | - |
|
140 | - case '[VENUE_FORMATTED_ADDRESS]': |
|
141 | - return $this->_venue('formatted_address'); |
|
142 | - break; |
|
143 | - |
|
144 | - case '[GOOGLE_MAP_URL]': |
|
145 | - return $this->_venue('gmap_url'); |
|
146 | - break; |
|
147 | - |
|
148 | - case '[GOOGLE_MAP_LINK]': |
|
149 | - return $this->_venue('gmap_link'); |
|
150 | - break; |
|
151 | - |
|
152 | - case '[GOOGLE_MAP_IMAGE]': |
|
153 | - return $this->_venue('gmap_link_img'); |
|
154 | - break; |
|
155 | - |
|
156 | - case '[VENUE_DETAILS_URL]': |
|
157 | - return $this->_venue('permalink'); |
|
158 | - break; |
|
159 | - } |
|
160 | - |
|
161 | - if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
162 | - $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
163 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
164 | - |
|
165 | - // pull the meta value from the venue post |
|
166 | - $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
167 | - |
|
168 | - return ! empty($venue_meta) ? $venue_meta : ''; |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * This retrieves the EE_Venue from the available data object. |
|
174 | - * |
|
175 | - * @return EE_Venue|null |
|
176 | - * @throws EE_Error |
|
177 | - * @throws EntityNotFoundException |
|
178 | - */ |
|
179 | - private function _get_venue() |
|
180 | - { |
|
181 | - |
|
182 | - // we need the EE_Event object to get the venue. |
|
183 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
184 | - |
|
185 | - // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
186 | - // reg_obj instead. |
|
187 | - if (! $this->_event instanceof EE_Event) { |
|
188 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
189 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
190 | - |
|
191 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
192 | - ? $aee->reg_obj->event() |
|
193 | - : null; |
|
194 | - |
|
195 | - // if still empty do we have a ticket data item? |
|
196 | - $this->_event = ! $this->_event instanceof EE_Event |
|
197 | - && $this->_data instanceof EE_Ticket |
|
198 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
199 | - ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
200 | - : $this->_event; |
|
201 | - |
|
202 | - // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
203 | - // and use that. |
|
204 | - $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
205 | - ? reset($aee->events) |
|
206 | - : $this->_event; |
|
207 | - } |
|
208 | - |
|
209 | - // If we have an event object use it to pull the venue. |
|
210 | - if ($this->_event instanceof EE_Event) { |
|
211 | - return $this->_event->get_first_related('Venue'); |
|
212 | - } |
|
213 | - |
|
214 | - return null; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * This retrieves the specified venue information |
|
219 | - * |
|
220 | - * @param string $field What Venue field to retrieve |
|
221 | - * @return string What was retrieved! |
|
222 | - * @throws EE_Error |
|
223 | - * @throws EntityNotFoundException |
|
224 | - */ |
|
225 | - private function _venue($field) |
|
226 | - { |
|
227 | - |
|
228 | - if (! $this->_venue instanceof EE_Venue) { |
|
229 | - return ''; |
|
230 | - } //no venue so get out. |
|
231 | - |
|
232 | - switch ($field) { |
|
233 | - case 'title': |
|
234 | - return $this->_venue->get('VNU_name'); |
|
235 | - break; |
|
236 | - |
|
237 | - case 'description': |
|
238 | - return $this->_venue->get('VNU_desc'); |
|
239 | - break; |
|
240 | - |
|
241 | - case 'url': |
|
242 | - $url = $this->_venue->get('VNU_url'); |
|
243 | - return empty($url) ? $this->_venue->get_permalink() : $url; |
|
244 | - break; |
|
245 | - |
|
246 | - case 'permalink': |
|
247 | - return $this->_venue->get_permalink(); |
|
248 | - break; |
|
249 | - |
|
250 | - case 'image': |
|
251 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | - . '" alt="' . sprintf( |
|
253 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
254 | - $this->_venue->get('VNU_name') |
|
255 | - ) . '" />'; |
|
256 | - break; |
|
257 | - |
|
258 | - case 'phone': |
|
259 | - return $this->_venue->get('VNU_phone'); |
|
260 | - break; |
|
261 | - |
|
262 | - case 'address': |
|
263 | - return $this->_venue->get('VNU_address'); |
|
264 | - break; |
|
265 | - |
|
266 | - case 'address2': |
|
267 | - return $this->_venue->get('VNU_address2'); |
|
268 | - break; |
|
269 | - |
|
270 | - case 'city': |
|
271 | - return $this->_venue->get('VNU_city'); |
|
272 | - break; |
|
273 | - |
|
274 | - case 'state': |
|
275 | - $state = $this->_venue->state_obj(); |
|
276 | - return is_object($state) ? $state->get('STA_name') : ''; |
|
277 | - break; |
|
278 | - |
|
279 | - case 'country': |
|
280 | - $country = $this->_venue->country_obj(); |
|
281 | - return is_object($country) ? $country->get('CNT_name') : ''; |
|
282 | - break; |
|
283 | - |
|
284 | - case 'zip': |
|
285 | - return $this->_venue->get('VNU_zip'); |
|
286 | - break; |
|
287 | - |
|
288 | - case 'formatted_address': |
|
289 | - return EEH_Address::format($this->_venue); |
|
290 | - break; |
|
291 | - |
|
292 | - case 'gmap_link': |
|
293 | - case 'gmap_url': |
|
294 | - case 'gmap_link_img': |
|
295 | - $atts = $this->get_map_attributes($this->_venue, $field); |
|
296 | - return EEH_Maps::google_map_link($atts); |
|
297 | - break; |
|
298 | - } |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Generates the attributes for retrieving a google_map artifact. |
|
305 | - * |
|
306 | - * @param EE_Venue $venue |
|
307 | - * @param string $field |
|
308 | - * @return array |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
312 | - { |
|
313 | - $state = $venue->state_obj(); |
|
314 | - $country = $venue->country_obj(); |
|
315 | - $atts = array( |
|
316 | - 'id' => $venue->ID(), |
|
317 | - 'address' => $venue->get('VNU_address'), |
|
318 | - 'city' => $venue->get('VNU_city'), |
|
319 | - 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
320 | - 'zip' => $venue->get('VNU_zip'), |
|
321 | - 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
322 | - 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
323 | - 'map_w' => 200, |
|
324 | - 'map_h' => 200, |
|
325 | - ); |
|
326 | - if ($field === 'gmap_url') { |
|
327 | - $atts['type'] = 'url_only'; |
|
328 | - } |
|
329 | - return $atts; |
|
330 | - } |
|
20 | + /** |
|
21 | + * Will hold the EE_Event if available |
|
22 | + * |
|
23 | + * @var EE_Event |
|
24 | + */ |
|
25 | + protected $_event; |
|
26 | + |
|
27 | + /** |
|
28 | + * Will hold the EE_Venue if available |
|
29 | + * |
|
30 | + * @var EE_Venue |
|
31 | + */ |
|
32 | + protected $_venue; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Initialize properties |
|
37 | + */ |
|
38 | + protected function _init_props() |
|
39 | + { |
|
40 | + $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
41 | + $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
42 | + $this->_shortcodes = array( |
|
43 | + '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
44 | + '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
45 | + '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
46 | + '[VENUE_DETAILS_URL]' => sprintf( |
|
47 | + esc_html__( |
|
48 | + 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
49 | + 'event_espresso' |
|
50 | + ), |
|
51 | + '[VENUE_URL]' |
|
52 | + ), |
|
53 | + '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
54 | + '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
55 | + '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
56 | + '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
57 | + '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
58 | + '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
59 | + '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
60 | + '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
61 | + 'This just outputs the venue address in a semantic address format.', |
|
62 | + 'event_espresso' |
|
63 | + ), |
|
64 | + '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
65 | + '[VENUE_META_*]' => esc_html__( |
|
66 | + 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
67 | + 'event_espresso' |
|
68 | + ), |
|
69 | + '[GOOGLE_MAP_URL]' => esc_html__( |
|
70 | + 'URL for the google map associated with the venue.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
74 | + '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Parse incoming shortcode |
|
81 | + * |
|
82 | + * @param string $shortcode |
|
83 | + * @return string |
|
84 | + * @throws EE_Error |
|
85 | + * @throws EntityNotFoundException |
|
86 | + */ |
|
87 | + protected function _parser($shortcode) |
|
88 | + { |
|
89 | + $this->_venue = $this->_get_venue(); |
|
90 | + // If there is no venue object by now then get out. |
|
91 | + if (! $this->_venue instanceof EE_Venue) { |
|
92 | + return ''; |
|
93 | + } |
|
94 | + |
|
95 | + switch ($shortcode) { |
|
96 | + case '[VENUE_TITLE]': |
|
97 | + return $this->_venue('title'); |
|
98 | + break; |
|
99 | + |
|
100 | + case '[VENUE_DESCRIPTION]': |
|
101 | + return $this->_venue('description'); |
|
102 | + break; |
|
103 | + |
|
104 | + case '[VENUE_URL]': |
|
105 | + return $this->_venue('url'); |
|
106 | + break; |
|
107 | + |
|
108 | + case '[VENUE_IMAGE]': |
|
109 | + return $this->_venue('image'); |
|
110 | + break; |
|
111 | + |
|
112 | + case '[VENUE_PHONE]': |
|
113 | + return $this->_venue('phone'); |
|
114 | + break; |
|
115 | + |
|
116 | + case '[VENUE_ADDRESS]': |
|
117 | + return $this->_venue('address'); |
|
118 | + break; |
|
119 | + |
|
120 | + case '[VENUE_ADDRESS2]': |
|
121 | + return $this->_venue('address2'); |
|
122 | + break; |
|
123 | + |
|
124 | + case '[VENUE_CITY]': |
|
125 | + return $this->_venue('city'); |
|
126 | + break; |
|
127 | + |
|
128 | + case '[VENUE_COUNTRY]': |
|
129 | + return $this->_venue('country'); |
|
130 | + break; |
|
131 | + |
|
132 | + case '[VENUE_STATE]': |
|
133 | + return $this->_venue('state'); |
|
134 | + break; |
|
135 | + |
|
136 | + case '[VENUE_ZIP]': |
|
137 | + return $this->_venue('zip'); |
|
138 | + break; |
|
139 | + |
|
140 | + case '[VENUE_FORMATTED_ADDRESS]': |
|
141 | + return $this->_venue('formatted_address'); |
|
142 | + break; |
|
143 | + |
|
144 | + case '[GOOGLE_MAP_URL]': |
|
145 | + return $this->_venue('gmap_url'); |
|
146 | + break; |
|
147 | + |
|
148 | + case '[GOOGLE_MAP_LINK]': |
|
149 | + return $this->_venue('gmap_link'); |
|
150 | + break; |
|
151 | + |
|
152 | + case '[GOOGLE_MAP_IMAGE]': |
|
153 | + return $this->_venue('gmap_link_img'); |
|
154 | + break; |
|
155 | + |
|
156 | + case '[VENUE_DETAILS_URL]': |
|
157 | + return $this->_venue('permalink'); |
|
158 | + break; |
|
159 | + } |
|
160 | + |
|
161 | + if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
162 | + $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
163 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
164 | + |
|
165 | + // pull the meta value from the venue post |
|
166 | + $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
167 | + |
|
168 | + return ! empty($venue_meta) ? $venue_meta : ''; |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * This retrieves the EE_Venue from the available data object. |
|
174 | + * |
|
175 | + * @return EE_Venue|null |
|
176 | + * @throws EE_Error |
|
177 | + * @throws EntityNotFoundException |
|
178 | + */ |
|
179 | + private function _get_venue() |
|
180 | + { |
|
181 | + |
|
182 | + // we need the EE_Event object to get the venue. |
|
183 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
184 | + |
|
185 | + // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
186 | + // reg_obj instead. |
|
187 | + if (! $this->_event instanceof EE_Event) { |
|
188 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
189 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
190 | + |
|
191 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
192 | + ? $aee->reg_obj->event() |
|
193 | + : null; |
|
194 | + |
|
195 | + // if still empty do we have a ticket data item? |
|
196 | + $this->_event = ! $this->_event instanceof EE_Event |
|
197 | + && $this->_data instanceof EE_Ticket |
|
198 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
199 | + ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
200 | + : $this->_event; |
|
201 | + |
|
202 | + // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
203 | + // and use that. |
|
204 | + $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
205 | + ? reset($aee->events) |
|
206 | + : $this->_event; |
|
207 | + } |
|
208 | + |
|
209 | + // If we have an event object use it to pull the venue. |
|
210 | + if ($this->_event instanceof EE_Event) { |
|
211 | + return $this->_event->get_first_related('Venue'); |
|
212 | + } |
|
213 | + |
|
214 | + return null; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * This retrieves the specified venue information |
|
219 | + * |
|
220 | + * @param string $field What Venue field to retrieve |
|
221 | + * @return string What was retrieved! |
|
222 | + * @throws EE_Error |
|
223 | + * @throws EntityNotFoundException |
|
224 | + */ |
|
225 | + private function _venue($field) |
|
226 | + { |
|
227 | + |
|
228 | + if (! $this->_venue instanceof EE_Venue) { |
|
229 | + return ''; |
|
230 | + } //no venue so get out. |
|
231 | + |
|
232 | + switch ($field) { |
|
233 | + case 'title': |
|
234 | + return $this->_venue->get('VNU_name'); |
|
235 | + break; |
|
236 | + |
|
237 | + case 'description': |
|
238 | + return $this->_venue->get('VNU_desc'); |
|
239 | + break; |
|
240 | + |
|
241 | + case 'url': |
|
242 | + $url = $this->_venue->get('VNU_url'); |
|
243 | + return empty($url) ? $this->_venue->get_permalink() : $url; |
|
244 | + break; |
|
245 | + |
|
246 | + case 'permalink': |
|
247 | + return $this->_venue->get_permalink(); |
|
248 | + break; |
|
249 | + |
|
250 | + case 'image': |
|
251 | + return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | + . '" alt="' . sprintf( |
|
253 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
254 | + $this->_venue->get('VNU_name') |
|
255 | + ) . '" />'; |
|
256 | + break; |
|
257 | + |
|
258 | + case 'phone': |
|
259 | + return $this->_venue->get('VNU_phone'); |
|
260 | + break; |
|
261 | + |
|
262 | + case 'address': |
|
263 | + return $this->_venue->get('VNU_address'); |
|
264 | + break; |
|
265 | + |
|
266 | + case 'address2': |
|
267 | + return $this->_venue->get('VNU_address2'); |
|
268 | + break; |
|
269 | + |
|
270 | + case 'city': |
|
271 | + return $this->_venue->get('VNU_city'); |
|
272 | + break; |
|
273 | + |
|
274 | + case 'state': |
|
275 | + $state = $this->_venue->state_obj(); |
|
276 | + return is_object($state) ? $state->get('STA_name') : ''; |
|
277 | + break; |
|
278 | + |
|
279 | + case 'country': |
|
280 | + $country = $this->_venue->country_obj(); |
|
281 | + return is_object($country) ? $country->get('CNT_name') : ''; |
|
282 | + break; |
|
283 | + |
|
284 | + case 'zip': |
|
285 | + return $this->_venue->get('VNU_zip'); |
|
286 | + break; |
|
287 | + |
|
288 | + case 'formatted_address': |
|
289 | + return EEH_Address::format($this->_venue); |
|
290 | + break; |
|
291 | + |
|
292 | + case 'gmap_link': |
|
293 | + case 'gmap_url': |
|
294 | + case 'gmap_link_img': |
|
295 | + $atts = $this->get_map_attributes($this->_venue, $field); |
|
296 | + return EEH_Maps::google_map_link($atts); |
|
297 | + break; |
|
298 | + } |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Generates the attributes for retrieving a google_map artifact. |
|
305 | + * |
|
306 | + * @param EE_Venue $venue |
|
307 | + * @param string $field |
|
308 | + * @return array |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
312 | + { |
|
313 | + $state = $venue->state_obj(); |
|
314 | + $country = $venue->country_obj(); |
|
315 | + $atts = array( |
|
316 | + 'id' => $venue->ID(), |
|
317 | + 'address' => $venue->get('VNU_address'), |
|
318 | + 'city' => $venue->get('VNU_city'), |
|
319 | + 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
320 | + 'zip' => $venue->get('VNU_zip'), |
|
321 | + 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
322 | + 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
323 | + 'map_w' => 200, |
|
324 | + 'map_h' => 200, |
|
325 | + ); |
|
326 | + if ($field === 'gmap_url') { |
|
327 | + $atts['type'] = 'url_only'; |
|
328 | + } |
|
329 | + return $atts; |
|
330 | + } |
|
331 | 331 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | { |
89 | 89 | $this->_venue = $this->_get_venue(); |
90 | 90 | // If there is no venue object by now then get out. |
91 | - if (! $this->_venue instanceof EE_Venue) { |
|
91 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
92 | 92 | return ''; |
93 | 93 | } |
94 | 94 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
186 | 186 | // reg_obj instead. |
187 | - if (! $this->_event instanceof EE_Event) { |
|
187 | + if ( ! $this->_event instanceof EE_Event) { |
|
188 | 188 | $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
189 | 189 | $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
190 | 190 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $this->_event = ! $this->_event instanceof EE_Event |
197 | 197 | && $this->_data instanceof EE_Ticket |
198 | 198 | && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
199 | - ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
199 | + ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
200 | 200 | : $this->_event; |
201 | 201 | |
202 | 202 | // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | private function _venue($field) |
226 | 226 | { |
227 | 227 | |
228 | - if (! $this->_venue instanceof EE_Venue) { |
|
228 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
229 | 229 | return ''; |
230 | 230 | } //no venue so get out. |
231 | 231 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | break; |
249 | 249 | |
250 | 250 | case 'image': |
251 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | - . '" alt="' . sprintf( |
|
251 | + return '<img src="'.$this->_venue->feature_image_url(array(200, 200,)) |
|
252 | + . '" alt="'.sprintf( |
|
253 | 253 | esc_attr__('%s Feature Image', 'event_espresso'), |
254 | 254 | $this->_venue->get('VNU_name') |
255 | - ) . '" />'; |
|
255 | + ).'" />'; |
|
256 | 256 | break; |
257 | 257 | |
258 | 258 | case 'phone': |
@@ -15,22 +15,22 @@ |
||
15 | 15 | class EE_Radio_Button_Input extends EE_Form_Input_With_Options_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param array $answer_options |
|
20 | - * @param array $input_settings |
|
21 | - */ |
|
22 | - public function __construct($answer_options, $input_settings = array()) |
|
23 | - { |
|
24 | - $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy()); |
|
25 | - $this->_add_validation_strategy( |
|
26 | - new EE_Enum_Validation_Strategy( |
|
27 | - isset($input_settings['validation_error_message']) |
|
28 | - ? $input_settings['validation_error_message'] |
|
29 | - : null |
|
30 | - ) |
|
31 | - ); |
|
32 | - $this->_multiple_selections = false; |
|
33 | - parent::__construct($answer_options, $input_settings); |
|
34 | - } |
|
18 | + /** |
|
19 | + * @param array $answer_options |
|
20 | + * @param array $input_settings |
|
21 | + */ |
|
22 | + public function __construct($answer_options, $input_settings = array()) |
|
23 | + { |
|
24 | + $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy()); |
|
25 | + $this->_add_validation_strategy( |
|
26 | + new EE_Enum_Validation_Strategy( |
|
27 | + isset($input_settings['validation_error_message']) |
|
28 | + ? $input_settings['validation_error_message'] |
|
29 | + : null |
|
30 | + ) |
|
31 | + ); |
|
32 | + $this->_multiple_selections = false; |
|
33 | + parent::__construct($answer_options, $input_settings); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |