Completed
Branch BUG/11361/fix-log-calls-using-... (7ad8bc)
by
unknown
27:20 queued 14:31
created
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -218,19 +218,19 @@  discard block
 block discarded – undo
218 218
      */
219 219
     public static function set_definitions()
220 220
     {
221
-        if(defined('SPCO_BASE_PATH')) {
221
+        if (defined('SPCO_BASE_PATH')) {
222 222
             return;
223 223
         }
224 224
         define(
225 225
             'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
226
+            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS
227 227
         );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
228
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
229
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
230
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
231
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
232
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
233
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
234 234
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235 235
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236 236
     }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
             return;
252 252
         }
253 253
         // filter list of reg_steps
254
-        $reg_steps_to_load = (array)apply_filters(
254
+        $reg_steps_to_load = (array) apply_filters(
255 255
             'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256 256
             EED_Single_Page_Checkout::get_reg_steps()
257 257
         );
@@ -303,25 +303,25 @@  discard block
 block discarded – undo
303 303
         if (empty($reg_steps)) {
304 304
             $reg_steps = array(
305 305
                 10  => array(
306
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
306
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
307 307
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308 308
                     'slug'       => 'attendee_information',
309 309
                     'has_hooks'  => false,
310 310
                 ),
311 311
                 20  => array(
312
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
312
+                    'file_path'  => SPCO_REG_STEPS_PATH.'registration_confirmation',
313 313
                     'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314 314
                     'slug'       => 'registration_confirmation',
315 315
                     'has_hooks'  => false,
316 316
                 ),
317 317
                 30  => array(
318
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
318
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
319 319
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320 320
                     'slug'       => 'payment_options',
321 321
                     'has_hooks'  => true,
322 322
                 ),
323 323
                 999 => array(
324
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
324
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
325 325
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326 326
                     'slug'       => 'finalize_registration',
327 327
                     'has_hooks'  => false,
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
             // DEBUG LOG
506 506
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507 507
             // get reg form
508
-            if( ! $this->_check_form_submission()) {
508
+            if ( ! $this->_check_form_submission()) {
509 509
                 EED_Single_Page_Checkout::$_initialized = true;
510 510
                 return;
511 511
             }
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
         );
547 547
         // is session still valid ?
548 548
         if ($clear_session_requested
549
-            || ( EE_Registry::instance()->SSN->expired()
549
+            || (EE_Registry::instance()->SSN->expired()
550 550
               && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551 551
             )
552 552
         ) {
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
             // EE_Registry::instance()->SSN->reset_cart();
556 556
             // EE_Registry::instance()->SSN->reset_checkout();
557 557
             // EE_Registry::instance()->SSN->reset_transaction();
558
-            if (! $clear_session_requested) {
558
+            if ( ! $clear_session_requested) {
559 559
                 EE_Error::add_attention(
560 560
                     EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561 561
                     __FILE__, __FUNCTION__, __LINE__
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
                     if ( ! $registration instanceof EE_Registration) {
1115 1115
                         throw new InvalidEntityException($registration, 'EE_Registration');
1116 1116
                     }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1117
+                    $registrations[$registration->ID()] = $registration;
1118 1118
                 }
1119 1119
             }
1120 1120
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
                         ) {
1376 1376
                             EE_Error::add_success(
1377 1377
                                 $this->checkout->current_step->success_message()
1378
-                                . '<br />' . $this->checkout->next_step->_instructions()
1378
+                                . '<br />'.$this->checkout->next_step->_instructions()
1379 1379
                             );
1380 1380
                         }
1381 1381
                         // pack it up, pack it in...
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
         // load css
1520 1520
         wp_register_style(
1521 1521
             'single_page_checkout',
1522
-            SPCO_CSS_URL . 'single_page_checkout.css',
1522
+            SPCO_CSS_URL.'single_page_checkout.css',
1523 1523
             array('espresso_default'),
1524 1524
             EVENT_ESPRESSO_VERSION
1525 1525
         );
@@ -1527,21 +1527,21 @@  discard block
 block discarded – undo
1527 1527
         // load JS
1528 1528
         wp_register_script(
1529 1529
             'jquery_plugin',
1530
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1530
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1531 1531
             array('jquery'),
1532 1532
             '1.0.1',
1533 1533
             true
1534 1534
         );
1535 1535
         wp_register_script(
1536 1536
             'jquery_countdown',
1537
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1537
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1538 1538
             array('jquery_plugin'),
1539 1539
             '2.0.2',
1540 1540
             true
1541 1541
         );
1542 1542
         wp_register_script(
1543 1543
             'single_page_checkout',
1544
-            SPCO_JS_URL . 'single_page_checkout.js',
1544
+            SPCO_JS_URL.'single_page_checkout.js',
1545 1545
             array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1546 1546
             EVENT_ESPRESSO_VERSION,
1547 1547
             true
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1565 1565
          */
1566 1566
         do_action(
1567
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1567
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1568 1568
             $this
1569 1569
         );
1570 1570
     }
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
                     'layout_strategy' =>
1619 1619
                         new EE_Template_Layout(
1620 1620
                             array(
1621
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1621
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1622 1622
                                 'template_args'        => array(
1623 1623
                                     'empty_cart'              => $empty_cart,
1624 1624
                                     'revisit'                 => $this->checkout->revisit,
@@ -1692,7 +1692,7 @@  discard block
 block discarded – undo
1692 1692
         ) {
1693 1693
             add_filter(
1694 1694
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1695
-                function ($url) {
1695
+                function($url) {
1696 1696
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1697 1697
                 }
1698 1698
             );
@@ -1871,7 +1871,7 @@  discard block
 block discarded – undo
1871 1871
             '</h4>',
1872 1872
             '<br />',
1873 1873
             '<p>',
1874
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1874
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1875 1875
             '">',
1876 1876
             '</a>',
1877 1877
             '</p>'
Please login to merge, or discard this patch.
Indentation   +1844 added lines, -1844 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,1849 +20,1849 @@  discard block
 block discarded – undo
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * $_initialized - has the SPCO controller already been initialized ?
25
-     *
26
-     * @access private
27
-     * @var bool $_initialized
28
-     */
29
-    private static $_initialized = false;
30
-
31
-
32
-    /**
33
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
-     *
35
-     * @access private
36
-     * @var bool $_valid_checkout
37
-     */
38
-    private static $_checkout_verified = true;
39
-
40
-    /**
41
-     *    $_reg_steps_array - holds initial array of reg steps
42
-     *
43
-     * @access private
44
-     * @var array $_reg_steps_array
45
-     */
46
-    private static $_reg_steps_array = array();
47
-
48
-    /**
49
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
-     *
51
-     * @access public
52
-     * @var EE_Checkout $checkout
53
-     */
54
-    public $checkout;
55
-
56
-
57
-
58
-    /**
59
-     * @return EED_Module|EED_Single_Page_Checkout
60
-     */
61
-    public static function instance()
62
-    {
63
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
-        return parent::get_instance(__CLASS__);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return EE_Transaction
81
-     */
82
-    public function transaction()
83
-    {
84
-        return $this->checkout->transaction;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    set_hooks - for hooking into EE Core, other modules, etc
91
-     *
92
-     * @access    public
93
-     * @return    void
94
-     * @throws EE_Error
95
-     */
96
-    public static function set_hooks()
97
-    {
98
-        EED_Single_Page_Checkout::set_definitions();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
-     *
106
-     * @access    public
107
-     * @return    void
108
-     * @throws EE_Error
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        EED_Single_Page_Checkout::set_definitions();
113
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
-            return;
115
-        }
116
-        // going to start an output buffer in case anything gets accidentally output
117
-        // that might disrupt our JSON response
118
-        ob_start();
119
-        EED_Single_Page_Checkout::load_request_handler();
120
-        EED_Single_Page_Checkout::load_reg_steps();
121
-        // set ajax hooks
122
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    process ajax request
134
-     *
135
-     * @param string $ajax_action
136
-     * @throws EE_Error
137
-     */
138
-    public static function process_ajax_request($ajax_action)
139
-    {
140
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
141
-        EED_Single_Page_Checkout::instance()->_initialize();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *    ajax display registration step
148
-     *
149
-     * @throws EE_Error
150
-     */
151
-    public static function display_reg_step()
152
-    {
153
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    ajax process registration step
160
-     *
161
-     * @throws EE_Error
162
-     */
163
-    public static function process_reg_step()
164
-    {
165
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    ajax process registration step
172
-     *
173
-     * @throws EE_Error
174
-     */
175
-    public static function update_reg_step()
176
-    {
177
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *   update_checkout
184
-     *
185
-     * @access public
186
-     * @return void
187
-     * @throws EE_Error
188
-     */
189
-    public static function update_checkout()
190
-    {
191
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     *    load_request_handler
198
-     *
199
-     * @access    public
200
-     * @return    void
201
-     */
202
-    public static function load_request_handler()
203
-    {
204
-        // load core Request_Handler class
205
-        if (EE_Registry::instance()->REQ !== null) {
206
-            EE_Registry::instance()->load_core('Request_Handler');
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     *    set_definitions
214
-     *
215
-     * @access    public
216
-     * @return    void
217
-     * @throws EE_Error
218
-     */
219
-    public static function set_definitions()
220
-    {
221
-        if(defined('SPCO_BASE_PATH')) {
222
-            return;
223
-        }
224
-        define(
225
-            'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
-        );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * load_reg_steps
242
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
243
-     *
244
-     * @access    private
245
-     * @throws EE_Error
246
-     */
247
-    public static function load_reg_steps()
248
-    {
249
-        static $reg_steps_loaded = false;
250
-        if ($reg_steps_loaded) {
251
-            return;
252
-        }
253
-        // filter list of reg_steps
254
-        $reg_steps_to_load = (array)apply_filters(
255
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256
-            EED_Single_Page_Checkout::get_reg_steps()
257
-        );
258
-        // sort by key (order)
259
-        ksort($reg_steps_to_load);
260
-        // loop through folders
261
-        foreach ($reg_steps_to_load as $order => $reg_step) {
262
-            // we need a
263
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
264
-                // copy over to the reg_steps_array
265
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
266
-                // register custom key route for each reg step
267
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
268
-                EE_Config::register_route(
269
-                    $reg_step['slug'],
270
-                    'EED_Single_Page_Checkout',
271
-                    'run',
272
-                    'step'
273
-                );
274
-                // add AJAX or other hooks
275
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
276
-                    // setup autoloaders if necessary
277
-                    if ( ! class_exists($reg_step['class_name'])) {
278
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
279
-                            $reg_step['file_path'],
280
-                            true
281
-                        );
282
-                    }
283
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
284
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
285
-                    }
286
-                }
287
-            }
288
-        }
289
-        $reg_steps_loaded = true;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     *    get_reg_steps
296
-     *
297
-     * @access    public
298
-     * @return    array
299
-     */
300
-    public static function get_reg_steps()
301
-    {
302
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
303
-        if (empty($reg_steps)) {
304
-            $reg_steps = array(
305
-                10  => array(
306
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308
-                    'slug'       => 'attendee_information',
309
-                    'has_hooks'  => false,
310
-                ),
311
-                20  => array(
312
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
313
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314
-                    'slug'       => 'registration_confirmation',
315
-                    'has_hooks'  => false,
316
-                ),
317
-                30  => array(
318
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
319
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320
-                    'slug'       => 'payment_options',
321
-                    'has_hooks'  => true,
322
-                ),
323
-                999 => array(
324
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
325
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326
-                    'slug'       => 'finalize_registration',
327
-                    'has_hooks'  => false,
328
-                ),
329
-            );
330
-        }
331
-        return $reg_steps;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     *    registration_checkout_for_admin
338
-     *
339
-     * @access    public
340
-     * @return    string
341
-     * @throws EE_Error
342
-     */
343
-    public static function registration_checkout_for_admin()
344
-    {
345
-        EED_Single_Page_Checkout::load_request_handler();
346
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
347
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
348
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
349
-        EED_Single_Page_Checkout::instance()->_initialize();
350
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
351
-        return EE_Registry::instance()->REQ->get_output();
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * process_registration_from_admin
358
-     *
359
-     * @access public
360
-     * @return \EE_Transaction
361
-     * @throws EE_Error
362
-     */
363
-    public static function process_registration_from_admin()
364
-    {
365
-        EED_Single_Page_Checkout::load_request_handler();
366
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
367
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
368
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
369
-        EED_Single_Page_Checkout::instance()->_initialize();
370
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
371
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
372
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
373
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
374
-                if ($final_reg_step->process_reg_step()) {
375
-                    $final_reg_step->set_completed();
376
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
377
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
378
-                }
379
-            }
380
-        }
381
-        return null;
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     *    run
388
-     *
389
-     * @access    public
390
-     * @param WP_Query $WP_Query
391
-     * @return    void
392
-     * @throws EE_Error
393
-     */
394
-    public function run($WP_Query)
395
-    {
396
-        if (
397
-            $WP_Query instanceof WP_Query
398
-            && $WP_Query->is_main_query()
399
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
400
-            && $this->_is_reg_checkout()
401
-        ) {
402
-            $this->_initialize();
403
-        }
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * determines whether current url matches reg page url
410
-     *
411
-     * @return bool
412
-     */
413
-    protected function _is_reg_checkout()
414
-    {
415
-        // get current permalink for reg page without any extra query args
416
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
417
-        // get request URI for current request, but without the scheme or host
418
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
419
-        $current_request_uri = html_entity_decode($current_request_uri);
420
-        // get array of query args from the current request URI
421
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
422
-        // grab page id if it is set
423
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
424
-        // and remove the page id from the query args (we will re-add it later)
425
-        unset($query_args['page_id']);
426
-        // now strip all query args from current request URI
427
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
428
-        // and re-add the page id if it was set
429
-        if ($page_id) {
430
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
431
-        }
432
-        // remove slashes and ?
433
-        $current_request_uri = trim($current_request_uri, '?/');
434
-        // is current request URI part of the known full reg page URL ?
435
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
436
-    }
437
-
438
-
439
-
440
-    /**
441
-     * @param WP_Query $wp_query
442
-     * @return    void
443
-     * @throws EE_Error
444
-     */
445
-    public static function init($wp_query)
446
-    {
447
-        EED_Single_Page_Checkout::instance()->run($wp_query);
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     *    _initialize - initial module setup
454
-     *
455
-     * @access    private
456
-     * @throws EE_Error
457
-     * @return    void
458
-     */
459
-    private function _initialize()
460
-    {
461
-        // ensure SPCO doesn't run twice
462
-        if (EED_Single_Page_Checkout::$_initialized) {
463
-            return;
464
-        }
465
-        try {
466
-            EED_Single_Page_Checkout::load_reg_steps();
467
-            $this->_verify_session();
468
-            // setup the EE_Checkout object
469
-            $this->checkout = $this->_initialize_checkout();
470
-            // filter checkout
471
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
472
-            // get the $_GET
473
-            $this->_get_request_vars();
474
-            if ($this->_block_bots()) {
475
-                return;
476
-            }
477
-            // filter continue_reg
478
-            $this->checkout->continue_reg = apply_filters(
479
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
480
-                true,
481
-                $this->checkout
482
-            );
483
-            // load the reg steps array
484
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
485
-                EED_Single_Page_Checkout::$_initialized = true;
486
-                return;
487
-            }
488
-            // set the current step
489
-            $this->checkout->set_current_step($this->checkout->step);
490
-            // and the next step
491
-            $this->checkout->set_next_step();
492
-            // verify that everything has been setup correctly
493
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
494
-                EED_Single_Page_Checkout::$_initialized = true;
495
-                return;
496
-            }
497
-            // lock the transaction
498
-            $this->checkout->transaction->lock();
499
-            // make sure all of our cached objects are added to their respective model entity mappers
500
-            $this->checkout->refresh_all_entities();
501
-            // set amount owing
502
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
503
-            // initialize each reg step, which gives them the chance to potentially alter the process
504
-            $this->_initialize_reg_steps();
505
-            // DEBUG LOG
506
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507
-            // get reg form
508
-            if( ! $this->_check_form_submission()) {
509
-                EED_Single_Page_Checkout::$_initialized = true;
510
-                return;
511
-            }
512
-            // checkout the action!!!
513
-            $this->_process_form_action();
514
-            // add some style and make it dance
515
-            $this->add_styles_and_scripts();
516
-            // kk... SPCO has successfully run
517
-            EED_Single_Page_Checkout::$_initialized = true;
518
-            // set no cache headers and constants
519
-            EE_System::do_not_cache();
520
-            // add anchor
521
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
522
-            // remove transaction lock
523
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
524
-        } catch (Exception $e) {
525
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
526
-        }
527
-    }
528
-
529
-
530
-
531
-    /**
532
-     *    _verify_session
533
-     * checks that the session is valid and not expired
534
-     *
535
-     * @access    private
536
-     * @throws EE_Error
537
-     */
538
-    private function _verify_session()
539
-    {
540
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
541
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
542
-        }
543
-        $clear_session_requested = filter_var(
544
-            EE_Registry::instance()->REQ->get('clear_session', false),
545
-            FILTER_VALIDATE_BOOLEAN
546
-        );
547
-        // is session still valid ?
548
-        if ($clear_session_requested
549
-            || ( EE_Registry::instance()->SSN->expired()
550
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551
-            )
552
-        ) {
553
-            $this->checkout = new EE_Checkout();
554
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
555
-            // EE_Registry::instance()->SSN->reset_cart();
556
-            // EE_Registry::instance()->SSN->reset_checkout();
557
-            // EE_Registry::instance()->SSN->reset_transaction();
558
-            if (! $clear_session_requested) {
559
-                EE_Error::add_attention(
560
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561
-                    __FILE__, __FUNCTION__, __LINE__
562
-                );
563
-            }
564
-            // EE_Registry::instance()->SSN->reset_expired();
565
-        }
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     *    _initialize_checkout
572
-     * loads and instantiates EE_Checkout
573
-     *
574
-     * @access    private
575
-     * @throws EE_Error
576
-     * @return EE_Checkout
577
-     */
578
-    private function _initialize_checkout()
579
-    {
580
-        // look in session for existing checkout
581
-        /** @type EE_Checkout $checkout */
582
-        $checkout = EE_Registry::instance()->SSN->checkout();
583
-        // verify
584
-        if ( ! $checkout instanceof EE_Checkout) {
585
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
586
-            $checkout = EE_Registry::instance()->load_file(
587
-                SPCO_INC_PATH,
588
-                'EE_Checkout',
589
-                'class', array(),
590
-                false
591
-            );
592
-        } else {
593
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
594
-                $this->unlock_transaction();
595
-                wp_safe_redirect($checkout->redirect_url);
596
-                exit();
597
-            }
598
-        }
599
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
600
-        // verify again
601
-        if ( ! $checkout instanceof EE_Checkout) {
602
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
603
-        }
604
-        // reset anything that needs a clean slate for each request
605
-        $checkout->reset_for_current_request();
606
-        return $checkout;
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     *    _get_request_vars
613
-     *
614
-     * @access    private
615
-     * @return    void
616
-     * @throws EE_Error
617
-     */
618
-    private function _get_request_vars()
619
-    {
620
-        // load classes
621
-        EED_Single_Page_Checkout::load_request_handler();
622
-        //make sure this request is marked as belonging to EE
623
-        EE_Registry::instance()->REQ->set_espresso_page(true);
624
-        // which step is being requested ?
625
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
626
-        // which step is being edited ?
627
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
628
-        // and what we're doing on the current step
629
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
630
-        // timestamp
631
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
632
-        // returning to edit ?
633
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
634
-        // add reg url link to registration query params
635
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
636
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
637
-        }
638
-        // or some other kind of revisit ?
639
-        $this->checkout->revisit = filter_var(
640
-            EE_Registry::instance()->REQ->get('revisit', false),
641
-            FILTER_VALIDATE_BOOLEAN
642
-        );
643
-        // and whether or not to generate a reg form for this request
644
-        $this->checkout->generate_reg_form = filter_var(
645
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
-            FILTER_VALIDATE_BOOLEAN
647
-        );
648
-        // and whether or not to process a reg form submission for this request
649
-        $this->checkout->process_form_submission = filter_var(
650
-            EE_Registry::instance()->REQ->get(
651
-                'process_form_submission',
652
-                $this->checkout->action === 'process_reg_step'
653
-            ),
654
-            FILTER_VALIDATE_BOOLEAN
655
-        );
656
-        $this->checkout->process_form_submission = filter_var(
657
-            $this->checkout->action !== 'display_spco_reg_step'
658
-                ? $this->checkout->process_form_submission
659
-                : false,
660
-            FILTER_VALIDATE_BOOLEAN
661
-        );
662
-        // $this->_display_request_vars();
663
-    }
664
-
665
-
666
-
667
-    /**
668
-     *  _display_request_vars
669
-     *
670
-     * @access    protected
671
-     * @return    void
672
-     */
673
-    protected function _display_request_vars()
674
-    {
675
-        if ( ! WP_DEBUG) {
676
-            return;
677
-        }
678
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * _block_bots
692
-     * checks that the incoming request has either of the following set:
693
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
-     * then where you coming from man?
697
-     *
698
-     * @return boolean
699
-     */
700
-    private function _block_bots()
701
-    {
702
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
-            return true;
705
-        }
706
-        return false;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     *    _get_first_step
713
-     *  gets slug for first step in $_reg_steps_array
714
-     *
715
-     * @access    private
716
-     * @throws EE_Error
717
-     * @return    string
718
-     */
719
-    private function _get_first_step()
720
-    {
721
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
-    }
724
-
725
-
726
-
727
-    /**
728
-     *    _load_and_instantiate_reg_steps
729
-     *  instantiates each reg step based on the loaded reg_steps array
730
-     *
731
-     * @access    private
732
-     * @throws EE_Error
733
-     * @return    bool
734
-     */
735
-    private function _load_and_instantiate_reg_steps()
736
-    {
737
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
-        // have reg_steps already been instantiated ?
739
-        if (
740
-            empty($this->checkout->reg_steps)
741
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
-        ) {
743
-            // if not, then loop through raw reg steps array
744
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
-                    return false;
747
-                }
748
-            }
749
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
-            // skip the registration_confirmation page ?
752
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
-                // just remove it from the reg steps array
754
-                $this->checkout->remove_reg_step('registration_confirmation', false);
755
-            } else if (
756
-                isset($this->checkout->reg_steps['registration_confirmation'])
757
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
-            ) {
759
-                // set the order to something big like 100
760
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
761
-            }
762
-            // filter the array for good luck
763
-            $this->checkout->reg_steps = apply_filters(
764
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
-                $this->checkout->reg_steps
766
-            );
767
-            // finally re-sort based on the reg step class order properties
768
-            $this->checkout->sort_reg_steps();
769
-        } else {
770
-            foreach ($this->checkout->reg_steps as $reg_step) {
771
-                // set all current step stati to FALSE
772
-                $reg_step->set_is_current_step(false);
773
-            }
774
-        }
775
-        if (empty($this->checkout->reg_steps)) {
776
-            EE_Error::add_error(
777
-                __('No Reg Steps were loaded..', 'event_espresso'),
778
-                __FILE__, __FUNCTION__, __LINE__
779
-            );
780
-            return false;
781
-        }
782
-        // make reg step details available to JS
783
-        $this->checkout->set_reg_step_JSON_info();
784
-        return true;
785
-    }
786
-
787
-
788
-
789
-    /**
790
-     *     _load_and_instantiate_reg_step
791
-     *
792
-     * @access    private
793
-     * @param array $reg_step
794
-     * @param int   $order
795
-     * @return bool
796
-     */
797
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
-    {
799
-        // we need a file_path, class_name, and slug to add a reg step
800
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
-            if (
803
-                $this->checkout->reg_url_link
804
-                && $this->checkout->step !== $reg_step['slug']
805
-                && $reg_step['slug'] !== 'finalize_registration'
806
-                // normally at this point we would NOT load the reg step, but this filter can change that
807
-                && apply_filters(
808
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
-                    true,
810
-                    $reg_step,
811
-                    $this->checkout
812
-                )
813
-            ) {
814
-                return true;
815
-            }
816
-            // instantiate step class using file path and class name
817
-            $reg_step_obj = EE_Registry::instance()->load_file(
818
-                $reg_step['file_path'],
819
-                $reg_step['class_name'],
820
-                'class',
821
-                $this->checkout,
822
-                false
823
-            );
824
-            // did we gets the goods ?
825
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
-                // set reg step order based on config
827
-                $reg_step_obj->set_order($order);
828
-                // add instantiated reg step object to the master reg steps array
829
-                $this->checkout->add_reg_step($reg_step_obj);
830
-            } else {
831
-                EE_Error::add_error(
832
-                    __('The current step could not be set.', 'event_espresso'),
833
-                    __FILE__, __FUNCTION__, __LINE__
834
-                );
835
-                return false;
836
-            }
837
-        } else {
838
-            if (WP_DEBUG) {
839
-                EE_Error::add_error(
840
-                    sprintf(
841
-                        __(
842
-                            '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',
843
-                            'event_espresso'
844
-                        ),
845
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
-                        '<ul>',
849
-                        '<li>',
850
-                        '</li>',
851
-                        '</ul>'
852
-                    ),
853
-                    __FILE__, __FUNCTION__, __LINE__
854
-                );
855
-            }
856
-            return false;
857
-        }
858
-        return true;
859
-    }
860
-
861
-
862
-    /**
863
-     * _verify_transaction_and_get_registrations
864
-     *
865
-     * @access private
866
-     * @return bool
867
-     * @throws InvalidDataTypeException
868
-     * @throws InvalidEntityException
869
-     * @throws EE_Error
870
-     */
871
-    private function _verify_transaction_and_get_registrations()
872
-    {
873
-        // was there already a valid transaction in the checkout from the session ?
874
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
-            // get transaction from db or session
876
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
-                ? $this->_get_transaction_and_cart_for_previous_visit()
878
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
879
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
-                EE_Error::add_error(
881
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
882
-                        'event_espresso'),
883
-                    __FILE__, __FUNCTION__, __LINE__
884
-                );
885
-                $this->checkout->transaction = EE_Transaction::new_instance();
886
-                // add some style and make it dance
887
-                $this->add_styles_and_scripts();
888
-                EED_Single_Page_Checkout::$_initialized = true;
889
-                return false;
890
-            }
891
-            // and the registrations for the transaction
892
-            $this->_get_registrations($this->checkout->transaction);
893
-        }
894
-        return true;
895
-    }
896
-
897
-
898
-
899
-    /**
900
-     * _get_transaction_and_cart_for_previous_visit
901
-     *
902
-     * @access private
903
-     * @return mixed EE_Transaction|NULL
904
-     */
905
-    private function _get_transaction_and_cart_for_previous_visit()
906
-    {
907
-        /** @var $TXN_model EEM_Transaction */
908
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
909
-        // because the reg_url_link is present in the request,
910
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
911
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
-        // verify transaction
913
-        if ($transaction instanceof EE_Transaction) {
914
-            // and get the cart that was used for that transaction
915
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
-            return $transaction;
917
-        }
918
-        EE_Error::add_error(
919
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
-            __FILE__, __FUNCTION__, __LINE__
921
-        );
922
-        return null;
923
-
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * _get_cart_for_transaction
930
-     *
931
-     * @access private
932
-     * @param EE_Transaction $transaction
933
-     * @return EE_Cart
934
-     */
935
-    private function _get_cart_for_transaction($transaction)
936
-    {
937
-        return $this->checkout->get_cart_for_transaction($transaction);
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * get_cart_for_transaction
944
-     *
945
-     * @access public
946
-     * @param EE_Transaction $transaction
947
-     * @return EE_Cart
948
-     */
949
-    public function get_cart_for_transaction(EE_Transaction $transaction)
950
-    {
951
-        return $this->checkout->get_cart_for_transaction($transaction);
952
-    }
953
-
954
-
955
-
956
-    /**
957
-     * _get_transaction_and_cart_for_current_session
958
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
-     *
960
-     * @access private
961
-     * @return EE_Transaction
962
-     * @throws EE_Error
963
-     */
964
-    private function _get_cart_for_current_session_and_setup_new_transaction()
965
-    {
966
-        //  if there's no transaction, then this is the FIRST visit to SPCO
967
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
969
-        // and then create a new transaction
970
-        $transaction = $this->_initialize_transaction();
971
-        // verify transaction
972
-        if ($transaction instanceof EE_Transaction) {
973
-            // save it so that we have an ID for other objects to use
974
-            $transaction->save();
975
-            // and save TXN data to the cart
976
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
-        } else {
978
-            EE_Error::add_error(
979
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
980
-                __FILE__, __FUNCTION__, __LINE__
981
-            );
982
-        }
983
-        return $transaction;
984
-    }
985
-
986
-
987
-
988
-    /**
989
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
-     *
991
-     * @access private
992
-     * @return mixed EE_Transaction|NULL
993
-     */
994
-    private function _initialize_transaction()
995
-    {
996
-        try {
997
-            // ensure cart totals have been calculated
998
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
-            // grab the cart grand total
1000
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
1001
-            // create new TXN
1002
-            $transaction = EE_Transaction::new_instance(
1003
-                array(
1004
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
-                    'TXN_paid'      => 0,
1007
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1008
-                )
1009
-            );
1010
-            // save it so that we have an ID for other objects to use
1011
-            $transaction->save();
1012
-            // set cron job for following up on TXNs after their session has expired
1013
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1014
-                EE_Registry::instance()->SSN->expiration() + 1,
1015
-                $transaction->ID()
1016
-            );
1017
-            return $transaction;
1018
-        } catch (Exception $e) {
1019
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
-        }
1021
-        return null;
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * _get_registrations
1027
-     *
1028
-     * @access private
1029
-     * @param EE_Transaction $transaction
1030
-     * @return void
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidEntityException
1033
-     * @throws EE_Error
1034
-     */
1035
-    private function _get_registrations(EE_Transaction $transaction)
1036
-    {
1037
-        // first step: grab the registrants  { : o
1038
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1039
-        $this->checkout->total_ticket_count = count($registrations);
1040
-        // verify registrations have been set
1041
-        if (empty($registrations)) {
1042
-            // if no cached registrations, then check the db
1043
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1044
-            // still nothing ? well as long as this isn't a revisit
1045
-            if (empty($registrations) && ! $this->checkout->revisit) {
1046
-                // generate new registrations from scratch
1047
-                $registrations = $this->_initialize_registrations($transaction);
1048
-            }
1049
-        }
1050
-        // sort by their original registration order
1051
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1052
-        // then loop thru the array
1053
-        foreach ($registrations as $registration) {
1054
-            // verify each registration
1055
-            if ($registration instanceof EE_Registration) {
1056
-                // we display all attendee info for the primary registrant
1057
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1058
-                    && $registration->is_primary_registrant()
1059
-                ) {
1060
-                    $this->checkout->primary_revisit = true;
1061
-                    break;
1062
-                }
1063
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1064
-                    // but hide info if it doesn't belong to you
1065
-                    $transaction->clear_cache('Registration', $registration->ID());
1066
-                    $this->checkout->total_ticket_count--;
1067
-                }
1068
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1069
-            }
1070
-        }
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
-     *
1077
-     * @access private
1078
-     * @param EE_Transaction $transaction
1079
-     * @return    array
1080
-     * @throws InvalidDataTypeException
1081
-     * @throws InvalidEntityException
1082
-     * @throws EE_Error
1083
-     */
1084
-    private function _initialize_registrations(EE_Transaction $transaction)
1085
-    {
1086
-        $att_nmbr = 0;
1087
-        $registrations = array();
1088
-        if ($transaction instanceof EE_Transaction) {
1089
-            /** @type EE_Registration_Processor $registration_processor */
1090
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
-            // now let's add the cart items to the $transaction
1093
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
-                //do the following for each ticket of this type they selected
1095
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
-                    $att_nmbr++;
1097
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1099
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
-                        array(
1101
-                            $transaction,
1102
-                            $line_item,
1103
-                            $att_nmbr,
1104
-                            $this->checkout->total_ticket_count,
1105
-                        )
1106
-                    );
1107
-                    // override capabilities for frontend registrations
1108
-                    if ( ! is_admin()) {
1109
-                        $CreateRegistrationCommand->setCapCheck(
1110
-                            new PublicCapabilities('', 'create_new_registration')
1111
-                        );
1112
-                    }
1113
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
-                    if ( ! $registration instanceof EE_Registration) {
1115
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1116
-                    }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1118
-                }
1119
-            }
1120
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
-        }
1122
-        return $registrations;
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * sorts registrations by REG_count
1129
-     *
1130
-     * @access public
1131
-     * @param EE_Registration $reg_A
1132
-     * @param EE_Registration $reg_B
1133
-     * @return int
1134
-     */
1135
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
-    {
1137
-        // this shouldn't ever happen within the same TXN, but oh well
1138
-        if ($reg_A->count() === $reg_B->count()) {
1139
-            return 0;
1140
-        }
1141
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
-    }
1143
-
1144
-
1145
-
1146
-    /**
1147
-     *    _final_verifications
1148
-     * just makes sure that everything is set up correctly before proceeding
1149
-     *
1150
-     * @access    private
1151
-     * @return    bool
1152
-     * @throws EE_Error
1153
-     */
1154
-    private function _final_verifications()
1155
-    {
1156
-        // filter checkout
1157
-        $this->checkout = apply_filters(
1158
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
-            $this->checkout
1160
-        );
1161
-        //verify that current step is still set correctly
1162
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
-            EE_Error::add_error(
1164
-                __('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'),
1165
-                __FILE__,
1166
-                __FUNCTION__,
1167
-                __LINE__
1168
-            );
1169
-            return false;
1170
-        }
1171
-        // if returning to SPCO, then verify that primary registrant is set
1172
-        if ( ! empty($this->checkout->reg_url_link)) {
1173
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1174
-            if ( ! $valid_registrant instanceof EE_Registration) {
1175
-                EE_Error::add_error(
1176
-                    __('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'),
1177
-                    __FILE__,
1178
-                    __FUNCTION__,
1179
-                    __LINE__
1180
-                );
1181
-                return false;
1182
-            }
1183
-            $valid_registrant = null;
1184
-            foreach (
1185
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
-            ) {
1187
-                if (
1188
-                    $registration instanceof EE_Registration
1189
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1190
-                ) {
1191
-                    $valid_registrant = $registration;
1192
-                }
1193
-            }
1194
-            if ( ! $valid_registrant instanceof EE_Registration) {
1195
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
-                    // clear the session, mark the checkout as unverified, and try again
1198
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
-                    EED_Single_Page_Checkout::$_initialized = false;
1200
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1201
-                    $this->_initialize();
1202
-                    EE_Error::reset_notices();
1203
-                    return false;
1204
-                }
1205
-                EE_Error::add_error(
1206
-                    __(
1207
-                        '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.',
1208
-                        'event_espresso'
1209
-                    ),
1210
-                    __FILE__,
1211
-                    __FUNCTION__,
1212
-                    __LINE__
1213
-                );
1214
-                return false;
1215
-            }
1216
-        }
1217
-        // now that things have been kinda sufficiently verified,
1218
-        // let's add the checkout to the session so that it's available to other systems
1219
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
-        return true;
1221
-    }
1222
-
1223
-
1224
-
1225
-    /**
1226
-     *    _initialize_reg_steps
1227
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
-     *
1230
-     * @access    private
1231
-     * @param bool $reinitializing
1232
-     * @throws EE_Error
1233
-     */
1234
-    private function _initialize_reg_steps($reinitializing = false)
1235
-    {
1236
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
-        foreach ($this->checkout->reg_steps as $reg_step) {
1239
-            if ( ! $reg_step->initialize_reg_step()) {
1240
-                // if not initialized then maybe this step is being removed...
1241
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
-                    // if it was the current step, then we need to start over here
1243
-                    $this->_initialize_reg_steps(true);
1244
-                    return;
1245
-                }
1246
-                continue;
1247
-            }
1248
-            // add css and JS for current step
1249
-            $reg_step->enqueue_styles_and_scripts();
1250
-            // i18n
1251
-            $reg_step->translate_js_strings();
1252
-            if ($reg_step->is_current_step()) {
1253
-                // the text that appears on the reg step form submit button
1254
-                $reg_step->set_submit_button_text();
1255
-            }
1256
-        }
1257
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
-        do_action(
1259
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
-            $this->checkout->current_step
1261
-        );
1262
-    }
1263
-
1264
-
1265
-
1266
-    /**
1267
-     * _check_form_submission
1268
-     *
1269
-     * @access private
1270
-     * @return boolean
1271
-     */
1272
-    private function _check_form_submission()
1273
-    {
1274
-        //does this request require the reg form to be generated ?
1275
-        if ($this->checkout->generate_reg_form) {
1276
-            // ever heard that song by Blue Rodeo ?
1277
-            try {
1278
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
-                // if not displaying a form, then check for form submission
1280
-                if (
1281
-                    $this->checkout->process_form_submission
1282
-                    && $this->checkout->current_step->reg_form->was_submitted()
1283
-                ) {
1284
-                    // clear out any old data in case this step is being run again
1285
-                    $this->checkout->current_step->set_valid_data(array());
1286
-                    // capture submitted form data
1287
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1288
-                        apply_filters(
1289
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
-                            EE_Registry::instance()->REQ->params(),
1291
-                            $this->checkout
1292
-                        )
1293
-                    );
1294
-                    // validate submitted form data
1295
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
-                        // thou shall not pass !!!
1297
-                        $this->checkout->continue_reg = false;
1298
-                        // any form validation errors?
1299
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
-                            EE_Error::add_error(
1301
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1302
-                                __FILE__, __FUNCTION__, __LINE__
1303
-                            );
1304
-                        }
1305
-                        // well not really... what will happen is
1306
-                        // we'll just get redirected back to redo the current step
1307
-                        $this->go_to_next_step();
1308
-                        return false;
1309
-                    }
1310
-                }
1311
-            } catch (EE_Error $e) {
1312
-                $e->get_error();
1313
-            }
1314
-        }
1315
-        return true;
1316
-    }
1317
-
1318
-
1319
-
1320
-    /**
1321
-     * _process_action
1322
-     *
1323
-     * @access private
1324
-     * @return void
1325
-     * @throws EE_Error
1326
-     */
1327
-    private function _process_form_action()
1328
-    {
1329
-        // what cha wanna do?
1330
-        switch ($this->checkout->action) {
1331
-            // AJAX next step reg form
1332
-            case 'display_spco_reg_step' :
1333
-                $this->checkout->redirect = false;
1334
-                if (EE_Registry::instance()->REQ->ajax) {
1335
-                    $this->checkout->json_response->set_reg_step_html(
1336
-                        $this->checkout->current_step->display_reg_form()
1337
-                    );
1338
-                }
1339
-                break;
1340
-            default :
1341
-                // meh... do one of those other steps first
1342
-                if (
1343
-                    ! empty($this->checkout->action)
1344
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1345
-                ) {
1346
-                    // dynamically creates hook point like:
1347
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1348
-                    do_action(
1349
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1350
-                        $this->checkout->current_step
1351
-                    );
1352
-                    // call action on current step
1353
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1354
-                        // good registrant, you get to proceed
1355
-                        if (
1356
-                            $this->checkout->current_step->success_message() !== ''
1357
-                            && apply_filters(
1358
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1359
-                                false
1360
-                            )
1361
-                        ) {
1362
-                            EE_Error::add_success(
1363
-                                $this->checkout->current_step->success_message()
1364
-                                . '<br />' . $this->checkout->next_step->_instructions()
1365
-                            );
1366
-                        }
1367
-                        // pack it up, pack it in...
1368
-                        $this->_setup_redirect();
1369
-                    }
1370
-                    // dynamically creates hook point like:
1371
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1372
-                    do_action(
1373
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1374
-                        $this->checkout->current_step
1375
-                    );
1376
-                } else {
1377
-                    EE_Error::add_error(
1378
-                        sprintf(
1379
-                            __(
1380
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1381
-                                'event_espresso'
1382
-                            ),
1383
-                            $this->checkout->action,
1384
-                            $this->checkout->current_step->name()
1385
-                        ),
1386
-                        __FILE__,
1387
-                        __FUNCTION__,
1388
-                        __LINE__
1389
-                    );
1390
-                }
1391
-            // end default
1392
-        }
1393
-        // store our progress so far
1394
-        $this->checkout->stash_transaction_and_checkout();
1395
-        // advance to the next step! If you pass GO, collect $200
1396
-        $this->go_to_next_step();
1397
-    }
1398
-
1399
-
1400
-
1401
-    /**
1402
-     *        add_styles_and_scripts
1403
-     *
1404
-     * @access        public
1405
-     * @return        void
1406
-     */
1407
-    public function add_styles_and_scripts()
1408
-    {
1409
-        // i18n
1410
-        $this->translate_js_strings();
1411
-        if ($this->checkout->admin_request) {
1412
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1413
-        } else {
1414
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1415
-        }
1416
-    }
1417
-
1418
-
1419
-
1420
-    /**
1421
-     *        translate_js_strings
1422
-     *
1423
-     * @access        public
1424
-     * @return        void
1425
-     */
1426
-    public function translate_js_strings()
1427
-    {
1428
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1429
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1430
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1431
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1432
-            'event_espresso'
1433
-        );
1434
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1435
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1436
-            'event_espresso'
1437
-        );
1438
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1439
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1440
-            'event_espresso'
1441
-        );
1442
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1443
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1444
-            'event_espresso'
1445
-        );
1446
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1447
-            'This registration step could not be completed. Please refresh the page and try again.',
1448
-            'event_espresso'
1449
-        );
1450
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1451
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1452
-            'event_espresso'
1453
-        );
1454
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1455
-            __(
1456
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1457
-                'event_espresso'
1458
-            ),
1459
-            '<br/>',
1460
-            '<br/>'
1461
-        );
1462
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1463
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1464
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1465
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1466
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1467
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1468
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1469
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1470
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1471
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1472
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1473
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1474
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1475
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1476
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1477
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1478
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1479
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1480
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1481
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1482
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1483
-            true
1484
-        );
1485
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1486
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1487
-        );
1488
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1489
-            'M d, Y H:i:s',
1490
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1491
-        );
1492
-    }
1493
-
1494
-
1495
-
1496
-    /**
1497
-     *    enqueue_styles_and_scripts
1498
-     *
1499
-     * @access        public
1500
-     * @return        void
1501
-     * @throws EE_Error
1502
-     */
1503
-    public function enqueue_styles_and_scripts()
1504
-    {
1505
-        // load css
1506
-        wp_register_style(
1507
-            'single_page_checkout',
1508
-            SPCO_CSS_URL . 'single_page_checkout.css',
1509
-            array('espresso_default'),
1510
-            EVENT_ESPRESSO_VERSION
1511
-        );
1512
-        wp_enqueue_style('single_page_checkout');
1513
-        // load JS
1514
-        wp_register_script(
1515
-            'jquery_plugin',
1516
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1517
-            array('jquery'),
1518
-            '1.0.1',
1519
-            true
1520
-        );
1521
-        wp_register_script(
1522
-            'jquery_countdown',
1523
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1524
-            array('jquery_plugin'),
1525
-            '2.0.2',
1526
-            true
1527
-        );
1528
-        wp_register_script(
1529
-            'single_page_checkout',
1530
-            SPCO_JS_URL . 'single_page_checkout.js',
1531
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1532
-            EVENT_ESPRESSO_VERSION,
1533
-            true
1534
-        );
1535
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1536
-            $this->checkout->registration_form->enqueue_js();
1537
-        }
1538
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1539
-            $this->checkout->current_step->reg_form->enqueue_js();
1540
-        }
1541
-        wp_enqueue_script('single_page_checkout');
1542
-        /**
1543
-         * global action hook for enqueueing styles and scripts with
1544
-         * spco calls.
1545
-         */
1546
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1547
-        /**
1548
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1549
-         * The hook will end up being something like:
1550
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1551
-         */
1552
-        do_action(
1553
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1554
-            $this
1555
-        );
1556
-    }
1557
-
1558
-
1559
-
1560
-    /**
1561
-     *    display the Registration Single Page Checkout Form
1562
-     *
1563
-     * @access    private
1564
-     * @return    void
1565
-     * @throws EE_Error
1566
-     */
1567
-    private function _display_spco_reg_form()
1568
-    {
1569
-        // if registering via the admin, just display the reg form for the current step
1570
-        if ($this->checkout->admin_request) {
1571
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1572
-        } else {
1573
-            // add powered by EE msg
1574
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1575
-            $empty_cart = count(
1576
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1577
-            ) < 1;
1578
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1579
-            $cookies_not_set_msg = '';
1580
-            if ($empty_cart) {
1581
-                $cookies_not_set_msg = apply_filters(
1582
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1583
-                    sprintf(
1584
-                        __(
1585
-                            '%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',
1586
-                            'event_espresso'
1587
-                        ),
1588
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1589
-                        '</div>',
1590
-                        '<h6 class="important-notice">',
1591
-                        '</h6>',
1592
-                        '<p>',
1593
-                        '</p>',
1594
-                        '<br />',
1595
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1596
-                        '</a>'
1597
-                    )
1598
-                );
1599
-            }
1600
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1601
-                array(
1602
-                    'name'            => 'single-page-checkout',
1603
-                    'html_id'         => 'ee-single-page-checkout-dv',
1604
-                    'layout_strategy' =>
1605
-                        new EE_Template_Layout(
1606
-                            array(
1607
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1608
-                                'template_args'        => array(
1609
-                                    'empty_cart'              => $empty_cart,
1610
-                                    'revisit'                 => $this->checkout->revisit,
1611
-                                    'reg_steps'               => $this->checkout->reg_steps,
1612
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1613
-                                        ? $this->checkout->next_step->slug()
1614
-                                        : '',
1615
-                                    'empty_msg'               => apply_filters(
1616
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1617
-                                        sprintf(
1618
-                                            __(
1619
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1620
-                                                'event_espresso'
1621
-                                            ),
1622
-                                            '<a href="'
1623
-                                            . get_post_type_archive_link('espresso_events')
1624
-                                            . '" title="',
1625
-                                            '">',
1626
-                                            '</a>'
1627
-                                        )
1628
-                                    ),
1629
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1630
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1631
-                                    'session_expiration'      => gmdate(
1632
-                                        'M d, Y H:i:s',
1633
-                                        EE_Registry::instance()->SSN->expiration()
1634
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1635
-                                    ),
1636
-                                ),
1637
-                            )
1638
-                        ),
1639
-                )
1640
-            );
1641
-            // load template and add to output sent that gets filtered into the_content()
1642
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1643
-        }
1644
-    }
1645
-
1646
-
1647
-
1648
-    /**
1649
-     *    add_extra_finalize_registration_inputs
1650
-     *
1651
-     * @access    public
1652
-     * @param $next_step
1653
-     * @internal  param string $label
1654
-     * @return void
1655
-     */
1656
-    public function add_extra_finalize_registration_inputs($next_step)
1657
-    {
1658
-        if ($next_step === 'finalize_registration') {
1659
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1660
-        }
1661
-    }
1662
-
1663
-
1664
-
1665
-    /**
1666
-     *    display_registration_footer
1667
-     *
1668
-     * @access    public
1669
-     * @return    string
1670
-     */
1671
-    public static function display_registration_footer()
1672
-    {
1673
-        if (
1674
-        apply_filters(
1675
-            'FHEE__EE_Front__Controller__show_reg_footer',
1676
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1677
-        )
1678
-        ) {
1679
-            add_filter(
1680
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1681
-                function ($url) {
1682
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1683
-                }
1684
-            );
1685
-            echo apply_filters(
1686
-                'FHEE__EE_Front_Controller__display_registration_footer',
1687
-                \EEH_Template::powered_by_event_espresso(
1688
-                    '',
1689
-                    'espresso-registration-footer-dv',
1690
-                    array('utm_content' => 'registration_checkout')
1691
-                )
1692
-            );
1693
-        }
1694
-        return '';
1695
-    }
1696
-
1697
-
1698
-
1699
-    /**
1700
-     *    unlock_transaction
1701
-     *
1702
-     * @access    public
1703
-     * @return    void
1704
-     * @throws EE_Error
1705
-     */
1706
-    public function unlock_transaction()
1707
-    {
1708
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1709
-            $this->checkout->transaction->unlock();
1710
-        }
1711
-    }
1712
-
1713
-
1714
-
1715
-    /**
1716
-     *        _setup_redirect
1717
-     *
1718
-     * @access    private
1719
-     * @return void
1720
-     */
1721
-    private function _setup_redirect()
1722
-    {
1723
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1724
-            $this->checkout->redirect = true;
1725
-            if (empty($this->checkout->redirect_url)) {
1726
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1727
-            }
1728
-            $this->checkout->redirect_url = apply_filters(
1729
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1730
-                $this->checkout->redirect_url,
1731
-                $this->checkout
1732
-            );
1733
-        }
1734
-    }
1735
-
1736
-
1737
-
1738
-    /**
1739
-     *   handle ajax message responses and redirects
1740
-     *
1741
-     * @access public
1742
-     * @return void
1743
-     * @throws EE_Error
1744
-     */
1745
-    public function go_to_next_step()
1746
-    {
1747
-        if (EE_Registry::instance()->REQ->ajax) {
1748
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1749
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1750
-        }
1751
-        $this->unlock_transaction();
1752
-        // just return for these conditions
1753
-        if (
1754
-            $this->checkout->admin_request
1755
-            || $this->checkout->action === 'redirect_form'
1756
-            || $this->checkout->action === 'update_checkout'
1757
-        ) {
1758
-            return;
1759
-        }
1760
-        // AJAX response
1761
-        $this->_handle_json_response();
1762
-        // redirect to next step or the Thank You page
1763
-        $this->_handle_html_redirects();
1764
-        // hmmm... must be something wrong, so let's just display the form again !
1765
-        $this->_display_spco_reg_form();
1766
-    }
1767
-
1768
-
1769
-
1770
-    /**
1771
-     *   _handle_json_response
1772
-     *
1773
-     * @access protected
1774
-     * @return void
1775
-     */
1776
-    protected function _handle_json_response()
1777
-    {
1778
-        // if this is an ajax request
1779
-        if (EE_Registry::instance()->REQ->ajax) {
1780
-            // DEBUG LOG
1781
-            //$this->checkout->log(
1782
-            //	__CLASS__, __FUNCTION__, __LINE__,
1783
-            //	array(
1784
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1785
-            //		'redirect'                   => $this->checkout->redirect,
1786
-            //		'continue_reg'               => $this->checkout->continue_reg,
1787
-            //	)
1788
-            //);
1789
-            $this->checkout->json_response->set_registration_time_limit(
1790
-                $this->checkout->get_registration_time_limit()
1791
-            );
1792
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1793
-            // just send the ajax (
1794
-            $json_response = apply_filters(
1795
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1796
-                $this->checkout->json_response
1797
-            );
1798
-            echo $json_response;
1799
-            exit();
1800
-        }
1801
-    }
1802
-
1803
-
1804
-
1805
-    /**
1806
-     *   _handle_redirects
1807
-     *
1808
-     * @access protected
1809
-     * @return void
1810
-     */
1811
-    protected function _handle_html_redirects()
1812
-    {
1813
-        // going somewhere ?
1814
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1815
-            // store notices in a transient
1816
-            EE_Error::get_notices(false, true, true);
1817
-            // DEBUG LOG
1818
-            //$this->checkout->log(
1819
-            //	__CLASS__, __FUNCTION__, __LINE__,
1820
-            //	array(
1821
-            //		'headers_sent' => headers_sent(),
1822
-            //		'redirect_url'     => $this->checkout->redirect_url,
1823
-            //		'headers_list'    => headers_list(),
1824
-            //	)
1825
-            //);
1826
-            wp_safe_redirect($this->checkout->redirect_url);
1827
-            exit();
1828
-        }
1829
-    }
1830
-
1831
-
1832
-
1833
-    /**
1834
-     *   set_checkout_anchor
1835
-     *
1836
-     * @access public
1837
-     * @return void
1838
-     */
1839
-    public function set_checkout_anchor()
1840
-    {
1841
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1842
-    }
1843
-
1844
-    /**
1845
-     *    getRegistrationExpirationNotice
1846
-     *
1847
-     * @since $VID:$
1848
-     * @access    public
1849
-     * @return    string
1850
-     */
1851
-    public static function getRegistrationExpirationNotice()
1852
-    {
1853
-        return sprintf(
1854
-            __('%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 accept our apologies for any inconvenience this may have caused.%8$s',
1855
-                'event_espresso'),
1856
-            '<h4 class="important-notice">',
1857
-            '</h4>',
1858
-            '<br />',
1859
-            '<p>',
1860
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1861
-            '">',
1862
-            '</a>',
1863
-            '</p>'
1864
-        );
1865
-    }
23
+	/**
24
+	 * $_initialized - has the SPCO controller already been initialized ?
25
+	 *
26
+	 * @access private
27
+	 * @var bool $_initialized
28
+	 */
29
+	private static $_initialized = false;
30
+
31
+
32
+	/**
33
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
+	 *
35
+	 * @access private
36
+	 * @var bool $_valid_checkout
37
+	 */
38
+	private static $_checkout_verified = true;
39
+
40
+	/**
41
+	 *    $_reg_steps_array - holds initial array of reg steps
42
+	 *
43
+	 * @access private
44
+	 * @var array $_reg_steps_array
45
+	 */
46
+	private static $_reg_steps_array = array();
47
+
48
+	/**
49
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
+	 *
51
+	 * @access public
52
+	 * @var EE_Checkout $checkout
53
+	 */
54
+	public $checkout;
55
+
56
+
57
+
58
+	/**
59
+	 * @return EED_Module|EED_Single_Page_Checkout
60
+	 */
61
+	public static function instance()
62
+	{
63
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
+		return parent::get_instance(__CLASS__);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return EE_Transaction
81
+	 */
82
+	public function transaction()
83
+	{
84
+		return $this->checkout->transaction;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    set_hooks - for hooking into EE Core, other modules, etc
91
+	 *
92
+	 * @access    public
93
+	 * @return    void
94
+	 * @throws EE_Error
95
+	 */
96
+	public static function set_hooks()
97
+	{
98
+		EED_Single_Page_Checkout::set_definitions();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
+	 *
106
+	 * @access    public
107
+	 * @return    void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		EED_Single_Page_Checkout::set_definitions();
113
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
+			return;
115
+		}
116
+		// going to start an output buffer in case anything gets accidentally output
117
+		// that might disrupt our JSON response
118
+		ob_start();
119
+		EED_Single_Page_Checkout::load_request_handler();
120
+		EED_Single_Page_Checkout::load_reg_steps();
121
+		// set ajax hooks
122
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    process ajax request
134
+	 *
135
+	 * @param string $ajax_action
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function process_ajax_request($ajax_action)
139
+	{
140
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
141
+		EED_Single_Page_Checkout::instance()->_initialize();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *    ajax display registration step
148
+	 *
149
+	 * @throws EE_Error
150
+	 */
151
+	public static function display_reg_step()
152
+	{
153
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    ajax process registration step
160
+	 *
161
+	 * @throws EE_Error
162
+	 */
163
+	public static function process_reg_step()
164
+	{
165
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    ajax process registration step
172
+	 *
173
+	 * @throws EE_Error
174
+	 */
175
+	public static function update_reg_step()
176
+	{
177
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *   update_checkout
184
+	 *
185
+	 * @access public
186
+	 * @return void
187
+	 * @throws EE_Error
188
+	 */
189
+	public static function update_checkout()
190
+	{
191
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 *    load_request_handler
198
+	 *
199
+	 * @access    public
200
+	 * @return    void
201
+	 */
202
+	public static function load_request_handler()
203
+	{
204
+		// load core Request_Handler class
205
+		if (EE_Registry::instance()->REQ !== null) {
206
+			EE_Registry::instance()->load_core('Request_Handler');
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 *    set_definitions
214
+	 *
215
+	 * @access    public
216
+	 * @return    void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function set_definitions()
220
+	{
221
+		if(defined('SPCO_BASE_PATH')) {
222
+			return;
223
+		}
224
+		define(
225
+			'SPCO_BASE_PATH',
226
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+		);
228
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * load_reg_steps
242
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
243
+	 *
244
+	 * @access    private
245
+	 * @throws EE_Error
246
+	 */
247
+	public static function load_reg_steps()
248
+	{
249
+		static $reg_steps_loaded = false;
250
+		if ($reg_steps_loaded) {
251
+			return;
252
+		}
253
+		// filter list of reg_steps
254
+		$reg_steps_to_load = (array)apply_filters(
255
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256
+			EED_Single_Page_Checkout::get_reg_steps()
257
+		);
258
+		// sort by key (order)
259
+		ksort($reg_steps_to_load);
260
+		// loop through folders
261
+		foreach ($reg_steps_to_load as $order => $reg_step) {
262
+			// we need a
263
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
264
+				// copy over to the reg_steps_array
265
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
266
+				// register custom key route for each reg step
267
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
268
+				EE_Config::register_route(
269
+					$reg_step['slug'],
270
+					'EED_Single_Page_Checkout',
271
+					'run',
272
+					'step'
273
+				);
274
+				// add AJAX or other hooks
275
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
276
+					// setup autoloaders if necessary
277
+					if ( ! class_exists($reg_step['class_name'])) {
278
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
279
+							$reg_step['file_path'],
280
+							true
281
+						);
282
+					}
283
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
284
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
285
+					}
286
+				}
287
+			}
288
+		}
289
+		$reg_steps_loaded = true;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 *    get_reg_steps
296
+	 *
297
+	 * @access    public
298
+	 * @return    array
299
+	 */
300
+	public static function get_reg_steps()
301
+	{
302
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
303
+		if (empty($reg_steps)) {
304
+			$reg_steps = array(
305
+				10  => array(
306
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308
+					'slug'       => 'attendee_information',
309
+					'has_hooks'  => false,
310
+				),
311
+				20  => array(
312
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
313
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314
+					'slug'       => 'registration_confirmation',
315
+					'has_hooks'  => false,
316
+				),
317
+				30  => array(
318
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
319
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320
+					'slug'       => 'payment_options',
321
+					'has_hooks'  => true,
322
+				),
323
+				999 => array(
324
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
325
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326
+					'slug'       => 'finalize_registration',
327
+					'has_hooks'  => false,
328
+				),
329
+			);
330
+		}
331
+		return $reg_steps;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 *    registration_checkout_for_admin
338
+	 *
339
+	 * @access    public
340
+	 * @return    string
341
+	 * @throws EE_Error
342
+	 */
343
+	public static function registration_checkout_for_admin()
344
+	{
345
+		EED_Single_Page_Checkout::load_request_handler();
346
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
347
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
348
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
349
+		EED_Single_Page_Checkout::instance()->_initialize();
350
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
351
+		return EE_Registry::instance()->REQ->get_output();
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * process_registration_from_admin
358
+	 *
359
+	 * @access public
360
+	 * @return \EE_Transaction
361
+	 * @throws EE_Error
362
+	 */
363
+	public static function process_registration_from_admin()
364
+	{
365
+		EED_Single_Page_Checkout::load_request_handler();
366
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
367
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
368
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
369
+		EED_Single_Page_Checkout::instance()->_initialize();
370
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
371
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
372
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
373
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
374
+				if ($final_reg_step->process_reg_step()) {
375
+					$final_reg_step->set_completed();
376
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
377
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
378
+				}
379
+			}
380
+		}
381
+		return null;
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 *    run
388
+	 *
389
+	 * @access    public
390
+	 * @param WP_Query $WP_Query
391
+	 * @return    void
392
+	 * @throws EE_Error
393
+	 */
394
+	public function run($WP_Query)
395
+	{
396
+		if (
397
+			$WP_Query instanceof WP_Query
398
+			&& $WP_Query->is_main_query()
399
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
400
+			&& $this->_is_reg_checkout()
401
+		) {
402
+			$this->_initialize();
403
+		}
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * determines whether current url matches reg page url
410
+	 *
411
+	 * @return bool
412
+	 */
413
+	protected function _is_reg_checkout()
414
+	{
415
+		// get current permalink for reg page without any extra query args
416
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
417
+		// get request URI for current request, but without the scheme or host
418
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
419
+		$current_request_uri = html_entity_decode($current_request_uri);
420
+		// get array of query args from the current request URI
421
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
422
+		// grab page id if it is set
423
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
424
+		// and remove the page id from the query args (we will re-add it later)
425
+		unset($query_args['page_id']);
426
+		// now strip all query args from current request URI
427
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
428
+		// and re-add the page id if it was set
429
+		if ($page_id) {
430
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
431
+		}
432
+		// remove slashes and ?
433
+		$current_request_uri = trim($current_request_uri, '?/');
434
+		// is current request URI part of the known full reg page URL ?
435
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
436
+	}
437
+
438
+
439
+
440
+	/**
441
+	 * @param WP_Query $wp_query
442
+	 * @return    void
443
+	 * @throws EE_Error
444
+	 */
445
+	public static function init($wp_query)
446
+	{
447
+		EED_Single_Page_Checkout::instance()->run($wp_query);
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 *    _initialize - initial module setup
454
+	 *
455
+	 * @access    private
456
+	 * @throws EE_Error
457
+	 * @return    void
458
+	 */
459
+	private function _initialize()
460
+	{
461
+		// ensure SPCO doesn't run twice
462
+		if (EED_Single_Page_Checkout::$_initialized) {
463
+			return;
464
+		}
465
+		try {
466
+			EED_Single_Page_Checkout::load_reg_steps();
467
+			$this->_verify_session();
468
+			// setup the EE_Checkout object
469
+			$this->checkout = $this->_initialize_checkout();
470
+			// filter checkout
471
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
472
+			// get the $_GET
473
+			$this->_get_request_vars();
474
+			if ($this->_block_bots()) {
475
+				return;
476
+			}
477
+			// filter continue_reg
478
+			$this->checkout->continue_reg = apply_filters(
479
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
480
+				true,
481
+				$this->checkout
482
+			);
483
+			// load the reg steps array
484
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
485
+				EED_Single_Page_Checkout::$_initialized = true;
486
+				return;
487
+			}
488
+			// set the current step
489
+			$this->checkout->set_current_step($this->checkout->step);
490
+			// and the next step
491
+			$this->checkout->set_next_step();
492
+			// verify that everything has been setup correctly
493
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
494
+				EED_Single_Page_Checkout::$_initialized = true;
495
+				return;
496
+			}
497
+			// lock the transaction
498
+			$this->checkout->transaction->lock();
499
+			// make sure all of our cached objects are added to their respective model entity mappers
500
+			$this->checkout->refresh_all_entities();
501
+			// set amount owing
502
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
503
+			// initialize each reg step, which gives them the chance to potentially alter the process
504
+			$this->_initialize_reg_steps();
505
+			// DEBUG LOG
506
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507
+			// get reg form
508
+			if( ! $this->_check_form_submission()) {
509
+				EED_Single_Page_Checkout::$_initialized = true;
510
+				return;
511
+			}
512
+			// checkout the action!!!
513
+			$this->_process_form_action();
514
+			// add some style and make it dance
515
+			$this->add_styles_and_scripts();
516
+			// kk... SPCO has successfully run
517
+			EED_Single_Page_Checkout::$_initialized = true;
518
+			// set no cache headers and constants
519
+			EE_System::do_not_cache();
520
+			// add anchor
521
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
522
+			// remove transaction lock
523
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
524
+		} catch (Exception $e) {
525
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
526
+		}
527
+	}
528
+
529
+
530
+
531
+	/**
532
+	 *    _verify_session
533
+	 * checks that the session is valid and not expired
534
+	 *
535
+	 * @access    private
536
+	 * @throws EE_Error
537
+	 */
538
+	private function _verify_session()
539
+	{
540
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
541
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
542
+		}
543
+		$clear_session_requested = filter_var(
544
+			EE_Registry::instance()->REQ->get('clear_session', false),
545
+			FILTER_VALIDATE_BOOLEAN
546
+		);
547
+		// is session still valid ?
548
+		if ($clear_session_requested
549
+			|| ( EE_Registry::instance()->SSN->expired()
550
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551
+			)
552
+		) {
553
+			$this->checkout = new EE_Checkout();
554
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
555
+			// EE_Registry::instance()->SSN->reset_cart();
556
+			// EE_Registry::instance()->SSN->reset_checkout();
557
+			// EE_Registry::instance()->SSN->reset_transaction();
558
+			if (! $clear_session_requested) {
559
+				EE_Error::add_attention(
560
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561
+					__FILE__, __FUNCTION__, __LINE__
562
+				);
563
+			}
564
+			// EE_Registry::instance()->SSN->reset_expired();
565
+		}
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 *    _initialize_checkout
572
+	 * loads and instantiates EE_Checkout
573
+	 *
574
+	 * @access    private
575
+	 * @throws EE_Error
576
+	 * @return EE_Checkout
577
+	 */
578
+	private function _initialize_checkout()
579
+	{
580
+		// look in session for existing checkout
581
+		/** @type EE_Checkout $checkout */
582
+		$checkout = EE_Registry::instance()->SSN->checkout();
583
+		// verify
584
+		if ( ! $checkout instanceof EE_Checkout) {
585
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
586
+			$checkout = EE_Registry::instance()->load_file(
587
+				SPCO_INC_PATH,
588
+				'EE_Checkout',
589
+				'class', array(),
590
+				false
591
+			);
592
+		} else {
593
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
594
+				$this->unlock_transaction();
595
+				wp_safe_redirect($checkout->redirect_url);
596
+				exit();
597
+			}
598
+		}
599
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
600
+		// verify again
601
+		if ( ! $checkout instanceof EE_Checkout) {
602
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
603
+		}
604
+		// reset anything that needs a clean slate for each request
605
+		$checkout->reset_for_current_request();
606
+		return $checkout;
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 *    _get_request_vars
613
+	 *
614
+	 * @access    private
615
+	 * @return    void
616
+	 * @throws EE_Error
617
+	 */
618
+	private function _get_request_vars()
619
+	{
620
+		// load classes
621
+		EED_Single_Page_Checkout::load_request_handler();
622
+		//make sure this request is marked as belonging to EE
623
+		EE_Registry::instance()->REQ->set_espresso_page(true);
624
+		// which step is being requested ?
625
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
626
+		// which step is being edited ?
627
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
628
+		// and what we're doing on the current step
629
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
630
+		// timestamp
631
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
632
+		// returning to edit ?
633
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
634
+		// add reg url link to registration query params
635
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
636
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
637
+		}
638
+		// or some other kind of revisit ?
639
+		$this->checkout->revisit = filter_var(
640
+			EE_Registry::instance()->REQ->get('revisit', false),
641
+			FILTER_VALIDATE_BOOLEAN
642
+		);
643
+		// and whether or not to generate a reg form for this request
644
+		$this->checkout->generate_reg_form = filter_var(
645
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
+			FILTER_VALIDATE_BOOLEAN
647
+		);
648
+		// and whether or not to process a reg form submission for this request
649
+		$this->checkout->process_form_submission = filter_var(
650
+			EE_Registry::instance()->REQ->get(
651
+				'process_form_submission',
652
+				$this->checkout->action === 'process_reg_step'
653
+			),
654
+			FILTER_VALIDATE_BOOLEAN
655
+		);
656
+		$this->checkout->process_form_submission = filter_var(
657
+			$this->checkout->action !== 'display_spco_reg_step'
658
+				? $this->checkout->process_form_submission
659
+				: false,
660
+			FILTER_VALIDATE_BOOLEAN
661
+		);
662
+		// $this->_display_request_vars();
663
+	}
664
+
665
+
666
+
667
+	/**
668
+	 *  _display_request_vars
669
+	 *
670
+	 * @access    protected
671
+	 * @return    void
672
+	 */
673
+	protected function _display_request_vars()
674
+	{
675
+		if ( ! WP_DEBUG) {
676
+			return;
677
+		}
678
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * _block_bots
692
+	 * checks that the incoming request has either of the following set:
693
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
+	 * then where you coming from man?
697
+	 *
698
+	 * @return boolean
699
+	 */
700
+	private function _block_bots()
701
+	{
702
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
+			return true;
705
+		}
706
+		return false;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 *    _get_first_step
713
+	 *  gets slug for first step in $_reg_steps_array
714
+	 *
715
+	 * @access    private
716
+	 * @throws EE_Error
717
+	 * @return    string
718
+	 */
719
+	private function _get_first_step()
720
+	{
721
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
+	}
724
+
725
+
726
+
727
+	/**
728
+	 *    _load_and_instantiate_reg_steps
729
+	 *  instantiates each reg step based on the loaded reg_steps array
730
+	 *
731
+	 * @access    private
732
+	 * @throws EE_Error
733
+	 * @return    bool
734
+	 */
735
+	private function _load_and_instantiate_reg_steps()
736
+	{
737
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
+		// have reg_steps already been instantiated ?
739
+		if (
740
+			empty($this->checkout->reg_steps)
741
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
+		) {
743
+			// if not, then loop through raw reg steps array
744
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
+					return false;
747
+				}
748
+			}
749
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
+			// skip the registration_confirmation page ?
752
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
+				// just remove it from the reg steps array
754
+				$this->checkout->remove_reg_step('registration_confirmation', false);
755
+			} else if (
756
+				isset($this->checkout->reg_steps['registration_confirmation'])
757
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
+			) {
759
+				// set the order to something big like 100
760
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
761
+			}
762
+			// filter the array for good luck
763
+			$this->checkout->reg_steps = apply_filters(
764
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
+				$this->checkout->reg_steps
766
+			);
767
+			// finally re-sort based on the reg step class order properties
768
+			$this->checkout->sort_reg_steps();
769
+		} else {
770
+			foreach ($this->checkout->reg_steps as $reg_step) {
771
+				// set all current step stati to FALSE
772
+				$reg_step->set_is_current_step(false);
773
+			}
774
+		}
775
+		if (empty($this->checkout->reg_steps)) {
776
+			EE_Error::add_error(
777
+				__('No Reg Steps were loaded..', 'event_espresso'),
778
+				__FILE__, __FUNCTION__, __LINE__
779
+			);
780
+			return false;
781
+		}
782
+		// make reg step details available to JS
783
+		$this->checkout->set_reg_step_JSON_info();
784
+		return true;
785
+	}
786
+
787
+
788
+
789
+	/**
790
+	 *     _load_and_instantiate_reg_step
791
+	 *
792
+	 * @access    private
793
+	 * @param array $reg_step
794
+	 * @param int   $order
795
+	 * @return bool
796
+	 */
797
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
+	{
799
+		// we need a file_path, class_name, and slug to add a reg step
800
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
+			if (
803
+				$this->checkout->reg_url_link
804
+				&& $this->checkout->step !== $reg_step['slug']
805
+				&& $reg_step['slug'] !== 'finalize_registration'
806
+				// normally at this point we would NOT load the reg step, but this filter can change that
807
+				&& apply_filters(
808
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
+					true,
810
+					$reg_step,
811
+					$this->checkout
812
+				)
813
+			) {
814
+				return true;
815
+			}
816
+			// instantiate step class using file path and class name
817
+			$reg_step_obj = EE_Registry::instance()->load_file(
818
+				$reg_step['file_path'],
819
+				$reg_step['class_name'],
820
+				'class',
821
+				$this->checkout,
822
+				false
823
+			);
824
+			// did we gets the goods ?
825
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
+				// set reg step order based on config
827
+				$reg_step_obj->set_order($order);
828
+				// add instantiated reg step object to the master reg steps array
829
+				$this->checkout->add_reg_step($reg_step_obj);
830
+			} else {
831
+				EE_Error::add_error(
832
+					__('The current step could not be set.', 'event_espresso'),
833
+					__FILE__, __FUNCTION__, __LINE__
834
+				);
835
+				return false;
836
+			}
837
+		} else {
838
+			if (WP_DEBUG) {
839
+				EE_Error::add_error(
840
+					sprintf(
841
+						__(
842
+							'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',
843
+							'event_espresso'
844
+						),
845
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
+						'<ul>',
849
+						'<li>',
850
+						'</li>',
851
+						'</ul>'
852
+					),
853
+					__FILE__, __FUNCTION__, __LINE__
854
+				);
855
+			}
856
+			return false;
857
+		}
858
+		return true;
859
+	}
860
+
861
+
862
+	/**
863
+	 * _verify_transaction_and_get_registrations
864
+	 *
865
+	 * @access private
866
+	 * @return bool
867
+	 * @throws InvalidDataTypeException
868
+	 * @throws InvalidEntityException
869
+	 * @throws EE_Error
870
+	 */
871
+	private function _verify_transaction_and_get_registrations()
872
+	{
873
+		// was there already a valid transaction in the checkout from the session ?
874
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
+			// get transaction from db or session
876
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
+				? $this->_get_transaction_and_cart_for_previous_visit()
878
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
879
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
+				EE_Error::add_error(
881
+					__('Your Registration and Transaction information could not be retrieved from the db.',
882
+						'event_espresso'),
883
+					__FILE__, __FUNCTION__, __LINE__
884
+				);
885
+				$this->checkout->transaction = EE_Transaction::new_instance();
886
+				// add some style and make it dance
887
+				$this->add_styles_and_scripts();
888
+				EED_Single_Page_Checkout::$_initialized = true;
889
+				return false;
890
+			}
891
+			// and the registrations for the transaction
892
+			$this->_get_registrations($this->checkout->transaction);
893
+		}
894
+		return true;
895
+	}
896
+
897
+
898
+
899
+	/**
900
+	 * _get_transaction_and_cart_for_previous_visit
901
+	 *
902
+	 * @access private
903
+	 * @return mixed EE_Transaction|NULL
904
+	 */
905
+	private function _get_transaction_and_cart_for_previous_visit()
906
+	{
907
+		/** @var $TXN_model EEM_Transaction */
908
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
909
+		// because the reg_url_link is present in the request,
910
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
911
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
+		// verify transaction
913
+		if ($transaction instanceof EE_Transaction) {
914
+			// and get the cart that was used for that transaction
915
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
+			return $transaction;
917
+		}
918
+		EE_Error::add_error(
919
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
+			__FILE__, __FUNCTION__, __LINE__
921
+		);
922
+		return null;
923
+
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * _get_cart_for_transaction
930
+	 *
931
+	 * @access private
932
+	 * @param EE_Transaction $transaction
933
+	 * @return EE_Cart
934
+	 */
935
+	private function _get_cart_for_transaction($transaction)
936
+	{
937
+		return $this->checkout->get_cart_for_transaction($transaction);
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * get_cart_for_transaction
944
+	 *
945
+	 * @access public
946
+	 * @param EE_Transaction $transaction
947
+	 * @return EE_Cart
948
+	 */
949
+	public function get_cart_for_transaction(EE_Transaction $transaction)
950
+	{
951
+		return $this->checkout->get_cart_for_transaction($transaction);
952
+	}
953
+
954
+
955
+
956
+	/**
957
+	 * _get_transaction_and_cart_for_current_session
958
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
+	 *
960
+	 * @access private
961
+	 * @return EE_Transaction
962
+	 * @throws EE_Error
963
+	 */
964
+	private function _get_cart_for_current_session_and_setup_new_transaction()
965
+	{
966
+		//  if there's no transaction, then this is the FIRST visit to SPCO
967
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
969
+		// and then create a new transaction
970
+		$transaction = $this->_initialize_transaction();
971
+		// verify transaction
972
+		if ($transaction instanceof EE_Transaction) {
973
+			// save it so that we have an ID for other objects to use
974
+			$transaction->save();
975
+			// and save TXN data to the cart
976
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
+		} else {
978
+			EE_Error::add_error(
979
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
980
+				__FILE__, __FUNCTION__, __LINE__
981
+			);
982
+		}
983
+		return $transaction;
984
+	}
985
+
986
+
987
+
988
+	/**
989
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
+	 *
991
+	 * @access private
992
+	 * @return mixed EE_Transaction|NULL
993
+	 */
994
+	private function _initialize_transaction()
995
+	{
996
+		try {
997
+			// ensure cart totals have been calculated
998
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
+			// grab the cart grand total
1000
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
1001
+			// create new TXN
1002
+			$transaction = EE_Transaction::new_instance(
1003
+				array(
1004
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
+					'TXN_paid'      => 0,
1007
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1008
+				)
1009
+			);
1010
+			// save it so that we have an ID for other objects to use
1011
+			$transaction->save();
1012
+			// set cron job for following up on TXNs after their session has expired
1013
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1014
+				EE_Registry::instance()->SSN->expiration() + 1,
1015
+				$transaction->ID()
1016
+			);
1017
+			return $transaction;
1018
+		} catch (Exception $e) {
1019
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
+		}
1021
+		return null;
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * _get_registrations
1027
+	 *
1028
+	 * @access private
1029
+	 * @param EE_Transaction $transaction
1030
+	 * @return void
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidEntityException
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	private function _get_registrations(EE_Transaction $transaction)
1036
+	{
1037
+		// first step: grab the registrants  { : o
1038
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1039
+		$this->checkout->total_ticket_count = count($registrations);
1040
+		// verify registrations have been set
1041
+		if (empty($registrations)) {
1042
+			// if no cached registrations, then check the db
1043
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1044
+			// still nothing ? well as long as this isn't a revisit
1045
+			if (empty($registrations) && ! $this->checkout->revisit) {
1046
+				// generate new registrations from scratch
1047
+				$registrations = $this->_initialize_registrations($transaction);
1048
+			}
1049
+		}
1050
+		// sort by their original registration order
1051
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1052
+		// then loop thru the array
1053
+		foreach ($registrations as $registration) {
1054
+			// verify each registration
1055
+			if ($registration instanceof EE_Registration) {
1056
+				// we display all attendee info for the primary registrant
1057
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1058
+					&& $registration->is_primary_registrant()
1059
+				) {
1060
+					$this->checkout->primary_revisit = true;
1061
+					break;
1062
+				}
1063
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1064
+					// but hide info if it doesn't belong to you
1065
+					$transaction->clear_cache('Registration', $registration->ID());
1066
+					$this->checkout->total_ticket_count--;
1067
+				}
1068
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1069
+			}
1070
+		}
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
+	 *
1077
+	 * @access private
1078
+	 * @param EE_Transaction $transaction
1079
+	 * @return    array
1080
+	 * @throws InvalidDataTypeException
1081
+	 * @throws InvalidEntityException
1082
+	 * @throws EE_Error
1083
+	 */
1084
+	private function _initialize_registrations(EE_Transaction $transaction)
1085
+	{
1086
+		$att_nmbr = 0;
1087
+		$registrations = array();
1088
+		if ($transaction instanceof EE_Transaction) {
1089
+			/** @type EE_Registration_Processor $registration_processor */
1090
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
+			// now let's add the cart items to the $transaction
1093
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
+				//do the following for each ticket of this type they selected
1095
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
+					$att_nmbr++;
1097
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1099
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
+						array(
1101
+							$transaction,
1102
+							$line_item,
1103
+							$att_nmbr,
1104
+							$this->checkout->total_ticket_count,
1105
+						)
1106
+					);
1107
+					// override capabilities for frontend registrations
1108
+					if ( ! is_admin()) {
1109
+						$CreateRegistrationCommand->setCapCheck(
1110
+							new PublicCapabilities('', 'create_new_registration')
1111
+						);
1112
+					}
1113
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
+					if ( ! $registration instanceof EE_Registration) {
1115
+						throw new InvalidEntityException($registration, 'EE_Registration');
1116
+					}
1117
+					$registrations[ $registration->ID() ] = $registration;
1118
+				}
1119
+			}
1120
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
+		}
1122
+		return $registrations;
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * sorts registrations by REG_count
1129
+	 *
1130
+	 * @access public
1131
+	 * @param EE_Registration $reg_A
1132
+	 * @param EE_Registration $reg_B
1133
+	 * @return int
1134
+	 */
1135
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
+	{
1137
+		// this shouldn't ever happen within the same TXN, but oh well
1138
+		if ($reg_A->count() === $reg_B->count()) {
1139
+			return 0;
1140
+		}
1141
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
+	}
1143
+
1144
+
1145
+
1146
+	/**
1147
+	 *    _final_verifications
1148
+	 * just makes sure that everything is set up correctly before proceeding
1149
+	 *
1150
+	 * @access    private
1151
+	 * @return    bool
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	private function _final_verifications()
1155
+	{
1156
+		// filter checkout
1157
+		$this->checkout = apply_filters(
1158
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
+			$this->checkout
1160
+		);
1161
+		//verify that current step is still set correctly
1162
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
+			EE_Error::add_error(
1164
+				__('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'),
1165
+				__FILE__,
1166
+				__FUNCTION__,
1167
+				__LINE__
1168
+			);
1169
+			return false;
1170
+		}
1171
+		// if returning to SPCO, then verify that primary registrant is set
1172
+		if ( ! empty($this->checkout->reg_url_link)) {
1173
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1174
+			if ( ! $valid_registrant instanceof EE_Registration) {
1175
+				EE_Error::add_error(
1176
+					__('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'),
1177
+					__FILE__,
1178
+					__FUNCTION__,
1179
+					__LINE__
1180
+				);
1181
+				return false;
1182
+			}
1183
+			$valid_registrant = null;
1184
+			foreach (
1185
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
+			) {
1187
+				if (
1188
+					$registration instanceof EE_Registration
1189
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1190
+				) {
1191
+					$valid_registrant = $registration;
1192
+				}
1193
+			}
1194
+			if ( ! $valid_registrant instanceof EE_Registration) {
1195
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
+					// clear the session, mark the checkout as unverified, and try again
1198
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
+					EED_Single_Page_Checkout::$_initialized = false;
1200
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1201
+					$this->_initialize();
1202
+					EE_Error::reset_notices();
1203
+					return false;
1204
+				}
1205
+				EE_Error::add_error(
1206
+					__(
1207
+						'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.',
1208
+						'event_espresso'
1209
+					),
1210
+					__FILE__,
1211
+					__FUNCTION__,
1212
+					__LINE__
1213
+				);
1214
+				return false;
1215
+			}
1216
+		}
1217
+		// now that things have been kinda sufficiently verified,
1218
+		// let's add the checkout to the session so that it's available to other systems
1219
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
+		return true;
1221
+	}
1222
+
1223
+
1224
+
1225
+	/**
1226
+	 *    _initialize_reg_steps
1227
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
+	 *
1230
+	 * @access    private
1231
+	 * @param bool $reinitializing
1232
+	 * @throws EE_Error
1233
+	 */
1234
+	private function _initialize_reg_steps($reinitializing = false)
1235
+	{
1236
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
+		foreach ($this->checkout->reg_steps as $reg_step) {
1239
+			if ( ! $reg_step->initialize_reg_step()) {
1240
+				// if not initialized then maybe this step is being removed...
1241
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
+					// if it was the current step, then we need to start over here
1243
+					$this->_initialize_reg_steps(true);
1244
+					return;
1245
+				}
1246
+				continue;
1247
+			}
1248
+			// add css and JS for current step
1249
+			$reg_step->enqueue_styles_and_scripts();
1250
+			// i18n
1251
+			$reg_step->translate_js_strings();
1252
+			if ($reg_step->is_current_step()) {
1253
+				// the text that appears on the reg step form submit button
1254
+				$reg_step->set_submit_button_text();
1255
+			}
1256
+		}
1257
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
+		do_action(
1259
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
+			$this->checkout->current_step
1261
+		);
1262
+	}
1263
+
1264
+
1265
+
1266
+	/**
1267
+	 * _check_form_submission
1268
+	 *
1269
+	 * @access private
1270
+	 * @return boolean
1271
+	 */
1272
+	private function _check_form_submission()
1273
+	{
1274
+		//does this request require the reg form to be generated ?
1275
+		if ($this->checkout->generate_reg_form) {
1276
+			// ever heard that song by Blue Rodeo ?
1277
+			try {
1278
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
+				// if not displaying a form, then check for form submission
1280
+				if (
1281
+					$this->checkout->process_form_submission
1282
+					&& $this->checkout->current_step->reg_form->was_submitted()
1283
+				) {
1284
+					// clear out any old data in case this step is being run again
1285
+					$this->checkout->current_step->set_valid_data(array());
1286
+					// capture submitted form data
1287
+					$this->checkout->current_step->reg_form->receive_form_submission(
1288
+						apply_filters(
1289
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
+							EE_Registry::instance()->REQ->params(),
1291
+							$this->checkout
1292
+						)
1293
+					);
1294
+					// validate submitted form data
1295
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
+						// thou shall not pass !!!
1297
+						$this->checkout->continue_reg = false;
1298
+						// any form validation errors?
1299
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
+							EE_Error::add_error(
1301
+								$this->checkout->current_step->reg_form->submission_error_message(),
1302
+								__FILE__, __FUNCTION__, __LINE__
1303
+							);
1304
+						}
1305
+						// well not really... what will happen is
1306
+						// we'll just get redirected back to redo the current step
1307
+						$this->go_to_next_step();
1308
+						return false;
1309
+					}
1310
+				}
1311
+			} catch (EE_Error $e) {
1312
+				$e->get_error();
1313
+			}
1314
+		}
1315
+		return true;
1316
+	}
1317
+
1318
+
1319
+
1320
+	/**
1321
+	 * _process_action
1322
+	 *
1323
+	 * @access private
1324
+	 * @return void
1325
+	 * @throws EE_Error
1326
+	 */
1327
+	private function _process_form_action()
1328
+	{
1329
+		// what cha wanna do?
1330
+		switch ($this->checkout->action) {
1331
+			// AJAX next step reg form
1332
+			case 'display_spco_reg_step' :
1333
+				$this->checkout->redirect = false;
1334
+				if (EE_Registry::instance()->REQ->ajax) {
1335
+					$this->checkout->json_response->set_reg_step_html(
1336
+						$this->checkout->current_step->display_reg_form()
1337
+					);
1338
+				}
1339
+				break;
1340
+			default :
1341
+				// meh... do one of those other steps first
1342
+				if (
1343
+					! empty($this->checkout->action)
1344
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1345
+				) {
1346
+					// dynamically creates hook point like:
1347
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1348
+					do_action(
1349
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1350
+						$this->checkout->current_step
1351
+					);
1352
+					// call action on current step
1353
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1354
+						// good registrant, you get to proceed
1355
+						if (
1356
+							$this->checkout->current_step->success_message() !== ''
1357
+							&& apply_filters(
1358
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1359
+								false
1360
+							)
1361
+						) {
1362
+							EE_Error::add_success(
1363
+								$this->checkout->current_step->success_message()
1364
+								. '<br />' . $this->checkout->next_step->_instructions()
1365
+							);
1366
+						}
1367
+						// pack it up, pack it in...
1368
+						$this->_setup_redirect();
1369
+					}
1370
+					// dynamically creates hook point like:
1371
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1372
+					do_action(
1373
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1374
+						$this->checkout->current_step
1375
+					);
1376
+				} else {
1377
+					EE_Error::add_error(
1378
+						sprintf(
1379
+							__(
1380
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1381
+								'event_espresso'
1382
+							),
1383
+							$this->checkout->action,
1384
+							$this->checkout->current_step->name()
1385
+						),
1386
+						__FILE__,
1387
+						__FUNCTION__,
1388
+						__LINE__
1389
+					);
1390
+				}
1391
+			// end default
1392
+		}
1393
+		// store our progress so far
1394
+		$this->checkout->stash_transaction_and_checkout();
1395
+		// advance to the next step! If you pass GO, collect $200
1396
+		$this->go_to_next_step();
1397
+	}
1398
+
1399
+
1400
+
1401
+	/**
1402
+	 *        add_styles_and_scripts
1403
+	 *
1404
+	 * @access        public
1405
+	 * @return        void
1406
+	 */
1407
+	public function add_styles_and_scripts()
1408
+	{
1409
+		// i18n
1410
+		$this->translate_js_strings();
1411
+		if ($this->checkout->admin_request) {
1412
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1413
+		} else {
1414
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1415
+		}
1416
+	}
1417
+
1418
+
1419
+
1420
+	/**
1421
+	 *        translate_js_strings
1422
+	 *
1423
+	 * @access        public
1424
+	 * @return        void
1425
+	 */
1426
+	public function translate_js_strings()
1427
+	{
1428
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1429
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1430
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1431
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1432
+			'event_espresso'
1433
+		);
1434
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1435
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1436
+			'event_espresso'
1437
+		);
1438
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1439
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1440
+			'event_espresso'
1441
+		);
1442
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1443
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1444
+			'event_espresso'
1445
+		);
1446
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1447
+			'This registration step could not be completed. Please refresh the page and try again.',
1448
+			'event_espresso'
1449
+		);
1450
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1451
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1452
+			'event_espresso'
1453
+		);
1454
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1455
+			__(
1456
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1457
+				'event_espresso'
1458
+			),
1459
+			'<br/>',
1460
+			'<br/>'
1461
+		);
1462
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1463
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1464
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1465
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1466
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1467
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1468
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1469
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1470
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1471
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1472
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1473
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1474
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1475
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1476
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1477
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1478
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1479
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1480
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1481
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1482
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1483
+			true
1484
+		);
1485
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1486
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1487
+		);
1488
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1489
+			'M d, Y H:i:s',
1490
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1491
+		);
1492
+	}
1493
+
1494
+
1495
+
1496
+	/**
1497
+	 *    enqueue_styles_and_scripts
1498
+	 *
1499
+	 * @access        public
1500
+	 * @return        void
1501
+	 * @throws EE_Error
1502
+	 */
1503
+	public function enqueue_styles_and_scripts()
1504
+	{
1505
+		// load css
1506
+		wp_register_style(
1507
+			'single_page_checkout',
1508
+			SPCO_CSS_URL . 'single_page_checkout.css',
1509
+			array('espresso_default'),
1510
+			EVENT_ESPRESSO_VERSION
1511
+		);
1512
+		wp_enqueue_style('single_page_checkout');
1513
+		// load JS
1514
+		wp_register_script(
1515
+			'jquery_plugin',
1516
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1517
+			array('jquery'),
1518
+			'1.0.1',
1519
+			true
1520
+		);
1521
+		wp_register_script(
1522
+			'jquery_countdown',
1523
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1524
+			array('jquery_plugin'),
1525
+			'2.0.2',
1526
+			true
1527
+		);
1528
+		wp_register_script(
1529
+			'single_page_checkout',
1530
+			SPCO_JS_URL . 'single_page_checkout.js',
1531
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1532
+			EVENT_ESPRESSO_VERSION,
1533
+			true
1534
+		);
1535
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1536
+			$this->checkout->registration_form->enqueue_js();
1537
+		}
1538
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1539
+			$this->checkout->current_step->reg_form->enqueue_js();
1540
+		}
1541
+		wp_enqueue_script('single_page_checkout');
1542
+		/**
1543
+		 * global action hook for enqueueing styles and scripts with
1544
+		 * spco calls.
1545
+		 */
1546
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1547
+		/**
1548
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1549
+		 * The hook will end up being something like:
1550
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1551
+		 */
1552
+		do_action(
1553
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1554
+			$this
1555
+		);
1556
+	}
1557
+
1558
+
1559
+
1560
+	/**
1561
+	 *    display the Registration Single Page Checkout Form
1562
+	 *
1563
+	 * @access    private
1564
+	 * @return    void
1565
+	 * @throws EE_Error
1566
+	 */
1567
+	private function _display_spco_reg_form()
1568
+	{
1569
+		// if registering via the admin, just display the reg form for the current step
1570
+		if ($this->checkout->admin_request) {
1571
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1572
+		} else {
1573
+			// add powered by EE msg
1574
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1575
+			$empty_cart = count(
1576
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1577
+			) < 1;
1578
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1579
+			$cookies_not_set_msg = '';
1580
+			if ($empty_cart) {
1581
+				$cookies_not_set_msg = apply_filters(
1582
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1583
+					sprintf(
1584
+						__(
1585
+							'%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',
1586
+							'event_espresso'
1587
+						),
1588
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1589
+						'</div>',
1590
+						'<h6 class="important-notice">',
1591
+						'</h6>',
1592
+						'<p>',
1593
+						'</p>',
1594
+						'<br />',
1595
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1596
+						'</a>'
1597
+					)
1598
+				);
1599
+			}
1600
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1601
+				array(
1602
+					'name'            => 'single-page-checkout',
1603
+					'html_id'         => 'ee-single-page-checkout-dv',
1604
+					'layout_strategy' =>
1605
+						new EE_Template_Layout(
1606
+							array(
1607
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1608
+								'template_args'        => array(
1609
+									'empty_cart'              => $empty_cart,
1610
+									'revisit'                 => $this->checkout->revisit,
1611
+									'reg_steps'               => $this->checkout->reg_steps,
1612
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1613
+										? $this->checkout->next_step->slug()
1614
+										: '',
1615
+									'empty_msg'               => apply_filters(
1616
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1617
+										sprintf(
1618
+											__(
1619
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1620
+												'event_espresso'
1621
+											),
1622
+											'<a href="'
1623
+											. get_post_type_archive_link('espresso_events')
1624
+											. '" title="',
1625
+											'">',
1626
+											'</a>'
1627
+										)
1628
+									),
1629
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1630
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1631
+									'session_expiration'      => gmdate(
1632
+										'M d, Y H:i:s',
1633
+										EE_Registry::instance()->SSN->expiration()
1634
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1635
+									),
1636
+								),
1637
+							)
1638
+						),
1639
+				)
1640
+			);
1641
+			// load template and add to output sent that gets filtered into the_content()
1642
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1643
+		}
1644
+	}
1645
+
1646
+
1647
+
1648
+	/**
1649
+	 *    add_extra_finalize_registration_inputs
1650
+	 *
1651
+	 * @access    public
1652
+	 * @param $next_step
1653
+	 * @internal  param string $label
1654
+	 * @return void
1655
+	 */
1656
+	public function add_extra_finalize_registration_inputs($next_step)
1657
+	{
1658
+		if ($next_step === 'finalize_registration') {
1659
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1660
+		}
1661
+	}
1662
+
1663
+
1664
+
1665
+	/**
1666
+	 *    display_registration_footer
1667
+	 *
1668
+	 * @access    public
1669
+	 * @return    string
1670
+	 */
1671
+	public static function display_registration_footer()
1672
+	{
1673
+		if (
1674
+		apply_filters(
1675
+			'FHEE__EE_Front__Controller__show_reg_footer',
1676
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1677
+		)
1678
+		) {
1679
+			add_filter(
1680
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1681
+				function ($url) {
1682
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1683
+				}
1684
+			);
1685
+			echo apply_filters(
1686
+				'FHEE__EE_Front_Controller__display_registration_footer',
1687
+				\EEH_Template::powered_by_event_espresso(
1688
+					'',
1689
+					'espresso-registration-footer-dv',
1690
+					array('utm_content' => 'registration_checkout')
1691
+				)
1692
+			);
1693
+		}
1694
+		return '';
1695
+	}
1696
+
1697
+
1698
+
1699
+	/**
1700
+	 *    unlock_transaction
1701
+	 *
1702
+	 * @access    public
1703
+	 * @return    void
1704
+	 * @throws EE_Error
1705
+	 */
1706
+	public function unlock_transaction()
1707
+	{
1708
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1709
+			$this->checkout->transaction->unlock();
1710
+		}
1711
+	}
1712
+
1713
+
1714
+
1715
+	/**
1716
+	 *        _setup_redirect
1717
+	 *
1718
+	 * @access    private
1719
+	 * @return void
1720
+	 */
1721
+	private function _setup_redirect()
1722
+	{
1723
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1724
+			$this->checkout->redirect = true;
1725
+			if (empty($this->checkout->redirect_url)) {
1726
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1727
+			}
1728
+			$this->checkout->redirect_url = apply_filters(
1729
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1730
+				$this->checkout->redirect_url,
1731
+				$this->checkout
1732
+			);
1733
+		}
1734
+	}
1735
+
1736
+
1737
+
1738
+	/**
1739
+	 *   handle ajax message responses and redirects
1740
+	 *
1741
+	 * @access public
1742
+	 * @return void
1743
+	 * @throws EE_Error
1744
+	 */
1745
+	public function go_to_next_step()
1746
+	{
1747
+		if (EE_Registry::instance()->REQ->ajax) {
1748
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1749
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1750
+		}
1751
+		$this->unlock_transaction();
1752
+		// just return for these conditions
1753
+		if (
1754
+			$this->checkout->admin_request
1755
+			|| $this->checkout->action === 'redirect_form'
1756
+			|| $this->checkout->action === 'update_checkout'
1757
+		) {
1758
+			return;
1759
+		}
1760
+		// AJAX response
1761
+		$this->_handle_json_response();
1762
+		// redirect to next step or the Thank You page
1763
+		$this->_handle_html_redirects();
1764
+		// hmmm... must be something wrong, so let's just display the form again !
1765
+		$this->_display_spco_reg_form();
1766
+	}
1767
+
1768
+
1769
+
1770
+	/**
1771
+	 *   _handle_json_response
1772
+	 *
1773
+	 * @access protected
1774
+	 * @return void
1775
+	 */
1776
+	protected function _handle_json_response()
1777
+	{
1778
+		// if this is an ajax request
1779
+		if (EE_Registry::instance()->REQ->ajax) {
1780
+			// DEBUG LOG
1781
+			//$this->checkout->log(
1782
+			//	__CLASS__, __FUNCTION__, __LINE__,
1783
+			//	array(
1784
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1785
+			//		'redirect'                   => $this->checkout->redirect,
1786
+			//		'continue_reg'               => $this->checkout->continue_reg,
1787
+			//	)
1788
+			//);
1789
+			$this->checkout->json_response->set_registration_time_limit(
1790
+				$this->checkout->get_registration_time_limit()
1791
+			);
1792
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1793
+			// just send the ajax (
1794
+			$json_response = apply_filters(
1795
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1796
+				$this->checkout->json_response
1797
+			);
1798
+			echo $json_response;
1799
+			exit();
1800
+		}
1801
+	}
1802
+
1803
+
1804
+
1805
+	/**
1806
+	 *   _handle_redirects
1807
+	 *
1808
+	 * @access protected
1809
+	 * @return void
1810
+	 */
1811
+	protected function _handle_html_redirects()
1812
+	{
1813
+		// going somewhere ?
1814
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1815
+			// store notices in a transient
1816
+			EE_Error::get_notices(false, true, true);
1817
+			// DEBUG LOG
1818
+			//$this->checkout->log(
1819
+			//	__CLASS__, __FUNCTION__, __LINE__,
1820
+			//	array(
1821
+			//		'headers_sent' => headers_sent(),
1822
+			//		'redirect_url'     => $this->checkout->redirect_url,
1823
+			//		'headers_list'    => headers_list(),
1824
+			//	)
1825
+			//);
1826
+			wp_safe_redirect($this->checkout->redirect_url);
1827
+			exit();
1828
+		}
1829
+	}
1830
+
1831
+
1832
+
1833
+	/**
1834
+	 *   set_checkout_anchor
1835
+	 *
1836
+	 * @access public
1837
+	 * @return void
1838
+	 */
1839
+	public function set_checkout_anchor()
1840
+	{
1841
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1842
+	}
1843
+
1844
+	/**
1845
+	 *    getRegistrationExpirationNotice
1846
+	 *
1847
+	 * @since $VID:$
1848
+	 * @access    public
1849
+	 * @return    string
1850
+	 */
1851
+	public static function getRegistrationExpirationNotice()
1852
+	{
1853
+		return sprintf(
1854
+			__('%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 accept our apologies for any inconvenience this may have caused.%8$s',
1855
+				'event_espresso'),
1856
+			'<h4 class="important-notice">',
1857
+			'</h4>',
1858
+			'<br />',
1859
+			'<p>',
1860
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1861
+			'">',
1862
+			'</a>',
1863
+			'</p>'
1864
+		);
1865
+	}
1866 1866
 
1867 1867
 }
1868 1868
 // End of file EED_Single_Page_Checkout.module.php
Please login to merge, or discard this patch.
attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php 2 patches
Indentation   +1335 added lines, -1335 removed lines patch added patch discarded remove patch
@@ -17,1343 +17,1343 @@
 block discarded – undo
17 17
 class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step
18 18
 {
19 19
 
20
-    /**
21
-     * @type bool $_print_copy_info
22
-     */
23
-    private $_print_copy_info = false;
24
-
25
-    /**
26
-     * @type array $_attendee_data
27
-     */
28
-    private $_attendee_data = array();
29
-
30
-    /**
31
-     * @type array $_required_questions
32
-     */
33
-    private $_required_questions = array();
34
-
35
-    /**
36
-     * @type array $_registration_answers
37
-     */
38
-    private $_registration_answers = array();
39
-
40
-
41
-    /**
42
-     *    class constructor
43
-     *
44
-     * @access    public
45
-     * @param    EE_Checkout $checkout
46
-     */
47
-    public function __construct(EE_Checkout $checkout)
48
-    {
49
-        $this->_slug     = 'attendee_information';
50
-        $this->_name     = esc_html__('Attendee Information', 'event_espresso');
51
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php';
52
-        $this->checkout  = $checkout;
53
-        $this->_reset_success_message();
54
-        $this->set_instructions(
55
-            esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
56
-        );
57
-    }
58
-
59
-
60
-    public function translate_js_strings()
61
-    {
62
-        EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
63
-            ' is a required question.',
64
-            'event_espresso'
65
-        );
66
-        EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
67
-            ' is a required question. Please enter a value for at least one of the options.',
68
-            'event_espresso'
69
-        );
70
-        EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
71
-            'Please answer all required questions correctly before proceeding.',
72
-            'event_espresso'
73
-        );
74
-        EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
75
-            esc_html__(
76
-                'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
77
-                'event_espresso'
78
-            ),
79
-            '<br/>'
80
-        );
81
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
82
-            'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
83
-            'event_espresso'
84
-        );
85
-        EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
86
-            'You must enter a valid email address.',
87
-            'event_espresso'
88
-        );
89
-        EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
90
-            'You must enter a valid email address and answer all other required questions before you can proceed.',
91
-            'event_espresso'
92
-        );
93
-    }
94
-
95
-
96
-    public function enqueue_styles_and_scripts()
97
-    {
98
-    }
99
-
100
-
101
-    /**
102
-     * @return boolean
103
-     */
104
-    public function initialize_reg_step()
105
-    {
106
-        return true;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return EE_Form_Section_Proper
112
-     * @throws EE_Error
113
-     * @throws InvalidArgumentException
114
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
115
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
116
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
117
-     */
118
-    public function generate_reg_form()
119
-    {
120
-        $this->_print_copy_info = false;
121
-        $primary_registrant     = null;
122
-        // autoload Line_Item_Display classes
123
-        EEH_Autoloader::register_line_item_display_autoloaders();
124
-        $Line_Item_Display = new EE_Line_Item_Display();
125
-        // calculate taxes
126
-        $Line_Item_Display->display_line_item(
127
-            $this->checkout->cart->get_grand_total(),
128
-            array('set_tax_rate' => true)
129
-        );
130
-        /** @var $subsections EE_Form_Section_Proper[] */
131
-        $subsections   = array(
132
-            'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
133
-        );
134
-        $template_args = array(
135
-            'revisit'       => $this->checkout->revisit,
136
-            'registrations' => array(),
137
-            'ticket_count'  => array(),
138
-        );
139
-        // grab the saved registrations from the transaction
140
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
141
-        if ($registrations) {
142
-            foreach ($registrations as $registration) {
143
-                // can this registration be processed during this visit ?
144
-                if ($registration instanceof EE_Registration
145
-                    && $this->checkout->visit_allows_processing_of_this_registration($registration)
146
-                ) {
147
-                    $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
148
-                    if (! $this->checkout->admin_request) {
149
-                        $template_args['registrations'][$registration->reg_url_link()]    = $registration;
150
-                        $template_args['ticket_count'][$registration->ticket()->ID()]     = isset(
151
-                            $template_args['ticket_count'][$registration->ticket()->ID()]
152
-                        )
153
-                            ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1
154
-                            : 1;
155
-                        $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
156
-                            $this->checkout->cart->get_grand_total(),
157
-                            'Ticket',
158
-                            array($registration->ticket()->ID())
159
-                        );
160
-                        $ticket_line_item = is_array($ticket_line_item)
161
-                            ? reset($ticket_line_item)
162
-                            : $ticket_line_item;
163
-                        $template_args['ticket_line_item'][$registration->ticket()->ID()] =
164
-                            $Line_Item_Display->display_line_item($ticket_line_item);
165
-                    }
166
-                    if ($registration->is_primary_registrant()) {
167
-                        $primary_registrant = $registration->reg_url_link();
168
-                    }
169
-                }
170
-            }
171
-            // print_copy_info ?
172
-            if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) {
173
-                // TODO: add admin option for toggling copy attendee info,
174
-                // then use that value to change $this->_print_copy_info
175
-                $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
176
-                    ? $this->_copy_attendee_info_form()
177
-                    : $this->_auto_copy_attendee_info();
178
-                // generate hidden input
179
-                if (isset($subsections[$primary_registrant])
180
-                    && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper
181
-                ) {
182
-                    $subsections[$primary_registrant]->add_subsections(
183
-                        $copy_options,
184
-                        'primary_registrant',
185
-                        false
186
-                    );
187
-                }
188
-            }
189
-        }
190
-
191
-        return new EE_Form_Section_Proper(
192
-            array(
193
-                'name'            => $this->reg_form_name(),
194
-                'html_id'         => $this->reg_form_name(),
195
-                'subsections'     => $subsections,
196
-                'layout_strategy' => $this->checkout->admin_request ?
197
-                    new EE_Div_Per_Section_Layout() :
198
-                    new EE_Template_Layout(
199
-                        array(
200
-                            'layout_template_file' => $this->_template, // layout_template
201
-                            'template_args'        => $template_args,
202
-                        )
203
-                    ),
204
-            )
205
-        );
206
-    }
207
-
208
-
209
-    /**
210
-     * @param EE_Registration $registration
211
-     * @return EE_Form_Section_Base
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
215
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
216
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
217
-     */
218
-    private function _registrations_reg_form(EE_Registration $registration)
219
-    {
220
-        static $attendee_nmbr = 1;
221
-        $form_args = array();
222
-        // verify that registration has valid event
223
-        if ($registration->event() instanceof EE_Event) {
224
-            $question_groups = $registration->event()->question_groups(
225
-                apply_filters(
226
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
227
-                    array(
228
-                        array(
229
-                            'Event.EVT_ID'                     => $registration->event()->ID(),
230
-                            'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
231
-                        ),
232
-                        'order_by' => array('QSG_order' => 'ASC'),
233
-                    ),
234
-                    $registration,
235
-                    $this
236
-                )
237
-            );
238
-            if ($question_groups) {
239
-                // array of params to pass to parent constructor
240
-                $form_args = array(
241
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
242
-                    'html_class'      => 'ee-reg-form-attendee-dv',
243
-                    'html_style'      => $this->checkout->admin_request
244
-                        ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
245
-                        : '',
246
-                    'subsections'     => array(),
247
-                    'layout_strategy' => new EE_Fieldset_Section_Layout(
248
-                        array(
249
-                            'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
250
-                            'legend_text'  => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr),
251
-                        )
252
-                    ),
253
-                );
254
-                foreach ($question_groups as $question_group) {
255
-                    if ($question_group instanceof EE_Question_Group) {
256
-                        $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form(
257
-                            $registration,
258
-                            $question_group
259
-                        );
260
-                    }
261
-                }
262
-                // add hidden input
263
-                $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
264
-                    $registration
265
-                );
266
-                // if we have question groups for additional attendees, then display the copy options
267
-                $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info;
268
-                if ($registration->is_primary_registrant()) {
269
-                    // generate hidden input
270
-                    $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
271
-                        $registration
272
-                    );
273
-                }
274
-            }
275
-        }
276
-        $attendee_nmbr++;
277
-        return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML();
278
-    }
279
-
280
-
281
-    /**
282
-     * _additional_attendee_reg_info_input
283
-     *
284
-     * @access public
285
-     * @param EE_Registration $registration
286
-     * @param bool            $additional_attendee_reg_info
287
-     * @return    EE_Form_Input_Base
288
-     * @throws \EE_Error
289
-     */
290
-    private function _additional_attendee_reg_info_input(
291
-        EE_Registration $registration,
292
-        $additional_attendee_reg_info = true
293
-    ) {
294
-        // generate hidden input
295
-        return new EE_Hidden_Input(
296
-            array(
297
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
298
-                'default' => $additional_attendee_reg_info,
299
-            )
300
-        );
301
-    }
302
-
303
-
304
-    /**
305
-     * @param EE_Registration   $registration
306
-     * @param EE_Question_Group $question_group
307
-     * @return EE_Form_Section_Proper
308
-     * @throws EE_Error
309
-     * @throws InvalidArgumentException
310
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
311
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
312
-     */
313
-    private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
314
-    {
315
-        // array of params to pass to parent constructor
316
-        $form_args = array(
317
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
318
-            'html_class'      => $this->checkout->admin_request
319
-                ? 'form-table ee-reg-form-qstn-grp-dv'
320
-                : 'ee-reg-form-qstn-grp-dv',
321
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() .  '-' . $registration->ID() . '-lbl',
322
-            'subsections'     => array(
323
-                'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
324
-            ),
325
-            'layout_strategy' => $this->checkout->admin_request
326
-                ? new EE_Admin_Two_Column_Layout()
327
-                : new EE_Div_Per_Section_Layout(),
328
-        );
329
-        // where params
330
-        $query_params = array('QST_deleted' => 0);
331
-        // don't load admin only questions on the frontend
332
-        if (! $this->checkout->admin_request) {
333
-            $query_params['QST_admin_only'] = array('!=', true);
334
-        }
335
-        $questions = $question_group->get_many_related(
336
-            'Question',
337
-            apply_filters(
338
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
339
-                array(
340
-                    $query_params,
341
-                    'order_by' => array(
342
-                        'Question_Group_Question.QGQ_order' => 'ASC',
343
-                    ),
344
-                ),
345
-                $question_group,
346
-                $registration,
347
-                $this
348
-            )
349
-        );
350
-        // filter for additional content before questions
351
-        $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
352
-            apply_filters(
353
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
354
-                '',
355
-                $registration,
356
-                $question_group,
357
-                $this
358
-            )
359
-        );
360
-        // loop thru questions
361
-        foreach ($questions as $question) {
362
-            if ($question instanceof EE_Question) {
363
-                $identifier                            = $question->is_system_question()
364
-                    ? $question->system_ID()
365
-                    : $question->ID();
366
-                $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question);
367
-            }
368
-        }
369
-        $form_args['subsections'] = apply_filters(
370
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
371
-            $form_args['subsections'],
372
-            $registration,
373
-            $question_group,
374
-            $this
375
-        );
376
-        // filter for additional content after questions
377
-        $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
378
-            apply_filters(
379
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
380
-                '',
381
-                $registration,
382
-                $question_group,
383
-                $this
384
-            )
385
-        );
20
+	/**
21
+	 * @type bool $_print_copy_info
22
+	 */
23
+	private $_print_copy_info = false;
24
+
25
+	/**
26
+	 * @type array $_attendee_data
27
+	 */
28
+	private $_attendee_data = array();
29
+
30
+	/**
31
+	 * @type array $_required_questions
32
+	 */
33
+	private $_required_questions = array();
34
+
35
+	/**
36
+	 * @type array $_registration_answers
37
+	 */
38
+	private $_registration_answers = array();
39
+
40
+
41
+	/**
42
+	 *    class constructor
43
+	 *
44
+	 * @access    public
45
+	 * @param    EE_Checkout $checkout
46
+	 */
47
+	public function __construct(EE_Checkout $checkout)
48
+	{
49
+		$this->_slug     = 'attendee_information';
50
+		$this->_name     = esc_html__('Attendee Information', 'event_espresso');
51
+		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php';
52
+		$this->checkout  = $checkout;
53
+		$this->_reset_success_message();
54
+		$this->set_instructions(
55
+			esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
56
+		);
57
+	}
58
+
59
+
60
+	public function translate_js_strings()
61
+	{
62
+		EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
63
+			' is a required question.',
64
+			'event_espresso'
65
+		);
66
+		EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
67
+			' is a required question. Please enter a value for at least one of the options.',
68
+			'event_espresso'
69
+		);
70
+		EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
71
+			'Please answer all required questions correctly before proceeding.',
72
+			'event_espresso'
73
+		);
74
+		EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
75
+			esc_html__(
76
+				'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
77
+				'event_espresso'
78
+			),
79
+			'<br/>'
80
+		);
81
+		EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
82
+			'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
83
+			'event_espresso'
84
+		);
85
+		EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
86
+			'You must enter a valid email address.',
87
+			'event_espresso'
88
+		);
89
+		EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
90
+			'You must enter a valid email address and answer all other required questions before you can proceed.',
91
+			'event_espresso'
92
+		);
93
+	}
94
+
95
+
96
+	public function enqueue_styles_and_scripts()
97
+	{
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return boolean
103
+	 */
104
+	public function initialize_reg_step()
105
+	{
106
+		return true;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return EE_Form_Section_Proper
112
+	 * @throws EE_Error
113
+	 * @throws InvalidArgumentException
114
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
115
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
116
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
117
+	 */
118
+	public function generate_reg_form()
119
+	{
120
+		$this->_print_copy_info = false;
121
+		$primary_registrant     = null;
122
+		// autoload Line_Item_Display classes
123
+		EEH_Autoloader::register_line_item_display_autoloaders();
124
+		$Line_Item_Display = new EE_Line_Item_Display();
125
+		// calculate taxes
126
+		$Line_Item_Display->display_line_item(
127
+			$this->checkout->cart->get_grand_total(),
128
+			array('set_tax_rate' => true)
129
+		);
130
+		/** @var $subsections EE_Form_Section_Proper[] */
131
+		$subsections   = array(
132
+			'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
133
+		);
134
+		$template_args = array(
135
+			'revisit'       => $this->checkout->revisit,
136
+			'registrations' => array(),
137
+			'ticket_count'  => array(),
138
+		);
139
+		// grab the saved registrations from the transaction
140
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
141
+		if ($registrations) {
142
+			foreach ($registrations as $registration) {
143
+				// can this registration be processed during this visit ?
144
+				if ($registration instanceof EE_Registration
145
+					&& $this->checkout->visit_allows_processing_of_this_registration($registration)
146
+				) {
147
+					$subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
148
+					if (! $this->checkout->admin_request) {
149
+						$template_args['registrations'][$registration->reg_url_link()]    = $registration;
150
+						$template_args['ticket_count'][$registration->ticket()->ID()]     = isset(
151
+							$template_args['ticket_count'][$registration->ticket()->ID()]
152
+						)
153
+							? $template_args['ticket_count'][$registration->ticket()->ID()] + 1
154
+							: 1;
155
+						$ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
156
+							$this->checkout->cart->get_grand_total(),
157
+							'Ticket',
158
+							array($registration->ticket()->ID())
159
+						);
160
+						$ticket_line_item = is_array($ticket_line_item)
161
+							? reset($ticket_line_item)
162
+							: $ticket_line_item;
163
+						$template_args['ticket_line_item'][$registration->ticket()->ID()] =
164
+							$Line_Item_Display->display_line_item($ticket_line_item);
165
+					}
166
+					if ($registration->is_primary_registrant()) {
167
+						$primary_registrant = $registration->reg_url_link();
168
+					}
169
+				}
170
+			}
171
+			// print_copy_info ?
172
+			if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) {
173
+				// TODO: add admin option for toggling copy attendee info,
174
+				// then use that value to change $this->_print_copy_info
175
+				$copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
176
+					? $this->_copy_attendee_info_form()
177
+					: $this->_auto_copy_attendee_info();
178
+				// generate hidden input
179
+				if (isset($subsections[$primary_registrant])
180
+					&& $subsections[$primary_registrant] instanceof EE_Form_Section_Proper
181
+				) {
182
+					$subsections[$primary_registrant]->add_subsections(
183
+						$copy_options,
184
+						'primary_registrant',
185
+						false
186
+					);
187
+				}
188
+			}
189
+		}
190
+
191
+		return new EE_Form_Section_Proper(
192
+			array(
193
+				'name'            => $this->reg_form_name(),
194
+				'html_id'         => $this->reg_form_name(),
195
+				'subsections'     => $subsections,
196
+				'layout_strategy' => $this->checkout->admin_request ?
197
+					new EE_Div_Per_Section_Layout() :
198
+					new EE_Template_Layout(
199
+						array(
200
+							'layout_template_file' => $this->_template, // layout_template
201
+							'template_args'        => $template_args,
202
+						)
203
+					),
204
+			)
205
+		);
206
+	}
207
+
208
+
209
+	/**
210
+	 * @param EE_Registration $registration
211
+	 * @return EE_Form_Section_Base
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
215
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
216
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
217
+	 */
218
+	private function _registrations_reg_form(EE_Registration $registration)
219
+	{
220
+		static $attendee_nmbr = 1;
221
+		$form_args = array();
222
+		// verify that registration has valid event
223
+		if ($registration->event() instanceof EE_Event) {
224
+			$question_groups = $registration->event()->question_groups(
225
+				apply_filters(
226
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
227
+					array(
228
+						array(
229
+							'Event.EVT_ID'                     => $registration->event()->ID(),
230
+							'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
231
+						),
232
+						'order_by' => array('QSG_order' => 'ASC'),
233
+					),
234
+					$registration,
235
+					$this
236
+				)
237
+			);
238
+			if ($question_groups) {
239
+				// array of params to pass to parent constructor
240
+				$form_args = array(
241
+					'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
242
+					'html_class'      => 'ee-reg-form-attendee-dv',
243
+					'html_style'      => $this->checkout->admin_request
244
+						? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
245
+						: '',
246
+					'subsections'     => array(),
247
+					'layout_strategy' => new EE_Fieldset_Section_Layout(
248
+						array(
249
+							'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
250
+							'legend_text'  => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr),
251
+						)
252
+					),
253
+				);
254
+				foreach ($question_groups as $question_group) {
255
+					if ($question_group instanceof EE_Question_Group) {
256
+						$form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form(
257
+							$registration,
258
+							$question_group
259
+						);
260
+					}
261
+				}
262
+				// add hidden input
263
+				$form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
264
+					$registration
265
+				);
266
+				// if we have question groups for additional attendees, then display the copy options
267
+				$this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info;
268
+				if ($registration->is_primary_registrant()) {
269
+					// generate hidden input
270
+					$form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
271
+						$registration
272
+					);
273
+				}
274
+			}
275
+		}
276
+		$attendee_nmbr++;
277
+		return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML();
278
+	}
279
+
280
+
281
+	/**
282
+	 * _additional_attendee_reg_info_input
283
+	 *
284
+	 * @access public
285
+	 * @param EE_Registration $registration
286
+	 * @param bool            $additional_attendee_reg_info
287
+	 * @return    EE_Form_Input_Base
288
+	 * @throws \EE_Error
289
+	 */
290
+	private function _additional_attendee_reg_info_input(
291
+		EE_Registration $registration,
292
+		$additional_attendee_reg_info = true
293
+	) {
294
+		// generate hidden input
295
+		return new EE_Hidden_Input(
296
+			array(
297
+				'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
298
+				'default' => $additional_attendee_reg_info,
299
+			)
300
+		);
301
+	}
302
+
303
+
304
+	/**
305
+	 * @param EE_Registration   $registration
306
+	 * @param EE_Question_Group $question_group
307
+	 * @return EE_Form_Section_Proper
308
+	 * @throws EE_Error
309
+	 * @throws InvalidArgumentException
310
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
311
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
312
+	 */
313
+	private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
314
+	{
315
+		// array of params to pass to parent constructor
316
+		$form_args = array(
317
+			'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
318
+			'html_class'      => $this->checkout->admin_request
319
+				? 'form-table ee-reg-form-qstn-grp-dv'
320
+				: 'ee-reg-form-qstn-grp-dv',
321
+			'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() .  '-' . $registration->ID() . '-lbl',
322
+			'subsections'     => array(
323
+				'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
324
+			),
325
+			'layout_strategy' => $this->checkout->admin_request
326
+				? new EE_Admin_Two_Column_Layout()
327
+				: new EE_Div_Per_Section_Layout(),
328
+		);
329
+		// where params
330
+		$query_params = array('QST_deleted' => 0);
331
+		// don't load admin only questions on the frontend
332
+		if (! $this->checkout->admin_request) {
333
+			$query_params['QST_admin_only'] = array('!=', true);
334
+		}
335
+		$questions = $question_group->get_many_related(
336
+			'Question',
337
+			apply_filters(
338
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
339
+				array(
340
+					$query_params,
341
+					'order_by' => array(
342
+						'Question_Group_Question.QGQ_order' => 'ASC',
343
+					),
344
+				),
345
+				$question_group,
346
+				$registration,
347
+				$this
348
+			)
349
+		);
350
+		// filter for additional content before questions
351
+		$form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
352
+			apply_filters(
353
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
354
+				'',
355
+				$registration,
356
+				$question_group,
357
+				$this
358
+			)
359
+		);
360
+		// loop thru questions
361
+		foreach ($questions as $question) {
362
+			if ($question instanceof EE_Question) {
363
+				$identifier                            = $question->is_system_question()
364
+					? $question->system_ID()
365
+					: $question->ID();
366
+				$form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question);
367
+			}
368
+		}
369
+		$form_args['subsections'] = apply_filters(
370
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
371
+			$form_args['subsections'],
372
+			$registration,
373
+			$question_group,
374
+			$this
375
+		);
376
+		// filter for additional content after questions
377
+		$form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
378
+			apply_filters(
379
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
380
+				'',
381
+				$registration,
382
+				$question_group,
383
+				$this
384
+			)
385
+		);
386 386
 //		d( $form_args );
387
-        $question_group_reg_form = new EE_Form_Section_Proper($form_args);
388
-        return apply_filters(
389
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
390
-            $question_group_reg_form,
391
-            $registration,
392
-            $question_group,
393
-            $this
394
-        );
395
-    }
396
-
397
-
398
-    /**
399
-     * @access public
400
-     * @param EE_Question_Group $question_group
401
-     * @return    EE_Form_Section_HTML
402
-     */
403
-    private function _question_group_header(EE_Question_Group $question_group)
404
-    {
405
-        $html = '';
406
-        // group_name
407
-        if ($question_group->show_group_name() && $question_group->name() !== '') {
408
-            if ($this->checkout->admin_request) {
409
-                $html .= EEH_HTML::br();
410
-                $html .= EEH_HTML::h3(
411
-                    $question_group->name(),
412
-                    '',
413
-                    'ee-reg-form-qstn-grp-title title',
414
-                    'font-size: 1.3em; padding-left:0;'
415
-                );
416
-            } else {
417
-                $html .= EEH_HTML::h4(
418
-                    $question_group->name(),
419
-                    '',
420
-                    'ee-reg-form-qstn-grp-title section-title'
421
-                );
422
-            }
423
-        }
424
-        // group_desc
425
-        if ($question_group->show_group_desc() && $question_group->desc() !== '') {
426
-            $html .= EEH_HTML::p(
427
-                $question_group->desc(),
428
-                '',
429
-                $this->checkout->admin_request
430
-                    ? 'ee-reg-form-qstn-grp-desc-pg'
431
-                    : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
432
-            );
433
-        }
434
-        return new EE_Form_Section_HTML($html);
435
-    }
436
-
437
-
438
-    /**
439
-     * @access public
440
-     * @return    EE_Form_Section_Proper
441
-     * @throws \EE_Error
442
-     */
443
-    private function _copy_attendee_info_form()
444
-    {
445
-        // array of params to pass to parent constructor
446
-        return new EE_Form_Section_Proper(
447
-            array(
448
-                'subsections'     => $this->_copy_attendee_info_inputs(),
449
-                'layout_strategy' => new EE_Template_Layout(
450
-                    array(
451
-                        'layout_template_file'     => SPCO_REG_STEPS_PATH
452
-                                                      . $this->_slug
453
-                                                      . DS
454
-                                                      . 'copy_attendee_info.template.php',
455
-                        'begin_template_file'      => null,
456
-                        'input_template_file'      => null,
457
-                        'subsection_template_file' => null,
458
-                        'end_template_file'        => null,
459
-                    )
460
-                ),
461
-            )
462
-        );
463
-    }
464
-
465
-
466
-    /**
467
-     * _auto_copy_attendee_info
468
-     *
469
-     * @access public
470
-     * @return EE_Form_Section_HTML
471
-     */
472
-    private function _auto_copy_attendee_info()
473
-    {
474
-        return new EE_Form_Section_HTML(
475
-            EEH_Template::locate_template(
476
-                SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php',
477
-                apply_filters(
478
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
479
-                    array()
480
-                ),
481
-                true,
482
-                true
483
-            )
484
-        );
485
-    }
486
-
487
-
488
-    /**
489
-     * _copy_attendee_info_inputs
490
-     *
491
-     * @access public
492
-     * @return array
493
-     * @throws \EE_Error
494
-     */
495
-    private function _copy_attendee_info_inputs()
496
-    {
497
-        $copy_attendee_info_inputs = array();
498
-        $prev_ticket               = null;
499
-        // grab the saved registrations from the transaction
500
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
501
-        foreach ($registrations as $registration) {
502
-            // for all  attendees other than the primary attendee
503
-            if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
504
-                // if this is a new ticket OR if this is the very first additional attendee after the primary attendee
505
-                if ($registration->ticket()->ID() !== $prev_ticket) {
506
-                    $item_name = $registration->ticket()->name();
507
-                    $item_name .= $registration->ticket()->description() !== ''
508
-                        ? ' - ' . $registration->ticket()->description()
509
-                        : '';
510
-                    $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] =
511
-                        new EE_Form_Section_HTML(
512
-                            '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
513
-                        );
514
-                    $prev_ticket = $registration->ticket()->ID();
515
-                }
516
-
517
-                $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] =
518
-                    new EE_Checkbox_Multi_Input(
519
-                        array(
520
-                            $registration->ID() => sprintf(
521
-                                esc_html__('Attendee #%s', 'event_espresso'),
522
-                                $registration->count()
523
-                            ),
524
-                        ),
525
-                        array(
526
-                            'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
527
-                            'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
528
-                            'display_html_label_text' => false,
529
-                        )
530
-                    );
531
-            }
532
-        }
533
-        return $copy_attendee_info_inputs;
534
-    }
535
-
536
-
537
-    /**
538
-     * _additional_primary_registrant_inputs
539
-     *
540
-     * @access public
541
-     * @param EE_Registration $registration
542
-     * @return    EE_Form_Input_Base
543
-     * @throws \EE_Error
544
-     */
545
-    private function _additional_primary_registrant_inputs(EE_Registration $registration)
546
-    {
547
-        // generate hidden input
548
-        return new EE_Hidden_Input(
549
-            array(
550
-                'html_id' => 'primary_registrant',
551
-                'default' => $registration->reg_url_link(),
552
-            )
553
-        );
554
-    }
555
-
556
-
557
-    /**
558
-     * @access public
559
-     * @param EE_Registration $registration
560
-     * @param EE_Question     $question
561
-     * @return EE_Form_Input_Base
562
-     * @throws EE_Error
563
-     * @throws InvalidArgumentException
564
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
565
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
566
-     */
567
-    public function reg_form_question(EE_Registration $registration, EE_Question $question)
568
-    {
569
-
570
-        // if this question was for an attendee detail, then check for that answer
571
-        $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
572
-            $registration,
573
-            $question->system_ID()
574
-        );
575
-        $answer       = $answer_value === null
576
-            ? EEM_Answer::instance()->get_one(
577
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
578
-            )
579
-            : null;
580
-        // if NOT returning to edit an existing registration
581
-        // OR if this question is for an attendee property
582
-        // OR we still don't have an EE_Answer object
583
-        if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
584
-            // create an EE_Answer object for storing everything in
585
-            $answer = EE_Answer::new_instance(array(
586
-                'QST_ID' => $question->ID(),
587
-                'REG_ID' => $registration->ID(),
588
-            ));
589
-        }
590
-        // verify instance
591
-        if ($answer instanceof EE_Answer) {
592
-            if (! empty($answer_value)) {
593
-                $answer->set('ANS_value', $answer_value);
594
-            }
595
-            $answer->cache('Question', $question);
596
-            //remember system ID had a bug where sometimes it could be null
597
-            $answer_cache_id = $question->is_system_question()
598
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
599
-                : $question->ID() . '-' . $registration->reg_url_link();
600
-            $registration->cache('Answer', $answer, $answer_cache_id);
601
-        }
602
-        return $this->_generate_question_input($registration, $question, $answer);
603
-    }
604
-
605
-
606
-    /**
607
-     * @param EE_Registration $registration
608
-     * @param EE_Question     $question
609
-     * @param                 mixed EE_Answer|NULL      $answer
610
-     * @return EE_Form_Input_Base
611
-     * @throws \EE_Error
612
-     */
613
-    private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
614
-    {
615
-        $identifier                             = $question->is_system_question()
616
-            ? $question->system_ID()
617
-            : $question->ID();
618
-        $this->_required_questions[$identifier] = $question->required() ? true : false;
619
-        add_filter(
620
-            'FHEE__EE_Question__generate_form_input__country_options',
621
-            array($this, 'use_cached_countries_for_form_input'),
622
-            10,
623
-            4
624
-        );
625
-        add_filter(
626
-            'FHEE__EE_Question__generate_form_input__state_options',
627
-            array($this, 'use_cached_states_for_form_input'),
628
-            10,
629
-            4
630
-        );
631
-        $input_constructor_args                  = array(
632
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
633
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
634
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
635
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
636
-            'html_label_class' => 'ee-reg-qstn',
637
-        );
638
-        $input_constructor_args['html_label_id'] .= '-lbl';
639
-        if ($answer instanceof EE_Answer && $answer->ID()) {
640
-            $input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
641
-            $input_constructor_args['html_id']       .= '-' . $answer->ID();
642
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
643
-        }
644
-        $form_input = $question->generate_form_input(
645
-            $registration,
646
-            $answer,
647
-            $input_constructor_args
648
-        );
649
-        remove_filter(
650
-            'FHEE__EE_Question__generate_form_input__country_options',
651
-            array($this, 'use_cached_countries_for_form_input')
652
-        );
653
-        remove_filter(
654
-            'FHEE__EE_Question__generate_form_input__state_options',
655
-            array($this, 'use_cached_states_for_form_input')
656
-        );
657
-        return $form_input;
658
-    }
659
-
660
-
661
-    /**
662
-     * Gets the list of countries for the form input
663
-     *
664
-     * @param array|null       $countries_list
665
-     * @param \EE_Question     $question
666
-     * @param \EE_Registration $registration
667
-     * @param \EE_Answer       $answer
668
-     * @return array 2d keys are country IDs, values are their names
669
-     * @throws EE_Error
670
-     * @throws InvalidArgumentException
671
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
672
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
673
-     */
674
-    public function use_cached_countries_for_form_input(
675
-        $countries_list,
676
-        \EE_Question $question = null,
677
-        \EE_Registration $registration = null,
678
-        \EE_Answer $answer = null
679
-    ) {
680
-        $country_options = array('' => '');
681
-        // get possibly cached list of countries
682
-        $countries = $this->checkout->action === 'process_reg_step'
683
-            ? EEM_Country::instance()->get_all_countries()
684
-            : EEM_Country::instance()->get_all_active_countries();
685
-        if (! empty($countries)) {
686
-            foreach ($countries as $country) {
687
-                if ($country instanceof EE_Country) {
688
-                    $country_options[$country->ID()] = $country->name();
689
-                }
690
-            }
691
-        }
692
-        if ($question instanceof EE_Question
693
-            && $registration instanceof EE_Registration) {
694
-            $answer = EEM_Answer::instance()->get_one(
695
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
696
-            );
697
-        } else {
698
-            $answer = EE_Answer::new_instance();
699
-        }
700
-        $country_options = apply_filters(
701
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
702
-            $country_options,
703
-            $this,
704
-            $registration,
705
-            $question,
706
-            $answer
707
-        );
708
-        return $country_options;
709
-    }
710
-
711
-
712
-    /**
713
-     * Gets the list of states for the form input
714
-     *
715
-     * @param array|null       $states_list
716
-     * @param \EE_Question     $question
717
-     * @param \EE_Registration $registration
718
-     * @param \EE_Answer       $answer
719
-     * @return array 2d keys are state IDs, values are their names
720
-     * @throws EE_Error
721
-     * @throws InvalidArgumentException
722
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
723
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
724
-     */
725
-    public function use_cached_states_for_form_input(
726
-        $states_list,
727
-        \EE_Question $question = null,
728
-        \EE_Registration $registration = null,
729
-        \EE_Answer $answer = null
730
-    ) {
731
-        $state_options = array('' => array('' => ''));
732
-        $states        = $this->checkout->action === 'process_reg_step'
733
-            ? EEM_State::instance()->get_all_states()
734
-            : EEM_State::instance()->get_all_active_states();
735
-        if (! empty($states)) {
736
-            foreach ($states as $state) {
737
-                if ($state instanceof EE_State) {
738
-                    $state_options[$state->country()->name()][$state->ID()] = $state->name();
739
-                }
740
-            }
741
-        }
742
-        $state_options = apply_filters(
743
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
744
-            $state_options,
745
-            $this,
746
-            $registration,
747
-            $question,
748
-            $answer
749
-        );
750
-        return $state_options;
751
-    }
752
-
753
-
754
-
755
-
756
-
757
-
758
-    /********************************************************************************************************/
759
-    /****************************************  PROCESS REG STEP  ****************************************/
760
-    /********************************************************************************************************/
761
-    /**
762
-     * @return bool
763
-     * @throws EE_Error
764
-     * @throws InvalidArgumentException
765
-     * @throws ReflectionException
766
-     * @throws RuntimeException
767
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
768
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
769
-     */
770
-    public function process_reg_step()
771
-    {
772
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
773
-        // grab validated data from form
774
-        $valid_data = $this->checkout->current_step->valid_data();
775
-        // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
776
-        // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
777
-        // if we don't have any $valid_data then something went TERRIBLY WRONG !!!
778
-        if (empty($valid_data)) {
779
-            EE_Error::add_error(
780
-                esc_html__('No valid question responses were received.', 'event_espresso'),
781
-                __FILE__,
782
-                __FUNCTION__,
783
-                __LINE__
784
-            );
785
-            return false;
786
-        }
787
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
788
-            EE_Error::add_error(
789
-                esc_html__(
790
-                    'A valid transaction could not be initiated for processing your registrations.',
791
-                    'event_espresso'
792
-                ),
793
-                __FILE__,
794
-                __FUNCTION__,
795
-                __LINE__
796
-            );
797
-            return false;
798
-        }
799
-        // get cached registrations
800
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
801
-        // verify we got the goods
802
-        if (empty($registrations)) {
803
-            //combine the old translated string with a new one, in order to not break translations
804
-            $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' )
805
-                             . sprintf(
806
-                                 esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'),
807
-                                 '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
808
-                                 '</a>',
809
-                                 '<br />'
810
-                             );
811
-            EE_Error::add_error(
812
-                $error_message,
813
-                __FILE__,
814
-                __FUNCTION__,
815
-                __LINE__
816
-            );
817
-            return false;
818
-        }
819
-        // extract attendee info from form data and save to model objects
820
-        $registrations_processed = $this->_process_registrations($registrations, $valid_data);
821
-        // if first pass thru SPCO,
822
-        // then let's check processed registrations against the total number of tickets in the cart
823
-        if ($registrations_processed === false) {
824
-            // but return immediately if the previous step exited early due to errors
825
-            return false;
826
-        } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
827
-            // generate a correctly translated string for all possible singular/plural combinations
828
-            if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
829
-                $error_msg = sprintf(
830
-                    esc_html__(
831
-                        'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
832
-                        'event_espresso'
833
-                    ),
834
-                    $this->checkout->total_ticket_count,
835
-                    $registrations_processed
836
-                );
837
-            } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
838
-                $error_msg = sprintf(
839
-                    esc_html__(
840
-                        'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
841
-                        'event_espresso'
842
-                    ),
843
-                    $this->checkout->total_ticket_count,
844
-                    $registrations_processed
845
-                );
846
-            } else {
847
-                $error_msg = sprintf(
848
-                    esc_html__(
849
-                        'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed',
850
-                        'event_espresso'
851
-                    ),
852
-                    $this->checkout->total_ticket_count,
853
-                    $registrations_processed
854
-                );
855
-            }
856
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
857
-            return false;
858
-        }
859
-        // mark this reg step as completed
860
-        $this->set_completed();
861
-        $this->_set_success_message(
862
-            esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
863
-        );
864
-        //do action in case a plugin wants to do something with the data submitted in step 1.
865
-        //passes EE_Single_Page_Checkout, and it's posted data
866
-        do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
867
-        return true;
868
-    }
869
-
870
-
871
-    /**
872
-     *    _process_registrations
873
-     *
874
-     * @param EE_Registration[] $registrations
875
-     * @param array             $valid_data
876
-     * @return bool|int
877
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
878
-     * @throws EE_Error
879
-     * @throws InvalidArgumentException
880
-     * @throws ReflectionException
881
-     * @throws RuntimeException
882
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
883
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
884
-     */
885
-    private function _process_registrations($registrations = array(), $valid_data = array())
886
-    {
887
-        // load resources and set some defaults
888
-        EE_Registry::instance()->load_model('Attendee');
889
-        // holder for primary registrant attendee object
890
-        $this->checkout->primary_attendee_obj = null;
891
-        // array for tracking reg form data for the primary registrant
892
-        $primary_registrant = array(
893
-            'line_item_id' => null,
894
-        );
895
-        $copy_primary       = false;
896
-        // reg form sections that do not contain inputs
897
-        $non_input_form_sections = array(
898
-            'primary_registrant',
899
-            'additional_attendee_reg_info',
900
-            'spco_copy_attendee_chk',
901
-        );
902
-        // attendee counter
903
-        $att_nmbr = 0;
904
-        // grab the saved registrations from the transaction
905
-        foreach ($registrations as $registration) {
906
-            // verify EE_Registration object
907
-            if (! $registration instanceof EE_Registration) {
908
-                EE_Error::add_error(
909
-                    esc_html__(
910
-                        'An invalid Registration object was discovered when attempting to process your registration information.',
911
-                        'event_espresso'
912
-                    ),
913
-                    __FILE__,
914
-                    __FUNCTION__,
915
-                    __LINE__
916
-                );
917
-                return false;
918
-            }
919
-            /** @var string $reg_url_link */
920
-            $reg_url_link = $registration->reg_url_link();
921
-            // reg_url_link exists ?
922
-            if (! empty($reg_url_link)) {
923
-                // should this registration be processed during this visit ?
924
-                if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
925
-                    // if NOT revisiting, then let's save the registration now,
926
-                    // so that we have a REG_ID to use when generating other objects
927
-                    if (! $this->checkout->revisit) {
928
-                        $registration->save();
929
-                    }
930
-                    /**
931
-                     * This allows plugins to trigger a fail on processing of a
932
-                     * registration for any conditions they may have for it to pass.
933
-                     *
934
-                     * @var bool   if true is returned by the plugin then the
935
-                     *            registration processing is halted.
936
-                     */
937
-                    if (apply_filters(
938
-                        'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
939
-                        false,
940
-                        $att_nmbr,
941
-                        $registration,
942
-                        $registrations,
943
-                        $valid_data,
944
-                        $this
945
-                    )) {
946
-                        return false;
947
-                    }
948
-
949
-                    // Houston, we have a registration!
950
-                    $att_nmbr++;
951
-                    $this->_attendee_data[$reg_url_link] = array();
952
-                    // grab any existing related answer objects
953
-                    $this->_registration_answers = $registration->answers();
954
-                    // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
955
-                    if (isset($valid_data[$reg_url_link])) {
956
-                        // do we need to copy basic info from primary attendee ?
957
-                        $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info'])
958
-                                        && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0
959
-                            ? true
960
-                            : false;
961
-                        // filter form input data for this registration
962
-                        $valid_data[$reg_url_link] = (array)apply_filters(
963
-                            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
964
-                            $valid_data[$reg_url_link]
965
-                        );
966
-                        if (isset($valid_data['primary_attendee'])) {
967
-                            $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
968
-                                ? $valid_data['primary_attendee']
969
-                                : false;
970
-                            unset($valid_data['primary_attendee']);
971
-                        }
972
-                        // now loop through our array of valid post data && process attendee reg forms
973
-                        foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) {
974
-                            if (! in_array($form_section, $non_input_form_sections)) {
975
-                                foreach ($form_inputs as $form_input => $input_value) {
976
-                                    // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
977
-                                    // check for critical inputs
978
-                                    if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
979
-                                        $form_input,
980
-                                        $input_value
981
-                                    )
982
-                                    ) {
983
-                                        return false;
984
-                                    }
985
-                                    // store a bit of data about the primary attendee
986
-                                    if ($att_nmbr === 1
987
-                                        && ! empty($input_value)
988
-                                        && $reg_url_link === $primary_registrant['line_item_id']
989
-                                    ) {
990
-                                        $primary_registrant[$form_input] = $input_value;
991
-                                    } elseif ($copy_primary
992
-                                        && $input_value === null
993
-                                        && isset($primary_registrant[$form_input])
994
-                                    ) {
995
-                                        $input_value = $primary_registrant[$form_input];
996
-                                    }
997
-                                    // now attempt to save the input data
998
-                                    if (! $this->_save_registration_form_input(
999
-                                        $registration,
1000
-                                        $form_input,
1001
-                                        $input_value
1002
-                                    )
1003
-                                    ) {
1004
-                                        EE_Error::add_error(
1005
-                                            sprintf(
1006
-                                                esc_html__(
1007
-                                                    'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1008
-                                                    'event_espresso'
1009
-                                                ),
1010
-                                                $form_input,
1011
-                                                $input_value
1012
-                                            ),
1013
-                                            __FILE__,
1014
-                                            __FUNCTION__,
1015
-                                            __LINE__
1016
-                                        );
1017
-                                        return false;
1018
-                                    }
1019
-                                }
1020
-                            }
1021
-                        }  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1022
-                    }
1023
-                    //EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1024
-                    // this registration does not require additional attendee information ?
1025
-                    if ($copy_primary
1026
-                        && $att_nmbr > 1
1027
-                        && $this->checkout->primary_attendee_obj instanceof EE_Attendee
1028
-                    ) {
1029
-                        // just copy the primary registrant
1030
-                        $attendee = $this->checkout->primary_attendee_obj;
1031
-                    } else {
1032
-                        // ensure critical details are set for additional attendees
1033
-                        $this->_attendee_data[$reg_url_link] = $att_nmbr > 1
1034
-                            ? $this->_copy_critical_attendee_details_from_primary_registrant(
1035
-                                $this->_attendee_data[$reg_url_link]
1036
-                            )
1037
-                            : $this->_attendee_data[$reg_url_link];
1038
-                        // execute create attendee command (which may return an existing attendee)
1039
-                        $attendee = EE_Registry::instance()->BUS->execute(
1040
-                            new CreateAttendeeCommand(
1041
-                                $this->_attendee_data[$reg_url_link],
1042
-                                $registration
1043
-                            )
1044
-                        );
1045
-                        // who's #1 ?
1046
-                        if ($att_nmbr === 1) {
1047
-                            $this->checkout->primary_attendee_obj = $attendee;
1048
-                        }
1049
-                    }
1050
-                    // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1051
-                    // add relation to registration, set attendee ID, and cache attendee
1052
-                    $this->_associate_attendee_with_registration($registration, $attendee);
1053
-                    // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1054
-                    if (! $registration->attendee() instanceof EE_Attendee) {
1055
-                        EE_Error::add_error(
1056
-                            sprintf(
1057
-                                esc_html__(
1058
-                                    'Registration %s has an invalid or missing Attendee object.',
1059
-                                    'event_espresso'
1060
-                                ),
1061
-                                $reg_url_link
1062
-                            ),
1063
-                            __FILE__,
1064
-                            __FUNCTION__,
1065
-                            __LINE__
1066
-                        );
1067
-                        return false;
1068
-                    }
1069
-                    /** @type EE_Registration_Processor $registration_processor */
1070
-                    $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1071
-                    // at this point, we should have enough details about the registrant to consider the registration
1072
-                    // NOT incomplete
1073
-                    $registration_processor->toggle_incomplete_registration_status_to_default(
1074
-                        $registration,
1075
-                        false,
1076
-                        new Context(
1077
-                            'spco_reg_step_attendee_information_process_registrations',
1078
-                            esc_html__(
1079
-                                'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1080
-                                'event_espresso'
1081
-                            )
1082
-                        )
1083
-                    );
1084
-                    // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1085
-                    // abandoned
1086
-                    $this->checkout->transaction->toggle_failed_transaction_status();
1087
-                    // if we've gotten this far, then let's save what we have
1088
-                    $registration->save();
1089
-                    // add relation between TXN and registration
1090
-                    $this->_associate_registration_with_transaction($registration);
1091
-                }
1092
-            } else {
1093
-                EE_Error::add_error(
1094
-                    esc_html__(
1095
-                        'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1096
-                        'event_espresso'
1097
-                    ),
1098
-                    __FILE__,
1099
-                    __FUNCTION__,
1100
-                    __LINE__
1101
-                );
1102
-                // remove malformed data
1103
-                unset($valid_data[$reg_url_link]);
1104
-                return false;
1105
-            }
1106
-
1107
-        } // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1108
-        return $att_nmbr;
1109
-    }
1110
-
1111
-
1112
-    /**
1113
-     *    _save_registration_form_input
1114
-     *
1115
-     * @param EE_Registration $registration
1116
-     * @param string          $form_input
1117
-     * @param string          $input_value
1118
-     * @return bool
1119
-     * @throws EE_Error
1120
-     * @throws InvalidArgumentException
1121
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1122
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1123
-     */
1124
-    private function _save_registration_form_input(
1125
-        EE_Registration $registration,
1126
-        $form_input = '',
1127
-        $input_value = ''
1128
-    ) {
1129
-        // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1130
-        // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1131
-        // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1132
-        // allow for plugins to hook in and do their own processing of the form input.
1133
-        // For plugins to bypass normal processing here, they just need to return a boolean value.
1134
-        if (apply_filters(
1135
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1136
-            false,
1137
-            $registration,
1138
-            $form_input,
1139
-            $input_value,
1140
-            $this
1141
-        )) {
1142
-            return true;
1143
-        }
1144
-        /*
387
+		$question_group_reg_form = new EE_Form_Section_Proper($form_args);
388
+		return apply_filters(
389
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
390
+			$question_group_reg_form,
391
+			$registration,
392
+			$question_group,
393
+			$this
394
+		);
395
+	}
396
+
397
+
398
+	/**
399
+	 * @access public
400
+	 * @param EE_Question_Group $question_group
401
+	 * @return    EE_Form_Section_HTML
402
+	 */
403
+	private function _question_group_header(EE_Question_Group $question_group)
404
+	{
405
+		$html = '';
406
+		// group_name
407
+		if ($question_group->show_group_name() && $question_group->name() !== '') {
408
+			if ($this->checkout->admin_request) {
409
+				$html .= EEH_HTML::br();
410
+				$html .= EEH_HTML::h3(
411
+					$question_group->name(),
412
+					'',
413
+					'ee-reg-form-qstn-grp-title title',
414
+					'font-size: 1.3em; padding-left:0;'
415
+				);
416
+			} else {
417
+				$html .= EEH_HTML::h4(
418
+					$question_group->name(),
419
+					'',
420
+					'ee-reg-form-qstn-grp-title section-title'
421
+				);
422
+			}
423
+		}
424
+		// group_desc
425
+		if ($question_group->show_group_desc() && $question_group->desc() !== '') {
426
+			$html .= EEH_HTML::p(
427
+				$question_group->desc(),
428
+				'',
429
+				$this->checkout->admin_request
430
+					? 'ee-reg-form-qstn-grp-desc-pg'
431
+					: 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
432
+			);
433
+		}
434
+		return new EE_Form_Section_HTML($html);
435
+	}
436
+
437
+
438
+	/**
439
+	 * @access public
440
+	 * @return    EE_Form_Section_Proper
441
+	 * @throws \EE_Error
442
+	 */
443
+	private function _copy_attendee_info_form()
444
+	{
445
+		// array of params to pass to parent constructor
446
+		return new EE_Form_Section_Proper(
447
+			array(
448
+				'subsections'     => $this->_copy_attendee_info_inputs(),
449
+				'layout_strategy' => new EE_Template_Layout(
450
+					array(
451
+						'layout_template_file'     => SPCO_REG_STEPS_PATH
452
+													  . $this->_slug
453
+													  . DS
454
+													  . 'copy_attendee_info.template.php',
455
+						'begin_template_file'      => null,
456
+						'input_template_file'      => null,
457
+						'subsection_template_file' => null,
458
+						'end_template_file'        => null,
459
+					)
460
+				),
461
+			)
462
+		);
463
+	}
464
+
465
+
466
+	/**
467
+	 * _auto_copy_attendee_info
468
+	 *
469
+	 * @access public
470
+	 * @return EE_Form_Section_HTML
471
+	 */
472
+	private function _auto_copy_attendee_info()
473
+	{
474
+		return new EE_Form_Section_HTML(
475
+			EEH_Template::locate_template(
476
+				SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php',
477
+				apply_filters(
478
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
479
+					array()
480
+				),
481
+				true,
482
+				true
483
+			)
484
+		);
485
+	}
486
+
487
+
488
+	/**
489
+	 * _copy_attendee_info_inputs
490
+	 *
491
+	 * @access public
492
+	 * @return array
493
+	 * @throws \EE_Error
494
+	 */
495
+	private function _copy_attendee_info_inputs()
496
+	{
497
+		$copy_attendee_info_inputs = array();
498
+		$prev_ticket               = null;
499
+		// grab the saved registrations from the transaction
500
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
501
+		foreach ($registrations as $registration) {
502
+			// for all  attendees other than the primary attendee
503
+			if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
504
+				// if this is a new ticket OR if this is the very first additional attendee after the primary attendee
505
+				if ($registration->ticket()->ID() !== $prev_ticket) {
506
+					$item_name = $registration->ticket()->name();
507
+					$item_name .= $registration->ticket()->description() !== ''
508
+						? ' - ' . $registration->ticket()->description()
509
+						: '';
510
+					$copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] =
511
+						new EE_Form_Section_HTML(
512
+							'<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
513
+						);
514
+					$prev_ticket = $registration->ticket()->ID();
515
+				}
516
+
517
+				$copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] =
518
+					new EE_Checkbox_Multi_Input(
519
+						array(
520
+							$registration->ID() => sprintf(
521
+								esc_html__('Attendee #%s', 'event_espresso'),
522
+								$registration->count()
523
+							),
524
+						),
525
+						array(
526
+							'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
527
+							'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
528
+							'display_html_label_text' => false,
529
+						)
530
+					);
531
+			}
532
+		}
533
+		return $copy_attendee_info_inputs;
534
+	}
535
+
536
+
537
+	/**
538
+	 * _additional_primary_registrant_inputs
539
+	 *
540
+	 * @access public
541
+	 * @param EE_Registration $registration
542
+	 * @return    EE_Form_Input_Base
543
+	 * @throws \EE_Error
544
+	 */
545
+	private function _additional_primary_registrant_inputs(EE_Registration $registration)
546
+	{
547
+		// generate hidden input
548
+		return new EE_Hidden_Input(
549
+			array(
550
+				'html_id' => 'primary_registrant',
551
+				'default' => $registration->reg_url_link(),
552
+			)
553
+		);
554
+	}
555
+
556
+
557
+	/**
558
+	 * @access public
559
+	 * @param EE_Registration $registration
560
+	 * @param EE_Question     $question
561
+	 * @return EE_Form_Input_Base
562
+	 * @throws EE_Error
563
+	 * @throws InvalidArgumentException
564
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
565
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
566
+	 */
567
+	public function reg_form_question(EE_Registration $registration, EE_Question $question)
568
+	{
569
+
570
+		// if this question was for an attendee detail, then check for that answer
571
+		$answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
572
+			$registration,
573
+			$question->system_ID()
574
+		);
575
+		$answer       = $answer_value === null
576
+			? EEM_Answer::instance()->get_one(
577
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
578
+			)
579
+			: null;
580
+		// if NOT returning to edit an existing registration
581
+		// OR if this question is for an attendee property
582
+		// OR we still don't have an EE_Answer object
583
+		if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
584
+			// create an EE_Answer object for storing everything in
585
+			$answer = EE_Answer::new_instance(array(
586
+				'QST_ID' => $question->ID(),
587
+				'REG_ID' => $registration->ID(),
588
+			));
589
+		}
590
+		// verify instance
591
+		if ($answer instanceof EE_Answer) {
592
+			if (! empty($answer_value)) {
593
+				$answer->set('ANS_value', $answer_value);
594
+			}
595
+			$answer->cache('Question', $question);
596
+			//remember system ID had a bug where sometimes it could be null
597
+			$answer_cache_id = $question->is_system_question()
598
+				? $question->system_ID() . '-' . $registration->reg_url_link()
599
+				: $question->ID() . '-' . $registration->reg_url_link();
600
+			$registration->cache('Answer', $answer, $answer_cache_id);
601
+		}
602
+		return $this->_generate_question_input($registration, $question, $answer);
603
+	}
604
+
605
+
606
+	/**
607
+	 * @param EE_Registration $registration
608
+	 * @param EE_Question     $question
609
+	 * @param                 mixed EE_Answer|NULL      $answer
610
+	 * @return EE_Form_Input_Base
611
+	 * @throws \EE_Error
612
+	 */
613
+	private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
614
+	{
615
+		$identifier                             = $question->is_system_question()
616
+			? $question->system_ID()
617
+			: $question->ID();
618
+		$this->_required_questions[$identifier] = $question->required() ? true : false;
619
+		add_filter(
620
+			'FHEE__EE_Question__generate_form_input__country_options',
621
+			array($this, 'use_cached_countries_for_form_input'),
622
+			10,
623
+			4
624
+		);
625
+		add_filter(
626
+			'FHEE__EE_Question__generate_form_input__state_options',
627
+			array($this, 'use_cached_states_for_form_input'),
628
+			10,
629
+			4
630
+		);
631
+		$input_constructor_args                  = array(
632
+			'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
633
+			'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
634
+			'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
635
+			'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
636
+			'html_label_class' => 'ee-reg-qstn',
637
+		);
638
+		$input_constructor_args['html_label_id'] .= '-lbl';
639
+		if ($answer instanceof EE_Answer && $answer->ID()) {
640
+			$input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
641
+			$input_constructor_args['html_id']       .= '-' . $answer->ID();
642
+			$input_constructor_args['html_label_id'] .= '-' . $answer->ID();
643
+		}
644
+		$form_input = $question->generate_form_input(
645
+			$registration,
646
+			$answer,
647
+			$input_constructor_args
648
+		);
649
+		remove_filter(
650
+			'FHEE__EE_Question__generate_form_input__country_options',
651
+			array($this, 'use_cached_countries_for_form_input')
652
+		);
653
+		remove_filter(
654
+			'FHEE__EE_Question__generate_form_input__state_options',
655
+			array($this, 'use_cached_states_for_form_input')
656
+		);
657
+		return $form_input;
658
+	}
659
+
660
+
661
+	/**
662
+	 * Gets the list of countries for the form input
663
+	 *
664
+	 * @param array|null       $countries_list
665
+	 * @param \EE_Question     $question
666
+	 * @param \EE_Registration $registration
667
+	 * @param \EE_Answer       $answer
668
+	 * @return array 2d keys are country IDs, values are their names
669
+	 * @throws EE_Error
670
+	 * @throws InvalidArgumentException
671
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
672
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
673
+	 */
674
+	public function use_cached_countries_for_form_input(
675
+		$countries_list,
676
+		\EE_Question $question = null,
677
+		\EE_Registration $registration = null,
678
+		\EE_Answer $answer = null
679
+	) {
680
+		$country_options = array('' => '');
681
+		// get possibly cached list of countries
682
+		$countries = $this->checkout->action === 'process_reg_step'
683
+			? EEM_Country::instance()->get_all_countries()
684
+			: EEM_Country::instance()->get_all_active_countries();
685
+		if (! empty($countries)) {
686
+			foreach ($countries as $country) {
687
+				if ($country instanceof EE_Country) {
688
+					$country_options[$country->ID()] = $country->name();
689
+				}
690
+			}
691
+		}
692
+		if ($question instanceof EE_Question
693
+			&& $registration instanceof EE_Registration) {
694
+			$answer = EEM_Answer::instance()->get_one(
695
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
696
+			);
697
+		} else {
698
+			$answer = EE_Answer::new_instance();
699
+		}
700
+		$country_options = apply_filters(
701
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
702
+			$country_options,
703
+			$this,
704
+			$registration,
705
+			$question,
706
+			$answer
707
+		);
708
+		return $country_options;
709
+	}
710
+
711
+
712
+	/**
713
+	 * Gets the list of states for the form input
714
+	 *
715
+	 * @param array|null       $states_list
716
+	 * @param \EE_Question     $question
717
+	 * @param \EE_Registration $registration
718
+	 * @param \EE_Answer       $answer
719
+	 * @return array 2d keys are state IDs, values are their names
720
+	 * @throws EE_Error
721
+	 * @throws InvalidArgumentException
722
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
723
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
724
+	 */
725
+	public function use_cached_states_for_form_input(
726
+		$states_list,
727
+		\EE_Question $question = null,
728
+		\EE_Registration $registration = null,
729
+		\EE_Answer $answer = null
730
+	) {
731
+		$state_options = array('' => array('' => ''));
732
+		$states        = $this->checkout->action === 'process_reg_step'
733
+			? EEM_State::instance()->get_all_states()
734
+			: EEM_State::instance()->get_all_active_states();
735
+		if (! empty($states)) {
736
+			foreach ($states as $state) {
737
+				if ($state instanceof EE_State) {
738
+					$state_options[$state->country()->name()][$state->ID()] = $state->name();
739
+				}
740
+			}
741
+		}
742
+		$state_options = apply_filters(
743
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
744
+			$state_options,
745
+			$this,
746
+			$registration,
747
+			$question,
748
+			$answer
749
+		);
750
+		return $state_options;
751
+	}
752
+
753
+
754
+
755
+
756
+
757
+
758
+	/********************************************************************************************************/
759
+	/****************************************  PROCESS REG STEP  ****************************************/
760
+	/********************************************************************************************************/
761
+	/**
762
+	 * @return bool
763
+	 * @throws EE_Error
764
+	 * @throws InvalidArgumentException
765
+	 * @throws ReflectionException
766
+	 * @throws RuntimeException
767
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
768
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
769
+	 */
770
+	public function process_reg_step()
771
+	{
772
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
773
+		// grab validated data from form
774
+		$valid_data = $this->checkout->current_step->valid_data();
775
+		// EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
776
+		// EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
777
+		// if we don't have any $valid_data then something went TERRIBLY WRONG !!!
778
+		if (empty($valid_data)) {
779
+			EE_Error::add_error(
780
+				esc_html__('No valid question responses were received.', 'event_espresso'),
781
+				__FILE__,
782
+				__FUNCTION__,
783
+				__LINE__
784
+			);
785
+			return false;
786
+		}
787
+		if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
788
+			EE_Error::add_error(
789
+				esc_html__(
790
+					'A valid transaction could not be initiated for processing your registrations.',
791
+					'event_espresso'
792
+				),
793
+				__FILE__,
794
+				__FUNCTION__,
795
+				__LINE__
796
+			);
797
+			return false;
798
+		}
799
+		// get cached registrations
800
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
801
+		// verify we got the goods
802
+		if (empty($registrations)) {
803
+			//combine the old translated string with a new one, in order to not break translations
804
+			$error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' )
805
+							 . sprintf(
806
+								 esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'),
807
+								 '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
808
+								 '</a>',
809
+								 '<br />'
810
+							 );
811
+			EE_Error::add_error(
812
+				$error_message,
813
+				__FILE__,
814
+				__FUNCTION__,
815
+				__LINE__
816
+			);
817
+			return false;
818
+		}
819
+		// extract attendee info from form data and save to model objects
820
+		$registrations_processed = $this->_process_registrations($registrations, $valid_data);
821
+		// if first pass thru SPCO,
822
+		// then let's check processed registrations against the total number of tickets in the cart
823
+		if ($registrations_processed === false) {
824
+			// but return immediately if the previous step exited early due to errors
825
+			return false;
826
+		} elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
827
+			// generate a correctly translated string for all possible singular/plural combinations
828
+			if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
829
+				$error_msg = sprintf(
830
+					esc_html__(
831
+						'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
832
+						'event_espresso'
833
+					),
834
+					$this->checkout->total_ticket_count,
835
+					$registrations_processed
836
+				);
837
+			} elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
838
+				$error_msg = sprintf(
839
+					esc_html__(
840
+						'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
841
+						'event_espresso'
842
+					),
843
+					$this->checkout->total_ticket_count,
844
+					$registrations_processed
845
+				);
846
+			} else {
847
+				$error_msg = sprintf(
848
+					esc_html__(
849
+						'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed',
850
+						'event_espresso'
851
+					),
852
+					$this->checkout->total_ticket_count,
853
+					$registrations_processed
854
+				);
855
+			}
856
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
857
+			return false;
858
+		}
859
+		// mark this reg step as completed
860
+		$this->set_completed();
861
+		$this->_set_success_message(
862
+			esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
863
+		);
864
+		//do action in case a plugin wants to do something with the data submitted in step 1.
865
+		//passes EE_Single_Page_Checkout, and it's posted data
866
+		do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
867
+		return true;
868
+	}
869
+
870
+
871
+	/**
872
+	 *    _process_registrations
873
+	 *
874
+	 * @param EE_Registration[] $registrations
875
+	 * @param array             $valid_data
876
+	 * @return bool|int
877
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
878
+	 * @throws EE_Error
879
+	 * @throws InvalidArgumentException
880
+	 * @throws ReflectionException
881
+	 * @throws RuntimeException
882
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
883
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
884
+	 */
885
+	private function _process_registrations($registrations = array(), $valid_data = array())
886
+	{
887
+		// load resources and set some defaults
888
+		EE_Registry::instance()->load_model('Attendee');
889
+		// holder for primary registrant attendee object
890
+		$this->checkout->primary_attendee_obj = null;
891
+		// array for tracking reg form data for the primary registrant
892
+		$primary_registrant = array(
893
+			'line_item_id' => null,
894
+		);
895
+		$copy_primary       = false;
896
+		// reg form sections that do not contain inputs
897
+		$non_input_form_sections = array(
898
+			'primary_registrant',
899
+			'additional_attendee_reg_info',
900
+			'spco_copy_attendee_chk',
901
+		);
902
+		// attendee counter
903
+		$att_nmbr = 0;
904
+		// grab the saved registrations from the transaction
905
+		foreach ($registrations as $registration) {
906
+			// verify EE_Registration object
907
+			if (! $registration instanceof EE_Registration) {
908
+				EE_Error::add_error(
909
+					esc_html__(
910
+						'An invalid Registration object was discovered when attempting to process your registration information.',
911
+						'event_espresso'
912
+					),
913
+					__FILE__,
914
+					__FUNCTION__,
915
+					__LINE__
916
+				);
917
+				return false;
918
+			}
919
+			/** @var string $reg_url_link */
920
+			$reg_url_link = $registration->reg_url_link();
921
+			// reg_url_link exists ?
922
+			if (! empty($reg_url_link)) {
923
+				// should this registration be processed during this visit ?
924
+				if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
925
+					// if NOT revisiting, then let's save the registration now,
926
+					// so that we have a REG_ID to use when generating other objects
927
+					if (! $this->checkout->revisit) {
928
+						$registration->save();
929
+					}
930
+					/**
931
+					 * This allows plugins to trigger a fail on processing of a
932
+					 * registration for any conditions they may have for it to pass.
933
+					 *
934
+					 * @var bool   if true is returned by the plugin then the
935
+					 *            registration processing is halted.
936
+					 */
937
+					if (apply_filters(
938
+						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
939
+						false,
940
+						$att_nmbr,
941
+						$registration,
942
+						$registrations,
943
+						$valid_data,
944
+						$this
945
+					)) {
946
+						return false;
947
+					}
948
+
949
+					// Houston, we have a registration!
950
+					$att_nmbr++;
951
+					$this->_attendee_data[$reg_url_link] = array();
952
+					// grab any existing related answer objects
953
+					$this->_registration_answers = $registration->answers();
954
+					// unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
955
+					if (isset($valid_data[$reg_url_link])) {
956
+						// do we need to copy basic info from primary attendee ?
957
+						$copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info'])
958
+										&& absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0
959
+							? true
960
+							: false;
961
+						// filter form input data for this registration
962
+						$valid_data[$reg_url_link] = (array)apply_filters(
963
+							'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
964
+							$valid_data[$reg_url_link]
965
+						);
966
+						if (isset($valid_data['primary_attendee'])) {
967
+							$primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
968
+								? $valid_data['primary_attendee']
969
+								: false;
970
+							unset($valid_data['primary_attendee']);
971
+						}
972
+						// now loop through our array of valid post data && process attendee reg forms
973
+						foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) {
974
+							if (! in_array($form_section, $non_input_form_sections)) {
975
+								foreach ($form_inputs as $form_input => $input_value) {
976
+									// \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
977
+									// check for critical inputs
978
+									if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
979
+										$form_input,
980
+										$input_value
981
+									)
982
+									) {
983
+										return false;
984
+									}
985
+									// store a bit of data about the primary attendee
986
+									if ($att_nmbr === 1
987
+										&& ! empty($input_value)
988
+										&& $reg_url_link === $primary_registrant['line_item_id']
989
+									) {
990
+										$primary_registrant[$form_input] = $input_value;
991
+									} elseif ($copy_primary
992
+										&& $input_value === null
993
+										&& isset($primary_registrant[$form_input])
994
+									) {
995
+										$input_value = $primary_registrant[$form_input];
996
+									}
997
+									// now attempt to save the input data
998
+									if (! $this->_save_registration_form_input(
999
+										$registration,
1000
+										$form_input,
1001
+										$input_value
1002
+									)
1003
+									) {
1004
+										EE_Error::add_error(
1005
+											sprintf(
1006
+												esc_html__(
1007
+													'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1008
+													'event_espresso'
1009
+												),
1010
+												$form_input,
1011
+												$input_value
1012
+											),
1013
+											__FILE__,
1014
+											__FUNCTION__,
1015
+											__LINE__
1016
+										);
1017
+										return false;
1018
+									}
1019
+								}
1020
+							}
1021
+						}  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1022
+					}
1023
+					//EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1024
+					// this registration does not require additional attendee information ?
1025
+					if ($copy_primary
1026
+						&& $att_nmbr > 1
1027
+						&& $this->checkout->primary_attendee_obj instanceof EE_Attendee
1028
+					) {
1029
+						// just copy the primary registrant
1030
+						$attendee = $this->checkout->primary_attendee_obj;
1031
+					} else {
1032
+						// ensure critical details are set for additional attendees
1033
+						$this->_attendee_data[$reg_url_link] = $att_nmbr > 1
1034
+							? $this->_copy_critical_attendee_details_from_primary_registrant(
1035
+								$this->_attendee_data[$reg_url_link]
1036
+							)
1037
+							: $this->_attendee_data[$reg_url_link];
1038
+						// execute create attendee command (which may return an existing attendee)
1039
+						$attendee = EE_Registry::instance()->BUS->execute(
1040
+							new CreateAttendeeCommand(
1041
+								$this->_attendee_data[$reg_url_link],
1042
+								$registration
1043
+							)
1044
+						);
1045
+						// who's #1 ?
1046
+						if ($att_nmbr === 1) {
1047
+							$this->checkout->primary_attendee_obj = $attendee;
1048
+						}
1049
+					}
1050
+					// EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1051
+					// add relation to registration, set attendee ID, and cache attendee
1052
+					$this->_associate_attendee_with_registration($registration, $attendee);
1053
+					// \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1054
+					if (! $registration->attendee() instanceof EE_Attendee) {
1055
+						EE_Error::add_error(
1056
+							sprintf(
1057
+								esc_html__(
1058
+									'Registration %s has an invalid or missing Attendee object.',
1059
+									'event_espresso'
1060
+								),
1061
+								$reg_url_link
1062
+							),
1063
+							__FILE__,
1064
+							__FUNCTION__,
1065
+							__LINE__
1066
+						);
1067
+						return false;
1068
+					}
1069
+					/** @type EE_Registration_Processor $registration_processor */
1070
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1071
+					// at this point, we should have enough details about the registrant to consider the registration
1072
+					// NOT incomplete
1073
+					$registration_processor->toggle_incomplete_registration_status_to_default(
1074
+						$registration,
1075
+						false,
1076
+						new Context(
1077
+							'spco_reg_step_attendee_information_process_registrations',
1078
+							esc_html__(
1079
+								'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1080
+								'event_espresso'
1081
+							)
1082
+						)
1083
+					);
1084
+					// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1085
+					// abandoned
1086
+					$this->checkout->transaction->toggle_failed_transaction_status();
1087
+					// if we've gotten this far, then let's save what we have
1088
+					$registration->save();
1089
+					// add relation between TXN and registration
1090
+					$this->_associate_registration_with_transaction($registration);
1091
+				}
1092
+			} else {
1093
+				EE_Error::add_error(
1094
+					esc_html__(
1095
+						'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1096
+						'event_espresso'
1097
+					),
1098
+					__FILE__,
1099
+					__FUNCTION__,
1100
+					__LINE__
1101
+				);
1102
+				// remove malformed data
1103
+				unset($valid_data[$reg_url_link]);
1104
+				return false;
1105
+			}
1106
+
1107
+		} // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1108
+		return $att_nmbr;
1109
+	}
1110
+
1111
+
1112
+	/**
1113
+	 *    _save_registration_form_input
1114
+	 *
1115
+	 * @param EE_Registration $registration
1116
+	 * @param string          $form_input
1117
+	 * @param string          $input_value
1118
+	 * @return bool
1119
+	 * @throws EE_Error
1120
+	 * @throws InvalidArgumentException
1121
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1122
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1123
+	 */
1124
+	private function _save_registration_form_input(
1125
+		EE_Registration $registration,
1126
+		$form_input = '',
1127
+		$input_value = ''
1128
+	) {
1129
+		// \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1130
+		// \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1131
+		// \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1132
+		// allow for plugins to hook in and do their own processing of the form input.
1133
+		// For plugins to bypass normal processing here, they just need to return a boolean value.
1134
+		if (apply_filters(
1135
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1136
+			false,
1137
+			$registration,
1138
+			$form_input,
1139
+			$input_value,
1140
+			$this
1141
+		)) {
1142
+			return true;
1143
+		}
1144
+		/*
1145 1145
          * $answer_cache_id is the key used to find the EE_Answer we want
1146 1146
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1147 1147
          */
1148
-        $answer_cache_id = $this->checkout->reg_url_link
1149
-            ? $form_input . '-' . $registration->reg_url_link()
1150
-            : $form_input;
1151
-        $answer_is_obj   = isset($this->_registration_answers[$answer_cache_id])
1152
-                           && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer
1153
-            ? true
1154
-            : false;
1155
-        //rename form_inputs if they are EE_Attendee properties
1156
-        switch ((string) $form_input) {
1157
-            case 'state':
1158
-            case 'STA_ID':
1159
-                $attendee_property = true;
1160
-                $form_input        = 'STA_ID';
1161
-                break;
1162
-
1163
-            case 'country':
1164
-            case 'CNT_ISO':
1165
-                $attendee_property = true;
1166
-                $form_input        = 'CNT_ISO';
1167
-                break;
1168
-
1169
-            default:
1170
-                $ATT_input = 'ATT_' . $form_input;
1171
-                //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1172
-                $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1173
-                $form_input        = $attendee_property ? 'ATT_' . $form_input : $form_input;
1174
-        }
1175
-        // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1176
-        // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1177
-        // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1178
-        // if this form input has a corresponding attendee property
1179
-        if ($attendee_property) {
1180
-            $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value;
1181
-            if ($answer_is_obj) {
1182
-                // and delete the corresponding answer since we won't be storing this data in that object
1183
-                $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer');
1184
-                $this->_registration_answers[$answer_cache_id]->delete_permanently();
1185
-            }
1186
-            return true;
1187
-        } elseif ($answer_is_obj) {
1188
-            // save this data to the answer object
1189
-            $this->_registration_answers[$answer_cache_id]->set_value($input_value);
1190
-            $result = $this->_registration_answers[$answer_cache_id]->save();
1191
-            return $result !== false ? true : false;
1192
-        } else {
1193
-            foreach ($this->_registration_answers as $answer) {
1194
-                if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1195
-                    $answer->set_value($input_value);
1196
-                    $result = $answer->save();
1197
-                    return $result !== false ? true : false;
1198
-                }
1199
-            }
1200
-        }
1201
-        return false;
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     *    _verify_critical_attendee_details_are_set
1207
-     *
1208
-     * @param string $form_input
1209
-     * @param string $input_value
1210
-     * @return boolean
1211
-     */
1212
-    private function _verify_critical_attendee_details_are_set_and_validate_email(
1213
-        $form_input = '',
1214
-        $input_value = ''
1215
-    ) {
1216
-        if (empty($input_value)) {
1217
-            // if the form input isn't marked as being required, then just return
1218
-            if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1219
-                return true;
1220
-            }
1221
-            switch ($form_input) {
1222
-                case 'fname':
1223
-                    EE_Error::add_error(
1224
-                        esc_html__('First Name is a required value.', 'event_espresso'),
1225
-                        __FILE__,
1226
-                        __FUNCTION__,
1227
-                        __LINE__
1228
-                    );
1229
-                    return false;
1230
-                    break;
1231
-                case 'lname':
1232
-                    EE_Error::add_error(
1233
-                        esc_html__('Last Name is a required value.', 'event_espresso'),
1234
-                        __FILE__,
1235
-                        __FUNCTION__,
1236
-                        __LINE__
1237
-                    );
1238
-                    return false;
1239
-                    break;
1240
-                case 'email':
1241
-                    EE_Error::add_error(
1242
-                        esc_html__('Please enter a valid email address.', 'event_espresso'),
1243
-                        __FILE__,
1244
-                        __FUNCTION__,
1245
-                        __LINE__
1246
-                    );
1247
-                    return false;
1248
-                    break;
1249
-            }
1250
-        }
1251
-        return true;
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     *    _associate_attendee_with_registration
1257
-     *
1258
-     * @param EE_Registration $registration
1259
-     * @param EE_Attendee     $attendee
1260
-     * @return void
1261
-     * @throws EE_Error
1262
-     * @throws RuntimeException
1263
-     */
1264
-    private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1265
-    {
1266
-        // add relation to attendee
1267
-        $registration->_add_relation_to($attendee, 'Attendee');
1268
-        $registration->set_attendee_id($attendee->ID());
1269
-        $registration->update_cache_after_object_save('Attendee', $attendee);
1270
-    }
1271
-
1272
-
1273
-    /**
1274
-     *    _associate_registration_with_transaction
1275
-     *
1276
-     * @param EE_Registration $registration
1277
-     * @return void
1278
-     * @throws \EE_Error
1279
-     */
1280
-    private function _associate_registration_with_transaction(EE_Registration $registration)
1281
-    {
1282
-        // add relation to registration
1283
-        $this->checkout->transaction->_add_relation_to($registration, 'Registration');
1284
-        $this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     *    _copy_critical_attendee_details_from_primary_registrant
1290
-     *    ensures that all attendees at least have data for first name, last name, and email address
1291
-     *
1292
-     * @param array $attendee_data
1293
-     * @return array
1294
-     * @throws \EE_Error
1295
-     */
1296
-    private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1297
-    {
1298
-        // bare minimum critical details include first name, last name, email address
1299
-        $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1300
-        // add address info to critical details?
1301
-        if (apply_filters(
1302
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1303
-            false
1304
-        )) {
1305
-            $address_details           = array(
1306
-                'ATT_address',
1307
-                'ATT_address2',
1308
-                'ATT_city',
1309
-                'STA_ID',
1310
-                'CNT_ISO',
1311
-                'ATT_zip',
1312
-                'ATT_phone',
1313
-            );
1314
-            $critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1315
-        }
1316
-        foreach ($critical_attendee_details as $critical_attendee_detail) {
1317
-            if (! isset($attendee_data[$critical_attendee_detail])
1318
-                || empty($attendee_data[$critical_attendee_detail])
1319
-            ) {
1320
-                $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get(
1321
-                    $critical_attendee_detail
1322
-                );
1323
-            }
1324
-        }
1325
-        return $attendee_data;
1326
-    }
1327
-
1328
-
1329
-    /**
1330
-     *    update_reg_step
1331
-     *    this is the final step after a user  revisits the site to edit their attendee information
1332
-     *    this gets called AFTER the process_reg_step() method above
1333
-     *
1334
-     * @return bool
1335
-     * @throws EE_Error
1336
-     * @throws InvalidArgumentException
1337
-     * @throws ReflectionException
1338
-     * @throws RuntimeException
1339
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1340
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1341
-     */
1342
-    public function update_reg_step()
1343
-    {
1344
-        // save everything
1345
-        if ($this->process_reg_step()) {
1346
-            $this->checkout->redirect     = true;
1347
-            $this->checkout->redirect_url = add_query_arg(
1348
-                array(
1349
-                    'e_reg_url_link' => $this->checkout->reg_url_link,
1350
-                    'revisit'        => true,
1351
-                ),
1352
-                $this->checkout->thank_you_page_url
1353
-            );
1354
-            $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1355
-            return true;
1356
-        }
1357
-        return false;
1358
-    }
1148
+		$answer_cache_id = $this->checkout->reg_url_link
1149
+			? $form_input . '-' . $registration->reg_url_link()
1150
+			: $form_input;
1151
+		$answer_is_obj   = isset($this->_registration_answers[$answer_cache_id])
1152
+						   && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer
1153
+			? true
1154
+			: false;
1155
+		//rename form_inputs if they are EE_Attendee properties
1156
+		switch ((string) $form_input) {
1157
+			case 'state':
1158
+			case 'STA_ID':
1159
+				$attendee_property = true;
1160
+				$form_input        = 'STA_ID';
1161
+				break;
1162
+
1163
+			case 'country':
1164
+			case 'CNT_ISO':
1165
+				$attendee_property = true;
1166
+				$form_input        = 'CNT_ISO';
1167
+				break;
1168
+
1169
+			default:
1170
+				$ATT_input = 'ATT_' . $form_input;
1171
+				//EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1172
+				$attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1173
+				$form_input        = $attendee_property ? 'ATT_' . $form_input : $form_input;
1174
+		}
1175
+		// EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1176
+		// EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1177
+		// EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1178
+		// if this form input has a corresponding attendee property
1179
+		if ($attendee_property) {
1180
+			$this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value;
1181
+			if ($answer_is_obj) {
1182
+				// and delete the corresponding answer since we won't be storing this data in that object
1183
+				$registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer');
1184
+				$this->_registration_answers[$answer_cache_id]->delete_permanently();
1185
+			}
1186
+			return true;
1187
+		} elseif ($answer_is_obj) {
1188
+			// save this data to the answer object
1189
+			$this->_registration_answers[$answer_cache_id]->set_value($input_value);
1190
+			$result = $this->_registration_answers[$answer_cache_id]->save();
1191
+			return $result !== false ? true : false;
1192
+		} else {
1193
+			foreach ($this->_registration_answers as $answer) {
1194
+				if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1195
+					$answer->set_value($input_value);
1196
+					$result = $answer->save();
1197
+					return $result !== false ? true : false;
1198
+				}
1199
+			}
1200
+		}
1201
+		return false;
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 *    _verify_critical_attendee_details_are_set
1207
+	 *
1208
+	 * @param string $form_input
1209
+	 * @param string $input_value
1210
+	 * @return boolean
1211
+	 */
1212
+	private function _verify_critical_attendee_details_are_set_and_validate_email(
1213
+		$form_input = '',
1214
+		$input_value = ''
1215
+	) {
1216
+		if (empty($input_value)) {
1217
+			// if the form input isn't marked as being required, then just return
1218
+			if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1219
+				return true;
1220
+			}
1221
+			switch ($form_input) {
1222
+				case 'fname':
1223
+					EE_Error::add_error(
1224
+						esc_html__('First Name is a required value.', 'event_espresso'),
1225
+						__FILE__,
1226
+						__FUNCTION__,
1227
+						__LINE__
1228
+					);
1229
+					return false;
1230
+					break;
1231
+				case 'lname':
1232
+					EE_Error::add_error(
1233
+						esc_html__('Last Name is a required value.', 'event_espresso'),
1234
+						__FILE__,
1235
+						__FUNCTION__,
1236
+						__LINE__
1237
+					);
1238
+					return false;
1239
+					break;
1240
+				case 'email':
1241
+					EE_Error::add_error(
1242
+						esc_html__('Please enter a valid email address.', 'event_espresso'),
1243
+						__FILE__,
1244
+						__FUNCTION__,
1245
+						__LINE__
1246
+					);
1247
+					return false;
1248
+					break;
1249
+			}
1250
+		}
1251
+		return true;
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 *    _associate_attendee_with_registration
1257
+	 *
1258
+	 * @param EE_Registration $registration
1259
+	 * @param EE_Attendee     $attendee
1260
+	 * @return void
1261
+	 * @throws EE_Error
1262
+	 * @throws RuntimeException
1263
+	 */
1264
+	private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1265
+	{
1266
+		// add relation to attendee
1267
+		$registration->_add_relation_to($attendee, 'Attendee');
1268
+		$registration->set_attendee_id($attendee->ID());
1269
+		$registration->update_cache_after_object_save('Attendee', $attendee);
1270
+	}
1271
+
1272
+
1273
+	/**
1274
+	 *    _associate_registration_with_transaction
1275
+	 *
1276
+	 * @param EE_Registration $registration
1277
+	 * @return void
1278
+	 * @throws \EE_Error
1279
+	 */
1280
+	private function _associate_registration_with_transaction(EE_Registration $registration)
1281
+	{
1282
+		// add relation to registration
1283
+		$this->checkout->transaction->_add_relation_to($registration, 'Registration');
1284
+		$this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 *    _copy_critical_attendee_details_from_primary_registrant
1290
+	 *    ensures that all attendees at least have data for first name, last name, and email address
1291
+	 *
1292
+	 * @param array $attendee_data
1293
+	 * @return array
1294
+	 * @throws \EE_Error
1295
+	 */
1296
+	private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1297
+	{
1298
+		// bare minimum critical details include first name, last name, email address
1299
+		$critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1300
+		// add address info to critical details?
1301
+		if (apply_filters(
1302
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1303
+			false
1304
+		)) {
1305
+			$address_details           = array(
1306
+				'ATT_address',
1307
+				'ATT_address2',
1308
+				'ATT_city',
1309
+				'STA_ID',
1310
+				'CNT_ISO',
1311
+				'ATT_zip',
1312
+				'ATT_phone',
1313
+			);
1314
+			$critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1315
+		}
1316
+		foreach ($critical_attendee_details as $critical_attendee_detail) {
1317
+			if (! isset($attendee_data[$critical_attendee_detail])
1318
+				|| empty($attendee_data[$critical_attendee_detail])
1319
+			) {
1320
+				$attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get(
1321
+					$critical_attendee_detail
1322
+				);
1323
+			}
1324
+		}
1325
+		return $attendee_data;
1326
+	}
1327
+
1328
+
1329
+	/**
1330
+	 *    update_reg_step
1331
+	 *    this is the final step after a user  revisits the site to edit their attendee information
1332
+	 *    this gets called AFTER the process_reg_step() method above
1333
+	 *
1334
+	 * @return bool
1335
+	 * @throws EE_Error
1336
+	 * @throws InvalidArgumentException
1337
+	 * @throws ReflectionException
1338
+	 * @throws RuntimeException
1339
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1340
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1341
+	 */
1342
+	public function update_reg_step()
1343
+	{
1344
+		// save everything
1345
+		if ($this->process_reg_step()) {
1346
+			$this->checkout->redirect     = true;
1347
+			$this->checkout->redirect_url = add_query_arg(
1348
+				array(
1349
+					'e_reg_url_link' => $this->checkout->reg_url_link,
1350
+					'revisit'        => true,
1351
+				),
1352
+				$this->checkout->thank_you_page_url
1353
+			);
1354
+			$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1355
+			return true;
1356
+		}
1357
+		return false;
1358
+	}
1359 1359
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -52 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     {
49 49
         $this->_slug     = 'attendee_information';
50 50
         $this->_name     = esc_html__('Attendee Information', 'event_espresso');
51
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php';
51
+        $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php';
52 52
         $this->checkout  = $checkout;
53 53
         $this->_reset_success_message();
54 54
         $this->set_instructions(
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 
60 60
     public function translate_js_strings()
61 61
     {
62
-        EE_Registry::$i18n_js_strings['required_field']            = esc_html__(
62
+        EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
63 63
             ' is a required question.',
64 64
             'event_espresso'
65 65
         );
66
-        EE_Registry::$i18n_js_strings['required_multi_field']      = esc_html__(
66
+        EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
67 67
             ' is a required question. Please enter a value for at least one of the options.',
68 68
             'event_espresso'
69 69
         );
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
             'Please answer all required questions correctly before proceeding.',
72 72
             'event_espresso'
73 73
         );
74
-        EE_Registry::$i18n_js_strings['attendee_info_copied']      = sprintf(
74
+        EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
75 75
             esc_html__(
76 76
                 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
77 77
                 'event_espresso'
78 78
             ),
79 79
             '<br/>'
80 80
         );
81
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error']  = esc_html__(
81
+        EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
82 82
             'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
83 83
             'event_espresso'
84 84
         );
85
-        EE_Registry::$i18n_js_strings['enter_valid_email']         = esc_html__(
85
+        EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
86 86
             'You must enter a valid email address.',
87 87
             'event_espresso'
88 88
         );
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                     && $this->checkout->visit_allows_processing_of_this_registration($registration)
146 146
                 ) {
147 147
                     $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration);
148
-                    if (! $this->checkout->admin_request) {
148
+                    if ( ! $this->checkout->admin_request) {
149 149
                         $template_args['registrations'][$registration->reg_url_link()]    = $registration;
150 150
                         $template_args['ticket_count'][$registration->ticket()->ID()]     = isset(
151 151
                             $template_args['ticket_count'][$registration->ticket()->ID()]
@@ -194,8 +194,7 @@  discard block
 block discarded – undo
194 194
                 'html_id'         => $this->reg_form_name(),
195 195
                 'subsections'     => $subsections,
196 196
                 'layout_strategy' => $this->checkout->admin_request ?
197
-                    new EE_Div_Per_Section_Layout() :
198
-                    new EE_Template_Layout(
197
+                    new EE_Div_Per_Section_Layout() : new EE_Template_Layout(
199 198
                         array(
200 199
                             'layout_template_file' => $this->_template, // layout_template
201 200
                             'template_args'        => $template_args,
@@ -238,7 +237,7 @@  discard block
 block discarded – undo
238 237
             if ($question_groups) {
239 238
                 // array of params to pass to parent constructor
240 239
                 $form_args = array(
241
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
240
+                    'html_id'         => 'ee-registration-'.$registration->reg_url_link(),
242 241
                     'html_class'      => 'ee-reg-form-attendee-dv',
243 242
                     'html_style'      => $this->checkout->admin_request
244 243
                         ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
@@ -294,7 +293,7 @@  discard block
 block discarded – undo
294 293
         // generate hidden input
295 294
         return new EE_Hidden_Input(
296 295
             array(
297
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
296
+                'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(),
298 297
                 'default' => $additional_attendee_reg_info,
299 298
             )
300 299
         );
@@ -314,11 +313,11 @@  discard block
 block discarded – undo
314 313
     {
315 314
         // array of params to pass to parent constructor
316 315
         $form_args = array(
317
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
316
+            'html_id'         => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID(),
318 317
             'html_class'      => $this->checkout->admin_request
319 318
                 ? 'form-table ee-reg-form-qstn-grp-dv'
320 319
                 : 'ee-reg-form-qstn-grp-dv',
321
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() .  '-' . $registration->ID() . '-lbl',
320
+            'html_label_id'   => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID().'-lbl',
322 321
             'subsections'     => array(
323 322
                 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
324 323
             ),
@@ -329,7 +328,7 @@  discard block
 block discarded – undo
329 328
         // where params
330 329
         $query_params = array('QST_deleted' => 0);
331 330
         // don't load admin only questions on the frontend
332
-        if (! $this->checkout->admin_request) {
331
+        if ( ! $this->checkout->admin_request) {
333 332
             $query_params['QST_admin_only'] = array('!=', true);
334 333
         }
335 334
         $questions = $question_group->get_many_related(
@@ -473,7 +472,7 @@  discard block
 block discarded – undo
473 472
     {
474 473
         return new EE_Form_Section_HTML(
475 474
             EEH_Template::locate_template(
476
-                SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php',
475
+                SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php',
477 476
                 apply_filters(
478 477
                     'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
479 478
                     array()
@@ -505,16 +504,16 @@  discard block
 block discarded – undo
505 504
                 if ($registration->ticket()->ID() !== $prev_ticket) {
506 505
                     $item_name = $registration->ticket()->name();
507 506
                     $item_name .= $registration->ticket()->description() !== ''
508
-                        ? ' - ' . $registration->ticket()->description()
507
+                        ? ' - '.$registration->ticket()->description()
509 508
                         : '';
510
-                    $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] =
509
+                    $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] =
511 510
                         new EE_Form_Section_HTML(
512
-                            '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
511
+                            '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>'
513 512
                         );
514 513
                     $prev_ticket = $registration->ticket()->ID();
515 514
                 }
516 515
 
517
-                $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] =
516
+                $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] =
518 517
                     new EE_Checkbox_Multi_Input(
519 518
                         array(
520 519
                             $registration->ID() => sprintf(
@@ -523,7 +522,7 @@  discard block
 block discarded – undo
523 522
                             ),
524 523
                         ),
525 524
                         array(
526
-                            'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
525
+                            'html_id'                 => 'spco-copy-attendee-chk-'.$registration->reg_url_link(),
527 526
                             'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
528 527
                             'display_html_label_text' => false,
529 528
                         )
@@ -572,7 +571,7 @@  discard block
 block discarded – undo
572 571
             $registration,
573 572
             $question->system_ID()
574 573
         );
575
-        $answer       = $answer_value === null
574
+        $answer = $answer_value === null
576 575
             ? EEM_Answer::instance()->get_one(
577 576
                 array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
578 577
             )
@@ -589,14 +588,14 @@  discard block
 block discarded – undo
589 588
         }
590 589
         // verify instance
591 590
         if ($answer instanceof EE_Answer) {
592
-            if (! empty($answer_value)) {
591
+            if ( ! empty($answer_value)) {
593 592
                 $answer->set('ANS_value', $answer_value);
594 593
             }
595 594
             $answer->cache('Question', $question);
596 595
             //remember system ID had a bug where sometimes it could be null
597 596
             $answer_cache_id = $question->is_system_question()
598
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
599
-                : $question->ID() . '-' . $registration->reg_url_link();
597
+                ? $question->system_ID().'-'.$registration->reg_url_link()
598
+                : $question->ID().'-'.$registration->reg_url_link();
600 599
             $registration->cache('Answer', $answer, $answer_cache_id);
601 600
         }
602 601
         return $this->_generate_question_input($registration, $question, $answer);
@@ -628,18 +627,18 @@  discard block
 block discarded – undo
628 627
             10,
629 628
             4
630 629
         );
631
-        $input_constructor_args                  = array(
632
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
633
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
634
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
635
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
630
+        $input_constructor_args = array(
631
+            'html_name'        => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']',
632
+            'html_id'          => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier,
633
+            'html_class'       => 'ee-reg-qstn ee-reg-qstn-'.$identifier,
634
+            'html_label_id'    => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier,
636 635
             'html_label_class' => 'ee-reg-qstn',
637 636
         );
638 637
         $input_constructor_args['html_label_id'] .= '-lbl';
639 638
         if ($answer instanceof EE_Answer && $answer->ID()) {
640
-            $input_constructor_args['html_name']     .= '[' . $answer->ID() . ']';
641
-            $input_constructor_args['html_id']       .= '-' . $answer->ID();
642
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
639
+            $input_constructor_args['html_name']     .= '['.$answer->ID().']';
640
+            $input_constructor_args['html_id']       .= '-'.$answer->ID();
641
+            $input_constructor_args['html_label_id'] .= '-'.$answer->ID();
643 642
         }
644 643
         $form_input = $question->generate_form_input(
645 644
             $registration,
@@ -682,7 +681,7 @@  discard block
 block discarded – undo
682 681
         $countries = $this->checkout->action === 'process_reg_step'
683 682
             ? EEM_Country::instance()->get_all_countries()
684 683
             : EEM_Country::instance()->get_all_active_countries();
685
-        if (! empty($countries)) {
684
+        if ( ! empty($countries)) {
686 685
             foreach ($countries as $country) {
687 686
                 if ($country instanceof EE_Country) {
688 687
                     $country_options[$country->ID()] = $country->name();
@@ -732,7 +731,7 @@  discard block
 block discarded – undo
732 731
         $states        = $this->checkout->action === 'process_reg_step'
733 732
             ? EEM_State::instance()->get_all_states()
734 733
             : EEM_State::instance()->get_all_active_states();
735
-        if (! empty($states)) {
734
+        if ( ! empty($states)) {
736 735
             foreach ($states as $state) {
737 736
                 if ($state instanceof EE_State) {
738 737
                     $state_options[$state->country()->name()][$state->ID()] = $state->name();
@@ -784,7 +783,7 @@  discard block
 block discarded – undo
784 783
             );
785 784
             return false;
786 785
         }
787
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
786
+        if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
788 787
             EE_Error::add_error(
789 788
                 esc_html__(
790 789
                     'A valid transaction could not be initiated for processing your registrations.',
@@ -801,10 +800,10 @@  discard block
 block discarded – undo
801 800
         // verify we got the goods
802 801
         if (empty($registrations)) {
803 802
             //combine the old translated string with a new one, in order to not break translations
804
-            $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' )
803
+            $error_message = esc_html__('Your form data could not be applied to any valid registrations.', 'event_espresso')
805 804
                              . sprintf(
806 805
                                  esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'),
807
-                                 '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
806
+                                 '<a href="'.get_post_type_archive_link('espresso_events').'" >',
808 807
                                  '</a>',
809 808
                                  '<br />'
810 809
                              );
@@ -823,7 +822,7 @@  discard block
 block discarded – undo
823 822
         if ($registrations_processed === false) {
824 823
             // but return immediately if the previous step exited early due to errors
825 824
             return false;
826
-        } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
825
+        } elseif ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
827 826
             // generate a correctly translated string for all possible singular/plural combinations
828 827
             if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
829 828
                 $error_msg = sprintf(
@@ -904,7 +903,7 @@  discard block
 block discarded – undo
904 903
         // grab the saved registrations from the transaction
905 904
         foreach ($registrations as $registration) {
906 905
             // verify EE_Registration object
907
-            if (! $registration instanceof EE_Registration) {
906
+            if ( ! $registration instanceof EE_Registration) {
908 907
                 EE_Error::add_error(
909 908
                     esc_html__(
910 909
                         'An invalid Registration object was discovered when attempting to process your registration information.',
@@ -919,12 +918,12 @@  discard block
 block discarded – undo
919 918
             /** @var string $reg_url_link */
920 919
             $reg_url_link = $registration->reg_url_link();
921 920
             // reg_url_link exists ?
922
-            if (! empty($reg_url_link)) {
921
+            if ( ! empty($reg_url_link)) {
923 922
                 // should this registration be processed during this visit ?
924 923
                 if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
925 924
                     // if NOT revisiting, then let's save the registration now,
926 925
                     // so that we have a REG_ID to use when generating other objects
927
-                    if (! $this->checkout->revisit) {
926
+                    if ( ! $this->checkout->revisit) {
928 927
                         $registration->save();
929 928
                     }
930 929
                     /**
@@ -959,7 +958,7 @@  discard block
 block discarded – undo
959 958
                             ? true
960 959
                             : false;
961 960
                         // filter form input data for this registration
962
-                        $valid_data[$reg_url_link] = (array)apply_filters(
961
+                        $valid_data[$reg_url_link] = (array) apply_filters(
963 962
                             'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
964 963
                             $valid_data[$reg_url_link]
965 964
                         );
@@ -971,11 +970,11 @@  discard block
 block discarded – undo
971 970
                         }
972 971
                         // now loop through our array of valid post data && process attendee reg forms
973 972
                         foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) {
974
-                            if (! in_array($form_section, $non_input_form_sections)) {
973
+                            if ( ! in_array($form_section, $non_input_form_sections)) {
975 974
                                 foreach ($form_inputs as $form_input => $input_value) {
976 975
                                     // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
977 976
                                     // check for critical inputs
978
-                                    if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
977
+                                    if ( ! $this->_verify_critical_attendee_details_are_set_and_validate_email(
979 978
                                         $form_input,
980 979
                                         $input_value
981 980
                                     )
@@ -995,7 +994,7 @@  discard block
 block discarded – undo
995 994
                                         $input_value = $primary_registrant[$form_input];
996 995
                                     }
997 996
                                     // now attempt to save the input data
998
-                                    if (! $this->_save_registration_form_input(
997
+                                    if ( ! $this->_save_registration_form_input(
999 998
                                         $registration,
1000 999
                                         $form_input,
1001 1000
                                         $input_value
@@ -1051,7 +1050,7 @@  discard block
 block discarded – undo
1051 1050
                     // add relation to registration, set attendee ID, and cache attendee
1052 1051
                     $this->_associate_attendee_with_registration($registration, $attendee);
1053 1052
                     // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1054
-                    if (! $registration->attendee() instanceof EE_Attendee) {
1053
+                    if ( ! $registration->attendee() instanceof EE_Attendee) {
1055 1054
                         EE_Error::add_error(
1056 1055
                             sprintf(
1057 1056
                                 esc_html__(
@@ -1146,7 +1145,7 @@  discard block
 block discarded – undo
1146 1145
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1147 1146
          */
1148 1147
         $answer_cache_id = $this->checkout->reg_url_link
1149
-            ? $form_input . '-' . $registration->reg_url_link()
1148
+            ? $form_input.'-'.$registration->reg_url_link()
1150 1149
             : $form_input;
1151 1150
         $answer_is_obj   = isset($this->_registration_answers[$answer_cache_id])
1152 1151
                            && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer
@@ -1167,10 +1166,10 @@  discard block
 block discarded – undo
1167 1166
                 break;
1168 1167
 
1169 1168
             default:
1170
-                $ATT_input = 'ATT_' . $form_input;
1169
+                $ATT_input = 'ATT_'.$form_input;
1171 1170
                 //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1172 1171
                 $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1173
-                $form_input        = $attendee_property ? 'ATT_' . $form_input : $form_input;
1172
+                $form_input        = $attendee_property ? 'ATT_'.$form_input : $form_input;
1174 1173
         }
1175 1174
         // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1176 1175
         // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
@@ -1215,7 +1214,7 @@  discard block
 block discarded – undo
1215 1214
     ) {
1216 1215
         if (empty($input_value)) {
1217 1216
             // if the form input isn't marked as being required, then just return
1218
-            if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1217
+            if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) {
1219 1218
                 return true;
1220 1219
             }
1221 1220
             switch ($form_input) {
@@ -1302,7 +1301,7 @@  discard block
 block discarded – undo
1302 1301
             'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1303 1302
             false
1304 1303
         )) {
1305
-            $address_details           = array(
1304
+            $address_details = array(
1306 1305
                 'ATT_address',
1307 1306
                 'ATT_address2',
1308 1307
                 'ATT_city',
@@ -1314,7 +1313,7 @@  discard block
 block discarded – undo
1314 1313
             $critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1315 1314
         }
1316 1315
         foreach ($critical_attendee_details as $critical_attendee_detail) {
1317
-            if (! isset($attendee_data[$critical_attendee_detail])
1316
+            if ( ! isset($attendee_data[$critical_attendee_detail])
1318 1317
                 || empty($attendee_data[$critical_attendee_detail])
1319 1318
             ) {
1320 1319
                 $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get(
Please login to merge, or discard this patch.
modules/ticket_sales_monitor/EED_Ticket_Sales_Monitor.module.php 3 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      *
327 327
      * @param    EE_Ticket $ticket
328 328
      * @param int          $quantity
329
-     * @return bool
329
+     * @return integer
330 330
      * @throws EE_Error
331 331
      */
332 332
     protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
     /**
344 344
      * @param  EE_Ticket $ticket
345 345
      * @param  int       $quantity
346
-     * @return bool
346
+     * @return integer
347 347
      * @throws EE_Error
348 348
      */
349 349
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
@@ -969,6 +969,7 @@  discard block
 block discarded – undo
969 969
     /**
970 970
      * @param EE_Ticket[]    $tickets_with_reservations
971 971
      * @param EE_Line_Item[] $valid_reserved_ticket_line_items
972
+     * @param string $source
972 973
      * @return int
973 974
      * @throws UnexpectedEntityException
974 975
      * @throws DomainException
Please login to merge, or discard this patch.
Indentation   +1043 added lines, -1043 removed lines patch added patch discarded remove patch
@@ -23,1050 +23,1050 @@
 block discarded – undo
23 23
 class EED_Ticket_Sales_Monitor extends EED_Module
24 24
 {
25 25
 
26
-    const debug = false;    //	true false
27
-
28
-    /**
29
-     * an array of raw ticket data from EED_Ticket_Selector
30
-     *
31
-     * @var array $ticket_selections
32
-     */
33
-    protected $ticket_selections = array();
34
-
35
-    /**
36
-     * the raw ticket data from EED_Ticket_Selector is organized in rows
37
-     * according to how they are displayed in the actual Ticket_Selector
38
-     * this tracks the current row being processed
39
-     *
40
-     * @var int $current_row
41
-     */
42
-    protected $current_row = 0;
43
-
44
-    /**
45
-     * an array for tracking names of tickets that have sold out
46
-     *
47
-     * @var array $sold_out_tickets
48
-     */
49
-    protected $sold_out_tickets = array();
50
-
51
-    /**
52
-     * an array for tracking names of tickets that have had their quantities reduced
53
-     *
54
-     * @var array $decremented_tickets
55
-     */
56
-    protected $decremented_tickets = array();
57
-
58
-
59
-
60
-    /**
61
-     * set_hooks - for hooking into EE Core, other modules, etc
62
-     *
63
-     * @return    void
64
-     */
65
-    public static function set_hooks()
66
-    {
67
-        // release tickets for expired carts
68
-        add_action(
69
-            'EED_Ticket_Selector__process_ticket_selections__before',
70
-            array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'),
71
-            1
72
-        );
73
-        // check ticket reserves AFTER MER does it's check (hence priority 20)
74
-        add_filter(
75
-            'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
76
-            array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
77
-            20,
78
-            3
79
-        );
80
-        // add notices for sold out tickets
81
-        add_action(
82
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
83
-            array('EED_Ticket_Sales_Monitor', 'post_notices'),
84
-            10
85
-        );
86
-        // handle ticket quantities adjusted in cart
87
-        //add_action(
88
-        //	'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated',
89
-        //	array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ),
90
-        //	10, 2
91
-        //);
92
-        // handle tickets deleted from cart
93
-        add_action(
94
-            'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
95
-            array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
96
-            10,
97
-            2
98
-        );
99
-        // handle emptied carts
100
-        add_action(
101
-            'AHEE__EE_Session__reset_cart__before_reset',
102
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
103
-            10,
104
-            1
105
-        );
106
-        add_action(
107
-            'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
108
-            array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
109
-            10,
110
-            1
111
-        );
112
-        // handle cancelled registrations
113
-        add_action(
114
-            'AHEE__EE_Session__reset_checkout__before_reset',
115
-            array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
116
-            10,
117
-            1
118
-        );
119
-        // cron tasks
120
-        add_action(
121
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
122
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
123
-            10,
124
-            1
125
-        );
126
-        add_action(
127
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
128
-            array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
129
-            10,
130
-            1
131
-        );
132
-        add_action(
133
-            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
134
-            array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
135
-            10,
136
-            1
137
-        );
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
144
-     *
145
-     * @return void
146
-     */
147
-    public static function set_hooks_admin()
148
-    {
149
-        EED_Ticket_Sales_Monitor::set_hooks();
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * @return EED_Ticket_Sales_Monitor|EED_Module
156
-     */
157
-    public static function instance()
158
-    {
159
-        return parent::get_instance(__CLASS__);
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * @param WP_Query $WP_Query
166
-     * @return    void
167
-     */
168
-    public function run($WP_Query)
169
-    {
170
-    }
171
-
172
-
173
-
174
-    /********************************** PRE_TICKET_SALES  **********************************/
175
-
176
-
177
-
178
-    /**
179
-     * Retrieves grand totals from the line items that have no TXN ID
180
-     * and timestamps less than the current time minus the session lifespan.
181
-     * These are carts that have been abandoned before the "registrant" even attempted to checkout.
182
-     * We're going to release the tickets for these line items before attempting to add more to the cart.
183
-     *
184
-     * @return void
185
-     * @throws DomainException
186
-     * @throws EE_Error
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidInterfaceException
190
-     * @throws UnexpectedEntityException
191
-     */
192
-    public static function release_tickets_for_expired_carts()
193
-    {
194
-        do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin');
195
-        $expired_ticket_IDs      = array();
196
-        $valid_ticket_line_items = array();
197
-        $total_line_items        = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction();
198
-        if (empty($total_line_items)) {
199
-            do_action(
200
-                'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
201
-                $total_line_items,
202
-                $valid_ticket_line_items,
203
-                $expired_ticket_IDs
204
-            );
205
-            return;
206
-        }
207
-        $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan();
208
-        foreach ($total_line_items as $total_line_item) {
209
-            /** @var EE_Line_Item $total_line_item */
210
-            $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
211
-            foreach ($ticket_line_items as $ticket_line_item) {
212
-                if (! $ticket_line_item instanceof EE_Line_Item) {
213
-                    continue;
214
-                }
215
-                if ($total_line_item->timestamp(true) <= $expired) {
216
-                    $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID();
217
-                } else {
218
-                    $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item;
219
-                }
220
-            }
221
-        }
222
-        if (! empty($expired_ticket_IDs)) {
223
-            EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
224
-                \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
225
-                $valid_ticket_line_items,
226
-                __FUNCTION__
227
-            );
228
-            // let's get rid of expired line items so that they can't interfere with tracking
229
-            add_action(
230
-                'shutdown',
231
-                array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'),
232
-                999
233
-            );
234
-        }
235
-        do_action(
236
-            'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
237
-            $total_line_items,
238
-            $valid_ticket_line_items,
239
-            $expired_ticket_IDs
240
-        );
241
-    }
242
-
243
-
244
-
245
-    /********************************** VALIDATE_TICKET_SALE  **********************************/
246
-
247
-
248
-
249
-    /**
250
-     * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
251
-     *
252
-     * @param int       $qty
253
-     * @param EE_Ticket $ticket
254
-     * @return bool
255
-     * @throws UnexpectedEntityException
256
-     * @throws EE_Error
257
-     */
258
-    public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
259
-    {
260
-        $qty = absint($qty);
261
-        if ($qty > 0) {
262
-            $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
263
-        }
264
-        if (self::debug) {
265
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
266
-            echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
267
-        }
268
-        return $qty;
269
-    }
270
-
271
-
272
-
273
-    /**
274
-     * checks whether an individual ticket is available for purchase based on datetime, and ticket details
275
-     *
276
-     * @param   EE_Ticket $ticket
277
-     * @param int         $qty
278
-     * @return int
279
-     * @throws UnexpectedEntityException
280
-     * @throws EE_Error
281
-     */
282
-    protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
283
-    {
284
-        if (self::debug) {
285
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
286
-        }
287
-        if (! $ticket instanceof EE_Ticket) {
288
-            return 0;
289
-        }
290
-        if (self::debug) {
291
-            echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
292
-            echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
293
-        }
294
-        $ticket->refresh_from_db();
295
-        // first let's determine the ticket availability based on sales
296
-        $available = $ticket->qty('saleable');
297
-        if (self::debug) {
298
-            echo '<br /> . . . ticket->qty: ' . $ticket->qty();
299
-            echo '<br /> . . . ticket->sold: ' . $ticket->sold();
300
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
301
-            echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
302
-            echo '<br /> . . . available: ' . $available;
303
-        }
304
-        if ($available < 1) {
305
-            $this->_ticket_sold_out($ticket);
306
-            return 0;
307
-        }
308
-        if (self::debug) {
309
-            echo '<br /> . . . qty: ' . $qty;
310
-        }
311
-        if ($available < $qty) {
312
-            $qty = $available;
313
-            if (self::debug) {
314
-                echo '<br /> . . . QTY ADJUSTED: ' . $qty;
315
-            }
316
-            $this->_ticket_quantity_decremented($ticket);
317
-        }
318
-        $this->_reserve_ticket($ticket, $qty);
319
-        return $qty;
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * increments ticket reserved based on quantity passed
326
-     *
327
-     * @param    EE_Ticket $ticket
328
-     * @param int          $quantity
329
-     * @return bool
330
-     * @throws EE_Error
331
-     */
332
-    protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
333
-    {
334
-        if (self::debug) {
335
-            echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
336
-        }
337
-        $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__);
338
-        return $ticket->save();
339
-    }
340
-
341
-
342
-
343
-    /**
344
-     * @param  EE_Ticket $ticket
345
-     * @param  int       $quantity
346
-     * @return bool
347
-     * @throws EE_Error
348
-     */
349
-    protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
350
-    {
351
-        if (self::debug) {
352
-            echo '<br /> . . . ticket->ID: ' . $ticket->ID();
353
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
354
-        }
355
-        $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__);
356
-        if (self::debug) {
357
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
358
-        }
359
-        return $ticket->save() ? 1 : 0;
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * removes quantities within the ticket selector based on zero ticket availability
366
-     *
367
-     * @param    EE_Ticket $ticket
368
-     * @return    void
369
-     * @throws UnexpectedEntityException
370
-     * @throws EE_Error
371
-     */
372
-    protected function _ticket_sold_out(EE_Ticket $ticket)
373
-    {
374
-        if (self::debug) {
375
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
376
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
377
-        }
378
-        $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * adjusts quantities within the ticket selector based on decreased ticket availability
385
-     *
386
-     * @param    EE_Ticket $ticket
387
-     * @return void
388
-     * @throws UnexpectedEntityException
389
-     * @throws EE_Error
390
-     */
391
-    protected function _ticket_quantity_decremented(EE_Ticket $ticket)
392
-    {
393
-        if (self::debug) {
394
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
395
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
396
-        }
397
-        $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     * builds string out of ticket and event name
404
-     *
405
-     * @param    EE_Ticket $ticket
406
-     * @return string
407
-     * @throws UnexpectedEntityException
408
-     * @throws EE_Error
409
-     */
410
-    protected function _get_ticket_and_event_name(EE_Ticket $ticket)
411
-    {
412
-        $event = $ticket->get_related_event();
413
-        if ($event instanceof EE_Event) {
414
-            $ticket_name = sprintf(
415
-                _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
416
-                $ticket->name(),
417
-                $event->name()
418
-            );
419
-        } else {
420
-            $ticket_name = $ticket->name();
421
-        }
422
-        return $ticket_name;
423
-    }
424
-
425
-
426
-
427
-    /********************************** EVENT CART  **********************************/
428
-
429
-
430
-
431
-    /**
432
-     * releases or reserves ticket(s) based on quantity passed
433
-     *
434
-     * @param  EE_Line_Item $line_item
435
-     * @param  int          $quantity
436
-     * @return void
437
-     * @throws EE_Error
438
-     * @throws InvalidArgumentException
439
-     * @throws InvalidDataTypeException
440
-     * @throws InvalidInterfaceException
441
-     */
442
-    public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
443
-    {
444
-        $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
445
-        if ($ticket instanceof EE_Ticket) {
446
-            $ticket->add_extra_meta(
447
-                EE_Ticket::META_KEY_TICKET_RESERVATIONS,
448
-                __LINE__ . ') ' . __METHOD__ . '()'
449
-            );
450
-            if ($quantity > 0) {
451
-                EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
452
-            } else {
453
-                EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
454
-            }
455
-        }
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * releases reserved ticket(s) based on quantity passed
462
-     *
463
-     * @param  EE_Ticket $ticket
464
-     * @param  int       $quantity
465
-     * @return void
466
-     * @throws EE_Error
467
-     */
468
-    public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
469
-    {
470
-        $ticket->add_extra_meta(
471
-            EE_Ticket::META_KEY_TICKET_RESERVATIONS,
472
-            __LINE__ . ') ' . __METHOD__ . '()'
473
-        );
474
-        EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
475
-    }
476
-
477
-
478
-
479
-    /********************************** POST_NOTICES  **********************************/
480
-
481
-
482
-
483
-    /**
484
-     * @return void
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws ReflectionException
488
-     * @throws InvalidDataTypeException
489
-     * @throws InvalidInterfaceException
490
-     */
491
-    public static function post_notices()
492
-    {
493
-        EED_Ticket_Sales_Monitor::instance()->_post_notices();
494
-    }
495
-
496
-
497
-
498
-    /**
499
-     * @return void
500
-     * @throws EE_Error
501
-     * @throws InvalidArgumentException
502
-     * @throws ReflectionException
503
-     * @throws InvalidDataTypeException
504
-     * @throws InvalidInterfaceException
505
-     */
506
-    protected function _post_notices()
507
-    {
508
-        if (self::debug) {
509
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
510
-        }
511
-        $refresh_msg    = '';
512
-        $none_added_msg = '';
513
-        if (defined('DOING_AJAX') && DOING_AJAX) {
514
-            $refresh_msg    = __(
515
-                'Please refresh the page to view updated ticket quantities.',
516
-                'event_espresso'
517
-            );
518
-            $none_added_msg = __('No tickets were added for the event.', 'event_espresso');
519
-        }
520
-        if (! empty($this->sold_out_tickets)) {
521
-            EE_Error::add_attention(
522
-                sprintf(
523
-                    apply_filters(
524
-                        'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
525
-                        __(
526
-                            'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
527
-                            'event_espresso'
528
-                        )
529
-                    ),
530
-                    '<br />',
531
-                    implode('<br />', $this->sold_out_tickets),
532
-                    $none_added_msg,
533
-                    $refresh_msg
534
-                )
535
-            );
536
-            // alter code flow in the Ticket Selector for better UX
537
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
538
-            add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
539
-            $this->sold_out_tickets = array();
540
-            // and reset the cart
541
-            EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
542
-        }
543
-        if (! empty($this->decremented_tickets)) {
544
-            EE_Error::add_attention(
545
-                sprintf(
546
-                    apply_filters(
547
-                        'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
548
-                        __(
549
-                            'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
550
-                            'event_espresso'
551
-                        )
552
-                    ),
553
-                    '<br />',
554
-                    implode('<br />', $this->decremented_tickets),
555
-                    $none_added_msg,
556
-                    $refresh_msg
557
-                )
558
-            );
559
-            $this->decremented_tickets = array();
560
-        }
561
-    }
562
-
563
-
564
-
565
-    /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
566
-
567
-
568
-
569
-    /**
570
-     * releases reserved tickets for all registrations of an EE_Transaction
571
-     * by default, will NOT release tickets for finalized transactions
572
-     *
573
-     * @param    EE_Transaction $transaction
574
-     * @return int
575
-     * @throws EE_Error
576
-     * @throws InvalidSessionDataException
577
-     */
578
-    protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
579
-    {
580
-        if (self::debug) {
581
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
582
-            echo '<br /> . transaction->ID: ' . $transaction->ID();
583
-            echo '<br /> . TXN status_ID: ' . $transaction->status_ID();
584
-        }
585
-        // check if 'finalize_registration' step has been completed...
586
-        $finalized = $transaction->reg_step_completed('finalize_registration');
587
-        if (self::debug) {
588
-            // DEBUG LOG
589
-            EEH_Debug_Tools::log(
590
-                __CLASS__,
591
-                __FUNCTION__,
592
-                __LINE__,
593
-                array('finalized' => $finalized),
594
-                false,
595
-                'EE_Transaction: ' . $transaction->ID()
596
-            );
597
-        }
598
-        // how many tickets were released
599
-        $count = 0;
600
-        if (self::debug) {
601
-            echo '<br /> . . . TXN finalized: ' . $finalized;
602
-        }
603
-        $release_tickets_with_TXN_status = array(
604
-            EEM_Transaction::failed_status_code,
605
-            EEM_Transaction::abandoned_status_code,
606
-            EEM_Transaction::incomplete_status_code,
607
-        );
608
-        $events = array();
609
-        // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed
610
-        if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
611
-            // cancel any reserved tickets for registrations that were not approved
612
-            $registrations = $transaction->registrations();
613
-            if (self::debug) {
614
-                echo '<br /> . . . # registrations: ' . count($registrations);
615
-                $reg    = reset($registrations);
616
-                $ticket = $reg->ticket();
617
-                if ($ticket instanceof EE_Ticket) {
618
-                    $ticket->add_extra_meta(
619
-                        EE_Ticket::META_KEY_TICKET_RESERVATIONS,
620
-                        __LINE__ . ') Release All Tickets TXN:' . $transaction->ID()
621
-                    );
622
-                }
623
-            }
624
-            if (! empty($registrations)) {
625
-                foreach ($registrations as $registration) {
626
-                    if (
627
-                        $registration instanceof EE_Registration
628
-                        && $this->_release_reserved_ticket_for_registration($registration, $transaction)
629
-                    ) {
630
-                        $count++;
631
-                        $events[ $registration->event_ID() ] = $registration->event();
632
-                    }
633
-                }
634
-            }
635
-        }
636
-        if ($events !== array()) {
637
-            foreach ($events as $event) {
638
-                /** @var EE_Event $event */
639
-                $event->perform_sold_out_status_check();
640
-            }
641
-        }
642
-        return $count;
643
-    }
644
-
645
-
646
-
647
-    /**
648
-     * releases reserved tickets for an EE_Registration
649
-     * by default, will NOT release tickets for APPROVED registrations
650
-     *
651
-     * @param EE_Registration $registration
652
-     * @param EE_Transaction  $transaction
653
-     * @return int
654
-     * @throws EE_Error
655
-     */
656
-    protected function _release_reserved_ticket_for_registration(
657
-        EE_Registration $registration,
658
-        EE_Transaction $transaction
659
-    ) {
660
-        $STS_ID = $transaction->status_ID();
661
-        if (self::debug) {
662
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
663
-            echo '<br /> . . registration->ID: ' . $registration->ID();
664
-            echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
665
-            echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
666
-        }
667
-        if (
668
-            // release Tickets for Failed Transactions and Abandoned Transactions
669
-            $STS_ID === EEM_Transaction::failed_status_code
670
-            || $STS_ID === EEM_Transaction::abandoned_status_code
671
-            || (
672
-                // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
673
-                $STS_ID === EEM_Transaction::incomplete_status_code
674
-                && $registration->status_ID() !== EEM_Registration::status_id_approved
675
-            )
676
-        ) {
677
-            if (self::debug) {
678
-                echo '<br /><br /> . . RELEASE RESERVED TICKET';
679
-                $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true);
680
-                echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: ';
681
-                var_dump($rsrvd);
682
-            }
683
-            $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__);
684
-            return 1;
685
-        }
686
-        return 0;
687
-    }
688
-
689
-
690
-
691
-    /********************************** SESSION_CART_RESET  **********************************/
692
-
693
-
694
-
695
-    /**
696
-     * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
697
-     *
698
-     * @param EE_Session $session
699
-     * @return void
700
-     * @throws EE_Error
701
-     * @throws InvalidArgumentException
702
-     * @throws ReflectionException
703
-     * @throws InvalidDataTypeException
704
-     * @throws InvalidInterfaceException
705
-     */
706
-    public static function session_cart_reset(EE_Session $session)
707
-    {
708
-        if (self::debug) {
709
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
710
-        }
711
-        // first check of the session has a valid Checkout object
712
-        $checkout = $session->checkout();
713
-        if ($checkout instanceof EE_Checkout) {
714
-            // and use that to clear ticket reservations because it will update the associated registration meta data
715
-            EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
716
-            return;
717
-        }
718
-        $cart = $session->cart();
719
-        if ($cart instanceof EE_Cart) {
720
-            if (self::debug) {
721
-                echo '<br /><br /> cart instance of EE_Cart: ';
722
-            }
723
-            EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session);
724
-        } else {
725
-            if (self::debug) {
726
-                echo '<br /><br /> invalid EE_Cart: ';
727
-                var_export($cart, true);
728
-            }
729
-        }
730
-    }
731
-
732
-
733
-
734
-    /**
735
-     * releases reserved tickets in the EE_Cart
736
-     *
737
-     * @param EE_Cart $cart
738
-     * @return void
739
-     * @throws EE_Error
740
-     * @throws InvalidArgumentException
741
-     * @throws ReflectionException
742
-     * @throws InvalidDataTypeException
743
-     * @throws InvalidInterfaceException
744
-     */
745
-    protected function _session_cart_reset(EE_Cart $cart, EE_Session $session)
746
-    {
747
-        if (self::debug) {
748
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
749
-        }
750
-        EE_Registry::instance()->load_helper('Line_Item');
751
-        $ticket_line_items = $cart->get_tickets();
752
-        if (empty($ticket_line_items)) {
753
-            return;
754
-        }
755
-        foreach ($ticket_line_items as $ticket_line_item) {
756
-            if (self::debug) {
757
-                echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
758
-            }
759
-            if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
760
-                if (self::debug) {
761
-                    echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
762
-                }
763
-                $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
764
-                if ($ticket instanceof EE_Ticket) {
765
-                    if (self::debug) {
766
-                        echo '<br /> . . ticket->ID(): ' . $ticket->ID();
767
-                        echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
768
-                    }
769
-                    $ticket->add_extra_meta(
770
-                        EE_Ticket::META_KEY_TICKET_RESERVATIONS,
771
-                        __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id()
772
-                    );
773
-                    $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
774
-                }
775
-            }
776
-        }
777
-        if (self::debug) {
778
-            echo '<br /><br /> RESET COMPLETED ';
779
-        }
780
-    }
781
-
782
-
783
-
784
-    /********************************** SESSION_CHECKOUT_RESET  **********************************/
785
-
786
-
787
-
788
-    /**
789
-     * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
790
-     *
791
-     * @param EE_Session $session
792
-     * @return void
793
-     * @throws EE_Error
794
-     * @throws InvalidSessionDataException
795
-     */
796
-    public static function session_checkout_reset(EE_Session $session)
797
-    {
798
-        $checkout = $session->checkout();
799
-        if ($checkout instanceof EE_Checkout) {
800
-            EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
801
-        }
802
-    }
803
-
804
-
805
-
806
-    /**
807
-     * releases reserved tickets for the EE_Checkout->transaction
808
-     *
809
-     * @param EE_Checkout $checkout
810
-     * @return void
811
-     * @throws EE_Error
812
-     * @throws InvalidSessionDataException
813
-     */
814
-    protected function _session_checkout_reset(EE_Checkout $checkout)
815
-    {
816
-        if (self::debug) {
817
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
818
-        }
819
-        // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
820
-        if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
821
-            return;
822
-        }
823
-        $this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
824
-    }
825
-
826
-
827
-
828
-    /********************************** SESSION_EXPIRED_RESET  **********************************/
829
-
830
-
831
-
832
-    /**
833
-     * @param    EE_Session $session
834
-     * @return    void
835
-     */
836
-    public static function session_expired_reset(EE_Session $session)
837
-    {
838
-    }
839
-
840
-
841
-
842
-    /********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
843
-
844
-
845
-
846
-    /**
847
-     * releases reserved tickets for all registrations of an ABANDONED EE_Transaction
848
-     * by default, will NOT release tickets for free transactions, or any that have received a payment
849
-     *
850
-     * @param EE_Transaction $transaction
851
-     * @return void
852
-     * @throws EE_Error
853
-     * @throws InvalidSessionDataException
854
-     */
855
-    public static function process_abandoned_transactions(EE_Transaction $transaction)
856
-    {
857
-        // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
858
-        if ($transaction->is_free() || $transaction->paid() > 0) {
859
-            if (self::debug) {
860
-                // DEBUG LOG
861
-                EEH_Debug_Tools::log(
862
-                    __CLASS__,
863
-                    __FUNCTION__,
864
-                    __LINE__,
865
-                    array($transaction),
866
-                    false,
867
-                    'EE_Transaction: ' . $transaction->ID()
868
-                );
869
-            }
870
-            return;
871
-        }
872
-        // have their been any successful payments made ?
873
-        $payments = $transaction->payments();
874
-        foreach ($payments as $payment) {
875
-            if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
876
-                if (self::debug) {
877
-                    // DEBUG LOG
878
-                    EEH_Debug_Tools::log(
879
-                        __CLASS__,
880
-                        __FUNCTION__,
881
-                        __LINE__,
882
-                        array($payment),
883
-                        false,
884
-                        'EE_Transaction: ' . $transaction->ID()
885
-                    );
886
-                }
887
-                return;
888
-            }
889
-        }
890
-        // since you haven't even attempted to pay for your ticket...
891
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
892
-    }
893
-
894
-
895
-
896
-    /********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
897
-
898
-
899
-
900
-    /**
901
-     * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
902
-     *
903
-     * @param EE_Transaction $transaction
904
-     * @return void
905
-     * @throws EE_Error
906
-     * @throws InvalidSessionDataException
907
-     */
908
-    public static function process_failed_transactions(EE_Transaction $transaction)
909
-    {
910
-        // since you haven't even attempted to pay for your ticket...
911
-        EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
912
-    }
913
-
914
-
915
-
916
-    /********************************** RESET RESERVATION COUNTS  *********************************/
917
-
918
-
919
-
920
-    /**
921
-     * Resets all ticket and datetime reserved counts to zero
922
-     * Tickets that are currently associated with a Transaction that is in progress
923
-     *
924
-     * @throws EE_Error
925
-     * @throws DomainException
926
-     * @throws InvalidDataTypeException
927
-     * @throws InvalidInterfaceException
928
-     * @throws InvalidArgumentException
929
-     * @throws UnexpectedEntityException
930
-     */
931
-    public static function reset_reservation_counts()
932
-    {
933
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
934
-        $valid_reserved_tickets = array();
935
-        /** @var EE_Transaction[] $transactions_not_in_progress */
936
-        $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress();
937
-        foreach ($transactions_not_in_progress as $transaction) {
938
-            // if this TXN has been fully completed, then skip it
939
-            if ($transaction->reg_step_completed('finalize_registration')) {
940
-                continue;
941
-            }
942
-            $total_line_item = $transaction->total_line_item();
943
-            // $transaction_in_progress->line
944
-            if (! $total_line_item instanceof EE_Line_Item) {
945
-                throw new DomainException(
946
-                    esc_html__(
947
-                        'Transaction does not have a valid Total Line Item associated with it.',
948
-                        'event_espresso'
949
-                    )
950
-                );
951
-            }
952
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
953
-                $total_line_item
954
-            );
955
-        }
956
-        $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts();
957
-        foreach ($total_line_items as $total_line_item) {
958
-            $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
959
-                $total_line_item
960
-            );
961
-        }
962
-        $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations();
963
-        return EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
964
-            $tickets_with_reservations,
965
-            $valid_reserved_tickets,
966
-            __FUNCTION__
967
-        );
968
-    }
969
-
970
-
971
-
972
-    /**
973
-     * @param EE_Line_Item $total_line_item
974
-     * @return EE_Line_Item[]
975
-     */
976
-    private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item)
977
-    {
978
-        /** @var EE_Line_Item[] $valid_reserved_tickets */
979
-        $valid_reserved_tickets = array();
980
-        $ticket_line_items      = EEH_Line_Item::get_ticket_line_items($total_line_item);
981
-        foreach ($ticket_line_items as $ticket_line_item) {
982
-            if ($ticket_line_item instanceof EE_Line_Item) {
983
-                $valid_reserved_tickets[] = $ticket_line_item;
984
-            }
985
-        }
986
-        return $valid_reserved_tickets;
987
-    }
988
-
989
-
990
-
991
-    /**
992
-     * @param EE_Ticket[]    $tickets_with_reservations
993
-     * @param EE_Line_Item[] $valid_reserved_ticket_line_items
994
-     * @return int
995
-     * @throws UnexpectedEntityException
996
-     * @throws DomainException
997
-     * @throws EE_Error
998
-     */
999
-    private static function release_reservations_for_tickets(
1000
-        array $tickets_with_reservations,
1001
-        array $valid_reserved_ticket_line_items = array(),
1002
-        $source
1003
-    ) {
1004
-        $total_tickets_released = 0;
1005
-        $sold_out_events = array();
1006
-        foreach ($tickets_with_reservations as $ticket_with_reservations) {
1007
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
1008
-                continue;
1009
-            }
1010
-            $reserved_qty = $ticket_with_reservations->reserved();
1011
-            foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) {
1012
-                if (
1013
-                    $valid_reserved_ticket_line_item instanceof EE_Line_Item
1014
-                    && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID()
1015
-                ) {
1016
-                    $reserved_qty -= $valid_reserved_ticket_line_item->quantity();
1017
-                }
1018
-            }
1019
-            if ($reserved_qty > 0) {
1020
-                $ticket_with_reservations->add_extra_meta(
1021
-                    EE_Ticket::META_KEY_TICKET_RESERVATIONS,
1022
-                    __LINE__ . ') ' . $source . '()'
1023
-                );
1024
-                $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__);
1025
-                $ticket_with_reservations->save();
1026
-                $total_tickets_released += $reserved_qty;
1027
-                $event = $ticket_with_reservations->get_related_event();
1028
-                // track sold out events
1029
-                if ($event instanceof EE_Event && $event->is_sold_out()) {
1030
-                    $sold_out_events[] = $event;
1031
-                }
1032
-            }
1033
-        }
1034
-        // double check whether sold out events should remain sold out after releasing tickets
1035
-        if($sold_out_events !== array()){
1036
-            foreach ($sold_out_events as $sold_out_event) {
1037
-                /** @var EE_Event $sold_out_event */
1038
-                $sold_out_event->perform_sold_out_status_check();
1039
-            }
1040
-        }
1041
-        return $total_tickets_released;
1042
-    }
1043
-
1044
-
1045
-
1046
-    /********************************** SHUTDOWN  **********************************/
1047
-
1048
-
1049
-
1050
-    /**
1051
-     * @return false|int
1052
-     * @throws EE_Error
1053
-     * @throws InvalidArgumentException
1054
-     * @throws InvalidDataTypeException
1055
-     * @throws InvalidInterfaceException
1056
-     */
1057
-    public static function clear_expired_line_items_with_no_transaction()
1058
-    {
1059
-        /** @type WPDB $wpdb */
1060
-        global $wpdb;
1061
-        return $wpdb->query(
1062
-            $wpdb->prepare(
1063
-                'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
26
+	const debug = false;    //	true false
27
+
28
+	/**
29
+	 * an array of raw ticket data from EED_Ticket_Selector
30
+	 *
31
+	 * @var array $ticket_selections
32
+	 */
33
+	protected $ticket_selections = array();
34
+
35
+	/**
36
+	 * the raw ticket data from EED_Ticket_Selector is organized in rows
37
+	 * according to how they are displayed in the actual Ticket_Selector
38
+	 * this tracks the current row being processed
39
+	 *
40
+	 * @var int $current_row
41
+	 */
42
+	protected $current_row = 0;
43
+
44
+	/**
45
+	 * an array for tracking names of tickets that have sold out
46
+	 *
47
+	 * @var array $sold_out_tickets
48
+	 */
49
+	protected $sold_out_tickets = array();
50
+
51
+	/**
52
+	 * an array for tracking names of tickets that have had their quantities reduced
53
+	 *
54
+	 * @var array $decremented_tickets
55
+	 */
56
+	protected $decremented_tickets = array();
57
+
58
+
59
+
60
+	/**
61
+	 * set_hooks - for hooking into EE Core, other modules, etc
62
+	 *
63
+	 * @return    void
64
+	 */
65
+	public static function set_hooks()
66
+	{
67
+		// release tickets for expired carts
68
+		add_action(
69
+			'EED_Ticket_Selector__process_ticket_selections__before',
70
+			array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'),
71
+			1
72
+		);
73
+		// check ticket reserves AFTER MER does it's check (hence priority 20)
74
+		add_filter(
75
+			'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty',
76
+			array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'),
77
+			20,
78
+			3
79
+		);
80
+		// add notices for sold out tickets
81
+		add_action(
82
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
83
+			array('EED_Ticket_Sales_Monitor', 'post_notices'),
84
+			10
85
+		);
86
+		// handle ticket quantities adjusted in cart
87
+		//add_action(
88
+		//	'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated',
89
+		//	array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ),
90
+		//	10, 2
91
+		//);
92
+		// handle tickets deleted from cart
93
+		add_action(
94
+			'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart',
95
+			array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'),
96
+			10,
97
+			2
98
+		);
99
+		// handle emptied carts
100
+		add_action(
101
+			'AHEE__EE_Session__reset_cart__before_reset',
102
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
103
+			10,
104
+			1
105
+		);
106
+		add_action(
107
+			'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart',
108
+			array('EED_Ticket_Sales_Monitor', 'session_cart_reset'),
109
+			10,
110
+			1
111
+		);
112
+		// handle cancelled registrations
113
+		add_action(
114
+			'AHEE__EE_Session__reset_checkout__before_reset',
115
+			array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'),
116
+			10,
117
+			1
118
+		);
119
+		// cron tasks
120
+		add_action(
121
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
122
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
123
+			10,
124
+			1
125
+		);
126
+		add_action(
127
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
128
+			array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'),
129
+			10,
130
+			1
131
+		);
132
+		add_action(
133
+			'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
134
+			array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'),
135
+			10,
136
+			1
137
+		);
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
144
+	 *
145
+	 * @return void
146
+	 */
147
+	public static function set_hooks_admin()
148
+	{
149
+		EED_Ticket_Sales_Monitor::set_hooks();
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * @return EED_Ticket_Sales_Monitor|EED_Module
156
+	 */
157
+	public static function instance()
158
+	{
159
+		return parent::get_instance(__CLASS__);
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * @param WP_Query $WP_Query
166
+	 * @return    void
167
+	 */
168
+	public function run($WP_Query)
169
+	{
170
+	}
171
+
172
+
173
+
174
+	/********************************** PRE_TICKET_SALES  **********************************/
175
+
176
+
177
+
178
+	/**
179
+	 * Retrieves grand totals from the line items that have no TXN ID
180
+	 * and timestamps less than the current time minus the session lifespan.
181
+	 * These are carts that have been abandoned before the "registrant" even attempted to checkout.
182
+	 * We're going to release the tickets for these line items before attempting to add more to the cart.
183
+	 *
184
+	 * @return void
185
+	 * @throws DomainException
186
+	 * @throws EE_Error
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidInterfaceException
190
+	 * @throws UnexpectedEntityException
191
+	 */
192
+	public static function release_tickets_for_expired_carts()
193
+	{
194
+		do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin');
195
+		$expired_ticket_IDs      = array();
196
+		$valid_ticket_line_items = array();
197
+		$total_line_items        = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction();
198
+		if (empty($total_line_items)) {
199
+			do_action(
200
+				'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
201
+				$total_line_items,
202
+				$valid_ticket_line_items,
203
+				$expired_ticket_IDs
204
+			);
205
+			return;
206
+		}
207
+		$expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan();
208
+		foreach ($total_line_items as $total_line_item) {
209
+			/** @var EE_Line_Item $total_line_item */
210
+			$ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
211
+			foreach ($ticket_line_items as $ticket_line_item) {
212
+				if (! $ticket_line_item instanceof EE_Line_Item) {
213
+					continue;
214
+				}
215
+				if ($total_line_item->timestamp(true) <= $expired) {
216
+					$expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID();
217
+				} else {
218
+					$valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item;
219
+				}
220
+			}
221
+		}
222
+		if (! empty($expired_ticket_IDs)) {
223
+			EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
224
+				\EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
225
+				$valid_ticket_line_items,
226
+				__FUNCTION__
227
+			);
228
+			// let's get rid of expired line items so that they can't interfere with tracking
229
+			add_action(
230
+				'shutdown',
231
+				array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'),
232
+				999
233
+			);
234
+		}
235
+		do_action(
236
+			'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end',
237
+			$total_line_items,
238
+			$valid_ticket_line_items,
239
+			$expired_ticket_IDs
240
+		);
241
+	}
242
+
243
+
244
+
245
+	/********************************** VALIDATE_TICKET_SALE  **********************************/
246
+
247
+
248
+
249
+	/**
250
+	 * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data'
251
+	 *
252
+	 * @param int       $qty
253
+	 * @param EE_Ticket $ticket
254
+	 * @return bool
255
+	 * @throws UnexpectedEntityException
256
+	 * @throws EE_Error
257
+	 */
258
+	public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket)
259
+	{
260
+		$qty = absint($qty);
261
+		if ($qty > 0) {
262
+			$qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
263
+		}
264
+		if (self::debug) {
265
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
266
+			echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
267
+		}
268
+		return $qty;
269
+	}
270
+
271
+
272
+
273
+	/**
274
+	 * checks whether an individual ticket is available for purchase based on datetime, and ticket details
275
+	 *
276
+	 * @param   EE_Ticket $ticket
277
+	 * @param int         $qty
278
+	 * @return int
279
+	 * @throws UnexpectedEntityException
280
+	 * @throws EE_Error
281
+	 */
282
+	protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
283
+	{
284
+		if (self::debug) {
285
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
286
+		}
287
+		if (! $ticket instanceof EE_Ticket) {
288
+			return 0;
289
+		}
290
+		if (self::debug) {
291
+			echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
292
+			echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
293
+		}
294
+		$ticket->refresh_from_db();
295
+		// first let's determine the ticket availability based on sales
296
+		$available = $ticket->qty('saleable');
297
+		if (self::debug) {
298
+			echo '<br /> . . . ticket->qty: ' . $ticket->qty();
299
+			echo '<br /> . . . ticket->sold: ' . $ticket->sold();
300
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
301
+			echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
302
+			echo '<br /> . . . available: ' . $available;
303
+		}
304
+		if ($available < 1) {
305
+			$this->_ticket_sold_out($ticket);
306
+			return 0;
307
+		}
308
+		if (self::debug) {
309
+			echo '<br /> . . . qty: ' . $qty;
310
+		}
311
+		if ($available < $qty) {
312
+			$qty = $available;
313
+			if (self::debug) {
314
+				echo '<br /> . . . QTY ADJUSTED: ' . $qty;
315
+			}
316
+			$this->_ticket_quantity_decremented($ticket);
317
+		}
318
+		$this->_reserve_ticket($ticket, $qty);
319
+		return $qty;
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * increments ticket reserved based on quantity passed
326
+	 *
327
+	 * @param    EE_Ticket $ticket
328
+	 * @param int          $quantity
329
+	 * @return bool
330
+	 * @throws EE_Error
331
+	 */
332
+	protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
333
+	{
334
+		if (self::debug) {
335
+			echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
336
+		}
337
+		$ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__);
338
+		return $ticket->save();
339
+	}
340
+
341
+
342
+
343
+	/**
344
+	 * @param  EE_Ticket $ticket
345
+	 * @param  int       $quantity
346
+	 * @return bool
347
+	 * @throws EE_Error
348
+	 */
349
+	protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
350
+	{
351
+		if (self::debug) {
352
+			echo '<br /> . . . ticket->ID: ' . $ticket->ID();
353
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
354
+		}
355
+		$ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__);
356
+		if (self::debug) {
357
+			echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
358
+		}
359
+		return $ticket->save() ? 1 : 0;
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * removes quantities within the ticket selector based on zero ticket availability
366
+	 *
367
+	 * @param    EE_Ticket $ticket
368
+	 * @return    void
369
+	 * @throws UnexpectedEntityException
370
+	 * @throws EE_Error
371
+	 */
372
+	protected function _ticket_sold_out(EE_Ticket $ticket)
373
+	{
374
+		if (self::debug) {
375
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
376
+			echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
377
+		}
378
+		$this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * adjusts quantities within the ticket selector based on decreased ticket availability
385
+	 *
386
+	 * @param    EE_Ticket $ticket
387
+	 * @return void
388
+	 * @throws UnexpectedEntityException
389
+	 * @throws EE_Error
390
+	 */
391
+	protected function _ticket_quantity_decremented(EE_Ticket $ticket)
392
+	{
393
+		if (self::debug) {
394
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
395
+			echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
396
+		}
397
+		$this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 * builds string out of ticket and event name
404
+	 *
405
+	 * @param    EE_Ticket $ticket
406
+	 * @return string
407
+	 * @throws UnexpectedEntityException
408
+	 * @throws EE_Error
409
+	 */
410
+	protected function _get_ticket_and_event_name(EE_Ticket $ticket)
411
+	{
412
+		$event = $ticket->get_related_event();
413
+		if ($event instanceof EE_Event) {
414
+			$ticket_name = sprintf(
415
+				_x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'),
416
+				$ticket->name(),
417
+				$event->name()
418
+			);
419
+		} else {
420
+			$ticket_name = $ticket->name();
421
+		}
422
+		return $ticket_name;
423
+	}
424
+
425
+
426
+
427
+	/********************************** EVENT CART  **********************************/
428
+
429
+
430
+
431
+	/**
432
+	 * releases or reserves ticket(s) based on quantity passed
433
+	 *
434
+	 * @param  EE_Line_Item $line_item
435
+	 * @param  int          $quantity
436
+	 * @return void
437
+	 * @throws EE_Error
438
+	 * @throws InvalidArgumentException
439
+	 * @throws InvalidDataTypeException
440
+	 * @throws InvalidInterfaceException
441
+	 */
442
+	public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1)
443
+	{
444
+		$ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID()));
445
+		if ($ticket instanceof EE_Ticket) {
446
+			$ticket->add_extra_meta(
447
+				EE_Ticket::META_KEY_TICKET_RESERVATIONS,
448
+				__LINE__ . ') ' . __METHOD__ . '()'
449
+			);
450
+			if ($quantity > 0) {
451
+				EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
452
+			} else {
453
+				EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
454
+			}
455
+		}
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * releases reserved ticket(s) based on quantity passed
462
+	 *
463
+	 * @param  EE_Ticket $ticket
464
+	 * @param  int       $quantity
465
+	 * @return void
466
+	 * @throws EE_Error
467
+	 */
468
+	public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1)
469
+	{
470
+		$ticket->add_extra_meta(
471
+			EE_Ticket::META_KEY_TICKET_RESERVATIONS,
472
+			__LINE__ . ') ' . __METHOD__ . '()'
473
+		);
474
+		EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
475
+	}
476
+
477
+
478
+
479
+	/********************************** POST_NOTICES  **********************************/
480
+
481
+
482
+
483
+	/**
484
+	 * @return void
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws ReflectionException
488
+	 * @throws InvalidDataTypeException
489
+	 * @throws InvalidInterfaceException
490
+	 */
491
+	public static function post_notices()
492
+	{
493
+		EED_Ticket_Sales_Monitor::instance()->_post_notices();
494
+	}
495
+
496
+
497
+
498
+	/**
499
+	 * @return void
500
+	 * @throws EE_Error
501
+	 * @throws InvalidArgumentException
502
+	 * @throws ReflectionException
503
+	 * @throws InvalidDataTypeException
504
+	 * @throws InvalidInterfaceException
505
+	 */
506
+	protected function _post_notices()
507
+	{
508
+		if (self::debug) {
509
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
510
+		}
511
+		$refresh_msg    = '';
512
+		$none_added_msg = '';
513
+		if (defined('DOING_AJAX') && DOING_AJAX) {
514
+			$refresh_msg    = __(
515
+				'Please refresh the page to view updated ticket quantities.',
516
+				'event_espresso'
517
+			);
518
+			$none_added_msg = __('No tickets were added for the event.', 'event_espresso');
519
+		}
520
+		if (! empty($this->sold_out_tickets)) {
521
+			EE_Error::add_attention(
522
+				sprintf(
523
+					apply_filters(
524
+						'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice',
525
+						__(
526
+							'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
527
+							'event_espresso'
528
+						)
529
+					),
530
+					'<br />',
531
+					implode('<br />', $this->sold_out_tickets),
532
+					$none_added_msg,
533
+					$refresh_msg
534
+				)
535
+			);
536
+			// alter code flow in the Ticket Selector for better UX
537
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true');
538
+			add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false');
539
+			$this->sold_out_tickets = array();
540
+			// and reset the cart
541
+			EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
542
+		}
543
+		if (! empty($this->decremented_tickets)) {
544
+			EE_Error::add_attention(
545
+				sprintf(
546
+					apply_filters(
547
+						'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice',
548
+						__(
549
+							'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s',
550
+							'event_espresso'
551
+						)
552
+					),
553
+					'<br />',
554
+					implode('<br />', $this->decremented_tickets),
555
+					$none_added_msg,
556
+					$refresh_msg
557
+				)
558
+			);
559
+			$this->decremented_tickets = array();
560
+		}
561
+	}
562
+
563
+
564
+
565
+	/********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION  **********************************/
566
+
567
+
568
+
569
+	/**
570
+	 * releases reserved tickets for all registrations of an EE_Transaction
571
+	 * by default, will NOT release tickets for finalized transactions
572
+	 *
573
+	 * @param    EE_Transaction $transaction
574
+	 * @return int
575
+	 * @throws EE_Error
576
+	 * @throws InvalidSessionDataException
577
+	 */
578
+	protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
579
+	{
580
+		if (self::debug) {
581
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
582
+			echo '<br /> . transaction->ID: ' . $transaction->ID();
583
+			echo '<br /> . TXN status_ID: ' . $transaction->status_ID();
584
+		}
585
+		// check if 'finalize_registration' step has been completed...
586
+		$finalized = $transaction->reg_step_completed('finalize_registration');
587
+		if (self::debug) {
588
+			// DEBUG LOG
589
+			EEH_Debug_Tools::log(
590
+				__CLASS__,
591
+				__FUNCTION__,
592
+				__LINE__,
593
+				array('finalized' => $finalized),
594
+				false,
595
+				'EE_Transaction: ' . $transaction->ID()
596
+			);
597
+		}
598
+		// how many tickets were released
599
+		$count = 0;
600
+		if (self::debug) {
601
+			echo '<br /> . . . TXN finalized: ' . $finalized;
602
+		}
603
+		$release_tickets_with_TXN_status = array(
604
+			EEM_Transaction::failed_status_code,
605
+			EEM_Transaction::abandoned_status_code,
606
+			EEM_Transaction::incomplete_status_code,
607
+		);
608
+		$events = array();
609
+		// if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed
610
+		if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
611
+			// cancel any reserved tickets for registrations that were not approved
612
+			$registrations = $transaction->registrations();
613
+			if (self::debug) {
614
+				echo '<br /> . . . # registrations: ' . count($registrations);
615
+				$reg    = reset($registrations);
616
+				$ticket = $reg->ticket();
617
+				if ($ticket instanceof EE_Ticket) {
618
+					$ticket->add_extra_meta(
619
+						EE_Ticket::META_KEY_TICKET_RESERVATIONS,
620
+						__LINE__ . ') Release All Tickets TXN:' . $transaction->ID()
621
+					);
622
+				}
623
+			}
624
+			if (! empty($registrations)) {
625
+				foreach ($registrations as $registration) {
626
+					if (
627
+						$registration instanceof EE_Registration
628
+						&& $this->_release_reserved_ticket_for_registration($registration, $transaction)
629
+					) {
630
+						$count++;
631
+						$events[ $registration->event_ID() ] = $registration->event();
632
+					}
633
+				}
634
+			}
635
+		}
636
+		if ($events !== array()) {
637
+			foreach ($events as $event) {
638
+				/** @var EE_Event $event */
639
+				$event->perform_sold_out_status_check();
640
+			}
641
+		}
642
+		return $count;
643
+	}
644
+
645
+
646
+
647
+	/**
648
+	 * releases reserved tickets for an EE_Registration
649
+	 * by default, will NOT release tickets for APPROVED registrations
650
+	 *
651
+	 * @param EE_Registration $registration
652
+	 * @param EE_Transaction  $transaction
653
+	 * @return int
654
+	 * @throws EE_Error
655
+	 */
656
+	protected function _release_reserved_ticket_for_registration(
657
+		EE_Registration $registration,
658
+		EE_Transaction $transaction
659
+	) {
660
+		$STS_ID = $transaction->status_ID();
661
+		if (self::debug) {
662
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
663
+			echo '<br /> . . registration->ID: ' . $registration->ID();
664
+			echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
665
+			echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
666
+		}
667
+		if (
668
+			// release Tickets for Failed Transactions and Abandoned Transactions
669
+			$STS_ID === EEM_Transaction::failed_status_code
670
+			|| $STS_ID === EEM_Transaction::abandoned_status_code
671
+			|| (
672
+				// also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved
673
+				$STS_ID === EEM_Transaction::incomplete_status_code
674
+				&& $registration->status_ID() !== EEM_Registration::status_id_approved
675
+			)
676
+		) {
677
+			if (self::debug) {
678
+				echo '<br /><br /> . . RELEASE RESERVED TICKET';
679
+				$rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true);
680
+				echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: ';
681
+				var_dump($rsrvd);
682
+			}
683
+			$registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__);
684
+			return 1;
685
+		}
686
+		return 0;
687
+	}
688
+
689
+
690
+
691
+	/********************************** SESSION_CART_RESET  **********************************/
692
+
693
+
694
+
695
+	/**
696
+	 * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset'
697
+	 *
698
+	 * @param EE_Session $session
699
+	 * @return void
700
+	 * @throws EE_Error
701
+	 * @throws InvalidArgumentException
702
+	 * @throws ReflectionException
703
+	 * @throws InvalidDataTypeException
704
+	 * @throws InvalidInterfaceException
705
+	 */
706
+	public static function session_cart_reset(EE_Session $session)
707
+	{
708
+		if (self::debug) {
709
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
710
+		}
711
+		// first check of the session has a valid Checkout object
712
+		$checkout = $session->checkout();
713
+		if ($checkout instanceof EE_Checkout) {
714
+			// and use that to clear ticket reservations because it will update the associated registration meta data
715
+			EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
716
+			return;
717
+		}
718
+		$cart = $session->cart();
719
+		if ($cart instanceof EE_Cart) {
720
+			if (self::debug) {
721
+				echo '<br /><br /> cart instance of EE_Cart: ';
722
+			}
723
+			EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session);
724
+		} else {
725
+			if (self::debug) {
726
+				echo '<br /><br /> invalid EE_Cart: ';
727
+				var_export($cart, true);
728
+			}
729
+		}
730
+	}
731
+
732
+
733
+
734
+	/**
735
+	 * releases reserved tickets in the EE_Cart
736
+	 *
737
+	 * @param EE_Cart $cart
738
+	 * @return void
739
+	 * @throws EE_Error
740
+	 * @throws InvalidArgumentException
741
+	 * @throws ReflectionException
742
+	 * @throws InvalidDataTypeException
743
+	 * @throws InvalidInterfaceException
744
+	 */
745
+	protected function _session_cart_reset(EE_Cart $cart, EE_Session $session)
746
+	{
747
+		if (self::debug) {
748
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
749
+		}
750
+		EE_Registry::instance()->load_helper('Line_Item');
751
+		$ticket_line_items = $cart->get_tickets();
752
+		if (empty($ticket_line_items)) {
753
+			return;
754
+		}
755
+		foreach ($ticket_line_items as $ticket_line_item) {
756
+			if (self::debug) {
757
+				echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
758
+			}
759
+			if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
760
+				if (self::debug) {
761
+					echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
762
+				}
763
+				$ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
764
+				if ($ticket instanceof EE_Ticket) {
765
+					if (self::debug) {
766
+						echo '<br /> . . ticket->ID(): ' . $ticket->ID();
767
+						echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
768
+					}
769
+					$ticket->add_extra_meta(
770
+						EE_Ticket::META_KEY_TICKET_RESERVATIONS,
771
+						__LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id()
772
+					);
773
+					$this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
774
+				}
775
+			}
776
+		}
777
+		if (self::debug) {
778
+			echo '<br /><br /> RESET COMPLETED ';
779
+		}
780
+	}
781
+
782
+
783
+
784
+	/********************************** SESSION_CHECKOUT_RESET  **********************************/
785
+
786
+
787
+
788
+	/**
789
+	 * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset'
790
+	 *
791
+	 * @param EE_Session $session
792
+	 * @return void
793
+	 * @throws EE_Error
794
+	 * @throws InvalidSessionDataException
795
+	 */
796
+	public static function session_checkout_reset(EE_Session $session)
797
+	{
798
+		$checkout = $session->checkout();
799
+		if ($checkout instanceof EE_Checkout) {
800
+			EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout);
801
+		}
802
+	}
803
+
804
+
805
+
806
+	/**
807
+	 * releases reserved tickets for the EE_Checkout->transaction
808
+	 *
809
+	 * @param EE_Checkout $checkout
810
+	 * @return void
811
+	 * @throws EE_Error
812
+	 * @throws InvalidSessionDataException
813
+	 */
814
+	protected function _session_checkout_reset(EE_Checkout $checkout)
815
+	{
816
+		if (self::debug) {
817
+			echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
818
+		}
819
+		// we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
820
+		if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
821
+			return;
822
+		}
823
+		$this->_release_all_reserved_tickets_for_transaction($checkout->transaction);
824
+	}
825
+
826
+
827
+
828
+	/********************************** SESSION_EXPIRED_RESET  **********************************/
829
+
830
+
831
+
832
+	/**
833
+	 * @param    EE_Session $session
834
+	 * @return    void
835
+	 */
836
+	public static function session_expired_reset(EE_Session $session)
837
+	{
838
+	}
839
+
840
+
841
+
842
+	/********************************** PROCESS_ABANDONED_TRANSACTIONS  **********************************/
843
+
844
+
845
+
846
+	/**
847
+	 * releases reserved tickets for all registrations of an ABANDONED EE_Transaction
848
+	 * by default, will NOT release tickets for free transactions, or any that have received a payment
849
+	 *
850
+	 * @param EE_Transaction $transaction
851
+	 * @return void
852
+	 * @throws EE_Error
853
+	 * @throws InvalidSessionDataException
854
+	 */
855
+	public static function process_abandoned_transactions(EE_Transaction $transaction)
856
+	{
857
+		// is this TXN free or has any money been paid towards this TXN? If so, then leave it alone
858
+		if ($transaction->is_free() || $transaction->paid() > 0) {
859
+			if (self::debug) {
860
+				// DEBUG LOG
861
+				EEH_Debug_Tools::log(
862
+					__CLASS__,
863
+					__FUNCTION__,
864
+					__LINE__,
865
+					array($transaction),
866
+					false,
867
+					'EE_Transaction: ' . $transaction->ID()
868
+				);
869
+			}
870
+			return;
871
+		}
872
+		// have their been any successful payments made ?
873
+		$payments = $transaction->payments();
874
+		foreach ($payments as $payment) {
875
+			if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) {
876
+				if (self::debug) {
877
+					// DEBUG LOG
878
+					EEH_Debug_Tools::log(
879
+						__CLASS__,
880
+						__FUNCTION__,
881
+						__LINE__,
882
+						array($payment),
883
+						false,
884
+						'EE_Transaction: ' . $transaction->ID()
885
+					);
886
+				}
887
+				return;
888
+			}
889
+		}
890
+		// since you haven't even attempted to pay for your ticket...
891
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
892
+	}
893
+
894
+
895
+
896
+	/********************************** PROCESS_FAILED_TRANSACTIONS  **********************************/
897
+
898
+
899
+
900
+	/**
901
+	 * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction
902
+	 *
903
+	 * @param EE_Transaction $transaction
904
+	 * @return void
905
+	 * @throws EE_Error
906
+	 * @throws InvalidSessionDataException
907
+	 */
908
+	public static function process_failed_transactions(EE_Transaction $transaction)
909
+	{
910
+		// since you haven't even attempted to pay for your ticket...
911
+		EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction);
912
+	}
913
+
914
+
915
+
916
+	/********************************** RESET RESERVATION COUNTS  *********************************/
917
+
918
+
919
+
920
+	/**
921
+	 * Resets all ticket and datetime reserved counts to zero
922
+	 * Tickets that are currently associated with a Transaction that is in progress
923
+	 *
924
+	 * @throws EE_Error
925
+	 * @throws DomainException
926
+	 * @throws InvalidDataTypeException
927
+	 * @throws InvalidInterfaceException
928
+	 * @throws InvalidArgumentException
929
+	 * @throws UnexpectedEntityException
930
+	 */
931
+	public static function reset_reservation_counts()
932
+	{
933
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
934
+		$valid_reserved_tickets = array();
935
+		/** @var EE_Transaction[] $transactions_not_in_progress */
936
+		$transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress();
937
+		foreach ($transactions_not_in_progress as $transaction) {
938
+			// if this TXN has been fully completed, then skip it
939
+			if ($transaction->reg_step_completed('finalize_registration')) {
940
+				continue;
941
+			}
942
+			$total_line_item = $transaction->total_line_item();
943
+			// $transaction_in_progress->line
944
+			if (! $total_line_item instanceof EE_Line_Item) {
945
+				throw new DomainException(
946
+					esc_html__(
947
+						'Transaction does not have a valid Total Line Item associated with it.',
948
+						'event_espresso'
949
+					)
950
+				);
951
+			}
952
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
953
+				$total_line_item
954
+			);
955
+		}
956
+		$total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts();
957
+		foreach ($total_line_items as $total_line_item) {
958
+			$valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total(
959
+				$total_line_item
960
+			);
961
+		}
962
+		$tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations();
963
+		return EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
964
+			$tickets_with_reservations,
965
+			$valid_reserved_tickets,
966
+			__FUNCTION__
967
+		);
968
+	}
969
+
970
+
971
+
972
+	/**
973
+	 * @param EE_Line_Item $total_line_item
974
+	 * @return EE_Line_Item[]
975
+	 */
976
+	private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item)
977
+	{
978
+		/** @var EE_Line_Item[] $valid_reserved_tickets */
979
+		$valid_reserved_tickets = array();
980
+		$ticket_line_items      = EEH_Line_Item::get_ticket_line_items($total_line_item);
981
+		foreach ($ticket_line_items as $ticket_line_item) {
982
+			if ($ticket_line_item instanceof EE_Line_Item) {
983
+				$valid_reserved_tickets[] = $ticket_line_item;
984
+			}
985
+		}
986
+		return $valid_reserved_tickets;
987
+	}
988
+
989
+
990
+
991
+	/**
992
+	 * @param EE_Ticket[]    $tickets_with_reservations
993
+	 * @param EE_Line_Item[] $valid_reserved_ticket_line_items
994
+	 * @return int
995
+	 * @throws UnexpectedEntityException
996
+	 * @throws DomainException
997
+	 * @throws EE_Error
998
+	 */
999
+	private static function release_reservations_for_tickets(
1000
+		array $tickets_with_reservations,
1001
+		array $valid_reserved_ticket_line_items = array(),
1002
+		$source
1003
+	) {
1004
+		$total_tickets_released = 0;
1005
+		$sold_out_events = array();
1006
+		foreach ($tickets_with_reservations as $ticket_with_reservations) {
1007
+			if (! $ticket_with_reservations instanceof EE_Ticket) {
1008
+				continue;
1009
+			}
1010
+			$reserved_qty = $ticket_with_reservations->reserved();
1011
+			foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) {
1012
+				if (
1013
+					$valid_reserved_ticket_line_item instanceof EE_Line_Item
1014
+					&& $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID()
1015
+				) {
1016
+					$reserved_qty -= $valid_reserved_ticket_line_item->quantity();
1017
+				}
1018
+			}
1019
+			if ($reserved_qty > 0) {
1020
+				$ticket_with_reservations->add_extra_meta(
1021
+					EE_Ticket::META_KEY_TICKET_RESERVATIONS,
1022
+					__LINE__ . ') ' . $source . '()'
1023
+				);
1024
+				$ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__);
1025
+				$ticket_with_reservations->save();
1026
+				$total_tickets_released += $reserved_qty;
1027
+				$event = $ticket_with_reservations->get_related_event();
1028
+				// track sold out events
1029
+				if ($event instanceof EE_Event && $event->is_sold_out()) {
1030
+					$sold_out_events[] = $event;
1031
+				}
1032
+			}
1033
+		}
1034
+		// double check whether sold out events should remain sold out after releasing tickets
1035
+		if($sold_out_events !== array()){
1036
+			foreach ($sold_out_events as $sold_out_event) {
1037
+				/** @var EE_Event $sold_out_event */
1038
+				$sold_out_event->perform_sold_out_status_check();
1039
+			}
1040
+		}
1041
+		return $total_tickets_released;
1042
+	}
1043
+
1044
+
1045
+
1046
+	/********************************** SHUTDOWN  **********************************/
1047
+
1048
+
1049
+
1050
+	/**
1051
+	 * @return false|int
1052
+	 * @throws EE_Error
1053
+	 * @throws InvalidArgumentException
1054
+	 * @throws InvalidDataTypeException
1055
+	 * @throws InvalidInterfaceException
1056
+	 */
1057
+	public static function clear_expired_line_items_with_no_transaction()
1058
+	{
1059
+		/** @type WPDB $wpdb */
1060
+		global $wpdb;
1061
+		return $wpdb->query(
1062
+			$wpdb->prepare(
1063
+				'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
1064 1064
                 WHERE TXN_ID = 0 AND LIN_timestamp <= %s',
1065
-                // use GMT time because that's what LIN_timestamps are in
1066
-                date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
1067
-            )
1068
-        );
1069
-    }
1065
+				// use GMT time because that's what LIN_timestamps are in
1066
+				date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
1067
+			)
1068
+		);
1069
+	}
1070 1070
 
1071 1071
 }
1072 1072
 // End of file EED_Ticket_Sales_Monitor.module.php
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 class EED_Ticket_Sales_Monitor extends EED_Module
24 24
 {
25 25
 
26
-    const debug = false;    //	true false
26
+    const debug = false; //	true false
27 27
 
28 28
     /**
29 29
      * an array of raw ticket data from EED_Ticket_Selector
@@ -209,17 +209,17 @@  discard block
 block discarded – undo
209 209
             /** @var EE_Line_Item $total_line_item */
210 210
             $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item);
211 211
             foreach ($ticket_line_items as $ticket_line_item) {
212
-                if (! $ticket_line_item instanceof EE_Line_Item) {
212
+                if ( ! $ticket_line_item instanceof EE_Line_Item) {
213 213
                     continue;
214 214
                 }
215 215
                 if ($total_line_item->timestamp(true) <= $expired) {
216
-                    $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID();
216
+                    $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID();
217 217
                 } else {
218
-                    $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item;
218
+                    $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item;
219 219
                 }
220 220
             }
221 221
         }
222
-        if (! empty($expired_ticket_IDs)) {
222
+        if ( ! empty($expired_ticket_IDs)) {
223 223
             EED_Ticket_Sales_Monitor::release_reservations_for_tickets(
224 224
                 \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs),
225 225
                 $valid_ticket_line_items,
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
             $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty);
263 263
         }
264 264
         if (self::debug) {
265
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()';
266
-            echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>';
265
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()';
266
+            echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>';
267 267
         }
268 268
         return $qty;
269 269
     }
@@ -282,36 +282,36 @@  discard block
 block discarded – undo
282 282
     protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1)
283 283
     {
284 284
         if (self::debug) {
285
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
285
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
286 286
         }
287
-        if (! $ticket instanceof EE_Ticket) {
287
+        if ( ! $ticket instanceof EE_Ticket) {
288 288
             return 0;
289 289
         }
290 290
         if (self::debug) {
291
-            echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>';
292
-            echo '<br /> . original ticket->reserved: ' . $ticket->reserved();
291
+            echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>';
292
+            echo '<br /> . original ticket->reserved: '.$ticket->reserved();
293 293
         }
294 294
         $ticket->refresh_from_db();
295 295
         // first let's determine the ticket availability based on sales
296 296
         $available = $ticket->qty('saleable');
297 297
         if (self::debug) {
298
-            echo '<br /> . . . ticket->qty: ' . $ticket->qty();
299
-            echo '<br /> . . . ticket->sold: ' . $ticket->sold();
300
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
301
-            echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable');
302
-            echo '<br /> . . . available: ' . $available;
298
+            echo '<br /> . . . ticket->qty: '.$ticket->qty();
299
+            echo '<br /> . . . ticket->sold: '.$ticket->sold();
300
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
301
+            echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable');
302
+            echo '<br /> . . . available: '.$available;
303 303
         }
304 304
         if ($available < 1) {
305 305
             $this->_ticket_sold_out($ticket);
306 306
             return 0;
307 307
         }
308 308
         if (self::debug) {
309
-            echo '<br /> . . . qty: ' . $qty;
309
+            echo '<br /> . . . qty: '.$qty;
310 310
         }
311 311
         if ($available < $qty) {
312 312
             $qty = $available;
313 313
             if (self::debug) {
314
-                echo '<br /> . . . QTY ADJUSTED: ' . $qty;
314
+                echo '<br /> . . . QTY ADJUSTED: '.$qty;
315 315
             }
316 316
             $this->_ticket_quantity_decremented($ticket);
317 317
         }
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
     protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1)
333 333
     {
334 334
         if (self::debug) {
335
-            echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity;
335
+            echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity;
336 336
         }
337
-        $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__);
337
+        $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'.__LINE__);
338 338
         return $ticket->save();
339 339
     }
340 340
 
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
     protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1)
350 350
     {
351 351
         if (self::debug) {
352
-            echo '<br /> . . . ticket->ID: ' . $ticket->ID();
353
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
352
+            echo '<br /> . . . ticket->ID: '.$ticket->ID();
353
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
354 354
         }
355
-        $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__);
355
+        $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'.__LINE__);
356 356
         if (self::debug) {
357
-            echo '<br /> . . . ticket->reserved: ' . $ticket->reserved();
357
+            echo '<br /> . . . ticket->reserved: '.$ticket->reserved();
358 358
         }
359 359
         return $ticket->save() ? 1 : 0;
360 360
     }
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
     protected function _ticket_sold_out(EE_Ticket $ticket)
373 373
     {
374 374
         if (self::debug) {
375
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
376
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
375
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
376
+            echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
377 377
         }
378 378
         $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket);
379 379
     }
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
     protected function _ticket_quantity_decremented(EE_Ticket $ticket)
392 392
     {
393 393
         if (self::debug) {
394
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
395
-            echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket);
394
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
395
+            echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket);
396 396
         }
397 397
         $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket);
398 398
     }
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
         if ($ticket instanceof EE_Ticket) {
446 446
             $ticket->add_extra_meta(
447 447
                 EE_Ticket::META_KEY_TICKET_RESERVATIONS,
448
-                __LINE__ . ') ' . __METHOD__ . '()'
448
+                __LINE__.') '.__METHOD__.'()'
449 449
             );
450 450
             if ($quantity > 0) {
451 451
                 EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity);
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
     {
470 470
         $ticket->add_extra_meta(
471 471
             EE_Ticket::META_KEY_TICKET_RESERVATIONS,
472
-            __LINE__ . ') ' . __METHOD__ . '()'
472
+            __LINE__.') '.__METHOD__.'()'
473 473
         );
474 474
         EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity);
475 475
     }
@@ -506,18 +506,18 @@  discard block
 block discarded – undo
506 506
     protected function _post_notices()
507 507
     {
508 508
         if (self::debug) {
509
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
509
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
510 510
         }
511 511
         $refresh_msg    = '';
512 512
         $none_added_msg = '';
513 513
         if (defined('DOING_AJAX') && DOING_AJAX) {
514
-            $refresh_msg    = __(
514
+            $refresh_msg = __(
515 515
                 'Please refresh the page to view updated ticket quantities.',
516 516
                 'event_espresso'
517 517
             );
518 518
             $none_added_msg = __('No tickets were added for the event.', 'event_espresso');
519 519
         }
520
-        if (! empty($this->sold_out_tickets)) {
520
+        if ( ! empty($this->sold_out_tickets)) {
521 521
             EE_Error::add_attention(
522 522
                 sprintf(
523 523
                     apply_filters(
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
             // and reset the cart
541 541
             EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN);
542 542
         }
543
-        if (! empty($this->decremented_tickets)) {
543
+        if ( ! empty($this->decremented_tickets)) {
544 544
             EE_Error::add_attention(
545 545
                 sprintf(
546 546
                     apply_filters(
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
     protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction)
579 579
     {
580 580
         if (self::debug) {
581
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
582
-            echo '<br /> . transaction->ID: ' . $transaction->ID();
583
-            echo '<br /> . TXN status_ID: ' . $transaction->status_ID();
581
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
582
+            echo '<br /> . transaction->ID: '.$transaction->ID();
583
+            echo '<br /> . TXN status_ID: '.$transaction->status_ID();
584 584
         }
585 585
         // check if 'finalize_registration' step has been completed...
586 586
         $finalized = $transaction->reg_step_completed('finalize_registration');
@@ -592,13 +592,13 @@  discard block
 block discarded – undo
592 592
                 __LINE__,
593 593
                 array('finalized' => $finalized),
594 594
                 false,
595
-                'EE_Transaction: ' . $transaction->ID()
595
+                'EE_Transaction: '.$transaction->ID()
596 596
             );
597 597
         }
598 598
         // how many tickets were released
599 599
         $count = 0;
600 600
         if (self::debug) {
601
-            echo '<br /> . . . TXN finalized: ' . $finalized;
601
+            echo '<br /> . . . TXN finalized: '.$finalized;
602 602
         }
603 603
         $release_tickets_with_TXN_status = array(
604 604
             EEM_Transaction::failed_status_code,
@@ -607,28 +607,28 @@  discard block
 block discarded – undo
607 607
         );
608 608
         $events = array();
609 609
         // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed
610
-        if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
610
+        if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) {
611 611
             // cancel any reserved tickets for registrations that were not approved
612 612
             $registrations = $transaction->registrations();
613 613
             if (self::debug) {
614
-                echo '<br /> . . . # registrations: ' . count($registrations);
614
+                echo '<br /> . . . # registrations: '.count($registrations);
615 615
                 $reg    = reset($registrations);
616 616
                 $ticket = $reg->ticket();
617 617
                 if ($ticket instanceof EE_Ticket) {
618 618
                     $ticket->add_extra_meta(
619 619
                         EE_Ticket::META_KEY_TICKET_RESERVATIONS,
620
-                        __LINE__ . ') Release All Tickets TXN:' . $transaction->ID()
620
+                        __LINE__.') Release All Tickets TXN:'.$transaction->ID()
621 621
                     );
622 622
                 }
623 623
             }
624
-            if (! empty($registrations)) {
624
+            if ( ! empty($registrations)) {
625 625
                 foreach ($registrations as $registration) {
626 626
                     if (
627 627
                         $registration instanceof EE_Registration
628 628
                         && $this->_release_reserved_ticket_for_registration($registration, $transaction)
629 629
                     ) {
630 630
                         $count++;
631
-                        $events[ $registration->event_ID() ] = $registration->event();
631
+                        $events[$registration->event_ID()] = $registration->event();
632 632
                     }
633 633
                 }
634 634
             }
@@ -659,10 +659,10 @@  discard block
 block discarded – undo
659 659
     ) {
660 660
         $STS_ID = $transaction->status_ID();
661 661
         if (self::debug) {
662
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
663
-            echo '<br /> . . registration->ID: ' . $registration->ID();
664
-            echo '<br /> . . registration->status_ID: ' . $registration->status_ID();
665
-            echo '<br /> . . transaction->status_ID(): ' . $STS_ID;
662
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
663
+            echo '<br /> . . registration->ID: '.$registration->ID();
664
+            echo '<br /> . . registration->status_ID: '.$registration->status_ID();
665
+            echo '<br /> . . transaction->status_ID(): '.$STS_ID;
666 666
         }
667 667
         if (
668 668
             // release Tickets for Failed Transactions and Abandoned Transactions
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
                 echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: ';
681 681
                 var_dump($rsrvd);
682 682
             }
683
-            $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__);
683
+            $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__);
684 684
             return 1;
685 685
         }
686 686
         return 0;
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
     public static function session_cart_reset(EE_Session $session)
707 707
     {
708 708
         if (self::debug) {
709
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
709
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
710 710
         }
711 711
         // first check of the session has a valid Checkout object
712 712
         $checkout = $session->checkout();
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
     protected function _session_cart_reset(EE_Cart $cart, EE_Session $session)
746 746
     {
747 747
         if (self::debug) {
748
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
748
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
749 749
         }
750 750
         EE_Registry::instance()->load_helper('Line_Item');
751 751
         $ticket_line_items = $cart->get_tickets();
@@ -754,21 +754,21 @@  discard block
 block discarded – undo
754 754
         }
755 755
         foreach ($ticket_line_items as $ticket_line_item) {
756 756
             if (self::debug) {
757
-                echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID();
757
+                echo '<br /> . ticket_line_item->ID(): '.$ticket_line_item->ID();
758 758
             }
759 759
             if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') {
760 760
                 if (self::debug) {
761
-                    echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID();
761
+                    echo '<br /> . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID();
762 762
                 }
763 763
                 $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
764 764
                 if ($ticket instanceof EE_Ticket) {
765 765
                     if (self::debug) {
766
-                        echo '<br /> . . ticket->ID(): ' . $ticket->ID();
767
-                        echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity();
766
+                        echo '<br /> . . ticket->ID(): '.$ticket->ID();
767
+                        echo '<br /> . . ticket_line_item->quantity(): '.$ticket_line_item->quantity();
768 768
                     }
769 769
                     $ticket->add_extra_meta(
770 770
                         EE_Ticket::META_KEY_TICKET_RESERVATIONS,
771
-                        __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id()
771
+                        __LINE__.') '.__METHOD__.'() SID = '.$session->id()
772 772
                     );
773 773
                     $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity());
774 774
                 }
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
     protected function _session_checkout_reset(EE_Checkout $checkout)
815 815
     {
816 816
         if (self::debug) {
817
-            echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() ';
817
+            echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() ';
818 818
         }
819 819
         // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit
820 820
         if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) {
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
                     __LINE__,
865 865
                     array($transaction),
866 866
                     false,
867
-                    'EE_Transaction: ' . $transaction->ID()
867
+                    'EE_Transaction: '.$transaction->ID()
868 868
                 );
869 869
             }
870 870
             return;
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
                         __LINE__,
882 882
                         array($payment),
883 883
                         false,
884
-                        'EE_Transaction: ' . $transaction->ID()
884
+                        'EE_Transaction: '.$transaction->ID()
885 885
                     );
886 886
                 }
887 887
                 return;
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
             }
942 942
             $total_line_item = $transaction->total_line_item();
943 943
             // $transaction_in_progress->line
944
-            if (! $total_line_item instanceof EE_Line_Item) {
944
+            if ( ! $total_line_item instanceof EE_Line_Item) {
945 945
                 throw new DomainException(
946 946
                     esc_html__(
947 947
                         'Transaction does not have a valid Total Line Item associated with it.',
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
         $total_tickets_released = 0;
1005 1005
         $sold_out_events = array();
1006 1006
         foreach ($tickets_with_reservations as $ticket_with_reservations) {
1007
-            if (! $ticket_with_reservations instanceof EE_Ticket) {
1007
+            if ( ! $ticket_with_reservations instanceof EE_Ticket) {
1008 1008
                 continue;
1009 1009
             }
1010 1010
             $reserved_qty = $ticket_with_reservations->reserved();
@@ -1019,9 +1019,9 @@  discard block
 block discarded – undo
1019 1019
             if ($reserved_qty > 0) {
1020 1020
                 $ticket_with_reservations->add_extra_meta(
1021 1021
                     EE_Ticket::META_KEY_TICKET_RESERVATIONS,
1022
-                    __LINE__ . ') ' . $source . '()'
1022
+                    __LINE__.') '.$source.'()'
1023 1023
                 );
1024
-                $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__);
1024
+                $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'.__LINE__);
1025 1025
                 $ticket_with_reservations->save();
1026 1026
                 $total_tickets_released += $reserved_qty;
1027 1027
                 $event = $ticket_with_reservations->get_related_event();
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
             }
1033 1033
         }
1034 1034
         // double check whether sold out events should remain sold out after releasing tickets
1035
-        if($sold_out_events !== array()){
1035
+        if ($sold_out_events !== array()) {
1036 1036
             foreach ($sold_out_events as $sold_out_event) {
1037 1037
                 /** @var EE_Event $sold_out_event */
1038 1038
                 $sold_out_event->perform_sold_out_status_check();
@@ -1060,7 +1060,7 @@  discard block
 block discarded – undo
1060 1060
         global $wpdb;
1061 1061
         return $wpdb->query(
1062 1062
             $wpdb->prepare(
1063
-                'DELETE FROM ' . EEM_Line_Item::instance()->table() . '
1063
+                'DELETE FROM '.EEM_Line_Item::instance()->table().'
1064 1064
                 WHERE TXN_ID = 0 AND LIN_timestamp <= %s',
1065 1065
                 // use GMT time because that's what LIN_timestamps are in
1066 1066
                 date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan())
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket.class.php 2 patches
Indentation   +665 added lines, -665 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	const onsale = 'TKO';
55 55
 
56
-    /**
57
-     * extra meta key for tracking ticket reservations
58
-     *
59
-     * @type string
60
-     */
61
-    const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations';
62
-
63
-    /**
56
+	/**
57
+	 * extra meta key for tracking ticket reservations
58
+	 *
59
+	 * @type string
60
+	 */
61
+	const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations';
62
+
63
+	/**
64 64
 	 * cached result from method of the same name
65 65
 	 * @var float $_ticket_total_with_taxes
66 66
 	 */
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 
69 69
 
70 70
 
71
-    /**
72
-     * @param array  $props_n_values          incoming values
73
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
74
-     *                                        used.)
75
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
76
-     *                                        date_format and the second value is the time format
77
-     * @return EE_Ticket
78
-     * @throws \EE_Error
79
-     */
71
+	/**
72
+	 * @param array  $props_n_values          incoming values
73
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
74
+	 *                                        used.)
75
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
76
+	 *                                        date_format and the second value is the time format
77
+	 * @return EE_Ticket
78
+	 * @throws \EE_Error
79
+	 */
80 80
 	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
81 81
 		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
82 82
 		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
@@ -84,36 +84,36 @@  discard block
 block discarded – undo
84 84
 
85 85
 
86 86
 
87
-    /**
88
-     * @param array  $props_n_values  incoming values from the database
89
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
90
-     *                                the website will be used.
91
-     * @return EE_Ticket
92
-     * @throws \EE_Error
93
-     */
87
+	/**
88
+	 * @param array  $props_n_values  incoming values from the database
89
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
90
+	 *                                the website will be used.
91
+	 * @return EE_Ticket
92
+	 * @throws \EE_Error
93
+	 */
94 94
 	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
95 95
 		return new self( $props_n_values, TRUE, $timezone );
96 96
 	}
97 97
 
98 98
 
99 99
 
100
-    /**
101
-     * @return bool
102
-     * @throws \EE_Error
103
-     */
100
+	/**
101
+	 * @return bool
102
+	 * @throws \EE_Error
103
+	 */
104 104
 	public function parent() {
105 105
 		return $this->get( 'TKT_parent' );
106 106
 	}
107 107
 
108 108
 
109 109
 
110
-    /**
111
-     * return if a ticket has quantities available for purchase
112
-     *
113
-     * @param  int $DTT_ID the primary key for a particular datetime
114
-     * @return boolean
115
-     * @throws \EE_Error
116
-     */
110
+	/**
111
+	 * return if a ticket has quantities available for purchase
112
+	 *
113
+	 * @param  int $DTT_ID the primary key for a particular datetime
114
+	 * @return boolean
115
+	 * @throws \EE_Error
116
+	 */
117 117
 	public function available( $DTT_ID = 0 ) {
118 118
 		// are we checking availability for a particular datetime ?
119 119
 		if ( $DTT_ID ) {
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 
131 131
 
132 132
 
133
-    /**
134
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
135
-     *
136
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
137
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
138
-     * @return mixed status int if the display string isn't requested
139
-     * @throws \EE_Error
140
-     */
133
+	/**
134
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
135
+	 *
136
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
137
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
138
+	 * @return mixed status int if the display string isn't requested
139
+	 * @throws \EE_Error
140
+	 */
141 141
 	public function ticket_status( $display = FALSE, $remaining = null ) {
142 142
 		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
143 143
 		if ( ! $remaining ) {
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
 
161 161
 
162 162
 
163
-    /**
164
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
165
-     *
166
-     * @access public
167
-     * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
168
-     * @return boolean         true = tickets remaining, false not.
169
-     * @throws \EE_Error
170
-     */
163
+	/**
164
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
165
+	 *
166
+	 * @access public
167
+	 * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
168
+	 * @return boolean         true = tickets remaining, false not.
169
+	 * @throws \EE_Error
170
+	 */
171 171
 	public function is_remaining( $DTT_ID = 0 ) {
172 172
 		$num_remaining = $this->remaining( $DTT_ID );
173 173
 		if ( $num_remaining === 0 ) {
@@ -181,76 +181,76 @@  discard block
 block discarded – undo
181 181
 
182 182
 
183 183
 
184
-    /**
185
-     * return the total number of tickets available for purchase
186
-     *
187
-     * @param  int $DTT_ID the primary key for a particular datetime.
188
-     *                     set to 0 for all related datetimes
189
-     * @return int
190
-     * @throws \EE_Error
191
-     */
184
+	/**
185
+	 * return the total number of tickets available for purchase
186
+	 *
187
+	 * @param  int $DTT_ID the primary key for a particular datetime.
188
+	 *                     set to 0 for all related datetimes
189
+	 * @return int
190
+	 * @throws \EE_Error
191
+	 */
192 192
 	public function remaining( $DTT_ID = 0 ) {
193 193
 		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
194 194
 	}
195 195
 
196 196
 
197 197
 
198
-    /**
199
-     * Gets min
200
-     *
201
-     * @return int
202
-     * @throws \EE_Error
203
-     */
198
+	/**
199
+	 * Gets min
200
+	 *
201
+	 * @return int
202
+	 * @throws \EE_Error
203
+	 */
204 204
 	public function min() {
205 205
 		return $this->get( 'TKT_min' );
206 206
 	}
207 207
 
208 208
 
209 209
 
210
-    /**
211
-     * return if a ticket is no longer available cause its available dates have expired.
212
-     *
213
-     * @return boolean
214
-     * @throws \EE_Error
215
-     */
210
+	/**
211
+	 * return if a ticket is no longer available cause its available dates have expired.
212
+	 *
213
+	 * @return boolean
214
+	 * @throws \EE_Error
215
+	 */
216 216
 	public function is_expired() {
217 217
 		return ( $this->get_raw( 'TKT_end_date' ) < time() );
218 218
 	}
219 219
 
220 220
 
221 221
 
222
-    /**
223
-     * Return if a ticket is yet to go on sale or not
224
-     *
225
-     * @return boolean
226
-     * @throws \EE_Error
227
-     */
222
+	/**
223
+	 * Return if a ticket is yet to go on sale or not
224
+	 *
225
+	 * @return boolean
226
+	 * @throws \EE_Error
227
+	 */
228 228
 	public function is_pending() {
229 229
 		return ( $this->get_raw( 'TKT_start_date' ) > time() );
230 230
 	}
231 231
 
232 232
 
233 233
 
234
-    /**
235
-     * Return if a ticket is on sale or not
236
-     *
237
-     * @return boolean
238
-     * @throws \EE_Error
239
-     */
234
+	/**
235
+	 * Return if a ticket is on sale or not
236
+	 *
237
+	 * @return boolean
238
+	 * @throws \EE_Error
239
+	 */
240 240
 	public function is_on_sale() {
241 241
 		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
242 242
 	}
243 243
 
244 244
 
245 245
 
246
-    /**
247
-     * This returns the chronologically last datetime that this ticket is associated with
248
-     *
249
-     * @param string $dt_frmt
250
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
251
-     * @return string
252
-     * @throws \EE_Error
253
-     */
246
+	/**
247
+	 * This returns the chronologically last datetime that this ticket is associated with
248
+	 *
249
+	 * @param string $dt_frmt
250
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
251
+	 * @return string
252
+	 * @throws \EE_Error
253
+	 */
254 254
 	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
255 255
 		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
256 256
 		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
@@ -260,12 +260,12 @@  discard block
 block discarded – undo
260 260
 
261 261
 
262 262
 
263
-    /**
264
-     * This returns the chronologically first datetime that this ticket is associated with
265
-     *
266
-     * @return EE_Datetime
267
-     * @throws \EE_Error
268
-     */
263
+	/**
264
+	 * This returns the chronologically first datetime that this ticket is associated with
265
+	 *
266
+	 * @return EE_Datetime
267
+	 * @throws \EE_Error
268
+	 */
269 269
 	public function first_datetime() {
270 270
 		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
271 271
 		return reset( $datetimes );
@@ -273,14 +273,14 @@  discard block
 block discarded – undo
273 273
 
274 274
 
275 275
 
276
-    /**
277
-     * Gets all the datetimes this ticket can be used for attending.
278
-     * Unless otherwise specified, orders datetimes by start date.
279
-     *
280
-     * @param array $query_params see EEM_Base::get_all()
281
-     * @return EE_Datetime[]|EE_Base_Class[]
282
-     * @throws \EE_Error
283
-     */
276
+	/**
277
+	 * Gets all the datetimes this ticket can be used for attending.
278
+	 * Unless otherwise specified, orders datetimes by start date.
279
+	 *
280
+	 * @param array $query_params see EEM_Base::get_all()
281
+	 * @return EE_Datetime[]|EE_Base_Class[]
282
+	 * @throws \EE_Error
283
+	 */
284 284
 	public function datetimes( $query_params = array() ) {
285 285
 		if ( ! isset( $query_params[ 'order_by' ] ) ) {
286 286
 			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
 
291 291
 
292 292
 
293
-    /**
294
-     * This returns the chronologically last datetime that this ticket is associated with
295
-     *
296
-     * @return EE_Datetime
297
-     * @throws \EE_Error
298
-     */
293
+	/**
294
+	 * This returns the chronologically last datetime that this ticket is associated with
295
+	 *
296
+	 * @return EE_Datetime
297
+	 * @throws \EE_Error
298
+	 */
299 299
 	public function last_datetime() {
300 300
 		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
301 301
 		return end( $datetimes );
@@ -303,19 +303,19 @@  discard block
 block discarded – undo
303 303
 
304 304
 
305 305
 
306
-    /**
307
-     * This returns the total tickets sold depending on the given parameters.
308
-     *
309
-     * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
310
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
311
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
312
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
313
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
314
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
315
-     * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
316
-     * @return mixed (array|int)          how many tickets have sold
317
-     * @throws \EE_Error
318
-     */
306
+	/**
307
+	 * This returns the total tickets sold depending on the given parameters.
308
+	 *
309
+	 * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
310
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
311
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
312
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
313
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
314
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
315
+	 * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
316
+	 * @return mixed (array|int)          how many tickets have sold
317
+	 * @throws \EE_Error
318
+	 */
319 319
 	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
320 320
 		$total = 0;
321 321
 		$tickets_sold = $this->_all_tickets_sold();
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
 
341 341
 
342 342
 
343
-    /**
344
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
345
-     *
346
-     * @return EE_Ticket[]
347
-     * @throws \EE_Error
348
-     */
343
+	/**
344
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
345
+	 *
346
+	 * @return EE_Ticket[]
347
+	 * @throws \EE_Error
348
+	 */
349 349
 	protected function _all_tickets_sold() {
350 350
 		$datetimes = $this->get_many_related( 'Datetime' );
351 351
 		$tickets_sold = array();
@@ -361,29 +361,29 @@  discard block
 block discarded – undo
361 361
 
362 362
 
363 363
 
364
-    /**
365
-     * This returns the base price object for the ticket.
366
-     *
367
-     * @param  bool $return_array whether to return as an array indexed by price id or just the object.
368
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
369
-     * @throws \EE_Error
370
-     */
364
+	/**
365
+	 * This returns the base price object for the ticket.
366
+	 *
367
+	 * @param  bool $return_array whether to return as an array indexed by price id or just the object.
368
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
369
+	 * @throws \EE_Error
370
+	 */
371 371
 	public function base_price( $return_array = FALSE ) {
372 372
 		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
373 373
 		return $return_array
374
-            ? $this->get_many_related( 'Price', array( $_where ) )
375
-            : $this->get_first_related( 'Price', array( $_where ) );
374
+			? $this->get_many_related( 'Price', array( $_where ) )
375
+			: $this->get_first_related( 'Price', array( $_where ) );
376 376
 	}
377 377
 
378 378
 
379 379
 
380
-    /**
381
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
382
-     *
383
-     * @access public
384
-     * @return EE_Price[]
385
-     * @throws \EE_Error
386
-     */
380
+	/**
381
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
382
+	 *
383
+	 * @access public
384
+	 * @return EE_Price[]
385
+	 * @throws \EE_Error
386
+	 */
387 387
 	public function price_modifiers() {
388 388
 		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
389 389
 		return $this->prices( $query_params );
@@ -391,132 +391,132 @@  discard block
 block discarded – undo
391 391
 
392 392
 
393 393
 
394
-    /**
395
-     * Gets all the prices that combine to form the final price of this ticket
396
-     *
397
-     * @param array $query_params like EEM_Base::get_all
398
-     * @return EE_Price[]|EE_Base_Class[]
399
-     * @throws \EE_Error
400
-     */
394
+	/**
395
+	 * Gets all the prices that combine to form the final price of this ticket
396
+	 *
397
+	 * @param array $query_params like EEM_Base::get_all
398
+	 * @return EE_Price[]|EE_Base_Class[]
399
+	 * @throws \EE_Error
400
+	 */
401 401
 	public function prices( $query_params = array() ) {
402 402
 		return $this->get_many_related( 'Price', $query_params );
403 403
 	}
404 404
 
405 405
 
406 406
 
407
-    /**
408
-     * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
409
-     *
410
-     * @param array $query_params see EEM_Base::get_all()
411
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
412
-     * @throws \EE_Error
413
-     */
407
+	/**
408
+	 * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
409
+	 *
410
+	 * @param array $query_params see EEM_Base::get_all()
411
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
412
+	 * @throws \EE_Error
413
+	 */
414 414
 	public function datetime_tickets( $query_params = array() ) {
415 415
 		return $this->get_many_related( 'Datetime_Ticket', $query_params );
416 416
 	}
417 417
 
418 418
 
419 419
 
420
-    /**
421
-     * Gets all the datetimes from the db ordered by DTT_order
422
-     *
423
-     * @param boolean $show_expired
424
-     * @param boolean $show_deleted
425
-     * @return EE_Datetime[]
426
-     * @throws \EE_Error
427
-     */
420
+	/**
421
+	 * Gets all the datetimes from the db ordered by DTT_order
422
+	 *
423
+	 * @param boolean $show_expired
424
+	 * @param boolean $show_deleted
425
+	 * @return EE_Datetime[]
426
+	 * @throws \EE_Error
427
+	 */
428 428
 	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
429 429
 		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
430 430
 	}
431 431
 
432 432
 
433 433
 
434
-    /**
435
-     * Gets ID
436
-     *
437
-     * @return string
438
-     * @throws \EE_Error
439
-     */
434
+	/**
435
+	 * Gets ID
436
+	 *
437
+	 * @return string
438
+	 * @throws \EE_Error
439
+	 */
440 440
 	public function ID() {
441 441
 		return $this->get( 'TKT_ID' );
442 442
 	}
443 443
 
444 444
 
445 445
 
446
-    /**
447
-     * get the author of the ticket.
448
-     *
449
-     * @since 4.5.0
450
-     * @return int
451
-     * @throws \EE_Error
452
-     */
446
+	/**
447
+	 * get the author of the ticket.
448
+	 *
449
+	 * @since 4.5.0
450
+	 * @return int
451
+	 * @throws \EE_Error
452
+	 */
453 453
 	public function wp_user() {
454 454
 		return $this->get('TKT_wp_user');
455 455
 	}
456 456
 
457 457
 
458 458
 
459
-    /**
460
-     * Gets the template for the ticket
461
-     *
462
-     * @return EE_Ticket_Template|EE_Base_Class
463
-     * @throws \EE_Error
464
-     */
459
+	/**
460
+	 * Gets the template for the ticket
461
+	 *
462
+	 * @return EE_Ticket_Template|EE_Base_Class
463
+	 * @throws \EE_Error
464
+	 */
465 465
 	public function template() {
466 466
 		return $this->get_first_related( 'Ticket_Template' );
467 467
 	}
468 468
 
469 469
 
470 470
 
471
-    /**
472
-     * Simply returns an array of EE_Price objects that are taxes.
473
-     *
474
-     * @return EE_Price[]
475
-     * @throws \EE_Error
476
-     */
471
+	/**
472
+	 * Simply returns an array of EE_Price objects that are taxes.
473
+	 *
474
+	 * @return EE_Price[]
475
+	 * @throws \EE_Error
476
+	 */
477 477
 	public function get_ticket_taxes_for_admin() {
478 478
 		return EE_Taxes::get_taxes_for_admin();
479 479
 	}
480 480
 
481 481
 
482 482
 
483
-    /**
484
-     * @return float
485
-     * @throws \EE_Error
486
-     */
483
+	/**
484
+	 * @return float
485
+	 * @throws \EE_Error
486
+	 */
487 487
 	public function ticket_price() {
488 488
 		return $this->get( 'TKT_price' );
489 489
 	}
490 490
 
491 491
 
492 492
 
493
-    /**
494
-     * @return mixed
495
-     * @throws \EE_Error
496
-     */
493
+	/**
494
+	 * @return mixed
495
+	 * @throws \EE_Error
496
+	 */
497 497
 	public function pretty_price() {
498 498
 		return $this->get_pretty( 'TKT_price' );
499 499
 	}
500 500
 
501 501
 
502 502
 
503
-    /**
504
-     * @return bool
505
-     * @throws \EE_Error
506
-     */
503
+	/**
504
+	 * @return bool
505
+	 * @throws \EE_Error
506
+	 */
507 507
 	public function is_free() {
508 508
 		return $this->get_ticket_total_with_taxes() === (float) 0;
509 509
 	}
510 510
 
511 511
 
512 512
 
513
-    /**
514
-     * get_ticket_total_with_taxes
515
-     *
516
-     * @param bool $no_cache
517
-     * @return float
518
-     * @throws \EE_Error
519
-     */
513
+	/**
514
+	 * get_ticket_total_with_taxes
515
+	 *
516
+	 * @param bool $no_cache
517
+	 * @return float
518
+	 * @throws \EE_Error
519
+	 */
520 520
 	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
521 521
 		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
522 522
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
@@ -533,201 +533,201 @@  discard block
 block discarded – undo
533 533
 
534 534
 
535 535
 
536
-    /**
537
-     * @return float
538
-     * @throws \EE_Error
539
-     */
536
+	/**
537
+	 * @return float
538
+	 * @throws \EE_Error
539
+	 */
540 540
 	public function get_ticket_subtotal() {
541 541
 		return EE_Taxes::get_subtotal_for_admin( $this );
542 542
 	}
543 543
 
544 544
 
545 545
 
546
-    /**
547
-     * Returns the total taxes applied to this ticket
548
-     *
549
-     * @return float
550
-     * @throws \EE_Error
551
-     */
546
+	/**
547
+	 * Returns the total taxes applied to this ticket
548
+	 *
549
+	 * @return float
550
+	 * @throws \EE_Error
551
+	 */
552 552
 	public function get_ticket_taxes_total_for_admin() {
553 553
 		return EE_Taxes::get_total_taxes_for_admin( $this );
554 554
 	}
555 555
 
556 556
 
557 557
 
558
-    /**
559
-     * Sets name
560
-     *
561
-     * @param string $name
562
-     * @throws \EE_Error
563
-     */
558
+	/**
559
+	 * Sets name
560
+	 *
561
+	 * @param string $name
562
+	 * @throws \EE_Error
563
+	 */
564 564
 	public function set_name( $name ) {
565 565
 		$this->set( 'TKT_name', $name );
566 566
 	}
567 567
 
568 568
 
569 569
 
570
-    /**
571
-     * Gets description
572
-     *
573
-     * @return string
574
-     * @throws \EE_Error
575
-     */
570
+	/**
571
+	 * Gets description
572
+	 *
573
+	 * @return string
574
+	 * @throws \EE_Error
575
+	 */
576 576
 	public function description() {
577 577
 		return $this->get( 'TKT_description' );
578 578
 	}
579 579
 
580 580
 
581 581
 
582
-    /**
583
-     * Sets description
584
-     *
585
-     * @param string $description
586
-     * @throws \EE_Error
587
-     */
582
+	/**
583
+	 * Sets description
584
+	 *
585
+	 * @param string $description
586
+	 * @throws \EE_Error
587
+	 */
588 588
 	public function set_description( $description ) {
589 589
 		$this->set( 'TKT_description', $description );
590 590
 	}
591 591
 
592 592
 
593 593
 
594
-    /**
595
-     * Gets start_date
596
-     *
597
-     * @param string $dt_frmt
598
-     * @param string $tm_frmt
599
-     * @return string
600
-     * @throws \EE_Error
601
-     */
594
+	/**
595
+	 * Gets start_date
596
+	 *
597
+	 * @param string $dt_frmt
598
+	 * @param string $tm_frmt
599
+	 * @return string
600
+	 * @throws \EE_Error
601
+	 */
602 602
 	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
603 603
 		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
604 604
 	}
605 605
 
606 606
 
607 607
 
608
-    /**
609
-     * Sets start_date
610
-     *
611
-     * @param string $start_date
612
-     * @return void
613
-     * @throws \EE_Error
614
-     */
608
+	/**
609
+	 * Sets start_date
610
+	 *
611
+	 * @param string $start_date
612
+	 * @return void
613
+	 * @throws \EE_Error
614
+	 */
615 615
 	public function set_start_date( $start_date ) {
616 616
 		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
617 617
 	}
618 618
 
619 619
 
620 620
 
621
-    /**
622
-     * Gets end_date
623
-     *
624
-     * @param string $dt_frmt
625
-     * @param string $tm_frmt
626
-     * @return string
627
-     * @throws \EE_Error
628
-     */
621
+	/**
622
+	 * Gets end_date
623
+	 *
624
+	 * @param string $dt_frmt
625
+	 * @param string $tm_frmt
626
+	 * @return string
627
+	 * @throws \EE_Error
628
+	 */
629 629
 	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
630 630
 		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
631 631
 	}
632 632
 
633 633
 
634 634
 
635
-    /**
636
-     * Sets end_date
637
-     *
638
-     * @param string $end_date
639
-     * @return void
640
-     * @throws \EE_Error
641
-     */
635
+	/**
636
+	 * Sets end_date
637
+	 *
638
+	 * @param string $end_date
639
+	 * @return void
640
+	 * @throws \EE_Error
641
+	 */
642 642
 	public function set_end_date( $end_date ) {
643 643
 		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
644 644
 	}
645 645
 
646 646
 
647 647
 
648
-    /**
649
-     * Sets sell until time
650
-     *
651
-     * @since 4.5.0
652
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
653
-     * @throws \EE_Error
654
-     */
648
+	/**
649
+	 * Sets sell until time
650
+	 *
651
+	 * @since 4.5.0
652
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
653
+	 * @throws \EE_Error
654
+	 */
655 655
 	public function set_end_time( $time ) {
656 656
 		$this->_set_time_for( $time, 'TKT_end_date' );
657 657
 	}
658 658
 
659 659
 
660 660
 
661
-    /**
662
-     * Sets min
663
-     *
664
-     * @param int $min
665
-     * @return void
666
-     * @throws \EE_Error
667
-     */
661
+	/**
662
+	 * Sets min
663
+	 *
664
+	 * @param int $min
665
+	 * @return void
666
+	 * @throws \EE_Error
667
+	 */
668 668
 	public function set_min( $min ) {
669 669
 		$this->set( 'TKT_min', $min );
670 670
 	}
671 671
 
672 672
 
673 673
 
674
-    /**
675
-     * Gets max
676
-     *
677
-     * @return int
678
-     * @throws \EE_Error
679
-     */
674
+	/**
675
+	 * Gets max
676
+	 *
677
+	 * @return int
678
+	 * @throws \EE_Error
679
+	 */
680 680
 	public function max() {
681 681
 		return $this->get( 'TKT_max' );
682 682
 	}
683 683
 
684 684
 
685 685
 
686
-    /**
687
-     * Sets max
688
-     *
689
-     * @param int $max
690
-     * @return void
691
-     * @throws \EE_Error
692
-     */
686
+	/**
687
+	 * Sets max
688
+	 *
689
+	 * @param int $max
690
+	 * @return void
691
+	 * @throws \EE_Error
692
+	 */
693 693
 	public function set_max( $max ) {
694 694
 		$this->set( 'TKT_max', $max );
695 695
 	}
696 696
 
697 697
 
698 698
 
699
-    /**
700
-     * Sets price
701
-     *
702
-     * @param float $price
703
-     * @return void
704
-     * @throws \EE_Error
705
-     */
699
+	/**
700
+	 * Sets price
701
+	 *
702
+	 * @param float $price
703
+	 * @return void
704
+	 * @throws \EE_Error
705
+	 */
706 706
 	public function set_price( $price ) {
707 707
 		$this->set( 'TKT_price', $price );
708 708
 	}
709 709
 
710 710
 
711 711
 
712
-    /**
713
-     * Gets sold
714
-     *
715
-     * @return int
716
-     * @throws \EE_Error
717
-     */
712
+	/**
713
+	 * Gets sold
714
+	 *
715
+	 * @return int
716
+	 * @throws \EE_Error
717
+	 */
718 718
 	public function sold() {
719 719
 		return $this->get_raw( 'TKT_sold' );
720 720
 	}
721 721
 
722 722
 
723 723
 
724
-    /**
725
-     * Sets sold
726
-     *
727
-     * @param int $sold
728
-     * @return void
729
-     * @throws \EE_Error
730
-     */
724
+	/**
725
+	 * Sets sold
726
+	 *
727
+	 * @param int $sold
728
+	 * @return void
729
+	 * @throws \EE_Error
730
+	 */
731 731
 	public function set_sold( $sold ) {
732 732
 		// sold can not go below zero
733 733
 		$sold = max( 0, $sold );
@@ -736,13 +736,13 @@  discard block
 block discarded – undo
736 736
 
737 737
 
738 738
 
739
-    /**
740
-     * increments sold by amount passed by $qty
741
-     *
742
-     * @param int $qty
743
-     * @return void
744
-     * @throws \EE_Error
745
-     */
739
+	/**
740
+	 * increments sold by amount passed by $qty
741
+	 *
742
+	 * @param int $qty
743
+	 * @return void
744
+	 * @throws \EE_Error
745
+	 */
746 746
 	public function increase_sold( $qty = 1 ) {
747 747
 		$sold = $this->sold() + $qty;
748 748
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
@@ -751,22 +751,22 @@  discard block
 block discarded – undo
751 751
 		$this->_increase_sold_for_datetimes( $qty );
752 752
 		$this->set_sold( $sold );
753 753
 		do_action(
754
-		    'AHEE__EE_Ticket__increase_sold',
755
-            $this,
756
-            $qty,
757
-            $sold
758
-        );
754
+			'AHEE__EE_Ticket__increase_sold',
755
+			$this,
756
+			$qty,
757
+			$sold
758
+		);
759 759
 	}
760 760
 
761 761
 
762 762
 
763
-    /**
764
-     * Increases sold on related datetimes
765
-     *
766
-     * @param int $qty
767
-     * @return void
768
-     * @throws \EE_Error
769
-     */
763
+	/**
764
+	 * Increases sold on related datetimes
765
+	 *
766
+	 * @param int $qty
767
+	 * @return void
768
+	 * @throws \EE_Error
769
+	 */
770 770
 	protected function _increase_sold_for_datetimes( $qty = 1 ) {
771 771
 		$datetimes = $this->datetimes();
772 772
 		if ( is_array( $datetimes ) ) {
@@ -781,34 +781,34 @@  discard block
 block discarded – undo
781 781
 
782 782
 
783 783
 
784
-    /**
785
-     * decrements (subtracts) sold by amount passed by $qty
786
-     *
787
-     * @param int $qty
788
-     * @return void
789
-     * @throws \EE_Error
790
-     */
784
+	/**
785
+	 * decrements (subtracts) sold by amount passed by $qty
786
+	 *
787
+	 * @param int $qty
788
+	 * @return void
789
+	 * @throws \EE_Error
790
+	 */
791 791
 	public function decrease_sold( $qty = 1 ) {
792 792
 		$sold = $this->sold() - $qty;
793 793
 		$this->_decrease_sold_for_datetimes( $qty );
794 794
 		$this->set_sold( $sold );
795
-        do_action(
796
-            'AHEE__EE_Ticket__decrease_sold',
797
-            $this,
798
-            $qty,
799
-            $sold
800
-        );
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * Decreases sold on related datetimes
807
-     *
808
-     * @param int $qty
809
-     * @return void
810
-     * @throws \EE_Error
811
-     */
795
+		do_action(
796
+			'AHEE__EE_Ticket__decrease_sold',
797
+			$this,
798
+			$qty,
799
+			$sold
800
+		);
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * Decreases sold on related datetimes
807
+	 *
808
+	 * @param int $qty
809
+	 * @return void
810
+	 * @throws \EE_Error
811
+	 */
812 812
 	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
813 813
 		$datetimes = $this->datetimes();
814 814
 		if ( is_array( $datetimes ) ) {
@@ -823,25 +823,25 @@  discard block
 block discarded – undo
823 823
 
824 824
 
825 825
 
826
-    /**
827
-     * Gets qty of reserved tickets
828
-     *
829
-     * @return int
830
-     * @throws \EE_Error
831
-     */
826
+	/**
827
+	 * Gets qty of reserved tickets
828
+	 *
829
+	 * @return int
830
+	 * @throws \EE_Error
831
+	 */
832 832
 	public function reserved() {
833 833
 		return $this->get_raw( 'TKT_reserved' );
834 834
 	}
835 835
 
836 836
 
837 837
 
838
-    /**
839
-     * Sets reserved
840
-     *
841
-     * @param int $reserved
842
-     * @return void
843
-     * @throws \EE_Error
844
-     */
838
+	/**
839
+	 * Sets reserved
840
+	 *
841
+	 * @param int $reserved
842
+	 * @return void
843
+	 * @throws \EE_Error
844
+	 */
845 845
 	public function set_reserved( $reserved ) {
846 846
 		// reserved can not go below zero
847 847
 		$reserved = max( 0, (int) $reserved );
@@ -849,48 +849,48 @@  discard block
 block discarded – undo
849 849
 	}
850 850
 
851 851
 
852
-    /**
853
-     * increments reserved by amount passed by $qty
854
-     *
855
-     * @param int    $qty
856
-     * @param string $source
857
-     * @return void
858
-     * @throws EE_Error
859
-     * @throws InvalidArgumentException
860
-     * @throws ReflectionException
861
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
862
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
863
-     */
852
+	/**
853
+	 * increments reserved by amount passed by $qty
854
+	 *
855
+	 * @param int    $qty
856
+	 * @param string $source
857
+	 * @return void
858
+	 * @throws EE_Error
859
+	 * @throws InvalidArgumentException
860
+	 * @throws ReflectionException
861
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
862
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
863
+	 */
864 864
 	public function increase_reserved( $qty = 1, $source = 'unknown' ) {
865 865
 		$qty = absint( $qty );
866 866
 		$reserved = $this->reserved() + $qty;
867
-        if (
868
-            $reserved
869
-            && $this->add_extra_meta(
870
-                EE_Ticket::META_KEY_TICKET_RESERVATIONS,
871
-                "{$qty} from {$source}"
872
-            )
873
-        ) {
874
-            $this->_increase_reserved_for_datetimes($qty);
875
-            $this->set_reserved($reserved);
876
-            do_action(
877
-                'AHEE__EE_Ticket__increase_reserved',
878
-                $this,
879
-                $qty,
880
-                $reserved
881
-            );
882
-        }
883
-    }
884
-
885
-
886
-
887
-    /**
888
-     * Increases sold on related datetimes
889
-     *
890
-     * @param int $qty
891
-     * @return void
892
-     * @throws \EE_Error
893
-     */
867
+		if (
868
+			$reserved
869
+			&& $this->add_extra_meta(
870
+				EE_Ticket::META_KEY_TICKET_RESERVATIONS,
871
+				"{$qty} from {$source}"
872
+			)
873
+		) {
874
+			$this->_increase_reserved_for_datetimes($qty);
875
+			$this->set_reserved($reserved);
876
+			do_action(
877
+				'AHEE__EE_Ticket__increase_reserved',
878
+				$this,
879
+				$qty,
880
+				$reserved
881
+			);
882
+		}
883
+	}
884
+
885
+
886
+
887
+	/**
888
+	 * Increases sold on related datetimes
889
+	 *
890
+	 * @param int $qty
891
+	 * @return void
892
+	 * @throws \EE_Error
893
+	 */
894 894
 	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
895 895
 		$datetimes = $this->datetimes();
896 896
 		if ( is_array( $datetimes ) ) {
@@ -904,49 +904,49 @@  discard block
 block discarded – undo
904 904
 	}
905 905
 
906 906
 
907
-    /**
908
-     * decrements (subtracts) reserved by amount passed by $qty
909
-     *
910
-     * @param int    $qty
911
-     * @param bool   $adjust_datetimes
912
-     * @param string $source
913
-     * @return void
914
-     * @throws EE_Error
915
-     * @throws InvalidArgumentException
916
-     * @throws ReflectionException
917
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
918
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
919
-     */
907
+	/**
908
+	 * decrements (subtracts) reserved by amount passed by $qty
909
+	 *
910
+	 * @param int    $qty
911
+	 * @param bool   $adjust_datetimes
912
+	 * @param string $source
913
+	 * @return void
914
+	 * @throws EE_Error
915
+	 * @throws InvalidArgumentException
916
+	 * @throws ReflectionException
917
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
918
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
919
+	 */
920 920
 	public function decrease_reserved( $qty = 1, $adjust_datetimes = true, $source = 'unknown' ) {
921 921
 		$reserved = $this->reserved() - absint( $qty );
922
-        if (
923
-            $this->add_extra_meta(
924
-                EE_Ticket::META_KEY_TICKET_RESERVATIONS,
925
-                "-{$qty} from {$source}"
926
-            )
927
-        ) {
928
-            if ($adjust_datetimes) {
929
-                $this->_decrease_reserved_for_datetimes($qty);
930
-            }
931
-            $this->set_reserved($reserved);
932
-            do_action(
933
-                'AHEE__EE_Ticket__decrease_reserved',
934
-                $this,
935
-                $qty,
936
-                $reserved
937
-            );
938
-        }
939
-    }
940
-
941
-
942
-
943
-    /**
944
-     * Increases sold on related datetimes
945
-     *
946
-     * @param int $qty
947
-     * @return void
948
-     * @throws \EE_Error
949
-     */
922
+		if (
923
+			$this->add_extra_meta(
924
+				EE_Ticket::META_KEY_TICKET_RESERVATIONS,
925
+				"-{$qty} from {$source}"
926
+			)
927
+		) {
928
+			if ($adjust_datetimes) {
929
+				$this->_decrease_reserved_for_datetimes($qty);
930
+			}
931
+			$this->set_reserved($reserved);
932
+			do_action(
933
+				'AHEE__EE_Ticket__decrease_reserved',
934
+				$this,
935
+				$qty,
936
+				$reserved
937
+			);
938
+		}
939
+	}
940
+
941
+
942
+
943
+	/**
944
+	 * Increases sold on related datetimes
945
+	 *
946
+	 * @param int $qty
947
+	 * @return void
948
+	 * @throws \EE_Error
949
+	 */
950 950
 	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
951 951
 		$datetimes = $this->datetimes();
952 952
 		if ( is_array( $datetimes ) ) {
@@ -961,18 +961,18 @@  discard block
 block discarded – undo
961 961
 
962 962
 
963 963
 
964
-    /**
965
-     * Gets ticket quantity
966
-     *
967
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
968
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
969
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
970
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
971
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
972
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
973
-     * @return int
974
-     * @throws \EE_Error
975
-     */
964
+	/**
965
+	 * Gets ticket quantity
966
+	 *
967
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
968
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
969
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
970
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
971
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
972
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
973
+	 * @return int
974
+	 * @throws \EE_Error
975
+	 */
976 976
 	public function qty( $context = '' ) {
977 977
 		switch ( $context ) {
978 978
 			case 'reg_limit' :
@@ -986,19 +986,19 @@  discard block
 block discarded – undo
986 986
 
987 987
 
988 988
 
989
-    /**
990
-     * Gets ticket quantity
991
-     *
992
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
993
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
994
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
995
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
996
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
997
-     * @param  int   $DTT_ID      the primary key for a particular datetime.
998
-     *                            set to 0 for all related datetimes
999
-     * @return int
1000
-     * @throws \EE_Error
1001
-     */
989
+	/**
990
+	 * Gets ticket quantity
991
+	 *
992
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
993
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
994
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
995
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
996
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
997
+	 * @param  int   $DTT_ID      the primary key for a particular datetime.
998
+	 *                            set to 0 for all related datetimes
999
+	 * @return int
1000
+	 * @throws \EE_Error
1001
+	 */
1002 1002
 	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
1003 1003
 		$raw = $this->get_raw( 'TKT_qty' );
1004 1004
 		// return immediately if it's zero
@@ -1081,212 +1081,212 @@  discard block
 block discarded – undo
1081 1081
 
1082 1082
 
1083 1083
 
1084
-    /**
1085
-     * Gets uses
1086
-     *
1087
-     * @return int
1088
-     * @throws \EE_Error
1089
-     */
1084
+	/**
1085
+	 * Gets uses
1086
+	 *
1087
+	 * @return int
1088
+	 * @throws \EE_Error
1089
+	 */
1090 1090
 	public function uses() {
1091 1091
 		return $this->get( 'TKT_uses' );
1092 1092
 	}
1093 1093
 
1094 1094
 
1095 1095
 
1096
-    /**
1097
-     * Sets uses
1098
-     *
1099
-     * @param int $uses
1100
-     * @return void
1101
-     * @throws \EE_Error
1102
-     */
1096
+	/**
1097
+	 * Sets uses
1098
+	 *
1099
+	 * @param int $uses
1100
+	 * @return void
1101
+	 * @throws \EE_Error
1102
+	 */
1103 1103
 	public function set_uses( $uses ) {
1104 1104
 		$this->set( 'TKT_uses', $uses );
1105 1105
 	}
1106 1106
 
1107 1107
 
1108 1108
 
1109
-    /**
1110
-     * returns whether ticket is required or not.
1111
-     *
1112
-     * @return boolean
1113
-     * @throws \EE_Error
1114
-     */
1109
+	/**
1110
+	 * returns whether ticket is required or not.
1111
+	 *
1112
+	 * @return boolean
1113
+	 * @throws \EE_Error
1114
+	 */
1115 1115
 	public function required() {
1116 1116
 		return $this->get( 'TKT_required' );
1117 1117
 	}
1118 1118
 
1119 1119
 
1120 1120
 
1121
-    /**
1122
-     * sets the TKT_required property
1123
-     *
1124
-     * @param boolean $required
1125
-     * @return void
1126
-     * @throws \EE_Error
1127
-     */
1121
+	/**
1122
+	 * sets the TKT_required property
1123
+	 *
1124
+	 * @param boolean $required
1125
+	 * @return void
1126
+	 * @throws \EE_Error
1127
+	 */
1128 1128
 	public function set_required( $required ) {
1129 1129
 		$this->set( 'TKT_required', $required );
1130 1130
 	}
1131 1131
 
1132 1132
 
1133 1133
 
1134
-    /**
1135
-     * Gets taxable
1136
-     *
1137
-     * @return boolean
1138
-     * @throws \EE_Error
1139
-     */
1134
+	/**
1135
+	 * Gets taxable
1136
+	 *
1137
+	 * @return boolean
1138
+	 * @throws \EE_Error
1139
+	 */
1140 1140
 	public function taxable() {
1141 1141
 		return $this->get( 'TKT_taxable' );
1142 1142
 	}
1143 1143
 
1144 1144
 
1145 1145
 
1146
-    /**
1147
-     * Sets taxable
1148
-     *
1149
-     * @param boolean $taxable
1150
-     * @return void
1151
-     * @throws \EE_Error
1152
-     */
1146
+	/**
1147
+	 * Sets taxable
1148
+	 *
1149
+	 * @param boolean $taxable
1150
+	 * @return void
1151
+	 * @throws \EE_Error
1152
+	 */
1153 1153
 	public function set_taxable( $taxable ) {
1154 1154
 		$this->set( 'TKT_taxable', $taxable );
1155 1155
 	}
1156 1156
 
1157 1157
 
1158 1158
 
1159
-    /**
1160
-     * Gets is_default
1161
-     *
1162
-     * @return boolean
1163
-     * @throws \EE_Error
1164
-     */
1159
+	/**
1160
+	 * Gets is_default
1161
+	 *
1162
+	 * @return boolean
1163
+	 * @throws \EE_Error
1164
+	 */
1165 1165
 	public function is_default() {
1166 1166
 		return $this->get( 'TKT_is_default' );
1167 1167
 	}
1168 1168
 
1169 1169
 
1170 1170
 
1171
-    /**
1172
-     * Sets is_default
1173
-     *
1174
-     * @param boolean $is_default
1175
-     * @return void
1176
-     * @throws \EE_Error
1177
-     */
1171
+	/**
1172
+	 * Sets is_default
1173
+	 *
1174
+	 * @param boolean $is_default
1175
+	 * @return void
1176
+	 * @throws \EE_Error
1177
+	 */
1178 1178
 	public function set_is_default( $is_default ) {
1179 1179
 		$this->set( 'TKT_is_default', $is_default );
1180 1180
 	}
1181 1181
 
1182 1182
 
1183 1183
 
1184
-    /**
1185
-     * Gets order
1186
-     *
1187
-     * @return int
1188
-     * @throws \EE_Error
1189
-     */
1184
+	/**
1185
+	 * Gets order
1186
+	 *
1187
+	 * @return int
1188
+	 * @throws \EE_Error
1189
+	 */
1190 1190
 	public function order() {
1191 1191
 		return $this->get( 'TKT_order' );
1192 1192
 	}
1193 1193
 
1194 1194
 
1195 1195
 
1196
-    /**
1197
-     * Sets order
1198
-     *
1199
-     * @param int $order
1200
-     * @return void
1201
-     * @throws \EE_Error
1202
-     */
1196
+	/**
1197
+	 * Sets order
1198
+	 *
1199
+	 * @param int $order
1200
+	 * @return void
1201
+	 * @throws \EE_Error
1202
+	 */
1203 1203
 	public function set_order( $order ) {
1204 1204
 		$this->set( 'TKT_order', $order );
1205 1205
 	}
1206 1206
 
1207 1207
 
1208 1208
 
1209
-    /**
1210
-     * Gets row
1211
-     *
1212
-     * @return int
1213
-     * @throws \EE_Error
1214
-     */
1209
+	/**
1210
+	 * Gets row
1211
+	 *
1212
+	 * @return int
1213
+	 * @throws \EE_Error
1214
+	 */
1215 1215
 	public function row() {
1216 1216
 		return $this->get( 'TKT_row' );
1217 1217
 	}
1218 1218
 
1219 1219
 
1220 1220
 
1221
-    /**
1222
-     * Sets row
1223
-     *
1224
-     * @param int $row
1225
-     * @return void
1226
-     * @throws \EE_Error
1227
-     */
1221
+	/**
1222
+	 * Sets row
1223
+	 *
1224
+	 * @param int $row
1225
+	 * @return void
1226
+	 * @throws \EE_Error
1227
+	 */
1228 1228
 	public function set_row( $row ) {
1229 1229
 		$this->set( 'TKT_row', $row );
1230 1230
 	}
1231 1231
 
1232 1232
 
1233 1233
 
1234
-    /**
1235
-     * Gets deleted
1236
-     *
1237
-     * @return boolean
1238
-     * @throws \EE_Error
1239
-     */
1234
+	/**
1235
+	 * Gets deleted
1236
+	 *
1237
+	 * @return boolean
1238
+	 * @throws \EE_Error
1239
+	 */
1240 1240
 	public function deleted() {
1241 1241
 		return $this->get( 'TKT_deleted' );
1242 1242
 	}
1243 1243
 
1244 1244
 
1245 1245
 
1246
-    /**
1247
-     * Sets deleted
1248
-     *
1249
-     * @param boolean $deleted
1250
-     * @return void
1251
-     * @throws \EE_Error
1252
-     */
1246
+	/**
1247
+	 * Sets deleted
1248
+	 *
1249
+	 * @param boolean $deleted
1250
+	 * @return void
1251
+	 * @throws \EE_Error
1252
+	 */
1253 1253
 	public function set_deleted( $deleted ) {
1254 1254
 		$this->set( 'TKT_deleted', $deleted );
1255 1255
 	}
1256 1256
 
1257 1257
 
1258 1258
 
1259
-    /**
1260
-     * Gets parent
1261
-     *
1262
-     * @return int
1263
-     * @throws \EE_Error
1264
-     */
1259
+	/**
1260
+	 * Gets parent
1261
+	 *
1262
+	 * @return int
1263
+	 * @throws \EE_Error
1264
+	 */
1265 1265
 	public function parent_ID() {
1266 1266
 		return $this->get( 'TKT_parent' );
1267 1267
 	}
1268 1268
 
1269 1269
 
1270 1270
 
1271
-    /**
1272
-     * Sets parent
1273
-     *
1274
-     * @param int $parent
1275
-     * @return void
1276
-     * @throws \EE_Error
1277
-     */
1271
+	/**
1272
+	 * Sets parent
1273
+	 *
1274
+	 * @param int $parent
1275
+	 * @return void
1276
+	 * @throws \EE_Error
1277
+	 */
1278 1278
 	public function set_parent_ID( $parent ) {
1279 1279
 		$this->set( 'TKT_parent', $parent );
1280 1280
 	}
1281 1281
 
1282 1282
 
1283 1283
 
1284
-    /**
1285
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1286
-     *
1287
-     * @return string
1288
-     * @throws \EE_Error
1289
-     */
1284
+	/**
1285
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1286
+	 *
1287
+	 * @return string
1288
+	 * @throws \EE_Error
1289
+	 */
1290 1290
 	public function name_and_info() {
1291 1291
 		$times = array();
1292 1292
 		foreach ( $this->datetimes() as $datetime ) {
@@ -1297,67 +1297,67 @@  discard block
 block discarded – undo
1297 1297
 
1298 1298
 
1299 1299
 
1300
-    /**
1301
-     * Gets name
1302
-     *
1303
-     * @return string
1304
-     * @throws \EE_Error
1305
-     */
1300
+	/**
1301
+	 * Gets name
1302
+	 *
1303
+	 * @return string
1304
+	 * @throws \EE_Error
1305
+	 */
1306 1306
 	public function name() {
1307 1307
 		return $this->get( 'TKT_name' );
1308 1308
 	}
1309 1309
 
1310 1310
 
1311 1311
 
1312
-    /**
1313
-     * Gets price
1314
-     *
1315
-     * @return float
1316
-     * @throws \EE_Error
1317
-     */
1312
+	/**
1313
+	 * Gets price
1314
+	 *
1315
+	 * @return float
1316
+	 * @throws \EE_Error
1317
+	 */
1318 1318
 	public function price() {
1319 1319
 		return $this->get( 'TKT_price' );
1320 1320
 	}
1321 1321
 
1322 1322
 
1323 1323
 
1324
-    /**
1325
-     * Gets all the registrations for this ticket
1326
-     *
1327
-     * @param array $query_params like EEM_Base::get_all's
1328
-     * @return EE_Registration[]|EE_Base_Class[]
1329
-     * @throws \EE_Error
1330
-     */
1324
+	/**
1325
+	 * Gets all the registrations for this ticket
1326
+	 *
1327
+	 * @param array $query_params like EEM_Base::get_all's
1328
+	 * @return EE_Registration[]|EE_Base_Class[]
1329
+	 * @throws \EE_Error
1330
+	 */
1331 1331
 	public function registrations( $query_params = array() ) {
1332 1332
 		return $this->get_many_related( 'Registration', $query_params );
1333 1333
 	}
1334 1334
 
1335 1335
 
1336 1336
 
1337
-    /**
1338
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1339
-     * into account
1340
-     *
1341
-     * @return int
1342
-     * @throws \EE_Error
1343
-     */
1337
+	/**
1338
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1339
+	 * into account
1340
+	 *
1341
+	 * @return int
1342
+	 * @throws \EE_Error
1343
+	 */
1344 1344
 	public function update_tickets_sold() {
1345
-        $count_regs_for_this_ticket = $this->count_registrations(
1346
-            array(
1347
-                array(
1348
-                    'STS_ID'      => EEM_Registration::status_id_approved,
1349
-                    'REG_deleted' => 0,
1350
-                ),
1351
-            )
1352
-        );
1353
-        $sold = $this->sold();
1354
-        if ($count_regs_for_this_ticket > $sold) {
1355
-            $this->increase_sold($count_regs_for_this_ticket - $sold);
1356
-            $this->save();
1357
-        } else if ($count_regs_for_this_ticket < $sold) {
1358
-            $this->decrease_sold($count_regs_for_this_ticket - $sold);
1359
-            $this->save();
1360
-        }
1345
+		$count_regs_for_this_ticket = $this->count_registrations(
1346
+			array(
1347
+				array(
1348
+					'STS_ID'      => EEM_Registration::status_id_approved,
1349
+					'REG_deleted' => 0,
1350
+				),
1351
+			)
1352
+		);
1353
+		$sold = $this->sold();
1354
+		if ($count_regs_for_this_ticket > $sold) {
1355
+			$this->increase_sold($count_regs_for_this_ticket - $sold);
1356
+			$this->save();
1357
+		} else if ($count_regs_for_this_ticket < $sold) {
1358
+			$this->decrease_sold($count_regs_for_this_ticket - $sold);
1359
+			$this->save();
1360
+		}
1361 1361
 		return $count_regs_for_this_ticket;
1362 1362
 	}
1363 1363
 
@@ -1385,21 +1385,21 @@  discard block
 block discarded – undo
1385 1385
 
1386 1386
 
1387 1387
 
1388
-    /**
1389
-     * Implementation of the EEI_Event_Relation interface method
1390
-     *
1391
-     * @see EEI_Event_Relation for comments
1392
-     * @return EE_Event
1393
-     * @throws \EE_Error
1394
-     * @throws UnexpectedEntityException
1395
-     */
1388
+	/**
1389
+	 * Implementation of the EEI_Event_Relation interface method
1390
+	 *
1391
+	 * @see EEI_Event_Relation for comments
1392
+	 * @return EE_Event
1393
+	 * @throws \EE_Error
1394
+	 * @throws UnexpectedEntityException
1395
+	 */
1396 1396
 	public function get_related_event() {
1397 1397
 		//get one datetime to use for getting the event
1398 1398
 		$datetime = $this->first_datetime();
1399 1399
 		if ( ! $datetime instanceof \EE_Datetime ) {
1400 1400
 			throw new UnexpectedEntityException(
1401 1401
 				$datetime,
1402
-                'EE_Datetime',
1402
+				'EE_Datetime',
1403 1403
 				sprintf(
1404 1404
 					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1405 1405
 					$this->name()
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
 		if ( ! $event instanceof \EE_Event ) {
1411 1411
 			throw new UnexpectedEntityException(
1412 1412
 				$event,
1413
-                'EE_Event',
1413
+				'EE_Event',
1414 1414
 				sprintf(
1415 1415
 					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1416 1416
 					$this->name()
@@ -1422,14 +1422,14 @@  discard block
 block discarded – undo
1422 1422
 
1423 1423
 
1424 1424
 
1425
-    /**
1426
-     * Implementation of the EEI_Event_Relation interface method
1427
-     *
1428
-     * @see EEI_Event_Relation for comments
1429
-     * @return string
1430
-     * @throws UnexpectedEntityException
1431
-     * @throws \EE_Error
1432
-     */
1425
+	/**
1426
+	 * Implementation of the EEI_Event_Relation interface method
1427
+	 *
1428
+	 * @see EEI_Event_Relation for comments
1429
+	 * @return string
1430
+	 * @throws UnexpectedEntityException
1431
+	 * @throws \EE_Error
1432
+	 */
1433 1433
 	public function get_event_name() {
1434 1434
 		$event = $this->get_related_event();
1435 1435
 		return $event instanceof EE_Event ? $event->name() : '';
@@ -1437,28 +1437,28 @@  discard block
 block discarded – undo
1437 1437
 
1438 1438
 
1439 1439
 
1440
-    /**
1441
-     * Implementation of the EEI_Event_Relation interface method
1442
-     *
1443
-     * @see EEI_Event_Relation for comments
1444
-     * @return int
1445
-     * @throws UnexpectedEntityException
1446
-     * @throws \EE_Error
1447
-     */
1440
+	/**
1441
+	 * Implementation of the EEI_Event_Relation interface method
1442
+	 *
1443
+	 * @see EEI_Event_Relation for comments
1444
+	 * @return int
1445
+	 * @throws UnexpectedEntityException
1446
+	 * @throws \EE_Error
1447
+	 */
1448 1448
 	public function get_event_ID() {
1449 1449
 		$event = $this->get_related_event();
1450 1450
 		return $event instanceof EE_Event ? $event->ID() : 0;
1451 1451
 	}
1452 1452
 
1453 1453
 
1454
-    /**
1455
-     * This simply returns whether a ticket can be permanently deleted or not.
1456
-     * The criteria for determining this is whether the ticket has any related registrations.
1457
-     * If there are none then it can be permanently deleted.
1458
-     *
1459
-     * @return bool
1460
-     */
1454
+	/**
1455
+	 * This simply returns whether a ticket can be permanently deleted or not.
1456
+	 * The criteria for determining this is whether the ticket has any related registrations.
1457
+	 * If there are none then it can be permanently deleted.
1458
+	 *
1459
+	 * @return bool
1460
+	 */
1461 1461
 	public function is_permanently_deleteable() {
1462
-	    return $this->count_registrations() === 0;
1463
-    }
1462
+		return $this->count_registrations() === 0;
1463
+	}
1464 1464
 } //end EE_Ticket class
Please login to merge, or discard this patch.
Spacing   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\UnexpectedEntityException;
2 2
 
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * Event Espresso
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
      * @return EE_Ticket
78 78
      * @throws \EE_Error
79 79
      */
80
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
81
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
82
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
80
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
81
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
82
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
83 83
 	}
84 84
 
85 85
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
      * @return EE_Ticket
92 92
      * @throws \EE_Error
93 93
      */
94
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
95
-		return new self( $props_n_values, TRUE, $timezone );
94
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
95
+		return new self($props_n_values, TRUE, $timezone);
96 96
 	}
97 97
 
98 98
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @throws \EE_Error
103 103
      */
104 104
 	public function parent() {
105
-		return $this->get( 'TKT_parent' );
105
+		return $this->get('TKT_parent');
106 106
 	}
107 107
 
108 108
 
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
      * @return boolean
115 115
      * @throws \EE_Error
116 116
      */
117
-	public function available( $DTT_ID = 0 ) {
117
+	public function available($DTT_ID = 0) {
118 118
 		// are we checking availability for a particular datetime ?
119
-		if ( $DTT_ID ) {
119
+		if ($DTT_ID) {
120 120
 			// get that datetime object
121
-			$datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) );
121
+			$datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID)));
122 122
 			// if  ticket sales for this datetime have exceeded the reg limit...
123
-			if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) {
123
+			if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
124 124
 				return FALSE;
125 125
 			}
126 126
 		}
@@ -138,22 +138,22 @@  discard block
 block discarded – undo
138 138
      * @return mixed status int if the display string isn't requested
139 139
      * @throws \EE_Error
140 140
      */
141
-	public function ticket_status( $display = FALSE, $remaining = null ) {
142
-		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
143
-		if ( ! $remaining ) {
144
-			return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out;
141
+	public function ticket_status($display = FALSE, $remaining = null) {
142
+		$remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
143
+		if ( ! $remaining) {
144
+			return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out;
145 145
 		}
146
-		if ( $this->get( 'TKT_deleted' ) ) {
147
-			return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived;
146
+		if ($this->get('TKT_deleted')) {
147
+			return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived;
148 148
 		}
149
-		if ( $this->is_expired() ) {
150
-			return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired;
149
+		if ($this->is_expired()) {
150
+			return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired;
151 151
 		}
152
-		if ( $this->is_pending() ) {
153
-			return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending;
152
+		if ($this->is_pending()) {
153
+			return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending;
154 154
 		}
155
-		if ( $this->is_on_sale() ) {
156
-			return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale;
155
+		if ($this->is_on_sale()) {
156
+			return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale;
157 157
 		}
158 158
 		return '';
159 159
 	}
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
      * @return boolean         true = tickets remaining, false not.
169 169
      * @throws \EE_Error
170 170
      */
171
-	public function is_remaining( $DTT_ID = 0 ) {
172
-		$num_remaining = $this->remaining( $DTT_ID );
173
-		if ( $num_remaining === 0 ) {
171
+	public function is_remaining($DTT_ID = 0) {
172
+		$num_remaining = $this->remaining($DTT_ID);
173
+		if ($num_remaining === 0) {
174 174
 			return FALSE;
175 175
 		}
176
-		if ( $num_remaining > 0 && $num_remaining < $this->min() ) {
176
+		if ($num_remaining > 0 && $num_remaining < $this->min()) {
177 177
 			return FALSE;
178 178
 		}
179 179
 		return TRUE;
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
      * @return int
190 190
      * @throws \EE_Error
191 191
      */
192
-	public function remaining( $DTT_ID = 0 ) {
193
-		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
192
+	public function remaining($DTT_ID = 0) {
193
+		return $this->real_quantity_on_ticket('saleable', $DTT_ID);
194 194
 	}
195 195
 
196 196
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      * @throws \EE_Error
203 203
      */
204 204
 	public function min() {
205
-		return $this->get( 'TKT_min' );
205
+		return $this->get('TKT_min');
206 206
 	}
207 207
 
208 208
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
      * @throws \EE_Error
215 215
      */
216 216
 	public function is_expired() {
217
-		return ( $this->get_raw( 'TKT_end_date' ) < time() );
217
+		return ($this->get_raw('TKT_end_date') < time());
218 218
 	}
219 219
 
220 220
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      * @throws \EE_Error
227 227
      */
228 228
 	public function is_pending() {
229
-		return ( $this->get_raw( 'TKT_start_date' ) > time() );
229
+		return ($this->get_raw('TKT_start_date') > time());
230 230
 	}
231 231
 
232 232
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      * @throws \EE_Error
239 239
      */
240 240
 	public function is_on_sale() {
241
-		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
241
+		return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time());
242 242
 	}
243 243
 
244 244
 
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
      * @return string
252 252
      * @throws \EE_Error
253 253
      */
254
-	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
255
-		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
256
-		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
254
+	public function date_range($dt_frmt = '', $conjunction = ' - ') {
255
+		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : '';
256
+		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : '';
257 257
 
258
-		return $first_date && $last_date ? $first_date . $conjunction  . $last_date : '';
258
+		return $first_date && $last_date ? $first_date.$conjunction.$last_date : '';
259 259
 	}
260 260
 
261 261
 
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
      * @throws \EE_Error
268 268
      */
269 269
 	public function first_datetime() {
270
-		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
271
-		return reset( $datetimes );
270
+		$datetimes = $this->datetimes(array('limit' => 1));
271
+		return reset($datetimes);
272 272
 	}
273 273
 
274 274
 
@@ -281,11 +281,11 @@  discard block
 block discarded – undo
281 281
      * @return EE_Datetime[]|EE_Base_Class[]
282 282
      * @throws \EE_Error
283 283
      */
284
-	public function datetimes( $query_params = array() ) {
285
-		if ( ! isset( $query_params[ 'order_by' ] ) ) {
286
-			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
284
+	public function datetimes($query_params = array()) {
285
+		if ( ! isset($query_params['order_by'])) {
286
+			$query_params['order_by']['DTT_order'] = 'ASC';
287 287
 		}
288
-		return $this->get_many_related( 'Datetime', $query_params );
288
+		return $this->get_many_related('Datetime', $query_params);
289 289
 	}
290 290
 
291 291
 
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
      * @throws \EE_Error
298 298
      */
299 299
 	public function last_datetime() {
300
-		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
301
-		return end( $datetimes );
300
+		$datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC')));
301
+		return end($datetimes);
302 302
 	}
303 303
 
304 304
 
@@ -316,22 +316,22 @@  discard block
 block discarded – undo
316 316
      * @return mixed (array|int)          how many tickets have sold
317 317
      * @throws \EE_Error
318 318
      */
319
-	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
319
+	public function tickets_sold($what = 'ticket', $dtt_id = NULL) {
320 320
 		$total = 0;
321 321
 		$tickets_sold = $this->_all_tickets_sold();
322
-		switch ( $what ) {
322
+		switch ($what) {
323 323
 			case 'ticket' :
324
-				return $tickets_sold[ 'ticket' ];
324
+				return $tickets_sold['ticket'];
325 325
 				break;
326 326
 			case 'datetime' :
327
-				if ( empty( $tickets_sold[ 'datetime' ] ) ) {
327
+				if (empty($tickets_sold['datetime'])) {
328 328
 					return $total;
329 329
 				}
330
-				if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) {
331
-					EE_Error::add_error( __( 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
330
+				if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) {
331
+					EE_Error::add_error(__('You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
332 332
 					return $total;
333 333
 				}
334
-				return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ];
334
+				return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id];
335 335
 				break;
336 336
 			default:
337 337
 				return $total;
@@ -347,15 +347,15 @@  discard block
 block discarded – undo
347 347
      * @throws \EE_Error
348 348
      */
349 349
 	protected function _all_tickets_sold() {
350
-		$datetimes = $this->get_many_related( 'Datetime' );
350
+		$datetimes = $this->get_many_related('Datetime');
351 351
 		$tickets_sold = array();
352
-		if ( ! empty( $datetimes ) ) {
353
-			foreach ( $datetimes as $datetime ) {
354
-				$tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' );
352
+		if ( ! empty($datetimes)) {
353
+			foreach ($datetimes as $datetime) {
354
+				$tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold');
355 355
 			}
356 356
 		}
357 357
 		//Tickets sold
358
-		$tickets_sold[ 'ticket' ] = $this->sold();
358
+		$tickets_sold['ticket'] = $this->sold();
359 359
 		return $tickets_sold;
360 360
 	}
361 361
 
@@ -368,11 +368,11 @@  discard block
 block discarded – undo
368 368
      * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
369 369
      * @throws \EE_Error
370 370
      */
371
-	public function base_price( $return_array = FALSE ) {
372
-		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
371
+	public function base_price($return_array = FALSE) {
372
+		$_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price);
373 373
 		return $return_array
374
-            ? $this->get_many_related( 'Price', array( $_where ) )
375
-            : $this->get_first_related( 'Price', array( $_where ) );
374
+            ? $this->get_many_related('Price', array($_where))
375
+            : $this->get_first_related('Price', array($_where));
376 376
 	}
377 377
 
378 378
 
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
      * @throws \EE_Error
386 386
      */
387 387
 	public function price_modifiers() {
388
-		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
389
-		return $this->prices( $query_params );
388
+		$query_params = array(0 => array('Price_Type.PBT_ID' => array('NOT IN', array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax))));
389
+		return $this->prices($query_params);
390 390
 	}
391 391
 
392 392
 
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
      * @return EE_Price[]|EE_Base_Class[]
399 399
      * @throws \EE_Error
400 400
      */
401
-	public function prices( $query_params = array() ) {
402
-		return $this->get_many_related( 'Price', $query_params );
401
+	public function prices($query_params = array()) {
402
+		return $this->get_many_related('Price', $query_params);
403 403
 	}
404 404
 
405 405
 
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
      * @return EE_Datetime_Ticket|EE_Base_Class[]
412 412
      * @throws \EE_Error
413 413
      */
414
-	public function datetime_tickets( $query_params = array() ) {
415
-		return $this->get_many_related( 'Datetime_Ticket', $query_params );
414
+	public function datetime_tickets($query_params = array()) {
415
+		return $this->get_many_related('Datetime_Ticket', $query_params);
416 416
 	}
417 417
 
418 418
 
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
      * @return EE_Datetime[]
426 426
      * @throws \EE_Error
427 427
      */
428
-	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
429
-		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
428
+	public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) {
429
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted);
430 430
 	}
431 431
 
432 432
 
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
      * @throws \EE_Error
439 439
      */
440 440
 	public function ID() {
441
-		return $this->get( 'TKT_ID' );
441
+		return $this->get('TKT_ID');
442 442
 	}
443 443
 
444 444
 
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
      * @throws \EE_Error
464 464
      */
465 465
 	public function template() {
466
-		return $this->get_first_related( 'Ticket_Template' );
466
+		return $this->get_first_related('Ticket_Template');
467 467
 	}
468 468
 
469 469
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
      * @throws \EE_Error
486 486
      */
487 487
 	public function ticket_price() {
488
-		return $this->get( 'TKT_price' );
488
+		return $this->get('TKT_price');
489 489
 	}
490 490
 
491 491
 
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
      * @throws \EE_Error
496 496
      */
497 497
 	public function pretty_price() {
498
-		return $this->get_pretty( 'TKT_price' );
498
+		return $this->get_pretty('TKT_price');
499 499
 	}
500 500
 
501 501
 
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
      * @return float
518 518
      * @throws \EE_Error
519 519
      */
520
-	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
521
-		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
520
+	public function get_ticket_total_with_taxes($no_cache = FALSE) {
521
+		if ($this->_ticket_total_with_taxes === null || $no_cache) {
522 522
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
523 523
 		}
524 524
 		return (float) $this->_ticket_total_with_taxes;
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 
528 528
 
529 529
 	public function ensure_TKT_Price_correct() {
530
-		$this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) );
530
+		$this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
531 531
 		$this->save();
532 532
 	}
533 533
 
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
      * @throws \EE_Error
539 539
      */
540 540
 	public function get_ticket_subtotal() {
541
-		return EE_Taxes::get_subtotal_for_admin( $this );
541
+		return EE_Taxes::get_subtotal_for_admin($this);
542 542
 	}
543 543
 
544 544
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
      * @throws \EE_Error
551 551
      */
552 552
 	public function get_ticket_taxes_total_for_admin() {
553
-		return EE_Taxes::get_total_taxes_for_admin( $this );
553
+		return EE_Taxes::get_total_taxes_for_admin($this);
554 554
 	}
555 555
 
556 556
 
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
      * @param string $name
562 562
      * @throws \EE_Error
563 563
      */
564
-	public function set_name( $name ) {
565
-		$this->set( 'TKT_name', $name );
564
+	public function set_name($name) {
565
+		$this->set('TKT_name', $name);
566 566
 	}
567 567
 
568 568
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      * @throws \EE_Error
575 575
      */
576 576
 	public function description() {
577
-		return $this->get( 'TKT_description' );
577
+		return $this->get('TKT_description');
578 578
 	}
579 579
 
580 580
 
@@ -585,8 +585,8 @@  discard block
 block discarded – undo
585 585
      * @param string $description
586 586
      * @throws \EE_Error
587 587
      */
588
-	public function set_description( $description ) {
589
-		$this->set( 'TKT_description', $description );
588
+	public function set_description($description) {
589
+		$this->set('TKT_description', $description);
590 590
 	}
591 591
 
592 592
 
@@ -599,8 +599,8 @@  discard block
 block discarded – undo
599 599
      * @return string
600 600
      * @throws \EE_Error
601 601
      */
602
-	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
603
-		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
602
+	public function start_date($dt_frmt = '', $tm_frmt = '') {
603
+		return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt);
604 604
 	}
605 605
 
606 606
 
@@ -612,8 +612,8 @@  discard block
 block discarded – undo
612 612
      * @return void
613 613
      * @throws \EE_Error
614 614
      */
615
-	public function set_start_date( $start_date ) {
616
-		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
615
+	public function set_start_date($start_date) {
616
+		$this->_set_date_time('B', $start_date, 'TKT_start_date');
617 617
 	}
618 618
 
619 619
 
@@ -626,8 +626,8 @@  discard block
 block discarded – undo
626 626
      * @return string
627 627
      * @throws \EE_Error
628 628
      */
629
-	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
630
-		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
629
+	public function end_date($dt_frmt = '', $tm_frmt = '') {
630
+		return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt);
631 631
 	}
632 632
 
633 633
 
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
      * @return void
640 640
      * @throws \EE_Error
641 641
      */
642
-	public function set_end_date( $end_date ) {
643
-		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
642
+	public function set_end_date($end_date) {
643
+		$this->_set_date_time('B', $end_date, 'TKT_end_date');
644 644
 	}
645 645
 
646 646
 
@@ -652,8 +652,8 @@  discard block
 block discarded – undo
652 652
      * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
653 653
      * @throws \EE_Error
654 654
      */
655
-	public function set_end_time( $time ) {
656
-		$this->_set_time_for( $time, 'TKT_end_date' );
655
+	public function set_end_time($time) {
656
+		$this->_set_time_for($time, 'TKT_end_date');
657 657
 	}
658 658
 
659 659
 
@@ -665,8 +665,8 @@  discard block
 block discarded – undo
665 665
      * @return void
666 666
      * @throws \EE_Error
667 667
      */
668
-	public function set_min( $min ) {
669
-		$this->set( 'TKT_min', $min );
668
+	public function set_min($min) {
669
+		$this->set('TKT_min', $min);
670 670
 	}
671 671
 
672 672
 
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
      * @throws \EE_Error
679 679
      */
680 680
 	public function max() {
681
-		return $this->get( 'TKT_max' );
681
+		return $this->get('TKT_max');
682 682
 	}
683 683
 
684 684
 
@@ -690,8 +690,8 @@  discard block
 block discarded – undo
690 690
      * @return void
691 691
      * @throws \EE_Error
692 692
      */
693
-	public function set_max( $max ) {
694
-		$this->set( 'TKT_max', $max );
693
+	public function set_max($max) {
694
+		$this->set('TKT_max', $max);
695 695
 	}
696 696
 
697 697
 
@@ -703,8 +703,8 @@  discard block
 block discarded – undo
703 703
      * @return void
704 704
      * @throws \EE_Error
705 705
      */
706
-	public function set_price( $price ) {
707
-		$this->set( 'TKT_price', $price );
706
+	public function set_price($price) {
707
+		$this->set('TKT_price', $price);
708 708
 	}
709 709
 
710 710
 
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
      * @throws \EE_Error
717 717
      */
718 718
 	public function sold() {
719
-		return $this->get_raw( 'TKT_sold' );
719
+		return $this->get_raw('TKT_sold');
720 720
 	}
721 721
 
722 722
 
@@ -728,10 +728,10 @@  discard block
 block discarded – undo
728 728
      * @return void
729 729
      * @throws \EE_Error
730 730
      */
731
-	public function set_sold( $sold ) {
731
+	public function set_sold($sold) {
732 732
 		// sold can not go below zero
733
-		$sold = max( 0, $sold );
734
-		$this->set( 'TKT_sold', $sold );
733
+		$sold = max(0, $sold);
734
+		$this->set('TKT_sold', $sold);
735 735
 	}
736 736
 
737 737
 
@@ -743,13 +743,13 @@  discard block
 block discarded – undo
743 743
      * @return void
744 744
      * @throws \EE_Error
745 745
      */
746
-	public function increase_sold( $qty = 1 ) {
746
+	public function increase_sold($qty = 1) {
747 747
 		$sold = $this->sold() + $qty;
748 748
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
749 749
 		// via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called
750
-		$this->decrease_reserved( $qty, false, "TKT: {$this->ID()} (ln:" . __LINE__ . ')');
751
-		$this->_increase_sold_for_datetimes( $qty );
752
-		$this->set_sold( $sold );
750
+		$this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:".__LINE__.')');
751
+		$this->_increase_sold_for_datetimes($qty);
752
+		$this->set_sold($sold);
753 753
 		do_action(
754 754
 		    'AHEE__EE_Ticket__increase_sold',
755 755
             $this,
@@ -767,12 +767,12 @@  discard block
 block discarded – undo
767 767
      * @return void
768 768
      * @throws \EE_Error
769 769
      */
770
-	protected function _increase_sold_for_datetimes( $qty = 1 ) {
770
+	protected function _increase_sold_for_datetimes($qty = 1) {
771 771
 		$datetimes = $this->datetimes();
772
-		if ( is_array( $datetimes ) ) {
773
-			foreach ( $datetimes as $datetime ) {
774
-				if ( $datetime instanceof EE_Datetime ) {
775
-					$datetime->increase_sold( $qty );
772
+		if (is_array($datetimes)) {
773
+			foreach ($datetimes as $datetime) {
774
+				if ($datetime instanceof EE_Datetime) {
775
+					$datetime->increase_sold($qty);
776 776
 					$datetime->save();
777 777
 				}
778 778
 			}
@@ -788,10 +788,10 @@  discard block
 block discarded – undo
788 788
      * @return void
789 789
      * @throws \EE_Error
790 790
      */
791
-	public function decrease_sold( $qty = 1 ) {
791
+	public function decrease_sold($qty = 1) {
792 792
 		$sold = $this->sold() - $qty;
793
-		$this->_decrease_sold_for_datetimes( $qty );
794
-		$this->set_sold( $sold );
793
+		$this->_decrease_sold_for_datetimes($qty);
794
+		$this->set_sold($sold);
795 795
         do_action(
796 796
             'AHEE__EE_Ticket__decrease_sold',
797 797
             $this,
@@ -809,12 +809,12 @@  discard block
 block discarded – undo
809 809
      * @return void
810 810
      * @throws \EE_Error
811 811
      */
812
-	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
812
+	protected function _decrease_sold_for_datetimes($qty = 1) {
813 813
 		$datetimes = $this->datetimes();
814
-		if ( is_array( $datetimes ) ) {
815
-			foreach ( $datetimes as $datetime ) {
816
-				if ( $datetime instanceof EE_Datetime ) {
817
-					$datetime->decrease_sold( $qty );
814
+		if (is_array($datetimes)) {
815
+			foreach ($datetimes as $datetime) {
816
+				if ($datetime instanceof EE_Datetime) {
817
+					$datetime->decrease_sold($qty);
818 818
 					$datetime->save();
819 819
 				}
820 820
 			}
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
      * @throws \EE_Error
831 831
      */
832 832
 	public function reserved() {
833
-		return $this->get_raw( 'TKT_reserved' );
833
+		return $this->get_raw('TKT_reserved');
834 834
 	}
835 835
 
836 836
 
@@ -842,10 +842,10 @@  discard block
 block discarded – undo
842 842
      * @return void
843 843
      * @throws \EE_Error
844 844
      */
845
-	public function set_reserved( $reserved ) {
845
+	public function set_reserved($reserved) {
846 846
 		// reserved can not go below zero
847
-		$reserved = max( 0, (int) $reserved );
848
-		$this->set( 'TKT_reserved', $reserved );
847
+		$reserved = max(0, (int) $reserved);
848
+		$this->set('TKT_reserved', $reserved);
849 849
 	}
850 850
 
851 851
 
@@ -861,8 +861,8 @@  discard block
 block discarded – undo
861 861
      * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
862 862
      * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
863 863
      */
864
-	public function increase_reserved( $qty = 1, $source = 'unknown' ) {
865
-		$qty = absint( $qty );
864
+	public function increase_reserved($qty = 1, $source = 'unknown') {
865
+		$qty = absint($qty);
866 866
 		$reserved = $this->reserved() + $qty;
867 867
         if (
868 868
             $reserved
@@ -891,12 +891,12 @@  discard block
 block discarded – undo
891 891
      * @return void
892 892
      * @throws \EE_Error
893 893
      */
894
-	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
894
+	protected function _increase_reserved_for_datetimes($qty = 1) {
895 895
 		$datetimes = $this->datetimes();
896
-		if ( is_array( $datetimes ) ) {
897
-			foreach ( $datetimes as $datetime ) {
898
-				if ( $datetime instanceof EE_Datetime ) {
899
-					$datetime->increase_reserved( $qty );
896
+		if (is_array($datetimes)) {
897
+			foreach ($datetimes as $datetime) {
898
+				if ($datetime instanceof EE_Datetime) {
899
+					$datetime->increase_reserved($qty);
900 900
 					$datetime->save();
901 901
 				}
902 902
 			}
@@ -917,8 +917,8 @@  discard block
 block discarded – undo
917 917
      * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
918 918
      * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
919 919
      */
920
-	public function decrease_reserved( $qty = 1, $adjust_datetimes = true, $source = 'unknown' ) {
921
-		$reserved = $this->reserved() - absint( $qty );
920
+	public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') {
921
+		$reserved = $this->reserved() - absint($qty);
922 922
         if (
923 923
             $this->add_extra_meta(
924 924
                 EE_Ticket::META_KEY_TICKET_RESERVATIONS,
@@ -947,12 +947,12 @@  discard block
 block discarded – undo
947 947
      * @return void
948 948
      * @throws \EE_Error
949 949
      */
950
-	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
950
+	protected function _decrease_reserved_for_datetimes($qty = 1) {
951 951
 		$datetimes = $this->datetimes();
952
-		if ( is_array( $datetimes ) ) {
953
-			foreach ( $datetimes as $datetime ) {
954
-				if ( $datetime instanceof EE_Datetime ) {
955
-					$datetime->decrease_reserved( $qty );
952
+		if (is_array($datetimes)) {
953
+			foreach ($datetimes as $datetime) {
954
+				if ($datetime instanceof EE_Datetime) {
955
+					$datetime->decrease_reserved($qty);
956 956
 					$datetime->save();
957 957
 				}
958 958
 			}
@@ -973,14 +973,14 @@  discard block
 block discarded – undo
973 973
      * @return int
974 974
      * @throws \EE_Error
975 975
      */
976
-	public function qty( $context = '' ) {
977
-		switch ( $context ) {
976
+	public function qty($context = '') {
977
+		switch ($context) {
978 978
 			case 'reg_limit' :
979 979
 				return $this->real_quantity_on_ticket();
980 980
 			case 'saleable' :
981
-				return $this->real_quantity_on_ticket( 'saleable' );
981
+				return $this->real_quantity_on_ticket('saleable');
982 982
 			default:
983
-				return $this->get_raw( 'TKT_qty' );
983
+				return $this->get_raw('TKT_qty');
984 984
 		}
985 985
 	}
986 986
 
@@ -999,15 +999,15 @@  discard block
 block discarded – undo
999 999
      * @return int
1000 1000
      * @throws \EE_Error
1001 1001
      */
1002
-	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
1003
-		$raw = $this->get_raw( 'TKT_qty' );
1002
+	public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) {
1003
+		$raw = $this->get_raw('TKT_qty');
1004 1004
 		// return immediately if it's zero
1005
-		if ( $raw === 0 ) {
1005
+		if ($raw === 0) {
1006 1006
 			return $raw;
1007 1007
 		}
1008 1008
 		//echo "\n\n<br />Ticket: " . $this->name() . '<br />';
1009 1009
 		// ensure qty doesn't exceed raw value for THIS ticket
1010
-		$qty = min( EE_INF, $raw );
1010
+		$qty = min(EE_INF, $raw);
1011 1011
 		//echo "\n . qty: " . $qty . '<br />';
1012 1012
 		// calculate this ticket's total sales and reservations
1013 1013
 		$sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
@@ -1016,23 +1016,23 @@  discard block
 block discarded – undo
1016 1016
 		//echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
1017 1017
 		// first we need to calculate the maximum number of tickets available for the datetime
1018 1018
 		// do we want data for one datetime or all of them ?
1019
-		$query_params = $DTT_ID ? array( array( 'DTT_ID' => $DTT_ID ) ) : array();
1020
-		$datetimes = $this->datetimes( $query_params );
1021
-		if ( is_array( $datetimes ) && ! empty( $datetimes ) ) {
1022
-			foreach ( $datetimes as $datetime ) {
1023
-				if ( $datetime instanceof EE_Datetime ) {
1019
+		$query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array();
1020
+		$datetimes = $this->datetimes($query_params);
1021
+		if (is_array($datetimes) && ! empty($datetimes)) {
1022
+			foreach ($datetimes as $datetime) {
1023
+				if ($datetime instanceof EE_Datetime) {
1024 1024
 					$datetime->refresh_from_db();
1025 1025
 					//echo "\n . . datetime name: " . $datetime->name() . '<br />';
1026 1026
 					//echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
1027 1027
 					// initialize with no restrictions for each datetime
1028 1028
 					// but adjust datetime qty based on datetime reg limit
1029
-					$datetime_qty = min( EE_INF, $datetime->reg_limit() );
1029
+					$datetime_qty = min(EE_INF, $datetime->reg_limit());
1030 1030
 					//echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
1031 1031
 					//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1032 1032
 					// if we want the actual saleable amount, then we need to consider OTHER ticket sales
1033 1033
 					// and reservations for this datetime, that do NOT include sales and reservations
1034 1034
 					// for this ticket (so we add $this->sold() and $this->reserved() back in)
1035
-					if ( $context === 'saleable' ) {
1035
+					if ($context === 'saleable') {
1036 1036
 						$datetime_qty = max(
1037 1037
 							$datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
1038 1038
 							0
@@ -1044,16 +1044,16 @@  discard block
 block discarded – undo
1044 1044
 						$datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
1045 1045
 						//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1046 1046
 					}
1047
-					$qty = min( $datetime_qty, $qty );
1047
+					$qty = min($datetime_qty, $qty);
1048 1048
 					//echo "\n . . qty: " . $qty . '<br />';
1049 1049
 				}
1050 1050
 			}
1051 1051
 		}
1052 1052
 		// NOW that we know the  maximum number of tickets available for the datetime
1053 1053
 		// we can finally factor in the details for this specific ticket
1054
-		if ( $qty > 0 && $context === 'saleable' ) {
1054
+		if ($qty > 0 && $context === 'saleable') {
1055 1055
 			// and subtract the sales for THIS ticket
1056
-			$qty = max( $qty - $sold_and_reserved_for_this_ticket, 0 );
1056
+			$qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1057 1057
 			//echo "\n . qty: " . $qty . '<br />';
1058 1058
 		}
1059 1059
 		//echo "\nFINAL QTY: " . $qty . "<br /><br />";
@@ -1069,14 +1069,14 @@  discard block
 block discarded – undo
1069 1069
 	 * @return void
1070 1070
 	 * @throws \EE_Error
1071 1071
 	 */
1072
-	public function set_qty( $qty ) {
1072
+	public function set_qty($qty) {
1073 1073
 		$datetimes = $this->datetimes();
1074
-		foreach ( $datetimes as $datetime ) {
1075
-			if ( $datetime instanceof EE_Datetime ) {
1076
-				$qty = min( $qty, $datetime->reg_limit() );
1074
+		foreach ($datetimes as $datetime) {
1075
+			if ($datetime instanceof EE_Datetime) {
1076
+				$qty = min($qty, $datetime->reg_limit());
1077 1077
 			}
1078 1078
 		}
1079
-		$this->set( 'TKT_qty', $qty );
1079
+		$this->set('TKT_qty', $qty);
1080 1080
 	}
1081 1081
 
1082 1082
 
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
      * @throws \EE_Error
1089 1089
      */
1090 1090
 	public function uses() {
1091
-		return $this->get( 'TKT_uses' );
1091
+		return $this->get('TKT_uses');
1092 1092
 	}
1093 1093
 
1094 1094
 
@@ -1100,8 +1100,8 @@  discard block
 block discarded – undo
1100 1100
      * @return void
1101 1101
      * @throws \EE_Error
1102 1102
      */
1103
-	public function set_uses( $uses ) {
1104
-		$this->set( 'TKT_uses', $uses );
1103
+	public function set_uses($uses) {
1104
+		$this->set('TKT_uses', $uses);
1105 1105
 	}
1106 1106
 
1107 1107
 
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
      * @throws \EE_Error
1114 1114
      */
1115 1115
 	public function required() {
1116
-		return $this->get( 'TKT_required' );
1116
+		return $this->get('TKT_required');
1117 1117
 	}
1118 1118
 
1119 1119
 
@@ -1125,8 +1125,8 @@  discard block
 block discarded – undo
1125 1125
      * @return void
1126 1126
      * @throws \EE_Error
1127 1127
      */
1128
-	public function set_required( $required ) {
1129
-		$this->set( 'TKT_required', $required );
1128
+	public function set_required($required) {
1129
+		$this->set('TKT_required', $required);
1130 1130
 	}
1131 1131
 
1132 1132
 
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
      * @throws \EE_Error
1139 1139
      */
1140 1140
 	public function taxable() {
1141
-		return $this->get( 'TKT_taxable' );
1141
+		return $this->get('TKT_taxable');
1142 1142
 	}
1143 1143
 
1144 1144
 
@@ -1150,8 +1150,8 @@  discard block
 block discarded – undo
1150 1150
      * @return void
1151 1151
      * @throws \EE_Error
1152 1152
      */
1153
-	public function set_taxable( $taxable ) {
1154
-		$this->set( 'TKT_taxable', $taxable );
1153
+	public function set_taxable($taxable) {
1154
+		$this->set('TKT_taxable', $taxable);
1155 1155
 	}
1156 1156
 
1157 1157
 
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
      * @throws \EE_Error
1164 1164
      */
1165 1165
 	public function is_default() {
1166
-		return $this->get( 'TKT_is_default' );
1166
+		return $this->get('TKT_is_default');
1167 1167
 	}
1168 1168
 
1169 1169
 
@@ -1175,8 +1175,8 @@  discard block
 block discarded – undo
1175 1175
      * @return void
1176 1176
      * @throws \EE_Error
1177 1177
      */
1178
-	public function set_is_default( $is_default ) {
1179
-		$this->set( 'TKT_is_default', $is_default );
1178
+	public function set_is_default($is_default) {
1179
+		$this->set('TKT_is_default', $is_default);
1180 1180
 	}
1181 1181
 
1182 1182
 
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
      * @throws \EE_Error
1189 1189
      */
1190 1190
 	public function order() {
1191
-		return $this->get( 'TKT_order' );
1191
+		return $this->get('TKT_order');
1192 1192
 	}
1193 1193
 
1194 1194
 
@@ -1200,8 +1200,8 @@  discard block
 block discarded – undo
1200 1200
      * @return void
1201 1201
      * @throws \EE_Error
1202 1202
      */
1203
-	public function set_order( $order ) {
1204
-		$this->set( 'TKT_order', $order );
1203
+	public function set_order($order) {
1204
+		$this->set('TKT_order', $order);
1205 1205
 	}
1206 1206
 
1207 1207
 
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
      * @throws \EE_Error
1214 1214
      */
1215 1215
 	public function row() {
1216
-		return $this->get( 'TKT_row' );
1216
+		return $this->get('TKT_row');
1217 1217
 	}
1218 1218
 
1219 1219
 
@@ -1225,8 +1225,8 @@  discard block
 block discarded – undo
1225 1225
      * @return void
1226 1226
      * @throws \EE_Error
1227 1227
      */
1228
-	public function set_row( $row ) {
1229
-		$this->set( 'TKT_row', $row );
1228
+	public function set_row($row) {
1229
+		$this->set('TKT_row', $row);
1230 1230
 	}
1231 1231
 
1232 1232
 
@@ -1238,7 +1238,7 @@  discard block
 block discarded – undo
1238 1238
      * @throws \EE_Error
1239 1239
      */
1240 1240
 	public function deleted() {
1241
-		return $this->get( 'TKT_deleted' );
1241
+		return $this->get('TKT_deleted');
1242 1242
 	}
1243 1243
 
1244 1244
 
@@ -1250,8 +1250,8 @@  discard block
 block discarded – undo
1250 1250
      * @return void
1251 1251
      * @throws \EE_Error
1252 1252
      */
1253
-	public function set_deleted( $deleted ) {
1254
-		$this->set( 'TKT_deleted', $deleted );
1253
+	public function set_deleted($deleted) {
1254
+		$this->set('TKT_deleted', $deleted);
1255 1255
 	}
1256 1256
 
1257 1257
 
@@ -1263,7 +1263,7 @@  discard block
 block discarded – undo
1263 1263
      * @throws \EE_Error
1264 1264
      */
1265 1265
 	public function parent_ID() {
1266
-		return $this->get( 'TKT_parent' );
1266
+		return $this->get('TKT_parent');
1267 1267
 	}
1268 1268
 
1269 1269
 
@@ -1275,8 +1275,8 @@  discard block
 block discarded – undo
1275 1275
      * @return void
1276 1276
      * @throws \EE_Error
1277 1277
      */
1278
-	public function set_parent_ID( $parent ) {
1279
-		$this->set( 'TKT_parent', $parent );
1278
+	public function set_parent_ID($parent) {
1279
+		$this->set('TKT_parent', $parent);
1280 1280
 	}
1281 1281
 
1282 1282
 
@@ -1289,10 +1289,10 @@  discard block
 block discarded – undo
1289 1289
      */
1290 1290
 	public function name_and_info() {
1291 1291
 		$times = array();
1292
-		foreach ( $this->datetimes() as $datetime ) {
1292
+		foreach ($this->datetimes() as $datetime) {
1293 1293
 			$times[] = $datetime->start_date_and_time();
1294 1294
 		}
1295
-		return $this->name() . ' @ ' . implode( ', ', $times ) . ' for ' . $this->pretty_price();
1295
+		return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price();
1296 1296
 	}
1297 1297
 
1298 1298
 
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
      * @throws \EE_Error
1305 1305
      */
1306 1306
 	public function name() {
1307
-		return $this->get( 'TKT_name' );
1307
+		return $this->get('TKT_name');
1308 1308
 	}
1309 1309
 
1310 1310
 
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
      * @throws \EE_Error
1317 1317
      */
1318 1318
 	public function price() {
1319
-		return $this->get( 'TKT_price' );
1319
+		return $this->get('TKT_price');
1320 1320
 	}
1321 1321
 
1322 1322
 
@@ -1328,8 +1328,8 @@  discard block
 block discarded – undo
1328 1328
      * @return EE_Registration[]|EE_Base_Class[]
1329 1329
      * @throws \EE_Error
1330 1330
      */
1331
-	public function registrations( $query_params = array() ) {
1332
-		return $this->get_many_related( 'Registration', $query_params );
1331
+	public function registrations($query_params = array()) {
1332
+		return $this->get_many_related('Registration', $query_params);
1333 1333
 	}
1334 1334
 
1335 1335
 
@@ -1368,7 +1368,7 @@  discard block
 block discarded – undo
1368 1368
 	 * @param array $query_params like EEM_Base::get_all's
1369 1369
 	 * @return int
1370 1370
 	 */
1371
-	public function count_registrations( $query_params = array() ) {
1371
+	public function count_registrations($query_params = array()) {
1372 1372
 		return $this->count_related('Registration', $query_params);
1373 1373
 	}
1374 1374
 
@@ -1396,23 +1396,23 @@  discard block
 block discarded – undo
1396 1396
 	public function get_related_event() {
1397 1397
 		//get one datetime to use for getting the event
1398 1398
 		$datetime = $this->first_datetime();
1399
-		if ( ! $datetime instanceof \EE_Datetime ) {
1399
+		if ( ! $datetime instanceof \EE_Datetime) {
1400 1400
 			throw new UnexpectedEntityException(
1401 1401
 				$datetime,
1402 1402
                 'EE_Datetime',
1403 1403
 				sprintf(
1404
-					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1404
+					__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1405 1405
 					$this->name()
1406 1406
 				)
1407 1407
 			);
1408 1408
 		}
1409 1409
 		$event = $datetime->event();
1410
-		if ( ! $event instanceof \EE_Event ) {
1410
+		if ( ! $event instanceof \EE_Event) {
1411 1411
 			throw new UnexpectedEntityException(
1412 1412
 				$event,
1413 1413
                 'EE_Event',
1414 1414
 				sprintf(
1415
-					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1415
+					__('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1416 1416
 					$this->name()
1417 1417
 				)
1418 1418
 			);
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/forms/SettingsForm.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
     public function _validate()
116 116
     {
117 117
         parent::_validate();
118
-        if (! $this->_payment_method_type instanceof \EE_PMT_Paypal_Express) {
118
+        if ( ! $this->_payment_method_type instanceof \EE_PMT_Paypal_Express) {
119 119
             throw new EntityNotFoundException('EE_PMT_Paypal_Express', '$this->_payment_method_type');
120 120
         }
121
-        if (! $this->_payment_method_type->get_gateway() instanceof \EEG_Paypal_Express) {
121
+        if ( ! $this->_payment_method_type->get_gateway() instanceof \EEG_Paypal_Express) {
122 122
             throw new EntityNotFoundException('EEG_Paypal_Express', '$this->_payment_method_type->get_gateway()');
123 123
         }
124 124
         $credentials_message = $this->checkForCredentialsErrors();
125
-        if( $credentials_message !== '') {
125
+        if ($credentials_message !== '') {
126 126
             $this->add_validation_error($credentials_message);
127 127
             $this->get_input('PMD_debug_mode')->add_validation_error(
128 128
                 esc_html__('If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', 'event_espresso')
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      * Gets the HTML to show the link to the help tab
155 155
      * @return string
156 156
      */
157
-    protected function helpTabLink(){
157
+    protected function helpTabLink() {
158 158
         return $this->helpTabLink;
159 159
     }
160 160
     /**
Please login to merge, or discard this patch.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -24,210 +24,210 @@
 block discarded – undo
24 24
 class SettingsForm extends EE_Payment_Method_Form
25 25
 {
26 26
 
27
-    /**
28
-     * @var string of HTML being the help tab link
29
-     */
30
-    protected $helpTabLink;
27
+	/**
28
+	 * @var string of HTML being the help tab link
29
+	 */
30
+	protected $helpTabLink;
31 31
 
32
-    /**
33
-     * SettingsForm constructor.
34
-     *
35
-     * @param array $options_array
36
-     * @param string     $help_tab_link
37
-     */
38
-    public function __construct(array $options_array = array(), $help_tab_link)
39
-    {
40
-        $this->helpTabLink = $help_tab_link;
41
-        $options_array = array_replace_recursive(
42
-            array(
43
-                'extra_meta_inputs' => array(
44
-                    'api_username' => new EE_Text_Input(
45
-                        array(
46
-                            'html_label_text' => sprintf(
47
-                                esc_html__('API Username %s', 'event_espresso'),
48
-                                $help_tab_link
49
-                            ),
50
-                            'required'        => true,
51
-                        )
52
-                    ),
53
-                    'api_password' => new EE_Text_Input(
54
-                        array(
55
-                            'html_label_text' => sprintf(
56
-                                esc_html__('API Password %s', 'event_espresso'),
57
-                                $help_tab_link
58
-                            ),
59
-                            'required'        => true,
60
-                        )
61
-                    ),
62
-                    'api_signature' => new EE_Text_Input(
63
-                        array(
64
-                            'html_label_text' => sprintf(
65
-                                esc_html__('API Signature %s', 'event_espresso'),
66
-                                $help_tab_link
67
-                            ),
68
-                            'required'        => true,
69
-                        )
70
-                    ),
71
-                    'request_shipping_addr' => new EE_Yes_No_Input(
72
-                        array(
73
-                            'html_label_text' => sprintf(
74
-                                esc_html__('Request Shipping Address %s', 'event_espresso'),
75
-                                $help_tab_link
76
-                            ),
77
-                            'html_help_text'  => esc_html__(
78
-                            // @codingStandardsIgnoreStart
79
-                                'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
80
-                                // @codingStandardsIgnoreEnd
81
-                                'event_espresso'
82
-                            ),
83
-                            'required'        => true,
84
-                            'default'         => false,
85
-                        )
86
-                    ),
87
-                    'image_url' => new EE_Admin_File_Uploader_Input(
88
-                        array(
89
-                            'html_label_text' => sprintf(
90
-                                esc_html__('Image URL %s', 'event_espresso'),
91
-                                $help_tab_link
92
-                            ),
93
-                            'html_help_text'  => esc_html__(
94
-                                'Used for your business/personal logo on the PayPal page',
95
-                                'event_espresso'
96
-                            ),
97
-                            'required'        => false,
98
-                        )
99
-                    ),
100
-                )
101
-            ),
102
-            $options_array
103
-        );
104
-        parent::__construct($options_array);
105
-    }
32
+	/**
33
+	 * SettingsForm constructor.
34
+	 *
35
+	 * @param array $options_array
36
+	 * @param string     $help_tab_link
37
+	 */
38
+	public function __construct(array $options_array = array(), $help_tab_link)
39
+	{
40
+		$this->helpTabLink = $help_tab_link;
41
+		$options_array = array_replace_recursive(
42
+			array(
43
+				'extra_meta_inputs' => array(
44
+					'api_username' => new EE_Text_Input(
45
+						array(
46
+							'html_label_text' => sprintf(
47
+								esc_html__('API Username %s', 'event_espresso'),
48
+								$help_tab_link
49
+							),
50
+							'required'        => true,
51
+						)
52
+					),
53
+					'api_password' => new EE_Text_Input(
54
+						array(
55
+							'html_label_text' => sprintf(
56
+								esc_html__('API Password %s', 'event_espresso'),
57
+								$help_tab_link
58
+							),
59
+							'required'        => true,
60
+						)
61
+					),
62
+					'api_signature' => new EE_Text_Input(
63
+						array(
64
+							'html_label_text' => sprintf(
65
+								esc_html__('API Signature %s', 'event_espresso'),
66
+								$help_tab_link
67
+							),
68
+							'required'        => true,
69
+						)
70
+					),
71
+					'request_shipping_addr' => new EE_Yes_No_Input(
72
+						array(
73
+							'html_label_text' => sprintf(
74
+								esc_html__('Request Shipping Address %s', 'event_espresso'),
75
+								$help_tab_link
76
+							),
77
+							'html_help_text'  => esc_html__(
78
+							// @codingStandardsIgnoreStart
79
+								'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
80
+								// @codingStandardsIgnoreEnd
81
+								'event_espresso'
82
+							),
83
+							'required'        => true,
84
+							'default'         => false,
85
+						)
86
+					),
87
+					'image_url' => new EE_Admin_File_Uploader_Input(
88
+						array(
89
+							'html_label_text' => sprintf(
90
+								esc_html__('Image URL %s', 'event_espresso'),
91
+								$help_tab_link
92
+							),
93
+							'html_help_text'  => esc_html__(
94
+								'Used for your business/personal logo on the PayPal page',
95
+								'event_espresso'
96
+							),
97
+							'required'        => false,
98
+						)
99
+					),
100
+				)
101
+			),
102
+			$options_array
103
+		);
104
+		parent::__construct($options_array);
105
+	}
106 106
 
107 107
 
108 108
 
109
-    /**
110
-     * Does the normal validation, but also verifies the PayPal API credentials work.
111
-     * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more tips)
112
-     * on each of the inputs that could be the cause of the problem.
113
-     * @throws EntityNotFoundException
114
-     */
115
-    public function _validate()
116
-    {
117
-        parent::_validate();
118
-        if (! $this->_payment_method_type instanceof \EE_PMT_Paypal_Express) {
119
-            throw new EntityNotFoundException('EE_PMT_Paypal_Express', '$this->_payment_method_type');
120
-        }
121
-        if (! $this->_payment_method_type->get_gateway() instanceof \EEG_Paypal_Express) {
122
-            throw new EntityNotFoundException('EEG_Paypal_Express', '$this->_payment_method_type->get_gateway()');
123
-        }
124
-        $credentials_message = $this->checkForCredentialsErrors();
125
-        if( $credentials_message !== '') {
126
-            $this->add_validation_error($credentials_message);
127
-            $this->get_input('PMD_debug_mode')->add_validation_error(
128
-                esc_html__('If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', 'event_espresso')
129
-            );
130
-            $this->get_input('api_username')->add_validation_error(
131
-                sprintf(
132
-                    esc_html__('Are you sure this is your API username, not your login username?%1$s', 'event_espresso'),
133
-                    $this->helpTabLink()
134
-                )
135
-            );
136
-            $this->get_input('api_password')->add_validation_error(
137
-                sprintf(
138
-                    esc_html__('Are you sure this is your API password, not your login password.%1$s', 'event_espresso'),
139
-                    $this->helpTabLink()
140
-                )
141
-            );
142
-            $this->get_input('api_signature')->add_validation_error(
143
-                sprintf(
144
-                    esc_html__('Please verify your API signature is correct.%1$s', 'event_espresso'),
145
-                    $this->helpTabLink()
146
-                )
147
-            );
148
-        }
149
-    }
109
+	/**
110
+	 * Does the normal validation, but also verifies the PayPal API credentials work.
111
+	 * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more tips)
112
+	 * on each of the inputs that could be the cause of the problem.
113
+	 * @throws EntityNotFoundException
114
+	 */
115
+	public function _validate()
116
+	{
117
+		parent::_validate();
118
+		if (! $this->_payment_method_type instanceof \EE_PMT_Paypal_Express) {
119
+			throw new EntityNotFoundException('EE_PMT_Paypal_Express', '$this->_payment_method_type');
120
+		}
121
+		if (! $this->_payment_method_type->get_gateway() instanceof \EEG_Paypal_Express) {
122
+			throw new EntityNotFoundException('EEG_Paypal_Express', '$this->_payment_method_type->get_gateway()');
123
+		}
124
+		$credentials_message = $this->checkForCredentialsErrors();
125
+		if( $credentials_message !== '') {
126
+			$this->add_validation_error($credentials_message);
127
+			$this->get_input('PMD_debug_mode')->add_validation_error(
128
+				esc_html__('If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', 'event_espresso')
129
+			);
130
+			$this->get_input('api_username')->add_validation_error(
131
+				sprintf(
132
+					esc_html__('Are you sure this is your API username, not your login username?%1$s', 'event_espresso'),
133
+					$this->helpTabLink()
134
+				)
135
+			);
136
+			$this->get_input('api_password')->add_validation_error(
137
+				sprintf(
138
+					esc_html__('Are you sure this is your API password, not your login password.%1$s', 'event_espresso'),
139
+					$this->helpTabLink()
140
+				)
141
+			);
142
+			$this->get_input('api_signature')->add_validation_error(
143
+				sprintf(
144
+					esc_html__('Please verify your API signature is correct.%1$s', 'event_espresso'),
145
+					$this->helpTabLink()
146
+				)
147
+			);
148
+		}
149
+	}
150 150
 
151 151
 
152 152
 
153
-    /**
154
-     * Gets the HTML to show the link to the help tab
155
-     * @return string
156
-     */
157
-    protected function helpTabLink(){
158
-        return $this->helpTabLink;
159
-    }
160
-    /**
161
-     * Tests the the PayPal API credentials work ok
162
-     * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string
163
-     */
164
-    protected function checkForCredentialsErrors()
165
-    {
166
-        $request_params = array(
167
-            'METHOD'    => 'GetBalance',
168
-            'VERSION'   => '204.0',
169
-            'USER'      => urlencode($this->get_input_value('api_username')),
170
-            'PWD'       => urlencode($this->get_input_value('api_password')),
171
-            'SIGNATURE' => urlencode($this->get_input_value('api_signature')),
172
-        );
173
-        $gateway_url = $this->get_input_value('PMD_debug_mode')
174
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
175
-            : 'https://api-3t.paypal.com/nvp';
176
-        // Request Customer Details.
177
-        $response = wp_remote_post(
178
-            $gateway_url,
179
-            array(
180
-                'method'      => 'POST',
181
-                'timeout'     => 45,
182
-                'httpversion' => '1.1',
183
-                'cookies'     => array(),
184
-                'headers'     => array(),
185
-                'body'        => http_build_query($request_params, '', '&'),
186
-            )
187
-        );
188
-        if (is_wp_error($response) || empty($response['body'])) {
189
-            // If we got here then there was an error in this request.
190
-            //maybe is turned off. We don't know the credentials are invalid
191
-            EE_Error::add_error(
192
-                sprintf(
193
-                    esc_html__('Your PayPal credentials could not be verified. There was an error communicating with PayPal, it was %1$s', 'event_espresso'),
194
-                    $response->get_error_message()
195
-                ),
196
-                __FILE__,
197
-                __FUNCTION__,
198
-                __LINE__
199
-            );
200
-        }
201
-        $response_args = array();
202
-        parse_str(urldecode($response['body']), $response_args);
153
+	/**
154
+	 * Gets the HTML to show the link to the help tab
155
+	 * @return string
156
+	 */
157
+	protected function helpTabLink(){
158
+		return $this->helpTabLink;
159
+	}
160
+	/**
161
+	 * Tests the the PayPal API credentials work ok
162
+	 * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string
163
+	 */
164
+	protected function checkForCredentialsErrors()
165
+	{
166
+		$request_params = array(
167
+			'METHOD'    => 'GetBalance',
168
+			'VERSION'   => '204.0',
169
+			'USER'      => urlencode($this->get_input_value('api_username')),
170
+			'PWD'       => urlencode($this->get_input_value('api_password')),
171
+			'SIGNATURE' => urlencode($this->get_input_value('api_signature')),
172
+		);
173
+		$gateway_url = $this->get_input_value('PMD_debug_mode')
174
+			? 'https://api-3t.sandbox.paypal.com/nvp'
175
+			: 'https://api-3t.paypal.com/nvp';
176
+		// Request Customer Details.
177
+		$response = wp_remote_post(
178
+			$gateway_url,
179
+			array(
180
+				'method'      => 'POST',
181
+				'timeout'     => 45,
182
+				'httpversion' => '1.1',
183
+				'cookies'     => array(),
184
+				'headers'     => array(),
185
+				'body'        => http_build_query($request_params, '', '&'),
186
+			)
187
+		);
188
+		if (is_wp_error($response) || empty($response['body'])) {
189
+			// If we got here then there was an error in this request.
190
+			//maybe is turned off. We don't know the credentials are invalid
191
+			EE_Error::add_error(
192
+				sprintf(
193
+					esc_html__('Your PayPal credentials could not be verified. There was an error communicating with PayPal, it was %1$s', 'event_espresso'),
194
+					$response->get_error_message()
195
+				),
196
+				__FILE__,
197
+				__FUNCTION__,
198
+				__LINE__
199
+			);
200
+		}
201
+		$response_args = array();
202
+		parse_str(urldecode($response['body']), $response_args);
203 203
 
204
-        if (empty($response_args['ACK'])) {
205
-            EE_Error::add_error(
206
-                esc_html__('Your PayPal credentials could not be verified. Part of their response was missing.', 'event_espresso'),
207
-                __FILE__,
208
-                __FUNCTION__,
209
-                __LINE__
210
-            );
211
-        }
212
-        if (
213
-        in_array(
214
-            $response_args['ACK'],
215
-            array(
216
-                'Success',
217
-                'SuccessWithWarning'
218
-            ),
219
-            true
220
-        )
221
-        ) {
222
-            return '';
223
-        } else {
224
-            return sprintf(
225
-                esc_html__('Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', 'event_espresso'),
226
-                    isset($response_args['L_LONGMESSAGE0']) ? $response_args['L_LONGMESSAGE0'] : esc_html__('No error message received from PayPal', 'event_espresso'),
227
-                isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0
228
-            );
229
-        }
230
-    }
204
+		if (empty($response_args['ACK'])) {
205
+			EE_Error::add_error(
206
+				esc_html__('Your PayPal credentials could not be verified. Part of their response was missing.', 'event_espresso'),
207
+				__FILE__,
208
+				__FUNCTION__,
209
+				__LINE__
210
+			);
211
+		}
212
+		if (
213
+		in_array(
214
+			$response_args['ACK'],
215
+			array(
216
+				'Success',
217
+				'SuccessWithWarning'
218
+			),
219
+			true
220
+		)
221
+		) {
222
+			return '';
223
+		} else {
224
+			return sprintf(
225
+				esc_html__('Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', 'event_espresso'),
226
+					isset($response_args['L_LONGMESSAGE0']) ? $response_args['L_LONGMESSAGE0'] : esc_html__('No error message received from PayPal', 'event_espresso'),
227
+				isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0
228
+			);
229
+		}
230
+	}
231 231
 }
232 232
 // End of file SettingsForm.php
233 233
 // Location: EventEspresso\payment_methods\Paypal_Express\forms/SettingsForm.php
234 234
\ No newline at end of file
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EE_PMT_Paypal_Express.pm.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\payment_methods\Paypal_Express\forms\SettingsForm;
4 4
 
5 5
 if (! defined('EVENT_ESPRESSO_VERSION')) {
6
-    exit('NO direct script access allowed');
6
+	exit('NO direct script access allowed');
7 7
 }
8 8
 
9 9
 
@@ -21,91 +21,91 @@  discard block
 block discarded – undo
21 21
 class EE_PMT_Paypal_Express extends EE_PMT_Base
22 22
 {
23 23
 
24
-    /**
25
-     * EE_PMT_Paypal_Express constructor.
26
-     */
27
-    public function __construct($pm_instance = null)
28
-    {
29
-        require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php');
30
-        $this->_gateway = new EEG_Paypal_Express();
24
+	/**
25
+	 * EE_PMT_Paypal_Express constructor.
26
+	 */
27
+	public function __construct($pm_instance = null)
28
+	{
29
+		require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php');
30
+		$this->_gateway = new EEG_Paypal_Express();
31 31
 
32
-        $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso');
33
-        $this->_template_path = $this->file_folder() . 'templates' . DS;
34
-        $this->_default_description = esc_html__(
35
-            // @codingStandardsIgnoreStart
36
-            'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.',
37
-            // @codingStandardsIgnoreEnd
38
-            'event_espresso'
39
-        );
40
-        $this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo-gold-160.png';
32
+		$this->_pretty_name = esc_html__('PayPal Express', 'event_espresso');
33
+		$this->_template_path = $this->file_folder() . 'templates' . DS;
34
+		$this->_default_description = esc_html__(
35
+			// @codingStandardsIgnoreStart
36
+			'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.',
37
+			// @codingStandardsIgnoreEnd
38
+			'event_espresso'
39
+		);
40
+		$this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo-gold-160.png';
41 41
 
42
-        parent::__construct($pm_instance);
43
-    }
42
+		parent::__construct($pm_instance);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * Adds the help tab.
48
-     *
49
-     * @see EE_PMT_Base::help_tabs_config()
50
-     * @return array
51
-     */
52
-    public function help_tabs_config()
53
-    {
54
-        return array(
55
-            $this->get_help_tab_name() => array(
56
-                'title'    => esc_html__('PayPal Express Settings', 'event_espresso'),
57
-                'filename' => 'payment_methods_overview_paypal_express'
58
-            )
59
-        );
60
-    }
46
+	/**
47
+	 * Adds the help tab.
48
+	 *
49
+	 * @see EE_PMT_Base::help_tabs_config()
50
+	 * @return array
51
+	 */
52
+	public function help_tabs_config()
53
+	{
54
+		return array(
55
+			$this->get_help_tab_name() => array(
56
+				'title'    => esc_html__('PayPal Express Settings', 'event_espresso'),
57
+				'filename' => 'payment_methods_overview_paypal_express'
58
+			)
59
+		);
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * Gets the form for all the settings related to this payment method type.
65
-     *
66
-     * @return EE_Payment_Method_Form
67
-     */
68
-    public function generate_new_settings_form()
69
-    {
70
-        $form = new SettingsForm(array(), $this->get_help_tab_link());
71
-        return $form;
72
-    }
63
+	/**
64
+	 * Gets the form for all the settings related to this payment method type.
65
+	 *
66
+	 * @return EE_Payment_Method_Form
67
+	 */
68
+	public function generate_new_settings_form()
69
+	{
70
+		$form = new SettingsForm(array(), $this->get_help_tab_link());
71
+		return $form;
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * Creates a billing form for this payment method type.
77
-     *
78
-     * @param \EE_Transaction $transaction
79
-     * @return \EE_Billing_Info_Form
80
-     */
81
-    public function generate_new_billing_form(EE_Transaction $transaction = null)
82
-    {
83
-        if ($this->_pm_instance->debug_mode()) {
84
-            $form = new EE_Billing_Info_Form(
85
-                $this->_pm_instance,
86
-                array(
87
-                    'name' => 'paypal_express_Info_Form',
88
-                    'subsections' => array(
89
-                        'paypal_express_debug_info' => new EE_Form_Section_Proper(
90
-                            array(
91
-                                'layout_strategy' => new EE_Template_Layout(
92
-                                    array(
93
-                                        'layout_template_file' => $this->_template_path
94
-                                                                    . 'paypal_express_debug_info.template.php',
95
-                                        'template_args'        => array(
96
-                                            'debug_mode' => $this->_pm_instance->debug_mode()
97
-                                        )
98
-                                    )
99
-                                )
100
-                            )
101
-                        )
102
-                    )
103
-                )
104
-            );
105
-            return $form;
106
-        }
75
+	/**
76
+	 * Creates a billing form for this payment method type.
77
+	 *
78
+	 * @param \EE_Transaction $transaction
79
+	 * @return \EE_Billing_Info_Form
80
+	 */
81
+	public function generate_new_billing_form(EE_Transaction $transaction = null)
82
+	{
83
+		if ($this->_pm_instance->debug_mode()) {
84
+			$form = new EE_Billing_Info_Form(
85
+				$this->_pm_instance,
86
+				array(
87
+					'name' => 'paypal_express_Info_Form',
88
+					'subsections' => array(
89
+						'paypal_express_debug_info' => new EE_Form_Section_Proper(
90
+							array(
91
+								'layout_strategy' => new EE_Template_Layout(
92
+									array(
93
+										'layout_template_file' => $this->_template_path
94
+																	. 'paypal_express_debug_info.template.php',
95
+										'template_args'        => array(
96
+											'debug_mode' => $this->_pm_instance->debug_mode()
97
+										)
98
+									)
99
+								)
100
+							)
101
+						)
102
+					)
103
+				)
104
+			);
105
+			return $form;
106
+		}
107 107
 
108
-        return false;
109
-    }
108
+		return false;
109
+	}
110 110
 }
111 111
 // End of file EE_PMT_Paypal_Express.pm.php
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 use EventEspresso\payment_methods\Paypal_Express\forms\SettingsForm;
4 4
 
5
-if (! defined('EVENT_ESPRESSO_VERSION')) {
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6 6
     exit('NO direct script access allowed');
7 7
 }
8 8
 
@@ -26,18 +26,18 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function __construct($pm_instance = null)
28 28
     {
29
-        require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php');
29
+        require_once($this->file_folder().'EEG_Paypal_Express.gateway.php');
30 30
         $this->_gateway = new EEG_Paypal_Express();
31 31
 
32 32
         $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso');
33
-        $this->_template_path = $this->file_folder() . 'templates' . DS;
33
+        $this->_template_path = $this->file_folder().'templates'.DS;
34 34
         $this->_default_description = esc_html__(
35 35
             // @codingStandardsIgnoreStart
36 36
             'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.',
37 37
             // @codingStandardsIgnoreEnd
38 38
             'event_espresso'
39 39
         );
40
-        $this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo-gold-160.png';
40
+        $this->_default_button_url = $this->file_url().'lib'.DS.'paypal-express-checkout-logo-gold-160.png';
41 41
 
42 42
         parent::__construct($pm_instance);
43 43
     }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_PMT_Base.lib.php 1 patch
Indentation   +722 added lines, -722 removed lines patch added patch discarded remove patch
@@ -21,728 +21,728 @@
 block discarded – undo
21 21
 abstract class EE_PMT_Base
22 22
 {
23 23
 
24
-    const onsite = 'on-site';
25
-    const offsite = 'off-site';
26
-    const offline = 'off-line';
27
-
28
-    /**
29
-     * @var EE_Payment_Method
30
-     */
31
-    protected $_pm_instance = NULL;
32
-
33
-    /**
34
-     * @var boolean
35
-     */
36
-    protected $_requires_https = FALSE;
37
-
38
-    /**
39
-     * @var boolean
40
-     */
41
-    protected $_has_billing_form;
42
-
43
-    /**
44
-     * @var EE_Gateway
45
-     */
46
-    protected $_gateway = NULL;
47
-
48
-    /**
49
-     * @var EE_Payment_Method_Form
50
-     */
51
-    protected $_settings_form = NULL;
52
-
53
-    /**
54
-     * @var EE_Form_Section_Proper
55
-     */
56
-    protected $_billing_form = NULL;
57
-
58
-    /**
59
-     * @var boolean
60
-     */
61
-    protected $_cache_billing_form = TRUE;
62
-
63
-    /**
64
-     * String of the absolute path to the folder containing this file, with a trailing slash.
65
-     * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
66
-     * @var string
67
-     */
68
-    protected $_file_folder = NULL;
69
-
70
-    /**
71
-     * String to the absolute URL to this file (useful for getting its web-accessible resources
72
-     * like images, js, or css)
73
-     * @var string
74
-     */
75
-    protected $_file_url = NULL;
76
-
77
-    /**
78
-     * Pretty name for the payment method
79
-     * @var string
80
-     */
81
-    protected $_pretty_name = NULL;
82
-
83
-    /**
84
-     *
85
-     * @var string
86
-     */
87
-    protected $_default_button_url = NULL;
88
-
89
-    /**
90
-     *
91
-     * @var string
92
-     */
93
-    protected $_default_description = NULL;
94
-
95
-
96
-    /**
97
-     *
98
-     * @param EE_Payment_Method $pm_instance
99
-     * @throws EE_Error
100
-     * @return EE_PMT_Base
101
-     */
102
-    function __construct($pm_instance = NULL)
103
-    {
104
-        if ($pm_instance instanceof EE_Payment_Method) {
105
-            $this->set_instance($pm_instance);
106
-        }
107
-        if ($this->_gateway) {
108
-            $this->_gateway->set_payment_model(EEM_Payment::instance());
109
-            $this->_gateway->set_payment_log(EEM_Change_Log::instance());
110
-            $this->_gateway->set_template_helper(new EEH_Template());
111
-            $this->_gateway->set_line_item_helper(new EEH_Line_Item());
112
-            $this->_gateway->set_money_helper(new EEH_Money());
113
-            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
114
-            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115
-            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116
-        }
117
-        if (!isset($this->_has_billing_form)) {
118
-            // by default, On Site gateways have a billing form
119
-            if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120
-                $this->set_has_billing_form(true);
121
-            } else {
122
-                $this->set_has_billing_form(false);
123
-            }
124
-        }
125
-
126
-        if (!$this->_pretty_name) {
127
-            throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128
-        }
129
-        //if the child didn't specify a default button, use the credit card one
130
-        if ($this->_default_button_url === NULL) {
131
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
132
-        }
133
-    }
134
-
135
-
136
-    /**
137
-     * @param boolean $has_billing_form
138
-     */
139
-    public function set_has_billing_form($has_billing_form)
140
-    {
141
-        $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
142
-    }
143
-
144
-
145
-    /**
146
-     * sets the file_folder property
147
-     */
148
-    protected function _set_file_folder()
149
-    {
150
-        $reflector = new ReflectionClass(get_class($this));
151
-        $fn = $reflector->getFileName();
152
-        $this->_file_folder = dirname($fn) . DS;
153
-    }
154
-
155
-
156
-    /**
157
-     * sets the file URL with a trailing slash for this PMT
158
-     */
159
-    protected function _set_file_url()
160
-    {
161
-        $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
162
-        $file_folder_fixed = str_replace('\\', DS, $this->file_folder());
163
-        $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
164
-        $this->_file_url = $file_path;
165
-    }
166
-
167
-    /**
168
-     * Gets the default description on all payment methods of this type
169
-     * @return string
170
-     */
171
-    public function default_description()
172
-    {
173
-        return $this->_default_description;
174
-    }
175
-
176
-
177
-    /**
178
-     * Returns the folder containing the PMT child class, with a trailing slash
179
-     * @return string
180
-     */
181
-    public function file_folder()
182
-    {
183
-        if (!$this->_file_folder) {
184
-            $this->_set_file_folder();
185
-        }
186
-        return $this->_file_folder;
187
-    }
188
-
189
-
190
-    /**
191
-     * @return string
192
-     */
193
-    public function file_url()
194
-    {
195
-        if (!$this->_file_url) {
196
-            $this->_set_file_url();
197
-        }
198
-        return $this->_file_url;
199
-    }
200
-
201
-
202
-    /**
203
-     * Sets the payment method instance this payment method type is for.
204
-     * Its important teh payment method instance is set before
205
-     * @param EE_Payment_Method $payment_method_instance
206
-     */
207
-    function set_instance($payment_method_instance)
208
-    {
209
-        $this->_pm_instance = $payment_method_instance;
210
-        //if they have already requested the settings form, make sure its
211
-        //data matches this model object
212
-        if ($this->_settings_form) {
213
-            $this->settings_form()->populate_model_obj($payment_method_instance);
214
-        }
215
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
216
-            $this->_gateway->set_settings($payment_method_instance->settings_array());
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * Gets teh form for displaying to admins where they setup the payment method
223
-     * @return EE_Payment_Method_Form
224
-     */
225
-    function settings_form()
226
-    {
227
-        if (!$this->_settings_form) {
228
-            $this->_settings_form = $this->generate_new_settings_form();
229
-            $this->_settings_form->set_payment_method_type($this);
230
-            //if we have already assigned a model object to this pmt, make
231
-            //sure its reflected in teh form we just generated
232
-            if ($this->_pm_instance) {
233
-                $this->_settings_form->populate_model_obj($this->_pm_instance);
234
-            }
235
-        }
236
-        return $this->_settings_form;
237
-    }
238
-
239
-
240
-    /**
241
-     * Gets the form for all the settings related to this payment method type
242
-     * @return EE_Payment_Method_Form
243
-     */
244
-    abstract function generate_new_settings_form();
245
-
246
-
247
-    /**
248
-     * Sets the form for settings. This may be useful if we have already received
249
-     * a form submission and have form data it in, and want to use it anytime we're showing
250
-     * this payment method type's settings form later in the request
251
-     * @param EE_Payment_Method_Form $form
252
-     */
253
-    public function set_settings_form($form)
254
-    {
255
-        $this->_settings_form = $form;
256
-    }
257
-
258
-
259
-    /**
260
-     * @return boolean
261
-     */
262
-    public function has_billing_form()
263
-    {
264
-        return $this->_has_billing_form;
265
-    }
266
-
267
-
268
-    /**
269
-     * Gets the form for displaying to attendees where they can enter their billing info
270
-     * which will be sent to teh gateway (can be null)
271
-     *
272
-     * @param \EE_Transaction $transaction
273
-     * @param array $extra_args
274
-     * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275
-     */
276
-    public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277
-    {
278
-        // has billing form already been regenerated ? or overwrite cache?
279
-        if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
280
-            $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281
-        }
282
-        //if we know who the attendee is, and this is a billing form
283
-        //that uses attendee info, populate it
284
-        if (
285
-        apply_filters(
286
-            'FHEE__populate_billing_form_fields_from_attendee',
287
-            (
288
-                $this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
-                && $transaction instanceof EE_Transaction
290
-                && $transaction->primary_registration() instanceof EE_Registration
291
-                && $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
-            ),
293
-            $this->_billing_form,
294
-            $transaction
295
-        )
296
-        ) {
297
-            $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
298
-        }
299
-        return $this->_billing_form;
300
-    }
301
-
302
-
303
-    /**
304
-     * Creates the billing form for this payment method type
305
-     * @param \EE_Transaction $transaction
306
-     * @return \EE_Billing_Info_Form
307
-     */
308
-    abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
309
-
310
-
311
-    /**
312
-     * apply_billing_form_debug_settings
313
-     * applies debug data to the form
314
-     *
315
-     * @param \EE_Billing_Info_Form $billing_form
316
-     * @return \EE_Billing_Info_Form
317
-     */
318
-    public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
319
-    {
320
-        return $billing_form;
321
-    }
322
-
323
-
324
-    /**
325
-     * Sets the billing form for this payment method type. You may want to use this
326
-     * if you have form
327
-     * @param EE_Payment_Method $form
328
-     */
329
-    public function set_billing_form($form)
330
-    {
331
-        $this->_billing_form = $form;
332
-    }
333
-
334
-
335
-    /**
336
-     * Returns whether or not this payment method requires HTTPS to be used
337
-     * @return boolean
338
-     */
339
-    function requires_https()
340
-    {
341
-        return $this->_requires_https;
342
-    }
343
-
344
-
345
-    /**
346
-     *
347
-     * @param EE_Transaction $transaction
348
-     * @param float $amount
349
-     * @param EE_Billing_Info_Form $billing_info
350
-     * @param string $return_url
351
-     * @param string $fail_url
352
-     * @param string $method
353
-     * @param bool $by_admin
354
-     * @return EE_Payment
355
-     * @throws EE_Error
356
-     */
357
-    function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false)
358
-    {
359
-        // @todo: add surcharge for the payment method, if any
360
-        if ($this->_gateway) {
361
-            //there is a gateway, so we're going to make a payment object
362
-            //but wait! do they already have a payment in progress that we thought was failed?
363
-            $duplicate_properties = array(
364
-                'STS_ID' => EEM_Payment::status_id_failed,
365
-                'TXN_ID' => $transaction->ID(),
366
-                'PMD_ID' => $this->_pm_instance->ID(),
367
-                'PAY_source' => $method,
368
-                'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(),
369
-                'PAY_gateway_response' => null,
370
-            );
371
-            $payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372
-            //if we didn't already have a payment in progress for the same thing,
373
-            //then we actually want to make a new payment
374
-            if (!$payment instanceof EE_Payment) {
375
-                $payment = EE_Payment::new_instance(
376
-                    array_merge(
377
-                        $duplicate_properties,
378
-                        array(
379
-                            'PAY_timestamp' => time(),
380
-                            'PAY_txn_id_chq_nmbr' => null,
381
-                            'PAY_po_number' => null,
382
-                            'PAY_extra_accntng' => null,
383
-                            'PAY_details' => null,
384
-                        )
385
-                    )
386
-                );
387
-            }
388
-            //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
389
-            $payment->save();
390
-            $billing_values = $this->_get_billing_values_from_form($billing_info);
391
-
392
-            //  Offsite Gateway
393
-            if ($this->_gateway instanceof EE_Offsite_Gateway) {
394
-
395
-                $payment = $this->_gateway->set_redirection_info(
396
-                    $payment,
397
-                    $billing_values,
398
-                    $return_url,
399
-                    EE_Config::instance()->core->txn_page_url(
400
-                        array(
401
-                            'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(),
402
-                            'ee_payment_method' => $this->_pm_instance->slug()
403
-                        )
404
-                    ),
405
-                    $fail_url
406
-                );
407
-                $payment->save();
408
-                //  Onsite Gateway
409
-            } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
410
-
411
-                $payment = $this->_gateway->do_direct_payment($payment, $billing_values);
412
-                $payment->save();
413
-
414
-            } else {
415
-                throw new EE_Error(
416
-                    sprintf(
417
-                        __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'),
418
-                        get_class($this),
419
-                        gettype($this->_gateway)
420
-                    )
421
-                );
422
-            }
423
-
424
-        } else {
425
-            // no gateway provided
426
-            // there is no payment. Must be an offline gateway
427
-            // create a payment object anyways, but dont save it
428
-            $payment = EE_Payment::new_instance(
429
-                array(
430
-                    'STS_ID' => EEM_Payment::status_id_pending,
431
-                    'TXN_ID' => $transaction->ID(),
432
-                    'PMD_ID' => $transaction->payment_method_ID(),
433
-                    'PAY_amount' => 0.00,
434
-                    'PAY_timestamp' => time(),
435
-                )
436
-            );
437
-
438
-        }
439
-
440
-        // if there is billing info, clean it and save it now
441
-        if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
442
-            $this->_save_billing_info_to_attendee($billing_info, $transaction);
443
-        }
444
-
445
-        return $payment;
446
-    }
447
-
448
-    /**
449
-     * Gets the values we want to pass onto the gateway. Normally these
450
-     * are just the 'pretty' values, but there may be times the data may need
451
-     * a  little massaging. Proper subsections will become arrays of inputs
452
-     * @param EE_Billing_Info_Form $billing_form
453
-     * @return array
454
-     */
455
-    protected function _get_billing_values_from_form($billing_form)
456
-    {
457
-        if ($billing_form instanceof EE_Form_Section_Proper) {
458
-            return $billing_form->input_pretty_values(true);
459
-        } else {
460
-            return NULL;
461
-        }
462
-    }
463
-
464
-
465
-    /**
466
-     * Handles an instant payment notification when the transaction is known (by default).
467
-     * @param array $req_data
468
-     * @param EE_Transaction $transaction
469
-     * @return EE_Payment
470
-     * @throws EE_Error
471
-     */
472
-    public function handle_ipn($req_data, $transaction)
473
-    {
474
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
-        if (!$this->_gateway instanceof EE_Offsite_Gateway) {
476
-            throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477
-
478
-        }
479
-        $payment = $this->_gateway->handle_payment_update($req_data, $transaction);
480
-        return $payment;
481
-    }
482
-
483
-
484
-    /**
485
-     * Saves the billing info onto the attendee of the primary registrant on this transaction, and
486
-     * cleans it first.
487
-     * @param EE_Billing_Attendee_Info_Form $billing_form
488
-     * @param EE_Transaction $transaction
489
-     * @return boolean success
490
-     */
491
-    protected function _save_billing_info_to_attendee($billing_form, $transaction)
492
-    {
493
-        if (!$transaction || !$transaction instanceof EE_Transaction) {
494
-            EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495
-            return false;
496
-        }
497
-        $primary_reg = $transaction->primary_registration();
498
-        if (!$primary_reg) {
499
-            EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500
-            return false;
501
-        }
502
-        $attendee = $primary_reg->attendee();
503
-        if (!$attendee) {
504
-            EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505
-            return false;
506
-        }
507
-        return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
508
-
509
-    }
510
-
511
-
512
-    /**
513
-     * Gets the payment this IPN is for. Children may often want to
514
-     * override this to inspect the request
515
-     * @param EE_Transaction $transaction
516
-     * @param array $req_data
517
-     * @return EE_Payment
518
-     */
519
-    protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
520
-    {
521
-        return $transaction->last_payment();
522
-    }
523
-
524
-
525
-    /**
526
-     * In case generic code cannot provide the payment processor with a specific payment method
527
-     * and transaction, it will try calling this method on each activate payment method.
528
-     * If the payment method is able to identify the request as being for it, it should fetch
529
-     * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
530
-     * handle the IPN
531
-     * @param array $req_data
532
-     * @return EE_Payment only if this payment method can find the info its needs from $req_data
533
-     * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
534
-     * @throws EE_Error
535
-     */
536
-    public function handle_unclaimed_ipn($req_data = array())
537
-    {
538
-        throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
539
-    }
540
-
541
-
542
-    /**
543
-     * Logic to be accomplished when the payment attempt is complete.
544
-     * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
545
-     * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
546
-     * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
547
-     * of the payment). Fed a transaction because it's always assumed to be the last payment that
548
-     * we're dealing with. Returns that last payment (if there is one)
549
-     *
550
-     * @param EE_Transaction $transaction
551
-     * @return EE_Payment
552
-     */
553
-    public function finalize_payment_for($transaction)
554
-    {
555
-        return $transaction->last_payment();
556
-    }
557
-
558
-
559
-    /**
560
-     * Whether or not this payment method's gateway supports sending refund requests
561
-     * @return boolean
562
-     */
563
-    public function supports_sending_refunds()
564
-    {
565
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
566
-            return $this->_gateway->supports_sending_refunds();
567
-        } else {
568
-            return false;
569
-        }
570
-    }
571
-
572
-
573
-    /**
574
-     *
575
-     * @param EE_Payment $payment
576
-     * @param array $refund_info
577
-     * @throws EE_Error
578
-     * @return EE_Payment
579
-     */
580
-    public function process_refund(EE_Payment $payment, $refund_info = array())
581
-    {
582
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
583
-            return $this->_gateway->do_direct_refund($payment, $refund_info);
584
-        } else {
585
-            throw new EE_Error(
586
-                sprintf(
587
-                    __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
588
-                    get_class($this)
589
-                )
590
-            );
591
-        }
592
-    }
593
-
594
-
595
-    /**
596
-     * Returns one the class's constants onsite,offsite, or offline, depending on this
597
-     * payment method's gateway.
598
-     * @return string
599
-     * @throws EE_Error
600
-     */
601
-    public function payment_occurs()
602
-    {
603
-        if (!$this->_gateway) {
604
-            return EE_PMT_Base::offline;
605
-        } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606
-            return EE_PMT_Base::onsite;
607
-        } elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
608
-            return EE_PMT_Base::offsite;
609
-        } else {
610
-            throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
611
-        }
612
-    }
613
-
614
-
615
-    /**
616
-     * For adding any html output ab ove the payment overview.
617
-     * Many gateways won't want ot display anything, so this function just returns an empty string.
618
-     * Other gateways may want to override this, such as offline gateways.
619
-     * @param EE_Payment $payment
620
-     * @return string
621
-     */
622
-    public function payment_overview_content(EE_Payment $payment)
623
-    {
624
-        return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625
-    }
626
-
627
-
628
-    /**
629
-     * @return array where keys are the help tab name,
630
-     * values are: array {
631
-     * @type string $title i18n name for the help tab
632
-     * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file)
633
-     * @type array $template_args any arguments you want passed to the template file while rendering.
634
-     *                Keys will be variable names and values with be their values.
635
-     */
636
-    public function help_tabs_config()
637
-    {
638
-        return array();
639
-    }
640
-
641
-
642
-    /**
643
-     * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
644
-     * the payment method's table's PMT_type column)
645
-     * @return string
646
-     */
647
-    public function system_name()
648
-    {
649
-        $classname = get_class($this);
650
-        return str_replace("EE_PMT_", '', $classname);
651
-    }
652
-
653
-
654
-    /**
655
-     * A pretty i18n version of the PMT name
656
-     * @return string
657
-     */
658
-    public function pretty_name()
659
-    {
660
-        return $this->_pretty_name;
661
-    }
662
-
663
-
664
-    /**
665
-     * Gets the default absolute URL to the payment method type's button
666
-     * @return string
667
-     */
668
-    public function default_button_url()
669
-    {
670
-        return $this->_default_button_url;
671
-    }
672
-
673
-
674
-    /**
675
-     * Gets the gateway used by this payment method (if any)
676
-     * @return EE_Gateway
677
-     */
678
-    public function get_gateway()
679
-    {
680
-        return $this->_gateway;
681
-    }
682
-
683
-
684
-    /**
685
-     * @return string html for the link to a help tab
686
-     */
687
-    public function get_help_tab_link()
688
-    {
689
-        return EEH_Template::get_help_tab_link(
690
-            $this->get_help_tab_name(),
691
-            'espresso_payment_settings',
692
-            'default'
693
-        );
694
-    }
695
-
696
-
697
-    /**
698
-     * Returns the name of the help tab for this PMT
699
-     * @return string
700
-     */
701
-    public function get_help_tab_name()
702
-    {
703
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
704
-    }
705
-
706
-    /**
707
-     * The name of the wp capability that should be associated with the usage of
708
-     * this PMT by an admin
709
-     * @return string
710
-     */
711
-    public function cap_name()
712
-    {
713
-        return 'ee_payment_method_' . strtolower($this->system_name());
714
-    }
715
-
716
-    /**
717
-     * Called by client code to tell the gateway that if it wants to change
718
-     * the transaction or line items or registrations related to teh payment it already
719
-     * processed (we think, but possibly not) that now's the time to do it.
720
-     * It is expected that gateways will store any info they need for this on the PAY_details,
721
-     * or maybe an extra meta value
722
-     * @param EE_Payment $payment
723
-     * @return void
724
-     */
725
-    public function update_txn_based_on_payment($payment)
726
-    {
727
-        if ($this->_gateway instanceof EE_Gateway) {
728
-            $this->_gateway->update_txn_based_on_payment($payment);
729
-        }
730
-    }
731
-
732
-    /**
733
-     * Returns a string of HTML describing this payment method type for an admin,
734
-     * primarily intended for them to read before activating it.
735
-     * The easiest way to set this is to create a folder 'templates' alongside
736
-     * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
737
-     * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
738
-     * then you'd create a file named "templates" in the same folder as it, and name the file
739
-     * "foo_bar_intro.template.php", and its content will be returned by this method
740
-     * @return string
741
-     */
742
-    public function introductory_html()
743
-    {
744
-        return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
745
-    }
24
+	const onsite = 'on-site';
25
+	const offsite = 'off-site';
26
+	const offline = 'off-line';
27
+
28
+	/**
29
+	 * @var EE_Payment_Method
30
+	 */
31
+	protected $_pm_instance = NULL;
32
+
33
+	/**
34
+	 * @var boolean
35
+	 */
36
+	protected $_requires_https = FALSE;
37
+
38
+	/**
39
+	 * @var boolean
40
+	 */
41
+	protected $_has_billing_form;
42
+
43
+	/**
44
+	 * @var EE_Gateway
45
+	 */
46
+	protected $_gateway = NULL;
47
+
48
+	/**
49
+	 * @var EE_Payment_Method_Form
50
+	 */
51
+	protected $_settings_form = NULL;
52
+
53
+	/**
54
+	 * @var EE_Form_Section_Proper
55
+	 */
56
+	protected $_billing_form = NULL;
57
+
58
+	/**
59
+	 * @var boolean
60
+	 */
61
+	protected $_cache_billing_form = TRUE;
62
+
63
+	/**
64
+	 * String of the absolute path to the folder containing this file, with a trailing slash.
65
+	 * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
66
+	 * @var string
67
+	 */
68
+	protected $_file_folder = NULL;
69
+
70
+	/**
71
+	 * String to the absolute URL to this file (useful for getting its web-accessible resources
72
+	 * like images, js, or css)
73
+	 * @var string
74
+	 */
75
+	protected $_file_url = NULL;
76
+
77
+	/**
78
+	 * Pretty name for the payment method
79
+	 * @var string
80
+	 */
81
+	protected $_pretty_name = NULL;
82
+
83
+	/**
84
+	 *
85
+	 * @var string
86
+	 */
87
+	protected $_default_button_url = NULL;
88
+
89
+	/**
90
+	 *
91
+	 * @var string
92
+	 */
93
+	protected $_default_description = NULL;
94
+
95
+
96
+	/**
97
+	 *
98
+	 * @param EE_Payment_Method $pm_instance
99
+	 * @throws EE_Error
100
+	 * @return EE_PMT_Base
101
+	 */
102
+	function __construct($pm_instance = NULL)
103
+	{
104
+		if ($pm_instance instanceof EE_Payment_Method) {
105
+			$this->set_instance($pm_instance);
106
+		}
107
+		if ($this->_gateway) {
108
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
109
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
110
+			$this->_gateway->set_template_helper(new EEH_Template());
111
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
112
+			$this->_gateway->set_money_helper(new EEH_Money());
113
+			$this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
114
+			$this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115
+			do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116
+		}
117
+		if (!isset($this->_has_billing_form)) {
118
+			// by default, On Site gateways have a billing form
119
+			if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120
+				$this->set_has_billing_form(true);
121
+			} else {
122
+				$this->set_has_billing_form(false);
123
+			}
124
+		}
125
+
126
+		if (!$this->_pretty_name) {
127
+			throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128
+		}
129
+		//if the child didn't specify a default button, use the credit card one
130
+		if ($this->_default_button_url === NULL) {
131
+			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
132
+		}
133
+	}
134
+
135
+
136
+	/**
137
+	 * @param boolean $has_billing_form
138
+	 */
139
+	public function set_has_billing_form($has_billing_form)
140
+	{
141
+		$this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
142
+	}
143
+
144
+
145
+	/**
146
+	 * sets the file_folder property
147
+	 */
148
+	protected function _set_file_folder()
149
+	{
150
+		$reflector = new ReflectionClass(get_class($this));
151
+		$fn = $reflector->getFileName();
152
+		$this->_file_folder = dirname($fn) . DS;
153
+	}
154
+
155
+
156
+	/**
157
+	 * sets the file URL with a trailing slash for this PMT
158
+	 */
159
+	protected function _set_file_url()
160
+	{
161
+		$plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
162
+		$file_folder_fixed = str_replace('\\', DS, $this->file_folder());
163
+		$file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
164
+		$this->_file_url = $file_path;
165
+	}
166
+
167
+	/**
168
+	 * Gets the default description on all payment methods of this type
169
+	 * @return string
170
+	 */
171
+	public function default_description()
172
+	{
173
+		return $this->_default_description;
174
+	}
175
+
176
+
177
+	/**
178
+	 * Returns the folder containing the PMT child class, with a trailing slash
179
+	 * @return string
180
+	 */
181
+	public function file_folder()
182
+	{
183
+		if (!$this->_file_folder) {
184
+			$this->_set_file_folder();
185
+		}
186
+		return $this->_file_folder;
187
+	}
188
+
189
+
190
+	/**
191
+	 * @return string
192
+	 */
193
+	public function file_url()
194
+	{
195
+		if (!$this->_file_url) {
196
+			$this->_set_file_url();
197
+		}
198
+		return $this->_file_url;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Sets the payment method instance this payment method type is for.
204
+	 * Its important teh payment method instance is set before
205
+	 * @param EE_Payment_Method $payment_method_instance
206
+	 */
207
+	function set_instance($payment_method_instance)
208
+	{
209
+		$this->_pm_instance = $payment_method_instance;
210
+		//if they have already requested the settings form, make sure its
211
+		//data matches this model object
212
+		if ($this->_settings_form) {
213
+			$this->settings_form()->populate_model_obj($payment_method_instance);
214
+		}
215
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
216
+			$this->_gateway->set_settings($payment_method_instance->settings_array());
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * Gets teh form for displaying to admins where they setup the payment method
223
+	 * @return EE_Payment_Method_Form
224
+	 */
225
+	function settings_form()
226
+	{
227
+		if (!$this->_settings_form) {
228
+			$this->_settings_form = $this->generate_new_settings_form();
229
+			$this->_settings_form->set_payment_method_type($this);
230
+			//if we have already assigned a model object to this pmt, make
231
+			//sure its reflected in teh form we just generated
232
+			if ($this->_pm_instance) {
233
+				$this->_settings_form->populate_model_obj($this->_pm_instance);
234
+			}
235
+		}
236
+		return $this->_settings_form;
237
+	}
238
+
239
+
240
+	/**
241
+	 * Gets the form for all the settings related to this payment method type
242
+	 * @return EE_Payment_Method_Form
243
+	 */
244
+	abstract function generate_new_settings_form();
245
+
246
+
247
+	/**
248
+	 * Sets the form for settings. This may be useful if we have already received
249
+	 * a form submission and have form data it in, and want to use it anytime we're showing
250
+	 * this payment method type's settings form later in the request
251
+	 * @param EE_Payment_Method_Form $form
252
+	 */
253
+	public function set_settings_form($form)
254
+	{
255
+		$this->_settings_form = $form;
256
+	}
257
+
258
+
259
+	/**
260
+	 * @return boolean
261
+	 */
262
+	public function has_billing_form()
263
+	{
264
+		return $this->_has_billing_form;
265
+	}
266
+
267
+
268
+	/**
269
+	 * Gets the form for displaying to attendees where they can enter their billing info
270
+	 * which will be sent to teh gateway (can be null)
271
+	 *
272
+	 * @param \EE_Transaction $transaction
273
+	 * @param array $extra_args
274
+	 * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275
+	 */
276
+	public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277
+	{
278
+		// has billing form already been regenerated ? or overwrite cache?
279
+		if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
280
+			$this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281
+		}
282
+		//if we know who the attendee is, and this is a billing form
283
+		//that uses attendee info, populate it
284
+		if (
285
+		apply_filters(
286
+			'FHEE__populate_billing_form_fields_from_attendee',
287
+			(
288
+				$this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
+				&& $transaction instanceof EE_Transaction
290
+				&& $transaction->primary_registration() instanceof EE_Registration
291
+				&& $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
+			),
293
+			$this->_billing_form,
294
+			$transaction
295
+		)
296
+		) {
297
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
298
+		}
299
+		return $this->_billing_form;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Creates the billing form for this payment method type
305
+	 * @param \EE_Transaction $transaction
306
+	 * @return \EE_Billing_Info_Form
307
+	 */
308
+	abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
309
+
310
+
311
+	/**
312
+	 * apply_billing_form_debug_settings
313
+	 * applies debug data to the form
314
+	 *
315
+	 * @param \EE_Billing_Info_Form $billing_form
316
+	 * @return \EE_Billing_Info_Form
317
+	 */
318
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
319
+	{
320
+		return $billing_form;
321
+	}
322
+
323
+
324
+	/**
325
+	 * Sets the billing form for this payment method type. You may want to use this
326
+	 * if you have form
327
+	 * @param EE_Payment_Method $form
328
+	 */
329
+	public function set_billing_form($form)
330
+	{
331
+		$this->_billing_form = $form;
332
+	}
333
+
334
+
335
+	/**
336
+	 * Returns whether or not this payment method requires HTTPS to be used
337
+	 * @return boolean
338
+	 */
339
+	function requires_https()
340
+	{
341
+		return $this->_requires_https;
342
+	}
343
+
344
+
345
+	/**
346
+	 *
347
+	 * @param EE_Transaction $transaction
348
+	 * @param float $amount
349
+	 * @param EE_Billing_Info_Form $billing_info
350
+	 * @param string $return_url
351
+	 * @param string $fail_url
352
+	 * @param string $method
353
+	 * @param bool $by_admin
354
+	 * @return EE_Payment
355
+	 * @throws EE_Error
356
+	 */
357
+	function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false)
358
+	{
359
+		// @todo: add surcharge for the payment method, if any
360
+		if ($this->_gateway) {
361
+			//there is a gateway, so we're going to make a payment object
362
+			//but wait! do they already have a payment in progress that we thought was failed?
363
+			$duplicate_properties = array(
364
+				'STS_ID' => EEM_Payment::status_id_failed,
365
+				'TXN_ID' => $transaction->ID(),
366
+				'PMD_ID' => $this->_pm_instance->ID(),
367
+				'PAY_source' => $method,
368
+				'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(),
369
+				'PAY_gateway_response' => null,
370
+			);
371
+			$payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372
+			//if we didn't already have a payment in progress for the same thing,
373
+			//then we actually want to make a new payment
374
+			if (!$payment instanceof EE_Payment) {
375
+				$payment = EE_Payment::new_instance(
376
+					array_merge(
377
+						$duplicate_properties,
378
+						array(
379
+							'PAY_timestamp' => time(),
380
+							'PAY_txn_id_chq_nmbr' => null,
381
+							'PAY_po_number' => null,
382
+							'PAY_extra_accntng' => null,
383
+							'PAY_details' => null,
384
+						)
385
+					)
386
+				);
387
+			}
388
+			//make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
389
+			$payment->save();
390
+			$billing_values = $this->_get_billing_values_from_form($billing_info);
391
+
392
+			//  Offsite Gateway
393
+			if ($this->_gateway instanceof EE_Offsite_Gateway) {
394
+
395
+				$payment = $this->_gateway->set_redirection_info(
396
+					$payment,
397
+					$billing_values,
398
+					$return_url,
399
+					EE_Config::instance()->core->txn_page_url(
400
+						array(
401
+							'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(),
402
+							'ee_payment_method' => $this->_pm_instance->slug()
403
+						)
404
+					),
405
+					$fail_url
406
+				);
407
+				$payment->save();
408
+				//  Onsite Gateway
409
+			} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
410
+
411
+				$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
412
+				$payment->save();
413
+
414
+			} else {
415
+				throw new EE_Error(
416
+					sprintf(
417
+						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'),
418
+						get_class($this),
419
+						gettype($this->_gateway)
420
+					)
421
+				);
422
+			}
423
+
424
+		} else {
425
+			// no gateway provided
426
+			// there is no payment. Must be an offline gateway
427
+			// create a payment object anyways, but dont save it
428
+			$payment = EE_Payment::new_instance(
429
+				array(
430
+					'STS_ID' => EEM_Payment::status_id_pending,
431
+					'TXN_ID' => $transaction->ID(),
432
+					'PMD_ID' => $transaction->payment_method_ID(),
433
+					'PAY_amount' => 0.00,
434
+					'PAY_timestamp' => time(),
435
+				)
436
+			);
437
+
438
+		}
439
+
440
+		// if there is billing info, clean it and save it now
441
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
442
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
443
+		}
444
+
445
+		return $payment;
446
+	}
447
+
448
+	/**
449
+	 * Gets the values we want to pass onto the gateway. Normally these
450
+	 * are just the 'pretty' values, but there may be times the data may need
451
+	 * a  little massaging. Proper subsections will become arrays of inputs
452
+	 * @param EE_Billing_Info_Form $billing_form
453
+	 * @return array
454
+	 */
455
+	protected function _get_billing_values_from_form($billing_form)
456
+	{
457
+		if ($billing_form instanceof EE_Form_Section_Proper) {
458
+			return $billing_form->input_pretty_values(true);
459
+		} else {
460
+			return NULL;
461
+		}
462
+	}
463
+
464
+
465
+	/**
466
+	 * Handles an instant payment notification when the transaction is known (by default).
467
+	 * @param array $req_data
468
+	 * @param EE_Transaction $transaction
469
+	 * @return EE_Payment
470
+	 * @throws EE_Error
471
+	 */
472
+	public function handle_ipn($req_data, $transaction)
473
+	{
474
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
+		if (!$this->_gateway instanceof EE_Offsite_Gateway) {
476
+			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477
+
478
+		}
479
+		$payment = $this->_gateway->handle_payment_update($req_data, $transaction);
480
+		return $payment;
481
+	}
482
+
483
+
484
+	/**
485
+	 * Saves the billing info onto the attendee of the primary registrant on this transaction, and
486
+	 * cleans it first.
487
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
488
+	 * @param EE_Transaction $transaction
489
+	 * @return boolean success
490
+	 */
491
+	protected function _save_billing_info_to_attendee($billing_form, $transaction)
492
+	{
493
+		if (!$transaction || !$transaction instanceof EE_Transaction) {
494
+			EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495
+			return false;
496
+		}
497
+		$primary_reg = $transaction->primary_registration();
498
+		if (!$primary_reg) {
499
+			EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500
+			return false;
501
+		}
502
+		$attendee = $primary_reg->attendee();
503
+		if (!$attendee) {
504
+			EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505
+			return false;
506
+		}
507
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
508
+
509
+	}
510
+
511
+
512
+	/**
513
+	 * Gets the payment this IPN is for. Children may often want to
514
+	 * override this to inspect the request
515
+	 * @param EE_Transaction $transaction
516
+	 * @param array $req_data
517
+	 * @return EE_Payment
518
+	 */
519
+	protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
520
+	{
521
+		return $transaction->last_payment();
522
+	}
523
+
524
+
525
+	/**
526
+	 * In case generic code cannot provide the payment processor with a specific payment method
527
+	 * and transaction, it will try calling this method on each activate payment method.
528
+	 * If the payment method is able to identify the request as being for it, it should fetch
529
+	 * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
530
+	 * handle the IPN
531
+	 * @param array $req_data
532
+	 * @return EE_Payment only if this payment method can find the info its needs from $req_data
533
+	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
534
+	 * @throws EE_Error
535
+	 */
536
+	public function handle_unclaimed_ipn($req_data = array())
537
+	{
538
+		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
539
+	}
540
+
541
+
542
+	/**
543
+	 * Logic to be accomplished when the payment attempt is complete.
544
+	 * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
545
+	 * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
546
+	 * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
547
+	 * of the payment). Fed a transaction because it's always assumed to be the last payment that
548
+	 * we're dealing with. Returns that last payment (if there is one)
549
+	 *
550
+	 * @param EE_Transaction $transaction
551
+	 * @return EE_Payment
552
+	 */
553
+	public function finalize_payment_for($transaction)
554
+	{
555
+		return $transaction->last_payment();
556
+	}
557
+
558
+
559
+	/**
560
+	 * Whether or not this payment method's gateway supports sending refund requests
561
+	 * @return boolean
562
+	 */
563
+	public function supports_sending_refunds()
564
+	{
565
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
566
+			return $this->_gateway->supports_sending_refunds();
567
+		} else {
568
+			return false;
569
+		}
570
+	}
571
+
572
+
573
+	/**
574
+	 *
575
+	 * @param EE_Payment $payment
576
+	 * @param array $refund_info
577
+	 * @throws EE_Error
578
+	 * @return EE_Payment
579
+	 */
580
+	public function process_refund(EE_Payment $payment, $refund_info = array())
581
+	{
582
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
583
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
584
+		} else {
585
+			throw new EE_Error(
586
+				sprintf(
587
+					__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
588
+					get_class($this)
589
+				)
590
+			);
591
+		}
592
+	}
593
+
594
+
595
+	/**
596
+	 * Returns one the class's constants onsite,offsite, or offline, depending on this
597
+	 * payment method's gateway.
598
+	 * @return string
599
+	 * @throws EE_Error
600
+	 */
601
+	public function payment_occurs()
602
+	{
603
+		if (!$this->_gateway) {
604
+			return EE_PMT_Base::offline;
605
+		} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606
+			return EE_PMT_Base::onsite;
607
+		} elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
608
+			return EE_PMT_Base::offsite;
609
+		} else {
610
+			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
611
+		}
612
+	}
613
+
614
+
615
+	/**
616
+	 * For adding any html output ab ove the payment overview.
617
+	 * Many gateways won't want ot display anything, so this function just returns an empty string.
618
+	 * Other gateways may want to override this, such as offline gateways.
619
+	 * @param EE_Payment $payment
620
+	 * @return string
621
+	 */
622
+	public function payment_overview_content(EE_Payment $payment)
623
+	{
624
+		return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625
+	}
626
+
627
+
628
+	/**
629
+	 * @return array where keys are the help tab name,
630
+	 * values are: array {
631
+	 * @type string $title i18n name for the help tab
632
+	 * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file)
633
+	 * @type array $template_args any arguments you want passed to the template file while rendering.
634
+	 *                Keys will be variable names and values with be their values.
635
+	 */
636
+	public function help_tabs_config()
637
+	{
638
+		return array();
639
+	}
640
+
641
+
642
+	/**
643
+	 * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
644
+	 * the payment method's table's PMT_type column)
645
+	 * @return string
646
+	 */
647
+	public function system_name()
648
+	{
649
+		$classname = get_class($this);
650
+		return str_replace("EE_PMT_", '', $classname);
651
+	}
652
+
653
+
654
+	/**
655
+	 * A pretty i18n version of the PMT name
656
+	 * @return string
657
+	 */
658
+	public function pretty_name()
659
+	{
660
+		return $this->_pretty_name;
661
+	}
662
+
663
+
664
+	/**
665
+	 * Gets the default absolute URL to the payment method type's button
666
+	 * @return string
667
+	 */
668
+	public function default_button_url()
669
+	{
670
+		return $this->_default_button_url;
671
+	}
672
+
673
+
674
+	/**
675
+	 * Gets the gateway used by this payment method (if any)
676
+	 * @return EE_Gateway
677
+	 */
678
+	public function get_gateway()
679
+	{
680
+		return $this->_gateway;
681
+	}
682
+
683
+
684
+	/**
685
+	 * @return string html for the link to a help tab
686
+	 */
687
+	public function get_help_tab_link()
688
+	{
689
+		return EEH_Template::get_help_tab_link(
690
+			$this->get_help_tab_name(),
691
+			'espresso_payment_settings',
692
+			'default'
693
+		);
694
+	}
695
+
696
+
697
+	/**
698
+	 * Returns the name of the help tab for this PMT
699
+	 * @return string
700
+	 */
701
+	public function get_help_tab_name()
702
+	{
703
+		return 'ee_' . strtolower($this->system_name()) . '_help_tab';
704
+	}
705
+
706
+	/**
707
+	 * The name of the wp capability that should be associated with the usage of
708
+	 * this PMT by an admin
709
+	 * @return string
710
+	 */
711
+	public function cap_name()
712
+	{
713
+		return 'ee_payment_method_' . strtolower($this->system_name());
714
+	}
715
+
716
+	/**
717
+	 * Called by client code to tell the gateway that if it wants to change
718
+	 * the transaction or line items or registrations related to teh payment it already
719
+	 * processed (we think, but possibly not) that now's the time to do it.
720
+	 * It is expected that gateways will store any info they need for this on the PAY_details,
721
+	 * or maybe an extra meta value
722
+	 * @param EE_Payment $payment
723
+	 * @return void
724
+	 */
725
+	public function update_txn_based_on_payment($payment)
726
+	{
727
+		if ($this->_gateway instanceof EE_Gateway) {
728
+			$this->_gateway->update_txn_based_on_payment($payment);
729
+		}
730
+	}
731
+
732
+	/**
733
+	 * Returns a string of HTML describing this payment method type for an admin,
734
+	 * primarily intended for them to read before activating it.
735
+	 * The easiest way to set this is to create a folder 'templates' alongside
736
+	 * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
737
+	 * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
738
+	 * then you'd create a file named "templates" in the same folder as it, and name the file
739
+	 * "foo_bar_intro.template.php", and its content will be returned by this method
740
+	 * @return string
741
+	 */
742
+	public function introductory_html()
743
+	{
744
+		return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
745
+	}
746 746
 
747 747
 
748 748
 }
Please login to merge, or discard this patch.
core/domain/services/registration/CreateRegistrationService.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use OutOfRangeException;
18 18
 
19 19
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
20
-    exit('No direct script access allowed');
20
+	exit('No direct script access allowed');
21 21
 }
22 22
 
23 23
 
@@ -41,54 +41,54 @@  discard block
 block discarded – undo
41 41
 	 * @param EE_Line_Item   $ticket_line_item
42 42
 	 * @param                 $reg_count
43 43
 	 * @param                 $reg_group_size
44
-     * @param string          $reg_status
45
-     * @return EE_Registration
44
+	 * @param string          $reg_status
45
+	 * @return EE_Registration
46 46
 	 * @throws OutOfRangeException
47 47
 	 * @throws EE_Error
48 48
 	 * @throws UnexpectedEntityException
49 49
 	 */
50
-    public function create(
51
-        EE_Event $event,
52
-        EE_Transaction $transaction,
53
-        EE_Ticket $ticket,
54
-        EE_Line_Item $ticket_line_item,
55
-        $reg_count,
56
-        $reg_group_size,
57
-        $reg_status = EEM_Registration::status_id_incomplete
58
-    ) {
59
-        $registrations = $transaction->registrations();
60
-        $reg_count = $reg_count ? $reg_count : count($registrations) + 1;
61
-        $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item);
62
-        $reg_code = new RegCode($reg_url_link, $transaction, $ticket);
63
-        // generate new EE_Registration
64
-        $registration = EE_Registration::new_instance(
65
-            array(
66
-                'EVT_ID'          => $event->ID(),
67
-                'TXN_ID'          => $transaction->ID(),
68
-                'TKT_ID'          => $ticket->ID(),
69
-                'STS_ID'          => $reg_status,
70
-                'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item),
71
-                'REG_session'     => EE_Registry::instance()->SSN->id(),
72
-                'REG_count'       => $reg_count,
73
-                'REG_group_size'  => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations),
74
-                'REG_url_link'    => $reg_url_link,
75
-                'REG_code'        => $reg_code,
76
-            )
77
-        );
78
-        if ( ! $registration instanceof EE_Registration) {
79
-            throw new UnexpectedEntityException($registration, 'EE_Registration');
80
-        }
81
-        // save registration so that we have an ID
82
-        $registration->save();
83
-        // track reservation on reg but don't adjust ticket and datetime reserved counts
84
-        // because that is done as soon as the tickets are added/removed from the cart
85
-        $registration->reserve_ticket(false, 'CreateRegistrationService:'. __LINE__);
86
-        $registration->_add_relation_to($event, 'Event', array(), $event->ID());
87
-        $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
88
-        $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
89
-        $registration->save();
90
-        return $registration;
91
-    }
50
+	public function create(
51
+		EE_Event $event,
52
+		EE_Transaction $transaction,
53
+		EE_Ticket $ticket,
54
+		EE_Line_Item $ticket_line_item,
55
+		$reg_count,
56
+		$reg_group_size,
57
+		$reg_status = EEM_Registration::status_id_incomplete
58
+	) {
59
+		$registrations = $transaction->registrations();
60
+		$reg_count = $reg_count ? $reg_count : count($registrations) + 1;
61
+		$reg_url_link = new RegUrlLink($reg_count, $ticket_line_item);
62
+		$reg_code = new RegCode($reg_url_link, $transaction, $ticket);
63
+		// generate new EE_Registration
64
+		$registration = EE_Registration::new_instance(
65
+			array(
66
+				'EVT_ID'          => $event->ID(),
67
+				'TXN_ID'          => $transaction->ID(),
68
+				'TKT_ID'          => $ticket->ID(),
69
+				'STS_ID'          => $reg_status,
70
+				'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item),
71
+				'REG_session'     => EE_Registry::instance()->SSN->id(),
72
+				'REG_count'       => $reg_count,
73
+				'REG_group_size'  => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations),
74
+				'REG_url_link'    => $reg_url_link,
75
+				'REG_code'        => $reg_code,
76
+			)
77
+		);
78
+		if ( ! $registration instanceof EE_Registration) {
79
+			throw new UnexpectedEntityException($registration, 'EE_Registration');
80
+		}
81
+		// save registration so that we have an ID
82
+		$registration->save();
83
+		// track reservation on reg but don't adjust ticket and datetime reserved counts
84
+		// because that is done as soon as the tickets are added/removed from the cart
85
+		$registration->reserve_ticket(false, 'CreateRegistrationService:'. __LINE__);
86
+		$registration->_add_relation_to($event, 'Event', array(), $event->ID());
87
+		$registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
88
+		$transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
89
+		$registration->save();
90
+		return $registration;
91
+	}
92 92
 
93 93
 
94 94
 
@@ -100,40 +100,40 @@  discard block
 block discarded – undo
100 100
 	 * @throws EE_Error
101 101
 	 * @throws OutOfRangeException
102 102
 	 */
103
-    protected function resolveFinalPrice(
104
-        EE_Transaction $transaction,
105
-        EE_Ticket $ticket,
106
-        EE_Line_Item $ticket_line_item
107
-    ) {
108
-        $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item(
109
-            $transaction->total_line_item(),
110
-            $ticket_line_item
111
-        );
112
-        $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
113
-        return (float)$final_price;
114
-    }
103
+	protected function resolveFinalPrice(
104
+		EE_Transaction $transaction,
105
+		EE_Ticket $ticket,
106
+		EE_Line_Item $ticket_line_item
107
+	) {
108
+		$final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item(
109
+			$transaction->total_line_item(),
110
+			$ticket_line_item
111
+		);
112
+		$final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
113
+		return (float)$final_price;
114
+	}
115 115
 
116 116
 
117 117
 
118
-    /**
119
-     * @param  EE_Registration[] $registrations
120
-     * @param  boolean            $update_existing_registrations
121
-     * @return int
122
-     * @throws EE_Error
123
-     */
124
-    protected function incrementRegCount(array $registrations, $update_existing_registrations = true)
125
-    {
126
-        $new_reg_count = count($registrations) + 1;
127
-        if ($update_existing_registrations) {
128
-            foreach ($registrations as $registration) {
129
-                if ($registration instanceof EE_Registration) {
130
-                    $registration->set_count($new_reg_count);
131
-                    $registration->save();
132
-                }
133
-            }
134
-        }
135
-        return $new_reg_count;
136
-    }
118
+	/**
119
+	 * @param  EE_Registration[] $registrations
120
+	 * @param  boolean            $update_existing_registrations
121
+	 * @return int
122
+	 * @throws EE_Error
123
+	 */
124
+	protected function incrementRegCount(array $registrations, $update_existing_registrations = true)
125
+	{
126
+		$new_reg_count = count($registrations) + 1;
127
+		if ($update_existing_registrations) {
128
+			foreach ($registrations as $registration) {
129
+				if ($registration instanceof EE_Registration) {
130
+					$registration->set_count($new_reg_count);
131
+					$registration->save();
132
+				}
133
+			}
134
+		}
135
+		return $new_reg_count;
136
+	}
137 137
 
138 138
 
139 139
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
         $registration->save();
83 83
         // track reservation on reg but don't adjust ticket and datetime reserved counts
84 84
         // because that is done as soon as the tickets are added/removed from the cart
85
-        $registration->reserve_ticket(false, 'CreateRegistrationService:'. __LINE__);
85
+        $registration->reserve_ticket(false, 'CreateRegistrationService:'.__LINE__);
86 86
         $registration->_add_relation_to($event, 'Event', array(), $event->ID());
87 87
         $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
88 88
         $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
             $ticket_line_item
111 111
         );
112 112
         $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
113
-        return (float)$final_price;
113
+        return (float) $final_price;
114 114
     }
115 115
 
116 116
 
Please login to merge, or discard this patch.
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +775 added lines, -775 removed lines patch added patch discarded remove patch
@@ -27,781 +27,781 @@
 block discarded – undo
27 27
 class EE_Registration_Processor extends EE_Processor_Base
28 28
 {
29 29
 
30
-    /**
31
-     * @var EE_Registration_Processor $_instance
32
-     * @access    private
33
-     */
34
-    private static $_instance;
35
-
36
-    /**
37
-     * initial reg status at the beginning of this request.
38
-     * indexed by registration ID
39
-     *
40
-     * @var array
41
-     */
42
-    protected $_old_reg_status = array();
43
-
44
-    /**
45
-     * reg status at the end of the request after all processing.
46
-     * indexed by registration ID
47
-     *
48
-     * @var array
49
-     */
50
-    protected $_new_reg_status = array();
51
-
52
-    /**
53
-     * amounts paid at the end of the request after all processing.
54
-     * indexed by registration ID
55
-     *
56
-     * @var array
57
-     */
58
-    protected static $_amount_paid = array();
59
-
60
-    /**
61
-     * Cache of the reg final price for registrations corresponding to a ticket line item
62
-     *
63
-     * @deprecated
64
-     * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
65
-     */
66
-    protected $_reg_final_price_per_tkt_line_item;
67
-
68
-    /**
69
-     * @var EE_Request $request
70
-     */
71
-    protected $request;
72
-
73
-
74
-
75
-    /**
76
-     * @singleton method used to instantiate class object
77
-     * @param EE_Request|null $request
78
-     * @return EE_Registration_Processor instance
79
-     * @throws \InvalidArgumentException
80
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
81
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
82
-     */
83
-    public static function instance(EE_Request $request = null)
84
-    {
85
-        // check if class object is instantiated
86
-        if (! self::$_instance instanceof EE_Registration_Processor) {
87
-            if(! $request instanceof EE_Request) {
88
-                $request = LoaderFactory::getLoader()->getShared('EE_Request');
89
-            }
90
-            self::$_instance = new self($request);
91
-        }
92
-        return self::$_instance;
93
-    }
94
-
95
-
96
-    /**
97
-     * EE_Registration_Processor constructor.
98
-     *
99
-     * @param EE_Request $request
100
-     */
101
-    public function __construct(EE_Request $request)
102
-    {
103
-        $this->request = $request;
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * @param int $REG_ID
110
-     * @return string
111
-     */
112
-    public function old_reg_status($REG_ID)
113
-    {
114
-        return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * @param int    $REG_ID
121
-     * @param string $old_reg_status
122
-     */
123
-    public function set_old_reg_status($REG_ID, $old_reg_status)
124
-    {
125
-        // only set the first time
126
-        if (! isset($this->_old_reg_status[$REG_ID])) {
127
-            $this->_old_reg_status[$REG_ID] = $old_reg_status;
128
-        }
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @param int $REG_ID
135
-     * @return string
136
-     */
137
-    public function new_reg_status($REG_ID)
138
-    {
139
-        return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * @param int    $REG_ID
146
-     * @param string $new_reg_status
147
-     */
148
-    public function set_new_reg_status($REG_ID, $new_reg_status)
149
-    {
150
-        $this->_new_reg_status[$REG_ID] = $new_reg_status;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * reg_status_updated
157
-     *
158
-     * @param int $REG_ID
159
-     * @return bool
160
-     */
161
-    public function reg_status_updated($REG_ID)
162
-    {
163
-        return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * @param EE_Registration $registration
170
-     * @throws EE_Error
171
-     * @throws EntityNotFoundException
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidDataTypeException
174
-     * @throws InvalidInterfaceException
175
-     * @throws ReflectionException
176
-     * @throws RuntimeException
177
-     */
178
-    public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
179
-    {
180
-        $this->toggle_incomplete_registration_status_to_default($registration, false);
181
-        $this->toggle_registration_status_for_default_approved_events($registration, false);
182
-        $this->toggle_registration_status_if_no_monies_owing($registration, false);
183
-        $registration->save();
184
-        // trigger notifications
185
-        $this->trigger_registration_update_notifications($registration);
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     *    manually_update_registration_status
192
-     *
193
-     * @access public
194
-     * @param EE_Registration $registration
195
-     * @param string          $new_reg_status
196
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
197
-     *                              to client code
198
-     * @return bool
199
-     * @throws EE_Error
200
-     * @throws EntityNotFoundException
201
-     * @throws InvalidArgumentException
202
-     * @throws InvalidDataTypeException
203
-     * @throws InvalidInterfaceException
204
-     * @throws ReflectionException
205
-     * @throws RuntimeException
206
-     */
207
-    public function manually_update_registration_status(
208
-        EE_Registration $registration,
209
-        $new_reg_status = '',
210
-        $save = true
211
-    ) {
212
-        // set initial REG_Status
213
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
214
-        // set incoming REG_Status
215
-        $this->set_new_reg_status($registration->ID(), $new_reg_status);
216
-        // toggle reg status but only if it has changed and the user can do so
217
-        if (
218
-            $this->reg_status_updated($registration->ID())
219
-            && (
220
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
221
-                || EE_Registry::instance()->CAP->current_user_can(
222
-                    'ee_edit_registration',
223
-                    'toggle_registration_status',
224
-                    $registration->ID()
225
-                )
226
-            )
227
-        ) {
228
-            // change status to new value
229
-            $updated = $registration->set_status($this->new_reg_status($registration->ID()));
230
-            if ($updated && $save) {
231
-                $registration->save();
232
-            }
233
-            return true;
234
-        }
235
-        return false;
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     *    toggle_incomplete_registration_status_to_default
242
-     *        changes any incomplete registrations to either the event or global default registration status
243
-     *
244
-     * @access public
245
-     * @param EE_Registration $registration
246
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
247
-     *                              to client code
248
-     * @param ContextInterface|null    $context
249
-     * @return void
250
-     * @throws EE_Error
251
-     * @throws InvalidArgumentException
252
-     * @throws ReflectionException
253
-     * @throws RuntimeException
254
-     * @throws EntityNotFoundException
255
-     * @throws InvalidDataTypeException
256
-     * @throws InvalidInterfaceException
257
-     */
258
-    public function toggle_incomplete_registration_status_to_default(
259
-        EE_Registration $registration,
260
-        $save = true,
261
-        ContextInterface $context = null
262
-    ) {
263
-        $existing_reg_status = $registration->status_ID();
264
-        // set initial REG_Status
265
-        $this->set_old_reg_status($registration->ID(), $existing_reg_status);
266
-        // is the registration currently incomplete ?
267
-        if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
268
-            // grab default reg status for the event, if set
269
-            $event_default_registration_status = $registration->event()->default_registration_status();
270
-            // if no default reg status is set for the event, then use the global value
271
-            $STS_ID = ! empty($event_default_registration_status)
272
-                ? $event_default_registration_status
273
-                : EE_Registry::instance()->CFG->registration->default_STS_ID;
274
-            // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
275
-            $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
276
-                : $STS_ID;
277
-            // set incoming REG_Status
278
-            $this->set_new_reg_status($registration->ID(), $STS_ID);
279
-            $registration->set_status($STS_ID, false, $context);
280
-            if ($save) {
281
-                $registration->save();
282
-            }
283
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
284
-            if (! EE_Processor_Base::$IPN) {
285
-                // otherwise, send out notifications
286
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
287
-            }
288
-            // DEBUG LOG
289
-            //$this->log(
290
-            //	__CLASS__, __FUNCTION__, __LINE__,
291
-            //	$registration->transaction(),
292
-            //	array(
293
-            //		'IPN'                   => EE_Processor_Base::$IPN,
294
-            //		'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ),
295
-            //	)
296
-            //);
297
-        }
298
-    }
299
-
300
-
301
-
302
-    /**
303
-     *    toggle_registration_status_for_default_approved_events
304
-     *
305
-     * @access public
306
-     * @param EE_Registration $registration
307
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
308
-     *                              to client code
309
-     * @return bool
310
-     * @throws EE_Error
311
-     * @throws EntityNotFoundException
312
-     * @throws InvalidArgumentException
313
-     * @throws InvalidDataTypeException
314
-     * @throws InvalidInterfaceException
315
-     * @throws ReflectionException
316
-     * @throws RuntimeException
317
-     */
318
-    public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
319
-    {
320
-        $reg_status = $registration->status_ID();
321
-        // set initial REG_Status
322
-        $this->set_old_reg_status($registration->ID(), $reg_status);
323
-        // if not already, toggle reg status to approved IF the event default reg status is approved
324
-        // ( as long as the registration wasn't cancelled or declined at some point )
325
-        if (
326
-            $reg_status !== EEM_Registration::status_id_cancelled
327
-            && $reg_status
328
-               !== EEM_Registration::status_id_declined
329
-            && $reg_status !== EEM_Registration::status_id_approved
330
-            && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
331
-        ) {
332
-            // set incoming REG_Status
333
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
334
-            // toggle status to approved
335
-            $registration->set_status(EEM_Registration::status_id_approved);
336
-            if ($save) {
337
-                $registration->save();
338
-            }
339
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
340
-            if (! EE_Processor_Base::$IPN) {
341
-                // otherwise, send out notifications
342
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
343
-            }
344
-            // DEBUG LOG
345
-            //$this->log(
346
-            //	__CLASS__, __FUNCTION__, __LINE__,
347
-            //	$registration->transaction(),
348
-            //	array(
349
-            //		'IPN'                   => EE_Processor_Base::$IPN,
350
-            //		'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ),
351
-            //	)
352
-            //);
353
-            return true;
354
-        }
355
-        return false;
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     *    toggle_registration_statuses_if_no_monies_owing
362
-     *
363
-     * @access public
364
-     * @param EE_Registration $registration
365
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
366
-     *                              to client code
367
-     * @param array           $additional_details
368
-     * @return bool
369
-     * @throws EE_Error
370
-     * @throws EntityNotFoundException
371
-     * @throws InvalidArgumentException
372
-     * @throws InvalidDataTypeException
373
-     * @throws InvalidInterfaceException
374
-     * @throws ReflectionException
375
-     * @throws RuntimeException
376
-     */
377
-    public function toggle_registration_status_if_no_monies_owing(
378
-        EE_Registration $registration,
379
-        $save = true,
380
-        array $additional_details = array()
381
-    ) {
382
-        // set initial REG_Status
383
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
384
-        // was a payment just made ?
385
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
386
-                      && $additional_details['payment_updates']
387
-                      && $additional_details['last_payment'] instanceof EE_Payment
388
-            ? $additional_details['last_payment']
389
-            : null;
390
-        $total_paid = array_sum(self::$_amount_paid);
391
-        // toggle reg status to approved IF
392
-        if (
393
-            // REG status is pending payment
394
-            $registration->status_ID() === EEM_Registration::status_id_pending_payment
395
-            // AND no monies are owing
396
-            && (
397
-                (
398
-                    $registration->transaction()->is_completed()
399
-                    || $registration->transaction()->is_overpaid()
400
-                    || $registration->transaction()->is_free()
401
-                    || apply_filters(
402
-                        'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
403
-                        false,
404
-                        $registration
405
-                    )
406
-                )
407
-                || (
408
-                    $payment instanceof EE_Payment && $payment->is_approved()
409
-                    && // this specific registration has not yet been paid for
410
-                    ! isset(self::$_amount_paid[$registration->ID()])
411
-                    && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
412
-                    $payment->amount() - $total_paid >= $registration->final_price()
413
-                )
414
-            )
415
-        ) {
416
-            // mark as paid
417
-            self::$_amount_paid[$registration->ID()] = $registration->final_price();
418
-            // track new REG_Status
419
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
420
-            // toggle status to approved
421
-            $registration->set_status(EEM_Registration::status_id_approved);
422
-            if ($save) {
423
-                $registration->save();
424
-            }
425
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
426
-            if (! EE_Processor_Base::$IPN) {
427
-                // otherwise, send out notifications
428
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
429
-            }
430
-            // DEBUG LOG
431
-            //$this->log(
432
-            //	__CLASS__, __FUNCTION__, __LINE__,
433
-            //	$registration->transaction(),
434
-            //	array(
435
-            //		'IPN'                   => EE_Processor_Base::$IPN,
436
-            //		'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ),
437
-            //	)
438
-            //);
439
-            return true;
440
-        }
441
-        return false;
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     *    registration_status_changed
448
-     *
449
-     * @access public
450
-     * @param EE_Registration $registration
451
-     * @param array           $additional_details
452
-     * @return void
453
-     */
454
-    public function trigger_registration_update_notifications($registration, array $additional_details = array())
455
-    {
456
-        try {
457
-            if (! $registration instanceof EE_Registration) {
458
-                throw new EE_Error(
459
-                    esc_html__('An invalid registration was received.', 'event_espresso')
460
-                );
461
-            }
462
-            // EE_Registry::instance()->load_helper( 'Debug_Tools' );
463
-            // EEH_Debug_Tools::log(
464
-            // 	__CLASS__,
465
-            // 	__FUNCTION__,
466
-            // 	__LINE__,
467
-            // 	array( $registration->transaction(), $additional_details ),
468
-            // 	false,
469
-            // 	'EE_Transaction: ' . $registration->transaction()->ID()
470
-            // );
471
-            if (! $registration->is_primary_registrant()) {
472
-                return;
473
-            }
474
-            do_action(
475
-                'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
476
-                $registration,
477
-                $additional_details
478
-            );
479
-        } catch (Exception $e) {
480
-            EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
481
-        }
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     * sets reg status based either on passed param or on transaction status and event pre-approval setting
488
-     *
489
-     * @param EE_Registration $registration
490
-     * @param array           $additional_details
491
-     * @return bool
492
-     * @throws EE_Error
493
-     * @throws EntityNotFoundException
494
-     * @throws InvalidArgumentException
495
-     * @throws InvalidDataTypeException
496
-     * @throws InvalidInterfaceException
497
-     * @throws ReflectionException
498
-     * @throws RuntimeException
499
-     */
500
-    public function update_registration_after_checkout_or_payment(
501
-        EE_Registration $registration,
502
-        array $additional_details = array()
503
-    ) {
504
-        // set initial REG_Status
505
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
506
-        // if the registration status gets updated, then save the registration
507
-        if (
508
-            $this->toggle_registration_status_for_default_approved_events($registration, false)
509
-            || $this->toggle_registration_status_if_no_monies_owing(
510
-                $registration,
511
-                false,
512
-                $additional_details
513
-            )
514
-        ) {
515
-            $registration->save();
516
-        }
517
-        // set new  REG_Status
518
-        $this->set_new_reg_status($registration->ID(), $registration->status_ID());
519
-        return $this->reg_status_updated($registration->ID())
520
-               && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     * Updates the registration' final prices based on the current line item tree (taking into account
527
-     * discounts, taxes, and other line items unrelated to tickets.)
528
-     *
529
-     * @param EE_Transaction $transaction
530
-     * @param boolean        $save_regs whether to immediately save registrations in this function or not
531
-     * @return void
532
-     * @throws EE_Error
533
-     * @throws InvalidArgumentException
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidInterfaceException
536
-     * @throws RuntimeException
537
-     */
538
-    public function update_registration_final_prices($transaction, $save_regs = true)
539
-    {
540
-        $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
541
-            $transaction->total_line_item()
542
-        );
543
-        foreach ($transaction->registrations() as $registration) {
544
-            /** @var EE_Line_Item $line_item */
545
-            $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
546
-            if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
547
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
548
-                if ($save_regs) {
549
-                    $registration->save();
550
-                }
551
-            }
552
-        }
553
-        //and make sure there's no rounding problem
554
-        $this->fix_reg_final_price_rounding_issue($transaction);
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * Makes sure there is no rounding errors for the REG_final_prices.
561
-     * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
562
-     * they will each be for $0.99333333, which gets rounded to $1 again.
563
-     * So the transaction total will be $2.99, but each registration will be for $1,
564
-     * so if each registrant paid individually they will have overpaid by $0.01.
565
-     * So in order to overcome this, we check for any difference, and if there is a difference
566
-     * we just grab one registrant at random and make them responsible for it.
567
-     * This should be used after setting REG_final_prices (it's done automatically as part of
568
-     * EE_Registration_Processor::update_registration_final_prices())
569
-     *
570
-     * @param EE_Transaction $transaction
571
-     * @return bool success verifying that there is NO difference after this method is done
572
-     * @throws EE_Error
573
-     * @throws InvalidArgumentException
574
-     * @throws InvalidDataTypeException
575
-     * @throws InvalidInterfaceException
576
-     */
577
-    public function fix_reg_final_price_rounding_issue($transaction)
578
-    {
579
-        $reg_final_price_sum = EEM_Registration::instance()->sum(
580
-            array(
581
-                array(
582
-                    'TXN_ID' => $transaction->ID(),
583
-                ),
584
-            ),
585
-            'REG_final_price'
586
-        );
587
-        $diff = $transaction->total() - $reg_final_price_sum;
588
-        //ok then, just grab one of the registrations
589
-        if ($diff !== 0) {
590
-            $a_reg   = EEM_Registration::instance()->get_one(
591
-                array(
592
-                    array(
593
-                        'TXN_ID' => $transaction->ID(),
594
-                    ),
595
-                )
596
-            );
597
-            return $a_reg instanceof EE_Registration
598
-                ? (bool) $a_reg->save(array('REG_final_price' => $a_reg->final_price() + $diff))
599
-                : false;
600
-        }
601
-        return true;
602
-    }
603
-
604
-
605
-
606
-    /**
607
-     * update_registration_after_being_canceled_or_declined
608
-     *
609
-     * @param EE_Registration $registration
610
-     * @param array           $closed_reg_statuses
611
-     * @param bool            $update_reg
612
-     * @return bool
613
-     * @throws EE_Error
614
-     * @throws RuntimeException
615
-     */
616
-    public function update_registration_after_being_canceled_or_declined(
617
-        EE_Registration $registration,
618
-        array $closed_reg_statuses = array(),
619
-        $update_reg = true
620
-    ) {
621
-        // these reg statuses should not be considered in any calculations involving monies owing
622
-        $closed_reg_statuses = ! empty($closed_reg_statuses)
623
-            ? $closed_reg_statuses
624
-            : EEM_Registration::closed_reg_statuses();
625
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626
-            return false;
627
-        }
628
-        // release a reserved ticket by decrementing ticket and datetime reserved values
629
-        $registration->release_reserved_ticket(true, 'RegProcessor:'. __LINE__);
630
-        $registration->set_final_price(0);
631
-        if ($update_reg) {
632
-            $registration->save();
633
-        }
634
-        return true;
635
-    }
636
-
637
-
638
-
639
-    /**
640
-     * update_canceled_or_declined_registration_after_being_reinstated
641
-     *
642
-     * @param EE_Registration $registration
643
-     * @param array           $closed_reg_statuses
644
-     * @param bool            $update_reg
645
-     * @return bool
646
-     * @throws EE_Error
647
-     * @throws RuntimeException
648
-     */
649
-    public function update_canceled_or_declined_registration_after_being_reinstated(
650
-        EE_Registration $registration,
651
-        array $closed_reg_statuses = array(),
652
-        $update_reg = true
653
-    ) {
654
-        // these reg statuses should not be considered in any calculations involving monies owing
655
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
656
-            : EEM_Registration::closed_reg_statuses();
657
-        if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
658
-            return false;
659
-        }
660
-        $ticket = $registration->ticket();
661
-        if (! $ticket instanceof EE_Ticket) {
662
-            throw new EE_Error(
663
-                sprintf(
664
-                    esc_html__(
665
-                        'The Ticket for Registration %1$d was not found or is invalid.',
666
-                        'event_espresso'
667
-                    ),
668
-                    $registration->ticket_ID()
669
-                )
670
-            );
671
-        }
672
-        $registration->set_final_price($ticket->price());
673
-        if ($update_reg) {
674
-            $registration->save();
675
-        }
676
-        return true;
677
-    }
678
-
679
-
680
-
681
-    /**
682
-     * generate_ONE_registration_from_line_item
683
-     * Although a ticket line item may have a quantity greater than 1,
684
-     * this method will ONLY CREATE ONE REGISTRATION !!!
685
-     * Regardless of the ticket line item quantity.
686
-     * This means that any code calling this method is responsible for ensuring
687
-     * that the final registration count matches the ticket line item quantity.
688
-     * This was done to make it easier to match the number of registrations
689
-     * to the number of tickets in the cart, when the cart has been edited
690
-     * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
691
-     * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
692
-     *
693
-     * @deprecated
694
-     * @since 4.9.1
695
-     * @param EE_Line_Item    $line_item
696
-     * @param \EE_Transaction $transaction
697
-     * @param int             $att_nmbr
698
-     * @param int             $total_ticket_count
699
-     * @return EE_Registration | null
700
-     * @throws \OutOfRangeException
701
-     * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
702
-     * @throws \EE_Error
703
-     */
704
-    public function generate_ONE_registration_from_line_item(
705
-        EE_Line_Item $line_item,
706
-        EE_Transaction $transaction,
707
-        $att_nmbr = 1,
708
-        $total_ticket_count = 1
709
-    ) {
710
-        EE_Error::doing_it_wrong(
711
-            __CLASS__ . '::' . __FUNCTION__,
712
-            sprintf(
713
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714
-                '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
715
-            ),
716
-            '4.9.1',
717
-            '5.0.0'
718
-        );
719
-        // grab the related ticket object for this line_item
720
-        $ticket = $line_item->ticket();
721
-        if (! $ticket instanceof EE_Ticket) {
722
-            EE_Error::add_error(
723
-                sprintf(
724
-                    esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
725
-                    $line_item->ID()
726
-                ),
727
-                __FILE__,
728
-                __FUNCTION__,
729
-                __LINE__
730
-            );
731
-            return null;
732
-        }
733
-        $registration_service = new CreateRegistrationService();
734
-        // then generate a new registration from that
735
-        return $registration_service->create(
736
-            $ticket->get_related_event(),
737
-            $transaction,
738
-            $ticket,
739
-            $line_item,
740
-            $att_nmbr,
741
-            $total_ticket_count
742
-        );
743
-    }
744
-
745
-
746
-
747
-    /**
748
-     * generates reg_url_link
749
-     *
750
-     * @deprecated
751
-     * @since 4.9.1
752
-     * @param int                   $att_nmbr
753
-     * @param EE_Line_Item | string $item
754
-     * @return string
755
-     * @throws InvalidArgumentException
756
-     */
757
-    public function generate_reg_url_link($att_nmbr, $item)
758
-    {
759
-        EE_Error::doing_it_wrong(
760
-            __CLASS__ . '::' . __FUNCTION__,
761
-            sprintf(
762
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
763
-                'EventEspresso\core\domain\entities\RegUrlLink'
764
-            ),
765
-            '4.9.1',
766
-            '5.0.0'
767
-        );
768
-        return new RegUrlLink($att_nmbr, $item);
769
-    }
770
-
771
-
772
-
773
-    /**
774
-     * generates reg code
775
-     *
776
-     * @deprecated
777
-     * @since 4.9.1
778
-     * @param EE_Registration $registration
779
-     * @return string
780
-     * @throws EE_Error
781
-     * @throws EntityNotFoundException
782
-     * @throws InvalidArgumentException
783
-     */
784
-    public function generate_reg_code(EE_Registration $registration)
785
-    {
786
-        EE_Error::doing_it_wrong(
787
-            __CLASS__ . '::' . __FUNCTION__,
788
-            sprintf(
789
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
790
-                'EventEspresso\core\domain\entities\RegCode'
791
-            ),
792
-            '4.9.1',
793
-            '5.0.0'
794
-        );
795
-        return apply_filters(
796
-            'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
797
-            new RegCode(
798
-                RegUrlLink::fromRegistration($registration),
799
-                $registration->transaction(),
800
-                $registration->ticket()
801
-            ),
802
-            $registration
803
-        );
804
-    }
30
+	/**
31
+	 * @var EE_Registration_Processor $_instance
32
+	 * @access    private
33
+	 */
34
+	private static $_instance;
35
+
36
+	/**
37
+	 * initial reg status at the beginning of this request.
38
+	 * indexed by registration ID
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected $_old_reg_status = array();
43
+
44
+	/**
45
+	 * reg status at the end of the request after all processing.
46
+	 * indexed by registration ID
47
+	 *
48
+	 * @var array
49
+	 */
50
+	protected $_new_reg_status = array();
51
+
52
+	/**
53
+	 * amounts paid at the end of the request after all processing.
54
+	 * indexed by registration ID
55
+	 *
56
+	 * @var array
57
+	 */
58
+	protected static $_amount_paid = array();
59
+
60
+	/**
61
+	 * Cache of the reg final price for registrations corresponding to a ticket line item
62
+	 *
63
+	 * @deprecated
64
+	 * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
65
+	 */
66
+	protected $_reg_final_price_per_tkt_line_item;
67
+
68
+	/**
69
+	 * @var EE_Request $request
70
+	 */
71
+	protected $request;
72
+
73
+
74
+
75
+	/**
76
+	 * @singleton method used to instantiate class object
77
+	 * @param EE_Request|null $request
78
+	 * @return EE_Registration_Processor instance
79
+	 * @throws \InvalidArgumentException
80
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
81
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
82
+	 */
83
+	public static function instance(EE_Request $request = null)
84
+	{
85
+		// check if class object is instantiated
86
+		if (! self::$_instance instanceof EE_Registration_Processor) {
87
+			if(! $request instanceof EE_Request) {
88
+				$request = LoaderFactory::getLoader()->getShared('EE_Request');
89
+			}
90
+			self::$_instance = new self($request);
91
+		}
92
+		return self::$_instance;
93
+	}
94
+
95
+
96
+	/**
97
+	 * EE_Registration_Processor constructor.
98
+	 *
99
+	 * @param EE_Request $request
100
+	 */
101
+	public function __construct(EE_Request $request)
102
+	{
103
+		$this->request = $request;
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * @param int $REG_ID
110
+	 * @return string
111
+	 */
112
+	public function old_reg_status($REG_ID)
113
+	{
114
+		return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * @param int    $REG_ID
121
+	 * @param string $old_reg_status
122
+	 */
123
+	public function set_old_reg_status($REG_ID, $old_reg_status)
124
+	{
125
+		// only set the first time
126
+		if (! isset($this->_old_reg_status[$REG_ID])) {
127
+			$this->_old_reg_status[$REG_ID] = $old_reg_status;
128
+		}
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @param int $REG_ID
135
+	 * @return string
136
+	 */
137
+	public function new_reg_status($REG_ID)
138
+	{
139
+		return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * @param int    $REG_ID
146
+	 * @param string $new_reg_status
147
+	 */
148
+	public function set_new_reg_status($REG_ID, $new_reg_status)
149
+	{
150
+		$this->_new_reg_status[$REG_ID] = $new_reg_status;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * reg_status_updated
157
+	 *
158
+	 * @param int $REG_ID
159
+	 * @return bool
160
+	 */
161
+	public function reg_status_updated($REG_ID)
162
+	{
163
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * @param EE_Registration $registration
170
+	 * @throws EE_Error
171
+	 * @throws EntityNotFoundException
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws InvalidInterfaceException
175
+	 * @throws ReflectionException
176
+	 * @throws RuntimeException
177
+	 */
178
+	public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
179
+	{
180
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
181
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
182
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
183
+		$registration->save();
184
+		// trigger notifications
185
+		$this->trigger_registration_update_notifications($registration);
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 *    manually_update_registration_status
192
+	 *
193
+	 * @access public
194
+	 * @param EE_Registration $registration
195
+	 * @param string          $new_reg_status
196
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
197
+	 *                              to client code
198
+	 * @return bool
199
+	 * @throws EE_Error
200
+	 * @throws EntityNotFoundException
201
+	 * @throws InvalidArgumentException
202
+	 * @throws InvalidDataTypeException
203
+	 * @throws InvalidInterfaceException
204
+	 * @throws ReflectionException
205
+	 * @throws RuntimeException
206
+	 */
207
+	public function manually_update_registration_status(
208
+		EE_Registration $registration,
209
+		$new_reg_status = '',
210
+		$save = true
211
+	) {
212
+		// set initial REG_Status
213
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
214
+		// set incoming REG_Status
215
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
216
+		// toggle reg status but only if it has changed and the user can do so
217
+		if (
218
+			$this->reg_status_updated($registration->ID())
219
+			&& (
220
+				(! $this->request->isAdmin() || $this->request->isFrontAjax())
221
+				|| EE_Registry::instance()->CAP->current_user_can(
222
+					'ee_edit_registration',
223
+					'toggle_registration_status',
224
+					$registration->ID()
225
+				)
226
+			)
227
+		) {
228
+			// change status to new value
229
+			$updated = $registration->set_status($this->new_reg_status($registration->ID()));
230
+			if ($updated && $save) {
231
+				$registration->save();
232
+			}
233
+			return true;
234
+		}
235
+		return false;
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 *    toggle_incomplete_registration_status_to_default
242
+	 *        changes any incomplete registrations to either the event or global default registration status
243
+	 *
244
+	 * @access public
245
+	 * @param EE_Registration $registration
246
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
247
+	 *                              to client code
248
+	 * @param ContextInterface|null    $context
249
+	 * @return void
250
+	 * @throws EE_Error
251
+	 * @throws InvalidArgumentException
252
+	 * @throws ReflectionException
253
+	 * @throws RuntimeException
254
+	 * @throws EntityNotFoundException
255
+	 * @throws InvalidDataTypeException
256
+	 * @throws InvalidInterfaceException
257
+	 */
258
+	public function toggle_incomplete_registration_status_to_default(
259
+		EE_Registration $registration,
260
+		$save = true,
261
+		ContextInterface $context = null
262
+	) {
263
+		$existing_reg_status = $registration->status_ID();
264
+		// set initial REG_Status
265
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
266
+		// is the registration currently incomplete ?
267
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
268
+			// grab default reg status for the event, if set
269
+			$event_default_registration_status = $registration->event()->default_registration_status();
270
+			// if no default reg status is set for the event, then use the global value
271
+			$STS_ID = ! empty($event_default_registration_status)
272
+				? $event_default_registration_status
273
+				: EE_Registry::instance()->CFG->registration->default_STS_ID;
274
+			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
275
+			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
276
+				: $STS_ID;
277
+			// set incoming REG_Status
278
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
279
+			$registration->set_status($STS_ID, false, $context);
280
+			if ($save) {
281
+				$registration->save();
282
+			}
283
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
284
+			if (! EE_Processor_Base::$IPN) {
285
+				// otherwise, send out notifications
286
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
287
+			}
288
+			// DEBUG LOG
289
+			//$this->log(
290
+			//	__CLASS__, __FUNCTION__, __LINE__,
291
+			//	$registration->transaction(),
292
+			//	array(
293
+			//		'IPN'                   => EE_Processor_Base::$IPN,
294
+			//		'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ),
295
+			//	)
296
+			//);
297
+		}
298
+	}
299
+
300
+
301
+
302
+	/**
303
+	 *    toggle_registration_status_for_default_approved_events
304
+	 *
305
+	 * @access public
306
+	 * @param EE_Registration $registration
307
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
308
+	 *                              to client code
309
+	 * @return bool
310
+	 * @throws EE_Error
311
+	 * @throws EntityNotFoundException
312
+	 * @throws InvalidArgumentException
313
+	 * @throws InvalidDataTypeException
314
+	 * @throws InvalidInterfaceException
315
+	 * @throws ReflectionException
316
+	 * @throws RuntimeException
317
+	 */
318
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
319
+	{
320
+		$reg_status = $registration->status_ID();
321
+		// set initial REG_Status
322
+		$this->set_old_reg_status($registration->ID(), $reg_status);
323
+		// if not already, toggle reg status to approved IF the event default reg status is approved
324
+		// ( as long as the registration wasn't cancelled or declined at some point )
325
+		if (
326
+			$reg_status !== EEM_Registration::status_id_cancelled
327
+			&& $reg_status
328
+			   !== EEM_Registration::status_id_declined
329
+			&& $reg_status !== EEM_Registration::status_id_approved
330
+			&& $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
331
+		) {
332
+			// set incoming REG_Status
333
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
334
+			// toggle status to approved
335
+			$registration->set_status(EEM_Registration::status_id_approved);
336
+			if ($save) {
337
+				$registration->save();
338
+			}
339
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
340
+			if (! EE_Processor_Base::$IPN) {
341
+				// otherwise, send out notifications
342
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
343
+			}
344
+			// DEBUG LOG
345
+			//$this->log(
346
+			//	__CLASS__, __FUNCTION__, __LINE__,
347
+			//	$registration->transaction(),
348
+			//	array(
349
+			//		'IPN'                   => EE_Processor_Base::$IPN,
350
+			//		'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ),
351
+			//	)
352
+			//);
353
+			return true;
354
+		}
355
+		return false;
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 *    toggle_registration_statuses_if_no_monies_owing
362
+	 *
363
+	 * @access public
364
+	 * @param EE_Registration $registration
365
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
366
+	 *                              to client code
367
+	 * @param array           $additional_details
368
+	 * @return bool
369
+	 * @throws EE_Error
370
+	 * @throws EntityNotFoundException
371
+	 * @throws InvalidArgumentException
372
+	 * @throws InvalidDataTypeException
373
+	 * @throws InvalidInterfaceException
374
+	 * @throws ReflectionException
375
+	 * @throws RuntimeException
376
+	 */
377
+	public function toggle_registration_status_if_no_monies_owing(
378
+		EE_Registration $registration,
379
+		$save = true,
380
+		array $additional_details = array()
381
+	) {
382
+		// set initial REG_Status
383
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
384
+		// was a payment just made ?
385
+		$payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
386
+					  && $additional_details['payment_updates']
387
+					  && $additional_details['last_payment'] instanceof EE_Payment
388
+			? $additional_details['last_payment']
389
+			: null;
390
+		$total_paid = array_sum(self::$_amount_paid);
391
+		// toggle reg status to approved IF
392
+		if (
393
+			// REG status is pending payment
394
+			$registration->status_ID() === EEM_Registration::status_id_pending_payment
395
+			// AND no monies are owing
396
+			&& (
397
+				(
398
+					$registration->transaction()->is_completed()
399
+					|| $registration->transaction()->is_overpaid()
400
+					|| $registration->transaction()->is_free()
401
+					|| apply_filters(
402
+						'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
403
+						false,
404
+						$registration
405
+					)
406
+				)
407
+				|| (
408
+					$payment instanceof EE_Payment && $payment->is_approved()
409
+					&& // this specific registration has not yet been paid for
410
+					! isset(self::$_amount_paid[$registration->ID()])
411
+					&& // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
412
+					$payment->amount() - $total_paid >= $registration->final_price()
413
+				)
414
+			)
415
+		) {
416
+			// mark as paid
417
+			self::$_amount_paid[$registration->ID()] = $registration->final_price();
418
+			// track new REG_Status
419
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
420
+			// toggle status to approved
421
+			$registration->set_status(EEM_Registration::status_id_approved);
422
+			if ($save) {
423
+				$registration->save();
424
+			}
425
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
426
+			if (! EE_Processor_Base::$IPN) {
427
+				// otherwise, send out notifications
428
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
429
+			}
430
+			// DEBUG LOG
431
+			//$this->log(
432
+			//	__CLASS__, __FUNCTION__, __LINE__,
433
+			//	$registration->transaction(),
434
+			//	array(
435
+			//		'IPN'                   => EE_Processor_Base::$IPN,
436
+			//		'deliver_notifications' => has_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications' ),
437
+			//	)
438
+			//);
439
+			return true;
440
+		}
441
+		return false;
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 *    registration_status_changed
448
+	 *
449
+	 * @access public
450
+	 * @param EE_Registration $registration
451
+	 * @param array           $additional_details
452
+	 * @return void
453
+	 */
454
+	public function trigger_registration_update_notifications($registration, array $additional_details = array())
455
+	{
456
+		try {
457
+			if (! $registration instanceof EE_Registration) {
458
+				throw new EE_Error(
459
+					esc_html__('An invalid registration was received.', 'event_espresso')
460
+				);
461
+			}
462
+			// EE_Registry::instance()->load_helper( 'Debug_Tools' );
463
+			// EEH_Debug_Tools::log(
464
+			// 	__CLASS__,
465
+			// 	__FUNCTION__,
466
+			// 	__LINE__,
467
+			// 	array( $registration->transaction(), $additional_details ),
468
+			// 	false,
469
+			// 	'EE_Transaction: ' . $registration->transaction()->ID()
470
+			// );
471
+			if (! $registration->is_primary_registrant()) {
472
+				return;
473
+			}
474
+			do_action(
475
+				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
476
+				$registration,
477
+				$additional_details
478
+			);
479
+		} catch (Exception $e) {
480
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
481
+		}
482
+	}
483
+
484
+
485
+
486
+	/**
487
+	 * sets reg status based either on passed param or on transaction status and event pre-approval setting
488
+	 *
489
+	 * @param EE_Registration $registration
490
+	 * @param array           $additional_details
491
+	 * @return bool
492
+	 * @throws EE_Error
493
+	 * @throws EntityNotFoundException
494
+	 * @throws InvalidArgumentException
495
+	 * @throws InvalidDataTypeException
496
+	 * @throws InvalidInterfaceException
497
+	 * @throws ReflectionException
498
+	 * @throws RuntimeException
499
+	 */
500
+	public function update_registration_after_checkout_or_payment(
501
+		EE_Registration $registration,
502
+		array $additional_details = array()
503
+	) {
504
+		// set initial REG_Status
505
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
506
+		// if the registration status gets updated, then save the registration
507
+		if (
508
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
509
+			|| $this->toggle_registration_status_if_no_monies_owing(
510
+				$registration,
511
+				false,
512
+				$additional_details
513
+			)
514
+		) {
515
+			$registration->save();
516
+		}
517
+		// set new  REG_Status
518
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
519
+		return $this->reg_status_updated($registration->ID())
520
+			   && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 * Updates the registration' final prices based on the current line item tree (taking into account
527
+	 * discounts, taxes, and other line items unrelated to tickets.)
528
+	 *
529
+	 * @param EE_Transaction $transaction
530
+	 * @param boolean        $save_regs whether to immediately save registrations in this function or not
531
+	 * @return void
532
+	 * @throws EE_Error
533
+	 * @throws InvalidArgumentException
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidInterfaceException
536
+	 * @throws RuntimeException
537
+	 */
538
+	public function update_registration_final_prices($transaction, $save_regs = true)
539
+	{
540
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
541
+			$transaction->total_line_item()
542
+		);
543
+		foreach ($transaction->registrations() as $registration) {
544
+			/** @var EE_Line_Item $line_item */
545
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
546
+			if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
547
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
548
+				if ($save_regs) {
549
+					$registration->save();
550
+				}
551
+			}
552
+		}
553
+		//and make sure there's no rounding problem
554
+		$this->fix_reg_final_price_rounding_issue($transaction);
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * Makes sure there is no rounding errors for the REG_final_prices.
561
+	 * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
562
+	 * they will each be for $0.99333333, which gets rounded to $1 again.
563
+	 * So the transaction total will be $2.99, but each registration will be for $1,
564
+	 * so if each registrant paid individually they will have overpaid by $0.01.
565
+	 * So in order to overcome this, we check for any difference, and if there is a difference
566
+	 * we just grab one registrant at random and make them responsible for it.
567
+	 * This should be used after setting REG_final_prices (it's done automatically as part of
568
+	 * EE_Registration_Processor::update_registration_final_prices())
569
+	 *
570
+	 * @param EE_Transaction $transaction
571
+	 * @return bool success verifying that there is NO difference after this method is done
572
+	 * @throws EE_Error
573
+	 * @throws InvalidArgumentException
574
+	 * @throws InvalidDataTypeException
575
+	 * @throws InvalidInterfaceException
576
+	 */
577
+	public function fix_reg_final_price_rounding_issue($transaction)
578
+	{
579
+		$reg_final_price_sum = EEM_Registration::instance()->sum(
580
+			array(
581
+				array(
582
+					'TXN_ID' => $transaction->ID(),
583
+				),
584
+			),
585
+			'REG_final_price'
586
+		);
587
+		$diff = $transaction->total() - $reg_final_price_sum;
588
+		//ok then, just grab one of the registrations
589
+		if ($diff !== 0) {
590
+			$a_reg   = EEM_Registration::instance()->get_one(
591
+				array(
592
+					array(
593
+						'TXN_ID' => $transaction->ID(),
594
+					),
595
+				)
596
+			);
597
+			return $a_reg instanceof EE_Registration
598
+				? (bool) $a_reg->save(array('REG_final_price' => $a_reg->final_price() + $diff))
599
+				: false;
600
+		}
601
+		return true;
602
+	}
603
+
604
+
605
+
606
+	/**
607
+	 * update_registration_after_being_canceled_or_declined
608
+	 *
609
+	 * @param EE_Registration $registration
610
+	 * @param array           $closed_reg_statuses
611
+	 * @param bool            $update_reg
612
+	 * @return bool
613
+	 * @throws EE_Error
614
+	 * @throws RuntimeException
615
+	 */
616
+	public function update_registration_after_being_canceled_or_declined(
617
+		EE_Registration $registration,
618
+		array $closed_reg_statuses = array(),
619
+		$update_reg = true
620
+	) {
621
+		// these reg statuses should not be considered in any calculations involving monies owing
622
+		$closed_reg_statuses = ! empty($closed_reg_statuses)
623
+			? $closed_reg_statuses
624
+			: EEM_Registration::closed_reg_statuses();
625
+		if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626
+			return false;
627
+		}
628
+		// release a reserved ticket by decrementing ticket and datetime reserved values
629
+		$registration->release_reserved_ticket(true, 'RegProcessor:'. __LINE__);
630
+		$registration->set_final_price(0);
631
+		if ($update_reg) {
632
+			$registration->save();
633
+		}
634
+		return true;
635
+	}
636
+
637
+
638
+
639
+	/**
640
+	 * update_canceled_or_declined_registration_after_being_reinstated
641
+	 *
642
+	 * @param EE_Registration $registration
643
+	 * @param array           $closed_reg_statuses
644
+	 * @param bool            $update_reg
645
+	 * @return bool
646
+	 * @throws EE_Error
647
+	 * @throws RuntimeException
648
+	 */
649
+	public function update_canceled_or_declined_registration_after_being_reinstated(
650
+		EE_Registration $registration,
651
+		array $closed_reg_statuses = array(),
652
+		$update_reg = true
653
+	) {
654
+		// these reg statuses should not be considered in any calculations involving monies owing
655
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
656
+			: EEM_Registration::closed_reg_statuses();
657
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
658
+			return false;
659
+		}
660
+		$ticket = $registration->ticket();
661
+		if (! $ticket instanceof EE_Ticket) {
662
+			throw new EE_Error(
663
+				sprintf(
664
+					esc_html__(
665
+						'The Ticket for Registration %1$d was not found or is invalid.',
666
+						'event_espresso'
667
+					),
668
+					$registration->ticket_ID()
669
+				)
670
+			);
671
+		}
672
+		$registration->set_final_price($ticket->price());
673
+		if ($update_reg) {
674
+			$registration->save();
675
+		}
676
+		return true;
677
+	}
678
+
679
+
680
+
681
+	/**
682
+	 * generate_ONE_registration_from_line_item
683
+	 * Although a ticket line item may have a quantity greater than 1,
684
+	 * this method will ONLY CREATE ONE REGISTRATION !!!
685
+	 * Regardless of the ticket line item quantity.
686
+	 * This means that any code calling this method is responsible for ensuring
687
+	 * that the final registration count matches the ticket line item quantity.
688
+	 * This was done to make it easier to match the number of registrations
689
+	 * to the number of tickets in the cart, when the cart has been edited
690
+	 * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
691
+	 * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
692
+	 *
693
+	 * @deprecated
694
+	 * @since 4.9.1
695
+	 * @param EE_Line_Item    $line_item
696
+	 * @param \EE_Transaction $transaction
697
+	 * @param int             $att_nmbr
698
+	 * @param int             $total_ticket_count
699
+	 * @return EE_Registration | null
700
+	 * @throws \OutOfRangeException
701
+	 * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
702
+	 * @throws \EE_Error
703
+	 */
704
+	public function generate_ONE_registration_from_line_item(
705
+		EE_Line_Item $line_item,
706
+		EE_Transaction $transaction,
707
+		$att_nmbr = 1,
708
+		$total_ticket_count = 1
709
+	) {
710
+		EE_Error::doing_it_wrong(
711
+			__CLASS__ . '::' . __FUNCTION__,
712
+			sprintf(
713
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714
+				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
715
+			),
716
+			'4.9.1',
717
+			'5.0.0'
718
+		);
719
+		// grab the related ticket object for this line_item
720
+		$ticket = $line_item->ticket();
721
+		if (! $ticket instanceof EE_Ticket) {
722
+			EE_Error::add_error(
723
+				sprintf(
724
+					esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
725
+					$line_item->ID()
726
+				),
727
+				__FILE__,
728
+				__FUNCTION__,
729
+				__LINE__
730
+			);
731
+			return null;
732
+		}
733
+		$registration_service = new CreateRegistrationService();
734
+		// then generate a new registration from that
735
+		return $registration_service->create(
736
+			$ticket->get_related_event(),
737
+			$transaction,
738
+			$ticket,
739
+			$line_item,
740
+			$att_nmbr,
741
+			$total_ticket_count
742
+		);
743
+	}
744
+
745
+
746
+
747
+	/**
748
+	 * generates reg_url_link
749
+	 *
750
+	 * @deprecated
751
+	 * @since 4.9.1
752
+	 * @param int                   $att_nmbr
753
+	 * @param EE_Line_Item | string $item
754
+	 * @return string
755
+	 * @throws InvalidArgumentException
756
+	 */
757
+	public function generate_reg_url_link($att_nmbr, $item)
758
+	{
759
+		EE_Error::doing_it_wrong(
760
+			__CLASS__ . '::' . __FUNCTION__,
761
+			sprintf(
762
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
763
+				'EventEspresso\core\domain\entities\RegUrlLink'
764
+			),
765
+			'4.9.1',
766
+			'5.0.0'
767
+		);
768
+		return new RegUrlLink($att_nmbr, $item);
769
+	}
770
+
771
+
772
+
773
+	/**
774
+	 * generates reg code
775
+	 *
776
+	 * @deprecated
777
+	 * @since 4.9.1
778
+	 * @param EE_Registration $registration
779
+	 * @return string
780
+	 * @throws EE_Error
781
+	 * @throws EntityNotFoundException
782
+	 * @throws InvalidArgumentException
783
+	 */
784
+	public function generate_reg_code(EE_Registration $registration)
785
+	{
786
+		EE_Error::doing_it_wrong(
787
+			__CLASS__ . '::' . __FUNCTION__,
788
+			sprintf(
789
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
790
+				'EventEspresso\core\domain\entities\RegCode'
791
+			),
792
+			'4.9.1',
793
+			'5.0.0'
794
+		);
795
+		return apply_filters(
796
+			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
797
+			new RegCode(
798
+				RegUrlLink::fromRegistration($registration),
799
+				$registration->transaction(),
800
+				$registration->ticket()
801
+			),
802
+			$registration
803
+		);
804
+	}
805 805
 
806 806
 
807 807
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
     public static function instance(EE_Request $request = null)
84 84
     {
85 85
         // check if class object is instantiated
86
-        if (! self::$_instance instanceof EE_Registration_Processor) {
87
-            if(! $request instanceof EE_Request) {
86
+        if ( ! self::$_instance instanceof EE_Registration_Processor) {
87
+            if ( ! $request instanceof EE_Request) {
88 88
                 $request = LoaderFactory::getLoader()->getShared('EE_Request');
89 89
             }
90 90
             self::$_instance = new self($request);
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     public function set_old_reg_status($REG_ID, $old_reg_status)
124 124
     {
125 125
         // only set the first time
126
-        if (! isset($this->_old_reg_status[$REG_ID])) {
126
+        if ( ! isset($this->_old_reg_status[$REG_ID])) {
127 127
             $this->_old_reg_status[$REG_ID] = $old_reg_status;
128 128
         }
129 129
     }
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
         if (
218 218
             $this->reg_status_updated($registration->ID())
219 219
             && (
220
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
220
+                ( ! $this->request->isAdmin() || $this->request->isFrontAjax())
221 221
                 || EE_Registry::instance()->CAP->current_user_can(
222 222
                     'ee_edit_registration',
223 223
                     'toggle_registration_status',
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
                 $registration->save();
282 282
             }
283 283
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
284
-            if (! EE_Processor_Base::$IPN) {
284
+            if ( ! EE_Processor_Base::$IPN) {
285 285
                 // otherwise, send out notifications
286 286
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
287 287
             }
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                 $registration->save();
338 338
             }
339 339
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
340
-            if (! EE_Processor_Base::$IPN) {
340
+            if ( ! EE_Processor_Base::$IPN) {
341 341
                 // otherwise, send out notifications
342 342
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
343 343
             }
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
         // set initial REG_Status
383 383
         $this->set_old_reg_status($registration->ID(), $registration->status_ID());
384 384
         // was a payment just made ?
385
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
385
+        $payment = isset($additional_details['payment_updates'], $additional_details['last_payment'])
386 386
                       && $additional_details['payment_updates']
387 387
                       && $additional_details['last_payment'] instanceof EE_Payment
388 388
             ? $additional_details['last_payment']
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
                 $registration->save();
424 424
             }
425 425
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
426
-            if (! EE_Processor_Base::$IPN) {
426
+            if ( ! EE_Processor_Base::$IPN) {
427 427
                 // otherwise, send out notifications
428 428
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
429 429
             }
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     public function trigger_registration_update_notifications($registration, array $additional_details = array())
455 455
     {
456 456
         try {
457
-            if (! $registration instanceof EE_Registration) {
457
+            if ( ! $registration instanceof EE_Registration) {
458 458
                 throw new EE_Error(
459 459
                     esc_html__('An invalid registration was received.', 'event_espresso')
460 460
                 );
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
             // 	false,
469 469
             // 	'EE_Transaction: ' . $registration->transaction()->ID()
470 470
             // );
471
-            if (! $registration->is_primary_registrant()) {
471
+            if ( ! $registration->is_primary_registrant()) {
472 472
                 return;
473 473
             }
474 474
             do_action(
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         $diff = $transaction->total() - $reg_final_price_sum;
588 588
         //ok then, just grab one of the registrations
589 589
         if ($diff !== 0) {
590
-            $a_reg   = EEM_Registration::instance()->get_one(
590
+            $a_reg = EEM_Registration::instance()->get_one(
591 591
                 array(
592 592
                     array(
593 593
                         'TXN_ID' => $transaction->ID(),
@@ -622,11 +622,11 @@  discard block
 block discarded – undo
622 622
         $closed_reg_statuses = ! empty($closed_reg_statuses)
623 623
             ? $closed_reg_statuses
624 624
             : EEM_Registration::closed_reg_statuses();
625
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
625
+        if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626 626
             return false;
627 627
         }
628 628
         // release a reserved ticket by decrementing ticket and datetime reserved values
629
-        $registration->release_reserved_ticket(true, 'RegProcessor:'. __LINE__);
629
+        $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__);
630 630
         $registration->set_final_price(0);
631 631
         if ($update_reg) {
632 632
             $registration->save();
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
             return false;
659 659
         }
660 660
         $ticket = $registration->ticket();
661
-        if (! $ticket instanceof EE_Ticket) {
661
+        if ( ! $ticket instanceof EE_Ticket) {
662 662
             throw new EE_Error(
663 663
                 sprintf(
664 664
                     esc_html__(
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         $total_ticket_count = 1
709 709
     ) {
710 710
         EE_Error::doing_it_wrong(
711
-            __CLASS__ . '::' . __FUNCTION__,
711
+            __CLASS__.'::'.__FUNCTION__,
712 712
             sprintf(
713 713
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714 714
                 '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
         );
719 719
         // grab the related ticket object for this line_item
720 720
         $ticket = $line_item->ticket();
721
-        if (! $ticket instanceof EE_Ticket) {
721
+        if ( ! $ticket instanceof EE_Ticket) {
722 722
             EE_Error::add_error(
723 723
                 sprintf(
724 724
                     esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
     public function generate_reg_url_link($att_nmbr, $item)
758 758
     {
759 759
         EE_Error::doing_it_wrong(
760
-            __CLASS__ . '::' . __FUNCTION__,
760
+            __CLASS__.'::'.__FUNCTION__,
761 761
             sprintf(
762 762
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
763 763
                 'EventEspresso\core\domain\entities\RegUrlLink'
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
     public function generate_reg_code(EE_Registration $registration)
785 785
     {
786 786
         EE_Error::doing_it_wrong(
787
-            __CLASS__ . '::' . __FUNCTION__,
787
+            __CLASS__.'::'.__FUNCTION__,
788 788
             sprintf(
789 789
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
790 790
                 'EventEspresso\core\domain\entities\RegCode'
Please login to merge, or discard this patch.