@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | EE_Registry::instance()->load_class('Processor_Base'); |
5 | 5 | |
@@ -16,737 +16,737 @@ discard block |
||
16 | 16 | class EE_Payment_Processor extends EE_Processor_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var EE_Payment_Processor $_instance |
|
21 | - * @access private |
|
22 | - */ |
|
23 | - private static $_instance; |
|
24 | - |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @singleton method used to instantiate class object |
|
29 | - * @access public |
|
30 | - * @return EE_Payment_Processor instance |
|
31 | - */ |
|
32 | - public static function instance() |
|
33 | - { |
|
34 | - // check if class object is instantiated |
|
35 | - if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
36 | - self::$_instance = new self(); |
|
37 | - } |
|
38 | - return self::$_instance; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - *private constructor to prevent direct creation |
|
45 | - * |
|
46 | - * @Constructor |
|
47 | - * @access private |
|
48 | - */ |
|
49 | - private function __construct() |
|
50 | - { |
|
51 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
52 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
59 | - * appropriately. Saves the payment that is generated |
|
60 | - * |
|
61 | - * @param EE_Payment_Method $payment_method |
|
62 | - * @param EE_Transaction $transaction |
|
63 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
64 | - * Leave null if payment is for the full amount owing |
|
65 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
66 | - * Receive_form_submission() should have |
|
67 | - * already been called on the billing form |
|
68 | - * (ie, its inputs should have their normalized values set). |
|
69 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
70 | - * where to go AFTER the offsite gateway |
|
71 | - * @param string $method like 'CART', indicates who the client who called this was |
|
72 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
73 | - * @param boolean $update_txn whether or not to call |
|
74 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
75 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
76 | - * @return \EE_Payment |
|
77 | - * @throws \EE_Error |
|
78 | - */ |
|
79 | - public function process_payment( |
|
80 | - EE_Payment_Method $payment_method, |
|
81 | - EE_Transaction $transaction, |
|
82 | - $amount = null, |
|
83 | - $billing_form = null, |
|
84 | - $return_url = null, |
|
85 | - $method = 'CART', |
|
86 | - $by_admin = false, |
|
87 | - $update_txn = true, |
|
88 | - $cancel_url = '' |
|
89 | - ) { |
|
90 | - if ((float)$amount < 0) { |
|
91 | - throw new EE_Error( |
|
92 | - sprintf( |
|
93 | - __( |
|
94 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
95 | - 'event_espresso' |
|
96 | - ), |
|
97 | - $amount, |
|
98 | - $transaction->ID() |
|
99 | - ) |
|
100 | - ); |
|
101 | - } |
|
102 | - // verify payment method |
|
103 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
104 | - // verify transaction |
|
105 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
106 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
107 | - // verify payment method type |
|
108 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
109 | - $payment = $payment_method->type_obj()->process_payment( |
|
110 | - $transaction, |
|
111 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
112 | - $billing_form, |
|
113 | - $return_url, |
|
114 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
115 | - $method, |
|
116 | - $by_admin |
|
117 | - ); |
|
118 | - // check if payment method uses an off-site gateway |
|
119 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
120 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
121 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
122 | - } |
|
123 | - return $payment; |
|
124 | - } else { |
|
125 | - EE_Error::add_error( |
|
126 | - sprintf( |
|
127 | - __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
128 | - '<br/>', |
|
129 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
130 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
131 | - ); |
|
132 | - return null; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @param EE_Transaction|int $transaction |
|
140 | - * @param EE_Payment_Method $payment_method |
|
141 | - * @throws EE_Error |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
145 | - { |
|
146 | - /** @type \EE_Transaction $transaction */ |
|
147 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
148 | - $primary_reg = $transaction->primary_registration(); |
|
149 | - if ( ! $primary_reg instanceof EE_Registration) { |
|
150 | - throw new EE_Error( |
|
151 | - sprintf( |
|
152 | - __( |
|
153 | - "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
154 | - "event_espresso" |
|
155 | - ), |
|
156 | - $transaction->ID() |
|
157 | - ) |
|
158 | - ); |
|
159 | - } |
|
160 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
161 | - $url = add_query_arg( |
|
162 | - array( |
|
163 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
164 | - 'ee_payment_method' => $payment_method->slug(), |
|
165 | - ), |
|
166 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
167 | - ); |
|
168 | - return $url; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
175 | - * we can easily find what registration the IPN is for and what payment method. |
|
176 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
177 | - * If a payment is found for the IPN info, it is saved. |
|
178 | - * |
|
179 | - * @param array $_req_data eg $_REQUEST |
|
180 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
181 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
182 | - * @param boolean $update_txn whether or not to call |
|
183 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
184 | - * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
185 | - * or is processed manually ( false like Mijireh ) |
|
186 | - * @throws EE_Error |
|
187 | - * @throws Exception |
|
188 | - * @return EE_Payment |
|
189 | - */ |
|
190 | - public function process_ipn( |
|
191 | - $_req_data, |
|
192 | - $transaction = null, |
|
193 | - $payment_method = null, |
|
194 | - $update_txn = true, |
|
195 | - $separate_IPN_request = true |
|
196 | - ) { |
|
197 | - EE_Registry::instance()->load_model('Change_Log'); |
|
198 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
199 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
200 | - $obj_for_log = null; |
|
201 | - if ($transaction instanceof EE_Transaction) { |
|
202 | - $obj_for_log = $transaction; |
|
203 | - if ($payment_method instanceof EE_Payment_Method) { |
|
204 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
205 | - array( |
|
206 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
207 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
208 | - ) |
|
209 | - ); |
|
210 | - } |
|
211 | - } else if ($payment_method instanceof EE_Payment) { |
|
212 | - $obj_for_log = $payment_method; |
|
213 | - } |
|
214 | - $log = EEM_Change_Log::instance()->log( |
|
215 | - EEM_Change_Log::type_gateway, |
|
216 | - array('IPN data received' => $_req_data), |
|
217 | - $obj_for_log |
|
218 | - ); |
|
219 | - try { |
|
220 | - /** |
|
221 | - * @var EE_Payment $payment |
|
222 | - */ |
|
223 | - $payment = null; |
|
224 | - if ($transaction && $payment_method) { |
|
225 | - /** @type EE_Transaction $transaction */ |
|
226 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
227 | - /** @type EE_Payment_Method $payment_method */ |
|
228 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
229 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
230 | - try { |
|
231 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
232 | - $log->set_object($payment); |
|
233 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
234 | - EEM_Change_Log::instance()->log( |
|
235 | - EEM_Change_Log::type_gateway, |
|
236 | - array( |
|
237 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
238 | - 'current_url' => EEH_URL::current_url(), |
|
239 | - 'payment' => $e->getPaymentProperties(), |
|
240 | - 'IPN_data' => $e->getIpnData(), |
|
241 | - ), |
|
242 | - $obj_for_log |
|
243 | - ); |
|
244 | - return $e->getPayment(); |
|
245 | - } |
|
246 | - } else { |
|
247 | - // not a payment |
|
248 | - EE_Error::add_error( |
|
249 | - sprintf( |
|
250 | - __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
251 | - '<br/>', |
|
252 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
253 | - ), |
|
254 | - __FILE__, __FUNCTION__, __LINE__ |
|
255 | - ); |
|
256 | - } |
|
257 | - } else { |
|
258 | - //that's actually pretty ok. The IPN just wasn't able |
|
259 | - //to identify which transaction or payment method this was for |
|
260 | - // give all active payment methods a chance to claim it |
|
261 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
262 | - foreach ($active_payment_methods as $active_payment_method) { |
|
263 | - try { |
|
264 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
265 | - $payment_method = $active_payment_method; |
|
266 | - EEM_Change_Log::instance()->log( |
|
267 | - EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
268 | - ); |
|
269 | - break; |
|
270 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
271 | - EEM_Change_Log::instance()->log( |
|
272 | - EEM_Change_Log::type_gateway, |
|
273 | - array( |
|
274 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
275 | - 'current_url' => EEH_URL::current_url(), |
|
276 | - 'payment' => $e->getPaymentProperties(), |
|
277 | - 'IPN_data' => $e->getIpnData(), |
|
278 | - ), |
|
279 | - $obj_for_log |
|
280 | - ); |
|
281 | - return $e->getPayment(); |
|
282 | - } catch (EE_Error $e) { |
|
283 | - //that's fine- it apparently couldn't handle the IPN |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
287 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
288 | - if ($payment instanceof EE_Payment) { |
|
289 | - $payment->save(); |
|
290 | - // update the TXN |
|
291 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
292 | - } else { |
|
293 | - //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
294 | - if ($payment_method) { |
|
295 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
296 | - } elseif ($transaction) { |
|
297 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
298 | - } |
|
299 | - } |
|
300 | - return $payment; |
|
301 | - } catch (EE_Error $e) { |
|
302 | - do_action( |
|
303 | - 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
304 | - __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
305 | - print_r($transaction, true), |
|
306 | - print_r($_req_data, true), |
|
307 | - $e->getMessage() |
|
308 | - ) |
|
309 | - ); |
|
310 | - throw $e; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * Removes any non-printable illegal characters from the input, |
|
318 | - * which might cause a raucous when trying to insert into the database |
|
319 | - * |
|
320 | - * @param array $request_data |
|
321 | - * @return array |
|
322 | - */ |
|
323 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
324 | - { |
|
325 | - $return_data = array(); |
|
326 | - foreach ($request_data as $key => $value) { |
|
327 | - $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
328 | - } |
|
329 | - return $return_data; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Removes any non-printable illegal characters from the input, |
|
336 | - * which might cause a raucous when trying to insert into the database |
|
337 | - * |
|
338 | - * @param string $request_data |
|
339 | - * @return string |
|
340 | - */ |
|
341 | - protected function _remove_unusable_characters($request_data) |
|
342 | - { |
|
343 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * Should be called just before displaying the payment attempt results to the user, |
|
350 | - * when the payment attempt has finished. Some payment methods may have special |
|
351 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
352 | - * and then the user is redirected to a page that displays the payment's status, this |
|
353 | - * should be called while loading the page that displays the payment's status. If the user is |
|
354 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
355 | - * provider. |
|
356 | - * |
|
357 | - * @param EE_Transaction|int $transaction |
|
358 | - * @param bool $update_txn whether or not to call |
|
359 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
360 | - * @throws \EE_Error |
|
361 | - * @return EE_Payment |
|
362 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
363 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
364 | - */ |
|
365 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
366 | - { |
|
367 | - /** @var $transaction EE_Transaction */ |
|
368 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
369 | - $last_payment_method = $transaction->payment_method(); |
|
370 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
371 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
372 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
373 | - return $payment; |
|
374 | - } else { |
|
375 | - return null; |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
383 | - * |
|
384 | - * @param EE_Payment_Method $payment_method |
|
385 | - * @param EE_Payment $payment_to_refund |
|
386 | - * @param array $refund_info |
|
387 | - * @return EE_Payment |
|
388 | - * @throws \EE_Error |
|
389 | - */ |
|
390 | - public function process_refund( |
|
391 | - EE_Payment_Method $payment_method, |
|
392 | - EE_Payment $payment_to_refund, |
|
393 | - $refund_info = array() |
|
394 | - ) { |
|
395 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
396 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
397 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
398 | - } |
|
399 | - return $payment_to_refund; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * This should be called each time there may have been an update to a |
|
406 | - * payment on a transaction (ie, we asked for a payment to process a |
|
407 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
408 | - * we told a payment method to |
|
409 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
410 | - * process a refund. This should handle firing the correct hooks to |
|
411 | - * indicate |
|
412 | - * what exactly happened and updating the transaction appropriately). This |
|
413 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
414 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
415 | - * of transactions and payments, and to be tied to payment processing. |
|
416 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
417 | - * of previous code to decide whether or not to save (because the payment passed into |
|
418 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
419 | - * in which case we only want that payment object for some temporary usage during this request, |
|
420 | - * but we don't want it to be saved). |
|
421 | - * |
|
422 | - * @param EE_Transaction|int $transaction |
|
423 | - * @param EE_Payment $payment |
|
424 | - * @param boolean $update_txn |
|
425 | - * whether or not to call |
|
426 | - * EE_Transaction_Processor:: |
|
427 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
428 | - * (you can save 1 DB query if you know you're going |
|
429 | - * to save it later instead) |
|
430 | - * @param bool $IPN |
|
431 | - * if processing IPNs or other similar payment |
|
432 | - * related activities that occur in alternate |
|
433 | - * requests than the main one that is processing the |
|
434 | - * TXN, then set this to true to check whether the |
|
435 | - * TXN is locked before updating |
|
436 | - * @throws \EE_Error |
|
437 | - */ |
|
438 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
439 | - { |
|
440 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
441 | - /** @type EE_Transaction $transaction */ |
|
442 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
443 | - // can we freely update the TXN at this moment? |
|
444 | - if ($IPN && $transaction->is_locked()) { |
|
445 | - // don't update the transaction at this exact moment |
|
446 | - // because the TXN is active in another request |
|
447 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
448 | - time(), |
|
449 | - $transaction->ID(), |
|
450 | - $payment->ID() |
|
451 | - ); |
|
452 | - } else { |
|
453 | - // verify payment and that it has been saved |
|
454 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
455 | - if ( |
|
456 | - $payment->payment_method() instanceof EE_Payment_Method |
|
457 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
458 | - ) { |
|
459 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
460 | - // update TXN registrations with payment info |
|
461 | - $this->process_registration_payments($transaction, $payment); |
|
462 | - } |
|
463 | - $do_action = $payment->just_approved() |
|
464 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
465 | - : $do_action; |
|
466 | - } else { |
|
467 | - // send out notifications |
|
468 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
469 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
470 | - } |
|
471 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
472 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
473 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
474 | - // set new value for total paid |
|
475 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
476 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
477 | - if ($update_txn) { |
|
478 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
479 | - } |
|
480 | - } |
|
481 | - // granular hook for others to use. |
|
482 | - do_action($do_action, $transaction, $payment); |
|
483 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
484 | - //global hook for others to use. |
|
485 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
493 | - * |
|
494 | - * @param EE_Transaction $transaction |
|
495 | - * @param EE_Payment $payment |
|
496 | - * @param EE_Registration[] $registrations |
|
497 | - * @throws \EE_Error |
|
498 | - */ |
|
499 | - public function process_registration_payments( |
|
500 | - EE_Transaction $transaction, |
|
501 | - EE_Payment $payment, |
|
502 | - $registrations = array() |
|
503 | - ) { |
|
504 | - // only process if payment was successful |
|
505 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
506 | - return; |
|
507 | - } |
|
508 | - //EEM_Registration::instance()->show_next_x_db_queries(); |
|
509 | - if (empty($registrations)) { |
|
510 | - // find registrations with monies owing that can receive a payment |
|
511 | - $registrations = $transaction->registrations( |
|
512 | - array( |
|
513 | - array( |
|
514 | - // only these reg statuses can receive payments |
|
515 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
516 | - 'REG_final_price' => array('!=', 0), |
|
517 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
518 | - ), |
|
519 | - ) |
|
520 | - ); |
|
521 | - } |
|
522 | - // still nothing ??!?? |
|
523 | - if (empty($registrations)) { |
|
524 | - return; |
|
525 | - } |
|
526 | - // todo: break out the following logic into a separate strategy class |
|
527 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
528 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
529 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
530 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
531 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
532 | - $refund = $payment->is_a_refund(); |
|
533 | - // how much is available to apply to registrations? |
|
534 | - $available_payment_amount = abs($payment->amount()); |
|
535 | - foreach ($registrations as $registration) { |
|
536 | - if ($registration instanceof EE_Registration) { |
|
537 | - // nothing left? |
|
538 | - if ($available_payment_amount <= 0) { |
|
539 | - break; |
|
540 | - } |
|
541 | - if ($refund) { |
|
542 | - $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
543 | - } else { |
|
544 | - $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
545 | - } |
|
546 | - } |
|
547 | - } |
|
548 | - if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
549 | - EE_Error::add_attention( |
|
550 | - sprintf( |
|
551 | - __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
552 | - 'event_espresso'), |
|
553 | - EEH_Template::format_currency($available_payment_amount), |
|
554 | - implode(', ', array_keys($registrations)), |
|
555 | - '<br/>', |
|
556 | - EEH_Template::format_currency($payment->amount()) |
|
557 | - ), |
|
558 | - __FILE__, __FUNCTION__, __LINE__ |
|
559 | - ); |
|
560 | - } |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * update registration REG_paid field after successful payment and link registration with payment |
|
567 | - * |
|
568 | - * @param EE_Registration $registration |
|
569 | - * @param EE_Payment $payment |
|
570 | - * @param float $available_payment_amount |
|
571 | - * @return float |
|
572 | - * @throws \EE_Error |
|
573 | - */ |
|
574 | - public function process_registration_payment( |
|
575 | - EE_Registration $registration, |
|
576 | - EE_Payment $payment, |
|
577 | - $available_payment_amount = 0.00 |
|
578 | - ) { |
|
579 | - $owing = $registration->final_price() - $registration->paid(); |
|
580 | - if ($owing > 0) { |
|
581 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
582 | - $payment_amount = min($available_payment_amount, $owing); |
|
583 | - // update $available_payment_amount |
|
584 | - $available_payment_amount -= $payment_amount; |
|
585 | - //calculate and set new REG_paid |
|
586 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
587 | - // now save it |
|
588 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
589 | - } |
|
590 | - return $available_payment_amount; |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * update registration REG_paid field after successful payment and link registration with payment |
|
597 | - * |
|
598 | - * @param EE_Registration $registration |
|
599 | - * @param EE_Payment $payment |
|
600 | - * @param float $payment_amount |
|
601 | - * @return void |
|
602 | - * @throws \EE_Error |
|
603 | - */ |
|
604 | - protected function _apply_registration_payment( |
|
605 | - EE_Registration $registration, |
|
606 | - EE_Payment $payment, |
|
607 | - $payment_amount = 0.00 |
|
608 | - ) { |
|
609 | - // find any existing reg payment records for this registration and payment |
|
610 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
611 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
612 | - ); |
|
613 | - // if existing registration payment exists |
|
614 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
615 | - // then update that record |
|
616 | - $existing_reg_payment->set_amount($payment_amount); |
|
617 | - $existing_reg_payment->save(); |
|
618 | - } else { |
|
619 | - // or add new relation between registration and payment and set amount |
|
620 | - $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
621 | - // make it stick |
|
622 | - $registration->save(); |
|
623 | - } |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * update registration REG_paid field after refund and link registration with payment |
|
630 | - * |
|
631 | - * @param EE_Registration $registration |
|
632 | - * @param EE_Payment $payment |
|
633 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
634 | - * @return float |
|
635 | - * @throws \EE_Error |
|
636 | - */ |
|
637 | - public function process_registration_refund( |
|
638 | - EE_Registration $registration, |
|
639 | - EE_Payment $payment, |
|
640 | - $available_refund_amount = 0.00 |
|
641 | - ) { |
|
642 | - //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
643 | - if ($registration->paid() > 0) { |
|
644 | - // ensure $available_refund_amount is NOT negative |
|
645 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
646 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
647 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
648 | - // update $available_payment_amount |
|
649 | - $available_refund_amount -= $refund_amount; |
|
650 | - //calculate and set new REG_paid |
|
651 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
652 | - // convert payment amount back to a negative value for storage in the db |
|
653 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
654 | - // now save it |
|
655 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
656 | - } |
|
657 | - return $available_refund_amount; |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * Process payments and transaction after payment process completed. |
|
664 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
665 | - * if this request happens to be processing an IPN, |
|
666 | - * then we will also set the Payment Options Reg Step to completed, |
|
667 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
668 | - * |
|
669 | - * @param EE_Transaction $transaction |
|
670 | - * @param EE_Payment $payment |
|
671 | - * @param bool $IPN |
|
672 | - * @throws \EE_Error |
|
673 | - */ |
|
674 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
675 | - { |
|
676 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
677 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
678 | - // is the Payment Options Reg Step completed ? |
|
679 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
680 | - // if the Payment Options Reg Step is completed... |
|
681 | - $revisit = $payment_options_step_completed === true ? true : false; |
|
682 | - // then this is kinda sorta a revisit with regards to payments at least |
|
683 | - $transaction_processor->set_revisit($revisit); |
|
684 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
685 | - if ( |
|
686 | - $IPN |
|
687 | - && $payment_options_step_completed !== true |
|
688 | - && ($payment->is_approved() || $payment->is_pending()) |
|
689 | - ) { |
|
690 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
691 | - 'payment_options' |
|
692 | - ); |
|
693 | - } |
|
694 | - // maybe update status, but don't save transaction just yet |
|
695 | - $transaction->update_status_based_on_total_paid(false); |
|
696 | - // check if 'finalize_registration' step has been completed... |
|
697 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
698 | - // if this is an IPN and the final step has not been initiated |
|
699 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
700 | - // and if it hasn't already been set as being started... |
|
701 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
702 | - } |
|
703 | - $transaction->save(); |
|
704 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
705 | - if ($IPN && $finalized !== false) { |
|
706 | - // and if we are all good to go, then send out notifications |
|
707 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
708 | - //ok, now process the transaction according to the payment |
|
709 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
710 | - } |
|
711 | - // DEBUG LOG |
|
712 | - $payment_method = $payment->payment_method(); |
|
713 | - if ($payment_method instanceof EE_Payment_Method) { |
|
714 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
715 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
716 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
717 | - if ($gateway instanceof EE_Gateway) { |
|
718 | - $gateway->log( |
|
719 | - array( |
|
720 | - 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
721 | - 'transaction' => $transaction->model_field_array(), |
|
722 | - 'finalized' => $finalized, |
|
723 | - 'IPN' => $IPN, |
|
724 | - 'deliver_notifications' => has_filter( |
|
725 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
726 | - ), |
|
727 | - ), |
|
728 | - $payment |
|
729 | - ); |
|
730 | - } |
|
731 | - } |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * Force posts to PayPal to use TLS v1.2. See: |
|
739 | - * https://core.trac.wordpress.org/ticket/36320 |
|
740 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
741 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
742 | - * This will affect paypal standard, pro, express, and payflow. |
|
743 | - */ |
|
744 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
745 | - { |
|
746 | - if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
747 | - //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
748 | - //instead of the constant because it might not be defined |
|
749 | - curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
750 | - } |
|
751 | - } |
|
19 | + /** |
|
20 | + * @var EE_Payment_Processor $_instance |
|
21 | + * @access private |
|
22 | + */ |
|
23 | + private static $_instance; |
|
24 | + |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @singleton method used to instantiate class object |
|
29 | + * @access public |
|
30 | + * @return EE_Payment_Processor instance |
|
31 | + */ |
|
32 | + public static function instance() |
|
33 | + { |
|
34 | + // check if class object is instantiated |
|
35 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
36 | + self::$_instance = new self(); |
|
37 | + } |
|
38 | + return self::$_instance; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + *private constructor to prevent direct creation |
|
45 | + * |
|
46 | + * @Constructor |
|
47 | + * @access private |
|
48 | + */ |
|
49 | + private function __construct() |
|
50 | + { |
|
51 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
52 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
59 | + * appropriately. Saves the payment that is generated |
|
60 | + * |
|
61 | + * @param EE_Payment_Method $payment_method |
|
62 | + * @param EE_Transaction $transaction |
|
63 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
64 | + * Leave null if payment is for the full amount owing |
|
65 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
66 | + * Receive_form_submission() should have |
|
67 | + * already been called on the billing form |
|
68 | + * (ie, its inputs should have their normalized values set). |
|
69 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
70 | + * where to go AFTER the offsite gateway |
|
71 | + * @param string $method like 'CART', indicates who the client who called this was |
|
72 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
73 | + * @param boolean $update_txn whether or not to call |
|
74 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
75 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
76 | + * @return \EE_Payment |
|
77 | + * @throws \EE_Error |
|
78 | + */ |
|
79 | + public function process_payment( |
|
80 | + EE_Payment_Method $payment_method, |
|
81 | + EE_Transaction $transaction, |
|
82 | + $amount = null, |
|
83 | + $billing_form = null, |
|
84 | + $return_url = null, |
|
85 | + $method = 'CART', |
|
86 | + $by_admin = false, |
|
87 | + $update_txn = true, |
|
88 | + $cancel_url = '' |
|
89 | + ) { |
|
90 | + if ((float)$amount < 0) { |
|
91 | + throw new EE_Error( |
|
92 | + sprintf( |
|
93 | + __( |
|
94 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
95 | + 'event_espresso' |
|
96 | + ), |
|
97 | + $amount, |
|
98 | + $transaction->ID() |
|
99 | + ) |
|
100 | + ); |
|
101 | + } |
|
102 | + // verify payment method |
|
103 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
104 | + // verify transaction |
|
105 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
106 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
107 | + // verify payment method type |
|
108 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
109 | + $payment = $payment_method->type_obj()->process_payment( |
|
110 | + $transaction, |
|
111 | + min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
112 | + $billing_form, |
|
113 | + $return_url, |
|
114 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
115 | + $method, |
|
116 | + $by_admin |
|
117 | + ); |
|
118 | + // check if payment method uses an off-site gateway |
|
119 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
120 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
121 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
122 | + } |
|
123 | + return $payment; |
|
124 | + } else { |
|
125 | + EE_Error::add_error( |
|
126 | + sprintf( |
|
127 | + __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
128 | + '<br/>', |
|
129 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
130 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
131 | + ); |
|
132 | + return null; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @param EE_Transaction|int $transaction |
|
140 | + * @param EE_Payment_Method $payment_method |
|
141 | + * @throws EE_Error |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
145 | + { |
|
146 | + /** @type \EE_Transaction $transaction */ |
|
147 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
148 | + $primary_reg = $transaction->primary_registration(); |
|
149 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
150 | + throw new EE_Error( |
|
151 | + sprintf( |
|
152 | + __( |
|
153 | + "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
154 | + "event_espresso" |
|
155 | + ), |
|
156 | + $transaction->ID() |
|
157 | + ) |
|
158 | + ); |
|
159 | + } |
|
160 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
161 | + $url = add_query_arg( |
|
162 | + array( |
|
163 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
164 | + 'ee_payment_method' => $payment_method->slug(), |
|
165 | + ), |
|
166 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
167 | + ); |
|
168 | + return $url; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
175 | + * we can easily find what registration the IPN is for and what payment method. |
|
176 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
177 | + * If a payment is found for the IPN info, it is saved. |
|
178 | + * |
|
179 | + * @param array $_req_data eg $_REQUEST |
|
180 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
181 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
182 | + * @param boolean $update_txn whether or not to call |
|
183 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
184 | + * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
185 | + * or is processed manually ( false like Mijireh ) |
|
186 | + * @throws EE_Error |
|
187 | + * @throws Exception |
|
188 | + * @return EE_Payment |
|
189 | + */ |
|
190 | + public function process_ipn( |
|
191 | + $_req_data, |
|
192 | + $transaction = null, |
|
193 | + $payment_method = null, |
|
194 | + $update_txn = true, |
|
195 | + $separate_IPN_request = true |
|
196 | + ) { |
|
197 | + EE_Registry::instance()->load_model('Change_Log'); |
|
198 | + $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
199 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
200 | + $obj_for_log = null; |
|
201 | + if ($transaction instanceof EE_Transaction) { |
|
202 | + $obj_for_log = $transaction; |
|
203 | + if ($payment_method instanceof EE_Payment_Method) { |
|
204 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
205 | + array( |
|
206 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
207 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
208 | + ) |
|
209 | + ); |
|
210 | + } |
|
211 | + } else if ($payment_method instanceof EE_Payment) { |
|
212 | + $obj_for_log = $payment_method; |
|
213 | + } |
|
214 | + $log = EEM_Change_Log::instance()->log( |
|
215 | + EEM_Change_Log::type_gateway, |
|
216 | + array('IPN data received' => $_req_data), |
|
217 | + $obj_for_log |
|
218 | + ); |
|
219 | + try { |
|
220 | + /** |
|
221 | + * @var EE_Payment $payment |
|
222 | + */ |
|
223 | + $payment = null; |
|
224 | + if ($transaction && $payment_method) { |
|
225 | + /** @type EE_Transaction $transaction */ |
|
226 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
227 | + /** @type EE_Payment_Method $payment_method */ |
|
228 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
229 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
230 | + try { |
|
231 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
232 | + $log->set_object($payment); |
|
233 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
234 | + EEM_Change_Log::instance()->log( |
|
235 | + EEM_Change_Log::type_gateway, |
|
236 | + array( |
|
237 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
238 | + 'current_url' => EEH_URL::current_url(), |
|
239 | + 'payment' => $e->getPaymentProperties(), |
|
240 | + 'IPN_data' => $e->getIpnData(), |
|
241 | + ), |
|
242 | + $obj_for_log |
|
243 | + ); |
|
244 | + return $e->getPayment(); |
|
245 | + } |
|
246 | + } else { |
|
247 | + // not a payment |
|
248 | + EE_Error::add_error( |
|
249 | + sprintf( |
|
250 | + __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
251 | + '<br/>', |
|
252 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
253 | + ), |
|
254 | + __FILE__, __FUNCTION__, __LINE__ |
|
255 | + ); |
|
256 | + } |
|
257 | + } else { |
|
258 | + //that's actually pretty ok. The IPN just wasn't able |
|
259 | + //to identify which transaction or payment method this was for |
|
260 | + // give all active payment methods a chance to claim it |
|
261 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
262 | + foreach ($active_payment_methods as $active_payment_method) { |
|
263 | + try { |
|
264 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
265 | + $payment_method = $active_payment_method; |
|
266 | + EEM_Change_Log::instance()->log( |
|
267 | + EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
268 | + ); |
|
269 | + break; |
|
270 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
271 | + EEM_Change_Log::instance()->log( |
|
272 | + EEM_Change_Log::type_gateway, |
|
273 | + array( |
|
274 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
275 | + 'current_url' => EEH_URL::current_url(), |
|
276 | + 'payment' => $e->getPaymentProperties(), |
|
277 | + 'IPN_data' => $e->getIpnData(), |
|
278 | + ), |
|
279 | + $obj_for_log |
|
280 | + ); |
|
281 | + return $e->getPayment(); |
|
282 | + } catch (EE_Error $e) { |
|
283 | + //that's fine- it apparently couldn't handle the IPN |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
288 | + if ($payment instanceof EE_Payment) { |
|
289 | + $payment->save(); |
|
290 | + // update the TXN |
|
291 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
292 | + } else { |
|
293 | + //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
294 | + if ($payment_method) { |
|
295 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
296 | + } elseif ($transaction) { |
|
297 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
298 | + } |
|
299 | + } |
|
300 | + return $payment; |
|
301 | + } catch (EE_Error $e) { |
|
302 | + do_action( |
|
303 | + 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
304 | + __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
305 | + print_r($transaction, true), |
|
306 | + print_r($_req_data, true), |
|
307 | + $e->getMessage() |
|
308 | + ) |
|
309 | + ); |
|
310 | + throw $e; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * Removes any non-printable illegal characters from the input, |
|
318 | + * which might cause a raucous when trying to insert into the database |
|
319 | + * |
|
320 | + * @param array $request_data |
|
321 | + * @return array |
|
322 | + */ |
|
323 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
324 | + { |
|
325 | + $return_data = array(); |
|
326 | + foreach ($request_data as $key => $value) { |
|
327 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
328 | + } |
|
329 | + return $return_data; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Removes any non-printable illegal characters from the input, |
|
336 | + * which might cause a raucous when trying to insert into the database |
|
337 | + * |
|
338 | + * @param string $request_data |
|
339 | + * @return string |
|
340 | + */ |
|
341 | + protected function _remove_unusable_characters($request_data) |
|
342 | + { |
|
343 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * Should be called just before displaying the payment attempt results to the user, |
|
350 | + * when the payment attempt has finished. Some payment methods may have special |
|
351 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
352 | + * and then the user is redirected to a page that displays the payment's status, this |
|
353 | + * should be called while loading the page that displays the payment's status. If the user is |
|
354 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
355 | + * provider. |
|
356 | + * |
|
357 | + * @param EE_Transaction|int $transaction |
|
358 | + * @param bool $update_txn whether or not to call |
|
359 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
360 | + * @throws \EE_Error |
|
361 | + * @return EE_Payment |
|
362 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
363 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
364 | + */ |
|
365 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
366 | + { |
|
367 | + /** @var $transaction EE_Transaction */ |
|
368 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
369 | + $last_payment_method = $transaction->payment_method(); |
|
370 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
371 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
372 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
373 | + return $payment; |
|
374 | + } else { |
|
375 | + return null; |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
383 | + * |
|
384 | + * @param EE_Payment_Method $payment_method |
|
385 | + * @param EE_Payment $payment_to_refund |
|
386 | + * @param array $refund_info |
|
387 | + * @return EE_Payment |
|
388 | + * @throws \EE_Error |
|
389 | + */ |
|
390 | + public function process_refund( |
|
391 | + EE_Payment_Method $payment_method, |
|
392 | + EE_Payment $payment_to_refund, |
|
393 | + $refund_info = array() |
|
394 | + ) { |
|
395 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
396 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
397 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
398 | + } |
|
399 | + return $payment_to_refund; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * This should be called each time there may have been an update to a |
|
406 | + * payment on a transaction (ie, we asked for a payment to process a |
|
407 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
408 | + * we told a payment method to |
|
409 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
410 | + * process a refund. This should handle firing the correct hooks to |
|
411 | + * indicate |
|
412 | + * what exactly happened and updating the transaction appropriately). This |
|
413 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
414 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
415 | + * of transactions and payments, and to be tied to payment processing. |
|
416 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
417 | + * of previous code to decide whether or not to save (because the payment passed into |
|
418 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
419 | + * in which case we only want that payment object for some temporary usage during this request, |
|
420 | + * but we don't want it to be saved). |
|
421 | + * |
|
422 | + * @param EE_Transaction|int $transaction |
|
423 | + * @param EE_Payment $payment |
|
424 | + * @param boolean $update_txn |
|
425 | + * whether or not to call |
|
426 | + * EE_Transaction_Processor:: |
|
427 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
428 | + * (you can save 1 DB query if you know you're going |
|
429 | + * to save it later instead) |
|
430 | + * @param bool $IPN |
|
431 | + * if processing IPNs or other similar payment |
|
432 | + * related activities that occur in alternate |
|
433 | + * requests than the main one that is processing the |
|
434 | + * TXN, then set this to true to check whether the |
|
435 | + * TXN is locked before updating |
|
436 | + * @throws \EE_Error |
|
437 | + */ |
|
438 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
439 | + { |
|
440 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
441 | + /** @type EE_Transaction $transaction */ |
|
442 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
443 | + // can we freely update the TXN at this moment? |
|
444 | + if ($IPN && $transaction->is_locked()) { |
|
445 | + // don't update the transaction at this exact moment |
|
446 | + // because the TXN is active in another request |
|
447 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
448 | + time(), |
|
449 | + $transaction->ID(), |
|
450 | + $payment->ID() |
|
451 | + ); |
|
452 | + } else { |
|
453 | + // verify payment and that it has been saved |
|
454 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
455 | + if ( |
|
456 | + $payment->payment_method() instanceof EE_Payment_Method |
|
457 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
458 | + ) { |
|
459 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
460 | + // update TXN registrations with payment info |
|
461 | + $this->process_registration_payments($transaction, $payment); |
|
462 | + } |
|
463 | + $do_action = $payment->just_approved() |
|
464 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
465 | + : $do_action; |
|
466 | + } else { |
|
467 | + // send out notifications |
|
468 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
469 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
470 | + } |
|
471 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
472 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
473 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
474 | + // set new value for total paid |
|
475 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
476 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
477 | + if ($update_txn) { |
|
478 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
479 | + } |
|
480 | + } |
|
481 | + // granular hook for others to use. |
|
482 | + do_action($do_action, $transaction, $payment); |
|
483 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
484 | + //global hook for others to use. |
|
485 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
493 | + * |
|
494 | + * @param EE_Transaction $transaction |
|
495 | + * @param EE_Payment $payment |
|
496 | + * @param EE_Registration[] $registrations |
|
497 | + * @throws \EE_Error |
|
498 | + */ |
|
499 | + public function process_registration_payments( |
|
500 | + EE_Transaction $transaction, |
|
501 | + EE_Payment $payment, |
|
502 | + $registrations = array() |
|
503 | + ) { |
|
504 | + // only process if payment was successful |
|
505 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
506 | + return; |
|
507 | + } |
|
508 | + //EEM_Registration::instance()->show_next_x_db_queries(); |
|
509 | + if (empty($registrations)) { |
|
510 | + // find registrations with monies owing that can receive a payment |
|
511 | + $registrations = $transaction->registrations( |
|
512 | + array( |
|
513 | + array( |
|
514 | + // only these reg statuses can receive payments |
|
515 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
516 | + 'REG_final_price' => array('!=', 0), |
|
517 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
518 | + ), |
|
519 | + ) |
|
520 | + ); |
|
521 | + } |
|
522 | + // still nothing ??!?? |
|
523 | + if (empty($registrations)) { |
|
524 | + return; |
|
525 | + } |
|
526 | + // todo: break out the following logic into a separate strategy class |
|
527 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
528 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
529 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
530 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
531 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
532 | + $refund = $payment->is_a_refund(); |
|
533 | + // how much is available to apply to registrations? |
|
534 | + $available_payment_amount = abs($payment->amount()); |
|
535 | + foreach ($registrations as $registration) { |
|
536 | + if ($registration instanceof EE_Registration) { |
|
537 | + // nothing left? |
|
538 | + if ($available_payment_amount <= 0) { |
|
539 | + break; |
|
540 | + } |
|
541 | + if ($refund) { |
|
542 | + $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
543 | + } else { |
|
544 | + $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
545 | + } |
|
546 | + } |
|
547 | + } |
|
548 | + if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
549 | + EE_Error::add_attention( |
|
550 | + sprintf( |
|
551 | + __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
552 | + 'event_espresso'), |
|
553 | + EEH_Template::format_currency($available_payment_amount), |
|
554 | + implode(', ', array_keys($registrations)), |
|
555 | + '<br/>', |
|
556 | + EEH_Template::format_currency($payment->amount()) |
|
557 | + ), |
|
558 | + __FILE__, __FUNCTION__, __LINE__ |
|
559 | + ); |
|
560 | + } |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * update registration REG_paid field after successful payment and link registration with payment |
|
567 | + * |
|
568 | + * @param EE_Registration $registration |
|
569 | + * @param EE_Payment $payment |
|
570 | + * @param float $available_payment_amount |
|
571 | + * @return float |
|
572 | + * @throws \EE_Error |
|
573 | + */ |
|
574 | + public function process_registration_payment( |
|
575 | + EE_Registration $registration, |
|
576 | + EE_Payment $payment, |
|
577 | + $available_payment_amount = 0.00 |
|
578 | + ) { |
|
579 | + $owing = $registration->final_price() - $registration->paid(); |
|
580 | + if ($owing > 0) { |
|
581 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
582 | + $payment_amount = min($available_payment_amount, $owing); |
|
583 | + // update $available_payment_amount |
|
584 | + $available_payment_amount -= $payment_amount; |
|
585 | + //calculate and set new REG_paid |
|
586 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
587 | + // now save it |
|
588 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
589 | + } |
|
590 | + return $available_payment_amount; |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * update registration REG_paid field after successful payment and link registration with payment |
|
597 | + * |
|
598 | + * @param EE_Registration $registration |
|
599 | + * @param EE_Payment $payment |
|
600 | + * @param float $payment_amount |
|
601 | + * @return void |
|
602 | + * @throws \EE_Error |
|
603 | + */ |
|
604 | + protected function _apply_registration_payment( |
|
605 | + EE_Registration $registration, |
|
606 | + EE_Payment $payment, |
|
607 | + $payment_amount = 0.00 |
|
608 | + ) { |
|
609 | + // find any existing reg payment records for this registration and payment |
|
610 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
611 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
612 | + ); |
|
613 | + // if existing registration payment exists |
|
614 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
615 | + // then update that record |
|
616 | + $existing_reg_payment->set_amount($payment_amount); |
|
617 | + $existing_reg_payment->save(); |
|
618 | + } else { |
|
619 | + // or add new relation between registration and payment and set amount |
|
620 | + $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
621 | + // make it stick |
|
622 | + $registration->save(); |
|
623 | + } |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * update registration REG_paid field after refund and link registration with payment |
|
630 | + * |
|
631 | + * @param EE_Registration $registration |
|
632 | + * @param EE_Payment $payment |
|
633 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
634 | + * @return float |
|
635 | + * @throws \EE_Error |
|
636 | + */ |
|
637 | + public function process_registration_refund( |
|
638 | + EE_Registration $registration, |
|
639 | + EE_Payment $payment, |
|
640 | + $available_refund_amount = 0.00 |
|
641 | + ) { |
|
642 | + //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
643 | + if ($registration->paid() > 0) { |
|
644 | + // ensure $available_refund_amount is NOT negative |
|
645 | + $available_refund_amount = (float)abs($available_refund_amount); |
|
646 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
647 | + $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
648 | + // update $available_payment_amount |
|
649 | + $available_refund_amount -= $refund_amount; |
|
650 | + //calculate and set new REG_paid |
|
651 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
652 | + // convert payment amount back to a negative value for storage in the db |
|
653 | + $refund_amount = (float)abs($refund_amount) * -1; |
|
654 | + // now save it |
|
655 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
656 | + } |
|
657 | + return $available_refund_amount; |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * Process payments and transaction after payment process completed. |
|
664 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
665 | + * if this request happens to be processing an IPN, |
|
666 | + * then we will also set the Payment Options Reg Step to completed, |
|
667 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
668 | + * |
|
669 | + * @param EE_Transaction $transaction |
|
670 | + * @param EE_Payment $payment |
|
671 | + * @param bool $IPN |
|
672 | + * @throws \EE_Error |
|
673 | + */ |
|
674 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
675 | + { |
|
676 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
677 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
678 | + // is the Payment Options Reg Step completed ? |
|
679 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
680 | + // if the Payment Options Reg Step is completed... |
|
681 | + $revisit = $payment_options_step_completed === true ? true : false; |
|
682 | + // then this is kinda sorta a revisit with regards to payments at least |
|
683 | + $transaction_processor->set_revisit($revisit); |
|
684 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
685 | + if ( |
|
686 | + $IPN |
|
687 | + && $payment_options_step_completed !== true |
|
688 | + && ($payment->is_approved() || $payment->is_pending()) |
|
689 | + ) { |
|
690 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
691 | + 'payment_options' |
|
692 | + ); |
|
693 | + } |
|
694 | + // maybe update status, but don't save transaction just yet |
|
695 | + $transaction->update_status_based_on_total_paid(false); |
|
696 | + // check if 'finalize_registration' step has been completed... |
|
697 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
698 | + // if this is an IPN and the final step has not been initiated |
|
699 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
700 | + // and if it hasn't already been set as being started... |
|
701 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
702 | + } |
|
703 | + $transaction->save(); |
|
704 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
705 | + if ($IPN && $finalized !== false) { |
|
706 | + // and if we are all good to go, then send out notifications |
|
707 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
708 | + //ok, now process the transaction according to the payment |
|
709 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
710 | + } |
|
711 | + // DEBUG LOG |
|
712 | + $payment_method = $payment->payment_method(); |
|
713 | + if ($payment_method instanceof EE_Payment_Method) { |
|
714 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
715 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
716 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
717 | + if ($gateway instanceof EE_Gateway) { |
|
718 | + $gateway->log( |
|
719 | + array( |
|
720 | + 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
721 | + 'transaction' => $transaction->model_field_array(), |
|
722 | + 'finalized' => $finalized, |
|
723 | + 'IPN' => $IPN, |
|
724 | + 'deliver_notifications' => has_filter( |
|
725 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
726 | + ), |
|
727 | + ), |
|
728 | + $payment |
|
729 | + ); |
|
730 | + } |
|
731 | + } |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * Force posts to PayPal to use TLS v1.2. See: |
|
739 | + * https://core.trac.wordpress.org/ticket/36320 |
|
740 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
741 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
742 | + * This will affect paypal standard, pro, express, and payflow. |
|
743 | + */ |
|
744 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
745 | + { |
|
746 | + if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
747 | + //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
748 | + //instead of the constant because it might not be defined |
|
749 | + curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
750 | + } |
|
751 | + } |
|
752 | 752 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | * allows gateways to be used by different systems other than Event Espresso |
7 | 7 | */ |
8 | -interface EEI_Payment extends EEI_Base{ |
|
8 | +interface EEI_Payment extends EEI_Base { |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * @return string indicating which the payment is approved, pending, cancelled or failed |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * Interface EEI_Payment_Method |
155 | 155 | */ |
156 | -interface EEI_Payment_Method{ |
|
156 | +interface EEI_Payment_Method { |
|
157 | 157 | |
158 | 158 | } |
159 | 159 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param string $model_name |
173 | 173 | * @return EE_Log |
174 | 174 | */ |
175 | - public function gateway_log($message,$id,$model_name); |
|
175 | + public function gateway_log($message, $id, $model_name); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 |
@@ -44,77 +44,76 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected $_image_url; |
46 | 46 | |
47 | - /** |
|
48 | - * gateway URL variable |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_base_gateway_url = ''; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * EEG_Paypal_Express constructor. |
|
58 | - */ |
|
59 | - public function __construct() |
|
60 | - { |
|
61 | - $this->_currencies_supported = array( |
|
62 | - 'USD', |
|
63 | - 'AUD', |
|
64 | - 'BRL', |
|
65 | - 'CAD', |
|
66 | - 'CZK', |
|
67 | - 'DKK', |
|
68 | - 'EUR', |
|
69 | - 'HKD', |
|
70 | - 'HUF', |
|
71 | - 'ILS', |
|
72 | - 'JPY', |
|
73 | - 'MYR', |
|
74 | - 'MXN', |
|
75 | - 'NOK', |
|
76 | - 'NZD', |
|
77 | - 'PHP', |
|
78 | - 'PLN', |
|
79 | - 'GBP', |
|
80 | - 'RUB', |
|
81 | - 'SGD', |
|
82 | - 'SEK', |
|
83 | - 'CHF', |
|
84 | - 'TWD', |
|
85 | - 'THB', |
|
86 | - 'TRY' |
|
87 | - ); |
|
88 | - parent::__construct(); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
47 | + /** |
|
48 | + * gateway URL variable |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_base_gateway_url = ''; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * EEG_Paypal_Express constructor. |
|
58 | + */ |
|
59 | + public function __construct() |
|
60 | + { |
|
61 | + $this->_currencies_supported = array( |
|
62 | + 'USD', |
|
63 | + 'AUD', |
|
64 | + 'BRL', |
|
65 | + 'CAD', |
|
66 | + 'CZK', |
|
67 | + 'DKK', |
|
68 | + 'EUR', |
|
69 | + 'HKD', |
|
70 | + 'HUF', |
|
71 | + 'ILS', |
|
72 | + 'JPY', |
|
73 | + 'MYR', |
|
74 | + 'MXN', |
|
75 | + 'NOK', |
|
76 | + 'NZD', |
|
77 | + 'PHP', |
|
78 | + 'PLN', |
|
79 | + 'GBP', |
|
80 | + 'RUB', |
|
81 | + 'SGD', |
|
82 | + 'SEK', |
|
83 | + 'CHF', |
|
84 | + 'TWD', |
|
85 | + 'THB', |
|
86 | + 'TRY' |
|
87 | + ); |
|
88 | + parent::__construct(); |
|
89 | + } |
|
90 | + |
|
95 | 91 | |
92 | + |
|
93 | + /** |
|
94 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
96 | 95 | * |
97 | 96 | *@param array $settings_array |
98 | 97 | */ |
99 | 98 | public function set_settings( $settings_array ) { |
100 | 99 | parent::set_settings($settings_array); |
101 | 100 | // Redirect URL. |
102 | - $this->_base_gateway_url = $this->_debug_mode |
|
103 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
104 | - : 'https://api-3t.paypal.com/nvp'; |
|
101 | + $this->_base_gateway_url = $this->_debug_mode |
|
102 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
103 | + : 'https://api-3t.paypal.com/nvp'; |
|
105 | 104 | } |
106 | 105 | |
107 | 106 | |
108 | 107 | |
109 | - /** |
|
110 | - * @param EEI_Payment $payment |
|
111 | - * @param array $billing_info |
|
112 | - * @param string $return_url |
|
113 | - * @param string $notify_url |
|
114 | - * @param string $cancel_url |
|
115 | - * @return \EE_Payment|\EEI_Payment |
|
116 | - * @throws \EE_Error |
|
117 | - */ |
|
108 | + /** |
|
109 | + * @param EEI_Payment $payment |
|
110 | + * @param array $billing_info |
|
111 | + * @param string $return_url |
|
112 | + * @param string $notify_url |
|
113 | + * @param string $cancel_url |
|
114 | + * @return \EE_Payment|\EEI_Payment |
|
115 | + * @throws \EE_Error |
|
116 | + */ |
|
118 | 117 | public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) { |
119 | 118 | if ( ! $payment instanceof EEI_Payment ) { |
120 | 119 | $payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) ); |
@@ -202,9 +201,9 @@ discard block |
||
202 | 201 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
203 | 202 | // Item quantity. |
204 | 203 | $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
205 | - // Digital item is sold. |
|
206 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
207 | - $item_num++; |
|
204 | + // Digital item is sold. |
|
205 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
206 | + $item_num++; |
|
208 | 207 | } |
209 | 208 | } else { |
210 | 209 | // Just one Item. |
@@ -272,7 +271,6 @@ discard block |
||
272 | 271 | |
273 | 272 | |
274 | 273 | /** |
275 | - |
|
276 | 274 | * @param array $update_info { |
277 | 275 | * @type string $gateway_txn_id |
278 | 276 | * @type string status an EEMI_Payment status |
@@ -292,8 +290,8 @@ discard block |
||
292 | 290 | return $payment; |
293 | 291 | } |
294 | 292 | $primary_registrant = $transaction->primary_registration(); |
295 | - $payment_details = $payment->details(); |
|
296 | - // Check if we still have the token. |
|
293 | + $payment_details = $payment->details(); |
|
294 | + // Check if we still have the token. |
|
297 | 295 | if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) { |
298 | 296 | $payment->set_status( $this->_pay_model->failed_status() ); |
299 | 297 | return $payment; |
@@ -402,36 +400,36 @@ discard block |
||
402 | 400 | */ |
403 | 401 | public function _ppExpress_check_response( $request_response ) { |
404 | 402 | if (empty($request_response['body']) || is_wp_error( $request_response ) ) { |
405 | - // If we got here then there was an error in this request. |
|
406 | - return array('status' => false, 'args' => $request_response); |
|
407 | - } |
|
408 | - $response_args = array(); |
|
409 | - parse_str( urldecode($request_response['body']), $response_args ); |
|
410 | - if ( ! isset($response_args['ACK'])) { |
|
411 | - return array('status' => false, 'args' => $request_response); |
|
412 | - } |
|
413 | - if ( |
|
414 | - $response_args['ACK'] === 'Success' |
|
415 | - && ( |
|
416 | - isset($response_args['PAYERID']) |
|
417 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
418 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
419 | - || isset($response_args['TOKEN']) |
|
420 | - ) |
|
421 | - ) { |
|
422 | - // Response status OK, return response parameters for further processing. |
|
423 | - return array('status' => true, 'args' => $response_args); |
|
424 | - } else { |
|
425 | - $errors = $this->_get_errors($response_args); |
|
426 | - return array('status' => false, 'args' => $errors); |
|
427 | - } |
|
403 | + // If we got here then there was an error in this request. |
|
404 | + return array('status' => false, 'args' => $request_response); |
|
405 | + } |
|
406 | + $response_args = array(); |
|
407 | + parse_str( urldecode($request_response['body']), $response_args ); |
|
408 | + if ( ! isset($response_args['ACK'])) { |
|
409 | + return array('status' => false, 'args' => $request_response); |
|
410 | + } |
|
411 | + if ( |
|
412 | + $response_args['ACK'] === 'Success' |
|
413 | + && ( |
|
414 | + isset($response_args['PAYERID']) |
|
415 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
416 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
417 | + || isset($response_args['TOKEN']) |
|
418 | + ) |
|
419 | + ) { |
|
420 | + // Response status OK, return response parameters for further processing. |
|
421 | + return array('status' => true, 'args' => $response_args); |
|
422 | + } else { |
|
423 | + $errors = $this->_get_errors($response_args); |
|
424 | + return array('status' => false, 'args' => $errors); |
|
425 | + } |
|
428 | 426 | } |
429 | 427 | |
430 | 428 | |
431 | 429 | /** |
432 | - * Log a "Cleared" request. |
|
433 | - * |
|
434 | - * @param array $request |
|
430 | + * Log a "Cleared" request. |
|
431 | + * |
|
432 | + * @param array $request |
|
435 | 433 | * @param EEI_Payment $payment |
436 | 434 | * @param string $info |
437 | 435 | * @return void |
@@ -454,17 +452,17 @@ discard block |
||
454 | 452 | $n = 0; |
455 | 453 | while ( isset($data_array["L_ERRORCODE{$n}"]) ) { |
456 | 454 | $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
457 | - ? $data_array["L_ERRORCODE{$n}"] |
|
458 | - : ''; |
|
455 | + ? $data_array["L_ERRORCODE{$n}"] |
|
456 | + : ''; |
|
459 | 457 | $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
460 | - ? $data_array["L_SEVERITYCODE{$n}"] |
|
461 | - : ''; |
|
458 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
459 | + : ''; |
|
462 | 460 | $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
463 | - ? $data_array["L_SHORTMESSAGE{$n}"] |
|
464 | - : ''; |
|
461 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
462 | + : ''; |
|
465 | 463 | $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
466 | - ? $data_array["L_LONGMESSAGE{$n}"] |
|
467 | - : ''; |
|
464 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
465 | + : ''; |
|
468 | 466 | |
469 | 467 | if ( $n === 0 ) { |
470 | 468 | $errors = array( |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('NO direct script access allowed'); } |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * ---------------------------------------------- |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | *@param array $settings_array |
98 | 98 | */ |
99 | - public function set_settings( $settings_array ) { |
|
99 | + public function set_settings($settings_array) { |
|
100 | 100 | parent::set_settings($settings_array); |
101 | 101 | // Redirect URL. |
102 | 102 | $this->_base_gateway_url = $this->_debug_mode |
@@ -115,19 +115,19 @@ discard block |
||
115 | 115 | * @return \EE_Payment|\EEI_Payment |
116 | 116 | * @throws \EE_Error |
117 | 117 | */ |
118 | - public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) { |
|
119 | - if ( ! $payment instanceof EEI_Payment ) { |
|
120 | - $payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) ); |
|
121 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
118 | + public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) { |
|
119 | + if ( ! $payment instanceof EEI_Payment) { |
|
120 | + $payment->set_gateway_response(__('Error. No associated payment was found.', 'event_espresso')); |
|
121 | + $payment->set_status($this->_pay_model->failed_status()); |
|
122 | 122 | return $payment; |
123 | 123 | } |
124 | 124 | $transaction = $payment->transaction(); |
125 | - if ( ! $transaction instanceof EEI_Transaction ) { |
|
126 | - $payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
|
127 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
125 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
126 | + $payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso')); |
|
127 | + $payment->set_status($this->_pay_model->failed_status()); |
|
128 | 128 | return $payment; |
129 | 129 | } |
130 | - $order_description = substr( $this->_format_order_description($payment), 0, 127 ); |
|
130 | + $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
131 | 131 | $primary_registration = $transaction->primary_registration(); |
132 | 132 | $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false; |
133 | 133 | $locale = explode('-', get_bloginfo('language')); |
@@ -141,37 +141,37 @@ discard block |
||
141 | 141 | 'RETURNURL' => $return_url, |
142 | 142 | 'CANCELURL' => $cancel_url, |
143 | 143 | 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
144 | - 'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
|
145 | - 'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this |
|
144 | + 'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
|
145 | + 'BUTTONSOURCE' => 'EventEspresso_SP', //EE will blow up if you change this |
|
146 | 146 | 'LOCALECODE' => $locale[1] // Locale of the pages displayed by PayPal during Express Checkout. |
147 | 147 | ); |
148 | 148 | |
149 | 149 | // Show itemized list. |
150 | - if ( $this->_money->compare_floats( $payment->amount(), $transaction->total(), '==' ) ) { |
|
150 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
151 | 151 | $item_num = 0; |
152 | 152 | $itemized_sum = 0; |
153 | 153 | $total_line_items = $transaction->total_line_item(); |
154 | 154 | // Go through each item in the list. |
155 | - foreach ( $total_line_items->get_items() as $line_item ) { |
|
156 | - if ( $line_item instanceof EE_Line_Item ) { |
|
155 | + foreach ($total_line_items->get_items() as $line_item) { |
|
156 | + if ($line_item instanceof EE_Line_Item) { |
|
157 | 157 | // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
158 | - if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) { |
|
158 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
159 | 159 | continue; |
160 | 160 | } |
161 | 161 | |
162 | 162 | $unit_price = $line_item->unit_price(); |
163 | 163 | $line_item_quantity = $line_item->quantity(); |
164 | 164 | // This is a discount. |
165 | - if ( $line_item->is_percent() ) { |
|
165 | + if ($line_item->is_percent()) { |
|
166 | 166 | $unit_price = $line_item->total(); |
167 | 167 | $line_item_quantity = 1; |
168 | 168 | } |
169 | 169 | // Item Name. |
170 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name( $line_item, $payment), 0, 127); |
|
170 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name($line_item, $payment), 0, 127); |
|
171 | 171 | // Item description. |
172 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc( $line_item, $payment), 0, 127); |
|
172 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc($line_item, $payment), 0, 127); |
|
173 | 173 | // Cost of individual item. |
174 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price ); |
|
174 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price); |
|
175 | 175 | // Item Number. |
176 | 176 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
177 | 177 | // Item quantity. |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
189 | 189 | $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
190 | 190 | |
191 | - $itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 ); |
|
191 | + $itemized_sum_diff_from_txn_total = round($transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2); |
|
192 | 192 | // If we were not able to recognize some item like promotion, surcharge or cancellation, |
193 | 193 | // add the difference as an extra line item. |
194 | - if ( $this->_money->compare_floats( $itemized_sum_diff_from_txn_total, 0, '!=' ) ) { |
|
194 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
195 | 195 | // Item Name. |
196 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 ); |
|
196 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr(__('Other (promotion/surcharge/cancellation)', 'event_espresso'), 0, 127); |
|
197 | 197 | // Item description. |
198 | 198 | $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
199 | 199 | // Cost of individual item. |
200 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total ); |
|
200 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total); |
|
201 | 201 | // Item Number. |
202 | 202 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
203 | 203 | // Item quantity. |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | } else { |
210 | 210 | // Just one Item. |
211 | 211 | // Item Name. |
212 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( $this->_format_partial_payment_line_item_name($payment), 0, 127 ); |
|
212 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr($this->_format_partial_payment_line_item_name($payment), 0, 127); |
|
213 | 213 | // Item description. |
214 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( $this->_format_partial_payment_line_item_desc($payment), 0, 127 ); |
|
214 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr($this->_format_partial_payment_line_item_desc($payment), 0, 127); |
|
215 | 215 | // Cost of individual item. |
216 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() ); |
|
216 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount()); |
|
217 | 217 | // Item Number. |
218 | 218 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
219 | 219 | // Item quantity. |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | // Digital item is sold. |
222 | 222 | $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
223 | 223 | // Item's sales S/H and tax amount. |
224 | - $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() ); |
|
224 | + $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount()); |
|
225 | 225 | $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
226 | 226 | $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
227 | 227 | $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
228 | 228 | } |
229 | 229 | // Automatically filling out shipping and contact information. |
230 | - if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) { |
|
231 | - $token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
230 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
231 | + $token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
232 | 232 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
233 | 233 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
234 | 234 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
@@ -237,34 +237,34 @@ discard block |
||
237 | 237 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
238 | 238 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
239 | 239 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
240 | - } elseif ( ! $this->_request_shipping_addr ) { |
|
240 | + } elseif ( ! $this->_request_shipping_addr) { |
|
241 | 241 | // Do not request shipping details on the PP Checkout page. |
242 | 242 | $token_request_dtls['NOSHIPPING'] = '1'; |
243 | 243 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
244 | 244 | |
245 | 245 | } |
246 | 246 | // Used a business/personal logo on the PayPal page. |
247 | - if ( ! empty($this->_image_url) ) { |
|
247 | + if ( ! empty($this->_image_url)) { |
|
248 | 248 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
249 | 249 | } |
250 | 250 | // Request PayPal token. |
251 | - $token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment ); |
|
252 | - $token_rstatus = $this->_ppExpress_check_response( $token_request_response ); |
|
253 | - $response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array(); |
|
254 | - if ( $token_rstatus['status'] ) { |
|
251 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
252 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
253 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) ? $token_rstatus['args'] : array(); |
|
254 | + if ($token_rstatus['status']) { |
|
255 | 255 | // We got the Token so we may continue with the payment and redirect the client. |
256 | - $payment->set_details( $response_args ); |
|
256 | + $payment->set_details($response_args); |
|
257 | 257 | |
258 | 258 | $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
259 | - $payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] ); |
|
259 | + $payment->set_redirect_url($gateway_url.'/checkoutnow?useraction=commit&cmd=_express-checkout&token='.$response_args['TOKEN']); |
|
260 | 260 | } else { |
261 | - if ( isset($response_args['L_ERRORCODE']) ) { |
|
262 | - $payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] ); |
|
261 | + if (isset($response_args['L_ERRORCODE'])) { |
|
262 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
263 | 263 | } else { |
264 | - $payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) ); |
|
264 | + $payment->set_gateway_response(__('Error occurred while trying to setup the Express Checkout.', 'event_espresso')); |
|
265 | 265 | } |
266 | - $payment->set_details( $response_args ); |
|
267 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
266 | + $payment->set_details($response_args); |
|
267 | + $payment->set_status($this->_pay_model->failed_status()); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | return $payment; |
@@ -280,22 +280,22 @@ discard block |
||
280 | 280 | * @param EEI_Transaction $transaction |
281 | 281 | * @return EEI_Payment |
282 | 282 | */ |
283 | - public function handle_payment_update( $update_info, $transaction ) { |
|
283 | + public function handle_payment_update($update_info, $transaction) { |
|
284 | 284 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
285 | 285 | |
286 | - if ( $payment instanceof EEI_Payment ) { |
|
287 | - $this->log( array( 'Return from Authorization' => $update_info ), $payment ); |
|
286 | + if ($payment instanceof EEI_Payment) { |
|
287 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
288 | 288 | $transaction = $payment->transaction(); |
289 | - if ( ! $transaction instanceof EEI_Transaction ) { |
|
290 | - $payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
|
291 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
289 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
290 | + $payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso')); |
|
291 | + $payment->set_status($this->_pay_model->failed_status()); |
|
292 | 292 | return $payment; |
293 | 293 | } |
294 | 294 | $primary_registrant = $transaction->primary_registration(); |
295 | 295 | $payment_details = $payment->details(); |
296 | 296 | // Check if we still have the token. |
297 | - if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) { |
|
298 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
297 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
298 | + $payment->set_status($this->_pay_model->failed_status()); |
|
299 | 299 | return $payment; |
300 | 300 | } |
301 | 301 | |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | 'TOKEN' => $payment_details['TOKEN'] |
305 | 305 | ); |
306 | 306 | // Request Customer Details. |
307 | - $cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment ); |
|
308 | - $cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response ); |
|
309 | - $cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : array(); |
|
310 | - if ( $cdetails_rstatus['status'] ) { |
|
307 | + $cdetails_request_response = $this->_ppExpress_request($cdetails_request_dtls, 'Customer Details', $payment); |
|
308 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
309 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) ? $cdetails_rstatus['args'] : array(); |
|
310 | + if ($cdetails_rstatus['status']) { |
|
311 | 311 | // We got the PayerID so now we can Complete the transaction. |
312 | 312 | $docheckout_request_dtls = array( |
313 | 313 | 'METHOD' => 'DoExpressCheckoutPayment', |
@@ -318,39 +318,39 @@ discard block |
||
318 | 318 | 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code() |
319 | 319 | ); |
320 | 320 | // Payment Checkout/Capture. |
321 | - $docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment ); |
|
322 | - $docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response ); |
|
323 | - $docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array(); |
|
324 | - if ( $docheckout_rstatus['status'] ) { |
|
321 | + $docheckout_request_response = $this->_ppExpress_request($docheckout_request_dtls, 'Do Payment', $payment); |
|
322 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
323 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) ? $docheckout_rstatus['args'] : array(); |
|
324 | + if ($docheckout_rstatus['status']) { |
|
325 | 325 | // All is well, payment approved. |
326 | 326 | $primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : ''; |
327 | - $payment->set_extra_accntng( $primary_registration_code ); |
|
328 | - $payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0 ); |
|
329 | - $payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null ); |
|
330 | - $payment->set_details( $cdata_response_args ); |
|
331 | - $payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' ); |
|
332 | - $payment->set_status( $this->_pay_model->approved_status() ); |
|
327 | + $payment->set_extra_accntng($primary_registration_code); |
|
328 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0); |
|
329 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null); |
|
330 | + $payment->set_details($cdata_response_args); |
|
331 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : ''); |
|
332 | + $payment->set_status($this->_pay_model->approved_status()); |
|
333 | 333 | } else { |
334 | - if ( isset($docheckout_response_args['L_ERRORCODE']) ) { |
|
335 | - $payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] ); |
|
334 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
335 | + $payment->set_gateway_response($docheckout_response_args['L_ERRORCODE'].'; '.$docheckout_response_args['L_SHORTMESSAGE']); |
|
336 | 336 | } else { |
337 | - $payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) ); |
|
337 | + $payment->set_gateway_response(__('Error occurred while trying to Capture the funds.', 'event_espresso')); |
|
338 | 338 | } |
339 | - $payment->set_details( $docheckout_response_args ); |
|
340 | - $payment->set_status( $this->_pay_model->declined_status() ); |
|
339 | + $payment->set_details($docheckout_response_args); |
|
340 | + $payment->set_status($this->_pay_model->declined_status()); |
|
341 | 341 | } |
342 | 342 | } else { |
343 | - if ( isset($cdata_response_args['L_ERRORCODE']) ) { |
|
344 | - $payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] ); |
|
343 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
344 | + $payment->set_gateway_response($cdata_response_args['L_ERRORCODE'].'; '.$cdata_response_args['L_SHORTMESSAGE']); |
|
345 | 345 | } else { |
346 | - $payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) ); |
|
346 | + $payment->set_gateway_response(__('Error occurred while trying to get payment Details from PayPal.', 'event_espresso')); |
|
347 | 347 | } |
348 | - $payment->set_details( $cdata_response_args ); |
|
349 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
348 | + $payment->set_details($cdata_response_args); |
|
349 | + $payment->set_status($this->_pay_model->failed_status()); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) ); |
|
353 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
352 | + $payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso')); |
|
353 | + $payment->set_status($this->_pay_model->failed_status()); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | return $payment; |
@@ -365,16 +365,16 @@ discard block |
||
365 | 365 | * @param EEI_Payment $payment |
366 | 366 | * @return mixed |
367 | 367 | */ |
368 | - public function _ppExpress_request( $request_params, $request_text, $payment ) { |
|
368 | + public function _ppExpress_request($request_params, $request_text, $payment) { |
|
369 | 369 | $request_dtls = array( |
370 | 370 | 'VERSION' => '204.0', |
371 | - 'USER' => urlencode( $this->_api_username ), |
|
372 | - 'PWD' => urlencode( $this->_api_password ), |
|
373 | - 'SIGNATURE' => urlencode( $this->_api_signature ) |
|
371 | + 'USER' => urlencode($this->_api_username), |
|
372 | + 'PWD' => urlencode($this->_api_password), |
|
373 | + 'SIGNATURE' => urlencode($this->_api_signature) |
|
374 | 374 | ); |
375 | - $dtls = array_merge( $request_dtls, $request_params ); |
|
375 | + $dtls = array_merge($request_dtls, $request_params); |
|
376 | 376 | |
377 | - $this->_log_clean_request( $dtls, $payment, $request_text . ' Request' ); |
|
377 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
378 | 378 | // Request Customer Details. |
379 | 379 | $request_response = wp_remote_post( |
380 | 380 | $this->_base_gateway_url, |
@@ -384,11 +384,11 @@ discard block |
||
384 | 384 | 'httpversion' => '1.1', |
385 | 385 | 'cookies' => array(), |
386 | 386 | 'headers' => array(), |
387 | - 'body' => http_build_query( $dtls ) |
|
387 | + 'body' => http_build_query($dtls) |
|
388 | 388 | ) |
389 | 389 | ); |
390 | 390 | // Log the response. |
391 | - $this->log( array( $request_text . ' Response' => $request_response), $payment ); |
|
391 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
392 | 392 | |
393 | 393 | return $request_response; |
394 | 394 | } |
@@ -400,13 +400,13 @@ discard block |
||
400 | 400 | * @param mixed $request_response |
401 | 401 | * @return array |
402 | 402 | */ |
403 | - public function _ppExpress_check_response( $request_response ) { |
|
404 | - if (empty($request_response['body']) || is_wp_error( $request_response ) ) { |
|
403 | + public function _ppExpress_check_response($request_response) { |
|
404 | + if (empty($request_response['body']) || is_wp_error($request_response)) { |
|
405 | 405 | // If we got here then there was an error in this request. |
406 | 406 | return array('status' => false, 'args' => $request_response); |
407 | 407 | } |
408 | 408 | $response_args = array(); |
409 | - parse_str( urldecode($request_response['body']), $response_args ); |
|
409 | + parse_str(urldecode($request_response['body']), $response_args); |
|
410 | 410 | if ( ! isset($response_args['ACK'])) { |
411 | 411 | return array('status' => false, 'args' => $request_response); |
412 | 412 | } |
@@ -436,10 +436,10 @@ discard block |
||
436 | 436 | * @param string $info |
437 | 437 | * @return void |
438 | 438 | */ |
439 | - private function _log_clean_request($request, $payment, $info ) { |
|
439 | + private function _log_clean_request($request, $payment, $info) { |
|
440 | 440 | $cleaned_request_data = $request; |
441 | 441 | unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
442 | - $this->log( array($info => $cleaned_request_data), $payment ); |
|
442 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | * @param array $data_array |
450 | 450 | * @return array |
451 | 451 | */ |
452 | - private function _get_errors( $data_array ) { |
|
452 | + private function _get_errors($data_array) { |
|
453 | 453 | $errors = array(); |
454 | 454 | $n = 0; |
455 | - while ( isset($data_array["L_ERRORCODE{$n}"]) ) { |
|
455 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
456 | 456 | $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
457 | 457 | ? $data_array["L_ERRORCODE{$n}"] |
458 | 458 | : ''; |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | ? $data_array["L_LONGMESSAGE{$n}"] |
467 | 467 | : ''; |
468 | 468 | |
469 | - if ( $n === 0 ) { |
|
469 | + if ($n === 0) { |
|
470 | 470 | $errors = array( |
471 | 471 | 'L_ERRORCODE' => $l_error_code, |
472 | 472 | 'L_SHORTMESSAGE' => $l_short_message, |
@@ -474,10 +474,10 @@ discard block |
||
474 | 474 | 'L_SEVERITYCODE' => $l_severity_code |
475 | 475 | ); |
476 | 476 | } else { |
477 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
478 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
479 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
480 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
477 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
478 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
479 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
480 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | $n++; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -14,1218 +14,1218 @@ discard block |
||
14 | 14 | class EED_Ticket_Selector extends EED_Module |
15 | 15 | { |
16 | 16 | |
17 | - const debug = false; // true false |
|
18 | - |
|
19 | - /** |
|
20 | - * event that ticket selector is being generated for |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @var \EE_Event |
|
24 | - */ |
|
25 | - protected static $_event; |
|
26 | - |
|
27 | - /** |
|
28 | - * array of datetimes and the spaces available for them |
|
29 | - * |
|
30 | - * @access private |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - private static $_available_spaces = array(); |
|
34 | - |
|
35 | - /** |
|
36 | - * max attendees that can register for event at one time |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - private static $_max_atndz = EE_INF; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
47 | - * |
|
48 | - * @var bool |
|
49 | - */ |
|
50 | - protected static $_in_iframe = false; |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @return EED_Ticket_Selector |
|
56 | - */ |
|
57 | - public static function instance() |
|
58 | - { |
|
59 | - return parent::get_instance(__CLASS__); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - protected function set_config() |
|
65 | - { |
|
66 | - $this->set_config_section('template_settings'); |
|
67 | - $this->set_config_class('EE_Ticket_Selector_Config'); |
|
68 | - $this->set_config_name('EED_Ticket_Selector'); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
75 | - * |
|
76 | - * @access public |
|
77 | - * @return void |
|
78 | - */ |
|
79 | - public static function set_hooks() |
|
80 | - { |
|
81 | - // routing |
|
82 | - EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector'); |
|
83 | - EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections'); |
|
84 | - EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
|
85 | - add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
86 | - add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
87 | - add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
94 | - * |
|
95 | - * @access public |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - public static function set_hooks_admin() |
|
99 | - { |
|
100 | - add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
101 | - //add button for iframe code to event editor. |
|
102 | - add_filter('get_sample_permalink_html', array('EED_Ticket_Selector', 'iframe_code_button'), 10, 2); |
|
103 | - add_action('admin_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets_admin'), 10); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * set_definitions |
|
110 | - * |
|
111 | - * @access public |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - public static function set_definitions() |
|
115 | - { |
|
116 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
117 | - define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
118 | - //if config is not set, initialize |
|
119 | - //If config is not set, set it. |
|
120 | - if (EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector === null) { |
|
121 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = new EE_Ticket_Selector_Config(); |
|
122 | - } |
|
123 | - EE_Registry::$i18n_js_strings['ts_embed_iframe_title'] = __('Copy and Paste the following:', 'event_espresso'); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * gets the ball rolling |
|
130 | - * |
|
131 | - * @access public |
|
132 | - * @param WP $WP |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - public function run($WP) |
|
136 | - { |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * ticket_selector_iframe |
|
143 | - * |
|
144 | - * @access public |
|
145 | - * @return void |
|
146 | - * @throws \EE_Error |
|
147 | - */ |
|
148 | - public function ticket_selector_iframe() |
|
149 | - { |
|
150 | - self::$_in_iframe = true; |
|
151 | - /** @type EEM_Event $EEM_Event */ |
|
152 | - $EEM_Event = EE_Registry::instance()->load_model('Event'); |
|
153 | - $event = $EEM_Event->get_one_by_ID( |
|
154 | - EE_Registry::instance()->REQ->get('event', 0) |
|
155 | - ); |
|
156 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
157 | - $template_args['ticket_selector'] = EED_Ticket_Selector::display_ticket_selector($event); |
|
158 | - $template_args['css'] = apply_filters( |
|
159 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
160 | - array( |
|
161 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_embed.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
162 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
163 | - includes_url('css/dashicons.min.css?ver=' . $GLOBALS['wp_version']), |
|
164 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
165 | - ) |
|
166 | - ); |
|
167 | - EE_Registry::$i18n_js_strings['ticket_selector_iframe'] = true; |
|
168 | - EE_Registry::$i18n_js_strings['EEDTicketSelectorMsg'] = esc_html__('Please choose at least one ticket before continuing.', |
|
169 | - 'event_espresso'); |
|
170 | - $template_args['eei18n'] = apply_filters( |
|
171 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__eei18n_js_strings', |
|
172 | - EE_Registry::localize_i18n_js_strings() |
|
173 | - ); |
|
174 | - $template_args['js'] = apply_filters( |
|
175 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
176 | - array( |
|
177 | - includes_url('js/jquery/jquery.js?ver=' . $GLOBALS['wp_version']), |
|
178 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
179 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_iframe_embed.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
180 | - ) |
|
181 | - ); |
|
182 | - $template_args['notices'] = EEH_Template::display_template( |
|
183 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
184 | - array(), |
|
185 | - true |
|
186 | - ); |
|
187 | - EEH_Template::display_template( |
|
188 | - TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart_iframe.template.php', |
|
189 | - $template_args |
|
190 | - ); |
|
191 | - exit; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * Adds an iframe embed code button to the Event editor. |
|
198 | - * |
|
199 | - * @param string $permalink_string The current html string for the permalink section. |
|
200 | - * @param int $id The post id for the event. |
|
201 | - * @return string The new html string for the permalink area. |
|
202 | - */ |
|
203 | - public static function iframe_code_button($permalink_string, $id ) |
|
204 | - { |
|
205 | - //make sure this is ONLY when editing and the event id has been set. |
|
206 | - if ( ! empty($id)) { |
|
207 | - $post = get_post($id); |
|
208 | - //if NOT event then let's get out. |
|
209 | - if ($post->post_type !== 'espresso_events') { |
|
210 | - return $permalink_string; |
|
211 | - } |
|
212 | - $permalink_string .= '<a id="js-ticket-selector-embed-trigger" class="button button-small" href="#" tabindex="-1">' |
|
213 | - . __('Embed', 'event_espresso') |
|
214 | - . '</a> '; |
|
215 | - $ticket_selector_url = add_query_arg(array('ticket_selector' => 'iframe', 'event' => $id), site_url()); |
|
216 | - $iframe_string = esc_html( |
|
217 | - '<iframe src="' . $ticket_selector_url . '" width="100%" height="100%"></iframe>' |
|
218 | - ); |
|
219 | - $permalink_string .= ' |
|
17 | + const debug = false; // true false |
|
18 | + |
|
19 | + /** |
|
20 | + * event that ticket selector is being generated for |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @var \EE_Event |
|
24 | + */ |
|
25 | + protected static $_event; |
|
26 | + |
|
27 | + /** |
|
28 | + * array of datetimes and the spaces available for them |
|
29 | + * |
|
30 | + * @access private |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + private static $_available_spaces = array(); |
|
34 | + |
|
35 | + /** |
|
36 | + * max attendees that can register for event at one time |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + private static $_max_atndz = EE_INF; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
47 | + * |
|
48 | + * @var bool |
|
49 | + */ |
|
50 | + protected static $_in_iframe = false; |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @return EED_Ticket_Selector |
|
56 | + */ |
|
57 | + public static function instance() |
|
58 | + { |
|
59 | + return parent::get_instance(__CLASS__); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + protected function set_config() |
|
65 | + { |
|
66 | + $this->set_config_section('template_settings'); |
|
67 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
68 | + $this->set_config_name('EED_Ticket_Selector'); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
75 | + * |
|
76 | + * @access public |
|
77 | + * @return void |
|
78 | + */ |
|
79 | + public static function set_hooks() |
|
80 | + { |
|
81 | + // routing |
|
82 | + EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector'); |
|
83 | + EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections'); |
|
84 | + EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
|
85 | + add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
86 | + add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
87 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
94 | + * |
|
95 | + * @access public |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + public static function set_hooks_admin() |
|
99 | + { |
|
100 | + add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
101 | + //add button for iframe code to event editor. |
|
102 | + add_filter('get_sample_permalink_html', array('EED_Ticket_Selector', 'iframe_code_button'), 10, 2); |
|
103 | + add_action('admin_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets_admin'), 10); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * set_definitions |
|
110 | + * |
|
111 | + * @access public |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + public static function set_definitions() |
|
115 | + { |
|
116 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
117 | + define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
118 | + //if config is not set, initialize |
|
119 | + //If config is not set, set it. |
|
120 | + if (EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector === null) { |
|
121 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = new EE_Ticket_Selector_Config(); |
|
122 | + } |
|
123 | + EE_Registry::$i18n_js_strings['ts_embed_iframe_title'] = __('Copy and Paste the following:', 'event_espresso'); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * gets the ball rolling |
|
130 | + * |
|
131 | + * @access public |
|
132 | + * @param WP $WP |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + public function run($WP) |
|
136 | + { |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * ticket_selector_iframe |
|
143 | + * |
|
144 | + * @access public |
|
145 | + * @return void |
|
146 | + * @throws \EE_Error |
|
147 | + */ |
|
148 | + public function ticket_selector_iframe() |
|
149 | + { |
|
150 | + self::$_in_iframe = true; |
|
151 | + /** @type EEM_Event $EEM_Event */ |
|
152 | + $EEM_Event = EE_Registry::instance()->load_model('Event'); |
|
153 | + $event = $EEM_Event->get_one_by_ID( |
|
154 | + EE_Registry::instance()->REQ->get('event', 0) |
|
155 | + ); |
|
156 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
157 | + $template_args['ticket_selector'] = EED_Ticket_Selector::display_ticket_selector($event); |
|
158 | + $template_args['css'] = apply_filters( |
|
159 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
160 | + array( |
|
161 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_embed.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
162 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
163 | + includes_url('css/dashicons.min.css?ver=' . $GLOBALS['wp_version']), |
|
164 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
165 | + ) |
|
166 | + ); |
|
167 | + EE_Registry::$i18n_js_strings['ticket_selector_iframe'] = true; |
|
168 | + EE_Registry::$i18n_js_strings['EEDTicketSelectorMsg'] = esc_html__('Please choose at least one ticket before continuing.', |
|
169 | + 'event_espresso'); |
|
170 | + $template_args['eei18n'] = apply_filters( |
|
171 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__eei18n_js_strings', |
|
172 | + EE_Registry::localize_i18n_js_strings() |
|
173 | + ); |
|
174 | + $template_args['js'] = apply_filters( |
|
175 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
176 | + array( |
|
177 | + includes_url('js/jquery/jquery.js?ver=' . $GLOBALS['wp_version']), |
|
178 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
179 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_iframe_embed.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
180 | + ) |
|
181 | + ); |
|
182 | + $template_args['notices'] = EEH_Template::display_template( |
|
183 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
184 | + array(), |
|
185 | + true |
|
186 | + ); |
|
187 | + EEH_Template::display_template( |
|
188 | + TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart_iframe.template.php', |
|
189 | + $template_args |
|
190 | + ); |
|
191 | + exit; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * Adds an iframe embed code button to the Event editor. |
|
198 | + * |
|
199 | + * @param string $permalink_string The current html string for the permalink section. |
|
200 | + * @param int $id The post id for the event. |
|
201 | + * @return string The new html string for the permalink area. |
|
202 | + */ |
|
203 | + public static function iframe_code_button($permalink_string, $id ) |
|
204 | + { |
|
205 | + //make sure this is ONLY when editing and the event id has been set. |
|
206 | + if ( ! empty($id)) { |
|
207 | + $post = get_post($id); |
|
208 | + //if NOT event then let's get out. |
|
209 | + if ($post->post_type !== 'espresso_events') { |
|
210 | + return $permalink_string; |
|
211 | + } |
|
212 | + $permalink_string .= '<a id="js-ticket-selector-embed-trigger" class="button button-small" href="#" tabindex="-1">' |
|
213 | + . __('Embed', 'event_espresso') |
|
214 | + . '</a> '; |
|
215 | + $ticket_selector_url = add_query_arg(array('ticket_selector' => 'iframe', 'event' => $id), site_url()); |
|
216 | + $iframe_string = esc_html( |
|
217 | + '<iframe src="' . $ticket_selector_url . '" width="100%" height="100%"></iframe>' |
|
218 | + ); |
|
219 | + $permalink_string .= ' |
|
220 | 220 | <div id="js-ts-iframe" style="display:none"> |
221 | 221 | <div style="width:100%; height: 500px;"> |
222 | 222 | ' . $iframe_string . ' |
223 | 223 | </div> |
224 | 224 | </div>'; |
225 | - } |
|
226 | - return $permalink_string; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * finds and sets the EE_Event object for use throughout class |
|
233 | - * |
|
234 | - * @access public |
|
235 | - * @param mixed $event |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - protected static function set_event($event = null) |
|
239 | - { |
|
240 | - if ($event === null) { |
|
241 | - global $post; |
|
242 | - $event = $post; |
|
243 | - } |
|
244 | - if ($event instanceof EE_Event) { |
|
245 | - self::$_event = $event; |
|
246 | - } else if ($event instanceof WP_Post ) { |
|
247 | - if ( isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
248 | - self::$_event = $event->EE_Event; |
|
249 | - } else if ( $event->post_type === 'espresso_events') { |
|
250 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
251 | - self::$_event = $event->EE_Event; |
|
252 | - } |
|
253 | - } else { |
|
254 | - $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
255 | - $dev_msg = $user_msg |
|
256 | - . __('In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
257 | - 'event_espresso'); |
|
258 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
259 | - return false; |
|
260 | - } |
|
261 | - return true; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * creates buttons for selecting number of attendees for an event |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @param EE_Event $event |
|
271 | - * @param bool $view_details |
|
272 | - * @return string |
|
273 | - * @throws \EE_Error |
|
274 | - */ |
|
275 | - public static function display_ticket_selector($event = null, $view_details = false) |
|
276 | - { |
|
277 | - // reset filter for displaying submit button |
|
278 | - remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
279 | - // poke and prod incoming event till it tells us what it is |
|
280 | - if ( ! EED_Ticket_Selector::set_event($event)) { |
|
281 | - return false; |
|
282 | - } |
|
283 | - $event_post = self::$_event instanceof EE_Event ? self::$_event->ID() : $event; |
|
284 | - // grab event status |
|
285 | - $_event_active_status = self::$_event->get_active_status(); |
|
286 | - if ( |
|
287 | - ! is_admin() |
|
288 | - && ( |
|
289 | - ! self::$_event->display_ticket_selector() |
|
290 | - || $view_details |
|
291 | - || post_password_required($event_post) |
|
292 | - || ( |
|
293 | - $_event_active_status !== EE_Datetime::active |
|
294 | - && $_event_active_status !== EE_Datetime::upcoming |
|
295 | - && $_event_active_status !== EE_Datetime::sold_out |
|
296 | - && ! ( |
|
297 | - $_event_active_status === EE_Datetime::inactive |
|
298 | - && is_user_logged_in() |
|
299 | - ) |
|
300 | - ) |
|
301 | - ) |
|
302 | - ) { |
|
303 | - return ! is_single() ? EED_Ticket_Selector::display_view_details_btn() : ''; |
|
304 | - } |
|
305 | - $template_args = array(); |
|
306 | - $template_args['event_status'] = $_event_active_status; |
|
307 | - $template_args['date_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
308 | - get_option('date_format')); |
|
309 | - $template_args['time_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
310 | - get_option('time_format')); |
|
311 | - $template_args['EVT_ID'] = self::$_event->ID(); |
|
312 | - $template_args['event'] = self::$_event; |
|
313 | - // is the event expired ? |
|
314 | - $template_args['event_is_expired'] = self::$_event->is_expired(); |
|
315 | - if ($template_args['event_is_expired']) { |
|
316 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' |
|
317 | - . __('We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
318 | - 'event_espresso') |
|
319 | - . '</span></div>'; |
|
320 | - } |
|
321 | - $ticket_query_args = array( |
|
322 | - array('Datetime.EVT_ID' => self::$_event->ID()), |
|
323 | - 'order_by' => array( |
|
324 | - 'TKT_order' => 'ASC', |
|
325 | - 'TKT_required' => 'DESC', |
|
326 | - 'TKT_start_date' => 'ASC', |
|
327 | - 'TKT_end_date' => 'ASC', |
|
328 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
329 | - ), |
|
330 | - ); |
|
331 | - if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
332 | - //use the correct applicable time query depending on what version of core is being run. |
|
333 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') ? time() |
|
334 | - : current_time('timestamp'); |
|
335 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
336 | - } |
|
337 | - // get all tickets for this event ordered by the datetime |
|
338 | - $template_args['tickets'] = EEM_Ticket::instance()->get_all($ticket_query_args); |
|
339 | - if (count($template_args['tickets']) < 1) { |
|
340 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' |
|
341 | - . __('We\'re sorry, but all ticket sales have ended.', 'event_espresso') |
|
342 | - . '</span></div>'; |
|
343 | - } |
|
344 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
345 | - \EED_Ticket_Selector::$_max_atndz = apply_filters( |
|
346 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
347 | - self::$_event->additional_limit() |
|
348 | - ); |
|
349 | - $template_args['max_atndz'] = \EED_Ticket_Selector::$_max_atndz; |
|
350 | - if ($template_args['max_atndz'] < 1) { |
|
351 | - $sales_closed_msg = __('We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
352 | - 'event_espresso'); |
|
353 | - if (current_user_can('edit_post', self::$_event->ID())) { |
|
354 | - $sales_closed_msg .= sprintf( |
|
355 | - __('%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
356 | - 'event_espresso'), |
|
357 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
358 | - '</b><br />', |
|
359 | - $link = '<span class="edit-link"><a class="post-edit-link" href="' |
|
360 | - . get_edit_post_link(self::$_event->ID()) |
|
361 | - . '">', |
|
362 | - '</a></span></div>' |
|
363 | - ); |
|
364 | - } |
|
365 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
366 | - } |
|
367 | - $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php'; |
|
368 | - $templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
369 | - $templates['ticket_selector'], self::$_event); |
|
370 | - // redirecting to another site for registration ?? |
|
371 | - $external_url = self::$_event->external_url() !== null || self::$_event->external_url() !== '' |
|
372 | - ? self::$_event->external_url() : false; |
|
373 | - // if not redirecting to another site for registration |
|
374 | - if ( ! $external_url) { |
|
375 | - // then display the ticket selector |
|
376 | - $ticket_selector = EEH_Template::locate_template($templates['ticket_selector'], $template_args); |
|
377 | - } else { |
|
378 | - // if not we still need to trigger the display of the submit button |
|
379 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
380 | - //display notice to admin that registration is external |
|
381 | - $ticket_selector = ! is_admin() ? '' |
|
382 | - : __('Registration is at an external URL for this event.', 'event_espresso'); |
|
383 | - } |
|
384 | - // now set up the form (but not for the admin) |
|
385 | - $ticket_selector = ! is_admin() |
|
386 | - ? EED_Ticket_Selector::ticket_selector_form_open( |
|
387 | - self::$_event->ID(), |
|
388 | - $external_url |
|
389 | - ) . $ticket_selector |
|
390 | - : $ticket_selector; |
|
391 | - // submit button and form close tag |
|
392 | - $ticket_selector .= ! is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit($external_url) : ''; |
|
393 | - // set no cache headers and constants |
|
394 | - EE_System::do_not_cache(); |
|
395 | - return $ticket_selector; |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * ticket_selector_form_open |
|
402 | - * |
|
403 | - * @access public |
|
404 | - * @param int $ID |
|
405 | - * @param string $external_url |
|
406 | - * @return string |
|
407 | - */ |
|
408 | - public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
409 | - { |
|
410 | - // if redirecting, we don't need any anything else |
|
411 | - if ($external_url) { |
|
412 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
413 | - // open link in new window ? |
|
414 | - $html .= apply_filters( |
|
415 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
416 | - false |
|
417 | - ) |
|
418 | - ? ' target="_blank"' |
|
419 | - : ''; |
|
420 | - $html .= '>'; |
|
421 | - $query_args = (array)EEH_URL::get_query_string($external_url); |
|
422 | - foreach ($query_args as $query_arg => $value) { |
|
423 | - $html .= ' |
|
225 | + } |
|
226 | + return $permalink_string; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * finds and sets the EE_Event object for use throughout class |
|
233 | + * |
|
234 | + * @access public |
|
235 | + * @param mixed $event |
|
236 | + * @return bool |
|
237 | + */ |
|
238 | + protected static function set_event($event = null) |
|
239 | + { |
|
240 | + if ($event === null) { |
|
241 | + global $post; |
|
242 | + $event = $post; |
|
243 | + } |
|
244 | + if ($event instanceof EE_Event) { |
|
245 | + self::$_event = $event; |
|
246 | + } else if ($event instanceof WP_Post ) { |
|
247 | + if ( isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
248 | + self::$_event = $event->EE_Event; |
|
249 | + } else if ( $event->post_type === 'espresso_events') { |
|
250 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
251 | + self::$_event = $event->EE_Event; |
|
252 | + } |
|
253 | + } else { |
|
254 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
255 | + $dev_msg = $user_msg |
|
256 | + . __('In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
257 | + 'event_espresso'); |
|
258 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
259 | + return false; |
|
260 | + } |
|
261 | + return true; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * creates buttons for selecting number of attendees for an event |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @param EE_Event $event |
|
271 | + * @param bool $view_details |
|
272 | + * @return string |
|
273 | + * @throws \EE_Error |
|
274 | + */ |
|
275 | + public static function display_ticket_selector($event = null, $view_details = false) |
|
276 | + { |
|
277 | + // reset filter for displaying submit button |
|
278 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
279 | + // poke and prod incoming event till it tells us what it is |
|
280 | + if ( ! EED_Ticket_Selector::set_event($event)) { |
|
281 | + return false; |
|
282 | + } |
|
283 | + $event_post = self::$_event instanceof EE_Event ? self::$_event->ID() : $event; |
|
284 | + // grab event status |
|
285 | + $_event_active_status = self::$_event->get_active_status(); |
|
286 | + if ( |
|
287 | + ! is_admin() |
|
288 | + && ( |
|
289 | + ! self::$_event->display_ticket_selector() |
|
290 | + || $view_details |
|
291 | + || post_password_required($event_post) |
|
292 | + || ( |
|
293 | + $_event_active_status !== EE_Datetime::active |
|
294 | + && $_event_active_status !== EE_Datetime::upcoming |
|
295 | + && $_event_active_status !== EE_Datetime::sold_out |
|
296 | + && ! ( |
|
297 | + $_event_active_status === EE_Datetime::inactive |
|
298 | + && is_user_logged_in() |
|
299 | + ) |
|
300 | + ) |
|
301 | + ) |
|
302 | + ) { |
|
303 | + return ! is_single() ? EED_Ticket_Selector::display_view_details_btn() : ''; |
|
304 | + } |
|
305 | + $template_args = array(); |
|
306 | + $template_args['event_status'] = $_event_active_status; |
|
307 | + $template_args['date_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
308 | + get_option('date_format')); |
|
309 | + $template_args['time_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
310 | + get_option('time_format')); |
|
311 | + $template_args['EVT_ID'] = self::$_event->ID(); |
|
312 | + $template_args['event'] = self::$_event; |
|
313 | + // is the event expired ? |
|
314 | + $template_args['event_is_expired'] = self::$_event->is_expired(); |
|
315 | + if ($template_args['event_is_expired']) { |
|
316 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' |
|
317 | + . __('We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
318 | + 'event_espresso') |
|
319 | + . '</span></div>'; |
|
320 | + } |
|
321 | + $ticket_query_args = array( |
|
322 | + array('Datetime.EVT_ID' => self::$_event->ID()), |
|
323 | + 'order_by' => array( |
|
324 | + 'TKT_order' => 'ASC', |
|
325 | + 'TKT_required' => 'DESC', |
|
326 | + 'TKT_start_date' => 'ASC', |
|
327 | + 'TKT_end_date' => 'ASC', |
|
328 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
329 | + ), |
|
330 | + ); |
|
331 | + if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
332 | + //use the correct applicable time query depending on what version of core is being run. |
|
333 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') ? time() |
|
334 | + : current_time('timestamp'); |
|
335 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
336 | + } |
|
337 | + // get all tickets for this event ordered by the datetime |
|
338 | + $template_args['tickets'] = EEM_Ticket::instance()->get_all($ticket_query_args); |
|
339 | + if (count($template_args['tickets']) < 1) { |
|
340 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' |
|
341 | + . __('We\'re sorry, but all ticket sales have ended.', 'event_espresso') |
|
342 | + . '</span></div>'; |
|
343 | + } |
|
344 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
345 | + \EED_Ticket_Selector::$_max_atndz = apply_filters( |
|
346 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
347 | + self::$_event->additional_limit() |
|
348 | + ); |
|
349 | + $template_args['max_atndz'] = \EED_Ticket_Selector::$_max_atndz; |
|
350 | + if ($template_args['max_atndz'] < 1) { |
|
351 | + $sales_closed_msg = __('We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
352 | + 'event_espresso'); |
|
353 | + if (current_user_can('edit_post', self::$_event->ID())) { |
|
354 | + $sales_closed_msg .= sprintf( |
|
355 | + __('%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
356 | + 'event_espresso'), |
|
357 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
358 | + '</b><br />', |
|
359 | + $link = '<span class="edit-link"><a class="post-edit-link" href="' |
|
360 | + . get_edit_post_link(self::$_event->ID()) |
|
361 | + . '">', |
|
362 | + '</a></span></div>' |
|
363 | + ); |
|
364 | + } |
|
365 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
366 | + } |
|
367 | + $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php'; |
|
368 | + $templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
369 | + $templates['ticket_selector'], self::$_event); |
|
370 | + // redirecting to another site for registration ?? |
|
371 | + $external_url = self::$_event->external_url() !== null || self::$_event->external_url() !== '' |
|
372 | + ? self::$_event->external_url() : false; |
|
373 | + // if not redirecting to another site for registration |
|
374 | + if ( ! $external_url) { |
|
375 | + // then display the ticket selector |
|
376 | + $ticket_selector = EEH_Template::locate_template($templates['ticket_selector'], $template_args); |
|
377 | + } else { |
|
378 | + // if not we still need to trigger the display of the submit button |
|
379 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
380 | + //display notice to admin that registration is external |
|
381 | + $ticket_selector = ! is_admin() ? '' |
|
382 | + : __('Registration is at an external URL for this event.', 'event_espresso'); |
|
383 | + } |
|
384 | + // now set up the form (but not for the admin) |
|
385 | + $ticket_selector = ! is_admin() |
|
386 | + ? EED_Ticket_Selector::ticket_selector_form_open( |
|
387 | + self::$_event->ID(), |
|
388 | + $external_url |
|
389 | + ) . $ticket_selector |
|
390 | + : $ticket_selector; |
|
391 | + // submit button and form close tag |
|
392 | + $ticket_selector .= ! is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit($external_url) : ''; |
|
393 | + // set no cache headers and constants |
|
394 | + EE_System::do_not_cache(); |
|
395 | + return $ticket_selector; |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * ticket_selector_form_open |
|
402 | + * |
|
403 | + * @access public |
|
404 | + * @param int $ID |
|
405 | + * @param string $external_url |
|
406 | + * @return string |
|
407 | + */ |
|
408 | + public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
409 | + { |
|
410 | + // if redirecting, we don't need any anything else |
|
411 | + if ($external_url) { |
|
412 | + $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
413 | + // open link in new window ? |
|
414 | + $html .= apply_filters( |
|
415 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
416 | + false |
|
417 | + ) |
|
418 | + ? ' target="_blank"' |
|
419 | + : ''; |
|
420 | + $html .= '>'; |
|
421 | + $query_args = (array)EEH_URL::get_query_string($external_url); |
|
422 | + foreach ($query_args as $query_arg => $value) { |
|
423 | + $html .= ' |
|
424 | 424 | <input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
425 | - } |
|
426 | - return $html; |
|
427 | - } |
|
428 | - // if there is no submit button, then don't start building a form |
|
429 | - // because the "View Details" button will build its own form |
|
430 | - if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
431 | - return ''; |
|
432 | - } |
|
433 | - $checkout_url = EEH_Event_View::event_link_url($ID); |
|
434 | - if ( ! $checkout_url) { |
|
435 | - EE_Error::add_error(__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
436 | - __FILE__, __FUNCTION__, __LINE__); |
|
437 | - } |
|
438 | - $extra_params = self::$_in_iframe ? ' target="_blank"' : ''; |
|
439 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
440 | - $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false); |
|
441 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
442 | - $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, self::$_event); |
|
443 | - return $html; |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * display_ticket_selector_submit |
|
450 | - * |
|
451 | - * @param string $external_url |
|
452 | - * @return string |
|
453 | - * @throws \EE_Error |
|
454 | - */ |
|
455 | - public static function display_ticket_selector_submit($external_url = '') |
|
456 | - { |
|
457 | - $html = ''; |
|
458 | - if ( ! is_admin()) { |
|
459 | - // standard TS displayed with submit button, ie: "Register Now" |
|
460 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
461 | - $html .= \EED_Ticket_Selector::display_register_now_button(); |
|
462 | - $html .= empty($external_url) ? |
|
463 | - \EED_Ticket_Selector::no_tkt_slctr_end_dv() |
|
464 | - : \EED_Ticket_Selector::clear_tkt_slctr(); |
|
465 | - $html .= '<br/>' . \EED_Ticket_Selector::ticket_selector_form_close(); |
|
466 | - } else if ( EED_Ticket_Selector::$_max_atndz === 1 ) { |
|
467 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
468 | - if ( EED_Ticket_Selector::$_event->is_sold_out() ) { |
|
469 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
470 | - $html .= apply_filters( |
|
471 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
472 | - sprintf( |
|
473 | - __( |
|
474 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
475 | - 'event_espresso' |
|
476 | - ), |
|
477 | - '<p class="no-ticket-selector-msg clear-float">', |
|
478 | - EED_Ticket_Selector::$_event->name(), |
|
479 | - '</p>', |
|
480 | - '<br />' |
|
481 | - ), |
|
482 | - EED_Ticket_Selector::$_event |
|
483 | - ); |
|
484 | - if ( |
|
485 | - apply_filters( |
|
486 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
487 | - false, |
|
488 | - EED_Ticket_Selector::$_event |
|
489 | - ) |
|
490 | - ) { |
|
491 | - $html .= \EED_Ticket_Selector::display_register_now_button(); |
|
492 | - } |
|
493 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
494 | - $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv(); |
|
495 | - } else if ( |
|
496 | - apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
497 | - && ! is_single() |
|
498 | - ) { |
|
499 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
500 | - // but no tickets are available, so display event's "View Details" button. |
|
501 | - // it is being viewed via somewhere other than a single post |
|
502 | - $html .= EED_Ticket_Selector::display_view_details_btn(true); |
|
503 | - } |
|
504 | - } else if (is_archive()) { |
|
505 | - // event list, no tickets available so display event's "View Details" button |
|
506 | - $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv(); |
|
507 | - $html .= EED_Ticket_Selector::display_view_details_btn(); |
|
508 | - } else { |
|
509 | - if ( |
|
510 | - apply_filters( |
|
511 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
512 | - false, |
|
513 | - EED_Ticket_Selector::$_event |
|
514 | - ) |
|
515 | - ) { |
|
516 | - $html .= \EED_Ticket_Selector::display_register_now_button(); |
|
517 | - } |
|
518 | - // no submit or view details button, and no additional content |
|
519 | - $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv(); |
|
520 | - } |
|
521 | - if ( ! is_archive()) { |
|
522 | - $html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
523 | - } |
|
524 | - } |
|
525 | - return $html; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * @return string |
|
532 | - */ |
|
533 | - public static function clear_tkt_slctr() |
|
534 | - { |
|
535 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
536 | - return '<div class="clear"></div>'; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @deprecated 4.9.13 |
|
543 | - * @return string |
|
544 | - */ |
|
545 | - public static function tkt_slctr_end_dv() |
|
546 | - { |
|
547 | - return \EED_Ticket_Selector::clear_tkt_slctr(); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * @return string |
|
554 | - */ |
|
555 | - public static function no_tkt_slctr_end_dv() |
|
556 | - { |
|
557 | - // DWMTS event, no TS, appears after a "Register Now" or "view Details" button |
|
558 | - return '<div class="clear"></div></div>'; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * ticket_selector_form_close |
|
565 | - * |
|
566 | - * @access public |
|
567 | - * @access public |
|
568 | - * @return string |
|
569 | - */ |
|
570 | - public static function ticket_selector_form_close() |
|
571 | - { |
|
572 | - return '</form>'; |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * @return string |
|
579 | - * @throws \EE_Error |
|
580 | - */ |
|
581 | - public static function display_register_now_button() |
|
582 | - { |
|
583 | - $btn_text = apply_filters( |
|
584 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
585 | - __('Register Now', 'event_espresso'), |
|
586 | - EED_Ticket_Selector::$_event |
|
587 | - ); |
|
588 | - $external_url = EED_Ticket_Selector::$_event->external_url(); |
|
589 | - $html = '<input id="ticket-selector-submit-' . EED_Ticket_Selector::$_event->ID() . '-btn"'; |
|
590 | - $html .= ' class="ticket-selector-submit-btn '; |
|
591 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
592 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
593 | - $html .= apply_filters( |
|
594 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
595 | - '', |
|
596 | - EED_Ticket_Selector::$_event |
|
597 | - ); |
|
598 | - return $html; |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * display_view_details_btn |
|
604 | - * |
|
605 | - * @access public |
|
606 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
607 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
608 | - * either because they are sold out, expired, or not yet on sale. |
|
609 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
610 | - * @return string |
|
611 | - * @throws \EE_Error |
|
612 | - */ |
|
613 | - public static function display_view_details_btn($DWMTS = false) |
|
614 | - { |
|
615 | - if ( ! self::$_event->get_permalink()) { |
|
616 | - EE_Error::add_error( |
|
617 | - __('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
618 | - __FILE__, __FUNCTION__, __LINE__ |
|
619 | - ); |
|
620 | - } |
|
621 | - $view_details_btn = '<form method="POST" action="'; |
|
622 | - $view_details_btn .= apply_filters( |
|
623 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
624 | - self::$_event->get_permalink(), |
|
625 | - self::$_event |
|
626 | - ); |
|
627 | - $view_details_btn .= '">'; |
|
628 | - $btn_text = apply_filters( |
|
629 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
630 | - __('View Details', 'event_espresso'), |
|
631 | - self::$_event |
|
632 | - ); |
|
633 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
634 | - . self::$_event->ID() |
|
635 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
636 | - . $btn_text |
|
637 | - . '" />'; |
|
638 | - $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', self::$_event); |
|
639 | - if ($DWMTS) { |
|
640 | - $view_details_btn .= \EED_Ticket_Selector::ticket_selector_form_close(); |
|
641 | - $view_details_btn .= \EED_Ticket_Selector::no_tkt_slctr_end_dv(); |
|
642 | - $view_details_btn .= '<br/>'; |
|
643 | - } else { |
|
644 | - $view_details_btn .= \EED_Ticket_Selector::clear_tkt_slctr(); |
|
645 | - $view_details_btn .= '<br/>'; |
|
646 | - $view_details_btn .= \EED_Ticket_Selector::ticket_selector_form_close(); |
|
647 | - } |
|
648 | - return $view_details_btn; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * cancel_ticket_selections |
|
655 | - * |
|
656 | - * @access public |
|
657 | - * @access public |
|
658 | - * @return string |
|
659 | - */ |
|
660 | - public static function cancel_ticket_selections() |
|
661 | - { |
|
662 | - // check nonce |
|
663 | - if ( ! EED_Ticket_Selector::process_ticket_selector_nonce('cancel_ticket_selections')) { |
|
664 | - return false; |
|
665 | - } |
|
666 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
667 | - if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
668 | - wp_safe_redirect( |
|
669 | - EEH_Event_View::event_link_url( |
|
670 | - EE_Registry::instance()->REQ->get('event_id') |
|
671 | - ) |
|
672 | - ); |
|
673 | - } else { |
|
674 | - wp_safe_redirect( |
|
675 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
676 | - ); |
|
677 | - } |
|
678 | - die(); |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * process_ticket_selector_nonce |
|
685 | - * |
|
686 | - * @access public |
|
687 | - * @param string $nonce_name |
|
688 | - * @param string $id |
|
689 | - * @return bool |
|
690 | - */ |
|
691 | - public static function process_ticket_selector_nonce($nonce_name, $id = '') |
|
692 | - { |
|
693 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
694 | - if ( |
|
695 | - ! is_admin() |
|
696 | - && ( |
|
697 | - ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
698 | - || ! wp_verify_nonce( |
|
699 | - EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
700 | - $nonce_name |
|
701 | - ) |
|
702 | - ) |
|
703 | - ) { |
|
704 | - EE_Error::add_error( |
|
705 | - sprintf( |
|
706 | - __( |
|
707 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
708 | - 'event_espresso' |
|
709 | - ), |
|
710 | - '<br/>' |
|
711 | - ), |
|
712 | - __FILE__, |
|
713 | - __FUNCTION__, |
|
714 | - __LINE__ |
|
715 | - ); |
|
716 | - return false; |
|
717 | - } |
|
718 | - return true; |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * process_ticket_selections |
|
725 | - * |
|
726 | - * @access public |
|
727 | - * @return array|boolean |
|
728 | - * @throws \EE_Error |
|
729 | - */ |
|
730 | - public function process_ticket_selections() |
|
731 | - { |
|
732 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
733 | - // do we have an event id? |
|
734 | - if ( ! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
735 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
736 | - EE_Error::add_error( |
|
737 | - sprintf( |
|
738 | - __( |
|
739 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
740 | - 'event_espresso' |
|
741 | - ), |
|
742 | - '<br/>' |
|
743 | - ), |
|
744 | - __FILE__, |
|
745 | - __FUNCTION__, |
|
746 | - __LINE__ |
|
747 | - ); |
|
748 | - } |
|
749 | - //if event id is valid |
|
750 | - $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
751 | - // check nonce |
|
752 | - if ( ! EED_Ticket_Selector::process_ticket_selector_nonce('process_ticket_selections', $id)) { |
|
753 | - return false; |
|
754 | - } |
|
755 | - // d( EE_Registry::instance()->REQ ); |
|
756 | - self::$_available_spaces = array( |
|
757 | - 'tickets' => array(), |
|
758 | - 'datetimes' => array(), |
|
759 | - ); |
|
760 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
761 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
762 | - EE_Registry::instance()->load_core('Session'); |
|
763 | - // unless otherwise requested, clear the session |
|
764 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
765 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
766 | - } |
|
767 | - //d( EE_Registry::instance()->SSN ); |
|
768 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
769 | - // validate/sanitize data |
|
770 | - $valid = self::_validate_post_data($id); |
|
771 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
772 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
773 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
774 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
775 | - //check total tickets ordered vs max number of attendees that can register |
|
776 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
777 | - // ordering too many tickets !!! |
|
778 | - $total_tickets_string = _n('You have attempted to purchase %s ticket.', |
|
779 | - 'You have attempted to purchase %s tickets.', $valid['total_tickets'], 'event_espresso'); |
|
780 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
781 | - // dev only message |
|
782 | - $max_atndz_string = _n('The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
783 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
784 | - $valid['max_atndz'], 'event_espresso'); |
|
785 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
786 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
787 | - } else { |
|
788 | - // all data appears to be valid |
|
789 | - $tckts_slctd = false; |
|
790 | - $tickets_added = 0; |
|
791 | - $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
|
792 | - if ($valid['total_tickets'] > 0) { |
|
793 | - // load cart |
|
794 | - EE_Registry::instance()->load_core('Cart'); |
|
795 | - // cycle thru the number of data rows sent from the event listing |
|
796 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
797 | - // does this row actually contain a ticket quantity? |
|
798 | - if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
799 | - // YES we have a ticket quantity |
|
800 | - $tckts_slctd = true; |
|
801 | - // d( $valid['ticket_obj'][$x] ); |
|
802 | - if ($valid['ticket_obj'][$x] instanceof EE_Ticket) { |
|
803 | - // then add ticket to cart |
|
804 | - $tickets_added += self::_add_ticket_to_cart($valid['ticket_obj'][$x], $valid['qty'][$x]); |
|
805 | - if (EE_Error::has_error()) { |
|
806 | - break; |
|
807 | - } |
|
808 | - } else { |
|
809 | - // nothing added to cart retrieved |
|
810 | - EE_Error::add_error( |
|
811 | - sprintf(__('A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
812 | - 'event_espresso'), '<br/>'), |
|
813 | - __FILE__, __FUNCTION__, __LINE__ |
|
814 | - ); |
|
815 | - } |
|
816 | - } |
|
817 | - } |
|
818 | - } |
|
819 | - do_action( |
|
820 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
821 | - EE_Registry::instance()->CART, |
|
822 | - $this |
|
823 | - ); |
|
824 | - //d( EE_Registry::instance()->CART ); |
|
825 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
826 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
827 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
828 | - do_action( |
|
829 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
830 | - EE_Registry::instance()->CART, |
|
831 | - $this |
|
832 | - ); |
|
833 | - EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
834 | - EE_Registry::instance()->CART->save_cart(false); |
|
835 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
836 | - // just return TRUE for registrations being made from admin |
|
837 | - if (is_admin()) { |
|
838 | - return true; |
|
839 | - } |
|
840 | - EE_Error::get_notices(false, true); |
|
841 | - wp_safe_redirect( |
|
842 | - apply_filters( |
|
843 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
844 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
845 | - ) |
|
846 | - ); |
|
847 | - exit(); |
|
848 | - } else { |
|
849 | - if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
850 | - // nothing added to cart |
|
851 | - EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), __FILE__, |
|
852 | - __FUNCTION__, __LINE__); |
|
853 | - } |
|
854 | - } |
|
855 | - } else { |
|
856 | - // no ticket quantities were selected |
|
857 | - EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
858 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
859 | - } |
|
860 | - } |
|
861 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
862 | - // at this point, just return if registration is being made from admin |
|
863 | - if (is_admin()) { |
|
864 | - return false; |
|
865 | - } |
|
866 | - if ($valid['return_url']) { |
|
867 | - EE_Error::get_notices(false, true); |
|
868 | - wp_safe_redirect($valid['return_url']); |
|
869 | - exit(); |
|
870 | - } elseif (isset($event_to_add['id'])) { |
|
871 | - EE_Error::get_notices(false, true); |
|
872 | - wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
873 | - exit(); |
|
874 | - } else { |
|
875 | - echo EE_Error::get_notices(); |
|
876 | - } |
|
877 | - return false; |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * validate_post_data |
|
884 | - * |
|
885 | - * @access private |
|
886 | - * @param int $id |
|
887 | - * @return array|FALSE |
|
888 | - */ |
|
889 | - private static function _validate_post_data($id = 0) |
|
890 | - { |
|
891 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
892 | - if ( ! $id) { |
|
893 | - EE_Error::add_error( |
|
894 | - __('The event id provided was not valid.', 'event_espresso'), |
|
895 | - __FILE__, |
|
896 | - __FUNCTION__, |
|
897 | - __LINE__ |
|
898 | - ); |
|
899 | - return false; |
|
900 | - } |
|
901 | - // start with an empty array() |
|
902 | - $valid_data = array(); |
|
903 | - // grab valid id |
|
904 | - $valid_data['id'] = $id; |
|
905 | - // grab and sanitize return-url |
|
906 | - $valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-' . $id)); |
|
907 | - // array of other form names |
|
908 | - $inputs_to_clean = array( |
|
909 | - 'event_id' => 'tkt-slctr-event-id', |
|
910 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
911 | - 'rows' => 'tkt-slctr-rows-', |
|
912 | - 'qty' => 'tkt-slctr-qty-', |
|
913 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
914 | - 'return_url' => 'tkt-slctr-return-url-', |
|
915 | - ); |
|
916 | - // let's track the total number of tickets ordered.' |
|
917 | - $valid_data['total_tickets'] = 0; |
|
918 | - // cycle through $inputs_to_clean array |
|
919 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
920 | - // check for POST data |
|
921 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
922 | - // grab value |
|
923 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
924 | - switch ($what) { |
|
925 | - // integers |
|
926 | - case 'event_id': |
|
927 | - $valid_data[$what] = absint($input_value); |
|
928 | - // get event via the event id we put in the form |
|
929 | - $valid_data['event'] = EE_Registry::instance() |
|
930 | - ->load_model('Event') |
|
931 | - ->get_one_by_ID($valid_data['event_id']); |
|
932 | - break; |
|
933 | - case 'rows': |
|
934 | - case 'max_atndz': |
|
935 | - $valid_data[$what] = absint($input_value); |
|
936 | - break; |
|
937 | - // arrays of integers |
|
938 | - case 'qty': |
|
939 | - /** @var array $row_qty */ |
|
940 | - $row_qty = $input_value; |
|
941 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
942 | - if ( ! is_array($row_qty)) { |
|
943 | - // get number of rows |
|
944 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
945 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
946 | - : 1; |
|
947 | - // explode ints by the dash |
|
948 | - $row_qty = explode('-', $row_qty); |
|
949 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
950 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
951 | - $row_qty = array($row => $qty); |
|
952 | - // d( $row_qty ); |
|
953 | - for ($x = 1; $x <= $rows; $x++) { |
|
954 | - if ( ! isset($row_qty[$x])) { |
|
955 | - $row_qty[$x] = 0; |
|
956 | - } |
|
957 | - } |
|
958 | - } |
|
959 | - ksort($row_qty); |
|
960 | - // d( $row_qty ); |
|
961 | - // cycle thru values |
|
962 | - foreach ($row_qty as $qty) { |
|
963 | - $qty = absint($qty); |
|
964 | - // sanitize as integers |
|
965 | - $valid_data[$what][] = $qty; |
|
966 | - $valid_data['total_tickets'] += $qty; |
|
967 | - } |
|
968 | - break; |
|
969 | - // array of integers |
|
970 | - case 'ticket_id': |
|
971 | - $value_array = array(); |
|
972 | - // cycle thru values |
|
973 | - foreach ((array)$input_value as $key => $value) { |
|
974 | - // allow only numbers, letters, spaces, commas and dashes |
|
975 | - $value_array[$key] = wp_strip_all_tags($value); |
|
976 | - // get ticket via the ticket id we put in the form |
|
977 | - $ticket_obj = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
978 | - $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
979 | - } |
|
980 | - $valid_data[$what] = $value_array; |
|
981 | - break; |
|
982 | - case 'return_url' : |
|
983 | - // grab and sanitize return-url |
|
984 | - $valid_data[$what] = esc_url_raw($input_value); |
|
985 | - break; |
|
986 | - } // end switch $what |
|
987 | - } |
|
988 | - } // end foreach $inputs_to_clean |
|
989 | - // d( $valid_data ); |
|
990 | - // die(); |
|
991 | - return $valid_data; |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * adds a ticket to the cart |
|
998 | - * |
|
999 | - * @access private |
|
1000 | - * @param EE_Ticket $ticket |
|
1001 | - * @param int $qty |
|
1002 | - * @return TRUE on success, FALSE on fail |
|
1003 | - * @throws \EE_Error |
|
1004 | - */ |
|
1005 | - private static function _add_ticket_to_cart(EE_Ticket $ticket = null, $qty = 1) |
|
1006 | - { |
|
1007 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1008 | - // get the number of spaces left for this datetime ticket |
|
1009 | - $available_spaces = self::_ticket_datetime_availability($ticket); |
|
1010 | - // compare available spaces against the number of tickets being purchased |
|
1011 | - if ($available_spaces >= $qty) { |
|
1012 | - // allow addons to prevent a ticket from being added to cart |
|
1013 | - if ( ! apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', true, $ticket, |
|
1014 | - $qty, $available_spaces) |
|
1015 | - ) { |
|
1016 | - return false; |
|
1017 | - } |
|
1018 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
1019 | - // add event to cart |
|
1020 | - if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
1021 | - self::_recalculate_ticket_datetime_availability($ticket, $qty); |
|
1022 | - return true; |
|
1023 | - } else { |
|
1024 | - return false; |
|
1025 | - } |
|
1026 | - } else { |
|
1027 | - // tickets can not be purchased but let's find the exact number left for the last ticket selected PRIOR to subtracting tickets |
|
1028 | - $available_spaces = self::_ticket_datetime_availability($ticket, true); |
|
1029 | - // greedy greedy greedy eh? |
|
1030 | - if ($available_spaces > 0) { |
|
1031 | - if ( |
|
1032 | - apply_filters( |
|
1033 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
1034 | - true, |
|
1035 | - $ticket, |
|
1036 | - $qty, |
|
1037 | - $available_spaces |
|
1038 | - ) |
|
1039 | - ) { |
|
1040 | - EED_Ticket_Selector::_display_availability_error($available_spaces); |
|
1041 | - } |
|
1042 | - } else { |
|
1043 | - EE_Error::add_error( |
|
1044 | - __('We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
1045 | - 'event_espresso'), |
|
1046 | - __FILE__, __FUNCTION__, __LINE__ |
|
1047 | - ); |
|
1048 | - } |
|
1049 | - return false; |
|
1050 | - } |
|
1051 | - } |
|
1052 | - |
|
1053 | - |
|
1054 | - |
|
1055 | - /** |
|
1056 | - * _display_availability_error |
|
1057 | - * |
|
1058 | - * @access private |
|
1059 | - * @param int $available_spaces |
|
1060 | - * @throws \EE_Error |
|
1061 | - */ |
|
1062 | - private static function _display_availability_error($available_spaces = 1) |
|
1063 | - { |
|
1064 | - // add error messaging - we're using the _n function that will generate |
|
1065 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
1066 | - if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
1067 | - $msg = sprintf( |
|
1068 | - _n( |
|
1069 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
1070 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
1071 | - $available_spaces, |
|
1072 | - 'event_espresso' |
|
1073 | - ), |
|
1074 | - $available_spaces, |
|
1075 | - '<br />' |
|
1076 | - ); |
|
1077 | - } else { |
|
1078 | - $msg = sprintf( |
|
1079 | - _n( |
|
1080 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
1081 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
1082 | - $available_spaces, |
|
1083 | - 'event_espresso' |
|
1084 | - ), |
|
1085 | - $available_spaces, |
|
1086 | - '<br />' |
|
1087 | - ); |
|
1088 | - } |
|
1089 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1090 | - } |
|
1091 | - |
|
1092 | - |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * _ticket_datetime_availability |
|
1096 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
1097 | - * and tracks the spaces remaining for each of those datetimes |
|
1098 | - * |
|
1099 | - * @access private |
|
1100 | - * @param EE_Ticket $ticket - selected ticket |
|
1101 | - * @param bool $get_original_ticket_spaces |
|
1102 | - * @return int |
|
1103 | - * @throws \EE_Error |
|
1104 | - */ |
|
1105 | - private static function _ticket_datetime_availability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
1106 | - { |
|
1107 | - // if the $_available_spaces array has not been set up yet... |
|
1108 | - if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
1109 | - self::_set_initial_ticket_datetime_availability($ticket); |
|
1110 | - } |
|
1111 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
1112 | - if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
1113 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
1114 | - foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
1115 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
1116 | - if ($get_original_ticket_spaces) { |
|
1117 | - // then grab the available spaces from the "tickets" array and compare with the above to get the lowest number |
|
1118 | - $available_spaces = min($available_spaces, |
|
1119 | - self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]); |
|
1120 | - } else { |
|
1121 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
1122 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
1123 | - } |
|
1124 | - } |
|
1125 | - } |
|
1126 | - return $available_spaces; |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * _set_initial_ticket_datetime_availability |
|
1133 | - * |
|
1134 | - * @access private |
|
1135 | - * @param EE_Ticket $ticket |
|
1136 | - * @return void |
|
1137 | - * @throws \EE_Error |
|
1138 | - */ |
|
1139 | - private static function _set_initial_ticket_datetime_availability(EE_Ticket $ticket) |
|
1140 | - { |
|
1141 | - // first, get all of the datetimes that are available to this ticket |
|
1142 | - $datetimes = $ticket->get_many_related( |
|
1143 | - 'Datetime', |
|
1144 | - array( |
|
1145 | - array( |
|
1146 | - 'DTT_EVT_end' => array( |
|
1147 | - '>=', |
|
1148 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
1149 | - ), |
|
1150 | - ), |
|
1151 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1152 | - ) |
|
1153 | - ); |
|
1154 | - if ( ! empty($datetimes)) { |
|
1155 | - // now loop thru all of the datetimes |
|
1156 | - foreach ($datetimes as $datetime) { |
|
1157 | - if ($datetime instanceof EE_Datetime) { |
|
1158 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
1159 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
1160 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
1161 | - self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
1162 | - $ticket->qty() - $ticket->sold(), |
|
1163 | - $spaces_remaining |
|
1164 | - ); |
|
1165 | - // if the remaining spaces for this datetime is already set, then compare that against the datetime spaces remaining, and take the lowest number, |
|
1166 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
1167 | - self::$_available_spaces['datetimes'][$datetime->ID()] = isset(self::$_available_spaces['datetimes'][$datetime->ID()]) |
|
1168 | - ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
1169 | - : $spaces_remaining; |
|
1170 | - } |
|
1171 | - } |
|
1172 | - } |
|
1173 | - } |
|
1174 | - |
|
1175 | - |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * _recalculate_ticket_datetime_availability |
|
1179 | - * |
|
1180 | - * @access private |
|
1181 | - * @param EE_Ticket $ticket |
|
1182 | - * @param int $qty |
|
1183 | - * @return void |
|
1184 | - */ |
|
1185 | - private static function _recalculate_ticket_datetime_availability(EE_Ticket $ticket, $qty = 0) |
|
1186 | - { |
|
1187 | - if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
1188 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
1189 | - foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
1190 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
1191 | - self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
1192 | - } |
|
1193 | - } |
|
1194 | - } |
|
1195 | - |
|
1196 | - |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * load js |
|
1200 | - * |
|
1201 | - * @access public |
|
1202 | - * @return void |
|
1203 | - */ |
|
1204 | - public static function load_tckt_slctr_assets() |
|
1205 | - { |
|
1206 | - // add some style |
|
1207 | - if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
1208 | - wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'); |
|
1209 | - wp_enqueue_style('ticket_selector'); |
|
1210 | - // make it dance |
|
1211 | - // wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE); |
|
1212 | - // wp_enqueue_script('ticket_selector'); |
|
1213 | - } |
|
1214 | - } |
|
1215 | - |
|
1216 | - |
|
1217 | - |
|
1218 | - public static function load_tckt_slctr_assets_admin() |
|
1219 | - { |
|
1220 | - //iframe button js on admin event editor page |
|
1221 | - if (EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
1222 | - && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
1223 | - ) { |
|
1224 | - wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL . 'ticket-selector-embed.js', |
|
1225 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
1226 | - wp_enqueue_script('ticket_selector_embed'); |
|
1227 | - } |
|
1228 | - } |
|
425 | + } |
|
426 | + return $html; |
|
427 | + } |
|
428 | + // if there is no submit button, then don't start building a form |
|
429 | + // because the "View Details" button will build its own form |
|
430 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
431 | + return ''; |
|
432 | + } |
|
433 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
434 | + if ( ! $checkout_url) { |
|
435 | + EE_Error::add_error(__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
436 | + __FILE__, __FUNCTION__, __LINE__); |
|
437 | + } |
|
438 | + $extra_params = self::$_in_iframe ? ' target="_blank"' : ''; |
|
439 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
440 | + $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false); |
|
441 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
442 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, self::$_event); |
|
443 | + return $html; |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * display_ticket_selector_submit |
|
450 | + * |
|
451 | + * @param string $external_url |
|
452 | + * @return string |
|
453 | + * @throws \EE_Error |
|
454 | + */ |
|
455 | + public static function display_ticket_selector_submit($external_url = '') |
|
456 | + { |
|
457 | + $html = ''; |
|
458 | + if ( ! is_admin()) { |
|
459 | + // standard TS displayed with submit button, ie: "Register Now" |
|
460 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
461 | + $html .= \EED_Ticket_Selector::display_register_now_button(); |
|
462 | + $html .= empty($external_url) ? |
|
463 | + \EED_Ticket_Selector::no_tkt_slctr_end_dv() |
|
464 | + : \EED_Ticket_Selector::clear_tkt_slctr(); |
|
465 | + $html .= '<br/>' . \EED_Ticket_Selector::ticket_selector_form_close(); |
|
466 | + } else if ( EED_Ticket_Selector::$_max_atndz === 1 ) { |
|
467 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
468 | + if ( EED_Ticket_Selector::$_event->is_sold_out() ) { |
|
469 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
470 | + $html .= apply_filters( |
|
471 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
472 | + sprintf( |
|
473 | + __( |
|
474 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
475 | + 'event_espresso' |
|
476 | + ), |
|
477 | + '<p class="no-ticket-selector-msg clear-float">', |
|
478 | + EED_Ticket_Selector::$_event->name(), |
|
479 | + '</p>', |
|
480 | + '<br />' |
|
481 | + ), |
|
482 | + EED_Ticket_Selector::$_event |
|
483 | + ); |
|
484 | + if ( |
|
485 | + apply_filters( |
|
486 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
487 | + false, |
|
488 | + EED_Ticket_Selector::$_event |
|
489 | + ) |
|
490 | + ) { |
|
491 | + $html .= \EED_Ticket_Selector::display_register_now_button(); |
|
492 | + } |
|
493 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
494 | + $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv(); |
|
495 | + } else if ( |
|
496 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
497 | + && ! is_single() |
|
498 | + ) { |
|
499 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
500 | + // but no tickets are available, so display event's "View Details" button. |
|
501 | + // it is being viewed via somewhere other than a single post |
|
502 | + $html .= EED_Ticket_Selector::display_view_details_btn(true); |
|
503 | + } |
|
504 | + } else if (is_archive()) { |
|
505 | + // event list, no tickets available so display event's "View Details" button |
|
506 | + $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv(); |
|
507 | + $html .= EED_Ticket_Selector::display_view_details_btn(); |
|
508 | + } else { |
|
509 | + if ( |
|
510 | + apply_filters( |
|
511 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
512 | + false, |
|
513 | + EED_Ticket_Selector::$_event |
|
514 | + ) |
|
515 | + ) { |
|
516 | + $html .= \EED_Ticket_Selector::display_register_now_button(); |
|
517 | + } |
|
518 | + // no submit or view details button, and no additional content |
|
519 | + $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv(); |
|
520 | + } |
|
521 | + if ( ! is_archive()) { |
|
522 | + $html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
523 | + } |
|
524 | + } |
|
525 | + return $html; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * @return string |
|
532 | + */ |
|
533 | + public static function clear_tkt_slctr() |
|
534 | + { |
|
535 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
536 | + return '<div class="clear"></div>'; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @deprecated 4.9.13 |
|
543 | + * @return string |
|
544 | + */ |
|
545 | + public static function tkt_slctr_end_dv() |
|
546 | + { |
|
547 | + return \EED_Ticket_Selector::clear_tkt_slctr(); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * @return string |
|
554 | + */ |
|
555 | + public static function no_tkt_slctr_end_dv() |
|
556 | + { |
|
557 | + // DWMTS event, no TS, appears after a "Register Now" or "view Details" button |
|
558 | + return '<div class="clear"></div></div>'; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * ticket_selector_form_close |
|
565 | + * |
|
566 | + * @access public |
|
567 | + * @access public |
|
568 | + * @return string |
|
569 | + */ |
|
570 | + public static function ticket_selector_form_close() |
|
571 | + { |
|
572 | + return '</form>'; |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * @return string |
|
579 | + * @throws \EE_Error |
|
580 | + */ |
|
581 | + public static function display_register_now_button() |
|
582 | + { |
|
583 | + $btn_text = apply_filters( |
|
584 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
585 | + __('Register Now', 'event_espresso'), |
|
586 | + EED_Ticket_Selector::$_event |
|
587 | + ); |
|
588 | + $external_url = EED_Ticket_Selector::$_event->external_url(); |
|
589 | + $html = '<input id="ticket-selector-submit-' . EED_Ticket_Selector::$_event->ID() . '-btn"'; |
|
590 | + $html .= ' class="ticket-selector-submit-btn '; |
|
591 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
592 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
593 | + $html .= apply_filters( |
|
594 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
595 | + '', |
|
596 | + EED_Ticket_Selector::$_event |
|
597 | + ); |
|
598 | + return $html; |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * display_view_details_btn |
|
604 | + * |
|
605 | + * @access public |
|
606 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
607 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
608 | + * either because they are sold out, expired, or not yet on sale. |
|
609 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
610 | + * @return string |
|
611 | + * @throws \EE_Error |
|
612 | + */ |
|
613 | + public static function display_view_details_btn($DWMTS = false) |
|
614 | + { |
|
615 | + if ( ! self::$_event->get_permalink()) { |
|
616 | + EE_Error::add_error( |
|
617 | + __('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
618 | + __FILE__, __FUNCTION__, __LINE__ |
|
619 | + ); |
|
620 | + } |
|
621 | + $view_details_btn = '<form method="POST" action="'; |
|
622 | + $view_details_btn .= apply_filters( |
|
623 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
624 | + self::$_event->get_permalink(), |
|
625 | + self::$_event |
|
626 | + ); |
|
627 | + $view_details_btn .= '">'; |
|
628 | + $btn_text = apply_filters( |
|
629 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
630 | + __('View Details', 'event_espresso'), |
|
631 | + self::$_event |
|
632 | + ); |
|
633 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
634 | + . self::$_event->ID() |
|
635 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
636 | + . $btn_text |
|
637 | + . '" />'; |
|
638 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', self::$_event); |
|
639 | + if ($DWMTS) { |
|
640 | + $view_details_btn .= \EED_Ticket_Selector::ticket_selector_form_close(); |
|
641 | + $view_details_btn .= \EED_Ticket_Selector::no_tkt_slctr_end_dv(); |
|
642 | + $view_details_btn .= '<br/>'; |
|
643 | + } else { |
|
644 | + $view_details_btn .= \EED_Ticket_Selector::clear_tkt_slctr(); |
|
645 | + $view_details_btn .= '<br/>'; |
|
646 | + $view_details_btn .= \EED_Ticket_Selector::ticket_selector_form_close(); |
|
647 | + } |
|
648 | + return $view_details_btn; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * cancel_ticket_selections |
|
655 | + * |
|
656 | + * @access public |
|
657 | + * @access public |
|
658 | + * @return string |
|
659 | + */ |
|
660 | + public static function cancel_ticket_selections() |
|
661 | + { |
|
662 | + // check nonce |
|
663 | + if ( ! EED_Ticket_Selector::process_ticket_selector_nonce('cancel_ticket_selections')) { |
|
664 | + return false; |
|
665 | + } |
|
666 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
667 | + if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
668 | + wp_safe_redirect( |
|
669 | + EEH_Event_View::event_link_url( |
|
670 | + EE_Registry::instance()->REQ->get('event_id') |
|
671 | + ) |
|
672 | + ); |
|
673 | + } else { |
|
674 | + wp_safe_redirect( |
|
675 | + site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
676 | + ); |
|
677 | + } |
|
678 | + die(); |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * process_ticket_selector_nonce |
|
685 | + * |
|
686 | + * @access public |
|
687 | + * @param string $nonce_name |
|
688 | + * @param string $id |
|
689 | + * @return bool |
|
690 | + */ |
|
691 | + public static function process_ticket_selector_nonce($nonce_name, $id = '') |
|
692 | + { |
|
693 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
694 | + if ( |
|
695 | + ! is_admin() |
|
696 | + && ( |
|
697 | + ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
698 | + || ! wp_verify_nonce( |
|
699 | + EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
700 | + $nonce_name |
|
701 | + ) |
|
702 | + ) |
|
703 | + ) { |
|
704 | + EE_Error::add_error( |
|
705 | + sprintf( |
|
706 | + __( |
|
707 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
708 | + 'event_espresso' |
|
709 | + ), |
|
710 | + '<br/>' |
|
711 | + ), |
|
712 | + __FILE__, |
|
713 | + __FUNCTION__, |
|
714 | + __LINE__ |
|
715 | + ); |
|
716 | + return false; |
|
717 | + } |
|
718 | + return true; |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * process_ticket_selections |
|
725 | + * |
|
726 | + * @access public |
|
727 | + * @return array|boolean |
|
728 | + * @throws \EE_Error |
|
729 | + */ |
|
730 | + public function process_ticket_selections() |
|
731 | + { |
|
732 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
733 | + // do we have an event id? |
|
734 | + if ( ! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
735 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
736 | + EE_Error::add_error( |
|
737 | + sprintf( |
|
738 | + __( |
|
739 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
740 | + 'event_espresso' |
|
741 | + ), |
|
742 | + '<br/>' |
|
743 | + ), |
|
744 | + __FILE__, |
|
745 | + __FUNCTION__, |
|
746 | + __LINE__ |
|
747 | + ); |
|
748 | + } |
|
749 | + //if event id is valid |
|
750 | + $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
751 | + // check nonce |
|
752 | + if ( ! EED_Ticket_Selector::process_ticket_selector_nonce('process_ticket_selections', $id)) { |
|
753 | + return false; |
|
754 | + } |
|
755 | + // d( EE_Registry::instance()->REQ ); |
|
756 | + self::$_available_spaces = array( |
|
757 | + 'tickets' => array(), |
|
758 | + 'datetimes' => array(), |
|
759 | + ); |
|
760 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
761 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
762 | + EE_Registry::instance()->load_core('Session'); |
|
763 | + // unless otherwise requested, clear the session |
|
764 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
765 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
766 | + } |
|
767 | + //d( EE_Registry::instance()->SSN ); |
|
768 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
769 | + // validate/sanitize data |
|
770 | + $valid = self::_validate_post_data($id); |
|
771 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
772 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
773 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
774 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
775 | + //check total tickets ordered vs max number of attendees that can register |
|
776 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
777 | + // ordering too many tickets !!! |
|
778 | + $total_tickets_string = _n('You have attempted to purchase %s ticket.', |
|
779 | + 'You have attempted to purchase %s tickets.', $valid['total_tickets'], 'event_espresso'); |
|
780 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
781 | + // dev only message |
|
782 | + $max_atndz_string = _n('The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
783 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
784 | + $valid['max_atndz'], 'event_espresso'); |
|
785 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
786 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
787 | + } else { |
|
788 | + // all data appears to be valid |
|
789 | + $tckts_slctd = false; |
|
790 | + $tickets_added = 0; |
|
791 | + $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
|
792 | + if ($valid['total_tickets'] > 0) { |
|
793 | + // load cart |
|
794 | + EE_Registry::instance()->load_core('Cart'); |
|
795 | + // cycle thru the number of data rows sent from the event listing |
|
796 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
797 | + // does this row actually contain a ticket quantity? |
|
798 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
799 | + // YES we have a ticket quantity |
|
800 | + $tckts_slctd = true; |
|
801 | + // d( $valid['ticket_obj'][$x] ); |
|
802 | + if ($valid['ticket_obj'][$x] instanceof EE_Ticket) { |
|
803 | + // then add ticket to cart |
|
804 | + $tickets_added += self::_add_ticket_to_cart($valid['ticket_obj'][$x], $valid['qty'][$x]); |
|
805 | + if (EE_Error::has_error()) { |
|
806 | + break; |
|
807 | + } |
|
808 | + } else { |
|
809 | + // nothing added to cart retrieved |
|
810 | + EE_Error::add_error( |
|
811 | + sprintf(__('A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
812 | + 'event_espresso'), '<br/>'), |
|
813 | + __FILE__, __FUNCTION__, __LINE__ |
|
814 | + ); |
|
815 | + } |
|
816 | + } |
|
817 | + } |
|
818 | + } |
|
819 | + do_action( |
|
820 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
821 | + EE_Registry::instance()->CART, |
|
822 | + $this |
|
823 | + ); |
|
824 | + //d( EE_Registry::instance()->CART ); |
|
825 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
826 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
827 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
828 | + do_action( |
|
829 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
830 | + EE_Registry::instance()->CART, |
|
831 | + $this |
|
832 | + ); |
|
833 | + EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
834 | + EE_Registry::instance()->CART->save_cart(false); |
|
835 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
836 | + // just return TRUE for registrations being made from admin |
|
837 | + if (is_admin()) { |
|
838 | + return true; |
|
839 | + } |
|
840 | + EE_Error::get_notices(false, true); |
|
841 | + wp_safe_redirect( |
|
842 | + apply_filters( |
|
843 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
844 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
845 | + ) |
|
846 | + ); |
|
847 | + exit(); |
|
848 | + } else { |
|
849 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
850 | + // nothing added to cart |
|
851 | + EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), __FILE__, |
|
852 | + __FUNCTION__, __LINE__); |
|
853 | + } |
|
854 | + } |
|
855 | + } else { |
|
856 | + // no ticket quantities were selected |
|
857 | + EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
858 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
859 | + } |
|
860 | + } |
|
861 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
862 | + // at this point, just return if registration is being made from admin |
|
863 | + if (is_admin()) { |
|
864 | + return false; |
|
865 | + } |
|
866 | + if ($valid['return_url']) { |
|
867 | + EE_Error::get_notices(false, true); |
|
868 | + wp_safe_redirect($valid['return_url']); |
|
869 | + exit(); |
|
870 | + } elseif (isset($event_to_add['id'])) { |
|
871 | + EE_Error::get_notices(false, true); |
|
872 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
873 | + exit(); |
|
874 | + } else { |
|
875 | + echo EE_Error::get_notices(); |
|
876 | + } |
|
877 | + return false; |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * validate_post_data |
|
884 | + * |
|
885 | + * @access private |
|
886 | + * @param int $id |
|
887 | + * @return array|FALSE |
|
888 | + */ |
|
889 | + private static function _validate_post_data($id = 0) |
|
890 | + { |
|
891 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
892 | + if ( ! $id) { |
|
893 | + EE_Error::add_error( |
|
894 | + __('The event id provided was not valid.', 'event_espresso'), |
|
895 | + __FILE__, |
|
896 | + __FUNCTION__, |
|
897 | + __LINE__ |
|
898 | + ); |
|
899 | + return false; |
|
900 | + } |
|
901 | + // start with an empty array() |
|
902 | + $valid_data = array(); |
|
903 | + // grab valid id |
|
904 | + $valid_data['id'] = $id; |
|
905 | + // grab and sanitize return-url |
|
906 | + $valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-' . $id)); |
|
907 | + // array of other form names |
|
908 | + $inputs_to_clean = array( |
|
909 | + 'event_id' => 'tkt-slctr-event-id', |
|
910 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
911 | + 'rows' => 'tkt-slctr-rows-', |
|
912 | + 'qty' => 'tkt-slctr-qty-', |
|
913 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
914 | + 'return_url' => 'tkt-slctr-return-url-', |
|
915 | + ); |
|
916 | + // let's track the total number of tickets ordered.' |
|
917 | + $valid_data['total_tickets'] = 0; |
|
918 | + // cycle through $inputs_to_clean array |
|
919 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
920 | + // check for POST data |
|
921 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
922 | + // grab value |
|
923 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
924 | + switch ($what) { |
|
925 | + // integers |
|
926 | + case 'event_id': |
|
927 | + $valid_data[$what] = absint($input_value); |
|
928 | + // get event via the event id we put in the form |
|
929 | + $valid_data['event'] = EE_Registry::instance() |
|
930 | + ->load_model('Event') |
|
931 | + ->get_one_by_ID($valid_data['event_id']); |
|
932 | + break; |
|
933 | + case 'rows': |
|
934 | + case 'max_atndz': |
|
935 | + $valid_data[$what] = absint($input_value); |
|
936 | + break; |
|
937 | + // arrays of integers |
|
938 | + case 'qty': |
|
939 | + /** @var array $row_qty */ |
|
940 | + $row_qty = $input_value; |
|
941 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
942 | + if ( ! is_array($row_qty)) { |
|
943 | + // get number of rows |
|
944 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
945 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
946 | + : 1; |
|
947 | + // explode ints by the dash |
|
948 | + $row_qty = explode('-', $row_qty); |
|
949 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
950 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
951 | + $row_qty = array($row => $qty); |
|
952 | + // d( $row_qty ); |
|
953 | + for ($x = 1; $x <= $rows; $x++) { |
|
954 | + if ( ! isset($row_qty[$x])) { |
|
955 | + $row_qty[$x] = 0; |
|
956 | + } |
|
957 | + } |
|
958 | + } |
|
959 | + ksort($row_qty); |
|
960 | + // d( $row_qty ); |
|
961 | + // cycle thru values |
|
962 | + foreach ($row_qty as $qty) { |
|
963 | + $qty = absint($qty); |
|
964 | + // sanitize as integers |
|
965 | + $valid_data[$what][] = $qty; |
|
966 | + $valid_data['total_tickets'] += $qty; |
|
967 | + } |
|
968 | + break; |
|
969 | + // array of integers |
|
970 | + case 'ticket_id': |
|
971 | + $value_array = array(); |
|
972 | + // cycle thru values |
|
973 | + foreach ((array)$input_value as $key => $value) { |
|
974 | + // allow only numbers, letters, spaces, commas and dashes |
|
975 | + $value_array[$key] = wp_strip_all_tags($value); |
|
976 | + // get ticket via the ticket id we put in the form |
|
977 | + $ticket_obj = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
978 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
979 | + } |
|
980 | + $valid_data[$what] = $value_array; |
|
981 | + break; |
|
982 | + case 'return_url' : |
|
983 | + // grab and sanitize return-url |
|
984 | + $valid_data[$what] = esc_url_raw($input_value); |
|
985 | + break; |
|
986 | + } // end switch $what |
|
987 | + } |
|
988 | + } // end foreach $inputs_to_clean |
|
989 | + // d( $valid_data ); |
|
990 | + // die(); |
|
991 | + return $valid_data; |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * adds a ticket to the cart |
|
998 | + * |
|
999 | + * @access private |
|
1000 | + * @param EE_Ticket $ticket |
|
1001 | + * @param int $qty |
|
1002 | + * @return TRUE on success, FALSE on fail |
|
1003 | + * @throws \EE_Error |
|
1004 | + */ |
|
1005 | + private static function _add_ticket_to_cart(EE_Ticket $ticket = null, $qty = 1) |
|
1006 | + { |
|
1007 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1008 | + // get the number of spaces left for this datetime ticket |
|
1009 | + $available_spaces = self::_ticket_datetime_availability($ticket); |
|
1010 | + // compare available spaces against the number of tickets being purchased |
|
1011 | + if ($available_spaces >= $qty) { |
|
1012 | + // allow addons to prevent a ticket from being added to cart |
|
1013 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', true, $ticket, |
|
1014 | + $qty, $available_spaces) |
|
1015 | + ) { |
|
1016 | + return false; |
|
1017 | + } |
|
1018 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
1019 | + // add event to cart |
|
1020 | + if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
1021 | + self::_recalculate_ticket_datetime_availability($ticket, $qty); |
|
1022 | + return true; |
|
1023 | + } else { |
|
1024 | + return false; |
|
1025 | + } |
|
1026 | + } else { |
|
1027 | + // tickets can not be purchased but let's find the exact number left for the last ticket selected PRIOR to subtracting tickets |
|
1028 | + $available_spaces = self::_ticket_datetime_availability($ticket, true); |
|
1029 | + // greedy greedy greedy eh? |
|
1030 | + if ($available_spaces > 0) { |
|
1031 | + if ( |
|
1032 | + apply_filters( |
|
1033 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
1034 | + true, |
|
1035 | + $ticket, |
|
1036 | + $qty, |
|
1037 | + $available_spaces |
|
1038 | + ) |
|
1039 | + ) { |
|
1040 | + EED_Ticket_Selector::_display_availability_error($available_spaces); |
|
1041 | + } |
|
1042 | + } else { |
|
1043 | + EE_Error::add_error( |
|
1044 | + __('We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
1045 | + 'event_espresso'), |
|
1046 | + __FILE__, __FUNCTION__, __LINE__ |
|
1047 | + ); |
|
1048 | + } |
|
1049 | + return false; |
|
1050 | + } |
|
1051 | + } |
|
1052 | + |
|
1053 | + |
|
1054 | + |
|
1055 | + /** |
|
1056 | + * _display_availability_error |
|
1057 | + * |
|
1058 | + * @access private |
|
1059 | + * @param int $available_spaces |
|
1060 | + * @throws \EE_Error |
|
1061 | + */ |
|
1062 | + private static function _display_availability_error($available_spaces = 1) |
|
1063 | + { |
|
1064 | + // add error messaging - we're using the _n function that will generate |
|
1065 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
1066 | + if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
1067 | + $msg = sprintf( |
|
1068 | + _n( |
|
1069 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
1070 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
1071 | + $available_spaces, |
|
1072 | + 'event_espresso' |
|
1073 | + ), |
|
1074 | + $available_spaces, |
|
1075 | + '<br />' |
|
1076 | + ); |
|
1077 | + } else { |
|
1078 | + $msg = sprintf( |
|
1079 | + _n( |
|
1080 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
1081 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
1082 | + $available_spaces, |
|
1083 | + 'event_espresso' |
|
1084 | + ), |
|
1085 | + $available_spaces, |
|
1086 | + '<br />' |
|
1087 | + ); |
|
1088 | + } |
|
1089 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1090 | + } |
|
1091 | + |
|
1092 | + |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * _ticket_datetime_availability |
|
1096 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
1097 | + * and tracks the spaces remaining for each of those datetimes |
|
1098 | + * |
|
1099 | + * @access private |
|
1100 | + * @param EE_Ticket $ticket - selected ticket |
|
1101 | + * @param bool $get_original_ticket_spaces |
|
1102 | + * @return int |
|
1103 | + * @throws \EE_Error |
|
1104 | + */ |
|
1105 | + private static function _ticket_datetime_availability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
1106 | + { |
|
1107 | + // if the $_available_spaces array has not been set up yet... |
|
1108 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
1109 | + self::_set_initial_ticket_datetime_availability($ticket); |
|
1110 | + } |
|
1111 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
1112 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
1113 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
1114 | + foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
1115 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
1116 | + if ($get_original_ticket_spaces) { |
|
1117 | + // then grab the available spaces from the "tickets" array and compare with the above to get the lowest number |
|
1118 | + $available_spaces = min($available_spaces, |
|
1119 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]); |
|
1120 | + } else { |
|
1121 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
1122 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
1123 | + } |
|
1124 | + } |
|
1125 | + } |
|
1126 | + return $available_spaces; |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * _set_initial_ticket_datetime_availability |
|
1133 | + * |
|
1134 | + * @access private |
|
1135 | + * @param EE_Ticket $ticket |
|
1136 | + * @return void |
|
1137 | + * @throws \EE_Error |
|
1138 | + */ |
|
1139 | + private static function _set_initial_ticket_datetime_availability(EE_Ticket $ticket) |
|
1140 | + { |
|
1141 | + // first, get all of the datetimes that are available to this ticket |
|
1142 | + $datetimes = $ticket->get_many_related( |
|
1143 | + 'Datetime', |
|
1144 | + array( |
|
1145 | + array( |
|
1146 | + 'DTT_EVT_end' => array( |
|
1147 | + '>=', |
|
1148 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
1149 | + ), |
|
1150 | + ), |
|
1151 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1152 | + ) |
|
1153 | + ); |
|
1154 | + if ( ! empty($datetimes)) { |
|
1155 | + // now loop thru all of the datetimes |
|
1156 | + foreach ($datetimes as $datetime) { |
|
1157 | + if ($datetime instanceof EE_Datetime) { |
|
1158 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
1159 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
1160 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
1161 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
1162 | + $ticket->qty() - $ticket->sold(), |
|
1163 | + $spaces_remaining |
|
1164 | + ); |
|
1165 | + // if the remaining spaces for this datetime is already set, then compare that against the datetime spaces remaining, and take the lowest number, |
|
1166 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
1167 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset(self::$_available_spaces['datetimes'][$datetime->ID()]) |
|
1168 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
1169 | + : $spaces_remaining; |
|
1170 | + } |
|
1171 | + } |
|
1172 | + } |
|
1173 | + } |
|
1174 | + |
|
1175 | + |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * _recalculate_ticket_datetime_availability |
|
1179 | + * |
|
1180 | + * @access private |
|
1181 | + * @param EE_Ticket $ticket |
|
1182 | + * @param int $qty |
|
1183 | + * @return void |
|
1184 | + */ |
|
1185 | + private static function _recalculate_ticket_datetime_availability(EE_Ticket $ticket, $qty = 0) |
|
1186 | + { |
|
1187 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
1188 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
1189 | + foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
1190 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
1191 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
1192 | + } |
|
1193 | + } |
|
1194 | + } |
|
1195 | + |
|
1196 | + |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * load js |
|
1200 | + * |
|
1201 | + * @access public |
|
1202 | + * @return void |
|
1203 | + */ |
|
1204 | + public static function load_tckt_slctr_assets() |
|
1205 | + { |
|
1206 | + // add some style |
|
1207 | + if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
1208 | + wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'); |
|
1209 | + wp_enqueue_style('ticket_selector'); |
|
1210 | + // make it dance |
|
1211 | + // wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE); |
|
1212 | + // wp_enqueue_script('ticket_selector'); |
|
1213 | + } |
|
1214 | + } |
|
1215 | + |
|
1216 | + |
|
1217 | + |
|
1218 | + public static function load_tckt_slctr_assets_admin() |
|
1219 | + { |
|
1220 | + //iframe button js on admin event editor page |
|
1221 | + if (EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
1222 | + && EE_Registry::instance()->REQ->get('action') === 'edit' |
|
1223 | + ) { |
|
1224 | + wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL . 'ticket-selector-embed.js', |
|
1225 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
1226 | + wp_enqueue_script('ticket_selector_embed'); |
|
1227 | + } |
|
1228 | + } |
|
1229 | 1229 | |
1230 | 1230 | |
1231 | 1231 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | class EED_Ticket_Selector extends EED_Module |
15 | 15 | { |
16 | 16 | |
17 | - const debug = false; // true false |
|
17 | + const debug = false; // true false |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * event that ticket selector is being generated for |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public static function set_definitions() |
115 | 115 | { |
116 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
117 | - define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
116 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
117 | + define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
118 | 118 | //if config is not set, initialize |
119 | 119 | //If config is not set, set it. |
120 | 120 | if (EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector === null) { |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | $template_args['css'] = apply_filters( |
159 | 159 | 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
160 | 160 | array( |
161 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_embed.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
162 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
163 | - includes_url('css/dashicons.min.css?ver=' . $GLOBALS['wp_version']), |
|
164 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
161 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector_embed.css?ver='.EVENT_ESPRESSO_VERSION, |
|
162 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css?ver='.EVENT_ESPRESSO_VERSION, |
|
163 | + includes_url('css/dashicons.min.css?ver='.$GLOBALS['wp_version']), |
|
164 | + EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
165 | 165 | ) |
166 | 166 | ); |
167 | 167 | EE_Registry::$i18n_js_strings['ticket_selector_iframe'] = true; |
@@ -174,18 +174,18 @@ discard block |
||
174 | 174 | $template_args['js'] = apply_filters( |
175 | 175 | 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
176 | 176 | array( |
177 | - includes_url('js/jquery/jquery.js?ver=' . $GLOBALS['wp_version']), |
|
178 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
179 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_iframe_embed.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
177 | + includes_url('js/jquery/jquery.js?ver='.$GLOBALS['wp_version']), |
|
178 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
179 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector_iframe_embed.js?ver='.EVENT_ESPRESSO_VERSION, |
|
180 | 180 | ) |
181 | 181 | ); |
182 | 182 | $template_args['notices'] = EEH_Template::display_template( |
183 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
183 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
184 | 184 | array(), |
185 | 185 | true |
186 | 186 | ); |
187 | 187 | EEH_Template::display_template( |
188 | - TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart_iframe.template.php', |
|
188 | + TICKET_SELECTOR_TEMPLATES_PATH.'ticket_selector_chart_iframe.template.php', |
|
189 | 189 | $template_args |
190 | 190 | ); |
191 | 191 | exit; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @param int $id The post id for the event. |
201 | 201 | * @return string The new html string for the permalink area. |
202 | 202 | */ |
203 | - public static function iframe_code_button($permalink_string, $id ) |
|
203 | + public static function iframe_code_button($permalink_string, $id) |
|
204 | 204 | { |
205 | 205 | //make sure this is ONLY when editing and the event id has been set. |
206 | 206 | if ( ! empty($id)) { |
@@ -214,12 +214,12 @@ discard block |
||
214 | 214 | . '</a> '; |
215 | 215 | $ticket_selector_url = add_query_arg(array('ticket_selector' => 'iframe', 'event' => $id), site_url()); |
216 | 216 | $iframe_string = esc_html( |
217 | - '<iframe src="' . $ticket_selector_url . '" width="100%" height="100%"></iframe>' |
|
217 | + '<iframe src="'.$ticket_selector_url.'" width="100%" height="100%"></iframe>' |
|
218 | 218 | ); |
219 | 219 | $permalink_string .= ' |
220 | 220 | <div id="js-ts-iframe" style="display:none"> |
221 | 221 | <div style="width:100%; height: 500px;"> |
222 | - ' . $iframe_string . ' |
|
222 | + ' . $iframe_string.' |
|
223 | 223 | </div> |
224 | 224 | </div>'; |
225 | 225 | } |
@@ -243,10 +243,10 @@ discard block |
||
243 | 243 | } |
244 | 244 | if ($event instanceof EE_Event) { |
245 | 245 | self::$_event = $event; |
246 | - } else if ($event instanceof WP_Post ) { |
|
247 | - if ( isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
246 | + } else if ($event instanceof WP_Post) { |
|
247 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
248 | 248 | self::$_event = $event->EE_Event; |
249 | - } else if ( $event->post_type === 'espresso_events') { |
|
249 | + } else if ($event->post_type === 'espresso_events') { |
|
250 | 250 | $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
251 | 251 | self::$_event = $event->EE_Event; |
252 | 252 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $dev_msg = $user_msg |
256 | 256 | . __('In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
257 | 257 | 'event_espresso'); |
258 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
258 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
259 | 259 | return false; |
260 | 260 | } |
261 | 261 | return true; |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | '</a></span></div>' |
363 | 363 | ); |
364 | 364 | } |
365 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
365 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
366 | 366 | } |
367 | - $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php'; |
|
367 | + $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH.'ticket_selector_chart.template.php'; |
|
368 | 368 | $templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
369 | 369 | $templates['ticket_selector'], self::$_event); |
370 | 370 | // redirecting to another site for registration ?? |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | ? EED_Ticket_Selector::ticket_selector_form_open( |
387 | 387 | self::$_event->ID(), |
388 | 388 | $external_url |
389 | - ) . $ticket_selector |
|
389 | + ).$ticket_selector |
|
390 | 390 | : $ticket_selector; |
391 | 391 | // submit button and form close tag |
392 | 392 | $ticket_selector .= ! is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit($external_url) : ''; |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | { |
410 | 410 | // if redirecting, we don't need any anything else |
411 | 411 | if ($external_url) { |
412 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
412 | + $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"'; |
|
413 | 413 | // open link in new window ? |
414 | 414 | $html .= apply_filters( |
415 | 415 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
@@ -418,10 +418,10 @@ discard block |
||
418 | 418 | ? ' target="_blank"' |
419 | 419 | : ''; |
420 | 420 | $html .= '>'; |
421 | - $query_args = (array)EEH_URL::get_query_string($external_url); |
|
421 | + $query_args = (array) EEH_URL::get_query_string($external_url); |
|
422 | 422 | foreach ($query_args as $query_arg => $value) { |
423 | 423 | $html .= ' |
424 | - <input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
424 | + <input type="hidden" name="' . $query_arg.'" value="'.$value.'">'; |
|
425 | 425 | } |
426 | 426 | return $html; |
427 | 427 | } |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | __FILE__, __FUNCTION__, __LINE__); |
437 | 437 | } |
438 | 438 | $extra_params = self::$_in_iframe ? ' target="_blank"' : ''; |
439 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
440 | - $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false); |
|
439 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>'; |
|
440 | + $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_'.$ID, true, false); |
|
441 | 441 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
442 | 442 | $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, self::$_event); |
443 | 443 | return $html; |
@@ -462,10 +462,10 @@ discard block |
||
462 | 462 | $html .= empty($external_url) ? |
463 | 463 | \EED_Ticket_Selector::no_tkt_slctr_end_dv() |
464 | 464 | : \EED_Ticket_Selector::clear_tkt_slctr(); |
465 | - $html .= '<br/>' . \EED_Ticket_Selector::ticket_selector_form_close(); |
|
466 | - } else if ( EED_Ticket_Selector::$_max_atndz === 1 ) { |
|
465 | + $html .= '<br/>'.\EED_Ticket_Selector::ticket_selector_form_close(); |
|
466 | + } else if (EED_Ticket_Selector::$_max_atndz === 1) { |
|
467 | 467 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
468 | - if ( EED_Ticket_Selector::$_event->is_sold_out() ) { |
|
468 | + if (EED_Ticket_Selector::$_event->is_sold_out()) { |
|
469 | 469 | // then instead of a View Details or Submit button, just display a "Sold Out" message |
470 | 470 | $html .= apply_filters( |
471 | 471 | 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
@@ -586,10 +586,10 @@ discard block |
||
586 | 586 | EED_Ticket_Selector::$_event |
587 | 587 | ); |
588 | 588 | $external_url = EED_Ticket_Selector::$_event->external_url(); |
589 | - $html = '<input id="ticket-selector-submit-' . EED_Ticket_Selector::$_event->ID() . '-btn"'; |
|
589 | + $html = '<input id="ticket-selector-submit-'.EED_Ticket_Selector::$_event->ID().'-btn"'; |
|
590 | 590 | $html .= ' class="ticket-selector-submit-btn '; |
591 | 591 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
592 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
592 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
593 | 593 | $html .= apply_filters( |
594 | 594 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
595 | 595 | '', |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | ); |
673 | 673 | } else { |
674 | 674 | wp_safe_redirect( |
675 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
675 | + site_url('/'.EE_Registry::instance()->CFG->core->event_cpt_slug.'/') |
|
676 | 676 | ); |
677 | 677 | } |
678 | 678 | die(); |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
784 | 784 | $valid['max_atndz'], 'event_espresso'); |
785 | 785 | $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
786 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
786 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
787 | 787 | } else { |
788 | 788 | // all data appears to be valid |
789 | 789 | $tckts_slctd = false; |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | // grab valid id |
904 | 904 | $valid_data['id'] = $id; |
905 | 905 | // grab and sanitize return-url |
906 | - $valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-' . $id)); |
|
906 | + $valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-'.$id)); |
|
907 | 907 | // array of other form names |
908 | 908 | $inputs_to_clean = array( |
909 | 909 | 'event_id' => 'tkt-slctr-event-id', |
@@ -918,9 +918,9 @@ discard block |
||
918 | 918 | // cycle through $inputs_to_clean array |
919 | 919 | foreach ($inputs_to_clean as $what => $input_to_clean) { |
920 | 920 | // check for POST data |
921 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
921 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) { |
|
922 | 922 | // grab value |
923 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
923 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean.$id); |
|
924 | 924 | switch ($what) { |
925 | 925 | // integers |
926 | 926 | case 'event_id': |
@@ -941,8 +941,8 @@ discard block |
||
941 | 941 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
942 | 942 | if ( ! is_array($row_qty)) { |
943 | 943 | // get number of rows |
944 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
945 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
944 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id) |
|
945 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id)) |
|
946 | 946 | : 1; |
947 | 947 | // explode ints by the dash |
948 | 948 | $row_qty = explode('-', $row_qty); |
@@ -970,7 +970,7 @@ discard block |
||
970 | 970 | case 'ticket_id': |
971 | 971 | $value_array = array(); |
972 | 972 | // cycle thru values |
973 | - foreach ((array)$input_value as $key => $value) { |
|
973 | + foreach ((array) $input_value as $key => $value) { |
|
974 | 974 | // allow only numbers, letters, spaces, commas and dashes |
975 | 975 | $value_array[$key] = wp_strip_all_tags($value); |
976 | 976 | // get ticket via the ticket id we put in the form |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | $available_spaces = $ticket->qty() - $ticket->sold(); |
1112 | 1112 | if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
1113 | 1113 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
1114 | - foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
1114 | + foreach ((array) self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
1115 | 1115 | // if we want the original datetime availability BEFORE we started subtracting tickets ? |
1116 | 1116 | if ($get_original_ticket_spaces) { |
1117 | 1117 | // then grab the available spaces from the "tickets" array and compare with the above to get the lowest number |
@@ -1186,7 +1186,7 @@ discard block |
||
1186 | 1186 | { |
1187 | 1187 | if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
1188 | 1188 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
1189 | - foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
1189 | + foreach ((array) self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
1190 | 1190 | // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
1191 | 1191 | self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
1192 | 1192 | } |
@@ -1205,7 +1205,7 @@ discard block |
||
1205 | 1205 | { |
1206 | 1206 | // add some style |
1207 | 1207 | if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
1208 | - wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'); |
|
1208 | + wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css'); |
|
1209 | 1209 | wp_enqueue_style('ticket_selector'); |
1210 | 1210 | // make it dance |
1211 | 1211 | // wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE); |
@@ -1221,7 +1221,7 @@ discard block |
||
1221 | 1221 | if (EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
1222 | 1222 | && EE_Registry::instance()->REQ->get('action') === 'edit' |
1223 | 1223 | ) { |
1224 | - wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL . 'ticket-selector-embed.js', |
|
1224 | + wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL.'ticket-selector-embed.js', |
|
1225 | 1225 | array('ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
1226 | 1226 | wp_enqueue_script('ticket_selector_embed'); |
1227 | 1227 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\exceptions\InvalidEntityException; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -17,1709 +17,1709 @@ discard block |
||
17 | 17 | class EED_Single_Page_Checkout extends EED_Module |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * $_initialized - has the SPCO controller already been initialized ? |
|
22 | - * |
|
23 | - * @access private |
|
24 | - * @var bool $_initialized |
|
25 | - */ |
|
26 | - private static $_initialized = false; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
31 | - * |
|
32 | - * @access private |
|
33 | - * @var bool $_valid_checkout |
|
34 | - */ |
|
35 | - private static $_checkout_verified = true; |
|
36 | - |
|
37 | - /** |
|
38 | - * $_reg_steps_array - holds initial array of reg steps |
|
39 | - * |
|
40 | - * @access private |
|
41 | - * @var array $_reg_steps_array |
|
42 | - */ |
|
43 | - private static $_reg_steps_array = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Checkout $checkout |
|
50 | - */ |
|
51 | - public $checkout; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return EED_Single_Page_Checkout |
|
57 | - */ |
|
58 | - public static function instance() |
|
59 | - { |
|
60 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
61 | - return parent::get_instance(__CLASS__); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @return EE_CART |
|
68 | - */ |
|
69 | - public function cart() |
|
70 | - { |
|
71 | - return $this->checkout->cart; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @return EE_Transaction |
|
78 | - */ |
|
79 | - public function transaction() |
|
80 | - { |
|
81 | - return $this->checkout->transaction; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @return void |
|
91 | - * @throws \EE_Error |
|
92 | - */ |
|
93 | - public static function set_hooks() |
|
94 | - { |
|
95 | - EED_Single_Page_Checkout::set_definitions(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @return void |
|
105 | - * @throws \EE_Error |
|
106 | - */ |
|
107 | - public static function set_hooks_admin() |
|
108 | - { |
|
109 | - EED_Single_Page_Checkout::set_definitions(); |
|
110 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
111 | - // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called |
|
112 | - add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1); |
|
113 | - return; |
|
114 | - } |
|
115 | - // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
|
116 | - ob_start(); |
|
117 | - EED_Single_Page_Checkout::load_request_handler(); |
|
118 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
119 | - // set ajax hooks |
|
120 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
121 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
122 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
123 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
124 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
125 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * process ajax request |
|
132 | - * |
|
133 | - * @param string $ajax_action |
|
134 | - * @throws \EE_Error |
|
135 | - */ |
|
136 | - public static function process_ajax_request($ajax_action) |
|
137 | - { |
|
138 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
139 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * ajax display registration step |
|
146 | - * |
|
147 | - * @throws \EE_Error |
|
148 | - */ |
|
149 | - public static function display_reg_step() |
|
150 | - { |
|
151 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * ajax process registration step |
|
158 | - * |
|
159 | - * @throws \EE_Error |
|
160 | - */ |
|
161 | - public static function process_reg_step() |
|
162 | - { |
|
163 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * ajax process registration step |
|
170 | - * |
|
171 | - * @throws \EE_Error |
|
172 | - */ |
|
173 | - public static function update_reg_step() |
|
174 | - { |
|
175 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * update_checkout |
|
182 | - * |
|
183 | - * @access public |
|
184 | - * @return void |
|
185 | - * @throws \EE_Error |
|
186 | - */ |
|
187 | - public static function update_checkout() |
|
188 | - { |
|
189 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * load_request_handler |
|
196 | - * |
|
197 | - * @access public |
|
198 | - * @return void |
|
199 | - */ |
|
200 | - public static function load_request_handler() |
|
201 | - { |
|
202 | - // load core Request_Handler class |
|
203 | - if ( ! isset(EE_Registry::instance()->REQ)) { |
|
204 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * set_definitions |
|
212 | - * |
|
213 | - * @access public |
|
214 | - * @return void |
|
215 | - * @throws \EE_Error |
|
216 | - */ |
|
217 | - public static function set_definitions() |
|
218 | - { |
|
219 | - define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
220 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
221 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
222 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
223 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
224 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
225 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
226 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
227 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
228 | - __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
229 | - 'event_espresso'), |
|
230 | - '<h4 class="important-notice">', |
|
231 | - '</h4>', |
|
232 | - '<br />', |
|
233 | - '<p>', |
|
234 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
235 | - '">', |
|
236 | - '</a>', |
|
237 | - '</p>' |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * load_reg_steps |
|
245 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
246 | - * |
|
247 | - * @access private |
|
248 | - * @throws EE_Error |
|
249 | - * @return void |
|
250 | - */ |
|
251 | - public static function load_reg_steps() |
|
252 | - { |
|
253 | - static $reg_steps_loaded = false; |
|
254 | - if ($reg_steps_loaded) { |
|
255 | - return; |
|
256 | - } |
|
257 | - // filter list of reg_steps |
|
258 | - $reg_steps_to_load = (array)apply_filters( |
|
259 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
260 | - EED_Single_Page_Checkout::get_reg_steps() |
|
261 | - ); |
|
262 | - // sort by key (order) |
|
263 | - ksort($reg_steps_to_load); |
|
264 | - // loop through folders |
|
265 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
266 | - // we need a |
|
267 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
268 | - // copy over to the reg_steps_array |
|
269 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
270 | - // register custom key route for each reg step |
|
271 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
272 | - EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
273 | - // add AJAX or other hooks |
|
274 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
275 | - // setup autoloaders if necessary |
|
276 | - if ( ! class_exists($reg_step['class_name'])) { |
|
277 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true); |
|
278 | - } |
|
279 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
280 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - $reg_steps_loaded = true; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * get_reg_steps |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @return array |
|
295 | - */ |
|
296 | - public static function get_reg_steps() |
|
297 | - { |
|
298 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
299 | - if (empty($reg_steps)) { |
|
300 | - $reg_steps = array( |
|
301 | - 10 => array( |
|
302 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
303 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
304 | - 'slug' => 'attendee_information', |
|
305 | - 'has_hooks' => false, |
|
306 | - ), |
|
307 | - 20 => array( |
|
308 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
309 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
310 | - 'slug' => 'registration_confirmation', |
|
311 | - 'has_hooks' => false, |
|
312 | - ), |
|
313 | - 30 => array( |
|
314 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
315 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
316 | - 'slug' => 'payment_options', |
|
317 | - 'has_hooks' => true, |
|
318 | - ), |
|
319 | - 999 => array( |
|
320 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
321 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
322 | - 'slug' => 'finalize_registration', |
|
323 | - 'has_hooks' => false, |
|
324 | - ), |
|
325 | - ); |
|
326 | - } |
|
327 | - return $reg_steps; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * registration_checkout_for_admin |
|
334 | - * |
|
335 | - * @access public |
|
336 | - * @return string |
|
337 | - * @throws \EE_Error |
|
338 | - */ |
|
339 | - public static function registration_checkout_for_admin() |
|
340 | - { |
|
341 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
342 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
343 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
344 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
345 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
346 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
347 | - return EE_Registry::instance()->REQ->get_output(); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * process_registration_from_admin |
|
354 | - * |
|
355 | - * @access public |
|
356 | - * @return \EE_Transaction |
|
357 | - * @throws \EE_Error |
|
358 | - */ |
|
359 | - public static function process_registration_from_admin() |
|
360 | - { |
|
361 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
362 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
363 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
364 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
365 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
366 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
367 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
368 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
369 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
370 | - if ($final_reg_step->process_reg_step()) { |
|
371 | - $final_reg_step->set_completed(); |
|
372 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
373 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
374 | - } |
|
375 | - } |
|
376 | - } |
|
377 | - return null; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * run |
|
384 | - * |
|
385 | - * @access public |
|
386 | - * @param WP_Query $WP_Query |
|
387 | - * @return void |
|
388 | - * @throws \EE_Error |
|
389 | - */ |
|
390 | - public function run($WP_Query) |
|
391 | - { |
|
392 | - if ( |
|
393 | - $WP_Query instanceof WP_Query |
|
394 | - && $WP_Query->is_main_query() |
|
395 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
396 | - && $this->_is_reg_checkout() |
|
397 | - ) { |
|
398 | - $this->_initialize(); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * determines whether current url matches reg page url |
|
406 | - * |
|
407 | - * @return bool |
|
408 | - */ |
|
409 | - protected function _is_reg_checkout() |
|
410 | - { |
|
411 | - // get current permalink for reg page without any extra query args |
|
412 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
413 | - // get request URI for current request, but without the scheme or host |
|
414 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
415 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
416 | - // get array of query args from the current request URI |
|
417 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
418 | - // grab page id if it is set |
|
419 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
420 | - // and remove the page id from the query args (we will re-add it later) |
|
421 | - unset($query_args['page_id']); |
|
422 | - // now strip all query args from current request URI |
|
423 | - $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri); |
|
424 | - // and re-add the page id if it was set |
|
425 | - if ($page_id) { |
|
426 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
427 | - } |
|
428 | - // remove slashes and ? |
|
429 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
430 | - // is current request URI part of the known full reg page URL ? |
|
431 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * run |
|
438 | - * |
|
439 | - * @access public |
|
440 | - * @param WP_Query $WP_Query |
|
441 | - * @return void |
|
442 | - * @throws \EE_Error |
|
443 | - */ |
|
444 | - public static function init($WP_Query) |
|
445 | - { |
|
446 | - EED_Single_Page_Checkout::instance()->run($WP_Query); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * _initialize - initial module setup |
|
453 | - * |
|
454 | - * @access private |
|
455 | - * @throws EE_Error |
|
456 | - * @return void |
|
457 | - */ |
|
458 | - private function _initialize() |
|
459 | - { |
|
460 | - // ensure SPCO doesn't run twice |
|
461 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
462 | - return; |
|
463 | - } |
|
464 | - try { |
|
465 | - $this->_verify_session(); |
|
466 | - // setup the EE_Checkout object |
|
467 | - $this->checkout = $this->_initialize_checkout(); |
|
468 | - // filter checkout |
|
469 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
470 | - // get the $_GET |
|
471 | - $this->_get_request_vars(); |
|
472 | - if ($this->_block_bots()) { |
|
473 | - return; |
|
474 | - } |
|
475 | - // filter continue_reg |
|
476 | - $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout); |
|
477 | - // load the reg steps array |
|
478 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
479 | - EED_Single_Page_Checkout::$_initialized = true; |
|
480 | - return; |
|
481 | - } |
|
482 | - // set the current step |
|
483 | - $this->checkout->set_current_step($this->checkout->step); |
|
484 | - // and the next step |
|
485 | - $this->checkout->set_next_step(); |
|
486 | - // verify that everything has been setup correctly |
|
487 | - if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
488 | - EED_Single_Page_Checkout::$_initialized = true; |
|
489 | - return; |
|
490 | - } |
|
491 | - // lock the transaction |
|
492 | - $this->checkout->transaction->lock(); |
|
493 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
494 | - $this->checkout->refresh_all_entities(); |
|
495 | - // set amount owing |
|
496 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
497 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
498 | - $this->_initialize_reg_steps(); |
|
499 | - // DEBUG LOG |
|
500 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
501 | - // get reg form |
|
502 | - if( ! $this->_check_form_submission()) { |
|
503 | - EED_Single_Page_Checkout::$_initialized = true; |
|
504 | - return; |
|
505 | - } |
|
506 | - // checkout the action!!! |
|
507 | - $this->_process_form_action(); |
|
508 | - // add some style and make it dance |
|
509 | - $this->add_styles_and_scripts(); |
|
510 | - // kk... SPCO has successfully run |
|
511 | - EED_Single_Page_Checkout::$_initialized = true; |
|
512 | - // set no cache headers and constants |
|
513 | - EE_System::do_not_cache(); |
|
514 | - // add anchor |
|
515 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
516 | - // remove transaction lock |
|
517 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
518 | - } catch (Exception $e) { |
|
519 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * _verify_session |
|
527 | - * checks that the session is valid and not expired |
|
528 | - * |
|
529 | - * @access private |
|
530 | - * @throws EE_Error |
|
531 | - */ |
|
532 | - private function _verify_session() |
|
533 | - { |
|
534 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
535 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
536 | - } |
|
537 | - // is session still valid ? |
|
538 | - if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') { |
|
539 | - $this->checkout = new EE_Checkout(); |
|
540 | - EE_Registry::instance()->SSN->reset_cart(); |
|
541 | - EE_Registry::instance()->SSN->reset_checkout(); |
|
542 | - EE_Registry::instance()->SSN->reset_transaction(); |
|
543 | - EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__, |
|
544 | - __FUNCTION__, __LINE__); |
|
545 | - EE_Registry::instance()->SSN->reset_expired(); |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * _initialize_checkout |
|
553 | - * loads and instantiates EE_Checkout |
|
554 | - * |
|
555 | - * @access private |
|
556 | - * @throws EE_Error |
|
557 | - * @return EE_Checkout |
|
558 | - */ |
|
559 | - private function _initialize_checkout() |
|
560 | - { |
|
561 | - // look in session for existing checkout |
|
562 | - /** @type EE_Checkout $checkout */ |
|
563 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
564 | - // verify |
|
565 | - if ( ! $checkout instanceof EE_Checkout) { |
|
566 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
567 | - $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false); |
|
568 | - } else { |
|
569 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
570 | - $this->unlock_transaction(); |
|
571 | - wp_safe_redirect($checkout->redirect_url); |
|
572 | - exit(); |
|
573 | - } |
|
574 | - } |
|
575 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
576 | - // verify again |
|
577 | - if ( ! $checkout instanceof EE_Checkout) { |
|
578 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
579 | - } |
|
580 | - // reset anything that needs a clean slate for each request |
|
581 | - $checkout->reset_for_current_request(); |
|
582 | - return $checkout; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * _get_request_vars |
|
589 | - * |
|
590 | - * @access private |
|
591 | - * @return void |
|
592 | - * @throws \EE_Error |
|
593 | - */ |
|
594 | - private function _get_request_vars() |
|
595 | - { |
|
596 | - // load classes |
|
597 | - EED_Single_Page_Checkout::load_request_handler(); |
|
598 | - //make sure this request is marked as belonging to EE |
|
599 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
600 | - // which step is being requested ? |
|
601 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
602 | - // which step is being edited ? |
|
603 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
604 | - // and what we're doing on the current step |
|
605 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
606 | - // timestamp |
|
607 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
608 | - // returning to edit ? |
|
609 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
610 | - // or some other kind of revisit ? |
|
611 | - $this->checkout->revisit = filter_var( |
|
612 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
613 | - FILTER_VALIDATE_BOOLEAN |
|
614 | - ); |
|
615 | - // and whether or not to generate a reg form for this request |
|
616 | - $this->checkout->generate_reg_form = filter_var( |
|
617 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
618 | - FILTER_VALIDATE_BOOLEAN |
|
619 | - ); |
|
620 | - // and whether or not to process a reg form submission for this request |
|
621 | - $this->checkout->process_form_submission = filter_var( |
|
622 | - EE_Registry::instance()->REQ->get( |
|
623 | - 'process_form_submission', |
|
624 | - $this->checkout->action === 'process_reg_step' |
|
625 | - ), |
|
626 | - FILTER_VALIDATE_BOOLEAN |
|
627 | - ); |
|
628 | - $this->checkout->process_form_submission = filter_var( |
|
629 | - $this->checkout->action !== 'display_spco_reg_step' |
|
630 | - ? $this->checkout->process_form_submission |
|
631 | - : false, |
|
632 | - FILTER_VALIDATE_BOOLEAN |
|
633 | - ); |
|
634 | - // $this->_display_request_vars(); |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * _display_request_vars |
|
641 | - * |
|
642 | - * @access protected |
|
643 | - * @return void |
|
644 | - */ |
|
645 | - protected function _display_request_vars() |
|
646 | - { |
|
647 | - if ( ! WP_DEBUG) { |
|
648 | - return; |
|
649 | - } |
|
650 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
651 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
652 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
653 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
654 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
655 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
656 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
657 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * _block_bots |
|
664 | - * checks that the incoming request has either of the following set: |
|
665 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
666 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
667 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
668 | - * then where you coming from man? |
|
669 | - * |
|
670 | - * @return boolean |
|
671 | - */ |
|
672 | - private function _block_bots() |
|
673 | - { |
|
674 | - $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
675 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
676 | - return true; |
|
677 | - } |
|
678 | - return false; |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * _get_first_step |
|
685 | - * gets slug for first step in $_reg_steps_array |
|
686 | - * |
|
687 | - * @access private |
|
688 | - * @throws EE_Error |
|
689 | - * @return string |
|
690 | - */ |
|
691 | - private function _get_first_step() |
|
692 | - { |
|
693 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
694 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * _load_and_instantiate_reg_steps |
|
701 | - * instantiates each reg step based on the loaded reg_steps array |
|
702 | - * |
|
703 | - * @access private |
|
704 | - * @throws EE_Error |
|
705 | - * @return bool |
|
706 | - */ |
|
707 | - private function _load_and_instantiate_reg_steps() |
|
708 | - { |
|
709 | - // have reg_steps already been instantiated ? |
|
710 | - if ( |
|
711 | - empty($this->checkout->reg_steps) |
|
712 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
713 | - ) { |
|
714 | - // if not, then loop through raw reg steps array |
|
715 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
716 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
717 | - return false; |
|
718 | - } |
|
719 | - } |
|
720 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
721 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
722 | - // skip the registration_confirmation page ? |
|
723 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
724 | - // just remove it from the reg steps array |
|
725 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
726 | - } else if ( |
|
727 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
728 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
729 | - ) { |
|
730 | - // set the order to something big like 100 |
|
731 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
732 | - } |
|
733 | - // filter the array for good luck |
|
734 | - $this->checkout->reg_steps = apply_filters( |
|
735 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
736 | - $this->checkout->reg_steps |
|
737 | - ); |
|
738 | - // finally re-sort based on the reg step class order properties |
|
739 | - $this->checkout->sort_reg_steps(); |
|
740 | - } else { |
|
741 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
742 | - // set all current step stati to FALSE |
|
743 | - $reg_step->set_is_current_step(false); |
|
744 | - } |
|
745 | - } |
|
746 | - if (empty($this->checkout->reg_steps)) { |
|
747 | - EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
748 | - return false; |
|
749 | - } |
|
750 | - // make reg step details available to JS |
|
751 | - $this->checkout->set_reg_step_JSON_info(); |
|
752 | - return true; |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _load_and_instantiate_reg_step |
|
759 | - * |
|
760 | - * @access private |
|
761 | - * @param array $reg_step |
|
762 | - * @param int $order |
|
763 | - * @return bool |
|
764 | - */ |
|
765 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
766 | - { |
|
767 | - // we need a file_path, class_name, and slug to add a reg step |
|
768 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
769 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
770 | - if ( |
|
771 | - $this->checkout->reg_url_link |
|
772 | - && $this->checkout->step !== $reg_step['slug'] |
|
773 | - && $reg_step['slug'] !== 'finalize_registration' |
|
774 | - ) { |
|
775 | - return true; |
|
776 | - } |
|
777 | - // instantiate step class using file path and class name |
|
778 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
779 | - $reg_step['file_path'], |
|
780 | - $reg_step['class_name'], |
|
781 | - 'class', |
|
782 | - $this->checkout, |
|
783 | - false |
|
784 | - ); |
|
785 | - // did we gets the goods ? |
|
786 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
787 | - // set reg step order based on config |
|
788 | - $reg_step_obj->set_order($order); |
|
789 | - // add instantiated reg step object to the master reg steps array |
|
790 | - $this->checkout->add_reg_step($reg_step_obj); |
|
791 | - } else { |
|
792 | - EE_Error::add_error( |
|
793 | - __('The current step could not be set.', 'event_espresso'), |
|
794 | - __FILE__, __FUNCTION__, __LINE__ |
|
795 | - ); |
|
796 | - return false; |
|
797 | - } |
|
798 | - } else { |
|
799 | - if (WP_DEBUG) { |
|
800 | - EE_Error::add_error( |
|
801 | - sprintf( |
|
802 | - __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
803 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
804 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
805 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
806 | - '<ul>', |
|
807 | - '<li>', |
|
808 | - '</li>', |
|
809 | - '</ul>' |
|
810 | - ), |
|
811 | - __FILE__, __FUNCTION__, __LINE__ |
|
812 | - ); |
|
813 | - } |
|
814 | - return false; |
|
815 | - } |
|
816 | - return true; |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - |
|
821 | - /** |
|
822 | - * _verify_transaction_and_get_registrations |
|
823 | - * |
|
824 | - * @access private |
|
825 | - * @return bool |
|
826 | - */ |
|
827 | - private function _verify_transaction_and_get_registrations() |
|
828 | - { |
|
829 | - // was there already a valid transaction in the checkout from the session ? |
|
830 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
831 | - // get transaction from db or session |
|
832 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
833 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
834 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
835 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
836 | - EE_Error::add_error( |
|
837 | - __('Your Registration and Transaction information could not be retrieved from the db.', |
|
838 | - 'event_espresso'), |
|
839 | - __FILE__, __FUNCTION__, __LINE__ |
|
840 | - ); |
|
841 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
842 | - // add some style and make it dance |
|
843 | - $this->add_styles_and_scripts(); |
|
844 | - EED_Single_Page_Checkout::$_initialized = true; |
|
845 | - return false; |
|
846 | - } |
|
847 | - // and the registrations for the transaction |
|
848 | - $this->_get_registrations($this->checkout->transaction); |
|
849 | - } |
|
850 | - return true; |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - |
|
855 | - /** |
|
856 | - * _get_transaction_and_cart_for_previous_visit |
|
857 | - * |
|
858 | - * @access private |
|
859 | - * @return mixed EE_Transaction|NULL |
|
860 | - */ |
|
861 | - private function _get_transaction_and_cart_for_previous_visit() |
|
862 | - { |
|
863 | - /** @var $TXN_model EEM_Transaction */ |
|
864 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
865 | - // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
|
866 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
867 | - // verify transaction |
|
868 | - if ($transaction instanceof EE_Transaction) { |
|
869 | - // and get the cart that was used for that transaction |
|
870 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
871 | - return $transaction; |
|
872 | - } else { |
|
873 | - EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
874 | - return null; |
|
875 | - } |
|
876 | - } |
|
877 | - |
|
878 | - |
|
879 | - |
|
880 | - /** |
|
881 | - * _get_cart_for_transaction |
|
882 | - * |
|
883 | - * @access private |
|
884 | - * @param EE_Transaction $transaction |
|
885 | - * @return EE_Cart |
|
886 | - */ |
|
887 | - private function _get_cart_for_transaction($transaction) |
|
888 | - { |
|
889 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
890 | - } |
|
891 | - |
|
892 | - |
|
893 | - |
|
894 | - /** |
|
895 | - * get_cart_for_transaction |
|
896 | - * |
|
897 | - * @access public |
|
898 | - * @param EE_Transaction $transaction |
|
899 | - * @return EE_Cart |
|
900 | - */ |
|
901 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
902 | - { |
|
903 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
904 | - } |
|
905 | - |
|
906 | - |
|
907 | - |
|
908 | - /** |
|
909 | - * _get_transaction_and_cart_for_current_session |
|
910 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
911 | - * |
|
912 | - * @access private |
|
913 | - * @return EE_Transaction |
|
914 | - * @throws \EE_Error |
|
915 | - */ |
|
916 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
917 | - { |
|
918 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
919 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
920 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
921 | - // and then create a new transaction |
|
922 | - $transaction = $this->_initialize_transaction(); |
|
923 | - // verify transaction |
|
924 | - if ($transaction instanceof EE_Transaction) { |
|
925 | - // save it so that we have an ID for other objects to use |
|
926 | - $transaction->save(); |
|
927 | - // and save TXN data to the cart |
|
928 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
929 | - } else { |
|
930 | - EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
931 | - } |
|
932 | - return $transaction; |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - |
|
937 | - /** |
|
938 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
939 | - * |
|
940 | - * @access private |
|
941 | - * @return mixed EE_Transaction|NULL |
|
942 | - */ |
|
943 | - private function _initialize_transaction() |
|
944 | - { |
|
945 | - try { |
|
946 | - // ensure cart totals have been calculated |
|
947 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
948 | - // grab the cart grand total |
|
949 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
950 | - // create new TXN |
|
951 | - $transaction = EE_Transaction::new_instance( |
|
952 | - array( |
|
953 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
954 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
955 | - 'TXN_paid' => 0, |
|
956 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
957 | - ) |
|
958 | - ); |
|
959 | - // save it so that we have an ID for other objects to use |
|
960 | - $transaction->save(); |
|
961 | - // set cron job for following up on TXNs after their session has expired |
|
962 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
963 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
964 | - $transaction->ID() |
|
965 | - ); |
|
966 | - return $transaction; |
|
967 | - } catch (Exception $e) { |
|
968 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
969 | - } |
|
970 | - return null; |
|
971 | - } |
|
972 | - |
|
973 | - |
|
974 | - |
|
975 | - /** |
|
976 | - * _get_registrations |
|
977 | - * |
|
978 | - * @access private |
|
979 | - * @param EE_Transaction $transaction |
|
980 | - * @return void |
|
981 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
982 | - * @throws \EE_Error |
|
983 | - */ |
|
984 | - private function _get_registrations(EE_Transaction $transaction) |
|
985 | - { |
|
986 | - // first step: grab the registrants { : o |
|
987 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
988 | - // verify registrations have been set |
|
989 | - if (empty($registrations)) { |
|
990 | - // if no cached registrations, then check the db |
|
991 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
992 | - // still nothing ? well as long as this isn't a revisit |
|
993 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
994 | - // generate new registrations from scratch |
|
995 | - $registrations = $this->_initialize_registrations($transaction); |
|
996 | - } |
|
997 | - } |
|
998 | - // sort by their original registration order |
|
999 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1000 | - // then loop thru the array |
|
1001 | - foreach ($registrations as $registration) { |
|
1002 | - // verify each registration |
|
1003 | - if ($registration instanceof EE_Registration) { |
|
1004 | - // we display all attendee info for the primary registrant |
|
1005 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1006 | - && $registration->is_primary_registrant() |
|
1007 | - ) { |
|
1008 | - $this->checkout->primary_revisit = true; |
|
1009 | - break; |
|
1010 | - } else if ($this->checkout->revisit |
|
1011 | - && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
1012 | - ) { |
|
1013 | - // but hide info if it doesn't belong to you |
|
1014 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
1015 | - } |
|
1016 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1017 | - } |
|
1018 | - } |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - |
|
1023 | - /** |
|
1024 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1025 | - * |
|
1026 | - * @access private |
|
1027 | - * @param EE_Transaction $transaction |
|
1028 | - * @return array |
|
1029 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
1030 | - * @throws \EE_Error |
|
1031 | - */ |
|
1032 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
1033 | - { |
|
1034 | - $att_nmbr = 0; |
|
1035 | - $registrations = array(); |
|
1036 | - if ($transaction instanceof EE_Transaction) { |
|
1037 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1038 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1039 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1040 | - // now let's add the cart items to the $transaction |
|
1041 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1042 | - //do the following for each ticket of this type they selected |
|
1043 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1044 | - $att_nmbr++; |
|
1045 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1046 | - $CreateRegistrationCommand = EE_Registry::instance() |
|
1047 | - ->create( |
|
1048 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1049 | - array( |
|
1050 | - $transaction, |
|
1051 | - $line_item, |
|
1052 | - $att_nmbr, |
|
1053 | - $this->checkout->total_ticket_count, |
|
1054 | - ) |
|
1055 | - ); |
|
1056 | - // override capabilities for frontend registrations |
|
1057 | - if ( ! is_admin()) { |
|
1058 | - $CreateRegistrationCommand->setCapCheck( |
|
1059 | - new PublicCapabilities('', 'create_new_registration') |
|
1060 | - ); |
|
1061 | - } |
|
1062 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1063 | - if ( ! $registration instanceof EE_Registration) { |
|
1064 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1065 | - } |
|
1066 | - $registrations[ $registration->ID() ] = $registration; |
|
1067 | - } |
|
1068 | - } |
|
1069 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1070 | - } |
|
1071 | - return $registrations; |
|
1072 | - } |
|
1073 | - |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * sorts registrations by REG_count |
|
1078 | - * |
|
1079 | - * @access public |
|
1080 | - * @param EE_Registration $reg_A |
|
1081 | - * @param EE_Registration $reg_B |
|
1082 | - * @return int |
|
1083 | - */ |
|
1084 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1085 | - { |
|
1086 | - // this shouldn't ever happen within the same TXN, but oh well |
|
1087 | - if ($reg_A->count() === $reg_B->count()) { |
|
1088 | - return 0; |
|
1089 | - } |
|
1090 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * _final_verifications |
|
1097 | - * just makes sure that everything is set up correctly before proceeding |
|
1098 | - * |
|
1099 | - * @access private |
|
1100 | - * @return bool |
|
1101 | - * @throws \EE_Error |
|
1102 | - */ |
|
1103 | - private function _final_verifications() |
|
1104 | - { |
|
1105 | - // filter checkout |
|
1106 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
1107 | - //verify that current step is still set correctly |
|
1108 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1109 | - EE_Error::add_error( |
|
1110 | - __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1111 | - __FILE__, |
|
1112 | - __FUNCTION__, |
|
1113 | - __LINE__ |
|
1114 | - ); |
|
1115 | - return false; |
|
1116 | - } |
|
1117 | - // if returning to SPCO, then verify that primary registrant is set |
|
1118 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
1119 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1120 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1121 | - EE_Error::add_error( |
|
1122 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1123 | - __FILE__, |
|
1124 | - __FUNCTION__, |
|
1125 | - __LINE__ |
|
1126 | - ); |
|
1127 | - return false; |
|
1128 | - } |
|
1129 | - $valid_registrant = null; |
|
1130 | - foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
1131 | - if ( |
|
1132 | - $registration instanceof EE_Registration |
|
1133 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1134 | - ) { |
|
1135 | - $valid_registrant = $registration; |
|
1136 | - } |
|
1137 | - } |
|
1138 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1139 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1140 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1141 | - // clear the session, mark the checkout as unverified, and try again |
|
1142 | - EE_Registry::instance()->SSN->clear_session(); |
|
1143 | - EED_Single_Page_Checkout::$_initialized = false; |
|
1144 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1145 | - $this->_initialize(); |
|
1146 | - EE_Error::reset_notices(); |
|
1147 | - return false; |
|
1148 | - } |
|
1149 | - EE_Error::add_error( |
|
1150 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1151 | - __FILE__, |
|
1152 | - __FUNCTION__, |
|
1153 | - __LINE__ |
|
1154 | - ); |
|
1155 | - return false; |
|
1156 | - } |
|
1157 | - } |
|
1158 | - // now that things have been kinda sufficiently verified, |
|
1159 | - // let's add the checkout to the session so that's available other systems |
|
1160 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1161 | - return true; |
|
1162 | - } |
|
1163 | - |
|
1164 | - |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * _initialize_reg_steps |
|
1168 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1169 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1170 | - * |
|
1171 | - * @access private |
|
1172 | - * @param bool $reinitializing |
|
1173 | - * @throws \EE_Error |
|
1174 | - */ |
|
1175 | - private function _initialize_reg_steps($reinitializing = false) |
|
1176 | - { |
|
1177 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1178 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1179 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
1180 | - if ( ! $reg_step->initialize_reg_step()) { |
|
1181 | - // if not initialized then maybe this step is being removed... |
|
1182 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1183 | - // if it was the current step, then we need to start over here |
|
1184 | - $this->_initialize_reg_steps(true); |
|
1185 | - return; |
|
1186 | - } |
|
1187 | - continue; |
|
1188 | - } |
|
1189 | - // add css and JS for current step |
|
1190 | - $reg_step->enqueue_styles_and_scripts(); |
|
1191 | - // i18n |
|
1192 | - $reg_step->translate_js_strings(); |
|
1193 | - if ($reg_step->is_current_step()) { |
|
1194 | - // the text that appears on the reg step form submit button |
|
1195 | - $reg_step->set_submit_button_text(); |
|
1196 | - } |
|
1197 | - } |
|
1198 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1199 | - do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
1200 | - } |
|
1201 | - |
|
1202 | - |
|
1203 | - |
|
1204 | - /** |
|
1205 | - * _check_form_submission |
|
1206 | - * |
|
1207 | - * @access private |
|
1208 | - * @return boolean |
|
1209 | - */ |
|
1210 | - private function _check_form_submission() |
|
1211 | - { |
|
1212 | - //does this request require the reg form to be generated ? |
|
1213 | - if ($this->checkout->generate_reg_form) { |
|
1214 | - // ever heard that song by Blue Rodeo ? |
|
1215 | - try { |
|
1216 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1217 | - // if not displaying a form, then check for form submission |
|
1218 | - if ( |
|
1219 | - $this->checkout->process_form_submission |
|
1220 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
1221 | - ) { |
|
1222 | - // clear out any old data in case this step is being run again |
|
1223 | - $this->checkout->current_step->set_valid_data(array()); |
|
1224 | - // capture submitted form data |
|
1225 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
1226 | - apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout) |
|
1227 | - ); |
|
1228 | - // validate submitted form data |
|
1229 | - if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1230 | - // thou shall not pass !!! |
|
1231 | - $this->checkout->continue_reg = false; |
|
1232 | - // any form validation errors? |
|
1233 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1234 | - $submission_error_messages = array(); |
|
1235 | - // bad, bad, bad registrant |
|
1236 | - foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
1237 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1238 | - $submission_error_messages[] = sprintf( |
|
1239 | - __('%s : %s', 'event_espresso'), |
|
1240 | - $validation_error->get_form_section()->html_label_text(), |
|
1241 | - $validation_error->getMessage() |
|
1242 | - ); |
|
1243 | - } |
|
1244 | - } |
|
1245 | - EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
1246 | - } |
|
1247 | - // well not really... what will happen is we'll just get redirected back to redo the current step |
|
1248 | - $this->go_to_next_step(); |
|
1249 | - return false; |
|
1250 | - } |
|
1251 | - } |
|
1252 | - } catch (EE_Error $e) { |
|
1253 | - $e->get_error(); |
|
1254 | - } |
|
1255 | - } |
|
1256 | - return true; |
|
1257 | - } |
|
1258 | - |
|
1259 | - |
|
1260 | - |
|
1261 | - /** |
|
1262 | - * _process_action |
|
1263 | - * |
|
1264 | - * @access private |
|
1265 | - * @return void |
|
1266 | - * @throws \EE_Error |
|
1267 | - */ |
|
1268 | - private function _process_form_action() |
|
1269 | - { |
|
1270 | - // what cha wanna do? |
|
1271 | - switch ($this->checkout->action) { |
|
1272 | - // AJAX next step reg form |
|
1273 | - case 'display_spco_reg_step' : |
|
1274 | - $this->checkout->redirect = false; |
|
1275 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1276 | - $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
1277 | - } |
|
1278 | - break; |
|
1279 | - default : |
|
1280 | - // meh... do one of those other steps first |
|
1281 | - if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
1282 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1283 | - do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1284 | - // call action on current step |
|
1285 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1286 | - // good registrant, you get to proceed |
|
1287 | - if ( |
|
1288 | - $this->checkout->current_step->success_message() !== '' |
|
1289 | - && apply_filters( |
|
1290 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1291 | - false |
|
1292 | - ) |
|
1293 | - ) { |
|
1294 | - EE_Error::add_success( |
|
1295 | - $this->checkout->current_step->success_message() |
|
1296 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1297 | - ); |
|
1298 | - } |
|
1299 | - // pack it up, pack it in... |
|
1300 | - $this->_setup_redirect(); |
|
1301 | - } |
|
1302 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1303 | - do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1304 | - } else { |
|
1305 | - EE_Error::add_error( |
|
1306 | - sprintf( |
|
1307 | - __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
1308 | - $this->checkout->action, |
|
1309 | - $this->checkout->current_step->name() |
|
1310 | - ), |
|
1311 | - __FILE__, |
|
1312 | - __FUNCTION__, |
|
1313 | - __LINE__ |
|
1314 | - ); |
|
1315 | - } |
|
1316 | - // end default |
|
1317 | - } |
|
1318 | - // store our progress so far |
|
1319 | - $this->checkout->stash_transaction_and_checkout(); |
|
1320 | - // advance to the next step! If you pass GO, collect $200 |
|
1321 | - $this->go_to_next_step(); |
|
1322 | - } |
|
1323 | - |
|
1324 | - |
|
1325 | - |
|
1326 | - /** |
|
1327 | - * add_styles_and_scripts |
|
1328 | - * |
|
1329 | - * @access public |
|
1330 | - * @return void |
|
1331 | - */ |
|
1332 | - public function add_styles_and_scripts() |
|
1333 | - { |
|
1334 | - // i18n |
|
1335 | - $this->translate_js_strings(); |
|
1336 | - if ($this->checkout->admin_request) { |
|
1337 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1338 | - } else { |
|
1339 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1340 | - } |
|
1341 | - } |
|
1342 | - |
|
1343 | - |
|
1344 | - |
|
1345 | - /** |
|
1346 | - * translate_js_strings |
|
1347 | - * |
|
1348 | - * @access public |
|
1349 | - * @return void |
|
1350 | - */ |
|
1351 | - public function translate_js_strings() |
|
1352 | - { |
|
1353 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1354 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1355 | - EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1356 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1357 | - EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
1358 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1359 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
|
1360 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
|
1361 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1362 | - __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), |
|
1363 | - '<br/>', |
|
1364 | - '<br/>' |
|
1365 | - ); |
|
1366 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1367 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1368 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1369 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1370 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1371 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1372 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1373 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1374 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1375 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1376 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1377 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1378 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1379 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1380 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1381 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1382 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1383 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1384 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1385 | - __( |
|
1386 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
1387 | - 'event_espresso' |
|
1388 | - ), |
|
1389 | - '<h4 class="important-notice">', |
|
1390 | - '</h4>', |
|
1391 | - '<br />', |
|
1392 | - '<p>', |
|
1393 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1394 | - '">', |
|
1395 | - '</a>', |
|
1396 | - '</p>' |
|
1397 | - ); |
|
1398 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
1399 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1400 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1401 | - ); |
|
1402 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1403 | - 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1404 | - ); |
|
1405 | - } |
|
1406 | - |
|
1407 | - |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * enqueue_styles_and_scripts |
|
1411 | - * |
|
1412 | - * @access public |
|
1413 | - * @return void |
|
1414 | - * @throws \EE_Error |
|
1415 | - */ |
|
1416 | - public function enqueue_styles_and_scripts() |
|
1417 | - { |
|
1418 | - // load css |
|
1419 | - wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1420 | - wp_enqueue_style('single_page_checkout'); |
|
1421 | - // load JS |
|
1422 | - wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
1423 | - wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
1424 | - wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
1425 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1426 | - $this->checkout->registration_form->enqueue_js(); |
|
1427 | - } |
|
1428 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1429 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
1430 | - } |
|
1431 | - wp_enqueue_script('single_page_checkout'); |
|
1432 | - /** |
|
1433 | - * global action hook for enqueueing styles and scripts with |
|
1434 | - * spco calls. |
|
1435 | - */ |
|
1436 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1437 | - /** |
|
1438 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1439 | - * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1440 | - */ |
|
1441 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
1442 | - } |
|
1443 | - |
|
1444 | - |
|
1445 | - |
|
1446 | - /** |
|
1447 | - * display the Registration Single Page Checkout Form |
|
1448 | - * |
|
1449 | - * @access private |
|
1450 | - * @return void |
|
1451 | - * @throws \EE_Error |
|
1452 | - */ |
|
1453 | - private function _display_spco_reg_form() |
|
1454 | - { |
|
1455 | - // if registering via the admin, just display the reg form for the current step |
|
1456 | - if ($this->checkout->admin_request) { |
|
1457 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1458 | - } else { |
|
1459 | - // add powered by EE msg |
|
1460 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1461 | - $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 |
|
1462 | - ? true |
|
1463 | - : false; |
|
1464 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1465 | - $cookies_not_set_msg = ''; |
|
1466 | - if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1467 | - $cookies_not_set_msg = apply_filters( |
|
1468 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1469 | - sprintf( |
|
1470 | - __( |
|
1471 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1472 | - 'event_espresso' |
|
1473 | - ), |
|
1474 | - '<div class="ee-attention">', |
|
1475 | - '</div>', |
|
1476 | - '<h6 class="important-notice">', |
|
1477 | - '</h6>', |
|
1478 | - '<p>', |
|
1479 | - '</p>', |
|
1480 | - '<br />', |
|
1481 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1482 | - '</a>' |
|
1483 | - ) |
|
1484 | - ); |
|
1485 | - } |
|
1486 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1487 | - array( |
|
1488 | - 'name' => 'single-page-checkout', |
|
1489 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
1490 | - 'layout_strategy' => |
|
1491 | - new EE_Template_Layout( |
|
1492 | - array( |
|
1493 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1494 | - 'template_args' => array( |
|
1495 | - 'empty_cart' => $empty_cart, |
|
1496 | - 'revisit' => $this->checkout->revisit, |
|
1497 | - 'reg_steps' => $this->checkout->reg_steps, |
|
1498 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1499 | - ? $this->checkout->next_step->slug() |
|
1500 | - : '', |
|
1501 | - 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1502 | - 'empty_msg' => apply_filters( |
|
1503 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1504 | - sprintf( |
|
1505 | - __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1506 | - 'event_espresso'), |
|
1507 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1508 | - '">', |
|
1509 | - '</a>' |
|
1510 | - ) |
|
1511 | - ), |
|
1512 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1513 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1514 | - 'session_expiration' => |
|
1515 | - date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)), |
|
1516 | - ), |
|
1517 | - ) |
|
1518 | - ), |
|
1519 | - ) |
|
1520 | - ); |
|
1521 | - // load template and add to output sent that gets filtered into the_content() |
|
1522 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1523 | - } |
|
1524 | - } |
|
1525 | - |
|
1526 | - |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * add_extra_finalize_registration_inputs |
|
1530 | - * |
|
1531 | - * @access public |
|
1532 | - * @param $next_step |
|
1533 | - * @internal param string $label |
|
1534 | - * @return void |
|
1535 | - */ |
|
1536 | - public function add_extra_finalize_registration_inputs($next_step) |
|
1537 | - { |
|
1538 | - if ($next_step === 'finalize_registration') { |
|
1539 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1540 | - } |
|
1541 | - } |
|
1542 | - |
|
1543 | - |
|
1544 | - |
|
1545 | - /** |
|
1546 | - * display_registration_footer |
|
1547 | - * |
|
1548 | - * @access public |
|
1549 | - * @return string |
|
1550 | - */ |
|
1551 | - public static function display_registration_footer() |
|
1552 | - { |
|
1553 | - if ( |
|
1554 | - apply_filters( |
|
1555 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1556 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1557 | - ) |
|
1558 | - ) { |
|
1559 | - add_filter( |
|
1560 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1561 | - function ($url) { |
|
1562 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1563 | - } |
|
1564 | - ); |
|
1565 | - echo apply_filters( |
|
1566 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1567 | - \EEH_Template::powered_by_event_espresso( |
|
1568 | - '', |
|
1569 | - 'espresso-registration-footer-dv', |
|
1570 | - array('utm_content' => 'registration_checkout') |
|
1571 | - ) |
|
1572 | - ); |
|
1573 | - } |
|
1574 | - return ''; |
|
1575 | - } |
|
1576 | - |
|
1577 | - |
|
1578 | - |
|
1579 | - /** |
|
1580 | - * unlock_transaction |
|
1581 | - * |
|
1582 | - * @access public |
|
1583 | - * @return void |
|
1584 | - * @throws \EE_Error |
|
1585 | - */ |
|
1586 | - public function unlock_transaction() |
|
1587 | - { |
|
1588 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1589 | - $this->checkout->transaction->unlock(); |
|
1590 | - } |
|
1591 | - } |
|
1592 | - |
|
1593 | - |
|
1594 | - |
|
1595 | - /** |
|
1596 | - * _setup_redirect |
|
1597 | - * |
|
1598 | - * @access private |
|
1599 | - * @return void |
|
1600 | - */ |
|
1601 | - private function _setup_redirect() |
|
1602 | - { |
|
1603 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1604 | - $this->checkout->redirect = true; |
|
1605 | - if (empty($this->checkout->redirect_url)) { |
|
1606 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1607 | - } |
|
1608 | - $this->checkout->redirect_url = apply_filters( |
|
1609 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1610 | - $this->checkout->redirect_url, |
|
1611 | - $this->checkout |
|
1612 | - ); |
|
1613 | - } |
|
1614 | - } |
|
1615 | - |
|
1616 | - |
|
1617 | - |
|
1618 | - /** |
|
1619 | - * handle ajax message responses and redirects |
|
1620 | - * |
|
1621 | - * @access public |
|
1622 | - * @return void |
|
1623 | - * @throws \EE_Error |
|
1624 | - */ |
|
1625 | - public function go_to_next_step() |
|
1626 | - { |
|
1627 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1628 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1629 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1630 | - } |
|
1631 | - $this->unlock_transaction(); |
|
1632 | - // just return for these conditions |
|
1633 | - if ( |
|
1634 | - $this->checkout->admin_request |
|
1635 | - || $this->checkout->action === 'redirect_form' |
|
1636 | - || $this->checkout->action === 'update_checkout' |
|
1637 | - ) { |
|
1638 | - return; |
|
1639 | - } |
|
1640 | - // AJAX response |
|
1641 | - $this->_handle_json_response(); |
|
1642 | - // redirect to next step or the Thank You page |
|
1643 | - $this->_handle_html_redirects(); |
|
1644 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
1645 | - $this->_display_spco_reg_form(); |
|
1646 | - } |
|
1647 | - |
|
1648 | - |
|
1649 | - |
|
1650 | - /** |
|
1651 | - * _handle_json_response |
|
1652 | - * |
|
1653 | - * @access protected |
|
1654 | - * @return void |
|
1655 | - */ |
|
1656 | - protected function _handle_json_response() |
|
1657 | - { |
|
1658 | - // if this is an ajax request |
|
1659 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1660 | - // DEBUG LOG |
|
1661 | - //$this->checkout->log( |
|
1662 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1663 | - // array( |
|
1664 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1665 | - // 'redirect' => $this->checkout->redirect, |
|
1666 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
1667 | - // ) |
|
1668 | - //); |
|
1669 | - $this->checkout->json_response->set_registration_time_limit( |
|
1670 | - $this->checkout->get_registration_time_limit() |
|
1671 | - ); |
|
1672 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1673 | - // just send the ajax ( |
|
1674 | - $json_response = apply_filters( |
|
1675 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1676 | - $this->checkout->json_response |
|
1677 | - ); |
|
1678 | - echo $json_response; |
|
1679 | - exit(); |
|
1680 | - } |
|
1681 | - } |
|
1682 | - |
|
1683 | - |
|
1684 | - |
|
1685 | - /** |
|
1686 | - * _handle_redirects |
|
1687 | - * |
|
1688 | - * @access protected |
|
1689 | - * @return void |
|
1690 | - */ |
|
1691 | - protected function _handle_html_redirects() |
|
1692 | - { |
|
1693 | - // going somewhere ? |
|
1694 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1695 | - // store notices in a transient |
|
1696 | - EE_Error::get_notices(false, true, true); |
|
1697 | - // DEBUG LOG |
|
1698 | - //$this->checkout->log( |
|
1699 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1700 | - // array( |
|
1701 | - // 'headers_sent' => headers_sent(), |
|
1702 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
1703 | - // 'headers_list' => headers_list(), |
|
1704 | - // ) |
|
1705 | - //); |
|
1706 | - wp_safe_redirect($this->checkout->redirect_url); |
|
1707 | - exit(); |
|
1708 | - } |
|
1709 | - } |
|
1710 | - |
|
1711 | - |
|
1712 | - |
|
1713 | - /** |
|
1714 | - * set_checkout_anchor |
|
1715 | - * |
|
1716 | - * @access public |
|
1717 | - * @return void |
|
1718 | - */ |
|
1719 | - public function set_checkout_anchor() |
|
1720 | - { |
|
1721 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1722 | - } |
|
20 | + /** |
|
21 | + * $_initialized - has the SPCO controller already been initialized ? |
|
22 | + * |
|
23 | + * @access private |
|
24 | + * @var bool $_initialized |
|
25 | + */ |
|
26 | + private static $_initialized = false; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
31 | + * |
|
32 | + * @access private |
|
33 | + * @var bool $_valid_checkout |
|
34 | + */ |
|
35 | + private static $_checkout_verified = true; |
|
36 | + |
|
37 | + /** |
|
38 | + * $_reg_steps_array - holds initial array of reg steps |
|
39 | + * |
|
40 | + * @access private |
|
41 | + * @var array $_reg_steps_array |
|
42 | + */ |
|
43 | + private static $_reg_steps_array = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Checkout $checkout |
|
50 | + */ |
|
51 | + public $checkout; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return EED_Single_Page_Checkout |
|
57 | + */ |
|
58 | + public static function instance() |
|
59 | + { |
|
60 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
61 | + return parent::get_instance(__CLASS__); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @return EE_CART |
|
68 | + */ |
|
69 | + public function cart() |
|
70 | + { |
|
71 | + return $this->checkout->cart; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @return EE_Transaction |
|
78 | + */ |
|
79 | + public function transaction() |
|
80 | + { |
|
81 | + return $this->checkout->transaction; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @return void |
|
91 | + * @throws \EE_Error |
|
92 | + */ |
|
93 | + public static function set_hooks() |
|
94 | + { |
|
95 | + EED_Single_Page_Checkout::set_definitions(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @return void |
|
105 | + * @throws \EE_Error |
|
106 | + */ |
|
107 | + public static function set_hooks_admin() |
|
108 | + { |
|
109 | + EED_Single_Page_Checkout::set_definitions(); |
|
110 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
111 | + // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called |
|
112 | + add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1); |
|
113 | + return; |
|
114 | + } |
|
115 | + // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
|
116 | + ob_start(); |
|
117 | + EED_Single_Page_Checkout::load_request_handler(); |
|
118 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
119 | + // set ajax hooks |
|
120 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
121 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
122 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
123 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
124 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
125 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * process ajax request |
|
132 | + * |
|
133 | + * @param string $ajax_action |
|
134 | + * @throws \EE_Error |
|
135 | + */ |
|
136 | + public static function process_ajax_request($ajax_action) |
|
137 | + { |
|
138 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
139 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * ajax display registration step |
|
146 | + * |
|
147 | + * @throws \EE_Error |
|
148 | + */ |
|
149 | + public static function display_reg_step() |
|
150 | + { |
|
151 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * ajax process registration step |
|
158 | + * |
|
159 | + * @throws \EE_Error |
|
160 | + */ |
|
161 | + public static function process_reg_step() |
|
162 | + { |
|
163 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * ajax process registration step |
|
170 | + * |
|
171 | + * @throws \EE_Error |
|
172 | + */ |
|
173 | + public static function update_reg_step() |
|
174 | + { |
|
175 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * update_checkout |
|
182 | + * |
|
183 | + * @access public |
|
184 | + * @return void |
|
185 | + * @throws \EE_Error |
|
186 | + */ |
|
187 | + public static function update_checkout() |
|
188 | + { |
|
189 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * load_request_handler |
|
196 | + * |
|
197 | + * @access public |
|
198 | + * @return void |
|
199 | + */ |
|
200 | + public static function load_request_handler() |
|
201 | + { |
|
202 | + // load core Request_Handler class |
|
203 | + if ( ! isset(EE_Registry::instance()->REQ)) { |
|
204 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * set_definitions |
|
212 | + * |
|
213 | + * @access public |
|
214 | + * @return void |
|
215 | + * @throws \EE_Error |
|
216 | + */ |
|
217 | + public static function set_definitions() |
|
218 | + { |
|
219 | + define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
220 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
221 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
222 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
223 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
224 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
225 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
226 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
227 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
228 | + __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
229 | + 'event_espresso'), |
|
230 | + '<h4 class="important-notice">', |
|
231 | + '</h4>', |
|
232 | + '<br />', |
|
233 | + '<p>', |
|
234 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
235 | + '">', |
|
236 | + '</a>', |
|
237 | + '</p>' |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * load_reg_steps |
|
245 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
246 | + * |
|
247 | + * @access private |
|
248 | + * @throws EE_Error |
|
249 | + * @return void |
|
250 | + */ |
|
251 | + public static function load_reg_steps() |
|
252 | + { |
|
253 | + static $reg_steps_loaded = false; |
|
254 | + if ($reg_steps_loaded) { |
|
255 | + return; |
|
256 | + } |
|
257 | + // filter list of reg_steps |
|
258 | + $reg_steps_to_load = (array)apply_filters( |
|
259 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
260 | + EED_Single_Page_Checkout::get_reg_steps() |
|
261 | + ); |
|
262 | + // sort by key (order) |
|
263 | + ksort($reg_steps_to_load); |
|
264 | + // loop through folders |
|
265 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
266 | + // we need a |
|
267 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
268 | + // copy over to the reg_steps_array |
|
269 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
270 | + // register custom key route for each reg step |
|
271 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
272 | + EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
273 | + // add AJAX or other hooks |
|
274 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
275 | + // setup autoloaders if necessary |
|
276 | + if ( ! class_exists($reg_step['class_name'])) { |
|
277 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true); |
|
278 | + } |
|
279 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
280 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + } |
|
285 | + $reg_steps_loaded = true; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * get_reg_steps |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @return array |
|
295 | + */ |
|
296 | + public static function get_reg_steps() |
|
297 | + { |
|
298 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
299 | + if (empty($reg_steps)) { |
|
300 | + $reg_steps = array( |
|
301 | + 10 => array( |
|
302 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
303 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
304 | + 'slug' => 'attendee_information', |
|
305 | + 'has_hooks' => false, |
|
306 | + ), |
|
307 | + 20 => array( |
|
308 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
309 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
310 | + 'slug' => 'registration_confirmation', |
|
311 | + 'has_hooks' => false, |
|
312 | + ), |
|
313 | + 30 => array( |
|
314 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
315 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
316 | + 'slug' => 'payment_options', |
|
317 | + 'has_hooks' => true, |
|
318 | + ), |
|
319 | + 999 => array( |
|
320 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
321 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
322 | + 'slug' => 'finalize_registration', |
|
323 | + 'has_hooks' => false, |
|
324 | + ), |
|
325 | + ); |
|
326 | + } |
|
327 | + return $reg_steps; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * registration_checkout_for_admin |
|
334 | + * |
|
335 | + * @access public |
|
336 | + * @return string |
|
337 | + * @throws \EE_Error |
|
338 | + */ |
|
339 | + public static function registration_checkout_for_admin() |
|
340 | + { |
|
341 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
342 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
343 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
344 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
345 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
346 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
347 | + return EE_Registry::instance()->REQ->get_output(); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * process_registration_from_admin |
|
354 | + * |
|
355 | + * @access public |
|
356 | + * @return \EE_Transaction |
|
357 | + * @throws \EE_Error |
|
358 | + */ |
|
359 | + public static function process_registration_from_admin() |
|
360 | + { |
|
361 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
362 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
363 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
364 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
365 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
366 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
367 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
368 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
369 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
370 | + if ($final_reg_step->process_reg_step()) { |
|
371 | + $final_reg_step->set_completed(); |
|
372 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
373 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
374 | + } |
|
375 | + } |
|
376 | + } |
|
377 | + return null; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * run |
|
384 | + * |
|
385 | + * @access public |
|
386 | + * @param WP_Query $WP_Query |
|
387 | + * @return void |
|
388 | + * @throws \EE_Error |
|
389 | + */ |
|
390 | + public function run($WP_Query) |
|
391 | + { |
|
392 | + if ( |
|
393 | + $WP_Query instanceof WP_Query |
|
394 | + && $WP_Query->is_main_query() |
|
395 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
396 | + && $this->_is_reg_checkout() |
|
397 | + ) { |
|
398 | + $this->_initialize(); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * determines whether current url matches reg page url |
|
406 | + * |
|
407 | + * @return bool |
|
408 | + */ |
|
409 | + protected function _is_reg_checkout() |
|
410 | + { |
|
411 | + // get current permalink for reg page without any extra query args |
|
412 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
413 | + // get request URI for current request, but without the scheme or host |
|
414 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
415 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
416 | + // get array of query args from the current request URI |
|
417 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
418 | + // grab page id if it is set |
|
419 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
420 | + // and remove the page id from the query args (we will re-add it later) |
|
421 | + unset($query_args['page_id']); |
|
422 | + // now strip all query args from current request URI |
|
423 | + $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri); |
|
424 | + // and re-add the page id if it was set |
|
425 | + if ($page_id) { |
|
426 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
427 | + } |
|
428 | + // remove slashes and ? |
|
429 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
430 | + // is current request URI part of the known full reg page URL ? |
|
431 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * run |
|
438 | + * |
|
439 | + * @access public |
|
440 | + * @param WP_Query $WP_Query |
|
441 | + * @return void |
|
442 | + * @throws \EE_Error |
|
443 | + */ |
|
444 | + public static function init($WP_Query) |
|
445 | + { |
|
446 | + EED_Single_Page_Checkout::instance()->run($WP_Query); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * _initialize - initial module setup |
|
453 | + * |
|
454 | + * @access private |
|
455 | + * @throws EE_Error |
|
456 | + * @return void |
|
457 | + */ |
|
458 | + private function _initialize() |
|
459 | + { |
|
460 | + // ensure SPCO doesn't run twice |
|
461 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
462 | + return; |
|
463 | + } |
|
464 | + try { |
|
465 | + $this->_verify_session(); |
|
466 | + // setup the EE_Checkout object |
|
467 | + $this->checkout = $this->_initialize_checkout(); |
|
468 | + // filter checkout |
|
469 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
470 | + // get the $_GET |
|
471 | + $this->_get_request_vars(); |
|
472 | + if ($this->_block_bots()) { |
|
473 | + return; |
|
474 | + } |
|
475 | + // filter continue_reg |
|
476 | + $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout); |
|
477 | + // load the reg steps array |
|
478 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
479 | + EED_Single_Page_Checkout::$_initialized = true; |
|
480 | + return; |
|
481 | + } |
|
482 | + // set the current step |
|
483 | + $this->checkout->set_current_step($this->checkout->step); |
|
484 | + // and the next step |
|
485 | + $this->checkout->set_next_step(); |
|
486 | + // verify that everything has been setup correctly |
|
487 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
488 | + EED_Single_Page_Checkout::$_initialized = true; |
|
489 | + return; |
|
490 | + } |
|
491 | + // lock the transaction |
|
492 | + $this->checkout->transaction->lock(); |
|
493 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
494 | + $this->checkout->refresh_all_entities(); |
|
495 | + // set amount owing |
|
496 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
497 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
498 | + $this->_initialize_reg_steps(); |
|
499 | + // DEBUG LOG |
|
500 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
501 | + // get reg form |
|
502 | + if( ! $this->_check_form_submission()) { |
|
503 | + EED_Single_Page_Checkout::$_initialized = true; |
|
504 | + return; |
|
505 | + } |
|
506 | + // checkout the action!!! |
|
507 | + $this->_process_form_action(); |
|
508 | + // add some style and make it dance |
|
509 | + $this->add_styles_and_scripts(); |
|
510 | + // kk... SPCO has successfully run |
|
511 | + EED_Single_Page_Checkout::$_initialized = true; |
|
512 | + // set no cache headers and constants |
|
513 | + EE_System::do_not_cache(); |
|
514 | + // add anchor |
|
515 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
516 | + // remove transaction lock |
|
517 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
518 | + } catch (Exception $e) { |
|
519 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * _verify_session |
|
527 | + * checks that the session is valid and not expired |
|
528 | + * |
|
529 | + * @access private |
|
530 | + * @throws EE_Error |
|
531 | + */ |
|
532 | + private function _verify_session() |
|
533 | + { |
|
534 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
535 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
536 | + } |
|
537 | + // is session still valid ? |
|
538 | + if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') { |
|
539 | + $this->checkout = new EE_Checkout(); |
|
540 | + EE_Registry::instance()->SSN->reset_cart(); |
|
541 | + EE_Registry::instance()->SSN->reset_checkout(); |
|
542 | + EE_Registry::instance()->SSN->reset_transaction(); |
|
543 | + EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__, |
|
544 | + __FUNCTION__, __LINE__); |
|
545 | + EE_Registry::instance()->SSN->reset_expired(); |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * _initialize_checkout |
|
553 | + * loads and instantiates EE_Checkout |
|
554 | + * |
|
555 | + * @access private |
|
556 | + * @throws EE_Error |
|
557 | + * @return EE_Checkout |
|
558 | + */ |
|
559 | + private function _initialize_checkout() |
|
560 | + { |
|
561 | + // look in session for existing checkout |
|
562 | + /** @type EE_Checkout $checkout */ |
|
563 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
564 | + // verify |
|
565 | + if ( ! $checkout instanceof EE_Checkout) { |
|
566 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
567 | + $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false); |
|
568 | + } else { |
|
569 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
570 | + $this->unlock_transaction(); |
|
571 | + wp_safe_redirect($checkout->redirect_url); |
|
572 | + exit(); |
|
573 | + } |
|
574 | + } |
|
575 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
576 | + // verify again |
|
577 | + if ( ! $checkout instanceof EE_Checkout) { |
|
578 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
579 | + } |
|
580 | + // reset anything that needs a clean slate for each request |
|
581 | + $checkout->reset_for_current_request(); |
|
582 | + return $checkout; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * _get_request_vars |
|
589 | + * |
|
590 | + * @access private |
|
591 | + * @return void |
|
592 | + * @throws \EE_Error |
|
593 | + */ |
|
594 | + private function _get_request_vars() |
|
595 | + { |
|
596 | + // load classes |
|
597 | + EED_Single_Page_Checkout::load_request_handler(); |
|
598 | + //make sure this request is marked as belonging to EE |
|
599 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
600 | + // which step is being requested ? |
|
601 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
602 | + // which step is being edited ? |
|
603 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
604 | + // and what we're doing on the current step |
|
605 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
606 | + // timestamp |
|
607 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
608 | + // returning to edit ? |
|
609 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
610 | + // or some other kind of revisit ? |
|
611 | + $this->checkout->revisit = filter_var( |
|
612 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
613 | + FILTER_VALIDATE_BOOLEAN |
|
614 | + ); |
|
615 | + // and whether or not to generate a reg form for this request |
|
616 | + $this->checkout->generate_reg_form = filter_var( |
|
617 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
618 | + FILTER_VALIDATE_BOOLEAN |
|
619 | + ); |
|
620 | + // and whether or not to process a reg form submission for this request |
|
621 | + $this->checkout->process_form_submission = filter_var( |
|
622 | + EE_Registry::instance()->REQ->get( |
|
623 | + 'process_form_submission', |
|
624 | + $this->checkout->action === 'process_reg_step' |
|
625 | + ), |
|
626 | + FILTER_VALIDATE_BOOLEAN |
|
627 | + ); |
|
628 | + $this->checkout->process_form_submission = filter_var( |
|
629 | + $this->checkout->action !== 'display_spco_reg_step' |
|
630 | + ? $this->checkout->process_form_submission |
|
631 | + : false, |
|
632 | + FILTER_VALIDATE_BOOLEAN |
|
633 | + ); |
|
634 | + // $this->_display_request_vars(); |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * _display_request_vars |
|
641 | + * |
|
642 | + * @access protected |
|
643 | + * @return void |
|
644 | + */ |
|
645 | + protected function _display_request_vars() |
|
646 | + { |
|
647 | + if ( ! WP_DEBUG) { |
|
648 | + return; |
|
649 | + } |
|
650 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
651 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
652 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
653 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
654 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
655 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
656 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
657 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * _block_bots |
|
664 | + * checks that the incoming request has either of the following set: |
|
665 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
666 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
667 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
668 | + * then where you coming from man? |
|
669 | + * |
|
670 | + * @return boolean |
|
671 | + */ |
|
672 | + private function _block_bots() |
|
673 | + { |
|
674 | + $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
675 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
676 | + return true; |
|
677 | + } |
|
678 | + return false; |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * _get_first_step |
|
685 | + * gets slug for first step in $_reg_steps_array |
|
686 | + * |
|
687 | + * @access private |
|
688 | + * @throws EE_Error |
|
689 | + * @return string |
|
690 | + */ |
|
691 | + private function _get_first_step() |
|
692 | + { |
|
693 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
694 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * _load_and_instantiate_reg_steps |
|
701 | + * instantiates each reg step based on the loaded reg_steps array |
|
702 | + * |
|
703 | + * @access private |
|
704 | + * @throws EE_Error |
|
705 | + * @return bool |
|
706 | + */ |
|
707 | + private function _load_and_instantiate_reg_steps() |
|
708 | + { |
|
709 | + // have reg_steps already been instantiated ? |
|
710 | + if ( |
|
711 | + empty($this->checkout->reg_steps) |
|
712 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
713 | + ) { |
|
714 | + // if not, then loop through raw reg steps array |
|
715 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
716 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
717 | + return false; |
|
718 | + } |
|
719 | + } |
|
720 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
721 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
722 | + // skip the registration_confirmation page ? |
|
723 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
724 | + // just remove it from the reg steps array |
|
725 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
726 | + } else if ( |
|
727 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
728 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
729 | + ) { |
|
730 | + // set the order to something big like 100 |
|
731 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
732 | + } |
|
733 | + // filter the array for good luck |
|
734 | + $this->checkout->reg_steps = apply_filters( |
|
735 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
736 | + $this->checkout->reg_steps |
|
737 | + ); |
|
738 | + // finally re-sort based on the reg step class order properties |
|
739 | + $this->checkout->sort_reg_steps(); |
|
740 | + } else { |
|
741 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
742 | + // set all current step stati to FALSE |
|
743 | + $reg_step->set_is_current_step(false); |
|
744 | + } |
|
745 | + } |
|
746 | + if (empty($this->checkout->reg_steps)) { |
|
747 | + EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
748 | + return false; |
|
749 | + } |
|
750 | + // make reg step details available to JS |
|
751 | + $this->checkout->set_reg_step_JSON_info(); |
|
752 | + return true; |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _load_and_instantiate_reg_step |
|
759 | + * |
|
760 | + * @access private |
|
761 | + * @param array $reg_step |
|
762 | + * @param int $order |
|
763 | + * @return bool |
|
764 | + */ |
|
765 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
766 | + { |
|
767 | + // we need a file_path, class_name, and slug to add a reg step |
|
768 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
769 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
770 | + if ( |
|
771 | + $this->checkout->reg_url_link |
|
772 | + && $this->checkout->step !== $reg_step['slug'] |
|
773 | + && $reg_step['slug'] !== 'finalize_registration' |
|
774 | + ) { |
|
775 | + return true; |
|
776 | + } |
|
777 | + // instantiate step class using file path and class name |
|
778 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
779 | + $reg_step['file_path'], |
|
780 | + $reg_step['class_name'], |
|
781 | + 'class', |
|
782 | + $this->checkout, |
|
783 | + false |
|
784 | + ); |
|
785 | + // did we gets the goods ? |
|
786 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
787 | + // set reg step order based on config |
|
788 | + $reg_step_obj->set_order($order); |
|
789 | + // add instantiated reg step object to the master reg steps array |
|
790 | + $this->checkout->add_reg_step($reg_step_obj); |
|
791 | + } else { |
|
792 | + EE_Error::add_error( |
|
793 | + __('The current step could not be set.', 'event_espresso'), |
|
794 | + __FILE__, __FUNCTION__, __LINE__ |
|
795 | + ); |
|
796 | + return false; |
|
797 | + } |
|
798 | + } else { |
|
799 | + if (WP_DEBUG) { |
|
800 | + EE_Error::add_error( |
|
801 | + sprintf( |
|
802 | + __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
803 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
804 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
805 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
806 | + '<ul>', |
|
807 | + '<li>', |
|
808 | + '</li>', |
|
809 | + '</ul>' |
|
810 | + ), |
|
811 | + __FILE__, __FUNCTION__, __LINE__ |
|
812 | + ); |
|
813 | + } |
|
814 | + return false; |
|
815 | + } |
|
816 | + return true; |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + |
|
821 | + /** |
|
822 | + * _verify_transaction_and_get_registrations |
|
823 | + * |
|
824 | + * @access private |
|
825 | + * @return bool |
|
826 | + */ |
|
827 | + private function _verify_transaction_and_get_registrations() |
|
828 | + { |
|
829 | + // was there already a valid transaction in the checkout from the session ? |
|
830 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
831 | + // get transaction from db or session |
|
832 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
833 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
834 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
835 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
836 | + EE_Error::add_error( |
|
837 | + __('Your Registration and Transaction information could not be retrieved from the db.', |
|
838 | + 'event_espresso'), |
|
839 | + __FILE__, __FUNCTION__, __LINE__ |
|
840 | + ); |
|
841 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
842 | + // add some style and make it dance |
|
843 | + $this->add_styles_and_scripts(); |
|
844 | + EED_Single_Page_Checkout::$_initialized = true; |
|
845 | + return false; |
|
846 | + } |
|
847 | + // and the registrations for the transaction |
|
848 | + $this->_get_registrations($this->checkout->transaction); |
|
849 | + } |
|
850 | + return true; |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + |
|
855 | + /** |
|
856 | + * _get_transaction_and_cart_for_previous_visit |
|
857 | + * |
|
858 | + * @access private |
|
859 | + * @return mixed EE_Transaction|NULL |
|
860 | + */ |
|
861 | + private function _get_transaction_and_cart_for_previous_visit() |
|
862 | + { |
|
863 | + /** @var $TXN_model EEM_Transaction */ |
|
864 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
865 | + // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
|
866 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
867 | + // verify transaction |
|
868 | + if ($transaction instanceof EE_Transaction) { |
|
869 | + // and get the cart that was used for that transaction |
|
870 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
871 | + return $transaction; |
|
872 | + } else { |
|
873 | + EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
874 | + return null; |
|
875 | + } |
|
876 | + } |
|
877 | + |
|
878 | + |
|
879 | + |
|
880 | + /** |
|
881 | + * _get_cart_for_transaction |
|
882 | + * |
|
883 | + * @access private |
|
884 | + * @param EE_Transaction $transaction |
|
885 | + * @return EE_Cart |
|
886 | + */ |
|
887 | + private function _get_cart_for_transaction($transaction) |
|
888 | + { |
|
889 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
890 | + } |
|
891 | + |
|
892 | + |
|
893 | + |
|
894 | + /** |
|
895 | + * get_cart_for_transaction |
|
896 | + * |
|
897 | + * @access public |
|
898 | + * @param EE_Transaction $transaction |
|
899 | + * @return EE_Cart |
|
900 | + */ |
|
901 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
902 | + { |
|
903 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
904 | + } |
|
905 | + |
|
906 | + |
|
907 | + |
|
908 | + /** |
|
909 | + * _get_transaction_and_cart_for_current_session |
|
910 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
911 | + * |
|
912 | + * @access private |
|
913 | + * @return EE_Transaction |
|
914 | + * @throws \EE_Error |
|
915 | + */ |
|
916 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
917 | + { |
|
918 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
919 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
920 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
921 | + // and then create a new transaction |
|
922 | + $transaction = $this->_initialize_transaction(); |
|
923 | + // verify transaction |
|
924 | + if ($transaction instanceof EE_Transaction) { |
|
925 | + // save it so that we have an ID for other objects to use |
|
926 | + $transaction->save(); |
|
927 | + // and save TXN data to the cart |
|
928 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
929 | + } else { |
|
930 | + EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
931 | + } |
|
932 | + return $transaction; |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + |
|
937 | + /** |
|
938 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
939 | + * |
|
940 | + * @access private |
|
941 | + * @return mixed EE_Transaction|NULL |
|
942 | + */ |
|
943 | + private function _initialize_transaction() |
|
944 | + { |
|
945 | + try { |
|
946 | + // ensure cart totals have been calculated |
|
947 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
948 | + // grab the cart grand total |
|
949 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
950 | + // create new TXN |
|
951 | + $transaction = EE_Transaction::new_instance( |
|
952 | + array( |
|
953 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
954 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
955 | + 'TXN_paid' => 0, |
|
956 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
957 | + ) |
|
958 | + ); |
|
959 | + // save it so that we have an ID for other objects to use |
|
960 | + $transaction->save(); |
|
961 | + // set cron job for following up on TXNs after their session has expired |
|
962 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
963 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
964 | + $transaction->ID() |
|
965 | + ); |
|
966 | + return $transaction; |
|
967 | + } catch (Exception $e) { |
|
968 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
969 | + } |
|
970 | + return null; |
|
971 | + } |
|
972 | + |
|
973 | + |
|
974 | + |
|
975 | + /** |
|
976 | + * _get_registrations |
|
977 | + * |
|
978 | + * @access private |
|
979 | + * @param EE_Transaction $transaction |
|
980 | + * @return void |
|
981 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
982 | + * @throws \EE_Error |
|
983 | + */ |
|
984 | + private function _get_registrations(EE_Transaction $transaction) |
|
985 | + { |
|
986 | + // first step: grab the registrants { : o |
|
987 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
988 | + // verify registrations have been set |
|
989 | + if (empty($registrations)) { |
|
990 | + // if no cached registrations, then check the db |
|
991 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
992 | + // still nothing ? well as long as this isn't a revisit |
|
993 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
994 | + // generate new registrations from scratch |
|
995 | + $registrations = $this->_initialize_registrations($transaction); |
|
996 | + } |
|
997 | + } |
|
998 | + // sort by their original registration order |
|
999 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1000 | + // then loop thru the array |
|
1001 | + foreach ($registrations as $registration) { |
|
1002 | + // verify each registration |
|
1003 | + if ($registration instanceof EE_Registration) { |
|
1004 | + // we display all attendee info for the primary registrant |
|
1005 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1006 | + && $registration->is_primary_registrant() |
|
1007 | + ) { |
|
1008 | + $this->checkout->primary_revisit = true; |
|
1009 | + break; |
|
1010 | + } else if ($this->checkout->revisit |
|
1011 | + && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
1012 | + ) { |
|
1013 | + // but hide info if it doesn't belong to you |
|
1014 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
1015 | + } |
|
1016 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1017 | + } |
|
1018 | + } |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + |
|
1023 | + /** |
|
1024 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1025 | + * |
|
1026 | + * @access private |
|
1027 | + * @param EE_Transaction $transaction |
|
1028 | + * @return array |
|
1029 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
1030 | + * @throws \EE_Error |
|
1031 | + */ |
|
1032 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
1033 | + { |
|
1034 | + $att_nmbr = 0; |
|
1035 | + $registrations = array(); |
|
1036 | + if ($transaction instanceof EE_Transaction) { |
|
1037 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1038 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1039 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1040 | + // now let's add the cart items to the $transaction |
|
1041 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1042 | + //do the following for each ticket of this type they selected |
|
1043 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1044 | + $att_nmbr++; |
|
1045 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1046 | + $CreateRegistrationCommand = EE_Registry::instance() |
|
1047 | + ->create( |
|
1048 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1049 | + array( |
|
1050 | + $transaction, |
|
1051 | + $line_item, |
|
1052 | + $att_nmbr, |
|
1053 | + $this->checkout->total_ticket_count, |
|
1054 | + ) |
|
1055 | + ); |
|
1056 | + // override capabilities for frontend registrations |
|
1057 | + if ( ! is_admin()) { |
|
1058 | + $CreateRegistrationCommand->setCapCheck( |
|
1059 | + new PublicCapabilities('', 'create_new_registration') |
|
1060 | + ); |
|
1061 | + } |
|
1062 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1063 | + if ( ! $registration instanceof EE_Registration) { |
|
1064 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1065 | + } |
|
1066 | + $registrations[ $registration->ID() ] = $registration; |
|
1067 | + } |
|
1068 | + } |
|
1069 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1070 | + } |
|
1071 | + return $registrations; |
|
1072 | + } |
|
1073 | + |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * sorts registrations by REG_count |
|
1078 | + * |
|
1079 | + * @access public |
|
1080 | + * @param EE_Registration $reg_A |
|
1081 | + * @param EE_Registration $reg_B |
|
1082 | + * @return int |
|
1083 | + */ |
|
1084 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1085 | + { |
|
1086 | + // this shouldn't ever happen within the same TXN, but oh well |
|
1087 | + if ($reg_A->count() === $reg_B->count()) { |
|
1088 | + return 0; |
|
1089 | + } |
|
1090 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * _final_verifications |
|
1097 | + * just makes sure that everything is set up correctly before proceeding |
|
1098 | + * |
|
1099 | + * @access private |
|
1100 | + * @return bool |
|
1101 | + * @throws \EE_Error |
|
1102 | + */ |
|
1103 | + private function _final_verifications() |
|
1104 | + { |
|
1105 | + // filter checkout |
|
1106 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
1107 | + //verify that current step is still set correctly |
|
1108 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1109 | + EE_Error::add_error( |
|
1110 | + __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1111 | + __FILE__, |
|
1112 | + __FUNCTION__, |
|
1113 | + __LINE__ |
|
1114 | + ); |
|
1115 | + return false; |
|
1116 | + } |
|
1117 | + // if returning to SPCO, then verify that primary registrant is set |
|
1118 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
1119 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1120 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1121 | + EE_Error::add_error( |
|
1122 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1123 | + __FILE__, |
|
1124 | + __FUNCTION__, |
|
1125 | + __LINE__ |
|
1126 | + ); |
|
1127 | + return false; |
|
1128 | + } |
|
1129 | + $valid_registrant = null; |
|
1130 | + foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
1131 | + if ( |
|
1132 | + $registration instanceof EE_Registration |
|
1133 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1134 | + ) { |
|
1135 | + $valid_registrant = $registration; |
|
1136 | + } |
|
1137 | + } |
|
1138 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1139 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1140 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1141 | + // clear the session, mark the checkout as unverified, and try again |
|
1142 | + EE_Registry::instance()->SSN->clear_session(); |
|
1143 | + EED_Single_Page_Checkout::$_initialized = false; |
|
1144 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1145 | + $this->_initialize(); |
|
1146 | + EE_Error::reset_notices(); |
|
1147 | + return false; |
|
1148 | + } |
|
1149 | + EE_Error::add_error( |
|
1150 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1151 | + __FILE__, |
|
1152 | + __FUNCTION__, |
|
1153 | + __LINE__ |
|
1154 | + ); |
|
1155 | + return false; |
|
1156 | + } |
|
1157 | + } |
|
1158 | + // now that things have been kinda sufficiently verified, |
|
1159 | + // let's add the checkout to the session so that's available other systems |
|
1160 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1161 | + return true; |
|
1162 | + } |
|
1163 | + |
|
1164 | + |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * _initialize_reg_steps |
|
1168 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1169 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1170 | + * |
|
1171 | + * @access private |
|
1172 | + * @param bool $reinitializing |
|
1173 | + * @throws \EE_Error |
|
1174 | + */ |
|
1175 | + private function _initialize_reg_steps($reinitializing = false) |
|
1176 | + { |
|
1177 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1178 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1179 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
1180 | + if ( ! $reg_step->initialize_reg_step()) { |
|
1181 | + // if not initialized then maybe this step is being removed... |
|
1182 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1183 | + // if it was the current step, then we need to start over here |
|
1184 | + $this->_initialize_reg_steps(true); |
|
1185 | + return; |
|
1186 | + } |
|
1187 | + continue; |
|
1188 | + } |
|
1189 | + // add css and JS for current step |
|
1190 | + $reg_step->enqueue_styles_and_scripts(); |
|
1191 | + // i18n |
|
1192 | + $reg_step->translate_js_strings(); |
|
1193 | + if ($reg_step->is_current_step()) { |
|
1194 | + // the text that appears on the reg step form submit button |
|
1195 | + $reg_step->set_submit_button_text(); |
|
1196 | + } |
|
1197 | + } |
|
1198 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1199 | + do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
1200 | + } |
|
1201 | + |
|
1202 | + |
|
1203 | + |
|
1204 | + /** |
|
1205 | + * _check_form_submission |
|
1206 | + * |
|
1207 | + * @access private |
|
1208 | + * @return boolean |
|
1209 | + */ |
|
1210 | + private function _check_form_submission() |
|
1211 | + { |
|
1212 | + //does this request require the reg form to be generated ? |
|
1213 | + if ($this->checkout->generate_reg_form) { |
|
1214 | + // ever heard that song by Blue Rodeo ? |
|
1215 | + try { |
|
1216 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1217 | + // if not displaying a form, then check for form submission |
|
1218 | + if ( |
|
1219 | + $this->checkout->process_form_submission |
|
1220 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
1221 | + ) { |
|
1222 | + // clear out any old data in case this step is being run again |
|
1223 | + $this->checkout->current_step->set_valid_data(array()); |
|
1224 | + // capture submitted form data |
|
1225 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
1226 | + apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout) |
|
1227 | + ); |
|
1228 | + // validate submitted form data |
|
1229 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1230 | + // thou shall not pass !!! |
|
1231 | + $this->checkout->continue_reg = false; |
|
1232 | + // any form validation errors? |
|
1233 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1234 | + $submission_error_messages = array(); |
|
1235 | + // bad, bad, bad registrant |
|
1236 | + foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
1237 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1238 | + $submission_error_messages[] = sprintf( |
|
1239 | + __('%s : %s', 'event_espresso'), |
|
1240 | + $validation_error->get_form_section()->html_label_text(), |
|
1241 | + $validation_error->getMessage() |
|
1242 | + ); |
|
1243 | + } |
|
1244 | + } |
|
1245 | + EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
1246 | + } |
|
1247 | + // well not really... what will happen is we'll just get redirected back to redo the current step |
|
1248 | + $this->go_to_next_step(); |
|
1249 | + return false; |
|
1250 | + } |
|
1251 | + } |
|
1252 | + } catch (EE_Error $e) { |
|
1253 | + $e->get_error(); |
|
1254 | + } |
|
1255 | + } |
|
1256 | + return true; |
|
1257 | + } |
|
1258 | + |
|
1259 | + |
|
1260 | + |
|
1261 | + /** |
|
1262 | + * _process_action |
|
1263 | + * |
|
1264 | + * @access private |
|
1265 | + * @return void |
|
1266 | + * @throws \EE_Error |
|
1267 | + */ |
|
1268 | + private function _process_form_action() |
|
1269 | + { |
|
1270 | + // what cha wanna do? |
|
1271 | + switch ($this->checkout->action) { |
|
1272 | + // AJAX next step reg form |
|
1273 | + case 'display_spco_reg_step' : |
|
1274 | + $this->checkout->redirect = false; |
|
1275 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1276 | + $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
1277 | + } |
|
1278 | + break; |
|
1279 | + default : |
|
1280 | + // meh... do one of those other steps first |
|
1281 | + if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
1282 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1283 | + do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1284 | + // call action on current step |
|
1285 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1286 | + // good registrant, you get to proceed |
|
1287 | + if ( |
|
1288 | + $this->checkout->current_step->success_message() !== '' |
|
1289 | + && apply_filters( |
|
1290 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1291 | + false |
|
1292 | + ) |
|
1293 | + ) { |
|
1294 | + EE_Error::add_success( |
|
1295 | + $this->checkout->current_step->success_message() |
|
1296 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
1297 | + ); |
|
1298 | + } |
|
1299 | + // pack it up, pack it in... |
|
1300 | + $this->_setup_redirect(); |
|
1301 | + } |
|
1302 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1303 | + do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1304 | + } else { |
|
1305 | + EE_Error::add_error( |
|
1306 | + sprintf( |
|
1307 | + __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
1308 | + $this->checkout->action, |
|
1309 | + $this->checkout->current_step->name() |
|
1310 | + ), |
|
1311 | + __FILE__, |
|
1312 | + __FUNCTION__, |
|
1313 | + __LINE__ |
|
1314 | + ); |
|
1315 | + } |
|
1316 | + // end default |
|
1317 | + } |
|
1318 | + // store our progress so far |
|
1319 | + $this->checkout->stash_transaction_and_checkout(); |
|
1320 | + // advance to the next step! If you pass GO, collect $200 |
|
1321 | + $this->go_to_next_step(); |
|
1322 | + } |
|
1323 | + |
|
1324 | + |
|
1325 | + |
|
1326 | + /** |
|
1327 | + * add_styles_and_scripts |
|
1328 | + * |
|
1329 | + * @access public |
|
1330 | + * @return void |
|
1331 | + */ |
|
1332 | + public function add_styles_and_scripts() |
|
1333 | + { |
|
1334 | + // i18n |
|
1335 | + $this->translate_js_strings(); |
|
1336 | + if ($this->checkout->admin_request) { |
|
1337 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1338 | + } else { |
|
1339 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1340 | + } |
|
1341 | + } |
|
1342 | + |
|
1343 | + |
|
1344 | + |
|
1345 | + /** |
|
1346 | + * translate_js_strings |
|
1347 | + * |
|
1348 | + * @access public |
|
1349 | + * @return void |
|
1350 | + */ |
|
1351 | + public function translate_js_strings() |
|
1352 | + { |
|
1353 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1354 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1355 | + EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1356 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1357 | + EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
1358 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1359 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
|
1360 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
|
1361 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1362 | + __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), |
|
1363 | + '<br/>', |
|
1364 | + '<br/>' |
|
1365 | + ); |
|
1366 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1367 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1368 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1369 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1370 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1371 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1372 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1373 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1374 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1375 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1376 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1377 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1378 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1379 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1380 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1381 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1382 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1383 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1384 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1385 | + __( |
|
1386 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
1387 | + 'event_espresso' |
|
1388 | + ), |
|
1389 | + '<h4 class="important-notice">', |
|
1390 | + '</h4>', |
|
1391 | + '<br />', |
|
1392 | + '<p>', |
|
1393 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1394 | + '">', |
|
1395 | + '</a>', |
|
1396 | + '</p>' |
|
1397 | + ); |
|
1398 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
1399 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1400 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1401 | + ); |
|
1402 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1403 | + 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1404 | + ); |
|
1405 | + } |
|
1406 | + |
|
1407 | + |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * enqueue_styles_and_scripts |
|
1411 | + * |
|
1412 | + * @access public |
|
1413 | + * @return void |
|
1414 | + * @throws \EE_Error |
|
1415 | + */ |
|
1416 | + public function enqueue_styles_and_scripts() |
|
1417 | + { |
|
1418 | + // load css |
|
1419 | + wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1420 | + wp_enqueue_style('single_page_checkout'); |
|
1421 | + // load JS |
|
1422 | + wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
1423 | + wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
1424 | + wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
1425 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1426 | + $this->checkout->registration_form->enqueue_js(); |
|
1427 | + } |
|
1428 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1429 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
1430 | + } |
|
1431 | + wp_enqueue_script('single_page_checkout'); |
|
1432 | + /** |
|
1433 | + * global action hook for enqueueing styles and scripts with |
|
1434 | + * spco calls. |
|
1435 | + */ |
|
1436 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1437 | + /** |
|
1438 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1439 | + * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1440 | + */ |
|
1441 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
1442 | + } |
|
1443 | + |
|
1444 | + |
|
1445 | + |
|
1446 | + /** |
|
1447 | + * display the Registration Single Page Checkout Form |
|
1448 | + * |
|
1449 | + * @access private |
|
1450 | + * @return void |
|
1451 | + * @throws \EE_Error |
|
1452 | + */ |
|
1453 | + private function _display_spco_reg_form() |
|
1454 | + { |
|
1455 | + // if registering via the admin, just display the reg form for the current step |
|
1456 | + if ($this->checkout->admin_request) { |
|
1457 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1458 | + } else { |
|
1459 | + // add powered by EE msg |
|
1460 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1461 | + $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 |
|
1462 | + ? true |
|
1463 | + : false; |
|
1464 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1465 | + $cookies_not_set_msg = ''; |
|
1466 | + if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1467 | + $cookies_not_set_msg = apply_filters( |
|
1468 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1469 | + sprintf( |
|
1470 | + __( |
|
1471 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1472 | + 'event_espresso' |
|
1473 | + ), |
|
1474 | + '<div class="ee-attention">', |
|
1475 | + '</div>', |
|
1476 | + '<h6 class="important-notice">', |
|
1477 | + '</h6>', |
|
1478 | + '<p>', |
|
1479 | + '</p>', |
|
1480 | + '<br />', |
|
1481 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1482 | + '</a>' |
|
1483 | + ) |
|
1484 | + ); |
|
1485 | + } |
|
1486 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1487 | + array( |
|
1488 | + 'name' => 'single-page-checkout', |
|
1489 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
1490 | + 'layout_strategy' => |
|
1491 | + new EE_Template_Layout( |
|
1492 | + array( |
|
1493 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1494 | + 'template_args' => array( |
|
1495 | + 'empty_cart' => $empty_cart, |
|
1496 | + 'revisit' => $this->checkout->revisit, |
|
1497 | + 'reg_steps' => $this->checkout->reg_steps, |
|
1498 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1499 | + ? $this->checkout->next_step->slug() |
|
1500 | + : '', |
|
1501 | + 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1502 | + 'empty_msg' => apply_filters( |
|
1503 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1504 | + sprintf( |
|
1505 | + __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1506 | + 'event_espresso'), |
|
1507 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1508 | + '">', |
|
1509 | + '</a>' |
|
1510 | + ) |
|
1511 | + ), |
|
1512 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1513 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1514 | + 'session_expiration' => |
|
1515 | + date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)), |
|
1516 | + ), |
|
1517 | + ) |
|
1518 | + ), |
|
1519 | + ) |
|
1520 | + ); |
|
1521 | + // load template and add to output sent that gets filtered into the_content() |
|
1522 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1523 | + } |
|
1524 | + } |
|
1525 | + |
|
1526 | + |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * add_extra_finalize_registration_inputs |
|
1530 | + * |
|
1531 | + * @access public |
|
1532 | + * @param $next_step |
|
1533 | + * @internal param string $label |
|
1534 | + * @return void |
|
1535 | + */ |
|
1536 | + public function add_extra_finalize_registration_inputs($next_step) |
|
1537 | + { |
|
1538 | + if ($next_step === 'finalize_registration') { |
|
1539 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1540 | + } |
|
1541 | + } |
|
1542 | + |
|
1543 | + |
|
1544 | + |
|
1545 | + /** |
|
1546 | + * display_registration_footer |
|
1547 | + * |
|
1548 | + * @access public |
|
1549 | + * @return string |
|
1550 | + */ |
|
1551 | + public static function display_registration_footer() |
|
1552 | + { |
|
1553 | + if ( |
|
1554 | + apply_filters( |
|
1555 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1556 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1557 | + ) |
|
1558 | + ) { |
|
1559 | + add_filter( |
|
1560 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1561 | + function ($url) { |
|
1562 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1563 | + } |
|
1564 | + ); |
|
1565 | + echo apply_filters( |
|
1566 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1567 | + \EEH_Template::powered_by_event_espresso( |
|
1568 | + '', |
|
1569 | + 'espresso-registration-footer-dv', |
|
1570 | + array('utm_content' => 'registration_checkout') |
|
1571 | + ) |
|
1572 | + ); |
|
1573 | + } |
|
1574 | + return ''; |
|
1575 | + } |
|
1576 | + |
|
1577 | + |
|
1578 | + |
|
1579 | + /** |
|
1580 | + * unlock_transaction |
|
1581 | + * |
|
1582 | + * @access public |
|
1583 | + * @return void |
|
1584 | + * @throws \EE_Error |
|
1585 | + */ |
|
1586 | + public function unlock_transaction() |
|
1587 | + { |
|
1588 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1589 | + $this->checkout->transaction->unlock(); |
|
1590 | + } |
|
1591 | + } |
|
1592 | + |
|
1593 | + |
|
1594 | + |
|
1595 | + /** |
|
1596 | + * _setup_redirect |
|
1597 | + * |
|
1598 | + * @access private |
|
1599 | + * @return void |
|
1600 | + */ |
|
1601 | + private function _setup_redirect() |
|
1602 | + { |
|
1603 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1604 | + $this->checkout->redirect = true; |
|
1605 | + if (empty($this->checkout->redirect_url)) { |
|
1606 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1607 | + } |
|
1608 | + $this->checkout->redirect_url = apply_filters( |
|
1609 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1610 | + $this->checkout->redirect_url, |
|
1611 | + $this->checkout |
|
1612 | + ); |
|
1613 | + } |
|
1614 | + } |
|
1615 | + |
|
1616 | + |
|
1617 | + |
|
1618 | + /** |
|
1619 | + * handle ajax message responses and redirects |
|
1620 | + * |
|
1621 | + * @access public |
|
1622 | + * @return void |
|
1623 | + * @throws \EE_Error |
|
1624 | + */ |
|
1625 | + public function go_to_next_step() |
|
1626 | + { |
|
1627 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1628 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1629 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1630 | + } |
|
1631 | + $this->unlock_transaction(); |
|
1632 | + // just return for these conditions |
|
1633 | + if ( |
|
1634 | + $this->checkout->admin_request |
|
1635 | + || $this->checkout->action === 'redirect_form' |
|
1636 | + || $this->checkout->action === 'update_checkout' |
|
1637 | + ) { |
|
1638 | + return; |
|
1639 | + } |
|
1640 | + // AJAX response |
|
1641 | + $this->_handle_json_response(); |
|
1642 | + // redirect to next step or the Thank You page |
|
1643 | + $this->_handle_html_redirects(); |
|
1644 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
1645 | + $this->_display_spco_reg_form(); |
|
1646 | + } |
|
1647 | + |
|
1648 | + |
|
1649 | + |
|
1650 | + /** |
|
1651 | + * _handle_json_response |
|
1652 | + * |
|
1653 | + * @access protected |
|
1654 | + * @return void |
|
1655 | + */ |
|
1656 | + protected function _handle_json_response() |
|
1657 | + { |
|
1658 | + // if this is an ajax request |
|
1659 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1660 | + // DEBUG LOG |
|
1661 | + //$this->checkout->log( |
|
1662 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1663 | + // array( |
|
1664 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1665 | + // 'redirect' => $this->checkout->redirect, |
|
1666 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
1667 | + // ) |
|
1668 | + //); |
|
1669 | + $this->checkout->json_response->set_registration_time_limit( |
|
1670 | + $this->checkout->get_registration_time_limit() |
|
1671 | + ); |
|
1672 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1673 | + // just send the ajax ( |
|
1674 | + $json_response = apply_filters( |
|
1675 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1676 | + $this->checkout->json_response |
|
1677 | + ); |
|
1678 | + echo $json_response; |
|
1679 | + exit(); |
|
1680 | + } |
|
1681 | + } |
|
1682 | + |
|
1683 | + |
|
1684 | + |
|
1685 | + /** |
|
1686 | + * _handle_redirects |
|
1687 | + * |
|
1688 | + * @access protected |
|
1689 | + * @return void |
|
1690 | + */ |
|
1691 | + protected function _handle_html_redirects() |
|
1692 | + { |
|
1693 | + // going somewhere ? |
|
1694 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1695 | + // store notices in a transient |
|
1696 | + EE_Error::get_notices(false, true, true); |
|
1697 | + // DEBUG LOG |
|
1698 | + //$this->checkout->log( |
|
1699 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1700 | + // array( |
|
1701 | + // 'headers_sent' => headers_sent(), |
|
1702 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
1703 | + // 'headers_list' => headers_list(), |
|
1704 | + // ) |
|
1705 | + //); |
|
1706 | + wp_safe_redirect($this->checkout->redirect_url); |
|
1707 | + exit(); |
|
1708 | + } |
|
1709 | + } |
|
1710 | + |
|
1711 | + |
|
1712 | + |
|
1713 | + /** |
|
1714 | + * set_checkout_anchor |
|
1715 | + * |
|
1716 | + * @access public |
|
1717 | + * @return void |
|
1718 | + */ |
|
1719 | + public function set_checkout_anchor() |
|
1720 | + { |
|
1721 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1722 | + } |
|
1723 | 1723 | |
1724 | 1724 | |
1725 | 1725 |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | */ |
217 | 217 | public static function set_definitions() |
218 | 218 | { |
219 | - define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
220 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
221 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
222 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
223 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
224 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
225 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
219 | + define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS); |
|
220 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); |
|
221 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); |
|
222 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); |
|
223 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); |
|
224 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); |
|
225 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); |
|
226 | 226 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
227 | 227 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
228 | 228 | __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | '</h4>', |
232 | 232 | '<br />', |
233 | 233 | '<p>', |
234 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
234 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
235 | 235 | '">', |
236 | 236 | '</a>', |
237 | 237 | '</p>' |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | return; |
256 | 256 | } |
257 | 257 | // filter list of reg_steps |
258 | - $reg_steps_to_load = (array)apply_filters( |
|
258 | + $reg_steps_to_load = (array) apply_filters( |
|
259 | 259 | 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
260 | 260 | EED_Single_Page_Checkout::get_reg_steps() |
261 | 261 | ); |
@@ -299,25 +299,25 @@ discard block |
||
299 | 299 | if (empty($reg_steps)) { |
300 | 300 | $reg_steps = array( |
301 | 301 | 10 => array( |
302 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
302 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
303 | 303 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
304 | 304 | 'slug' => 'attendee_information', |
305 | 305 | 'has_hooks' => false, |
306 | 306 | ), |
307 | 307 | 20 => array( |
308 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
308 | + 'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation', |
|
309 | 309 | 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
310 | 310 | 'slug' => 'registration_confirmation', |
311 | 311 | 'has_hooks' => false, |
312 | 312 | ), |
313 | 313 | 30 => array( |
314 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
314 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
315 | 315 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
316 | 316 | 'slug' => 'payment_options', |
317 | 317 | 'has_hooks' => true, |
318 | 318 | ), |
319 | 319 | 999 => array( |
320 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
320 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
321 | 321 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
322 | 322 | 'slug' => 'finalize_registration', |
323 | 323 | 'has_hooks' => false, |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | // DEBUG LOG |
500 | 500 | //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
501 | 501 | // get reg form |
502 | - if( ! $this->_check_form_submission()) { |
|
502 | + if ( ! $this->_check_form_submission()) { |
|
503 | 503 | EED_Single_Page_Checkout::$_initialized = true; |
504 | 504 | return; |
505 | 505 | } |
@@ -1063,7 +1063,7 @@ discard block |
||
1063 | 1063 | if ( ! $registration instanceof EE_Registration) { |
1064 | 1064 | throw new InvalidEntityException($registration, 'EE_Registration'); |
1065 | 1065 | } |
1066 | - $registrations[ $registration->ID() ] = $registration; |
|
1066 | + $registrations[$registration->ID()] = $registration; |
|
1067 | 1067 | } |
1068 | 1068 | } |
1069 | 1069 | $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
@@ -1293,7 +1293,7 @@ discard block |
||
1293 | 1293 | ) { |
1294 | 1294 | EE_Error::add_success( |
1295 | 1295 | $this->checkout->current_step->success_message() |
1296 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1296 | + . '<br />'.$this->checkout->next_step->_instructions() |
|
1297 | 1297 | ); |
1298 | 1298 | } |
1299 | 1299 | // pack it up, pack it in... |
@@ -1390,7 +1390,7 @@ discard block |
||
1390 | 1390 | '</h4>', |
1391 | 1391 | '<br />', |
1392 | 1392 | '<p>', |
1393 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1393 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
1394 | 1394 | '">', |
1395 | 1395 | '</a>', |
1396 | 1396 | '</p>' |
@@ -1416,12 +1416,12 @@ discard block |
||
1416 | 1416 | public function enqueue_styles_and_scripts() |
1417 | 1417 | { |
1418 | 1418 | // load css |
1419 | - wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1419 | + wp_register_style('single_page_checkout', SPCO_CSS_URL.'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1420 | 1420 | wp_enqueue_style('single_page_checkout'); |
1421 | 1421 | // load JS |
1422 | - wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
1423 | - wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
1424 | - wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
1422 | + wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL.'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
1423 | + wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL.'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
1424 | + wp_register_script('single_page_checkout', SPCO_JS_URL.'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
1425 | 1425 | if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
1426 | 1426 | $this->checkout->registration_form->enqueue_js(); |
1427 | 1427 | } |
@@ -1438,7 +1438,7 @@ discard block |
||
1438 | 1438 | * dynamic action hook for enqueueing styles and scripts with spco calls. |
1439 | 1439 | * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
1440 | 1440 | */ |
1441 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
1441 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), $this); |
|
1442 | 1442 | } |
1443 | 1443 | |
1444 | 1444 | |
@@ -1490,7 +1490,7 @@ discard block |
||
1490 | 1490 | 'layout_strategy' => |
1491 | 1491 | new EE_Template_Layout( |
1492 | 1492 | array( |
1493 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1493 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
1494 | 1494 | 'template_args' => array( |
1495 | 1495 | 'empty_cart' => $empty_cart, |
1496 | 1496 | 'revisit' => $this->checkout->revisit, |
@@ -1504,7 +1504,7 @@ discard block |
||
1504 | 1504 | sprintf( |
1505 | 1505 | __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
1506 | 1506 | 'event_espresso'), |
1507 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1507 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
1508 | 1508 | '">', |
1509 | 1509 | '</a>' |
1510 | 1510 | ) |
@@ -1558,7 +1558,7 @@ discard block |
||
1558 | 1558 | ) { |
1559 | 1559 | add_filter( |
1560 | 1560 | 'FHEE__EEH_Template__powered_by_event_espresso__url', |
1561 | - function ($url) { |
|
1561 | + function($url) { |
|
1562 | 1562 | return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
1563 | 1563 | } |
1564 | 1564 | ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,239 +40,239 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.26.rc.002'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.26.rc.002'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - /** |
|
197 | - * espresso_plugin_activation |
|
198 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
199 | - */ |
|
200 | - function espresso_plugin_activation() |
|
201 | - { |
|
202 | - update_option('ee_espresso_activation', true); |
|
203 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + /** |
|
197 | + * espresso_plugin_activation |
|
198 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
199 | + */ |
|
200 | + function espresso_plugin_activation() |
|
201 | + { |
|
202 | + update_option('ee_espresso_activation', true); |
|
203 | + } |
|
204 | 204 | |
205 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
206 | - /** |
|
207 | - * espresso_load_error_handling |
|
208 | - * this function loads EE's class for handling exceptions and errors |
|
209 | - */ |
|
210 | - function espresso_load_error_handling() |
|
211 | - { |
|
212 | - // load debugging tools |
|
213 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
214 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
215 | - EEH_Debug_Tools::instance(); |
|
216 | - } |
|
217 | - // load error handling |
|
218 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
219 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
220 | - } else { |
|
221 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
222 | - } |
|
223 | - } |
|
205 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
206 | + /** |
|
207 | + * espresso_load_error_handling |
|
208 | + * this function loads EE's class for handling exceptions and errors |
|
209 | + */ |
|
210 | + function espresso_load_error_handling() |
|
211 | + { |
|
212 | + // load debugging tools |
|
213 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
214 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
215 | + EEH_Debug_Tools::instance(); |
|
216 | + } |
|
217 | + // load error handling |
|
218 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
219 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
220 | + } else { |
|
221 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
222 | + } |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * espresso_load_required |
|
227 | - * given a class name and path, this function will load that file or throw an exception |
|
228 | - * |
|
229 | - * @param string $classname |
|
230 | - * @param string $full_path_to_file |
|
231 | - * @throws EE_Error |
|
232 | - */ |
|
233 | - function espresso_load_required($classname, $full_path_to_file) |
|
234 | - { |
|
235 | - static $error_handling_loaded = false; |
|
236 | - if ( ! $error_handling_loaded) { |
|
237 | - espresso_load_error_handling(); |
|
238 | - $error_handling_loaded = true; |
|
239 | - } |
|
240 | - if (is_readable($full_path_to_file)) { |
|
241 | - require_once($full_path_to_file); |
|
242 | - } else { |
|
243 | - throw new EE_Error ( |
|
244 | - sprintf( |
|
245 | - esc_html__( |
|
246 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - $classname |
|
250 | - ) |
|
251 | - ); |
|
252 | - } |
|
253 | - } |
|
225 | + /** |
|
226 | + * espresso_load_required |
|
227 | + * given a class name and path, this function will load that file or throw an exception |
|
228 | + * |
|
229 | + * @param string $classname |
|
230 | + * @param string $full_path_to_file |
|
231 | + * @throws EE_Error |
|
232 | + */ |
|
233 | + function espresso_load_required($classname, $full_path_to_file) |
|
234 | + { |
|
235 | + static $error_handling_loaded = false; |
|
236 | + if ( ! $error_handling_loaded) { |
|
237 | + espresso_load_error_handling(); |
|
238 | + $error_handling_loaded = true; |
|
239 | + } |
|
240 | + if (is_readable($full_path_to_file)) { |
|
241 | + require_once($full_path_to_file); |
|
242 | + } else { |
|
243 | + throw new EE_Error ( |
|
244 | + sprintf( |
|
245 | + esc_html__( |
|
246 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + $classname |
|
250 | + ) |
|
251 | + ); |
|
252 | + } |
|
253 | + } |
|
254 | 254 | |
255 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
256 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
257 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
258 | - new EE_Bootstrap(); |
|
259 | - } |
|
255 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
256 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
257 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
258 | + new EE_Bootstrap(); |
|
259 | + } |
|
260 | 260 | } |
261 | 261 | if ( ! function_exists('espresso_deactivate_plugin')) { |
262 | - /** |
|
263 | - * deactivate_plugin |
|
264 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
265 | - * |
|
266 | - * @access public |
|
267 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
271 | - { |
|
272 | - if ( ! function_exists('deactivate_plugins')) { |
|
273 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
274 | - } |
|
275 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
276 | - deactivate_plugins($plugin_basename); |
|
277 | - } |
|
262 | + /** |
|
263 | + * deactivate_plugin |
|
264 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
265 | + * |
|
266 | + * @access public |
|
267 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
271 | + { |
|
272 | + if ( ! function_exists('deactivate_plugins')) { |
|
273 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
274 | + } |
|
275 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
276 | + deactivate_plugins($plugin_basename); |
|
277 | + } |
|
278 | 278 | } |