Completed
Branch BUG-10307-no-js-form-submissio... (069387)
by
unknown
24:32 queued 13:33
created
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Indentation   +1688 added lines, -1688 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,1693 +17,1693 @@  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
-            if( ! $this->_check_form_submission()) {
503
-                EED_Single_Page_Checkout::$_initialized = true;
504
-                return;
505
-            }
506
-            // checkout the action!!!
507
-            $this->_process_form_action();
508
-            // add some style and make it dance
509
-            $this->add_styles_and_scripts();
510
-            // kk... SPCO has successfully run
511
-            EED_Single_Page_Checkout::$_initialized = true;
512
-            // set no cache headers and constants
513
-            EE_System::do_not_cache();
514
-            // add anchor
515
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
516
-            // remove transaction lock
517
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
518
-        } catch (Exception $e) {
519
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
520
-        }
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     *    _verify_session
527
-     * checks that the session is valid and not expired
528
-     *
529
-     * @access    private
530
-     * @throws EE_Error
531
-     */
532
-    private function _verify_session()
533
-    {
534
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
535
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
536
-        }
537
-        // is session still valid ?
538
-        if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') {
539
-            $this->checkout = new EE_Checkout();
540
-            EE_Registry::instance()->SSN->reset_cart();
541
-            EE_Registry::instance()->SSN->reset_checkout();
542
-            EE_Registry::instance()->SSN->reset_transaction();
543
-            EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__,
544
-                __FUNCTION__, __LINE__);
545
-            EE_Registry::instance()->SSN->reset_expired();
546
-        }
547
-    }
548
-
549
-
550
-
551
-    /**
552
-     *    _initialize_checkout
553
-     * loads and instantiates EE_Checkout
554
-     *
555
-     * @access    private
556
-     * @throws EE_Error
557
-     * @return EE_Checkout
558
-     */
559
-    private function _initialize_checkout()
560
-    {
561
-        // look in session for existing checkout
562
-        /** @type EE_Checkout $checkout */
563
-        $checkout = EE_Registry::instance()->SSN->checkout();
564
-        // verify
565
-        if ( ! $checkout instanceof EE_Checkout) {
566
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
567
-            $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false);
568
-        } else {
569
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
570
-                $this->unlock_transaction();
571
-                wp_safe_redirect($checkout->redirect_url);
572
-                exit();
573
-            }
574
-        }
575
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
576
-        // verify again
577
-        if ( ! $checkout instanceof EE_Checkout) {
578
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
579
-        }
580
-        // reset anything that needs a clean slate for each request
581
-        $checkout->reset_for_current_request();
582
-        return $checkout;
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     *    _get_request_vars
589
-     *
590
-     * @access    private
591
-     * @return    void
592
-     * @throws \EE_Error
593
-     */
594
-    private function _get_request_vars()
595
-    {
596
-        // load classes
597
-        EED_Single_Page_Checkout::load_request_handler();
598
-        //make sure this request is marked as belonging to EE
599
-        EE_Registry::instance()->REQ->set_espresso_page(true);
600
-        // which step is being requested ?
601
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
602
-        // which step is being edited ?
603
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
604
-        // and what we're doing on the current step
605
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
606
-        // timestamp
607
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
608
-        // returning to edit ?
609
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
610
-        // or some other kind of revisit ?
611
-        $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false);
612
-        // and whether or not to generate a reg form for this request
613
-        $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true);        // TRUE 	FALSE
614
-        // and whether or not to process a reg form submission for this request
615
-        $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get(
616
-            'process_form_submission',
617
-            $this->checkout->action === 'process_reg_step'
618
-        ); // TRUE 	FALSE
619
-        $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step'
620
-            ? $this->checkout->process_form_submission
621
-            : false;        // TRUE 	FALSE
622
-        // $this->_display_request_vars();
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     *  _display_request_vars
629
-     *
630
-     * @access    protected
631
-     * @return    void
632
-     */
633
-    protected function _display_request_vars()
634
-    {
635
-        if ( ! WP_DEBUG) {
636
-            return;
637
-        }
638
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
639
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
640
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
641
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
642
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
643
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
644
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
645
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * _block_bots
652
-     * checks that the incoming request has either of the following set:
653
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
654
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
655
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
656
-     * then where you coming from man?
657
-     *
658
-     * @return boolean
659
-     */
660
-    private function _block_bots()
661
-    {
662
-        $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
663
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
664
-            return true;
665
-        }
666
-        return false;
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     *    _get_first_step
673
-     *  gets slug for first step in $_reg_steps_array
674
-     *
675
-     * @access    private
676
-     * @throws EE_Error
677
-     * @return    array
678
-     */
679
-    private function _get_first_step()
680
-    {
681
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
682
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     *    _load_and_instantiate_reg_steps
689
-     *  instantiates each reg step based on the loaded reg_steps array
690
-     *
691
-     * @access    private
692
-     * @throws EE_Error
693
-     * @return    bool
694
-     */
695
-    private function _load_and_instantiate_reg_steps()
696
-    {
697
-        // have reg_steps already been instantiated ?
698
-        if (
699
-            empty($this->checkout->reg_steps)
700
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
701
-        ) {
702
-            // if not, then loop through raw reg steps array
703
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
704
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
705
-                    return false;
706
-                }
707
-            }
708
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
709
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
710
-            // skip the registration_confirmation page ?
711
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
712
-                // just remove it from the reg steps array
713
-                $this->checkout->remove_reg_step('registration_confirmation', false);
714
-            } else if (
715
-                isset($this->checkout->reg_steps['registration_confirmation'])
716
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
717
-            ) {
718
-                // set the order to something big like 100
719
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
720
-            }
721
-            // filter the array for good luck
722
-            $this->checkout->reg_steps = apply_filters(
723
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
724
-                $this->checkout->reg_steps
725
-            );
726
-            // finally re-sort based on the reg step class order properties
727
-            $this->checkout->sort_reg_steps();
728
-        } else {
729
-            foreach ($this->checkout->reg_steps as $reg_step) {
730
-                // set all current step stati to FALSE
731
-                $reg_step->set_is_current_step(false);
732
-            }
733
-        }
734
-        if (empty($this->checkout->reg_steps)) {
735
-            EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
736
-            return false;
737
-        }
738
-        // make reg step details available to JS
739
-        $this->checkout->set_reg_step_JSON_info();
740
-        return true;
741
-    }
742
-
743
-
744
-
745
-    /**
746
-     *     _load_and_instantiate_reg_step
747
-     *
748
-     * @access    private
749
-     * @param array $reg_step
750
-     * @param int   $order
751
-     * @return bool
752
-     */
753
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
754
-    {
755
-        // we need a file_path, class_name, and slug to add a reg step
756
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
757
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
758
-            if (
759
-                $this->checkout->reg_url_link
760
-                && $this->checkout->step !== $reg_step['slug']
761
-                && $reg_step['slug'] !== 'finalize_registration'
762
-            ) {
763
-                return true;
764
-            }
765
-            // instantiate step class using file path and class name
766
-            $reg_step_obj = EE_Registry::instance()->load_file(
767
-                $reg_step['file_path'],
768
-                $reg_step['class_name'],
769
-                'class',
770
-                $this->checkout,
771
-                false
772
-            );
773
-            // did we gets the goods ?
774
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
775
-                // set reg step order based on config
776
-                $reg_step_obj->set_order($order);
777
-                // add instantiated reg step object to the master reg steps array
778
-                $this->checkout->add_reg_step($reg_step_obj);
779
-            } else {
780
-                EE_Error::add_error(
781
-                    __('The current step could not be set.', 'event_espresso'),
782
-                    __FILE__, __FUNCTION__, __LINE__
783
-                );
784
-                return false;
785
-            }
786
-        } else {
787
-            if (WP_DEBUG) {
788
-                EE_Error::add_error(
789
-                    sprintf(
790
-                        __('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'),
791
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
792
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
793
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
794
-                        '<ul>',
795
-                        '<li>',
796
-                        '</li>',
797
-                        '</ul>'
798
-                    ),
799
-                    __FILE__, __FUNCTION__, __LINE__
800
-                );
801
-            }
802
-            return false;
803
-        }
804
-        return true;
805
-    }
806
-
807
-
808
-
809
-    /**
810
-     * _verify_transaction_and_get_registrations
811
-     *
812
-     * @access private
813
-     * @return bool
814
-     */
815
-    private function _verify_transaction_and_get_registrations()
816
-    {
817
-        // was there already a valid transaction in the checkout from the session ?
818
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
819
-            // get transaction from db or session
820
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
821
-                ? $this->_get_transaction_and_cart_for_previous_visit()
822
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
823
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
824
-                EE_Error::add_error(
825
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
826
-                        'event_espresso'),
827
-                    __FILE__, __FUNCTION__, __LINE__
828
-                );
829
-                $this->checkout->transaction = EE_Transaction::new_instance();
830
-                // add some style and make it dance
831
-                $this->add_styles_and_scripts();
832
-                EED_Single_Page_Checkout::$_initialized = true;
833
-                return false;
834
-            }
835
-            // and the registrations for the transaction
836
-            $this->_get_registrations($this->checkout->transaction);
837
-        }
838
-        return true;
839
-    }
840
-
841
-
842
-
843
-    /**
844
-     * _get_transaction_and_cart_for_previous_visit
845
-     *
846
-     * @access private
847
-     * @return mixed EE_Transaction|NULL
848
-     */
849
-    private function _get_transaction_and_cart_for_previous_visit()
850
-    {
851
-        /** @var $TXN_model EEM_Transaction */
852
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
853
-        // 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
854
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
855
-        // verify transaction
856
-        if ($transaction instanceof EE_Transaction) {
857
-            // and get the cart that was used for that transaction
858
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
859
-            return $transaction;
860
-        } else {
861
-            EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
862
-            return null;
863
-        }
864
-    }
865
-
866
-
867
-
868
-    /**
869
-     * _get_cart_for_transaction
870
-     *
871
-     * @access private
872
-     * @param EE_Transaction $transaction
873
-     * @return EE_Cart
874
-     */
875
-    private function _get_cart_for_transaction($transaction)
876
-    {
877
-        return $this->checkout->get_cart_for_transaction($transaction);
878
-    }
879
-
880
-
881
-
882
-    /**
883
-     * get_cart_for_transaction
884
-     *
885
-     * @access public
886
-     * @param EE_Transaction $transaction
887
-     * @return EE_Cart
888
-     */
889
-    public function get_cart_for_transaction(EE_Transaction $transaction)
890
-    {
891
-        return $this->checkout->get_cart_for_transaction($transaction);
892
-    }
893
-
894
-
895
-
896
-    /**
897
-     * _get_transaction_and_cart_for_current_session
898
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
899
-     *
900
-     * @access private
901
-     * @return EE_Transaction
902
-     * @throws \EE_Error
903
-     */
904
-    private function _get_cart_for_current_session_and_setup_new_transaction()
905
-    {
906
-        //  if there's no transaction, then this is the FIRST visit to SPCO
907
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
908
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
909
-        // and then create a new transaction
910
-        $transaction = $this->_initialize_transaction();
911
-        // verify transaction
912
-        if ($transaction instanceof EE_Transaction) {
913
-            // save it so that we have an ID for other objects to use
914
-            $transaction->save();
915
-            // and save TXN data to the cart
916
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
917
-        } else {
918
-            EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
919
-        }
920
-        return $transaction;
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
927
-     *
928
-     * @access private
929
-     * @return mixed EE_Transaction|NULL
930
-     */
931
-    private function _initialize_transaction()
932
-    {
933
-        try {
934
-            // ensure cart totals have been calculated
935
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
936
-            // grab the cart grand total
937
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
938
-            // create new TXN
939
-            $transaction = EE_Transaction::new_instance(
940
-                array(
941
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
942
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
943
-                    'TXN_paid'      => 0,
944
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
945
-                )
946
-            );
947
-            // save it so that we have an ID for other objects to use
948
-            $transaction->save();
949
-            // set cron job for following up on TXNs after their session has expired
950
-            EE_Cron_Tasks::schedule_expired_transaction_check(
951
-                EE_Registry::instance()->SSN->expiration() + 1,
952
-                $transaction->ID()
953
-            );
954
-            return $transaction;
955
-        } catch (Exception $e) {
956
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
957
-        }
958
-        return null;
959
-    }
960
-
961
-
962
-
963
-    /**
964
-     * _get_registrations
965
-     *
966
-     * @access private
967
-     * @param EE_Transaction $transaction
968
-     * @return void
969
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
970
-     * @throws \EE_Error
971
-     */
972
-    private function _get_registrations(EE_Transaction $transaction)
973
-    {
974
-        // first step: grab the registrants  { : o
975
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
976
-        // verify registrations have been set
977
-        if (empty($registrations)) {
978
-            // if no cached registrations, then check the db
979
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
980
-            // still nothing ? well as long as this isn't a revisit
981
-            if (empty($registrations) && ! $this->checkout->revisit) {
982
-                // generate new registrations from scratch
983
-                $registrations = $this->_initialize_registrations($transaction);
984
-            }
985
-        }
986
-        // sort by their original registration order
987
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
988
-        // then loop thru the array
989
-        foreach ($registrations as $registration) {
990
-            // verify each registration
991
-            if ($registration instanceof EE_Registration) {
992
-                // we display all attendee info for the primary registrant
993
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
994
-                    && $registration->is_primary_registrant()
995
-                ) {
996
-                    $this->checkout->primary_revisit = true;
997
-                    break;
998
-                } else if ($this->checkout->revisit
999
-                           && $this->checkout->reg_url_link !== $registration->reg_url_link()
1000
-                ) {
1001
-                    // but hide info if it doesn't belong to you
1002
-                    $transaction->clear_cache('Registration', $registration->ID());
1003
-                }
1004
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1005
-            }
1006
-        }
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1013
-     *
1014
-     * @access private
1015
-     * @param EE_Transaction $transaction
1016
-     * @return    array
1017
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
1018
-     * @throws \EE_Error
1019
-     */
1020
-    private function _initialize_registrations(EE_Transaction $transaction)
1021
-    {
1022
-        $att_nmbr = 0;
1023
-        $registrations = array();
1024
-        if ($transaction instanceof EE_Transaction) {
1025
-            /** @type EE_Registration_Processor $registration_processor */
1026
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1027
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1028
-            // now let's add the cart items to the $transaction
1029
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1030
-                //do the following for each ticket of this type they selected
1031
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1032
-                    $att_nmbr++;
1033
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1034
-                    $CreateRegistrationCommand = EE_Registry::instance()
1035
-                                                            ->create(
1036
-                                                                'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1037
-                                                                array(
1038
-                                                                    $transaction,
1039
-                                                                    $line_item,
1040
-                                                                    $att_nmbr,
1041
-                                                                    $this->checkout->total_ticket_count,
1042
-                                                                )
1043
-                                                            );
1044
-                    // override capabilities for frontend registrations
1045
-                    if ( ! is_admin()) {
1046
-                        $CreateRegistrationCommand->setCapCheck(
1047
-                            new PublicCapabilities('', 'create_new_registration')
1048
-                        );
1049
-                    }
1050
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1051
-                    if ( ! $registration instanceof EE_Registration) {
1052
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1053
-                    }
1054
-                    $registrations[ $registration->ID() ] = $registration;
1055
-                }
1056
-            }
1057
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1058
-        }
1059
-        return $registrations;
1060
-    }
1061
-
1062
-
1063
-
1064
-    /**
1065
-     * sorts registrations by REG_count
1066
-     *
1067
-     * @access public
1068
-     * @param EE_Registration $reg_A
1069
-     * @param EE_Registration $reg_B
1070
-     * @return int
1071
-     */
1072
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1073
-    {
1074
-        // this shouldn't ever happen within the same TXN, but oh well
1075
-        if ($reg_A->count() === $reg_B->count()) {
1076
-            return 0;
1077
-        }
1078
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1079
-    }
1080
-
1081
-
1082
-
1083
-    /**
1084
-     *    _final_verifications
1085
-     * just makes sure that everything is set up correctly before proceeding
1086
-     *
1087
-     * @access    private
1088
-     * @return    bool
1089
-     * @throws \EE_Error
1090
-     */
1091
-    private function _final_verifications()
1092
-    {
1093
-        // filter checkout
1094
-        $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout);
1095
-        //verify that current step is still set correctly
1096
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1097
-            EE_Error::add_error(
1098
-                __('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'),
1099
-                __FILE__,
1100
-                __FUNCTION__,
1101
-                __LINE__
1102
-            );
1103
-            return false;
1104
-        }
1105
-        // if returning to SPCO, then verify that primary registrant is set
1106
-        if ( ! empty($this->checkout->reg_url_link)) {
1107
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1108
-            if ( ! $valid_registrant instanceof EE_Registration) {
1109
-                EE_Error::add_error(
1110
-                    __('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'),
1111
-                    __FILE__,
1112
-                    __FUNCTION__,
1113
-                    __LINE__
1114
-                );
1115
-                return false;
1116
-            }
1117
-            $valid_registrant = null;
1118
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1119
-                if (
1120
-                    $registration instanceof EE_Registration
1121
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1122
-                ) {
1123
-                    $valid_registrant = $registration;
1124
-                }
1125
-            }
1126
-            if ( ! $valid_registrant instanceof EE_Registration) {
1127
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1128
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1129
-                    // clear the session, mark the checkout as unverified, and try again
1130
-                    EE_Registry::instance()->SSN->clear_session();
1131
-                    EED_Single_Page_Checkout::$_initialized = false;
1132
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1133
-                    $this->_initialize();
1134
-                    EE_Error::reset_notices();
1135
-                    return false;
1136
-                }
1137
-                EE_Error::add_error(
1138
-                    __('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'),
1139
-                    __FILE__,
1140
-                    __FUNCTION__,
1141
-                    __LINE__
1142
-                );
1143
-                return false;
1144
-            }
1145
-        }
1146
-        // now that things have been kinda sufficiently verified,
1147
-        // let's add the checkout to the session so that's available other systems
1148
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1149
-        return true;
1150
-    }
1151
-
1152
-
1153
-
1154
-    /**
1155
-     *    _initialize_reg_steps
1156
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1157
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1158
-     *
1159
-     * @access    private
1160
-     * @param bool $reinitializing
1161
-     * @throws \EE_Error
1162
-     */
1163
-    private function _initialize_reg_steps($reinitializing = false)
1164
-    {
1165
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1166
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1167
-        foreach ($this->checkout->reg_steps as $reg_step) {
1168
-            if ( ! $reg_step->initialize_reg_step()) {
1169
-                // if not initialized then maybe this step is being removed...
1170
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1171
-                    // if it was the current step, then we need to start over here
1172
-                    $this->_initialize_reg_steps(true);
1173
-                    return;
1174
-                }
1175
-                continue;
1176
-            }
1177
-            // add css and JS for current step
1178
-            $reg_step->enqueue_styles_and_scripts();
1179
-            // i18n
1180
-            $reg_step->translate_js_strings();
1181
-            if ($reg_step->is_current_step()) {
1182
-                // the text that appears on the reg step form submit button
1183
-                $reg_step->set_submit_button_text();
1184
-            }
1185
-        }
1186
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1187
-        do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step);
1188
-    }
1189
-
1190
-
1191
-
1192
-    /**
1193
-     * _check_form_submission
1194
-     *
1195
-     * @access private
1196
-     * @return boolean
1197
-     */
1198
-    private function _check_form_submission()
1199
-    {
1200
-        //does this request require the reg form to be generated ?
1201
-        if ($this->checkout->generate_reg_form) {
1202
-            // ever heard that song by Blue Rodeo ?
1203
-            try {
1204
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1205
-                // if not displaying a form, then check for form submission
1206
-                if (
1207
-                    $this->checkout->process_form_submission
1208
-                    && $this->checkout->current_step->reg_form->was_submitted()
1209
-                ) {
1210
-                    // clear out any old data in case this step is being run again
1211
-                    $this->checkout->current_step->set_valid_data(array());
1212
-                    // capture submitted form data
1213
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1214
-                        apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout)
1215
-                    );
1216
-                    // validate submitted form data
1217
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1218
-                        // thou shall not pass !!!
1219
-                        $this->checkout->continue_reg = false;
1220
-                        // any form validation errors?
1221
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1222
-                            $submission_error_messages = array();
1223
-                            // bad, bad, bad registrant
1224
-                            foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) {
1225
-                                if ($validation_error instanceof EE_Validation_Error) {
1226
-                                    $submission_error_messages[] = sprintf(
1227
-                                        __('%s : %s', 'event_espresso'),
1228
-                                        $validation_error->get_form_section()->html_label_text(),
1229
-                                        $validation_error->getMessage()
1230
-                                    );
1231
-                                }
1232
-                            }
1233
-                            EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1234
-                        }
1235
-                        // well not really... what will happen is we'll just get redirected back to redo the current step
1236
-                        $this->go_to_next_step();
1237
-                        return false;
1238
-                    }
1239
-                }
1240
-            } catch (EE_Error $e) {
1241
-                $e->get_error();
1242
-            }
1243
-        }
1244
-        return true;
1245
-    }
1246
-
1247
-
1248
-
1249
-    /**
1250
-     * _process_action
1251
-     *
1252
-     * @access private
1253
-     * @return void
1254
-     * @throws \EE_Error
1255
-     */
1256
-    private function _process_form_action()
1257
-    {
1258
-        // what cha wanna do?
1259
-        switch ($this->checkout->action) {
1260
-            // AJAX next step reg form
1261
-            case 'display_spco_reg_step' :
1262
-                $this->checkout->redirect = false;
1263
-                if (EE_Registry::instance()->REQ->ajax) {
1264
-                    $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form());
1265
-                }
1266
-                break;
1267
-            default :
1268
-                // meh... do one of those other steps first
1269
-                if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) {
1270
-                    // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1271
-                    do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1272
-                    // call action on current step
1273
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1274
-                        // good registrant, you get to proceed
1275
-                        if (
1276
-                            $this->checkout->current_step->success_message() !== ''
1277
-                            && apply_filters(
1278
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1279
-                                false
1280
-                            )
1281
-                        ) {
1282
-                            EE_Error::add_success(
1283
-                                $this->checkout->current_step->success_message()
1284
-                                . '<br />' . $this->checkout->next_step->_instructions()
1285
-                            );
1286
-                        }
1287
-                        // pack it up, pack it in...
1288
-                        $this->_setup_redirect();
1289
-                    }
1290
-                    // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1291
-                    do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1292
-                } else {
1293
-                    EE_Error::add_error(
1294
-                        sprintf(
1295
-                            __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'),
1296
-                            $this->checkout->action,
1297
-                            $this->checkout->current_step->name()
1298
-                        ),
1299
-                        __FILE__,
1300
-                        __FUNCTION__,
1301
-                        __LINE__
1302
-                    );
1303
-                }
1304
-            // end default
1305
-        }
1306
-        // store our progress so far
1307
-        $this->checkout->stash_transaction_and_checkout();
1308
-        // advance to the next step! If you pass GO, collect $200
1309
-        $this->go_to_next_step();
1310
-    }
1311
-
1312
-
1313
-
1314
-    /**
1315
-     *        add_styles_and_scripts
1316
-     *
1317
-     * @access        public
1318
-     * @return        void
1319
-     */
1320
-    public function add_styles_and_scripts()
1321
-    {
1322
-        // i18n
1323
-        $this->translate_js_strings();
1324
-        if ($this->checkout->admin_request) {
1325
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1326
-        } else {
1327
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1328
-        }
1329
-    }
1330
-
1331
-
1332
-
1333
-    /**
1334
-     *        translate_js_strings
1335
-     *
1336
-     * @access        public
1337
-     * @return        void
1338
-     */
1339
-    public function translate_js_strings()
1340
-    {
1341
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1342
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1343
-        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');
1344
-        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');
1345
-        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');
1346
-        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');
1347
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso');
1348
-        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');
1349
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1350
-            __('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'),
1351
-            '<br/>',
1352
-            '<br/>'
1353
-        );
1354
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1355
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1356
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1357
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1358
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1359
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1360
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1361
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1362
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1363
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1364
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1365
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1366
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1367
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1368
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1369
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1370
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1371
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1372
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1373
-            __(
1374
-                '%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',
1375
-                'event_espresso'
1376
-            ),
1377
-            '<h4 class="important-notice">',
1378
-            '</h4>',
1379
-            '<br />',
1380
-            '<p>',
1381
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1382
-            '">',
1383
-            '</a>',
1384
-            '</p>'
1385
-        );
1386
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true);
1387
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1388
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1389
-        );
1390
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1391
-            'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1392
-        );
1393
-    }
1394
-
1395
-
1396
-
1397
-    /**
1398
-     *    enqueue_styles_and_scripts
1399
-     *
1400
-     * @access        public
1401
-     * @return        void
1402
-     * @throws \EE_Error
1403
-     */
1404
-    public function enqueue_styles_and_scripts()
1405
-    {
1406
-        // load css
1407
-        wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1408
-        wp_enqueue_style('single_page_checkout');
1409
-        // load JS
1410
-        wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1411
-        wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1412
-        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);
1413
-        $this->checkout->registration_form->enqueue_js();
1414
-        $this->checkout->current_step->reg_form->enqueue_js();
1415
-        wp_enqueue_script('single_page_checkout');
1416
-        /**
1417
-         * global action hook for enqueueing styles and scripts with
1418
-         * spco calls.
1419
-         */
1420
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1421
-        /**
1422
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1423
-         * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1424
-         */
1425
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this);
1426
-    }
1427
-
1428
-
1429
-
1430
-    /**
1431
-     *    display the Registration Single Page Checkout Form
1432
-     *
1433
-     * @access    private
1434
-     * @return    void
1435
-     * @throws \EE_Error
1436
-     */
1437
-    private function _display_spco_reg_form()
1438
-    {
1439
-        // if registering via the admin, just display the reg form for the current step
1440
-        if ($this->checkout->admin_request) {
1441
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1442
-        } else {
1443
-            // add powered by EE msg
1444
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1445
-            $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1
1446
-                ? true
1447
-                : false;
1448
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1449
-            $cookies_not_set_msg = '';
1450
-            if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1451
-                $cookies_not_set_msg = apply_filters(
1452
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1453
-                    sprintf(
1454
-                        __(
1455
-                            '%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',
1456
-                            'event_espresso'
1457
-                        ),
1458
-                        '<div class="ee-attention">',
1459
-                        '</div>',
1460
-                        '<h6 class="important-notice">',
1461
-                        '</h6>',
1462
-                        '<p>',
1463
-                        '</p>',
1464
-                        '<br />',
1465
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1466
-                        '</a>'
1467
-                    )
1468
-                );
1469
-            }
1470
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1471
-                array(
1472
-                    'name'            => 'single-page-checkout',
1473
-                    'html_id'         => 'ee-single-page-checkout-dv',
1474
-                    'layout_strategy' =>
1475
-                        new EE_Template_Layout(
1476
-                            array(
1477
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1478
-                                'template_args'        => array(
1479
-                                    'empty_cart'              => $empty_cart,
1480
-                                    'revisit'                 => $this->checkout->revisit,
1481
-                                    'reg_steps'               => $this->checkout->reg_steps,
1482
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1483
-                                        ? $this->checkout->next_step->slug()
1484
-                                        : '',
1485
-                                    'cancel_page_url'         => $this->checkout->cancel_page_url,
1486
-                                    'empty_msg'               => apply_filters(
1487
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1488
-                                        sprintf(
1489
-                                            __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1490
-                                                'event_espresso'),
1491
-                                            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1492
-                                            '">',
1493
-                                            '</a>'
1494
-                                        )
1495
-                                    ),
1496
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1497
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1498
-                                    'session_expiration'      =>
1499
-                                        date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)),
1500
-                                ),
1501
-                            )
1502
-                        ),
1503
-                )
1504
-            );
1505
-            // load template and add to output sent that gets filtered into the_content()
1506
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1507
-        }
1508
-    }
1509
-
1510
-
1511
-
1512
-    /**
1513
-     *    add_extra_finalize_registration_inputs
1514
-     *
1515
-     * @access    public
1516
-     * @param $next_step
1517
-     * @internal  param string $label
1518
-     * @return void
1519
-     */
1520
-    public function add_extra_finalize_registration_inputs($next_step)
1521
-    {
1522
-        if ($next_step === 'finalize_registration') {
1523
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1524
-        }
1525
-    }
1526
-
1527
-
1528
-
1529
-    /**
1530
-     *    display_registration_footer
1531
-     *
1532
-     * @access    public
1533
-     * @return    string
1534
-     */
1535
-    public static function display_registration_footer()
1536
-    {
1537
-        if (
1538
-        apply_filters(
1539
-            'FHEE__EE_Front__Controller__show_reg_footer',
1540
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1541
-        )
1542
-        ) {
1543
-            add_filter(
1544
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1545
-                function ($url) {
1546
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1547
-                }
1548
-            );
1549
-            echo apply_filters(
1550
-                'FHEE__EE_Front_Controller__display_registration_footer',
1551
-                \EEH_Template::powered_by_event_espresso(
1552
-                    '',
1553
-                    'espresso-registration-footer-dv',
1554
-                    array('utm_content' => 'registration_checkout')
1555
-                )
1556
-            );
1557
-        }
1558
-        return '';
1559
-    }
1560
-
1561
-
1562
-
1563
-    /**
1564
-     *    unlock_transaction
1565
-     *
1566
-     * @access    public
1567
-     * @return    void
1568
-     * @throws \EE_Error
1569
-     */
1570
-    public function unlock_transaction()
1571
-    {
1572
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1573
-            $this->checkout->transaction->unlock();
1574
-        }
1575
-    }
1576
-
1577
-
1578
-
1579
-    /**
1580
-     *        _setup_redirect
1581
-     *
1582
-     * @access    private
1583
-     * @return void
1584
-     */
1585
-    private function _setup_redirect()
1586
-    {
1587
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1588
-            $this->checkout->redirect = true;
1589
-            if (empty($this->checkout->redirect_url)) {
1590
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1591
-            }
1592
-            $this->checkout->redirect_url = apply_filters(
1593
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1594
-                $this->checkout->redirect_url,
1595
-                $this->checkout
1596
-            );
1597
-        }
1598
-    }
1599
-
1600
-
1601
-
1602
-    /**
1603
-     *   handle ajax message responses and redirects
1604
-     *
1605
-     * @access public
1606
-     * @return void
1607
-     * @throws \EE_Error
1608
-     */
1609
-    public function go_to_next_step()
1610
-    {
1611
-        if (EE_Registry::instance()->REQ->ajax) {
1612
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1613
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1614
-        }
1615
-        $this->unlock_transaction();
1616
-        // just return for these conditions
1617
-        if (
1618
-            $this->checkout->admin_request
1619
-            || $this->checkout->action === 'redirect_form'
1620
-            || $this->checkout->action === 'update_checkout'
1621
-        ) {
1622
-            return;
1623
-        }
1624
-        // AJAX response
1625
-        $this->_handle_json_response();
1626
-        // redirect to next step or the Thank You page
1627
-        $this->_handle_html_redirects();
1628
-        // hmmm... must be something wrong, so let's just display the form again !
1629
-        $this->_display_spco_reg_form();
1630
-    }
1631
-
1632
-
1633
-
1634
-    /**
1635
-     *   _handle_json_response
1636
-     *
1637
-     * @access protected
1638
-     * @return void
1639
-     */
1640
-    protected function _handle_json_response()
1641
-    {
1642
-        // if this is an ajax request
1643
-        if (EE_Registry::instance()->REQ->ajax) {
1644
-            // DEBUG LOG
1645
-            //$this->checkout->log(
1646
-            //	__CLASS__, __FUNCTION__, __LINE__,
1647
-            //	array(
1648
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1649
-            //		'redirect'                   => $this->checkout->redirect,
1650
-            //		'continue_reg'               => $this->checkout->continue_reg,
1651
-            //	)
1652
-            //);
1653
-            $this->checkout->json_response->set_registration_time_limit(
1654
-                $this->checkout->get_registration_time_limit()
1655
-            );
1656
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1657
-            // just send the ajax (
1658
-            $json_response = apply_filters(
1659
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1660
-                $this->checkout->json_response
1661
-            );
1662
-            echo $json_response;
1663
-            exit();
1664
-        }
1665
-    }
1666
-
1667
-
1668
-
1669
-    /**
1670
-     *   _handle_redirects
1671
-     *
1672
-     * @access protected
1673
-     * @return void
1674
-     */
1675
-    protected function _handle_html_redirects()
1676
-    {
1677
-        // going somewhere ?
1678
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1679
-            // store notices in a transient
1680
-            EE_Error::get_notices(false, true, true);
1681
-            // DEBUG LOG
1682
-            //$this->checkout->log(
1683
-            //	__CLASS__, __FUNCTION__, __LINE__,
1684
-            //	array(
1685
-            //		'headers_sent' => headers_sent(),
1686
-            //		'redirect_url'     => $this->checkout->redirect_url,
1687
-            //		'headers_list'    => headers_list(),
1688
-            //	)
1689
-            //);
1690
-            wp_safe_redirect($this->checkout->redirect_url);
1691
-            exit();
1692
-        }
1693
-    }
1694
-
1695
-
1696
-
1697
-    /**
1698
-     *   set_checkout_anchor
1699
-     *
1700
-     * @access public
1701
-     * @return void
1702
-     */
1703
-    public function set_checkout_anchor()
1704
-    {
1705
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1706
-    }
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
+			if( ! $this->_check_form_submission()) {
503
+				EED_Single_Page_Checkout::$_initialized = true;
504
+				return;
505
+			}
506
+			// checkout the action!!!
507
+			$this->_process_form_action();
508
+			// add some style and make it dance
509
+			$this->add_styles_and_scripts();
510
+			// kk... SPCO has successfully run
511
+			EED_Single_Page_Checkout::$_initialized = true;
512
+			// set no cache headers and constants
513
+			EE_System::do_not_cache();
514
+			// add anchor
515
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
516
+			// remove transaction lock
517
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
518
+		} catch (Exception $e) {
519
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
520
+		}
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 *    _verify_session
527
+	 * checks that the session is valid and not expired
528
+	 *
529
+	 * @access    private
530
+	 * @throws EE_Error
531
+	 */
532
+	private function _verify_session()
533
+	{
534
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
535
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
536
+		}
537
+		// is session still valid ?
538
+		if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') {
539
+			$this->checkout = new EE_Checkout();
540
+			EE_Registry::instance()->SSN->reset_cart();
541
+			EE_Registry::instance()->SSN->reset_checkout();
542
+			EE_Registry::instance()->SSN->reset_transaction();
543
+			EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__,
544
+				__FUNCTION__, __LINE__);
545
+			EE_Registry::instance()->SSN->reset_expired();
546
+		}
547
+	}
548
+
549
+
550
+
551
+	/**
552
+	 *    _initialize_checkout
553
+	 * loads and instantiates EE_Checkout
554
+	 *
555
+	 * @access    private
556
+	 * @throws EE_Error
557
+	 * @return EE_Checkout
558
+	 */
559
+	private function _initialize_checkout()
560
+	{
561
+		// look in session for existing checkout
562
+		/** @type EE_Checkout $checkout */
563
+		$checkout = EE_Registry::instance()->SSN->checkout();
564
+		// verify
565
+		if ( ! $checkout instanceof EE_Checkout) {
566
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
567
+			$checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false);
568
+		} else {
569
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
570
+				$this->unlock_transaction();
571
+				wp_safe_redirect($checkout->redirect_url);
572
+				exit();
573
+			}
574
+		}
575
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
576
+		// verify again
577
+		if ( ! $checkout instanceof EE_Checkout) {
578
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
579
+		}
580
+		// reset anything that needs a clean slate for each request
581
+		$checkout->reset_for_current_request();
582
+		return $checkout;
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 *    _get_request_vars
589
+	 *
590
+	 * @access    private
591
+	 * @return    void
592
+	 * @throws \EE_Error
593
+	 */
594
+	private function _get_request_vars()
595
+	{
596
+		// load classes
597
+		EED_Single_Page_Checkout::load_request_handler();
598
+		//make sure this request is marked as belonging to EE
599
+		EE_Registry::instance()->REQ->set_espresso_page(true);
600
+		// which step is being requested ?
601
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
602
+		// which step is being edited ?
603
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
604
+		// and what we're doing on the current step
605
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
606
+		// timestamp
607
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
608
+		// returning to edit ?
609
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
610
+		// or some other kind of revisit ?
611
+		$this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false);
612
+		// and whether or not to generate a reg form for this request
613
+		$this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true);        // TRUE 	FALSE
614
+		// and whether or not to process a reg form submission for this request
615
+		$this->checkout->process_form_submission = EE_Registry::instance()->REQ->get(
616
+			'process_form_submission',
617
+			$this->checkout->action === 'process_reg_step'
618
+		); // TRUE 	FALSE
619
+		$this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step'
620
+			? $this->checkout->process_form_submission
621
+			: false;        // TRUE 	FALSE
622
+		// $this->_display_request_vars();
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 *  _display_request_vars
629
+	 *
630
+	 * @access    protected
631
+	 * @return    void
632
+	 */
633
+	protected function _display_request_vars()
634
+	{
635
+		if ( ! WP_DEBUG) {
636
+			return;
637
+		}
638
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
639
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
640
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
641
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
642
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
643
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
644
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
645
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * _block_bots
652
+	 * checks that the incoming request has either of the following set:
653
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
654
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
655
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
656
+	 * then where you coming from man?
657
+	 *
658
+	 * @return boolean
659
+	 */
660
+	private function _block_bots()
661
+	{
662
+		$invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
663
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
664
+			return true;
665
+		}
666
+		return false;
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 *    _get_first_step
673
+	 *  gets slug for first step in $_reg_steps_array
674
+	 *
675
+	 * @access    private
676
+	 * @throws EE_Error
677
+	 * @return    array
678
+	 */
679
+	private function _get_first_step()
680
+	{
681
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
682
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 *    _load_and_instantiate_reg_steps
689
+	 *  instantiates each reg step based on the loaded reg_steps array
690
+	 *
691
+	 * @access    private
692
+	 * @throws EE_Error
693
+	 * @return    bool
694
+	 */
695
+	private function _load_and_instantiate_reg_steps()
696
+	{
697
+		// have reg_steps already been instantiated ?
698
+		if (
699
+			empty($this->checkout->reg_steps)
700
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
701
+		) {
702
+			// if not, then loop through raw reg steps array
703
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
704
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
705
+					return false;
706
+				}
707
+			}
708
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
709
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
710
+			// skip the registration_confirmation page ?
711
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
712
+				// just remove it from the reg steps array
713
+				$this->checkout->remove_reg_step('registration_confirmation', false);
714
+			} else if (
715
+				isset($this->checkout->reg_steps['registration_confirmation'])
716
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
717
+			) {
718
+				// set the order to something big like 100
719
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
720
+			}
721
+			// filter the array for good luck
722
+			$this->checkout->reg_steps = apply_filters(
723
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
724
+				$this->checkout->reg_steps
725
+			);
726
+			// finally re-sort based on the reg step class order properties
727
+			$this->checkout->sort_reg_steps();
728
+		} else {
729
+			foreach ($this->checkout->reg_steps as $reg_step) {
730
+				// set all current step stati to FALSE
731
+				$reg_step->set_is_current_step(false);
732
+			}
733
+		}
734
+		if (empty($this->checkout->reg_steps)) {
735
+			EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
736
+			return false;
737
+		}
738
+		// make reg step details available to JS
739
+		$this->checkout->set_reg_step_JSON_info();
740
+		return true;
741
+	}
742
+
743
+
744
+
745
+	/**
746
+	 *     _load_and_instantiate_reg_step
747
+	 *
748
+	 * @access    private
749
+	 * @param array $reg_step
750
+	 * @param int   $order
751
+	 * @return bool
752
+	 */
753
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
754
+	{
755
+		// we need a file_path, class_name, and slug to add a reg step
756
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
757
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
758
+			if (
759
+				$this->checkout->reg_url_link
760
+				&& $this->checkout->step !== $reg_step['slug']
761
+				&& $reg_step['slug'] !== 'finalize_registration'
762
+			) {
763
+				return true;
764
+			}
765
+			// instantiate step class using file path and class name
766
+			$reg_step_obj = EE_Registry::instance()->load_file(
767
+				$reg_step['file_path'],
768
+				$reg_step['class_name'],
769
+				'class',
770
+				$this->checkout,
771
+				false
772
+			);
773
+			// did we gets the goods ?
774
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
775
+				// set reg step order based on config
776
+				$reg_step_obj->set_order($order);
777
+				// add instantiated reg step object to the master reg steps array
778
+				$this->checkout->add_reg_step($reg_step_obj);
779
+			} else {
780
+				EE_Error::add_error(
781
+					__('The current step could not be set.', 'event_espresso'),
782
+					__FILE__, __FUNCTION__, __LINE__
783
+				);
784
+				return false;
785
+			}
786
+		} else {
787
+			if (WP_DEBUG) {
788
+				EE_Error::add_error(
789
+					sprintf(
790
+						__('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'),
791
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
792
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
793
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
794
+						'<ul>',
795
+						'<li>',
796
+						'</li>',
797
+						'</ul>'
798
+					),
799
+					__FILE__, __FUNCTION__, __LINE__
800
+				);
801
+			}
802
+			return false;
803
+		}
804
+		return true;
805
+	}
806
+
807
+
808
+
809
+	/**
810
+	 * _verify_transaction_and_get_registrations
811
+	 *
812
+	 * @access private
813
+	 * @return bool
814
+	 */
815
+	private function _verify_transaction_and_get_registrations()
816
+	{
817
+		// was there already a valid transaction in the checkout from the session ?
818
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
819
+			// get transaction from db or session
820
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
821
+				? $this->_get_transaction_and_cart_for_previous_visit()
822
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
823
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
824
+				EE_Error::add_error(
825
+					__('Your Registration and Transaction information could not be retrieved from the db.',
826
+						'event_espresso'),
827
+					__FILE__, __FUNCTION__, __LINE__
828
+				);
829
+				$this->checkout->transaction = EE_Transaction::new_instance();
830
+				// add some style and make it dance
831
+				$this->add_styles_and_scripts();
832
+				EED_Single_Page_Checkout::$_initialized = true;
833
+				return false;
834
+			}
835
+			// and the registrations for the transaction
836
+			$this->_get_registrations($this->checkout->transaction);
837
+		}
838
+		return true;
839
+	}
840
+
841
+
842
+
843
+	/**
844
+	 * _get_transaction_and_cart_for_previous_visit
845
+	 *
846
+	 * @access private
847
+	 * @return mixed EE_Transaction|NULL
848
+	 */
849
+	private function _get_transaction_and_cart_for_previous_visit()
850
+	{
851
+		/** @var $TXN_model EEM_Transaction */
852
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
853
+		// 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
854
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
855
+		// verify transaction
856
+		if ($transaction instanceof EE_Transaction) {
857
+			// and get the cart that was used for that transaction
858
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
859
+			return $transaction;
860
+		} else {
861
+			EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
862
+			return null;
863
+		}
864
+	}
865
+
866
+
867
+
868
+	/**
869
+	 * _get_cart_for_transaction
870
+	 *
871
+	 * @access private
872
+	 * @param EE_Transaction $transaction
873
+	 * @return EE_Cart
874
+	 */
875
+	private function _get_cart_for_transaction($transaction)
876
+	{
877
+		return $this->checkout->get_cart_for_transaction($transaction);
878
+	}
879
+
880
+
881
+
882
+	/**
883
+	 * get_cart_for_transaction
884
+	 *
885
+	 * @access public
886
+	 * @param EE_Transaction $transaction
887
+	 * @return EE_Cart
888
+	 */
889
+	public function get_cart_for_transaction(EE_Transaction $transaction)
890
+	{
891
+		return $this->checkout->get_cart_for_transaction($transaction);
892
+	}
893
+
894
+
895
+
896
+	/**
897
+	 * _get_transaction_and_cart_for_current_session
898
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
899
+	 *
900
+	 * @access private
901
+	 * @return EE_Transaction
902
+	 * @throws \EE_Error
903
+	 */
904
+	private function _get_cart_for_current_session_and_setup_new_transaction()
905
+	{
906
+		//  if there's no transaction, then this is the FIRST visit to SPCO
907
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
908
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
909
+		// and then create a new transaction
910
+		$transaction = $this->_initialize_transaction();
911
+		// verify transaction
912
+		if ($transaction instanceof EE_Transaction) {
913
+			// save it so that we have an ID for other objects to use
914
+			$transaction->save();
915
+			// and save TXN data to the cart
916
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
917
+		} else {
918
+			EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
919
+		}
920
+		return $transaction;
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
927
+	 *
928
+	 * @access private
929
+	 * @return mixed EE_Transaction|NULL
930
+	 */
931
+	private function _initialize_transaction()
932
+	{
933
+		try {
934
+			// ensure cart totals have been calculated
935
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
936
+			// grab the cart grand total
937
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
938
+			// create new TXN
939
+			$transaction = EE_Transaction::new_instance(
940
+				array(
941
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
942
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
943
+					'TXN_paid'      => 0,
944
+					'STS_ID'        => EEM_Transaction::failed_status_code,
945
+				)
946
+			);
947
+			// save it so that we have an ID for other objects to use
948
+			$transaction->save();
949
+			// set cron job for following up on TXNs after their session has expired
950
+			EE_Cron_Tasks::schedule_expired_transaction_check(
951
+				EE_Registry::instance()->SSN->expiration() + 1,
952
+				$transaction->ID()
953
+			);
954
+			return $transaction;
955
+		} catch (Exception $e) {
956
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
957
+		}
958
+		return null;
959
+	}
960
+
961
+
962
+
963
+	/**
964
+	 * _get_registrations
965
+	 *
966
+	 * @access private
967
+	 * @param EE_Transaction $transaction
968
+	 * @return void
969
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
970
+	 * @throws \EE_Error
971
+	 */
972
+	private function _get_registrations(EE_Transaction $transaction)
973
+	{
974
+		// first step: grab the registrants  { : o
975
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
976
+		// verify registrations have been set
977
+		if (empty($registrations)) {
978
+			// if no cached registrations, then check the db
979
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
980
+			// still nothing ? well as long as this isn't a revisit
981
+			if (empty($registrations) && ! $this->checkout->revisit) {
982
+				// generate new registrations from scratch
983
+				$registrations = $this->_initialize_registrations($transaction);
984
+			}
985
+		}
986
+		// sort by their original registration order
987
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
988
+		// then loop thru the array
989
+		foreach ($registrations as $registration) {
990
+			// verify each registration
991
+			if ($registration instanceof EE_Registration) {
992
+				// we display all attendee info for the primary registrant
993
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
994
+					&& $registration->is_primary_registrant()
995
+				) {
996
+					$this->checkout->primary_revisit = true;
997
+					break;
998
+				} else if ($this->checkout->revisit
999
+						   && $this->checkout->reg_url_link !== $registration->reg_url_link()
1000
+				) {
1001
+					// but hide info if it doesn't belong to you
1002
+					$transaction->clear_cache('Registration', $registration->ID());
1003
+				}
1004
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1005
+			}
1006
+		}
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1013
+	 *
1014
+	 * @access private
1015
+	 * @param EE_Transaction $transaction
1016
+	 * @return    array
1017
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
1018
+	 * @throws \EE_Error
1019
+	 */
1020
+	private function _initialize_registrations(EE_Transaction $transaction)
1021
+	{
1022
+		$att_nmbr = 0;
1023
+		$registrations = array();
1024
+		if ($transaction instanceof EE_Transaction) {
1025
+			/** @type EE_Registration_Processor $registration_processor */
1026
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1027
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1028
+			// now let's add the cart items to the $transaction
1029
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1030
+				//do the following for each ticket of this type they selected
1031
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1032
+					$att_nmbr++;
1033
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1034
+					$CreateRegistrationCommand = EE_Registry::instance()
1035
+															->create(
1036
+																'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1037
+																array(
1038
+																	$transaction,
1039
+																	$line_item,
1040
+																	$att_nmbr,
1041
+																	$this->checkout->total_ticket_count,
1042
+																)
1043
+															);
1044
+					// override capabilities for frontend registrations
1045
+					if ( ! is_admin()) {
1046
+						$CreateRegistrationCommand->setCapCheck(
1047
+							new PublicCapabilities('', 'create_new_registration')
1048
+						);
1049
+					}
1050
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1051
+					if ( ! $registration instanceof EE_Registration) {
1052
+						throw new InvalidEntityException($registration, 'EE_Registration');
1053
+					}
1054
+					$registrations[ $registration->ID() ] = $registration;
1055
+				}
1056
+			}
1057
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1058
+		}
1059
+		return $registrations;
1060
+	}
1061
+
1062
+
1063
+
1064
+	/**
1065
+	 * sorts registrations by REG_count
1066
+	 *
1067
+	 * @access public
1068
+	 * @param EE_Registration $reg_A
1069
+	 * @param EE_Registration $reg_B
1070
+	 * @return int
1071
+	 */
1072
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1073
+	{
1074
+		// this shouldn't ever happen within the same TXN, but oh well
1075
+		if ($reg_A->count() === $reg_B->count()) {
1076
+			return 0;
1077
+		}
1078
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1079
+	}
1080
+
1081
+
1082
+
1083
+	/**
1084
+	 *    _final_verifications
1085
+	 * just makes sure that everything is set up correctly before proceeding
1086
+	 *
1087
+	 * @access    private
1088
+	 * @return    bool
1089
+	 * @throws \EE_Error
1090
+	 */
1091
+	private function _final_verifications()
1092
+	{
1093
+		// filter checkout
1094
+		$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout);
1095
+		//verify that current step is still set correctly
1096
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1097
+			EE_Error::add_error(
1098
+				__('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'),
1099
+				__FILE__,
1100
+				__FUNCTION__,
1101
+				__LINE__
1102
+			);
1103
+			return false;
1104
+		}
1105
+		// if returning to SPCO, then verify that primary registrant is set
1106
+		if ( ! empty($this->checkout->reg_url_link)) {
1107
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1108
+			if ( ! $valid_registrant instanceof EE_Registration) {
1109
+				EE_Error::add_error(
1110
+					__('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'),
1111
+					__FILE__,
1112
+					__FUNCTION__,
1113
+					__LINE__
1114
+				);
1115
+				return false;
1116
+			}
1117
+			$valid_registrant = null;
1118
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1119
+				if (
1120
+					$registration instanceof EE_Registration
1121
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1122
+				) {
1123
+					$valid_registrant = $registration;
1124
+				}
1125
+			}
1126
+			if ( ! $valid_registrant instanceof EE_Registration) {
1127
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1128
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1129
+					// clear the session, mark the checkout as unverified, and try again
1130
+					EE_Registry::instance()->SSN->clear_session();
1131
+					EED_Single_Page_Checkout::$_initialized = false;
1132
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1133
+					$this->_initialize();
1134
+					EE_Error::reset_notices();
1135
+					return false;
1136
+				}
1137
+				EE_Error::add_error(
1138
+					__('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'),
1139
+					__FILE__,
1140
+					__FUNCTION__,
1141
+					__LINE__
1142
+				);
1143
+				return false;
1144
+			}
1145
+		}
1146
+		// now that things have been kinda sufficiently verified,
1147
+		// let's add the checkout to the session so that's available other systems
1148
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1149
+		return true;
1150
+	}
1151
+
1152
+
1153
+
1154
+	/**
1155
+	 *    _initialize_reg_steps
1156
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1157
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1158
+	 *
1159
+	 * @access    private
1160
+	 * @param bool $reinitializing
1161
+	 * @throws \EE_Error
1162
+	 */
1163
+	private function _initialize_reg_steps($reinitializing = false)
1164
+	{
1165
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1166
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1167
+		foreach ($this->checkout->reg_steps as $reg_step) {
1168
+			if ( ! $reg_step->initialize_reg_step()) {
1169
+				// if not initialized then maybe this step is being removed...
1170
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1171
+					// if it was the current step, then we need to start over here
1172
+					$this->_initialize_reg_steps(true);
1173
+					return;
1174
+				}
1175
+				continue;
1176
+			}
1177
+			// add css and JS for current step
1178
+			$reg_step->enqueue_styles_and_scripts();
1179
+			// i18n
1180
+			$reg_step->translate_js_strings();
1181
+			if ($reg_step->is_current_step()) {
1182
+				// the text that appears on the reg step form submit button
1183
+				$reg_step->set_submit_button_text();
1184
+			}
1185
+		}
1186
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1187
+		do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step);
1188
+	}
1189
+
1190
+
1191
+
1192
+	/**
1193
+	 * _check_form_submission
1194
+	 *
1195
+	 * @access private
1196
+	 * @return boolean
1197
+	 */
1198
+	private function _check_form_submission()
1199
+	{
1200
+		//does this request require the reg form to be generated ?
1201
+		if ($this->checkout->generate_reg_form) {
1202
+			// ever heard that song by Blue Rodeo ?
1203
+			try {
1204
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1205
+				// if not displaying a form, then check for form submission
1206
+				if (
1207
+					$this->checkout->process_form_submission
1208
+					&& $this->checkout->current_step->reg_form->was_submitted()
1209
+				) {
1210
+					// clear out any old data in case this step is being run again
1211
+					$this->checkout->current_step->set_valid_data(array());
1212
+					// capture submitted form data
1213
+					$this->checkout->current_step->reg_form->receive_form_submission(
1214
+						apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout)
1215
+					);
1216
+					// validate submitted form data
1217
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1218
+						// thou shall not pass !!!
1219
+						$this->checkout->continue_reg = false;
1220
+						// any form validation errors?
1221
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1222
+							$submission_error_messages = array();
1223
+							// bad, bad, bad registrant
1224
+							foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) {
1225
+								if ($validation_error instanceof EE_Validation_Error) {
1226
+									$submission_error_messages[] = sprintf(
1227
+										__('%s : %s', 'event_espresso'),
1228
+										$validation_error->get_form_section()->html_label_text(),
1229
+										$validation_error->getMessage()
1230
+									);
1231
+								}
1232
+							}
1233
+							EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1234
+						}
1235
+						// well not really... what will happen is we'll just get redirected back to redo the current step
1236
+						$this->go_to_next_step();
1237
+						return false;
1238
+					}
1239
+				}
1240
+			} catch (EE_Error $e) {
1241
+				$e->get_error();
1242
+			}
1243
+		}
1244
+		return true;
1245
+	}
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 * _process_action
1251
+	 *
1252
+	 * @access private
1253
+	 * @return void
1254
+	 * @throws \EE_Error
1255
+	 */
1256
+	private function _process_form_action()
1257
+	{
1258
+		// what cha wanna do?
1259
+		switch ($this->checkout->action) {
1260
+			// AJAX next step reg form
1261
+			case 'display_spco_reg_step' :
1262
+				$this->checkout->redirect = false;
1263
+				if (EE_Registry::instance()->REQ->ajax) {
1264
+					$this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form());
1265
+				}
1266
+				break;
1267
+			default :
1268
+				// meh... do one of those other steps first
1269
+				if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) {
1270
+					// dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1271
+					do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1272
+					// call action on current step
1273
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1274
+						// good registrant, you get to proceed
1275
+						if (
1276
+							$this->checkout->current_step->success_message() !== ''
1277
+							&& apply_filters(
1278
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1279
+								false
1280
+							)
1281
+						) {
1282
+							EE_Error::add_success(
1283
+								$this->checkout->current_step->success_message()
1284
+								. '<br />' . $this->checkout->next_step->_instructions()
1285
+							);
1286
+						}
1287
+						// pack it up, pack it in...
1288
+						$this->_setup_redirect();
1289
+					}
1290
+					// dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1291
+					do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1292
+				} else {
1293
+					EE_Error::add_error(
1294
+						sprintf(
1295
+							__('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'),
1296
+							$this->checkout->action,
1297
+							$this->checkout->current_step->name()
1298
+						),
1299
+						__FILE__,
1300
+						__FUNCTION__,
1301
+						__LINE__
1302
+					);
1303
+				}
1304
+			// end default
1305
+		}
1306
+		// store our progress so far
1307
+		$this->checkout->stash_transaction_and_checkout();
1308
+		// advance to the next step! If you pass GO, collect $200
1309
+		$this->go_to_next_step();
1310
+	}
1311
+
1312
+
1313
+
1314
+	/**
1315
+	 *        add_styles_and_scripts
1316
+	 *
1317
+	 * @access        public
1318
+	 * @return        void
1319
+	 */
1320
+	public function add_styles_and_scripts()
1321
+	{
1322
+		// i18n
1323
+		$this->translate_js_strings();
1324
+		if ($this->checkout->admin_request) {
1325
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1326
+		} else {
1327
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1328
+		}
1329
+	}
1330
+
1331
+
1332
+
1333
+	/**
1334
+	 *        translate_js_strings
1335
+	 *
1336
+	 * @access        public
1337
+	 * @return        void
1338
+	 */
1339
+	public function translate_js_strings()
1340
+	{
1341
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1342
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1343
+		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');
1344
+		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');
1345
+		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');
1346
+		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');
1347
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso');
1348
+		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');
1349
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1350
+			__('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'),
1351
+			'<br/>',
1352
+			'<br/>'
1353
+		);
1354
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1355
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1356
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1357
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1358
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1359
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1360
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1361
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1362
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1363
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1364
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1365
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1366
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1367
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1368
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1369
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1370
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1371
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1372
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1373
+			__(
1374
+				'%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',
1375
+				'event_espresso'
1376
+			),
1377
+			'<h4 class="important-notice">',
1378
+			'</h4>',
1379
+			'<br />',
1380
+			'<p>',
1381
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1382
+			'">',
1383
+			'</a>',
1384
+			'</p>'
1385
+		);
1386
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true);
1387
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1388
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1389
+		);
1390
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1391
+			'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1392
+		);
1393
+	}
1394
+
1395
+
1396
+
1397
+	/**
1398
+	 *    enqueue_styles_and_scripts
1399
+	 *
1400
+	 * @access        public
1401
+	 * @return        void
1402
+	 * @throws \EE_Error
1403
+	 */
1404
+	public function enqueue_styles_and_scripts()
1405
+	{
1406
+		// load css
1407
+		wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1408
+		wp_enqueue_style('single_page_checkout');
1409
+		// load JS
1410
+		wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1411
+		wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1412
+		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);
1413
+		$this->checkout->registration_form->enqueue_js();
1414
+		$this->checkout->current_step->reg_form->enqueue_js();
1415
+		wp_enqueue_script('single_page_checkout');
1416
+		/**
1417
+		 * global action hook for enqueueing styles and scripts with
1418
+		 * spco calls.
1419
+		 */
1420
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1421
+		/**
1422
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1423
+		 * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1424
+		 */
1425
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this);
1426
+	}
1427
+
1428
+
1429
+
1430
+	/**
1431
+	 *    display the Registration Single Page Checkout Form
1432
+	 *
1433
+	 * @access    private
1434
+	 * @return    void
1435
+	 * @throws \EE_Error
1436
+	 */
1437
+	private function _display_spco_reg_form()
1438
+	{
1439
+		// if registering via the admin, just display the reg form for the current step
1440
+		if ($this->checkout->admin_request) {
1441
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1442
+		} else {
1443
+			// add powered by EE msg
1444
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1445
+			$empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1
1446
+				? true
1447
+				: false;
1448
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1449
+			$cookies_not_set_msg = '';
1450
+			if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1451
+				$cookies_not_set_msg = apply_filters(
1452
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1453
+					sprintf(
1454
+						__(
1455
+							'%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',
1456
+							'event_espresso'
1457
+						),
1458
+						'<div class="ee-attention">',
1459
+						'</div>',
1460
+						'<h6 class="important-notice">',
1461
+						'</h6>',
1462
+						'<p>',
1463
+						'</p>',
1464
+						'<br />',
1465
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1466
+						'</a>'
1467
+					)
1468
+				);
1469
+			}
1470
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1471
+				array(
1472
+					'name'            => 'single-page-checkout',
1473
+					'html_id'         => 'ee-single-page-checkout-dv',
1474
+					'layout_strategy' =>
1475
+						new EE_Template_Layout(
1476
+							array(
1477
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1478
+								'template_args'        => array(
1479
+									'empty_cart'              => $empty_cart,
1480
+									'revisit'                 => $this->checkout->revisit,
1481
+									'reg_steps'               => $this->checkout->reg_steps,
1482
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1483
+										? $this->checkout->next_step->slug()
1484
+										: '',
1485
+									'cancel_page_url'         => $this->checkout->cancel_page_url,
1486
+									'empty_msg'               => apply_filters(
1487
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1488
+										sprintf(
1489
+											__('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1490
+												'event_espresso'),
1491
+											'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1492
+											'">',
1493
+											'</a>'
1494
+										)
1495
+									),
1496
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1497
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1498
+									'session_expiration'      =>
1499
+										date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)),
1500
+								),
1501
+							)
1502
+						),
1503
+				)
1504
+			);
1505
+			// load template and add to output sent that gets filtered into the_content()
1506
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1507
+		}
1508
+	}
1509
+
1510
+
1511
+
1512
+	/**
1513
+	 *    add_extra_finalize_registration_inputs
1514
+	 *
1515
+	 * @access    public
1516
+	 * @param $next_step
1517
+	 * @internal  param string $label
1518
+	 * @return void
1519
+	 */
1520
+	public function add_extra_finalize_registration_inputs($next_step)
1521
+	{
1522
+		if ($next_step === 'finalize_registration') {
1523
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1524
+		}
1525
+	}
1526
+
1527
+
1528
+
1529
+	/**
1530
+	 *    display_registration_footer
1531
+	 *
1532
+	 * @access    public
1533
+	 * @return    string
1534
+	 */
1535
+	public static function display_registration_footer()
1536
+	{
1537
+		if (
1538
+		apply_filters(
1539
+			'FHEE__EE_Front__Controller__show_reg_footer',
1540
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1541
+		)
1542
+		) {
1543
+			add_filter(
1544
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1545
+				function ($url) {
1546
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1547
+				}
1548
+			);
1549
+			echo apply_filters(
1550
+				'FHEE__EE_Front_Controller__display_registration_footer',
1551
+				\EEH_Template::powered_by_event_espresso(
1552
+					'',
1553
+					'espresso-registration-footer-dv',
1554
+					array('utm_content' => 'registration_checkout')
1555
+				)
1556
+			);
1557
+		}
1558
+		return '';
1559
+	}
1560
+
1561
+
1562
+
1563
+	/**
1564
+	 *    unlock_transaction
1565
+	 *
1566
+	 * @access    public
1567
+	 * @return    void
1568
+	 * @throws \EE_Error
1569
+	 */
1570
+	public function unlock_transaction()
1571
+	{
1572
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1573
+			$this->checkout->transaction->unlock();
1574
+		}
1575
+	}
1576
+
1577
+
1578
+
1579
+	/**
1580
+	 *        _setup_redirect
1581
+	 *
1582
+	 * @access    private
1583
+	 * @return void
1584
+	 */
1585
+	private function _setup_redirect()
1586
+	{
1587
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1588
+			$this->checkout->redirect = true;
1589
+			if (empty($this->checkout->redirect_url)) {
1590
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1591
+			}
1592
+			$this->checkout->redirect_url = apply_filters(
1593
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1594
+				$this->checkout->redirect_url,
1595
+				$this->checkout
1596
+			);
1597
+		}
1598
+	}
1599
+
1600
+
1601
+
1602
+	/**
1603
+	 *   handle ajax message responses and redirects
1604
+	 *
1605
+	 * @access public
1606
+	 * @return void
1607
+	 * @throws \EE_Error
1608
+	 */
1609
+	public function go_to_next_step()
1610
+	{
1611
+		if (EE_Registry::instance()->REQ->ajax) {
1612
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1613
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1614
+		}
1615
+		$this->unlock_transaction();
1616
+		// just return for these conditions
1617
+		if (
1618
+			$this->checkout->admin_request
1619
+			|| $this->checkout->action === 'redirect_form'
1620
+			|| $this->checkout->action === 'update_checkout'
1621
+		) {
1622
+			return;
1623
+		}
1624
+		// AJAX response
1625
+		$this->_handle_json_response();
1626
+		// redirect to next step or the Thank You page
1627
+		$this->_handle_html_redirects();
1628
+		// hmmm... must be something wrong, so let's just display the form again !
1629
+		$this->_display_spco_reg_form();
1630
+	}
1631
+
1632
+
1633
+
1634
+	/**
1635
+	 *   _handle_json_response
1636
+	 *
1637
+	 * @access protected
1638
+	 * @return void
1639
+	 */
1640
+	protected function _handle_json_response()
1641
+	{
1642
+		// if this is an ajax request
1643
+		if (EE_Registry::instance()->REQ->ajax) {
1644
+			// DEBUG LOG
1645
+			//$this->checkout->log(
1646
+			//	__CLASS__, __FUNCTION__, __LINE__,
1647
+			//	array(
1648
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1649
+			//		'redirect'                   => $this->checkout->redirect,
1650
+			//		'continue_reg'               => $this->checkout->continue_reg,
1651
+			//	)
1652
+			//);
1653
+			$this->checkout->json_response->set_registration_time_limit(
1654
+				$this->checkout->get_registration_time_limit()
1655
+			);
1656
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1657
+			// just send the ajax (
1658
+			$json_response = apply_filters(
1659
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1660
+				$this->checkout->json_response
1661
+			);
1662
+			echo $json_response;
1663
+			exit();
1664
+		}
1665
+	}
1666
+
1667
+
1668
+
1669
+	/**
1670
+	 *   _handle_redirects
1671
+	 *
1672
+	 * @access protected
1673
+	 * @return void
1674
+	 */
1675
+	protected function _handle_html_redirects()
1676
+	{
1677
+		// going somewhere ?
1678
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1679
+			// store notices in a transient
1680
+			EE_Error::get_notices(false, true, true);
1681
+			// DEBUG LOG
1682
+			//$this->checkout->log(
1683
+			//	__CLASS__, __FUNCTION__, __LINE__,
1684
+			//	array(
1685
+			//		'headers_sent' => headers_sent(),
1686
+			//		'redirect_url'     => $this->checkout->redirect_url,
1687
+			//		'headers_list'    => headers_list(),
1688
+			//	)
1689
+			//);
1690
+			wp_safe_redirect($this->checkout->redirect_url);
1691
+			exit();
1692
+		}
1693
+	}
1694
+
1695
+
1696
+
1697
+	/**
1698
+	 *   set_checkout_anchor
1699
+	 *
1700
+	 * @access public
1701
+	 * @return void
1702
+	 */
1703
+	public function set_checkout_anchor()
1704
+	{
1705
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1706
+	}
1707 1707
 
1708 1708
 
1709 1709
 
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 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,
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
             // DEBUG LOG
500 500
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
501 501
             // get reg form
502
-            if( ! $this->_check_form_submission()) {
502
+            if ( ! $this->_check_form_submission()) {
503 503
                 EED_Single_Page_Checkout::$_initialized = true;
504 504
                 return;
505 505
             }
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
         // or some other kind of revisit ?
611 611
         $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false);
612 612
         // and whether or not to generate a reg form for this request
613
-        $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true);        // TRUE 	FALSE
613
+        $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true); // TRUE 	FALSE
614 614
         // and whether or not to process a reg form submission for this request
615 615
         $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get(
616 616
             'process_form_submission',
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
         ); // TRUE 	FALSE
619 619
         $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step'
620 620
             ? $this->checkout->process_form_submission
621
-            : false;        // TRUE 	FALSE
621
+            : false; // TRUE 	FALSE
622 622
         // $this->_display_request_vars();
623 623
     }
624 624
 
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
                     if ( ! $registration instanceof EE_Registration) {
1052 1052
                         throw new InvalidEntityException($registration, 'EE_Registration');
1053 1053
                     }
1054
-                    $registrations[ $registration->ID() ] = $registration;
1054
+                    $registrations[$registration->ID()] = $registration;
1055 1055
                 }
1056 1056
             }
1057 1057
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1281,7 +1281,7 @@  discard block
 block discarded – undo
1281 1281
                         ) {
1282 1282
                             EE_Error::add_success(
1283 1283
                                 $this->checkout->current_step->success_message()
1284
-                                . '<br />' . $this->checkout->next_step->_instructions()
1284
+                                . '<br />'.$this->checkout->next_step->_instructions()
1285 1285
                             );
1286 1286
                         }
1287 1287
                         // pack it up, pack it in...
@@ -1378,7 +1378,7 @@  discard block
 block discarded – undo
1378 1378
             '</h4>',
1379 1379
             '<br />',
1380 1380
             '<p>',
1381
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1381
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1382 1382
             '">',
1383 1383
             '</a>',
1384 1384
             '</p>'
@@ -1404,12 +1404,12 @@  discard block
 block discarded – undo
1404 1404
     public function enqueue_styles_and_scripts()
1405 1405
     {
1406 1406
         // load css
1407
-        wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1407
+        wp_register_style('single_page_checkout', SPCO_CSS_URL.'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1408 1408
         wp_enqueue_style('single_page_checkout');
1409 1409
         // load JS
1410
-        wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1411
-        wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1412
-        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);
1410
+        wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL.'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1411
+        wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL.'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1412
+        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);
1413 1413
         $this->checkout->registration_form->enqueue_js();
1414 1414
         $this->checkout->current_step->reg_form->enqueue_js();
1415 1415
         wp_enqueue_script('single_page_checkout');
@@ -1422,7 +1422,7 @@  discard block
 block discarded – undo
1422 1422
          * dynamic action hook for enqueueing styles and scripts with spco calls.
1423 1423
          * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1424 1424
          */
1425
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this);
1425
+        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), $this);
1426 1426
     }
1427 1427
 
1428 1428
 
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
                     'layout_strategy' =>
1475 1475
                         new EE_Template_Layout(
1476 1476
                             array(
1477
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1477
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1478 1478
                                 'template_args'        => array(
1479 1479
                                     'empty_cart'              => $empty_cart,
1480 1480
                                     'revisit'                 => $this->checkout->revisit,
@@ -1488,7 +1488,7 @@  discard block
 block discarded – undo
1488 1488
                                         sprintf(
1489 1489
                                             __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1490 1490
                                                 'event_espresso'),
1491
-                                            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1491
+                                            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1492 1492
                                             '">',
1493 1493
                                             '</a>'
1494 1494
                                         )
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
         ) {
1543 1543
             add_filter(
1544 1544
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1545
-                function ($url) {
1545
+                function($url) {
1546 1546
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1547 1547
                 }
1548 1548
             );
Please login to merge, or discard this patch.