Completed
Branch BUG-10738-inconsistency-in-ses... (fb18f5)
by
unknown
33:00 queued 22:19
created
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Indentation   +1861 added lines, -1861 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,1866 +20,1866 @@  discard block
 block discarded – undo
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * $_initialized - has the SPCO controller already been initialized ?
25
-     *
26
-     * @access private
27
-     * @var bool $_initialized
28
-     */
29
-    private static $_initialized = false;
30
-
31
-
32
-    /**
33
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
-     *
35
-     * @access private
36
-     * @var bool $_valid_checkout
37
-     */
38
-    private static $_checkout_verified = true;
39
-
40
-    /**
41
-     *    $_reg_steps_array - holds initial array of reg steps
42
-     *
43
-     * @access private
44
-     * @var array $_reg_steps_array
45
-     */
46
-    private static $_reg_steps_array = array();
47
-
48
-    /**
49
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
-     *
51
-     * @access public
52
-     * @var EE_Checkout $checkout
53
-     */
54
-    public $checkout;
55
-
56
-
57
-
58
-    /**
59
-     * @return EED_Module|EED_Single_Page_Checkout
60
-     */
61
-    public static function instance()
62
-    {
63
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
-        return parent::get_instance(__CLASS__);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return EE_Transaction
81
-     */
82
-    public function transaction()
83
-    {
84
-        return $this->checkout->transaction;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    set_hooks - for hooking into EE Core, other modules, etc
91
-     *
92
-     * @access    public
93
-     * @return    void
94
-     * @throws EE_Error
95
-     */
96
-    public static function set_hooks()
97
-    {
98
-        EED_Single_Page_Checkout::set_definitions();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
-     *
106
-     * @access    public
107
-     * @return    void
108
-     * @throws EE_Error
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        EED_Single_Page_Checkout::set_definitions();
113
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
-            return;
115
-        }
116
-        // going to start an output buffer in case anything gets accidentally output
117
-        // that might disrupt our JSON response
118
-        ob_start();
119
-        EED_Single_Page_Checkout::load_request_handler();
120
-        EED_Single_Page_Checkout::load_reg_steps();
121
-        // set ajax hooks
122
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    process ajax request
134
-     *
135
-     * @param string $ajax_action
136
-     * @throws EE_Error
137
-     */
138
-    public static function process_ajax_request($ajax_action)
139
-    {
140
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
141
-        EED_Single_Page_Checkout::instance()->_initialize();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *    ajax display registration step
148
-     *
149
-     * @throws EE_Error
150
-     */
151
-    public static function display_reg_step()
152
-    {
153
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    ajax process registration step
160
-     *
161
-     * @throws EE_Error
162
-     */
163
-    public static function process_reg_step()
164
-    {
165
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    ajax process registration step
172
-     *
173
-     * @throws EE_Error
174
-     */
175
-    public static function update_reg_step()
176
-    {
177
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *   update_checkout
184
-     *
185
-     * @access public
186
-     * @return void
187
-     * @throws EE_Error
188
-     */
189
-    public static function update_checkout()
190
-    {
191
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     *    load_request_handler
198
-     *
199
-     * @access    public
200
-     * @return    void
201
-     */
202
-    public static function load_request_handler()
203
-    {
204
-        // load core Request_Handler class
205
-        if (EE_Registry::instance()->REQ !== null) {
206
-            EE_Registry::instance()->load_core('Request_Handler');
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     *    set_definitions
214
-     *
215
-     * @access    public
216
-     * @return    void
217
-     * @throws EE_Error
218
-     */
219
-    public static function set_definitions()
220
-    {
221
-        if(defined('SPCO_BASE_PATH')) {
222
-            return;
223
-        }
224
-        define(
225
-            'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
-        );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236
-            __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
237
-                'event_espresso'),
238
-            '<h4 class="important-notice">',
239
-            '</h4>',
240
-            '<br />',
241
-            '<p>',
242
-            '<a href="'
243
-            . apply_filters(
244
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information__process_reg_step__no_regs_link_to_event_list',
245
-                get_post_type_archive_link('espresso_events')
246
-            )
247
-            . '" title="',
248
-            '">',
249
-            '</a>',
250
-            '</p>'
251
-        );
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     * load_reg_steps
258
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
259
-     *
260
-     * @access    private
261
-     * @throws EE_Error
262
-     */
263
-    public static function load_reg_steps()
264
-    {
265
-        static $reg_steps_loaded = false;
266
-        if ($reg_steps_loaded) {
267
-            return;
268
-        }
269
-        // filter list of reg_steps
270
-        $reg_steps_to_load = (array)apply_filters(
271
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
272
-            EED_Single_Page_Checkout::get_reg_steps()
273
-        );
274
-        // sort by key (order)
275
-        ksort($reg_steps_to_load);
276
-        // loop through folders
277
-        foreach ($reg_steps_to_load as $order => $reg_step) {
278
-            // we need a
279
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
280
-                // copy over to the reg_steps_array
281
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
282
-                // register custom key route for each reg step
283
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
284
-                EE_Config::register_route(
285
-                    $reg_step['slug'],
286
-                    'EED_Single_Page_Checkout',
287
-                    'run',
288
-                    'step'
289
-                );
290
-                // add AJAX or other hooks
291
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
292
-                    // setup autoloaders if necessary
293
-                    if ( ! class_exists($reg_step['class_name'])) {
294
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
295
-                            $reg_step['file_path'],
296
-                            true
297
-                        );
298
-                    }
299
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
300
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
301
-                    }
302
-                }
303
-            }
304
-        }
305
-        $reg_steps_loaded = true;
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     *    get_reg_steps
312
-     *
313
-     * @access    public
314
-     * @return    array
315
-     */
316
-    public static function get_reg_steps()
317
-    {
318
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
319
-        if (empty($reg_steps)) {
320
-            $reg_steps = array(
321
-                10  => array(
322
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
323
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
324
-                    'slug'       => 'attendee_information',
325
-                    'has_hooks'  => false,
326
-                ),
327
-                20  => array(
328
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
329
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
330
-                    'slug'       => 'registration_confirmation',
331
-                    'has_hooks'  => false,
332
-                ),
333
-                30  => array(
334
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
335
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
336
-                    'slug'       => 'payment_options',
337
-                    'has_hooks'  => true,
338
-                ),
339
-                999 => array(
340
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
341
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
342
-                    'slug'       => 'finalize_registration',
343
-                    'has_hooks'  => false,
344
-                ),
345
-            );
346
-        }
347
-        return $reg_steps;
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     *    registration_checkout_for_admin
354
-     *
355
-     * @access    public
356
-     * @return    string
357
-     * @throws EE_Error
358
-     */
359
-    public static function registration_checkout_for_admin()
360
-    {
361
-        EED_Single_Page_Checkout::load_request_handler();
362
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
363
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
364
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
365
-        EED_Single_Page_Checkout::instance()->_initialize();
366
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
367
-        return EE_Registry::instance()->REQ->get_output();
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     * process_registration_from_admin
374
-     *
375
-     * @access public
376
-     * @return \EE_Transaction
377
-     * @throws EE_Error
378
-     */
379
-    public static function process_registration_from_admin()
380
-    {
381
-        EED_Single_Page_Checkout::load_request_handler();
382
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
383
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
384
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
385
-        EED_Single_Page_Checkout::instance()->_initialize();
386
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
387
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
388
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
389
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
390
-                if ($final_reg_step->process_reg_step()) {
391
-                    $final_reg_step->set_completed();
392
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
393
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
394
-                }
395
-            }
396
-        }
397
-        return null;
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     *    run
404
-     *
405
-     * @access    public
406
-     * @param WP_Query $WP_Query
407
-     * @return    void
408
-     * @throws EE_Error
409
-     */
410
-    public function run($WP_Query)
411
-    {
412
-        if (
413
-            $WP_Query instanceof WP_Query
414
-            && $WP_Query->is_main_query()
415
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
416
-            && $this->_is_reg_checkout()
417
-        ) {
418
-            $this->_initialize();
419
-        }
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * determines whether current url matches reg page url
426
-     *
427
-     * @return bool
428
-     */
429
-    protected function _is_reg_checkout()
430
-    {
431
-        // get current permalink for reg page without any extra query args
432
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
433
-        // get request URI for current request, but without the scheme or host
434
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
435
-        $current_request_uri = html_entity_decode($current_request_uri);
436
-        // get array of query args from the current request URI
437
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
438
-        // grab page id if it is set
439
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
440
-        // and remove the page id from the query args (we will re-add it later)
441
-        unset($query_args['page_id']);
442
-        // now strip all query args from current request URI
443
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
444
-        // and re-add the page id if it was set
445
-        if ($page_id) {
446
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
447
-        }
448
-        // remove slashes and ?
449
-        $current_request_uri = trim($current_request_uri, '?/');
450
-        // is current request URI part of the known full reg page URL ?
451
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
452
-    }
453
-
454
-
455
-
456
-    /**
457
-     * @param WP_Query $wp_query
458
-     * @return    void
459
-     * @throws EE_Error
460
-     */
461
-    public static function init($wp_query)
462
-    {
463
-        EED_Single_Page_Checkout::instance()->run($wp_query);
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     *    _initialize - initial module setup
470
-     *
471
-     * @access    private
472
-     * @throws EE_Error
473
-     * @return    void
474
-     */
475
-    private function _initialize()
476
-    {
477
-        // ensure SPCO doesn't run twice
478
-        if (EED_Single_Page_Checkout::$_initialized) {
479
-            return;
480
-        }
481
-        try {
482
-            EED_Single_Page_Checkout::load_reg_steps();
483
-            $this->_verify_session();
484
-            // setup the EE_Checkout object
485
-            $this->checkout = $this->_initialize_checkout();
486
-            // filter checkout
487
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
488
-            // get the $_GET
489
-            $this->_get_request_vars();
490
-            if ($this->_block_bots()) {
491
-                return;
492
-            }
493
-            // filter continue_reg
494
-            $this->checkout->continue_reg = apply_filters(
495
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
496
-                true,
497
-                $this->checkout
498
-            );
499
-            // load the reg steps array
500
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
501
-                EED_Single_Page_Checkout::$_initialized = true;
502
-                return;
503
-            }
504
-            // set the current step
505
-            $this->checkout->set_current_step($this->checkout->step);
506
-            // and the next step
507
-            $this->checkout->set_next_step();
508
-            // verify that everything has been setup correctly
509
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
510
-                EED_Single_Page_Checkout::$_initialized = true;
511
-                return;
512
-            }
513
-            // lock the transaction
514
-            $this->checkout->transaction->lock();
515
-            // make sure all of our cached objects are added to their respective model entity mappers
516
-            $this->checkout->refresh_all_entities();
517
-            // set amount owing
518
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
519
-            // initialize each reg step, which gives them the chance to potentially alter the process
520
-            $this->_initialize_reg_steps();
521
-            // DEBUG LOG
522
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
523
-            // get reg form
524
-            if( ! $this->_check_form_submission()) {
525
-                EED_Single_Page_Checkout::$_initialized = true;
526
-                return;
527
-            }
528
-            // checkout the action!!!
529
-            $this->_process_form_action();
530
-            // add some style and make it dance
531
-            $this->add_styles_and_scripts();
532
-            // kk... SPCO has successfully run
533
-            EED_Single_Page_Checkout::$_initialized = true;
534
-            // set no cache headers and constants
535
-            EE_System::do_not_cache();
536
-            // add anchor
537
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
538
-            // remove transaction lock
539
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
540
-        } catch (Exception $e) {
541
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
542
-        }
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     *    _verify_session
549
-     * checks that the session is valid and not expired
550
-     *
551
-     * @access    private
552
-     * @throws EE_Error
553
-     */
554
-    private function _verify_session()
555
-    {
556
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
557
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
558
-        }
559
-        $clear_session_requested = filter_var(
560
-            EE_Registry::instance()->REQ->get('clear_session', false),
561
-            FILTER_VALIDATE_BOOLEAN
562
-        );
563
-        // is session still valid ?
564
-        if ($clear_session_requested
565
-            || ( EE_Registry::instance()->SSN->expired()
566
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
567
-            )
568
-        ) {
569
-            $this->checkout = new EE_Checkout();
570
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
571
-            // EE_Registry::instance()->SSN->reset_cart();
572
-            // EE_Registry::instance()->SSN->reset_checkout();
573
-            // EE_Registry::instance()->SSN->reset_transaction();
574
-            if (! $clear_session_requested) {
575
-                EE_Error::add_attention(
576
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
577
-                    __FILE__, __FUNCTION__, __LINE__
578
-                );
579
-            }
580
-            // EE_Registry::instance()->SSN->reset_expired();
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     *    _initialize_checkout
588
-     * loads and instantiates EE_Checkout
589
-     *
590
-     * @access    private
591
-     * @throws EE_Error
592
-     * @return EE_Checkout
593
-     */
594
-    private function _initialize_checkout()
595
-    {
596
-        // look in session for existing checkout
597
-        /** @type EE_Checkout $checkout */
598
-        $checkout = EE_Registry::instance()->SSN->checkout();
599
-        // verify
600
-        if ( ! $checkout instanceof EE_Checkout) {
601
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
602
-            $checkout = EE_Registry::instance()->load_file(
603
-                SPCO_INC_PATH,
604
-                'EE_Checkout',
605
-                'class', array(),
606
-                false
607
-            );
608
-        } else {
609
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
610
-                $this->unlock_transaction();
611
-                wp_safe_redirect($checkout->redirect_url);
612
-                exit();
613
-            }
614
-        }
615
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
616
-        // verify again
617
-        if ( ! $checkout instanceof EE_Checkout) {
618
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
619
-        }
620
-        // reset anything that needs a clean slate for each request
621
-        $checkout->reset_for_current_request();
622
-        return $checkout;
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     *    _get_request_vars
629
-     *
630
-     * @access    private
631
-     * @return    void
632
-     * @throws EE_Error
633
-     */
634
-    private function _get_request_vars()
635
-    {
636
-        // load classes
637
-        EED_Single_Page_Checkout::load_request_handler();
638
-        //make sure this request is marked as belonging to EE
639
-        EE_Registry::instance()->REQ->set_espresso_page(true);
640
-        // which step is being requested ?
641
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
642
-        // which step is being edited ?
643
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
644
-        // and what we're doing on the current step
645
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
646
-        // timestamp
647
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
648
-        // returning to edit ?
649
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
650
-        // or some other kind of revisit ?
651
-        $this->checkout->revisit = filter_var(
652
-            EE_Registry::instance()->REQ->get('revisit', false),
653
-            FILTER_VALIDATE_BOOLEAN
654
-        );
655
-        // and whether or not to generate a reg form for this request
656
-        $this->checkout->generate_reg_form = filter_var(
657
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
658
-            FILTER_VALIDATE_BOOLEAN
659
-        );
660
-        // and whether or not to process a reg form submission for this request
661
-        $this->checkout->process_form_submission = filter_var(
662
-            EE_Registry::instance()->REQ->get(
663
-                'process_form_submission',
664
-                $this->checkout->action === 'process_reg_step'
665
-            ),
666
-            FILTER_VALIDATE_BOOLEAN
667
-        );
668
-        $this->checkout->process_form_submission = filter_var(
669
-            $this->checkout->action !== 'display_spco_reg_step'
670
-                ? $this->checkout->process_form_submission
671
-                : false,
672
-            FILTER_VALIDATE_BOOLEAN
673
-        );
674
-        // $this->_display_request_vars();
675
-    }
676
-
677
-
678
-
679
-    /**
680
-     *  _display_request_vars
681
-     *
682
-     * @access    protected
683
-     * @return    void
684
-     */
685
-    protected function _display_request_vars()
686
-    {
687
-        if ( ! WP_DEBUG) {
688
-            return;
689
-        }
690
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
691
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
692
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
693
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
694
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
695
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
696
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
697
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * _block_bots
704
-     * checks that the incoming request has either of the following set:
705
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
706
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
707
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
708
-     * then where you coming from man?
709
-     *
710
-     * @return boolean
711
-     */
712
-    private function _block_bots()
713
-    {
714
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
715
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
716
-            return true;
717
-        }
718
-        return false;
719
-    }
720
-
721
-
722
-
723
-    /**
724
-     *    _get_first_step
725
-     *  gets slug for first step in $_reg_steps_array
726
-     *
727
-     * @access    private
728
-     * @throws EE_Error
729
-     * @return    string
730
-     */
731
-    private function _get_first_step()
732
-    {
733
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
734
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
735
-    }
736
-
737
-
738
-
739
-    /**
740
-     *    _load_and_instantiate_reg_steps
741
-     *  instantiates each reg step based on the loaded reg_steps array
742
-     *
743
-     * @access    private
744
-     * @throws EE_Error
745
-     * @return    bool
746
-     */
747
-    private function _load_and_instantiate_reg_steps()
748
-    {
749
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
750
-        // have reg_steps already been instantiated ?
751
-        if (
752
-            empty($this->checkout->reg_steps)
753
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
754
-        ) {
755
-            // if not, then loop through raw reg steps array
756
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
757
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
758
-                    return false;
759
-                }
760
-            }
761
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
762
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
763
-            // skip the registration_confirmation page ?
764
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
765
-                // just remove it from the reg steps array
766
-                $this->checkout->remove_reg_step('registration_confirmation', false);
767
-            } else if (
768
-                isset($this->checkout->reg_steps['registration_confirmation'])
769
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
770
-            ) {
771
-                // set the order to something big like 100
772
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
773
-            }
774
-            // filter the array for good luck
775
-            $this->checkout->reg_steps = apply_filters(
776
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
777
-                $this->checkout->reg_steps
778
-            );
779
-            // finally re-sort based on the reg step class order properties
780
-            $this->checkout->sort_reg_steps();
781
-        } else {
782
-            foreach ($this->checkout->reg_steps as $reg_step) {
783
-                // set all current step stati to FALSE
784
-                $reg_step->set_is_current_step(false);
785
-            }
786
-        }
787
-        if (empty($this->checkout->reg_steps)) {
788
-            EE_Error::add_error(
789
-                __('No Reg Steps were loaded..', 'event_espresso'),
790
-                __FILE__, __FUNCTION__, __LINE__
791
-            );
792
-            return false;
793
-        }
794
-        // make reg step details available to JS
795
-        $this->checkout->set_reg_step_JSON_info();
796
-        return true;
797
-    }
798
-
799
-
800
-
801
-    /**
802
-     *     _load_and_instantiate_reg_step
803
-     *
804
-     * @access    private
805
-     * @param array $reg_step
806
-     * @param int   $order
807
-     * @return bool
808
-     */
809
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
810
-    {
811
-        // we need a file_path, class_name, and slug to add a reg step
812
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
813
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
814
-            if (
815
-                $this->checkout->reg_url_link
816
-                && $this->checkout->step !== $reg_step['slug']
817
-                && $reg_step['slug'] !== 'finalize_registration'
818
-                // normally at this point we would NOT load the reg step, but this filter can change that
819
-                && apply_filters(
820
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
821
-                    true,
822
-                    $reg_step,
823
-                    $this->checkout
824
-                )
825
-            ) {
826
-                return true;
827
-            }
828
-            // instantiate step class using file path and class name
829
-            $reg_step_obj = EE_Registry::instance()->load_file(
830
-                $reg_step['file_path'],
831
-                $reg_step['class_name'],
832
-                'class',
833
-                $this->checkout,
834
-                false
835
-            );
836
-            // did we gets the goods ?
837
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
838
-                // set reg step order based on config
839
-                $reg_step_obj->set_order($order);
840
-                // add instantiated reg step object to the master reg steps array
841
-                $this->checkout->add_reg_step($reg_step_obj);
842
-            } else {
843
-                EE_Error::add_error(
844
-                    __('The current step could not be set.', 'event_espresso'),
845
-                    __FILE__, __FUNCTION__, __LINE__
846
-                );
847
-                return false;
848
-            }
849
-        } else {
850
-            if (WP_DEBUG) {
851
-                EE_Error::add_error(
852
-                    sprintf(
853
-                        __(
854
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
855
-                            'event_espresso'
856
-                        ),
857
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
858
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
859
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
860
-                        '<ul>',
861
-                        '<li>',
862
-                        '</li>',
863
-                        '</ul>'
864
-                    ),
865
-                    __FILE__, __FUNCTION__, __LINE__
866
-                );
867
-            }
868
-            return false;
869
-        }
870
-        return true;
871
-    }
872
-
873
-
874
-    /**
875
-     * _verify_transaction_and_get_registrations
876
-     *
877
-     * @access private
878
-     * @return bool
879
-     * @throws InvalidDataTypeException
880
-     * @throws InvalidEntityException
881
-     * @throws EE_Error
882
-     */
883
-    private function _verify_transaction_and_get_registrations()
884
-    {
885
-        // was there already a valid transaction in the checkout from the session ?
886
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
887
-            // get transaction from db or session
888
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
889
-                ? $this->_get_transaction_and_cart_for_previous_visit()
890
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
891
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
892
-                EE_Error::add_error(
893
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
894
-                        'event_espresso'),
895
-                    __FILE__, __FUNCTION__, __LINE__
896
-                );
897
-                $this->checkout->transaction = EE_Transaction::new_instance();
898
-                // add some style and make it dance
899
-                $this->add_styles_and_scripts();
900
-                EED_Single_Page_Checkout::$_initialized = true;
901
-                return false;
902
-            }
903
-            // and the registrations for the transaction
904
-            $this->_get_registrations($this->checkout->transaction);
905
-        }
906
-        return true;
907
-    }
908
-
909
-
910
-
911
-    /**
912
-     * _get_transaction_and_cart_for_previous_visit
913
-     *
914
-     * @access private
915
-     * @return mixed EE_Transaction|NULL
916
-     */
917
-    private function _get_transaction_and_cart_for_previous_visit()
918
-    {
919
-        /** @var $TXN_model EEM_Transaction */
920
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
921
-        // because the reg_url_link is present in the request,
922
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
923
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
924
-        // verify transaction
925
-        if ($transaction instanceof EE_Transaction) {
926
-            // and get the cart that was used for that transaction
927
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
928
-            return $transaction;
929
-        }
930
-        EE_Error::add_error(
931
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
932
-            __FILE__, __FUNCTION__, __LINE__
933
-        );
934
-        return null;
935
-
936
-    }
937
-
938
-
939
-
940
-    /**
941
-     * _get_cart_for_transaction
942
-     *
943
-     * @access private
944
-     * @param EE_Transaction $transaction
945
-     * @return EE_Cart
946
-     */
947
-    private function _get_cart_for_transaction($transaction)
948
-    {
949
-        return $this->checkout->get_cart_for_transaction($transaction);
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * get_cart_for_transaction
956
-     *
957
-     * @access public
958
-     * @param EE_Transaction $transaction
959
-     * @return EE_Cart
960
-     */
961
-    public function get_cart_for_transaction(EE_Transaction $transaction)
962
-    {
963
-        return $this->checkout->get_cart_for_transaction($transaction);
964
-    }
965
-
966
-
967
-
968
-    /**
969
-     * _get_transaction_and_cart_for_current_session
970
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
971
-     *
972
-     * @access private
973
-     * @return EE_Transaction
974
-     * @throws EE_Error
975
-     */
976
-    private function _get_cart_for_current_session_and_setup_new_transaction()
977
-    {
978
-        //  if there's no transaction, then this is the FIRST visit to SPCO
979
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
980
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
981
-        // and then create a new transaction
982
-        $transaction = $this->_initialize_transaction();
983
-        // verify transaction
984
-        if ($transaction instanceof EE_Transaction) {
985
-            // save it so that we have an ID for other objects to use
986
-            $transaction->save();
987
-            // and save TXN data to the cart
988
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
989
-        } else {
990
-            EE_Error::add_error(
991
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
992
-                __FILE__, __FUNCTION__, __LINE__
993
-            );
994
-        }
995
-        return $transaction;
996
-    }
997
-
998
-
999
-
1000
-    /**
1001
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
1002
-     *
1003
-     * @access private
1004
-     * @return mixed EE_Transaction|NULL
1005
-     */
1006
-    private function _initialize_transaction()
1007
-    {
1008
-        try {
1009
-            // ensure cart totals have been calculated
1010
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
1011
-            // grab the cart grand total
1012
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
1013
-            // create new TXN
1014
-            $transaction = EE_Transaction::new_instance(
1015
-                array(
1016
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1017
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1018
-                    'TXN_paid'      => 0,
1019
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1020
-                )
1021
-            );
1022
-            // save it so that we have an ID for other objects to use
1023
-            $transaction->save();
1024
-            // set cron job for following up on TXNs after their session has expired
1025
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1026
-                EE_Registry::instance()->SSN->expiration() + 1,
1027
-                $transaction->ID()
1028
-            );
1029
-            return $transaction;
1030
-        } catch (Exception $e) {
1031
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1032
-        }
1033
-        return null;
1034
-    }
1035
-
1036
-
1037
-    /**
1038
-     * _get_registrations
1039
-     *
1040
-     * @access private
1041
-     * @param EE_Transaction $transaction
1042
-     * @return void
1043
-     * @throws InvalidDataTypeException
1044
-     * @throws InvalidEntityException
1045
-     * @throws EE_Error
1046
-     */
1047
-    private function _get_registrations(EE_Transaction $transaction)
1048
-    {
1049
-        // first step: grab the registrants  { : o
1050
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
1051
-        // verify registrations have been set
1052
-        if (empty($registrations)) {
1053
-            // if no cached registrations, then check the db
1054
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1055
-            // still nothing ? well as long as this isn't a revisit
1056
-            if (empty($registrations) && ! $this->checkout->revisit) {
1057
-                // generate new registrations from scratch
1058
-                $registrations = $this->_initialize_registrations($transaction);
1059
-            }
1060
-        }
1061
-        // sort by their original registration order
1062
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1063
-        // then loop thru the array
1064
-        foreach ($registrations as $registration) {
1065
-            // verify each registration
1066
-            if ($registration instanceof EE_Registration) {
1067
-                // we display all attendee info for the primary registrant
1068
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1069
-                    && $registration->is_primary_registrant()
1070
-                ) {
1071
-                    $this->checkout->primary_revisit = true;
1072
-                    break;
1073
-                }
1074
-                if ($this->checkout->revisit
1075
-                           && $this->checkout->reg_url_link !== $registration->reg_url_link()
1076
-                ) {
1077
-                    // but hide info if it doesn't belong to you
1078
-                    $transaction->clear_cache('Registration', $registration->ID());
1079
-                }
1080
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1081
-            }
1082
-        }
1083
-    }
1084
-
1085
-
1086
-    /**
1087
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1088
-     *
1089
-     * @access private
1090
-     * @param EE_Transaction $transaction
1091
-     * @return    array
1092
-     * @throws InvalidDataTypeException
1093
-     * @throws InvalidEntityException
1094
-     * @throws EE_Error
1095
-     */
1096
-    private function _initialize_registrations(EE_Transaction $transaction)
1097
-    {
1098
-        $att_nmbr = 0;
1099
-        $registrations = array();
1100
-        if ($transaction instanceof EE_Transaction) {
1101
-            /** @type EE_Registration_Processor $registration_processor */
1102
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1103
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1104
-            // now let's add the cart items to the $transaction
1105
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1106
-                //do the following for each ticket of this type they selected
1107
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1108
-                    $att_nmbr++;
1109
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1110
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1111
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1112
-                        array(
1113
-                            $transaction,
1114
-                            $line_item,
1115
-                            $att_nmbr,
1116
-                            $this->checkout->total_ticket_count,
1117
-                        )
1118
-                    );
1119
-                    // override capabilities for frontend registrations
1120
-                    if ( ! is_admin()) {
1121
-                        $CreateRegistrationCommand->setCapCheck(
1122
-                            new PublicCapabilities('', 'create_new_registration')
1123
-                        );
1124
-                    }
1125
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1126
-                    if ( ! $registration instanceof EE_Registration) {
1127
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1128
-                    }
1129
-                    $registrations[ $registration->ID() ] = $registration;
1130
-                }
1131
-            }
1132
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1133
-        }
1134
-        return $registrations;
1135
-    }
1136
-
1137
-
1138
-
1139
-    /**
1140
-     * sorts registrations by REG_count
1141
-     *
1142
-     * @access public
1143
-     * @param EE_Registration $reg_A
1144
-     * @param EE_Registration $reg_B
1145
-     * @return int
1146
-     */
1147
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1148
-    {
1149
-        // this shouldn't ever happen within the same TXN, but oh well
1150
-        if ($reg_A->count() === $reg_B->count()) {
1151
-            return 0;
1152
-        }
1153
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1154
-    }
1155
-
1156
-
1157
-
1158
-    /**
1159
-     *    _final_verifications
1160
-     * just makes sure that everything is set up correctly before proceeding
1161
-     *
1162
-     * @access    private
1163
-     * @return    bool
1164
-     * @throws EE_Error
1165
-     */
1166
-    private function _final_verifications()
1167
-    {
1168
-        // filter checkout
1169
-        $this->checkout = apply_filters(
1170
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1171
-            $this->checkout
1172
-        );
1173
-        //verify that current step is still set correctly
1174
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1175
-            EE_Error::add_error(
1176
-                __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1177
-                __FILE__,
1178
-                __FUNCTION__,
1179
-                __LINE__
1180
-            );
1181
-            return false;
1182
-        }
1183
-        // if returning to SPCO, then verify that primary registrant is set
1184
-        if ( ! empty($this->checkout->reg_url_link)) {
1185
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1186
-            if ( ! $valid_registrant instanceof EE_Registration) {
1187
-                EE_Error::add_error(
1188
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1189
-                    __FILE__,
1190
-                    __FUNCTION__,
1191
-                    __LINE__
1192
-                );
1193
-                return false;
1194
-            }
1195
-            $valid_registrant = null;
1196
-            foreach (
1197
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1198
-            ) {
1199
-                if (
1200
-                    $registration instanceof EE_Registration
1201
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1202
-                ) {
1203
-                    $valid_registrant = $registration;
1204
-                }
1205
-            }
1206
-            if ( ! $valid_registrant instanceof EE_Registration) {
1207
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1208
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1209
-                    // clear the session, mark the checkout as unverified, and try again
1210
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1211
-                    EED_Single_Page_Checkout::$_initialized = false;
1212
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1213
-                    $this->_initialize();
1214
-                    EE_Error::reset_notices();
1215
-                    return false;
1216
-                }
1217
-                EE_Error::add_error(
1218
-                    __(
1219
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1220
-                        'event_espresso'
1221
-                    ),
1222
-                    __FILE__,
1223
-                    __FUNCTION__,
1224
-                    __LINE__
1225
-                );
1226
-                return false;
1227
-            }
1228
-        }
1229
-        // now that things have been kinda sufficiently verified,
1230
-        // let's add the checkout to the session so that it's available to other systems
1231
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1232
-        return true;
1233
-    }
1234
-
1235
-
1236
-
1237
-    /**
1238
-     *    _initialize_reg_steps
1239
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1240
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1241
-     *
1242
-     * @access    private
1243
-     * @param bool $reinitializing
1244
-     * @throws EE_Error
1245
-     */
1246
-    private function _initialize_reg_steps($reinitializing = false)
1247
-    {
1248
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1249
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1250
-        foreach ($this->checkout->reg_steps as $reg_step) {
1251
-            if ( ! $reg_step->initialize_reg_step()) {
1252
-                // if not initialized then maybe this step is being removed...
1253
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1254
-                    // if it was the current step, then we need to start over here
1255
-                    $this->_initialize_reg_steps(true);
1256
-                    return;
1257
-                }
1258
-                continue;
1259
-            }
1260
-            // add css and JS for current step
1261
-            $reg_step->enqueue_styles_and_scripts();
1262
-            // i18n
1263
-            $reg_step->translate_js_strings();
1264
-            if ($reg_step->is_current_step()) {
1265
-                // the text that appears on the reg step form submit button
1266
-                $reg_step->set_submit_button_text();
1267
-            }
1268
-        }
1269
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1270
-        do_action(
1271
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1272
-            $this->checkout->current_step
1273
-        );
1274
-    }
1275
-
1276
-
1277
-
1278
-    /**
1279
-     * _check_form_submission
1280
-     *
1281
-     * @access private
1282
-     * @return boolean
1283
-     */
1284
-    private function _check_form_submission()
1285
-    {
1286
-        //does this request require the reg form to be generated ?
1287
-        if ($this->checkout->generate_reg_form) {
1288
-            // ever heard that song by Blue Rodeo ?
1289
-            try {
1290
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1291
-                // if not displaying a form, then check for form submission
1292
-                if (
1293
-                    $this->checkout->process_form_submission
1294
-                    && $this->checkout->current_step->reg_form->was_submitted()
1295
-                ) {
1296
-                    // clear out any old data in case this step is being run again
1297
-                    $this->checkout->current_step->set_valid_data(array());
1298
-                    // capture submitted form data
1299
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1300
-                        apply_filters(
1301
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1302
-                            EE_Registry::instance()->REQ->params(),
1303
-                            $this->checkout
1304
-                        )
1305
-                    );
1306
-                    // validate submitted form data
1307
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1308
-                        // thou shall not pass !!!
1309
-                        $this->checkout->continue_reg = false;
1310
-                        // any form validation errors?
1311
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1312
-                            $submission_error_messages = array();
1313
-                            // bad, bad, bad registrant
1314
-                            foreach (
1315
-                                $this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1316
-                                as $validation_error
1317
-                            ) {
1318
-                                if ($validation_error instanceof EE_Validation_Error) {
1319
-                                    $submission_error_messages[] = sprintf(
1320
-                                        __('%s : %s', 'event_espresso'),
1321
-                                        $validation_error->get_form_section()->html_label_text(),
1322
-                                        $validation_error->getMessage()
1323
-                                    );
1324
-                                }
1325
-                            }
1326
-                            EE_Error::add_error(
1327
-                                implode('<br />', $submission_error_messages),
1328
-                                __FILE__, __FUNCTION__, __LINE__
1329
-                            );
1330
-                        }
1331
-                        // well not really... what will happen is
1332
-                        // we'll just get redirected back to redo the current step
1333
-                        $this->go_to_next_step();
1334
-                        return false;
1335
-                    }
1336
-                }
1337
-            } catch (EE_Error $e) {
1338
-                $e->get_error();
1339
-            }
1340
-        }
1341
-        return true;
1342
-    }
1343
-
1344
-
1345
-
1346
-    /**
1347
-     * _process_action
1348
-     *
1349
-     * @access private
1350
-     * @return void
1351
-     * @throws EE_Error
1352
-     */
1353
-    private function _process_form_action()
1354
-    {
1355
-        // what cha wanna do?
1356
-        switch ($this->checkout->action) {
1357
-            // AJAX next step reg form
1358
-            case 'display_spco_reg_step' :
1359
-                $this->checkout->redirect = false;
1360
-                if (EE_Registry::instance()->REQ->ajax) {
1361
-                    $this->checkout->json_response->set_reg_step_html(
1362
-                        $this->checkout->current_step->display_reg_form()
1363
-                    );
1364
-                }
1365
-                break;
1366
-            default :
1367
-                // meh... do one of those other steps first
1368
-                if (
1369
-                    ! empty($this->checkout->action)
1370
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1371
-                ) {
1372
-                    // dynamically creates hook point like:
1373
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1374
-                    do_action(
1375
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1376
-                        $this->checkout->current_step
1377
-                    );
1378
-                    // call action on current step
1379
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1380
-                        // good registrant, you get to proceed
1381
-                        if (
1382
-                            $this->checkout->current_step->success_message() !== ''
1383
-                            && apply_filters(
1384
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1385
-                                false
1386
-                            )
1387
-                        ) {
1388
-                            EE_Error::add_success(
1389
-                                $this->checkout->current_step->success_message()
1390
-                                . '<br />' . $this->checkout->next_step->_instructions()
1391
-                            );
1392
-                        }
1393
-                        // pack it up, pack it in...
1394
-                        $this->_setup_redirect();
1395
-                    }
1396
-                    // dynamically creates hook point like:
1397
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1398
-                    do_action(
1399
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1400
-                        $this->checkout->current_step
1401
-                    );
1402
-                } else {
1403
-                    EE_Error::add_error(
1404
-                        sprintf(
1405
-                            __(
1406
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1407
-                                'event_espresso'
1408
-                            ),
1409
-                            $this->checkout->action,
1410
-                            $this->checkout->current_step->name()
1411
-                        ),
1412
-                        __FILE__,
1413
-                        __FUNCTION__,
1414
-                        __LINE__
1415
-                    );
1416
-                }
1417
-            // end default
1418
-        }
1419
-        // store our progress so far
1420
-        $this->checkout->stash_transaction_and_checkout();
1421
-        // advance to the next step! If you pass GO, collect $200
1422
-        $this->go_to_next_step();
1423
-    }
1424
-
1425
-
1426
-
1427
-    /**
1428
-     *        add_styles_and_scripts
1429
-     *
1430
-     * @access        public
1431
-     * @return        void
1432
-     */
1433
-    public function add_styles_and_scripts()
1434
-    {
1435
-        // i18n
1436
-        $this->translate_js_strings();
1437
-        if ($this->checkout->admin_request) {
1438
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1439
-        } else {
1440
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1441
-        }
1442
-    }
1443
-
1444
-
1445
-
1446
-    /**
1447
-     *        translate_js_strings
1448
-     *
1449
-     * @access        public
1450
-     * @return        void
1451
-     */
1452
-    public function translate_js_strings()
1453
-    {
1454
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1455
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1456
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1457
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1458
-            'event_espresso'
1459
-        );
1460
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1461
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1462
-            'event_espresso'
1463
-        );
1464
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1465
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1466
-            'event_espresso'
1467
-        );
1468
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1469
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1470
-            'event_espresso'
1471
-        );
1472
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1473
-            'This registration step could not be completed. Please refresh the page and try again.',
1474
-            'event_espresso'
1475
-        );
1476
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1477
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1478
-            'event_espresso'
1479
-        );
1480
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1481
-            __(
1482
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1483
-                'event_espresso'
1484
-            ),
1485
-            '<br/>',
1486
-            '<br/>'
1487
-        );
1488
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1489
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1490
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1491
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1492
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1493
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1494
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1495
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1496
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1497
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1498
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1499
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1500
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1501
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1502
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1503
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1504
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1505
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1506
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1507
-            __(
1508
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
1509
-                'event_espresso'
1510
-            ),
1511
-            '<h4 class="important-notice">',
1512
-            '</h4>',
1513
-            '<br />',
1514
-            '<p>',
1515
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1516
-            '">',
1517
-            '</a>',
1518
-            '</p>'
1519
-        );
1520
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1521
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1522
-            true
1523
-        );
1524
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1525
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1526
-        );
1527
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1528
-            'M d, Y H:i:s',
1529
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1530
-        );
1531
-    }
1532
-
1533
-
1534
-
1535
-    /**
1536
-     *    enqueue_styles_and_scripts
1537
-     *
1538
-     * @access        public
1539
-     * @return        void
1540
-     * @throws EE_Error
1541
-     */
1542
-    public function enqueue_styles_and_scripts()
1543
-    {
1544
-        // load css
1545
-        wp_register_style(
1546
-            'single_page_checkout',
1547
-            SPCO_CSS_URL . 'single_page_checkout.css',
1548
-            array('espresso_default'),
1549
-            EVENT_ESPRESSO_VERSION
1550
-        );
1551
-        wp_enqueue_style('single_page_checkout');
1552
-        // load JS
1553
-        wp_register_script(
1554
-            'jquery_plugin',
1555
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1556
-            array('jquery'),
1557
-            '1.0.1',
1558
-            true
1559
-        );
1560
-        wp_register_script(
1561
-            'jquery_countdown',
1562
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1563
-            array('jquery_plugin'),
1564
-            '2.0.2',
1565
-            true
1566
-        );
1567
-        wp_register_script(
1568
-            'single_page_checkout',
1569
-            SPCO_JS_URL . 'single_page_checkout.js',
1570
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1571
-            EVENT_ESPRESSO_VERSION,
1572
-            true
1573
-        );
1574
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1575
-            $this->checkout->registration_form->enqueue_js();
1576
-        }
1577
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1578
-            $this->checkout->current_step->reg_form->enqueue_js();
1579
-        }
1580
-        wp_enqueue_script('single_page_checkout');
1581
-        /**
1582
-         * global action hook for enqueueing styles and scripts with
1583
-         * spco calls.
1584
-         */
1585
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1586
-        /**
1587
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1588
-         * The hook will end up being something like:
1589
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1590
-         */
1591
-        do_action(
1592
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1593
-            $this
1594
-        );
1595
-    }
1596
-
1597
-
1598
-
1599
-    /**
1600
-     *    display the Registration Single Page Checkout Form
1601
-     *
1602
-     * @access    private
1603
-     * @return    void
1604
-     * @throws EE_Error
1605
-     */
1606
-    private function _display_spco_reg_form()
1607
-    {
1608
-        // if registering via the admin, just display the reg form for the current step
1609
-        if ($this->checkout->admin_request) {
1610
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1611
-        } else {
1612
-            // add powered by EE msg
1613
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1614
-            $empty_cart = count(
1615
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1616
-            ) < 1;
1617
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1618
-            $cookies_not_set_msg = '';
1619
-            if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1620
-                $cookies_not_set_msg = apply_filters(
1621
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1622
-                    sprintf(
1623
-                        __(
1624
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1625
-                            'event_espresso'
1626
-                        ),
1627
-                        '<div class="ee-attention">',
1628
-                        '</div>',
1629
-                        '<h6 class="important-notice">',
1630
-                        '</h6>',
1631
-                        '<p>',
1632
-                        '</p>',
1633
-                        '<br />',
1634
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1635
-                        '</a>'
1636
-                    )
1637
-                );
1638
-            }
1639
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1640
-                array(
1641
-                    'name'            => 'single-page-checkout',
1642
-                    'html_id'         => 'ee-single-page-checkout-dv',
1643
-                    'layout_strategy' =>
1644
-                        new EE_Template_Layout(
1645
-                            array(
1646
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1647
-                                'template_args'        => array(
1648
-                                    'empty_cart'              => $empty_cart,
1649
-                                    'revisit'                 => $this->checkout->revisit,
1650
-                                    'reg_steps'               => $this->checkout->reg_steps,
1651
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1652
-                                        ? $this->checkout->next_step->slug()
1653
-                                        : '',
1654
-                                    'cancel_page_url'         => $this->checkout->cancel_page_url,
1655
-                                    'empty_msg'               => apply_filters(
1656
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1657
-                                        sprintf(
1658
-                                            __(
1659
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1660
-                                                'event_espresso'
1661
-                                            ),
1662
-                                            '<a href="'
1663
-                                            . get_post_type_archive_link('espresso_events')
1664
-                                            . '" title="',
1665
-                                            '">',
1666
-                                            '</a>'
1667
-                                        )
1668
-                                    ),
1669
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1670
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1671
-                                    'session_expiration'      => gmdate(
1672
-                                        'M d, Y H:i:s',
1673
-                                        EE_Registry::instance()->SSN->expiration()
1674
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1675
-                                    ),
1676
-                                ),
1677
-                            )
1678
-                        ),
1679
-                )
1680
-            );
1681
-            // load template and add to output sent that gets filtered into the_content()
1682
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1683
-        }
1684
-    }
1685
-
1686
-
1687
-
1688
-    /**
1689
-     *    add_extra_finalize_registration_inputs
1690
-     *
1691
-     * @access    public
1692
-     * @param $next_step
1693
-     * @internal  param string $label
1694
-     * @return void
1695
-     */
1696
-    public function add_extra_finalize_registration_inputs($next_step)
1697
-    {
1698
-        if ($next_step === 'finalize_registration') {
1699
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1700
-        }
1701
-    }
1702
-
1703
-
1704
-
1705
-    /**
1706
-     *    display_registration_footer
1707
-     *
1708
-     * @access    public
1709
-     * @return    string
1710
-     */
1711
-    public static function display_registration_footer()
1712
-    {
1713
-        if (
1714
-        apply_filters(
1715
-            'FHEE__EE_Front__Controller__show_reg_footer',
1716
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1717
-        )
1718
-        ) {
1719
-            add_filter(
1720
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1721
-                function ($url) {
1722
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1723
-                }
1724
-            );
1725
-            echo apply_filters(
1726
-                'FHEE__EE_Front_Controller__display_registration_footer',
1727
-                \EEH_Template::powered_by_event_espresso(
1728
-                    '',
1729
-                    'espresso-registration-footer-dv',
1730
-                    array('utm_content' => 'registration_checkout')
1731
-                )
1732
-            );
1733
-        }
1734
-        return '';
1735
-    }
1736
-
1737
-
1738
-
1739
-    /**
1740
-     *    unlock_transaction
1741
-     *
1742
-     * @access    public
1743
-     * @return    void
1744
-     * @throws EE_Error
1745
-     */
1746
-    public function unlock_transaction()
1747
-    {
1748
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1749
-            $this->checkout->transaction->unlock();
1750
-        }
1751
-    }
1752
-
1753
-
1754
-
1755
-    /**
1756
-     *        _setup_redirect
1757
-     *
1758
-     * @access    private
1759
-     * @return void
1760
-     */
1761
-    private function _setup_redirect()
1762
-    {
1763
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1764
-            $this->checkout->redirect = true;
1765
-            if (empty($this->checkout->redirect_url)) {
1766
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1767
-            }
1768
-            $this->checkout->redirect_url = apply_filters(
1769
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1770
-                $this->checkout->redirect_url,
1771
-                $this->checkout
1772
-            );
1773
-        }
1774
-    }
1775
-
1776
-
1777
-
1778
-    /**
1779
-     *   handle ajax message responses and redirects
1780
-     *
1781
-     * @access public
1782
-     * @return void
1783
-     * @throws EE_Error
1784
-     */
1785
-    public function go_to_next_step()
1786
-    {
1787
-        if (EE_Registry::instance()->REQ->ajax) {
1788
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1789
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1790
-        }
1791
-        $this->unlock_transaction();
1792
-        // just return for these conditions
1793
-        if (
1794
-            $this->checkout->admin_request
1795
-            || $this->checkout->action === 'redirect_form'
1796
-            || $this->checkout->action === 'update_checkout'
1797
-        ) {
1798
-            return;
1799
-        }
1800
-        // AJAX response
1801
-        $this->_handle_json_response();
1802
-        // redirect to next step or the Thank You page
1803
-        $this->_handle_html_redirects();
1804
-        // hmmm... must be something wrong, so let's just display the form again !
1805
-        $this->_display_spco_reg_form();
1806
-    }
1807
-
1808
-
1809
-
1810
-    /**
1811
-     *   _handle_json_response
1812
-     *
1813
-     * @access protected
1814
-     * @return void
1815
-     */
1816
-    protected function _handle_json_response()
1817
-    {
1818
-        // if this is an ajax request
1819
-        if (EE_Registry::instance()->REQ->ajax) {
1820
-            // DEBUG LOG
1821
-            //$this->checkout->log(
1822
-            //	__CLASS__, __FUNCTION__, __LINE__,
1823
-            //	array(
1824
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1825
-            //		'redirect'                   => $this->checkout->redirect,
1826
-            //		'continue_reg'               => $this->checkout->continue_reg,
1827
-            //	)
1828
-            //);
1829
-            $this->checkout->json_response->set_registration_time_limit(
1830
-                $this->checkout->get_registration_time_limit()
1831
-            );
1832
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1833
-            // just send the ajax (
1834
-            $json_response = apply_filters(
1835
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1836
-                $this->checkout->json_response
1837
-            );
1838
-            echo $json_response;
1839
-            exit();
1840
-        }
1841
-    }
1842
-
1843
-
1844
-
1845
-    /**
1846
-     *   _handle_redirects
1847
-     *
1848
-     * @access protected
1849
-     * @return void
1850
-     */
1851
-    protected function _handle_html_redirects()
1852
-    {
1853
-        // going somewhere ?
1854
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1855
-            // store notices in a transient
1856
-            EE_Error::get_notices(false, true, true);
1857
-            // DEBUG LOG
1858
-            //$this->checkout->log(
1859
-            //	__CLASS__, __FUNCTION__, __LINE__,
1860
-            //	array(
1861
-            //		'headers_sent' => headers_sent(),
1862
-            //		'redirect_url'     => $this->checkout->redirect_url,
1863
-            //		'headers_list'    => headers_list(),
1864
-            //	)
1865
-            //);
1866
-            wp_safe_redirect($this->checkout->redirect_url);
1867
-            exit();
1868
-        }
1869
-    }
1870
-
1871
-
1872
-
1873
-    /**
1874
-     *   set_checkout_anchor
1875
-     *
1876
-     * @access public
1877
-     * @return void
1878
-     */
1879
-    public function set_checkout_anchor()
1880
-    {
1881
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1882
-    }
23
+	/**
24
+	 * $_initialized - has the SPCO controller already been initialized ?
25
+	 *
26
+	 * @access private
27
+	 * @var bool $_initialized
28
+	 */
29
+	private static $_initialized = false;
30
+
31
+
32
+	/**
33
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
+	 *
35
+	 * @access private
36
+	 * @var bool $_valid_checkout
37
+	 */
38
+	private static $_checkout_verified = true;
39
+
40
+	/**
41
+	 *    $_reg_steps_array - holds initial array of reg steps
42
+	 *
43
+	 * @access private
44
+	 * @var array $_reg_steps_array
45
+	 */
46
+	private static $_reg_steps_array = array();
47
+
48
+	/**
49
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
+	 *
51
+	 * @access public
52
+	 * @var EE_Checkout $checkout
53
+	 */
54
+	public $checkout;
55
+
56
+
57
+
58
+	/**
59
+	 * @return EED_Module|EED_Single_Page_Checkout
60
+	 */
61
+	public static function instance()
62
+	{
63
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
+		return parent::get_instance(__CLASS__);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return EE_Transaction
81
+	 */
82
+	public function transaction()
83
+	{
84
+		return $this->checkout->transaction;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    set_hooks - for hooking into EE Core, other modules, etc
91
+	 *
92
+	 * @access    public
93
+	 * @return    void
94
+	 * @throws EE_Error
95
+	 */
96
+	public static function set_hooks()
97
+	{
98
+		EED_Single_Page_Checkout::set_definitions();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
+	 *
106
+	 * @access    public
107
+	 * @return    void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		EED_Single_Page_Checkout::set_definitions();
113
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
+			return;
115
+		}
116
+		// going to start an output buffer in case anything gets accidentally output
117
+		// that might disrupt our JSON response
118
+		ob_start();
119
+		EED_Single_Page_Checkout::load_request_handler();
120
+		EED_Single_Page_Checkout::load_reg_steps();
121
+		// set ajax hooks
122
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    process ajax request
134
+	 *
135
+	 * @param string $ajax_action
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function process_ajax_request($ajax_action)
139
+	{
140
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
141
+		EED_Single_Page_Checkout::instance()->_initialize();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *    ajax display registration step
148
+	 *
149
+	 * @throws EE_Error
150
+	 */
151
+	public static function display_reg_step()
152
+	{
153
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    ajax process registration step
160
+	 *
161
+	 * @throws EE_Error
162
+	 */
163
+	public static function process_reg_step()
164
+	{
165
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    ajax process registration step
172
+	 *
173
+	 * @throws EE_Error
174
+	 */
175
+	public static function update_reg_step()
176
+	{
177
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *   update_checkout
184
+	 *
185
+	 * @access public
186
+	 * @return void
187
+	 * @throws EE_Error
188
+	 */
189
+	public static function update_checkout()
190
+	{
191
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 *    load_request_handler
198
+	 *
199
+	 * @access    public
200
+	 * @return    void
201
+	 */
202
+	public static function load_request_handler()
203
+	{
204
+		// load core Request_Handler class
205
+		if (EE_Registry::instance()->REQ !== null) {
206
+			EE_Registry::instance()->load_core('Request_Handler');
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 *    set_definitions
214
+	 *
215
+	 * @access    public
216
+	 * @return    void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function set_definitions()
220
+	{
221
+		if(defined('SPCO_BASE_PATH')) {
222
+			return;
223
+		}
224
+		define(
225
+			'SPCO_BASE_PATH',
226
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+		);
228
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236
+			__('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
237
+				'event_espresso'),
238
+			'<h4 class="important-notice">',
239
+			'</h4>',
240
+			'<br />',
241
+			'<p>',
242
+			'<a href="'
243
+			. apply_filters(
244
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information__process_reg_step__no_regs_link_to_event_list',
245
+				get_post_type_archive_link('espresso_events')
246
+			)
247
+			. '" title="',
248
+			'">',
249
+			'</a>',
250
+			'</p>'
251
+		);
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 * load_reg_steps
258
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
259
+	 *
260
+	 * @access    private
261
+	 * @throws EE_Error
262
+	 */
263
+	public static function load_reg_steps()
264
+	{
265
+		static $reg_steps_loaded = false;
266
+		if ($reg_steps_loaded) {
267
+			return;
268
+		}
269
+		// filter list of reg_steps
270
+		$reg_steps_to_load = (array)apply_filters(
271
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
272
+			EED_Single_Page_Checkout::get_reg_steps()
273
+		);
274
+		// sort by key (order)
275
+		ksort($reg_steps_to_load);
276
+		// loop through folders
277
+		foreach ($reg_steps_to_load as $order => $reg_step) {
278
+			// we need a
279
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
280
+				// copy over to the reg_steps_array
281
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
282
+				// register custom key route for each reg step
283
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
284
+				EE_Config::register_route(
285
+					$reg_step['slug'],
286
+					'EED_Single_Page_Checkout',
287
+					'run',
288
+					'step'
289
+				);
290
+				// add AJAX or other hooks
291
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
292
+					// setup autoloaders if necessary
293
+					if ( ! class_exists($reg_step['class_name'])) {
294
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
295
+							$reg_step['file_path'],
296
+							true
297
+						);
298
+					}
299
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
300
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
301
+					}
302
+				}
303
+			}
304
+		}
305
+		$reg_steps_loaded = true;
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 *    get_reg_steps
312
+	 *
313
+	 * @access    public
314
+	 * @return    array
315
+	 */
316
+	public static function get_reg_steps()
317
+	{
318
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
319
+		if (empty($reg_steps)) {
320
+			$reg_steps = array(
321
+				10  => array(
322
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
323
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
324
+					'slug'       => 'attendee_information',
325
+					'has_hooks'  => false,
326
+				),
327
+				20  => array(
328
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
329
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
330
+					'slug'       => 'registration_confirmation',
331
+					'has_hooks'  => false,
332
+				),
333
+				30  => array(
334
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
335
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
336
+					'slug'       => 'payment_options',
337
+					'has_hooks'  => true,
338
+				),
339
+				999 => array(
340
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
341
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
342
+					'slug'       => 'finalize_registration',
343
+					'has_hooks'  => false,
344
+				),
345
+			);
346
+		}
347
+		return $reg_steps;
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 *    registration_checkout_for_admin
354
+	 *
355
+	 * @access    public
356
+	 * @return    string
357
+	 * @throws EE_Error
358
+	 */
359
+	public static function registration_checkout_for_admin()
360
+	{
361
+		EED_Single_Page_Checkout::load_request_handler();
362
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
363
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
364
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
365
+		EED_Single_Page_Checkout::instance()->_initialize();
366
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
367
+		return EE_Registry::instance()->REQ->get_output();
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 * process_registration_from_admin
374
+	 *
375
+	 * @access public
376
+	 * @return \EE_Transaction
377
+	 * @throws EE_Error
378
+	 */
379
+	public static function process_registration_from_admin()
380
+	{
381
+		EED_Single_Page_Checkout::load_request_handler();
382
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
383
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
384
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
385
+		EED_Single_Page_Checkout::instance()->_initialize();
386
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
387
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
388
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
389
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
390
+				if ($final_reg_step->process_reg_step()) {
391
+					$final_reg_step->set_completed();
392
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
393
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
394
+				}
395
+			}
396
+		}
397
+		return null;
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 *    run
404
+	 *
405
+	 * @access    public
406
+	 * @param WP_Query $WP_Query
407
+	 * @return    void
408
+	 * @throws EE_Error
409
+	 */
410
+	public function run($WP_Query)
411
+	{
412
+		if (
413
+			$WP_Query instanceof WP_Query
414
+			&& $WP_Query->is_main_query()
415
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
416
+			&& $this->_is_reg_checkout()
417
+		) {
418
+			$this->_initialize();
419
+		}
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * determines whether current url matches reg page url
426
+	 *
427
+	 * @return bool
428
+	 */
429
+	protected function _is_reg_checkout()
430
+	{
431
+		// get current permalink for reg page without any extra query args
432
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
433
+		// get request URI for current request, but without the scheme or host
434
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
435
+		$current_request_uri = html_entity_decode($current_request_uri);
436
+		// get array of query args from the current request URI
437
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
438
+		// grab page id if it is set
439
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
440
+		// and remove the page id from the query args (we will re-add it later)
441
+		unset($query_args['page_id']);
442
+		// now strip all query args from current request URI
443
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
444
+		// and re-add the page id if it was set
445
+		if ($page_id) {
446
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
447
+		}
448
+		// remove slashes and ?
449
+		$current_request_uri = trim($current_request_uri, '?/');
450
+		// is current request URI part of the known full reg page URL ?
451
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
452
+	}
453
+
454
+
455
+
456
+	/**
457
+	 * @param WP_Query $wp_query
458
+	 * @return    void
459
+	 * @throws EE_Error
460
+	 */
461
+	public static function init($wp_query)
462
+	{
463
+		EED_Single_Page_Checkout::instance()->run($wp_query);
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 *    _initialize - initial module setup
470
+	 *
471
+	 * @access    private
472
+	 * @throws EE_Error
473
+	 * @return    void
474
+	 */
475
+	private function _initialize()
476
+	{
477
+		// ensure SPCO doesn't run twice
478
+		if (EED_Single_Page_Checkout::$_initialized) {
479
+			return;
480
+		}
481
+		try {
482
+			EED_Single_Page_Checkout::load_reg_steps();
483
+			$this->_verify_session();
484
+			// setup the EE_Checkout object
485
+			$this->checkout = $this->_initialize_checkout();
486
+			// filter checkout
487
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
488
+			// get the $_GET
489
+			$this->_get_request_vars();
490
+			if ($this->_block_bots()) {
491
+				return;
492
+			}
493
+			// filter continue_reg
494
+			$this->checkout->continue_reg = apply_filters(
495
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
496
+				true,
497
+				$this->checkout
498
+			);
499
+			// load the reg steps array
500
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
501
+				EED_Single_Page_Checkout::$_initialized = true;
502
+				return;
503
+			}
504
+			// set the current step
505
+			$this->checkout->set_current_step($this->checkout->step);
506
+			// and the next step
507
+			$this->checkout->set_next_step();
508
+			// verify that everything has been setup correctly
509
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
510
+				EED_Single_Page_Checkout::$_initialized = true;
511
+				return;
512
+			}
513
+			// lock the transaction
514
+			$this->checkout->transaction->lock();
515
+			// make sure all of our cached objects are added to their respective model entity mappers
516
+			$this->checkout->refresh_all_entities();
517
+			// set amount owing
518
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
519
+			// initialize each reg step, which gives them the chance to potentially alter the process
520
+			$this->_initialize_reg_steps();
521
+			// DEBUG LOG
522
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
523
+			// get reg form
524
+			if( ! $this->_check_form_submission()) {
525
+				EED_Single_Page_Checkout::$_initialized = true;
526
+				return;
527
+			}
528
+			// checkout the action!!!
529
+			$this->_process_form_action();
530
+			// add some style and make it dance
531
+			$this->add_styles_and_scripts();
532
+			// kk... SPCO has successfully run
533
+			EED_Single_Page_Checkout::$_initialized = true;
534
+			// set no cache headers and constants
535
+			EE_System::do_not_cache();
536
+			// add anchor
537
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
538
+			// remove transaction lock
539
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
540
+		} catch (Exception $e) {
541
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
542
+		}
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 *    _verify_session
549
+	 * checks that the session is valid and not expired
550
+	 *
551
+	 * @access    private
552
+	 * @throws EE_Error
553
+	 */
554
+	private function _verify_session()
555
+	{
556
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
557
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
558
+		}
559
+		$clear_session_requested = filter_var(
560
+			EE_Registry::instance()->REQ->get('clear_session', false),
561
+			FILTER_VALIDATE_BOOLEAN
562
+		);
563
+		// is session still valid ?
564
+		if ($clear_session_requested
565
+			|| ( EE_Registry::instance()->SSN->expired()
566
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
567
+			)
568
+		) {
569
+			$this->checkout = new EE_Checkout();
570
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
571
+			// EE_Registry::instance()->SSN->reset_cart();
572
+			// EE_Registry::instance()->SSN->reset_checkout();
573
+			// EE_Registry::instance()->SSN->reset_transaction();
574
+			if (! $clear_session_requested) {
575
+				EE_Error::add_attention(
576
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
577
+					__FILE__, __FUNCTION__, __LINE__
578
+				);
579
+			}
580
+			// EE_Registry::instance()->SSN->reset_expired();
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 *    _initialize_checkout
588
+	 * loads and instantiates EE_Checkout
589
+	 *
590
+	 * @access    private
591
+	 * @throws EE_Error
592
+	 * @return EE_Checkout
593
+	 */
594
+	private function _initialize_checkout()
595
+	{
596
+		// look in session for existing checkout
597
+		/** @type EE_Checkout $checkout */
598
+		$checkout = EE_Registry::instance()->SSN->checkout();
599
+		// verify
600
+		if ( ! $checkout instanceof EE_Checkout) {
601
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
602
+			$checkout = EE_Registry::instance()->load_file(
603
+				SPCO_INC_PATH,
604
+				'EE_Checkout',
605
+				'class', array(),
606
+				false
607
+			);
608
+		} else {
609
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
610
+				$this->unlock_transaction();
611
+				wp_safe_redirect($checkout->redirect_url);
612
+				exit();
613
+			}
614
+		}
615
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
616
+		// verify again
617
+		if ( ! $checkout instanceof EE_Checkout) {
618
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
619
+		}
620
+		// reset anything that needs a clean slate for each request
621
+		$checkout->reset_for_current_request();
622
+		return $checkout;
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 *    _get_request_vars
629
+	 *
630
+	 * @access    private
631
+	 * @return    void
632
+	 * @throws EE_Error
633
+	 */
634
+	private function _get_request_vars()
635
+	{
636
+		// load classes
637
+		EED_Single_Page_Checkout::load_request_handler();
638
+		//make sure this request is marked as belonging to EE
639
+		EE_Registry::instance()->REQ->set_espresso_page(true);
640
+		// which step is being requested ?
641
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
642
+		// which step is being edited ?
643
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
644
+		// and what we're doing on the current step
645
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
646
+		// timestamp
647
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
648
+		// returning to edit ?
649
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
650
+		// or some other kind of revisit ?
651
+		$this->checkout->revisit = filter_var(
652
+			EE_Registry::instance()->REQ->get('revisit', false),
653
+			FILTER_VALIDATE_BOOLEAN
654
+		);
655
+		// and whether or not to generate a reg form for this request
656
+		$this->checkout->generate_reg_form = filter_var(
657
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
658
+			FILTER_VALIDATE_BOOLEAN
659
+		);
660
+		// and whether or not to process a reg form submission for this request
661
+		$this->checkout->process_form_submission = filter_var(
662
+			EE_Registry::instance()->REQ->get(
663
+				'process_form_submission',
664
+				$this->checkout->action === 'process_reg_step'
665
+			),
666
+			FILTER_VALIDATE_BOOLEAN
667
+		);
668
+		$this->checkout->process_form_submission = filter_var(
669
+			$this->checkout->action !== 'display_spco_reg_step'
670
+				? $this->checkout->process_form_submission
671
+				: false,
672
+			FILTER_VALIDATE_BOOLEAN
673
+		);
674
+		// $this->_display_request_vars();
675
+	}
676
+
677
+
678
+
679
+	/**
680
+	 *  _display_request_vars
681
+	 *
682
+	 * @access    protected
683
+	 * @return    void
684
+	 */
685
+	protected function _display_request_vars()
686
+	{
687
+		if ( ! WP_DEBUG) {
688
+			return;
689
+		}
690
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
691
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
692
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
693
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
694
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
695
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
696
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
697
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * _block_bots
704
+	 * checks that the incoming request has either of the following set:
705
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
706
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
707
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
708
+	 * then where you coming from man?
709
+	 *
710
+	 * @return boolean
711
+	 */
712
+	private function _block_bots()
713
+	{
714
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
715
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
716
+			return true;
717
+		}
718
+		return false;
719
+	}
720
+
721
+
722
+
723
+	/**
724
+	 *    _get_first_step
725
+	 *  gets slug for first step in $_reg_steps_array
726
+	 *
727
+	 * @access    private
728
+	 * @throws EE_Error
729
+	 * @return    string
730
+	 */
731
+	private function _get_first_step()
732
+	{
733
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
734
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
735
+	}
736
+
737
+
738
+
739
+	/**
740
+	 *    _load_and_instantiate_reg_steps
741
+	 *  instantiates each reg step based on the loaded reg_steps array
742
+	 *
743
+	 * @access    private
744
+	 * @throws EE_Error
745
+	 * @return    bool
746
+	 */
747
+	private function _load_and_instantiate_reg_steps()
748
+	{
749
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
750
+		// have reg_steps already been instantiated ?
751
+		if (
752
+			empty($this->checkout->reg_steps)
753
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
754
+		) {
755
+			// if not, then loop through raw reg steps array
756
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
757
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
758
+					return false;
759
+				}
760
+			}
761
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
762
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
763
+			// skip the registration_confirmation page ?
764
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
765
+				// just remove it from the reg steps array
766
+				$this->checkout->remove_reg_step('registration_confirmation', false);
767
+			} else if (
768
+				isset($this->checkout->reg_steps['registration_confirmation'])
769
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
770
+			) {
771
+				// set the order to something big like 100
772
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
773
+			}
774
+			// filter the array for good luck
775
+			$this->checkout->reg_steps = apply_filters(
776
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
777
+				$this->checkout->reg_steps
778
+			);
779
+			// finally re-sort based on the reg step class order properties
780
+			$this->checkout->sort_reg_steps();
781
+		} else {
782
+			foreach ($this->checkout->reg_steps as $reg_step) {
783
+				// set all current step stati to FALSE
784
+				$reg_step->set_is_current_step(false);
785
+			}
786
+		}
787
+		if (empty($this->checkout->reg_steps)) {
788
+			EE_Error::add_error(
789
+				__('No Reg Steps were loaded..', 'event_espresso'),
790
+				__FILE__, __FUNCTION__, __LINE__
791
+			);
792
+			return false;
793
+		}
794
+		// make reg step details available to JS
795
+		$this->checkout->set_reg_step_JSON_info();
796
+		return true;
797
+	}
798
+
799
+
800
+
801
+	/**
802
+	 *     _load_and_instantiate_reg_step
803
+	 *
804
+	 * @access    private
805
+	 * @param array $reg_step
806
+	 * @param int   $order
807
+	 * @return bool
808
+	 */
809
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
810
+	{
811
+		// we need a file_path, class_name, and slug to add a reg step
812
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
813
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
814
+			if (
815
+				$this->checkout->reg_url_link
816
+				&& $this->checkout->step !== $reg_step['slug']
817
+				&& $reg_step['slug'] !== 'finalize_registration'
818
+				// normally at this point we would NOT load the reg step, but this filter can change that
819
+				&& apply_filters(
820
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
821
+					true,
822
+					$reg_step,
823
+					$this->checkout
824
+				)
825
+			) {
826
+				return true;
827
+			}
828
+			// instantiate step class using file path and class name
829
+			$reg_step_obj = EE_Registry::instance()->load_file(
830
+				$reg_step['file_path'],
831
+				$reg_step['class_name'],
832
+				'class',
833
+				$this->checkout,
834
+				false
835
+			);
836
+			// did we gets the goods ?
837
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
838
+				// set reg step order based on config
839
+				$reg_step_obj->set_order($order);
840
+				// add instantiated reg step object to the master reg steps array
841
+				$this->checkout->add_reg_step($reg_step_obj);
842
+			} else {
843
+				EE_Error::add_error(
844
+					__('The current step could not be set.', 'event_espresso'),
845
+					__FILE__, __FUNCTION__, __LINE__
846
+				);
847
+				return false;
848
+			}
849
+		} else {
850
+			if (WP_DEBUG) {
851
+				EE_Error::add_error(
852
+					sprintf(
853
+						__(
854
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
855
+							'event_espresso'
856
+						),
857
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
858
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
859
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
860
+						'<ul>',
861
+						'<li>',
862
+						'</li>',
863
+						'</ul>'
864
+					),
865
+					__FILE__, __FUNCTION__, __LINE__
866
+				);
867
+			}
868
+			return false;
869
+		}
870
+		return true;
871
+	}
872
+
873
+
874
+	/**
875
+	 * _verify_transaction_and_get_registrations
876
+	 *
877
+	 * @access private
878
+	 * @return bool
879
+	 * @throws InvalidDataTypeException
880
+	 * @throws InvalidEntityException
881
+	 * @throws EE_Error
882
+	 */
883
+	private function _verify_transaction_and_get_registrations()
884
+	{
885
+		// was there already a valid transaction in the checkout from the session ?
886
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
887
+			// get transaction from db or session
888
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
889
+				? $this->_get_transaction_and_cart_for_previous_visit()
890
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
891
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
892
+				EE_Error::add_error(
893
+					__('Your Registration and Transaction information could not be retrieved from the db.',
894
+						'event_espresso'),
895
+					__FILE__, __FUNCTION__, __LINE__
896
+				);
897
+				$this->checkout->transaction = EE_Transaction::new_instance();
898
+				// add some style and make it dance
899
+				$this->add_styles_and_scripts();
900
+				EED_Single_Page_Checkout::$_initialized = true;
901
+				return false;
902
+			}
903
+			// and the registrations for the transaction
904
+			$this->_get_registrations($this->checkout->transaction);
905
+		}
906
+		return true;
907
+	}
908
+
909
+
910
+
911
+	/**
912
+	 * _get_transaction_and_cart_for_previous_visit
913
+	 *
914
+	 * @access private
915
+	 * @return mixed EE_Transaction|NULL
916
+	 */
917
+	private function _get_transaction_and_cart_for_previous_visit()
918
+	{
919
+		/** @var $TXN_model EEM_Transaction */
920
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
921
+		// because the reg_url_link is present in the request,
922
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
923
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
924
+		// verify transaction
925
+		if ($transaction instanceof EE_Transaction) {
926
+			// and get the cart that was used for that transaction
927
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
928
+			return $transaction;
929
+		}
930
+		EE_Error::add_error(
931
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
932
+			__FILE__, __FUNCTION__, __LINE__
933
+		);
934
+		return null;
935
+
936
+	}
937
+
938
+
939
+
940
+	/**
941
+	 * _get_cart_for_transaction
942
+	 *
943
+	 * @access private
944
+	 * @param EE_Transaction $transaction
945
+	 * @return EE_Cart
946
+	 */
947
+	private function _get_cart_for_transaction($transaction)
948
+	{
949
+		return $this->checkout->get_cart_for_transaction($transaction);
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * get_cart_for_transaction
956
+	 *
957
+	 * @access public
958
+	 * @param EE_Transaction $transaction
959
+	 * @return EE_Cart
960
+	 */
961
+	public function get_cart_for_transaction(EE_Transaction $transaction)
962
+	{
963
+		return $this->checkout->get_cart_for_transaction($transaction);
964
+	}
965
+
966
+
967
+
968
+	/**
969
+	 * _get_transaction_and_cart_for_current_session
970
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
971
+	 *
972
+	 * @access private
973
+	 * @return EE_Transaction
974
+	 * @throws EE_Error
975
+	 */
976
+	private function _get_cart_for_current_session_and_setup_new_transaction()
977
+	{
978
+		//  if there's no transaction, then this is the FIRST visit to SPCO
979
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
980
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
981
+		// and then create a new transaction
982
+		$transaction = $this->_initialize_transaction();
983
+		// verify transaction
984
+		if ($transaction instanceof EE_Transaction) {
985
+			// save it so that we have an ID for other objects to use
986
+			$transaction->save();
987
+			// and save TXN data to the cart
988
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
989
+		} else {
990
+			EE_Error::add_error(
991
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
992
+				__FILE__, __FUNCTION__, __LINE__
993
+			);
994
+		}
995
+		return $transaction;
996
+	}
997
+
998
+
999
+
1000
+	/**
1001
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
1002
+	 *
1003
+	 * @access private
1004
+	 * @return mixed EE_Transaction|NULL
1005
+	 */
1006
+	private function _initialize_transaction()
1007
+	{
1008
+		try {
1009
+			// ensure cart totals have been calculated
1010
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
1011
+			// grab the cart grand total
1012
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
1013
+			// create new TXN
1014
+			$transaction = EE_Transaction::new_instance(
1015
+				array(
1016
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1017
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1018
+					'TXN_paid'      => 0,
1019
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1020
+				)
1021
+			);
1022
+			// save it so that we have an ID for other objects to use
1023
+			$transaction->save();
1024
+			// set cron job for following up on TXNs after their session has expired
1025
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1026
+				EE_Registry::instance()->SSN->expiration() + 1,
1027
+				$transaction->ID()
1028
+			);
1029
+			return $transaction;
1030
+		} catch (Exception $e) {
1031
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1032
+		}
1033
+		return null;
1034
+	}
1035
+
1036
+
1037
+	/**
1038
+	 * _get_registrations
1039
+	 *
1040
+	 * @access private
1041
+	 * @param EE_Transaction $transaction
1042
+	 * @return void
1043
+	 * @throws InvalidDataTypeException
1044
+	 * @throws InvalidEntityException
1045
+	 * @throws EE_Error
1046
+	 */
1047
+	private function _get_registrations(EE_Transaction $transaction)
1048
+	{
1049
+		// first step: grab the registrants  { : o
1050
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
1051
+		// verify registrations have been set
1052
+		if (empty($registrations)) {
1053
+			// if no cached registrations, then check the db
1054
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1055
+			// still nothing ? well as long as this isn't a revisit
1056
+			if (empty($registrations) && ! $this->checkout->revisit) {
1057
+				// generate new registrations from scratch
1058
+				$registrations = $this->_initialize_registrations($transaction);
1059
+			}
1060
+		}
1061
+		// sort by their original registration order
1062
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1063
+		// then loop thru the array
1064
+		foreach ($registrations as $registration) {
1065
+			// verify each registration
1066
+			if ($registration instanceof EE_Registration) {
1067
+				// we display all attendee info for the primary registrant
1068
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1069
+					&& $registration->is_primary_registrant()
1070
+				) {
1071
+					$this->checkout->primary_revisit = true;
1072
+					break;
1073
+				}
1074
+				if ($this->checkout->revisit
1075
+						   && $this->checkout->reg_url_link !== $registration->reg_url_link()
1076
+				) {
1077
+					// but hide info if it doesn't belong to you
1078
+					$transaction->clear_cache('Registration', $registration->ID());
1079
+				}
1080
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1081
+			}
1082
+		}
1083
+	}
1084
+
1085
+
1086
+	/**
1087
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1088
+	 *
1089
+	 * @access private
1090
+	 * @param EE_Transaction $transaction
1091
+	 * @return    array
1092
+	 * @throws InvalidDataTypeException
1093
+	 * @throws InvalidEntityException
1094
+	 * @throws EE_Error
1095
+	 */
1096
+	private function _initialize_registrations(EE_Transaction $transaction)
1097
+	{
1098
+		$att_nmbr = 0;
1099
+		$registrations = array();
1100
+		if ($transaction instanceof EE_Transaction) {
1101
+			/** @type EE_Registration_Processor $registration_processor */
1102
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1103
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1104
+			// now let's add the cart items to the $transaction
1105
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1106
+				//do the following for each ticket of this type they selected
1107
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1108
+					$att_nmbr++;
1109
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1110
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1111
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1112
+						array(
1113
+							$transaction,
1114
+							$line_item,
1115
+							$att_nmbr,
1116
+							$this->checkout->total_ticket_count,
1117
+						)
1118
+					);
1119
+					// override capabilities for frontend registrations
1120
+					if ( ! is_admin()) {
1121
+						$CreateRegistrationCommand->setCapCheck(
1122
+							new PublicCapabilities('', 'create_new_registration')
1123
+						);
1124
+					}
1125
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1126
+					if ( ! $registration instanceof EE_Registration) {
1127
+						throw new InvalidEntityException($registration, 'EE_Registration');
1128
+					}
1129
+					$registrations[ $registration->ID() ] = $registration;
1130
+				}
1131
+			}
1132
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1133
+		}
1134
+		return $registrations;
1135
+	}
1136
+
1137
+
1138
+
1139
+	/**
1140
+	 * sorts registrations by REG_count
1141
+	 *
1142
+	 * @access public
1143
+	 * @param EE_Registration $reg_A
1144
+	 * @param EE_Registration $reg_B
1145
+	 * @return int
1146
+	 */
1147
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1148
+	{
1149
+		// this shouldn't ever happen within the same TXN, but oh well
1150
+		if ($reg_A->count() === $reg_B->count()) {
1151
+			return 0;
1152
+		}
1153
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1154
+	}
1155
+
1156
+
1157
+
1158
+	/**
1159
+	 *    _final_verifications
1160
+	 * just makes sure that everything is set up correctly before proceeding
1161
+	 *
1162
+	 * @access    private
1163
+	 * @return    bool
1164
+	 * @throws EE_Error
1165
+	 */
1166
+	private function _final_verifications()
1167
+	{
1168
+		// filter checkout
1169
+		$this->checkout = apply_filters(
1170
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1171
+			$this->checkout
1172
+		);
1173
+		//verify that current step is still set correctly
1174
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1175
+			EE_Error::add_error(
1176
+				__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1177
+				__FILE__,
1178
+				__FUNCTION__,
1179
+				__LINE__
1180
+			);
1181
+			return false;
1182
+		}
1183
+		// if returning to SPCO, then verify that primary registrant is set
1184
+		if ( ! empty($this->checkout->reg_url_link)) {
1185
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1186
+			if ( ! $valid_registrant instanceof EE_Registration) {
1187
+				EE_Error::add_error(
1188
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1189
+					__FILE__,
1190
+					__FUNCTION__,
1191
+					__LINE__
1192
+				);
1193
+				return false;
1194
+			}
1195
+			$valid_registrant = null;
1196
+			foreach (
1197
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1198
+			) {
1199
+				if (
1200
+					$registration instanceof EE_Registration
1201
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1202
+				) {
1203
+					$valid_registrant = $registration;
1204
+				}
1205
+			}
1206
+			if ( ! $valid_registrant instanceof EE_Registration) {
1207
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1208
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1209
+					// clear the session, mark the checkout as unverified, and try again
1210
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1211
+					EED_Single_Page_Checkout::$_initialized = false;
1212
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1213
+					$this->_initialize();
1214
+					EE_Error::reset_notices();
1215
+					return false;
1216
+				}
1217
+				EE_Error::add_error(
1218
+					__(
1219
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1220
+						'event_espresso'
1221
+					),
1222
+					__FILE__,
1223
+					__FUNCTION__,
1224
+					__LINE__
1225
+				);
1226
+				return false;
1227
+			}
1228
+		}
1229
+		// now that things have been kinda sufficiently verified,
1230
+		// let's add the checkout to the session so that it's available to other systems
1231
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1232
+		return true;
1233
+	}
1234
+
1235
+
1236
+
1237
+	/**
1238
+	 *    _initialize_reg_steps
1239
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1240
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1241
+	 *
1242
+	 * @access    private
1243
+	 * @param bool $reinitializing
1244
+	 * @throws EE_Error
1245
+	 */
1246
+	private function _initialize_reg_steps($reinitializing = false)
1247
+	{
1248
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1249
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1250
+		foreach ($this->checkout->reg_steps as $reg_step) {
1251
+			if ( ! $reg_step->initialize_reg_step()) {
1252
+				// if not initialized then maybe this step is being removed...
1253
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1254
+					// if it was the current step, then we need to start over here
1255
+					$this->_initialize_reg_steps(true);
1256
+					return;
1257
+				}
1258
+				continue;
1259
+			}
1260
+			// add css and JS for current step
1261
+			$reg_step->enqueue_styles_and_scripts();
1262
+			// i18n
1263
+			$reg_step->translate_js_strings();
1264
+			if ($reg_step->is_current_step()) {
1265
+				// the text that appears on the reg step form submit button
1266
+				$reg_step->set_submit_button_text();
1267
+			}
1268
+		}
1269
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1270
+		do_action(
1271
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1272
+			$this->checkout->current_step
1273
+		);
1274
+	}
1275
+
1276
+
1277
+
1278
+	/**
1279
+	 * _check_form_submission
1280
+	 *
1281
+	 * @access private
1282
+	 * @return boolean
1283
+	 */
1284
+	private function _check_form_submission()
1285
+	{
1286
+		//does this request require the reg form to be generated ?
1287
+		if ($this->checkout->generate_reg_form) {
1288
+			// ever heard that song by Blue Rodeo ?
1289
+			try {
1290
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1291
+				// if not displaying a form, then check for form submission
1292
+				if (
1293
+					$this->checkout->process_form_submission
1294
+					&& $this->checkout->current_step->reg_form->was_submitted()
1295
+				) {
1296
+					// clear out any old data in case this step is being run again
1297
+					$this->checkout->current_step->set_valid_data(array());
1298
+					// capture submitted form data
1299
+					$this->checkout->current_step->reg_form->receive_form_submission(
1300
+						apply_filters(
1301
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1302
+							EE_Registry::instance()->REQ->params(),
1303
+							$this->checkout
1304
+						)
1305
+					);
1306
+					// validate submitted form data
1307
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1308
+						// thou shall not pass !!!
1309
+						$this->checkout->continue_reg = false;
1310
+						// any form validation errors?
1311
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1312
+							$submission_error_messages = array();
1313
+							// bad, bad, bad registrant
1314
+							foreach (
1315
+								$this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1316
+								as $validation_error
1317
+							) {
1318
+								if ($validation_error instanceof EE_Validation_Error) {
1319
+									$submission_error_messages[] = sprintf(
1320
+										__('%s : %s', 'event_espresso'),
1321
+										$validation_error->get_form_section()->html_label_text(),
1322
+										$validation_error->getMessage()
1323
+									);
1324
+								}
1325
+							}
1326
+							EE_Error::add_error(
1327
+								implode('<br />', $submission_error_messages),
1328
+								__FILE__, __FUNCTION__, __LINE__
1329
+							);
1330
+						}
1331
+						// well not really... what will happen is
1332
+						// we'll just get redirected back to redo the current step
1333
+						$this->go_to_next_step();
1334
+						return false;
1335
+					}
1336
+				}
1337
+			} catch (EE_Error $e) {
1338
+				$e->get_error();
1339
+			}
1340
+		}
1341
+		return true;
1342
+	}
1343
+
1344
+
1345
+
1346
+	/**
1347
+	 * _process_action
1348
+	 *
1349
+	 * @access private
1350
+	 * @return void
1351
+	 * @throws EE_Error
1352
+	 */
1353
+	private function _process_form_action()
1354
+	{
1355
+		// what cha wanna do?
1356
+		switch ($this->checkout->action) {
1357
+			// AJAX next step reg form
1358
+			case 'display_spco_reg_step' :
1359
+				$this->checkout->redirect = false;
1360
+				if (EE_Registry::instance()->REQ->ajax) {
1361
+					$this->checkout->json_response->set_reg_step_html(
1362
+						$this->checkout->current_step->display_reg_form()
1363
+					);
1364
+				}
1365
+				break;
1366
+			default :
1367
+				// meh... do one of those other steps first
1368
+				if (
1369
+					! empty($this->checkout->action)
1370
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1371
+				) {
1372
+					// dynamically creates hook point like:
1373
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1374
+					do_action(
1375
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1376
+						$this->checkout->current_step
1377
+					);
1378
+					// call action on current step
1379
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1380
+						// good registrant, you get to proceed
1381
+						if (
1382
+							$this->checkout->current_step->success_message() !== ''
1383
+							&& apply_filters(
1384
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1385
+								false
1386
+							)
1387
+						) {
1388
+							EE_Error::add_success(
1389
+								$this->checkout->current_step->success_message()
1390
+								. '<br />' . $this->checkout->next_step->_instructions()
1391
+							);
1392
+						}
1393
+						// pack it up, pack it in...
1394
+						$this->_setup_redirect();
1395
+					}
1396
+					// dynamically creates hook point like:
1397
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1398
+					do_action(
1399
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1400
+						$this->checkout->current_step
1401
+					);
1402
+				} else {
1403
+					EE_Error::add_error(
1404
+						sprintf(
1405
+							__(
1406
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1407
+								'event_espresso'
1408
+							),
1409
+							$this->checkout->action,
1410
+							$this->checkout->current_step->name()
1411
+						),
1412
+						__FILE__,
1413
+						__FUNCTION__,
1414
+						__LINE__
1415
+					);
1416
+				}
1417
+			// end default
1418
+		}
1419
+		// store our progress so far
1420
+		$this->checkout->stash_transaction_and_checkout();
1421
+		// advance to the next step! If you pass GO, collect $200
1422
+		$this->go_to_next_step();
1423
+	}
1424
+
1425
+
1426
+
1427
+	/**
1428
+	 *        add_styles_and_scripts
1429
+	 *
1430
+	 * @access        public
1431
+	 * @return        void
1432
+	 */
1433
+	public function add_styles_and_scripts()
1434
+	{
1435
+		// i18n
1436
+		$this->translate_js_strings();
1437
+		if ($this->checkout->admin_request) {
1438
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1439
+		} else {
1440
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1441
+		}
1442
+	}
1443
+
1444
+
1445
+
1446
+	/**
1447
+	 *        translate_js_strings
1448
+	 *
1449
+	 * @access        public
1450
+	 * @return        void
1451
+	 */
1452
+	public function translate_js_strings()
1453
+	{
1454
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1455
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1456
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1457
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1458
+			'event_espresso'
1459
+		);
1460
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1461
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1462
+			'event_espresso'
1463
+		);
1464
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1465
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1466
+			'event_espresso'
1467
+		);
1468
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1469
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1470
+			'event_espresso'
1471
+		);
1472
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1473
+			'This registration step could not be completed. Please refresh the page and try again.',
1474
+			'event_espresso'
1475
+		);
1476
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1477
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1478
+			'event_espresso'
1479
+		);
1480
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1481
+			__(
1482
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1483
+				'event_espresso'
1484
+			),
1485
+			'<br/>',
1486
+			'<br/>'
1487
+		);
1488
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1489
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1490
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1491
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1492
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1493
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1494
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1495
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1496
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1497
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1498
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1499
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1500
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1501
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1502
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1503
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1504
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1505
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1506
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1507
+			__(
1508
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
1509
+				'event_espresso'
1510
+			),
1511
+			'<h4 class="important-notice">',
1512
+			'</h4>',
1513
+			'<br />',
1514
+			'<p>',
1515
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1516
+			'">',
1517
+			'</a>',
1518
+			'</p>'
1519
+		);
1520
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1521
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1522
+			true
1523
+		);
1524
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1525
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1526
+		);
1527
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1528
+			'M d, Y H:i:s',
1529
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1530
+		);
1531
+	}
1532
+
1533
+
1534
+
1535
+	/**
1536
+	 *    enqueue_styles_and_scripts
1537
+	 *
1538
+	 * @access        public
1539
+	 * @return        void
1540
+	 * @throws EE_Error
1541
+	 */
1542
+	public function enqueue_styles_and_scripts()
1543
+	{
1544
+		// load css
1545
+		wp_register_style(
1546
+			'single_page_checkout',
1547
+			SPCO_CSS_URL . 'single_page_checkout.css',
1548
+			array('espresso_default'),
1549
+			EVENT_ESPRESSO_VERSION
1550
+		);
1551
+		wp_enqueue_style('single_page_checkout');
1552
+		// load JS
1553
+		wp_register_script(
1554
+			'jquery_plugin',
1555
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1556
+			array('jquery'),
1557
+			'1.0.1',
1558
+			true
1559
+		);
1560
+		wp_register_script(
1561
+			'jquery_countdown',
1562
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1563
+			array('jquery_plugin'),
1564
+			'2.0.2',
1565
+			true
1566
+		);
1567
+		wp_register_script(
1568
+			'single_page_checkout',
1569
+			SPCO_JS_URL . 'single_page_checkout.js',
1570
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1571
+			EVENT_ESPRESSO_VERSION,
1572
+			true
1573
+		);
1574
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1575
+			$this->checkout->registration_form->enqueue_js();
1576
+		}
1577
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1578
+			$this->checkout->current_step->reg_form->enqueue_js();
1579
+		}
1580
+		wp_enqueue_script('single_page_checkout');
1581
+		/**
1582
+		 * global action hook for enqueueing styles and scripts with
1583
+		 * spco calls.
1584
+		 */
1585
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1586
+		/**
1587
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1588
+		 * The hook will end up being something like:
1589
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1590
+		 */
1591
+		do_action(
1592
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1593
+			$this
1594
+		);
1595
+	}
1596
+
1597
+
1598
+
1599
+	/**
1600
+	 *    display the Registration Single Page Checkout Form
1601
+	 *
1602
+	 * @access    private
1603
+	 * @return    void
1604
+	 * @throws EE_Error
1605
+	 */
1606
+	private function _display_spco_reg_form()
1607
+	{
1608
+		// if registering via the admin, just display the reg form for the current step
1609
+		if ($this->checkout->admin_request) {
1610
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1611
+		} else {
1612
+			// add powered by EE msg
1613
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1614
+			$empty_cart = count(
1615
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1616
+			) < 1;
1617
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1618
+			$cookies_not_set_msg = '';
1619
+			if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1620
+				$cookies_not_set_msg = apply_filters(
1621
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1622
+					sprintf(
1623
+						__(
1624
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1625
+							'event_espresso'
1626
+						),
1627
+						'<div class="ee-attention">',
1628
+						'</div>',
1629
+						'<h6 class="important-notice">',
1630
+						'</h6>',
1631
+						'<p>',
1632
+						'</p>',
1633
+						'<br />',
1634
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1635
+						'</a>'
1636
+					)
1637
+				);
1638
+			}
1639
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1640
+				array(
1641
+					'name'            => 'single-page-checkout',
1642
+					'html_id'         => 'ee-single-page-checkout-dv',
1643
+					'layout_strategy' =>
1644
+						new EE_Template_Layout(
1645
+							array(
1646
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1647
+								'template_args'        => array(
1648
+									'empty_cart'              => $empty_cart,
1649
+									'revisit'                 => $this->checkout->revisit,
1650
+									'reg_steps'               => $this->checkout->reg_steps,
1651
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1652
+										? $this->checkout->next_step->slug()
1653
+										: '',
1654
+									'cancel_page_url'         => $this->checkout->cancel_page_url,
1655
+									'empty_msg'               => apply_filters(
1656
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1657
+										sprintf(
1658
+											__(
1659
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1660
+												'event_espresso'
1661
+											),
1662
+											'<a href="'
1663
+											. get_post_type_archive_link('espresso_events')
1664
+											. '" title="',
1665
+											'">',
1666
+											'</a>'
1667
+										)
1668
+									),
1669
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1670
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1671
+									'session_expiration'      => gmdate(
1672
+										'M d, Y H:i:s',
1673
+										EE_Registry::instance()->SSN->expiration()
1674
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1675
+									),
1676
+								),
1677
+							)
1678
+						),
1679
+				)
1680
+			);
1681
+			// load template and add to output sent that gets filtered into the_content()
1682
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1683
+		}
1684
+	}
1685
+
1686
+
1687
+
1688
+	/**
1689
+	 *    add_extra_finalize_registration_inputs
1690
+	 *
1691
+	 * @access    public
1692
+	 * @param $next_step
1693
+	 * @internal  param string $label
1694
+	 * @return void
1695
+	 */
1696
+	public function add_extra_finalize_registration_inputs($next_step)
1697
+	{
1698
+		if ($next_step === 'finalize_registration') {
1699
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1700
+		}
1701
+	}
1702
+
1703
+
1704
+
1705
+	/**
1706
+	 *    display_registration_footer
1707
+	 *
1708
+	 * @access    public
1709
+	 * @return    string
1710
+	 */
1711
+	public static function display_registration_footer()
1712
+	{
1713
+		if (
1714
+		apply_filters(
1715
+			'FHEE__EE_Front__Controller__show_reg_footer',
1716
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1717
+		)
1718
+		) {
1719
+			add_filter(
1720
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1721
+				function ($url) {
1722
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1723
+				}
1724
+			);
1725
+			echo apply_filters(
1726
+				'FHEE__EE_Front_Controller__display_registration_footer',
1727
+				\EEH_Template::powered_by_event_espresso(
1728
+					'',
1729
+					'espresso-registration-footer-dv',
1730
+					array('utm_content' => 'registration_checkout')
1731
+				)
1732
+			);
1733
+		}
1734
+		return '';
1735
+	}
1736
+
1737
+
1738
+
1739
+	/**
1740
+	 *    unlock_transaction
1741
+	 *
1742
+	 * @access    public
1743
+	 * @return    void
1744
+	 * @throws EE_Error
1745
+	 */
1746
+	public function unlock_transaction()
1747
+	{
1748
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1749
+			$this->checkout->transaction->unlock();
1750
+		}
1751
+	}
1752
+
1753
+
1754
+
1755
+	/**
1756
+	 *        _setup_redirect
1757
+	 *
1758
+	 * @access    private
1759
+	 * @return void
1760
+	 */
1761
+	private function _setup_redirect()
1762
+	{
1763
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1764
+			$this->checkout->redirect = true;
1765
+			if (empty($this->checkout->redirect_url)) {
1766
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1767
+			}
1768
+			$this->checkout->redirect_url = apply_filters(
1769
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1770
+				$this->checkout->redirect_url,
1771
+				$this->checkout
1772
+			);
1773
+		}
1774
+	}
1775
+
1776
+
1777
+
1778
+	/**
1779
+	 *   handle ajax message responses and redirects
1780
+	 *
1781
+	 * @access public
1782
+	 * @return void
1783
+	 * @throws EE_Error
1784
+	 */
1785
+	public function go_to_next_step()
1786
+	{
1787
+		if (EE_Registry::instance()->REQ->ajax) {
1788
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1789
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1790
+		}
1791
+		$this->unlock_transaction();
1792
+		// just return for these conditions
1793
+		if (
1794
+			$this->checkout->admin_request
1795
+			|| $this->checkout->action === 'redirect_form'
1796
+			|| $this->checkout->action === 'update_checkout'
1797
+		) {
1798
+			return;
1799
+		}
1800
+		// AJAX response
1801
+		$this->_handle_json_response();
1802
+		// redirect to next step or the Thank You page
1803
+		$this->_handle_html_redirects();
1804
+		// hmmm... must be something wrong, so let's just display the form again !
1805
+		$this->_display_spco_reg_form();
1806
+	}
1807
+
1808
+
1809
+
1810
+	/**
1811
+	 *   _handle_json_response
1812
+	 *
1813
+	 * @access protected
1814
+	 * @return void
1815
+	 */
1816
+	protected function _handle_json_response()
1817
+	{
1818
+		// if this is an ajax request
1819
+		if (EE_Registry::instance()->REQ->ajax) {
1820
+			// DEBUG LOG
1821
+			//$this->checkout->log(
1822
+			//	__CLASS__, __FUNCTION__, __LINE__,
1823
+			//	array(
1824
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1825
+			//		'redirect'                   => $this->checkout->redirect,
1826
+			//		'continue_reg'               => $this->checkout->continue_reg,
1827
+			//	)
1828
+			//);
1829
+			$this->checkout->json_response->set_registration_time_limit(
1830
+				$this->checkout->get_registration_time_limit()
1831
+			);
1832
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1833
+			// just send the ajax (
1834
+			$json_response = apply_filters(
1835
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1836
+				$this->checkout->json_response
1837
+			);
1838
+			echo $json_response;
1839
+			exit();
1840
+		}
1841
+	}
1842
+
1843
+
1844
+
1845
+	/**
1846
+	 *   _handle_redirects
1847
+	 *
1848
+	 * @access protected
1849
+	 * @return void
1850
+	 */
1851
+	protected function _handle_html_redirects()
1852
+	{
1853
+		// going somewhere ?
1854
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1855
+			// store notices in a transient
1856
+			EE_Error::get_notices(false, true, true);
1857
+			// DEBUG LOG
1858
+			//$this->checkout->log(
1859
+			//	__CLASS__, __FUNCTION__, __LINE__,
1860
+			//	array(
1861
+			//		'headers_sent' => headers_sent(),
1862
+			//		'redirect_url'     => $this->checkout->redirect_url,
1863
+			//		'headers_list'    => headers_list(),
1864
+			//	)
1865
+			//);
1866
+			wp_safe_redirect($this->checkout->redirect_url);
1867
+			exit();
1868
+		}
1869
+	}
1870
+
1871
+
1872
+
1873
+	/**
1874
+	 *   set_checkout_anchor
1875
+	 *
1876
+	 * @access public
1877
+	 * @return void
1878
+	 */
1879
+	public function set_checkout_anchor()
1880
+	{
1881
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1882
+	}
1883 1883
 
1884 1884
 
1885 1885
 
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -218,19 +218,19 @@  discard block
 block discarded – undo
218 218
      */
219 219
     public static function set_definitions()
220 220
     {
221
-        if(defined('SPCO_BASE_PATH')) {
221
+        if (defined('SPCO_BASE_PATH')) {
222 222
             return;
223 223
         }
224 224
         define(
225 225
             'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
226
+            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS
227 227
         );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
228
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
229
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
230
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
231
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
232
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
233
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
234 234
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235 235
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236 236
             __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
             return;
268 268
         }
269 269
         // filter list of reg_steps
270
-        $reg_steps_to_load = (array)apply_filters(
270
+        $reg_steps_to_load = (array) apply_filters(
271 271
             'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
272 272
             EED_Single_Page_Checkout::get_reg_steps()
273 273
         );
@@ -319,25 +319,25 @@  discard block
 block discarded – undo
319 319
         if (empty($reg_steps)) {
320 320
             $reg_steps = array(
321 321
                 10  => array(
322
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
322
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
323 323
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
324 324
                     'slug'       => 'attendee_information',
325 325
                     'has_hooks'  => false,
326 326
                 ),
327 327
                 20  => array(
328
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
328
+                    'file_path'  => SPCO_REG_STEPS_PATH.'registration_confirmation',
329 329
                     'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
330 330
                     'slug'       => 'registration_confirmation',
331 331
                     'has_hooks'  => false,
332 332
                 ),
333 333
                 30  => array(
334
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
334
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
335 335
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
336 336
                     'slug'       => 'payment_options',
337 337
                     'has_hooks'  => true,
338 338
                 ),
339 339
                 999 => array(
340
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
340
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
341 341
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
342 342
                     'slug'       => 'finalize_registration',
343 343
                     'has_hooks'  => false,
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
             // DEBUG LOG
522 522
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
523 523
             // get reg form
524
-            if( ! $this->_check_form_submission()) {
524
+            if ( ! $this->_check_form_submission()) {
525 525
                 EED_Single_Page_Checkout::$_initialized = true;
526 526
                 return;
527 527
             }
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
         );
563 563
         // is session still valid ?
564 564
         if ($clear_session_requested
565
-            || ( EE_Registry::instance()->SSN->expired()
565
+            || (EE_Registry::instance()->SSN->expired()
566 566
               && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
567 567
             )
568 568
         ) {
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
             // EE_Registry::instance()->SSN->reset_cart();
572 572
             // EE_Registry::instance()->SSN->reset_checkout();
573 573
             // EE_Registry::instance()->SSN->reset_transaction();
574
-            if (! $clear_session_requested) {
574
+            if ( ! $clear_session_requested) {
575 575
                 EE_Error::add_attention(
576 576
                     EE_Registry::$i18n_js_strings['registration_expiration_notice'],
577 577
                     __FILE__, __FUNCTION__, __LINE__
@@ -1126,7 +1126,7 @@  discard block
 block discarded – undo
1126 1126
                     if ( ! $registration instanceof EE_Registration) {
1127 1127
                         throw new InvalidEntityException($registration, 'EE_Registration');
1128 1128
                     }
1129
-                    $registrations[ $registration->ID() ] = $registration;
1129
+                    $registrations[$registration->ID()] = $registration;
1130 1130
                 }
1131 1131
             }
1132 1132
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1387,7 +1387,7 @@  discard block
 block discarded – undo
1387 1387
                         ) {
1388 1388
                             EE_Error::add_success(
1389 1389
                                 $this->checkout->current_step->success_message()
1390
-                                . '<br />' . $this->checkout->next_step->_instructions()
1390
+                                . '<br />'.$this->checkout->next_step->_instructions()
1391 1391
                             );
1392 1392
                         }
1393 1393
                         // pack it up, pack it in...
@@ -1512,7 +1512,7 @@  discard block
 block discarded – undo
1512 1512
             '</h4>',
1513 1513
             '<br />',
1514 1514
             '<p>',
1515
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1515
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1516 1516
             '">',
1517 1517
             '</a>',
1518 1518
             '</p>'
@@ -1544,7 +1544,7 @@  discard block
 block discarded – undo
1544 1544
         // load css
1545 1545
         wp_register_style(
1546 1546
             'single_page_checkout',
1547
-            SPCO_CSS_URL . 'single_page_checkout.css',
1547
+            SPCO_CSS_URL.'single_page_checkout.css',
1548 1548
             array('espresso_default'),
1549 1549
             EVENT_ESPRESSO_VERSION
1550 1550
         );
@@ -1552,21 +1552,21 @@  discard block
 block discarded – undo
1552 1552
         // load JS
1553 1553
         wp_register_script(
1554 1554
             'jquery_plugin',
1555
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1555
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1556 1556
             array('jquery'),
1557 1557
             '1.0.1',
1558 1558
             true
1559 1559
         );
1560 1560
         wp_register_script(
1561 1561
             'jquery_countdown',
1562
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1562
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1563 1563
             array('jquery_plugin'),
1564 1564
             '2.0.2',
1565 1565
             true
1566 1566
         );
1567 1567
         wp_register_script(
1568 1568
             'single_page_checkout',
1569
-            SPCO_JS_URL . 'single_page_checkout.js',
1569
+            SPCO_JS_URL.'single_page_checkout.js',
1570 1570
             array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1571 1571
             EVENT_ESPRESSO_VERSION,
1572 1572
             true
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1590 1590
          */
1591 1591
         do_action(
1592
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1592
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1593 1593
             $this
1594 1594
         );
1595 1595
     }
@@ -1643,7 +1643,7 @@  discard block
 block discarded – undo
1643 1643
                     'layout_strategy' =>
1644 1644
                         new EE_Template_Layout(
1645 1645
                             array(
1646
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1646
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1647 1647
                                 'template_args'        => array(
1648 1648
                                     'empty_cart'              => $empty_cart,
1649 1649
                                     'revisit'                 => $this->checkout->revisit,
@@ -1718,7 +1718,7 @@  discard block
 block discarded – undo
1718 1718
         ) {
1719 1719
             add_filter(
1720 1720
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1721
-                function ($url) {
1721
+                function($url) {
1722 1722
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1723 1723
                 }
1724 1724
             );
Please login to merge, or discard this patch.