@@ -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::div( |
|
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::div( |
|
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 | } |
@@ -16,1259 +16,1259 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * This is used to hold the reports template data which is setup early in the request. |
|
21 | - * |
|
22 | - * @type array |
|
23 | - */ |
|
24 | - protected $_reports_template_data = array(); |
|
19 | + /** |
|
20 | + * This is used to hold the reports template data which is setup early in the request. |
|
21 | + * |
|
22 | + * @type array |
|
23 | + */ |
|
24 | + protected $_reports_template_data = array(); |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * Extend_Registrations_Admin_Page constructor. |
|
29 | - * |
|
30 | - * @param bool $routing |
|
31 | - */ |
|
32 | - public function __construct($routing = true) |
|
33 | - { |
|
34 | - parent::__construct($routing); |
|
35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
39 | - } |
|
40 | - } |
|
27 | + /** |
|
28 | + * Extend_Registrations_Admin_Page constructor. |
|
29 | + * |
|
30 | + * @param bool $routing |
|
31 | + */ |
|
32 | + public function __construct($routing = true) |
|
33 | + { |
|
34 | + parent::__construct($routing); |
|
35 | + if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Extending page configuration. |
|
45 | - */ |
|
46 | - protected function _extend_page_config() |
|
47 | - { |
|
48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
50 | - ? $this->_req_data['_REG_ID'] |
|
51 | - : 0; |
|
52 | - $new_page_routes = array( |
|
53 | - 'reports' => array( |
|
54 | - 'func' => '_registration_reports', |
|
55 | - 'capability' => 'ee_read_registrations', |
|
56 | - ), |
|
57 | - 'registration_checkins' => array( |
|
58 | - 'func' => '_registration_checkin_list_table', |
|
59 | - 'capability' => 'ee_read_checkins', |
|
60 | - ), |
|
61 | - 'newsletter_selected_send' => array( |
|
62 | - 'func' => '_newsletter_selected_send', |
|
63 | - 'noheader' => true, |
|
64 | - 'capability' => 'ee_send_message', |
|
65 | - ), |
|
66 | - 'delete_checkin_rows' => array( |
|
67 | - 'func' => '_delete_checkin_rows', |
|
68 | - 'noheader' => true, |
|
69 | - 'capability' => 'ee_delete_checkins', |
|
70 | - ), |
|
71 | - 'delete_checkin_row' => array( |
|
72 | - 'func' => '_delete_checkin_row', |
|
73 | - 'noheader' => true, |
|
74 | - 'capability' => 'ee_delete_checkin', |
|
75 | - 'obj_id' => $reg_id, |
|
76 | - ), |
|
77 | - 'toggle_checkin_status' => array( |
|
78 | - 'func' => '_toggle_checkin_status', |
|
79 | - 'noheader' => true, |
|
80 | - 'capability' => 'ee_edit_checkin', |
|
81 | - 'obj_id' => $reg_id, |
|
82 | - ), |
|
83 | - 'toggle_checkin_status_bulk' => array( |
|
84 | - 'func' => '_toggle_checkin_status', |
|
85 | - 'noheader' => true, |
|
86 | - 'capability' => 'ee_edit_checkins', |
|
87 | - ), |
|
88 | - 'event_registrations' => array( |
|
89 | - 'func' => '_event_registrations_list_table', |
|
90 | - 'capability' => 'ee_read_checkins', |
|
91 | - ), |
|
92 | - 'registrations_checkin_report' => array( |
|
93 | - 'func' => '_registrations_checkin_report', |
|
94 | - 'noheader' => true, |
|
95 | - 'capability' => 'ee_read_registrations', |
|
96 | - ), |
|
97 | - ); |
|
98 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
99 | - $new_page_config = array( |
|
100 | - 'reports' => array( |
|
101 | - 'nav' => array( |
|
102 | - 'label' => esc_html__('Reports', 'event_espresso'), |
|
103 | - 'order' => 30, |
|
104 | - ), |
|
105 | - 'help_tabs' => array( |
|
106 | - 'registrations_reports_help_tab' => array( |
|
107 | - 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
108 | - 'filename' => 'registrations_reports', |
|
109 | - ), |
|
110 | - ), |
|
111 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
112 | - 'require_nonce' => false, |
|
113 | - ), |
|
114 | - 'event_registrations' => array( |
|
115 | - 'nav' => array( |
|
116 | - 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
117 | - 'order' => 10, |
|
118 | - 'persistent' => true, |
|
119 | - ), |
|
120 | - 'help_tabs' => array( |
|
121 | - 'registrations_event_checkin_help_tab' => array( |
|
122 | - 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
123 | - 'filename' => 'registrations_event_checkin', |
|
124 | - ), |
|
125 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
126 | - 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
127 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
128 | - ), |
|
129 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
130 | - 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
131 | - 'filename' => 'registrations_event_checkin_filters', |
|
132 | - ), |
|
133 | - 'registrations_event_checkin_views_help_tab' => array( |
|
134 | - 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
135 | - 'filename' => 'registrations_event_checkin_views', |
|
136 | - ), |
|
137 | - 'registrations_event_checkin_other_help_tab' => array( |
|
138 | - 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
139 | - 'filename' => 'registrations_event_checkin_other', |
|
140 | - ), |
|
141 | - ), |
|
142 | - 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
143 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
144 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
145 | - 'metaboxes' => array(), |
|
146 | - 'require_nonce' => false, |
|
147 | - ), |
|
148 | - 'registration_checkins' => array( |
|
149 | - 'nav' => array( |
|
150 | - 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
151 | - 'order' => 15, |
|
152 | - 'persistent' => false, |
|
153 | - 'url' => '', |
|
154 | - ), |
|
155 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
156 | - // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
157 | - 'metaboxes' => array(), |
|
158 | - 'require_nonce' => false, |
|
159 | - ), |
|
160 | - ); |
|
161 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
162 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
163 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
164 | - } |
|
43 | + /** |
|
44 | + * Extending page configuration. |
|
45 | + */ |
|
46 | + protected function _extend_page_config() |
|
47 | + { |
|
48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
50 | + ? $this->_req_data['_REG_ID'] |
|
51 | + : 0; |
|
52 | + $new_page_routes = array( |
|
53 | + 'reports' => array( |
|
54 | + 'func' => '_registration_reports', |
|
55 | + 'capability' => 'ee_read_registrations', |
|
56 | + ), |
|
57 | + 'registration_checkins' => array( |
|
58 | + 'func' => '_registration_checkin_list_table', |
|
59 | + 'capability' => 'ee_read_checkins', |
|
60 | + ), |
|
61 | + 'newsletter_selected_send' => array( |
|
62 | + 'func' => '_newsletter_selected_send', |
|
63 | + 'noheader' => true, |
|
64 | + 'capability' => 'ee_send_message', |
|
65 | + ), |
|
66 | + 'delete_checkin_rows' => array( |
|
67 | + 'func' => '_delete_checkin_rows', |
|
68 | + 'noheader' => true, |
|
69 | + 'capability' => 'ee_delete_checkins', |
|
70 | + ), |
|
71 | + 'delete_checkin_row' => array( |
|
72 | + 'func' => '_delete_checkin_row', |
|
73 | + 'noheader' => true, |
|
74 | + 'capability' => 'ee_delete_checkin', |
|
75 | + 'obj_id' => $reg_id, |
|
76 | + ), |
|
77 | + 'toggle_checkin_status' => array( |
|
78 | + 'func' => '_toggle_checkin_status', |
|
79 | + 'noheader' => true, |
|
80 | + 'capability' => 'ee_edit_checkin', |
|
81 | + 'obj_id' => $reg_id, |
|
82 | + ), |
|
83 | + 'toggle_checkin_status_bulk' => array( |
|
84 | + 'func' => '_toggle_checkin_status', |
|
85 | + 'noheader' => true, |
|
86 | + 'capability' => 'ee_edit_checkins', |
|
87 | + ), |
|
88 | + 'event_registrations' => array( |
|
89 | + 'func' => '_event_registrations_list_table', |
|
90 | + 'capability' => 'ee_read_checkins', |
|
91 | + ), |
|
92 | + 'registrations_checkin_report' => array( |
|
93 | + 'func' => '_registrations_checkin_report', |
|
94 | + 'noheader' => true, |
|
95 | + 'capability' => 'ee_read_registrations', |
|
96 | + ), |
|
97 | + ); |
|
98 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
99 | + $new_page_config = array( |
|
100 | + 'reports' => array( |
|
101 | + 'nav' => array( |
|
102 | + 'label' => esc_html__('Reports', 'event_espresso'), |
|
103 | + 'order' => 30, |
|
104 | + ), |
|
105 | + 'help_tabs' => array( |
|
106 | + 'registrations_reports_help_tab' => array( |
|
107 | + 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
108 | + 'filename' => 'registrations_reports', |
|
109 | + ), |
|
110 | + ), |
|
111 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
112 | + 'require_nonce' => false, |
|
113 | + ), |
|
114 | + 'event_registrations' => array( |
|
115 | + 'nav' => array( |
|
116 | + 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
117 | + 'order' => 10, |
|
118 | + 'persistent' => true, |
|
119 | + ), |
|
120 | + 'help_tabs' => array( |
|
121 | + 'registrations_event_checkin_help_tab' => array( |
|
122 | + 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
123 | + 'filename' => 'registrations_event_checkin', |
|
124 | + ), |
|
125 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
126 | + 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
127 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
128 | + ), |
|
129 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
130 | + 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
131 | + 'filename' => 'registrations_event_checkin_filters', |
|
132 | + ), |
|
133 | + 'registrations_event_checkin_views_help_tab' => array( |
|
134 | + 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
135 | + 'filename' => 'registrations_event_checkin_views', |
|
136 | + ), |
|
137 | + 'registrations_event_checkin_other_help_tab' => array( |
|
138 | + 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
139 | + 'filename' => 'registrations_event_checkin_other', |
|
140 | + ), |
|
141 | + ), |
|
142 | + 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
143 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
144 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
145 | + 'metaboxes' => array(), |
|
146 | + 'require_nonce' => false, |
|
147 | + ), |
|
148 | + 'registration_checkins' => array( |
|
149 | + 'nav' => array( |
|
150 | + 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
151 | + 'order' => 15, |
|
152 | + 'persistent' => false, |
|
153 | + 'url' => '', |
|
154 | + ), |
|
155 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
156 | + // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
157 | + 'metaboxes' => array(), |
|
158 | + 'require_nonce' => false, |
|
159 | + ), |
|
160 | + ); |
|
161 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
162 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
163 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
164 | + } |
|
165 | 165 | |
166 | 166 | |
167 | - /** |
|
168 | - * Ajax hooks for all routes in this page. |
|
169 | - */ |
|
170 | - protected function _ajax_hooks() |
|
171 | - { |
|
172 | - parent::_ajax_hooks(); |
|
173 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
174 | - } |
|
167 | + /** |
|
168 | + * Ajax hooks for all routes in this page. |
|
169 | + */ |
|
170 | + protected function _ajax_hooks() |
|
171 | + { |
|
172 | + parent::_ajax_hooks(); |
|
173 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * Global scripts for all routes in this page. |
|
179 | - */ |
|
180 | - public function load_scripts_styles() |
|
181 | - { |
|
182 | - parent::load_scripts_styles(); |
|
183 | - // if newsletter message type is active then let's add filter and load js for it. |
|
184 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
185 | - // enqueue newsletter js |
|
186 | - wp_enqueue_script( |
|
187 | - 'ee-newsletter-trigger', |
|
188 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
189 | - array('ee-dialog'), |
|
190 | - EVENT_ESPRESSO_VERSION, |
|
191 | - true |
|
192 | - ); |
|
193 | - wp_enqueue_style( |
|
194 | - 'ee-newsletter-trigger-css', |
|
195 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
196 | - array(), |
|
197 | - EVENT_ESPRESSO_VERSION |
|
198 | - ); |
|
199 | - // hook in buttons for newsletter message type trigger. |
|
200 | - add_action( |
|
201 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
202 | - array($this, 'add_newsletter_action_buttons'), |
|
203 | - 10 |
|
204 | - ); |
|
205 | - } |
|
206 | - } |
|
177 | + /** |
|
178 | + * Global scripts for all routes in this page. |
|
179 | + */ |
|
180 | + public function load_scripts_styles() |
|
181 | + { |
|
182 | + parent::load_scripts_styles(); |
|
183 | + // if newsletter message type is active then let's add filter and load js for it. |
|
184 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
185 | + // enqueue newsletter js |
|
186 | + wp_enqueue_script( |
|
187 | + 'ee-newsletter-trigger', |
|
188 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
189 | + array('ee-dialog'), |
|
190 | + EVENT_ESPRESSO_VERSION, |
|
191 | + true |
|
192 | + ); |
|
193 | + wp_enqueue_style( |
|
194 | + 'ee-newsletter-trigger-css', |
|
195 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
196 | + array(), |
|
197 | + EVENT_ESPRESSO_VERSION |
|
198 | + ); |
|
199 | + // hook in buttons for newsletter message type trigger. |
|
200 | + add_action( |
|
201 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
202 | + array($this, 'add_newsletter_action_buttons'), |
|
203 | + 10 |
|
204 | + ); |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * Scripts and styles for just the reports route. |
|
211 | - */ |
|
212 | - public function load_scripts_styles_reports() |
|
213 | - { |
|
214 | - wp_register_script( |
|
215 | - 'ee-reg-reports-js', |
|
216 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
217 | - array('google-charts'), |
|
218 | - EVENT_ESPRESSO_VERSION, |
|
219 | - true |
|
220 | - ); |
|
221 | - wp_enqueue_script('ee-reg-reports-js'); |
|
222 | - $this->_registration_reports_js_setup(); |
|
223 | - } |
|
209 | + /** |
|
210 | + * Scripts and styles for just the reports route. |
|
211 | + */ |
|
212 | + public function load_scripts_styles_reports() |
|
213 | + { |
|
214 | + wp_register_script( |
|
215 | + 'ee-reg-reports-js', |
|
216 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
217 | + array('google-charts'), |
|
218 | + EVENT_ESPRESSO_VERSION, |
|
219 | + true |
|
220 | + ); |
|
221 | + wp_enqueue_script('ee-reg-reports-js'); |
|
222 | + $this->_registration_reports_js_setup(); |
|
223 | + } |
|
224 | 224 | |
225 | 225 | |
226 | - /** |
|
227 | - * Register screen options for event_registrations route. |
|
228 | - */ |
|
229 | - protected function _add_screen_options_event_registrations() |
|
230 | - { |
|
231 | - $this->_per_page_screen_option(); |
|
232 | - } |
|
226 | + /** |
|
227 | + * Register screen options for event_registrations route. |
|
228 | + */ |
|
229 | + protected function _add_screen_options_event_registrations() |
|
230 | + { |
|
231 | + $this->_per_page_screen_option(); |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - /** |
|
236 | - * Register screen options for registration_checkins route |
|
237 | - */ |
|
238 | - protected function _add_screen_options_registration_checkins() |
|
239 | - { |
|
240 | - $page_title = $this->_admin_page_title; |
|
241 | - $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
242 | - $this->_per_page_screen_option(); |
|
243 | - $this->_admin_page_title = $page_title; |
|
244 | - } |
|
235 | + /** |
|
236 | + * Register screen options for registration_checkins route |
|
237 | + */ |
|
238 | + protected function _add_screen_options_registration_checkins() |
|
239 | + { |
|
240 | + $page_title = $this->_admin_page_title; |
|
241 | + $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
242 | + $this->_per_page_screen_option(); |
|
243 | + $this->_admin_page_title = $page_title; |
|
244 | + } |
|
245 | 245 | |
246 | 246 | |
247 | - /** |
|
248 | - * Set views property for event_registrations route. |
|
249 | - */ |
|
250 | - protected function _set_list_table_views_event_registrations() |
|
251 | - { |
|
252 | - $this->_views = array( |
|
253 | - 'all' => array( |
|
254 | - 'slug' => 'all', |
|
255 | - 'label' => esc_html__('All', 'event_espresso'), |
|
256 | - 'count' => 0, |
|
257 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
258 | - ? array() |
|
259 | - : array( |
|
260 | - 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
261 | - ), |
|
262 | - ), |
|
263 | - ); |
|
264 | - } |
|
247 | + /** |
|
248 | + * Set views property for event_registrations route. |
|
249 | + */ |
|
250 | + protected function _set_list_table_views_event_registrations() |
|
251 | + { |
|
252 | + $this->_views = array( |
|
253 | + 'all' => array( |
|
254 | + 'slug' => 'all', |
|
255 | + 'label' => esc_html__('All', 'event_espresso'), |
|
256 | + 'count' => 0, |
|
257 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
258 | + ? array() |
|
259 | + : array( |
|
260 | + 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
261 | + ), |
|
262 | + ), |
|
263 | + ); |
|
264 | + } |
|
265 | 265 | |
266 | 266 | |
267 | - /** |
|
268 | - * Set views property for registration_checkins route. |
|
269 | - */ |
|
270 | - protected function _set_list_table_views_registration_checkins() |
|
271 | - { |
|
272 | - $this->_views = array( |
|
273 | - 'all' => array( |
|
274 | - 'slug' => 'all', |
|
275 | - 'label' => esc_html__('All', 'event_espresso'), |
|
276 | - 'count' => 0, |
|
277 | - 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
278 | - ), |
|
279 | - ); |
|
280 | - } |
|
267 | + /** |
|
268 | + * Set views property for registration_checkins route. |
|
269 | + */ |
|
270 | + protected function _set_list_table_views_registration_checkins() |
|
271 | + { |
|
272 | + $this->_views = array( |
|
273 | + 'all' => array( |
|
274 | + 'slug' => 'all', |
|
275 | + 'label' => esc_html__('All', 'event_espresso'), |
|
276 | + 'count' => 0, |
|
277 | + 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
278 | + ), |
|
279 | + ); |
|
280 | + } |
|
281 | 281 | |
282 | 282 | |
283 | - /** |
|
284 | - * callback for ajax action. |
|
285 | - * |
|
286 | - * @since 4.3.0 |
|
287 | - * @return void (JSON) |
|
288 | - * @throws EE_Error |
|
289 | - * @throws InvalidArgumentException |
|
290 | - * @throws InvalidDataTypeException |
|
291 | - * @throws InvalidInterfaceException |
|
292 | - */ |
|
293 | - public function get_newsletter_form_content() |
|
294 | - { |
|
295 | - // do a nonce check cause we're not coming in from an normal route here. |
|
296 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
297 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
298 | - ) : ''; |
|
299 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
300 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
301 | - // let's get the mtp for the incoming MTP_ ID |
|
302 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
303 | - EE_Error::add_error( |
|
304 | - esc_html__( |
|
305 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
306 | - 'event_espresso' |
|
307 | - ), |
|
308 | - __FILE__, |
|
309 | - __FUNCTION__, |
|
310 | - __LINE__ |
|
311 | - ); |
|
312 | - $this->_template_args['success'] = false; |
|
313 | - $this->_template_args['error'] = true; |
|
314 | - $this->_return_json(); |
|
315 | - } |
|
316 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
317 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
318 | - EE_Error::add_error( |
|
319 | - sprintf( |
|
320 | - esc_html__( |
|
321 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
322 | - 'event_espresso' |
|
323 | - ), |
|
324 | - $this->_req_data['GRP_ID'] |
|
325 | - ), |
|
326 | - __FILE__, |
|
327 | - __FUNCTION__, |
|
328 | - __LINE__ |
|
329 | - ); |
|
330 | - $this->_template_args['success'] = false; |
|
331 | - $this->_template_args['error'] = true; |
|
332 | - $this->_return_json(); |
|
333 | - } |
|
334 | - $MTPs = $MTPG->context_templates(); |
|
335 | - $MTPs = $MTPs['attendee']; |
|
336 | - $template_fields = array(); |
|
337 | - /** @var EE_Message_Template $MTP */ |
|
338 | - foreach ($MTPs as $MTP) { |
|
339 | - $field = $MTP->get('MTP_template_field'); |
|
340 | - if ($field === 'content') { |
|
341 | - $content = $MTP->get('MTP_content'); |
|
342 | - if (! empty($content['newsletter_content'])) { |
|
343 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
344 | - } |
|
345 | - continue; |
|
346 | - } |
|
347 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
348 | - } |
|
349 | - $this->_template_args['success'] = true; |
|
350 | - $this->_template_args['error'] = false; |
|
351 | - $this->_template_args['data'] = array( |
|
352 | - 'batch_message_from' => isset($template_fields['from']) |
|
353 | - ? $template_fields['from'] |
|
354 | - : '', |
|
355 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
356 | - ? $template_fields['subject'] |
|
357 | - : '', |
|
358 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
359 | - ? $template_fields['newsletter_content'] |
|
360 | - : '', |
|
361 | - ); |
|
362 | - $this->_return_json(); |
|
363 | - } |
|
283 | + /** |
|
284 | + * callback for ajax action. |
|
285 | + * |
|
286 | + * @since 4.3.0 |
|
287 | + * @return void (JSON) |
|
288 | + * @throws EE_Error |
|
289 | + * @throws InvalidArgumentException |
|
290 | + * @throws InvalidDataTypeException |
|
291 | + * @throws InvalidInterfaceException |
|
292 | + */ |
|
293 | + public function get_newsletter_form_content() |
|
294 | + { |
|
295 | + // do a nonce check cause we're not coming in from an normal route here. |
|
296 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
297 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
298 | + ) : ''; |
|
299 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
300 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
301 | + // let's get the mtp for the incoming MTP_ ID |
|
302 | + if (! isset($this->_req_data['GRP_ID'])) { |
|
303 | + EE_Error::add_error( |
|
304 | + esc_html__( |
|
305 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
306 | + 'event_espresso' |
|
307 | + ), |
|
308 | + __FILE__, |
|
309 | + __FUNCTION__, |
|
310 | + __LINE__ |
|
311 | + ); |
|
312 | + $this->_template_args['success'] = false; |
|
313 | + $this->_template_args['error'] = true; |
|
314 | + $this->_return_json(); |
|
315 | + } |
|
316 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
317 | + if (! $MTPG instanceof EE_Message_Template_Group) { |
|
318 | + EE_Error::add_error( |
|
319 | + sprintf( |
|
320 | + esc_html__( |
|
321 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
322 | + 'event_espresso' |
|
323 | + ), |
|
324 | + $this->_req_data['GRP_ID'] |
|
325 | + ), |
|
326 | + __FILE__, |
|
327 | + __FUNCTION__, |
|
328 | + __LINE__ |
|
329 | + ); |
|
330 | + $this->_template_args['success'] = false; |
|
331 | + $this->_template_args['error'] = true; |
|
332 | + $this->_return_json(); |
|
333 | + } |
|
334 | + $MTPs = $MTPG->context_templates(); |
|
335 | + $MTPs = $MTPs['attendee']; |
|
336 | + $template_fields = array(); |
|
337 | + /** @var EE_Message_Template $MTP */ |
|
338 | + foreach ($MTPs as $MTP) { |
|
339 | + $field = $MTP->get('MTP_template_field'); |
|
340 | + if ($field === 'content') { |
|
341 | + $content = $MTP->get('MTP_content'); |
|
342 | + if (! empty($content['newsletter_content'])) { |
|
343 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
344 | + } |
|
345 | + continue; |
|
346 | + } |
|
347 | + $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
348 | + } |
|
349 | + $this->_template_args['success'] = true; |
|
350 | + $this->_template_args['error'] = false; |
|
351 | + $this->_template_args['data'] = array( |
|
352 | + 'batch_message_from' => isset($template_fields['from']) |
|
353 | + ? $template_fields['from'] |
|
354 | + : '', |
|
355 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
356 | + ? $template_fields['subject'] |
|
357 | + : '', |
|
358 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
359 | + ? $template_fields['newsletter_content'] |
|
360 | + : '', |
|
361 | + ); |
|
362 | + $this->_return_json(); |
|
363 | + } |
|
364 | 364 | |
365 | 365 | |
366 | - /** |
|
367 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
368 | - * |
|
369 | - * @since 4.3.0 |
|
370 | - * @param EE_Admin_List_Table $list_table |
|
371 | - * @return void |
|
372 | - * @throws InvalidArgumentException |
|
373 | - * @throws InvalidDataTypeException |
|
374 | - * @throws InvalidInterfaceException |
|
375 | - */ |
|
376 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
377 | - { |
|
378 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
379 | - 'ee_send_message', |
|
380 | - 'espresso_registrations_newsletter_selected_send' |
|
381 | - ) |
|
382 | - ) { |
|
383 | - return; |
|
384 | - } |
|
385 | - $routes_to_add_to = array( |
|
386 | - 'contact_list', |
|
387 | - 'event_registrations', |
|
388 | - 'default', |
|
389 | - ); |
|
390 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
391 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
392 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
393 | - ) { |
|
394 | - echo ''; |
|
395 | - } else { |
|
396 | - $button_text = sprintf( |
|
397 | - esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
398 | - '<span class="send-selected-newsletter-count">0</span>' |
|
399 | - ); |
|
400 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
401 | - . '<span class="dashicons dashicons-email "></span>' |
|
402 | - . $button_text |
|
403 | - . '</button>'; |
|
404 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
405 | - } |
|
406 | - } |
|
407 | - } |
|
366 | + /** |
|
367 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
368 | + * |
|
369 | + * @since 4.3.0 |
|
370 | + * @param EE_Admin_List_Table $list_table |
|
371 | + * @return void |
|
372 | + * @throws InvalidArgumentException |
|
373 | + * @throws InvalidDataTypeException |
|
374 | + * @throws InvalidInterfaceException |
|
375 | + */ |
|
376 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
377 | + { |
|
378 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
379 | + 'ee_send_message', |
|
380 | + 'espresso_registrations_newsletter_selected_send' |
|
381 | + ) |
|
382 | + ) { |
|
383 | + return; |
|
384 | + } |
|
385 | + $routes_to_add_to = array( |
|
386 | + 'contact_list', |
|
387 | + 'event_registrations', |
|
388 | + 'default', |
|
389 | + ); |
|
390 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
391 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
392 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
393 | + ) { |
|
394 | + echo ''; |
|
395 | + } else { |
|
396 | + $button_text = sprintf( |
|
397 | + esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
398 | + '<span class="send-selected-newsletter-count">0</span>' |
|
399 | + ); |
|
400 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
401 | + . '<span class="dashicons dashicons-email "></span>' |
|
402 | + . $button_text |
|
403 | + . '</button>'; |
|
404 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
405 | + } |
|
406 | + } |
|
407 | + } |
|
408 | 408 | |
409 | 409 | |
410 | - /** |
|
411 | - * @throws DomainException |
|
412 | - * @throws EE_Error |
|
413 | - * @throws InvalidArgumentException |
|
414 | - * @throws InvalidDataTypeException |
|
415 | - * @throws InvalidInterfaceException |
|
416 | - */ |
|
417 | - public function newsletter_send_form_skeleton() |
|
418 | - { |
|
419 | - $list_table = $this->_list_table_object; |
|
420 | - $codes = array(); |
|
421 | - // need to templates for the newsletter message type for the template selector. |
|
422 | - $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
423 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
424 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
425 | - ); |
|
426 | - foreach ($mtps as $mtp) { |
|
427 | - $name = $mtp->name(); |
|
428 | - $values[] = array( |
|
429 | - 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
430 | - 'id' => $mtp->ID(), |
|
431 | - ); |
|
432 | - } |
|
433 | - // need to get a list of shortcodes that are available for the newsletter message type. |
|
434 | - $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
435 | - 'newsletter', |
|
436 | - 'email', |
|
437 | - array(), |
|
438 | - 'attendee', |
|
439 | - false |
|
440 | - ); |
|
441 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
442 | - $available_shortcodes = array(); |
|
443 | - foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
444 | - $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
445 | - ? 'content' |
|
446 | - : $field; |
|
447 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
448 | - $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
449 | - . $shortcode |
|
450 | - . '" data-linked-input-id="' . $field_id . '">' |
|
451 | - . $shortcode |
|
452 | - . '</span>'; |
|
453 | - } |
|
454 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
455 | - } |
|
456 | - $shortcodes = $codes; |
|
457 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
458 | - $form_template_args = array( |
|
459 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
460 | - 'form_route' => 'newsletter_selected_send', |
|
461 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
462 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
463 | - 'redirect_back_to' => $this->_req_action, |
|
464 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
465 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
466 | - 'shortcodes' => $shortcodes, |
|
467 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
468 | - ); |
|
469 | - EEH_Template::display_template($form_template, $form_template_args); |
|
470 | - } |
|
410 | + /** |
|
411 | + * @throws DomainException |
|
412 | + * @throws EE_Error |
|
413 | + * @throws InvalidArgumentException |
|
414 | + * @throws InvalidDataTypeException |
|
415 | + * @throws InvalidInterfaceException |
|
416 | + */ |
|
417 | + public function newsletter_send_form_skeleton() |
|
418 | + { |
|
419 | + $list_table = $this->_list_table_object; |
|
420 | + $codes = array(); |
|
421 | + // need to templates for the newsletter message type for the template selector. |
|
422 | + $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
423 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
424 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
425 | + ); |
|
426 | + foreach ($mtps as $mtp) { |
|
427 | + $name = $mtp->name(); |
|
428 | + $values[] = array( |
|
429 | + 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
430 | + 'id' => $mtp->ID(), |
|
431 | + ); |
|
432 | + } |
|
433 | + // need to get a list of shortcodes that are available for the newsletter message type. |
|
434 | + $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
435 | + 'newsletter', |
|
436 | + 'email', |
|
437 | + array(), |
|
438 | + 'attendee', |
|
439 | + false |
|
440 | + ); |
|
441 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
442 | + $available_shortcodes = array(); |
|
443 | + foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
444 | + $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
445 | + ? 'content' |
|
446 | + : $field; |
|
447 | + $field_id = 'batch-message-' . strtolower($field_id); |
|
448 | + $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
449 | + . $shortcode |
|
450 | + . '" data-linked-input-id="' . $field_id . '">' |
|
451 | + . $shortcode |
|
452 | + . '</span>'; |
|
453 | + } |
|
454 | + $codes[ $field ] = implode(', ', $available_shortcodes); |
|
455 | + } |
|
456 | + $shortcodes = $codes; |
|
457 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
458 | + $form_template_args = array( |
|
459 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
460 | + 'form_route' => 'newsletter_selected_send', |
|
461 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
462 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
463 | + 'redirect_back_to' => $this->_req_action, |
|
464 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
465 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
466 | + 'shortcodes' => $shortcodes, |
|
467 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
468 | + ); |
|
469 | + EEH_Template::display_template($form_template, $form_template_args); |
|
470 | + } |
|
471 | 471 | |
472 | 472 | |
473 | - /** |
|
474 | - * Handles sending selected registrations/contacts a newsletter. |
|
475 | - * |
|
476 | - * @since 4.3.0 |
|
477 | - * @return void |
|
478 | - * @throws EE_Error |
|
479 | - * @throws InvalidArgumentException |
|
480 | - * @throws InvalidDataTypeException |
|
481 | - * @throws InvalidInterfaceException |
|
482 | - */ |
|
483 | - protected function _newsletter_selected_send() |
|
484 | - { |
|
485 | - $success = true; |
|
486 | - // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
487 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
488 | - EE_Error::add_error( |
|
489 | - esc_html__( |
|
490 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
491 | - 'event_espresso' |
|
492 | - ), |
|
493 | - __FILE__, |
|
494 | - __FUNCTION__, |
|
495 | - __LINE__ |
|
496 | - ); |
|
497 | - $success = false; |
|
498 | - } |
|
499 | - if ($success) { |
|
500 | - // update Message template in case there are any changes |
|
501 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
502 | - $this->_req_data['newsletter_mtp_selected'] |
|
503 | - ); |
|
504 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
505 | - ? $Message_Template_Group->context_templates() |
|
506 | - : array(); |
|
507 | - if (empty($Message_Templates)) { |
|
508 | - EE_Error::add_error( |
|
509 | - esc_html__( |
|
510 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
511 | - 'event_espresso' |
|
512 | - ), |
|
513 | - __FILE__, |
|
514 | - __FUNCTION__, |
|
515 | - __LINE__ |
|
516 | - ); |
|
517 | - } |
|
518 | - // let's just update the specific fields |
|
519 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
520 | - if ($Message_Template instanceof EE_Message_Template) { |
|
521 | - $field = $Message_Template->get('MTP_template_field'); |
|
522 | - $content = $Message_Template->get('MTP_content'); |
|
523 | - $new_content = $content; |
|
524 | - switch ($field) { |
|
525 | - case 'from': |
|
526 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
527 | - ? $this->_req_data['batch_message']['from'] |
|
528 | - : $content; |
|
529 | - break; |
|
530 | - case 'subject': |
|
531 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
532 | - ? $this->_req_data['batch_message']['subject'] |
|
533 | - : $content; |
|
534 | - break; |
|
535 | - case 'content': |
|
536 | - $new_content = $content; |
|
537 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
538 | - ? $this->_req_data['batch_message']['content'] |
|
539 | - : $content['newsletter_content']; |
|
540 | - break; |
|
541 | - default: |
|
542 | - // continue the foreach loop, we don't want to set $new_content nor save. |
|
543 | - continue 2; |
|
544 | - } |
|
545 | - $Message_Template->set('MTP_content', $new_content); |
|
546 | - $Message_Template->save(); |
|
547 | - } |
|
548 | - } |
|
549 | - // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
550 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
551 | - ? $this->_req_data['batch_message']['id_type'] |
|
552 | - : 'registration'; |
|
553 | - // id_type will affect how we assemble the ids. |
|
554 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
555 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
556 | - : array(); |
|
557 | - $registrations_used_for_contact_data = array(); |
|
558 | - // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
559 | - switch ($id_type) { |
|
560 | - case 'registration': |
|
561 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
562 | - array( |
|
563 | - array( |
|
564 | - 'REG_ID' => array('IN', $ids), |
|
565 | - ), |
|
566 | - ) |
|
567 | - ); |
|
568 | - break; |
|
569 | - case 'contact': |
|
570 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
571 | - ->get_latest_registration_for_each_of_given_contacts( |
|
572 | - $ids |
|
573 | - ); |
|
574 | - break; |
|
575 | - } |
|
576 | - do_action_ref_array( |
|
577 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
578 | - array( |
|
579 | - $registrations_used_for_contact_data, |
|
580 | - $Message_Template_Group->ID(), |
|
581 | - ) |
|
582 | - ); |
|
583 | - // kept for backward compat, internally we no longer use this action. |
|
584 | - // @deprecated 4.8.36.rc.002 |
|
585 | - $contacts = $id_type === 'registration' |
|
586 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
587 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
588 | - do_action_ref_array( |
|
589 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
590 | - array( |
|
591 | - $contacts, |
|
592 | - $Message_Template_Group->ID(), |
|
593 | - ) |
|
594 | - ); |
|
595 | - } |
|
596 | - $query_args = array( |
|
597 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
598 | - ? $this->_req_data['redirect_back_to'] |
|
599 | - : 'default', |
|
600 | - ); |
|
601 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
602 | - } |
|
473 | + /** |
|
474 | + * Handles sending selected registrations/contacts a newsletter. |
|
475 | + * |
|
476 | + * @since 4.3.0 |
|
477 | + * @return void |
|
478 | + * @throws EE_Error |
|
479 | + * @throws InvalidArgumentException |
|
480 | + * @throws InvalidDataTypeException |
|
481 | + * @throws InvalidInterfaceException |
|
482 | + */ |
|
483 | + protected function _newsletter_selected_send() |
|
484 | + { |
|
485 | + $success = true; |
|
486 | + // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
487 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
488 | + EE_Error::add_error( |
|
489 | + esc_html__( |
|
490 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
491 | + 'event_espresso' |
|
492 | + ), |
|
493 | + __FILE__, |
|
494 | + __FUNCTION__, |
|
495 | + __LINE__ |
|
496 | + ); |
|
497 | + $success = false; |
|
498 | + } |
|
499 | + if ($success) { |
|
500 | + // update Message template in case there are any changes |
|
501 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
502 | + $this->_req_data['newsletter_mtp_selected'] |
|
503 | + ); |
|
504 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
505 | + ? $Message_Template_Group->context_templates() |
|
506 | + : array(); |
|
507 | + if (empty($Message_Templates)) { |
|
508 | + EE_Error::add_error( |
|
509 | + esc_html__( |
|
510 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
511 | + 'event_espresso' |
|
512 | + ), |
|
513 | + __FILE__, |
|
514 | + __FUNCTION__, |
|
515 | + __LINE__ |
|
516 | + ); |
|
517 | + } |
|
518 | + // let's just update the specific fields |
|
519 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
520 | + if ($Message_Template instanceof EE_Message_Template) { |
|
521 | + $field = $Message_Template->get('MTP_template_field'); |
|
522 | + $content = $Message_Template->get('MTP_content'); |
|
523 | + $new_content = $content; |
|
524 | + switch ($field) { |
|
525 | + case 'from': |
|
526 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
527 | + ? $this->_req_data['batch_message']['from'] |
|
528 | + : $content; |
|
529 | + break; |
|
530 | + case 'subject': |
|
531 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
532 | + ? $this->_req_data['batch_message']['subject'] |
|
533 | + : $content; |
|
534 | + break; |
|
535 | + case 'content': |
|
536 | + $new_content = $content; |
|
537 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
538 | + ? $this->_req_data['batch_message']['content'] |
|
539 | + : $content['newsletter_content']; |
|
540 | + break; |
|
541 | + default: |
|
542 | + // continue the foreach loop, we don't want to set $new_content nor save. |
|
543 | + continue 2; |
|
544 | + } |
|
545 | + $Message_Template->set('MTP_content', $new_content); |
|
546 | + $Message_Template->save(); |
|
547 | + } |
|
548 | + } |
|
549 | + // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
550 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
551 | + ? $this->_req_data['batch_message']['id_type'] |
|
552 | + : 'registration'; |
|
553 | + // id_type will affect how we assemble the ids. |
|
554 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
555 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
556 | + : array(); |
|
557 | + $registrations_used_for_contact_data = array(); |
|
558 | + // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
559 | + switch ($id_type) { |
|
560 | + case 'registration': |
|
561 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
562 | + array( |
|
563 | + array( |
|
564 | + 'REG_ID' => array('IN', $ids), |
|
565 | + ), |
|
566 | + ) |
|
567 | + ); |
|
568 | + break; |
|
569 | + case 'contact': |
|
570 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
571 | + ->get_latest_registration_for_each_of_given_contacts( |
|
572 | + $ids |
|
573 | + ); |
|
574 | + break; |
|
575 | + } |
|
576 | + do_action_ref_array( |
|
577 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
578 | + array( |
|
579 | + $registrations_used_for_contact_data, |
|
580 | + $Message_Template_Group->ID(), |
|
581 | + ) |
|
582 | + ); |
|
583 | + // kept for backward compat, internally we no longer use this action. |
|
584 | + // @deprecated 4.8.36.rc.002 |
|
585 | + $contacts = $id_type === 'registration' |
|
586 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
587 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
588 | + do_action_ref_array( |
|
589 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
590 | + array( |
|
591 | + $contacts, |
|
592 | + $Message_Template_Group->ID(), |
|
593 | + ) |
|
594 | + ); |
|
595 | + } |
|
596 | + $query_args = array( |
|
597 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
598 | + ? $this->_req_data['redirect_back_to'] |
|
599 | + : 'default', |
|
600 | + ); |
|
601 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
602 | + } |
|
603 | 603 | |
604 | 604 | |
605 | - /** |
|
606 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
607 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
608 | - */ |
|
609 | - protected function _registration_reports_js_setup() |
|
610 | - { |
|
611 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
612 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
613 | - } |
|
605 | + /** |
|
606 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
607 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
608 | + */ |
|
609 | + protected function _registration_reports_js_setup() |
|
610 | + { |
|
611 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
612 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
613 | + } |
|
614 | 614 | |
615 | 615 | |
616 | - /** |
|
617 | - * generates Business Reports regarding Registrations |
|
618 | - * |
|
619 | - * @access protected |
|
620 | - * @return void |
|
621 | - * @throws DomainException |
|
622 | - */ |
|
623 | - protected function _registration_reports() |
|
624 | - { |
|
625 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
626 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
627 | - $template_path, |
|
628 | - $this->_reports_template_data, |
|
629 | - true |
|
630 | - ); |
|
631 | - // the final template wrapper |
|
632 | - $this->display_admin_page_with_no_sidebar(); |
|
633 | - } |
|
616 | + /** |
|
617 | + * generates Business Reports regarding Registrations |
|
618 | + * |
|
619 | + * @access protected |
|
620 | + * @return void |
|
621 | + * @throws DomainException |
|
622 | + */ |
|
623 | + protected function _registration_reports() |
|
624 | + { |
|
625 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
626 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
627 | + $template_path, |
|
628 | + $this->_reports_template_data, |
|
629 | + true |
|
630 | + ); |
|
631 | + // the final template wrapper |
|
632 | + $this->display_admin_page_with_no_sidebar(); |
|
633 | + } |
|
634 | 634 | |
635 | 635 | |
636 | - /** |
|
637 | - * Generates Business Report showing total registrations per day. |
|
638 | - * |
|
639 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
640 | - * @return string |
|
641 | - * @throws EE_Error |
|
642 | - * @throws InvalidArgumentException |
|
643 | - * @throws InvalidDataTypeException |
|
644 | - * @throws InvalidInterfaceException |
|
645 | - */ |
|
646 | - private function _registrations_per_day_report($period = '-1 month') |
|
647 | - { |
|
648 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
649 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
650 | - $results = (array) $results; |
|
651 | - $regs = array(); |
|
652 | - $subtitle = ''; |
|
653 | - if ($results) { |
|
654 | - $column_titles = array(); |
|
655 | - $tracker = 0; |
|
656 | - foreach ($results as $result) { |
|
657 | - $report_column_values = array(); |
|
658 | - foreach ($result as $property_name => $property_value) { |
|
659 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
660 | - : (int) $property_value; |
|
661 | - $report_column_values[] = $property_value; |
|
662 | - if ($tracker === 0) { |
|
663 | - if ($property_name === 'Registration_REG_date') { |
|
664 | - $column_titles[] = esc_html__( |
|
665 | - 'Date (only days with registrations are shown)', |
|
666 | - 'event_espresso' |
|
667 | - ); |
|
668 | - } else { |
|
669 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
670 | - } |
|
671 | - } |
|
672 | - } |
|
673 | - $tracker++; |
|
674 | - $regs[] = $report_column_values; |
|
675 | - } |
|
676 | - // make sure the column_titles is pushed to the beginning of the array |
|
677 | - array_unshift($regs, $column_titles); |
|
678 | - // setup the date range. |
|
679 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
680 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
681 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
682 | - $subtitle = sprintf( |
|
683 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
684 | - $beginning_date->format('Y-m-d'), |
|
685 | - $ending_date->format('Y-m-d') |
|
686 | - ); |
|
687 | - } |
|
688 | - $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
689 | - $report_params = array( |
|
690 | - 'title' => $report_title, |
|
691 | - 'subtitle' => $subtitle, |
|
692 | - 'id' => $report_ID, |
|
693 | - 'regs' => $regs, |
|
694 | - 'noResults' => empty($regs), |
|
695 | - 'noRegsMsg' => sprintf( |
|
696 | - esc_html__( |
|
697 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
698 | - 'event_espresso' |
|
699 | - ), |
|
700 | - '<h2>' . $report_title . '</h2><p>', |
|
701 | - '</p>' |
|
702 | - ), |
|
703 | - ); |
|
704 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
705 | - return $report_ID; |
|
706 | - } |
|
636 | + /** |
|
637 | + * Generates Business Report showing total registrations per day. |
|
638 | + * |
|
639 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
640 | + * @return string |
|
641 | + * @throws EE_Error |
|
642 | + * @throws InvalidArgumentException |
|
643 | + * @throws InvalidDataTypeException |
|
644 | + * @throws InvalidInterfaceException |
|
645 | + */ |
|
646 | + private function _registrations_per_day_report($period = '-1 month') |
|
647 | + { |
|
648 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
649 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
650 | + $results = (array) $results; |
|
651 | + $regs = array(); |
|
652 | + $subtitle = ''; |
|
653 | + if ($results) { |
|
654 | + $column_titles = array(); |
|
655 | + $tracker = 0; |
|
656 | + foreach ($results as $result) { |
|
657 | + $report_column_values = array(); |
|
658 | + foreach ($result as $property_name => $property_value) { |
|
659 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
660 | + : (int) $property_value; |
|
661 | + $report_column_values[] = $property_value; |
|
662 | + if ($tracker === 0) { |
|
663 | + if ($property_name === 'Registration_REG_date') { |
|
664 | + $column_titles[] = esc_html__( |
|
665 | + 'Date (only days with registrations are shown)', |
|
666 | + 'event_espresso' |
|
667 | + ); |
|
668 | + } else { |
|
669 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
670 | + } |
|
671 | + } |
|
672 | + } |
|
673 | + $tracker++; |
|
674 | + $regs[] = $report_column_values; |
|
675 | + } |
|
676 | + // make sure the column_titles is pushed to the beginning of the array |
|
677 | + array_unshift($regs, $column_titles); |
|
678 | + // setup the date range. |
|
679 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
680 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
681 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
682 | + $subtitle = sprintf( |
|
683 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
684 | + $beginning_date->format('Y-m-d'), |
|
685 | + $ending_date->format('Y-m-d') |
|
686 | + ); |
|
687 | + } |
|
688 | + $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
689 | + $report_params = array( |
|
690 | + 'title' => $report_title, |
|
691 | + 'subtitle' => $subtitle, |
|
692 | + 'id' => $report_ID, |
|
693 | + 'regs' => $regs, |
|
694 | + 'noResults' => empty($regs), |
|
695 | + 'noRegsMsg' => sprintf( |
|
696 | + esc_html__( |
|
697 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
698 | + 'event_espresso' |
|
699 | + ), |
|
700 | + '<h2>' . $report_title . '</h2><p>', |
|
701 | + '</p>' |
|
702 | + ), |
|
703 | + ); |
|
704 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
705 | + return $report_ID; |
|
706 | + } |
|
707 | 707 | |
708 | 708 | |
709 | - /** |
|
710 | - * Generates Business Report showing total registrations per event. |
|
711 | - * |
|
712 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
713 | - * @return string |
|
714 | - * @throws EE_Error |
|
715 | - * @throws InvalidArgumentException |
|
716 | - * @throws InvalidDataTypeException |
|
717 | - * @throws InvalidInterfaceException |
|
718 | - */ |
|
719 | - private function _registrations_per_event_report($period = '-1 month') |
|
720 | - { |
|
721 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
722 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
723 | - $results = (array) $results; |
|
724 | - $regs = array(); |
|
725 | - $subtitle = ''; |
|
726 | - if ($results) { |
|
727 | - $column_titles = array(); |
|
728 | - $tracker = 0; |
|
729 | - foreach ($results as $result) { |
|
730 | - $report_column_values = array(); |
|
731 | - foreach ($result as $property_name => $property_value) { |
|
732 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
733 | - $property_value, |
|
734 | - 4, |
|
735 | - '...' |
|
736 | - ) : (int) $property_value; |
|
737 | - $report_column_values[] = $property_value; |
|
738 | - if ($tracker === 0) { |
|
739 | - if ($property_name === 'Registration_Event') { |
|
740 | - $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
741 | - } else { |
|
742 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
743 | - } |
|
744 | - } |
|
745 | - } |
|
746 | - $tracker++; |
|
747 | - $regs[] = $report_column_values; |
|
748 | - } |
|
749 | - // make sure the column_titles is pushed to the beginning of the array |
|
750 | - array_unshift($regs, $column_titles); |
|
751 | - // setup the date range. |
|
752 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
753 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
754 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
755 | - $subtitle = sprintf( |
|
756 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
757 | - $beginning_date->format('Y-m-d'), |
|
758 | - $ending_date->format('Y-m-d') |
|
759 | - ); |
|
760 | - } |
|
761 | - $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
762 | - $report_params = array( |
|
763 | - 'title' => $report_title, |
|
764 | - 'subtitle' => $subtitle, |
|
765 | - 'id' => $report_ID, |
|
766 | - 'regs' => $regs, |
|
767 | - 'noResults' => empty($regs), |
|
768 | - 'noRegsMsg' => sprintf( |
|
769 | - esc_html__( |
|
770 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
771 | - 'event_espresso' |
|
772 | - ), |
|
773 | - '<h2>' . $report_title . '</h2><p>', |
|
774 | - '</p>' |
|
775 | - ), |
|
776 | - ); |
|
777 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
778 | - return $report_ID; |
|
779 | - } |
|
709 | + /** |
|
710 | + * Generates Business Report showing total registrations per event. |
|
711 | + * |
|
712 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
713 | + * @return string |
|
714 | + * @throws EE_Error |
|
715 | + * @throws InvalidArgumentException |
|
716 | + * @throws InvalidDataTypeException |
|
717 | + * @throws InvalidInterfaceException |
|
718 | + */ |
|
719 | + private function _registrations_per_event_report($period = '-1 month') |
|
720 | + { |
|
721 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
722 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
723 | + $results = (array) $results; |
|
724 | + $regs = array(); |
|
725 | + $subtitle = ''; |
|
726 | + if ($results) { |
|
727 | + $column_titles = array(); |
|
728 | + $tracker = 0; |
|
729 | + foreach ($results as $result) { |
|
730 | + $report_column_values = array(); |
|
731 | + foreach ($result as $property_name => $property_value) { |
|
732 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
733 | + $property_value, |
|
734 | + 4, |
|
735 | + '...' |
|
736 | + ) : (int) $property_value; |
|
737 | + $report_column_values[] = $property_value; |
|
738 | + if ($tracker === 0) { |
|
739 | + if ($property_name === 'Registration_Event') { |
|
740 | + $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
741 | + } else { |
|
742 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
743 | + } |
|
744 | + } |
|
745 | + } |
|
746 | + $tracker++; |
|
747 | + $regs[] = $report_column_values; |
|
748 | + } |
|
749 | + // make sure the column_titles is pushed to the beginning of the array |
|
750 | + array_unshift($regs, $column_titles); |
|
751 | + // setup the date range. |
|
752 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
753 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
754 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
755 | + $subtitle = sprintf( |
|
756 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
757 | + $beginning_date->format('Y-m-d'), |
|
758 | + $ending_date->format('Y-m-d') |
|
759 | + ); |
|
760 | + } |
|
761 | + $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
762 | + $report_params = array( |
|
763 | + 'title' => $report_title, |
|
764 | + 'subtitle' => $subtitle, |
|
765 | + 'id' => $report_ID, |
|
766 | + 'regs' => $regs, |
|
767 | + 'noResults' => empty($regs), |
|
768 | + 'noRegsMsg' => sprintf( |
|
769 | + esc_html__( |
|
770 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
771 | + 'event_espresso' |
|
772 | + ), |
|
773 | + '<h2>' . $report_title . '</h2><p>', |
|
774 | + '</p>' |
|
775 | + ), |
|
776 | + ); |
|
777 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
778 | + return $report_ID; |
|
779 | + } |
|
780 | 780 | |
781 | 781 | |
782 | - /** |
|
783 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
784 | - * |
|
785 | - * @access protected |
|
786 | - * @return void |
|
787 | - * @throws EE_Error |
|
788 | - * @throws InvalidArgumentException |
|
789 | - * @throws InvalidDataTypeException |
|
790 | - * @throws InvalidInterfaceException |
|
791 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
792 | - */ |
|
793 | - protected function _registration_checkin_list_table() |
|
794 | - { |
|
795 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
796 | - $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
797 | - /** @var EE_Registration $registration */ |
|
798 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
799 | - $attendee = $registration->attendee(); |
|
800 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
801 | - 'new_registration', |
|
802 | - 'add-registrant', |
|
803 | - array('event_id' => $registration->event_ID()), |
|
804 | - 'add-new-h2' |
|
805 | - ); |
|
806 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
807 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
808 | - $legend_items = array( |
|
809 | - 'checkin' => array( |
|
810 | - 'class' => $checked_in->cssClasses(), |
|
811 | - 'desc' => $checked_in->legendLabel(), |
|
812 | - ), |
|
813 | - 'checkout' => array( |
|
814 | - 'class' => $checked_out->cssClasses(), |
|
815 | - 'desc' => $checked_out->legendLabel(), |
|
816 | - ), |
|
817 | - ); |
|
818 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
819 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
820 | - /** @var EE_Datetime $datetime */ |
|
821 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
822 | - $datetime_label = ''; |
|
823 | - if ($datetime instanceof EE_Datetime) { |
|
824 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
825 | - $datetime_label .= ! empty($datetime_label) |
|
826 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
827 | - : $datetime->get_dtt_display_name(); |
|
828 | - } |
|
829 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
830 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
831 | - array( |
|
832 | - 'action' => 'event_registrations', |
|
833 | - 'event_id' => $registration->event_ID(), |
|
834 | - 'DTT_ID' => $dtt_id, |
|
835 | - ), |
|
836 | - $this->_admin_base_url |
|
837 | - ) |
|
838 | - : ''; |
|
839 | - $datetime_link = ! empty($datetime_link) |
|
840 | - ? '<a href="' . $datetime_link . '">' |
|
841 | - . '<span id="checkin-dtt">' |
|
842 | - . $datetime_label |
|
843 | - . '</span></a>' |
|
844 | - : $datetime_label; |
|
845 | - $attendee_name = $attendee instanceof EE_Attendee |
|
846 | - ? $attendee->full_name() |
|
847 | - : ''; |
|
848 | - $attendee_link = $attendee instanceof EE_Attendee |
|
849 | - ? $attendee->get_admin_details_link() |
|
850 | - : ''; |
|
851 | - $attendee_link = ! empty($attendee_link) |
|
852 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
853 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
854 | - . '<span id="checkin-attendee-name">' |
|
855 | - . $attendee_name |
|
856 | - . '</span></a>' |
|
857 | - : ''; |
|
858 | - $event_link = $registration->event() instanceof EE_Event |
|
859 | - ? $registration->event()->get_admin_details_link() |
|
860 | - : ''; |
|
861 | - $event_link = ! empty($event_link) |
|
862 | - ? '<a href="' . $event_link . '"' |
|
863 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
864 | - . '<span id="checkin-event-name">' |
|
865 | - . $registration->event_name() |
|
866 | - . '</span>' |
|
867 | - . '</a>' |
|
868 | - : ''; |
|
869 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
870 | - ? '<h2>' . sprintf( |
|
871 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
872 | - $attendee_link, |
|
873 | - $datetime_link, |
|
874 | - $event_link |
|
875 | - ) . '</h2>' |
|
876 | - : ''; |
|
877 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
878 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
879 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
880 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
881 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
882 | - } |
|
782 | + /** |
|
783 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
784 | + * |
|
785 | + * @access protected |
|
786 | + * @return void |
|
787 | + * @throws EE_Error |
|
788 | + * @throws InvalidArgumentException |
|
789 | + * @throws InvalidDataTypeException |
|
790 | + * @throws InvalidInterfaceException |
|
791 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
792 | + */ |
|
793 | + protected function _registration_checkin_list_table() |
|
794 | + { |
|
795 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
796 | + $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
797 | + /** @var EE_Registration $registration */ |
|
798 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
799 | + $attendee = $registration->attendee(); |
|
800 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
801 | + 'new_registration', |
|
802 | + 'add-registrant', |
|
803 | + array('event_id' => $registration->event_ID()), |
|
804 | + 'add-new-h2' |
|
805 | + ); |
|
806 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
807 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
808 | + $legend_items = array( |
|
809 | + 'checkin' => array( |
|
810 | + 'class' => $checked_in->cssClasses(), |
|
811 | + 'desc' => $checked_in->legendLabel(), |
|
812 | + ), |
|
813 | + 'checkout' => array( |
|
814 | + 'class' => $checked_out->cssClasses(), |
|
815 | + 'desc' => $checked_out->legendLabel(), |
|
816 | + ), |
|
817 | + ); |
|
818 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
819 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
820 | + /** @var EE_Datetime $datetime */ |
|
821 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
822 | + $datetime_label = ''; |
|
823 | + if ($datetime instanceof EE_Datetime) { |
|
824 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
825 | + $datetime_label .= ! empty($datetime_label) |
|
826 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
827 | + : $datetime->get_dtt_display_name(); |
|
828 | + } |
|
829 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
830 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
831 | + array( |
|
832 | + 'action' => 'event_registrations', |
|
833 | + 'event_id' => $registration->event_ID(), |
|
834 | + 'DTT_ID' => $dtt_id, |
|
835 | + ), |
|
836 | + $this->_admin_base_url |
|
837 | + ) |
|
838 | + : ''; |
|
839 | + $datetime_link = ! empty($datetime_link) |
|
840 | + ? '<a href="' . $datetime_link . '">' |
|
841 | + . '<span id="checkin-dtt">' |
|
842 | + . $datetime_label |
|
843 | + . '</span></a>' |
|
844 | + : $datetime_label; |
|
845 | + $attendee_name = $attendee instanceof EE_Attendee |
|
846 | + ? $attendee->full_name() |
|
847 | + : ''; |
|
848 | + $attendee_link = $attendee instanceof EE_Attendee |
|
849 | + ? $attendee->get_admin_details_link() |
|
850 | + : ''; |
|
851 | + $attendee_link = ! empty($attendee_link) |
|
852 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
853 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
854 | + . '<span id="checkin-attendee-name">' |
|
855 | + . $attendee_name |
|
856 | + . '</span></a>' |
|
857 | + : ''; |
|
858 | + $event_link = $registration->event() instanceof EE_Event |
|
859 | + ? $registration->event()->get_admin_details_link() |
|
860 | + : ''; |
|
861 | + $event_link = ! empty($event_link) |
|
862 | + ? '<a href="' . $event_link . '"' |
|
863 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
864 | + . '<span id="checkin-event-name">' |
|
865 | + . $registration->event_name() |
|
866 | + . '</span>' |
|
867 | + . '</a>' |
|
868 | + : ''; |
|
869 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
870 | + ? '<h2>' . sprintf( |
|
871 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
872 | + $attendee_link, |
|
873 | + $datetime_link, |
|
874 | + $event_link |
|
875 | + ) . '</h2>' |
|
876 | + : ''; |
|
877 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
878 | + ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
879 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
880 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
881 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
882 | + } |
|
883 | 883 | |
884 | 884 | |
885 | - /** |
|
886 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
887 | - * |
|
888 | - * @return void (JSON) |
|
889 | - * @throws EE_Error |
|
890 | - * @throws InvalidArgumentException |
|
891 | - * @throws InvalidDataTypeException |
|
892 | - * @throws InvalidInterfaceException |
|
893 | - */ |
|
894 | - public function toggle_checkin_status() |
|
895 | - { |
|
896 | - // first make sure we have the necessary data |
|
897 | - if (! isset($this->_req_data['_regid'])) { |
|
898 | - EE_Error::add_error( |
|
899 | - esc_html__( |
|
900 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
901 | - 'event_espresso' |
|
902 | - ), |
|
903 | - __FILE__, |
|
904 | - __FUNCTION__, |
|
905 | - __LINE__ |
|
906 | - ); |
|
907 | - $this->_template_args['success'] = false; |
|
908 | - $this->_template_args['error'] = true; |
|
909 | - $this->_return_json(); |
|
910 | - }; |
|
911 | - // do a nonce check cause we're not coming in from an normal route here. |
|
912 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
913 | - : ''; |
|
914 | - $nonce_ref = 'checkin_nonce'; |
|
915 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
916 | - // beautiful! Made it this far so let's get the status. |
|
917 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
918 | - // setup new class to return via ajax |
|
919 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
920 | - $this->_template_args['success'] = true; |
|
921 | - $this->_return_json(); |
|
922 | - } |
|
885 | + /** |
|
886 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
887 | + * |
|
888 | + * @return void (JSON) |
|
889 | + * @throws EE_Error |
|
890 | + * @throws InvalidArgumentException |
|
891 | + * @throws InvalidDataTypeException |
|
892 | + * @throws InvalidInterfaceException |
|
893 | + */ |
|
894 | + public function toggle_checkin_status() |
|
895 | + { |
|
896 | + // first make sure we have the necessary data |
|
897 | + if (! isset($this->_req_data['_regid'])) { |
|
898 | + EE_Error::add_error( |
|
899 | + esc_html__( |
|
900 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
901 | + 'event_espresso' |
|
902 | + ), |
|
903 | + __FILE__, |
|
904 | + __FUNCTION__, |
|
905 | + __LINE__ |
|
906 | + ); |
|
907 | + $this->_template_args['success'] = false; |
|
908 | + $this->_template_args['error'] = true; |
|
909 | + $this->_return_json(); |
|
910 | + }; |
|
911 | + // do a nonce check cause we're not coming in from an normal route here. |
|
912 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
913 | + : ''; |
|
914 | + $nonce_ref = 'checkin_nonce'; |
|
915 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
916 | + // beautiful! Made it this far so let's get the status. |
|
917 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
918 | + // setup new class to return via ajax |
|
919 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
920 | + $this->_template_args['success'] = true; |
|
921 | + $this->_return_json(); |
|
922 | + } |
|
923 | 923 | |
924 | 924 | |
925 | - /** |
|
926 | - * handles toggling the checkin status for the registration, |
|
927 | - * |
|
928 | - * @access protected |
|
929 | - * @return int|void |
|
930 | - * @throws EE_Error |
|
931 | - * @throws InvalidArgumentException |
|
932 | - * @throws InvalidDataTypeException |
|
933 | - * @throws InvalidInterfaceException |
|
934 | - */ |
|
935 | - protected function _toggle_checkin_status() |
|
936 | - { |
|
937 | - // first let's get the query args out of the way for the redirect |
|
938 | - $query_args = array( |
|
939 | - 'action' => 'event_registrations', |
|
940 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
941 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
942 | - ); |
|
943 | - $new_status = false; |
|
944 | - // bulk action check in toggle |
|
945 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
946 | - // cycle thru checkboxes |
|
947 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
948 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
949 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
950 | - } |
|
951 | - } elseif (isset($this->_req_data['_regid'])) { |
|
952 | - // coming from ajax request |
|
953 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
954 | - $query_args['DTT_ID'] = $DTT_ID; |
|
955 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
956 | - } else { |
|
957 | - EE_Error::add_error( |
|
958 | - esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
959 | - __FILE__, |
|
960 | - __FUNCTION__, |
|
961 | - __LINE__ |
|
962 | - ); |
|
963 | - } |
|
964 | - if (defined('DOING_AJAX')) { |
|
965 | - return $new_status; |
|
966 | - } |
|
967 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
968 | - } |
|
925 | + /** |
|
926 | + * handles toggling the checkin status for the registration, |
|
927 | + * |
|
928 | + * @access protected |
|
929 | + * @return int|void |
|
930 | + * @throws EE_Error |
|
931 | + * @throws InvalidArgumentException |
|
932 | + * @throws InvalidDataTypeException |
|
933 | + * @throws InvalidInterfaceException |
|
934 | + */ |
|
935 | + protected function _toggle_checkin_status() |
|
936 | + { |
|
937 | + // first let's get the query args out of the way for the redirect |
|
938 | + $query_args = array( |
|
939 | + 'action' => 'event_registrations', |
|
940 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
941 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
942 | + ); |
|
943 | + $new_status = false; |
|
944 | + // bulk action check in toggle |
|
945 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
946 | + // cycle thru checkboxes |
|
947 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
948 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
949 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
950 | + } |
|
951 | + } elseif (isset($this->_req_data['_regid'])) { |
|
952 | + // coming from ajax request |
|
953 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
954 | + $query_args['DTT_ID'] = $DTT_ID; |
|
955 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
956 | + } else { |
|
957 | + EE_Error::add_error( |
|
958 | + esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
959 | + __FILE__, |
|
960 | + __FUNCTION__, |
|
961 | + __LINE__ |
|
962 | + ); |
|
963 | + } |
|
964 | + if (defined('DOING_AJAX')) { |
|
965 | + return $new_status; |
|
966 | + } |
|
967 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
968 | + } |
|
969 | 969 | |
970 | 970 | |
971 | - /** |
|
972 | - * This is toggles a single Check-in for the given registration and datetime. |
|
973 | - * |
|
974 | - * @param int $REG_ID The registration we're toggling |
|
975 | - * @param int $DTT_ID The datetime we're toggling |
|
976 | - * @return int The new status toggled to. |
|
977 | - * @throws EE_Error |
|
978 | - * @throws InvalidArgumentException |
|
979 | - * @throws InvalidDataTypeException |
|
980 | - * @throws InvalidInterfaceException |
|
981 | - */ |
|
982 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
983 | - { |
|
984 | - /** @var EE_Registration $REG */ |
|
985 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
986 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
987 | - if ($new_status !== false) { |
|
988 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
989 | - } else { |
|
990 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
991 | - $new_status = false; |
|
992 | - } |
|
993 | - return $new_status; |
|
994 | - } |
|
971 | + /** |
|
972 | + * This is toggles a single Check-in for the given registration and datetime. |
|
973 | + * |
|
974 | + * @param int $REG_ID The registration we're toggling |
|
975 | + * @param int $DTT_ID The datetime we're toggling |
|
976 | + * @return int The new status toggled to. |
|
977 | + * @throws EE_Error |
|
978 | + * @throws InvalidArgumentException |
|
979 | + * @throws InvalidDataTypeException |
|
980 | + * @throws InvalidInterfaceException |
|
981 | + */ |
|
982 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
983 | + { |
|
984 | + /** @var EE_Registration $REG */ |
|
985 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
986 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
987 | + if ($new_status !== false) { |
|
988 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
989 | + } else { |
|
990 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
991 | + $new_status = false; |
|
992 | + } |
|
993 | + return $new_status; |
|
994 | + } |
|
995 | 995 | |
996 | 996 | |
997 | - /** |
|
998 | - * Takes care of deleting multiple EE_Checkin table rows |
|
999 | - * |
|
1000 | - * @access protected |
|
1001 | - * @return void |
|
1002 | - * @throws EE_Error |
|
1003 | - * @throws InvalidArgumentException |
|
1004 | - * @throws InvalidDataTypeException |
|
1005 | - * @throws InvalidInterfaceException |
|
1006 | - */ |
|
1007 | - protected function _delete_checkin_rows() |
|
1008 | - { |
|
1009 | - $query_args = array( |
|
1010 | - 'action' => 'registration_checkins', |
|
1011 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1012 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1013 | - ); |
|
1014 | - $errors = 0; |
|
1015 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1016 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1017 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
1018 | - $errors++; |
|
1019 | - } |
|
1020 | - } |
|
1021 | - } else { |
|
1022 | - EE_Error::add_error( |
|
1023 | - esc_html__( |
|
1024 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
1025 | - 'event_espresso' |
|
1026 | - ), |
|
1027 | - __FILE__, |
|
1028 | - __FUNCTION__, |
|
1029 | - __LINE__ |
|
1030 | - ); |
|
1031 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1032 | - } |
|
1033 | - if ($errors > 0) { |
|
1034 | - EE_Error::add_error( |
|
1035 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
1036 | - __FILE__, |
|
1037 | - __FUNCTION__, |
|
1038 | - __LINE__ |
|
1039 | - ); |
|
1040 | - } else { |
|
1041 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
1042 | - } |
|
1043 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1044 | - } |
|
997 | + /** |
|
998 | + * Takes care of deleting multiple EE_Checkin table rows |
|
999 | + * |
|
1000 | + * @access protected |
|
1001 | + * @return void |
|
1002 | + * @throws EE_Error |
|
1003 | + * @throws InvalidArgumentException |
|
1004 | + * @throws InvalidDataTypeException |
|
1005 | + * @throws InvalidInterfaceException |
|
1006 | + */ |
|
1007 | + protected function _delete_checkin_rows() |
|
1008 | + { |
|
1009 | + $query_args = array( |
|
1010 | + 'action' => 'registration_checkins', |
|
1011 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1012 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1013 | + ); |
|
1014 | + $errors = 0; |
|
1015 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1016 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1017 | + if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
1018 | + $errors++; |
|
1019 | + } |
|
1020 | + } |
|
1021 | + } else { |
|
1022 | + EE_Error::add_error( |
|
1023 | + esc_html__( |
|
1024 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
1025 | + 'event_espresso' |
|
1026 | + ), |
|
1027 | + __FILE__, |
|
1028 | + __FUNCTION__, |
|
1029 | + __LINE__ |
|
1030 | + ); |
|
1031 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1032 | + } |
|
1033 | + if ($errors > 0) { |
|
1034 | + EE_Error::add_error( |
|
1035 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
1036 | + __FILE__, |
|
1037 | + __FUNCTION__, |
|
1038 | + __LINE__ |
|
1039 | + ); |
|
1040 | + } else { |
|
1041 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
1042 | + } |
|
1043 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1044 | + } |
|
1045 | 1045 | |
1046 | 1046 | |
1047 | - /** |
|
1048 | - * Deletes a single EE_Checkin row |
|
1049 | - * |
|
1050 | - * @return void |
|
1051 | - * @throws EE_Error |
|
1052 | - * @throws InvalidArgumentException |
|
1053 | - * @throws InvalidDataTypeException |
|
1054 | - * @throws InvalidInterfaceException |
|
1055 | - */ |
|
1056 | - protected function _delete_checkin_row() |
|
1057 | - { |
|
1058 | - $query_args = array( |
|
1059 | - 'action' => 'registration_checkins', |
|
1060 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1061 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1062 | - ); |
|
1063 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
1064 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1065 | - EE_Error::add_error( |
|
1066 | - esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
1067 | - __FILE__, |
|
1068 | - __FUNCTION__, |
|
1069 | - __LINE__ |
|
1070 | - ); |
|
1071 | - } else { |
|
1072 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1073 | - } |
|
1074 | - } else { |
|
1075 | - EE_Error::add_error( |
|
1076 | - esc_html__( |
|
1077 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1078 | - 'event_espresso' |
|
1079 | - ), |
|
1080 | - __FILE__, |
|
1081 | - __FUNCTION__, |
|
1082 | - __LINE__ |
|
1083 | - ); |
|
1084 | - } |
|
1085 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1086 | - } |
|
1047 | + /** |
|
1048 | + * Deletes a single EE_Checkin row |
|
1049 | + * |
|
1050 | + * @return void |
|
1051 | + * @throws EE_Error |
|
1052 | + * @throws InvalidArgumentException |
|
1053 | + * @throws InvalidDataTypeException |
|
1054 | + * @throws InvalidInterfaceException |
|
1055 | + */ |
|
1056 | + protected function _delete_checkin_row() |
|
1057 | + { |
|
1058 | + $query_args = array( |
|
1059 | + 'action' => 'registration_checkins', |
|
1060 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1061 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1062 | + ); |
|
1063 | + if (! empty($this->_req_data['CHK_ID'])) { |
|
1064 | + if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1065 | + EE_Error::add_error( |
|
1066 | + esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
1067 | + __FILE__, |
|
1068 | + __FUNCTION__, |
|
1069 | + __LINE__ |
|
1070 | + ); |
|
1071 | + } else { |
|
1072 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1073 | + } |
|
1074 | + } else { |
|
1075 | + EE_Error::add_error( |
|
1076 | + esc_html__( |
|
1077 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1078 | + 'event_espresso' |
|
1079 | + ), |
|
1080 | + __FILE__, |
|
1081 | + __FUNCTION__, |
|
1082 | + __LINE__ |
|
1083 | + ); |
|
1084 | + } |
|
1085 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1086 | + } |
|
1087 | 1087 | |
1088 | 1088 | |
1089 | - /** |
|
1090 | - * generates HTML for the Event Registrations List Table |
|
1091 | - * |
|
1092 | - * @access protected |
|
1093 | - * @return void |
|
1094 | - * @throws EE_Error |
|
1095 | - * @throws InvalidArgumentException |
|
1096 | - * @throws InvalidDataTypeException |
|
1097 | - * @throws InvalidInterfaceException |
|
1098 | - */ |
|
1099 | - protected function _event_registrations_list_table() |
|
1100 | - { |
|
1101 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1102 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1103 | - ? $this->get_action_link_or_button( |
|
1104 | - 'new_registration', |
|
1105 | - 'add-registrant', |
|
1106 | - array('event_id' => $this->_req_data['event_id']), |
|
1107 | - 'add-new-h2', |
|
1108 | - '', |
|
1109 | - false |
|
1110 | - ) |
|
1111 | - : ''; |
|
1112 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1113 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1114 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1115 | - $legend_items = array( |
|
1116 | - 'star-icon' => array( |
|
1117 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1118 | - 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1119 | - ), |
|
1120 | - 'checkin' => array( |
|
1121 | - 'class' => $checked_in->cssClasses(), |
|
1122 | - 'desc' => $checked_in->legendLabel(), |
|
1123 | - ), |
|
1124 | - 'checkout' => array( |
|
1125 | - 'class' => $checked_out->cssClasses(), |
|
1126 | - 'desc' => $checked_out->legendLabel(), |
|
1127 | - ), |
|
1128 | - 'nocheckinrecord' => array( |
|
1129 | - 'class' => $checked_never->cssClasses(), |
|
1130 | - 'desc' => $checked_never->legendLabel(), |
|
1131 | - ), |
|
1132 | - 'approved_status' => array( |
|
1133 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1134 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1135 | - ), |
|
1136 | - 'cancelled_status' => array( |
|
1137 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1138 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1139 | - ), |
|
1140 | - 'declined_status' => array( |
|
1141 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1142 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1143 | - ), |
|
1144 | - 'not_approved' => array( |
|
1145 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1146 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1147 | - ), |
|
1148 | - 'pending_status' => array( |
|
1149 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1150 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1151 | - ), |
|
1152 | - 'wait_list' => array( |
|
1153 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1154 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1155 | - ), |
|
1156 | - ); |
|
1157 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1158 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1159 | - $this->_template_args['before_list_table'] = ! empty($event_id) |
|
1160 | - ? '<h2>' . sprintf( |
|
1161 | - esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1162 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1163 | - ) . '</h2>' |
|
1164 | - : ''; |
|
1165 | - // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
1166 | - // the event. |
|
1167 | - /** @var EE_Event $event */ |
|
1168 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1169 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1170 | - $datetime = null; |
|
1171 | - if ($event instanceof EE_Event) { |
|
1172 | - $datetimes_on_event = $event->datetimes(); |
|
1173 | - if (count($datetimes_on_event) === 1) { |
|
1174 | - $datetime = reset($datetimes_on_event); |
|
1175 | - } |
|
1176 | - } |
|
1177 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1178 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1179 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1180 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1181 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1182 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1183 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1184 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1185 | - } |
|
1186 | - // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
1187 | - // column represents |
|
1188 | - if (! $datetime instanceof EE_Datetime) { |
|
1189 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1190 | - . esc_html__( |
|
1191 | - 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1192 | - 'event_espresso' |
|
1193 | - ) |
|
1194 | - . '</p>'; |
|
1195 | - } |
|
1196 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1197 | - } |
|
1089 | + /** |
|
1090 | + * generates HTML for the Event Registrations List Table |
|
1091 | + * |
|
1092 | + * @access protected |
|
1093 | + * @return void |
|
1094 | + * @throws EE_Error |
|
1095 | + * @throws InvalidArgumentException |
|
1096 | + * @throws InvalidDataTypeException |
|
1097 | + * @throws InvalidInterfaceException |
|
1098 | + */ |
|
1099 | + protected function _event_registrations_list_table() |
|
1100 | + { |
|
1101 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1102 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1103 | + ? $this->get_action_link_or_button( |
|
1104 | + 'new_registration', |
|
1105 | + 'add-registrant', |
|
1106 | + array('event_id' => $this->_req_data['event_id']), |
|
1107 | + 'add-new-h2', |
|
1108 | + '', |
|
1109 | + false |
|
1110 | + ) |
|
1111 | + : ''; |
|
1112 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1113 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1114 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1115 | + $legend_items = array( |
|
1116 | + 'star-icon' => array( |
|
1117 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1118 | + 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1119 | + ), |
|
1120 | + 'checkin' => array( |
|
1121 | + 'class' => $checked_in->cssClasses(), |
|
1122 | + 'desc' => $checked_in->legendLabel(), |
|
1123 | + ), |
|
1124 | + 'checkout' => array( |
|
1125 | + 'class' => $checked_out->cssClasses(), |
|
1126 | + 'desc' => $checked_out->legendLabel(), |
|
1127 | + ), |
|
1128 | + 'nocheckinrecord' => array( |
|
1129 | + 'class' => $checked_never->cssClasses(), |
|
1130 | + 'desc' => $checked_never->legendLabel(), |
|
1131 | + ), |
|
1132 | + 'approved_status' => array( |
|
1133 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1134 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1135 | + ), |
|
1136 | + 'cancelled_status' => array( |
|
1137 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1138 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1139 | + ), |
|
1140 | + 'declined_status' => array( |
|
1141 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1142 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1143 | + ), |
|
1144 | + 'not_approved' => array( |
|
1145 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1146 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1147 | + ), |
|
1148 | + 'pending_status' => array( |
|
1149 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1150 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1151 | + ), |
|
1152 | + 'wait_list' => array( |
|
1153 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1154 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1155 | + ), |
|
1156 | + ); |
|
1157 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1158 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1159 | + $this->_template_args['before_list_table'] = ! empty($event_id) |
|
1160 | + ? '<h2>' . sprintf( |
|
1161 | + esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1162 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1163 | + ) . '</h2>' |
|
1164 | + : ''; |
|
1165 | + // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
1166 | + // the event. |
|
1167 | + /** @var EE_Event $event */ |
|
1168 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1169 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1170 | + $datetime = null; |
|
1171 | + if ($event instanceof EE_Event) { |
|
1172 | + $datetimes_on_event = $event->datetimes(); |
|
1173 | + if (count($datetimes_on_event) === 1) { |
|
1174 | + $datetime = reset($datetimes_on_event); |
|
1175 | + } |
|
1176 | + } |
|
1177 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1178 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1179 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1180 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1181 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1182 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1183 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1184 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1185 | + } |
|
1186 | + // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
1187 | + // column represents |
|
1188 | + if (! $datetime instanceof EE_Datetime) { |
|
1189 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1190 | + . esc_html__( |
|
1191 | + 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1192 | + 'event_espresso' |
|
1193 | + ) |
|
1194 | + . '</p>'; |
|
1195 | + } |
|
1196 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1197 | + } |
|
1198 | 1198 | |
1199 | - /** |
|
1200 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1201 | - * conditions) |
|
1202 | - * |
|
1203 | - * @return void ends the request by a redirect or download |
|
1204 | - */ |
|
1205 | - public function _registrations_checkin_report() |
|
1206 | - { |
|
1207 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1208 | - } |
|
1199 | + /** |
|
1200 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1201 | + * conditions) |
|
1202 | + * |
|
1203 | + * @return void ends the request by a redirect or download |
|
1204 | + */ |
|
1205 | + public function _registrations_checkin_report() |
|
1206 | + { |
|
1207 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1208 | + } |
|
1209 | 1209 | |
1210 | - /** |
|
1211 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1212 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1213 | - * |
|
1214 | - * @param array $request |
|
1215 | - * @param int $per_page |
|
1216 | - * @param bool $count |
|
1217 | - * @return array |
|
1218 | - * @throws EE_Error |
|
1219 | - */ |
|
1220 | - protected function _get_checkin_query_params_from_request( |
|
1221 | - $request, |
|
1222 | - $per_page = 10, |
|
1223 | - $count = false |
|
1224 | - ) { |
|
1225 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1226 | - // unlike the regular registrations list table, |
|
1227 | - $status_ids_array = apply_filters( |
|
1228 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1229 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1230 | - ); |
|
1231 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1232 | - return $query_params; |
|
1233 | - } |
|
1210 | + /** |
|
1211 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1212 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1213 | + * |
|
1214 | + * @param array $request |
|
1215 | + * @param int $per_page |
|
1216 | + * @param bool $count |
|
1217 | + * @return array |
|
1218 | + * @throws EE_Error |
|
1219 | + */ |
|
1220 | + protected function _get_checkin_query_params_from_request( |
|
1221 | + $request, |
|
1222 | + $per_page = 10, |
|
1223 | + $count = false |
|
1224 | + ) { |
|
1225 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1226 | + // unlike the regular registrations list table, |
|
1227 | + $status_ids_array = apply_filters( |
|
1228 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1229 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1230 | + ); |
|
1231 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1232 | + return $query_params; |
|
1233 | + } |
|
1234 | 1234 | |
1235 | 1235 | |
1236 | - /** |
|
1237 | - * Gets registrations for an event |
|
1238 | - * |
|
1239 | - * @param int $per_page |
|
1240 | - * @param bool $count whether to return count or data. |
|
1241 | - * @param bool $trash |
|
1242 | - * @param string $orderby |
|
1243 | - * @return EE_Registration[]|int |
|
1244 | - * @throws EE_Error |
|
1245 | - * @throws InvalidArgumentException |
|
1246 | - * @throws InvalidDataTypeException |
|
1247 | - * @throws InvalidInterfaceException |
|
1248 | - */ |
|
1249 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1250 | - { |
|
1251 | - // normalize some request params that get setup by the parent `get_registrations` method. |
|
1252 | - $request = $this->_req_data; |
|
1253 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1254 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1255 | - if ($trash) { |
|
1256 | - $request['status'] = 'trash'; |
|
1257 | - } |
|
1258 | - $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
1259 | - /** |
|
1260 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1261 | - * |
|
1262 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1263 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1264 | - * or if you have the development copy of EE you can view this at the path: |
|
1265 | - * /docs/G--Model-System/model-query-params.md |
|
1266 | - */ |
|
1267 | - $query_params['group_by'] = ''; |
|
1236 | + /** |
|
1237 | + * Gets registrations for an event |
|
1238 | + * |
|
1239 | + * @param int $per_page |
|
1240 | + * @param bool $count whether to return count or data. |
|
1241 | + * @param bool $trash |
|
1242 | + * @param string $orderby |
|
1243 | + * @return EE_Registration[]|int |
|
1244 | + * @throws EE_Error |
|
1245 | + * @throws InvalidArgumentException |
|
1246 | + * @throws InvalidDataTypeException |
|
1247 | + * @throws InvalidInterfaceException |
|
1248 | + */ |
|
1249 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1250 | + { |
|
1251 | + // normalize some request params that get setup by the parent `get_registrations` method. |
|
1252 | + $request = $this->_req_data; |
|
1253 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1254 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1255 | + if ($trash) { |
|
1256 | + $request['status'] = 'trash'; |
|
1257 | + } |
|
1258 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
1259 | + /** |
|
1260 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1261 | + * |
|
1262 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1263 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1264 | + * or if you have the development copy of EE you can view this at the path: |
|
1265 | + * /docs/G--Model-System/model-query-params.md |
|
1266 | + */ |
|
1267 | + $query_params['group_by'] = ''; |
|
1268 | 1268 | |
1269 | - return $count |
|
1270 | - ? EEM_Registration::instance()->count($query_params) |
|
1271 | - /** @type EE_Registration[] */ |
|
1272 | - : EEM_Registration::instance()->get_all($query_params); |
|
1273 | - } |
|
1269 | + return $count |
|
1270 | + ? EEM_Registration::instance()->count($query_params) |
|
1271 | + /** @type EE_Registration[] */ |
|
1272 | + : EEM_Registration::instance()->get_all($query_params); |
|
1273 | + } |
|
1274 | 1274 | } |
@@ -14,178 +14,178 @@ |
||
14 | 14 | class EEH_Sideloader extends EEH_Base |
15 | 15 | { |
16 | 16 | |
17 | - private $_upload_to; |
|
18 | - private $_upload_from; |
|
19 | - private $_permissions; |
|
20 | - private $_new_file_name; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * constructor allows the user to set the properties on the sideloader on construct. However, there are also setters for doing so. |
|
25 | - * |
|
26 | - * @access public |
|
27 | - * @param array $init array fo initializing the sideloader if keys match the properties. |
|
28 | - */ |
|
29 | - public function __construct($init = array()) |
|
30 | - { |
|
31 | - $this->_init($init); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * sets the properties for class either to defaults or using incoming initialization array |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @param array $init array on init (keys match properties others ignored) |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - private function _init($init) |
|
43 | - { |
|
44 | - $defaults = array( |
|
45 | - '_upload_to' => $this->_get_wp_uploads_dir(), |
|
46 | - '_upload_from' => '', |
|
47 | - '_permissions' => 0644, |
|
48 | - '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
49 | - ); |
|
50 | - |
|
51 | - $props = array_merge($defaults, $init); |
|
52 | - |
|
53 | - foreach ($props as $key => $val) { |
|
54 | - if (EEH_Class_Tools::has_property($this, $key)) { |
|
55 | - $this->{$key} = $val; |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - // make sure we include the required wp file for needed functions |
|
60 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - // utilities |
|
65 | - private function _get_wp_uploads_dir() |
|
66 | - { |
|
67 | - } |
|
68 | - |
|
69 | - // setters |
|
70 | - public function set_upload_to($upload_to_folder) |
|
71 | - { |
|
72 | - $this->_upload_to = $upload_to_folder; |
|
73 | - } |
|
74 | - public function set_upload_from($upload_from_folder) |
|
75 | - { |
|
76 | - $this->_upload_from_folder = $upload_from_folder; |
|
77 | - } |
|
78 | - public function set_permissions($permissions) |
|
79 | - { |
|
80 | - $this->_permissions = $permissions; |
|
81 | - } |
|
82 | - public function set_new_file_name($new_file_name) |
|
83 | - { |
|
84 | - $this->_new_file_name = $new_file_name; |
|
85 | - } |
|
86 | - |
|
87 | - // getters |
|
88 | - public function get_upload_to() |
|
89 | - { |
|
90 | - return $this->_upload_to; |
|
91 | - } |
|
92 | - public function get_upload_from() |
|
93 | - { |
|
94 | - return $this->_upload_from; |
|
95 | - } |
|
96 | - public function get_permissions() |
|
97 | - { |
|
98 | - return $this->_permissions; |
|
99 | - } |
|
100 | - public function get_new_file_name() |
|
101 | - { |
|
102 | - return $this->_new_file_name; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - // upload methods |
|
107 | - public function sideload() |
|
108 | - { |
|
109 | - // setup temp dir |
|
110 | - $temp_file = wp_tempnam($this->_upload_from); |
|
111 | - |
|
112 | - if (!$temp_file) { |
|
113 | - EE_Error::add_error( |
|
114 | - esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
|
115 | - __FILE__, |
|
116 | - __FUNCTION__, |
|
117 | - __LINE__ |
|
118 | - ); |
|
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
123 | - |
|
124 | - $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
125 | - |
|
126 | - $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args); |
|
127 | - |
|
128 | - if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
129 | - unlink($temp_file); |
|
130 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
131 | - EE_Error::add_error( |
|
132 | - sprintf( |
|
133 | - esc_html__('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'), |
|
134 | - $this->_upload_from |
|
135 | - ), |
|
136 | - __FILE__, |
|
137 | - __FUNCTION__, |
|
138 | - __LINE__ |
|
139 | - ); |
|
140 | - } |
|
141 | - return false; |
|
142 | - } |
|
143 | - |
|
144 | - // possible md5 check |
|
145 | - $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
146 | - if ($content_md5) { |
|
147 | - $md5_check = verify_file_md5($temp_file, $content_md5); |
|
148 | - if (is_wp_error($md5_check)) { |
|
149 | - unlink($temp_file); |
|
150 | - EE_Error::add_error( |
|
151 | - $md5_check->get_error_message(), |
|
152 | - __FILE__, |
|
153 | - __FUNCTION__, |
|
154 | - __LINE__ |
|
155 | - ); |
|
156 | - return false; |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - $file = $temp_file; |
|
161 | - |
|
162 | - // now we have the file, let's get it in the right directory with the right name. |
|
163 | - $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
164 | - |
|
165 | - // move file in |
|
166 | - if (false === @ rename($file, $path)) { |
|
167 | - unlink($temp_file); |
|
168 | - EE_Error::add_error( |
|
169 | - sprintf( |
|
170 | - esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), |
|
171 | - $path |
|
172 | - ), |
|
173 | - __FILE__, |
|
174 | - __FUNCTION__, |
|
175 | - __LINE__ |
|
176 | - ); |
|
177 | - return false; |
|
178 | - } |
|
179 | - |
|
180 | - // set permissions |
|
181 | - $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
182 | - chmod($path, $permissions); |
|
183 | - |
|
184 | - // that's it. let's allow for actions after file uploaded. |
|
185 | - do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
186 | - |
|
187 | - // unlink tempfile |
|
188 | - @unlink($temp_file); |
|
189 | - return true; |
|
190 | - } |
|
17 | + private $_upload_to; |
|
18 | + private $_upload_from; |
|
19 | + private $_permissions; |
|
20 | + private $_new_file_name; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * constructor allows the user to set the properties on the sideloader on construct. However, there are also setters for doing so. |
|
25 | + * |
|
26 | + * @access public |
|
27 | + * @param array $init array fo initializing the sideloader if keys match the properties. |
|
28 | + */ |
|
29 | + public function __construct($init = array()) |
|
30 | + { |
|
31 | + $this->_init($init); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * sets the properties for class either to defaults or using incoming initialization array |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @param array $init array on init (keys match properties others ignored) |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + private function _init($init) |
|
43 | + { |
|
44 | + $defaults = array( |
|
45 | + '_upload_to' => $this->_get_wp_uploads_dir(), |
|
46 | + '_upload_from' => '', |
|
47 | + '_permissions' => 0644, |
|
48 | + '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
49 | + ); |
|
50 | + |
|
51 | + $props = array_merge($defaults, $init); |
|
52 | + |
|
53 | + foreach ($props as $key => $val) { |
|
54 | + if (EEH_Class_Tools::has_property($this, $key)) { |
|
55 | + $this->{$key} = $val; |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + // make sure we include the required wp file for needed functions |
|
60 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + // utilities |
|
65 | + private function _get_wp_uploads_dir() |
|
66 | + { |
|
67 | + } |
|
68 | + |
|
69 | + // setters |
|
70 | + public function set_upload_to($upload_to_folder) |
|
71 | + { |
|
72 | + $this->_upload_to = $upload_to_folder; |
|
73 | + } |
|
74 | + public function set_upload_from($upload_from_folder) |
|
75 | + { |
|
76 | + $this->_upload_from_folder = $upload_from_folder; |
|
77 | + } |
|
78 | + public function set_permissions($permissions) |
|
79 | + { |
|
80 | + $this->_permissions = $permissions; |
|
81 | + } |
|
82 | + public function set_new_file_name($new_file_name) |
|
83 | + { |
|
84 | + $this->_new_file_name = $new_file_name; |
|
85 | + } |
|
86 | + |
|
87 | + // getters |
|
88 | + public function get_upload_to() |
|
89 | + { |
|
90 | + return $this->_upload_to; |
|
91 | + } |
|
92 | + public function get_upload_from() |
|
93 | + { |
|
94 | + return $this->_upload_from; |
|
95 | + } |
|
96 | + public function get_permissions() |
|
97 | + { |
|
98 | + return $this->_permissions; |
|
99 | + } |
|
100 | + public function get_new_file_name() |
|
101 | + { |
|
102 | + return $this->_new_file_name; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + // upload methods |
|
107 | + public function sideload() |
|
108 | + { |
|
109 | + // setup temp dir |
|
110 | + $temp_file = wp_tempnam($this->_upload_from); |
|
111 | + |
|
112 | + if (!$temp_file) { |
|
113 | + EE_Error::add_error( |
|
114 | + esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
|
115 | + __FILE__, |
|
116 | + __FUNCTION__, |
|
117 | + __LINE__ |
|
118 | + ); |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
123 | + |
|
124 | + $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
125 | + |
|
126 | + $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args); |
|
127 | + |
|
128 | + if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
129 | + unlink($temp_file); |
|
130 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
131 | + EE_Error::add_error( |
|
132 | + sprintf( |
|
133 | + esc_html__('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'), |
|
134 | + $this->_upload_from |
|
135 | + ), |
|
136 | + __FILE__, |
|
137 | + __FUNCTION__, |
|
138 | + __LINE__ |
|
139 | + ); |
|
140 | + } |
|
141 | + return false; |
|
142 | + } |
|
143 | + |
|
144 | + // possible md5 check |
|
145 | + $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
146 | + if ($content_md5) { |
|
147 | + $md5_check = verify_file_md5($temp_file, $content_md5); |
|
148 | + if (is_wp_error($md5_check)) { |
|
149 | + unlink($temp_file); |
|
150 | + EE_Error::add_error( |
|
151 | + $md5_check->get_error_message(), |
|
152 | + __FILE__, |
|
153 | + __FUNCTION__, |
|
154 | + __LINE__ |
|
155 | + ); |
|
156 | + return false; |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + $file = $temp_file; |
|
161 | + |
|
162 | + // now we have the file, let's get it in the right directory with the right name. |
|
163 | + $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
164 | + |
|
165 | + // move file in |
|
166 | + if (false === @ rename($file, $path)) { |
|
167 | + unlink($temp_file); |
|
168 | + EE_Error::add_error( |
|
169 | + sprintf( |
|
170 | + esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), |
|
171 | + $path |
|
172 | + ), |
|
173 | + __FILE__, |
|
174 | + __FUNCTION__, |
|
175 | + __LINE__ |
|
176 | + ); |
|
177 | + return false; |
|
178 | + } |
|
179 | + |
|
180 | + // set permissions |
|
181 | + $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
182 | + chmod($path, $permissions); |
|
183 | + |
|
184 | + // that's it. let's allow for actions after file uploaded. |
|
185 | + do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
186 | + |
|
187 | + // unlink tempfile |
|
188 | + @unlink($temp_file); |
|
189 | + return true; |
|
190 | + } |
|
191 | 191 | } //end EEH_Template class |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | '_upload_to' => $this->_get_wp_uploads_dir(), |
46 | 46 | '_upload_from' => '', |
47 | 47 | '_permissions' => 0644, |
48 | - '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
48 | + '_new_file_name' => 'EE_Sideloader_'.uniqid().'.default' |
|
49 | 49 | ); |
50 | 50 | |
51 | 51 | $props = array_merge($defaults, $init); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | // make sure we include the required wp file for needed functions |
60 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
60 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | // setup temp dir |
110 | 110 | $temp_file = wp_tempnam($this->_upload_from); |
111 | 111 | |
112 | - if (!$temp_file) { |
|
112 | + if ( ! $temp_file) { |
|
113 | 113 | EE_Error::add_error( |
114 | 114 | esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
115 | 115 | __FILE__, |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
123 | 123 | |
124 | - $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
124 | + $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array('timeout' => 500, 'stream' => true, 'filename' => $temp_file), $this, $temp_file); |
|
125 | 125 | |
126 | 126 | $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args); |
127 | 127 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $file = $temp_file; |
161 | 161 | |
162 | 162 | // now we have the file, let's get it in the right directory with the right name. |
163 | - $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
163 | + $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to.$this->_new_file_name, $this); |
|
164 | 164 | |
165 | 165 | // move file in |
166 | 166 | if (false === @ rename($file, $path)) { |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | $stages = glob(EE_CORE . 'data_migration_scripts/4_10_0_stages/*'); |
17 | 17 | $class_to_filepath = []; |
18 | 18 | foreach ($stages as $filepath) { |
19 | - $matches = []; |
|
20 | - preg_match('~4_10_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
21 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
19 | + $matches = []; |
|
20 | + preg_match('~4_10_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
21 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
22 | 22 | } |
23 | 23 | // give addons a chance to autoload their stages too |
24 | 24 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_10_0__autoloaded_stages', $class_to_filepath); |
@@ -36,77 +36,77 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class EE_DMS_Core_4_10_0 extends EE_Data_Migration_Script_Base |
38 | 38 | { |
39 | - /** |
|
40 | - * @var EE_DMS_Core_4_9_0 |
|
41 | - */ |
|
42 | - protected $dms_4_9; |
|
39 | + /** |
|
40 | + * @var EE_DMS_Core_4_9_0 |
|
41 | + */ |
|
42 | + protected $dms_4_9; |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * @param TableManager $table_manager |
|
47 | - * @param TableAnalysis $table_analysis |
|
48 | - */ |
|
49 | - public function __construct( |
|
50 | - TableManager $table_manager = null, |
|
51 | - TableAnalysis $table_analysis = null, |
|
52 | - EE_DMS_Core_4_9_0 $dms_4_9 |
|
53 | - ) { |
|
54 | - if (! $dms_4_9 instanceof EE_DMS_Core_4_9_0) { |
|
55 | - $dms_4_9 = LoaderFactory::getLoader()->getShared('EE_DMS_Core_4_9_0'); |
|
56 | - } |
|
57 | - $this->dms_4_9 = $dms_4_9; |
|
58 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.10.0", "event_espresso"); |
|
59 | - $this->_priority = 10; |
|
60 | - $this->_migration_stages = array( |
|
61 | - new EE_DMS_4_10_0_Event_Question_Group(), |
|
62 | - ); |
|
63 | - parent::__construct($table_manager, $table_analysis); |
|
64 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * @param TableManager $table_manager |
|
47 | + * @param TableAnalysis $table_analysis |
|
48 | + */ |
|
49 | + public function __construct( |
|
50 | + TableManager $table_manager = null, |
|
51 | + TableAnalysis $table_analysis = null, |
|
52 | + EE_DMS_Core_4_9_0 $dms_4_9 |
|
53 | + ) { |
|
54 | + if (! $dms_4_9 instanceof EE_DMS_Core_4_9_0) { |
|
55 | + $dms_4_9 = LoaderFactory::getLoader()->getShared('EE_DMS_Core_4_9_0'); |
|
56 | + } |
|
57 | + $this->dms_4_9 = $dms_4_9; |
|
58 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.10.0", "event_espresso"); |
|
59 | + $this->_priority = 10; |
|
60 | + $this->_migration_stages = array( |
|
61 | + new EE_DMS_4_10_0_Event_Question_Group(), |
|
62 | + ); |
|
63 | + parent::__construct($table_manager, $table_analysis); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Whether to migrate or not. |
|
70 | - * |
|
71 | - * @param array $version_array |
|
72 | - * @return bool |
|
73 | - */ |
|
74 | - public function can_migrate_from_version($version_array) |
|
75 | - { |
|
76 | - $version_string = $version_array['Core']; |
|
77 | - if (version_compare($version_string, '4.10.0.rc.000', '<') && version_compare($version_string, '4.9.0', '>=')) { |
|
78 | - // echo "$version_string can be migrated from"; |
|
79 | - return true; |
|
80 | - } elseif (! $version_string) { |
|
81 | - // echo "no version string provided: $version_string"; |
|
82 | - // no version string provided... this must be pre 4.3 |
|
83 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
84 | - } else { |
|
85 | - // echo "$version_string doesnt apply"; |
|
86 | - return false; |
|
87 | - } |
|
88 | - } |
|
68 | + /** |
|
69 | + * Whether to migrate or not. |
|
70 | + * |
|
71 | + * @param array $version_array |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | + public function can_migrate_from_version($version_array) |
|
75 | + { |
|
76 | + $version_string = $version_array['Core']; |
|
77 | + if (version_compare($version_string, '4.10.0.rc.000', '<') && version_compare($version_string, '4.9.0', '>=')) { |
|
78 | + // echo "$version_string can be migrated from"; |
|
79 | + return true; |
|
80 | + } elseif (! $version_string) { |
|
81 | + // echo "no version string provided: $version_string"; |
|
82 | + // no version string provided... this must be pre 4.3 |
|
83 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
84 | + } else { |
|
85 | + // echo "$version_string doesnt apply"; |
|
86 | + return false; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - public function schema_changes_before_migration() |
|
96 | - { |
|
97 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
98 | - $now_in_mysql = current_time('mysql', true); |
|
99 | - $table_name = 'esp_answer'; |
|
100 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
92 | + /** |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + public function schema_changes_before_migration() |
|
96 | + { |
|
97 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
98 | + $now_in_mysql = current_time('mysql', true); |
|
99 | + $table_name = 'esp_answer'; |
|
100 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
101 | 101 | REG_ID int(10) unsigned NOT NULL, |
102 | 102 | QST_ID int(10) unsigned NOT NULL, |
103 | 103 | ANS_value text NOT NULL, |
104 | 104 | PRIMARY KEY (ANS_ID), |
105 | 105 | KEY REG_ID (REG_ID), |
106 | 106 | KEY QST_ID (QST_ID)"; |
107 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
108 | - $table_name = 'esp_attendee_meta'; |
|
109 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
107 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
108 | + $table_name = 'esp_attendee_meta'; |
|
109 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
110 | 110 | ATT_ID bigint(20) unsigned NOT NULL, |
111 | 111 | ATT_fname varchar(45) NOT NULL, |
112 | 112 | ATT_lname varchar(45) NOT NULL, |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | KEY ATT_email (ATT_email(191)), |
124 | 124 | KEY ATT_lname (ATT_lname), |
125 | 125 | KEY ATT_fname (ATT_fname)"; |
126 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
127 | - $table_name = 'esp_checkin'; |
|
128 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
126 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
127 | + $table_name = 'esp_checkin'; |
|
128 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
129 | 129 | REG_ID int(10) unsigned NOT NULL, |
130 | 130 | DTT_ID int(10) unsigned NOT NULL, |
131 | 131 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | PRIMARY KEY (CHK_ID), |
134 | 134 | KEY REG_ID (REG_ID), |
135 | 135 | KEY DTT_ID (DTT_ID)"; |
136 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
137 | - $table_name = 'esp_country'; |
|
138 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
136 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
137 | + $table_name = 'esp_country'; |
|
138 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
139 | 139 | CNT_ISO3 varchar(3) NOT NULL, |
140 | 140 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
141 | 141 | CNT_name varchar(45) NOT NULL, |
@@ -151,29 +151,29 @@ discard block |
||
151 | 151 | CNT_is_EU tinyint(1) DEFAULT '0', |
152 | 152 | CNT_active tinyint(1) DEFAULT '0', |
153 | 153 | PRIMARY KEY (CNT_ISO)"; |
154 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
155 | - $table_name = 'esp_currency'; |
|
156 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
154 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
155 | + $table_name = 'esp_currency'; |
|
156 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
157 | 157 | CUR_single varchar(45) DEFAULT 'dollar', |
158 | 158 | CUR_plural varchar(45) DEFAULT 'dollars', |
159 | 159 | CUR_sign varchar(45) DEFAULT '$', |
160 | 160 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
161 | 161 | CUR_active tinyint(1) DEFAULT '0', |
162 | 162 | PRIMARY KEY (CUR_code)"; |
163 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
164 | - // note: although this table is no longer in use, |
|
165 | - // it hasn't been removed because then queries to the model will have errors. |
|
166 | - // but you should expect this table and its corresponding model to be removed in |
|
167 | - // the next few months |
|
168 | - $table_name = 'esp_currency_payment_method'; |
|
169 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
163 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
164 | + // note: although this table is no longer in use, |
|
165 | + // it hasn't been removed because then queries to the model will have errors. |
|
166 | + // but you should expect this table and its corresponding model to be removed in |
|
167 | + // the next few months |
|
168 | + $table_name = 'esp_currency_payment_method'; |
|
169 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
170 | 170 | CUR_code varchar(6) NOT NULL, |
171 | 171 | PMD_ID int(11) NOT NULL, |
172 | 172 | PRIMARY KEY (CPM_ID), |
173 | 173 | KEY PMD_ID (PMD_ID)"; |
174 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
175 | - $table_name = 'esp_datetime'; |
|
176 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
174 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
175 | + $table_name = 'esp_datetime'; |
|
176 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
177 | 177 | EVT_ID bigint(20) unsigned NOT NULL, |
178 | 178 | DTT_name varchar(255) NOT NULL DEFAULT '', |
179 | 179 | DTT_description text NOT NULL, |
@@ -190,25 +190,25 @@ discard block |
||
190 | 190 | KEY DTT_EVT_start (DTT_EVT_start), |
191 | 191 | KEY EVT_ID (EVT_ID), |
192 | 192 | KEY DTT_is_primary (DTT_is_primary)"; |
193 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
194 | - $table_name = "esp_datetime_ticket"; |
|
195 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
193 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
194 | + $table_name = "esp_datetime_ticket"; |
|
195 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
196 | 196 | DTT_ID int(10) unsigned NOT NULL, |
197 | 197 | TKT_ID int(10) unsigned NOT NULL, |
198 | 198 | PRIMARY KEY (DTK_ID), |
199 | 199 | KEY DTT_ID (DTT_ID), |
200 | 200 | KEY TKT_ID (TKT_ID)"; |
201 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
202 | - $table_name = 'esp_event_message_template'; |
|
203 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
201 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
202 | + $table_name = 'esp_event_message_template'; |
|
203 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
204 | 204 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
205 | 205 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
206 | 206 | PRIMARY KEY (EMT_ID), |
207 | 207 | KEY EVT_ID (EVT_ID), |
208 | 208 | KEY GRP_ID (GRP_ID)"; |
209 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
210 | - $table_name = 'esp_event_meta'; |
|
211 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
209 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
210 | + $table_name = 'esp_event_meta'; |
|
211 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
212 | 212 | EVT_ID bigint(20) unsigned NOT NULL, |
213 | 213 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
214 | 214 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | EVT_donations tinyint(1) NULL, |
224 | 224 | PRIMARY KEY (EVTM_ID), |
225 | 225 | KEY EVT_ID (EVT_ID)"; |
226 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
227 | - $table_name = 'esp_event_question_group'; |
|
228 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
226 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
227 | + $table_name = 'esp_event_question_group'; |
|
228 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
229 | 229 | EVT_ID bigint(20) unsigned NOT NULL, |
230 | 230 | QSG_ID int(10) unsigned NOT NULL, |
231 | 231 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
@@ -233,25 +233,25 @@ discard block |
||
233 | 233 | PRIMARY KEY (EQG_ID), |
234 | 234 | KEY EVT_ID (EVT_ID), |
235 | 235 | KEY QSG_ID (QSG_ID)"; |
236 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
237 | - $table_name = 'esp_event_venue'; |
|
238 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
236 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
237 | + $table_name = 'esp_event_venue'; |
|
238 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
239 | 239 | EVT_ID bigint(20) unsigned NOT NULL, |
240 | 240 | VNU_ID bigint(20) unsigned NOT NULL, |
241 | 241 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
242 | 242 | PRIMARY KEY (EVV_ID)"; |
243 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
244 | - $table_name = 'esp_extra_meta'; |
|
245 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
243 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
244 | + $table_name = 'esp_extra_meta'; |
|
245 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
246 | 246 | OBJ_ID int(11) DEFAULT NULL, |
247 | 247 | EXM_type varchar(45) DEFAULT NULL, |
248 | 248 | EXM_key varchar(45) DEFAULT NULL, |
249 | 249 | EXM_value text, |
250 | 250 | PRIMARY KEY (EXM_ID), |
251 | 251 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
252 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
253 | - $table_name = 'esp_extra_join'; |
|
254 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
252 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
253 | + $table_name = 'esp_extra_join'; |
|
254 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
255 | 255 | EXJ_first_model_id varchar(6) NOT NULL, |
256 | 256 | EXJ_first_model_name varchar(20) NOT NULL, |
257 | 257 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -259,9 +259,9 @@ discard block |
||
259 | 259 | PRIMARY KEY (EXJ_ID), |
260 | 260 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
261 | 261 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
262 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
263 | - $table_name = 'esp_line_item'; |
|
264 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
262 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
263 | + $table_name = 'esp_line_item'; |
|
264 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
265 | 265 | LIN_code varchar(245) NOT NULL DEFAULT '', |
266 | 266 | TXN_ID int(11) DEFAULT NULL, |
267 | 267 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -282,9 +282,9 @@ discard block |
||
282 | 282 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
283 | 283 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
284 | 284 | KEY obj_id_obj_type (OBJ_ID,OBJ_type)"; |
285 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
286 | - $table_name = 'esp_log'; |
|
287 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
285 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
286 | + $table_name = 'esp_log'; |
|
287 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
288 | 288 | LOG_time datetime DEFAULT NULL, |
289 | 289 | OBJ_ID varchar(45) DEFAULT NULL, |
290 | 290 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | KEY LOG_time (LOG_time), |
296 | 296 | KEY OBJ (OBJ_type,OBJ_ID), |
297 | 297 | KEY LOG_type (LOG_type)"; |
298 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
299 | - $table_name = 'esp_message'; |
|
300 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
298 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
299 | + $table_name = 'esp_message'; |
|
300 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
301 | 301 | GRP_ID int(10) unsigned NULL, |
302 | 302 | MSG_token varchar(255) NULL, |
303 | 303 | TXN_ID int(10) unsigned NULL, |
@@ -329,18 +329,18 @@ discard block |
||
329 | 329 | KEY STS_ID (STS_ID), |
330 | 330 | KEY MSG_created (MSG_created), |
331 | 331 | KEY MSG_modified (MSG_modified)"; |
332 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
333 | - $table_name = 'esp_message_template'; |
|
334 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
332 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
333 | + $table_name = 'esp_message_template'; |
|
334 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
335 | 335 | GRP_ID int(10) unsigned NOT NULL, |
336 | 336 | MTP_context varchar(50) NOT NULL, |
337 | 337 | MTP_template_field varchar(30) NOT NULL, |
338 | 338 | MTP_content text NOT NULL, |
339 | 339 | PRIMARY KEY (MTP_ID), |
340 | 340 | KEY GRP_ID (GRP_ID)"; |
341 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
342 | - $table_name = 'esp_message_template_group'; |
|
343 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
341 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
342 | + $table_name = 'esp_message_template_group'; |
|
343 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
344 | 344 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
345 | 345 | MTP_name varchar(245) NOT NULL DEFAULT '', |
346 | 346 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -352,9 +352,9 @@ discard block |
||
352 | 352 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
353 | 353 | PRIMARY KEY (GRP_ID), |
354 | 354 | KEY MTP_user_id (MTP_user_id)"; |
355 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
356 | - $table_name = 'esp_payment'; |
|
357 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
355 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
356 | + $table_name = 'esp_payment'; |
|
357 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
358 | 358 | TXN_ID int(10) unsigned DEFAULT NULL, |
359 | 359 | STS_ID varchar(3) DEFAULT NULL, |
360 | 360 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -371,9 +371,9 @@ discard block |
||
371 | 371 | PRIMARY KEY (PAY_ID), |
372 | 372 | KEY PAY_timestamp (PAY_timestamp), |
373 | 373 | KEY TXN_ID (TXN_ID)"; |
374 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
375 | - $table_name = 'esp_payment_method'; |
|
376 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
374 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
375 | + $table_name = 'esp_payment_method'; |
|
376 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
377 | 377 | PMD_type varchar(124) DEFAULT NULL, |
378 | 378 | PMD_name varchar(255) DEFAULT NULL, |
379 | 379 | PMD_desc text, |
@@ -389,24 +389,24 @@ discard block |
||
389 | 389 | PRIMARY KEY (PMD_ID), |
390 | 390 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
391 | 391 | KEY PMD_type (PMD_type)"; |
392 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
393 | - $table_name = "esp_ticket_price"; |
|
394 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
392 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
393 | + $table_name = "esp_ticket_price"; |
|
394 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
395 | 395 | TKT_ID int(10) unsigned NOT NULL, |
396 | 396 | PRC_ID int(10) unsigned NOT NULL, |
397 | 397 | PRIMARY KEY (TKP_ID), |
398 | 398 | KEY TKT_ID (TKT_ID), |
399 | 399 | KEY PRC_ID (PRC_ID)"; |
400 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
401 | - $table_name = "esp_ticket_template"; |
|
402 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
400 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
401 | + $table_name = "esp_ticket_template"; |
|
402 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
403 | 403 | TTM_name varchar(45) NOT NULL, |
404 | 404 | TTM_description text, |
405 | 405 | TTM_file varchar(45), |
406 | 406 | PRIMARY KEY (TTM_ID)"; |
407 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
408 | - $table_name = 'esp_question'; |
|
409 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
407 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
408 | + $table_name = 'esp_question'; |
|
409 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
410 | 410 | QST_display_text text NOT NULL, |
411 | 411 | QST_admin_label varchar(255) NOT NULL, |
412 | 412 | QST_system varchar(25) DEFAULT NULL, |
@@ -420,18 +420,18 @@ discard block |
||
420 | 420 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
421 | 421 | PRIMARY KEY (QST_ID), |
422 | 422 | KEY QST_order (QST_order)'; |
423 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
424 | - $table_name = 'esp_question_group_question'; |
|
425 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
423 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
424 | + $table_name = 'esp_question_group_question'; |
|
425 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
426 | 426 | QSG_ID int(10) unsigned NOT NULL, |
427 | 427 | QST_ID int(10) unsigned NOT NULL, |
428 | 428 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
429 | 429 | PRIMARY KEY (QGQ_ID), |
430 | 430 | KEY QST_ID (QST_ID), |
431 | 431 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
432 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | - $table_name = 'esp_question_option'; |
|
434 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
432 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | + $table_name = 'esp_question_option'; |
|
434 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
435 | 435 | QSO_value varchar(255) NOT NULL, |
436 | 436 | QSO_desc text NOT NULL, |
437 | 437 | QST_ID int(10) unsigned NOT NULL, |
@@ -441,9 +441,9 @@ discard block |
||
441 | 441 | PRIMARY KEY (QSO_ID), |
442 | 442 | KEY QST_ID (QST_ID), |
443 | 443 | KEY QSO_order (QSO_order)"; |
444 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
445 | - $table_name = 'esp_registration'; |
|
446 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
444 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
445 | + $table_name = 'esp_registration'; |
|
446 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
447 | 447 | EVT_ID bigint(20) unsigned NOT NULL, |
448 | 448 | ATT_ID bigint(20) unsigned NOT NULL, |
449 | 449 | TXN_ID int(10) unsigned NOT NULL, |
@@ -467,18 +467,18 @@ discard block |
||
467 | 467 | KEY TKT_ID (TKT_ID), |
468 | 468 | KEY EVT_ID (EVT_ID), |
469 | 469 | KEY STS_ID (STS_ID)"; |
470 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
471 | - $table_name = 'esp_registration_payment'; |
|
472 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
470 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
471 | + $table_name = 'esp_registration_payment'; |
|
472 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
473 | 473 | REG_ID int(10) unsigned NOT NULL, |
474 | 474 | PAY_ID int(10) unsigned NULL, |
475 | 475 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
476 | 476 | PRIMARY KEY (RPY_ID), |
477 | 477 | KEY REG_ID (REG_ID), |
478 | 478 | KEY PAY_ID (PAY_ID)"; |
479 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
480 | - $table_name = 'esp_state'; |
|
481 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
479 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
480 | + $table_name = 'esp_state'; |
|
481 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
482 | 482 | CNT_ISO varchar(2) NOT NULL, |
483 | 483 | STA_abbrev varchar(24) NOT NULL, |
484 | 484 | STA_name varchar(100) NOT NULL, |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | PRIMARY KEY (STA_ID), |
487 | 487 | KEY STA_abbrev (STA_abbrev), |
488 | 488 | KEY CNT_ISO (CNT_ISO)"; |
489 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
490 | - $table_name = 'esp_status'; |
|
491 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
489 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
490 | + $table_name = 'esp_status'; |
|
491 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
492 | 492 | STS_code varchar(45) NOT NULL, |
493 | 493 | STS_type varchar(45) NOT NULL, |
494 | 494 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -496,9 +496,9 @@ discard block |
||
496 | 496 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
497 | 497 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
498 | 498 | KEY STS_type (STS_type)"; |
499 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
500 | - $table_name = 'esp_transaction'; |
|
501 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
499 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
500 | + $table_name = 'esp_transaction'; |
|
501 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
502 | 502 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
503 | 503 | TXN_total decimal(12,3) DEFAULT '0.00', |
504 | 504 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -510,9 +510,9 @@ discard block |
||
510 | 510 | PRIMARY KEY (TXN_ID), |
511 | 511 | KEY TXN_timestamp (TXN_timestamp), |
512 | 512 | KEY STS_ID (STS_ID)"; |
513 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
514 | - $table_name = 'esp_venue_meta'; |
|
515 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
513 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
514 | + $table_name = 'esp_venue_meta'; |
|
515 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
516 | 516 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
517 | 517 | VNU_address varchar(255) DEFAULT NULL, |
518 | 518 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -531,10 +531,10 @@ discard block |
||
531 | 531 | KEY VNU_ID (VNU_ID), |
532 | 532 | KEY STA_ID (STA_ID), |
533 | 533 | KEY CNT_ISO (CNT_ISO)"; |
534 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
535 | - // modified tables |
|
536 | - $table_name = "esp_price"; |
|
537 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
534 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
535 | + // modified tables |
|
536 | + $table_name = "esp_price"; |
|
537 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
538 | 538 | PRT_ID tinyint(3) unsigned NOT NULL, |
539 | 539 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
540 | 540 | PRC_name varchar(245) NOT NULL, |
@@ -547,9 +547,9 @@ discard block |
||
547 | 547 | PRC_parent int(10) unsigned DEFAULT 0, |
548 | 548 | PRIMARY KEY (PRC_ID), |
549 | 549 | KEY PRT_ID (PRT_ID)"; |
550 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
551 | - $table_name = "esp_price_type"; |
|
552 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
550 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
551 | + $table_name = "esp_price_type"; |
|
552 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
553 | 553 | PRT_name varchar(45) NOT NULL, |
554 | 554 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
555 | 555 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -558,9 +558,9 @@ discard block |
||
558 | 558 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
559 | 559 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
560 | 560 | PRIMARY KEY (PRT_ID)"; |
561 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
562 | - $table_name = "esp_ticket"; |
|
563 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
561 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
562 | + $table_name = "esp_ticket"; |
|
563 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
564 | 564 | TTM_ID int(10) unsigned NOT NULL, |
565 | 565 | TKT_name varchar(245) NOT NULL DEFAULT '', |
566 | 566 | TKT_description text NOT NULL, |
@@ -583,9 +583,9 @@ discard block |
||
583 | 583 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
584 | 584 | PRIMARY KEY (TKT_ID), |
585 | 585 | KEY TKT_start_date (TKT_start_date)"; |
586 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
587 | - $table_name = 'esp_question_group'; |
|
588 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
586 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
587 | + $table_name = 'esp_question_group'; |
|
588 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
589 | 589 | QSG_name varchar(255) NOT NULL, |
590 | 590 | QSG_identifier varchar(100) NOT NULL, |
591 | 591 | QSG_desc text NULL, |
@@ -598,38 +598,38 @@ discard block |
||
598 | 598 | PRIMARY KEY (QSG_ID), |
599 | 599 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
600 | 600 | KEY QSG_order (QSG_order)'; |
601 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
602 | - $this->insert_default_data(); |
|
603 | - return true; |
|
604 | - } |
|
601 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
602 | + $this->insert_default_data(); |
|
603 | + return true; |
|
604 | + } |
|
605 | 605 | |
606 | - /** |
|
607 | - * Inserts default data on new installs |
|
608 | - * @since $VID:$ |
|
609 | - * @throws EE_Error |
|
610 | - * @throws InvalidArgumentException |
|
611 | - * @throws ReflectionException |
|
612 | - * @throws InvalidDataTypeException |
|
613 | - * @throws InvalidInterfaceException |
|
614 | - */ |
|
615 | - public function insert_default_data() |
|
616 | - { |
|
617 | - $this->dms_4_9->insert_default_data(); |
|
618 | - } |
|
606 | + /** |
|
607 | + * Inserts default data on new installs |
|
608 | + * @since $VID:$ |
|
609 | + * @throws EE_Error |
|
610 | + * @throws InvalidArgumentException |
|
611 | + * @throws ReflectionException |
|
612 | + * @throws InvalidDataTypeException |
|
613 | + * @throws InvalidInterfaceException |
|
614 | + */ |
|
615 | + public function insert_default_data() |
|
616 | + { |
|
617 | + $this->dms_4_9->insert_default_data(); |
|
618 | + } |
|
619 | 619 | |
620 | 620 | |
621 | 621 | |
622 | - /** |
|
623 | - * @return boolean |
|
624 | - */ |
|
625 | - public function schema_changes_after_migration() |
|
626 | - { |
|
627 | - return true; |
|
628 | - } |
|
622 | + /** |
|
623 | + * @return boolean |
|
624 | + */ |
|
625 | + public function schema_changes_after_migration() |
|
626 | + { |
|
627 | + return true; |
|
628 | + } |
|
629 | 629 | |
630 | 630 | |
631 | 631 | |
632 | - public function migration_page_hooks() |
|
633 | - { |
|
634 | - } |
|
632 | + public function migration_page_hooks() |
|
633 | + { |
|
634 | + } |
|
635 | 635 | } |