@@ -10,9 +10,9 @@ |
||
10 | 10 | <head> |
11 | 11 | <title>[organization]<?php esc_html__(' Invoice #', 'event_espresso'); ?>[registration_code] |
12 | 12 | <?php esc_html__( |
13 | - ' for ', |
|
14 | - 'event_espresso' |
|
15 | - ); ?>[name]</title> |
|
13 | + ' for ', |
|
14 | + 'event_espresso' |
|
15 | + ); ?>[name]</title> |
|
16 | 16 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
17 | 17 | <!-- Base Stylesheet do not change or remove --> |
18 | 18 | <link rel="stylesheet" type="text/css" href="[base_url]base.css" media="screen"/> |
@@ -55,8 +55,8 @@ |
||
55 | 55 | */ |
56 | 56 | public function run($WP) |
57 | 57 | { |
58 | - if (is_readable(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php')) { |
|
59 | - require_once(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php'); |
|
58 | + if (is_readable(EE_MODULES.'gateways/Invoice/lib/Invoice.class.php')) { |
|
59 | + require_once(EE_MODULES.'gateways/Invoice/lib/Invoice.class.php'); |
|
60 | 60 | } else { |
61 | 61 | $msg = esc_html__('The Invoice.class.php file could not be loaded.', 'event_espresso'); |
62 | 62 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -10,91 +10,91 @@ |
||
10 | 10 | */ |
11 | 11 | class EED_Invoice extends EED_Module |
12 | 12 | { |
13 | - /** |
|
14 | - * @return EED_Invoice|EED_Module |
|
15 | - * @throws EE_Error |
|
16 | - * @throws ReflectionException |
|
17 | - */ |
|
18 | - public static function instance() |
|
19 | - { |
|
20 | - return parent::get_instance(__CLASS__); |
|
21 | - } |
|
13 | + /** |
|
14 | + * @return EED_Invoice|EED_Module |
|
15 | + * @throws EE_Error |
|
16 | + * @throws ReflectionException |
|
17 | + */ |
|
18 | + public static function instance() |
|
19 | + { |
|
20 | + return parent::get_instance(__CLASS__); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
26 | - * |
|
27 | - * @access public |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public static function set_hooks() |
|
31 | - { |
|
32 | - EE_Config::register_route('download_invoice', 'EED_Invoice', 'download_invoice'); |
|
33 | - EE_Config::register_route('launch_invoice', 'EED_Invoice', 'launch_invoice'); |
|
34 | - } |
|
24 | + /** |
|
25 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
26 | + * |
|
27 | + * @access public |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public static function set_hooks() |
|
31 | + { |
|
32 | + EE_Config::register_route('download_invoice', 'EED_Invoice', 'download_invoice'); |
|
33 | + EE_Config::register_route('launch_invoice', 'EED_Invoice', 'launch_invoice'); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
39 | - * |
|
40 | - * @access public |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public static function set_hooks_admin() |
|
44 | - { |
|
45 | - } |
|
37 | + /** |
|
38 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
39 | + * |
|
40 | + * @access public |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public static function set_hooks_admin() |
|
44 | + { |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * run - initial module setup |
|
50 | - * |
|
51 | - * @access public |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function run($WP) |
|
55 | - { |
|
56 | - if (is_readable(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php')) { |
|
57 | - require_once(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php'); |
|
58 | - } else { |
|
59 | - $msg = esc_html__('The Invoice.class.php file could not be loaded.', 'event_espresso'); |
|
60 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
61 | - } |
|
62 | - } |
|
48 | + /** |
|
49 | + * run - initial module setup |
|
50 | + * |
|
51 | + * @access public |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function run($WP) |
|
55 | + { |
|
56 | + if (is_readable(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php')) { |
|
57 | + require_once(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php'); |
|
58 | + } else { |
|
59 | + $msg = esc_html__('The Invoice.class.php file could not be loaded.', 'event_espresso'); |
|
60 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * invoice_launch |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function launch_invoice() |
|
72 | - { |
|
73 | - $this->run(null); |
|
74 | - $request = self::getRequest(); |
|
75 | - if ($request->requestParamIsSet('id')) { |
|
76 | - $id = $request->getRequestParam('id', '', 'key'); |
|
77 | - $invoice = new Invoice($id); |
|
78 | - $invoice->send_invoice(); |
|
79 | - } |
|
80 | - } |
|
65 | + /** |
|
66 | + * invoice_launch |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function launch_invoice() |
|
72 | + { |
|
73 | + $this->run(null); |
|
74 | + $request = self::getRequest(); |
|
75 | + if ($request->requestParamIsSet('id')) { |
|
76 | + $id = $request->getRequestParam('id', '', 'key'); |
|
77 | + $invoice = new Invoice($id); |
|
78 | + $invoice->send_invoice(); |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * download_invoice |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - public function download_invoice() |
|
90 | - { |
|
91 | - $this->run(null); |
|
92 | - $request = self::getRequest(); |
|
93 | - if ($request->requestParamIsSet('id')) { |
|
94 | - $id = $request->getRequestParam('id', '', 'key'); |
|
95 | - $invoice = new Invoice($id); |
|
96 | - // send invoice but force download |
|
97 | - $invoice->send_invoice(true); |
|
98 | - } |
|
99 | - } |
|
83 | + /** |
|
84 | + * download_invoice |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + public function download_invoice() |
|
90 | + { |
|
91 | + $this->run(null); |
|
92 | + $request = self::getRequest(); |
|
93 | + if ($request->requestParamIsSet('id')) { |
|
94 | + $id = $request->getRequestParam('id', '', 'key'); |
|
95 | + $invoice = new Invoice($id); |
|
96 | + // send invoice but force download |
|
97 | + $invoice->send_invoice(true); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $txn_update_params |
99 | 99 | ); |
100 | 100 | // check if transaction has a primary registrant and that it has a related Attendee object |
101 | - if (! $this->_validate_primary_registrant()) { |
|
101 | + if ( ! $this->_validate_primary_registrant()) { |
|
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | // you don't have to go home but you can't stay here ! |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | protected function _validate_primary_registrant() |
231 | 231 | { |
232 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
232 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
233 | 233 | EE_Error::add_error( |
234 | 234 | esc_html__('A valid Primary Registration for this Transaction could not be found.', 'event_espresso'), |
235 | 235 | __FILE__, |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | public function update_reg_step() |
256 | 256 | { |
257 | 257 | EE_Error::doing_it_wrong( |
258 | - __CLASS__ . '::' . __FILE__, |
|
258 | + __CLASS__.'::'.__FILE__, |
|
259 | 259 | esc_html__( |
260 | 260 | 'Can not call update_reg_step() on the Finalize Registration reg step.', |
261 | 261 | 'event_espresso' |
@@ -14,252 +14,252 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_SPCO_Reg_Step_Finalize_Registration extends EE_SPCO_Reg_Step |
16 | 16 | { |
17 | - /** |
|
18 | - * class constructor |
|
19 | - * |
|
20 | - * @access public |
|
21 | - * @param EE_Checkout $checkout |
|
22 | - */ |
|
23 | - public function __construct(EE_Checkout $checkout) |
|
24 | - { |
|
25 | - $this->request = EED_Single_Page_Checkout::getRequest(); |
|
26 | - $this->_slug = 'finalize_registration'; |
|
27 | - $this->_name = esc_html__('Finalize Registration', 'event_espresso'); |
|
28 | - $this->_submit_button_text = $this->_name; |
|
29 | - $this->_template = ''; |
|
30 | - $this->checkout = $checkout; |
|
31 | - } |
|
17 | + /** |
|
18 | + * class constructor |
|
19 | + * |
|
20 | + * @access public |
|
21 | + * @param EE_Checkout $checkout |
|
22 | + */ |
|
23 | + public function __construct(EE_Checkout $checkout) |
|
24 | + { |
|
25 | + $this->request = EED_Single_Page_Checkout::getRequest(); |
|
26 | + $this->_slug = 'finalize_registration'; |
|
27 | + $this->_name = esc_html__('Finalize Registration', 'event_espresso'); |
|
28 | + $this->_submit_button_text = $this->_name; |
|
29 | + $this->_template = ''; |
|
30 | + $this->checkout = $checkout; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - public function translate_js_strings() |
|
35 | - { |
|
36 | - } |
|
34 | + public function translate_js_strings() |
|
35 | + { |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - public function enqueue_styles_and_scripts() |
|
40 | - { |
|
41 | - } |
|
39 | + public function enqueue_styles_and_scripts() |
|
40 | + { |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @return boolean |
|
46 | - */ |
|
47 | - public function initialize_reg_step() |
|
48 | - { |
|
49 | - // there's actually no reg form to process if this is the final step |
|
50 | - if ($this->is_current_step()) { |
|
51 | - $this->checkout->step = $this->slug(); |
|
52 | - $this->checkout->action = 'process_reg_step'; |
|
53 | - $this->checkout->generate_reg_form = false; |
|
54 | - $this->request->setRequestParam('step', $this->checkout->step); |
|
55 | - $this->request->setRequestParam('action', $this->checkout->action); |
|
56 | - } |
|
57 | - return true; |
|
58 | - } |
|
44 | + /** |
|
45 | + * @return boolean |
|
46 | + */ |
|
47 | + public function initialize_reg_step() |
|
48 | + { |
|
49 | + // there's actually no reg form to process if this is the final step |
|
50 | + if ($this->is_current_step()) { |
|
51 | + $this->checkout->step = $this->slug(); |
|
52 | + $this->checkout->action = 'process_reg_step'; |
|
53 | + $this->checkout->generate_reg_form = false; |
|
54 | + $this->request->setRequestParam('step', $this->checkout->step); |
|
55 | + $this->request->setRequestParam('action', $this->checkout->action); |
|
56 | + } |
|
57 | + return true; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function generate_reg_form() |
|
65 | - { |
|
66 | - // create empty form so that things don't break |
|
67 | - $this->reg_form = new EE_Form_Section_Proper(); |
|
68 | - return ''; |
|
69 | - } |
|
61 | + /** |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function generate_reg_form() |
|
65 | + { |
|
66 | + // create empty form so that things don't break |
|
67 | + $this->reg_form = new EE_Form_Section_Proper(); |
|
68 | + return ''; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * @return boolean |
|
74 | - * @throws RuntimeException |
|
75 | - * @throws EE_Error |
|
76 | - * @throws ReflectionException |
|
77 | - */ |
|
78 | - public function process_reg_step() |
|
79 | - { |
|
80 | - // ensure all data gets refreshed from the db |
|
81 | - $this->checkout->refresh_all_entities(true); |
|
82 | - // ensures that all details and statuses for transaction, registration, and payments are updated |
|
83 | - $txn_update_params = $this->_finalize_transaction(); |
|
84 | - // maybe send messages |
|
85 | - $this->_set_notification_triggers(); |
|
86 | - // send messages |
|
87 | - /** @type EE_Registration_Processor $registration_processor */ |
|
88 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
89 | - $registration_processor->trigger_registration_update_notifications( |
|
90 | - $this->checkout->transaction->primary_registration(), |
|
91 | - $txn_update_params |
|
92 | - ); |
|
93 | - // set a hook point |
|
94 | - do_action( |
|
95 | - 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', |
|
96 | - $this->checkout, |
|
97 | - $txn_update_params |
|
98 | - ); |
|
99 | - // check if transaction has a primary registrant and that it has a related Attendee object |
|
100 | - if (! $this->_validate_primary_registrant()) { |
|
101 | - return false; |
|
102 | - } |
|
103 | - // you don't have to go home but you can't stay here ! |
|
104 | - $this->checkout->redirect = true; |
|
105 | - $this->checkout->continue_reg = true; |
|
106 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
107 | - if ( |
|
108 | - ! ( |
|
109 | - $this->checkout->payment_method instanceof EE_Payment_Method |
|
110 | - && $this->checkout->payment_method->is_off_site() |
|
111 | - ) |
|
112 | - ) { |
|
113 | - // mark this reg step as completed |
|
114 | - $this->set_completed(); |
|
115 | - } |
|
116 | - $this->checkout->set_exit_spco(); |
|
117 | - return true; |
|
118 | - } |
|
72 | + /** |
|
73 | + * @return boolean |
|
74 | + * @throws RuntimeException |
|
75 | + * @throws EE_Error |
|
76 | + * @throws ReflectionException |
|
77 | + */ |
|
78 | + public function process_reg_step() |
|
79 | + { |
|
80 | + // ensure all data gets refreshed from the db |
|
81 | + $this->checkout->refresh_all_entities(true); |
|
82 | + // ensures that all details and statuses for transaction, registration, and payments are updated |
|
83 | + $txn_update_params = $this->_finalize_transaction(); |
|
84 | + // maybe send messages |
|
85 | + $this->_set_notification_triggers(); |
|
86 | + // send messages |
|
87 | + /** @type EE_Registration_Processor $registration_processor */ |
|
88 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
89 | + $registration_processor->trigger_registration_update_notifications( |
|
90 | + $this->checkout->transaction->primary_registration(), |
|
91 | + $txn_update_params |
|
92 | + ); |
|
93 | + // set a hook point |
|
94 | + do_action( |
|
95 | + 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', |
|
96 | + $this->checkout, |
|
97 | + $txn_update_params |
|
98 | + ); |
|
99 | + // check if transaction has a primary registrant and that it has a related Attendee object |
|
100 | + if (! $this->_validate_primary_registrant()) { |
|
101 | + return false; |
|
102 | + } |
|
103 | + // you don't have to go home but you can't stay here ! |
|
104 | + $this->checkout->redirect = true; |
|
105 | + $this->checkout->continue_reg = true; |
|
106 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
107 | + if ( |
|
108 | + ! ( |
|
109 | + $this->checkout->payment_method instanceof EE_Payment_Method |
|
110 | + && $this->checkout->payment_method->is_off_site() |
|
111 | + ) |
|
112 | + ) { |
|
113 | + // mark this reg step as completed |
|
114 | + $this->set_completed(); |
|
115 | + } |
|
116 | + $this->checkout->set_exit_spco(); |
|
117 | + return true; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * _finalize_transaction |
|
123 | - * ensures that all details and statuses for transaction, registration, and payments are updated |
|
124 | - * |
|
125 | - * @return array |
|
126 | - * @throws RuntimeException |
|
127 | - * @throws EE_Error |
|
128 | - * @throws ReflectionException |
|
129 | - */ |
|
130 | - protected function _finalize_transaction() |
|
131 | - { |
|
132 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
133 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
134 | - // set revisit flag in txn processor |
|
135 | - $transaction_processor->set_revisit($this->checkout->revisit); |
|
136 | - // at this point we'll consider a TXN to not have been abandoned |
|
137 | - $this->checkout->transaction->toggle_abandoned_transaction_status(); |
|
138 | - if ($this->checkout->cart instanceof EE_Cart) { |
|
139 | - // save TXN data to the cart |
|
140 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
141 | - $this->checkout->transaction->ID() |
|
142 | - ); |
|
143 | - } |
|
144 | - // maybe update status, but don't save transaction just yet |
|
145 | - $this->checkout->transaction->update_status_based_on_total_paid(false); |
|
146 | - // this will result in the base session properties getting saved to the TXN_Session_data field |
|
147 | - $session_data = EE_Registry::instance()->SSN->get_session_data(null, true); |
|
148 | - // anonymize the last part of the IP address, now that the transaction is complete (we won't be using the IP address |
|
149 | - // for spam or bot detection now) |
|
150 | - if (function_exists('wp_privacy_anonymize_ip') && isset($session_data['ip_address'])) { |
|
151 | - $session_data['ip_address'] = wp_privacy_anonymize_ip($session_data['ip_address']); |
|
152 | - } |
|
153 | - $this->checkout->transaction->set_txn_session_data($session_data); |
|
154 | - // update the TXN if payment conditions have changed, but do NOT trigger notifications, |
|
155 | - // because we will do that in process_reg_step() after setting some more triggers |
|
156 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
157 | - $this->checkout->transaction, |
|
158 | - $this->checkout->payment, |
|
159 | - $this->checkout->reg_cache_where_params, |
|
160 | - false |
|
161 | - ); |
|
162 | - } |
|
121 | + /** |
|
122 | + * _finalize_transaction |
|
123 | + * ensures that all details and statuses for transaction, registration, and payments are updated |
|
124 | + * |
|
125 | + * @return array |
|
126 | + * @throws RuntimeException |
|
127 | + * @throws EE_Error |
|
128 | + * @throws ReflectionException |
|
129 | + */ |
|
130 | + protected function _finalize_transaction() |
|
131 | + { |
|
132 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
133 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
134 | + // set revisit flag in txn processor |
|
135 | + $transaction_processor->set_revisit($this->checkout->revisit); |
|
136 | + // at this point we'll consider a TXN to not have been abandoned |
|
137 | + $this->checkout->transaction->toggle_abandoned_transaction_status(); |
|
138 | + if ($this->checkout->cart instanceof EE_Cart) { |
|
139 | + // save TXN data to the cart |
|
140 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
141 | + $this->checkout->transaction->ID() |
|
142 | + ); |
|
143 | + } |
|
144 | + // maybe update status, but don't save transaction just yet |
|
145 | + $this->checkout->transaction->update_status_based_on_total_paid(false); |
|
146 | + // this will result in the base session properties getting saved to the TXN_Session_data field |
|
147 | + $session_data = EE_Registry::instance()->SSN->get_session_data(null, true); |
|
148 | + // anonymize the last part of the IP address, now that the transaction is complete (we won't be using the IP address |
|
149 | + // for spam or bot detection now) |
|
150 | + if (function_exists('wp_privacy_anonymize_ip') && isset($session_data['ip_address'])) { |
|
151 | + $session_data['ip_address'] = wp_privacy_anonymize_ip($session_data['ip_address']); |
|
152 | + } |
|
153 | + $this->checkout->transaction->set_txn_session_data($session_data); |
|
154 | + // update the TXN if payment conditions have changed, but do NOT trigger notifications, |
|
155 | + // because we will do that in process_reg_step() after setting some more triggers |
|
156 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
157 | + $this->checkout->transaction, |
|
158 | + $this->checkout->payment, |
|
159 | + $this->checkout->reg_cache_where_params, |
|
160 | + false |
|
161 | + ); |
|
162 | + } |
|
163 | 163 | |
164 | 164 | |
165 | - /** |
|
166 | - * If request is not a revisit, and an Off-Site gateway using IPNs has NOT been selected... |
|
167 | - * OR |
|
168 | - * if it IS a revisit and the TXN and/or one or more REG statuses have changed... |
|
169 | - * then trigger notifications |
|
170 | - * |
|
171 | - * @return void |
|
172 | - * @throws EE_Error |
|
173 | - * @throws ReflectionException |
|
174 | - */ |
|
175 | - protected function _set_notification_triggers() |
|
176 | - { |
|
165 | + /** |
|
166 | + * If request is not a revisit, and an Off-Site gateway using IPNs has NOT been selected... |
|
167 | + * OR |
|
168 | + * if it IS a revisit and the TXN and/or one or more REG statuses have changed... |
|
169 | + * then trigger notifications |
|
170 | + * |
|
171 | + * @return void |
|
172 | + * @throws EE_Error |
|
173 | + * @throws ReflectionException |
|
174 | + */ |
|
175 | + protected function _set_notification_triggers() |
|
176 | + { |
|
177 | 177 | |
178 | - if ($this->checkout->payment_method instanceof EE_Payment_Method) { |
|
179 | - // let's start with the assumption that we need to trigger notifications |
|
180 | - // then toggle this to false for conditions where we know we don't need to |
|
181 | - $deliver_notifications = true; |
|
182 | - if ( |
|
178 | + if ($this->checkout->payment_method instanceof EE_Payment_Method) { |
|
179 | + // let's start with the assumption that we need to trigger notifications |
|
180 | + // then toggle this to false for conditions where we know we don't need to |
|
181 | + $deliver_notifications = true; |
|
182 | + if ( |
|
183 | 183 | // if SPCO revisit |
184 | - filter_var($this->checkout->revisit, FILTER_VALIDATE_BOOLEAN) |
|
185 | - // and TXN or REG statuses have NOT changed due to a payment |
|
186 | - && ! ( |
|
187 | - $this->checkout->transaction->txn_status_updated() |
|
188 | - || $this->checkout->any_reg_status_updated() |
|
189 | - ) |
|
190 | - ) { |
|
191 | - $deliver_notifications = false; |
|
192 | - } |
|
193 | - if ($this->checkout->payment_method->is_off_site()) { |
|
194 | - /** @var EE_Gateway $gateway */ |
|
195 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
196 | - // and the gateway uses a separate request to process the IPN |
|
197 | - /** @var RequestInterface $request */ |
|
198 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
199 | - if ( |
|
200 | - $gateway instanceof EE_Offsite_Gateway |
|
201 | - && $gateway->handle_IPN_in_this_request($request->requestParams(), true) |
|
202 | - ) { |
|
203 | - // IPN request will handle triggering notifications |
|
204 | - $deliver_notifications = false; |
|
205 | - // no really... don't send any notices in this request |
|
206 | - remove_all_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications'); |
|
207 | - add_filter( |
|
208 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications', |
|
209 | - '__return_false', |
|
210 | - 15 |
|
211 | - ); |
|
212 | - } |
|
213 | - } |
|
214 | - if ($deliver_notifications) { |
|
215 | - // send out notifications |
|
216 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
217 | - } |
|
218 | - } |
|
219 | - } |
|
184 | + filter_var($this->checkout->revisit, FILTER_VALIDATE_BOOLEAN) |
|
185 | + // and TXN or REG statuses have NOT changed due to a payment |
|
186 | + && ! ( |
|
187 | + $this->checkout->transaction->txn_status_updated() |
|
188 | + || $this->checkout->any_reg_status_updated() |
|
189 | + ) |
|
190 | + ) { |
|
191 | + $deliver_notifications = false; |
|
192 | + } |
|
193 | + if ($this->checkout->payment_method->is_off_site()) { |
|
194 | + /** @var EE_Gateway $gateway */ |
|
195 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
196 | + // and the gateway uses a separate request to process the IPN |
|
197 | + /** @var RequestInterface $request */ |
|
198 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
199 | + if ( |
|
200 | + $gateway instanceof EE_Offsite_Gateway |
|
201 | + && $gateway->handle_IPN_in_this_request($request->requestParams(), true) |
|
202 | + ) { |
|
203 | + // IPN request will handle triggering notifications |
|
204 | + $deliver_notifications = false; |
|
205 | + // no really... don't send any notices in this request |
|
206 | + remove_all_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications'); |
|
207 | + add_filter( |
|
208 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications', |
|
209 | + '__return_false', |
|
210 | + 15 |
|
211 | + ); |
|
212 | + } |
|
213 | + } |
|
214 | + if ($deliver_notifications) { |
|
215 | + // send out notifications |
|
216 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
217 | + } |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | 221 | |
222 | - /** |
|
223 | - * check if transaction has a primary registrant and that it has a related Attendee object |
|
224 | - * |
|
225 | - * @return boolean |
|
226 | - * @throws EE_Error |
|
227 | - * @throws ReflectionException |
|
228 | - */ |
|
229 | - protected function _validate_primary_registrant() |
|
230 | - { |
|
231 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
232 | - EE_Error::add_error( |
|
233 | - esc_html__('A valid Primary Registration for this Transaction could not be found.', 'event_espresso'), |
|
234 | - __FILE__, |
|
235 | - __FUNCTION__, |
|
236 | - __LINE__ |
|
237 | - ); |
|
238 | - $this->checkout->redirect = false; |
|
239 | - $this->checkout->continue_reg = false; |
|
240 | - return false; |
|
241 | - } |
|
242 | - // setup URL for redirect |
|
243 | - $this->checkout->redirect_url = add_query_arg( |
|
244 | - ['e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link()], |
|
245 | - $this->checkout->thank_you_page_url |
|
246 | - ); |
|
247 | - return true; |
|
248 | - } |
|
222 | + /** |
|
223 | + * check if transaction has a primary registrant and that it has a related Attendee object |
|
224 | + * |
|
225 | + * @return boolean |
|
226 | + * @throws EE_Error |
|
227 | + * @throws ReflectionException |
|
228 | + */ |
|
229 | + protected function _validate_primary_registrant() |
|
230 | + { |
|
231 | + if (! $this->checkout->transaction_has_primary_registrant()) { |
|
232 | + EE_Error::add_error( |
|
233 | + esc_html__('A valid Primary Registration for this Transaction could not be found.', 'event_espresso'), |
|
234 | + __FILE__, |
|
235 | + __FUNCTION__, |
|
236 | + __LINE__ |
|
237 | + ); |
|
238 | + $this->checkout->redirect = false; |
|
239 | + $this->checkout->continue_reg = false; |
|
240 | + return false; |
|
241 | + } |
|
242 | + // setup URL for redirect |
|
243 | + $this->checkout->redirect_url = add_query_arg( |
|
244 | + ['e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link()], |
|
245 | + $this->checkout->thank_you_page_url |
|
246 | + ); |
|
247 | + return true; |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - public function update_reg_step() |
|
255 | - { |
|
256 | - EE_Error::doing_it_wrong( |
|
257 | - __CLASS__ . '::' . __FILE__, |
|
258 | - esc_html__( |
|
259 | - 'Can not call update_reg_step() on the Finalize Registration reg step.', |
|
260 | - 'event_espresso' |
|
261 | - ), |
|
262 | - '4.6.0' |
|
263 | - ); |
|
264 | - } |
|
251 | + /** |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + public function update_reg_step() |
|
255 | + { |
|
256 | + EE_Error::doing_it_wrong( |
|
257 | + __CLASS__ . '::' . __FILE__, |
|
258 | + esc_html__( |
|
259 | + 'Can not call update_reg_step() on the Finalize Registration reg step.', |
|
260 | + 'event_espresso' |
|
261 | + ), |
|
262 | + '4.6.0' |
|
263 | + ); |
|
264 | + } |
|
265 | 265 | } |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <p id="spco-auto-copy-attendee-pg" class="smaller-text lt-grey-text"> |
2 | 2 | <?php echo apply_filters( |
3 | - 'FHEE__registration_page_attendee_information__auto_copy_attendee_pg', |
|
4 | - esc_html__( |
|
5 | - 'The above information will be used for any additional tickets/attendees.', |
|
6 | - 'event_espresso' |
|
7 | - ) |
|
8 | - ); ?> |
|
3 | + 'FHEE__registration_page_attendee_information__auto_copy_attendee_pg', |
|
4 | + esc_html__( |
|
5 | + 'The above information will be used for any additional tickets/attendees.', |
|
6 | + 'event_espresso' |
|
7 | + ) |
|
8 | + ); ?> |
|
9 | 9 | </p> |
10 | 10 | \ No newline at end of file |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function reg_status_updated($REG_ID) |
316 | 316 | { |
317 | - return isset($this->reg_status_updated[ $REG_ID ]) ? $this->reg_status_updated[ $REG_ID ] : false; |
|
317 | + return isset($this->reg_status_updated[$REG_ID]) ? $this->reg_status_updated[$REG_ID] : false; |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | */ |
325 | 325 | public function set_reg_status_updated($REG_ID, $reg_status) |
326 | 326 | { |
327 | - $this->reg_status_updated[ $REG_ID ] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN); |
|
327 | + $this->reg_status_updated[$REG_ID] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | */ |
385 | 385 | public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj) |
386 | 386 | { |
387 | - $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj; |
|
387 | + $this->reg_steps[$reg_step_obj->slug()] = $reg_step_obj; |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | */ |
431 | 431 | public function remove_reg_step($reg_step_slug = '', $reset = true) |
432 | 432 | { |
433 | - unset($this->reg_steps[ $reg_step_slug ]); |
|
433 | + unset($this->reg_steps[$reg_step_slug]); |
|
434 | 434 | if ($this->transaction instanceof EE_Transaction) { |
435 | 435 | // now remove reg step from TXN and save |
436 | 436 | $this->transaction->remove_reg_step($reg_step_slug); |
@@ -452,8 +452,8 @@ discard block |
||
452 | 452 | */ |
453 | 453 | public function set_reg_step_order($reg_step_slug = '', $order = 100) |
454 | 454 | { |
455 | - if (isset($this->reg_steps[ $reg_step_slug ])) { |
|
456 | - $this->reg_steps[ $reg_step_slug ]->set_order($order); |
|
455 | + if (isset($this->reg_steps[$reg_step_slug])) { |
|
456 | + $this->reg_steps[$reg_step_slug]->set_order($order); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
@@ -468,8 +468,8 @@ discard block |
||
468 | 468 | public function set_current_step($current_step) |
469 | 469 | { |
470 | 470 | // grab what step we're on |
471 | - $this->current_step = isset($this->reg_steps[ $current_step ]) |
|
472 | - ? $this->reg_steps[ $current_step ] |
|
471 | + $this->current_step = isset($this->reg_steps[$current_step]) |
|
472 | + ? $this->reg_steps[$current_step] |
|
473 | 473 | : reset( |
474 | 474 | $this->reg_steps |
475 | 475 | ); |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | */ |
581 | 581 | public function find_reg_step($reg_step_slug = '') |
582 | 582 | { |
583 | - if (! empty($reg_step_slug)) { |
|
583 | + if ( ! empty($reg_step_slug)) { |
|
584 | 584 | // copy reg step array |
585 | 585 | $reg_steps = $this->reg_steps; |
586 | 586 | // set pointer to start of array |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | ) |
643 | 643 | ) { |
644 | 644 | // set the start time for this reg step |
645 | - if (! $this->transaction->set_reg_step_initiated($reg_step->slug())) { |
|
645 | + if ( ! $this->transaction->set_reg_step_initiated($reg_step->slug())) { |
|
646 | 646 | if (WP_DEBUG) { |
647 | 647 | EE_Error::add_error( |
648 | 648 | sprintf( |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | $session = EE_Registry::instance()->load_core('Session'); |
746 | 746 | $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null; |
747 | 747 | // verify cart |
748 | - if (! $cart instanceof EE_Cart) { |
|
748 | + if ( ! $cart instanceof EE_Cart) { |
|
749 | 749 | $cart = EE_Registry::instance()->load_core('Cart'); |
750 | 750 | } |
751 | 751 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | { |
764 | 764 | $txn_reg_steps_array = array(); |
765 | 765 | foreach ($this->reg_steps as $reg_step) { |
766 | - $txn_reg_steps_array[ $reg_step->slug() ] = false; |
|
766 | + $txn_reg_steps_array[$reg_step->slug()] = false; |
|
767 | 767 | } |
768 | 768 | return $txn_reg_steps_array; |
769 | 769 | } |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | */ |
803 | 803 | public function stash_transaction_and_checkout() |
804 | 804 | { |
805 | - if (! $this->revisit) { |
|
805 | + if ( ! $this->revisit) { |
|
806 | 806 | $this->update_txn_reg_steps_array(); |
807 | 807 | } |
808 | 808 | $this->track_transaction_and_registration_status_updates(); |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | // should this registration be processed during this visit ? |
930 | 930 | if ($this->visit_allows_processing_of_this_registration($registration)) { |
931 | 931 | // set TXN ID |
932 | - if (! $registration->transaction_ID()) { |
|
932 | + if ( ! $registration->transaction_ID()) { |
|
933 | 933 | $registration->set_transaction_id($this->transaction->ID()); |
934 | 934 | } |
935 | 935 | // verify and save the attendee |
@@ -939,7 +939,7 @@ discard block |
||
939 | 939 | // save changes |
940 | 940 | $registration->save(); |
941 | 941 | // update txn cache |
942 | - if (! $this->transaction->update_cache_after_object_save('Registration', $registration)) { |
|
942 | + if ( ! $this->transaction->update_cache_after_object_save('Registration', $registration)) { |
|
943 | 943 | if ($show_errors) { |
944 | 944 | EE_Error::add_error( |
945 | 945 | esc_html__( |
@@ -982,7 +982,7 @@ discard block |
||
982 | 982 | if ($registration->attendee() instanceof EE_Attendee) { |
983 | 983 | // save so that ATT has ID |
984 | 984 | $registration->attendee()->save(); |
985 | - if (! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) { |
|
985 | + if ( ! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) { |
|
986 | 986 | if ($show_errors) { |
987 | 987 | EE_Error::add_error( |
988 | 988 | esc_html__( |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | if ($answer instanceof EE_Answer) { |
1032 | 1032 | $answer->set_registration($registration->ID()); |
1033 | 1033 | $answer->save(); |
1034 | - if (! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) { |
|
1034 | + if ( ! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) { |
|
1035 | 1035 | if ($show_errors) { |
1036 | 1036 | EE_Error::add_error( |
1037 | 1037 | esc_html__( |
@@ -1352,11 +1352,11 @@ discard block |
||
1352 | 1352 | */ |
1353 | 1353 | public function __wakeup() |
1354 | 1354 | { |
1355 | - if (! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) { |
|
1355 | + if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) { |
|
1356 | 1356 | // $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db |
1357 | 1357 | $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj); |
1358 | 1358 | } |
1359 | - if (! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) { |
|
1359 | + if ( ! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) { |
|
1360 | 1360 | // $this->transaction is actually just an ID, so use it to get the object from the db |
1361 | 1361 | $this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction); |
1362 | 1362 | } |
@@ -1380,9 +1380,9 @@ discard block |
||
1380 | 1380 | { |
1381 | 1381 | $disabled = true; |
1382 | 1382 | if (WP_DEBUG && ! $disabled) { |
1383 | - $debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array()); |
|
1383 | + $debug_data = get_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), array()); |
|
1384 | 1384 | $default_data = array( |
1385 | - $class => $func . '() : ' . $line, |
|
1385 | + $class => $func.'() : '.$line, |
|
1386 | 1386 | 'request->step' => $this->step, |
1387 | 1387 | 'request->action' => $this->action, |
1388 | 1388 | 'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
@@ -1397,20 +1397,20 @@ discard block |
||
1397 | 1397 | $default_data['TXN_status'] = $this->transaction->status_ID(); |
1398 | 1398 | $default_data['TXN_reg_steps'] = $this->transaction->reg_steps(); |
1399 | 1399 | foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) { |
1400 | - $default_data['registrations'][ $REG_ID ] = $registration->status_ID(); |
|
1400 | + $default_data['registrations'][$REG_ID] = $registration->status_ID(); |
|
1401 | 1401 | } |
1402 | 1402 | if ($this->transaction->ID()) { |
1403 | - $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID(); |
|
1403 | + $TXN_ID = 'EE_Transaction: '.$this->transaction->ID(); |
|
1404 | 1404 | // don't serialize objects |
1405 | 1405 | $info = $this->_strip_objects($info); |
1406 | - if (! isset($debug_data[ $TXN_ID ])) { |
|
1407 | - $debug_data[ $TXN_ID ] = array(); |
|
1406 | + if ( ! isset($debug_data[$TXN_ID])) { |
|
1407 | + $debug_data[$TXN_ID] = array(); |
|
1408 | 1408 | } |
1409 | - $debug_data[ $TXN_ID ][ microtime() ] = array_merge( |
|
1409 | + $debug_data[$TXN_ID][microtime()] = array_merge( |
|
1410 | 1410 | $default_data, |
1411 | 1411 | $info |
1412 | 1412 | ); |
1413 | - update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data); |
|
1413 | + update_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), $debug_data); |
|
1414 | 1414 | } |
1415 | 1415 | } |
1416 | 1416 | } |
@@ -1427,17 +1427,17 @@ discard block |
||
1427 | 1427 | { |
1428 | 1428 | foreach ((array) $info as $key => $value) { |
1429 | 1429 | if (is_array($value)) { |
1430 | - $info[ $key ] = $this->_strip_objects($value); |
|
1430 | + $info[$key] = $this->_strip_objects($value); |
|
1431 | 1431 | } elseif (is_object($value)) { |
1432 | 1432 | $object_class = get_class($value); |
1433 | - $info[ $object_class ] = array(); |
|
1434 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0; |
|
1433 | + $info[$object_class] = array(); |
|
1434 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0; |
|
1435 | 1435 | if (method_exists($value, 'status')) { |
1436 | - $info[ $object_class ]['status'] = $value->status(); |
|
1436 | + $info[$object_class]['status'] = $value->status(); |
|
1437 | 1437 | } elseif (method_exists($value, 'status_ID')) { |
1438 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
1438 | + $info[$object_class]['status'] = $value->status_ID(); |
|
1439 | 1439 | } |
1440 | - unset($info[ $key ]); |
|
1440 | + unset($info[$key]); |
|
1441 | 1441 | } |
1442 | 1442 | } |
1443 | 1443 | return (array) $info; |
@@ -14,1430 +14,1430 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Checkout |
16 | 16 | { |
17 | - /** |
|
18 | - * whether current request originated from the EE admin |
|
19 | - * |
|
20 | - * @var bool |
|
21 | - */ |
|
22 | - public $admin_request = false; |
|
23 | - |
|
24 | - /** |
|
25 | - * whether returning to edit attendee information or to retry a payment |
|
26 | - * |
|
27 | - * @var bool |
|
28 | - */ |
|
29 | - public $revisit = false; |
|
30 | - |
|
31 | - /** |
|
32 | - * whether the primary registrant is returning to edit attendee information or to retry a payment |
|
33 | - * |
|
34 | - * @var bool |
|
35 | - */ |
|
36 | - public $primary_revisit = false; |
|
37 | - |
|
38 | - /** |
|
39 | - * is registration allowed to progress or halted for some reason such as failing to pass recaptcha? |
|
40 | - * |
|
41 | - * @var bool |
|
42 | - */ |
|
43 | - public $continue_reg = true; |
|
44 | - |
|
45 | - /** |
|
46 | - * redirect to thank you page ? |
|
47 | - * |
|
48 | - * @var bool |
|
49 | - */ |
|
50 | - public $redirect = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * generate the reg form or not ? |
|
54 | - * |
|
55 | - * @var bool |
|
56 | - */ |
|
57 | - public $generate_reg_form = true; |
|
58 | - |
|
59 | - /** |
|
60 | - * process a reg form submission or not ? |
|
61 | - * |
|
62 | - * @var bool |
|
63 | - */ |
|
64 | - public $process_form_submission = false; |
|
65 | - |
|
66 | - /** |
|
67 | - * tracks whether the TXN status modified during this checkout |
|
68 | - * |
|
69 | - * @var bool |
|
70 | - */ |
|
71 | - public $txn_status_updated = false; |
|
72 | - |
|
73 | - /** |
|
74 | - * only triggered to true after absolutely everything has finished. |
|
75 | - * |
|
76 | - * @var bool |
|
77 | - */ |
|
78 | - protected $exit_spco = false; |
|
79 | - |
|
80 | - /** |
|
81 | - * tracks whether any of the TXN's Registrations statuses modified during this checkout |
|
82 | - * indexed by registration ID |
|
83 | - * |
|
84 | - * @var array |
|
85 | - */ |
|
86 | - protected $reg_status_updated = array(); |
|
87 | - |
|
88 | - /** |
|
89 | - * timestamp when redirected from Ticket Selector to the checkout |
|
90 | - * |
|
91 | - * @var int |
|
92 | - */ |
|
93 | - public $uts = 0; |
|
94 | - |
|
95 | - /** |
|
96 | - * total number of tickets that were in the cart |
|
97 | - * |
|
98 | - * @var int |
|
99 | - */ |
|
100 | - public $total_ticket_count = 0; |
|
101 | - |
|
102 | - /** |
|
103 | - * corresponds loosely to EE_Transaction::remaining() |
|
104 | - * but can be modified by SPCO |
|
105 | - * |
|
106 | - * @var float |
|
107 | - */ |
|
108 | - public $amount_owing = 0; |
|
109 | - |
|
110 | - /** |
|
111 | - * the reg step slug from the incoming request |
|
112 | - * |
|
113 | - * @var string |
|
114 | - */ |
|
115 | - public $step = ''; |
|
116 | - |
|
117 | - /** |
|
118 | - * the reg step slug for a step being edited |
|
119 | - * |
|
120 | - * @var string |
|
121 | - */ |
|
122 | - public $edit_step = ''; |
|
123 | - |
|
124 | - /** |
|
125 | - * the action being performed on the current step |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
129 | - public $action = ''; |
|
130 | - |
|
131 | - /** |
|
132 | - * reg_url_link for a previously saved registration |
|
133 | - * |
|
134 | - * @var string |
|
135 | - */ |
|
136 | - public $reg_url_link = ''; |
|
137 | - |
|
138 | - /** |
|
139 | - * string slug for the payment method that was selected during the payment options step |
|
140 | - * |
|
141 | - * @var string |
|
142 | - */ |
|
143 | - public $selected_method_of_payment = ''; |
|
144 | - |
|
145 | - /** |
|
146 | - * base url for the site's registration checkout page - additional url params will be added to this |
|
147 | - * |
|
148 | - * @var string |
|
149 | - */ |
|
150 | - public $reg_page_base_url = ''; |
|
151 | - |
|
152 | - /** |
|
153 | - * base url for the site's registration cancelled page - additional url params will be added to this |
|
154 | - * |
|
155 | - * @var string |
|
156 | - */ |
|
157 | - public $cancel_page_url = ''; |
|
158 | - |
|
159 | - /** |
|
160 | - * base url for the site's thank you page - additional url params will be added to this |
|
161 | - * |
|
162 | - * @var string |
|
163 | - */ |
|
164 | - public $thank_you_page_url = ''; |
|
165 | - |
|
166 | - /** |
|
167 | - * base url for any redirects - additional url params will be added to this |
|
168 | - * |
|
169 | - * @var string |
|
170 | - */ |
|
171 | - public $redirect_url = ''; |
|
172 | - |
|
173 | - /** |
|
174 | - * form of POST data for use with off-site gateways |
|
175 | - * |
|
176 | - * @var string |
|
177 | - */ |
|
178 | - public $redirect_form = ''; |
|
179 | - |
|
180 | - /** |
|
181 | - * array of query where params to use when retrieving cached registrations from $this->checkout->transaction |
|
182 | - * |
|
183 | - * @var array |
|
184 | - */ |
|
185 | - public $reg_cache_where_params = array(); |
|
186 | - |
|
187 | - /** |
|
188 | - * a class for managing and creating the JSON encoded array of data that gets passed back to the client during AJAX |
|
189 | - * requests |
|
190 | - * |
|
191 | - * @var EE_SPCO_JSON_Response |
|
192 | - */ |
|
193 | - public $json_response; |
|
194 | - |
|
195 | - /** |
|
196 | - * where we are going next in the reg process |
|
197 | - * |
|
198 | - * @var EE_SPCO_Reg_Step |
|
199 | - */ |
|
200 | - public $next_step; |
|
201 | - |
|
202 | - /** |
|
203 | - * where we are in the reg process |
|
204 | - * |
|
205 | - * @var EE_SPCO_Reg_Step |
|
206 | - */ |
|
207 | - public $current_step; |
|
208 | - |
|
209 | - /** |
|
210 | - * $_cart - the current cart object |
|
211 | - * |
|
212 | - * @var EE_CART |
|
213 | - */ |
|
214 | - public $cart; |
|
215 | - |
|
216 | - /** |
|
217 | - * $_transaction - the current transaction object |
|
218 | - * |
|
219 | - * @var EE_Transaction |
|
220 | - */ |
|
221 | - public $transaction; |
|
222 | - |
|
223 | - /** |
|
224 | - * the related attendee object for the primary registrant |
|
225 | - * |
|
226 | - * @var EE_Attendee |
|
227 | - */ |
|
228 | - public $primary_attendee_obj; |
|
229 | - |
|
230 | - /** |
|
231 | - * $payment_method - the payment method object for the selected method of payment |
|
232 | - * |
|
233 | - * @var EE_Payment_Method |
|
234 | - */ |
|
235 | - public $payment_method; |
|
236 | - |
|
237 | - /** |
|
238 | - * $payment - if a payment was successfully made during the reg process, |
|
239 | - * then here it is !!! |
|
240 | - * |
|
241 | - * @var EE_Payment |
|
242 | - */ |
|
243 | - public $payment; |
|
244 | - |
|
245 | - /** |
|
246 | - * if a payment method was selected that uses an on-site gateway, then this is the billing form |
|
247 | - * |
|
248 | - * @var EE_Billing_Info_Form|EE_Billing_Attendee_Info_Form |
|
249 | - */ |
|
250 | - public $billing_form; |
|
251 | - |
|
252 | - /** |
|
253 | - * the entire registration form composed of ALL of the subsections generated by the various reg steps |
|
254 | - * |
|
255 | - * @var EE_Form_Section_Proper |
|
256 | - */ |
|
257 | - public $registration_form; |
|
258 | - |
|
259 | - /** |
|
260 | - * array of EE_SPCO_Reg_Step objects |
|
261 | - * |
|
262 | - * @var EE_SPCO_Reg_Step[] |
|
263 | - */ |
|
264 | - public $reg_steps = array(); |
|
265 | - |
|
266 | - /** |
|
267 | - * array of EE_Payment_Method objects |
|
268 | - * |
|
269 | - * @var EE_Payment_Method[] |
|
270 | - */ |
|
271 | - public $available_payment_methods = array(); |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * class constructor |
|
276 | - * |
|
277 | - * @access public |
|
278 | - */ |
|
279 | - public function __construct() |
|
280 | - { |
|
281 | - $this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url(); |
|
282 | - $this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url(); |
|
283 | - $this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url(); |
|
284 | - $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true); |
|
285 | - |
|
286 | - $this->admin_request = is_admin() && ! EED_Single_Page_Checkout::getRequest()->isAjax(); |
|
287 | - $this->reg_cache_where_params = array( |
|
288 | - 0 => array('REG_deleted' => false), |
|
289 | - 'order_by' => array('REG_count' => 'ASC'), |
|
290 | - ); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * returns true if ANY reg status was updated during checkout |
|
296 | - * |
|
297 | - * @return boolean |
|
298 | - */ |
|
299 | - public function any_reg_status_updated() |
|
300 | - { |
|
301 | - foreach ($this->reg_status_updated as $reg_status) { |
|
302 | - if ($reg_status) { |
|
303 | - return true; |
|
304 | - } |
|
305 | - } |
|
306 | - return false; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param $REG_ID |
|
312 | - * @return boolean |
|
313 | - */ |
|
314 | - public function reg_status_updated($REG_ID) |
|
315 | - { |
|
316 | - return isset($this->reg_status_updated[ $REG_ID ]) ? $this->reg_status_updated[ $REG_ID ] : false; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @param $REG_ID |
|
322 | - * @param $reg_status |
|
323 | - */ |
|
324 | - public function set_reg_status_updated($REG_ID, $reg_status) |
|
325 | - { |
|
326 | - $this->reg_status_updated[ $REG_ID ] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * exit_spco |
|
332 | - * |
|
333 | - * @return bool |
|
334 | - */ |
|
335 | - public function exit_spco() |
|
336 | - { |
|
337 | - return $this->exit_spco; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * set_exit_spco |
|
343 | - * can ONLY be set by the Finalize_Registration reg step |
|
344 | - */ |
|
345 | - public function set_exit_spco() |
|
346 | - { |
|
347 | - if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
348 | - $this->exit_spco = true; |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * reset_for_current_request |
|
355 | - * |
|
356 | - * @access public |
|
357 | - * @return void |
|
358 | - */ |
|
359 | - public function reset_for_current_request() |
|
360 | - { |
|
361 | - $this->process_form_submission = false; |
|
362 | - $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true); |
|
363 | - $this->admin_request = is_admin() && ! EED_Single_Page_Checkout::getRequest()->isFrontAjax(); |
|
364 | - $this->continue_reg = true; |
|
365 | - $this->redirect = false; |
|
366 | - // don't reset the cached redirect form if we're about to be asked to display it !!! |
|
367 | - $action = EED_Single_Page_Checkout::getRequest()->getRequestParam('action', 'display_spco_reg_step'); |
|
368 | - if ($action !== 'redirect_form') { |
|
369 | - $this->redirect_form = ''; |
|
370 | - } |
|
371 | - $this->redirect_url = ''; |
|
372 | - $this->json_response = new EE_SPCO_JSON_Response(); |
|
373 | - EE_Form_Section_Proper::reset_js_localization(); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * add_reg_step |
|
379 | - * |
|
380 | - * @access public |
|
381 | - * @param EE_SPCO_Reg_Step $reg_step_obj |
|
382 | - * @return void |
|
383 | - */ |
|
384 | - public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj) |
|
385 | - { |
|
386 | - $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * skip_reg_step |
|
392 | - * if the current reg step does not need to run for some reason, |
|
393 | - * then this will advance SPCO to the next reg step, |
|
394 | - * and mark the skipped step as completed |
|
395 | - * |
|
396 | - * @access public |
|
397 | - * @param string $reg_step_slug |
|
398 | - * @return void |
|
399 | - * @throws \EE_Error |
|
400 | - */ |
|
401 | - public function skip_reg_step($reg_step_slug = '') |
|
402 | - { |
|
403 | - $step_to_skip = $this->find_reg_step($reg_step_slug); |
|
404 | - if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) { |
|
405 | - $step_to_skip->set_is_current_step(false); |
|
406 | - $step_to_skip->set_completed(); |
|
407 | - // advance to the next step |
|
408 | - $this->set_current_step($this->next_step->slug()); |
|
409 | - // also reset the step param in the request in case any other code references that directly |
|
410 | - EED_Single_Page_Checkout::getRequest()->setRequestParam('step', $this->current_step->slug()); |
|
411 | - // since we are skipping a step and setting the current step to be what was previously the next step, |
|
412 | - // we need to check that the next step is now correct, and not still set to the current step. |
|
413 | - if ($this->current_step->slug() === $this->next_step->slug()) { |
|
414 | - // correctly setup the next step |
|
415 | - $this->set_next_step(); |
|
416 | - } |
|
417 | - $this->set_reg_step_initiated($this->current_step); |
|
418 | - } |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * remove_reg_step |
|
424 | - * |
|
425 | - * @access public |
|
426 | - * @param string $reg_step_slug |
|
427 | - * @param bool $reset whether to reset reg steps after removal |
|
428 | - * @throws EE_Error |
|
429 | - */ |
|
430 | - public function remove_reg_step($reg_step_slug = '', $reset = true) |
|
431 | - { |
|
432 | - unset($this->reg_steps[ $reg_step_slug ]); |
|
433 | - if ($this->transaction instanceof EE_Transaction) { |
|
434 | - // now remove reg step from TXN and save |
|
435 | - $this->transaction->remove_reg_step($reg_step_slug); |
|
436 | - $this->transaction->save(); |
|
437 | - } |
|
438 | - if ($reset) { |
|
439 | - $this->reset_reg_steps(); |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * set_reg_step_order |
|
446 | - * |
|
447 | - * @access public |
|
448 | - * @param string $reg_step_slug |
|
449 | - * @param int $order |
|
450 | - * @return void |
|
451 | - */ |
|
452 | - public function set_reg_step_order($reg_step_slug = '', $order = 100) |
|
453 | - { |
|
454 | - if (isset($this->reg_steps[ $reg_step_slug ])) { |
|
455 | - $this->reg_steps[ $reg_step_slug ]->set_order($order); |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * set_current_step |
|
462 | - * |
|
463 | - * @access public |
|
464 | - * @param string $current_step |
|
465 | - * @return void |
|
466 | - */ |
|
467 | - public function set_current_step($current_step) |
|
468 | - { |
|
469 | - // grab what step we're on |
|
470 | - $this->current_step = isset($this->reg_steps[ $current_step ]) |
|
471 | - ? $this->reg_steps[ $current_step ] |
|
472 | - : reset( |
|
473 | - $this->reg_steps |
|
474 | - ); |
|
475 | - // verify instance |
|
476 | - if ($this->current_step instanceof EE_SPCO_Reg_Step) { |
|
477 | - // we don't want to repeat completed steps if this is the first time through SPCO |
|
478 | - if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) { |
|
479 | - // so advance to the next step |
|
480 | - $this->set_next_step(); |
|
481 | - if ($this->next_step instanceof EE_SPCO_Reg_Step) { |
|
482 | - // and attempt to set it as the current step |
|
483 | - $this->set_current_step($this->next_step->slug()); |
|
484 | - } |
|
485 | - return; |
|
486 | - } |
|
487 | - $this->current_step->set_is_current_step(true); |
|
488 | - $this->current_step->setRequest(EED_Single_Page_Checkout::getRequest()); |
|
489 | - } else { |
|
490 | - EE_Error::add_error( |
|
491 | - esc_html__('The current step could not be set.', 'event_espresso'), |
|
492 | - __FILE__, |
|
493 | - __FUNCTION__, |
|
494 | - __LINE__ |
|
495 | - ); |
|
496 | - } |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * set_next_step |
|
502 | - * advances the reg_steps array pointer and sets the next step, then reverses pointer back to the current step |
|
503 | - * |
|
504 | - * @access public |
|
505 | - * @return void |
|
506 | - */ |
|
507 | - public function set_next_step() |
|
508 | - { |
|
509 | - // set pointer to start of array |
|
510 | - reset($this->reg_steps); |
|
511 | - // if there is more than one step |
|
512 | - if (count($this->reg_steps) > 1) { |
|
513 | - // advance to the current step and set pointer |
|
514 | - while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') { |
|
515 | - next($this->reg_steps); |
|
516 | - } |
|
517 | - } |
|
518 | - // advance one more spot ( if it exists ) |
|
519 | - $this->next_step = next($this->reg_steps); |
|
520 | - // verify instance |
|
521 | - $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : null; |
|
522 | - // then back to current step to reset |
|
523 | - prev($this->reg_steps); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * get_next_reg_step |
|
529 | - * this simply returns the next step from reg_steps array |
|
530 | - * |
|
531 | - * @access public |
|
532 | - * @return EE_SPCO_Reg_Step | null |
|
533 | - */ |
|
534 | - public function get_next_reg_step() |
|
535 | - { |
|
536 | - $next = next($this->reg_steps); |
|
537 | - prev($this->reg_steps); |
|
538 | - return $next instanceof EE_SPCO_Reg_Step ? $next : null; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * get_prev_reg_step |
|
544 | - * this simply returns the previous step from reg_steps array |
|
545 | - * |
|
546 | - * @access public |
|
547 | - * @return EE_SPCO_Reg_Step | null |
|
548 | - */ |
|
549 | - public function get_prev_reg_step() |
|
550 | - { |
|
551 | - $prev = prev($this->reg_steps); |
|
552 | - next($this->reg_steps); |
|
553 | - return $prev instanceof EE_SPCO_Reg_Step ? $prev : null; |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * sort_reg_steps |
|
559 | - * |
|
560 | - * @access public |
|
561 | - * @return void |
|
562 | - */ |
|
563 | - public function sort_reg_steps() |
|
564 | - { |
|
565 | - $reg_step_sorting_callback = apply_filters( |
|
566 | - 'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', |
|
567 | - 'reg_step_sorting_callback' |
|
568 | - ); |
|
569 | - uasort($this->reg_steps, array($this, $reg_step_sorting_callback)); |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * find_reg_step |
|
575 | - * finds a reg step by the given slug |
|
576 | - * |
|
577 | - * @access public |
|
578 | - * @param string $reg_step_slug |
|
579 | - * @return EE_SPCO_Reg_Step|null |
|
580 | - */ |
|
581 | - public function find_reg_step($reg_step_slug = '') |
|
582 | - { |
|
583 | - if (! empty($reg_step_slug)) { |
|
584 | - // copy reg step array |
|
585 | - $reg_steps = $this->reg_steps; |
|
586 | - // set pointer to start of array |
|
587 | - reset($reg_steps); |
|
588 | - // if there is more than one step |
|
589 | - if (count($reg_steps) > 1) { |
|
590 | - // advance to the current step and set pointer |
|
591 | - while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') { |
|
592 | - next($reg_steps); |
|
593 | - } |
|
594 | - return current($reg_steps); |
|
595 | - } |
|
596 | - } |
|
597 | - return null; |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * reg_step_sorting_callback |
|
603 | - * |
|
604 | - * @access public |
|
605 | - * @param EE_SPCO_Reg_Step $reg_step_A |
|
606 | - * @param EE_SPCO_Reg_Step $reg_step_B |
|
607 | - * @return int |
|
608 | - */ |
|
609 | - public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B) |
|
610 | - { |
|
611 | - // send finalize_registration step to the end of the array |
|
612 | - if ($reg_step_A->slug() === 'finalize_registration') { |
|
613 | - return 1; |
|
614 | - } elseif ($reg_step_B->slug() === 'finalize_registration') { |
|
615 | - return -1; |
|
616 | - } |
|
617 | - if ($reg_step_A->order() === $reg_step_B->order()) { |
|
618 | - return 0; |
|
619 | - } |
|
620 | - return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1; |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * set_reg_step_initiated |
|
626 | - * |
|
627 | - * @access public |
|
628 | - * @param EE_SPCO_Reg_Step $reg_step |
|
629 | - * @throws \EE_Error |
|
630 | - */ |
|
631 | - public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step) |
|
632 | - { |
|
633 | - // call set_reg_step_initiated ??? |
|
634 | - if ( |
|
17 | + /** |
|
18 | + * whether current request originated from the EE admin |
|
19 | + * |
|
20 | + * @var bool |
|
21 | + */ |
|
22 | + public $admin_request = false; |
|
23 | + |
|
24 | + /** |
|
25 | + * whether returning to edit attendee information or to retry a payment |
|
26 | + * |
|
27 | + * @var bool |
|
28 | + */ |
|
29 | + public $revisit = false; |
|
30 | + |
|
31 | + /** |
|
32 | + * whether the primary registrant is returning to edit attendee information or to retry a payment |
|
33 | + * |
|
34 | + * @var bool |
|
35 | + */ |
|
36 | + public $primary_revisit = false; |
|
37 | + |
|
38 | + /** |
|
39 | + * is registration allowed to progress or halted for some reason such as failing to pass recaptcha? |
|
40 | + * |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | + public $continue_reg = true; |
|
44 | + |
|
45 | + /** |
|
46 | + * redirect to thank you page ? |
|
47 | + * |
|
48 | + * @var bool |
|
49 | + */ |
|
50 | + public $redirect = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * generate the reg form or not ? |
|
54 | + * |
|
55 | + * @var bool |
|
56 | + */ |
|
57 | + public $generate_reg_form = true; |
|
58 | + |
|
59 | + /** |
|
60 | + * process a reg form submission or not ? |
|
61 | + * |
|
62 | + * @var bool |
|
63 | + */ |
|
64 | + public $process_form_submission = false; |
|
65 | + |
|
66 | + /** |
|
67 | + * tracks whether the TXN status modified during this checkout |
|
68 | + * |
|
69 | + * @var bool |
|
70 | + */ |
|
71 | + public $txn_status_updated = false; |
|
72 | + |
|
73 | + /** |
|
74 | + * only triggered to true after absolutely everything has finished. |
|
75 | + * |
|
76 | + * @var bool |
|
77 | + */ |
|
78 | + protected $exit_spco = false; |
|
79 | + |
|
80 | + /** |
|
81 | + * tracks whether any of the TXN's Registrations statuses modified during this checkout |
|
82 | + * indexed by registration ID |
|
83 | + * |
|
84 | + * @var array |
|
85 | + */ |
|
86 | + protected $reg_status_updated = array(); |
|
87 | + |
|
88 | + /** |
|
89 | + * timestamp when redirected from Ticket Selector to the checkout |
|
90 | + * |
|
91 | + * @var int |
|
92 | + */ |
|
93 | + public $uts = 0; |
|
94 | + |
|
95 | + /** |
|
96 | + * total number of tickets that were in the cart |
|
97 | + * |
|
98 | + * @var int |
|
99 | + */ |
|
100 | + public $total_ticket_count = 0; |
|
101 | + |
|
102 | + /** |
|
103 | + * corresponds loosely to EE_Transaction::remaining() |
|
104 | + * but can be modified by SPCO |
|
105 | + * |
|
106 | + * @var float |
|
107 | + */ |
|
108 | + public $amount_owing = 0; |
|
109 | + |
|
110 | + /** |
|
111 | + * the reg step slug from the incoming request |
|
112 | + * |
|
113 | + * @var string |
|
114 | + */ |
|
115 | + public $step = ''; |
|
116 | + |
|
117 | + /** |
|
118 | + * the reg step slug for a step being edited |
|
119 | + * |
|
120 | + * @var string |
|
121 | + */ |
|
122 | + public $edit_step = ''; |
|
123 | + |
|
124 | + /** |
|
125 | + * the action being performed on the current step |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | + public $action = ''; |
|
130 | + |
|
131 | + /** |
|
132 | + * reg_url_link for a previously saved registration |
|
133 | + * |
|
134 | + * @var string |
|
135 | + */ |
|
136 | + public $reg_url_link = ''; |
|
137 | + |
|
138 | + /** |
|
139 | + * string slug for the payment method that was selected during the payment options step |
|
140 | + * |
|
141 | + * @var string |
|
142 | + */ |
|
143 | + public $selected_method_of_payment = ''; |
|
144 | + |
|
145 | + /** |
|
146 | + * base url for the site's registration checkout page - additional url params will be added to this |
|
147 | + * |
|
148 | + * @var string |
|
149 | + */ |
|
150 | + public $reg_page_base_url = ''; |
|
151 | + |
|
152 | + /** |
|
153 | + * base url for the site's registration cancelled page - additional url params will be added to this |
|
154 | + * |
|
155 | + * @var string |
|
156 | + */ |
|
157 | + public $cancel_page_url = ''; |
|
158 | + |
|
159 | + /** |
|
160 | + * base url for the site's thank you page - additional url params will be added to this |
|
161 | + * |
|
162 | + * @var string |
|
163 | + */ |
|
164 | + public $thank_you_page_url = ''; |
|
165 | + |
|
166 | + /** |
|
167 | + * base url for any redirects - additional url params will be added to this |
|
168 | + * |
|
169 | + * @var string |
|
170 | + */ |
|
171 | + public $redirect_url = ''; |
|
172 | + |
|
173 | + /** |
|
174 | + * form of POST data for use with off-site gateways |
|
175 | + * |
|
176 | + * @var string |
|
177 | + */ |
|
178 | + public $redirect_form = ''; |
|
179 | + |
|
180 | + /** |
|
181 | + * array of query where params to use when retrieving cached registrations from $this->checkout->transaction |
|
182 | + * |
|
183 | + * @var array |
|
184 | + */ |
|
185 | + public $reg_cache_where_params = array(); |
|
186 | + |
|
187 | + /** |
|
188 | + * a class for managing and creating the JSON encoded array of data that gets passed back to the client during AJAX |
|
189 | + * requests |
|
190 | + * |
|
191 | + * @var EE_SPCO_JSON_Response |
|
192 | + */ |
|
193 | + public $json_response; |
|
194 | + |
|
195 | + /** |
|
196 | + * where we are going next in the reg process |
|
197 | + * |
|
198 | + * @var EE_SPCO_Reg_Step |
|
199 | + */ |
|
200 | + public $next_step; |
|
201 | + |
|
202 | + /** |
|
203 | + * where we are in the reg process |
|
204 | + * |
|
205 | + * @var EE_SPCO_Reg_Step |
|
206 | + */ |
|
207 | + public $current_step; |
|
208 | + |
|
209 | + /** |
|
210 | + * $_cart - the current cart object |
|
211 | + * |
|
212 | + * @var EE_CART |
|
213 | + */ |
|
214 | + public $cart; |
|
215 | + |
|
216 | + /** |
|
217 | + * $_transaction - the current transaction object |
|
218 | + * |
|
219 | + * @var EE_Transaction |
|
220 | + */ |
|
221 | + public $transaction; |
|
222 | + |
|
223 | + /** |
|
224 | + * the related attendee object for the primary registrant |
|
225 | + * |
|
226 | + * @var EE_Attendee |
|
227 | + */ |
|
228 | + public $primary_attendee_obj; |
|
229 | + |
|
230 | + /** |
|
231 | + * $payment_method - the payment method object for the selected method of payment |
|
232 | + * |
|
233 | + * @var EE_Payment_Method |
|
234 | + */ |
|
235 | + public $payment_method; |
|
236 | + |
|
237 | + /** |
|
238 | + * $payment - if a payment was successfully made during the reg process, |
|
239 | + * then here it is !!! |
|
240 | + * |
|
241 | + * @var EE_Payment |
|
242 | + */ |
|
243 | + public $payment; |
|
244 | + |
|
245 | + /** |
|
246 | + * if a payment method was selected that uses an on-site gateway, then this is the billing form |
|
247 | + * |
|
248 | + * @var EE_Billing_Info_Form|EE_Billing_Attendee_Info_Form |
|
249 | + */ |
|
250 | + public $billing_form; |
|
251 | + |
|
252 | + /** |
|
253 | + * the entire registration form composed of ALL of the subsections generated by the various reg steps |
|
254 | + * |
|
255 | + * @var EE_Form_Section_Proper |
|
256 | + */ |
|
257 | + public $registration_form; |
|
258 | + |
|
259 | + /** |
|
260 | + * array of EE_SPCO_Reg_Step objects |
|
261 | + * |
|
262 | + * @var EE_SPCO_Reg_Step[] |
|
263 | + */ |
|
264 | + public $reg_steps = array(); |
|
265 | + |
|
266 | + /** |
|
267 | + * array of EE_Payment_Method objects |
|
268 | + * |
|
269 | + * @var EE_Payment_Method[] |
|
270 | + */ |
|
271 | + public $available_payment_methods = array(); |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * class constructor |
|
276 | + * |
|
277 | + * @access public |
|
278 | + */ |
|
279 | + public function __construct() |
|
280 | + { |
|
281 | + $this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url(); |
|
282 | + $this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url(); |
|
283 | + $this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url(); |
|
284 | + $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true); |
|
285 | + |
|
286 | + $this->admin_request = is_admin() && ! EED_Single_Page_Checkout::getRequest()->isAjax(); |
|
287 | + $this->reg_cache_where_params = array( |
|
288 | + 0 => array('REG_deleted' => false), |
|
289 | + 'order_by' => array('REG_count' => 'ASC'), |
|
290 | + ); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * returns true if ANY reg status was updated during checkout |
|
296 | + * |
|
297 | + * @return boolean |
|
298 | + */ |
|
299 | + public function any_reg_status_updated() |
|
300 | + { |
|
301 | + foreach ($this->reg_status_updated as $reg_status) { |
|
302 | + if ($reg_status) { |
|
303 | + return true; |
|
304 | + } |
|
305 | + } |
|
306 | + return false; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param $REG_ID |
|
312 | + * @return boolean |
|
313 | + */ |
|
314 | + public function reg_status_updated($REG_ID) |
|
315 | + { |
|
316 | + return isset($this->reg_status_updated[ $REG_ID ]) ? $this->reg_status_updated[ $REG_ID ] : false; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @param $REG_ID |
|
322 | + * @param $reg_status |
|
323 | + */ |
|
324 | + public function set_reg_status_updated($REG_ID, $reg_status) |
|
325 | + { |
|
326 | + $this->reg_status_updated[ $REG_ID ] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * exit_spco |
|
332 | + * |
|
333 | + * @return bool |
|
334 | + */ |
|
335 | + public function exit_spco() |
|
336 | + { |
|
337 | + return $this->exit_spco; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * set_exit_spco |
|
343 | + * can ONLY be set by the Finalize_Registration reg step |
|
344 | + */ |
|
345 | + public function set_exit_spco() |
|
346 | + { |
|
347 | + if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
348 | + $this->exit_spco = true; |
|
349 | + } |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * reset_for_current_request |
|
355 | + * |
|
356 | + * @access public |
|
357 | + * @return void |
|
358 | + */ |
|
359 | + public function reset_for_current_request() |
|
360 | + { |
|
361 | + $this->process_form_submission = false; |
|
362 | + $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true); |
|
363 | + $this->admin_request = is_admin() && ! EED_Single_Page_Checkout::getRequest()->isFrontAjax(); |
|
364 | + $this->continue_reg = true; |
|
365 | + $this->redirect = false; |
|
366 | + // don't reset the cached redirect form if we're about to be asked to display it !!! |
|
367 | + $action = EED_Single_Page_Checkout::getRequest()->getRequestParam('action', 'display_spco_reg_step'); |
|
368 | + if ($action !== 'redirect_form') { |
|
369 | + $this->redirect_form = ''; |
|
370 | + } |
|
371 | + $this->redirect_url = ''; |
|
372 | + $this->json_response = new EE_SPCO_JSON_Response(); |
|
373 | + EE_Form_Section_Proper::reset_js_localization(); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * add_reg_step |
|
379 | + * |
|
380 | + * @access public |
|
381 | + * @param EE_SPCO_Reg_Step $reg_step_obj |
|
382 | + * @return void |
|
383 | + */ |
|
384 | + public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj) |
|
385 | + { |
|
386 | + $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * skip_reg_step |
|
392 | + * if the current reg step does not need to run for some reason, |
|
393 | + * then this will advance SPCO to the next reg step, |
|
394 | + * and mark the skipped step as completed |
|
395 | + * |
|
396 | + * @access public |
|
397 | + * @param string $reg_step_slug |
|
398 | + * @return void |
|
399 | + * @throws \EE_Error |
|
400 | + */ |
|
401 | + public function skip_reg_step($reg_step_slug = '') |
|
402 | + { |
|
403 | + $step_to_skip = $this->find_reg_step($reg_step_slug); |
|
404 | + if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) { |
|
405 | + $step_to_skip->set_is_current_step(false); |
|
406 | + $step_to_skip->set_completed(); |
|
407 | + // advance to the next step |
|
408 | + $this->set_current_step($this->next_step->slug()); |
|
409 | + // also reset the step param in the request in case any other code references that directly |
|
410 | + EED_Single_Page_Checkout::getRequest()->setRequestParam('step', $this->current_step->slug()); |
|
411 | + // since we are skipping a step and setting the current step to be what was previously the next step, |
|
412 | + // we need to check that the next step is now correct, and not still set to the current step. |
|
413 | + if ($this->current_step->slug() === $this->next_step->slug()) { |
|
414 | + // correctly setup the next step |
|
415 | + $this->set_next_step(); |
|
416 | + } |
|
417 | + $this->set_reg_step_initiated($this->current_step); |
|
418 | + } |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * remove_reg_step |
|
424 | + * |
|
425 | + * @access public |
|
426 | + * @param string $reg_step_slug |
|
427 | + * @param bool $reset whether to reset reg steps after removal |
|
428 | + * @throws EE_Error |
|
429 | + */ |
|
430 | + public function remove_reg_step($reg_step_slug = '', $reset = true) |
|
431 | + { |
|
432 | + unset($this->reg_steps[ $reg_step_slug ]); |
|
433 | + if ($this->transaction instanceof EE_Transaction) { |
|
434 | + // now remove reg step from TXN and save |
|
435 | + $this->transaction->remove_reg_step($reg_step_slug); |
|
436 | + $this->transaction->save(); |
|
437 | + } |
|
438 | + if ($reset) { |
|
439 | + $this->reset_reg_steps(); |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * set_reg_step_order |
|
446 | + * |
|
447 | + * @access public |
|
448 | + * @param string $reg_step_slug |
|
449 | + * @param int $order |
|
450 | + * @return void |
|
451 | + */ |
|
452 | + public function set_reg_step_order($reg_step_slug = '', $order = 100) |
|
453 | + { |
|
454 | + if (isset($this->reg_steps[ $reg_step_slug ])) { |
|
455 | + $this->reg_steps[ $reg_step_slug ]->set_order($order); |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * set_current_step |
|
462 | + * |
|
463 | + * @access public |
|
464 | + * @param string $current_step |
|
465 | + * @return void |
|
466 | + */ |
|
467 | + public function set_current_step($current_step) |
|
468 | + { |
|
469 | + // grab what step we're on |
|
470 | + $this->current_step = isset($this->reg_steps[ $current_step ]) |
|
471 | + ? $this->reg_steps[ $current_step ] |
|
472 | + : reset( |
|
473 | + $this->reg_steps |
|
474 | + ); |
|
475 | + // verify instance |
|
476 | + if ($this->current_step instanceof EE_SPCO_Reg_Step) { |
|
477 | + // we don't want to repeat completed steps if this is the first time through SPCO |
|
478 | + if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) { |
|
479 | + // so advance to the next step |
|
480 | + $this->set_next_step(); |
|
481 | + if ($this->next_step instanceof EE_SPCO_Reg_Step) { |
|
482 | + // and attempt to set it as the current step |
|
483 | + $this->set_current_step($this->next_step->slug()); |
|
484 | + } |
|
485 | + return; |
|
486 | + } |
|
487 | + $this->current_step->set_is_current_step(true); |
|
488 | + $this->current_step->setRequest(EED_Single_Page_Checkout::getRequest()); |
|
489 | + } else { |
|
490 | + EE_Error::add_error( |
|
491 | + esc_html__('The current step could not be set.', 'event_espresso'), |
|
492 | + __FILE__, |
|
493 | + __FUNCTION__, |
|
494 | + __LINE__ |
|
495 | + ); |
|
496 | + } |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * set_next_step |
|
502 | + * advances the reg_steps array pointer and sets the next step, then reverses pointer back to the current step |
|
503 | + * |
|
504 | + * @access public |
|
505 | + * @return void |
|
506 | + */ |
|
507 | + public function set_next_step() |
|
508 | + { |
|
509 | + // set pointer to start of array |
|
510 | + reset($this->reg_steps); |
|
511 | + // if there is more than one step |
|
512 | + if (count($this->reg_steps) > 1) { |
|
513 | + // advance to the current step and set pointer |
|
514 | + while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') { |
|
515 | + next($this->reg_steps); |
|
516 | + } |
|
517 | + } |
|
518 | + // advance one more spot ( if it exists ) |
|
519 | + $this->next_step = next($this->reg_steps); |
|
520 | + // verify instance |
|
521 | + $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : null; |
|
522 | + // then back to current step to reset |
|
523 | + prev($this->reg_steps); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * get_next_reg_step |
|
529 | + * this simply returns the next step from reg_steps array |
|
530 | + * |
|
531 | + * @access public |
|
532 | + * @return EE_SPCO_Reg_Step | null |
|
533 | + */ |
|
534 | + public function get_next_reg_step() |
|
535 | + { |
|
536 | + $next = next($this->reg_steps); |
|
537 | + prev($this->reg_steps); |
|
538 | + return $next instanceof EE_SPCO_Reg_Step ? $next : null; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * get_prev_reg_step |
|
544 | + * this simply returns the previous step from reg_steps array |
|
545 | + * |
|
546 | + * @access public |
|
547 | + * @return EE_SPCO_Reg_Step | null |
|
548 | + */ |
|
549 | + public function get_prev_reg_step() |
|
550 | + { |
|
551 | + $prev = prev($this->reg_steps); |
|
552 | + next($this->reg_steps); |
|
553 | + return $prev instanceof EE_SPCO_Reg_Step ? $prev : null; |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * sort_reg_steps |
|
559 | + * |
|
560 | + * @access public |
|
561 | + * @return void |
|
562 | + */ |
|
563 | + public function sort_reg_steps() |
|
564 | + { |
|
565 | + $reg_step_sorting_callback = apply_filters( |
|
566 | + 'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', |
|
567 | + 'reg_step_sorting_callback' |
|
568 | + ); |
|
569 | + uasort($this->reg_steps, array($this, $reg_step_sorting_callback)); |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * find_reg_step |
|
575 | + * finds a reg step by the given slug |
|
576 | + * |
|
577 | + * @access public |
|
578 | + * @param string $reg_step_slug |
|
579 | + * @return EE_SPCO_Reg_Step|null |
|
580 | + */ |
|
581 | + public function find_reg_step($reg_step_slug = '') |
|
582 | + { |
|
583 | + if (! empty($reg_step_slug)) { |
|
584 | + // copy reg step array |
|
585 | + $reg_steps = $this->reg_steps; |
|
586 | + // set pointer to start of array |
|
587 | + reset($reg_steps); |
|
588 | + // if there is more than one step |
|
589 | + if (count($reg_steps) > 1) { |
|
590 | + // advance to the current step and set pointer |
|
591 | + while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') { |
|
592 | + next($reg_steps); |
|
593 | + } |
|
594 | + return current($reg_steps); |
|
595 | + } |
|
596 | + } |
|
597 | + return null; |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * reg_step_sorting_callback |
|
603 | + * |
|
604 | + * @access public |
|
605 | + * @param EE_SPCO_Reg_Step $reg_step_A |
|
606 | + * @param EE_SPCO_Reg_Step $reg_step_B |
|
607 | + * @return int |
|
608 | + */ |
|
609 | + public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B) |
|
610 | + { |
|
611 | + // send finalize_registration step to the end of the array |
|
612 | + if ($reg_step_A->slug() === 'finalize_registration') { |
|
613 | + return 1; |
|
614 | + } elseif ($reg_step_B->slug() === 'finalize_registration') { |
|
615 | + return -1; |
|
616 | + } |
|
617 | + if ($reg_step_A->order() === $reg_step_B->order()) { |
|
618 | + return 0; |
|
619 | + } |
|
620 | + return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1; |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * set_reg_step_initiated |
|
626 | + * |
|
627 | + * @access public |
|
628 | + * @param EE_SPCO_Reg_Step $reg_step |
|
629 | + * @throws \EE_Error |
|
630 | + */ |
|
631 | + public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step) |
|
632 | + { |
|
633 | + // call set_reg_step_initiated ??? |
|
634 | + if ( |
|
635 | 635 | // first time visiting SPCO ? |
636 | - ! $this->revisit |
|
637 | - && ( |
|
638 | - // and displaying the reg step form for the first time ? |
|
639 | - $this->action === 'display_spco_reg_step' |
|
640 | - // or initializing the final step |
|
641 | - || $reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration |
|
642 | - ) |
|
643 | - ) { |
|
644 | - // set the start time for this reg step |
|
645 | - if (! $this->transaction->set_reg_step_initiated($reg_step->slug())) { |
|
646 | - if (WP_DEBUG) { |
|
647 | - EE_Error::add_error( |
|
648 | - sprintf( |
|
649 | - esc_html__('The "%1$s" registration step was not initialized properly.', 'event_espresso'), |
|
650 | - $reg_step->name() |
|
651 | - ), |
|
652 | - __FILE__, |
|
653 | - __FUNCTION__, |
|
654 | - __LINE__ |
|
655 | - ); |
|
656 | - } |
|
657 | - } |
|
658 | - } |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * set_reg_step_JSON_info |
|
664 | - * |
|
665 | - * @access public |
|
666 | - * @return void |
|
667 | - */ |
|
668 | - public function set_reg_step_JSON_info() |
|
669 | - { |
|
670 | - EE_Registry::$i18n_js_strings['reg_steps'] = array(); |
|
671 | - // pass basic reg step data to JS |
|
672 | - foreach ($this->reg_steps as $reg_step) { |
|
673 | - EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug(); |
|
674 | - } |
|
675 | - // reset reg step html |
|
676 | - // $this->json_response->set_reg_step_html(''); |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * reset_reg_steps |
|
682 | - * |
|
683 | - * @access public |
|
684 | - * @return void |
|
685 | - */ |
|
686 | - public function reset_reg_steps() |
|
687 | - { |
|
688 | - $this->sort_reg_steps(); |
|
689 | - $this->set_current_step(EED_Single_Page_Checkout::getRequest()->getRequestParam('step')); |
|
690 | - $this->set_next_step(); |
|
691 | - // the text that appears on the reg step form submit button |
|
692 | - $this->current_step->set_submit_button_text(); |
|
693 | - $this->set_reg_step_JSON_info(); |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * get_registration_time_limit |
|
699 | - * |
|
700 | - * @access public |
|
701 | - * @return string |
|
702 | - */ |
|
703 | - public function get_registration_time_limit() |
|
704 | - { |
|
705 | - $registration_time_limit = (float) (EE_Registry::instance()->SSN->expiration() - time()); |
|
706 | - $time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s'; |
|
707 | - $registration_time_limit = date($time_limit_format, $registration_time_limit); |
|
708 | - return apply_filters( |
|
709 | - 'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit', |
|
710 | - $registration_time_limit |
|
711 | - ); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * payment_required |
|
717 | - * |
|
718 | - * @return boolean |
|
719 | - */ |
|
720 | - public function payment_required() |
|
721 | - { |
|
722 | - // if NOT: |
|
723 | - // registration via admin |
|
724 | - // completed TXN |
|
725 | - // overpaid TXN |
|
726 | - // free TXN(total = 0.00) |
|
727 | - // then payment required is TRUE |
|
728 | - return ! ($this->admin_request |
|
729 | - || $this->transaction->is_completed() |
|
730 | - || $this->transaction->is_overpaid() |
|
731 | - || $this->transaction->is_free()) ? true : false; |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * get_cart_for_transaction |
|
737 | - * |
|
738 | - * @access public |
|
739 | - * @param EE_Transaction $transaction |
|
740 | - * @return EE_Cart |
|
741 | - */ |
|
742 | - public function get_cart_for_transaction($transaction) |
|
743 | - { |
|
744 | - $session = EE_Registry::instance()->load_core('Session'); |
|
745 | - $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null; |
|
746 | - // verify cart |
|
747 | - if (! $cart instanceof EE_Cart) { |
|
748 | - $cart = EE_Registry::instance()->load_core('Cart'); |
|
749 | - } |
|
750 | - |
|
751 | - return $cart; |
|
752 | - } |
|
753 | - |
|
754 | - |
|
755 | - /** |
|
756 | - * initialize_txn_reg_steps_array |
|
757 | - * |
|
758 | - * @access public |
|
759 | - * @return array |
|
760 | - */ |
|
761 | - public function initialize_txn_reg_steps_array() |
|
762 | - { |
|
763 | - $txn_reg_steps_array = array(); |
|
764 | - foreach ($this->reg_steps as $reg_step) { |
|
765 | - $txn_reg_steps_array[ $reg_step->slug() ] = false; |
|
766 | - } |
|
767 | - return $txn_reg_steps_array; |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * update_txn_reg_steps_array |
|
773 | - * |
|
774 | - * @access public |
|
775 | - * @return bool |
|
776 | - * @throws \EE_Error |
|
777 | - */ |
|
778 | - public function update_txn_reg_steps_array() |
|
779 | - { |
|
780 | - $updated = false; |
|
781 | - foreach ($this->reg_steps as $reg_step) { |
|
782 | - if ($reg_step->completed()) { |
|
783 | - $updated = $this->transaction->set_reg_step_completed($reg_step->slug()) |
|
784 | - ? true |
|
785 | - : $updated; |
|
786 | - } |
|
787 | - } |
|
788 | - if ($updated) { |
|
789 | - $this->transaction->save(); |
|
790 | - } |
|
791 | - return $updated; |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * stash_transaction_and_checkout |
|
797 | - * |
|
798 | - * @access public |
|
799 | - * @return void |
|
800 | - * @throws \EE_Error |
|
801 | - */ |
|
802 | - public function stash_transaction_and_checkout() |
|
803 | - { |
|
804 | - if (! $this->revisit) { |
|
805 | - $this->update_txn_reg_steps_array(); |
|
806 | - } |
|
807 | - $this->track_transaction_and_registration_status_updates(); |
|
808 | - // save all data to the db, but suppress errors |
|
809 | - // $this->save_all_data( FALSE ); |
|
810 | - // cache the checkout in the session |
|
811 | - EE_Registry::instance()->SSN->set_checkout($this); |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - /** |
|
816 | - * track_transaction_and_registration_status_updates |
|
817 | - * stores whether any updates were made to the TXN or it's related registrations |
|
818 | - * |
|
819 | - * @access public |
|
820 | - * @return void |
|
821 | - * @throws \EE_Error |
|
822 | - */ |
|
823 | - public function track_transaction_and_registration_status_updates() |
|
824 | - { |
|
825 | - // verify the transaction |
|
826 | - if ($this->transaction instanceof EE_Transaction) { |
|
827 | - // has there been a TXN status change during this checkout? |
|
828 | - $this->txn_status_updated = $this->transaction->txn_status_updated(); |
|
829 | - /** @type EE_Registration_Processor $registration_processor */ |
|
830 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
831 | - // grab the saved registrations from the transaction |
|
832 | - foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
833 | - if ($registration_processor->reg_status_updated($registration->ID())) { |
|
834 | - $this->set_reg_status_updated($registration->ID(), true); |
|
835 | - } |
|
836 | - } |
|
837 | - } |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * visit_allows_processing_of_this_registration |
|
843 | - * determines if the current SPCO visit should allow the passed EE_Registration to be used in processing. |
|
844 | - * one of the following conditions must be met: |
|
845 | - * EITHER: A) first time thru SPCO -> process ALL registrations ( NOT a revisit ) |
|
846 | - * OR : B) primary registrant is editing info -> process ALL registrations ( primary_revisit ) |
|
847 | - * OR : C) another registrant is editing info -> ONLY process their registration ( revisit AND their |
|
848 | - * reg_url_link matches ) |
|
849 | - * |
|
850 | - * @access public |
|
851 | - * @param EE_Registration $registration |
|
852 | - * @return bool |
|
853 | - * @throws \EE_Error |
|
854 | - */ |
|
855 | - public function visit_allows_processing_of_this_registration(EE_Registration $registration) |
|
856 | - { |
|
857 | - return ! $this->revisit |
|
858 | - || $this->primary_revisit |
|
859 | - || ( |
|
860 | - $this->revisit && $this->reg_url_link === $registration->reg_url_link() |
|
861 | - ) |
|
862 | - ? true |
|
863 | - : false; |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * _transaction_has_primary_registration |
|
869 | - * |
|
870 | - * @access private |
|
871 | - * @return bool |
|
872 | - */ |
|
873 | - public function transaction_has_primary_registrant() |
|
874 | - { |
|
875 | - return $this->primary_attendee_obj instanceof EE_Attendee ? true : false; |
|
876 | - } |
|
877 | - |
|
878 | - |
|
879 | - /** |
|
880 | - * save_all_data |
|
881 | - * simply loops through the current transaction and saves all data for each registration |
|
882 | - * |
|
883 | - * @access public |
|
884 | - * @param bool $show_errors |
|
885 | - * @return bool |
|
886 | - * @throws \EE_Error |
|
887 | - */ |
|
888 | - public function save_all_data($show_errors = true) |
|
889 | - { |
|
890 | - // verify the transaction |
|
891 | - if ($this->transaction instanceof EE_Transaction) { |
|
892 | - // save to ensure that TXN has ID |
|
893 | - $this->transaction->save(); |
|
894 | - // grab the saved registrations from the transaction |
|
895 | - foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
896 | - $this->_save_registration($registration, $show_errors); |
|
897 | - } |
|
898 | - } else { |
|
899 | - if ($show_errors) { |
|
900 | - EE_Error::add_error( |
|
901 | - esc_html__( |
|
902 | - 'A valid Transaction was not found when attempting to save your registration information.', |
|
903 | - 'event_espresso' |
|
904 | - ), |
|
905 | - __FILE__, |
|
906 | - __FUNCTION__, |
|
907 | - __LINE__ |
|
908 | - ); |
|
909 | - } |
|
910 | - return false; |
|
911 | - } |
|
912 | - return true; |
|
913 | - } |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * _save_registration_attendee |
|
918 | - * |
|
919 | - * @param EE_Registration $registration |
|
920 | - * @param bool $show_errors |
|
921 | - * @return void |
|
922 | - * @throws \EE_Error |
|
923 | - */ |
|
924 | - private function _save_registration($registration, $show_errors = true) |
|
925 | - { |
|
926 | - // verify object |
|
927 | - if ($registration instanceof EE_Registration) { |
|
928 | - // should this registration be processed during this visit ? |
|
929 | - if ($this->visit_allows_processing_of_this_registration($registration)) { |
|
930 | - // set TXN ID |
|
931 | - if (! $registration->transaction_ID()) { |
|
932 | - $registration->set_transaction_id($this->transaction->ID()); |
|
933 | - } |
|
934 | - // verify and save the attendee |
|
935 | - $this->_save_registration_attendee($registration, $show_errors); |
|
936 | - // save answers to reg form questions |
|
937 | - $this->_save_registration_answers($registration, $show_errors); |
|
938 | - // save changes |
|
939 | - $registration->save(); |
|
940 | - // update txn cache |
|
941 | - if (! $this->transaction->update_cache_after_object_save('Registration', $registration)) { |
|
942 | - if ($show_errors) { |
|
943 | - EE_Error::add_error( |
|
944 | - esc_html__( |
|
945 | - 'The newly saved Registration object could not be cached on the Transaction.', |
|
946 | - 'event_espresso' |
|
947 | - ), |
|
948 | - __FILE__, |
|
949 | - __FUNCTION__, |
|
950 | - __LINE__ |
|
951 | - ); |
|
952 | - } |
|
953 | - } |
|
954 | - } |
|
955 | - } else { |
|
956 | - if ($show_errors) { |
|
957 | - EE_Error::add_error( |
|
958 | - esc_html__( |
|
959 | - 'An invalid Registration object was discovered when attempting to save your registration information.', |
|
960 | - 'event_espresso' |
|
961 | - ), |
|
962 | - __FILE__, |
|
963 | - __FUNCTION__, |
|
964 | - __LINE__ |
|
965 | - ); |
|
966 | - } |
|
967 | - } |
|
968 | - } |
|
969 | - |
|
970 | - |
|
971 | - /** |
|
972 | - * _save_registration_attendee |
|
973 | - * |
|
974 | - * @param EE_Registration $registration |
|
975 | - * @param bool $show_errors |
|
976 | - * @return void |
|
977 | - * @throws \EE_Error |
|
978 | - */ |
|
979 | - private function _save_registration_attendee($registration, $show_errors = true) |
|
980 | - { |
|
981 | - if ($registration->attendee() instanceof EE_Attendee) { |
|
982 | - // save so that ATT has ID |
|
983 | - $registration->attendee()->save(); |
|
984 | - if (! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) { |
|
985 | - if ($show_errors) { |
|
986 | - EE_Error::add_error( |
|
987 | - esc_html__( |
|
988 | - 'The newly saved Attendee object could not be cached on the registration.', |
|
989 | - 'event_espresso' |
|
990 | - ), |
|
991 | - __FILE__, |
|
992 | - __FUNCTION__, |
|
993 | - __LINE__ |
|
994 | - ); |
|
995 | - } |
|
996 | - } |
|
997 | - } else { |
|
998 | - if ($show_errors) { |
|
999 | - EE_Error::add_error( |
|
1000 | - sprintf( |
|
1001 | - '%1$s||%1$s $attendee = %2$s', |
|
1002 | - esc_html__( |
|
1003 | - 'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', |
|
1004 | - 'event_espresso' |
|
1005 | - ), |
|
1006 | - var_export($registration->attendee(), true) |
|
1007 | - ), |
|
1008 | - __FILE__, |
|
1009 | - __FUNCTION__, |
|
1010 | - __LINE__ |
|
1011 | - ); |
|
1012 | - } |
|
1013 | - } |
|
1014 | - } |
|
1015 | - |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * _save_question_answers |
|
1019 | - * |
|
1020 | - * @param EE_Registration $registration |
|
1021 | - * @param bool $show_errors |
|
1022 | - * @return void |
|
1023 | - * @throws \EE_Error |
|
1024 | - */ |
|
1025 | - private function _save_registration_answers($registration, $show_errors = true) |
|
1026 | - { |
|
1027 | - // now save the answers |
|
1028 | - foreach ($registration->answers() as $cache_key => $answer) { |
|
1029 | - // verify object |
|
1030 | - if ($answer instanceof EE_Answer) { |
|
1031 | - $answer->set_registration($registration->ID()); |
|
1032 | - $answer->save(); |
|
1033 | - if (! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) { |
|
1034 | - if ($show_errors) { |
|
1035 | - EE_Error::add_error( |
|
1036 | - esc_html__( |
|
1037 | - 'The newly saved Answer object could not be cached on the registration.', |
|
1038 | - 'event_espresso' |
|
1039 | - ), |
|
1040 | - __FILE__, |
|
1041 | - __FUNCTION__, |
|
1042 | - __LINE__ |
|
1043 | - ); |
|
1044 | - } |
|
1045 | - } |
|
1046 | - } else { |
|
1047 | - if ($show_errors) { |
|
1048 | - EE_Error::add_error( |
|
1049 | - esc_html__( |
|
1050 | - 'An invalid Answer object was discovered when attempting to save your registration information.', |
|
1051 | - 'event_espresso' |
|
1052 | - ), |
|
1053 | - __FILE__, |
|
1054 | - __FUNCTION__, |
|
1055 | - __LINE__ |
|
1056 | - ); |
|
1057 | - } |
|
1058 | - } |
|
1059 | - } |
|
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * refresh_all_entities |
|
1065 | - * will either refresh the entity map with objects form the db or from the checkout cache |
|
1066 | - * |
|
1067 | - * @access public |
|
1068 | - * @param bool $from_db |
|
1069 | - * @return bool |
|
1070 | - * @throws \EE_Error |
|
1071 | - */ |
|
1072 | - public function refresh_all_entities($from_db = false) |
|
1073 | - { |
|
1074 | - $this->current_step->setRequest(EED_Single_Page_Checkout::getRequest()); |
|
1075 | - $from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response' |
|
1076 | - ? true |
|
1077 | - : $from_db; |
|
1078 | - // $this->log( |
|
1079 | - // __CLASS__, |
|
1080 | - // __FUNCTION__, |
|
1081 | - // __LINE__, |
|
1082 | - // array('from_db' => $from_db) |
|
1083 | - // ); |
|
1084 | - return $from_db ? $this->refresh_from_db() : $this->refresh_entity_map(); |
|
1085 | - } |
|
1086 | - |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * refresh_entity_map |
|
1090 | - * simply loops through the current transaction and updates each |
|
1091 | - * model's entity map using EEM_Base::refresh_entity_map_from_db() |
|
1092 | - * |
|
1093 | - * @access public |
|
1094 | - * @return bool |
|
1095 | - * @throws \EE_Error |
|
1096 | - */ |
|
1097 | - protected function refresh_from_db() |
|
1098 | - { |
|
1099 | - // verify the transaction |
|
1100 | - if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1101 | - // pull fresh TXN data from the db |
|
1102 | - $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID()); |
|
1103 | - // update EE_Checkout's cached primary_attendee object |
|
1104 | - $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction); |
|
1105 | - // update EE_Checkout's cached payment object |
|
1106 | - $payment = $this->transaction->last_payment(); |
|
1107 | - $this->payment = $payment instanceof EE_Payment ? $payment : $this->payment; |
|
1108 | - // update EE_Checkout's cached payment_method object |
|
1109 | - $payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null; |
|
1110 | - $this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method |
|
1111 | - : $this->payment_method; |
|
1112 | - // now refresh the cart, based on the TXN |
|
1113 | - $this->cart = $this->get_cart_for_transaction($this->transaction); |
|
1114 | - } else { |
|
1115 | - EE_Error::add_error( |
|
1116 | - esc_html__( |
|
1117 | - 'A valid Transaction was not found when attempting to update the model entity mapper.', |
|
1118 | - 'event_espresso' |
|
1119 | - ), |
|
1120 | - __FILE__, |
|
1121 | - __FUNCTION__, |
|
1122 | - __LINE__ |
|
1123 | - ); |
|
1124 | - return false; |
|
1125 | - } |
|
1126 | - return true; |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - /** |
|
1131 | - * _refresh_primary_attendee_obj_from_db |
|
1132 | - * |
|
1133 | - * @param EE_Transaction $transaction |
|
1134 | - * @return EE_Attendee | null |
|
1135 | - * @throws \EE_Error |
|
1136 | - */ |
|
1137 | - protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction) |
|
1138 | - { |
|
1139 | - $primary_attendee_obj = null; |
|
1140 | - // grab the saved registrations from the transaction |
|
1141 | - foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) { |
|
1142 | - // verify object |
|
1143 | - if ($registration instanceof EE_Registration) { |
|
1144 | - $attendee = $registration->attendee(); |
|
1145 | - // verify object && maybe cache primary_attendee_obj ? |
|
1146 | - if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) { |
|
1147 | - $primary_attendee_obj = $attendee; |
|
1148 | - } |
|
1149 | - } else { |
|
1150 | - EE_Error::add_error( |
|
1151 | - esc_html__( |
|
1152 | - 'An invalid Registration object was discovered when attempting to update the model entity mapper.', |
|
1153 | - 'event_espresso' |
|
1154 | - ), |
|
1155 | - __FILE__, |
|
1156 | - __FUNCTION__, |
|
1157 | - __LINE__ |
|
1158 | - ); |
|
1159 | - } |
|
1160 | - } |
|
1161 | - return $primary_attendee_obj; |
|
1162 | - } |
|
1163 | - |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * refresh_entity_map |
|
1167 | - * simply loops through the current transaction and updates |
|
1168 | - * each model's entity map using EEM_Base::refresh_entity_map_with() |
|
1169 | - * |
|
1170 | - * @access public |
|
1171 | - * @return bool |
|
1172 | - * @throws \EE_Error |
|
1173 | - */ |
|
1174 | - protected function refresh_entity_map() |
|
1175 | - { |
|
1176 | - // verify the transaction |
|
1177 | - if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1178 | - // never cache payment info |
|
1179 | - $this->transaction->clear_cache('Payment'); |
|
1180 | - // is the Payment Options Reg Step completed ? |
|
1181 | - if ($this->transaction->reg_step_completed('payment_options')) { |
|
1182 | - // then check for payments and update TXN accordingly |
|
1183 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
1184 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1185 | - $transaction_payments->calculate_total_payments_and_update_status($this->transaction); |
|
1186 | - } |
|
1187 | - // grab the saved registrations from the transaction |
|
1188 | - foreach ($this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration) { |
|
1189 | - $this->_refresh_registration($reg_cache_ID, $registration); |
|
1190 | - } |
|
1191 | - // make sure our cached TXN is added to the model entity mapper |
|
1192 | - $this->transaction = $this->transaction->get_model()->refresh_entity_map_with( |
|
1193 | - $this->transaction->ID(), |
|
1194 | - $this->transaction |
|
1195 | - ); |
|
1196 | - } else { |
|
1197 | - EE_Error::add_error( |
|
1198 | - esc_html__( |
|
1199 | - 'A valid Transaction was not found when attempting to update the model entity mapper.', |
|
1200 | - 'event_espresso' |
|
1201 | - ), |
|
1202 | - __FILE__, |
|
1203 | - __FUNCTION__, |
|
1204 | - __LINE__ |
|
1205 | - ); |
|
1206 | - return false; |
|
1207 | - } |
|
1208 | - // verify and update the cart because inaccurate totals are not so much fun |
|
1209 | - if ($this->cart instanceof EE_Cart) { |
|
1210 | - $grand_total = $this->cart->get_grand_total(); |
|
1211 | - if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) { |
|
1212 | - $grand_total->recalculate_total_including_taxes(); |
|
1213 | - $grand_total = $grand_total->get_model()->refresh_entity_map_with( |
|
1214 | - $this->cart->get_grand_total()->ID(), |
|
1215 | - $this->cart->get_grand_total() |
|
1216 | - ); |
|
1217 | - } |
|
1218 | - if ($grand_total instanceof EE_Line_Item) { |
|
1219 | - $this->cart = EE_Cart::instance($grand_total); |
|
1220 | - } else { |
|
1221 | - EE_Error::add_error( |
|
1222 | - esc_html__( |
|
1223 | - 'A valid Cart was not found when attempting to update the model entity mapper.', |
|
1224 | - 'event_espresso' |
|
1225 | - ), |
|
1226 | - __FILE__, |
|
1227 | - __FUNCTION__, |
|
1228 | - __LINE__ |
|
1229 | - ); |
|
1230 | - return false; |
|
1231 | - } |
|
1232 | - } |
|
1233 | - return true; |
|
1234 | - } |
|
1235 | - |
|
1236 | - |
|
1237 | - /** |
|
1238 | - * _refresh_registration |
|
1239 | - * |
|
1240 | - * @param string | int $reg_cache_ID |
|
1241 | - * @param EE_Registration $registration |
|
1242 | - * @return void |
|
1243 | - * @throws \EE_Error |
|
1244 | - */ |
|
1245 | - protected function _refresh_registration($reg_cache_ID, $registration) |
|
1246 | - { |
|
1247 | - |
|
1248 | - // verify object |
|
1249 | - if ($registration instanceof EE_Registration) { |
|
1250 | - // update the entity mapper attendee |
|
1251 | - $this->_refresh_registration_attendee($registration); |
|
1252 | - // update the entity mapper answers for reg form questions |
|
1253 | - $this->_refresh_registration_answers($registration); |
|
1254 | - // make sure the cached registration is added to the model entity mapper |
|
1255 | - $registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration); |
|
1256 | - } else { |
|
1257 | - EE_Error::add_error( |
|
1258 | - esc_html__( |
|
1259 | - 'An invalid Registration object was discovered when attempting to update the model entity mapper.', |
|
1260 | - 'event_espresso' |
|
1261 | - ), |
|
1262 | - __FILE__, |
|
1263 | - __FUNCTION__, |
|
1264 | - __LINE__ |
|
1265 | - ); |
|
1266 | - } |
|
1267 | - } |
|
1268 | - |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * _save_registration_attendee |
|
1272 | - * |
|
1273 | - * @param EE_Registration $registration |
|
1274 | - * @return void |
|
1275 | - * @throws \EE_Error |
|
1276 | - */ |
|
1277 | - protected function _refresh_registration_attendee($registration) |
|
1278 | - { |
|
1279 | - $attendee = $registration->attendee(); |
|
1280 | - // verify object |
|
1281 | - if ($attendee instanceof EE_Attendee && $attendee->ID()) { |
|
1282 | - // make sure the cached attendee is added to the model entity mapper |
|
1283 | - $registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee); |
|
1284 | - // maybe cache primary_attendee_obj ? |
|
1285 | - if ($registration->is_primary_registrant()) { |
|
1286 | - $this->primary_attendee_obj = $attendee; |
|
1287 | - } |
|
1288 | - } |
|
1289 | - } |
|
1290 | - |
|
1291 | - |
|
1292 | - /** |
|
1293 | - * _refresh_registration_answers |
|
1294 | - * |
|
1295 | - * @param EE_Registration $registration |
|
1296 | - * @return void |
|
1297 | - * @throws \EE_Error |
|
1298 | - */ |
|
1299 | - protected function _refresh_registration_answers($registration) |
|
1300 | - { |
|
1301 | - |
|
1302 | - // now update the answers |
|
1303 | - foreach ($registration->answers() as $cache_key => $answer) { |
|
1304 | - // verify object |
|
1305 | - if ($answer instanceof EE_Answer) { |
|
1306 | - if ($answer->ID()) { |
|
1307 | - // make sure the cached answer is added to the model entity mapper |
|
1308 | - $answer->get_model()->refresh_entity_map_with($answer->ID(), $answer); |
|
1309 | - } |
|
1310 | - } else { |
|
1311 | - EE_Error::add_error( |
|
1312 | - esc_html__( |
|
1313 | - 'An invalid Answer object was discovered when attempting to update the model entity mapper.', |
|
1314 | - 'event_espresso' |
|
1315 | - ), |
|
1316 | - __FILE__, |
|
1317 | - __FUNCTION__, |
|
1318 | - __LINE__ |
|
1319 | - ); |
|
1320 | - } |
|
1321 | - } |
|
1322 | - } |
|
1323 | - |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * __sleep |
|
1327 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
1328 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
1329 | - * reg form, because if needed, it will be regenerated anyways |
|
1330 | - * |
|
1331 | - * @return array |
|
1332 | - * @throws \EE_Error |
|
1333 | - */ |
|
1334 | - public function __sleep() |
|
1335 | - { |
|
1336 | - if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) { |
|
1337 | - $this->primary_attendee_obj = $this->primary_attendee_obj->ID(); |
|
1338 | - } // remove the reg form and the checkout |
|
1339 | - if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1340 | - $this->transaction = $this->transaction->ID(); |
|
1341 | - } // remove the reg form and the checkout |
|
1342 | - return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form')); |
|
1343 | - } |
|
1344 | - |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * __wakeup |
|
1348 | - * to conserve db space, we are removing the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization |
|
1349 | - * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object |
|
1350 | - */ |
|
1351 | - public function __wakeup() |
|
1352 | - { |
|
1353 | - if (! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) { |
|
1354 | - // $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db |
|
1355 | - $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj); |
|
1356 | - } |
|
1357 | - if (! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) { |
|
1358 | - // $this->transaction is actually just an ID, so use it to get the object from the db |
|
1359 | - $this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction); |
|
1360 | - } |
|
1361 | - foreach ($this->reg_steps as $reg_step) { |
|
1362 | - $reg_step->checkout = $this; |
|
1363 | - } |
|
1364 | - } |
|
1365 | - |
|
1366 | - |
|
1367 | - /** |
|
1368 | - * debug |
|
1369 | - * |
|
1370 | - * @param string $class |
|
1371 | - * @param string $func |
|
1372 | - * @param string $line |
|
1373 | - * @param array $info |
|
1374 | - * @param bool $display_request |
|
1375 | - * @throws \EE_Error |
|
1376 | - */ |
|
1377 | - public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false) |
|
1378 | - { |
|
1379 | - $disabled = true; |
|
1380 | - if (WP_DEBUG && ! $disabled) { |
|
1381 | - $debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array()); |
|
1382 | - $default_data = array( |
|
1383 | - $class => $func . '() : ' . $line, |
|
1384 | - 'request->step' => $this->step, |
|
1385 | - 'request->action' => $this->action, |
|
1386 | - 'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
|
1387 | - $this->current_step->slug() : '', |
|
1388 | - 'current_step->completed' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
|
1389 | - $this->current_step->completed() : '', |
|
1390 | - 'txn_status_updated' => $this->transaction->txn_status_updated(), |
|
1391 | - 'reg_status_updated' => $this->reg_status_updated, |
|
1392 | - 'reg_url_link' => $this->reg_url_link, |
|
1393 | - ); |
|
1394 | - if ($this->transaction instanceof EE_Transaction) { |
|
1395 | - $default_data['TXN_status'] = $this->transaction->status_ID(); |
|
1396 | - $default_data['TXN_reg_steps'] = $this->transaction->reg_steps(); |
|
1397 | - foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) { |
|
1398 | - $default_data['registrations'][ $REG_ID ] = $registration->status_ID(); |
|
1399 | - } |
|
1400 | - if ($this->transaction->ID()) { |
|
1401 | - $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID(); |
|
1402 | - // don't serialize objects |
|
1403 | - $info = $this->_strip_objects($info); |
|
1404 | - if (! isset($debug_data[ $TXN_ID ])) { |
|
1405 | - $debug_data[ $TXN_ID ] = array(); |
|
1406 | - } |
|
1407 | - $debug_data[ $TXN_ID ][ microtime() ] = array_merge( |
|
1408 | - $default_data, |
|
1409 | - $info |
|
1410 | - ); |
|
1411 | - update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data); |
|
1412 | - } |
|
1413 | - } |
|
1414 | - } |
|
1415 | - } |
|
1416 | - |
|
1417 | - |
|
1418 | - /** |
|
1419 | - * _strip_objects |
|
1420 | - * |
|
1421 | - * @param array $info |
|
1422 | - * @return array |
|
1423 | - */ |
|
1424 | - public function _strip_objects($info = array()) |
|
1425 | - { |
|
1426 | - foreach ((array) $info as $key => $value) { |
|
1427 | - if (is_array($value)) { |
|
1428 | - $info[ $key ] = $this->_strip_objects($value); |
|
1429 | - } elseif (is_object($value)) { |
|
1430 | - $object_class = get_class($value); |
|
1431 | - $info[ $object_class ] = array(); |
|
1432 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0; |
|
1433 | - if (method_exists($value, 'status')) { |
|
1434 | - $info[ $object_class ]['status'] = $value->status(); |
|
1435 | - } elseif (method_exists($value, 'status_ID')) { |
|
1436 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
1437 | - } |
|
1438 | - unset($info[ $key ]); |
|
1439 | - } |
|
1440 | - } |
|
1441 | - return (array) $info; |
|
1442 | - } |
|
636 | + ! $this->revisit |
|
637 | + && ( |
|
638 | + // and displaying the reg step form for the first time ? |
|
639 | + $this->action === 'display_spco_reg_step' |
|
640 | + // or initializing the final step |
|
641 | + || $reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration |
|
642 | + ) |
|
643 | + ) { |
|
644 | + // set the start time for this reg step |
|
645 | + if (! $this->transaction->set_reg_step_initiated($reg_step->slug())) { |
|
646 | + if (WP_DEBUG) { |
|
647 | + EE_Error::add_error( |
|
648 | + sprintf( |
|
649 | + esc_html__('The "%1$s" registration step was not initialized properly.', 'event_espresso'), |
|
650 | + $reg_step->name() |
|
651 | + ), |
|
652 | + __FILE__, |
|
653 | + __FUNCTION__, |
|
654 | + __LINE__ |
|
655 | + ); |
|
656 | + } |
|
657 | + } |
|
658 | + } |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * set_reg_step_JSON_info |
|
664 | + * |
|
665 | + * @access public |
|
666 | + * @return void |
|
667 | + */ |
|
668 | + public function set_reg_step_JSON_info() |
|
669 | + { |
|
670 | + EE_Registry::$i18n_js_strings['reg_steps'] = array(); |
|
671 | + // pass basic reg step data to JS |
|
672 | + foreach ($this->reg_steps as $reg_step) { |
|
673 | + EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug(); |
|
674 | + } |
|
675 | + // reset reg step html |
|
676 | + // $this->json_response->set_reg_step_html(''); |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * reset_reg_steps |
|
682 | + * |
|
683 | + * @access public |
|
684 | + * @return void |
|
685 | + */ |
|
686 | + public function reset_reg_steps() |
|
687 | + { |
|
688 | + $this->sort_reg_steps(); |
|
689 | + $this->set_current_step(EED_Single_Page_Checkout::getRequest()->getRequestParam('step')); |
|
690 | + $this->set_next_step(); |
|
691 | + // the text that appears on the reg step form submit button |
|
692 | + $this->current_step->set_submit_button_text(); |
|
693 | + $this->set_reg_step_JSON_info(); |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * get_registration_time_limit |
|
699 | + * |
|
700 | + * @access public |
|
701 | + * @return string |
|
702 | + */ |
|
703 | + public function get_registration_time_limit() |
|
704 | + { |
|
705 | + $registration_time_limit = (float) (EE_Registry::instance()->SSN->expiration() - time()); |
|
706 | + $time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s'; |
|
707 | + $registration_time_limit = date($time_limit_format, $registration_time_limit); |
|
708 | + return apply_filters( |
|
709 | + 'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit', |
|
710 | + $registration_time_limit |
|
711 | + ); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * payment_required |
|
717 | + * |
|
718 | + * @return boolean |
|
719 | + */ |
|
720 | + public function payment_required() |
|
721 | + { |
|
722 | + // if NOT: |
|
723 | + // registration via admin |
|
724 | + // completed TXN |
|
725 | + // overpaid TXN |
|
726 | + // free TXN(total = 0.00) |
|
727 | + // then payment required is TRUE |
|
728 | + return ! ($this->admin_request |
|
729 | + || $this->transaction->is_completed() |
|
730 | + || $this->transaction->is_overpaid() |
|
731 | + || $this->transaction->is_free()) ? true : false; |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * get_cart_for_transaction |
|
737 | + * |
|
738 | + * @access public |
|
739 | + * @param EE_Transaction $transaction |
|
740 | + * @return EE_Cart |
|
741 | + */ |
|
742 | + public function get_cart_for_transaction($transaction) |
|
743 | + { |
|
744 | + $session = EE_Registry::instance()->load_core('Session'); |
|
745 | + $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null; |
|
746 | + // verify cart |
|
747 | + if (! $cart instanceof EE_Cart) { |
|
748 | + $cart = EE_Registry::instance()->load_core('Cart'); |
|
749 | + } |
|
750 | + |
|
751 | + return $cart; |
|
752 | + } |
|
753 | + |
|
754 | + |
|
755 | + /** |
|
756 | + * initialize_txn_reg_steps_array |
|
757 | + * |
|
758 | + * @access public |
|
759 | + * @return array |
|
760 | + */ |
|
761 | + public function initialize_txn_reg_steps_array() |
|
762 | + { |
|
763 | + $txn_reg_steps_array = array(); |
|
764 | + foreach ($this->reg_steps as $reg_step) { |
|
765 | + $txn_reg_steps_array[ $reg_step->slug() ] = false; |
|
766 | + } |
|
767 | + return $txn_reg_steps_array; |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * update_txn_reg_steps_array |
|
773 | + * |
|
774 | + * @access public |
|
775 | + * @return bool |
|
776 | + * @throws \EE_Error |
|
777 | + */ |
|
778 | + public function update_txn_reg_steps_array() |
|
779 | + { |
|
780 | + $updated = false; |
|
781 | + foreach ($this->reg_steps as $reg_step) { |
|
782 | + if ($reg_step->completed()) { |
|
783 | + $updated = $this->transaction->set_reg_step_completed($reg_step->slug()) |
|
784 | + ? true |
|
785 | + : $updated; |
|
786 | + } |
|
787 | + } |
|
788 | + if ($updated) { |
|
789 | + $this->transaction->save(); |
|
790 | + } |
|
791 | + return $updated; |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * stash_transaction_and_checkout |
|
797 | + * |
|
798 | + * @access public |
|
799 | + * @return void |
|
800 | + * @throws \EE_Error |
|
801 | + */ |
|
802 | + public function stash_transaction_and_checkout() |
|
803 | + { |
|
804 | + if (! $this->revisit) { |
|
805 | + $this->update_txn_reg_steps_array(); |
|
806 | + } |
|
807 | + $this->track_transaction_and_registration_status_updates(); |
|
808 | + // save all data to the db, but suppress errors |
|
809 | + // $this->save_all_data( FALSE ); |
|
810 | + // cache the checkout in the session |
|
811 | + EE_Registry::instance()->SSN->set_checkout($this); |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + /** |
|
816 | + * track_transaction_and_registration_status_updates |
|
817 | + * stores whether any updates were made to the TXN or it's related registrations |
|
818 | + * |
|
819 | + * @access public |
|
820 | + * @return void |
|
821 | + * @throws \EE_Error |
|
822 | + */ |
|
823 | + public function track_transaction_and_registration_status_updates() |
|
824 | + { |
|
825 | + // verify the transaction |
|
826 | + if ($this->transaction instanceof EE_Transaction) { |
|
827 | + // has there been a TXN status change during this checkout? |
|
828 | + $this->txn_status_updated = $this->transaction->txn_status_updated(); |
|
829 | + /** @type EE_Registration_Processor $registration_processor */ |
|
830 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
831 | + // grab the saved registrations from the transaction |
|
832 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
833 | + if ($registration_processor->reg_status_updated($registration->ID())) { |
|
834 | + $this->set_reg_status_updated($registration->ID(), true); |
|
835 | + } |
|
836 | + } |
|
837 | + } |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * visit_allows_processing_of_this_registration |
|
843 | + * determines if the current SPCO visit should allow the passed EE_Registration to be used in processing. |
|
844 | + * one of the following conditions must be met: |
|
845 | + * EITHER: A) first time thru SPCO -> process ALL registrations ( NOT a revisit ) |
|
846 | + * OR : B) primary registrant is editing info -> process ALL registrations ( primary_revisit ) |
|
847 | + * OR : C) another registrant is editing info -> ONLY process their registration ( revisit AND their |
|
848 | + * reg_url_link matches ) |
|
849 | + * |
|
850 | + * @access public |
|
851 | + * @param EE_Registration $registration |
|
852 | + * @return bool |
|
853 | + * @throws \EE_Error |
|
854 | + */ |
|
855 | + public function visit_allows_processing_of_this_registration(EE_Registration $registration) |
|
856 | + { |
|
857 | + return ! $this->revisit |
|
858 | + || $this->primary_revisit |
|
859 | + || ( |
|
860 | + $this->revisit && $this->reg_url_link === $registration->reg_url_link() |
|
861 | + ) |
|
862 | + ? true |
|
863 | + : false; |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * _transaction_has_primary_registration |
|
869 | + * |
|
870 | + * @access private |
|
871 | + * @return bool |
|
872 | + */ |
|
873 | + public function transaction_has_primary_registrant() |
|
874 | + { |
|
875 | + return $this->primary_attendee_obj instanceof EE_Attendee ? true : false; |
|
876 | + } |
|
877 | + |
|
878 | + |
|
879 | + /** |
|
880 | + * save_all_data |
|
881 | + * simply loops through the current transaction and saves all data for each registration |
|
882 | + * |
|
883 | + * @access public |
|
884 | + * @param bool $show_errors |
|
885 | + * @return bool |
|
886 | + * @throws \EE_Error |
|
887 | + */ |
|
888 | + public function save_all_data($show_errors = true) |
|
889 | + { |
|
890 | + // verify the transaction |
|
891 | + if ($this->transaction instanceof EE_Transaction) { |
|
892 | + // save to ensure that TXN has ID |
|
893 | + $this->transaction->save(); |
|
894 | + // grab the saved registrations from the transaction |
|
895 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
896 | + $this->_save_registration($registration, $show_errors); |
|
897 | + } |
|
898 | + } else { |
|
899 | + if ($show_errors) { |
|
900 | + EE_Error::add_error( |
|
901 | + esc_html__( |
|
902 | + 'A valid Transaction was not found when attempting to save your registration information.', |
|
903 | + 'event_espresso' |
|
904 | + ), |
|
905 | + __FILE__, |
|
906 | + __FUNCTION__, |
|
907 | + __LINE__ |
|
908 | + ); |
|
909 | + } |
|
910 | + return false; |
|
911 | + } |
|
912 | + return true; |
|
913 | + } |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * _save_registration_attendee |
|
918 | + * |
|
919 | + * @param EE_Registration $registration |
|
920 | + * @param bool $show_errors |
|
921 | + * @return void |
|
922 | + * @throws \EE_Error |
|
923 | + */ |
|
924 | + private function _save_registration($registration, $show_errors = true) |
|
925 | + { |
|
926 | + // verify object |
|
927 | + if ($registration instanceof EE_Registration) { |
|
928 | + // should this registration be processed during this visit ? |
|
929 | + if ($this->visit_allows_processing_of_this_registration($registration)) { |
|
930 | + // set TXN ID |
|
931 | + if (! $registration->transaction_ID()) { |
|
932 | + $registration->set_transaction_id($this->transaction->ID()); |
|
933 | + } |
|
934 | + // verify and save the attendee |
|
935 | + $this->_save_registration_attendee($registration, $show_errors); |
|
936 | + // save answers to reg form questions |
|
937 | + $this->_save_registration_answers($registration, $show_errors); |
|
938 | + // save changes |
|
939 | + $registration->save(); |
|
940 | + // update txn cache |
|
941 | + if (! $this->transaction->update_cache_after_object_save('Registration', $registration)) { |
|
942 | + if ($show_errors) { |
|
943 | + EE_Error::add_error( |
|
944 | + esc_html__( |
|
945 | + 'The newly saved Registration object could not be cached on the Transaction.', |
|
946 | + 'event_espresso' |
|
947 | + ), |
|
948 | + __FILE__, |
|
949 | + __FUNCTION__, |
|
950 | + __LINE__ |
|
951 | + ); |
|
952 | + } |
|
953 | + } |
|
954 | + } |
|
955 | + } else { |
|
956 | + if ($show_errors) { |
|
957 | + EE_Error::add_error( |
|
958 | + esc_html__( |
|
959 | + 'An invalid Registration object was discovered when attempting to save your registration information.', |
|
960 | + 'event_espresso' |
|
961 | + ), |
|
962 | + __FILE__, |
|
963 | + __FUNCTION__, |
|
964 | + __LINE__ |
|
965 | + ); |
|
966 | + } |
|
967 | + } |
|
968 | + } |
|
969 | + |
|
970 | + |
|
971 | + /** |
|
972 | + * _save_registration_attendee |
|
973 | + * |
|
974 | + * @param EE_Registration $registration |
|
975 | + * @param bool $show_errors |
|
976 | + * @return void |
|
977 | + * @throws \EE_Error |
|
978 | + */ |
|
979 | + private function _save_registration_attendee($registration, $show_errors = true) |
|
980 | + { |
|
981 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
982 | + // save so that ATT has ID |
|
983 | + $registration->attendee()->save(); |
|
984 | + if (! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) { |
|
985 | + if ($show_errors) { |
|
986 | + EE_Error::add_error( |
|
987 | + esc_html__( |
|
988 | + 'The newly saved Attendee object could not be cached on the registration.', |
|
989 | + 'event_espresso' |
|
990 | + ), |
|
991 | + __FILE__, |
|
992 | + __FUNCTION__, |
|
993 | + __LINE__ |
|
994 | + ); |
|
995 | + } |
|
996 | + } |
|
997 | + } else { |
|
998 | + if ($show_errors) { |
|
999 | + EE_Error::add_error( |
|
1000 | + sprintf( |
|
1001 | + '%1$s||%1$s $attendee = %2$s', |
|
1002 | + esc_html__( |
|
1003 | + 'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', |
|
1004 | + 'event_espresso' |
|
1005 | + ), |
|
1006 | + var_export($registration->attendee(), true) |
|
1007 | + ), |
|
1008 | + __FILE__, |
|
1009 | + __FUNCTION__, |
|
1010 | + __LINE__ |
|
1011 | + ); |
|
1012 | + } |
|
1013 | + } |
|
1014 | + } |
|
1015 | + |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * _save_question_answers |
|
1019 | + * |
|
1020 | + * @param EE_Registration $registration |
|
1021 | + * @param bool $show_errors |
|
1022 | + * @return void |
|
1023 | + * @throws \EE_Error |
|
1024 | + */ |
|
1025 | + private function _save_registration_answers($registration, $show_errors = true) |
|
1026 | + { |
|
1027 | + // now save the answers |
|
1028 | + foreach ($registration->answers() as $cache_key => $answer) { |
|
1029 | + // verify object |
|
1030 | + if ($answer instanceof EE_Answer) { |
|
1031 | + $answer->set_registration($registration->ID()); |
|
1032 | + $answer->save(); |
|
1033 | + if (! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) { |
|
1034 | + if ($show_errors) { |
|
1035 | + EE_Error::add_error( |
|
1036 | + esc_html__( |
|
1037 | + 'The newly saved Answer object could not be cached on the registration.', |
|
1038 | + 'event_espresso' |
|
1039 | + ), |
|
1040 | + __FILE__, |
|
1041 | + __FUNCTION__, |
|
1042 | + __LINE__ |
|
1043 | + ); |
|
1044 | + } |
|
1045 | + } |
|
1046 | + } else { |
|
1047 | + if ($show_errors) { |
|
1048 | + EE_Error::add_error( |
|
1049 | + esc_html__( |
|
1050 | + 'An invalid Answer object was discovered when attempting to save your registration information.', |
|
1051 | + 'event_espresso' |
|
1052 | + ), |
|
1053 | + __FILE__, |
|
1054 | + __FUNCTION__, |
|
1055 | + __LINE__ |
|
1056 | + ); |
|
1057 | + } |
|
1058 | + } |
|
1059 | + } |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * refresh_all_entities |
|
1065 | + * will either refresh the entity map with objects form the db or from the checkout cache |
|
1066 | + * |
|
1067 | + * @access public |
|
1068 | + * @param bool $from_db |
|
1069 | + * @return bool |
|
1070 | + * @throws \EE_Error |
|
1071 | + */ |
|
1072 | + public function refresh_all_entities($from_db = false) |
|
1073 | + { |
|
1074 | + $this->current_step->setRequest(EED_Single_Page_Checkout::getRequest()); |
|
1075 | + $from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response' |
|
1076 | + ? true |
|
1077 | + : $from_db; |
|
1078 | + // $this->log( |
|
1079 | + // __CLASS__, |
|
1080 | + // __FUNCTION__, |
|
1081 | + // __LINE__, |
|
1082 | + // array('from_db' => $from_db) |
|
1083 | + // ); |
|
1084 | + return $from_db ? $this->refresh_from_db() : $this->refresh_entity_map(); |
|
1085 | + } |
|
1086 | + |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * refresh_entity_map |
|
1090 | + * simply loops through the current transaction and updates each |
|
1091 | + * model's entity map using EEM_Base::refresh_entity_map_from_db() |
|
1092 | + * |
|
1093 | + * @access public |
|
1094 | + * @return bool |
|
1095 | + * @throws \EE_Error |
|
1096 | + */ |
|
1097 | + protected function refresh_from_db() |
|
1098 | + { |
|
1099 | + // verify the transaction |
|
1100 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1101 | + // pull fresh TXN data from the db |
|
1102 | + $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID()); |
|
1103 | + // update EE_Checkout's cached primary_attendee object |
|
1104 | + $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction); |
|
1105 | + // update EE_Checkout's cached payment object |
|
1106 | + $payment = $this->transaction->last_payment(); |
|
1107 | + $this->payment = $payment instanceof EE_Payment ? $payment : $this->payment; |
|
1108 | + // update EE_Checkout's cached payment_method object |
|
1109 | + $payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null; |
|
1110 | + $this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method |
|
1111 | + : $this->payment_method; |
|
1112 | + // now refresh the cart, based on the TXN |
|
1113 | + $this->cart = $this->get_cart_for_transaction($this->transaction); |
|
1114 | + } else { |
|
1115 | + EE_Error::add_error( |
|
1116 | + esc_html__( |
|
1117 | + 'A valid Transaction was not found when attempting to update the model entity mapper.', |
|
1118 | + 'event_espresso' |
|
1119 | + ), |
|
1120 | + __FILE__, |
|
1121 | + __FUNCTION__, |
|
1122 | + __LINE__ |
|
1123 | + ); |
|
1124 | + return false; |
|
1125 | + } |
|
1126 | + return true; |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + /** |
|
1131 | + * _refresh_primary_attendee_obj_from_db |
|
1132 | + * |
|
1133 | + * @param EE_Transaction $transaction |
|
1134 | + * @return EE_Attendee | null |
|
1135 | + * @throws \EE_Error |
|
1136 | + */ |
|
1137 | + protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction) |
|
1138 | + { |
|
1139 | + $primary_attendee_obj = null; |
|
1140 | + // grab the saved registrations from the transaction |
|
1141 | + foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) { |
|
1142 | + // verify object |
|
1143 | + if ($registration instanceof EE_Registration) { |
|
1144 | + $attendee = $registration->attendee(); |
|
1145 | + // verify object && maybe cache primary_attendee_obj ? |
|
1146 | + if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) { |
|
1147 | + $primary_attendee_obj = $attendee; |
|
1148 | + } |
|
1149 | + } else { |
|
1150 | + EE_Error::add_error( |
|
1151 | + esc_html__( |
|
1152 | + 'An invalid Registration object was discovered when attempting to update the model entity mapper.', |
|
1153 | + 'event_espresso' |
|
1154 | + ), |
|
1155 | + __FILE__, |
|
1156 | + __FUNCTION__, |
|
1157 | + __LINE__ |
|
1158 | + ); |
|
1159 | + } |
|
1160 | + } |
|
1161 | + return $primary_attendee_obj; |
|
1162 | + } |
|
1163 | + |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * refresh_entity_map |
|
1167 | + * simply loops through the current transaction and updates |
|
1168 | + * each model's entity map using EEM_Base::refresh_entity_map_with() |
|
1169 | + * |
|
1170 | + * @access public |
|
1171 | + * @return bool |
|
1172 | + * @throws \EE_Error |
|
1173 | + */ |
|
1174 | + protected function refresh_entity_map() |
|
1175 | + { |
|
1176 | + // verify the transaction |
|
1177 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1178 | + // never cache payment info |
|
1179 | + $this->transaction->clear_cache('Payment'); |
|
1180 | + // is the Payment Options Reg Step completed ? |
|
1181 | + if ($this->transaction->reg_step_completed('payment_options')) { |
|
1182 | + // then check for payments and update TXN accordingly |
|
1183 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
1184 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1185 | + $transaction_payments->calculate_total_payments_and_update_status($this->transaction); |
|
1186 | + } |
|
1187 | + // grab the saved registrations from the transaction |
|
1188 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration) { |
|
1189 | + $this->_refresh_registration($reg_cache_ID, $registration); |
|
1190 | + } |
|
1191 | + // make sure our cached TXN is added to the model entity mapper |
|
1192 | + $this->transaction = $this->transaction->get_model()->refresh_entity_map_with( |
|
1193 | + $this->transaction->ID(), |
|
1194 | + $this->transaction |
|
1195 | + ); |
|
1196 | + } else { |
|
1197 | + EE_Error::add_error( |
|
1198 | + esc_html__( |
|
1199 | + 'A valid Transaction was not found when attempting to update the model entity mapper.', |
|
1200 | + 'event_espresso' |
|
1201 | + ), |
|
1202 | + __FILE__, |
|
1203 | + __FUNCTION__, |
|
1204 | + __LINE__ |
|
1205 | + ); |
|
1206 | + return false; |
|
1207 | + } |
|
1208 | + // verify and update the cart because inaccurate totals are not so much fun |
|
1209 | + if ($this->cart instanceof EE_Cart) { |
|
1210 | + $grand_total = $this->cart->get_grand_total(); |
|
1211 | + if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) { |
|
1212 | + $grand_total->recalculate_total_including_taxes(); |
|
1213 | + $grand_total = $grand_total->get_model()->refresh_entity_map_with( |
|
1214 | + $this->cart->get_grand_total()->ID(), |
|
1215 | + $this->cart->get_grand_total() |
|
1216 | + ); |
|
1217 | + } |
|
1218 | + if ($grand_total instanceof EE_Line_Item) { |
|
1219 | + $this->cart = EE_Cart::instance($grand_total); |
|
1220 | + } else { |
|
1221 | + EE_Error::add_error( |
|
1222 | + esc_html__( |
|
1223 | + 'A valid Cart was not found when attempting to update the model entity mapper.', |
|
1224 | + 'event_espresso' |
|
1225 | + ), |
|
1226 | + __FILE__, |
|
1227 | + __FUNCTION__, |
|
1228 | + __LINE__ |
|
1229 | + ); |
|
1230 | + return false; |
|
1231 | + } |
|
1232 | + } |
|
1233 | + return true; |
|
1234 | + } |
|
1235 | + |
|
1236 | + |
|
1237 | + /** |
|
1238 | + * _refresh_registration |
|
1239 | + * |
|
1240 | + * @param string | int $reg_cache_ID |
|
1241 | + * @param EE_Registration $registration |
|
1242 | + * @return void |
|
1243 | + * @throws \EE_Error |
|
1244 | + */ |
|
1245 | + protected function _refresh_registration($reg_cache_ID, $registration) |
|
1246 | + { |
|
1247 | + |
|
1248 | + // verify object |
|
1249 | + if ($registration instanceof EE_Registration) { |
|
1250 | + // update the entity mapper attendee |
|
1251 | + $this->_refresh_registration_attendee($registration); |
|
1252 | + // update the entity mapper answers for reg form questions |
|
1253 | + $this->_refresh_registration_answers($registration); |
|
1254 | + // make sure the cached registration is added to the model entity mapper |
|
1255 | + $registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration); |
|
1256 | + } else { |
|
1257 | + EE_Error::add_error( |
|
1258 | + esc_html__( |
|
1259 | + 'An invalid Registration object was discovered when attempting to update the model entity mapper.', |
|
1260 | + 'event_espresso' |
|
1261 | + ), |
|
1262 | + __FILE__, |
|
1263 | + __FUNCTION__, |
|
1264 | + __LINE__ |
|
1265 | + ); |
|
1266 | + } |
|
1267 | + } |
|
1268 | + |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * _save_registration_attendee |
|
1272 | + * |
|
1273 | + * @param EE_Registration $registration |
|
1274 | + * @return void |
|
1275 | + * @throws \EE_Error |
|
1276 | + */ |
|
1277 | + protected function _refresh_registration_attendee($registration) |
|
1278 | + { |
|
1279 | + $attendee = $registration->attendee(); |
|
1280 | + // verify object |
|
1281 | + if ($attendee instanceof EE_Attendee && $attendee->ID()) { |
|
1282 | + // make sure the cached attendee is added to the model entity mapper |
|
1283 | + $registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee); |
|
1284 | + // maybe cache primary_attendee_obj ? |
|
1285 | + if ($registration->is_primary_registrant()) { |
|
1286 | + $this->primary_attendee_obj = $attendee; |
|
1287 | + } |
|
1288 | + } |
|
1289 | + } |
|
1290 | + |
|
1291 | + |
|
1292 | + /** |
|
1293 | + * _refresh_registration_answers |
|
1294 | + * |
|
1295 | + * @param EE_Registration $registration |
|
1296 | + * @return void |
|
1297 | + * @throws \EE_Error |
|
1298 | + */ |
|
1299 | + protected function _refresh_registration_answers($registration) |
|
1300 | + { |
|
1301 | + |
|
1302 | + // now update the answers |
|
1303 | + foreach ($registration->answers() as $cache_key => $answer) { |
|
1304 | + // verify object |
|
1305 | + if ($answer instanceof EE_Answer) { |
|
1306 | + if ($answer->ID()) { |
|
1307 | + // make sure the cached answer is added to the model entity mapper |
|
1308 | + $answer->get_model()->refresh_entity_map_with($answer->ID(), $answer); |
|
1309 | + } |
|
1310 | + } else { |
|
1311 | + EE_Error::add_error( |
|
1312 | + esc_html__( |
|
1313 | + 'An invalid Answer object was discovered when attempting to update the model entity mapper.', |
|
1314 | + 'event_espresso' |
|
1315 | + ), |
|
1316 | + __FILE__, |
|
1317 | + __FUNCTION__, |
|
1318 | + __LINE__ |
|
1319 | + ); |
|
1320 | + } |
|
1321 | + } |
|
1322 | + } |
|
1323 | + |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * __sleep |
|
1327 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
1328 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
1329 | + * reg form, because if needed, it will be regenerated anyways |
|
1330 | + * |
|
1331 | + * @return array |
|
1332 | + * @throws \EE_Error |
|
1333 | + */ |
|
1334 | + public function __sleep() |
|
1335 | + { |
|
1336 | + if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) { |
|
1337 | + $this->primary_attendee_obj = $this->primary_attendee_obj->ID(); |
|
1338 | + } // remove the reg form and the checkout |
|
1339 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1340 | + $this->transaction = $this->transaction->ID(); |
|
1341 | + } // remove the reg form and the checkout |
|
1342 | + return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form')); |
|
1343 | + } |
|
1344 | + |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * __wakeup |
|
1348 | + * to conserve db space, we are removing the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization |
|
1349 | + * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object |
|
1350 | + */ |
|
1351 | + public function __wakeup() |
|
1352 | + { |
|
1353 | + if (! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) { |
|
1354 | + // $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db |
|
1355 | + $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj); |
|
1356 | + } |
|
1357 | + if (! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) { |
|
1358 | + // $this->transaction is actually just an ID, so use it to get the object from the db |
|
1359 | + $this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction); |
|
1360 | + } |
|
1361 | + foreach ($this->reg_steps as $reg_step) { |
|
1362 | + $reg_step->checkout = $this; |
|
1363 | + } |
|
1364 | + } |
|
1365 | + |
|
1366 | + |
|
1367 | + /** |
|
1368 | + * debug |
|
1369 | + * |
|
1370 | + * @param string $class |
|
1371 | + * @param string $func |
|
1372 | + * @param string $line |
|
1373 | + * @param array $info |
|
1374 | + * @param bool $display_request |
|
1375 | + * @throws \EE_Error |
|
1376 | + */ |
|
1377 | + public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false) |
|
1378 | + { |
|
1379 | + $disabled = true; |
|
1380 | + if (WP_DEBUG && ! $disabled) { |
|
1381 | + $debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array()); |
|
1382 | + $default_data = array( |
|
1383 | + $class => $func . '() : ' . $line, |
|
1384 | + 'request->step' => $this->step, |
|
1385 | + 'request->action' => $this->action, |
|
1386 | + 'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
|
1387 | + $this->current_step->slug() : '', |
|
1388 | + 'current_step->completed' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
|
1389 | + $this->current_step->completed() : '', |
|
1390 | + 'txn_status_updated' => $this->transaction->txn_status_updated(), |
|
1391 | + 'reg_status_updated' => $this->reg_status_updated, |
|
1392 | + 'reg_url_link' => $this->reg_url_link, |
|
1393 | + ); |
|
1394 | + if ($this->transaction instanceof EE_Transaction) { |
|
1395 | + $default_data['TXN_status'] = $this->transaction->status_ID(); |
|
1396 | + $default_data['TXN_reg_steps'] = $this->transaction->reg_steps(); |
|
1397 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) { |
|
1398 | + $default_data['registrations'][ $REG_ID ] = $registration->status_ID(); |
|
1399 | + } |
|
1400 | + if ($this->transaction->ID()) { |
|
1401 | + $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID(); |
|
1402 | + // don't serialize objects |
|
1403 | + $info = $this->_strip_objects($info); |
|
1404 | + if (! isset($debug_data[ $TXN_ID ])) { |
|
1405 | + $debug_data[ $TXN_ID ] = array(); |
|
1406 | + } |
|
1407 | + $debug_data[ $TXN_ID ][ microtime() ] = array_merge( |
|
1408 | + $default_data, |
|
1409 | + $info |
|
1410 | + ); |
|
1411 | + update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data); |
|
1412 | + } |
|
1413 | + } |
|
1414 | + } |
|
1415 | + } |
|
1416 | + |
|
1417 | + |
|
1418 | + /** |
|
1419 | + * _strip_objects |
|
1420 | + * |
|
1421 | + * @param array $info |
|
1422 | + * @return array |
|
1423 | + */ |
|
1424 | + public function _strip_objects($info = array()) |
|
1425 | + { |
|
1426 | + foreach ((array) $info as $key => $value) { |
|
1427 | + if (is_array($value)) { |
|
1428 | + $info[ $key ] = $this->_strip_objects($value); |
|
1429 | + } elseif (is_object($value)) { |
|
1430 | + $object_class = get_class($value); |
|
1431 | + $info[ $object_class ] = array(); |
|
1432 | + $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0; |
|
1433 | + if (method_exists($value, 'status')) { |
|
1434 | + $info[ $object_class ]['status'] = $value->status(); |
|
1435 | + } elseif (method_exists($value, 'status_ID')) { |
|
1436 | + $info[ $object_class ]['status'] = $value->status_ID(); |
|
1437 | + } |
|
1438 | + unset($info[ $key ]); |
|
1439 | + } |
|
1440 | + } |
|
1441 | + return (array) $info; |
|
1442 | + } |
|
1443 | 1443 | } |
@@ -20,198 +20,198 @@ |
||
20 | 20 | */ |
21 | 21 | class EE_Registration_Custom_Questions_Form extends EE_Form_Section_Proper |
22 | 22 | { |
23 | - /** |
|
24 | - * |
|
25 | - * @var EE_Registration |
|
26 | - */ |
|
27 | - protected $_registration = null; |
|
23 | + /** |
|
24 | + * |
|
25 | + * @var EE_Registration |
|
26 | + */ |
|
27 | + protected $_registration = null; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * |
|
32 | - * @param EE_Registration $reg |
|
33 | - * @param array $options |
|
34 | - * @throws EE_Error |
|
35 | - * @throws ReflectionException |
|
36 | - */ |
|
37 | - public function __construct(EE_Registration $reg, $options = array()) |
|
38 | - { |
|
39 | - $this->_registration = $reg; |
|
40 | - if (! isset($options['layout_strategy'])) { |
|
41 | - $options['layout_strategy'] = new EE_Admin_Two_Column_Layout(); |
|
42 | - } |
|
43 | - if (! isset($options['html_id'])) { |
|
44 | - $options['html_id'] = 'reg-admin-attendee-questions-frm'; |
|
45 | - } |
|
46 | - $this->build_form_from_registration(); |
|
47 | - parent::__construct($options); |
|
48 | - } |
|
30 | + /** |
|
31 | + * |
|
32 | + * @param EE_Registration $reg |
|
33 | + * @param array $options |
|
34 | + * @throws EE_Error |
|
35 | + * @throws ReflectionException |
|
36 | + */ |
|
37 | + public function __construct(EE_Registration $reg, $options = array()) |
|
38 | + { |
|
39 | + $this->_registration = $reg; |
|
40 | + if (! isset($options['layout_strategy'])) { |
|
41 | + $options['layout_strategy'] = new EE_Admin_Two_Column_Layout(); |
|
42 | + } |
|
43 | + if (! isset($options['html_id'])) { |
|
44 | + $options['html_id'] = 'reg-admin-attendee-questions-frm'; |
|
45 | + } |
|
46 | + $this->build_form_from_registration(); |
|
47 | + parent::__construct($options); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * Gets the registration object this form is about |
|
53 | - * @return EE_Registration |
|
54 | - */ |
|
55 | - public function get_registration() |
|
56 | - { |
|
57 | - return $this->_registration; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Gets the registration object this form is about |
|
53 | + * @return EE_Registration |
|
54 | + */ |
|
55 | + public function get_registration() |
|
56 | + { |
|
57 | + return $this->_registration; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @since 4.10.0.p |
|
62 | - * @throws EE_Error |
|
63 | - * @throws InvalidArgumentException |
|
64 | - * @throws ReflectionException |
|
65 | - * @throws InvalidDataTypeException |
|
66 | - * @throws InvalidInterfaceException |
|
67 | - */ |
|
68 | - public function build_form_from_registration() |
|
69 | - { |
|
70 | - $reg = $this->get_registration(); |
|
71 | - if (! $reg instanceof EE_Registration) { |
|
72 | - throw new EE_Error(esc_html__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso')); |
|
73 | - } |
|
74 | - // we want to get all their question groups |
|
75 | - $question_groups = EEM_Question_Group::instance()->get_all( |
|
76 | - [ |
|
77 | - [ |
|
78 | - 'Event_Question_Group.EVT_ID' => $reg->event_ID(), |
|
79 | - 'OR' => [ |
|
80 | - 'Question.QST_system*blank' => '', |
|
81 | - 'Question.QST_system*null' => ['IS_NULL'] |
|
82 | - ], |
|
83 | - 'Event_Question_Group.' |
|
84 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
85 | - $reg->is_primary_registrant() |
|
86 | - ) => true |
|
87 | - ], |
|
88 | - 'order_by' => ['QSG_order' => 'ASC'] |
|
89 | - ] |
|
90 | - ); |
|
91 | - // get each question groups questions |
|
92 | - foreach ($question_groups as $question_group) { |
|
93 | - if ($question_group instanceof EE_Question_Group) { |
|
94 | - $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group( |
|
95 | - $question_group, |
|
96 | - $reg |
|
97 | - ); |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
60 | + /** |
|
61 | + * @since 4.10.0.p |
|
62 | + * @throws EE_Error |
|
63 | + * @throws InvalidArgumentException |
|
64 | + * @throws ReflectionException |
|
65 | + * @throws InvalidDataTypeException |
|
66 | + * @throws InvalidInterfaceException |
|
67 | + */ |
|
68 | + public function build_form_from_registration() |
|
69 | + { |
|
70 | + $reg = $this->get_registration(); |
|
71 | + if (! $reg instanceof EE_Registration) { |
|
72 | + throw new EE_Error(esc_html__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso')); |
|
73 | + } |
|
74 | + // we want to get all their question groups |
|
75 | + $question_groups = EEM_Question_Group::instance()->get_all( |
|
76 | + [ |
|
77 | + [ |
|
78 | + 'Event_Question_Group.EVT_ID' => $reg->event_ID(), |
|
79 | + 'OR' => [ |
|
80 | + 'Question.QST_system*blank' => '', |
|
81 | + 'Question.QST_system*null' => ['IS_NULL'] |
|
82 | + ], |
|
83 | + 'Event_Question_Group.' |
|
84 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
85 | + $reg->is_primary_registrant() |
|
86 | + ) => true |
|
87 | + ], |
|
88 | + 'order_by' => ['QSG_order' => 'ASC'] |
|
89 | + ] |
|
90 | + ); |
|
91 | + // get each question groups questions |
|
92 | + foreach ($question_groups as $question_group) { |
|
93 | + if ($question_group instanceof EE_Question_Group) { |
|
94 | + $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group( |
|
95 | + $question_group, |
|
96 | + $reg |
|
97 | + ); |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * |
|
105 | - * @param EE_Question_Group $question_group |
|
106 | - * @param EE_Registration $registration |
|
107 | - * @return EE_Form_Section_Proper |
|
108 | - * @throws EE_Error |
|
109 | - * @throws ReflectionException |
|
110 | - */ |
|
111 | - public function build_subform_from_question_group($question_group, $registration) |
|
112 | - { |
|
113 | - if ( |
|
114 | - ! $question_group instanceof EE_Question_Group || |
|
115 | - ! $registration instanceof EE_Registration |
|
116 | - ) { |
|
117 | - throw new EE_Error(esc_html__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso')); |
|
118 | - } |
|
119 | - $parts_of_subsection = array( |
|
120 | - 'title' => new EE_Form_Section_HTML( |
|
121 | - EEH_HTML::h5( |
|
122 | - $question_group->name(), |
|
123 | - $question_group->identifier(), |
|
124 | - 'espresso-question-group-title-h5 section-title' |
|
125 | - ) |
|
126 | - ) |
|
127 | - ); |
|
128 | - $questions = $question_group->questions( |
|
129 | - array( |
|
130 | - array( |
|
131 | - 'OR' => array( |
|
132 | - 'QST_system*blank' => '', |
|
133 | - 'QST_system*null' => array( 'IS_NULL' ) |
|
134 | - ) |
|
135 | - ) |
|
136 | - ) |
|
137 | - ); |
|
138 | - foreach ($questions as $question) { |
|
139 | - $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration); |
|
140 | - } |
|
141 | - if ( |
|
142 | - EE_Registry::instance()->CAP->current_user_can( |
|
143 | - 'ee_edit_registration', |
|
144 | - 'edit-reg-questions-mbox', |
|
145 | - $this->_registration->ID() |
|
146 | - ) |
|
147 | - ) { |
|
148 | - $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML( |
|
149 | - EEH_HTML::table( |
|
150 | - EEH_HTML::tr( |
|
151 | - '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '"> |
|
103 | + /** |
|
104 | + * |
|
105 | + * @param EE_Question_Group $question_group |
|
106 | + * @param EE_Registration $registration |
|
107 | + * @return EE_Form_Section_Proper |
|
108 | + * @throws EE_Error |
|
109 | + * @throws ReflectionException |
|
110 | + */ |
|
111 | + public function build_subform_from_question_group($question_group, $registration) |
|
112 | + { |
|
113 | + if ( |
|
114 | + ! $question_group instanceof EE_Question_Group || |
|
115 | + ! $registration instanceof EE_Registration |
|
116 | + ) { |
|
117 | + throw new EE_Error(esc_html__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso')); |
|
118 | + } |
|
119 | + $parts_of_subsection = array( |
|
120 | + 'title' => new EE_Form_Section_HTML( |
|
121 | + EEH_HTML::h5( |
|
122 | + $question_group->name(), |
|
123 | + $question_group->identifier(), |
|
124 | + 'espresso-question-group-title-h5 section-title' |
|
125 | + ) |
|
126 | + ) |
|
127 | + ); |
|
128 | + $questions = $question_group->questions( |
|
129 | + array( |
|
130 | + array( |
|
131 | + 'OR' => array( |
|
132 | + 'QST_system*blank' => '', |
|
133 | + 'QST_system*null' => array( 'IS_NULL' ) |
|
134 | + ) |
|
135 | + ) |
|
136 | + ) |
|
137 | + ); |
|
138 | + foreach ($questions as $question) { |
|
139 | + $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration); |
|
140 | + } |
|
141 | + if ( |
|
142 | + EE_Registry::instance()->CAP->current_user_can( |
|
143 | + 'ee_edit_registration', |
|
144 | + 'edit-reg-questions-mbox', |
|
145 | + $this->_registration->ID() |
|
146 | + ) |
|
147 | + ) { |
|
148 | + $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML( |
|
149 | + EEH_HTML::table( |
|
150 | + EEH_HTML::tr( |
|
151 | + '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '"> |
|
152 | 152 | <span class="reg-admin-edit-question-group-spn">' . esc_html__('edit the above question group', 'event_espresso') . '</span> |
153 | 153 | <div class="dashicons dashicons-edit"></div> |
154 | 154 | </a></td>' |
155 | - ) . |
|
156 | - EEH_HTML::no_row() |
|
157 | - ) |
|
158 | - ); |
|
159 | - } |
|
160 | - return new EE_Form_Section_Proper( |
|
161 | - array( |
|
162 | - 'subsections' => $parts_of_subsection, |
|
163 | - 'html_class' => 'question-group-questions', |
|
164 | - ) |
|
165 | - ); |
|
166 | - } |
|
155 | + ) . |
|
156 | + EEH_HTML::no_row() |
|
157 | + ) |
|
158 | + ); |
|
159 | + } |
|
160 | + return new EE_Form_Section_Proper( |
|
161 | + array( |
|
162 | + 'subsections' => $parts_of_subsection, |
|
163 | + 'html_class' => 'question-group-questions', |
|
164 | + ) |
|
165 | + ); |
|
166 | + } |
|
167 | 167 | |
168 | 168 | |
169 | - /** |
|
170 | - * Overrides parent so if inputs were disabled, we leave those with their defaults |
|
171 | - * from the answers in the DB |
|
172 | - * |
|
173 | - * @param array $req_data like $_POST |
|
174 | - * @return void |
|
175 | - * @throws EE_Error |
|
176 | - */ |
|
177 | - protected function _normalize($req_data) |
|
178 | - { |
|
179 | - $this->_received_submission = true; |
|
180 | - $this->_validation_errors = array(); |
|
181 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
182 | - if ($subsection->form_data_present_in($req_data)) { |
|
183 | - try { |
|
184 | - $subsection->_normalize($req_data); |
|
185 | - } catch (EE_Validation_Error $e) { |
|
186 | - $subsection->add_validation_error($e); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
169 | + /** |
|
170 | + * Overrides parent so if inputs were disabled, we leave those with their defaults |
|
171 | + * from the answers in the DB |
|
172 | + * |
|
173 | + * @param array $req_data like $_POST |
|
174 | + * @return void |
|
175 | + * @throws EE_Error |
|
176 | + */ |
|
177 | + protected function _normalize($req_data) |
|
178 | + { |
|
179 | + $this->_received_submission = true; |
|
180 | + $this->_validation_errors = array(); |
|
181 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
182 | + if ($subsection->form_data_present_in($req_data)) { |
|
183 | + try { |
|
184 | + $subsection->_normalize($req_data); |
|
185 | + } catch (EE_Validation_Error $e) { |
|
186 | + $subsection->add_validation_error($e); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | 191 | |
192 | 192 | |
193 | - /** |
|
194 | - * Performs validation on this form section and its subsections. For each subsection, |
|
195 | - * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls |
|
196 | - * _validate on that subsection. If you need to perform validation on the form as a whole (considering multiple) |
|
197 | - * you would be best to override this _validate method, calling parent::_validate() first. |
|
198 | - * |
|
199 | - * @throws EE_Error |
|
200 | - */ |
|
201 | - protected function _validate() |
|
202 | - { |
|
203 | - /** @var RequestInterface $request */ |
|
204 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
205 | - $form_data = $request->requestParams(); |
|
206 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
207 | - if ($subsection->form_data_present_in($form_data)) { |
|
208 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
209 | - call_user_func_array(array($this,'_validate_' . $subsection_name), array($subsection)); |
|
210 | - } |
|
211 | - $subsection->_validate(); |
|
212 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
213 | - $subsection->_received_submission = true; |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
193 | + /** |
|
194 | + * Performs validation on this form section and its subsections. For each subsection, |
|
195 | + * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls |
|
196 | + * _validate on that subsection. If you need to perform validation on the form as a whole (considering multiple) |
|
197 | + * you would be best to override this _validate method, calling parent::_validate() first. |
|
198 | + * |
|
199 | + * @throws EE_Error |
|
200 | + */ |
|
201 | + protected function _validate() |
|
202 | + { |
|
203 | + /** @var RequestInterface $request */ |
|
204 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
205 | + $form_data = $request->requestParams(); |
|
206 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
207 | + if ($subsection->form_data_present_in($form_data)) { |
|
208 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
209 | + call_user_func_array(array($this,'_validate_' . $subsection_name), array($subsection)); |
|
210 | + } |
|
211 | + $subsection->_validate(); |
|
212 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
213 | + $subsection->_received_submission = true; |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | 217 | } |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | public function __construct(EE_Registration $reg, $options = array()) |
38 | 38 | { |
39 | 39 | $this->_registration = $reg; |
40 | - if (! isset($options['layout_strategy'])) { |
|
40 | + if ( ! isset($options['layout_strategy'])) { |
|
41 | 41 | $options['layout_strategy'] = new EE_Admin_Two_Column_Layout(); |
42 | 42 | } |
43 | - if (! isset($options['html_id'])) { |
|
43 | + if ( ! isset($options['html_id'])) { |
|
44 | 44 | $options['html_id'] = 'reg-admin-attendee-questions-frm'; |
45 | 45 | } |
46 | 46 | $this->build_form_from_registration(); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function build_form_from_registration() |
69 | 69 | { |
70 | 70 | $reg = $this->get_registration(); |
71 | - if (! $reg instanceof EE_Registration) { |
|
71 | + if ( ! $reg instanceof EE_Registration) { |
|
72 | 72 | throw new EE_Error(esc_html__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso')); |
73 | 73 | } |
74 | 74 | // we want to get all their question groups |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | // get each question groups questions |
92 | 92 | foreach ($question_groups as $question_group) { |
93 | 93 | if ($question_group instanceof EE_Question_Group) { |
94 | - $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group( |
|
94 | + $this->_subsections[$question_group->ID()] = $this->build_subform_from_question_group( |
|
95 | 95 | $question_group, |
96 | 96 | $reg |
97 | 97 | ); |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | array( |
131 | 131 | 'OR' => array( |
132 | 132 | 'QST_system*blank' => '', |
133 | - 'QST_system*null' => array( 'IS_NULL' ) |
|
133 | + 'QST_system*null' => array('IS_NULL') |
|
134 | 134 | ) |
135 | 135 | ) |
136 | 136 | ) |
137 | 137 | ); |
138 | 138 | foreach ($questions as $question) { |
139 | - $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration); |
|
139 | + $parts_of_subsection[$question->ID()] = $question->generate_form_input($registration); |
|
140 | 140 | } |
141 | 141 | if ( |
142 | 142 | EE_Registry::instance()->CAP->current_user_can( |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML( |
149 | 149 | EEH_HTML::table( |
150 | 150 | EEH_HTML::tr( |
151 | - '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '"> |
|
152 | - <span class="reg-admin-edit-question-group-spn">' . esc_html__('edit the above question group', 'event_espresso') . '</span> |
|
151 | + '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="'.esc_attr__('click to edit question', 'event_espresso').'"> |
|
152 | + <span class="reg-admin-edit-question-group-spn">' . esc_html__('edit the above question group', 'event_espresso').'</span> |
|
153 | 153 | <div class="dashicons dashicons-edit"></div> |
154 | 154 | </a></td>' |
155 | - ) . |
|
155 | + ). |
|
156 | 156 | EEH_HTML::no_row() |
157 | 157 | ) |
158 | 158 | ); |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | $form_data = $request->requestParams(); |
206 | 206 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
207 | 207 | if ($subsection->form_data_present_in($form_data)) { |
208 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
209 | - call_user_func_array(array($this,'_validate_' . $subsection_name), array($subsection)); |
|
208 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
209 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
210 | 210 | } |
211 | 211 | $subsection->_validate(); |
212 | 212 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function __construct($pm_instance = null) |
31 | 31 | { |
32 | - require_once($this->file_folder() . 'EEG_Paypal_Standard.gateway.php'); |
|
32 | + require_once($this->file_folder().'EEG_Paypal_Standard.gateway.php'); |
|
33 | 33 | $this->_gateway = new EEG_Paypal_Standard(); |
34 | 34 | $this->_pretty_name = esc_html__("PayPal Standard", 'event_espresso'); |
35 | 35 | $this->_default_description = sprintf( |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | '</strong>' |
42 | 42 | ); |
43 | 43 | parent::__construct($pm_instance); |
44 | - $this->_default_button_url = $this->file_url() . 'lib/paypal-logo.png'; |
|
44 | + $this->_default_button_url = $this->file_url().'lib/paypal-logo.png'; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function generate_new_settings_form() |
67 | 67 | { |
68 | - require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php'); |
|
68 | + require_once($this->file_folder().'EE_Paypal_Standard_Form.form.php'); |
|
69 | 69 | $form = new EE_Paypal_Standard_Form($this); |
70 | 70 | $form->get_input('PMD_debug_mode')->set_html_label_text( |
71 | 71 | sprintf(esc_html__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link()) |
@@ -15,106 +15,106 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_PMT_Paypal_Standard extends EE_PMT_Base |
17 | 17 | { |
18 | - const shipping_info_none = 1; |
|
18 | + const shipping_info_none = 1; |
|
19 | 19 | |
20 | - const shipping_info_optional = 0; |
|
20 | + const shipping_info_optional = 0; |
|
21 | 21 | |
22 | - const shipping_info_required = 2; |
|
22 | + const shipping_info_required = 2; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @param EE_Payment_Method|null $pm_instance |
|
27 | - * @throws ReflectionException |
|
28 | - * @throws EE_Error |
|
29 | - */ |
|
30 | - public function __construct($pm_instance = null) |
|
31 | - { |
|
32 | - require_once($this->file_folder() . 'EEG_Paypal_Standard.gateway.php'); |
|
33 | - $this->_gateway = new EEG_Paypal_Standard(); |
|
34 | - $this->_pretty_name = esc_html__("PayPal Standard", 'event_espresso'); |
|
35 | - $this->_default_description = sprintf( |
|
36 | - esc_html__( |
|
37 | - 'Upon submitting this form, you will be forwarded to PayPal to make your payment. %1$sMake sure you return to this site in order to properly finalize your registration.%2$s', |
|
38 | - 'event_espresso' |
|
39 | - ), |
|
40 | - '<strong>', |
|
41 | - '</strong>' |
|
42 | - ); |
|
43 | - parent::__construct($pm_instance); |
|
44 | - $this->_default_button_url = $this->file_url() . 'lib/paypal-logo.png'; |
|
45 | - } |
|
25 | + /** |
|
26 | + * @param EE_Payment_Method|null $pm_instance |
|
27 | + * @throws ReflectionException |
|
28 | + * @throws EE_Error |
|
29 | + */ |
|
30 | + public function __construct($pm_instance = null) |
|
31 | + { |
|
32 | + require_once($this->file_folder() . 'EEG_Paypal_Standard.gateway.php'); |
|
33 | + $this->_gateway = new EEG_Paypal_Standard(); |
|
34 | + $this->_pretty_name = esc_html__("PayPal Standard", 'event_espresso'); |
|
35 | + $this->_default_description = sprintf( |
|
36 | + esc_html__( |
|
37 | + 'Upon submitting this form, you will be forwarded to PayPal to make your payment. %1$sMake sure you return to this site in order to properly finalize your registration.%2$s', |
|
38 | + 'event_espresso' |
|
39 | + ), |
|
40 | + '<strong>', |
|
41 | + '</strong>' |
|
42 | + ); |
|
43 | + parent::__construct($pm_instance); |
|
44 | + $this->_default_button_url = $this->file_url() . 'lib/paypal-logo.png'; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * Creates the billing form for this payment method type |
|
50 | - * @param EE_Transaction|null $transaction |
|
51 | - * @return EE_Billing_Info_Form|null |
|
52 | - */ |
|
53 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
54 | - { |
|
55 | - return null; |
|
56 | - } |
|
48 | + /** |
|
49 | + * Creates the billing form for this payment method type |
|
50 | + * @param EE_Transaction|null $transaction |
|
51 | + * @return EE_Billing_Info_Form|null |
|
52 | + */ |
|
53 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
54 | + { |
|
55 | + return null; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Gets the form for all the settings related to this payment method type |
|
61 | - * |
|
62 | - * @return EE_Payment_Method_Form |
|
63 | - * @throws EE_Error |
|
64 | - * @throws ReflectionException |
|
65 | - */ |
|
66 | - public function generate_new_settings_form() |
|
67 | - { |
|
68 | - require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php'); |
|
69 | - $form = new EE_Paypal_Standard_Form($this); |
|
70 | - $form->get_input('PMD_debug_mode')->set_html_label_text( |
|
71 | - sprintf(esc_html__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link()) |
|
72 | - ); |
|
73 | - $form->get_input('shipping_details')->set_html_label_text( |
|
74 | - sprintf(esc_html__("Shipping Address Options %s", "event_espresso"), $this->get_help_tab_link()) |
|
75 | - ); |
|
76 | - return $form; |
|
77 | - } |
|
59 | + /** |
|
60 | + * Gets the form for all the settings related to this payment method type |
|
61 | + * |
|
62 | + * @return EE_Payment_Method_Form |
|
63 | + * @throws EE_Error |
|
64 | + * @throws ReflectionException |
|
65 | + */ |
|
66 | + public function generate_new_settings_form() |
|
67 | + { |
|
68 | + require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php'); |
|
69 | + $form = new EE_Paypal_Standard_Form($this); |
|
70 | + $form->get_input('PMD_debug_mode')->set_html_label_text( |
|
71 | + sprintf(esc_html__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link()) |
|
72 | + ); |
|
73 | + $form->get_input('shipping_details')->set_html_label_text( |
|
74 | + sprintf(esc_html__("Shipping Address Options %s", "event_espresso"), $this->get_help_tab_link()) |
|
75 | + ); |
|
76 | + return $form; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * Adds the help tab |
|
82 | - * |
|
83 | - * @return array |
|
84 | - * @see EE_PMT_Base::help_tabs_config() |
|
85 | - */ |
|
86 | - public function help_tabs_config() |
|
87 | - { |
|
88 | - return [ |
|
89 | - $this->get_help_tab_name() => [ |
|
90 | - 'title' => esc_html__("PayPal Standard Settings", 'event_espresso'), |
|
91 | - 'filename' => 'payment_methods_overview_paypalstandard', |
|
92 | - ], |
|
93 | - ]; |
|
94 | - } |
|
80 | + /** |
|
81 | + * Adds the help tab |
|
82 | + * |
|
83 | + * @return array |
|
84 | + * @see EE_PMT_Base::help_tabs_config() |
|
85 | + */ |
|
86 | + public function help_tabs_config() |
|
87 | + { |
|
88 | + return [ |
|
89 | + $this->get_help_tab_name() => [ |
|
90 | + 'title' => esc_html__("PayPal Standard Settings", 'event_espresso'), |
|
91 | + 'filename' => 'payment_methods_overview_paypalstandard', |
|
92 | + ], |
|
93 | + ]; |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * Logic to be accomplished when the payment attempt is complete. |
|
99 | - * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
100 | - * (Mijireh was an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
101 | - * Mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
102 | - * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
103 | - * |
|
104 | - * @param EE_Transaction $transaction |
|
105 | - * @return EE_Payment |
|
106 | - * @throws EE_Error |
|
107 | - * @throws ReflectionException |
|
108 | - */ |
|
109 | - public function finalize_payment_for(EE_Transaction $transaction): ?EE_Payment |
|
110 | - { |
|
111 | - /** @var RequestInterface $request */ |
|
112 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
113 | - // PayPal standard actually sends the IPN info along with the user when they return to our site |
|
114 | - // so in case the IPN is arriving later, let's try to process an IPN! |
|
115 | - if ($request->getServerParam('REQUEST_METHOD') === 'POST') { |
|
116 | - return $this->handle_ipn($request->postParams(), $transaction); |
|
117 | - } |
|
118 | - return parent::finalize_payment_for($transaction); |
|
119 | - } |
|
97 | + /** |
|
98 | + * Logic to be accomplished when the payment attempt is complete. |
|
99 | + * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
100 | + * (Mijireh was an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
101 | + * Mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
102 | + * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
103 | + * |
|
104 | + * @param EE_Transaction $transaction |
|
105 | + * @return EE_Payment |
|
106 | + * @throws EE_Error |
|
107 | + * @throws ReflectionException |
|
108 | + */ |
|
109 | + public function finalize_payment_for(EE_Transaction $transaction): ?EE_Payment |
|
110 | + { |
|
111 | + /** @var RequestInterface $request */ |
|
112 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
113 | + // PayPal standard actually sends the IPN info along with the user when they return to our site |
|
114 | + // so in case the IPN is arriving later, let's try to process an IPN! |
|
115 | + if ($request->getServerParam('REQUEST_METHOD') === 'POST') { |
|
116 | + return $this->handle_ipn($request->postParams(), $transaction); |
|
117 | + } |
|
118 | + return parent::finalize_payment_for($transaction); |
|
119 | + } |
|
120 | 120 | } |
@@ -59,14 +59,14 @@ |
||
59 | 59 | $ee_bot_checkout = array(); |
60 | 60 | add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false); |
61 | 61 | } |
62 | - if (! isset($ee_bot_checkout[ $ip_address ])) { |
|
63 | - $ee_bot_checkout[ $ip_address ] = array(); |
|
62 | + if ( ! isset($ee_bot_checkout[$ip_address])) { |
|
63 | + $ee_bot_checkout[$ip_address] = array(); |
|
64 | 64 | } |
65 | 65 | $http_referer = esc_attr($request->getServerParam('HTTP_REFERER', 0)); |
66 | - if (! isset($ee_bot_checkout[ $ip_address ][ $http_referer ])) { |
|
67 | - $ee_bot_checkout[ $ip_address ][ $http_referer ] = 0; |
|
66 | + if ( ! isset($ee_bot_checkout[$ip_address][$http_referer])) { |
|
67 | + $ee_bot_checkout[$ip_address][$http_referer] = 0; |
|
68 | 68 | } |
69 | - $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
|
69 | + $ee_bot_checkout[$ip_address][$http_referer]++; |
|
70 | 70 | update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout); |
71 | 71 | if (WP_DEBUG) { |
72 | 72 | EE_Error::add_error( |
@@ -26,181 +26,181 @@ |
||
26 | 26 | */ |
27 | 27 | class InvalidCheckoutAccess |
28 | 28 | { |
29 | - /** |
|
30 | - * key used for saving invalid checkout access data to the wp_options table |
|
31 | - */ |
|
32 | - const OPTION_KEY = 'ee_invalid_checkout_access'; |
|
29 | + /** |
|
30 | + * key used for saving invalid checkout access data to the wp_options table |
|
31 | + */ |
|
32 | + const OPTION_KEY = 'ee_invalid_checkout_access'; |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * _block_bots |
|
37 | - * checks that the incoming request has either of the following set: |
|
38 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
39 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
40 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
41 | - * then where you coming from man? |
|
42 | - * |
|
43 | - * @param EE_Checkout $checkout |
|
44 | - * @return bool true if access to registration checkout appears to be invalid |
|
45 | - */ |
|
46 | - public function checkoutAccessIsInvalid(EE_Checkout $checkout) |
|
47 | - { |
|
48 | - if ( |
|
49 | - ! ($checkout->uts || $checkout->reg_url_link) |
|
50 | - && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
51 | - && EE_Config::instance()->registration->track_invalid_checkout_access() |
|
52 | - ) { |
|
53 | - /** @var RequestInterface $request */ |
|
54 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
55 | - $ip_address = $request->ipAddress(); |
|
56 | - $ee_bot_checkout = get_option(InvalidCheckoutAccess::OPTION_KEY); |
|
57 | - if ($ee_bot_checkout === false) { |
|
58 | - $ee_bot_checkout = array(); |
|
59 | - add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false); |
|
60 | - } |
|
61 | - if (! isset($ee_bot_checkout[ $ip_address ])) { |
|
62 | - $ee_bot_checkout[ $ip_address ] = array(); |
|
63 | - } |
|
64 | - $http_referer = esc_attr($request->getServerParam('HTTP_REFERER', 0)); |
|
65 | - if (! isset($ee_bot_checkout[ $ip_address ][ $http_referer ])) { |
|
66 | - $ee_bot_checkout[ $ip_address ][ $http_referer ] = 0; |
|
67 | - } |
|
68 | - $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
|
69 | - update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout); |
|
70 | - if (WP_DEBUG) { |
|
71 | - EE_Error::add_error( |
|
72 | - esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
|
73 | - __FILE__, |
|
74 | - __FUNCTION__, |
|
75 | - __LINE__ |
|
76 | - ); |
|
77 | - } |
|
78 | - return true; |
|
79 | - } |
|
80 | - return false; |
|
81 | - } |
|
35 | + /** |
|
36 | + * _block_bots |
|
37 | + * checks that the incoming request has either of the following set: |
|
38 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
39 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
40 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
41 | + * then where you coming from man? |
|
42 | + * |
|
43 | + * @param EE_Checkout $checkout |
|
44 | + * @return bool true if access to registration checkout appears to be invalid |
|
45 | + */ |
|
46 | + public function checkoutAccessIsInvalid(EE_Checkout $checkout) |
|
47 | + { |
|
48 | + if ( |
|
49 | + ! ($checkout->uts || $checkout->reg_url_link) |
|
50 | + && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
51 | + && EE_Config::instance()->registration->track_invalid_checkout_access() |
|
52 | + ) { |
|
53 | + /** @var RequestInterface $request */ |
|
54 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
55 | + $ip_address = $request->ipAddress(); |
|
56 | + $ee_bot_checkout = get_option(InvalidCheckoutAccess::OPTION_KEY); |
|
57 | + if ($ee_bot_checkout === false) { |
|
58 | + $ee_bot_checkout = array(); |
|
59 | + add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false); |
|
60 | + } |
|
61 | + if (! isset($ee_bot_checkout[ $ip_address ])) { |
|
62 | + $ee_bot_checkout[ $ip_address ] = array(); |
|
63 | + } |
|
64 | + $http_referer = esc_attr($request->getServerParam('HTTP_REFERER', 0)); |
|
65 | + if (! isset($ee_bot_checkout[ $ip_address ][ $http_referer ])) { |
|
66 | + $ee_bot_checkout[ $ip_address ][ $http_referer ] = 0; |
|
67 | + } |
|
68 | + $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
|
69 | + update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout); |
|
70 | + if (WP_DEBUG) { |
|
71 | + EE_Error::add_error( |
|
72 | + esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
|
73 | + __FILE__, |
|
74 | + __FUNCTION__, |
|
75 | + __LINE__ |
|
76 | + ); |
|
77 | + } |
|
78 | + return true; |
|
79 | + } |
|
80 | + return false; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * _invalid_checkout_access_form |
|
86 | - * |
|
87 | - * @return EE_Form_Section_Proper |
|
88 | - * @throws EE_Error |
|
89 | - */ |
|
90 | - public function getForm() |
|
91 | - { |
|
92 | - return new EE_Form_Section_Proper( |
|
93 | - array( |
|
94 | - 'name' => 'invalid_checkout_access', |
|
95 | - 'html_id' => 'invalid_checkout_access', |
|
96 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
97 | - 'subsections' => array( |
|
98 | - 'invalid_checkout_access_hdr' => new EE_Form_Section_HTML( |
|
99 | - EEH_HTML::h2(esc_html__('Invalid Checkout Access', 'event_espresso')) |
|
100 | - ), |
|
101 | - 'ee_bot_checkout_data' => new EE_Text_Area_Input( |
|
102 | - array( |
|
103 | - 'html_label_text' => esc_html__('Invalid Checkout Data', 'event_espresso'), |
|
104 | - 'default' => var_export( |
|
105 | - get_option(InvalidCheckoutAccess::OPTION_KEY, array()), |
|
106 | - true |
|
107 | - ), |
|
108 | - 'required' => false, |
|
109 | - 'html_help_text' => esc_html__( |
|
110 | - 'Event Espresso blocks any attempt to directly access the registration checkout page, that is NOT from a Ticket Selector or for a return visit for a valid transaction. These are not valid requests accessing your checkout page, so we track the IP addresses, what web page they just came from, and the number of times that they have attempted to access your registration page. This information may help you with protecting your site by other means, such as firewalls, etc, but please note that IP addresses are almost guaranteed to be spoofed by malicious agents.', |
|
111 | - 'event_espresso' |
|
112 | - ), |
|
113 | - ) |
|
114 | - ), |
|
115 | - 'track_invalid_checkout_access' => new EE_Yes_No_Input( |
|
116 | - array( |
|
117 | - 'html_label_text' => esc_html__('Track Invalid Checkout Access?', 'event_espresso'), |
|
118 | - 'html_help_text' => esc_html__( |
|
119 | - 'Controls whether or not invalid attempts to directly access the registration checkout page should be tracked. Setting this to "No" means that the above data will no longer be collected.', |
|
120 | - 'event_espresso' |
|
121 | - ), |
|
122 | - 'default' => EE_Config::instance() |
|
123 | - ->registration |
|
124 | - ->track_invalid_checkout_access(), |
|
125 | - 'display_html_label_text' => false, |
|
126 | - ) |
|
127 | - ), |
|
128 | - 'delete_invalid_checkout_data' => new EE_Yes_No_Input( |
|
129 | - array( |
|
130 | - 'html_label_text' => esc_html__('Reset Invalid Checkout Data', 'event_espresso'), |
|
131 | - 'html_help_text' => esc_html__( |
|
132 | - 'Setting this to "Yes" will delete all existing invalid checkout access data.', |
|
133 | - 'event_espresso' |
|
134 | - ), |
|
135 | - 'default' => false, |
|
136 | - 'display_html_label_text' => false, |
|
137 | - ) |
|
138 | - ), |
|
139 | - ), |
|
140 | - ) |
|
141 | - ); |
|
142 | - } |
|
84 | + /** |
|
85 | + * _invalid_checkout_access_form |
|
86 | + * |
|
87 | + * @return EE_Form_Section_Proper |
|
88 | + * @throws EE_Error |
|
89 | + */ |
|
90 | + public function getForm() |
|
91 | + { |
|
92 | + return new EE_Form_Section_Proper( |
|
93 | + array( |
|
94 | + 'name' => 'invalid_checkout_access', |
|
95 | + 'html_id' => 'invalid_checkout_access', |
|
96 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
97 | + 'subsections' => array( |
|
98 | + 'invalid_checkout_access_hdr' => new EE_Form_Section_HTML( |
|
99 | + EEH_HTML::h2(esc_html__('Invalid Checkout Access', 'event_espresso')) |
|
100 | + ), |
|
101 | + 'ee_bot_checkout_data' => new EE_Text_Area_Input( |
|
102 | + array( |
|
103 | + 'html_label_text' => esc_html__('Invalid Checkout Data', 'event_espresso'), |
|
104 | + 'default' => var_export( |
|
105 | + get_option(InvalidCheckoutAccess::OPTION_KEY, array()), |
|
106 | + true |
|
107 | + ), |
|
108 | + 'required' => false, |
|
109 | + 'html_help_text' => esc_html__( |
|
110 | + 'Event Espresso blocks any attempt to directly access the registration checkout page, that is NOT from a Ticket Selector or for a return visit for a valid transaction. These are not valid requests accessing your checkout page, so we track the IP addresses, what web page they just came from, and the number of times that they have attempted to access your registration page. This information may help you with protecting your site by other means, such as firewalls, etc, but please note that IP addresses are almost guaranteed to be spoofed by malicious agents.', |
|
111 | + 'event_espresso' |
|
112 | + ), |
|
113 | + ) |
|
114 | + ), |
|
115 | + 'track_invalid_checkout_access' => new EE_Yes_No_Input( |
|
116 | + array( |
|
117 | + 'html_label_text' => esc_html__('Track Invalid Checkout Access?', 'event_espresso'), |
|
118 | + 'html_help_text' => esc_html__( |
|
119 | + 'Controls whether or not invalid attempts to directly access the registration checkout page should be tracked. Setting this to "No" means that the above data will no longer be collected.', |
|
120 | + 'event_espresso' |
|
121 | + ), |
|
122 | + 'default' => EE_Config::instance() |
|
123 | + ->registration |
|
124 | + ->track_invalid_checkout_access(), |
|
125 | + 'display_html_label_text' => false, |
|
126 | + ) |
|
127 | + ), |
|
128 | + 'delete_invalid_checkout_data' => new EE_Yes_No_Input( |
|
129 | + array( |
|
130 | + 'html_label_text' => esc_html__('Reset Invalid Checkout Data', 'event_espresso'), |
|
131 | + 'html_help_text' => esc_html__( |
|
132 | + 'Setting this to "Yes" will delete all existing invalid checkout access data.', |
|
133 | + 'event_espresso' |
|
134 | + ), |
|
135 | + 'default' => false, |
|
136 | + 'display_html_label_text' => false, |
|
137 | + ) |
|
138 | + ), |
|
139 | + ), |
|
140 | + ) |
|
141 | + ); |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | - /** |
|
146 | - * update_invalid_checkout_access_form |
|
147 | - * |
|
148 | - * @param EE_Registration_Config $EE_Registration_Config |
|
149 | - * @return EE_Registration_Config |
|
150 | - * @throws EE_Error |
|
151 | - * @throws ReflectionException |
|
152 | - */ |
|
153 | - public function processForm(EE_Registration_Config $EE_Registration_Config) |
|
154 | - { |
|
155 | - try { |
|
156 | - $invalid_checkout_access_form = $this->getForm(); |
|
157 | - // if not displaying a form, then check for form submission |
|
158 | - if ($invalid_checkout_access_form->was_submitted()) { |
|
159 | - // capture form data |
|
160 | - $invalid_checkout_access_form->receive_form_submission(); |
|
161 | - // validate form data |
|
162 | - if ($invalid_checkout_access_form->is_valid()) { |
|
163 | - // grab validated data from form |
|
164 | - $valid_data = $invalid_checkout_access_form->valid_data(); |
|
165 | - // ensure form inputs we want are set |
|
166 | - if ( |
|
167 | - isset( |
|
168 | - $valid_data['track_invalid_checkout_access'], |
|
169 | - $valid_data['delete_invalid_checkout_data'] |
|
170 | - ) |
|
171 | - ) { |
|
172 | - $EE_Registration_Config->set_track_invalid_checkout_access( |
|
173 | - $valid_data['track_invalid_checkout_access'] |
|
174 | - ); |
|
175 | - // if deleting, then update option with empty array |
|
176 | - if (filter_var($valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN)) { |
|
177 | - update_option(InvalidCheckoutAccess::OPTION_KEY, array()); |
|
178 | - } |
|
179 | - } else { |
|
180 | - EE_Error::add_error( |
|
181 | - esc_html__( |
|
182 | - 'Invalid or missing Invalid Checkout Access form data. Please refresh the form and try again.', |
|
183 | - 'event_espresso' |
|
184 | - ), |
|
185 | - __FILE__, |
|
186 | - __FUNCTION__, |
|
187 | - __LINE__ |
|
188 | - ); |
|
189 | - } |
|
190 | - } else { |
|
191 | - if ($invalid_checkout_access_form->submission_error_message() !== '') { |
|
192 | - EE_Error::add_error( |
|
193 | - $invalid_checkout_access_form->submission_error_message(), |
|
194 | - __FILE__, |
|
195 | - __FUNCTION__, |
|
196 | - __LINE__ |
|
197 | - ); |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - } catch (EE_Error $e) { |
|
202 | - $e->get_error(); |
|
203 | - } |
|
204 | - return $EE_Registration_Config; |
|
205 | - } |
|
145 | + /** |
|
146 | + * update_invalid_checkout_access_form |
|
147 | + * |
|
148 | + * @param EE_Registration_Config $EE_Registration_Config |
|
149 | + * @return EE_Registration_Config |
|
150 | + * @throws EE_Error |
|
151 | + * @throws ReflectionException |
|
152 | + */ |
|
153 | + public function processForm(EE_Registration_Config $EE_Registration_Config) |
|
154 | + { |
|
155 | + try { |
|
156 | + $invalid_checkout_access_form = $this->getForm(); |
|
157 | + // if not displaying a form, then check for form submission |
|
158 | + if ($invalid_checkout_access_form->was_submitted()) { |
|
159 | + // capture form data |
|
160 | + $invalid_checkout_access_form->receive_form_submission(); |
|
161 | + // validate form data |
|
162 | + if ($invalid_checkout_access_form->is_valid()) { |
|
163 | + // grab validated data from form |
|
164 | + $valid_data = $invalid_checkout_access_form->valid_data(); |
|
165 | + // ensure form inputs we want are set |
|
166 | + if ( |
|
167 | + isset( |
|
168 | + $valid_data['track_invalid_checkout_access'], |
|
169 | + $valid_data['delete_invalid_checkout_data'] |
|
170 | + ) |
|
171 | + ) { |
|
172 | + $EE_Registration_Config->set_track_invalid_checkout_access( |
|
173 | + $valid_data['track_invalid_checkout_access'] |
|
174 | + ); |
|
175 | + // if deleting, then update option with empty array |
|
176 | + if (filter_var($valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN)) { |
|
177 | + update_option(InvalidCheckoutAccess::OPTION_KEY, array()); |
|
178 | + } |
|
179 | + } else { |
|
180 | + EE_Error::add_error( |
|
181 | + esc_html__( |
|
182 | + 'Invalid or missing Invalid Checkout Access form data. Please refresh the form and try again.', |
|
183 | + 'event_espresso' |
|
184 | + ), |
|
185 | + __FILE__, |
|
186 | + __FUNCTION__, |
|
187 | + __LINE__ |
|
188 | + ); |
|
189 | + } |
|
190 | + } else { |
|
191 | + if ($invalid_checkout_access_form->submission_error_message() !== '') { |
|
192 | + EE_Error::add_error( |
|
193 | + $invalid_checkout_access_form->submission_error_message(), |
|
194 | + __FILE__, |
|
195 | + __FUNCTION__, |
|
196 | + __LINE__ |
|
197 | + ); |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + } catch (EE_Error $e) { |
|
202 | + $e->get_error(); |
|
203 | + } |
|
204 | + return $EE_Registration_Config; |
|
205 | + } |
|
206 | 206 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | <tr class="item"> |
9 | 9 | <td>[LINE_ITEM_NAME][LINE_ITEM_TAXABLE_*]</td> |
10 | 10 | <td colspan="2">[LINE_ITEM_DESCRIPTION] |
11 | - <p class="ticket-note"><?php echo sprintf(esc_html__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), '[TKT_USES_* schema=' . esc_html__('any', 'event_espresso') . ']'); ?></p> |
|
11 | + <p class="ticket-note"><?php echo sprintf(esc_html__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), '[TKT_USES_* schema='.esc_html__('any', 'event_espresso').']'); ?></p> |
|
12 | 12 | </td> |
13 | 13 | <td class="item_c">[LINE_ITEM_QUANTITY]</td> |
14 | 14 | <td class="item_c">[LINE_ITEM_AMOUNT]</td> |