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