Completed
Branch dev (3710f0)
by
unknown
25:03 queued 15:31
created
reg_steps/payment_options/EE_SPCO_Reg_Step_Payment_Options.class.php 2 patches
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         $this->request   = EED_Single_Page_Checkout::getRequest();
133 133
         $this->_slug     = 'payment_options';
134 134
         $this->_name     = esc_html__('Payment Options', 'event_espresso');
135
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php';
135
+        $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.'/payment_options_main.template.php';
136 136
         $this->checkout  = $checkout;
137 137
         $this->_reset_success_message();
138 138
         $this->set_instructions(
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public function translate_js_strings()
189 189
     {
190
-        EE_Registry::$i18n_js_strings['no_payment_method']      = esc_html__(
190
+        EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__(
191 191
             'Please select a method of payment in order to continue.',
192 192
             'event_espresso'
193 193
         );
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
             'A valid method of payment could not be determined. Please refresh the page and try again.',
196 196
             'event_espresso'
197 197
         );
198
-        EE_Registry::$i18n_js_strings['forwarding_to_offsite']  = esc_html__(
198
+        EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__(
199 199
             'Forwarding to Secure Payment Provider.',
200 200
             'event_espresso'
201 201
         );
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     {
217 217
         $transaction = $this->checkout->transaction;
218 218
         // if the transaction isn't set or nothing is owed on it, don't enqueue any JS
219
-        if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
219
+        if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
220 220
             return;
221 221
         }
222 222
         foreach (
@@ -311,18 +311,18 @@  discard block
 block discarded – undo
311 311
         foreach ($registrations as $REG_ID => $registration) {
312 312
             /** @var $registration EE_Registration */
313 313
             // has this registration lost it's space ?
314
-            if (isset($ejected_registrations[ $REG_ID ])) {
314
+            if (isset($ejected_registrations[$REG_ID])) {
315 315
                 if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) {
316
-                    $sold_out_events[ $registration->event()->ID() ] = $registration->event();
316
+                    $sold_out_events[$registration->event()->ID()] = $registration->event();
317 317
                 } else {
318
-                    $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
318
+                    $insufficient_spaces_available[$registration->event()->ID()] = $registration->event();
319 319
                 }
320 320
                 continue;
321 321
             }
322 322
             // event requires admin approval
323 323
             if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
324 324
                 // add event to list of events with pre-approval reg status
325
-                $registrations_requiring_pre_approval[ $REG_ID ] = $registration;
325
+                $registrations_requiring_pre_approval[$REG_ID] = $registration;
326 326
                 do_action(
327 327
                     'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
328 328
                     $registration->event(),
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
                 )
340 340
             ) {
341 341
                 // add event to list of events that are sold out
342
-                $sold_out_events[ $registration->event()->ID() ] = $registration->event();
342
+                $sold_out_events[$registration->event()->ID()] = $registration->event();
343 343
                 do_action(
344 344
                     'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
345 345
                     $registration->event(),
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
             }
350 350
             // are they allowed to pay now and is there monies owing?
351 351
             if ($registration->owes_monies_and_can_pay()) {
352
-                $registrations_requiring_payment[ $REG_ID ] = $registration;
352
+                $registrations_requiring_payment[$REG_ID] = $registration;
353 353
                 do_action(
354 354
                     'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
355 355
                     $registration->event(),
@@ -360,28 +360,28 @@  discard block
 block discarded – undo
360 360
                       && $registration->status_ID() !== EEM_Registration::status_id_not_approved
361 361
                       && $registration->ticket()->is_free()
362 362
             ) {
363
-                $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration;
363
+                $registrations_for_free_events[$registration->ticket()->ID()] = $registration;
364 364
             }
365 365
         }
366 366
         $subsections = [];
367 367
         // now decide which template to load
368
-        if (! empty($sold_out_events)) {
368
+        if ( ! empty($sold_out_events)) {
369 369
             $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
370 370
         }
371
-        if (! empty($insufficient_spaces_available)) {
371
+        if ( ! empty($insufficient_spaces_available)) {
372 372
             $subsections['insufficient_space'] = $this->_insufficient_spaces_available(
373 373
                 $insufficient_spaces_available
374 374
             );
375 375
         }
376
-        if (! empty($registrations_requiring_pre_approval)) {
376
+        if ( ! empty($registrations_requiring_pre_approval)) {
377 377
             $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
378 378
                 $registrations_requiring_pre_approval
379 379
             );
380 380
         }
381
-        if (! empty($registrations_for_free_events)) {
381
+        if ( ! empty($registrations_for_free_events)) {
382 382
             $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
383 383
         }
384
-        if (! empty($registrations_requiring_payment)) {
384
+        if ( ! empty($registrations_requiring_payment)) {
385 385
             if ($this->checkout->amount_owing > 0) {
386 386
                 // autoload Line_Item_Display classes
387 387
                 EEH_Autoloader::register_line_item_filter_autoloaders();
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
                         ['registrations' => $registrations]
403 403
                     )
404 404
                 );
405
-                $this->checkout->amount_owing   = $filtered_line_item_tree->total();
405
+                $this->checkout->amount_owing = $filtered_line_item_tree->total();
406 406
                 $this->_apply_registration_payments_to_amount_owing($registrations);
407 407
             }
408 408
             $no_payment_required = false;
@@ -446,13 +446,13 @@  discard block
 block discarded – undo
446 446
      */
447 447
     public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection)
448 448
     {
449
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
449
+        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
450 450
             return $line_item_filter_collection;
451 451
         }
452
-        if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
452
+        if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
453 453
             return $line_item_filter_collection;
454 454
         }
455
-        if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
455
+        if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
456 456
             return $line_item_filter_collection;
457 457
         }
458 458
         $line_item_filter_collection->add(
@@ -492,8 +492,8 @@  discard block
 block discarded – undo
492 492
         );
493 493
         foreach ($registrations as $REG_ID => $registration) {
494 494
             // has this registration lost it's space ?
495
-            if (isset($ejected_registrations[ $REG_ID ])) {
496
-                unset($registrations[ $REG_ID ]);
495
+            if (isset($ejected_registrations[$REG_ID])) {
496
+                unset($registrations[$REG_ID]);
497 497
             }
498 498
         }
499 499
         return $registrations;
@@ -543,25 +543,25 @@  discard block
 block discarded – undo
543 543
             }
544 544
             $EVT_ID = $registration->event_ID();
545 545
             $ticket = $registration->ticket();
546
-            if (! isset($tickets_remaining[ $ticket->ID() ])) {
547
-                $tickets_remaining[ $ticket->ID() ] = $ticket->remaining();
546
+            if ( ! isset($tickets_remaining[$ticket->ID()])) {
547
+                $tickets_remaining[$ticket->ID()] = $ticket->remaining();
548 548
             }
549
-            if ($tickets_remaining[ $ticket->ID() ] > 0) {
550
-                if (! isset($event_reg_count[ $EVT_ID ])) {
551
-                    $event_reg_count[ $EVT_ID ] = 0;
549
+            if ($tickets_remaining[$ticket->ID()] > 0) {
550
+                if ( ! isset($event_reg_count[$EVT_ID])) {
551
+                    $event_reg_count[$EVT_ID] = 0;
552 552
                 }
553
-                $event_reg_count[ $EVT_ID ]++;
554
-                if (! isset($event_spaces_remaining[ $EVT_ID ])) {
555
-                    $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale();
553
+                $event_reg_count[$EVT_ID]++;
554
+                if ( ! isset($event_spaces_remaining[$EVT_ID])) {
555
+                    $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale();
556 556
                 }
557 557
             }
558 558
             if (
559 559
                 $revisit
560
-                && ($tickets_remaining[ $ticket->ID() ] === 0
561
-                    || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
560
+                && ($tickets_remaining[$ticket->ID()] === 0
561
+                    || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID]
562 562
                 )
563 563
             ) {
564
-                $ejected_registrations[ $REG_ID ] = $registration->event();
564
+                $ejected_registrations[$REG_ID] = $registration->event();
565 565
                 if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
566 566
                     /** @type EE_Registration_Processor $registration_processor */
567 567
                     $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
         foreach ($sold_out_events_array as $sold_out_event) {
622 622
             $sold_out_events .= EEH_HTML::li(
623 623
                 EEH_HTML::span(
624
-                    '  ' . $sold_out_event->name(),
624
+                    '  '.$sold_out_event->name(),
625 625
                     '',
626 626
                     'dashicons dashicons-marker ee-icon-size-16 pink-text'
627 627
                 )
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
         foreach ($insufficient_spaces_events_array as $event) {
678 678
             if ($event instanceof EE_Event) {
679 679
                 $insufficient_space_events .= EEH_HTML::li(
680
-                    EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
680
+                    EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
681 681
                 );
682 682
             }
683 683
         }
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
         $events_requiring_pre_approval = [];
727 727
         foreach ($registrations_requiring_pre_approval as $registration) {
728 728
             if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
729
-                $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
729
+                $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li(
730 730
                     EEH_HTML::span(
731 731
                         '',
732 732
                         '',
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
     {
867 867
         return new EE_Form_Section_Proper(
868 868
             [
869
-                'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
869
+                'html_id'         => 'ee-'.$this->slug().'-extra-hidden-inputs',
870 870
                 'layout_strategy' => new EE_Div_Per_Section_Layout(),
871 871
                 'subsections'     => [
872 872
                     'spco_no_payment_required' => new EE_Hidden_Input(
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
                 $payments += $registration->registration_payments();
906 906
             }
907 907
         }
908
-        if (! empty($payments)) {
908
+        if ( ! empty($payments)) {
909 909
             foreach ($payments as $payment) {
910 910
                 if ($payment instanceof EE_Registration_Payment) {
911 911
                     $this->checkout->amount_owing -= $payment->amount();
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
             );
995 995
         }
996 996
         // switch up header depending on number of available payment methods
997
-        $payment_method_header     = count($this->checkout->available_payment_methods) > 1
997
+        $payment_method_header = count($this->checkout->available_payment_methods) > 1
998 998
             ? apply_filters(
999 999
                 'FHEE__registration_page_payment_options__method_of_payment_hdr',
1000 1000
                 esc_html__('Please Select Your Method of Payment', 'event_espresso')
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
                 $payment_method_button = EEH_HTML::img(
1029 1029
                     $payment_method->button_url(),
1030 1030
                     $payment_method->name(),
1031
-                    'spco-payment-method-' . $payment_method->slug() . '-btn-img',
1031
+                    'spco-payment-method-'.$payment_method->slug().'-btn-img',
1032 1032
                     'spco-payment-method-btn-img'
1033 1033
                 );
1034 1034
                 // check if any payment methods are set as default
@@ -1036,15 +1036,15 @@  discard block
 block discarded – undo
1036 1036
                 // open_by_default
1037 1037
                 if (
1038 1038
                     ($this->checkout->selected_method_of_payment === $payment_method->slug())
1039
-                    || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1039
+                    || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1040 1040
                 ) {
1041 1041
                     $this->checkout->selected_method_of_payment = $payment_method->slug();
1042 1042
                     $this->_save_selected_method_of_payment();
1043
-                    $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button;
1043
+                    $default_payment_method_option[$payment_method->slug()] = $payment_method_button;
1044 1044
                 } else {
1045
-                    $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
1045
+                    $available_payment_method_options[$payment_method->slug()] = $payment_method_button;
1046 1046
                 }
1047
-                $payment_methods_billing_info[ $payment_method->slug() . '-info' ] =
1047
+                $payment_methods_billing_info[$payment_method->slug().'-info'] =
1048 1048
                     $this->_payment_method_billing_info(
1049 1049
                         $payment_method
1050 1050
                     );
@@ -1057,7 +1057,7 @@  discard block
 block discarded – undo
1057 1057
         $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs(
1058 1058
             $available_payment_method_options
1059 1059
         );
1060
-        $available_payment_methods                              += $payment_methods_billing_info;
1060
+        $available_payment_methods += $payment_methods_billing_info;
1061 1061
         // build the available payment methods form
1062 1062
         return new EE_Form_Section_Proper(
1063 1063
             [
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
      */
1081 1081
     protected function _get_available_payment_methods()
1082 1082
     {
1083
-        if (! empty($this->checkout->available_payment_methods)) {
1083
+        if ( ! empty($this->checkout->available_payment_methods)) {
1084 1084
             return $this->checkout->available_payment_methods;
1085 1085
         }
1086 1086
         $available_payment_methods = [];
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
         );
1093 1093
         foreach ($payment_methods as $payment_method) {
1094 1094
             if ($payment_method instanceof EE_Payment_Method) {
1095
-                $available_payment_methods[ $payment_method->slug() ] = $payment_method;
1095
+                $available_payment_methods[$payment_method->slug()] = $payment_method;
1096 1096
             }
1097 1097
         }
1098 1098
         return $available_payment_methods;
@@ -1187,7 +1187,7 @@  discard block
 block discarded – undo
1187 1187
         );
1188 1188
         return new EE_Form_Section_Proper(
1189 1189
             [
1190
-                'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1190
+                'html_id'         => 'spco-payment-method-info-'.$payment_method->slug(),
1191 1191
                 'html_class'      => 'spco-payment-method-info-dv',
1192 1192
                 // only display the selected or default PM
1193 1193
                 'html_style'      => $currently_selected ? '' : 'display:none;',
@@ -1216,7 +1216,7 @@  discard block
 block discarded – undo
1216 1216
         // how have they chosen to pay?
1217 1217
         $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1218 1218
         $this->checkout->payment_method             = $this->_get_payment_method_for_selected_method_of_payment();
1219
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1219
+        if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
1220 1220
             return false;
1221 1221
         }
1222 1222
         if (
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
      */
1392 1392
     public function switch_payment_method()
1393 1393
     {
1394
-        if (! $this->_verify_payment_method_is_set()) {
1394
+        if ( ! $this->_verify_payment_method_is_set()) {
1395 1395
             return false;
1396 1396
         }
1397 1397
         if (
@@ -1527,7 +1527,7 @@  discard block
 block discarded – undo
1527 1527
             }
1528 1528
         }
1529 1529
         // verify payment method
1530
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1530
+        if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
1531 1531
             // get payment method for selected method of payment
1532 1532
             $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1533 1533
         }
@@ -1552,7 +1552,7 @@  discard block
 block discarded – undo
1552 1552
      */
1553 1553
     public function save_payer_details_via_ajax()
1554 1554
     {
1555
-        if (! $this->_verify_payment_method_is_set()) {
1555
+        if ( ! $this->_verify_payment_method_is_set()) {
1556 1556
             return;
1557 1557
         }
1558 1558
         // generate billing form for selected method of payment if it hasn't been done already
@@ -1562,7 +1562,7 @@  discard block
 block discarded – undo
1562 1562
             );
1563 1563
         }
1564 1564
         // generate primary attendee from payer info if applicable
1565
-        if (! $this->checkout->transaction_has_primary_registrant()) {
1565
+        if ( ! $this->checkout->transaction_has_primary_registrant()) {
1566 1566
             $attendee = $this->_create_attendee_from_request_data();
1567 1567
             if ($attendee instanceof EE_Attendee) {
1568 1568
                 foreach ($this->checkout->transaction->registrations() as $registration) {
@@ -1593,7 +1593,7 @@  discard block
 block discarded – undo
1593 1593
     {
1594 1594
         // get State ID
1595 1595
         $STA_ID = $this->request->getRequestParam('state');
1596
-        if (! empty($STA_ID)) {
1596
+        if ( ! empty($STA_ID)) {
1597 1597
             // can we get state object from name ?
1598 1598
             EE_Registry::instance()->load_model('State');
1599 1599
             $state  = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID');
@@ -1601,7 +1601,7 @@  discard block
 block discarded – undo
1601 1601
         }
1602 1602
         // get Country ISO
1603 1603
         $CNT_ISO = $this->request->getRequestParam('country');
1604
-        if (! empty($CNT_ISO)) {
1604
+        if ( ! empty($CNT_ISO)) {
1605 1605
             // can we get country object from name ?
1606 1606
             EE_Registry::instance()->load_model('Country');
1607 1607
             $country = EEM_Country::instance()->get_col(
@@ -1782,7 +1782,7 @@  discard block
 block discarded – undo
1782 1782
     protected function _maybe_set_completed(EE_Payment $payment)
1783 1783
     {
1784 1784
         // Do we need to redirect them? If so, there's more work to be done.
1785
-        if (! $payment->redirect_url()) {
1785
+        if ( ! $payment->redirect_url()) {
1786 1786
             $this->set_completed();
1787 1787
         }
1788 1788
     }
@@ -1839,7 +1839,7 @@  discard block
 block discarded – undo
1839 1839
     private function _process_payment()
1840 1840
     {
1841 1841
         // basically confirm that the event hasn't sold out since they hit the page
1842
-        if (! $this->_last_second_ticket_verifications()) {
1842
+        if ( ! $this->_last_second_ticket_verifications()) {
1843 1843
             return null;
1844 1844
         }
1845 1845
         // ya gotta make a choice man
@@ -1850,7 +1850,7 @@  discard block
 block discarded – undo
1850 1850
             return null;
1851 1851
         }
1852 1852
         // get EE_Payment_Method object
1853
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1853
+        if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1854 1854
             return null;
1855 1855
         }
1856 1856
         // setup billing form
@@ -1859,12 +1859,12 @@  discard block
 block discarded – undo
1859 1859
                 $this->checkout->payment_method
1860 1860
             );
1861 1861
             // bad billing form ?
1862
-            if (! $this->_billing_form_is_valid()) {
1862
+            if ( ! $this->_billing_form_is_valid()) {
1863 1863
                 return null;
1864 1864
             }
1865 1865
         }
1866 1866
         // ensure primary registrant has been fully processed
1867
-        if (! $this->_setup_primary_registrant_prior_to_payment()) {
1867
+        if ( ! $this->_setup_primary_registrant_prior_to_payment()) {
1868 1868
             return null;
1869 1869
         }
1870 1870
         // if session is close to expiring (under 10 minutes by default)
@@ -1920,7 +1920,7 @@  discard block
 block discarded – undo
1920 1920
     protected function _last_second_ticket_verifications()
1921 1921
     {
1922 1922
         // don't bother re-validating if not a return visit
1923
-        if (! $this->checkout->revisit) {
1923
+        if ( ! $this->checkout->revisit) {
1924 1924
             return true;
1925 1925
         }
1926 1926
         $registrations = $this->checkout->transaction->registrations();
@@ -1970,7 +1970,7 @@  discard block
 block discarded – undo
1970 1970
             $this->_get_payment_method_for_selected_method_of_payment()
1971 1971
         );
1972 1972
         $html                        = $payment_method_billing_info->get_html();
1973
-        $html                        .= $this->checkout->redirect_form;
1973
+        $html .= $this->checkout->redirect_form;
1974 1974
         /** @var ResponseInterface $response */
1975 1975
         $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
1976 1976
         $response->addOutput($html);
@@ -1986,7 +1986,7 @@  discard block
 block discarded – undo
1986 1986
      */
1987 1987
     private function _billing_form_is_valid()
1988 1988
     {
1989
-        if (! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1989
+        if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1990 1990
             return true;
1991 1991
         }
1992 1992
         if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
@@ -2104,7 +2104,7 @@  discard block
 block discarded – undo
2104 2104
     {
2105 2105
         // convert billing form data into an attendee
2106 2106
         $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
2107
-        if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2107
+        if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2108 2108
             EE_Error::add_error(
2109 2109
                 sprintf(
2110 2110
                     esc_html__(
@@ -2121,7 +2121,7 @@  discard block
 block discarded – undo
2121 2121
             return false;
2122 2122
         }
2123 2123
         $primary_registration = $this->checkout->transaction->primary_registration();
2124
-        if (! $primary_registration instanceof EE_Registration) {
2124
+        if ( ! $primary_registration instanceof EE_Registration) {
2125 2125
             EE_Error::add_error(
2126 2126
                 sprintf(
2127 2127
                     esc_html__(
@@ -2183,8 +2183,8 @@  discard block
 block discarded – undo
2183 2183
             return null;
2184 2184
         }
2185 2185
         // get EE_Payment_Method object
2186
-        if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) {
2187
-            $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
2186
+        if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) {
2187
+            $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment];
2188 2188
         } else {
2189 2189
             // load EEM_Payment_Method
2190 2190
             EE_Registry::instance()->load_model('Payment_Method');
@@ -2192,7 +2192,7 @@  discard block
 block discarded – undo
2192 2192
             $payment_method     = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2193 2193
         }
2194 2194
         // verify $payment_method
2195
-        if (! $payment_method instanceof EE_Payment_Method) {
2195
+        if ( ! $payment_method instanceof EE_Payment_Method) {
2196 2196
             // not a payment
2197 2197
             EE_Error::add_error(
2198 2198
                 sprintf(
@@ -2210,7 +2210,7 @@  discard block
 block discarded – undo
2210 2210
             return null;
2211 2211
         }
2212 2212
         // and verify it has a valid Payment_Method Type object
2213
-        if (! $payment_method->type_obj() instanceof EE_PMT_Base) {
2213
+        if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) {
2214 2214
             // not a payment
2215 2215
             EE_Error::add_error(
2216 2216
                 sprintf(
@@ -2248,7 +2248,7 @@  discard block
 block discarded – undo
2248 2248
         $payment = null;
2249 2249
         $this->checkout->transaction->save();
2250 2250
         $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2251
-        if (! $payment_processor instanceof EE_Payment_Processor) {
2251
+        if ( ! $payment_processor instanceof EE_Payment_Processor) {
2252 2252
             return false;
2253 2253
         }
2254 2254
         try {
@@ -2350,7 +2350,7 @@  discard block
 block discarded – undo
2350 2350
             return true;
2351 2351
         }
2352 2352
         // verify payment object
2353
-        if (! $payment instanceof EE_Payment) {
2353
+        if ( ! $payment instanceof EE_Payment) {
2354 2354
             // not a payment
2355 2355
             EE_Error::add_error(
2356 2356
                 sprintf(
@@ -2400,7 +2400,7 @@  discard block
 block discarded – undo
2400 2400
                 // and lastly, let's bump the payment status to pending
2401 2401
                 $payment->set_status(EEM_Payment::status_id_pending);
2402 2402
                 $payment->save();
2403
-            } elseif (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2403
+            } elseif ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2404 2404
                 // User shouldn't be redirected. So let's process it here.
2405 2405
                 // $this->_setup_redirect_for_next_step();
2406 2406
                 $this->checkout->continue_reg = false;
@@ -2481,7 +2481,7 @@  discard block
 block discarded – undo
2481 2481
                     return false;
2482 2482
                 // bad payment
2483 2483
                 case EEM_Payment::status_id_failed:
2484
-                    if (! empty($msg)) {
2484
+                    if ( ! empty($msg)) {
2485 2485
                         EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2486 2486
                         return false;
2487 2487
                     }
@@ -2539,18 +2539,18 @@  discard block
 block discarded – undo
2539 2539
         // how have they chosen to pay?
2540 2540
         $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2541 2541
         // get EE_Payment_Method object
2542
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2542
+        if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2543 2543
             $this->checkout->continue_reg = false;
2544 2544
             return false;
2545 2545
         }
2546
-        if (! $this->checkout->payment_method->is_off_site()) {
2546
+        if ( ! $this->checkout->payment_method->is_off_site()) {
2547 2547
             return false;
2548 2548
         }
2549 2549
         $this->_validate_offsite_return();
2550 2550
         // verify TXN
2551 2551
         if ($this->checkout->transaction instanceof EE_Transaction) {
2552 2552
             $gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2553
-            if (! $gateway instanceof EE_Offsite_Gateway) {
2553
+            if ( ! $gateway instanceof EE_Offsite_Gateway) {
2554 2554
                 $this->checkout->continue_reg = false;
2555 2555
                 return false;
2556 2556
             }
@@ -2564,7 +2564,7 @@  discard block
 block discarded – undo
2564 2564
                 $this->checkout->payment = $payment;
2565 2565
                 // mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2566 2566
                 // because we will complete this step during the IPN processing then
2567
-                if (! $this->handle_IPN_in_this_request()) {
2567
+                if ( ! $this->handle_IPN_in_this_request()) {
2568 2568
                     $this->set_completed();
2569 2569
                 }
2570 2570
                 return true;
@@ -2667,13 +2667,13 @@  discard block
 block discarded – undo
2667 2667
      */
2668 2668
     private function _redirect_wayward_request(EE_Registration $primary_registrant)
2669 2669
     {
2670
-        if (! $primary_registrant instanceof EE_Registration) {
2670
+        if ( ! $primary_registrant instanceof EE_Registration) {
2671 2671
             // try redirecting based on the current TXN
2672 2672
             $primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2673 2673
                 ? $this->checkout->transaction->primary_registration()
2674 2674
                 : null;
2675 2675
         }
2676
-        if (! $primary_registrant instanceof EE_Registration) {
2676
+        if ( ! $primary_registrant instanceof EE_Registration) {
2677 2677
             EE_Error::add_error(
2678 2678
                 sprintf(
2679 2679
                     esc_html__(
@@ -2744,7 +2744,7 @@  discard block
 block discarded – undo
2744 2744
             $payment = $this->checkout->transaction->last_payment();
2745 2745
             // $payment_source = 'last_payment after Exception';
2746 2746
             // but if we STILL don't have a payment object
2747
-            if (! $payment instanceof EE_Payment) {
2747
+            if ( ! $payment instanceof EE_Payment) {
2748 2748
                 // then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2749 2749
                 $this->_handle_payment_processor_exception($e);
2750 2750
             }
Please login to merge, or discard this patch.
Indentation   +2830 added lines, -2830 removed lines patch added patch discarded remove patch
@@ -19,2834 +19,2834 @@
 block discarded – undo
19 19
  */
20 20
 class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step
21 21
 {
22
-    /**
23
-     * @var EE_Line_Item_Display $Line_Item_Display
24
-     */
25
-    protected $line_item_display;
26
-
27
-    /**
28
-     * @var boolean $handle_IPN_in_this_request
29
-     */
30
-    protected $handle_IPN_in_this_request = false;
31
-
32
-
33
-    /**
34
-     *    set_hooks - for hooking into EE Core, other modules, etc
35
-     *
36
-     * @access    public
37
-     * @return    void
38
-     */
39
-    public static function set_hooks()
40
-    {
41
-        add_filter(
42
-            'FHEE__SPCO__EE_Line_Item_Filter_Collection',
43
-            ['EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters']
44
-        );
45
-        add_action(
46
-            'wp_ajax_switch_spco_billing_form',
47
-            ['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form']
48
-        );
49
-        add_action(
50
-            'wp_ajax_nopriv_switch_spco_billing_form',
51
-            ['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form']
52
-        );
53
-        add_action('wp_ajax_save_payer_details', ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']);
54
-        add_action(
55
-            'wp_ajax_nopriv_save_payer_details',
56
-            ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']
57
-        );
58
-        add_action(
59
-            'wp_ajax_get_transaction_details_for_gateways',
60
-            ['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details']
61
-        );
62
-        add_action(
63
-            'wp_ajax_nopriv_get_transaction_details_for_gateways',
64
-            ['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details']
65
-        );
66
-        add_filter(
67
-            'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
68
-            ['EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'],
69
-            10,
70
-            1
71
-        );
72
-    }
73
-
74
-
75
-    /**
76
-     *    ajax switch_spco_billing_form
77
-     *
78
-     */
79
-    public static function switch_spco_billing_form()
80
-    {
81
-        EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
82
-    }
83
-
84
-
85
-    /**
86
-     *    ajax save_payer_details
87
-     *
88
-     */
89
-    public static function save_payer_details()
90
-    {
91
-        EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
92
-    }
93
-
94
-
95
-    /**
96
-     *    ajax get_transaction_details
97
-     *
98
-     */
99
-    public static function get_transaction_details()
100
-    {
101
-        EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
102
-    }
103
-
104
-
105
-    /**
106
-     * bypass_recaptcha_for_load_payment_method
107
-     *
108
-     * @access public
109
-     * @return array
110
-     * @throws InvalidArgumentException
111
-     * @throws InvalidDataTypeException
112
-     * @throws InvalidInterfaceException
113
-     */
114
-    public static function bypass_recaptcha_for_load_payment_method()
115
-    {
116
-        return [
117
-            'EESID'  => EE_Registry::instance()->SSN->id(),
118
-            'step'   => 'payment_options',
119
-            'action' => 'spco_billing_form',
120
-        ];
121
-    }
122
-
123
-
124
-    /**
125
-     *    class constructor
126
-     *
127
-     * @access    public
128
-     * @param EE_Checkout $checkout
129
-     */
130
-    public function __construct(EE_Checkout $checkout)
131
-    {
132
-        $this->request   = EED_Single_Page_Checkout::getRequest();
133
-        $this->_slug     = 'payment_options';
134
-        $this->_name     = esc_html__('Payment Options', 'event_espresso');
135
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php';
136
-        $this->checkout  = $checkout;
137
-        $this->_reset_success_message();
138
-        $this->set_instructions(
139
-            esc_html__(
140
-                'Please select a method of payment and provide any necessary billing information before proceeding.',
141
-                'event_espresso'
142
-            )
143
-        );
144
-    }
145
-
146
-
147
-    /**
148
-     * @return null
149
-     */
150
-    public function line_item_display()
151
-    {
152
-        return $this->line_item_display;
153
-    }
154
-
155
-
156
-    /**
157
-     * @param null $line_item_display
158
-     */
159
-    public function set_line_item_display($line_item_display)
160
-    {
161
-        $this->line_item_display = $line_item_display;
162
-    }
163
-
164
-
165
-    /**
166
-     * @return boolean
167
-     */
168
-    public function handle_IPN_in_this_request()
169
-    {
170
-        return $this->handle_IPN_in_this_request;
171
-    }
172
-
173
-
174
-    /**
175
-     * @param boolean $handle_IPN_in_this_request
176
-     */
177
-    public function set_handle_IPN_in_this_request($handle_IPN_in_this_request)
178
-    {
179
-        $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
180
-    }
181
-
182
-
183
-    /**
184
-     * translate_js_strings
185
-     *
186
-     * @return void
187
-     */
188
-    public function translate_js_strings()
189
-    {
190
-        EE_Registry::$i18n_js_strings['no_payment_method']      = esc_html__(
191
-            'Please select a method of payment in order to continue.',
192
-            'event_espresso'
193
-        );
194
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
195
-            'A valid method of payment could not be determined. Please refresh the page and try again.',
196
-            'event_espresso'
197
-        );
198
-        EE_Registry::$i18n_js_strings['forwarding_to_offsite']  = esc_html__(
199
-            'Forwarding to Secure Payment Provider.',
200
-            'event_espresso'
201
-        );
202
-    }
203
-
204
-
205
-    /**
206
-     * enqueue_styles_and_scripts
207
-     *
208
-     * @return void
209
-     * @throws EE_Error
210
-     * @throws InvalidArgumentException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidInterfaceException
213
-     * @throws ReflectionException
214
-     */
215
-    public function enqueue_styles_and_scripts()
216
-    {
217
-        $transaction = $this->checkout->transaction;
218
-        // if the transaction isn't set or nothing is owed on it, don't enqueue any JS
219
-        if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
220
-            return;
221
-        }
222
-        foreach (
223
-            EEM_Payment_Method::instance()->get_all_for_transaction(
224
-                $transaction,
225
-                EEM_Payment_Method::scope_cart
226
-            ) as $payment_method
227
-        ) {
228
-            $type_obj = $payment_method->type_obj();
229
-            if ($type_obj instanceof EE_PMT_Base) {
230
-                $billing_form = $type_obj->generate_new_billing_form($transaction);
231
-                if ($billing_form instanceof EE_Form_Section_Proper) {
232
-                    $billing_form->enqueue_js();
233
-                }
234
-            }
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * initialize_reg_step
241
-     *
242
-     * @return bool
243
-     * @throws EE_Error
244
-     * @throws InvalidArgumentException
245
-     * @throws ReflectionException
246
-     * @throws InvalidDataTypeException
247
-     * @throws InvalidInterfaceException
248
-     */
249
-    public function initialize_reg_step()
250
-    {
251
-        // TODO: if /when we implement donations, then this will need overriding
252
-        if (
253
-            // don't need payment options for:
254
-            // registrations made via the admin
255
-            // completed transactions
256
-            // overpaid transactions
257
-            // $ 0.00 transactions(no payment required)
258
-            ! $this->checkout->payment_required()
259
-            // but do NOT remove if current action being called belongs to this reg step
260
-            && ! is_callable([$this, $this->checkout->action])
261
-            && ! $this->completed()
262
-        ) {
263
-            // and if so, then we no longer need the Payment Options step
264
-            if ($this->is_current_step()) {
265
-                $this->checkout->generate_reg_form = false;
266
-            }
267
-            $this->checkout->remove_reg_step($this->_slug);
268
-            // DEBUG LOG
269
-            // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
270
-            return false;
271
-        }
272
-        // load EEM_Payment_Method
273
-        EE_Registry::instance()->load_model('Payment_Method');
274
-        // get all active payment methods
275
-        $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
276
-            $this->checkout->transaction,
277
-            EEM_Payment_Method::scope_cart
278
-        );
279
-        return true;
280
-    }
281
-
282
-
283
-    /**
284
-     * @return EE_Form_Section_Proper
285
-     * @throws EE_Error
286
-     * @throws InvalidArgumentException
287
-     * @throws ReflectionException
288
-     * @throws EntityNotFoundException
289
-     * @throws InvalidDataTypeException
290
-     * @throws InvalidInterfaceException
291
-     * @throws InvalidStatusException
292
-     */
293
-    public function generate_reg_form()
294
-    {
295
-        // reset in case someone changes their mind
296
-        $this->_reset_selected_method_of_payment();
297
-        // set some defaults
298
-        $this->checkout->selected_method_of_payment = 'payments_closed';
299
-        $registrations_requiring_payment            = [];
300
-        $registrations_for_free_events              = [];
301
-        $registrations_requiring_pre_approval       = [];
302
-        $sold_out_events                            = [];
303
-        $insufficient_spaces_available              = [];
304
-        $no_payment_required                        = true;
305
-        // loop thru registrations to gather info
306
-        $registrations         = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
307
-        $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
308
-            $registrations,
309
-            $this->checkout->revisit
310
-        );
311
-        foreach ($registrations as $REG_ID => $registration) {
312
-            /** @var $registration EE_Registration */
313
-            // has this registration lost it's space ?
314
-            if (isset($ejected_registrations[ $REG_ID ])) {
315
-                if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) {
316
-                    $sold_out_events[ $registration->event()->ID() ] = $registration->event();
317
-                } else {
318
-                    $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
319
-                }
320
-                continue;
321
-            }
322
-            // event requires admin approval
323
-            if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
324
-                // add event to list of events with pre-approval reg status
325
-                $registrations_requiring_pre_approval[ $REG_ID ] = $registration;
326
-                do_action(
327
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
328
-                    $registration->event(),
329
-                    $this
330
-                );
331
-                continue;
332
-            }
333
-            if (
334
-                $this->checkout->revisit
335
-                && $registration->status_ID() !== EEM_Registration::status_id_approved
336
-                && (
337
-                    $registration->event()->is_sold_out()
338
-                    || $registration->event()->is_sold_out(true)
339
-                )
340
-            ) {
341
-                // add event to list of events that are sold out
342
-                $sold_out_events[ $registration->event()->ID() ] = $registration->event();
343
-                do_action(
344
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
345
-                    $registration->event(),
346
-                    $this
347
-                );
348
-                continue;
349
-            }
350
-            // are they allowed to pay now and is there monies owing?
351
-            if ($registration->owes_monies_and_can_pay()) {
352
-                $registrations_requiring_payment[ $REG_ID ] = $registration;
353
-                do_action(
354
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
355
-                    $registration->event(),
356
-                    $this
357
-                );
358
-            } elseif (
359
-                ! $this->checkout->revisit
360
-                      && $registration->status_ID() !== EEM_Registration::status_id_not_approved
361
-                      && $registration->ticket()->is_free()
362
-            ) {
363
-                $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration;
364
-            }
365
-        }
366
-        $subsections = [];
367
-        // now decide which template to load
368
-        if (! empty($sold_out_events)) {
369
-            $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
370
-        }
371
-        if (! empty($insufficient_spaces_available)) {
372
-            $subsections['insufficient_space'] = $this->_insufficient_spaces_available(
373
-                $insufficient_spaces_available
374
-            );
375
-        }
376
-        if (! empty($registrations_requiring_pre_approval)) {
377
-            $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
378
-                $registrations_requiring_pre_approval
379
-            );
380
-        }
381
-        if (! empty($registrations_for_free_events)) {
382
-            $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
383
-        }
384
-        if (! empty($registrations_requiring_payment)) {
385
-            if ($this->checkout->amount_owing > 0) {
386
-                // autoload Line_Item_Display classes
387
-                EEH_Autoloader::register_line_item_filter_autoloaders();
388
-                $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
389
-                    apply_filters(
390
-                        'FHEE__SPCO__EE_Line_Item_Filter_Collection',
391
-                        new EE_Line_Item_Filter_Collection()
392
-                    ),
393
-                    $this->checkout->cart->get_grand_total()
394
-                );
395
-                /** @var EE_Line_Item $filtered_line_item_tree */
396
-                $filtered_line_item_tree = $line_item_filter_processor->process();
397
-                EEH_Autoloader::register_line_item_display_autoloaders();
398
-                $this->set_line_item_display(new EE_Line_Item_Display('spco'));
399
-                $subsections['payment_options'] = $this->_display_payment_options(
400
-                    $this->line_item_display->display_line_item(
401
-                        $filtered_line_item_tree,
402
-                        ['registrations' => $registrations]
403
-                    )
404
-                );
405
-                $this->checkout->amount_owing   = $filtered_line_item_tree->total();
406
-                $this->_apply_registration_payments_to_amount_owing($registrations);
407
-            }
408
-            $no_payment_required = false;
409
-        } else {
410
-            $this->_hide_reg_step_submit_button_if_revisit();
411
-        }
412
-        $this->_save_selected_method_of_payment();
413
-
414
-        $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
415
-        $subsections['extra_hidden_inputs']   = $this->_extra_hidden_inputs($no_payment_required);
416
-
417
-        return new EE_Form_Section_Proper(
418
-            [
419
-                'name'            => $this->reg_form_name(),
420
-                'html_id'         => $this->reg_form_name(),
421
-                'subsections'     => $subsections,
422
-                'layout_strategy' => new EE_No_Layout(),
423
-            ]
424
-        );
425
-    }
426
-
427
-
428
-    /**
429
-     * add line item filters required for this reg step
430
-     * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks():
431
-     *        add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options',
432
-     *        'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the
433
-     *        payment options reg step, can apply these filters via the following: apply_filters(
434
-     *        'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing
435
-     *        filter collection by passing that instead of instantiating a new collection
436
-     *
437
-     * @param EE_Line_Item_Filter_Collection $line_item_filter_collection
438
-     * @return EE_Line_Item_Filter_Collection
439
-     * @throws EE_Error
440
-     * @throws InvalidArgumentException
441
-     * @throws ReflectionException
442
-     * @throws EntityNotFoundException
443
-     * @throws InvalidDataTypeException
444
-     * @throws InvalidInterfaceException
445
-     * @throws InvalidStatusException
446
-     */
447
-    public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection)
448
-    {
449
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
450
-            return $line_item_filter_collection;
451
-        }
452
-        if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
453
-            return $line_item_filter_collection;
454
-        }
455
-        if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
456
-            return $line_item_filter_collection;
457
-        }
458
-        $line_item_filter_collection->add(
459
-            new EE_Billable_Line_Item_Filter(
460
-                EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations(
461
-                    EE_Registry::instance()->SSN->checkout()->transaction->registrations(
462
-                        EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
463
-                    )
464
-                )
465
-            )
466
-        );
467
-        $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
468
-        return $line_item_filter_collection;
469
-    }
470
-
471
-
472
-    /**
473
-     * remove_ejected_registrations
474
-     * if a registrant has lost their potential space at an event due to lack of payment,
475
-     * then this method removes them from the list of registrations being paid for during this request
476
-     *
477
-     * @param EE_Registration[] $registrations
478
-     * @return EE_Registration[]
479
-     * @throws EE_Error
480
-     * @throws InvalidArgumentException
481
-     * @throws ReflectionException
482
-     * @throws EntityNotFoundException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     * @throws InvalidStatusException
486
-     */
487
-    public static function remove_ejected_registrations(array $registrations)
488
-    {
489
-        $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
490
-            $registrations,
491
-            EE_Registry::instance()->SSN->checkout()->revisit
492
-        );
493
-        foreach ($registrations as $REG_ID => $registration) {
494
-            // has this registration lost it's space ?
495
-            if (isset($ejected_registrations[ $REG_ID ])) {
496
-                unset($registrations[ $REG_ID ]);
497
-            }
498
-        }
499
-        return $registrations;
500
-    }
501
-
502
-
503
-    /**
504
-     * find_registrations_that_lost_their_space
505
-     * If a registrant chooses an offline payment method like Invoice,
506
-     * then no space is reserved for them at the event until they fully pay fo that site
507
-     * (unless the event's default reg status is set to APPROVED)
508
-     * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales,
509
-     * then this method will determine which registrations have lost the ability to complete the reg process.
510
-     *
511
-     * @param EE_Registration[] $registrations
512
-     * @param bool              $revisit
513
-     * @return array
514
-     * @throws EE_Error
515
-     * @throws InvalidArgumentException
516
-     * @throws ReflectionException
517
-     * @throws EntityNotFoundException
518
-     * @throws InvalidDataTypeException
519
-     * @throws InvalidInterfaceException
520
-     * @throws InvalidStatusException
521
-     */
522
-    public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false)
523
-    {
524
-        // registrations per event
525
-        $event_reg_count = [];
526
-        // spaces left per event
527
-        $event_spaces_remaining = [];
528
-        // tickets left sorted by ID
529
-        $tickets_remaining = [];
530
-        // registrations that have lost their space
531
-        $ejected_registrations = [];
532
-        foreach ($registrations as $REG_ID => $registration) {
533
-            if (
534
-                $registration->status_ID() === EEM_Registration::status_id_approved
535
-                || apply_filters(
536
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
537
-                    false,
538
-                    $registration,
539
-                    $revisit
540
-                )
541
-            ) {
542
-                continue;
543
-            }
544
-            $EVT_ID = $registration->event_ID();
545
-            $ticket = $registration->ticket();
546
-            if (! isset($tickets_remaining[ $ticket->ID() ])) {
547
-                $tickets_remaining[ $ticket->ID() ] = $ticket->remaining();
548
-            }
549
-            if ($tickets_remaining[ $ticket->ID() ] > 0) {
550
-                if (! isset($event_reg_count[ $EVT_ID ])) {
551
-                    $event_reg_count[ $EVT_ID ] = 0;
552
-                }
553
-                $event_reg_count[ $EVT_ID ]++;
554
-                if (! isset($event_spaces_remaining[ $EVT_ID ])) {
555
-                    $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale();
556
-                }
557
-            }
558
-            if (
559
-                $revisit
560
-                && ($tickets_remaining[ $ticket->ID() ] === 0
561
-                    || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
562
-                )
563
-            ) {
564
-                $ejected_registrations[ $REG_ID ] = $registration->event();
565
-                if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
566
-                    /** @type EE_Registration_Processor $registration_processor */
567
-                    $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
568
-                    // at this point, we should have enough details about the registrant to consider the registration
569
-                    // NOT incomplete
570
-                    $registration_processor->manually_update_registration_status(
571
-                        $registration,
572
-                        EEM_Registration::status_id_wait_list
573
-                    );
574
-                }
575
-            }
576
-        }
577
-        return $ejected_registrations;
578
-    }
579
-
580
-
581
-    /**
582
-     * _hide_reg_step_submit_button
583
-     * removes the html for the reg step submit button
584
-     * by replacing it with an empty string via filter callback
585
-     *
586
-     * @return void
587
-     */
588
-    protected function _adjust_registration_status_if_event_old_sold()
589
-    {
590
-    }
591
-
592
-
593
-    /**
594
-     * _hide_reg_step_submit_button
595
-     * removes the html for the reg step submit button
596
-     * by replacing it with an empty string via filter callback
597
-     *
598
-     * @return void
599
-     */
600
-    protected function _hide_reg_step_submit_button_if_revisit()
601
-    {
602
-        if ($this->checkout->revisit) {
603
-            add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
604
-        }
605
-    }
606
-
607
-
608
-    /**
609
-     * sold_out_events
610
-     * displays notices regarding events that have sold out since hte registrant first signed up
611
-     *
612
-     * @param EE_Event[] $sold_out_events_array
613
-     * @return EE_Form_Section_Proper
614
-     * @throws EE_Error
615
-     */
616
-    private function _sold_out_events($sold_out_events_array = [])
617
-    {
618
-        // set some defaults
619
-        $this->checkout->selected_method_of_payment = 'events_sold_out';
620
-        $sold_out_events                            = '';
621
-        foreach ($sold_out_events_array as $sold_out_event) {
622
-            $sold_out_events .= EEH_HTML::li(
623
-                EEH_HTML::span(
624
-                    '  ' . $sold_out_event->name(),
625
-                    '',
626
-                    'dashicons dashicons-marker ee-icon-size-16 pink-text'
627
-                )
628
-            );
629
-        }
630
-        return new EE_Form_Section_Proper(
631
-            [
632
-                'layout_strategy' => new EE_Template_Layout(
633
-                    [
634
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
635
-                                                  . $this->_slug
636
-                                                  . '/sold_out_events.template.php',
637
-                        'template_args'        => apply_filters(
638
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
639
-                            [
640
-                                'sold_out_events'     => $sold_out_events,
641
-                                'sold_out_events_msg' => apply_filters(
642
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
643
-                                    sprintf(
644
-                                        esc_html__(
645
-                                            'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s',
646
-                                            'event_espresso'
647
-                                        ),
648
-                                        '<strong>',
649
-                                        '</strong>',
650
-                                        '<br />'
651
-                                    )
652
-                                ),
653
-                            ]
654
-                        ),
655
-                    ]
656
-                ),
657
-            ]
658
-        );
659
-    }
660
-
661
-
662
-    /**
663
-     * _insufficient_spaces_available
664
-     * displays notices regarding events that do not have enough remaining spaces
665
-     * to satisfy the current number of registrations looking to pay
666
-     *
667
-     * @param EE_Event[] $insufficient_spaces_events_array
668
-     * @return EE_Form_Section_Proper
669
-     * @throws EE_Error
670
-     * @throws ReflectionException
671
-     */
672
-    private function _insufficient_spaces_available($insufficient_spaces_events_array = [])
673
-    {
674
-        // set some defaults
675
-        $this->checkout->selected_method_of_payment = 'invoice';
676
-        $insufficient_space_events                  = '';
677
-        foreach ($insufficient_spaces_events_array as $event) {
678
-            if ($event instanceof EE_Event) {
679
-                $insufficient_space_events .= EEH_HTML::li(
680
-                    EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
681
-                );
682
-            }
683
-        }
684
-        return new EE_Form_Section_Proper(
685
-            [
686
-                'subsections'     => [
687
-                    'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
688
-                    'extra_hidden_inputs'   => $this->_extra_hidden_inputs(),
689
-                ],
690
-                'layout_strategy' => new EE_Template_Layout(
691
-                    [
692
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
693
-                                                  . $this->_slug
694
-                                                  . '/sold_out_events.template.php',
695
-                        'template_args'        => apply_filters(
696
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args',
697
-                            [
698
-                                'sold_out_events'     => $insufficient_space_events,
699
-                                'sold_out_events_msg' => apply_filters(
700
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg',
701
-                                    esc_html__(
702
-                                        'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
703
-                                        'event_espresso'
704
-                                    )
705
-                                ),
706
-                            ]
707
-                        ),
708
-                    ]
709
-                ),
710
-            ]
711
-        );
712
-    }
713
-
714
-
715
-    /**
716
-     * registrations_requiring_pre_approval
717
-     *
718
-     * @param array $registrations_requiring_pre_approval
719
-     * @return EE_Form_Section_Proper
720
-     * @throws EE_Error
721
-     * @throws EntityNotFoundException
722
-     * @throws ReflectionException
723
-     */
724
-    private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = [])
725
-    {
726
-        $events_requiring_pre_approval = [];
727
-        foreach ($registrations_requiring_pre_approval as $registration) {
728
-            if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
729
-                $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
730
-                    EEH_HTML::span(
731
-                        '',
732
-                        '',
733
-                        'dashicons dashicons-marker ee-icon-size-16 orange-text'
734
-                    )
735
-                    . EEH_HTML::span($registration->event()->name(), '', 'orange-text')
736
-                );
737
-            }
738
-        }
739
-        return new EE_Form_Section_Proper(
740
-            [
741
-                'layout_strategy' => new EE_Template_Layout(
742
-                    [
743
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
744
-                                                  . $this->_slug
745
-                                                  . '/events_requiring_pre_approval.template.php', // layout_template
746
-                        'template_args'        => apply_filters(
747
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
748
-                            [
749
-                                'events_requiring_pre_approval'     => implode('', $events_requiring_pre_approval),
750
-                                'events_requiring_pre_approval_msg' => apply_filters(
751
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
752
-                                    esc_html__(
753
-                                        'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
754
-                                        'event_espresso'
755
-                                    )
756
-                                ),
757
-                            ]
758
-                        ),
759
-                    ]
760
-                ),
761
-            ]
762
-        );
763
-    }
764
-
765
-
766
-    /**
767
-     * _no_payment_required
768
-     *
769
-     * @param EE_Event[] $registrations_for_free_events
770
-     * @return EE_Form_Section_Proper
771
-     * @throws EE_Error
772
-     */
773
-    private function _no_payment_required($registrations_for_free_events = [])
774
-    {
775
-        // set some defaults
776
-        $this->checkout->selected_method_of_payment = 'no_payment_required';
777
-        // generate no_payment_required form
778
-        return new EE_Form_Section_Proper(
779
-            [
780
-                'layout_strategy' => new EE_Template_Layout(
781
-                    [
782
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
783
-                                                  . $this->_slug
784
-                                                  . '/no_payment_required.template.php', // layout_template
785
-                        'template_args'        => apply_filters(
786
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
787
-                            [
788
-                                'revisit'                       => $this->checkout->revisit,
789
-                                'registrations'                 => [],
790
-                                'ticket_count'                  => [],
791
-                                'registrations_for_free_events' => $registrations_for_free_events,
792
-                                'no_payment_required_msg'       => EEH_HTML::p(
793
-                                    esc_html__('This is a free event, so no billing will occur.', 'event_espresso')
794
-                                ),
795
-                            ]
796
-                        ),
797
-                    ]
798
-                ),
799
-            ]
800
-        );
801
-    }
802
-
803
-
804
-    /**
805
-     * _display_payment_options
806
-     *
807
-     * @param string $transaction_details
808
-     * @return EE_Form_Section_Proper
809
-     * @throws EE_Error
810
-     * @throws InvalidArgumentException
811
-     * @throws InvalidDataTypeException
812
-     * @throws InvalidInterfaceException
813
-     */
814
-    private function _display_payment_options($transaction_details = '')
815
-    {
816
-        // has method_of_payment been set by no-js user?
817
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
818
-        // build payment options form
819
-        return apply_filters(
820
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form',
821
-            new EE_Form_Section_Proper(
822
-                [
823
-                    'subsections'     => [
824
-                        'before_payment_options' => apply_filters(
825
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
826
-                            new EE_Form_Section_Proper(
827
-                                ['layout_strategy' => new EE_Div_Per_Section_Layout()]
828
-                            )
829
-                        ),
830
-                        'payment_options'        => $this->_setup_payment_options(),
831
-                        'after_payment_options'  => apply_filters(
832
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
833
-                            new EE_Form_Section_Proper(
834
-                                ['layout_strategy' => new EE_Div_Per_Section_Layout()]
835
-                            )
836
-                        ),
837
-                    ],
838
-                    'layout_strategy' => new EE_Template_Layout(
839
-                        [
840
-                            'layout_template_file' => $this->_template,
841
-                            'template_args'        => apply_filters(
842
-                                'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args',
843
-                                [
844
-                                    'reg_count'                 => $this->line_item_display->total_items(),
845
-                                    'transaction_details'       => $transaction_details,
846
-                                    'available_payment_methods' => [],
847
-                                ]
848
-                            ),
849
-                        ]
850
-                    ),
851
-                ]
852
-            )
853
-        );
854
-    }
855
-
856
-
857
-    /**
858
-     * _extra_hidden_inputs
859
-     *
860
-     * @param bool $no_payment_required
861
-     * @return EE_Form_Section_Proper
862
-     * @throws EE_Error
863
-     * @throws ReflectionException
864
-     */
865
-    private function _extra_hidden_inputs($no_payment_required = true)
866
-    {
867
-        return new EE_Form_Section_Proper(
868
-            [
869
-                'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
870
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
871
-                'subsections'     => [
872
-                    'spco_no_payment_required' => new EE_Hidden_Input(
873
-                        [
874
-                            'normalization_strategy' => new EE_Boolean_Normalization(),
875
-                            'html_name'              => 'spco_no_payment_required',
876
-                            'html_id'                => 'spco-no-payment-required-payment_options',
877
-                            'default'                => $no_payment_required,
878
-                        ]
879
-                    ),
880
-                    'spco_transaction_id'      => new EE_Fixed_Hidden_Input(
881
-                        [
882
-                            'normalization_strategy' => new EE_Int_Normalization(),
883
-                            'html_name'              => 'spco_transaction_id',
884
-                            'html_id'                => 'spco-transaction-id',
885
-                            'default'                => $this->checkout->transaction->ID(),
886
-                        ]
887
-                    ),
888
-                ],
889
-            ]
890
-        );
891
-    }
892
-
893
-
894
-    /**
895
-     *    _apply_registration_payments_to_amount_owing
896
-     *
897
-     * @param array $registrations
898
-     * @throws EE_Error
899
-     */
900
-    protected function _apply_registration_payments_to_amount_owing(array $registrations)
901
-    {
902
-        $payments = [];
903
-        foreach ($registrations as $registration) {
904
-            if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
905
-                $payments += $registration->registration_payments();
906
-            }
907
-        }
908
-        if (! empty($payments)) {
909
-            foreach ($payments as $payment) {
910
-                if ($payment instanceof EE_Registration_Payment) {
911
-                    $this->checkout->amount_owing -= $payment->amount();
912
-                }
913
-            }
914
-        }
915
-    }
916
-
917
-
918
-    /**
919
-     *    _reset_selected_method_of_payment
920
-     *
921
-     * @access    private
922
-     * @param bool $force_reset
923
-     * @return void
924
-     * @throws InvalidArgumentException
925
-     * @throws InvalidDataTypeException
926
-     * @throws InvalidInterfaceException
927
-     */
928
-    private function _reset_selected_method_of_payment($force_reset = false)
929
-    {
930
-        /** @var RequestInterface $request */
931
-        $request              = LoaderFactory::getLoader()->getShared(RequestInterface::class);
932
-        $reset_payment_method = $request->getRequestParam('reset_payment_method', $force_reset, 'bool');
933
-        if ($reset_payment_method) {
934
-            $this->checkout->selected_method_of_payment = null;
935
-            $this->checkout->payment_method             = null;
936
-            $this->checkout->billing_form               = null;
937
-            $this->_save_selected_method_of_payment();
938
-        }
939
-    }
940
-
941
-
942
-    /**
943
-     * _save_selected_method_of_payment
944
-     * stores the selected_method_of_payment in the session
945
-     * so that it's available for all subsequent requests including AJAX
946
-     *
947
-     * @access        private
948
-     * @param string $selected_method_of_payment
949
-     * @return void
950
-     * @throws InvalidArgumentException
951
-     * @throws InvalidDataTypeException
952
-     * @throws InvalidInterfaceException
953
-     */
954
-    private function _save_selected_method_of_payment($selected_method_of_payment = '')
955
-    {
956
-        $selected_method_of_payment = ! empty($selected_method_of_payment)
957
-            ? $selected_method_of_payment
958
-            : $this->checkout->selected_method_of_payment;
959
-        EE_Registry::instance()->SSN->set_session_data(
960
-            ['selected_method_of_payment' => $selected_method_of_payment]
961
-        );
962
-    }
963
-
964
-
965
-    /**
966
-     * _setup_payment_options
967
-     *
968
-     * @return EE_Form_Section_Proper
969
-     * @throws EE_Error
970
-     * @throws InvalidArgumentException
971
-     * @throws InvalidDataTypeException
972
-     * @throws InvalidInterfaceException
973
-     */
974
-    public function _setup_payment_options()
975
-    {
976
-        // load payment method classes
977
-        $this->checkout->available_payment_methods = $this->_get_available_payment_methods();
978
-        if (empty($this->checkout->available_payment_methods)) {
979
-            EE_Error::add_error(
980
-                apply_filters(
981
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods',
982
-                    sprintf(
983
-                        esc_html__(
984
-                            'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.',
985
-                            'event_espresso'
986
-                        ),
987
-                        '<br>',
988
-                        EE_Registry::instance()->CFG->organization->get_pretty('email')
989
-                    )
990
-                ),
991
-                __FILE__,
992
-                __FUNCTION__,
993
-                __LINE__
994
-            );
995
-        }
996
-        // switch up header depending on number of available payment methods
997
-        $payment_method_header     = count($this->checkout->available_payment_methods) > 1
998
-            ? apply_filters(
999
-                'FHEE__registration_page_payment_options__method_of_payment_hdr',
1000
-                esc_html__('Please Select Your Method of Payment', 'event_espresso')
1001
-            )
1002
-            : apply_filters(
1003
-                'FHEE__registration_page_payment_options__method_of_payment_hdr',
1004
-                esc_html__('Method of Payment', 'event_espresso')
1005
-            );
1006
-        $available_payment_methods = [
1007
-            // display the "Payment Method" header
1008
-            'payment_method_header' => new EE_Form_Section_HTML(
1009
-                apply_filters(
1010
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header',
1011
-                    EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'),
1012
-                    $payment_method_header
1013
-                )
1014
-            ),
1015
-        ];
1016
-        // the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
1017
-        $available_payment_method_options = [];
1018
-        $default_payment_method_option    = [];
1019
-        // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
1020
-        $payment_methods_billing_info = [
1021
-            new EE_Form_Section_HTML(
1022
-                EEH_HTML::div('<br />', '', '', 'clear:both;')
1023
-            ),
1024
-        ];
1025
-        // loop through payment methods
1026
-        foreach ($this->checkout->available_payment_methods as $payment_method) {
1027
-            if ($payment_method instanceof EE_Payment_Method) {
1028
-                $payment_method_button = EEH_HTML::img(
1029
-                    $payment_method->button_url(),
1030
-                    $payment_method->name(),
1031
-                    'spco-payment-method-' . $payment_method->slug() . '-btn-img',
1032
-                    'spco-payment-method-btn-img'
1033
-                );
1034
-                // check if any payment methods are set as default
1035
-                // if payment method is already selected OR nothing is selected and this payment method should be
1036
-                // open_by_default
1037
-                if (
1038
-                    ($this->checkout->selected_method_of_payment === $payment_method->slug())
1039
-                    || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1040
-                ) {
1041
-                    $this->checkout->selected_method_of_payment = $payment_method->slug();
1042
-                    $this->_save_selected_method_of_payment();
1043
-                    $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button;
1044
-                } else {
1045
-                    $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
1046
-                }
1047
-                $payment_methods_billing_info[ $payment_method->slug() . '-info' ] =
1048
-                    $this->_payment_method_billing_info(
1049
-                        $payment_method
1050
-                    );
1051
-            }
1052
-        }
1053
-        // prepend available_payment_method_options with default_payment_method_option so that it appears first in list
1054
-        // of PMs
1055
-        $available_payment_method_options = $default_payment_method_option + $available_payment_method_options;
1056
-        // now generate the actual form  inputs
1057
-        $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs(
1058
-            $available_payment_method_options
1059
-        );
1060
-        $available_payment_methods                              += $payment_methods_billing_info;
1061
-        // build the available payment methods form
1062
-        return new EE_Form_Section_Proper(
1063
-            [
1064
-                'html_id'         => 'spco-available-methods-of-payment-dv',
1065
-                'subsections'     => $available_payment_methods,
1066
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1067
-            ]
1068
-        );
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * _get_available_payment_methods
1074
-     *
1075
-     * @return EE_Payment_Method[]
1076
-     * @throws EE_Error
1077
-     * @throws InvalidArgumentException
1078
-     * @throws InvalidDataTypeException
1079
-     * @throws InvalidInterfaceException
1080
-     */
1081
-    protected function _get_available_payment_methods()
1082
-    {
1083
-        if (! empty($this->checkout->available_payment_methods)) {
1084
-            return $this->checkout->available_payment_methods;
1085
-        }
1086
-        $available_payment_methods = [];
1087
-        $EEM_Payment_Method        = EEM_Payment_Method::instance();
1088
-        // get all active payment methods
1089
-        $payment_methods = $EEM_Payment_Method->get_all_for_transaction(
1090
-            $this->checkout->transaction,
1091
-            EEM_Payment_Method::scope_cart
1092
-        );
1093
-        foreach ($payment_methods as $payment_method) {
1094
-            if ($payment_method instanceof EE_Payment_Method) {
1095
-                $available_payment_methods[ $payment_method->slug() ] = $payment_method;
1096
-            }
1097
-        }
1098
-        return $available_payment_methods;
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     *    _available_payment_method_inputs
1104
-     *
1105
-     * @access    private
1106
-     * @param array $available_payment_method_options
1107
-     * @return    EE_Form_Section_Proper
1108
-     * @throws EE_Error
1109
-     * @throws EE_Error
1110
-     */
1111
-    private function _available_payment_method_inputs($available_payment_method_options = [])
1112
-    {
1113
-        // generate inputs
1114
-        return new EE_Form_Section_Proper(
1115
-            [
1116
-                'html_id'         => 'ee-available-payment-method-inputs',
1117
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1118
-                'subsections'     => [
1119
-                    '' => new EE_Radio_Button_Input(
1120
-                        $available_payment_method_options,
1121
-                        [
1122
-                            'html_name'          => 'selected_method_of_payment',
1123
-                            'html_class'         => 'spco-payment-method',
1124
-                            'default'            => $this->checkout->selected_method_of_payment,
1125
-                            'label_size'         => 11,
1126
-                            'enforce_label_size' => true,
1127
-                        ]
1128
-                    ),
1129
-                ],
1130
-            ]
1131
-        );
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     *    _payment_method_billing_info
1137
-     *
1138
-     * @access    private
1139
-     * @param EE_Payment_Method $payment_method
1140
-     * @return EE_Form_Section_Proper
1141
-     * @throws EE_Error
1142
-     * @throws InvalidArgumentException
1143
-     * @throws InvalidDataTypeException
1144
-     * @throws InvalidInterfaceException
1145
-     */
1146
-    private function _payment_method_billing_info(EE_Payment_Method $payment_method)
1147
-    {
1148
-        $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug();
1149
-        // generate the billing form for payment method
1150
-        $billing_form                 = $currently_selected
1151
-            ? $this->_get_billing_form_for_payment_method($payment_method)
1152
-            : new EE_Form_Section_HTML();
1153
-        $this->checkout->billing_form = $currently_selected
1154
-            ? $billing_form
1155
-            : $this->checkout->billing_form;
1156
-        // it's all in the details
1157
-        $info_html = EEH_HTML::h3(
1158
-            esc_html__('Important information regarding your payment', 'event_espresso'),
1159
-            '',
1160
-            'spco-payment-method-hdr'
1161
-        );
1162
-        // add some info regarding the step, either from what's saved in the admin,
1163
-        // or a default string depending on whether the PM has a billing form or not
1164
-        if ($payment_method->description()) {
1165
-            $payment_method_info = $payment_method->description();
1166
-        } elseif ($billing_form instanceof EE_Billing_Info_Form) {
1167
-            $payment_method_info = sprintf(
1168
-                esc_html__(
1169
-                    'Please provide the following billing information, then click the "%1$s" button below in order to proceed.',
1170
-                    'event_espresso'
1171
-                ),
1172
-                $this->submit_button_text()
1173
-            );
1174
-        } else {
1175
-            $payment_method_info = sprintf(
1176
-                esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'),
1177
-                $this->submit_button_text()
1178
-            );
1179
-        }
1180
-        $info_html .= EEH_HTML::div(
1181
-            apply_filters(
1182
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info',
1183
-                $payment_method_info
1184
-            ),
1185
-            '',
1186
-            'spco-payment-method-desc ee-attention'
1187
-        );
1188
-        return new EE_Form_Section_Proper(
1189
-            [
1190
-                'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1191
-                'html_class'      => 'spco-payment-method-info-dv',
1192
-                // only display the selected or default PM
1193
-                'html_style'      => $currently_selected ? '' : 'display:none;',
1194
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1195
-                'subsections'     => [
1196
-                    'info'         => new EE_Form_Section_HTML($info_html),
1197
-                    'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(),
1198
-                ],
1199
-            ]
1200
-        );
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * get_billing_form_html_for_payment_method
1206
-     *
1207
-     * @return bool
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws ReflectionException
1211
-     * @throws InvalidDataTypeException
1212
-     * @throws InvalidInterfaceException
1213
-     */
1214
-    public function get_billing_form_html_for_payment_method()
1215
-    {
1216
-        // how have they chosen to pay?
1217
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1218
-        $this->checkout->payment_method             = $this->_get_payment_method_for_selected_method_of_payment();
1219
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1220
-            return false;
1221
-        }
1222
-        if (
1223
-            apply_filters(
1224
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1225
-                false
1226
-            )
1227
-        ) {
1228
-            EE_Error::add_success(
1229
-                apply_filters(
1230
-                    'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1231
-                    sprintf(
1232
-                        esc_html__(
1233
-                            'You have selected "%s" as your method of payment. Please note the important payment information below.',
1234
-                            'event_espresso'
1235
-                        ),
1236
-                        $this->checkout->payment_method->name()
1237
-                    )
1238
-                )
1239
-            );
1240
-        }
1241
-        // now generate billing form for selected method of payment
1242
-        $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1243
-        // fill form with attendee info if applicable
1244
-        if (
1245
-            $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
1246
-            && $this->checkout->transaction_has_primary_registrant()
1247
-        ) {
1248
-            $payment_method_billing_form->populate_from_attendee(
1249
-                $this->checkout->transaction->primary_registration()->attendee()
1250
-            );
1251
-        }
1252
-        // and debug content
1253
-        if (
1254
-            $payment_method_billing_form instanceof EE_Billing_Info_Form
1255
-            && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1256
-        ) {
1257
-            $payment_method_billing_form =
1258
-                $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1259
-                    $payment_method_billing_form
1260
-                );
1261
-        }
1262
-        $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper
1263
-            ? $payment_method_billing_form->get_html()
1264
-            : '';
1265
-        $this->checkout->json_response->set_return_data(['payment_method_info' => $billing_info]);
1266
-        // localize validation rules for main form
1267
-        $this->checkout->current_step->reg_form->localize_validation_rules();
1268
-        $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1269
-        return true;
1270
-    }
1271
-
1272
-
1273
-    /**
1274
-     * _get_billing_form_for_payment_method
1275
-     *
1276
-     * @param EE_Payment_Method $payment_method
1277
-     * @return EE_Billing_Info_Form|EE_Billing_Attendee_Info_Form|EE_Form_Section_HTML
1278
-     * @throws EE_Error
1279
-     * @throws InvalidArgumentException
1280
-     * @throws InvalidDataTypeException
1281
-     * @throws InvalidInterfaceException
1282
-     */
1283
-    private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method)
1284
-    {
1285
-        $billing_form = $payment_method->type_obj()->billing_form(
1286
-            $this->checkout->transaction,
1287
-            ['amount_owing' => $this->checkout->amount_owing]
1288
-        );
1289
-        if ($billing_form instanceof EE_Billing_Info_Form) {
1290
-            if (
1291
-                apply_filters(
1292
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1293
-                    false
1294
-                )
1295
-                && $this->request->requestParamIsSet('payment_method')
1296
-            ) {
1297
-                EE_Error::add_success(
1298
-                    apply_filters(
1299
-                        'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1300
-                        sprintf(
1301
-                            esc_html__(
1302
-                                'You have selected "%s" as your method of payment. Please note the important payment information below.',
1303
-                                'event_espresso'
1304
-                            ),
1305
-                            $payment_method->name()
1306
-                        )
1307
-                    )
1308
-                );
1309
-            }
1310
-            return apply_filters(
1311
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
1312
-                $billing_form,
1313
-                $payment_method
1314
-            );
1315
-        }
1316
-        // no actual billing form, so return empty HTML form section
1317
-        return new EE_Form_Section_HTML();
1318
-    }
1319
-
1320
-
1321
-    /**
1322
-     * _get_selected_method_of_payment
1323
-     *
1324
-     * @param boolean $required whether to throw an error if the "selected_method_of_payment"
1325
-     *                          is not found in the incoming request
1326
-     * @param string  $request_param
1327
-     * @return NULL|string
1328
-     * @throws EE_Error
1329
-     * @throws InvalidArgumentException
1330
-     * @throws InvalidDataTypeException
1331
-     * @throws InvalidInterfaceException
1332
-     */
1333
-    private function _get_selected_method_of_payment(
1334
-        $required = false,
1335
-        $request_param = 'selected_method_of_payment'
1336
-    ) {
1337
-        // is selected_method_of_payment set in the request ?
1338
-        $selected_method_of_payment = $this->request->getRequestParam($request_param);
1339
-        if ($selected_method_of_payment) {
1340
-            // sanitize it
1341
-            $selected_method_of_payment = is_array($selected_method_of_payment)
1342
-                ? array_shift($selected_method_of_payment)
1343
-                : $selected_method_of_payment;
1344
-            $selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
1345
-            // store it in the session so that it's available for all subsequent requests including AJAX
1346
-            $this->_save_selected_method_of_payment($selected_method_of_payment);
1347
-        } else {
1348
-            // or is is set in the session ?
1349
-            $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data(
1350
-                'selected_method_of_payment'
1351
-            );
1352
-        }
1353
-        // do ya really really gotta have it?
1354
-        if (empty($selected_method_of_payment) && $required) {
1355
-            EE_Error::add_error(
1356
-                sprintf(
1357
-                    esc_html__(
1358
-                        'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.',
1359
-                        'event_espresso'
1360
-                    ),
1361
-                    '<br/>',
1362
-                    '<br/>',
1363
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
1364
-                ),
1365
-                __FILE__,
1366
-                __FUNCTION__,
1367
-                __LINE__
1368
-            );
1369
-            return null;
1370
-        }
1371
-        return $selected_method_of_payment;
1372
-    }
1373
-
1374
-
1375
-
1376
-
1377
-
1378
-
1379
-    /********************************************************************************************************/
1380
-    /***********************************  SWITCH PAYMENT METHOD  ************************************/
1381
-    /********************************************************************************************************/
1382
-    /**
1383
-     * switch_payment_method
1384
-     *
1385
-     * @return bool
1386
-     * @throws EE_Error
1387
-     * @throws InvalidArgumentException
1388
-     * @throws InvalidDataTypeException
1389
-     * @throws InvalidInterfaceException
1390
-     * @throws ReflectionException
1391
-     */
1392
-    public function switch_payment_method()
1393
-    {
1394
-        if (! $this->_verify_payment_method_is_set()) {
1395
-            return false;
1396
-        }
1397
-        if (
1398
-            apply_filters(
1399
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1400
-                false
1401
-            )
1402
-        ) {
1403
-            EE_Error::add_success(
1404
-                apply_filters(
1405
-                    'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1406
-                    sprintf(
1407
-                        esc_html__(
1408
-                            'You have selected "%s" as your method of payment. Please note the important payment information below.',
1409
-                            'event_espresso'
1410
-                        ),
1411
-                        $this->checkout->payment_method->name()
1412
-                    )
1413
-                )
1414
-            );
1415
-        }
1416
-        // generate billing form for selected method of payment if it hasn't been done already
1417
-        if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1418
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1419
-                $this->checkout->payment_method
1420
-            );
1421
-        }
1422
-        // fill form with attendee info if applicable
1423
-        if (
1424
-            apply_filters(
1425
-                'FHEE__populate_billing_form_fields_from_attendee',
1426
-                (
1427
-                    $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
1428
-                    && $this->checkout->transaction_has_primary_registrant()
1429
-                ),
1430
-                $this->checkout->billing_form,
1431
-                $this->checkout->transaction
1432
-            )
1433
-        ) {
1434
-            $this->checkout->billing_form->populate_from_attendee(
1435
-                $this->checkout->transaction->primary_registration()->attendee()
1436
-            );
1437
-        }
1438
-        // and debug content
1439
-        if (
1440
-            $this->checkout->billing_form instanceof EE_Billing_Info_Form
1441
-            && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1442
-        ) {
1443
-            $this->checkout->billing_form =
1444
-                $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1445
-                    $this->checkout->billing_form
1446
-                );
1447
-        }
1448
-        // get html and validation rules for form
1449
-        if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
1450
-            $this->checkout->json_response->set_return_data(
1451
-                ['payment_method_info' => $this->checkout->billing_form->get_html()]
1452
-            );
1453
-            // localize validation rules for main form
1454
-            $this->checkout->billing_form->localize_validation_rules(true);
1455
-            $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1456
-        } else {
1457
-            $this->checkout->json_response->set_return_data(['payment_method_info' => '']);
1458
-        }
1459
-        // prevents advancement to next step
1460
-        $this->checkout->continue_reg = false;
1461
-        return true;
1462
-    }
1463
-
1464
-
1465
-    /**
1466
-     * _verify_payment_method_is_set
1467
-     *
1468
-     * @return bool
1469
-     * @throws EE_Error
1470
-     * @throws InvalidArgumentException
1471
-     * @throws ReflectionException
1472
-     * @throws InvalidDataTypeException
1473
-     * @throws InvalidInterfaceException
1474
-     */
1475
-    protected function _verify_payment_method_is_set()
1476
-    {
1477
-        // generate billing form for selected method of payment if it hasn't been done already
1478
-        if (empty($this->checkout->selected_method_of_payment)) {
1479
-            // how have they chosen to pay?
1480
-            $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1481
-        } else {
1482
-            // choose your own adventure based on method_of_payment
1483
-            switch ($this->checkout->selected_method_of_payment) {
1484
-                case 'events_sold_out':
1485
-                    EE_Error::add_attention(
1486
-                        apply_filters(
1487
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
1488
-                            esc_html__(
1489
-                                'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1490
-                                'event_espresso'
1491
-                            )
1492
-                        ),
1493
-                        __FILE__,
1494
-                        __FUNCTION__,
1495
-                        __LINE__
1496
-                    );
1497
-                    return false;
1498
-                case 'payments_closed':
1499
-                    EE_Error::add_attention(
1500
-                        apply_filters(
1501
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
1502
-                            esc_html__(
1503
-                                'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.',
1504
-                                'event_espresso'
1505
-                            )
1506
-                        ),
1507
-                        __FILE__,
1508
-                        __FUNCTION__,
1509
-                        __LINE__
1510
-                    );
1511
-                    return false;
1512
-                case 'no_payment_required':
1513
-                    EE_Error::add_attention(
1514
-                        apply_filters(
1515
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
1516
-                            esc_html__(
1517
-                                'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.',
1518
-                                'event_espresso'
1519
-                            )
1520
-                        ),
1521
-                        __FILE__,
1522
-                        __FUNCTION__,
1523
-                        __LINE__
1524
-                    );
1525
-                    return false;
1526
-                default:
1527
-            }
1528
-        }
1529
-        // verify payment method
1530
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1531
-            // get payment method for selected method of payment
1532
-            $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1533
-        }
1534
-        return $this->checkout->payment_method instanceof EE_Payment_Method;
1535
-    }
1536
-
1537
-
1538
-
1539
-    /********************************************************************************************************/
1540
-    /***************************************  SAVE PAYER DETAILS  ****************************************/
1541
-    /********************************************************************************************************/
1542
-    /**
1543
-     * save_payer_details_via_ajax
1544
-     *
1545
-     * @return void
1546
-     * @throws EE_Error
1547
-     * @throws InvalidArgumentException
1548
-     * @throws ReflectionException
1549
-     * @throws RuntimeException
1550
-     * @throws InvalidDataTypeException
1551
-     * @throws InvalidInterfaceException
1552
-     */
1553
-    public function save_payer_details_via_ajax()
1554
-    {
1555
-        if (! $this->_verify_payment_method_is_set()) {
1556
-            return;
1557
-        }
1558
-        // generate billing form for selected method of payment if it hasn't been done already
1559
-        if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1560
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1561
-                $this->checkout->payment_method
1562
-            );
1563
-        }
1564
-        // generate primary attendee from payer info if applicable
1565
-        if (! $this->checkout->transaction_has_primary_registrant()) {
1566
-            $attendee = $this->_create_attendee_from_request_data();
1567
-            if ($attendee instanceof EE_Attendee) {
1568
-                foreach ($this->checkout->transaction->registrations() as $registration) {
1569
-                    if ($registration->is_primary_registrant()) {
1570
-                        $this->checkout->primary_attendee_obj = $attendee;
1571
-                        $registration->_add_relation_to($attendee, 'Attendee');
1572
-                        $registration->set_attendee_id($attendee->ID());
1573
-                        $registration->update_cache_after_object_save('Attendee', $attendee);
1574
-                    }
1575
-                }
1576
-            }
1577
-        }
1578
-    }
1579
-
1580
-
1581
-    /**
1582
-     * create_attendee_from_request_data
1583
-     * uses info from alternate GET or POST data (such as AJAX) to create a new attendee
1584
-     *
1585
-     * @return EE_Attendee
1586
-     * @throws EE_Error
1587
-     * @throws InvalidArgumentException
1588
-     * @throws ReflectionException
1589
-     * @throws InvalidDataTypeException
1590
-     * @throws InvalidInterfaceException
1591
-     */
1592
-    protected function _create_attendee_from_request_data()
1593
-    {
1594
-        // get State ID
1595
-        $STA_ID = $this->request->getRequestParam('state');
1596
-        if (! empty($STA_ID)) {
1597
-            // can we get state object from name ?
1598
-            EE_Registry::instance()->load_model('State');
1599
-            $state  = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID');
1600
-            $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1601
-        }
1602
-        // get Country ISO
1603
-        $CNT_ISO = $this->request->getRequestParam('country');
1604
-        if (! empty($CNT_ISO)) {
1605
-            // can we get country object from name ?
1606
-            EE_Registry::instance()->load_model('Country');
1607
-            $country = EEM_Country::instance()->get_col(
1608
-                [['CNT_name' => $CNT_ISO], 'limit' => 1],
1609
-                'CNT_ISO'
1610
-            );
1611
-            $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1612
-        }
1613
-        // grab attendee data
1614
-        $attendee_data = [
1615
-            'ATT_fname'    => $this->request->getRequestParam('first_name'),
1616
-            'ATT_lname'    => $this->request->getRequestParam('last_name'),
1617
-            'ATT_email'    => $this->request->getRequestParam('email'),
1618
-            'ATT_address'  => $this->request->getRequestParam('address'),
1619
-            'ATT_address2' => $this->request->getRequestParam('address2'),
1620
-            'ATT_city'     => $this->request->getRequestParam('city'),
1621
-            'STA_ID'       => $STA_ID,
1622
-            'CNT_ISO'      => $CNT_ISO,
1623
-            'ATT_zip'      => $this->request->getRequestParam('zip'),
1624
-            'ATT_phone'    => $this->request->getRequestParam('phone'),
1625
-        ];
1626
-        // validate the email address since it is the most important piece of info
1627
-        if (empty($attendee_data['ATT_email'])) {
1628
-            EE_Error::add_error(
1629
-                esc_html__('An invalid email address was submitted.', 'event_espresso'),
1630
-                __FILE__,
1631
-                __FUNCTION__,
1632
-                __LINE__
1633
-            );
1634
-        }
1635
-        // does this attendee already exist in the db ? we're searching using a combination of first name, last name,
1636
-        // AND email address
1637
-        if (
1638
-            ! empty($attendee_data['ATT_fname'])
1639
-            && ! empty($attendee_data['ATT_lname'])
1640
-            && ! empty($attendee_data['ATT_email'])
1641
-        ) {
1642
-            $existing_attendee = EEM_Attendee::instance()->find_existing_attendee(
1643
-                [
1644
-                    'ATT_fname' => $attendee_data['ATT_fname'],
1645
-                    'ATT_lname' => $attendee_data['ATT_lname'],
1646
-                    'ATT_email' => $attendee_data['ATT_email'],
1647
-                ]
1648
-            );
1649
-            if ($existing_attendee instanceof EE_Attendee) {
1650
-                return $existing_attendee;
1651
-            }
1652
-        }
1653
-        // no existing attendee? kk let's create a new one
1654
-        // kinda lame, but we need a first and last name to create an attendee, so use the email address if those
1655
-        // don't exist
1656
-        $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname'])
1657
-            ? $attendee_data['ATT_fname']
1658
-            : $attendee_data['ATT_email'];
1659
-        $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname'])
1660
-            ? $attendee_data['ATT_lname']
1661
-            : $attendee_data['ATT_email'];
1662
-        return EE_Attendee::new_instance($attendee_data);
1663
-    }
1664
-
1665
-
1666
-
1667
-    /********************************************************************************************************/
1668
-    /****************************************  PROCESS REG STEP  *****************************************/
1669
-    /********************************************************************************************************/
1670
-    /**
1671
-     * process_reg_step
1672
-     *
1673
-     * @return bool
1674
-     * @throws EE_Error
1675
-     * @throws InvalidArgumentException
1676
-     * @throws ReflectionException
1677
-     * @throws EntityNotFoundException
1678
-     * @throws InvalidDataTypeException
1679
-     * @throws InvalidInterfaceException
1680
-     * @throws InvalidStatusException
1681
-     */
1682
-    public function process_reg_step()
1683
-    {
1684
-        // how have they chosen to pay?
1685
-        $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free()
1686
-            ? 'no_payment_required'
1687
-            : $this->_get_selected_method_of_payment(true);
1688
-        // choose your own adventure based on method_of_payment
1689
-        switch ($this->checkout->selected_method_of_payment) {
1690
-            case 'events_sold_out':
1691
-                $this->checkout->redirect     = true;
1692
-                $this->checkout->redirect_url = $this->checkout->cancel_page_url;
1693
-                $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1694
-                // mark this reg step as completed
1695
-                $this->set_completed();
1696
-                return false;
1697
-
1698
-            case 'payments_closed':
1699
-                if (
1700
-                    apply_filters(
1701
-                        'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success',
1702
-                        false
1703
-                    )
1704
-                ) {
1705
-                    EE_Error::add_success(
1706
-                        esc_html__('no payment required at this time.', 'event_espresso'),
1707
-                        __FILE__,
1708
-                        __FUNCTION__,
1709
-                        __LINE__
1710
-                    );
1711
-                }
1712
-                // mark this reg step as completed
1713
-                $this->set_completed();
1714
-                return true;
1715
-
1716
-            case 'no_payment_required':
1717
-                if (
1718
-                    apply_filters(
1719
-                        'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success',
1720
-                        false
1721
-                    )
1722
-                ) {
1723
-                    EE_Error::add_success(
1724
-                        esc_html__('no payment required.', 'event_espresso'),
1725
-                        __FILE__,
1726
-                        __FUNCTION__,
1727
-                        __LINE__
1728
-                    );
1729
-                }
1730
-                // mark this reg step as completed
1731
-                $this->set_completed();
1732
-                return true;
1733
-
1734
-            default:
1735
-                $registrations         = EE_Registry::instance()->SSN->checkout()->transaction->registrations(
1736
-                    EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
1737
-                );
1738
-                $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
1739
-                    $registrations,
1740
-                    EE_Registry::instance()->SSN->checkout()->revisit
1741
-                );
1742
-                // calculate difference between the two arrays
1743
-                $registrations = array_diff($registrations, $ejected_registrations);
1744
-                if (empty($registrations)) {
1745
-                    $this->_redirect_because_event_sold_out();
1746
-                    return false;
1747
-                }
1748
-                $payment = $this->_process_payment();
1749
-                if ($payment instanceof EE_Payment) {
1750
-                    $this->checkout->continue_reg = true;
1751
-                    $this->_maybe_set_completed($payment);
1752
-                } else {
1753
-                    $this->checkout->continue_reg = false;
1754
-                }
1755
-                return $payment instanceof EE_Payment;
1756
-        }
1757
-    }
1758
-
1759
-
1760
-    /**
1761
-     * _redirect_because_event_sold_out
1762
-     *
1763
-     * @return void
1764
-     */
1765
-    protected function _redirect_because_event_sold_out()
1766
-    {
1767
-        $this->checkout->continue_reg = false;
1768
-        // set redirect URL
1769
-        $this->checkout->redirect_url = add_query_arg(
1770
-            ['e_reg_url_link' => $this->checkout->reg_url_link],
1771
-            $this->checkout->current_step->reg_step_url()
1772
-        );
1773
-        $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1774
-    }
1775
-
1776
-
1777
-    /**
1778
-     * @param EE_Payment $payment
1779
-     * @return void
1780
-     * @throws EE_Error
1781
-     */
1782
-    protected function _maybe_set_completed(EE_Payment $payment)
1783
-    {
1784
-        // Do we need to redirect them? If so, there's more work to be done.
1785
-        if (! $payment->redirect_url()) {
1786
-            $this->set_completed();
1787
-        }
1788
-    }
1789
-
1790
-
1791
-    /**
1792
-     *    update_reg_step
1793
-     *    this is the final step after a user  revisits the site to retry a payment
1794
-     *
1795
-     * @return bool
1796
-     * @throws EE_Error
1797
-     * @throws InvalidArgumentException
1798
-     * @throws ReflectionException
1799
-     * @throws EntityNotFoundException
1800
-     * @throws InvalidDataTypeException
1801
-     * @throws InvalidInterfaceException
1802
-     * @throws InvalidStatusException
1803
-     */
1804
-    public function update_reg_step()
1805
-    {
1806
-        $success = true;
1807
-        // if payment required
1808
-        if ($this->checkout->transaction->total() > 0) {
1809
-            do_action(
1810
-                'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway',
1811
-                $this->checkout->transaction
1812
-            );
1813
-            // attempt payment via payment method
1814
-            $success = $this->process_reg_step();
1815
-        }
1816
-        if ($success && ! $this->checkout->redirect) {
1817
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
1818
-                $this->checkout->transaction->ID()
1819
-            );
1820
-            // set return URL
1821
-            $this->checkout->redirect_url = add_query_arg(
1822
-                ['e_reg_url_link' => $this->checkout->reg_url_link],
1823
-                $this->checkout->thank_you_page_url
1824
-            );
1825
-        }
1826
-        return $success;
1827
-    }
1828
-
1829
-
1830
-    /**
1831
-     * @return EE_Payment|null
1832
-     * @throws EE_Error
1833
-     * @throws InvalidArgumentException
1834
-     * @throws ReflectionException
1835
-     * @throws RuntimeException
1836
-     * @throws InvalidDataTypeException
1837
-     * @throws InvalidInterfaceException
1838
-     */
1839
-    private function _process_payment()
1840
-    {
1841
-        // basically confirm that the event hasn't sold out since they hit the page
1842
-        if (! $this->_last_second_ticket_verifications()) {
1843
-            return null;
1844
-        }
1845
-        // ya gotta make a choice man
1846
-        if (empty($this->checkout->selected_method_of_payment)) {
1847
-            $this->checkout->json_response->set_plz_select_method_of_payment(
1848
-                esc_html__('Please select a method of payment before proceeding.', 'event_espresso')
1849
-            );
1850
-            return null;
1851
-        }
1852
-        // get EE_Payment_Method object
1853
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1854
-            return null;
1855
-        }
1856
-        // setup billing form
1857
-        if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1858
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1859
-                $this->checkout->payment_method
1860
-            );
1861
-            // bad billing form ?
1862
-            if (! $this->_billing_form_is_valid()) {
1863
-                return null;
1864
-            }
1865
-        }
1866
-        // ensure primary registrant has been fully processed
1867
-        if (! $this->_setup_primary_registrant_prior_to_payment()) {
1868
-            return null;
1869
-        }
1870
-        // if session is close to expiring (under 10 minutes by default)
1871
-        if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1872
-            // add some time to session expiration so that payment can be completed
1873
-            EE_Registry::instance()->SSN->extend_expiration();
1874
-        }
1875
-        /** @type EE_Transaction_Processor $transaction_processor */
1876
-        // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1877
-        // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations
1878
-        // for events with a default reg status of Approved
1879
-        // $transaction_processor->toggle_registration_statuses_for_default_approved_events(
1880
-        //      $this->checkout->transaction, $this->checkout->reg_cache_where_params
1881
-        // );
1882
-        // attempt payment
1883
-        $payment = $this->_attempt_payment($this->checkout->payment_method);
1884
-        // process results
1885
-        $payment = $this->_validate_payment($payment);
1886
-        $payment = $this->_post_payment_processing($payment);
1887
-        // verify payment
1888
-        if ($payment instanceof EE_Payment) {
1889
-            // store that for later
1890
-            $this->checkout->payment = $payment;
1891
-            // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
1892
-            $this->checkout->transaction->toggle_failed_transaction_status();
1893
-            $payment_status = $payment->status();
1894
-            if (
1895
-                $payment_status === EEM_Payment::status_id_approved
1896
-                || $payment_status === EEM_Payment::status_id_pending
1897
-            ) {
1898
-                return $payment;
1899
-            }
1900
-            return null;
1901
-        }
1902
-        if ($payment === true) {
1903
-            // please note that offline payment methods will NOT make a payment,
1904
-            // but instead just mark themselves as the PMD_ID on the transaction, and return true
1905
-            $this->checkout->payment = $payment;
1906
-            return $payment;
1907
-        }
1908
-        // where's my money?
1909
-        return null;
1910
-    }
1911
-
1912
-
1913
-    /**
1914
-     * _last_second_ticket_verifications
1915
-     *
1916
-     * @return bool
1917
-     * @throws EE_Error
1918
-     * @throws ReflectionException
1919
-     */
1920
-    protected function _last_second_ticket_verifications()
1921
-    {
1922
-        // don't bother re-validating if not a return visit
1923
-        if (! $this->checkout->revisit) {
1924
-            return true;
1925
-        }
1926
-        $registrations = $this->checkout->transaction->registrations();
1927
-        if (empty($registrations)) {
1928
-            return false;
1929
-        }
1930
-        foreach ($registrations as $registration) {
1931
-            if ($registration instanceof EE_Registration && ! $registration->is_approved()) {
1932
-                $event = $registration->event_obj();
1933
-                if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1934
-                    EE_Error::add_error(
1935
-                        apply_filters(
1936
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1937
-                            sprintf(
1938
-                                esc_html__(
1939
-                                    'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
1940
-                                    'event_espresso'
1941
-                                ),
1942
-                                $event->name()
1943
-                            )
1944
-                        ),
1945
-                        __FILE__,
1946
-                        __FUNCTION__,
1947
-                        __LINE__
1948
-                    );
1949
-                    return false;
1950
-                }
1951
-            }
1952
-        }
1953
-        return true;
1954
-    }
1955
-
1956
-
1957
-    /**
1958
-     * redirect_form
1959
-     *
1960
-     * @return bool
1961
-     * @throws EE_Error
1962
-     * @throws InvalidArgumentException
1963
-     * @throws ReflectionException
1964
-     * @throws InvalidDataTypeException
1965
-     * @throws InvalidInterfaceException
1966
-     */
1967
-    public function redirect_form()
1968
-    {
1969
-        $payment_method_billing_info = $this->_payment_method_billing_info(
1970
-            $this->_get_payment_method_for_selected_method_of_payment()
1971
-        );
1972
-        $html                        = $payment_method_billing_info->get_html();
1973
-        $html                        .= $this->checkout->redirect_form;
1974
-        /** @var ResponseInterface $response */
1975
-        $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
1976
-        $response->addOutput($html);
1977
-        return true;
1978
-    }
1979
-
1980
-
1981
-    /**
1982
-     * _billing_form_is_valid
1983
-     *
1984
-     * @return bool
1985
-     * @throws EE_Error
1986
-     */
1987
-    private function _billing_form_is_valid()
1988
-    {
1989
-        if (! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1990
-            return true;
1991
-        }
1992
-        if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1993
-            if ($this->checkout->billing_form->was_submitted()) {
1994
-                $this->checkout->billing_form->receive_form_submission();
1995
-                if ($this->checkout->billing_form->is_valid()) {
1996
-                    return true;
1997
-                }
1998
-                $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
1999
-                $error_strings     = [];
2000
-                foreach ($validation_errors as $validation_error) {
2001
-                    if ($validation_error instanceof EE_Validation_Error) {
2002
-                        $form_section = $validation_error->get_form_section();
2003
-                        if ($form_section instanceof EE_Form_Input_Base) {
2004
-                            $label = $form_section->html_label_text();
2005
-                        } elseif ($form_section instanceof EE_Form_Section_Base) {
2006
-                            $label = $form_section->name();
2007
-                        } else {
2008
-                            $label = esc_html__('Validation Error', 'event_espresso');
2009
-                        }
2010
-                        $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
2011
-                    }
2012
-                }
2013
-                EE_Error::add_error(
2014
-                    sprintf(
2015
-                        esc_html__(
2016
-                            'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s',
2017
-                            'event_espresso'
2018
-                        ),
2019
-                        '<br/>',
2020
-                        implode('<br/>', $error_strings)
2021
-                    ),
2022
-                    __FILE__,
2023
-                    __FUNCTION__,
2024
-                    __LINE__
2025
-                );
2026
-            } else {
2027
-                EE_Error::add_error(
2028
-                    esc_html__(
2029
-                        'The billing form was not submitted or something prevented it\'s submission.',
2030
-                        'event_espresso'
2031
-                    ),
2032
-                    __FILE__,
2033
-                    __FUNCTION__,
2034
-                    __LINE__
2035
-                );
2036
-            }
2037
-        } else {
2038
-            EE_Error::add_error(
2039
-                esc_html__(
2040
-                    'The submitted billing form is invalid possibly due to a technical reason.',
2041
-                    'event_espresso'
2042
-                ),
2043
-                __FILE__,
2044
-                __FUNCTION__,
2045
-                __LINE__
2046
-            );
2047
-        }
2048
-        return false;
2049
-    }
2050
-
2051
-
2052
-    /**
2053
-     * _setup_primary_registrant_prior_to_payment
2054
-     * ensures that the primary registrant has a valid attendee object created with the critical details populated
2055
-     * (first & last name & email) and that both the transaction object and primary registration object have been saved
2056
-     * plz note that any other registrations will NOT be saved at this point (because they may not have any details
2057
-     * yet)
2058
-     *
2059
-     * @return bool
2060
-     * @throws EE_Error
2061
-     * @throws InvalidArgumentException
2062
-     * @throws ReflectionException
2063
-     * @throws RuntimeException
2064
-     * @throws InvalidDataTypeException
2065
-     * @throws InvalidInterfaceException
2066
-     */
2067
-    private function _setup_primary_registrant_prior_to_payment()
2068
-    {
2069
-        // check if transaction has a primary registrant and that it has a related Attendee object
2070
-        // if not, then we need to at least gather some primary registrant data before attempting payment
2071
-        if (
2072
-            $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
2073
-            && ! $this->checkout->transaction_has_primary_registrant()
2074
-            && ! $this->_capture_primary_registration_data_from_billing_form()
2075
-        ) {
2076
-            return false;
2077
-        }
2078
-        // because saving an object clears it's cache, we need to do the chevy shuffle
2079
-        // grab the primary_registration object
2080
-        $primary_registration = $this->checkout->transaction->primary_registration();
2081
-        // at this point we'll consider a TXN to not have been failed
2082
-        $this->checkout->transaction->toggle_failed_transaction_status();
2083
-        // save the TXN ( which clears cached copy of primary_registration)
2084
-        $this->checkout->transaction->save();
2085
-        // grab TXN ID and save it to the primary_registration
2086
-        $primary_registration->set_transaction_id($this->checkout->transaction->ID());
2087
-        // save what we have so far
2088
-        $primary_registration->save();
2089
-        return true;
2090
-    }
2091
-
2092
-
2093
-    /**
2094
-     * _capture_primary_registration_data_from_billing_form
2095
-     *
2096
-     * @return bool
2097
-     * @throws EE_Error
2098
-     * @throws InvalidArgumentException
2099
-     * @throws ReflectionException
2100
-     * @throws InvalidDataTypeException
2101
-     * @throws InvalidInterfaceException
2102
-     */
2103
-    private function _capture_primary_registration_data_from_billing_form()
2104
-    {
2105
-        // convert billing form data into an attendee
2106
-        $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
2107
-        if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2108
-            EE_Error::add_error(
2109
-                sprintf(
2110
-                    esc_html__(
2111
-                        'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.',
2112
-                        'event_espresso'
2113
-                    ),
2114
-                    '<br/>',
2115
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2116
-                ),
2117
-                __FILE__,
2118
-                __FUNCTION__,
2119
-                __LINE__
2120
-            );
2121
-            return false;
2122
-        }
2123
-        $primary_registration = $this->checkout->transaction->primary_registration();
2124
-        if (! $primary_registration instanceof EE_Registration) {
2125
-            EE_Error::add_error(
2126
-                sprintf(
2127
-                    esc_html__(
2128
-                        'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2129
-                        'event_espresso'
2130
-                    ),
2131
-                    '<br/>',
2132
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2133
-                ),
2134
-                __FILE__,
2135
-                __FUNCTION__,
2136
-                __LINE__
2137
-            );
2138
-            return false;
2139
-        }
2140
-        if (
2141
-            ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee')
2142
-              instanceof
2143
-              EE_Attendee
2144
-        ) {
2145
-            EE_Error::add_error(
2146
-                sprintf(
2147
-                    esc_html__(
2148
-                        'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.',
2149
-                        'event_espresso'
2150
-                    ),
2151
-                    '<br/>',
2152
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2153
-                ),
2154
-                __FILE__,
2155
-                __FUNCTION__,
2156
-                __LINE__
2157
-            );
2158
-            return false;
2159
-        }
2160
-        /** @type EE_Registration_Processor $registration_processor */
2161
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
2162
-        // at this point, we should have enough details about the registrant to consider the registration NOT incomplete
2163
-        $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
2164
-        return true;
2165
-    }
2166
-
2167
-
2168
-    /**
2169
-     * _get_payment_method_for_selected_method_of_payment
2170
-     * retrieves a valid payment method
2171
-     *
2172
-     * @return EE_Payment_Method
2173
-     * @throws EE_Error
2174
-     * @throws InvalidArgumentException
2175
-     * @throws ReflectionException
2176
-     * @throws InvalidDataTypeException
2177
-     * @throws InvalidInterfaceException
2178
-     */
2179
-    private function _get_payment_method_for_selected_method_of_payment()
2180
-    {
2181
-        if ($this->checkout->selected_method_of_payment === 'events_sold_out') {
2182
-            $this->_redirect_because_event_sold_out();
2183
-            return null;
2184
-        }
2185
-        // get EE_Payment_Method object
2186
-        if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) {
2187
-            $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
2188
-        } else {
2189
-            // load EEM_Payment_Method
2190
-            EE_Registry::instance()->load_model('Payment_Method');
2191
-            $EEM_Payment_Method = EEM_Payment_Method::instance();
2192
-            $payment_method     = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2193
-        }
2194
-        // verify $payment_method
2195
-        if (! $payment_method instanceof EE_Payment_Method) {
2196
-            // not a payment
2197
-            EE_Error::add_error(
2198
-                sprintf(
2199
-                    esc_html__(
2200
-                        'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2201
-                        'event_espresso'
2202
-                    ),
2203
-                    '<br/>',
2204
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2205
-                ),
2206
-                __FILE__,
2207
-                __FUNCTION__,
2208
-                __LINE__
2209
-            );
2210
-            return null;
2211
-        }
2212
-        // and verify it has a valid Payment_Method Type object
2213
-        if (! $payment_method->type_obj() instanceof EE_PMT_Base) {
2214
-            // not a payment
2215
-            EE_Error::add_error(
2216
-                sprintf(
2217
-                    esc_html__(
2218
-                        'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2219
-                        'event_espresso'
2220
-                    ),
2221
-                    '<br/>',
2222
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2223
-                ),
2224
-                __FILE__,
2225
-                __FUNCTION__,
2226
-                __LINE__
2227
-            );
2228
-            return null;
2229
-        }
2230
-        return $payment_method;
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     *    _attempt_payment
2236
-     *
2237
-     * @access    private
2238
-     * @type    EE_Payment_Method $payment_method
2239
-     * @return mixed EE_Payment | boolean
2240
-     * @throws EE_Error
2241
-     * @throws InvalidArgumentException
2242
-     * @throws ReflectionException
2243
-     * @throws InvalidDataTypeException
2244
-     * @throws InvalidInterfaceException
2245
-     */
2246
-    private function _attempt_payment(EE_Payment_Method $payment_method)
2247
-    {
2248
-        $payment = null;
2249
-        $this->checkout->transaction->save();
2250
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2251
-        if (! $payment_processor instanceof EE_Payment_Processor) {
2252
-            return false;
2253
-        }
2254
-        try {
2255
-            $payment_processor->set_revisit($this->checkout->revisit);
2256
-            // generate payment object
2257
-            $payment = $payment_processor->process_payment(
2258
-                $payment_method,
2259
-                $this->checkout->transaction,
2260
-                $this->checkout->amount_owing,
2261
-                $this->checkout->billing_form instanceof EE_Billing_Info_Form
2262
-                    ? $this->checkout->billing_form
2263
-                    : null,
2264
-                $this->_get_return_url($payment_method),
2265
-                'CART',
2266
-                $this->checkout->admin_request,
2267
-                true,
2268
-                $this->reg_step_url()
2269
-            );
2270
-        } catch (Exception $e) {
2271
-            $this->_handle_payment_processor_exception($e);
2272
-        }
2273
-        return $payment;
2274
-    }
2275
-
2276
-
2277
-    /**
2278
-     * _handle_payment_processor_exception
2279
-     *
2280
-     * @param Exception $e
2281
-     * @return void
2282
-     * @throws EE_Error
2283
-     * @throws InvalidArgumentException
2284
-     * @throws InvalidDataTypeException
2285
-     * @throws InvalidInterfaceException
2286
-     */
2287
-    protected function _handle_payment_processor_exception(Exception $e)
2288
-    {
2289
-        EE_Error::add_error(
2290
-            sprintf(
2291
-                esc_html__(
2292
-                    'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s',
2293
-                    'event_espresso'
2294
-                ),
2295
-                '<br/>',
2296
-                EE_Registry::instance()->CFG->organization->get_pretty('email'),
2297
-                $e->getMessage(),
2298
-                $e->getFile(),
2299
-                $e->getLine()
2300
-            ),
2301
-            __FILE__,
2302
-            __FUNCTION__,
2303
-            __LINE__
2304
-        );
2305
-    }
2306
-
2307
-
2308
-    /**
2309
-     * _get_return_url
2310
-     *
2311
-     * @param EE_Payment_Method $payment_method
2312
-     * @return string
2313
-     * @throws EE_Error
2314
-     * @throws ReflectionException
2315
-     */
2316
-    protected function _get_return_url(EE_Payment_Method $payment_method)
2317
-    {
2318
-        $return_url = '';
2319
-        switch ($payment_method->type_obj()->payment_occurs()) {
2320
-            case EE_PMT_Base::offsite:
2321
-                $return_url = add_query_arg(
2322
-                    [
2323
-                        'action'                     => 'process_gateway_response',
2324
-                        'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2325
-                        'spco_txn'                   => $this->checkout->transaction->ID(),
2326
-                    ],
2327
-                    $this->reg_step_url()
2328
-                );
2329
-                break;
2330
-            case EE_PMT_Base::onsite:
2331
-            case EE_PMT_Base::offline:
2332
-                $return_url = $this->checkout->next_step->reg_step_url();
2333
-                break;
2334
-        }
2335
-        return $return_url;
2336
-    }
2337
-
2338
-
2339
-    /**
2340
-     * _validate_payment
2341
-     *
2342
-     * @param EE_Payment $payment
2343
-     * @return EE_Payment|FALSE
2344
-     * @throws EE_Error
2345
-     * @throws InvalidArgumentException
2346
-     * @throws InvalidDataTypeException
2347
-     * @throws InvalidInterfaceException
2348
-     */
2349
-    private function _validate_payment($payment = null)
2350
-    {
2351
-        if ($this->checkout->payment_method->is_off_line()) {
2352
-            return true;
2353
-        }
2354
-        // verify payment object
2355
-        if (! $payment instanceof EE_Payment) {
2356
-            // not a payment
2357
-            EE_Error::add_error(
2358
-                sprintf(
2359
-                    esc_html__(
2360
-                        'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.',
2361
-                        'event_espresso'
2362
-                    ),
2363
-                    '<br/>',
2364
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2365
-                ),
2366
-                __FILE__,
2367
-                __FUNCTION__,
2368
-                __LINE__
2369
-            );
2370
-            return false;
2371
-        }
2372
-        return $payment;
2373
-    }
2374
-
2375
-
2376
-    /**
2377
-     * _post_payment_processing
2378
-     *
2379
-     * @param EE_Payment|bool $payment
2380
-     * @return bool|EE_Payment
2381
-     * @throws EE_Error
2382
-     * @throws InvalidArgumentException
2383
-     * @throws InvalidDataTypeException
2384
-     * @throws InvalidInterfaceException
2385
-     * @throws ReflectionException
2386
-     */
2387
-    private function _post_payment_processing($payment = null)
2388
-    {
2389
-        // Off-Line payment?
2390
-        if ($payment === true) {
2391
-            return true;
2392
-        }
2393
-        if ($payment instanceof EE_Payment) {
2394
-            // Should the user be redirected?
2395
-            if ($payment->redirect_url()) {
2396
-                do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
2397
-                $this->checkout->redirect      = true;
2398
-                $this->checkout->redirect_form = $payment->redirect_form();
2399
-                $this->checkout->redirect_url  = $this->reg_step_url('redirect_form');
2400
-                // set JSON response
2401
-                $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
2402
-                // and lastly, let's bump the payment status to pending
2403
-                $payment->set_status(EEM_Payment::status_id_pending);
2404
-                $payment->save();
2405
-            } elseif (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2406
-                // User shouldn't be redirected. So let's process it here.
2407
-                // $this->_setup_redirect_for_next_step();
2408
-                $this->checkout->continue_reg = false;
2409
-            }
2410
-            return $payment;
2411
-        }
2412
-        // ummm ya... not Off-Line, not On-Site, not off-Site ????
2413
-        $this->checkout->continue_reg = false;
2414
-        return false;
2415
-    }
2416
-
2417
-
2418
-    /**
2419
-     *    _process_payment_status
2420
-     *
2421
-     * @type    EE_Payment $payment
2422
-     * @param string       $payment_occurs
2423
-     * @return bool
2424
-     * @throws EE_Error
2425
-     * @throws InvalidArgumentException
2426
-     * @throws InvalidDataTypeException
2427
-     * @throws InvalidInterfaceException
2428
-     */
2429
-    private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline)
2430
-    {
2431
-        // off-line payment? carry on
2432
-        if ($payment_occurs === EE_PMT_Base::offline) {
2433
-            return true;
2434
-        }
2435
-        // verify payment validity
2436
-        if ($payment instanceof EE_Payment) {
2437
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
2438
-            $msg = $payment->gateway_response();
2439
-            // check results
2440
-            switch ($payment->status()) {
2441
-                // good payment
2442
-                case EEM_Payment::status_id_approved:
2443
-                    EE_Error::add_success(
2444
-                        esc_html__('Your payment was processed successfully.', 'event_espresso'),
2445
-                        __FILE__,
2446
-                        __FUNCTION__,
2447
-                        __LINE__
2448
-                    );
2449
-                    return true;
2450
-                // slow payment
2451
-                case EEM_Payment::status_id_pending:
2452
-                    if (empty($msg)) {
2453
-                        $msg = esc_html__(
2454
-                            'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.',
2455
-                            'event_espresso'
2456
-                        );
2457
-                    }
2458
-                    EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
2459
-                    return true;
2460
-                // don't wanna payment
2461
-                case EEM_Payment::status_id_cancelled:
2462
-                    if (empty($msg)) {
2463
-                        $msg = _n(
2464
-                            'Payment cancelled. Please try again.',
2465
-                            'Payment cancelled. Please try again or select another method of payment.',
2466
-                            count($this->checkout->available_payment_methods),
2467
-                            'event_espresso'
2468
-                        );
2469
-                    }
2470
-                    EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2471
-                    return false;
2472
-                // not enough payment
2473
-                case EEM_Payment::status_id_declined:
2474
-                    if (empty($msg)) {
2475
-                        $msg = _n(
2476
-                            'We\'re sorry but your payment was declined. Please try again.',
2477
-                            'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
2478
-                            count($this->checkout->available_payment_methods),
2479
-                            'event_espresso'
2480
-                        );
2481
-                    }
2482
-                    EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2483
-                    return false;
2484
-                // bad payment
2485
-                case EEM_Payment::status_id_failed:
2486
-                    if (! empty($msg)) {
2487
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2488
-                        return false;
2489
-                    }
2490
-                    // default to error below
2491
-                    break;
2492
-            }
2493
-        }
2494
-        // off-site payment gateway responses are too unreliable, so let's just assume that
2495
-        // the payment processing is just running slower than the registrant's request
2496
-        if ($payment_occurs === EE_PMT_Base::offsite) {
2497
-            return true;
2498
-        }
2499
-        EE_Error::add_error(
2500
-            sprintf(
2501
-                esc_html__(
2502
-                    'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.',
2503
-                    'event_espresso'
2504
-                ),
2505
-                '<br/>',
2506
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
2507
-            ),
2508
-            __FILE__,
2509
-            __FUNCTION__,
2510
-            __LINE__
2511
-        );
2512
-        return false;
2513
-    }
2514
-
2515
-
2516
-
2517
-
2518
-
2519
-
2520
-    /********************************************************************************************************/
2521
-    /**********************************  PROCESS GATEWAY RESPONSE  **********************************/
2522
-    /********************************************************************************************************/
2523
-    /**
2524
-     * process_gateway_response
2525
-     * this is the return point for Off-Site Payment Methods
2526
-     * It will attempt to "handle the IPN" if it appears that this has not already occurred,
2527
-     * otherwise, it will load up the last payment made for the TXN.
2528
-     * If the payment retrieved looks good, it will then either:
2529
-     *    complete the current step and allow advancement to the next reg step
2530
-     *        or present the payment options again
2531
-     *
2532
-     * @return bool
2533
-     * @throws EE_Error
2534
-     * @throws InvalidArgumentException
2535
-     * @throws ReflectionException
2536
-     * @throws InvalidDataTypeException
2537
-     * @throws InvalidInterfaceException
2538
-     */
2539
-    public function process_gateway_response()
2540
-    {
2541
-        // how have they chosen to pay?
2542
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2543
-        // get EE_Payment_Method object
2544
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2545
-            $this->checkout->continue_reg = false;
2546
-            return false;
2547
-        }
2548
-        if (! $this->checkout->payment_method->is_off_site()) {
2549
-            return false;
2550
-        }
2551
-        $this->_validate_offsite_return();
2552
-        // verify TXN
2553
-        if ($this->checkout->transaction instanceof EE_Transaction) {
2554
-            $gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2555
-            if (! $gateway instanceof EE_Offsite_Gateway) {
2556
-                $this->checkout->continue_reg = false;
2557
-                return false;
2558
-            }
2559
-            $payment = $this->_process_off_site_payment($gateway);
2560
-            $payment = $this->_process_cancelled_payments($payment);
2561
-            $payment = $this->_validate_payment($payment);
2562
-            // if payment was not declined by the payment gateway or cancelled by the registrant
2563
-            if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
2564
-                // $this->_setup_redirect_for_next_step();
2565
-                // store that for later
2566
-                $this->checkout->payment = $payment;
2567
-                // mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2568
-                // because we will complete this step during the IPN processing then
2569
-                if (! $this->handle_IPN_in_this_request()) {
2570
-                    $this->set_completed();
2571
-                }
2572
-                return true;
2573
-            }
2574
-        }
2575
-        // DEBUG LOG
2576
-        // $this->checkout->log(
2577
-        //     __CLASS__,
2578
-        //     __FUNCTION__,
2579
-        //     __LINE__,
2580
-        //     array('payment' => $payment)
2581
-        // );
2582
-        $this->checkout->continue_reg = false;
2583
-        return false;
2584
-    }
2585
-
2586
-
2587
-    /**
2588
-     * _validate_return
2589
-     *
2590
-     * @return void
2591
-     * @throws EE_Error
2592
-     * @throws InvalidArgumentException
2593
-     * @throws InvalidDataTypeException
2594
-     * @throws InvalidInterfaceException
2595
-     * @throws ReflectionException
2596
-     */
2597
-    private function _validate_offsite_return()
2598
-    {
2599
-        $TXN_ID = $this->request->getRequestParam('spco_txn', 0, 'int');
2600
-        if ($TXN_ID !== $this->checkout->transaction->ID()) {
2601
-            // Houston... we might have a problem
2602
-            $invalid_TXN = false;
2603
-            // first gather some info
2604
-            $valid_TXN          = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2605
-            $primary_registrant = $valid_TXN instanceof EE_Transaction
2606
-                ? $valid_TXN->primary_registration()
2607
-                : null;
2608
-            // let's start by retrieving the cart for this TXN
2609
-            $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction);
2610
-            if ($cart instanceof EE_Cart) {
2611
-                // verify that the current cart has tickets
2612
-                $tickets = $cart->get_tickets();
2613
-                if (empty($tickets)) {
2614
-                    $invalid_TXN = true;
2615
-                }
2616
-            } else {
2617
-                $invalid_TXN = true;
2618
-            }
2619
-            $valid_TXN_SID = $primary_registrant instanceof EE_Registration
2620
-                ? $primary_registrant->session_ID()
2621
-                : null;
2622
-            // validate current Session ID and compare against valid TXN session ID
2623
-            if (
2624
-                $invalid_TXN // if this is already true, then skip other checks
2625
-                || EE_Session::instance()->id() === null
2626
-                || (
2627
-                    // WARNING !!!
2628
-                    // this could be PayPal sending back duplicate requests (ya they do that)
2629
-                    // or it **could** mean someone is simply registering AGAIN after having just done so
2630
-                    // so now we need to determine if this current TXN looks valid or not
2631
-                    // and whether this reg step has even been started ?
2632
-                    EE_Session::instance()->id() === $valid_TXN_SID
2633
-                    // really? you're half way through this reg step, but you never started it ?
2634
-                    && $this->checkout->transaction->reg_step_completed($this->slug()) === false
2635
-                )
2636
-            ) {
2637
-                $invalid_TXN = true;
2638
-            }
2639
-            if ($invalid_TXN) {
2640
-                // is the valid TXN completed ?
2641
-                if ($valid_TXN instanceof EE_Transaction) {
2642
-                    // has this step even been started ?
2643
-                    $reg_step_completed = $valid_TXN->reg_step_completed($this->slug());
2644
-                    if ($reg_step_completed !== false && $reg_step_completed !== true) {
2645
-                        // so it **looks** like this is a double request from PayPal
2646
-                        // so let's try to pick up where we left off
2647
-                        $this->checkout->transaction = $valid_TXN;
2648
-                        $this->checkout->refresh_all_entities(true);
2649
-                        return;
2650
-                    }
2651
-                }
2652
-                // you appear to be lost?
2653
-                $this->_redirect_wayward_request($primary_registrant);
2654
-            }
2655
-        }
2656
-    }
2657
-
2658
-
2659
-    /**
2660
-     * _redirect_wayward_request
2661
-     *
2662
-     * @param EE_Registration|null $primary_registrant
2663
-     * @return void
2664
-     * @throws EE_Error
2665
-     * @throws InvalidArgumentException
2666
-     * @throws InvalidDataTypeException
2667
-     * @throws InvalidInterfaceException
2668
-     * @throws ReflectionException
2669
-     */
2670
-    private function _redirect_wayward_request(EE_Registration $primary_registrant)
2671
-    {
2672
-        if (! $primary_registrant instanceof EE_Registration) {
2673
-            // try redirecting based on the current TXN
2674
-            $primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2675
-                ? $this->checkout->transaction->primary_registration()
2676
-                : null;
2677
-        }
2678
-        if (! $primary_registrant instanceof EE_Registration) {
2679
-            EE_Error::add_error(
2680
-                sprintf(
2681
-                    esc_html__(
2682
-                        'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.',
2683
-                        'event_espresso'
2684
-                    ),
2685
-                    '<br/>',
2686
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2687
-                ),
2688
-                __FILE__,
2689
-                __FUNCTION__,
2690
-                __LINE__
2691
-            );
2692
-            return;
2693
-        }
2694
-        // make sure transaction is not locked
2695
-        $this->checkout->transaction->unlock();
2696
-        wp_safe_redirect(
2697
-            add_query_arg(
2698
-                [
2699
-                    'e_reg_url_link' => $primary_registrant->reg_url_link(),
2700
-                ],
2701
-                $this->checkout->thank_you_page_url
2702
-            )
2703
-        );
2704
-        exit();
2705
-    }
2706
-
2707
-
2708
-    /**
2709
-     * _process_off_site_payment
2710
-     *
2711
-     * @param EE_Offsite_Gateway $gateway
2712
-     * @return EE_Payment
2713
-     * @throws EE_Error
2714
-     * @throws InvalidArgumentException
2715
-     * @throws InvalidDataTypeException
2716
-     * @throws InvalidInterfaceException
2717
-     * @throws ReflectionException
2718
-     */
2719
-    private function _process_off_site_payment(EE_Offsite_Gateway $gateway)
2720
-    {
2721
-        try {
2722
-            $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
2723
-            $request_data = $request->requestParams();
2724
-            // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
2725
-            $this->set_handle_IPN_in_this_request(
2726
-                $gateway->handle_IPN_in_this_request($request_data, false)
2727
-            );
2728
-            if ($this->handle_IPN_in_this_request()) {
2729
-                // get payment details and process results
2730
-                /** @type EE_Payment_Processor $payment_processor */
2731
-                $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2732
-                $payment           = $payment_processor->process_ipn(
2733
-                    $request_data,
2734
-                    $this->checkout->transaction,
2735
-                    $this->checkout->payment_method,
2736
-                    true,
2737
-                    false
2738
-                );
2739
-                // $payment_source = 'process_ipn';
2740
-            } else {
2741
-                $payment = $this->checkout->transaction->last_payment();
2742
-                // $payment_source = 'last_payment';
2743
-            }
2744
-        } catch (Exception $e) {
2745
-            // let's just eat the exception and try to move on using any previously set payment info
2746
-            $payment = $this->checkout->transaction->last_payment();
2747
-            // $payment_source = 'last_payment after Exception';
2748
-            // but if we STILL don't have a payment object
2749
-            if (! $payment instanceof EE_Payment) {
2750
-                // then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2751
-                $this->_handle_payment_processor_exception($e);
2752
-            }
2753
-        }
2754
-        return $payment;
2755
-    }
2756
-
2757
-
2758
-    /**
2759
-     * _process_cancelled_payments
2760
-     * just makes sure that the payment status gets updated correctly
2761
-     * so tha tan error isn't generated during payment validation
2762
-     *
2763
-     * @param EE_Payment $payment
2764
-     * @return EE_Payment|null
2765
-     * @throws EE_Error
2766
-     */
2767
-    private function _process_cancelled_payments($payment = null)
2768
-    {
2769
-        if (
2770
-            $payment instanceof EE_Payment
2771
-            && $this->request->requestParamIsSet('ee_cancel_payment')
2772
-            && $payment->status() === EEM_Payment::status_id_failed
2773
-        ) {
2774
-            $payment->set_status(EEM_Payment::status_id_cancelled);
2775
-        }
2776
-        return $payment;
2777
-    }
2778
-
2779
-
2780
-    /**
2781
-     *    get_transaction_details_for_gateways
2782
-     *
2783
-     * @access    public
2784
-     * @return void
2785
-     * @throws EE_Error
2786
-     * @throws InvalidArgumentException
2787
-     * @throws ReflectionException
2788
-     * @throws InvalidDataTypeException
2789
-     * @throws InvalidInterfaceException
2790
-     */
2791
-    public function get_transaction_details_for_gateways()
2792
-    {
2793
-        $txn_details = [];
2794
-        // ya gotta make a choice man
2795
-        if (empty($this->checkout->selected_method_of_payment)) {
2796
-            $txn_details = [
2797
-                'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'),
2798
-            ];
2799
-        }
2800
-        // get EE_Payment_Method object
2801
-        if (
2802
-            empty($txn_details)
2803
-            && ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2804
-        ) {
2805
-            $txn_details = [
2806
-                'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2807
-                'error'                      => esc_html__(
2808
-                    'A valid Payment Method could not be determined.',
2809
-                    'event_espresso'
2810
-                ),
2811
-            ];
2812
-        }
2813
-        if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2814
-            $return_url  = $this->_get_return_url($this->checkout->payment_method);
2815
-            $txn_details = [
2816
-                'TXN_ID'         => $this->checkout->transaction->ID(),
2817
-                'TXN_timestamp'  => $this->checkout->transaction->datetime(),
2818
-                'TXN_total'      => $this->checkout->transaction->total(),
2819
-                'TXN_paid'       => $this->checkout->transaction->paid(),
2820
-                'TXN_reg_steps'  => $this->checkout->transaction->reg_steps(),
2821
-                'STS_ID'         => $this->checkout->transaction->status_ID(),
2822
-                'PMD_ID'         => $this->checkout->transaction->payment_method_ID(),
2823
-                'payment_amount' => $this->checkout->amount_owing,
2824
-                'return_url'     => $return_url,
2825
-                'cancel_url'     => add_query_arg(['ee_cancel_payment' => true], $return_url),
2826
-                'notify_url'     => EE_Config::instance()->core->txn_page_url(
2827
-                    [
2828
-                        'e_reg_url_link'    => $this->checkout->transaction->primary_registration()->reg_url_link(),
2829
-                        'ee_payment_method' => $this->checkout->payment_method->slug(),
2830
-                    ]
2831
-                ),
2832
-            ];
2833
-        }
2834
-        echo wp_json_encode($txn_details);
2835
-        exit();
2836
-    }
2837
-
2838
-
2839
-    /**
2840
-     *    __sleep
2841
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
2842
-     * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
2843
-     * reg form, because if needed, it will be regenerated anyways
2844
-     *
2845
-     * @return array
2846
-     */
2847
-    public function __sleep()
2848
-    {
2849
-        // remove the reg form and the checkout
2850
-        return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout', 'line_item_display']);
2851
-    }
22
+	/**
23
+	 * @var EE_Line_Item_Display $Line_Item_Display
24
+	 */
25
+	protected $line_item_display;
26
+
27
+	/**
28
+	 * @var boolean $handle_IPN_in_this_request
29
+	 */
30
+	protected $handle_IPN_in_this_request = false;
31
+
32
+
33
+	/**
34
+	 *    set_hooks - for hooking into EE Core, other modules, etc
35
+	 *
36
+	 * @access    public
37
+	 * @return    void
38
+	 */
39
+	public static function set_hooks()
40
+	{
41
+		add_filter(
42
+			'FHEE__SPCO__EE_Line_Item_Filter_Collection',
43
+			['EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters']
44
+		);
45
+		add_action(
46
+			'wp_ajax_switch_spco_billing_form',
47
+			['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form']
48
+		);
49
+		add_action(
50
+			'wp_ajax_nopriv_switch_spco_billing_form',
51
+			['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form']
52
+		);
53
+		add_action('wp_ajax_save_payer_details', ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']);
54
+		add_action(
55
+			'wp_ajax_nopriv_save_payer_details',
56
+			['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']
57
+		);
58
+		add_action(
59
+			'wp_ajax_get_transaction_details_for_gateways',
60
+			['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details']
61
+		);
62
+		add_action(
63
+			'wp_ajax_nopriv_get_transaction_details_for_gateways',
64
+			['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details']
65
+		);
66
+		add_filter(
67
+			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
68
+			['EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'],
69
+			10,
70
+			1
71
+		);
72
+	}
73
+
74
+
75
+	/**
76
+	 *    ajax switch_spco_billing_form
77
+	 *
78
+	 */
79
+	public static function switch_spco_billing_form()
80
+	{
81
+		EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
82
+	}
83
+
84
+
85
+	/**
86
+	 *    ajax save_payer_details
87
+	 *
88
+	 */
89
+	public static function save_payer_details()
90
+	{
91
+		EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
92
+	}
93
+
94
+
95
+	/**
96
+	 *    ajax get_transaction_details
97
+	 *
98
+	 */
99
+	public static function get_transaction_details()
100
+	{
101
+		EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
102
+	}
103
+
104
+
105
+	/**
106
+	 * bypass_recaptcha_for_load_payment_method
107
+	 *
108
+	 * @access public
109
+	 * @return array
110
+	 * @throws InvalidArgumentException
111
+	 * @throws InvalidDataTypeException
112
+	 * @throws InvalidInterfaceException
113
+	 */
114
+	public static function bypass_recaptcha_for_load_payment_method()
115
+	{
116
+		return [
117
+			'EESID'  => EE_Registry::instance()->SSN->id(),
118
+			'step'   => 'payment_options',
119
+			'action' => 'spco_billing_form',
120
+		];
121
+	}
122
+
123
+
124
+	/**
125
+	 *    class constructor
126
+	 *
127
+	 * @access    public
128
+	 * @param EE_Checkout $checkout
129
+	 */
130
+	public function __construct(EE_Checkout $checkout)
131
+	{
132
+		$this->request   = EED_Single_Page_Checkout::getRequest();
133
+		$this->_slug     = 'payment_options';
134
+		$this->_name     = esc_html__('Payment Options', 'event_espresso');
135
+		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php';
136
+		$this->checkout  = $checkout;
137
+		$this->_reset_success_message();
138
+		$this->set_instructions(
139
+			esc_html__(
140
+				'Please select a method of payment and provide any necessary billing information before proceeding.',
141
+				'event_espresso'
142
+			)
143
+		);
144
+	}
145
+
146
+
147
+	/**
148
+	 * @return null
149
+	 */
150
+	public function line_item_display()
151
+	{
152
+		return $this->line_item_display;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @param null $line_item_display
158
+	 */
159
+	public function set_line_item_display($line_item_display)
160
+	{
161
+		$this->line_item_display = $line_item_display;
162
+	}
163
+
164
+
165
+	/**
166
+	 * @return boolean
167
+	 */
168
+	public function handle_IPN_in_this_request()
169
+	{
170
+		return $this->handle_IPN_in_this_request;
171
+	}
172
+
173
+
174
+	/**
175
+	 * @param boolean $handle_IPN_in_this_request
176
+	 */
177
+	public function set_handle_IPN_in_this_request($handle_IPN_in_this_request)
178
+	{
179
+		$this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
180
+	}
181
+
182
+
183
+	/**
184
+	 * translate_js_strings
185
+	 *
186
+	 * @return void
187
+	 */
188
+	public function translate_js_strings()
189
+	{
190
+		EE_Registry::$i18n_js_strings['no_payment_method']      = esc_html__(
191
+			'Please select a method of payment in order to continue.',
192
+			'event_espresso'
193
+		);
194
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
195
+			'A valid method of payment could not be determined. Please refresh the page and try again.',
196
+			'event_espresso'
197
+		);
198
+		EE_Registry::$i18n_js_strings['forwarding_to_offsite']  = esc_html__(
199
+			'Forwarding to Secure Payment Provider.',
200
+			'event_espresso'
201
+		);
202
+	}
203
+
204
+
205
+	/**
206
+	 * enqueue_styles_and_scripts
207
+	 *
208
+	 * @return void
209
+	 * @throws EE_Error
210
+	 * @throws InvalidArgumentException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidInterfaceException
213
+	 * @throws ReflectionException
214
+	 */
215
+	public function enqueue_styles_and_scripts()
216
+	{
217
+		$transaction = $this->checkout->transaction;
218
+		// if the transaction isn't set or nothing is owed on it, don't enqueue any JS
219
+		if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
220
+			return;
221
+		}
222
+		foreach (
223
+			EEM_Payment_Method::instance()->get_all_for_transaction(
224
+				$transaction,
225
+				EEM_Payment_Method::scope_cart
226
+			) as $payment_method
227
+		) {
228
+			$type_obj = $payment_method->type_obj();
229
+			if ($type_obj instanceof EE_PMT_Base) {
230
+				$billing_form = $type_obj->generate_new_billing_form($transaction);
231
+				if ($billing_form instanceof EE_Form_Section_Proper) {
232
+					$billing_form->enqueue_js();
233
+				}
234
+			}
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * initialize_reg_step
241
+	 *
242
+	 * @return bool
243
+	 * @throws EE_Error
244
+	 * @throws InvalidArgumentException
245
+	 * @throws ReflectionException
246
+	 * @throws InvalidDataTypeException
247
+	 * @throws InvalidInterfaceException
248
+	 */
249
+	public function initialize_reg_step()
250
+	{
251
+		// TODO: if /when we implement donations, then this will need overriding
252
+		if (
253
+			// don't need payment options for:
254
+			// registrations made via the admin
255
+			// completed transactions
256
+			// overpaid transactions
257
+			// $ 0.00 transactions(no payment required)
258
+			! $this->checkout->payment_required()
259
+			// but do NOT remove if current action being called belongs to this reg step
260
+			&& ! is_callable([$this, $this->checkout->action])
261
+			&& ! $this->completed()
262
+		) {
263
+			// and if so, then we no longer need the Payment Options step
264
+			if ($this->is_current_step()) {
265
+				$this->checkout->generate_reg_form = false;
266
+			}
267
+			$this->checkout->remove_reg_step($this->_slug);
268
+			// DEBUG LOG
269
+			// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
270
+			return false;
271
+		}
272
+		// load EEM_Payment_Method
273
+		EE_Registry::instance()->load_model('Payment_Method');
274
+		// get all active payment methods
275
+		$this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
276
+			$this->checkout->transaction,
277
+			EEM_Payment_Method::scope_cart
278
+		);
279
+		return true;
280
+	}
281
+
282
+
283
+	/**
284
+	 * @return EE_Form_Section_Proper
285
+	 * @throws EE_Error
286
+	 * @throws InvalidArgumentException
287
+	 * @throws ReflectionException
288
+	 * @throws EntityNotFoundException
289
+	 * @throws InvalidDataTypeException
290
+	 * @throws InvalidInterfaceException
291
+	 * @throws InvalidStatusException
292
+	 */
293
+	public function generate_reg_form()
294
+	{
295
+		// reset in case someone changes their mind
296
+		$this->_reset_selected_method_of_payment();
297
+		// set some defaults
298
+		$this->checkout->selected_method_of_payment = 'payments_closed';
299
+		$registrations_requiring_payment            = [];
300
+		$registrations_for_free_events              = [];
301
+		$registrations_requiring_pre_approval       = [];
302
+		$sold_out_events                            = [];
303
+		$insufficient_spaces_available              = [];
304
+		$no_payment_required                        = true;
305
+		// loop thru registrations to gather info
306
+		$registrations         = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
307
+		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
308
+			$registrations,
309
+			$this->checkout->revisit
310
+		);
311
+		foreach ($registrations as $REG_ID => $registration) {
312
+			/** @var $registration EE_Registration */
313
+			// has this registration lost it's space ?
314
+			if (isset($ejected_registrations[ $REG_ID ])) {
315
+				if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) {
316
+					$sold_out_events[ $registration->event()->ID() ] = $registration->event();
317
+				} else {
318
+					$insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
319
+				}
320
+				continue;
321
+			}
322
+			// event requires admin approval
323
+			if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
324
+				// add event to list of events with pre-approval reg status
325
+				$registrations_requiring_pre_approval[ $REG_ID ] = $registration;
326
+				do_action(
327
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
328
+					$registration->event(),
329
+					$this
330
+				);
331
+				continue;
332
+			}
333
+			if (
334
+				$this->checkout->revisit
335
+				&& $registration->status_ID() !== EEM_Registration::status_id_approved
336
+				&& (
337
+					$registration->event()->is_sold_out()
338
+					|| $registration->event()->is_sold_out(true)
339
+				)
340
+			) {
341
+				// add event to list of events that are sold out
342
+				$sold_out_events[ $registration->event()->ID() ] = $registration->event();
343
+				do_action(
344
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
345
+					$registration->event(),
346
+					$this
347
+				);
348
+				continue;
349
+			}
350
+			// are they allowed to pay now and is there monies owing?
351
+			if ($registration->owes_monies_and_can_pay()) {
352
+				$registrations_requiring_payment[ $REG_ID ] = $registration;
353
+				do_action(
354
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
355
+					$registration->event(),
356
+					$this
357
+				);
358
+			} elseif (
359
+				! $this->checkout->revisit
360
+					  && $registration->status_ID() !== EEM_Registration::status_id_not_approved
361
+					  && $registration->ticket()->is_free()
362
+			) {
363
+				$registrations_for_free_events[ $registration->ticket()->ID() ] = $registration;
364
+			}
365
+		}
366
+		$subsections = [];
367
+		// now decide which template to load
368
+		if (! empty($sold_out_events)) {
369
+			$subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
370
+		}
371
+		if (! empty($insufficient_spaces_available)) {
372
+			$subsections['insufficient_space'] = $this->_insufficient_spaces_available(
373
+				$insufficient_spaces_available
374
+			);
375
+		}
376
+		if (! empty($registrations_requiring_pre_approval)) {
377
+			$subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
378
+				$registrations_requiring_pre_approval
379
+			);
380
+		}
381
+		if (! empty($registrations_for_free_events)) {
382
+			$subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
383
+		}
384
+		if (! empty($registrations_requiring_payment)) {
385
+			if ($this->checkout->amount_owing > 0) {
386
+				// autoload Line_Item_Display classes
387
+				EEH_Autoloader::register_line_item_filter_autoloaders();
388
+				$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
389
+					apply_filters(
390
+						'FHEE__SPCO__EE_Line_Item_Filter_Collection',
391
+						new EE_Line_Item_Filter_Collection()
392
+					),
393
+					$this->checkout->cart->get_grand_total()
394
+				);
395
+				/** @var EE_Line_Item $filtered_line_item_tree */
396
+				$filtered_line_item_tree = $line_item_filter_processor->process();
397
+				EEH_Autoloader::register_line_item_display_autoloaders();
398
+				$this->set_line_item_display(new EE_Line_Item_Display('spco'));
399
+				$subsections['payment_options'] = $this->_display_payment_options(
400
+					$this->line_item_display->display_line_item(
401
+						$filtered_line_item_tree,
402
+						['registrations' => $registrations]
403
+					)
404
+				);
405
+				$this->checkout->amount_owing   = $filtered_line_item_tree->total();
406
+				$this->_apply_registration_payments_to_amount_owing($registrations);
407
+			}
408
+			$no_payment_required = false;
409
+		} else {
410
+			$this->_hide_reg_step_submit_button_if_revisit();
411
+		}
412
+		$this->_save_selected_method_of_payment();
413
+
414
+		$subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
415
+		$subsections['extra_hidden_inputs']   = $this->_extra_hidden_inputs($no_payment_required);
416
+
417
+		return new EE_Form_Section_Proper(
418
+			[
419
+				'name'            => $this->reg_form_name(),
420
+				'html_id'         => $this->reg_form_name(),
421
+				'subsections'     => $subsections,
422
+				'layout_strategy' => new EE_No_Layout(),
423
+			]
424
+		);
425
+	}
426
+
427
+
428
+	/**
429
+	 * add line item filters required for this reg step
430
+	 * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks():
431
+	 *        add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options',
432
+	 *        'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the
433
+	 *        payment options reg step, can apply these filters via the following: apply_filters(
434
+	 *        'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing
435
+	 *        filter collection by passing that instead of instantiating a new collection
436
+	 *
437
+	 * @param EE_Line_Item_Filter_Collection $line_item_filter_collection
438
+	 * @return EE_Line_Item_Filter_Collection
439
+	 * @throws EE_Error
440
+	 * @throws InvalidArgumentException
441
+	 * @throws ReflectionException
442
+	 * @throws EntityNotFoundException
443
+	 * @throws InvalidDataTypeException
444
+	 * @throws InvalidInterfaceException
445
+	 * @throws InvalidStatusException
446
+	 */
447
+	public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection)
448
+	{
449
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
450
+			return $line_item_filter_collection;
451
+		}
452
+		if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
453
+			return $line_item_filter_collection;
454
+		}
455
+		if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
456
+			return $line_item_filter_collection;
457
+		}
458
+		$line_item_filter_collection->add(
459
+			new EE_Billable_Line_Item_Filter(
460
+				EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations(
461
+					EE_Registry::instance()->SSN->checkout()->transaction->registrations(
462
+						EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
463
+					)
464
+				)
465
+			)
466
+		);
467
+		$line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
468
+		return $line_item_filter_collection;
469
+	}
470
+
471
+
472
+	/**
473
+	 * remove_ejected_registrations
474
+	 * if a registrant has lost their potential space at an event due to lack of payment,
475
+	 * then this method removes them from the list of registrations being paid for during this request
476
+	 *
477
+	 * @param EE_Registration[] $registrations
478
+	 * @return EE_Registration[]
479
+	 * @throws EE_Error
480
+	 * @throws InvalidArgumentException
481
+	 * @throws ReflectionException
482
+	 * @throws EntityNotFoundException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 * @throws InvalidStatusException
486
+	 */
487
+	public static function remove_ejected_registrations(array $registrations)
488
+	{
489
+		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
490
+			$registrations,
491
+			EE_Registry::instance()->SSN->checkout()->revisit
492
+		);
493
+		foreach ($registrations as $REG_ID => $registration) {
494
+			// has this registration lost it's space ?
495
+			if (isset($ejected_registrations[ $REG_ID ])) {
496
+				unset($registrations[ $REG_ID ]);
497
+			}
498
+		}
499
+		return $registrations;
500
+	}
501
+
502
+
503
+	/**
504
+	 * find_registrations_that_lost_their_space
505
+	 * If a registrant chooses an offline payment method like Invoice,
506
+	 * then no space is reserved for them at the event until they fully pay fo that site
507
+	 * (unless the event's default reg status is set to APPROVED)
508
+	 * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales,
509
+	 * then this method will determine which registrations have lost the ability to complete the reg process.
510
+	 *
511
+	 * @param EE_Registration[] $registrations
512
+	 * @param bool              $revisit
513
+	 * @return array
514
+	 * @throws EE_Error
515
+	 * @throws InvalidArgumentException
516
+	 * @throws ReflectionException
517
+	 * @throws EntityNotFoundException
518
+	 * @throws InvalidDataTypeException
519
+	 * @throws InvalidInterfaceException
520
+	 * @throws InvalidStatusException
521
+	 */
522
+	public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false)
523
+	{
524
+		// registrations per event
525
+		$event_reg_count = [];
526
+		// spaces left per event
527
+		$event_spaces_remaining = [];
528
+		// tickets left sorted by ID
529
+		$tickets_remaining = [];
530
+		// registrations that have lost their space
531
+		$ejected_registrations = [];
532
+		foreach ($registrations as $REG_ID => $registration) {
533
+			if (
534
+				$registration->status_ID() === EEM_Registration::status_id_approved
535
+				|| apply_filters(
536
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
537
+					false,
538
+					$registration,
539
+					$revisit
540
+				)
541
+			) {
542
+				continue;
543
+			}
544
+			$EVT_ID = $registration->event_ID();
545
+			$ticket = $registration->ticket();
546
+			if (! isset($tickets_remaining[ $ticket->ID() ])) {
547
+				$tickets_remaining[ $ticket->ID() ] = $ticket->remaining();
548
+			}
549
+			if ($tickets_remaining[ $ticket->ID() ] > 0) {
550
+				if (! isset($event_reg_count[ $EVT_ID ])) {
551
+					$event_reg_count[ $EVT_ID ] = 0;
552
+				}
553
+				$event_reg_count[ $EVT_ID ]++;
554
+				if (! isset($event_spaces_remaining[ $EVT_ID ])) {
555
+					$event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale();
556
+				}
557
+			}
558
+			if (
559
+				$revisit
560
+				&& ($tickets_remaining[ $ticket->ID() ] === 0
561
+					|| $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
562
+				)
563
+			) {
564
+				$ejected_registrations[ $REG_ID ] = $registration->event();
565
+				if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
566
+					/** @type EE_Registration_Processor $registration_processor */
567
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
568
+					// at this point, we should have enough details about the registrant to consider the registration
569
+					// NOT incomplete
570
+					$registration_processor->manually_update_registration_status(
571
+						$registration,
572
+						EEM_Registration::status_id_wait_list
573
+					);
574
+				}
575
+			}
576
+		}
577
+		return $ejected_registrations;
578
+	}
579
+
580
+
581
+	/**
582
+	 * _hide_reg_step_submit_button
583
+	 * removes the html for the reg step submit button
584
+	 * by replacing it with an empty string via filter callback
585
+	 *
586
+	 * @return void
587
+	 */
588
+	protected function _adjust_registration_status_if_event_old_sold()
589
+	{
590
+	}
591
+
592
+
593
+	/**
594
+	 * _hide_reg_step_submit_button
595
+	 * removes the html for the reg step submit button
596
+	 * by replacing it with an empty string via filter callback
597
+	 *
598
+	 * @return void
599
+	 */
600
+	protected function _hide_reg_step_submit_button_if_revisit()
601
+	{
602
+		if ($this->checkout->revisit) {
603
+			add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
604
+		}
605
+	}
606
+
607
+
608
+	/**
609
+	 * sold_out_events
610
+	 * displays notices regarding events that have sold out since hte registrant first signed up
611
+	 *
612
+	 * @param EE_Event[] $sold_out_events_array
613
+	 * @return EE_Form_Section_Proper
614
+	 * @throws EE_Error
615
+	 */
616
+	private function _sold_out_events($sold_out_events_array = [])
617
+	{
618
+		// set some defaults
619
+		$this->checkout->selected_method_of_payment = 'events_sold_out';
620
+		$sold_out_events                            = '';
621
+		foreach ($sold_out_events_array as $sold_out_event) {
622
+			$sold_out_events .= EEH_HTML::li(
623
+				EEH_HTML::span(
624
+					'  ' . $sold_out_event->name(),
625
+					'',
626
+					'dashicons dashicons-marker ee-icon-size-16 pink-text'
627
+				)
628
+			);
629
+		}
630
+		return new EE_Form_Section_Proper(
631
+			[
632
+				'layout_strategy' => new EE_Template_Layout(
633
+					[
634
+						'layout_template_file' => SPCO_REG_STEPS_PATH
635
+												  . $this->_slug
636
+												  . '/sold_out_events.template.php',
637
+						'template_args'        => apply_filters(
638
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
639
+							[
640
+								'sold_out_events'     => $sold_out_events,
641
+								'sold_out_events_msg' => apply_filters(
642
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
643
+									sprintf(
644
+										esc_html__(
645
+											'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s',
646
+											'event_espresso'
647
+										),
648
+										'<strong>',
649
+										'</strong>',
650
+										'<br />'
651
+									)
652
+								),
653
+							]
654
+						),
655
+					]
656
+				),
657
+			]
658
+		);
659
+	}
660
+
661
+
662
+	/**
663
+	 * _insufficient_spaces_available
664
+	 * displays notices regarding events that do not have enough remaining spaces
665
+	 * to satisfy the current number of registrations looking to pay
666
+	 *
667
+	 * @param EE_Event[] $insufficient_spaces_events_array
668
+	 * @return EE_Form_Section_Proper
669
+	 * @throws EE_Error
670
+	 * @throws ReflectionException
671
+	 */
672
+	private function _insufficient_spaces_available($insufficient_spaces_events_array = [])
673
+	{
674
+		// set some defaults
675
+		$this->checkout->selected_method_of_payment = 'invoice';
676
+		$insufficient_space_events                  = '';
677
+		foreach ($insufficient_spaces_events_array as $event) {
678
+			if ($event instanceof EE_Event) {
679
+				$insufficient_space_events .= EEH_HTML::li(
680
+					EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
681
+				);
682
+			}
683
+		}
684
+		return new EE_Form_Section_Proper(
685
+			[
686
+				'subsections'     => [
687
+					'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
688
+					'extra_hidden_inputs'   => $this->_extra_hidden_inputs(),
689
+				],
690
+				'layout_strategy' => new EE_Template_Layout(
691
+					[
692
+						'layout_template_file' => SPCO_REG_STEPS_PATH
693
+												  . $this->_slug
694
+												  . '/sold_out_events.template.php',
695
+						'template_args'        => apply_filters(
696
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args',
697
+							[
698
+								'sold_out_events'     => $insufficient_space_events,
699
+								'sold_out_events_msg' => apply_filters(
700
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg',
701
+									esc_html__(
702
+										'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
703
+										'event_espresso'
704
+									)
705
+								),
706
+							]
707
+						),
708
+					]
709
+				),
710
+			]
711
+		);
712
+	}
713
+
714
+
715
+	/**
716
+	 * registrations_requiring_pre_approval
717
+	 *
718
+	 * @param array $registrations_requiring_pre_approval
719
+	 * @return EE_Form_Section_Proper
720
+	 * @throws EE_Error
721
+	 * @throws EntityNotFoundException
722
+	 * @throws ReflectionException
723
+	 */
724
+	private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = [])
725
+	{
726
+		$events_requiring_pre_approval = [];
727
+		foreach ($registrations_requiring_pre_approval as $registration) {
728
+			if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
729
+				$events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
730
+					EEH_HTML::span(
731
+						'',
732
+						'',
733
+						'dashicons dashicons-marker ee-icon-size-16 orange-text'
734
+					)
735
+					. EEH_HTML::span($registration->event()->name(), '', 'orange-text')
736
+				);
737
+			}
738
+		}
739
+		return new EE_Form_Section_Proper(
740
+			[
741
+				'layout_strategy' => new EE_Template_Layout(
742
+					[
743
+						'layout_template_file' => SPCO_REG_STEPS_PATH
744
+												  . $this->_slug
745
+												  . '/events_requiring_pre_approval.template.php', // layout_template
746
+						'template_args'        => apply_filters(
747
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
748
+							[
749
+								'events_requiring_pre_approval'     => implode('', $events_requiring_pre_approval),
750
+								'events_requiring_pre_approval_msg' => apply_filters(
751
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
752
+									esc_html__(
753
+										'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
754
+										'event_espresso'
755
+									)
756
+								),
757
+							]
758
+						),
759
+					]
760
+				),
761
+			]
762
+		);
763
+	}
764
+
765
+
766
+	/**
767
+	 * _no_payment_required
768
+	 *
769
+	 * @param EE_Event[] $registrations_for_free_events
770
+	 * @return EE_Form_Section_Proper
771
+	 * @throws EE_Error
772
+	 */
773
+	private function _no_payment_required($registrations_for_free_events = [])
774
+	{
775
+		// set some defaults
776
+		$this->checkout->selected_method_of_payment = 'no_payment_required';
777
+		// generate no_payment_required form
778
+		return new EE_Form_Section_Proper(
779
+			[
780
+				'layout_strategy' => new EE_Template_Layout(
781
+					[
782
+						'layout_template_file' => SPCO_REG_STEPS_PATH
783
+												  . $this->_slug
784
+												  . '/no_payment_required.template.php', // layout_template
785
+						'template_args'        => apply_filters(
786
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
787
+							[
788
+								'revisit'                       => $this->checkout->revisit,
789
+								'registrations'                 => [],
790
+								'ticket_count'                  => [],
791
+								'registrations_for_free_events' => $registrations_for_free_events,
792
+								'no_payment_required_msg'       => EEH_HTML::p(
793
+									esc_html__('This is a free event, so no billing will occur.', 'event_espresso')
794
+								),
795
+							]
796
+						),
797
+					]
798
+				),
799
+			]
800
+		);
801
+	}
802
+
803
+
804
+	/**
805
+	 * _display_payment_options
806
+	 *
807
+	 * @param string $transaction_details
808
+	 * @return EE_Form_Section_Proper
809
+	 * @throws EE_Error
810
+	 * @throws InvalidArgumentException
811
+	 * @throws InvalidDataTypeException
812
+	 * @throws InvalidInterfaceException
813
+	 */
814
+	private function _display_payment_options($transaction_details = '')
815
+	{
816
+		// has method_of_payment been set by no-js user?
817
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
818
+		// build payment options form
819
+		return apply_filters(
820
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form',
821
+			new EE_Form_Section_Proper(
822
+				[
823
+					'subsections'     => [
824
+						'before_payment_options' => apply_filters(
825
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
826
+							new EE_Form_Section_Proper(
827
+								['layout_strategy' => new EE_Div_Per_Section_Layout()]
828
+							)
829
+						),
830
+						'payment_options'        => $this->_setup_payment_options(),
831
+						'after_payment_options'  => apply_filters(
832
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
833
+							new EE_Form_Section_Proper(
834
+								['layout_strategy' => new EE_Div_Per_Section_Layout()]
835
+							)
836
+						),
837
+					],
838
+					'layout_strategy' => new EE_Template_Layout(
839
+						[
840
+							'layout_template_file' => $this->_template,
841
+							'template_args'        => apply_filters(
842
+								'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args',
843
+								[
844
+									'reg_count'                 => $this->line_item_display->total_items(),
845
+									'transaction_details'       => $transaction_details,
846
+									'available_payment_methods' => [],
847
+								]
848
+							),
849
+						]
850
+					),
851
+				]
852
+			)
853
+		);
854
+	}
855
+
856
+
857
+	/**
858
+	 * _extra_hidden_inputs
859
+	 *
860
+	 * @param bool $no_payment_required
861
+	 * @return EE_Form_Section_Proper
862
+	 * @throws EE_Error
863
+	 * @throws ReflectionException
864
+	 */
865
+	private function _extra_hidden_inputs($no_payment_required = true)
866
+	{
867
+		return new EE_Form_Section_Proper(
868
+			[
869
+				'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
870
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
871
+				'subsections'     => [
872
+					'spco_no_payment_required' => new EE_Hidden_Input(
873
+						[
874
+							'normalization_strategy' => new EE_Boolean_Normalization(),
875
+							'html_name'              => 'spco_no_payment_required',
876
+							'html_id'                => 'spco-no-payment-required-payment_options',
877
+							'default'                => $no_payment_required,
878
+						]
879
+					),
880
+					'spco_transaction_id'      => new EE_Fixed_Hidden_Input(
881
+						[
882
+							'normalization_strategy' => new EE_Int_Normalization(),
883
+							'html_name'              => 'spco_transaction_id',
884
+							'html_id'                => 'spco-transaction-id',
885
+							'default'                => $this->checkout->transaction->ID(),
886
+						]
887
+					),
888
+				],
889
+			]
890
+		);
891
+	}
892
+
893
+
894
+	/**
895
+	 *    _apply_registration_payments_to_amount_owing
896
+	 *
897
+	 * @param array $registrations
898
+	 * @throws EE_Error
899
+	 */
900
+	protected function _apply_registration_payments_to_amount_owing(array $registrations)
901
+	{
902
+		$payments = [];
903
+		foreach ($registrations as $registration) {
904
+			if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
905
+				$payments += $registration->registration_payments();
906
+			}
907
+		}
908
+		if (! empty($payments)) {
909
+			foreach ($payments as $payment) {
910
+				if ($payment instanceof EE_Registration_Payment) {
911
+					$this->checkout->amount_owing -= $payment->amount();
912
+				}
913
+			}
914
+		}
915
+	}
916
+
917
+
918
+	/**
919
+	 *    _reset_selected_method_of_payment
920
+	 *
921
+	 * @access    private
922
+	 * @param bool $force_reset
923
+	 * @return void
924
+	 * @throws InvalidArgumentException
925
+	 * @throws InvalidDataTypeException
926
+	 * @throws InvalidInterfaceException
927
+	 */
928
+	private function _reset_selected_method_of_payment($force_reset = false)
929
+	{
930
+		/** @var RequestInterface $request */
931
+		$request              = LoaderFactory::getLoader()->getShared(RequestInterface::class);
932
+		$reset_payment_method = $request->getRequestParam('reset_payment_method', $force_reset, 'bool');
933
+		if ($reset_payment_method) {
934
+			$this->checkout->selected_method_of_payment = null;
935
+			$this->checkout->payment_method             = null;
936
+			$this->checkout->billing_form               = null;
937
+			$this->_save_selected_method_of_payment();
938
+		}
939
+	}
940
+
941
+
942
+	/**
943
+	 * _save_selected_method_of_payment
944
+	 * stores the selected_method_of_payment in the session
945
+	 * so that it's available for all subsequent requests including AJAX
946
+	 *
947
+	 * @access        private
948
+	 * @param string $selected_method_of_payment
949
+	 * @return void
950
+	 * @throws InvalidArgumentException
951
+	 * @throws InvalidDataTypeException
952
+	 * @throws InvalidInterfaceException
953
+	 */
954
+	private function _save_selected_method_of_payment($selected_method_of_payment = '')
955
+	{
956
+		$selected_method_of_payment = ! empty($selected_method_of_payment)
957
+			? $selected_method_of_payment
958
+			: $this->checkout->selected_method_of_payment;
959
+		EE_Registry::instance()->SSN->set_session_data(
960
+			['selected_method_of_payment' => $selected_method_of_payment]
961
+		);
962
+	}
963
+
964
+
965
+	/**
966
+	 * _setup_payment_options
967
+	 *
968
+	 * @return EE_Form_Section_Proper
969
+	 * @throws EE_Error
970
+	 * @throws InvalidArgumentException
971
+	 * @throws InvalidDataTypeException
972
+	 * @throws InvalidInterfaceException
973
+	 */
974
+	public function _setup_payment_options()
975
+	{
976
+		// load payment method classes
977
+		$this->checkout->available_payment_methods = $this->_get_available_payment_methods();
978
+		if (empty($this->checkout->available_payment_methods)) {
979
+			EE_Error::add_error(
980
+				apply_filters(
981
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods',
982
+					sprintf(
983
+						esc_html__(
984
+							'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.',
985
+							'event_espresso'
986
+						),
987
+						'<br>',
988
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
989
+					)
990
+				),
991
+				__FILE__,
992
+				__FUNCTION__,
993
+				__LINE__
994
+			);
995
+		}
996
+		// switch up header depending on number of available payment methods
997
+		$payment_method_header     = count($this->checkout->available_payment_methods) > 1
998
+			? apply_filters(
999
+				'FHEE__registration_page_payment_options__method_of_payment_hdr',
1000
+				esc_html__('Please Select Your Method of Payment', 'event_espresso')
1001
+			)
1002
+			: apply_filters(
1003
+				'FHEE__registration_page_payment_options__method_of_payment_hdr',
1004
+				esc_html__('Method of Payment', 'event_espresso')
1005
+			);
1006
+		$available_payment_methods = [
1007
+			// display the "Payment Method" header
1008
+			'payment_method_header' => new EE_Form_Section_HTML(
1009
+				apply_filters(
1010
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header',
1011
+					EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'),
1012
+					$payment_method_header
1013
+				)
1014
+			),
1015
+		];
1016
+		// the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
1017
+		$available_payment_method_options = [];
1018
+		$default_payment_method_option    = [];
1019
+		// additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
1020
+		$payment_methods_billing_info = [
1021
+			new EE_Form_Section_HTML(
1022
+				EEH_HTML::div('<br />', '', '', 'clear:both;')
1023
+			),
1024
+		];
1025
+		// loop through payment methods
1026
+		foreach ($this->checkout->available_payment_methods as $payment_method) {
1027
+			if ($payment_method instanceof EE_Payment_Method) {
1028
+				$payment_method_button = EEH_HTML::img(
1029
+					$payment_method->button_url(),
1030
+					$payment_method->name(),
1031
+					'spco-payment-method-' . $payment_method->slug() . '-btn-img',
1032
+					'spco-payment-method-btn-img'
1033
+				);
1034
+				// check if any payment methods are set as default
1035
+				// if payment method is already selected OR nothing is selected and this payment method should be
1036
+				// open_by_default
1037
+				if (
1038
+					($this->checkout->selected_method_of_payment === $payment_method->slug())
1039
+					|| (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1040
+				) {
1041
+					$this->checkout->selected_method_of_payment = $payment_method->slug();
1042
+					$this->_save_selected_method_of_payment();
1043
+					$default_payment_method_option[ $payment_method->slug() ] = $payment_method_button;
1044
+				} else {
1045
+					$available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
1046
+				}
1047
+				$payment_methods_billing_info[ $payment_method->slug() . '-info' ] =
1048
+					$this->_payment_method_billing_info(
1049
+						$payment_method
1050
+					);
1051
+			}
1052
+		}
1053
+		// prepend available_payment_method_options with default_payment_method_option so that it appears first in list
1054
+		// of PMs
1055
+		$available_payment_method_options = $default_payment_method_option + $available_payment_method_options;
1056
+		// now generate the actual form  inputs
1057
+		$available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs(
1058
+			$available_payment_method_options
1059
+		);
1060
+		$available_payment_methods                              += $payment_methods_billing_info;
1061
+		// build the available payment methods form
1062
+		return new EE_Form_Section_Proper(
1063
+			[
1064
+				'html_id'         => 'spco-available-methods-of-payment-dv',
1065
+				'subsections'     => $available_payment_methods,
1066
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1067
+			]
1068
+		);
1069
+	}
1070
+
1071
+
1072
+	/**
1073
+	 * _get_available_payment_methods
1074
+	 *
1075
+	 * @return EE_Payment_Method[]
1076
+	 * @throws EE_Error
1077
+	 * @throws InvalidArgumentException
1078
+	 * @throws InvalidDataTypeException
1079
+	 * @throws InvalidInterfaceException
1080
+	 */
1081
+	protected function _get_available_payment_methods()
1082
+	{
1083
+		if (! empty($this->checkout->available_payment_methods)) {
1084
+			return $this->checkout->available_payment_methods;
1085
+		}
1086
+		$available_payment_methods = [];
1087
+		$EEM_Payment_Method        = EEM_Payment_Method::instance();
1088
+		// get all active payment methods
1089
+		$payment_methods = $EEM_Payment_Method->get_all_for_transaction(
1090
+			$this->checkout->transaction,
1091
+			EEM_Payment_Method::scope_cart
1092
+		);
1093
+		foreach ($payment_methods as $payment_method) {
1094
+			if ($payment_method instanceof EE_Payment_Method) {
1095
+				$available_payment_methods[ $payment_method->slug() ] = $payment_method;
1096
+			}
1097
+		}
1098
+		return $available_payment_methods;
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 *    _available_payment_method_inputs
1104
+	 *
1105
+	 * @access    private
1106
+	 * @param array $available_payment_method_options
1107
+	 * @return    EE_Form_Section_Proper
1108
+	 * @throws EE_Error
1109
+	 * @throws EE_Error
1110
+	 */
1111
+	private function _available_payment_method_inputs($available_payment_method_options = [])
1112
+	{
1113
+		// generate inputs
1114
+		return new EE_Form_Section_Proper(
1115
+			[
1116
+				'html_id'         => 'ee-available-payment-method-inputs',
1117
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1118
+				'subsections'     => [
1119
+					'' => new EE_Radio_Button_Input(
1120
+						$available_payment_method_options,
1121
+						[
1122
+							'html_name'          => 'selected_method_of_payment',
1123
+							'html_class'         => 'spco-payment-method',
1124
+							'default'            => $this->checkout->selected_method_of_payment,
1125
+							'label_size'         => 11,
1126
+							'enforce_label_size' => true,
1127
+						]
1128
+					),
1129
+				],
1130
+			]
1131
+		);
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 *    _payment_method_billing_info
1137
+	 *
1138
+	 * @access    private
1139
+	 * @param EE_Payment_Method $payment_method
1140
+	 * @return EE_Form_Section_Proper
1141
+	 * @throws EE_Error
1142
+	 * @throws InvalidArgumentException
1143
+	 * @throws InvalidDataTypeException
1144
+	 * @throws InvalidInterfaceException
1145
+	 */
1146
+	private function _payment_method_billing_info(EE_Payment_Method $payment_method)
1147
+	{
1148
+		$currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug();
1149
+		// generate the billing form for payment method
1150
+		$billing_form                 = $currently_selected
1151
+			? $this->_get_billing_form_for_payment_method($payment_method)
1152
+			: new EE_Form_Section_HTML();
1153
+		$this->checkout->billing_form = $currently_selected
1154
+			? $billing_form
1155
+			: $this->checkout->billing_form;
1156
+		// it's all in the details
1157
+		$info_html = EEH_HTML::h3(
1158
+			esc_html__('Important information regarding your payment', 'event_espresso'),
1159
+			'',
1160
+			'spco-payment-method-hdr'
1161
+		);
1162
+		// add some info regarding the step, either from what's saved in the admin,
1163
+		// or a default string depending on whether the PM has a billing form or not
1164
+		if ($payment_method->description()) {
1165
+			$payment_method_info = $payment_method->description();
1166
+		} elseif ($billing_form instanceof EE_Billing_Info_Form) {
1167
+			$payment_method_info = sprintf(
1168
+				esc_html__(
1169
+					'Please provide the following billing information, then click the "%1$s" button below in order to proceed.',
1170
+					'event_espresso'
1171
+				),
1172
+				$this->submit_button_text()
1173
+			);
1174
+		} else {
1175
+			$payment_method_info = sprintf(
1176
+				esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'),
1177
+				$this->submit_button_text()
1178
+			);
1179
+		}
1180
+		$info_html .= EEH_HTML::div(
1181
+			apply_filters(
1182
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info',
1183
+				$payment_method_info
1184
+			),
1185
+			'',
1186
+			'spco-payment-method-desc ee-attention'
1187
+		);
1188
+		return new EE_Form_Section_Proper(
1189
+			[
1190
+				'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1191
+				'html_class'      => 'spco-payment-method-info-dv',
1192
+				// only display the selected or default PM
1193
+				'html_style'      => $currently_selected ? '' : 'display:none;',
1194
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1195
+				'subsections'     => [
1196
+					'info'         => new EE_Form_Section_HTML($info_html),
1197
+					'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(),
1198
+				],
1199
+			]
1200
+		);
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * get_billing_form_html_for_payment_method
1206
+	 *
1207
+	 * @return bool
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws ReflectionException
1211
+	 * @throws InvalidDataTypeException
1212
+	 * @throws InvalidInterfaceException
1213
+	 */
1214
+	public function get_billing_form_html_for_payment_method()
1215
+	{
1216
+		// how have they chosen to pay?
1217
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1218
+		$this->checkout->payment_method             = $this->_get_payment_method_for_selected_method_of_payment();
1219
+		if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1220
+			return false;
1221
+		}
1222
+		if (
1223
+			apply_filters(
1224
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1225
+				false
1226
+			)
1227
+		) {
1228
+			EE_Error::add_success(
1229
+				apply_filters(
1230
+					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1231
+					sprintf(
1232
+						esc_html__(
1233
+							'You have selected "%s" as your method of payment. Please note the important payment information below.',
1234
+							'event_espresso'
1235
+						),
1236
+						$this->checkout->payment_method->name()
1237
+					)
1238
+				)
1239
+			);
1240
+		}
1241
+		// now generate billing form for selected method of payment
1242
+		$payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1243
+		// fill form with attendee info if applicable
1244
+		if (
1245
+			$payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
1246
+			&& $this->checkout->transaction_has_primary_registrant()
1247
+		) {
1248
+			$payment_method_billing_form->populate_from_attendee(
1249
+				$this->checkout->transaction->primary_registration()->attendee()
1250
+			);
1251
+		}
1252
+		// and debug content
1253
+		if (
1254
+			$payment_method_billing_form instanceof EE_Billing_Info_Form
1255
+			&& $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1256
+		) {
1257
+			$payment_method_billing_form =
1258
+				$this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1259
+					$payment_method_billing_form
1260
+				);
1261
+		}
1262
+		$billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper
1263
+			? $payment_method_billing_form->get_html()
1264
+			: '';
1265
+		$this->checkout->json_response->set_return_data(['payment_method_info' => $billing_info]);
1266
+		// localize validation rules for main form
1267
+		$this->checkout->current_step->reg_form->localize_validation_rules();
1268
+		$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1269
+		return true;
1270
+	}
1271
+
1272
+
1273
+	/**
1274
+	 * _get_billing_form_for_payment_method
1275
+	 *
1276
+	 * @param EE_Payment_Method $payment_method
1277
+	 * @return EE_Billing_Info_Form|EE_Billing_Attendee_Info_Form|EE_Form_Section_HTML
1278
+	 * @throws EE_Error
1279
+	 * @throws InvalidArgumentException
1280
+	 * @throws InvalidDataTypeException
1281
+	 * @throws InvalidInterfaceException
1282
+	 */
1283
+	private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method)
1284
+	{
1285
+		$billing_form = $payment_method->type_obj()->billing_form(
1286
+			$this->checkout->transaction,
1287
+			['amount_owing' => $this->checkout->amount_owing]
1288
+		);
1289
+		if ($billing_form instanceof EE_Billing_Info_Form) {
1290
+			if (
1291
+				apply_filters(
1292
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1293
+					false
1294
+				)
1295
+				&& $this->request->requestParamIsSet('payment_method')
1296
+			) {
1297
+				EE_Error::add_success(
1298
+					apply_filters(
1299
+						'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1300
+						sprintf(
1301
+							esc_html__(
1302
+								'You have selected "%s" as your method of payment. Please note the important payment information below.',
1303
+								'event_espresso'
1304
+							),
1305
+							$payment_method->name()
1306
+						)
1307
+					)
1308
+				);
1309
+			}
1310
+			return apply_filters(
1311
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
1312
+				$billing_form,
1313
+				$payment_method
1314
+			);
1315
+		}
1316
+		// no actual billing form, so return empty HTML form section
1317
+		return new EE_Form_Section_HTML();
1318
+	}
1319
+
1320
+
1321
+	/**
1322
+	 * _get_selected_method_of_payment
1323
+	 *
1324
+	 * @param boolean $required whether to throw an error if the "selected_method_of_payment"
1325
+	 *                          is not found in the incoming request
1326
+	 * @param string  $request_param
1327
+	 * @return NULL|string
1328
+	 * @throws EE_Error
1329
+	 * @throws InvalidArgumentException
1330
+	 * @throws InvalidDataTypeException
1331
+	 * @throws InvalidInterfaceException
1332
+	 */
1333
+	private function _get_selected_method_of_payment(
1334
+		$required = false,
1335
+		$request_param = 'selected_method_of_payment'
1336
+	) {
1337
+		// is selected_method_of_payment set in the request ?
1338
+		$selected_method_of_payment = $this->request->getRequestParam($request_param);
1339
+		if ($selected_method_of_payment) {
1340
+			// sanitize it
1341
+			$selected_method_of_payment = is_array($selected_method_of_payment)
1342
+				? array_shift($selected_method_of_payment)
1343
+				: $selected_method_of_payment;
1344
+			$selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
1345
+			// store it in the session so that it's available for all subsequent requests including AJAX
1346
+			$this->_save_selected_method_of_payment($selected_method_of_payment);
1347
+		} else {
1348
+			// or is is set in the session ?
1349
+			$selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data(
1350
+				'selected_method_of_payment'
1351
+			);
1352
+		}
1353
+		// do ya really really gotta have it?
1354
+		if (empty($selected_method_of_payment) && $required) {
1355
+			EE_Error::add_error(
1356
+				sprintf(
1357
+					esc_html__(
1358
+						'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.',
1359
+						'event_espresso'
1360
+					),
1361
+					'<br/>',
1362
+					'<br/>',
1363
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1364
+				),
1365
+				__FILE__,
1366
+				__FUNCTION__,
1367
+				__LINE__
1368
+			);
1369
+			return null;
1370
+		}
1371
+		return $selected_method_of_payment;
1372
+	}
1373
+
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+	/********************************************************************************************************/
1380
+	/***********************************  SWITCH PAYMENT METHOD  ************************************/
1381
+	/********************************************************************************************************/
1382
+	/**
1383
+	 * switch_payment_method
1384
+	 *
1385
+	 * @return bool
1386
+	 * @throws EE_Error
1387
+	 * @throws InvalidArgumentException
1388
+	 * @throws InvalidDataTypeException
1389
+	 * @throws InvalidInterfaceException
1390
+	 * @throws ReflectionException
1391
+	 */
1392
+	public function switch_payment_method()
1393
+	{
1394
+		if (! $this->_verify_payment_method_is_set()) {
1395
+			return false;
1396
+		}
1397
+		if (
1398
+			apply_filters(
1399
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1400
+				false
1401
+			)
1402
+		) {
1403
+			EE_Error::add_success(
1404
+				apply_filters(
1405
+					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1406
+					sprintf(
1407
+						esc_html__(
1408
+							'You have selected "%s" as your method of payment. Please note the important payment information below.',
1409
+							'event_espresso'
1410
+						),
1411
+						$this->checkout->payment_method->name()
1412
+					)
1413
+				)
1414
+			);
1415
+		}
1416
+		// generate billing form for selected method of payment if it hasn't been done already
1417
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1418
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1419
+				$this->checkout->payment_method
1420
+			);
1421
+		}
1422
+		// fill form with attendee info if applicable
1423
+		if (
1424
+			apply_filters(
1425
+				'FHEE__populate_billing_form_fields_from_attendee',
1426
+				(
1427
+					$this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
1428
+					&& $this->checkout->transaction_has_primary_registrant()
1429
+				),
1430
+				$this->checkout->billing_form,
1431
+				$this->checkout->transaction
1432
+			)
1433
+		) {
1434
+			$this->checkout->billing_form->populate_from_attendee(
1435
+				$this->checkout->transaction->primary_registration()->attendee()
1436
+			);
1437
+		}
1438
+		// and debug content
1439
+		if (
1440
+			$this->checkout->billing_form instanceof EE_Billing_Info_Form
1441
+			&& $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1442
+		) {
1443
+			$this->checkout->billing_form =
1444
+				$this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1445
+					$this->checkout->billing_form
1446
+				);
1447
+		}
1448
+		// get html and validation rules for form
1449
+		if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
1450
+			$this->checkout->json_response->set_return_data(
1451
+				['payment_method_info' => $this->checkout->billing_form->get_html()]
1452
+			);
1453
+			// localize validation rules for main form
1454
+			$this->checkout->billing_form->localize_validation_rules(true);
1455
+			$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1456
+		} else {
1457
+			$this->checkout->json_response->set_return_data(['payment_method_info' => '']);
1458
+		}
1459
+		// prevents advancement to next step
1460
+		$this->checkout->continue_reg = false;
1461
+		return true;
1462
+	}
1463
+
1464
+
1465
+	/**
1466
+	 * _verify_payment_method_is_set
1467
+	 *
1468
+	 * @return bool
1469
+	 * @throws EE_Error
1470
+	 * @throws InvalidArgumentException
1471
+	 * @throws ReflectionException
1472
+	 * @throws InvalidDataTypeException
1473
+	 * @throws InvalidInterfaceException
1474
+	 */
1475
+	protected function _verify_payment_method_is_set()
1476
+	{
1477
+		// generate billing form for selected method of payment if it hasn't been done already
1478
+		if (empty($this->checkout->selected_method_of_payment)) {
1479
+			// how have they chosen to pay?
1480
+			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1481
+		} else {
1482
+			// choose your own adventure based on method_of_payment
1483
+			switch ($this->checkout->selected_method_of_payment) {
1484
+				case 'events_sold_out':
1485
+					EE_Error::add_attention(
1486
+						apply_filters(
1487
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
1488
+							esc_html__(
1489
+								'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1490
+								'event_espresso'
1491
+							)
1492
+						),
1493
+						__FILE__,
1494
+						__FUNCTION__,
1495
+						__LINE__
1496
+					);
1497
+					return false;
1498
+				case 'payments_closed':
1499
+					EE_Error::add_attention(
1500
+						apply_filters(
1501
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
1502
+							esc_html__(
1503
+								'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.',
1504
+								'event_espresso'
1505
+							)
1506
+						),
1507
+						__FILE__,
1508
+						__FUNCTION__,
1509
+						__LINE__
1510
+					);
1511
+					return false;
1512
+				case 'no_payment_required':
1513
+					EE_Error::add_attention(
1514
+						apply_filters(
1515
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
1516
+							esc_html__(
1517
+								'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.',
1518
+								'event_espresso'
1519
+							)
1520
+						),
1521
+						__FILE__,
1522
+						__FUNCTION__,
1523
+						__LINE__
1524
+					);
1525
+					return false;
1526
+				default:
1527
+			}
1528
+		}
1529
+		// verify payment method
1530
+		if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1531
+			// get payment method for selected method of payment
1532
+			$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1533
+		}
1534
+		return $this->checkout->payment_method instanceof EE_Payment_Method;
1535
+	}
1536
+
1537
+
1538
+
1539
+	/********************************************************************************************************/
1540
+	/***************************************  SAVE PAYER DETAILS  ****************************************/
1541
+	/********************************************************************************************************/
1542
+	/**
1543
+	 * save_payer_details_via_ajax
1544
+	 *
1545
+	 * @return void
1546
+	 * @throws EE_Error
1547
+	 * @throws InvalidArgumentException
1548
+	 * @throws ReflectionException
1549
+	 * @throws RuntimeException
1550
+	 * @throws InvalidDataTypeException
1551
+	 * @throws InvalidInterfaceException
1552
+	 */
1553
+	public function save_payer_details_via_ajax()
1554
+	{
1555
+		if (! $this->_verify_payment_method_is_set()) {
1556
+			return;
1557
+		}
1558
+		// generate billing form for selected method of payment if it hasn't been done already
1559
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1560
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1561
+				$this->checkout->payment_method
1562
+			);
1563
+		}
1564
+		// generate primary attendee from payer info if applicable
1565
+		if (! $this->checkout->transaction_has_primary_registrant()) {
1566
+			$attendee = $this->_create_attendee_from_request_data();
1567
+			if ($attendee instanceof EE_Attendee) {
1568
+				foreach ($this->checkout->transaction->registrations() as $registration) {
1569
+					if ($registration->is_primary_registrant()) {
1570
+						$this->checkout->primary_attendee_obj = $attendee;
1571
+						$registration->_add_relation_to($attendee, 'Attendee');
1572
+						$registration->set_attendee_id($attendee->ID());
1573
+						$registration->update_cache_after_object_save('Attendee', $attendee);
1574
+					}
1575
+				}
1576
+			}
1577
+		}
1578
+	}
1579
+
1580
+
1581
+	/**
1582
+	 * create_attendee_from_request_data
1583
+	 * uses info from alternate GET or POST data (such as AJAX) to create a new attendee
1584
+	 *
1585
+	 * @return EE_Attendee
1586
+	 * @throws EE_Error
1587
+	 * @throws InvalidArgumentException
1588
+	 * @throws ReflectionException
1589
+	 * @throws InvalidDataTypeException
1590
+	 * @throws InvalidInterfaceException
1591
+	 */
1592
+	protected function _create_attendee_from_request_data()
1593
+	{
1594
+		// get State ID
1595
+		$STA_ID = $this->request->getRequestParam('state');
1596
+		if (! empty($STA_ID)) {
1597
+			// can we get state object from name ?
1598
+			EE_Registry::instance()->load_model('State');
1599
+			$state  = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID');
1600
+			$STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1601
+		}
1602
+		// get Country ISO
1603
+		$CNT_ISO = $this->request->getRequestParam('country');
1604
+		if (! empty($CNT_ISO)) {
1605
+			// can we get country object from name ?
1606
+			EE_Registry::instance()->load_model('Country');
1607
+			$country = EEM_Country::instance()->get_col(
1608
+				[['CNT_name' => $CNT_ISO], 'limit' => 1],
1609
+				'CNT_ISO'
1610
+			);
1611
+			$CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1612
+		}
1613
+		// grab attendee data
1614
+		$attendee_data = [
1615
+			'ATT_fname'    => $this->request->getRequestParam('first_name'),
1616
+			'ATT_lname'    => $this->request->getRequestParam('last_name'),
1617
+			'ATT_email'    => $this->request->getRequestParam('email'),
1618
+			'ATT_address'  => $this->request->getRequestParam('address'),
1619
+			'ATT_address2' => $this->request->getRequestParam('address2'),
1620
+			'ATT_city'     => $this->request->getRequestParam('city'),
1621
+			'STA_ID'       => $STA_ID,
1622
+			'CNT_ISO'      => $CNT_ISO,
1623
+			'ATT_zip'      => $this->request->getRequestParam('zip'),
1624
+			'ATT_phone'    => $this->request->getRequestParam('phone'),
1625
+		];
1626
+		// validate the email address since it is the most important piece of info
1627
+		if (empty($attendee_data['ATT_email'])) {
1628
+			EE_Error::add_error(
1629
+				esc_html__('An invalid email address was submitted.', 'event_espresso'),
1630
+				__FILE__,
1631
+				__FUNCTION__,
1632
+				__LINE__
1633
+			);
1634
+		}
1635
+		// does this attendee already exist in the db ? we're searching using a combination of first name, last name,
1636
+		// AND email address
1637
+		if (
1638
+			! empty($attendee_data['ATT_fname'])
1639
+			&& ! empty($attendee_data['ATT_lname'])
1640
+			&& ! empty($attendee_data['ATT_email'])
1641
+		) {
1642
+			$existing_attendee = EEM_Attendee::instance()->find_existing_attendee(
1643
+				[
1644
+					'ATT_fname' => $attendee_data['ATT_fname'],
1645
+					'ATT_lname' => $attendee_data['ATT_lname'],
1646
+					'ATT_email' => $attendee_data['ATT_email'],
1647
+				]
1648
+			);
1649
+			if ($existing_attendee instanceof EE_Attendee) {
1650
+				return $existing_attendee;
1651
+			}
1652
+		}
1653
+		// no existing attendee? kk let's create a new one
1654
+		// kinda lame, but we need a first and last name to create an attendee, so use the email address if those
1655
+		// don't exist
1656
+		$attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname'])
1657
+			? $attendee_data['ATT_fname']
1658
+			: $attendee_data['ATT_email'];
1659
+		$attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname'])
1660
+			? $attendee_data['ATT_lname']
1661
+			: $attendee_data['ATT_email'];
1662
+		return EE_Attendee::new_instance($attendee_data);
1663
+	}
1664
+
1665
+
1666
+
1667
+	/********************************************************************************************************/
1668
+	/****************************************  PROCESS REG STEP  *****************************************/
1669
+	/********************************************************************************************************/
1670
+	/**
1671
+	 * process_reg_step
1672
+	 *
1673
+	 * @return bool
1674
+	 * @throws EE_Error
1675
+	 * @throws InvalidArgumentException
1676
+	 * @throws ReflectionException
1677
+	 * @throws EntityNotFoundException
1678
+	 * @throws InvalidDataTypeException
1679
+	 * @throws InvalidInterfaceException
1680
+	 * @throws InvalidStatusException
1681
+	 */
1682
+	public function process_reg_step()
1683
+	{
1684
+		// how have they chosen to pay?
1685
+		$this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free()
1686
+			? 'no_payment_required'
1687
+			: $this->_get_selected_method_of_payment(true);
1688
+		// choose your own adventure based on method_of_payment
1689
+		switch ($this->checkout->selected_method_of_payment) {
1690
+			case 'events_sold_out':
1691
+				$this->checkout->redirect     = true;
1692
+				$this->checkout->redirect_url = $this->checkout->cancel_page_url;
1693
+				$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1694
+				// mark this reg step as completed
1695
+				$this->set_completed();
1696
+				return false;
1697
+
1698
+			case 'payments_closed':
1699
+				if (
1700
+					apply_filters(
1701
+						'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success',
1702
+						false
1703
+					)
1704
+				) {
1705
+					EE_Error::add_success(
1706
+						esc_html__('no payment required at this time.', 'event_espresso'),
1707
+						__FILE__,
1708
+						__FUNCTION__,
1709
+						__LINE__
1710
+					);
1711
+				}
1712
+				// mark this reg step as completed
1713
+				$this->set_completed();
1714
+				return true;
1715
+
1716
+			case 'no_payment_required':
1717
+				if (
1718
+					apply_filters(
1719
+						'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success',
1720
+						false
1721
+					)
1722
+				) {
1723
+					EE_Error::add_success(
1724
+						esc_html__('no payment required.', 'event_espresso'),
1725
+						__FILE__,
1726
+						__FUNCTION__,
1727
+						__LINE__
1728
+					);
1729
+				}
1730
+				// mark this reg step as completed
1731
+				$this->set_completed();
1732
+				return true;
1733
+
1734
+			default:
1735
+				$registrations         = EE_Registry::instance()->SSN->checkout()->transaction->registrations(
1736
+					EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
1737
+				);
1738
+				$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
1739
+					$registrations,
1740
+					EE_Registry::instance()->SSN->checkout()->revisit
1741
+				);
1742
+				// calculate difference between the two arrays
1743
+				$registrations = array_diff($registrations, $ejected_registrations);
1744
+				if (empty($registrations)) {
1745
+					$this->_redirect_because_event_sold_out();
1746
+					return false;
1747
+				}
1748
+				$payment = $this->_process_payment();
1749
+				if ($payment instanceof EE_Payment) {
1750
+					$this->checkout->continue_reg = true;
1751
+					$this->_maybe_set_completed($payment);
1752
+				} else {
1753
+					$this->checkout->continue_reg = false;
1754
+				}
1755
+				return $payment instanceof EE_Payment;
1756
+		}
1757
+	}
1758
+
1759
+
1760
+	/**
1761
+	 * _redirect_because_event_sold_out
1762
+	 *
1763
+	 * @return void
1764
+	 */
1765
+	protected function _redirect_because_event_sold_out()
1766
+	{
1767
+		$this->checkout->continue_reg = false;
1768
+		// set redirect URL
1769
+		$this->checkout->redirect_url = add_query_arg(
1770
+			['e_reg_url_link' => $this->checkout->reg_url_link],
1771
+			$this->checkout->current_step->reg_step_url()
1772
+		);
1773
+		$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1774
+	}
1775
+
1776
+
1777
+	/**
1778
+	 * @param EE_Payment $payment
1779
+	 * @return void
1780
+	 * @throws EE_Error
1781
+	 */
1782
+	protected function _maybe_set_completed(EE_Payment $payment)
1783
+	{
1784
+		// Do we need to redirect them? If so, there's more work to be done.
1785
+		if (! $payment->redirect_url()) {
1786
+			$this->set_completed();
1787
+		}
1788
+	}
1789
+
1790
+
1791
+	/**
1792
+	 *    update_reg_step
1793
+	 *    this is the final step after a user  revisits the site to retry a payment
1794
+	 *
1795
+	 * @return bool
1796
+	 * @throws EE_Error
1797
+	 * @throws InvalidArgumentException
1798
+	 * @throws ReflectionException
1799
+	 * @throws EntityNotFoundException
1800
+	 * @throws InvalidDataTypeException
1801
+	 * @throws InvalidInterfaceException
1802
+	 * @throws InvalidStatusException
1803
+	 */
1804
+	public function update_reg_step()
1805
+	{
1806
+		$success = true;
1807
+		// if payment required
1808
+		if ($this->checkout->transaction->total() > 0) {
1809
+			do_action(
1810
+				'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway',
1811
+				$this->checkout->transaction
1812
+			);
1813
+			// attempt payment via payment method
1814
+			$success = $this->process_reg_step();
1815
+		}
1816
+		if ($success && ! $this->checkout->redirect) {
1817
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
1818
+				$this->checkout->transaction->ID()
1819
+			);
1820
+			// set return URL
1821
+			$this->checkout->redirect_url = add_query_arg(
1822
+				['e_reg_url_link' => $this->checkout->reg_url_link],
1823
+				$this->checkout->thank_you_page_url
1824
+			);
1825
+		}
1826
+		return $success;
1827
+	}
1828
+
1829
+
1830
+	/**
1831
+	 * @return EE_Payment|null
1832
+	 * @throws EE_Error
1833
+	 * @throws InvalidArgumentException
1834
+	 * @throws ReflectionException
1835
+	 * @throws RuntimeException
1836
+	 * @throws InvalidDataTypeException
1837
+	 * @throws InvalidInterfaceException
1838
+	 */
1839
+	private function _process_payment()
1840
+	{
1841
+		// basically confirm that the event hasn't sold out since they hit the page
1842
+		if (! $this->_last_second_ticket_verifications()) {
1843
+			return null;
1844
+		}
1845
+		// ya gotta make a choice man
1846
+		if (empty($this->checkout->selected_method_of_payment)) {
1847
+			$this->checkout->json_response->set_plz_select_method_of_payment(
1848
+				esc_html__('Please select a method of payment before proceeding.', 'event_espresso')
1849
+			);
1850
+			return null;
1851
+		}
1852
+		// get EE_Payment_Method object
1853
+		if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1854
+			return null;
1855
+		}
1856
+		// setup billing form
1857
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1858
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1859
+				$this->checkout->payment_method
1860
+			);
1861
+			// bad billing form ?
1862
+			if (! $this->_billing_form_is_valid()) {
1863
+				return null;
1864
+			}
1865
+		}
1866
+		// ensure primary registrant has been fully processed
1867
+		if (! $this->_setup_primary_registrant_prior_to_payment()) {
1868
+			return null;
1869
+		}
1870
+		// if session is close to expiring (under 10 minutes by default)
1871
+		if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1872
+			// add some time to session expiration so that payment can be completed
1873
+			EE_Registry::instance()->SSN->extend_expiration();
1874
+		}
1875
+		/** @type EE_Transaction_Processor $transaction_processor */
1876
+		// $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1877
+		// in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations
1878
+		// for events with a default reg status of Approved
1879
+		// $transaction_processor->toggle_registration_statuses_for_default_approved_events(
1880
+		//      $this->checkout->transaction, $this->checkout->reg_cache_where_params
1881
+		// );
1882
+		// attempt payment
1883
+		$payment = $this->_attempt_payment($this->checkout->payment_method);
1884
+		// process results
1885
+		$payment = $this->_validate_payment($payment);
1886
+		$payment = $this->_post_payment_processing($payment);
1887
+		// verify payment
1888
+		if ($payment instanceof EE_Payment) {
1889
+			// store that for later
1890
+			$this->checkout->payment = $payment;
1891
+			// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
1892
+			$this->checkout->transaction->toggle_failed_transaction_status();
1893
+			$payment_status = $payment->status();
1894
+			if (
1895
+				$payment_status === EEM_Payment::status_id_approved
1896
+				|| $payment_status === EEM_Payment::status_id_pending
1897
+			) {
1898
+				return $payment;
1899
+			}
1900
+			return null;
1901
+		}
1902
+		if ($payment === true) {
1903
+			// please note that offline payment methods will NOT make a payment,
1904
+			// but instead just mark themselves as the PMD_ID on the transaction, and return true
1905
+			$this->checkout->payment = $payment;
1906
+			return $payment;
1907
+		}
1908
+		// where's my money?
1909
+		return null;
1910
+	}
1911
+
1912
+
1913
+	/**
1914
+	 * _last_second_ticket_verifications
1915
+	 *
1916
+	 * @return bool
1917
+	 * @throws EE_Error
1918
+	 * @throws ReflectionException
1919
+	 */
1920
+	protected function _last_second_ticket_verifications()
1921
+	{
1922
+		// don't bother re-validating if not a return visit
1923
+		if (! $this->checkout->revisit) {
1924
+			return true;
1925
+		}
1926
+		$registrations = $this->checkout->transaction->registrations();
1927
+		if (empty($registrations)) {
1928
+			return false;
1929
+		}
1930
+		foreach ($registrations as $registration) {
1931
+			if ($registration instanceof EE_Registration && ! $registration->is_approved()) {
1932
+				$event = $registration->event_obj();
1933
+				if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1934
+					EE_Error::add_error(
1935
+						apply_filters(
1936
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1937
+							sprintf(
1938
+								esc_html__(
1939
+									'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
1940
+									'event_espresso'
1941
+								),
1942
+								$event->name()
1943
+							)
1944
+						),
1945
+						__FILE__,
1946
+						__FUNCTION__,
1947
+						__LINE__
1948
+					);
1949
+					return false;
1950
+				}
1951
+			}
1952
+		}
1953
+		return true;
1954
+	}
1955
+
1956
+
1957
+	/**
1958
+	 * redirect_form
1959
+	 *
1960
+	 * @return bool
1961
+	 * @throws EE_Error
1962
+	 * @throws InvalidArgumentException
1963
+	 * @throws ReflectionException
1964
+	 * @throws InvalidDataTypeException
1965
+	 * @throws InvalidInterfaceException
1966
+	 */
1967
+	public function redirect_form()
1968
+	{
1969
+		$payment_method_billing_info = $this->_payment_method_billing_info(
1970
+			$this->_get_payment_method_for_selected_method_of_payment()
1971
+		);
1972
+		$html                        = $payment_method_billing_info->get_html();
1973
+		$html                        .= $this->checkout->redirect_form;
1974
+		/** @var ResponseInterface $response */
1975
+		$response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
1976
+		$response->addOutput($html);
1977
+		return true;
1978
+	}
1979
+
1980
+
1981
+	/**
1982
+	 * _billing_form_is_valid
1983
+	 *
1984
+	 * @return bool
1985
+	 * @throws EE_Error
1986
+	 */
1987
+	private function _billing_form_is_valid()
1988
+	{
1989
+		if (! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1990
+			return true;
1991
+		}
1992
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1993
+			if ($this->checkout->billing_form->was_submitted()) {
1994
+				$this->checkout->billing_form->receive_form_submission();
1995
+				if ($this->checkout->billing_form->is_valid()) {
1996
+					return true;
1997
+				}
1998
+				$validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
1999
+				$error_strings     = [];
2000
+				foreach ($validation_errors as $validation_error) {
2001
+					if ($validation_error instanceof EE_Validation_Error) {
2002
+						$form_section = $validation_error->get_form_section();
2003
+						if ($form_section instanceof EE_Form_Input_Base) {
2004
+							$label = $form_section->html_label_text();
2005
+						} elseif ($form_section instanceof EE_Form_Section_Base) {
2006
+							$label = $form_section->name();
2007
+						} else {
2008
+							$label = esc_html__('Validation Error', 'event_espresso');
2009
+						}
2010
+						$error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
2011
+					}
2012
+				}
2013
+				EE_Error::add_error(
2014
+					sprintf(
2015
+						esc_html__(
2016
+							'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s',
2017
+							'event_espresso'
2018
+						),
2019
+						'<br/>',
2020
+						implode('<br/>', $error_strings)
2021
+					),
2022
+					__FILE__,
2023
+					__FUNCTION__,
2024
+					__LINE__
2025
+				);
2026
+			} else {
2027
+				EE_Error::add_error(
2028
+					esc_html__(
2029
+						'The billing form was not submitted or something prevented it\'s submission.',
2030
+						'event_espresso'
2031
+					),
2032
+					__FILE__,
2033
+					__FUNCTION__,
2034
+					__LINE__
2035
+				);
2036
+			}
2037
+		} else {
2038
+			EE_Error::add_error(
2039
+				esc_html__(
2040
+					'The submitted billing form is invalid possibly due to a technical reason.',
2041
+					'event_espresso'
2042
+				),
2043
+				__FILE__,
2044
+				__FUNCTION__,
2045
+				__LINE__
2046
+			);
2047
+		}
2048
+		return false;
2049
+	}
2050
+
2051
+
2052
+	/**
2053
+	 * _setup_primary_registrant_prior_to_payment
2054
+	 * ensures that the primary registrant has a valid attendee object created with the critical details populated
2055
+	 * (first & last name & email) and that both the transaction object and primary registration object have been saved
2056
+	 * plz note that any other registrations will NOT be saved at this point (because they may not have any details
2057
+	 * yet)
2058
+	 *
2059
+	 * @return bool
2060
+	 * @throws EE_Error
2061
+	 * @throws InvalidArgumentException
2062
+	 * @throws ReflectionException
2063
+	 * @throws RuntimeException
2064
+	 * @throws InvalidDataTypeException
2065
+	 * @throws InvalidInterfaceException
2066
+	 */
2067
+	private function _setup_primary_registrant_prior_to_payment()
2068
+	{
2069
+		// check if transaction has a primary registrant and that it has a related Attendee object
2070
+		// if not, then we need to at least gather some primary registrant data before attempting payment
2071
+		if (
2072
+			$this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
2073
+			&& ! $this->checkout->transaction_has_primary_registrant()
2074
+			&& ! $this->_capture_primary_registration_data_from_billing_form()
2075
+		) {
2076
+			return false;
2077
+		}
2078
+		// because saving an object clears it's cache, we need to do the chevy shuffle
2079
+		// grab the primary_registration object
2080
+		$primary_registration = $this->checkout->transaction->primary_registration();
2081
+		// at this point we'll consider a TXN to not have been failed
2082
+		$this->checkout->transaction->toggle_failed_transaction_status();
2083
+		// save the TXN ( which clears cached copy of primary_registration)
2084
+		$this->checkout->transaction->save();
2085
+		// grab TXN ID and save it to the primary_registration
2086
+		$primary_registration->set_transaction_id($this->checkout->transaction->ID());
2087
+		// save what we have so far
2088
+		$primary_registration->save();
2089
+		return true;
2090
+	}
2091
+
2092
+
2093
+	/**
2094
+	 * _capture_primary_registration_data_from_billing_form
2095
+	 *
2096
+	 * @return bool
2097
+	 * @throws EE_Error
2098
+	 * @throws InvalidArgumentException
2099
+	 * @throws ReflectionException
2100
+	 * @throws InvalidDataTypeException
2101
+	 * @throws InvalidInterfaceException
2102
+	 */
2103
+	private function _capture_primary_registration_data_from_billing_form()
2104
+	{
2105
+		// convert billing form data into an attendee
2106
+		$this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
2107
+		if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2108
+			EE_Error::add_error(
2109
+				sprintf(
2110
+					esc_html__(
2111
+						'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.',
2112
+						'event_espresso'
2113
+					),
2114
+					'<br/>',
2115
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2116
+				),
2117
+				__FILE__,
2118
+				__FUNCTION__,
2119
+				__LINE__
2120
+			);
2121
+			return false;
2122
+		}
2123
+		$primary_registration = $this->checkout->transaction->primary_registration();
2124
+		if (! $primary_registration instanceof EE_Registration) {
2125
+			EE_Error::add_error(
2126
+				sprintf(
2127
+					esc_html__(
2128
+						'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2129
+						'event_espresso'
2130
+					),
2131
+					'<br/>',
2132
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2133
+				),
2134
+				__FILE__,
2135
+				__FUNCTION__,
2136
+				__LINE__
2137
+			);
2138
+			return false;
2139
+		}
2140
+		if (
2141
+			! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee')
2142
+			  instanceof
2143
+			  EE_Attendee
2144
+		) {
2145
+			EE_Error::add_error(
2146
+				sprintf(
2147
+					esc_html__(
2148
+						'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.',
2149
+						'event_espresso'
2150
+					),
2151
+					'<br/>',
2152
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2153
+				),
2154
+				__FILE__,
2155
+				__FUNCTION__,
2156
+				__LINE__
2157
+			);
2158
+			return false;
2159
+		}
2160
+		/** @type EE_Registration_Processor $registration_processor */
2161
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
2162
+		// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
2163
+		$registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
2164
+		return true;
2165
+	}
2166
+
2167
+
2168
+	/**
2169
+	 * _get_payment_method_for_selected_method_of_payment
2170
+	 * retrieves a valid payment method
2171
+	 *
2172
+	 * @return EE_Payment_Method
2173
+	 * @throws EE_Error
2174
+	 * @throws InvalidArgumentException
2175
+	 * @throws ReflectionException
2176
+	 * @throws InvalidDataTypeException
2177
+	 * @throws InvalidInterfaceException
2178
+	 */
2179
+	private function _get_payment_method_for_selected_method_of_payment()
2180
+	{
2181
+		if ($this->checkout->selected_method_of_payment === 'events_sold_out') {
2182
+			$this->_redirect_because_event_sold_out();
2183
+			return null;
2184
+		}
2185
+		// get EE_Payment_Method object
2186
+		if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) {
2187
+			$payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
2188
+		} else {
2189
+			// load EEM_Payment_Method
2190
+			EE_Registry::instance()->load_model('Payment_Method');
2191
+			$EEM_Payment_Method = EEM_Payment_Method::instance();
2192
+			$payment_method     = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2193
+		}
2194
+		// verify $payment_method
2195
+		if (! $payment_method instanceof EE_Payment_Method) {
2196
+			// not a payment
2197
+			EE_Error::add_error(
2198
+				sprintf(
2199
+					esc_html__(
2200
+						'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2201
+						'event_espresso'
2202
+					),
2203
+					'<br/>',
2204
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2205
+				),
2206
+				__FILE__,
2207
+				__FUNCTION__,
2208
+				__LINE__
2209
+			);
2210
+			return null;
2211
+		}
2212
+		// and verify it has a valid Payment_Method Type object
2213
+		if (! $payment_method->type_obj() instanceof EE_PMT_Base) {
2214
+			// not a payment
2215
+			EE_Error::add_error(
2216
+				sprintf(
2217
+					esc_html__(
2218
+						'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2219
+						'event_espresso'
2220
+					),
2221
+					'<br/>',
2222
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2223
+				),
2224
+				__FILE__,
2225
+				__FUNCTION__,
2226
+				__LINE__
2227
+			);
2228
+			return null;
2229
+		}
2230
+		return $payment_method;
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 *    _attempt_payment
2236
+	 *
2237
+	 * @access    private
2238
+	 * @type    EE_Payment_Method $payment_method
2239
+	 * @return mixed EE_Payment | boolean
2240
+	 * @throws EE_Error
2241
+	 * @throws InvalidArgumentException
2242
+	 * @throws ReflectionException
2243
+	 * @throws InvalidDataTypeException
2244
+	 * @throws InvalidInterfaceException
2245
+	 */
2246
+	private function _attempt_payment(EE_Payment_Method $payment_method)
2247
+	{
2248
+		$payment = null;
2249
+		$this->checkout->transaction->save();
2250
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2251
+		if (! $payment_processor instanceof EE_Payment_Processor) {
2252
+			return false;
2253
+		}
2254
+		try {
2255
+			$payment_processor->set_revisit($this->checkout->revisit);
2256
+			// generate payment object
2257
+			$payment = $payment_processor->process_payment(
2258
+				$payment_method,
2259
+				$this->checkout->transaction,
2260
+				$this->checkout->amount_owing,
2261
+				$this->checkout->billing_form instanceof EE_Billing_Info_Form
2262
+					? $this->checkout->billing_form
2263
+					: null,
2264
+				$this->_get_return_url($payment_method),
2265
+				'CART',
2266
+				$this->checkout->admin_request,
2267
+				true,
2268
+				$this->reg_step_url()
2269
+			);
2270
+		} catch (Exception $e) {
2271
+			$this->_handle_payment_processor_exception($e);
2272
+		}
2273
+		return $payment;
2274
+	}
2275
+
2276
+
2277
+	/**
2278
+	 * _handle_payment_processor_exception
2279
+	 *
2280
+	 * @param Exception $e
2281
+	 * @return void
2282
+	 * @throws EE_Error
2283
+	 * @throws InvalidArgumentException
2284
+	 * @throws InvalidDataTypeException
2285
+	 * @throws InvalidInterfaceException
2286
+	 */
2287
+	protected function _handle_payment_processor_exception(Exception $e)
2288
+	{
2289
+		EE_Error::add_error(
2290
+			sprintf(
2291
+				esc_html__(
2292
+					'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s',
2293
+					'event_espresso'
2294
+				),
2295
+				'<br/>',
2296
+				EE_Registry::instance()->CFG->organization->get_pretty('email'),
2297
+				$e->getMessage(),
2298
+				$e->getFile(),
2299
+				$e->getLine()
2300
+			),
2301
+			__FILE__,
2302
+			__FUNCTION__,
2303
+			__LINE__
2304
+		);
2305
+	}
2306
+
2307
+
2308
+	/**
2309
+	 * _get_return_url
2310
+	 *
2311
+	 * @param EE_Payment_Method $payment_method
2312
+	 * @return string
2313
+	 * @throws EE_Error
2314
+	 * @throws ReflectionException
2315
+	 */
2316
+	protected function _get_return_url(EE_Payment_Method $payment_method)
2317
+	{
2318
+		$return_url = '';
2319
+		switch ($payment_method->type_obj()->payment_occurs()) {
2320
+			case EE_PMT_Base::offsite:
2321
+				$return_url = add_query_arg(
2322
+					[
2323
+						'action'                     => 'process_gateway_response',
2324
+						'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2325
+						'spco_txn'                   => $this->checkout->transaction->ID(),
2326
+					],
2327
+					$this->reg_step_url()
2328
+				);
2329
+				break;
2330
+			case EE_PMT_Base::onsite:
2331
+			case EE_PMT_Base::offline:
2332
+				$return_url = $this->checkout->next_step->reg_step_url();
2333
+				break;
2334
+		}
2335
+		return $return_url;
2336
+	}
2337
+
2338
+
2339
+	/**
2340
+	 * _validate_payment
2341
+	 *
2342
+	 * @param EE_Payment $payment
2343
+	 * @return EE_Payment|FALSE
2344
+	 * @throws EE_Error
2345
+	 * @throws InvalidArgumentException
2346
+	 * @throws InvalidDataTypeException
2347
+	 * @throws InvalidInterfaceException
2348
+	 */
2349
+	private function _validate_payment($payment = null)
2350
+	{
2351
+		if ($this->checkout->payment_method->is_off_line()) {
2352
+			return true;
2353
+		}
2354
+		// verify payment object
2355
+		if (! $payment instanceof EE_Payment) {
2356
+			// not a payment
2357
+			EE_Error::add_error(
2358
+				sprintf(
2359
+					esc_html__(
2360
+						'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.',
2361
+						'event_espresso'
2362
+					),
2363
+					'<br/>',
2364
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2365
+				),
2366
+				__FILE__,
2367
+				__FUNCTION__,
2368
+				__LINE__
2369
+			);
2370
+			return false;
2371
+		}
2372
+		return $payment;
2373
+	}
2374
+
2375
+
2376
+	/**
2377
+	 * _post_payment_processing
2378
+	 *
2379
+	 * @param EE_Payment|bool $payment
2380
+	 * @return bool|EE_Payment
2381
+	 * @throws EE_Error
2382
+	 * @throws InvalidArgumentException
2383
+	 * @throws InvalidDataTypeException
2384
+	 * @throws InvalidInterfaceException
2385
+	 * @throws ReflectionException
2386
+	 */
2387
+	private function _post_payment_processing($payment = null)
2388
+	{
2389
+		// Off-Line payment?
2390
+		if ($payment === true) {
2391
+			return true;
2392
+		}
2393
+		if ($payment instanceof EE_Payment) {
2394
+			// Should the user be redirected?
2395
+			if ($payment->redirect_url()) {
2396
+				do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
2397
+				$this->checkout->redirect      = true;
2398
+				$this->checkout->redirect_form = $payment->redirect_form();
2399
+				$this->checkout->redirect_url  = $this->reg_step_url('redirect_form');
2400
+				// set JSON response
2401
+				$this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
2402
+				// and lastly, let's bump the payment status to pending
2403
+				$payment->set_status(EEM_Payment::status_id_pending);
2404
+				$payment->save();
2405
+			} elseif (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2406
+				// User shouldn't be redirected. So let's process it here.
2407
+				// $this->_setup_redirect_for_next_step();
2408
+				$this->checkout->continue_reg = false;
2409
+			}
2410
+			return $payment;
2411
+		}
2412
+		// ummm ya... not Off-Line, not On-Site, not off-Site ????
2413
+		$this->checkout->continue_reg = false;
2414
+		return false;
2415
+	}
2416
+
2417
+
2418
+	/**
2419
+	 *    _process_payment_status
2420
+	 *
2421
+	 * @type    EE_Payment $payment
2422
+	 * @param string       $payment_occurs
2423
+	 * @return bool
2424
+	 * @throws EE_Error
2425
+	 * @throws InvalidArgumentException
2426
+	 * @throws InvalidDataTypeException
2427
+	 * @throws InvalidInterfaceException
2428
+	 */
2429
+	private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline)
2430
+	{
2431
+		// off-line payment? carry on
2432
+		if ($payment_occurs === EE_PMT_Base::offline) {
2433
+			return true;
2434
+		}
2435
+		// verify payment validity
2436
+		if ($payment instanceof EE_Payment) {
2437
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
2438
+			$msg = $payment->gateway_response();
2439
+			// check results
2440
+			switch ($payment->status()) {
2441
+				// good payment
2442
+				case EEM_Payment::status_id_approved:
2443
+					EE_Error::add_success(
2444
+						esc_html__('Your payment was processed successfully.', 'event_espresso'),
2445
+						__FILE__,
2446
+						__FUNCTION__,
2447
+						__LINE__
2448
+					);
2449
+					return true;
2450
+				// slow payment
2451
+				case EEM_Payment::status_id_pending:
2452
+					if (empty($msg)) {
2453
+						$msg = esc_html__(
2454
+							'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.',
2455
+							'event_espresso'
2456
+						);
2457
+					}
2458
+					EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
2459
+					return true;
2460
+				// don't wanna payment
2461
+				case EEM_Payment::status_id_cancelled:
2462
+					if (empty($msg)) {
2463
+						$msg = _n(
2464
+							'Payment cancelled. Please try again.',
2465
+							'Payment cancelled. Please try again or select another method of payment.',
2466
+							count($this->checkout->available_payment_methods),
2467
+							'event_espresso'
2468
+						);
2469
+					}
2470
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2471
+					return false;
2472
+				// not enough payment
2473
+				case EEM_Payment::status_id_declined:
2474
+					if (empty($msg)) {
2475
+						$msg = _n(
2476
+							'We\'re sorry but your payment was declined. Please try again.',
2477
+							'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
2478
+							count($this->checkout->available_payment_methods),
2479
+							'event_espresso'
2480
+						);
2481
+					}
2482
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2483
+					return false;
2484
+				// bad payment
2485
+				case EEM_Payment::status_id_failed:
2486
+					if (! empty($msg)) {
2487
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2488
+						return false;
2489
+					}
2490
+					// default to error below
2491
+					break;
2492
+			}
2493
+		}
2494
+		// off-site payment gateway responses are too unreliable, so let's just assume that
2495
+		// the payment processing is just running slower than the registrant's request
2496
+		if ($payment_occurs === EE_PMT_Base::offsite) {
2497
+			return true;
2498
+		}
2499
+		EE_Error::add_error(
2500
+			sprintf(
2501
+				esc_html__(
2502
+					'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.',
2503
+					'event_espresso'
2504
+				),
2505
+				'<br/>',
2506
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
2507
+			),
2508
+			__FILE__,
2509
+			__FUNCTION__,
2510
+			__LINE__
2511
+		);
2512
+		return false;
2513
+	}
2514
+
2515
+
2516
+
2517
+
2518
+
2519
+
2520
+	/********************************************************************************************************/
2521
+	/**********************************  PROCESS GATEWAY RESPONSE  **********************************/
2522
+	/********************************************************************************************************/
2523
+	/**
2524
+	 * process_gateway_response
2525
+	 * this is the return point for Off-Site Payment Methods
2526
+	 * It will attempt to "handle the IPN" if it appears that this has not already occurred,
2527
+	 * otherwise, it will load up the last payment made for the TXN.
2528
+	 * If the payment retrieved looks good, it will then either:
2529
+	 *    complete the current step and allow advancement to the next reg step
2530
+	 *        or present the payment options again
2531
+	 *
2532
+	 * @return bool
2533
+	 * @throws EE_Error
2534
+	 * @throws InvalidArgumentException
2535
+	 * @throws ReflectionException
2536
+	 * @throws InvalidDataTypeException
2537
+	 * @throws InvalidInterfaceException
2538
+	 */
2539
+	public function process_gateway_response()
2540
+	{
2541
+		// how have they chosen to pay?
2542
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2543
+		// get EE_Payment_Method object
2544
+		if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2545
+			$this->checkout->continue_reg = false;
2546
+			return false;
2547
+		}
2548
+		if (! $this->checkout->payment_method->is_off_site()) {
2549
+			return false;
2550
+		}
2551
+		$this->_validate_offsite_return();
2552
+		// verify TXN
2553
+		if ($this->checkout->transaction instanceof EE_Transaction) {
2554
+			$gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2555
+			if (! $gateway instanceof EE_Offsite_Gateway) {
2556
+				$this->checkout->continue_reg = false;
2557
+				return false;
2558
+			}
2559
+			$payment = $this->_process_off_site_payment($gateway);
2560
+			$payment = $this->_process_cancelled_payments($payment);
2561
+			$payment = $this->_validate_payment($payment);
2562
+			// if payment was not declined by the payment gateway or cancelled by the registrant
2563
+			if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
2564
+				// $this->_setup_redirect_for_next_step();
2565
+				// store that for later
2566
+				$this->checkout->payment = $payment;
2567
+				// mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2568
+				// because we will complete this step during the IPN processing then
2569
+				if (! $this->handle_IPN_in_this_request()) {
2570
+					$this->set_completed();
2571
+				}
2572
+				return true;
2573
+			}
2574
+		}
2575
+		// DEBUG LOG
2576
+		// $this->checkout->log(
2577
+		//     __CLASS__,
2578
+		//     __FUNCTION__,
2579
+		//     __LINE__,
2580
+		//     array('payment' => $payment)
2581
+		// );
2582
+		$this->checkout->continue_reg = false;
2583
+		return false;
2584
+	}
2585
+
2586
+
2587
+	/**
2588
+	 * _validate_return
2589
+	 *
2590
+	 * @return void
2591
+	 * @throws EE_Error
2592
+	 * @throws InvalidArgumentException
2593
+	 * @throws InvalidDataTypeException
2594
+	 * @throws InvalidInterfaceException
2595
+	 * @throws ReflectionException
2596
+	 */
2597
+	private function _validate_offsite_return()
2598
+	{
2599
+		$TXN_ID = $this->request->getRequestParam('spco_txn', 0, 'int');
2600
+		if ($TXN_ID !== $this->checkout->transaction->ID()) {
2601
+			// Houston... we might have a problem
2602
+			$invalid_TXN = false;
2603
+			// first gather some info
2604
+			$valid_TXN          = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2605
+			$primary_registrant = $valid_TXN instanceof EE_Transaction
2606
+				? $valid_TXN->primary_registration()
2607
+				: null;
2608
+			// let's start by retrieving the cart for this TXN
2609
+			$cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction);
2610
+			if ($cart instanceof EE_Cart) {
2611
+				// verify that the current cart has tickets
2612
+				$tickets = $cart->get_tickets();
2613
+				if (empty($tickets)) {
2614
+					$invalid_TXN = true;
2615
+				}
2616
+			} else {
2617
+				$invalid_TXN = true;
2618
+			}
2619
+			$valid_TXN_SID = $primary_registrant instanceof EE_Registration
2620
+				? $primary_registrant->session_ID()
2621
+				: null;
2622
+			// validate current Session ID and compare against valid TXN session ID
2623
+			if (
2624
+				$invalid_TXN // if this is already true, then skip other checks
2625
+				|| EE_Session::instance()->id() === null
2626
+				|| (
2627
+					// WARNING !!!
2628
+					// this could be PayPal sending back duplicate requests (ya they do that)
2629
+					// or it **could** mean someone is simply registering AGAIN after having just done so
2630
+					// so now we need to determine if this current TXN looks valid or not
2631
+					// and whether this reg step has even been started ?
2632
+					EE_Session::instance()->id() === $valid_TXN_SID
2633
+					// really? you're half way through this reg step, but you never started it ?
2634
+					&& $this->checkout->transaction->reg_step_completed($this->slug()) === false
2635
+				)
2636
+			) {
2637
+				$invalid_TXN = true;
2638
+			}
2639
+			if ($invalid_TXN) {
2640
+				// is the valid TXN completed ?
2641
+				if ($valid_TXN instanceof EE_Transaction) {
2642
+					// has this step even been started ?
2643
+					$reg_step_completed = $valid_TXN->reg_step_completed($this->slug());
2644
+					if ($reg_step_completed !== false && $reg_step_completed !== true) {
2645
+						// so it **looks** like this is a double request from PayPal
2646
+						// so let's try to pick up where we left off
2647
+						$this->checkout->transaction = $valid_TXN;
2648
+						$this->checkout->refresh_all_entities(true);
2649
+						return;
2650
+					}
2651
+				}
2652
+				// you appear to be lost?
2653
+				$this->_redirect_wayward_request($primary_registrant);
2654
+			}
2655
+		}
2656
+	}
2657
+
2658
+
2659
+	/**
2660
+	 * _redirect_wayward_request
2661
+	 *
2662
+	 * @param EE_Registration|null $primary_registrant
2663
+	 * @return void
2664
+	 * @throws EE_Error
2665
+	 * @throws InvalidArgumentException
2666
+	 * @throws InvalidDataTypeException
2667
+	 * @throws InvalidInterfaceException
2668
+	 * @throws ReflectionException
2669
+	 */
2670
+	private function _redirect_wayward_request(EE_Registration $primary_registrant)
2671
+	{
2672
+		if (! $primary_registrant instanceof EE_Registration) {
2673
+			// try redirecting based on the current TXN
2674
+			$primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2675
+				? $this->checkout->transaction->primary_registration()
2676
+				: null;
2677
+		}
2678
+		if (! $primary_registrant instanceof EE_Registration) {
2679
+			EE_Error::add_error(
2680
+				sprintf(
2681
+					esc_html__(
2682
+						'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.',
2683
+						'event_espresso'
2684
+					),
2685
+					'<br/>',
2686
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2687
+				),
2688
+				__FILE__,
2689
+				__FUNCTION__,
2690
+				__LINE__
2691
+			);
2692
+			return;
2693
+		}
2694
+		// make sure transaction is not locked
2695
+		$this->checkout->transaction->unlock();
2696
+		wp_safe_redirect(
2697
+			add_query_arg(
2698
+				[
2699
+					'e_reg_url_link' => $primary_registrant->reg_url_link(),
2700
+				],
2701
+				$this->checkout->thank_you_page_url
2702
+			)
2703
+		);
2704
+		exit();
2705
+	}
2706
+
2707
+
2708
+	/**
2709
+	 * _process_off_site_payment
2710
+	 *
2711
+	 * @param EE_Offsite_Gateway $gateway
2712
+	 * @return EE_Payment
2713
+	 * @throws EE_Error
2714
+	 * @throws InvalidArgumentException
2715
+	 * @throws InvalidDataTypeException
2716
+	 * @throws InvalidInterfaceException
2717
+	 * @throws ReflectionException
2718
+	 */
2719
+	private function _process_off_site_payment(EE_Offsite_Gateway $gateway)
2720
+	{
2721
+		try {
2722
+			$request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
2723
+			$request_data = $request->requestParams();
2724
+			// if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
2725
+			$this->set_handle_IPN_in_this_request(
2726
+				$gateway->handle_IPN_in_this_request($request_data, false)
2727
+			);
2728
+			if ($this->handle_IPN_in_this_request()) {
2729
+				// get payment details and process results
2730
+				/** @type EE_Payment_Processor $payment_processor */
2731
+				$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2732
+				$payment           = $payment_processor->process_ipn(
2733
+					$request_data,
2734
+					$this->checkout->transaction,
2735
+					$this->checkout->payment_method,
2736
+					true,
2737
+					false
2738
+				);
2739
+				// $payment_source = 'process_ipn';
2740
+			} else {
2741
+				$payment = $this->checkout->transaction->last_payment();
2742
+				// $payment_source = 'last_payment';
2743
+			}
2744
+		} catch (Exception $e) {
2745
+			// let's just eat the exception and try to move on using any previously set payment info
2746
+			$payment = $this->checkout->transaction->last_payment();
2747
+			// $payment_source = 'last_payment after Exception';
2748
+			// but if we STILL don't have a payment object
2749
+			if (! $payment instanceof EE_Payment) {
2750
+				// then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2751
+				$this->_handle_payment_processor_exception($e);
2752
+			}
2753
+		}
2754
+		return $payment;
2755
+	}
2756
+
2757
+
2758
+	/**
2759
+	 * _process_cancelled_payments
2760
+	 * just makes sure that the payment status gets updated correctly
2761
+	 * so tha tan error isn't generated during payment validation
2762
+	 *
2763
+	 * @param EE_Payment $payment
2764
+	 * @return EE_Payment|null
2765
+	 * @throws EE_Error
2766
+	 */
2767
+	private function _process_cancelled_payments($payment = null)
2768
+	{
2769
+		if (
2770
+			$payment instanceof EE_Payment
2771
+			&& $this->request->requestParamIsSet('ee_cancel_payment')
2772
+			&& $payment->status() === EEM_Payment::status_id_failed
2773
+		) {
2774
+			$payment->set_status(EEM_Payment::status_id_cancelled);
2775
+		}
2776
+		return $payment;
2777
+	}
2778
+
2779
+
2780
+	/**
2781
+	 *    get_transaction_details_for_gateways
2782
+	 *
2783
+	 * @access    public
2784
+	 * @return void
2785
+	 * @throws EE_Error
2786
+	 * @throws InvalidArgumentException
2787
+	 * @throws ReflectionException
2788
+	 * @throws InvalidDataTypeException
2789
+	 * @throws InvalidInterfaceException
2790
+	 */
2791
+	public function get_transaction_details_for_gateways()
2792
+	{
2793
+		$txn_details = [];
2794
+		// ya gotta make a choice man
2795
+		if (empty($this->checkout->selected_method_of_payment)) {
2796
+			$txn_details = [
2797
+				'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'),
2798
+			];
2799
+		}
2800
+		// get EE_Payment_Method object
2801
+		if (
2802
+			empty($txn_details)
2803
+			&& ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2804
+		) {
2805
+			$txn_details = [
2806
+				'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2807
+				'error'                      => esc_html__(
2808
+					'A valid Payment Method could not be determined.',
2809
+					'event_espresso'
2810
+				),
2811
+			];
2812
+		}
2813
+		if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2814
+			$return_url  = $this->_get_return_url($this->checkout->payment_method);
2815
+			$txn_details = [
2816
+				'TXN_ID'         => $this->checkout->transaction->ID(),
2817
+				'TXN_timestamp'  => $this->checkout->transaction->datetime(),
2818
+				'TXN_total'      => $this->checkout->transaction->total(),
2819
+				'TXN_paid'       => $this->checkout->transaction->paid(),
2820
+				'TXN_reg_steps'  => $this->checkout->transaction->reg_steps(),
2821
+				'STS_ID'         => $this->checkout->transaction->status_ID(),
2822
+				'PMD_ID'         => $this->checkout->transaction->payment_method_ID(),
2823
+				'payment_amount' => $this->checkout->amount_owing,
2824
+				'return_url'     => $return_url,
2825
+				'cancel_url'     => add_query_arg(['ee_cancel_payment' => true], $return_url),
2826
+				'notify_url'     => EE_Config::instance()->core->txn_page_url(
2827
+					[
2828
+						'e_reg_url_link'    => $this->checkout->transaction->primary_registration()->reg_url_link(),
2829
+						'ee_payment_method' => $this->checkout->payment_method->slug(),
2830
+					]
2831
+				),
2832
+			];
2833
+		}
2834
+		echo wp_json_encode($txn_details);
2835
+		exit();
2836
+	}
2837
+
2838
+
2839
+	/**
2840
+	 *    __sleep
2841
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
2842
+	 * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
2843
+	 * reg form, because if needed, it will be regenerated anyways
2844
+	 *
2845
+	 * @return array
2846
+	 */
2847
+	public function __sleep()
2848
+	{
2849
+		// remove the reg form and the checkout
2850
+		return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout', 'line_item_display']);
2851
+	}
2852 2852
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Message.class.php 1 patch
Indentation   +869 added lines, -869 removed lines patch added patch discarded remove patch
@@ -9,877 +9,877 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Message extends EE_Base_Class implements EEI_Admin_Links
11 11
 {
12
-    /**
13
-     * @deprecated 4.9.0  Added for backward compat with add-on's
14
-     * @type null
15
-     */
16
-    public $template_pack;
17
-
18
-    /**
19
-     * @deprecated 4.9.0 Added for backward compat with add-on's
20
-     * @type null
21
-     */
22
-    public $template_variation;
23
-
24
-    /**
25
-     * @deprecated 4.9.0 Added for backward compat with add-on's
26
-     * @type string
27
-     */
28
-    public $content = '';
29
-
30
-
31
-    /**
32
-     * @type EE_messenger $_messenger
33
-     */
34
-    protected $_messenger = null;
35
-
36
-    /**
37
-     * @type EE_message_type $_message_type
38
-     */
39
-    protected $_message_type = null;
40
-
41
-
42
-    /**
43
-     * @param array  $props_n_values
44
-     * @param string $timezone
45
-     * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
46
-     *                             format.
47
-     * @return EE_Message
48
-     */
49
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
-    {
51
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
52
-        // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
53
-        if (! $has_object) {
54
-            EE_Registry::instance()->load_helper('URL');
55
-            $props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
56
-        }
57
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
-    }
59
-
60
-
61
-    /**
62
-     * @param array  $props_n_values
63
-     * @param string $timezone
64
-     * @return EE_Message
65
-     */
66
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
-    {
68
-        return new self($props_n_values, true, $timezone);
69
-    }
70
-
71
-
72
-    /**
73
-     * Gets MSG_token
74
-     *
75
-     * @return int
76
-     */
77
-    public function MSG_token()
78
-    {
79
-        return $this->get('MSG_token');
80
-    }
81
-
82
-
83
-    /**
84
-     * Sets MSG_token
85
-     *
86
-     * @param int $MSG_token
87
-     */
88
-    public function set_MSG_token($MSG_token)
89
-    {
90
-        $this->set('MSG_token', $MSG_token);
91
-    }
92
-
93
-
94
-    /**
95
-     * Gets GRP_ID
96
-     *
97
-     * @return int
98
-     */
99
-    public function GRP_ID()
100
-    {
101
-        return $this->get('GRP_ID');
102
-    }
103
-
104
-
105
-    /**
106
-     * Sets GRP_ID
107
-     *
108
-     * @param int $GRP_ID
109
-     */
110
-    public function set_GRP_ID($GRP_ID)
111
-    {
112
-        $this->set('GRP_ID', $GRP_ID);
113
-    }
114
-
115
-
116
-    /**
117
-     * Gets TXN_ID
118
-     *
119
-     * @return int
120
-     */
121
-    public function TXN_ID()
122
-    {
123
-        return $this->get('TXN_ID');
124
-    }
125
-
126
-
127
-    /**
128
-     * Sets TXN_ID
129
-     *
130
-     * @param int $TXN_ID
131
-     */
132
-    public function set_TXN_ID($TXN_ID)
133
-    {
134
-        $this->set('TXN_ID', $TXN_ID);
135
-    }
136
-
137
-
138
-    /**
139
-     * Gets messenger
140
-     *
141
-     * @return string
142
-     */
143
-    public function messenger()
144
-    {
145
-        return $this->get('MSG_messenger');
146
-    }
147
-
148
-
149
-    /**
150
-     * Sets messenger
151
-     *
152
-     * @param string $messenger
153
-     */
154
-    public function set_messenger($messenger)
155
-    {
156
-        $this->set('MSG_messenger', $messenger);
157
-    }
158
-
159
-
160
-    /**
161
-     * Returns corresponding messenger object for the set messenger on this message
162
-     *
163
-     * @return EE_messenger | null
164
-     */
165
-    public function messenger_object()
166
-    {
167
-        return $this->_messenger;
168
-    }
169
-
170
-
171
-    /**
172
-     * Sets messenger
173
-     *
174
-     * @param EE_messenger $messenger
175
-     */
176
-    public function set_messenger_object(EE_messenger $messenger)
177
-    {
178
-        $this->_messenger = $messenger;
179
-    }
180
-
181
-
182
-    /**
183
-     * validates messenger
184
-     *
185
-     * @param bool $throw_exceptions
186
-     * @return bool
187
-     * @throws \EE_Error
188
-     */
189
-    public function valid_messenger($throw_exceptions = false)
190
-    {
191
-        if ($this->_messenger instanceof EE_messenger) {
192
-            return true;
193
-        }
194
-        if ($throw_exceptions) {
195
-            throw new EE_Error(
196
-                sprintf(
197
-                    esc_html__(
198
-                        'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
199
-                        'event_espresso'
200
-                    ),
201
-                    $this->messenger()
202
-                )
203
-            );
204
-        }
205
-        return false;
206
-    }
207
-
208
-
209
-    /**
210
-     * This returns the set localized label for the messenger on this message.
211
-     * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
212
-     * with this message.
213
-     *
214
-     * @param   bool $plural whether to return the plural label or not.
215
-     * @return string
216
-     */
217
-    public function messenger_label($plural = false)
218
-    {
219
-        $label_type = $plural ? 'plural' : 'singular';
220
-        $messenger = $this->messenger_object();
221
-        return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
222
-    }
223
-
224
-
225
-    /**
226
-     * Gets message_type
227
-     *
228
-     * @return string
229
-     */
230
-    public function message_type()
231
-    {
232
-        return $this->get('MSG_message_type');
233
-    }
234
-
235
-
236
-    /**
237
-     * Sets message_type
238
-     *
239
-     * @param string $message_type
240
-     */
241
-    public function set_message_type($message_type)
242
-    {
243
-        $this->set('MSG_message_type', $message_type);
244
-    }
245
-
246
-
247
-    /**
248
-     * Returns the message type object for the set message type on this message
249
-     *
250
-     * @return EE_message_type | null
251
-     */
252
-    public function message_type_object()
253
-    {
254
-        return $this->_message_type;
255
-    }
256
-
257
-
258
-    /**
259
-     * Sets message_type
260
-     *
261
-     * @param EE_message_type $message_type
262
-     * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
263
-     *                                        the message type or not.
264
-     */
265
-    public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
266
-    {
267
-        $this->_message_type = $message_type;
268
-        if ($set_priority) {
269
-            $this->set_priority($this->_message_type->get_priority());
270
-        }
271
-    }
272
-
273
-
274
-    /**
275
-     * validates message_type
276
-     *
277
-     * @param bool $throw_exceptions
278
-     * @return bool
279
-     * @throws \EE_Error
280
-     */
281
-    public function valid_message_type($throw_exceptions = false)
282
-    {
283
-        if ($this->_message_type instanceof EE_message_type) {
284
-            return true;
285
-        }
286
-        if ($throw_exceptions) {
287
-            throw new EE_Error(
288
-                sprintf(
289
-                    esc_html__(
290
-                        'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
291
-                        'event_espresso'
292
-                    ),
293
-                    $this->message_type()
294
-                )
295
-            );
296
-        }
297
-        return false;
298
-    }
299
-
300
-
301
-    /**
302
-     * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
303
-     *
304
-     * @param bool $throw_exceptions
305
-     * @return bool
306
-     * @throws \EE_Error
307
-     */
308
-    public function is_valid($throw_exceptions = false)
309
-    {
310
-        if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
311
-            return true;
312
-        }
313
-        return false;
314
-    }
315
-
316
-
317
-    /**
318
-     * This validates whether the internal messenger and message type objects are valid for sending.
319
-     * Three checks are done:
320
-     * 1. There is a valid messenger object.
321
-     * 2. There is a valid message type object.
322
-     * 3. The message type object is active for the messenger.
323
-     *
324
-     * @throws EE_Error  But only if $throw_exceptions is set to true.
325
-     * @param bool $throw_exceptions
326
-     * @return bool
327
-     */
328
-    public function is_valid_for_sending_or_generation($throw_exceptions = false)
329
-    {
330
-        $valid = false;
331
-        if ($this->is_valid($throw_exceptions)) {
332
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
333
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
334
-            $valid = $message_resource_manager->is_message_type_active_for_messenger(
335
-                $this->messenger(),
336
-                $this->message_type()
337
-            );
338
-            if (! $valid && $throw_exceptions) {
339
-                throw new EE_Error(
340
-                    sprintf(
341
-                        esc_html__(
342
-                            'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
-                            'event_espresso'
344
-                        ),
345
-                        $this->message_type(),
346
-                        $this->messenger()
347
-                    )
348
-                );
349
-            }
350
-        }
351
-        return $valid;
352
-    }
353
-
354
-
355
-    /**
356
-     * This returns the set localized label for the message type on this message.
357
-     * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
358
-     * with this message.
359
-     *
360
-     * @param   bool $plural whether to return the plural label or not.
361
-     * @return string
362
-     */
363
-    public function message_type_label($plural = false)
364
-    {
365
-        $label_type = $plural ? 'plural' : 'singular';
366
-        $message_type = $this->message_type_object();
367
-        return $message_type instanceof EE_message_type
368
-            ? $message_type->label[ $label_type ]
369
-            : str_replace(
370
-                '_',
371
-                ' ',
372
-                $this->message_type()
373
-            );
374
-    }
375
-
376
-
377
-    /**
378
-     * Gets context
379
-     *
380
-     * @return string
381
-     */
382
-    public function context()
383
-    {
384
-        return $this->get('MSG_context');
385
-    }
386
-
387
-
388
-    /**
389
-     * This returns the corresponding localized label for the given context slug, if possible from installed message
390
-     * types. Otherwise, this will just return the set context slug on this object.
391
-     *
392
-     * @return string
393
-     */
394
-    public function context_label()
395
-    {
396
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
397
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
398
-        $contexts = $message_resource_manager->get_all_contexts();
399
-        return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
400
-    }
401
-
402
-
403
-    /**
404
-     * Sets context
405
-     *
406
-     * @param string $context
407
-     */
408
-    public function set_context($context)
409
-    {
410
-        $this->set('MSG_context', $context);
411
-    }
412
-
413
-
414
-    /**
415
-     * Gets recipient_ID
416
-     *
417
-     * @return int
418
-     */
419
-    public function recipient_ID()
420
-    {
421
-        return $this->get('MSG_recipient_ID');
422
-    }
423
-
424
-
425
-    /**
426
-     * Sets recipient_ID
427
-     *
428
-     * @param string $recipient_ID
429
-     */
430
-    public function set_recipient_ID($recipient_ID)
431
-    {
432
-        $this->set('MSG_recipient_ID', $recipient_ID);
433
-    }
434
-
435
-
436
-    /**
437
-     * Gets recipient_type
438
-     *
439
-     * @return string
440
-     */
441
-    public function recipient_type()
442
-    {
443
-        return $this->get('MSG_recipient_type');
444
-    }
445
-
446
-
447
-    /**
448
-     * Return the related object matching the recipient type and ID.
449
-     *
450
-     * @return EE_Base_Class | null
451
-     */
452
-    public function recipient_object()
453
-    {
454
-        if (! $this->recipient_type() || ! $this->recipient_ID()) {
455
-            return null;
456
-        }
457
-
458
-        return $this->get_first_related($this->recipient_type());
459
-    }
460
-
461
-
462
-    /**
463
-     * Sets recipient_type
464
-     *
465
-     * @param string $recipient_type
466
-     */
467
-    public function set_recipient_type($recipient_type)
468
-    {
469
-        $this->set('MSG_recipient_type', $recipient_type);
470
-    }
471
-
472
-
473
-    /**
474
-     * Gets content
475
-     *
476
-     * @return string
477
-     */
478
-    public function content()
479
-    {
480
-        return $this->get('MSG_content');
481
-    }
482
-
483
-
484
-    /**
485
-     * Sets content
486
-     *
487
-     * @param string $content
488
-     */
489
-    public function set_content($content)
490
-    {
491
-        $this->set('MSG_content', $content);
492
-    }
493
-
494
-
495
-    /**
496
-     * Gets subject
497
-     *
498
-     * @return string
499
-     */
500
-    public function subject()
501
-    {
502
-        return $this->get('MSG_subject');
503
-    }
504
-
505
-
506
-    /**
507
-     * Sets subject
508
-     *
509
-     * @param string $subject
510
-     */
511
-    public function set_subject($subject)
512
-    {
513
-        $this->set('MSG_subject', $subject);
514
-    }
515
-
516
-
517
-    /**
518
-     * Gets to
519
-     *
520
-     * @return string
521
-     */
522
-    public function to()
523
-    {
524
-        $to = $this->get('MSG_to');
525
-        return empty($to) ? esc_html__('No recipient', 'event_espresso') : $to;
526
-    }
527
-
528
-
529
-    /**
530
-     * Sets to
531
-     *
532
-     * @param string $to
533
-     */
534
-    public function set_to($to)
535
-    {
536
-        $this->set('MSG_to', $to);
537
-    }
538
-
539
-
540
-    /**
541
-     * Gets from
542
-     *
543
-     * @return string
544
-     */
545
-    public function from()
546
-    {
547
-        return $this->get('MSG_from');
548
-    }
549
-
550
-
551
-    /**
552
-     * Sets from
553
-     *
554
-     * @param string $from
555
-     */
556
-    public function set_from($from)
557
-    {
558
-        $this->set('MSG_from', $from);
559
-    }
560
-
561
-
562
-    /**
563
-     * Gets priority
564
-     *
565
-     * @return int
566
-     */
567
-    public function priority()
568
-    {
569
-        return $this->get('MSG_priority');
570
-    }
571
-
572
-
573
-    /**
574
-     * Sets priority
575
-     * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
576
-     * this method calls the send_now method to verify that.
577
-     *
578
-     * @param int $priority
579
-     */
580
-    public function set_priority($priority)
581
-    {
582
-        $priority = $this->send_now() ? EEM_Message::priority_high : $priority;
583
-        parent::set('MSG_priority', $priority);
584
-    }
585
-
586
-
587
-    /**
588
-     * Overrides parent::set method so we can capture any sets for priority.
589
-     *
590
-     * @see parent::set() for phpdocs
591
-     * @param string $field_name
592
-     * @param mixed  $field_value
593
-     * @param bool   $use_default
594
-     * @throws EE_Error
595
-     */
596
-    public function set($field_name, $field_value, $use_default = false)
597
-    {
598
-        if ($field_name === 'MSG_priority') {
599
-            $this->set_priority($field_value);
600
-        }
601
-        parent::set($field_name, $field_value, $use_default);
602
-    }
603
-
604
-
605
-    /**
606
-     * @return bool
607
-     * @throws \EE_Error
608
-     */
609
-    public function send_now()
610
-    {
611
-        $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high
612
-            : $this->priority();
613
-        return $send_now === EEM_Message::priority_high ? true : false;
614
-    }
615
-
616
-
617
-    /**
618
-     * Gets STS_ID
619
-     *
620
-     * @return string
621
-     */
622
-    public function STS_ID()
623
-    {
624
-        return $this->get('STS_ID');
625
-    }
626
-
627
-
628
-    /**
629
-     * Sets STS_ID
630
-     *
631
-     * @param string $STS_ID
632
-     */
633
-    public function set_STS_ID($STS_ID)
634
-    {
635
-        $this->set('STS_ID', $STS_ID);
636
-    }
637
-
638
-
639
-    /**
640
-     * Gets created
641
-     *
642
-     * @return string
643
-     */
644
-    public function created()
645
-    {
646
-        return $this->get('MSG_created');
647
-    }
648
-
649
-
650
-    /**
651
-     * Sets created
652
-     *
653
-     * @param string $created
654
-     */
655
-    public function set_created($created)
656
-    {
657
-        $this->set('MSG_created', $created);
658
-    }
659
-
660
-
661
-    /**
662
-     * Gets modified
663
-     *
664
-     * @return string
665
-     */
666
-    public function modified()
667
-    {
668
-        return $this->get('MSG_modified');
669
-    }
670
-
671
-
672
-    /**
673
-     * Sets modified
674
-     *
675
-     * @param string $modified
676
-     */
677
-    public function set_modified($modified)
678
-    {
679
-        $this->set('MSG_modified', $modified);
680
-    }
681
-
682
-
683
-    /**
684
-     * Sets generation data for this message.
685
-     *
686
-     * @param mixed $data
687
-     */
688
-    public function set_generation_data($data)
689
-    {
690
-        $this->set_field_or_extra_meta('MSG_generation_data', $data);
691
-    }
692
-
693
-
694
-    /**
695
-     * Returns any set generation data for this message.
696
-     *
697
-     * @return mixed|null
698
-     */
699
-    public function get_generation_data()
700
-    {
701
-        return $this->get_field_or_extra_meta('MSG_generation_data');
702
-    }
703
-
704
-
705
-    /**
706
-     * Gets any error message.
707
-     *
708
-     * @return mixed|null
709
-     */
710
-    public function error_message()
711
-    {
712
-        return $this->get_field_or_extra_meta('MSG_error');
713
-    }
714
-
715
-
716
-    /**
717
-     * Sets an error message.
718
-     *
719
-     * @param $message
720
-     * @return bool|int
721
-     */
722
-    public function set_error_message($message)
723
-    {
724
-        return $this->set_field_or_extra_meta('MSG_error', $message);
725
-    }
726
-
727
-
728
-    /**
729
-     * This retrieves the associated template pack with this message.
730
-     *
731
-     * @return EE_Messages_Template_Pack | null
732
-     */
733
-    public function get_template_pack()
734
-    {
735
-        /**
736
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
737
-         */
738
-        if (! empty($this->template_pack)) {
739
-            return $this->template_pack;
740
-        }
741
-        /** @type EE_Message_Template_Group $grp */
742
-        $grp = $this->get_first_related('Message_Template_Group');
743
-        // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
744
-        if (! $grp instanceof EE_Message_Template_Group) {
745
-            $grp = EEM_Message_Template_Group::instance()->get_one(
746
-                array(
747
-                    array(
748
-                        'MTP_messenger'    => $this->messenger(),
749
-                        'MTP_message_type' => $this->message_type(),
750
-                        'MTP_is_global'    => true,
751
-                    ),
752
-                )
753
-            );
754
-        }
755
-
756
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
757
-    }
758
-
759
-
760
-    /**
761
-     * Retrieves the variation used for generating this message.
762
-     *
763
-     * @return string
764
-     */
765
-    public function get_template_pack_variation()
766
-    {
767
-        /**
768
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
769
-         */
770
-        if (! empty($this->template_variation)) {
771
-            return $this->template_variation;
772
-        }
773
-
774
-        /** @type EE_Message_Template_Group $grp */
775
-        $grp = $this->get_first_related('Message_Template_Group');
776
-
777
-        // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
778
-        if (! $grp instanceof EE_Message_Template_Group) {
779
-            $grp = EEM_Message_Template_Group::instance()->get_one(
780
-                array(
781
-                    array(
782
-                        'MTP_messenger'    => $this->messenger(),
783
-                        'MTP_message_type' => $this->message_type(),
784
-                        'MTP_is_global'    => true,
785
-                    ),
786
-                )
787
-            );
788
-        }
789
-
790
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
791
-    }
792
-
793
-    /**
794
-     * Return the link to the admin details for the object.
795
-     *
796
-     * @return string
797
-     */
798
-    public function get_admin_details_link()
799
-    {
800
-        EE_Registry::instance()->load_helper('URL');
801
-        EE_Registry::instance()->load_helper('MSG_Template');
802
-        switch ($this->STS_ID()) {
803
-            case EEM_Message::status_failed:
804
-            case EEM_Message::status_debug_only:
805
-                return EEH_MSG_Template::generate_error_display_trigger($this);
806
-                break;
807
-
808
-            case EEM_Message::status_sent:
809
-                return EEH_MSG_Template::generate_browser_trigger($this);
810
-                break;
811
-
812
-            default:
813
-                return '';
814
-        }
815
-    }
816
-
817
-    /**
818
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
819
-     *
820
-     * @return string
821
-     */
822
-    public function get_admin_edit_link()
823
-    {
824
-        return $this->get_admin_details_link();
825
-    }
826
-
827
-    /**
828
-     * Returns the link to a settings page for the object.
829
-     *
830
-     * @return string
831
-     */
832
-    public function get_admin_settings_link()
833
-    {
834
-        EE_Registry::instance()->load_helper('URL');
835
-        return EEH_URL::add_query_args_and_nonce(
836
-            array(
837
-                'page'   => 'espresso_messages',
838
-                'action' => 'settings',
839
-            ),
840
-            admin_url('admin.php')
841
-        );
842
-    }
843
-
844
-    /**
845
-     * Returns the link to the "overview" for the object (typically the "list table" view).
846
-     *
847
-     * @return string
848
-     */
849
-    public function get_admin_overview_link()
850
-    {
851
-        EE_Registry::instance()->load_helper('URL');
852
-        return EEH_URL::add_query_args_and_nonce(
853
-            array(
854
-                'page'   => 'espresso_messages',
855
-                'action' => 'default',
856
-            ),
857
-            admin_url('admin.php')
858
-        );
859
-    }
860
-
861
-
862
-    /**
863
-     * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
864
-     * it.
865
-     * Note this also SAVES the current message object to the db because it adds an error message to accompany the
866
-     * status.
867
-     *
868
-     */
869
-    public function set_messenger_is_executing()
870
-    {
871
-        $this->set_STS_ID(EEM_Message::status_messenger_executing);
872
-        if (EEM_Message::debug()) {
873
-            $this->set_error_message(
874
-                esc_html__(
875
-                    'A message with this status indicates that there was a problem that occurred while the message was being
12
+	/**
13
+	 * @deprecated 4.9.0  Added for backward compat with add-on's
14
+	 * @type null
15
+	 */
16
+	public $template_pack;
17
+
18
+	/**
19
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
20
+	 * @type null
21
+	 */
22
+	public $template_variation;
23
+
24
+	/**
25
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
26
+	 * @type string
27
+	 */
28
+	public $content = '';
29
+
30
+
31
+	/**
32
+	 * @type EE_messenger $_messenger
33
+	 */
34
+	protected $_messenger = null;
35
+
36
+	/**
37
+	 * @type EE_message_type $_message_type
38
+	 */
39
+	protected $_message_type = null;
40
+
41
+
42
+	/**
43
+	 * @param array  $props_n_values
44
+	 * @param string $timezone
45
+	 * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
46
+	 *                             format.
47
+	 * @return EE_Message
48
+	 */
49
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
+	{
51
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
52
+		// if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
53
+		if (! $has_object) {
54
+			EE_Registry::instance()->load_helper('URL');
55
+			$props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
56
+		}
57
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
58
+	}
59
+
60
+
61
+	/**
62
+	 * @param array  $props_n_values
63
+	 * @param string $timezone
64
+	 * @return EE_Message
65
+	 */
66
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
+	{
68
+		return new self($props_n_values, true, $timezone);
69
+	}
70
+
71
+
72
+	/**
73
+	 * Gets MSG_token
74
+	 *
75
+	 * @return int
76
+	 */
77
+	public function MSG_token()
78
+	{
79
+		return $this->get('MSG_token');
80
+	}
81
+
82
+
83
+	/**
84
+	 * Sets MSG_token
85
+	 *
86
+	 * @param int $MSG_token
87
+	 */
88
+	public function set_MSG_token($MSG_token)
89
+	{
90
+		$this->set('MSG_token', $MSG_token);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Gets GRP_ID
96
+	 *
97
+	 * @return int
98
+	 */
99
+	public function GRP_ID()
100
+	{
101
+		return $this->get('GRP_ID');
102
+	}
103
+
104
+
105
+	/**
106
+	 * Sets GRP_ID
107
+	 *
108
+	 * @param int $GRP_ID
109
+	 */
110
+	public function set_GRP_ID($GRP_ID)
111
+	{
112
+		$this->set('GRP_ID', $GRP_ID);
113
+	}
114
+
115
+
116
+	/**
117
+	 * Gets TXN_ID
118
+	 *
119
+	 * @return int
120
+	 */
121
+	public function TXN_ID()
122
+	{
123
+		return $this->get('TXN_ID');
124
+	}
125
+
126
+
127
+	/**
128
+	 * Sets TXN_ID
129
+	 *
130
+	 * @param int $TXN_ID
131
+	 */
132
+	public function set_TXN_ID($TXN_ID)
133
+	{
134
+		$this->set('TXN_ID', $TXN_ID);
135
+	}
136
+
137
+
138
+	/**
139
+	 * Gets messenger
140
+	 *
141
+	 * @return string
142
+	 */
143
+	public function messenger()
144
+	{
145
+		return $this->get('MSG_messenger');
146
+	}
147
+
148
+
149
+	/**
150
+	 * Sets messenger
151
+	 *
152
+	 * @param string $messenger
153
+	 */
154
+	public function set_messenger($messenger)
155
+	{
156
+		$this->set('MSG_messenger', $messenger);
157
+	}
158
+
159
+
160
+	/**
161
+	 * Returns corresponding messenger object for the set messenger on this message
162
+	 *
163
+	 * @return EE_messenger | null
164
+	 */
165
+	public function messenger_object()
166
+	{
167
+		return $this->_messenger;
168
+	}
169
+
170
+
171
+	/**
172
+	 * Sets messenger
173
+	 *
174
+	 * @param EE_messenger $messenger
175
+	 */
176
+	public function set_messenger_object(EE_messenger $messenger)
177
+	{
178
+		$this->_messenger = $messenger;
179
+	}
180
+
181
+
182
+	/**
183
+	 * validates messenger
184
+	 *
185
+	 * @param bool $throw_exceptions
186
+	 * @return bool
187
+	 * @throws \EE_Error
188
+	 */
189
+	public function valid_messenger($throw_exceptions = false)
190
+	{
191
+		if ($this->_messenger instanceof EE_messenger) {
192
+			return true;
193
+		}
194
+		if ($throw_exceptions) {
195
+			throw new EE_Error(
196
+				sprintf(
197
+					esc_html__(
198
+						'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
199
+						'event_espresso'
200
+					),
201
+					$this->messenger()
202
+				)
203
+			);
204
+		}
205
+		return false;
206
+	}
207
+
208
+
209
+	/**
210
+	 * This returns the set localized label for the messenger on this message.
211
+	 * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
212
+	 * with this message.
213
+	 *
214
+	 * @param   bool $plural whether to return the plural label or not.
215
+	 * @return string
216
+	 */
217
+	public function messenger_label($plural = false)
218
+	{
219
+		$label_type = $plural ? 'plural' : 'singular';
220
+		$messenger = $this->messenger_object();
221
+		return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
222
+	}
223
+
224
+
225
+	/**
226
+	 * Gets message_type
227
+	 *
228
+	 * @return string
229
+	 */
230
+	public function message_type()
231
+	{
232
+		return $this->get('MSG_message_type');
233
+	}
234
+
235
+
236
+	/**
237
+	 * Sets message_type
238
+	 *
239
+	 * @param string $message_type
240
+	 */
241
+	public function set_message_type($message_type)
242
+	{
243
+		$this->set('MSG_message_type', $message_type);
244
+	}
245
+
246
+
247
+	/**
248
+	 * Returns the message type object for the set message type on this message
249
+	 *
250
+	 * @return EE_message_type | null
251
+	 */
252
+	public function message_type_object()
253
+	{
254
+		return $this->_message_type;
255
+	}
256
+
257
+
258
+	/**
259
+	 * Sets message_type
260
+	 *
261
+	 * @param EE_message_type $message_type
262
+	 * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
263
+	 *                                        the message type or not.
264
+	 */
265
+	public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
266
+	{
267
+		$this->_message_type = $message_type;
268
+		if ($set_priority) {
269
+			$this->set_priority($this->_message_type->get_priority());
270
+		}
271
+	}
272
+
273
+
274
+	/**
275
+	 * validates message_type
276
+	 *
277
+	 * @param bool $throw_exceptions
278
+	 * @return bool
279
+	 * @throws \EE_Error
280
+	 */
281
+	public function valid_message_type($throw_exceptions = false)
282
+	{
283
+		if ($this->_message_type instanceof EE_message_type) {
284
+			return true;
285
+		}
286
+		if ($throw_exceptions) {
287
+			throw new EE_Error(
288
+				sprintf(
289
+					esc_html__(
290
+						'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
291
+						'event_espresso'
292
+					),
293
+					$this->message_type()
294
+				)
295
+			);
296
+		}
297
+		return false;
298
+	}
299
+
300
+
301
+	/**
302
+	 * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
303
+	 *
304
+	 * @param bool $throw_exceptions
305
+	 * @return bool
306
+	 * @throws \EE_Error
307
+	 */
308
+	public function is_valid($throw_exceptions = false)
309
+	{
310
+		if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
311
+			return true;
312
+		}
313
+		return false;
314
+	}
315
+
316
+
317
+	/**
318
+	 * This validates whether the internal messenger and message type objects are valid for sending.
319
+	 * Three checks are done:
320
+	 * 1. There is a valid messenger object.
321
+	 * 2. There is a valid message type object.
322
+	 * 3. The message type object is active for the messenger.
323
+	 *
324
+	 * @throws EE_Error  But only if $throw_exceptions is set to true.
325
+	 * @param bool $throw_exceptions
326
+	 * @return bool
327
+	 */
328
+	public function is_valid_for_sending_or_generation($throw_exceptions = false)
329
+	{
330
+		$valid = false;
331
+		if ($this->is_valid($throw_exceptions)) {
332
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
333
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
334
+			$valid = $message_resource_manager->is_message_type_active_for_messenger(
335
+				$this->messenger(),
336
+				$this->message_type()
337
+			);
338
+			if (! $valid && $throw_exceptions) {
339
+				throw new EE_Error(
340
+					sprintf(
341
+						esc_html__(
342
+							'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
+							'event_espresso'
344
+						),
345
+						$this->message_type(),
346
+						$this->messenger()
347
+					)
348
+				);
349
+			}
350
+		}
351
+		return $valid;
352
+	}
353
+
354
+
355
+	/**
356
+	 * This returns the set localized label for the message type on this message.
357
+	 * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
358
+	 * with this message.
359
+	 *
360
+	 * @param   bool $plural whether to return the plural label or not.
361
+	 * @return string
362
+	 */
363
+	public function message_type_label($plural = false)
364
+	{
365
+		$label_type = $plural ? 'plural' : 'singular';
366
+		$message_type = $this->message_type_object();
367
+		return $message_type instanceof EE_message_type
368
+			? $message_type->label[ $label_type ]
369
+			: str_replace(
370
+				'_',
371
+				' ',
372
+				$this->message_type()
373
+			);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Gets context
379
+	 *
380
+	 * @return string
381
+	 */
382
+	public function context()
383
+	{
384
+		return $this->get('MSG_context');
385
+	}
386
+
387
+
388
+	/**
389
+	 * This returns the corresponding localized label for the given context slug, if possible from installed message
390
+	 * types. Otherwise, this will just return the set context slug on this object.
391
+	 *
392
+	 * @return string
393
+	 */
394
+	public function context_label()
395
+	{
396
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
397
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
398
+		$contexts = $message_resource_manager->get_all_contexts();
399
+		return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
400
+	}
401
+
402
+
403
+	/**
404
+	 * Sets context
405
+	 *
406
+	 * @param string $context
407
+	 */
408
+	public function set_context($context)
409
+	{
410
+		$this->set('MSG_context', $context);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Gets recipient_ID
416
+	 *
417
+	 * @return int
418
+	 */
419
+	public function recipient_ID()
420
+	{
421
+		return $this->get('MSG_recipient_ID');
422
+	}
423
+
424
+
425
+	/**
426
+	 * Sets recipient_ID
427
+	 *
428
+	 * @param string $recipient_ID
429
+	 */
430
+	public function set_recipient_ID($recipient_ID)
431
+	{
432
+		$this->set('MSG_recipient_ID', $recipient_ID);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Gets recipient_type
438
+	 *
439
+	 * @return string
440
+	 */
441
+	public function recipient_type()
442
+	{
443
+		return $this->get('MSG_recipient_type');
444
+	}
445
+
446
+
447
+	/**
448
+	 * Return the related object matching the recipient type and ID.
449
+	 *
450
+	 * @return EE_Base_Class | null
451
+	 */
452
+	public function recipient_object()
453
+	{
454
+		if (! $this->recipient_type() || ! $this->recipient_ID()) {
455
+			return null;
456
+		}
457
+
458
+		return $this->get_first_related($this->recipient_type());
459
+	}
460
+
461
+
462
+	/**
463
+	 * Sets recipient_type
464
+	 *
465
+	 * @param string $recipient_type
466
+	 */
467
+	public function set_recipient_type($recipient_type)
468
+	{
469
+		$this->set('MSG_recipient_type', $recipient_type);
470
+	}
471
+
472
+
473
+	/**
474
+	 * Gets content
475
+	 *
476
+	 * @return string
477
+	 */
478
+	public function content()
479
+	{
480
+		return $this->get('MSG_content');
481
+	}
482
+
483
+
484
+	/**
485
+	 * Sets content
486
+	 *
487
+	 * @param string $content
488
+	 */
489
+	public function set_content($content)
490
+	{
491
+		$this->set('MSG_content', $content);
492
+	}
493
+
494
+
495
+	/**
496
+	 * Gets subject
497
+	 *
498
+	 * @return string
499
+	 */
500
+	public function subject()
501
+	{
502
+		return $this->get('MSG_subject');
503
+	}
504
+
505
+
506
+	/**
507
+	 * Sets subject
508
+	 *
509
+	 * @param string $subject
510
+	 */
511
+	public function set_subject($subject)
512
+	{
513
+		$this->set('MSG_subject', $subject);
514
+	}
515
+
516
+
517
+	/**
518
+	 * Gets to
519
+	 *
520
+	 * @return string
521
+	 */
522
+	public function to()
523
+	{
524
+		$to = $this->get('MSG_to');
525
+		return empty($to) ? esc_html__('No recipient', 'event_espresso') : $to;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Sets to
531
+	 *
532
+	 * @param string $to
533
+	 */
534
+	public function set_to($to)
535
+	{
536
+		$this->set('MSG_to', $to);
537
+	}
538
+
539
+
540
+	/**
541
+	 * Gets from
542
+	 *
543
+	 * @return string
544
+	 */
545
+	public function from()
546
+	{
547
+		return $this->get('MSG_from');
548
+	}
549
+
550
+
551
+	/**
552
+	 * Sets from
553
+	 *
554
+	 * @param string $from
555
+	 */
556
+	public function set_from($from)
557
+	{
558
+		$this->set('MSG_from', $from);
559
+	}
560
+
561
+
562
+	/**
563
+	 * Gets priority
564
+	 *
565
+	 * @return int
566
+	 */
567
+	public function priority()
568
+	{
569
+		return $this->get('MSG_priority');
570
+	}
571
+
572
+
573
+	/**
574
+	 * Sets priority
575
+	 * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
576
+	 * this method calls the send_now method to verify that.
577
+	 *
578
+	 * @param int $priority
579
+	 */
580
+	public function set_priority($priority)
581
+	{
582
+		$priority = $this->send_now() ? EEM_Message::priority_high : $priority;
583
+		parent::set('MSG_priority', $priority);
584
+	}
585
+
586
+
587
+	/**
588
+	 * Overrides parent::set method so we can capture any sets for priority.
589
+	 *
590
+	 * @see parent::set() for phpdocs
591
+	 * @param string $field_name
592
+	 * @param mixed  $field_value
593
+	 * @param bool   $use_default
594
+	 * @throws EE_Error
595
+	 */
596
+	public function set($field_name, $field_value, $use_default = false)
597
+	{
598
+		if ($field_name === 'MSG_priority') {
599
+			$this->set_priority($field_value);
600
+		}
601
+		parent::set($field_name, $field_value, $use_default);
602
+	}
603
+
604
+
605
+	/**
606
+	 * @return bool
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function send_now()
610
+	{
611
+		$send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high
612
+			: $this->priority();
613
+		return $send_now === EEM_Message::priority_high ? true : false;
614
+	}
615
+
616
+
617
+	/**
618
+	 * Gets STS_ID
619
+	 *
620
+	 * @return string
621
+	 */
622
+	public function STS_ID()
623
+	{
624
+		return $this->get('STS_ID');
625
+	}
626
+
627
+
628
+	/**
629
+	 * Sets STS_ID
630
+	 *
631
+	 * @param string $STS_ID
632
+	 */
633
+	public function set_STS_ID($STS_ID)
634
+	{
635
+		$this->set('STS_ID', $STS_ID);
636
+	}
637
+
638
+
639
+	/**
640
+	 * Gets created
641
+	 *
642
+	 * @return string
643
+	 */
644
+	public function created()
645
+	{
646
+		return $this->get('MSG_created');
647
+	}
648
+
649
+
650
+	/**
651
+	 * Sets created
652
+	 *
653
+	 * @param string $created
654
+	 */
655
+	public function set_created($created)
656
+	{
657
+		$this->set('MSG_created', $created);
658
+	}
659
+
660
+
661
+	/**
662
+	 * Gets modified
663
+	 *
664
+	 * @return string
665
+	 */
666
+	public function modified()
667
+	{
668
+		return $this->get('MSG_modified');
669
+	}
670
+
671
+
672
+	/**
673
+	 * Sets modified
674
+	 *
675
+	 * @param string $modified
676
+	 */
677
+	public function set_modified($modified)
678
+	{
679
+		$this->set('MSG_modified', $modified);
680
+	}
681
+
682
+
683
+	/**
684
+	 * Sets generation data for this message.
685
+	 *
686
+	 * @param mixed $data
687
+	 */
688
+	public function set_generation_data($data)
689
+	{
690
+		$this->set_field_or_extra_meta('MSG_generation_data', $data);
691
+	}
692
+
693
+
694
+	/**
695
+	 * Returns any set generation data for this message.
696
+	 *
697
+	 * @return mixed|null
698
+	 */
699
+	public function get_generation_data()
700
+	{
701
+		return $this->get_field_or_extra_meta('MSG_generation_data');
702
+	}
703
+
704
+
705
+	/**
706
+	 * Gets any error message.
707
+	 *
708
+	 * @return mixed|null
709
+	 */
710
+	public function error_message()
711
+	{
712
+		return $this->get_field_or_extra_meta('MSG_error');
713
+	}
714
+
715
+
716
+	/**
717
+	 * Sets an error message.
718
+	 *
719
+	 * @param $message
720
+	 * @return bool|int
721
+	 */
722
+	public function set_error_message($message)
723
+	{
724
+		return $this->set_field_or_extra_meta('MSG_error', $message);
725
+	}
726
+
727
+
728
+	/**
729
+	 * This retrieves the associated template pack with this message.
730
+	 *
731
+	 * @return EE_Messages_Template_Pack | null
732
+	 */
733
+	public function get_template_pack()
734
+	{
735
+		/**
736
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
737
+		 */
738
+		if (! empty($this->template_pack)) {
739
+			return $this->template_pack;
740
+		}
741
+		/** @type EE_Message_Template_Group $grp */
742
+		$grp = $this->get_first_related('Message_Template_Group');
743
+		// if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
744
+		if (! $grp instanceof EE_Message_Template_Group) {
745
+			$grp = EEM_Message_Template_Group::instance()->get_one(
746
+				array(
747
+					array(
748
+						'MTP_messenger'    => $this->messenger(),
749
+						'MTP_message_type' => $this->message_type(),
750
+						'MTP_is_global'    => true,
751
+					),
752
+				)
753
+			);
754
+		}
755
+
756
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
757
+	}
758
+
759
+
760
+	/**
761
+	 * Retrieves the variation used for generating this message.
762
+	 *
763
+	 * @return string
764
+	 */
765
+	public function get_template_pack_variation()
766
+	{
767
+		/**
768
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
769
+		 */
770
+		if (! empty($this->template_variation)) {
771
+			return $this->template_variation;
772
+		}
773
+
774
+		/** @type EE_Message_Template_Group $grp */
775
+		$grp = $this->get_first_related('Message_Template_Group');
776
+
777
+		// if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
778
+		if (! $grp instanceof EE_Message_Template_Group) {
779
+			$grp = EEM_Message_Template_Group::instance()->get_one(
780
+				array(
781
+					array(
782
+						'MTP_messenger'    => $this->messenger(),
783
+						'MTP_message_type' => $this->message_type(),
784
+						'MTP_is_global'    => true,
785
+					),
786
+				)
787
+			);
788
+		}
789
+
790
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
791
+	}
792
+
793
+	/**
794
+	 * Return the link to the admin details for the object.
795
+	 *
796
+	 * @return string
797
+	 */
798
+	public function get_admin_details_link()
799
+	{
800
+		EE_Registry::instance()->load_helper('URL');
801
+		EE_Registry::instance()->load_helper('MSG_Template');
802
+		switch ($this->STS_ID()) {
803
+			case EEM_Message::status_failed:
804
+			case EEM_Message::status_debug_only:
805
+				return EEH_MSG_Template::generate_error_display_trigger($this);
806
+				break;
807
+
808
+			case EEM_Message::status_sent:
809
+				return EEH_MSG_Template::generate_browser_trigger($this);
810
+				break;
811
+
812
+			default:
813
+				return '';
814
+		}
815
+	}
816
+
817
+	/**
818
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
819
+	 *
820
+	 * @return string
821
+	 */
822
+	public function get_admin_edit_link()
823
+	{
824
+		return $this->get_admin_details_link();
825
+	}
826
+
827
+	/**
828
+	 * Returns the link to a settings page for the object.
829
+	 *
830
+	 * @return string
831
+	 */
832
+	public function get_admin_settings_link()
833
+	{
834
+		EE_Registry::instance()->load_helper('URL');
835
+		return EEH_URL::add_query_args_and_nonce(
836
+			array(
837
+				'page'   => 'espresso_messages',
838
+				'action' => 'settings',
839
+			),
840
+			admin_url('admin.php')
841
+		);
842
+	}
843
+
844
+	/**
845
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
846
+	 *
847
+	 * @return string
848
+	 */
849
+	public function get_admin_overview_link()
850
+	{
851
+		EE_Registry::instance()->load_helper('URL');
852
+		return EEH_URL::add_query_args_and_nonce(
853
+			array(
854
+				'page'   => 'espresso_messages',
855
+				'action' => 'default',
856
+			),
857
+			admin_url('admin.php')
858
+		);
859
+	}
860
+
861
+
862
+	/**
863
+	 * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
864
+	 * it.
865
+	 * Note this also SAVES the current message object to the db because it adds an error message to accompany the
866
+	 * status.
867
+	 *
868
+	 */
869
+	public function set_messenger_is_executing()
870
+	{
871
+		$this->set_STS_ID(EEM_Message::status_messenger_executing);
872
+		if (EEM_Message::debug()) {
873
+			$this->set_error_message(
874
+				esc_html__(
875
+					'A message with this status indicates that there was a problem that occurred while the message was being
876 876
                     processed by the messenger.  It is still possible that the message was sent successfully, but at some
877 877
                     point during the processing there was a failure.  This usually is indicative of a timeout issue with PHP 
878 878
                     or memory limits being reached.  If you see this repeatedly you may want to consider upgrading the memory 
879 879
                     available to PHP on your server.',
880
-                    'event_espresso'
881
-                )
882
-            );
883
-        }
884
-    }
880
+					'event_espresso'
881
+				)
882
+			);
883
+		}
884
+	}
885 885
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Soft_Delete_Base_Class.class.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -11,59 +11,59 @@
 block discarded – undo
11 11
  */
12 12
 abstract class EE_Soft_Delete_Base_Class extends EE_Base_Class
13 13
 {
14
-    /**
15
-     * Overrides parent _delete() so that we do soft deletes.
16
-     *
17
-     * @return bool
18
-     * @throws EE_Error
19
-     * @throws ReflectionException
20
-     */
21
-    protected function _delete()
22
-    {
23
-        return $this->delete_or_restore();
24
-    }
14
+	/**
15
+	 * Overrides parent _delete() so that we do soft deletes.
16
+	 *
17
+	 * @return bool
18
+	 * @throws EE_Error
19
+	 * @throws ReflectionException
20
+	 */
21
+	protected function _delete()
22
+	{
23
+		return $this->delete_or_restore();
24
+	}
25 25
 
26 26
 
27
-    /**
28
-     * Deletes or restores this object.
29
-     *
30
-     * @param bool $delete true=>delete, false=>restore
31
-     * @return bool
32
-     * @throws EE_Error
33
-     * @throws ReflectionException
34
-     */
35
-    public function delete_or_restore($delete = true)
36
-    {
37
-        /**
38
-         * Called just before trashing (soft delete) or restoring a trashed item.
39
-         *
40
-         * @param EE_Base_Class $model_object about to be trashed or restored
41
-         * @param bool          $delete       true the item is being trashed, false the item is being restored.
42
-         */
43
-        do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__before', $this, $delete);
44
-        $model = $this->get_model();
45
-        $result = $model->delete_or_restore_by_ID($delete, $this->ID());
46
-        /**
47
-         * Called just after trashing (soft delete) or restoring a trashed item.
48
-         *
49
-         * @param EE_Base_Class $model_object that was just trashed or restored.
50
-         * @param bool          $delete       true the item is being trashed, false the item is being restored.
51
-         * @param bool|int      $result
52
-         */
53
-        do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', $this, $delete, $result);
54
-        return $result;
55
-    }
27
+	/**
28
+	 * Deletes or restores this object.
29
+	 *
30
+	 * @param bool $delete true=>delete, false=>restore
31
+	 * @return bool
32
+	 * @throws EE_Error
33
+	 * @throws ReflectionException
34
+	 */
35
+	public function delete_or_restore($delete = true)
36
+	{
37
+		/**
38
+		 * Called just before trashing (soft delete) or restoring a trashed item.
39
+		 *
40
+		 * @param EE_Base_Class $model_object about to be trashed or restored
41
+		 * @param bool          $delete       true the item is being trashed, false the item is being restored.
42
+		 */
43
+		do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__before', $this, $delete);
44
+		$model = $this->get_model();
45
+		$result = $model->delete_or_restore_by_ID($delete, $this->ID());
46
+		/**
47
+		 * Called just after trashing (soft delete) or restoring a trashed item.
48
+		 *
49
+		 * @param EE_Base_Class $model_object that was just trashed or restored.
50
+		 * @param bool          $delete       true the item is being trashed, false the item is being restored.
51
+		 * @param bool|int      $result
52
+		 */
53
+		do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', $this, $delete, $result);
54
+		return $result;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Performs a restoration (un-deletes) this object
60
-     *
61
-     * @return bool
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public function restore()
66
-    {
67
-        return $this->delete_or_restore(false);
68
-    }
58
+	/**
59
+	 * Performs a restoration (un-deletes) this object
60
+	 *
61
+	 * @return bool
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public function restore()
66
+	{
67
+		return $this->delete_or_restore(false);
68
+	}
69 69
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Price_Type.model.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -11,142 +11,142 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Price_Type extends EEM_Soft_Delete_Base
13 13
 {
14
-    // private instance of the Price Type object
15
-    protected static $_instance = null;
16
-    // An array of the price type objects
17
-    public $type = null;
14
+	// private instance of the Price Type object
15
+	protected static $_instance = null;
16
+	// An array of the price type objects
17
+	public $type = null;
18 18
 
19
-    /**
20
-    *   Price Base types
21
-    *
22
-    *   @access private
23
-    *   @var int
24
-    */
25
-    public $base_types = null;
19
+	/**
20
+	 *   Price Base types
21
+	 *
22
+	 *   @access private
23
+	 *   @var int
24
+	 */
25
+	public $base_types = null;
26 26
 
27
-    /**
28
-     * return an array of Base types. Keys are INTs which are used in the database,
29
-     * values are text-representations of the base type.
30
-     * @return array
31
-     */
32
-    public function get_base_types()
33
-    {
34
-        return $this->base_types;
35
-    }
27
+	/**
28
+	 * return an array of Base types. Keys are INTs which are used in the database,
29
+	 * values are text-representations of the base type.
30
+	 * @return array
31
+	 */
32
+	public function get_base_types()
33
+	{
34
+		return $this->base_types;
35
+	}
36 36
 
37
-    /**
38
-     * Gets the name of the base
39
-     * @param type $base_type_int
40
-     * @return type
41
-     */
42
-    public function get_base_type_name($base_type_int)
43
-    {
44
-        return $this->base_types[ $base_type_int ];
45
-    }
37
+	/**
38
+	 * Gets the name of the base
39
+	 * @param type $base_type_int
40
+	 * @return type
41
+	 */
42
+	public function get_base_type_name($base_type_int)
43
+	{
44
+		return $this->base_types[ $base_type_int ];
45
+	}
46 46
 
47
-    /**
48
-     * constants for price base types. In the DB, we decided to store the price base type
49
-     * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
50
-     * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
51
-     * So, as an example, to query for all price types that are a tax, we'd do
52
-     * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
53
-     * instead of
54
-     * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
55
-     * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
56
-     * change, we can continue to use the constant, by simply change its value.
57
-     */
58
-    const base_type_base_price = 1;
59
-    const base_type_discount = 2;
60
-    const base_type_surcharge = 3;
61
-    const base_type_tax = 4;
62
-    /**
63
-     *      private constructor to prevent direct creation
64
-     *      @Constructor
65
-     *      @access protected
66
-     *      @return void
67
-     */
68
-    protected function __construct($timezone = null)
69
-    {
70
-        $this->base_types = array(
71
-            EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'),
72
-            EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'),
73
-            EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'),
74
-            EEM_Price_Type::base_type_tax => esc_html__('Tax', 'event_espresso') );
75
-        $this->singular_item = esc_html__('Price Type', 'event_espresso');
76
-        $this->plural_item = esc_html__('Price Types', 'event_espresso');
47
+	/**
48
+	 * constants for price base types. In the DB, we decided to store the price base type
49
+	 * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
50
+	 * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
51
+	 * So, as an example, to query for all price types that are a tax, we'd do
52
+	 * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
53
+	 * instead of
54
+	 * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
55
+	 * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
56
+	 * change, we can continue to use the constant, by simply change its value.
57
+	 */
58
+	const base_type_base_price = 1;
59
+	const base_type_discount = 2;
60
+	const base_type_surcharge = 3;
61
+	const base_type_tax = 4;
62
+	/**
63
+	 *      private constructor to prevent direct creation
64
+	 *      @Constructor
65
+	 *      @access protected
66
+	 *      @return void
67
+	 */
68
+	protected function __construct($timezone = null)
69
+	{
70
+		$this->base_types = array(
71
+			EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'),
72
+			EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'),
73
+			EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'),
74
+			EEM_Price_Type::base_type_tax => esc_html__('Tax', 'event_espresso') );
75
+		$this->singular_item = esc_html__('Price Type', 'event_espresso');
76
+		$this->plural_item = esc_html__('Price Types', 'event_espresso');
77 77
 
78
-        $this->_tables = array(
79
-            'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID')
80
-        );
81
-        $this->_fields = array(
82
-            'Price_Type' => array(
83
-                'PRT_ID' => new EE_Primary_Key_Int_Field('PRT_ID', esc_html__('Price Type ID', 'event_espresso')),
84
-                'PRT_name' => new EE_Plain_Text_Field('PRT_name', esc_html__('Price Type Name', 'event_espresso'), false, ''),
85
-                'PBT_ID' => new EE_Enum_Integer_Field('PBT_ID', esc_html__('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types),
86
-                'PRT_is_percent' => new EE_Boolean_Field('PRT_is_percent', esc_html__('Flag indicating price is a percentage', 'event_espresso'), false, false),
87
-                'PRT_order' => new EE_Integer_Field('PRT_order', esc_html__('Order in which price should be applied. ', 'event_espresso'), false, 0),
88
-                'PRT_deleted' => new EE_Trashed_Flag_Field('PRT_deleted', esc_html__('Flag indicating price type has been trashed', 'event_espresso'), false, false),
89
-                'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', esc_html__('Price Type Creator ID', 'event_espresso'), false),
90
-            )
91
-        );
92
-        $this->_model_relations = array(
93
-            'Price' => new EE_Has_Many_Relation(),
94
-            'WP_User' => new EE_Belongs_To_Relation(),
95
-        );
96
-        // this model is generally available for reading
97
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
98
-        // all price types are "default" in terms of capability names
99
-        $this->_caps_slug = 'default_price_types';
100
-        parent::__construct($timezone);
101
-    }
78
+		$this->_tables = array(
79
+			'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID')
80
+		);
81
+		$this->_fields = array(
82
+			'Price_Type' => array(
83
+				'PRT_ID' => new EE_Primary_Key_Int_Field('PRT_ID', esc_html__('Price Type ID', 'event_espresso')),
84
+				'PRT_name' => new EE_Plain_Text_Field('PRT_name', esc_html__('Price Type Name', 'event_espresso'), false, ''),
85
+				'PBT_ID' => new EE_Enum_Integer_Field('PBT_ID', esc_html__('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types),
86
+				'PRT_is_percent' => new EE_Boolean_Field('PRT_is_percent', esc_html__('Flag indicating price is a percentage', 'event_espresso'), false, false),
87
+				'PRT_order' => new EE_Integer_Field('PRT_order', esc_html__('Order in which price should be applied. ', 'event_espresso'), false, 0),
88
+				'PRT_deleted' => new EE_Trashed_Flag_Field('PRT_deleted', esc_html__('Flag indicating price type has been trashed', 'event_espresso'), false, false),
89
+				'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', esc_html__('Price Type Creator ID', 'event_espresso'), false),
90
+			)
91
+		);
92
+		$this->_model_relations = array(
93
+			'Price' => new EE_Has_Many_Relation(),
94
+			'WP_User' => new EE_Belongs_To_Relation(),
95
+		);
96
+		// this model is generally available for reading
97
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
98
+		// all price types are "default" in terms of capability names
99
+		$this->_caps_slug = 'default_price_types';
100
+		parent::__construct($timezone);
101
+	}
102 102
 
103 103
 
104 104
 
105 105
 
106
-    /**
107
-     *      instantiate a new price type object with blank/empty properties
108
-     *
109
-     *      @access     public
110
-     *      @return     mixed       array on success, FALSE on fail
111
-     */
112
-    public function get_new_price_type()
113
-    {
114
-        return EE_Price_Type::new_instance();
115
-    }
106
+	/**
107
+	 *      instantiate a new price type object with blank/empty properties
108
+	 *
109
+	 *      @access     public
110
+	 *      @return     mixed       array on success, FALSE on fail
111
+	 */
112
+	public function get_new_price_type()
113
+	{
114
+		return EE_Price_Type::new_instance();
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     *
120
-     * @param array   $query_params
121
-     * @param bool    $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
122
-     *                                that blocks it (ie, there' sno other data that depends on this data);
123
-     *                                if false, deletes regardless of other objects which may depend on it.
124
-     *                                Its generally advisable to always leave this as TRUE,
125
-     *                                otherwise you could easily corrupt your DB
126
-     * @return bool
127
-     * @throws EE_Error
128
-     * @throws ReflectionException
129
-     */
130
-    public function delete_permanently($query_params = array(), $allow_blocking = true)
131
-    {
132
-        $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
133
-        $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
118
+	/**
119
+	 *
120
+	 * @param array   $query_params
121
+	 * @param bool    $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
122
+	 *                                that blocks it (ie, there' sno other data that depends on this data);
123
+	 *                                if false, deletes regardless of other objects which may depend on it.
124
+	 *                                Its generally advisable to always leave this as TRUE,
125
+	 *                                otherwise you could easily corrupt your DB
126
+	 * @return bool
127
+	 * @throws EE_Error
128
+	 * @throws ReflectionException
129
+	 */
130
+	public function delete_permanently($query_params = array(), $allow_blocking = true)
131
+	{
132
+		$would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
133
+		$would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
134 134
 
135
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
135
+		$ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
136 136
 
137
-        // check if any prices use this price type
138
-        $prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids)));
139
-        if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
140
-            $prices_names_and_ids = array();
141
-            foreach ($prices as $price) {
142
-                /* @var $price EE_Price */
143
-                $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
144
-            }
145
-            $msg = sprintf(esc_html__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
146
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
147
-            return false;
148
-        }
137
+		// check if any prices use this price type
138
+		$prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids)));
139
+		if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
140
+			$prices_names_and_ids = array();
141
+			foreach ($prices as $price) {
142
+				/* @var $price EE_Price */
143
+				$prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
144
+			}
145
+			$msg = sprintf(esc_html__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
146
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
147
+			return false;
148
+		}
149 149
 
150
-        return parent::delete_permanently($query_params);
151
-    }
150
+		return parent::delete_permanently($query_params);
151
+	}
152 152
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Term_Taxonomy.model.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -10,133 +10,133 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Term_Taxonomy extends EEM_Base
12 12
 {
13
-    /**
14
-     * @var EEM_Term_Taxonomy
15
-     */
16
-    protected static $_instance = null;
13
+	/**
14
+	 * @var EEM_Term_Taxonomy
15
+	 */
16
+	protected static $_instance = null;
17 17
 
18 18
 
19
-    /**
20
-     * @param $timezone
21
-     * @throws EE_Error
22
-     */
23
-    protected function __construct($timezone = null)
24
-    {
25
-        $this->singular_item = esc_html__('Term Taxonomy', 'event_espresso');
26
-        $this->plural_item = esc_html__('Term Taxonomy', 'event_espresso');
27
-        $this->_tables = array(
28
-            'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'),
29
-        );
30
-        $this->_fields = array(
31
-            'Term_Taxonomy' => array(
32
-                'term_taxonomy_id' => new EE_Primary_Key_Int_Field(
33
-                    'term_taxonomy_id',
34
-                    esc_html__('Term-Taxonomy ID', 'event_espresso')
35
-                ),
36
-                'term_id'          => new EE_Foreign_Key_Int_Field(
37
-                    'term_id',
38
-                    esc_html__("Term Id", "event_espresso"),
39
-                    false,
40
-                    0,
41
-                    'Term'
42
-                ),
43
-                'taxonomy'         => new EE_Plain_Text_Field(
44
-                    'taxonomy',
45
-                    esc_html__('Taxonomy Name', 'event_espresso'),
46
-                    false,
47
-                    'category'
48
-                ),
49
-                'description'      => new EE_Post_Content_Field(
50
-                    'description',
51
-                    esc_html__("Description of Term", "event_espresso"),
52
-                    false,
53
-                    ''
54
-                ),
55
-                'parent'           => new EE_Integer_Field('parent', esc_html__("Parent Term ID", "event_espresso"), false, 0),
56
-                'term_count'       => new EE_Integer_Field(
57
-                    'count',
58
-                    esc_html__("Count of Objects attached", 'event_espresso'),
59
-                    false,
60
-                    0
61
-                ),
62
-            ),
63
-        );
64
-        $this->_model_relations = array(
65
-            'Term_Relationship' => new EE_Has_Many_Relation(),
66
-            'Term'              => new EE_Belongs_To_Relation(),
67
-        );
68
-        $cpt_models = array_keys(EE_Registry::instance()->cpt_models());
69
-        foreach ($cpt_models as $model_name) {
70
-            $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship');
71
-        }
72
-        $this->_wp_core_model = true;
73
-        $this->_indexes = array(
74
-            'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')),
75
-        );
76
-        $path_to_tax_model = '';
77
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
78
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected(
79
-            $path_to_tax_model
80
-        );
81
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false;
82
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false;
83
-        // add cap restrictions for editing relating to the "ee_edit_*"
84
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
85
-            array(
86
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
87
-            )
88
-        );
89
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
90
-            array(
91
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
92
-            )
93
-        );
94
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
95
-            array(
96
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
97
-            )
98
-        );
99
-        // add cap restrictions for deleting relating to the "ee_deleting_*"
100
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
101
-            array(
102
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
103
-            )
104
-        );
105
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
106
-            array(
107
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
108
-            )
109
-        );
110
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
111
-            array(
112
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
113
-            )
114
-        );
115
-        parent::__construct($timezone);
116
-        add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3);
117
-    }
19
+	/**
20
+	 * @param $timezone
21
+	 * @throws EE_Error
22
+	 */
23
+	protected function __construct($timezone = null)
24
+	{
25
+		$this->singular_item = esc_html__('Term Taxonomy', 'event_espresso');
26
+		$this->plural_item = esc_html__('Term Taxonomy', 'event_espresso');
27
+		$this->_tables = array(
28
+			'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'),
29
+		);
30
+		$this->_fields = array(
31
+			'Term_Taxonomy' => array(
32
+				'term_taxonomy_id' => new EE_Primary_Key_Int_Field(
33
+					'term_taxonomy_id',
34
+					esc_html__('Term-Taxonomy ID', 'event_espresso')
35
+				),
36
+				'term_id'          => new EE_Foreign_Key_Int_Field(
37
+					'term_id',
38
+					esc_html__("Term Id", "event_espresso"),
39
+					false,
40
+					0,
41
+					'Term'
42
+				),
43
+				'taxonomy'         => new EE_Plain_Text_Field(
44
+					'taxonomy',
45
+					esc_html__('Taxonomy Name', 'event_espresso'),
46
+					false,
47
+					'category'
48
+				),
49
+				'description'      => new EE_Post_Content_Field(
50
+					'description',
51
+					esc_html__("Description of Term", "event_espresso"),
52
+					false,
53
+					''
54
+				),
55
+				'parent'           => new EE_Integer_Field('parent', esc_html__("Parent Term ID", "event_espresso"), false, 0),
56
+				'term_count'       => new EE_Integer_Field(
57
+					'count',
58
+					esc_html__("Count of Objects attached", 'event_espresso'),
59
+					false,
60
+					0
61
+				),
62
+			),
63
+		);
64
+		$this->_model_relations = array(
65
+			'Term_Relationship' => new EE_Has_Many_Relation(),
66
+			'Term'              => new EE_Belongs_To_Relation(),
67
+		);
68
+		$cpt_models = array_keys(EE_Registry::instance()->cpt_models());
69
+		foreach ($cpt_models as $model_name) {
70
+			$this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship');
71
+		}
72
+		$this->_wp_core_model = true;
73
+		$this->_indexes = array(
74
+			'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')),
75
+		);
76
+		$path_to_tax_model = '';
77
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
78
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected(
79
+			$path_to_tax_model
80
+		);
81
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false;
82
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false;
83
+		// add cap restrictions for editing relating to the "ee_edit_*"
84
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
85
+			array(
86
+				$path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
87
+			)
88
+		);
89
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
90
+			array(
91
+				$path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
92
+			)
93
+		);
94
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
95
+			array(
96
+				$path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
97
+			)
98
+		);
99
+		// add cap restrictions for deleting relating to the "ee_deleting_*"
100
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
101
+			array(
102
+				$path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
103
+			)
104
+		);
105
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
106
+			array(
107
+				$path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
108
+			)
109
+		);
110
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
111
+			array(
112
+				$path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
113
+			)
114
+		);
115
+		parent::__construct($timezone);
116
+		add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3);
117
+	}
118 118
 
119 119
 
120
-    /**
121
-     * Makes sure that during REST API queries, we only return term-taxonomies
122
-     * for term taxonomies which should be shown in the rest api
123
-     *
124
-     * @param array    $model_query_params
125
-     * @param array    $querystring_query_params
126
-     * @param EEM_Base $model
127
-     * @return array
128
-     * @throws EE_Error
129
-     */
130
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
131
-    {
132
-        if ($model === EEM_Term_Taxonomy::instance()) {
133
-            $taxonomies = get_taxonomies(array('show_in_rest' => true));
134
-            if (! empty($taxonomies)) {
135
-                $model_query_params[0]['taxonomy'] = array('IN', $taxonomies);
136
-            }
137
-        }
138
-        return $model_query_params;
139
-    }
120
+	/**
121
+	 * Makes sure that during REST API queries, we only return term-taxonomies
122
+	 * for term taxonomies which should be shown in the rest api
123
+	 *
124
+	 * @param array    $model_query_params
125
+	 * @param array    $querystring_query_params
126
+	 * @param EEM_Base $model
127
+	 * @return array
128
+	 * @throws EE_Error
129
+	 */
130
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
131
+	{
132
+		if ($model === EEM_Term_Taxonomy::instance()) {
133
+			$taxonomies = get_taxonomies(array('show_in_rest' => true));
134
+			if (! empty($taxonomies)) {
135
+				$model_query_params[0]['taxonomy'] = array('IN', $taxonomies);
136
+			}
137
+		}
138
+		return $model_query_params;
139
+	}
140 140
 }
141 141
 // End of file EEM_Term_Taxonomy.model.php
142 142
 // Location: /includes/models/EEM_Term_Taxonomy.model.php
Please login to merge, or discard this patch.
core/db_models/EEM_Soft_Delete_Base.model.php 2 patches
Indentation   +367 added lines, -367 removed lines patch added patch discarded remove patch
@@ -28,371 +28,371 @@
 block discarded – undo
28 28
  */
29 29
 abstract class EEM_Soft_Delete_Base extends EEM_Base
30 30
 {
31
-    /**
32
-     * @param null $timezone
33
-     * @throws EE_Error
34
-     */
35
-    protected function __construct($timezone = null)
36
-    {
37
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
38
-            $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
39
-        }
40
-        parent::__construct($timezone);
41
-    }
42
-
43
-
44
-    /**
45
-     * Searches for field on this model of type 'deleted_flag'. if it is found, returns it's name.
46
-     *
47
-     * @return string
48
-     * @throws EE_Error
49
-     */
50
-    public function deleted_field_name()
51
-    {
52
-        $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
53
-        if ($field) {
54
-            return $field->get_name();
55
-        } else {
56
-            throw new EE_Error(
57
-                sprintf(
58
-                    esc_html__(
59
-                        'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
60
-                        'event_espresso'
61
-                    ),
62
-                    get_class($this),
63
-                    get_class($this)
64
-                )
65
-            );
66
-        }
67
-    }
68
-
69
-
70
-    /**
71
-     * Gets one item that's been deleted, according to $query_params
72
-     *
73
-     * @param array $query_params
74
-     * @return EE_Soft_Delete_Base_Class
75
-     * @throws EE_Error
76
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
77
-     */
78
-    public function get_one_deleted($query_params = [])
79
-    {
80
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
81
-        return $this->get_one($query_params);
82
-    }
83
-
84
-
85
-    /**
86
-     * Gets one item from the DB, regardless of whether it's been soft-deleted or not
87
-     *
88
-     * @param array $query_params like EEM_base::get_all's $query_params
89
-     * @return EE_Soft_Delete_Base_Class
90
-     * @throws EE_Error
91
-     */
92
-    public function get_one_deleted_or_undeleted($query_params = [])
93
-    {
94
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
95
-        return $this->get_one($query_params);
96
-    }
97
-
98
-
99
-    /**
100
-     * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
101
-     *
102
-     * @param int|string $id
103
-     * @return EE_Soft_Delete_Base_Class
104
-     * @throws EE_Error
105
-     */
106
-    public function get_one_by_ID_but_ignore_deleted($id)
107
-    {
108
-        return $this->get_one(
109
-            $this->alter_query_params_to_restrict_by_ID(
110
-                $id,
111
-                ['default_where_conditions' => 'default']
112
-            )
113
-        );
114
-    }
115
-
116
-
117
-    /**
118
-     * Counts all the deleted/trashed items
119
-     *
120
-     * @param array  $query_params
121
-     * @param string $field_to_count
122
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger
123
-     *                             that by the setting $distinct to TRUE;
124
-     * @return int
125
-     * @throws EE_Error
126
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
127
-     */
128
-    public function count_deleted($query_params = null, $field_to_count = null, $distinct = false)
129
-    {
130
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
131
-        return $this->count($query_params, $field_to_count, $distinct);
132
-    }
133
-
134
-
135
-    /**
136
-     * Alters the query params so that only trashed/soft-deleted items are considered
137
-     *
138
-     * @param array $query_params
139
-     * @return array
140
-     * @throws EE_Error
141
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
142
-     */
143
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
144
-    {
145
-        $deletedFlagFieldName                     = $this->deleted_field_name();
146
-        $query_params[0][ $deletedFlagFieldName ] = true;
147
-        return $query_params;
148
-    }
149
-
150
-
151
-    /**
152
-     * Alters the query params so that only trashed/soft-deleted items are considered
153
-     *
154
-     * @param array $query_params
155
-     * @return array
156
-     * @throws EE_Error
157
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
158
-     */
159
-    public function alter_query_params_so_only_trashed_items_included($query_params)
160
-    {
161
-        return $this->_alter_query_params_so_only_trashed_items_included($query_params);
162
-    }
163
-
164
-
165
-    /**
166
-     * Alters the query params so each item's deleted status is ignored.
167
-     *
168
-     * @param array $query_params
169
-     * @return array
170
-     */
171
-    public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = [])
172
-    {
173
-        return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
174
-    }
175
-
176
-
177
-    /**
178
-     * Alters the query params so each item's deleted status is ignored.
179
-     *
180
-     * @param array $query_params
181
-     * @return array
182
-     */
183
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
184
-    {
185
-        if (! isset($query_params['default_where_conditions'])) {
186
-            $query_params['default_where_conditions'] = 'minimum';
187
-        }
188
-        return $query_params;
189
-    }
190
-
191
-
192
-    /**
193
-     * Counts all deleted and undeleted items
194
-     *
195
-     * @param array  $query_params
196
-     * @param string $field_to_count
197
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger
198
-     *                             that by the setting $distinct to TRUE;
199
-     * @return int
200
-     * @throws EE_Error
201
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
202
-     */
203
-    public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false)
204
-    {
205
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
206
-        return $this->count($query_params, $field_to_count, $distinct);
207
-    }
208
-
209
-
210
-    /**
211
-     * Sum all the deleted items.
212
-     *
213
-     * @param array  $query_params
214
-     * @param string $field_to_sum
215
-     * @return float
216
-     * @throws EE_Error
217
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
218
-     */
219
-    public function sum_deleted($query_params = null, $field_to_sum = null)
220
-    {
221
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
222
-        return $this->sum($query_params, $field_to_sum);
223
-    }
224
-
225
-
226
-    /**
227
-     * Sums all the deleted and undeleted items.
228
-     *
229
-     * @param array  $query_params
230
-     * @param string $field_to_sum
231
-     * @return float
232
-     * @throws EE_Error
233
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
234
-     */
235
-    public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null)
236
-    {
237
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
238
-        return $this->sum($query_params, $field_to_sum);
239
-    }
240
-
241
-
242
-    /**
243
-     * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
244
-     * whether they've been soft-deleted or not
245
-     *
246
-     * @param array $query_params
247
-     * @return EE_Soft_Delete_Base_Class[]
248
-     * @throws EE_Error
249
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
250
-     */
251
-    public function get_all_deleted_and_undeleted($query_params = [])
252
-    {
253
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
254
-        return $this->get_all($query_params);
255
-    }
256
-
257
-
258
-    /**
259
-     * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
260
-     *
261
-     * @param array $query_params
262
-     * @return EE_Soft_Delete_Base_Class[]
263
-     * @throws EE_Error
264
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
265
-     */
266
-    public function get_all_deleted($query_params = [])
267
-    {
268
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
269
-        return $this->get_all($query_params);
270
-    }
271
-
272
-
273
-    /**
274
-     * Permanently deletes the selected rows. When selecting rows for deletion, ignores
275
-     * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
276
-     * before you can permanently delete them).
277
-     * Because this will cause a real deletion, related models may block this deletion (ie, add an error
278
-     * and abort the delete)
279
-     *
280
-     * @param array   $query_params
281
-     * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
282
-     *                                that blocks it (ie, there' sno other data that depends on this data);
283
-     *                                if false, deletes regardless of other objects which may depend on it.
284
-     *                                Its generally advisable to always leave this as TRUE,
285
-     *                                otherwise you could easily corrupt your DB
286
-     * @return int                    number of rows deleted
287
-     * @throws EE_Error
288
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
289
-     */
290
-    public function delete_permanently($query_params, $allow_blocking = true)
291
-    {
292
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
293
-        return parent::delete_permanently($query_params, $allow_blocking);
294
-    }
295
-
296
-
297
-    /**
298
-     * Restores a particular item by its ID (primary key). Ignores the fact whether the item
299
-     * has been soft-deleted or not.
300
-     *
301
-     * @param mixed $ID int if primary key is an int, string otherwise
302
-     * @return boolean success
303
-     * @throws EE_Error
304
-     */
305
-    public function restore_by_ID($ID = false)
306
-    {
307
-        return $this->delete_or_restore_by_ID(false, $ID);
308
-    }
309
-
310
-
311
-    /**
312
-     * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
313
-     * this function will ignore whether the items have been soft-deleted or not.
314
-     *
315
-     * @param boolean $delete true for delete, false for restore
316
-     * @param mixed   $ID     int if primary key is an int, string otherwise
317
-     * @return bool
318
-     * @throws EE_Error
319
-     */
320
-    public function delete_or_restore_by_ID($delete = true, $ID = false)
321
-    {
322
-        // returns false if entity doesn't have an ID or if delete/restore action failed
323
-        return $ID && $this->delete_or_restore($delete, $this->alter_query_params_to_restrict_by_ID($ID));
324
-    }
325
-
326
-
327
-    /**
328
-     * Overrides parent's 'delete' method to instead do a soft delete on all rows that
329
-     * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been
330
-     * soft-deleted or not. Note: because this item will be soft-deleted only, doesn't block because of model
331
-     * dependencies
332
-     *
333
-     * @param array $query_params
334
-     * @param bool  $block_deletes
335
-     * @return bool
336
-     * @throws EE_Error
337
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
338
-     */
339
-    public function delete($query_params = [], $block_deletes = false)
340
-    {
341
-        // no matter what, we WON'T block soft deletes.
342
-        return $this->delete_or_restore(true, $query_params);
343
-    }
344
-
345
-
346
-    /**
347
-     * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default,
348
-     * trashed/soft-deleted items are ignored in queries. However, this particular function ignores whether the items
349
-     * have been soft-deleted or not.
350
-     *
351
-     * @param array $query_params
352
-     * @return bool
353
-     * @throws EE_Error
354
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
355
-     */
356
-    public function restore($query_params = [])
357
-    {
358
-        return $this->delete_or_restore(false, $query_params);
359
-    }
360
-
361
-
362
-    /**
363
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
364
-     *
365
-     * @param boolean $delete true to indicate deletion, false to indicate restoration
366
-     * @param array   $query_params
367
-     * @return boolean
368
-     * @throws EE_Error
369
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
370
-     */
371
-    public function delete_or_restore($delete = true, $query_params = [])
372
-    {
373
-        $deletedFlagFieldName = $this->deleted_field_name();
374
-        $query_params         = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
375
-        return (bool) $this->update([$deletedFlagFieldName => $delete], $query_params);
376
-    }
377
-
378
-
379
-    /**
380
-     * Updates all the items of this model which match the $query params, regardless of whether
381
-     * they've been soft-deleted or not
382
-     *
383
-     * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
384
-     * @param array   $query_params            like EEM_base::get_all's $query_params
385
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
386
-     *                                         in this model's entity map according to $fields_n_values that match
387
-     *                                         $query_params. This obviously has some overhead, so you can disable it
388
-     *                                         by setting this to FALSE, but be aware that model objects being used
389
-     *                                         could get out-of-sync with the database
390
-     * @return int number of items updated
391
-     * @throws EE_Error
392
-     */
393
-    public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
394
-    {
395
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
396
-        return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
397
-    }
31
+	/**
32
+	 * @param null $timezone
33
+	 * @throws EE_Error
34
+	 */
35
+	protected function __construct($timezone = null)
36
+	{
37
+		if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
38
+			$this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
39
+		}
40
+		parent::__construct($timezone);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Searches for field on this model of type 'deleted_flag'. if it is found, returns it's name.
46
+	 *
47
+	 * @return string
48
+	 * @throws EE_Error
49
+	 */
50
+	public function deleted_field_name()
51
+	{
52
+		$field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
53
+		if ($field) {
54
+			return $field->get_name();
55
+		} else {
56
+			throw new EE_Error(
57
+				sprintf(
58
+					esc_html__(
59
+						'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
60
+						'event_espresso'
61
+					),
62
+					get_class($this),
63
+					get_class($this)
64
+				)
65
+			);
66
+		}
67
+	}
68
+
69
+
70
+	/**
71
+	 * Gets one item that's been deleted, according to $query_params
72
+	 *
73
+	 * @param array $query_params
74
+	 * @return EE_Soft_Delete_Base_Class
75
+	 * @throws EE_Error
76
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
77
+	 */
78
+	public function get_one_deleted($query_params = [])
79
+	{
80
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
81
+		return $this->get_one($query_params);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Gets one item from the DB, regardless of whether it's been soft-deleted or not
87
+	 *
88
+	 * @param array $query_params like EEM_base::get_all's $query_params
89
+	 * @return EE_Soft_Delete_Base_Class
90
+	 * @throws EE_Error
91
+	 */
92
+	public function get_one_deleted_or_undeleted($query_params = [])
93
+	{
94
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
95
+		return $this->get_one($query_params);
96
+	}
97
+
98
+
99
+	/**
100
+	 * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
101
+	 *
102
+	 * @param int|string $id
103
+	 * @return EE_Soft_Delete_Base_Class
104
+	 * @throws EE_Error
105
+	 */
106
+	public function get_one_by_ID_but_ignore_deleted($id)
107
+	{
108
+		return $this->get_one(
109
+			$this->alter_query_params_to_restrict_by_ID(
110
+				$id,
111
+				['default_where_conditions' => 'default']
112
+			)
113
+		);
114
+	}
115
+
116
+
117
+	/**
118
+	 * Counts all the deleted/trashed items
119
+	 *
120
+	 * @param array  $query_params
121
+	 * @param string $field_to_count
122
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger
123
+	 *                             that by the setting $distinct to TRUE;
124
+	 * @return int
125
+	 * @throws EE_Error
126
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
127
+	 */
128
+	public function count_deleted($query_params = null, $field_to_count = null, $distinct = false)
129
+	{
130
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
131
+		return $this->count($query_params, $field_to_count, $distinct);
132
+	}
133
+
134
+
135
+	/**
136
+	 * Alters the query params so that only trashed/soft-deleted items are considered
137
+	 *
138
+	 * @param array $query_params
139
+	 * @return array
140
+	 * @throws EE_Error
141
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
142
+	 */
143
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
144
+	{
145
+		$deletedFlagFieldName                     = $this->deleted_field_name();
146
+		$query_params[0][ $deletedFlagFieldName ] = true;
147
+		return $query_params;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Alters the query params so that only trashed/soft-deleted items are considered
153
+	 *
154
+	 * @param array $query_params
155
+	 * @return array
156
+	 * @throws EE_Error
157
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
158
+	 */
159
+	public function alter_query_params_so_only_trashed_items_included($query_params)
160
+	{
161
+		return $this->_alter_query_params_so_only_trashed_items_included($query_params);
162
+	}
163
+
164
+
165
+	/**
166
+	 * Alters the query params so each item's deleted status is ignored.
167
+	 *
168
+	 * @param array $query_params
169
+	 * @return array
170
+	 */
171
+	public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = [])
172
+	{
173
+		return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
174
+	}
175
+
176
+
177
+	/**
178
+	 * Alters the query params so each item's deleted status is ignored.
179
+	 *
180
+	 * @param array $query_params
181
+	 * @return array
182
+	 */
183
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
184
+	{
185
+		if (! isset($query_params['default_where_conditions'])) {
186
+			$query_params['default_where_conditions'] = 'minimum';
187
+		}
188
+		return $query_params;
189
+	}
190
+
191
+
192
+	/**
193
+	 * Counts all deleted and undeleted items
194
+	 *
195
+	 * @param array  $query_params
196
+	 * @param string $field_to_count
197
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger
198
+	 *                             that by the setting $distinct to TRUE;
199
+	 * @return int
200
+	 * @throws EE_Error
201
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
202
+	 */
203
+	public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false)
204
+	{
205
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
206
+		return $this->count($query_params, $field_to_count, $distinct);
207
+	}
208
+
209
+
210
+	/**
211
+	 * Sum all the deleted items.
212
+	 *
213
+	 * @param array  $query_params
214
+	 * @param string $field_to_sum
215
+	 * @return float
216
+	 * @throws EE_Error
217
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
218
+	 */
219
+	public function sum_deleted($query_params = null, $field_to_sum = null)
220
+	{
221
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
222
+		return $this->sum($query_params, $field_to_sum);
223
+	}
224
+
225
+
226
+	/**
227
+	 * Sums all the deleted and undeleted items.
228
+	 *
229
+	 * @param array  $query_params
230
+	 * @param string $field_to_sum
231
+	 * @return float
232
+	 * @throws EE_Error
233
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
234
+	 */
235
+	public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null)
236
+	{
237
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
238
+		return $this->sum($query_params, $field_to_sum);
239
+	}
240
+
241
+
242
+	/**
243
+	 * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
244
+	 * whether they've been soft-deleted or not
245
+	 *
246
+	 * @param array $query_params
247
+	 * @return EE_Soft_Delete_Base_Class[]
248
+	 * @throws EE_Error
249
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
250
+	 */
251
+	public function get_all_deleted_and_undeleted($query_params = [])
252
+	{
253
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
254
+		return $this->get_all($query_params);
255
+	}
256
+
257
+
258
+	/**
259
+	 * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
260
+	 *
261
+	 * @param array $query_params
262
+	 * @return EE_Soft_Delete_Base_Class[]
263
+	 * @throws EE_Error
264
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
265
+	 */
266
+	public function get_all_deleted($query_params = [])
267
+	{
268
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
269
+		return $this->get_all($query_params);
270
+	}
271
+
272
+
273
+	/**
274
+	 * Permanently deletes the selected rows. When selecting rows for deletion, ignores
275
+	 * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
276
+	 * before you can permanently delete them).
277
+	 * Because this will cause a real deletion, related models may block this deletion (ie, add an error
278
+	 * and abort the delete)
279
+	 *
280
+	 * @param array   $query_params
281
+	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
282
+	 *                                that blocks it (ie, there' sno other data that depends on this data);
283
+	 *                                if false, deletes regardless of other objects which may depend on it.
284
+	 *                                Its generally advisable to always leave this as TRUE,
285
+	 *                                otherwise you could easily corrupt your DB
286
+	 * @return int                    number of rows deleted
287
+	 * @throws EE_Error
288
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
289
+	 */
290
+	public function delete_permanently($query_params, $allow_blocking = true)
291
+	{
292
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
293
+		return parent::delete_permanently($query_params, $allow_blocking);
294
+	}
295
+
296
+
297
+	/**
298
+	 * Restores a particular item by its ID (primary key). Ignores the fact whether the item
299
+	 * has been soft-deleted or not.
300
+	 *
301
+	 * @param mixed $ID int if primary key is an int, string otherwise
302
+	 * @return boolean success
303
+	 * @throws EE_Error
304
+	 */
305
+	public function restore_by_ID($ID = false)
306
+	{
307
+		return $this->delete_or_restore_by_ID(false, $ID);
308
+	}
309
+
310
+
311
+	/**
312
+	 * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
313
+	 * this function will ignore whether the items have been soft-deleted or not.
314
+	 *
315
+	 * @param boolean $delete true for delete, false for restore
316
+	 * @param mixed   $ID     int if primary key is an int, string otherwise
317
+	 * @return bool
318
+	 * @throws EE_Error
319
+	 */
320
+	public function delete_or_restore_by_ID($delete = true, $ID = false)
321
+	{
322
+		// returns false if entity doesn't have an ID or if delete/restore action failed
323
+		return $ID && $this->delete_or_restore($delete, $this->alter_query_params_to_restrict_by_ID($ID));
324
+	}
325
+
326
+
327
+	/**
328
+	 * Overrides parent's 'delete' method to instead do a soft delete on all rows that
329
+	 * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been
330
+	 * soft-deleted or not. Note: because this item will be soft-deleted only, doesn't block because of model
331
+	 * dependencies
332
+	 *
333
+	 * @param array $query_params
334
+	 * @param bool  $block_deletes
335
+	 * @return bool
336
+	 * @throws EE_Error
337
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
338
+	 */
339
+	public function delete($query_params = [], $block_deletes = false)
340
+	{
341
+		// no matter what, we WON'T block soft deletes.
342
+		return $this->delete_or_restore(true, $query_params);
343
+	}
344
+
345
+
346
+	/**
347
+	 * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default,
348
+	 * trashed/soft-deleted items are ignored in queries. However, this particular function ignores whether the items
349
+	 * have been soft-deleted or not.
350
+	 *
351
+	 * @param array $query_params
352
+	 * @return bool
353
+	 * @throws EE_Error
354
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
355
+	 */
356
+	public function restore($query_params = [])
357
+	{
358
+		return $this->delete_or_restore(false, $query_params);
359
+	}
360
+
361
+
362
+	/**
363
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
364
+	 *
365
+	 * @param boolean $delete true to indicate deletion, false to indicate restoration
366
+	 * @param array   $query_params
367
+	 * @return boolean
368
+	 * @throws EE_Error
369
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
370
+	 */
371
+	public function delete_or_restore($delete = true, $query_params = [])
372
+	{
373
+		$deletedFlagFieldName = $this->deleted_field_name();
374
+		$query_params         = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
375
+		return (bool) $this->update([$deletedFlagFieldName => $delete], $query_params);
376
+	}
377
+
378
+
379
+	/**
380
+	 * Updates all the items of this model which match the $query params, regardless of whether
381
+	 * they've been soft-deleted or not
382
+	 *
383
+	 * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
384
+	 * @param array   $query_params            like EEM_base::get_all's $query_params
385
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
386
+	 *                                         in this model's entity map according to $fields_n_values that match
387
+	 *                                         $query_params. This obviously has some overhead, so you can disable it
388
+	 *                                         by setting this to FALSE, but be aware that model objects being used
389
+	 *                                         could get out-of-sync with the database
390
+	 * @return int number of items updated
391
+	 * @throws EE_Error
392
+	 */
393
+	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
394
+	{
395
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
396
+		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
397
+	}
398 398
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      */
35 35
     protected function __construct($timezone = null)
36 36
     {
37
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
37
+        if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
38 38
             $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
39 39
         }
40 40
         parent::__construct($timezone);
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     protected function _alter_query_params_so_only_trashed_items_included($query_params)
144 144
     {
145 145
         $deletedFlagFieldName                     = $this->deleted_field_name();
146
-        $query_params[0][ $deletedFlagFieldName ] = true;
146
+        $query_params[0][$deletedFlagFieldName] = true;
147 147
         return $query_params;
148 148
     }
149 149
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
184 184
     {
185
-        if (! isset($query_params['default_where_conditions'])) {
185
+        if ( ! isset($query_params['default_where_conditions'])) {
186 186
             $query_params['default_where_conditions'] = 'minimum';
187 187
         }
188 188
         return $query_params;
Please login to merge, or discard this patch.
core/services/orm/TrashLogger.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -18,127 +18,127 @@
 block discarded – undo
18 18
  */
19 19
 class TrashLogger
20 20
 {
21
-    /**
22
-     * extra meta key for tracking when entities are trashed and by who
23
-     *
24
-     * @type string
25
-     */
26
-    const EXTRA_META_KEY_ENTITY_TRASHED = 'entity-trashed';
27
-
28
-    /**
29
-     * extra meta key for tracking when entities are restored and by who
30
-     *
31
-     * @type string
32
-     */
33
-    const EXTRA_META_KEY_ENTITY_RESTORED = 'entity-restored';
34
-
35
-    /**
36
-     * extra meta key for tracking when entities are deleted and by who
37
-     *
38
-     * @type string
39
-     */
40
-    const EXTRA_META_KEY_ENTITY_DELETED = 'entity-deleted';
41
-
42
-
43
-    public function __construct()
44
-    {
45
-        add_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', [$this, 'logSoftDelete'], 10, 3);
46
-        add_action('AHEE__EE_Base_Class__delete_permanently__end', [$this, 'logHardDelete'], 10, 2);
47
-        add_action(
48
-            'AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted',
49
-            [$this, 'logBatchDelete'],
50
-            10,
51
-            2
52
-        );
53
-    }
54
-
55
-
56
-    /**
57
-     * @param EE_Soft_Delete_Base_Class $entity
58
-     * @param bool                      $delete
59
-     * @param bool                      $result
60
-     * @throws EE_Error
61
-     * @throws ReflectionException
62
-     */
63
-    public function logSoftDelete(EE_Soft_Delete_Base_Class $entity, $delete, $result)
64
-    {
65
-        // which base meta key to use... trashed or restored?
66
-        $action = $delete
67
-            ? TrashLogger::EXTRA_META_KEY_ENTITY_TRASHED
68
-            : TrashLogger::EXTRA_META_KEY_ENTITY_RESTORED;
69
-
70
-        $entity_class = $this->getEntityClass($entity);
71
-        $this->logDelete($entity->ID(), $entity_class, $action, $result);
72
-    }
73
-
74
-
75
-    /**
76
-     * @param EE_Base_Class $entity
77
-     * @param bool          $result
78
-     * @throws EE_Error
79
-     * @throws ReflectionException
80
-     */
81
-    public function logHardDelete(EE_Base_Class $entity, $result)
82
-    {
83
-        $entity_class = $this->getEntityClass($entity);
84
-        $this->logDelete($entity->ID(), $entity_class, TrashLogger::EXTRA_META_KEY_ENTITY_DELETED, $result);
85
-    }
86
-
87
-
88
-    /**
89
-     * @param int|string $entity_ID
90
-     * @param string     $entity_type
91
-     * @throws EE_Error
92
-     * @throws ReflectionException
93
-     */
94
-    public function logBatchDelete($entity_ID, $entity_type)
95
-    {
96
-        $entity_type = str_replace(['EE_', 'EEM_'], '', $entity_type);
97
-        $this->logDelete($entity_ID, $entity_type, TrashLogger::EXTRA_META_KEY_ENTITY_DELETED, true);
98
-    }
99
-
100
-
101
-    /**
102
-     * converts entity class like 'EE_Registration' to 'registration'
103
-     *
104
-     * @param EE_Base_Class $entity
105
-     * @return string
106
-     */
107
-    private function getEntityClass(EE_Base_Class $entity)
108
-    {
109
-        return str_replace('EE_', '', get_class($entity));
110
-    }
111
-
112
-
113
-    /**
114
-     * @param string $entity_ID
115
-     * @param string $entity_type
116
-     * @param string $action
117
-     * @param bool   $result
118
-     * @throws EE_Error
119
-     * @throws ReflectionException
120
-     */
121
-    private function logDelete($entity_ID, $entity_type, $action, $result)
122
-    {
123
-        // if trash/restore/delete was not successful, then get out
124
-        if (! $result) {
125
-            return;
126
-        }
127
-
128
-        // convert 'entity-deleted' to just 'deleted'
129
-        $action       = str_replace('entity-', '', $action);
130
-        $current_user = wp_get_current_user();
131
-        $user_name    = $current_user->ID ? $current_user->display_name : 'unknown user';
132
-        $timestamp    = date("D M j, Y @ g:i:s a", current_time('timestamp'));
133
-
134
-        $log = EE_Change_Log::new_instance(
135
-            [
136
-                'OBJ_ID'      => $entity_ID,
137
-                'OBJ_type'    => $entity_type,
138
-                'LOG_type'    => EEM_Change_Log::type_delete,
139
-                'LOG_message' => "$action by $user_name on $timestamp",
140
-            ]
141
-        );
142
-        $log->save();
143
-    }
21
+	/**
22
+	 * extra meta key for tracking when entities are trashed and by who
23
+	 *
24
+	 * @type string
25
+	 */
26
+	const EXTRA_META_KEY_ENTITY_TRASHED = 'entity-trashed';
27
+
28
+	/**
29
+	 * extra meta key for tracking when entities are restored and by who
30
+	 *
31
+	 * @type string
32
+	 */
33
+	const EXTRA_META_KEY_ENTITY_RESTORED = 'entity-restored';
34
+
35
+	/**
36
+	 * extra meta key for tracking when entities are deleted and by who
37
+	 *
38
+	 * @type string
39
+	 */
40
+	const EXTRA_META_KEY_ENTITY_DELETED = 'entity-deleted';
41
+
42
+
43
+	public function __construct()
44
+	{
45
+		add_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', [$this, 'logSoftDelete'], 10, 3);
46
+		add_action('AHEE__EE_Base_Class__delete_permanently__end', [$this, 'logHardDelete'], 10, 2);
47
+		add_action(
48
+			'AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted',
49
+			[$this, 'logBatchDelete'],
50
+			10,
51
+			2
52
+		);
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param EE_Soft_Delete_Base_Class $entity
58
+	 * @param bool                      $delete
59
+	 * @param bool                      $result
60
+	 * @throws EE_Error
61
+	 * @throws ReflectionException
62
+	 */
63
+	public function logSoftDelete(EE_Soft_Delete_Base_Class $entity, $delete, $result)
64
+	{
65
+		// which base meta key to use... trashed or restored?
66
+		$action = $delete
67
+			? TrashLogger::EXTRA_META_KEY_ENTITY_TRASHED
68
+			: TrashLogger::EXTRA_META_KEY_ENTITY_RESTORED;
69
+
70
+		$entity_class = $this->getEntityClass($entity);
71
+		$this->logDelete($entity->ID(), $entity_class, $action, $result);
72
+	}
73
+
74
+
75
+	/**
76
+	 * @param EE_Base_Class $entity
77
+	 * @param bool          $result
78
+	 * @throws EE_Error
79
+	 * @throws ReflectionException
80
+	 */
81
+	public function logHardDelete(EE_Base_Class $entity, $result)
82
+	{
83
+		$entity_class = $this->getEntityClass($entity);
84
+		$this->logDelete($entity->ID(), $entity_class, TrashLogger::EXTRA_META_KEY_ENTITY_DELETED, $result);
85
+	}
86
+
87
+
88
+	/**
89
+	 * @param int|string $entity_ID
90
+	 * @param string     $entity_type
91
+	 * @throws EE_Error
92
+	 * @throws ReflectionException
93
+	 */
94
+	public function logBatchDelete($entity_ID, $entity_type)
95
+	{
96
+		$entity_type = str_replace(['EE_', 'EEM_'], '', $entity_type);
97
+		$this->logDelete($entity_ID, $entity_type, TrashLogger::EXTRA_META_KEY_ENTITY_DELETED, true);
98
+	}
99
+
100
+
101
+	/**
102
+	 * converts entity class like 'EE_Registration' to 'registration'
103
+	 *
104
+	 * @param EE_Base_Class $entity
105
+	 * @return string
106
+	 */
107
+	private function getEntityClass(EE_Base_Class $entity)
108
+	{
109
+		return str_replace('EE_', '', get_class($entity));
110
+	}
111
+
112
+
113
+	/**
114
+	 * @param string $entity_ID
115
+	 * @param string $entity_type
116
+	 * @param string $action
117
+	 * @param bool   $result
118
+	 * @throws EE_Error
119
+	 * @throws ReflectionException
120
+	 */
121
+	private function logDelete($entity_ID, $entity_type, $action, $result)
122
+	{
123
+		// if trash/restore/delete was not successful, then get out
124
+		if (! $result) {
125
+			return;
126
+		}
127
+
128
+		// convert 'entity-deleted' to just 'deleted'
129
+		$action       = str_replace('entity-', '', $action);
130
+		$current_user = wp_get_current_user();
131
+		$user_name    = $current_user->ID ? $current_user->display_name : 'unknown user';
132
+		$timestamp    = date("D M j, Y @ g:i:s a", current_time('timestamp'));
133
+
134
+		$log = EE_Change_Log::new_instance(
135
+			[
136
+				'OBJ_ID'      => $entity_ID,
137
+				'OBJ_type'    => $entity_type,
138
+				'LOG_type'    => EEM_Change_Log::type_delete,
139
+				'LOG_message' => "$action by $user_name on $timestamp",
140
+			]
141
+		);
142
+		$log->save();
143
+	}
144 144
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@
 block discarded – undo
121 121
     private function logDelete($entity_ID, $entity_type, $action, $result)
122 122
     {
123 123
         // if trash/restore/delete was not successful, then get out
124
-        if (! $result) {
124
+        if ( ! $result) {
125 125
             return;
126 126
         }
127 127
 
Please login to merge, or discard this patch.
registrations/templates/attendee_registrations_main_meta_box.template.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -22,60 +22,60 @@
 block discarded – undo
22 22
                     <tr>
23 23
                         <td class="jst-left">
24 24
                             <?php
25
-                            $EVT_ID = absint($registration->event_ID());
26
-                            $event_url = add_query_arg(
27
-                                ['action' => 'edit', 'post' => $EVT_ID],
28
-                                admin_url('admin.php?page=espresso_events')
29
-                            );
30
-                            echo EE_Registry::instance()->CAP->current_user_can(
31
-                                'ee_edit_event',
32
-                                'espresso_events_edit',
33
-                                $EVT_ID
34
-                            )
35
-                                ? '<a href="' . esc_url_raw($event_url) . '"  aria-label="'
36
-                                  . esc_attr__('Edit Event', 'event_espresso') . '">'
37
-                                  . esc_html($registration->event_name()) . '</a>'
38
-                                : esc_html($registration->event_name());
39
-                            ?>
25
+							$EVT_ID = absint($registration->event_ID());
26
+							$event_url = add_query_arg(
27
+								['action' => 'edit', 'post' => $EVT_ID],
28
+								admin_url('admin.php?page=espresso_events')
29
+							);
30
+							echo EE_Registry::instance()->CAP->current_user_can(
31
+								'ee_edit_event',
32
+								'espresso_events_edit',
33
+								$EVT_ID
34
+							)
35
+								? '<a href="' . esc_url_raw($event_url) . '"  aria-label="'
36
+								  . esc_attr__('Edit Event', 'event_espresso') . '">'
37
+								  . esc_html($registration->event_name()) . '</a>'
38
+								: esc_html($registration->event_name());
39
+							?>
40 40
                         </td>
41 41
                         <td class="jst-left">
42 42
                             <?php
43
-                            $REG_ID = absint($registration->ID());
44
-                            $reg_url = EE_Admin_Page::add_query_args_and_nonce(
45
-                                ['action' => 'view_registration', '_REG_ID' => $REG_ID],
46
-                                REG_ADMIN_URL
47
-                            );
48
-                            echo EE_Registry::instance()->CAP->current_user_can(
49
-                                'ee_read_registration',
50
-                                'espresso_registrations_view_registration',
51
-                                $REG_ID
52
-                            )
53
-                                ? '<a href="' . esc_url_raw($reg_url) . '" aria-label="'
54
-                                  . esc_attr__('View Registration Details', 'event_espresso') . '">'
55
-                                  . esc_html__('View Registration', 'event_espresso') . '</a>'
56
-                                : $REG_ID;
57
-                            ?>
43
+							$REG_ID = absint($registration->ID());
44
+							$reg_url = EE_Admin_Page::add_query_args_and_nonce(
45
+								['action' => 'view_registration', '_REG_ID' => $REG_ID],
46
+								REG_ADMIN_URL
47
+							);
48
+							echo EE_Registry::instance()->CAP->current_user_can(
49
+								'ee_read_registration',
50
+								'espresso_registrations_view_registration',
51
+								$REG_ID
52
+							)
53
+								? '<a href="' . esc_url_raw($reg_url) . '" aria-label="'
54
+								  . esc_attr__('View Registration Details', 'event_espresso') . '">'
55
+								  . esc_html__('View Registration', 'event_espresso') . '</a>'
56
+								: $REG_ID;
57
+							?>
58 58
                         </td>
59 59
                         <td class="jst-left">
60 60
                             <?php
61
-                            $TXN_ID = absint($registration->transaction_ID());
62
-                            $txn_url = EE_Admin_Page::add_query_args_and_nonce(
63
-                                ['action' => 'view_transaction', 'TXN_ID' => $TXN_ID],
64
-                                TXN_ADMIN_URL
65
-                            );
66
-                            echo EE_Registry::instance()->CAP->current_user_can(
67
-                                'ee_read_transaction',
68
-                                'espresso_transactions_view_transaction'
69
-                            )
70
-                                ? '<a href="' . esc_url_raw($txn_url) . '" aria-label="'
71
-                                  . esc_attr__('View Transaction Details', 'event_espresso') . '">'
72
-                                  . sprintf(
73
-                                      esc_html__('View Transaction %d', 'event_espresso'),
74
-                                      $TXN_ID
75
-                                  ) .
76
-                                  '</a>'
77
-                                : $TXN_ID;
78
-                            ?>
61
+							$TXN_ID = absint($registration->transaction_ID());
62
+							$txn_url = EE_Admin_Page::add_query_args_and_nonce(
63
+								['action' => 'view_transaction', 'TXN_ID' => $TXN_ID],
64
+								TXN_ADMIN_URL
65
+							);
66
+							echo EE_Registry::instance()->CAP->current_user_can(
67
+								'ee_read_transaction',
68
+								'espresso_transactions_view_transaction'
69
+							)
70
+								? '<a href="' . esc_url_raw($txn_url) . '" aria-label="'
71
+								  . esc_attr__('View Transaction Details', 'event_espresso') . '">'
72
+								  . sprintf(
73
+									  esc_html__('View Transaction %d', 'event_espresso'),
74
+									  $TXN_ID
75
+								  ) .
76
+								  '</a>'
77
+								: $TXN_ID;
78
+							?>
79 79
                         </td>
80 80
                         <td class="jst-left"><?php echo esc_html($registration->reg_code()); ?></td>
81 81
                         <td class="jst-rght">
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
                                 'espresso_events_edit',
33 33
                                 $EVT_ID
34 34
                             )
35
-                                ? '<a href="' . esc_url_raw($event_url) . '"  aria-label="'
36
-                                  . esc_attr__('Edit Event', 'event_espresso') . '">'
37
-                                  . esc_html($registration->event_name()) . '</a>'
35
+                                ? '<a href="'.esc_url_raw($event_url).'"  aria-label="'
36
+                                  . esc_attr__('Edit Event', 'event_espresso').'">'
37
+                                  . esc_html($registration->event_name()).'</a>'
38 38
                                 : esc_html($registration->event_name());
39 39
                             ?>
40 40
                         </td>
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
                                 'espresso_registrations_view_registration',
51 51
                                 $REG_ID
52 52
                             )
53
-                                ? '<a href="' . esc_url_raw($reg_url) . '" aria-label="'
54
-                                  . esc_attr__('View Registration Details', 'event_espresso') . '">'
55
-                                  . esc_html__('View Registration', 'event_espresso') . '</a>'
53
+                                ? '<a href="'.esc_url_raw($reg_url).'" aria-label="'
54
+                                  . esc_attr__('View Registration Details', 'event_espresso').'">'
55
+                                  . esc_html__('View Registration', 'event_espresso').'</a>'
56 56
                                 : $REG_ID;
57 57
                             ?>
58 58
                         </td>
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
                                 'ee_read_transaction',
68 68
                                 'espresso_transactions_view_transaction'
69 69
                             )
70
-                                ? '<a href="' . esc_url_raw($txn_url) . '" aria-label="'
71
-                                  . esc_attr__('View Transaction Details', 'event_espresso') . '">'
70
+                                ? '<a href="'.esc_url_raw($txn_url).'" aria-label="'
71
+                                  . esc_attr__('View Transaction Details', 'event_espresso').'">'
72 72
                                   . sprintf(
73 73
                                       esc_html__('View Transaction %d', 'event_espresso'),
74 74
                                       $TXN_ID
75
-                                  ) .
75
+                                  ).
76 76
                                   '</a>'
77 77
                                 : $TXN_ID;
78 78
                             ?>
Please login to merge, or discard this patch.
registration_form/espresso_events_Registration_Form_Hooks_Extend.class.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                 : [];
135 135
             $EQGids = array_keys($EQGs);
136 136
 
137
-            if (! empty($QSGs)) {
137
+            if ( ! empty($QSGs)) {
138 138
                 $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
139 139
                 foreach ($QSGs as $QSG) {
140 140
                     $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked ' : '';
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
                     );
148 148
 
149 149
                     $html .= '
150
-					<p id="event-question-group-' . $QSG->ID() . '">
151
-						<input value="' . $QSG->ID() . '"'
152
-                             . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' />
153
-						<a href="' . $edit_link . '" 
154
-						   aria-label="' . sprintf(esc_attr__('Edit %s Group', 'event_espresso'), $QSG->get('QSG_name')) . '" 
150
+					<p id="event-question-group-' . $QSG->ID().'">
151
+						<input value="' . $QSG->ID().'"'
152
+                             . ' type="checkbox" name="add_attendee_question_groups['.$QSG->ID().']"'.$checked.' />
153
+						<a href="' . $edit_link.'" 
154
+						   aria-label="' . sprintf(esc_attr__('Edit %s Group', 'event_espresso'), $QSG->get('QSG_name')).'" 
155 155
                           target="_blank"
156 156
                         >
157
-                            ' . $QSG->get('QSG_name') . '
157
+                            ' . $QSG->get('QSG_name').'
158 158
                         </a>
159 159
 					</p>';
160 160
                     if ($QSG->ID() === 2) {
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
                         ' . esc_html__(
164 164
                             'The Personal Information question group is required whenever the Address Information question group is activated.',
165 165
                             'event_espresso'
166
-                        ) . '
166
+                        ).'
167 167
                         </p>';
168 168
                     }
169 169
                 }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         $current_qgs = array_keys($current_qgs); // we just want the ids
200 200
 
201 201
         // now let's get the groups selected in the editor and update (IF we have data)
202
-        if (! empty($question_groups)) {
202
+        if ( ! empty($question_groups)) {
203 203
             foreach ($question_groups as $qgid) {
204 204
                 // add to event
205 205
                 if ($qgid) {
Please login to merge, or discard this patch.
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -16,146 +16,146 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks
18 18
 {
19
-    /**
20
-     * extending the properties set in espresso_events_Registration_From_Hooks
21
-     *
22
-     * @access protected
23
-     * @return void
24
-     */
25
-    protected function _extend_properties()
26
-    {
27
-        if (
28
-            $this->_adminpage_obj->adminConfig()->useAdvancedEditor()
29
-            && $this->_adminpage_obj->feature()->allowed('use_reg_form_builder')
30
-        ) {
31
-            return;
32
-        }
33
-        $this->_metaboxes = array_merge(
34
-            $this->_metaboxes,
35
-            array(
36
-                1 => array(
37
-                    'page_route' => array('create_new', 'edit'),
38
-                    'func'       => 'additional_questions',
39
-                    'label'      => esc_html__('Questions for Additional Registrants', 'event_espresso'),
40
-                    'priority'   => 'default',
41
-                    'context'    => 'side',
42
-                ),
43
-            )
44
-        );
45
-        $this->_scripts_styles = array(
46
-            'registers' => array(
47
-                'extended-event-editor' => array(
48
-                    'url'     => EE_CORE_CAF_ADMIN_EXTEND_URL
49
-                                 . 'registration_form/assets/event-editor-question-groups.js',
50
-                    'depends' => array('jquery'),
51
-                ),
52
-            ),
53
-            'enqueues'  => array(
54
-                'extended-event-editor' => array('edit', 'create_new'),
55
-            ),
56
-        );
57
-    }
58
-
59
-
60
-    /**
61
-     * @param Callable[] $callbacks
62
-     * @return array
63
-     */
64
-    public function modify_callbacks($callbacks)
65
-    {
66
-        $callbacks = parent::modify_callbacks($callbacks);
67
-        $callbacks[] = array($this, 'additional_question_group_update');
68
-        return $callbacks;
69
-    }
70
-
71
-
72
-    /**
73
-     * Call back hooked into revision restores.
74
-     *
75
-     * @param $post_id
76
-     * @param $revision_id
77
-     * @return EE_Base_Class|void
78
-     * @throws EE_Error
79
-     * @throws InvalidArgumentException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     * @throws ReflectionException
83
-     */
84
-    public function restore_revision($post_id, $revision_id)
85
-    {
86
-        $post_evt = parent::restore_revision($post_id, $revision_id);
87
-
88
-        // restore revision for additional questions
89
-        $post_evt->restore_revision(
90
-            $revision_id,
91
-            ['Question_Group'],
92
-            [
93
-                'Question_Group' => ['Event_Question_Group.EQG_additional' => true],
94
-            ]
95
-        );
96
-    }
97
-
98
-
99
-    /**
100
-     * @param $post_id
101
-     * @param $post
102
-     * @throws EE_Error
103
-     * @throws InvalidArgumentException
104
-     * @throws InvalidDataTypeException
105
-     * @throws InvalidInterfaceException
106
-     */
107
-    public function additional_questions($post_id, $post)
108
-    {
109
-        $this->_event = $this->_adminpage_obj->get_event_object();
110
-        $event_id = $this->_event->ID();
111
-        ?>
19
+	/**
20
+	 * extending the properties set in espresso_events_Registration_From_Hooks
21
+	 *
22
+	 * @access protected
23
+	 * @return void
24
+	 */
25
+	protected function _extend_properties()
26
+	{
27
+		if (
28
+			$this->_adminpage_obj->adminConfig()->useAdvancedEditor()
29
+			&& $this->_adminpage_obj->feature()->allowed('use_reg_form_builder')
30
+		) {
31
+			return;
32
+		}
33
+		$this->_metaboxes = array_merge(
34
+			$this->_metaboxes,
35
+			array(
36
+				1 => array(
37
+					'page_route' => array('create_new', 'edit'),
38
+					'func'       => 'additional_questions',
39
+					'label'      => esc_html__('Questions for Additional Registrants', 'event_espresso'),
40
+					'priority'   => 'default',
41
+					'context'    => 'side',
42
+				),
43
+			)
44
+		);
45
+		$this->_scripts_styles = array(
46
+			'registers' => array(
47
+				'extended-event-editor' => array(
48
+					'url'     => EE_CORE_CAF_ADMIN_EXTEND_URL
49
+								 . 'registration_form/assets/event-editor-question-groups.js',
50
+					'depends' => array('jquery'),
51
+				),
52
+			),
53
+			'enqueues'  => array(
54
+				'extended-event-editor' => array('edit', 'create_new'),
55
+			),
56
+		);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @param Callable[] $callbacks
62
+	 * @return array
63
+	 */
64
+	public function modify_callbacks($callbacks)
65
+	{
66
+		$callbacks = parent::modify_callbacks($callbacks);
67
+		$callbacks[] = array($this, 'additional_question_group_update');
68
+		return $callbacks;
69
+	}
70
+
71
+
72
+	/**
73
+	 * Call back hooked into revision restores.
74
+	 *
75
+	 * @param $post_id
76
+	 * @param $revision_id
77
+	 * @return EE_Base_Class|void
78
+	 * @throws EE_Error
79
+	 * @throws InvalidArgumentException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 * @throws ReflectionException
83
+	 */
84
+	public function restore_revision($post_id, $revision_id)
85
+	{
86
+		$post_evt = parent::restore_revision($post_id, $revision_id);
87
+
88
+		// restore revision for additional questions
89
+		$post_evt->restore_revision(
90
+			$revision_id,
91
+			['Question_Group'],
92
+			[
93
+				'Question_Group' => ['Event_Question_Group.EQG_additional' => true],
94
+			]
95
+		);
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param $post_id
101
+	 * @param $post
102
+	 * @throws EE_Error
103
+	 * @throws InvalidArgumentException
104
+	 * @throws InvalidDataTypeException
105
+	 * @throws InvalidInterfaceException
106
+	 */
107
+	public function additional_questions($post_id, $post)
108
+	{
109
+		$this->_event = $this->_adminpage_obj->get_event_object();
110
+		$event_id = $this->_event->ID();
111
+		?>
112 112
         <div class="inside">
113 113
             <p><strong>
114 114
                     <?php esc_html_e('Question Groups', 'event_espresso'); ?>
115 115
                 </strong><br/>
116 116
                 <?php
117
-                printf(
118
-                    esc_html__(
119
-                        'Add a pre-populated %1$sgroup of questions%2$s to your event.',
120
-                        'event_espresso'
121
-                    ),
122
-                    '<a href="admin.php?page=espresso_registration_form" target="_blank">',
123
-                    '</a>'
124
-                );
125
-                ?>
117
+				printf(
118
+					esc_html__(
119
+						'Add a pre-populated %1$sgroup of questions%2$s to your event.',
120
+						'event_espresso'
121
+					),
122
+					'<a href="admin.php?page=espresso_registration_form" target="_blank">',
123
+					'</a>'
124
+				);
125
+				?>
126 126
             </p>
127 127
             <?php
128 128
 
129
-            $qsg_where['QSG_deleted'] = false;
130
-            $query_params = apply_filters(
131
-                'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters',
132
-                array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
133
-            );
134
-            $QSGs = EEM_Question_Group::instance()->get_all($query_params);
135
-            $EQGs = ! empty($event_id)
136
-                ? $this->_event->get_many_related(
137
-                    'Question_Group',
138
-                    [['Event_Question_Group.EQG_additional' => true]]
139
-                )
140
-                : [];
141
-            $EQGids = array_keys($EQGs);
142
-
143
-            if (! empty($QSGs)) {
144
-                $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
145
-                foreach ($QSGs as $QSG) {
146
-                    $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked ' : '';
147
-                    $edit_link = EE_Admin_Page::add_query_args_and_nonce(
148
-                        array(
149
-                            'action' => 'edit_question_group',
150
-                            'QSG_ID' => $QSG->ID(),
151
-                        ),
152
-                        EE_FORMS_ADMIN_URL
153
-                    );
154
-
155
-                    $html .= '
129
+			$qsg_where['QSG_deleted'] = false;
130
+			$query_params = apply_filters(
131
+				'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters',
132
+				array($qsg_where, 'order_by' => array('QSG_order' => 'ASC'))
133
+			);
134
+			$QSGs = EEM_Question_Group::instance()->get_all($query_params);
135
+			$EQGs = ! empty($event_id)
136
+				? $this->_event->get_many_related(
137
+					'Question_Group',
138
+					[['Event_Question_Group.EQG_additional' => true]]
139
+				)
140
+				: [];
141
+			$EQGids = array_keys($EQGs);
142
+
143
+			if (! empty($QSGs)) {
144
+				$html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
145
+				foreach ($QSGs as $QSG) {
146
+					$checked = in_array($QSG->ID(), $EQGids, true) ? ' checked ' : '';
147
+					$edit_link = EE_Admin_Page::add_query_args_and_nonce(
148
+						array(
149
+							'action' => 'edit_question_group',
150
+							'QSG_ID' => $QSG->ID(),
151
+						),
152
+						EE_FORMS_ADMIN_URL
153
+					);
154
+
155
+					$html .= '
156 156
 					<p id="event-question-group-' . $QSG->ID() . '">
157 157
 						<input value="' . $QSG->ID() . '"'
158
-                             . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' />
158
+							 . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' />
159 159
 						<a href="' . $edit_link . '" 
160 160
 						   aria-label="' . sprintf(esc_attr__('Edit %s Group', 'event_espresso'), $QSG->get('QSG_name')) . '" 
161 161
                           target="_blank"
@@ -163,67 +163,67 @@  discard block
 block discarded – undo
163 163
                             ' . $QSG->get('QSG_name') . '
164 164
                         </a>
165 165
 					</p>';
166
-                    if ($QSG->ID() === 2) {
167
-                        $html .= '
166
+					if ($QSG->ID() === 2) {
167
+						$html .= '
168 168
 					    <p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">
169 169
                         ' . esc_html__(
170
-                            'The Personal Information question group is required whenever the Address Information question group is activated.',
171
-                            'event_espresso'
172
-                        ) . '
170
+							'The Personal Information question group is required whenever the Address Information question group is activated.',
171
+							'event_espresso'
172
+						) . '
173 173
                         </p>';
174
-                    }
175
-                }
176
-                $html .= count($QSGs) > 10 ? '</div>' : '';
177
-
178
-                echo wp_kses($html, AllowedTags::getWithFormTags());
179
-            } else {
180
-                esc_html_e(
181
-                    'There seems to be a problem with your questions. Please contact [email protected]',
182
-                    'event_espresso'
183
-                );
184
-            }
185
-            do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content');
186
-            ?>
174
+					}
175
+				}
176
+				$html .= count($QSGs) > 10 ? '</div>' : '';
177
+
178
+				echo wp_kses($html, AllowedTags::getWithFormTags());
179
+			} else {
180
+				esc_html_e(
181
+					'There seems to be a problem with your questions. Please contact [email protected]',
182
+					'event_espresso'
183
+				);
184
+			}
185
+			do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content');
186
+			?>
187 187
         </div>
188 188
         <?php
189
-    }
190
-
191
-
192
-    public function additional_question_group_update($evtobj, $data)
193
-    {
194
-        $question_groups = ! empty($data['add_attendee_question_groups'])
195
-            ? (array) $data['add_attendee_question_groups']
196
-            : [];
197
-        $added_qgs = array_keys($question_groups);
198
-        $success = [];
199
-
200
-        // let's get all current question groups associated with this event.
201
-        $current_qgs = $evtobj->get_many_related(
202
-            'Question_Group',
203
-            [['Event_Question_Group.EQG_additional' => true]]
204
-        );
205
-        $current_qgs = array_keys($current_qgs); // we just want the ids
206
-
207
-        // now let's get the groups selected in the editor and update (IF we have data)
208
-        if (! empty($question_groups)) {
209
-            foreach ($question_groups as $qgid) {
210
-                // add to event
211
-                if ($qgid) {
212
-                    $qg = $evtobj->add_question_group($qgid, false);
213
-                }
214
-                $success[] = ! empty($qg) ? 1 : 0;
215
-            }
216
-        }
217
-
218
-        // wait a minute... are there question groups missing in the saved groups that ARE with the current event?
219
-        $removed_qgs = array_diff($current_qgs, $added_qgs);
220
-
221
-        foreach ($removed_qgs as $qgid) {
222
-            $qg = $evtobj->remove_question_group($qgid, false);
223
-            $success[] = ! empty($qg) ? 1 : 0;
224
-        }
225
-
226
-
227
-        return in_array(0, $success, true) ? false : true;
228
-    }
189
+	}
190
+
191
+
192
+	public function additional_question_group_update($evtobj, $data)
193
+	{
194
+		$question_groups = ! empty($data['add_attendee_question_groups'])
195
+			? (array) $data['add_attendee_question_groups']
196
+			: [];
197
+		$added_qgs = array_keys($question_groups);
198
+		$success = [];
199
+
200
+		// let's get all current question groups associated with this event.
201
+		$current_qgs = $evtobj->get_many_related(
202
+			'Question_Group',
203
+			[['Event_Question_Group.EQG_additional' => true]]
204
+		);
205
+		$current_qgs = array_keys($current_qgs); // we just want the ids
206
+
207
+		// now let's get the groups selected in the editor and update (IF we have data)
208
+		if (! empty($question_groups)) {
209
+			foreach ($question_groups as $qgid) {
210
+				// add to event
211
+				if ($qgid) {
212
+					$qg = $evtobj->add_question_group($qgid, false);
213
+				}
214
+				$success[] = ! empty($qg) ? 1 : 0;
215
+			}
216
+		}
217
+
218
+		// wait a minute... are there question groups missing in the saved groups that ARE with the current event?
219
+		$removed_qgs = array_diff($current_qgs, $added_qgs);
220
+
221
+		foreach ($removed_qgs as $qgid) {
222
+			$qg = $evtobj->remove_question_group($qgid, false);
223
+			$success[] = ! empty($qg) ? 1 : 0;
224
+		}
225
+
226
+
227
+		return in_array(0, $success, true) ? false : true;
228
+	}
229 229
 }
Please login to merge, or discard this patch.