Completed
Branch TASK/ignore-node-modules-symli... (d07a9d)
by
unknown
95:39 queued 81:47
created
core/EE_Payment_Processor.core.php 1 patch
Indentation   +838 added lines, -838 removed lines patch added patch discarded remove patch
@@ -18,842 +18,842 @@
 block discarded – undo
18 18
 class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Payment_Processor $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance;
26
-
27
-
28
-    /**
29
-     * @singleton method used to instantiate class object
30
-     * @access    public
31
-     * @return EE_Payment_Processor instance
32
-     */
33
-    public static function instance()
34
-    {
35
-        // check if class object is instantiated
36
-        if (! self::$_instance instanceof EE_Payment_Processor) {
37
-            self::$_instance = new self();
38
-        }
39
-        return self::$_instance;
40
-    }
41
-
42
-
43
-    /**
44
-     * @return EE_Payment_Processor
45
-     */
46
-    public static function reset()
47
-    {
48
-        self::$_instance = null;
49
-        return self::instance();
50
-    }
51
-
52
-
53
-    /**
54
-     *private constructor to prevent direct creation
55
-     *
56
-     * @Constructor
57
-     * @access private
58
-     */
59
-    private function __construct()
60
-    {
61
-        do_action('AHEE__EE_Payment_Processor__construct');
62
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
63
-    }
64
-
65
-
66
-    /**
67
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
68
-     * appropriately. Saves the payment that is generated
69
-     *
70
-     * @param EE_Payment_Method    $payment_method
71
-     * @param EE_Transaction       $transaction
72
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
73
-     *                                           Leave null if payment is for the full amount owing
74
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
75
-     *                                           Receive_form_submission() should have
76
-     *                                           already been called on the billing form
77
-     *                                           (ie, its inputs should have their normalized values set).
78
-     * @param string               $return_url   string used mostly by offsite gateways to specify
79
-     *                                           where to go AFTER the offsite gateway
80
-     * @param string               $method       like 'CART', indicates who the client who called this was
81
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
82
-     * @param boolean              $update_txn   whether or not to call
83
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
84
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
85
-     * @return EE_Payment
86
-     * @throws EE_Error
87
-     * @throws InvalidArgumentException
88
-     * @throws ReflectionException
89
-     * @throws RuntimeException
90
-     * @throws InvalidDataTypeException
91
-     * @throws InvalidInterfaceException
92
-     */
93
-    public function process_payment(
94
-        EE_Payment_Method $payment_method,
95
-        EE_Transaction $transaction,
96
-        $amount = null,
97
-        $billing_form = null,
98
-        $return_url = null,
99
-        $method = 'CART',
100
-        $by_admin = false,
101
-        $update_txn = true,
102
-        $cancel_url = ''
103
-    ) {
104
-        if ((float) $amount < 0) {
105
-            throw new EE_Error(
106
-                sprintf(
107
-                    __(
108
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
109
-                        'event_espresso'
110
-                    ),
111
-                    $amount,
112
-                    $transaction->ID()
113
-                )
114
-            );
115
-        }
116
-        // verify payment method
117
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
118
-            $payment_method,
119
-            true
120
-        );
121
-        // verify transaction
122
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
123
-        $transaction->set_payment_method_ID($payment_method->ID());
124
-        // verify payment method type
125
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
126
-            $payment = $payment_method->type_obj()->process_payment(
127
-                $transaction,
128
-                min($amount, $transaction->remaining()), // make sure we don't overcharge
129
-                $billing_form,
130
-                $return_url,
131
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
132
-                $method,
133
-                $by_admin
134
-            );
135
-            // check if payment method uses an off-site gateway
136
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
137
-                // don't process payments for off-site gateways yet because no payment has occurred yet
138
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
139
-            }
140
-            return $payment;
141
-        }
142
-        EE_Error::add_error(
143
-            sprintf(
144
-                __(
145
-                    'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
146
-                    'event_espresso'
147
-                ),
148
-                '<br/>',
149
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
150
-            ),
151
-            __FILE__,
152
-            __FUNCTION__,
153
-            __LINE__
154
-        );
155
-        return null;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param EE_Transaction|int $transaction
161
-     * @param EE_Payment_Method  $payment_method
162
-     * @return string
163
-     * @throws EE_Error
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     */
168
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
169
-    {
170
-        /** @type \EE_Transaction $transaction */
171
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172
-        $primary_reg = $transaction->primary_registration();
173
-        if (! $primary_reg instanceof EE_Registration) {
174
-            throw new EE_Error(
175
-                sprintf(
176
-                    __(
177
-                        'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
178
-                        'event_espresso'
179
-                    ),
180
-                    $transaction->ID()
181
-                )
182
-            );
183
-        }
184
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
185
-            $payment_method,
186
-            true
187
-        );
188
-        $url = add_query_arg(
189
-            array(
190
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
191
-                'ee_payment_method' => $payment_method->slug(),
192
-            ),
193
-            EE_Registry::instance()->CFG->core->txn_page_url()
194
-        );
195
-        return $url;
196
-    }
197
-
198
-
199
-    /**
200
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
201
-     * we can easily find what registration the IPN is for and what payment method.
202
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
203
-     * If a payment is found for the IPN info, it is saved.
204
-     *
205
-     * @param array              $_req_data            eg $_REQUEST
206
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
207
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
208
-     * @param boolean            $update_txn           whether or not to call
209
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
210
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
211
-     *                                                 or is processed manually ( false like Mijireh )
212
-     * @throws EE_Error
213
-     * @throws Exception
214
-     * @return EE_Payment
215
-     * @throws \RuntimeException
216
-     * @throws \ReflectionException
217
-     * @throws \InvalidArgumentException
218
-     * @throws InvalidInterfaceException
219
-     * @throws InvalidDataTypeException
220
-     */
221
-    public function process_ipn(
222
-        $_req_data,
223
-        $transaction = null,
224
-        $payment_method = null,
225
-        $update_txn = true,
226
-        $separate_IPN_request = true
227
-    ) {
228
-        EE_Registry::instance()->load_model('Change_Log');
229
-        $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
230
-        EE_Processor_Base::set_IPN($separate_IPN_request);
231
-        $obj_for_log = null;
232
-        if ($transaction instanceof EE_Transaction) {
233
-            $obj_for_log = $transaction;
234
-            if ($payment_method instanceof EE_Payment_Method) {
235
-                $obj_for_log = EEM_Payment::instance()->get_one(
236
-                    array(
237
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
238
-                        'order_by' => array('PAY_timestamp' => 'desc'),
239
-                    )
240
-                );
241
-            }
242
-        } elseif ($payment_method instanceof EE_Payment) {
243
-            $obj_for_log = $payment_method;
244
-        }
245
-        $log = EEM_Change_Log::instance()->log(
246
-            EEM_Change_Log::type_gateway,
247
-            array('IPN data received' => $_req_data),
248
-            $obj_for_log
249
-        );
250
-        try {
251
-            /**
252
-             * @var EE_Payment $payment
253
-             */
254
-            $payment = null;
255
-            if ($transaction && $payment_method) {
256
-                /** @type EE_Transaction $transaction */
257
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
258
-                /** @type EE_Payment_Method $payment_method */
259
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
260
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
261
-                    try {
262
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
263
-                        $log->set_object($payment);
264
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
265
-                        EEM_Change_Log::instance()->log(
266
-                            EEM_Change_Log::type_gateway,
267
-                            array(
268
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
269
-                                'current_url' => EEH_URL::current_url(),
270
-                                'payment'     => $e->getPaymentProperties(),
271
-                                'IPN_data'    => $e->getIpnData(),
272
-                            ),
273
-                            $obj_for_log
274
-                        );
275
-                        return $e->getPayment();
276
-                    }
277
-                } else {
278
-                    // not a payment
279
-                    EE_Error::add_error(
280
-                        sprintf(
281
-                            __(
282
-                                '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.',
283
-                                'event_espresso'
284
-                            ),
285
-                            '<br/>',
286
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
287
-                        ),
288
-                        __FILE__,
289
-                        __FUNCTION__,
290
-                        __LINE__
291
-                    );
292
-                }
293
-            } else {
294
-                // that's actually pretty ok. The IPN just wasn't able
295
-                // to identify which transaction or payment method this was for
296
-                // give all active payment methods a chance to claim it
297
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
298
-                foreach ($active_payment_methods as $active_payment_method) {
299
-                    try {
300
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
301
-                        $payment_method = $active_payment_method;
302
-                        EEM_Change_Log::instance()->log(
303
-                            EEM_Change_Log::type_gateway,
304
-                            array('IPN data' => $_req_data),
305
-                            $payment
306
-                        );
307
-                        break;
308
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
309
-                        EEM_Change_Log::instance()->log(
310
-                            EEM_Change_Log::type_gateway,
311
-                            array(
312
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
313
-                                'current_url' => EEH_URL::current_url(),
314
-                                'payment'     => $e->getPaymentProperties(),
315
-                                'IPN_data'    => $e->getIpnData(),
316
-                            ),
317
-                            $obj_for_log
318
-                        );
319
-                        return $e->getPayment();
320
-                    } catch (EE_Error $e) {
321
-                        // that's fine- it apparently couldn't handle the IPN
322
-                    }
323
-                }
324
-            }
325
-            // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
326
-            if ($payment instanceof EE_Payment) {
327
-                $payment->save();
328
-                //  update the TXN
329
-                $this->update_txn_based_on_payment(
330
-                    $transaction,
331
-                    $payment,
332
-                    $update_txn,
333
-                    $separate_IPN_request
334
-                );
335
-            } else {
336
-                // we couldn't find the payment for this IPN... let's try and log at least SOMETHING
337
-                if ($payment_method) {
338
-                    EEM_Change_Log::instance()->log(
339
-                        EEM_Change_Log::type_gateway,
340
-                        array('IPN data' => $_req_data),
341
-                        $payment_method
342
-                    );
343
-                } elseif ($transaction) {
344
-                    EEM_Change_Log::instance()->log(
345
-                        EEM_Change_Log::type_gateway,
346
-                        array('IPN data' => $_req_data),
347
-                        $transaction
348
-                    );
349
-                }
350
-            }
351
-            return $payment;
352
-        } catch (EE_Error $e) {
353
-            do_action(
354
-                'AHEE__log',
355
-                __FILE__,
356
-                __FUNCTION__,
357
-                sprintf(
358
-                    __(
359
-                        'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
360
-                        'event_espresso'
361
-                    ),
362
-                    print_r($transaction, true),
363
-                    print_r($_req_data, true),
364
-                    $e->getMessage()
365
-                )
366
-            );
367
-            throw $e;
368
-        }
369
-    }
370
-
371
-
372
-    /**
373
-     * Removes any non-printable illegal characters from the input,
374
-     * which might cause a raucous when trying to insert into the database
375
-     *
376
-     * @param  array $request_data
377
-     * @return array
378
-     */
379
-    protected function _remove_unusable_characters_from_array(array $request_data)
380
-    {
381
-        $return_data = array();
382
-        foreach ($request_data as $key => $value) {
383
-            $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
384
-                $value
385
-            );
386
-        }
387
-        return $return_data;
388
-    }
389
-
390
-
391
-    /**
392
-     * Removes any non-printable illegal characters from the input,
393
-     * which might cause a raucous when trying to insert into the database
394
-     *
395
-     * @param string $request_data
396
-     * @return string
397
-     */
398
-    protected function _remove_unusable_characters($request_data)
399
-    {
400
-        return preg_replace('/[^[:print:]]/', '', $request_data);
401
-    }
402
-
403
-
404
-    /**
405
-     * Should be called just before displaying the payment attempt results to the user,
406
-     * when the payment attempt has finished. Some payment methods may have special
407
-     * logic to perform here. For example, if process_payment() happens on a special request
408
-     * and then the user is redirected to a page that displays the payment's status, this
409
-     * should be called while loading the page that displays the payment's status. If the user is
410
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
411
-     * provider.
412
-     *
413
-     * @param EE_Transaction|int $transaction
414
-     * @param bool               $update_txn whether or not to call
415
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
416
-     * @return EE_Payment
417
-     * @throws EE_Error
418
-     * @throws InvalidArgumentException
419
-     * @throws ReflectionException
420
-     * @throws RuntimeException
421
-     * @throws InvalidDataTypeException
422
-     * @throws InvalidInterfaceException
423
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
424
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
425
-     */
426
-    public function finalize_payment_for($transaction, $update_txn = true)
427
-    {
428
-        /** @var $transaction EE_Transaction */
429
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
430
-        $last_payment_method = $transaction->payment_method();
431
-        if ($last_payment_method instanceof EE_Payment_Method) {
432
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
433
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
434
-            return $payment;
435
-        }
436
-        return null;
437
-    }
438
-
439
-
440
-    /**
441
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
442
-     *
443
-     * @param EE_Payment_Method $payment_method
444
-     * @param EE_Payment        $payment_to_refund
445
-     * @param array             $refund_info
446
-     * @return EE_Payment
447
-     * @throws EE_Error
448
-     * @throws InvalidArgumentException
449
-     * @throws ReflectionException
450
-     * @throws RuntimeException
451
-     * @throws InvalidDataTypeException
452
-     * @throws InvalidInterfaceException
453
-     */
454
-    public function process_refund(
455
-        EE_Payment_Method $payment_method,
456
-        EE_Payment $payment_to_refund,
457
-        array $refund_info = array()
458
-    ) {
459
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
460
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
461
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
462
-        }
463
-        return $payment_to_refund;
464
-    }
465
-
466
-
467
-    /**
468
-     * This should be called each time there may have been an update to a
469
-     * payment on a transaction (ie, we asked for a payment to process a
470
-     * payment for a transaction, or we told a payment method about an IPN, or
471
-     * we told a payment method to
472
-     * "finalize_payment_for" (a transaction), or we told a payment method to
473
-     * process a refund. This should handle firing the correct hooks to
474
-     * indicate
475
-     * what exactly happened and updating the transaction appropriately). This
476
-     * could be integrated directly into EE_Transaction upon save, but we want
477
-     * this logic to be separate from 'normal' plain-jane saving and updating
478
-     * of transactions and payments, and to be tied to payment processing.
479
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
480
-     * of previous code to decide whether or not to save (because the payment passed into
481
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
482
-     * in which case we only want that payment object for some temporary usage during this request,
483
-     * but we don't want it to be saved).
484
-     *
485
-     * @param EE_Transaction|int $transaction
486
-     * @param EE_Payment         $payment
487
-     * @param boolean            $update_txn
488
-     *                        whether or not to call
489
-     *                        EE_Transaction_Processor::
490
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
491
-     *                        (you can save 1 DB query if you know you're going
492
-     *                        to save it later instead)
493
-     * @param bool               $IPN
494
-     *                        if processing IPNs or other similar payment
495
-     *                        related activities that occur in alternate
496
-     *                        requests than the main one that is processing the
497
-     *                        TXN, then set this to true to check whether the
498
-     *                        TXN is locked before updating
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws ReflectionException
502
-     * @throws RuntimeException
503
-     * @throws InvalidDataTypeException
504
-     * @throws InvalidInterfaceException
505
-     */
506
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
507
-    {
508
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
509
-        /** @type EE_Transaction $transaction */
510
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
511
-        // can we freely update the TXN at this moment?
512
-        if ($IPN && $transaction->is_locked()) {
513
-            // don't update the transaction at this exact moment
514
-            // because the TXN is active in another request
515
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
516
-                time(),
517
-                $transaction->ID(),
518
-                $payment->ID()
519
-            );
520
-        } else {
521
-            // verify payment and that it has been saved
522
-            if ($payment instanceof EE_Payment && $payment->ID()) {
523
-                if ($payment->payment_method() instanceof EE_Payment_Method
524
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
-                ) {
526
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
-                    // update TXN registrations with payment info
528
-                    $this->process_registration_payments($transaction, $payment);
529
-                }
530
-                $do_action = $payment->just_approved()
531
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
-                    : $do_action;
533
-            } else {
534
-                // send out notifications
535
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
-            }
538
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
-                /** @type EE_Transaction_Payments $transaction_payments */
540
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
-                // set new value for total paid
542
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
543
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
-                if ($update_txn) {
545
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
546
-                }
547
-            }
548
-            // granular hook for others to use.
549
-            do_action($do_action, $transaction, $payment);
550
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
-            // global hook for others to use.
552
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
-        }
554
-    }
555
-
556
-
557
-    /**
558
-     * update registrations REG_paid field after successful payment and link registrations with payment
559
-     *
560
-     * @param EE_Transaction    $transaction
561
-     * @param EE_Payment        $payment
562
-     * @param EE_Registration[] $registrations
563
-     * @throws EE_Error
564
-     * @throws InvalidArgumentException
565
-     * @throws RuntimeException
566
-     * @throws InvalidDataTypeException
567
-     * @throws InvalidInterfaceException
568
-     */
569
-    public function process_registration_payments(
570
-        EE_Transaction $transaction,
571
-        EE_Payment $payment,
572
-        array $registrations = array()
573
-    ) {
574
-        // only process if payment was successful
575
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
576
-            return;
577
-        }
578
-        // EEM_Registration::instance()->show_next_x_db_queries();
579
-        if (empty($registrations)) {
580
-            // find registrations with monies owing that can receive a payment
581
-            $registrations = $transaction->registrations(
582
-                array(
583
-                    array(
584
-                        // only these reg statuses can receive payments
585
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
-                        'REG_final_price'  => array('!=', 0),
587
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
588
-                    ),
589
-                )
590
-            );
591
-        }
592
-        // still nothing ??!??
593
-        if (empty($registrations)) {
594
-            return;
595
-        }
596
-        // todo: break out the following logic into a separate strategy class
597
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
598
-        // todo: which would apply payments using the capitalist "first come first paid" approach
599
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
601
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
-        $refund = $payment->is_a_refund();
603
-        // how much is available to apply to registrations?
604
-        $available_payment_amount = abs($payment->amount());
605
-        foreach ($registrations as $registration) {
606
-            if ($registration instanceof EE_Registration) {
607
-                // nothing left?
608
-                if ($available_payment_amount <= 0) {
609
-                    break;
610
-                }
611
-                if ($refund) {
612
-                    $available_payment_amount = $this->process_registration_refund(
613
-                        $registration,
614
-                        $payment,
615
-                        $available_payment_amount
616
-                    );
617
-                } else {
618
-                    $available_payment_amount = $this->process_registration_payment(
619
-                        $registration,
620
-                        $payment,
621
-                        $available_payment_amount
622
-                    );
623
-                }
624
-            }
625
-        }
626
-        if ($available_payment_amount > 0
627
-            && apply_filters(
628
-                'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
629
-                false
630
-            )) {
631
-            EE_Error::add_attention(
632
-                sprintf(
633
-                    __(
634
-                        '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).',
635
-                        'event_espresso'
636
-                    ),
637
-                    EEH_Template::format_currency($available_payment_amount),
638
-                    implode(', ', array_keys($registrations)),
639
-                    '<br/>',
640
-                    EEH_Template::format_currency($payment->amount())
641
-                ),
642
-                __FILE__,
643
-                __FUNCTION__,
644
-                __LINE__
645
-            );
646
-        }
647
-    }
648
-
649
-
650
-    /**
651
-     * update registration REG_paid field after successful payment and link registration with payment
652
-     *
653
-     * @param EE_Registration $registration
654
-     * @param EE_Payment      $payment
655
-     * @param float           $available_payment_amount
656
-     * @return float
657
-     * @throws EE_Error
658
-     * @throws InvalidArgumentException
659
-     * @throws RuntimeException
660
-     * @throws InvalidDataTypeException
661
-     * @throws InvalidInterfaceException
662
-     */
663
-    public function process_registration_payment(
664
-        EE_Registration $registration,
665
-        EE_Payment $payment,
666
-        $available_payment_amount = 0.00
667
-    ) {
668
-        $owing = $registration->final_price() - $registration->paid();
669
-        if ($owing > 0) {
670
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
671
-            $payment_amount = min($available_payment_amount, $owing);
672
-            // update $available_payment_amount
673
-            $available_payment_amount -= $payment_amount;
674
-            // calculate and set new REG_paid
675
-            $registration->set_paid($registration->paid() + $payment_amount);
676
-            // now save it
677
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
678
-        }
679
-        return $available_payment_amount;
680
-    }
681
-
682
-
683
-    /**
684
-     * update registration REG_paid field after successful payment and link registration with payment
685
-     *
686
-     * @param EE_Registration $registration
687
-     * @param EE_Payment      $payment
688
-     * @param float           $payment_amount
689
-     * @return void
690
-     * @throws EE_Error
691
-     * @throws InvalidArgumentException
692
-     * @throws InvalidDataTypeException
693
-     * @throws InvalidInterfaceException
694
-     */
695
-    protected function _apply_registration_payment(
696
-        EE_Registration $registration,
697
-        EE_Payment $payment,
698
-        $payment_amount = 0.00
699
-    ) {
700
-        // find any existing reg payment records for this registration and payment
701
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
702
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
703
-        );
704
-        // if existing registration payment exists
705
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
706
-            // then update that record
707
-            $existing_reg_payment->set_amount($payment_amount);
708
-            $existing_reg_payment->save();
709
-        } else {
710
-            // or add new relation between registration and payment and set amount
711
-            $registration->_add_relation_to(
712
-                $payment,
713
-                'Payment',
714
-                array('RPY_amount' => $payment_amount)
715
-            );
716
-            // make it stick
717
-            $registration->save();
718
-        }
719
-    }
720
-
721
-
722
-    /**
723
-     * update registration REG_paid field after refund and link registration with payment
724
-     *
725
-     * @param EE_Registration $registration
726
-     * @param EE_Payment      $payment
727
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
728
-     * @return float
729
-     * @throws EE_Error
730
-     * @throws InvalidArgumentException
731
-     * @throws RuntimeException
732
-     * @throws InvalidDataTypeException
733
-     * @throws InvalidInterfaceException
734
-     */
735
-    public function process_registration_refund(
736
-        EE_Registration $registration,
737
-        EE_Payment $payment,
738
-        $available_refund_amount = 0.00
739
-    ) {
740
-        // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
741
-        if ($registration->paid() > 0) {
742
-            // ensure $available_refund_amount is NOT negative
743
-            $available_refund_amount = (float) abs($available_refund_amount);
744
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
745
-            $refund_amount = min($available_refund_amount, (float) $registration->paid());
746
-            // update $available_payment_amount
747
-            $available_refund_amount -= $refund_amount;
748
-            // calculate and set new REG_paid
749
-            $registration->set_paid($registration->paid() - $refund_amount);
750
-            // convert payment amount back to a negative value for storage in the db
751
-            $refund_amount = (float) abs($refund_amount) * -1;
752
-            // now save it
753
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
754
-        }
755
-        return $available_refund_amount;
756
-    }
757
-
758
-
759
-    /**
760
-     * Process payments and transaction after payment process completed.
761
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
762
-     * if this request happens to be processing an IPN,
763
-     * then we will also set the Payment Options Reg Step to completed,
764
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
765
-     *
766
-     * @param EE_Transaction $transaction
767
-     * @param EE_Payment     $payment
768
-     * @param bool           $IPN
769
-     * @throws EE_Error
770
-     * @throws InvalidArgumentException
771
-     * @throws ReflectionException
772
-     * @throws RuntimeException
773
-     * @throws InvalidDataTypeException
774
-     * @throws InvalidInterfaceException
775
-     */
776
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
777
-    {
778
-        /** @type EE_Transaction_Processor $transaction_processor */
779
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
780
-        // is the Payment Options Reg Step completed ?
781
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
782
-        // if the Payment Options Reg Step is completed...
783
-        $revisit = $payment_options_step_completed === true;
784
-        // then this is kinda sorta a revisit with regards to payments at least
785
-        $transaction_processor->set_revisit($revisit);
786
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
787
-        if ($IPN
788
-            && $payment_options_step_completed !== true
789
-            && ($payment->is_approved() || $payment->is_pending())
790
-        ) {
791
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
792
-                'payment_options'
793
-            );
794
-        }
795
-        // maybe update status, but don't save transaction just yet
796
-        $transaction->update_status_based_on_total_paid(false);
797
-        // check if 'finalize_registration' step has been completed...
798
-        $finalized = $transaction->reg_step_completed('finalize_registration');
799
-        //  if this is an IPN and the final step has not been initiated
800
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
801
-            // and if it hasn't already been set as being started...
802
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
803
-        }
804
-        $transaction->save();
805
-        // because the above will return false if the final step was not fully completed, we need to check again...
806
-        if ($IPN && $finalized !== false) {
807
-            // and if we are all good to go, then send out notifications
808
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
809
-            // ok, now process the transaction according to the payment
810
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
811
-                $transaction,
812
-                $payment
813
-            );
814
-        }
815
-        // DEBUG LOG
816
-        $payment_method = $payment->payment_method();
817
-        if ($payment_method instanceof EE_Payment_Method) {
818
-            $payment_method_type_obj = $payment_method->type_obj();
819
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
820
-                $gateway = $payment_method_type_obj->get_gateway();
821
-                if ($gateway instanceof EE_Gateway) {
822
-                    $gateway->log(
823
-                        array(
824
-                            'message'               => __('Post Payment Transaction Details', 'event_espresso'),
825
-                            'transaction'           => $transaction->model_field_array(),
826
-                            'finalized'             => $finalized,
827
-                            'IPN'                   => $IPN,
828
-                            'deliver_notifications' => has_filter(
829
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
830
-                            ),
831
-                        ),
832
-                        $payment
833
-                    );
834
-                }
835
-            }
836
-        }
837
-    }
838
-
839
-
840
-    /**
841
-     * Force posts to PayPal to use TLS v1.2. See:
842
-     * https://core.trac.wordpress.org/ticket/36320
843
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
844
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
845
-     * This will affect PayPal standard, pro, express, and Payflow.
846
-     *
847
-     * @param $handle
848
-     * @param $r
849
-     * @param $url
850
-     */
851
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
852
-    {
853
-        if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
854
-            // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
855
-            // instead of the constant because it might not be defined
856
-            curl_setopt($handle, CURLOPT_SSLVERSION, 6);
857
-        }
858
-    }
21
+	/**
22
+	 * @var EE_Payment_Processor $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance;
26
+
27
+
28
+	/**
29
+	 * @singleton method used to instantiate class object
30
+	 * @access    public
31
+	 * @return EE_Payment_Processor instance
32
+	 */
33
+	public static function instance()
34
+	{
35
+		// check if class object is instantiated
36
+		if (! self::$_instance instanceof EE_Payment_Processor) {
37
+			self::$_instance = new self();
38
+		}
39
+		return self::$_instance;
40
+	}
41
+
42
+
43
+	/**
44
+	 * @return EE_Payment_Processor
45
+	 */
46
+	public static function reset()
47
+	{
48
+		self::$_instance = null;
49
+		return self::instance();
50
+	}
51
+
52
+
53
+	/**
54
+	 *private constructor to prevent direct creation
55
+	 *
56
+	 * @Constructor
57
+	 * @access private
58
+	 */
59
+	private function __construct()
60
+	{
61
+		do_action('AHEE__EE_Payment_Processor__construct');
62
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
63
+	}
64
+
65
+
66
+	/**
67
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
68
+	 * appropriately. Saves the payment that is generated
69
+	 *
70
+	 * @param EE_Payment_Method    $payment_method
71
+	 * @param EE_Transaction       $transaction
72
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
73
+	 *                                           Leave null if payment is for the full amount owing
74
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
75
+	 *                                           Receive_form_submission() should have
76
+	 *                                           already been called on the billing form
77
+	 *                                           (ie, its inputs should have their normalized values set).
78
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
79
+	 *                                           where to go AFTER the offsite gateway
80
+	 * @param string               $method       like 'CART', indicates who the client who called this was
81
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
82
+	 * @param boolean              $update_txn   whether or not to call
83
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
84
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
85
+	 * @return EE_Payment
86
+	 * @throws EE_Error
87
+	 * @throws InvalidArgumentException
88
+	 * @throws ReflectionException
89
+	 * @throws RuntimeException
90
+	 * @throws InvalidDataTypeException
91
+	 * @throws InvalidInterfaceException
92
+	 */
93
+	public function process_payment(
94
+		EE_Payment_Method $payment_method,
95
+		EE_Transaction $transaction,
96
+		$amount = null,
97
+		$billing_form = null,
98
+		$return_url = null,
99
+		$method = 'CART',
100
+		$by_admin = false,
101
+		$update_txn = true,
102
+		$cancel_url = ''
103
+	) {
104
+		if ((float) $amount < 0) {
105
+			throw new EE_Error(
106
+				sprintf(
107
+					__(
108
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
109
+						'event_espresso'
110
+					),
111
+					$amount,
112
+					$transaction->ID()
113
+				)
114
+			);
115
+		}
116
+		// verify payment method
117
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
118
+			$payment_method,
119
+			true
120
+		);
121
+		// verify transaction
122
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
123
+		$transaction->set_payment_method_ID($payment_method->ID());
124
+		// verify payment method type
125
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
126
+			$payment = $payment_method->type_obj()->process_payment(
127
+				$transaction,
128
+				min($amount, $transaction->remaining()), // make sure we don't overcharge
129
+				$billing_form,
130
+				$return_url,
131
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
132
+				$method,
133
+				$by_admin
134
+			);
135
+			// check if payment method uses an off-site gateway
136
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
137
+				// don't process payments for off-site gateways yet because no payment has occurred yet
138
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
139
+			}
140
+			return $payment;
141
+		}
142
+		EE_Error::add_error(
143
+			sprintf(
144
+				__(
145
+					'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
146
+					'event_espresso'
147
+				),
148
+				'<br/>',
149
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
150
+			),
151
+			__FILE__,
152
+			__FUNCTION__,
153
+			__LINE__
154
+		);
155
+		return null;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param EE_Transaction|int $transaction
161
+	 * @param EE_Payment_Method  $payment_method
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 */
168
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
169
+	{
170
+		/** @type \EE_Transaction $transaction */
171
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172
+		$primary_reg = $transaction->primary_registration();
173
+		if (! $primary_reg instanceof EE_Registration) {
174
+			throw new EE_Error(
175
+				sprintf(
176
+					__(
177
+						'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
178
+						'event_espresso'
179
+					),
180
+					$transaction->ID()
181
+				)
182
+			);
183
+		}
184
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
185
+			$payment_method,
186
+			true
187
+		);
188
+		$url = add_query_arg(
189
+			array(
190
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
191
+				'ee_payment_method' => $payment_method->slug(),
192
+			),
193
+			EE_Registry::instance()->CFG->core->txn_page_url()
194
+		);
195
+		return $url;
196
+	}
197
+
198
+
199
+	/**
200
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
201
+	 * we can easily find what registration the IPN is for and what payment method.
202
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
203
+	 * If a payment is found for the IPN info, it is saved.
204
+	 *
205
+	 * @param array              $_req_data            eg $_REQUEST
206
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
207
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
208
+	 * @param boolean            $update_txn           whether or not to call
209
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
210
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
211
+	 *                                                 or is processed manually ( false like Mijireh )
212
+	 * @throws EE_Error
213
+	 * @throws Exception
214
+	 * @return EE_Payment
215
+	 * @throws \RuntimeException
216
+	 * @throws \ReflectionException
217
+	 * @throws \InvalidArgumentException
218
+	 * @throws InvalidInterfaceException
219
+	 * @throws InvalidDataTypeException
220
+	 */
221
+	public function process_ipn(
222
+		$_req_data,
223
+		$transaction = null,
224
+		$payment_method = null,
225
+		$update_txn = true,
226
+		$separate_IPN_request = true
227
+	) {
228
+		EE_Registry::instance()->load_model('Change_Log');
229
+		$_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
230
+		EE_Processor_Base::set_IPN($separate_IPN_request);
231
+		$obj_for_log = null;
232
+		if ($transaction instanceof EE_Transaction) {
233
+			$obj_for_log = $transaction;
234
+			if ($payment_method instanceof EE_Payment_Method) {
235
+				$obj_for_log = EEM_Payment::instance()->get_one(
236
+					array(
237
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
238
+						'order_by' => array('PAY_timestamp' => 'desc'),
239
+					)
240
+				);
241
+			}
242
+		} elseif ($payment_method instanceof EE_Payment) {
243
+			$obj_for_log = $payment_method;
244
+		}
245
+		$log = EEM_Change_Log::instance()->log(
246
+			EEM_Change_Log::type_gateway,
247
+			array('IPN data received' => $_req_data),
248
+			$obj_for_log
249
+		);
250
+		try {
251
+			/**
252
+			 * @var EE_Payment $payment
253
+			 */
254
+			$payment = null;
255
+			if ($transaction && $payment_method) {
256
+				/** @type EE_Transaction $transaction */
257
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
258
+				/** @type EE_Payment_Method $payment_method */
259
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
260
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
261
+					try {
262
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
263
+						$log->set_object($payment);
264
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
265
+						EEM_Change_Log::instance()->log(
266
+							EEM_Change_Log::type_gateway,
267
+							array(
268
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
269
+								'current_url' => EEH_URL::current_url(),
270
+								'payment'     => $e->getPaymentProperties(),
271
+								'IPN_data'    => $e->getIpnData(),
272
+							),
273
+							$obj_for_log
274
+						);
275
+						return $e->getPayment();
276
+					}
277
+				} else {
278
+					// not a payment
279
+					EE_Error::add_error(
280
+						sprintf(
281
+							__(
282
+								'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.',
283
+								'event_espresso'
284
+							),
285
+							'<br/>',
286
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
287
+						),
288
+						__FILE__,
289
+						__FUNCTION__,
290
+						__LINE__
291
+					);
292
+				}
293
+			} else {
294
+				// that's actually pretty ok. The IPN just wasn't able
295
+				// to identify which transaction or payment method this was for
296
+				// give all active payment methods a chance to claim it
297
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
298
+				foreach ($active_payment_methods as $active_payment_method) {
299
+					try {
300
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
301
+						$payment_method = $active_payment_method;
302
+						EEM_Change_Log::instance()->log(
303
+							EEM_Change_Log::type_gateway,
304
+							array('IPN data' => $_req_data),
305
+							$payment
306
+						);
307
+						break;
308
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
309
+						EEM_Change_Log::instance()->log(
310
+							EEM_Change_Log::type_gateway,
311
+							array(
312
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
313
+								'current_url' => EEH_URL::current_url(),
314
+								'payment'     => $e->getPaymentProperties(),
315
+								'IPN_data'    => $e->getIpnData(),
316
+							),
317
+							$obj_for_log
318
+						);
319
+						return $e->getPayment();
320
+					} catch (EE_Error $e) {
321
+						// that's fine- it apparently couldn't handle the IPN
322
+					}
323
+				}
324
+			}
325
+			// EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
326
+			if ($payment instanceof EE_Payment) {
327
+				$payment->save();
328
+				//  update the TXN
329
+				$this->update_txn_based_on_payment(
330
+					$transaction,
331
+					$payment,
332
+					$update_txn,
333
+					$separate_IPN_request
334
+				);
335
+			} else {
336
+				// we couldn't find the payment for this IPN... let's try and log at least SOMETHING
337
+				if ($payment_method) {
338
+					EEM_Change_Log::instance()->log(
339
+						EEM_Change_Log::type_gateway,
340
+						array('IPN data' => $_req_data),
341
+						$payment_method
342
+					);
343
+				} elseif ($transaction) {
344
+					EEM_Change_Log::instance()->log(
345
+						EEM_Change_Log::type_gateway,
346
+						array('IPN data' => $_req_data),
347
+						$transaction
348
+					);
349
+				}
350
+			}
351
+			return $payment;
352
+		} catch (EE_Error $e) {
353
+			do_action(
354
+				'AHEE__log',
355
+				__FILE__,
356
+				__FUNCTION__,
357
+				sprintf(
358
+					__(
359
+						'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
360
+						'event_espresso'
361
+					),
362
+					print_r($transaction, true),
363
+					print_r($_req_data, true),
364
+					$e->getMessage()
365
+				)
366
+			);
367
+			throw $e;
368
+		}
369
+	}
370
+
371
+
372
+	/**
373
+	 * Removes any non-printable illegal characters from the input,
374
+	 * which might cause a raucous when trying to insert into the database
375
+	 *
376
+	 * @param  array $request_data
377
+	 * @return array
378
+	 */
379
+	protected function _remove_unusable_characters_from_array(array $request_data)
380
+	{
381
+		$return_data = array();
382
+		foreach ($request_data as $key => $value) {
383
+			$return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
384
+				$value
385
+			);
386
+		}
387
+		return $return_data;
388
+	}
389
+
390
+
391
+	/**
392
+	 * Removes any non-printable illegal characters from the input,
393
+	 * which might cause a raucous when trying to insert into the database
394
+	 *
395
+	 * @param string $request_data
396
+	 * @return string
397
+	 */
398
+	protected function _remove_unusable_characters($request_data)
399
+	{
400
+		return preg_replace('/[^[:print:]]/', '', $request_data);
401
+	}
402
+
403
+
404
+	/**
405
+	 * Should be called just before displaying the payment attempt results to the user,
406
+	 * when the payment attempt has finished. Some payment methods may have special
407
+	 * logic to perform here. For example, if process_payment() happens on a special request
408
+	 * and then the user is redirected to a page that displays the payment's status, this
409
+	 * should be called while loading the page that displays the payment's status. If the user is
410
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
411
+	 * provider.
412
+	 *
413
+	 * @param EE_Transaction|int $transaction
414
+	 * @param bool               $update_txn whether or not to call
415
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
416
+	 * @return EE_Payment
417
+	 * @throws EE_Error
418
+	 * @throws InvalidArgumentException
419
+	 * @throws ReflectionException
420
+	 * @throws RuntimeException
421
+	 * @throws InvalidDataTypeException
422
+	 * @throws InvalidInterfaceException
423
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
424
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
425
+	 */
426
+	public function finalize_payment_for($transaction, $update_txn = true)
427
+	{
428
+		/** @var $transaction EE_Transaction */
429
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
430
+		$last_payment_method = $transaction->payment_method();
431
+		if ($last_payment_method instanceof EE_Payment_Method) {
432
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
433
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
434
+			return $payment;
435
+		}
436
+		return null;
437
+	}
438
+
439
+
440
+	/**
441
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
442
+	 *
443
+	 * @param EE_Payment_Method $payment_method
444
+	 * @param EE_Payment        $payment_to_refund
445
+	 * @param array             $refund_info
446
+	 * @return EE_Payment
447
+	 * @throws EE_Error
448
+	 * @throws InvalidArgumentException
449
+	 * @throws ReflectionException
450
+	 * @throws RuntimeException
451
+	 * @throws InvalidDataTypeException
452
+	 * @throws InvalidInterfaceException
453
+	 */
454
+	public function process_refund(
455
+		EE_Payment_Method $payment_method,
456
+		EE_Payment $payment_to_refund,
457
+		array $refund_info = array()
458
+	) {
459
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
460
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
461
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
462
+		}
463
+		return $payment_to_refund;
464
+	}
465
+
466
+
467
+	/**
468
+	 * This should be called each time there may have been an update to a
469
+	 * payment on a transaction (ie, we asked for a payment to process a
470
+	 * payment for a transaction, or we told a payment method about an IPN, or
471
+	 * we told a payment method to
472
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
473
+	 * process a refund. This should handle firing the correct hooks to
474
+	 * indicate
475
+	 * what exactly happened and updating the transaction appropriately). This
476
+	 * could be integrated directly into EE_Transaction upon save, but we want
477
+	 * this logic to be separate from 'normal' plain-jane saving and updating
478
+	 * of transactions and payments, and to be tied to payment processing.
479
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
480
+	 * of previous code to decide whether or not to save (because the payment passed into
481
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
482
+	 * in which case we only want that payment object for some temporary usage during this request,
483
+	 * but we don't want it to be saved).
484
+	 *
485
+	 * @param EE_Transaction|int $transaction
486
+	 * @param EE_Payment         $payment
487
+	 * @param boolean            $update_txn
488
+	 *                        whether or not to call
489
+	 *                        EE_Transaction_Processor::
490
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
491
+	 *                        (you can save 1 DB query if you know you're going
492
+	 *                        to save it later instead)
493
+	 * @param bool               $IPN
494
+	 *                        if processing IPNs or other similar payment
495
+	 *                        related activities that occur in alternate
496
+	 *                        requests than the main one that is processing the
497
+	 *                        TXN, then set this to true to check whether the
498
+	 *                        TXN is locked before updating
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws ReflectionException
502
+	 * @throws RuntimeException
503
+	 * @throws InvalidDataTypeException
504
+	 * @throws InvalidInterfaceException
505
+	 */
506
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
507
+	{
508
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
509
+		/** @type EE_Transaction $transaction */
510
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
511
+		// can we freely update the TXN at this moment?
512
+		if ($IPN && $transaction->is_locked()) {
513
+			// don't update the transaction at this exact moment
514
+			// because the TXN is active in another request
515
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
516
+				time(),
517
+				$transaction->ID(),
518
+				$payment->ID()
519
+			);
520
+		} else {
521
+			// verify payment and that it has been saved
522
+			if ($payment instanceof EE_Payment && $payment->ID()) {
523
+				if ($payment->payment_method() instanceof EE_Payment_Method
524
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
+				) {
526
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
+					// update TXN registrations with payment info
528
+					$this->process_registration_payments($transaction, $payment);
529
+				}
530
+				$do_action = $payment->just_approved()
531
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
+					: $do_action;
533
+			} else {
534
+				// send out notifications
535
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
+			}
538
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
+				/** @type EE_Transaction_Payments $transaction_payments */
540
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
+				// set new value for total paid
542
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
543
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
+				if ($update_txn) {
545
+					$this->_post_payment_processing($transaction, $payment, $IPN);
546
+				}
547
+			}
548
+			// granular hook for others to use.
549
+			do_action($do_action, $transaction, $payment);
550
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
+			// global hook for others to use.
552
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
+		}
554
+	}
555
+
556
+
557
+	/**
558
+	 * update registrations REG_paid field after successful payment and link registrations with payment
559
+	 *
560
+	 * @param EE_Transaction    $transaction
561
+	 * @param EE_Payment        $payment
562
+	 * @param EE_Registration[] $registrations
563
+	 * @throws EE_Error
564
+	 * @throws InvalidArgumentException
565
+	 * @throws RuntimeException
566
+	 * @throws InvalidDataTypeException
567
+	 * @throws InvalidInterfaceException
568
+	 */
569
+	public function process_registration_payments(
570
+		EE_Transaction $transaction,
571
+		EE_Payment $payment,
572
+		array $registrations = array()
573
+	) {
574
+		// only process if payment was successful
575
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
576
+			return;
577
+		}
578
+		// EEM_Registration::instance()->show_next_x_db_queries();
579
+		if (empty($registrations)) {
580
+			// find registrations with monies owing that can receive a payment
581
+			$registrations = $transaction->registrations(
582
+				array(
583
+					array(
584
+						// only these reg statuses can receive payments
585
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
+						'REG_final_price'  => array('!=', 0),
587
+						'REG_final_price*' => array('!=', 'REG_paid', true),
588
+					),
589
+				)
590
+			);
591
+		}
592
+		// still nothing ??!??
593
+		if (empty($registrations)) {
594
+			return;
595
+		}
596
+		// todo: break out the following logic into a separate strategy class
597
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
598
+		// todo: which would apply payments using the capitalist "first come first paid" approach
599
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
601
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
+		$refund = $payment->is_a_refund();
603
+		// how much is available to apply to registrations?
604
+		$available_payment_amount = abs($payment->amount());
605
+		foreach ($registrations as $registration) {
606
+			if ($registration instanceof EE_Registration) {
607
+				// nothing left?
608
+				if ($available_payment_amount <= 0) {
609
+					break;
610
+				}
611
+				if ($refund) {
612
+					$available_payment_amount = $this->process_registration_refund(
613
+						$registration,
614
+						$payment,
615
+						$available_payment_amount
616
+					);
617
+				} else {
618
+					$available_payment_amount = $this->process_registration_payment(
619
+						$registration,
620
+						$payment,
621
+						$available_payment_amount
622
+					);
623
+				}
624
+			}
625
+		}
626
+		if ($available_payment_amount > 0
627
+			&& apply_filters(
628
+				'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
629
+				false
630
+			)) {
631
+			EE_Error::add_attention(
632
+				sprintf(
633
+					__(
634
+						'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).',
635
+						'event_espresso'
636
+					),
637
+					EEH_Template::format_currency($available_payment_amount),
638
+					implode(', ', array_keys($registrations)),
639
+					'<br/>',
640
+					EEH_Template::format_currency($payment->amount())
641
+				),
642
+				__FILE__,
643
+				__FUNCTION__,
644
+				__LINE__
645
+			);
646
+		}
647
+	}
648
+
649
+
650
+	/**
651
+	 * update registration REG_paid field after successful payment and link registration with payment
652
+	 *
653
+	 * @param EE_Registration $registration
654
+	 * @param EE_Payment      $payment
655
+	 * @param float           $available_payment_amount
656
+	 * @return float
657
+	 * @throws EE_Error
658
+	 * @throws InvalidArgumentException
659
+	 * @throws RuntimeException
660
+	 * @throws InvalidDataTypeException
661
+	 * @throws InvalidInterfaceException
662
+	 */
663
+	public function process_registration_payment(
664
+		EE_Registration $registration,
665
+		EE_Payment $payment,
666
+		$available_payment_amount = 0.00
667
+	) {
668
+		$owing = $registration->final_price() - $registration->paid();
669
+		if ($owing > 0) {
670
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
671
+			$payment_amount = min($available_payment_amount, $owing);
672
+			// update $available_payment_amount
673
+			$available_payment_amount -= $payment_amount;
674
+			// calculate and set new REG_paid
675
+			$registration->set_paid($registration->paid() + $payment_amount);
676
+			// now save it
677
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
678
+		}
679
+		return $available_payment_amount;
680
+	}
681
+
682
+
683
+	/**
684
+	 * update registration REG_paid field after successful payment and link registration with payment
685
+	 *
686
+	 * @param EE_Registration $registration
687
+	 * @param EE_Payment      $payment
688
+	 * @param float           $payment_amount
689
+	 * @return void
690
+	 * @throws EE_Error
691
+	 * @throws InvalidArgumentException
692
+	 * @throws InvalidDataTypeException
693
+	 * @throws InvalidInterfaceException
694
+	 */
695
+	protected function _apply_registration_payment(
696
+		EE_Registration $registration,
697
+		EE_Payment $payment,
698
+		$payment_amount = 0.00
699
+	) {
700
+		// find any existing reg payment records for this registration and payment
701
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
702
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
703
+		);
704
+		// if existing registration payment exists
705
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
706
+			// then update that record
707
+			$existing_reg_payment->set_amount($payment_amount);
708
+			$existing_reg_payment->save();
709
+		} else {
710
+			// or add new relation between registration and payment and set amount
711
+			$registration->_add_relation_to(
712
+				$payment,
713
+				'Payment',
714
+				array('RPY_amount' => $payment_amount)
715
+			);
716
+			// make it stick
717
+			$registration->save();
718
+		}
719
+	}
720
+
721
+
722
+	/**
723
+	 * update registration REG_paid field after refund and link registration with payment
724
+	 *
725
+	 * @param EE_Registration $registration
726
+	 * @param EE_Payment      $payment
727
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
728
+	 * @return float
729
+	 * @throws EE_Error
730
+	 * @throws InvalidArgumentException
731
+	 * @throws RuntimeException
732
+	 * @throws InvalidDataTypeException
733
+	 * @throws InvalidInterfaceException
734
+	 */
735
+	public function process_registration_refund(
736
+		EE_Registration $registration,
737
+		EE_Payment $payment,
738
+		$available_refund_amount = 0.00
739
+	) {
740
+		// EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
741
+		if ($registration->paid() > 0) {
742
+			// ensure $available_refund_amount is NOT negative
743
+			$available_refund_amount = (float) abs($available_refund_amount);
744
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
745
+			$refund_amount = min($available_refund_amount, (float) $registration->paid());
746
+			// update $available_payment_amount
747
+			$available_refund_amount -= $refund_amount;
748
+			// calculate and set new REG_paid
749
+			$registration->set_paid($registration->paid() - $refund_amount);
750
+			// convert payment amount back to a negative value for storage in the db
751
+			$refund_amount = (float) abs($refund_amount) * -1;
752
+			// now save it
753
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
754
+		}
755
+		return $available_refund_amount;
756
+	}
757
+
758
+
759
+	/**
760
+	 * Process payments and transaction after payment process completed.
761
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
762
+	 * if this request happens to be processing an IPN,
763
+	 * then we will also set the Payment Options Reg Step to completed,
764
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
765
+	 *
766
+	 * @param EE_Transaction $transaction
767
+	 * @param EE_Payment     $payment
768
+	 * @param bool           $IPN
769
+	 * @throws EE_Error
770
+	 * @throws InvalidArgumentException
771
+	 * @throws ReflectionException
772
+	 * @throws RuntimeException
773
+	 * @throws InvalidDataTypeException
774
+	 * @throws InvalidInterfaceException
775
+	 */
776
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
777
+	{
778
+		/** @type EE_Transaction_Processor $transaction_processor */
779
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
780
+		// is the Payment Options Reg Step completed ?
781
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
782
+		// if the Payment Options Reg Step is completed...
783
+		$revisit = $payment_options_step_completed === true;
784
+		// then this is kinda sorta a revisit with regards to payments at least
785
+		$transaction_processor->set_revisit($revisit);
786
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
787
+		if ($IPN
788
+			&& $payment_options_step_completed !== true
789
+			&& ($payment->is_approved() || $payment->is_pending())
790
+		) {
791
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
792
+				'payment_options'
793
+			);
794
+		}
795
+		// maybe update status, but don't save transaction just yet
796
+		$transaction->update_status_based_on_total_paid(false);
797
+		// check if 'finalize_registration' step has been completed...
798
+		$finalized = $transaction->reg_step_completed('finalize_registration');
799
+		//  if this is an IPN and the final step has not been initiated
800
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
801
+			// and if it hasn't already been set as being started...
802
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
803
+		}
804
+		$transaction->save();
805
+		// because the above will return false if the final step was not fully completed, we need to check again...
806
+		if ($IPN && $finalized !== false) {
807
+			// and if we are all good to go, then send out notifications
808
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
809
+			// ok, now process the transaction according to the payment
810
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
811
+				$transaction,
812
+				$payment
813
+			);
814
+		}
815
+		// DEBUG LOG
816
+		$payment_method = $payment->payment_method();
817
+		if ($payment_method instanceof EE_Payment_Method) {
818
+			$payment_method_type_obj = $payment_method->type_obj();
819
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
820
+				$gateway = $payment_method_type_obj->get_gateway();
821
+				if ($gateway instanceof EE_Gateway) {
822
+					$gateway->log(
823
+						array(
824
+							'message'               => __('Post Payment Transaction Details', 'event_espresso'),
825
+							'transaction'           => $transaction->model_field_array(),
826
+							'finalized'             => $finalized,
827
+							'IPN'                   => $IPN,
828
+							'deliver_notifications' => has_filter(
829
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
830
+							),
831
+						),
832
+						$payment
833
+					);
834
+				}
835
+			}
836
+		}
837
+	}
838
+
839
+
840
+	/**
841
+	 * Force posts to PayPal to use TLS v1.2. See:
842
+	 * https://core.trac.wordpress.org/ticket/36320
843
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
844
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
845
+	 * This will affect PayPal standard, pro, express, and Payflow.
846
+	 *
847
+	 * @param $handle
848
+	 * @param $r
849
+	 * @param $url
850
+	 */
851
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
852
+	{
853
+		if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
854
+			// Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
855
+			// instead of the constant because it might not be defined
856
+			curl_setopt($handle, CURLOPT_SSLVERSION, 6);
857
+		}
858
+	}
859 859
 }
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEventAttendees.php 1 patch
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -27,334 +27,334 @@
 block discarded – undo
27 27
 class EspressoEventAttendees extends EspressoShortcode
28 28
 {
29 29
 
30
-    private $query_params = array(
31
-        0 => array(),
32
-    );
30
+	private $query_params = array(
31
+		0 => array(),
32
+	);
33 33
 
34
-    private $template_args = array(
35
-        'contacts' => array(),
36
-        'event'    => null,
37
-        'datetime' => null,
38
-        'ticket'   => null,
39
-    );
34
+	private $template_args = array(
35
+		'contacts' => array(),
36
+		'event'    => null,
37
+		'datetime' => null,
38
+		'ticket'   => null,
39
+	);
40 40
 
41
-    /**
42
-     * the actual shortcode tag that gets registered with WordPress
43
-     *
44
-     * @return string
45
-     */
46
-    public function getTag()
47
-    {
48
-        return 'ESPRESSO_EVENT_ATTENDEES';
49
-    }
41
+	/**
42
+	 * the actual shortcode tag that gets registered with WordPress
43
+	 *
44
+	 * @return string
45
+	 */
46
+	public function getTag()
47
+	{
48
+		return 'ESPRESSO_EVENT_ATTENDEES';
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * the time in seconds to cache the results of the processShortcode() method
54
-     * 0 means the processShortcode() results will NOT be cached at all
55
-     *
56
-     * @return int
57
-     */
58
-    public function cacheExpiration()
59
-    {
60
-        return 0;
61
-    }
52
+	/**
53
+	 * the time in seconds to cache the results of the processShortcode() method
54
+	 * 0 means the processShortcode() results will NOT be cached at all
55
+	 *
56
+	 * @return int
57
+	 */
58
+	public function cacheExpiration()
59
+	{
60
+		return 0;
61
+	}
62 62
 
63 63
 
64
-    /**
65
-     * a place for adding any initialization code that needs to run prior to wp_header().
66
-     * this may be required for shortcodes that utilize a corresponding module,
67
-     * and need to enqueue assets for that module
68
-     *
69
-     * @return void
70
-     */
71
-    public function initializeShortcode()
72
-    {
73
-        $this->shortcodeHasBeenInitialized();
74
-    }
64
+	/**
65
+	 * a place for adding any initialization code that needs to run prior to wp_header().
66
+	 * this may be required for shortcodes that utilize a corresponding module,
67
+	 * and need to enqueue assets for that module
68
+	 *
69
+	 * @return void
70
+	 */
71
+	public function initializeShortcode()
72
+	{
73
+		$this->shortcodeHasBeenInitialized();
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
79
-     *  [ESPRESSO_EVENT_ATTENDEES]
80
-     *  - defaults to attendees for earliest active event, or earliest upcoming event.
81
-     *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
82
-     *  - attendees for specific event.
83
-     *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
84
-     *  - attendees for a specific datetime.
85
-     *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
86
-     *  - attendees for a specific ticket.
87
-     *  [ESPRESSO_EVENT_ATTENDEES status=all]
88
-     *  - specific registration status (use status id) or all for all attendees regardless of status.
89
-     *  Note default is to only return approved attendees
90
-     *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
91
-     *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
92
-     *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
93
-     *  - default is to not display attendees list on archive pages.
94
-     * Note: because of the relationship between event_id, ticket_id, and datetime_id:
95
-     * If more than one of those params is included, then preference is given to the following:
96
-     *  - event_id is used whenever its present and any others are ignored.
97
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
98
-     *  - otherwise ticket_id is used if present.
99
-     *
100
-     * @param array $attributes
101
-     * @return string
102
-     * @throws EE_Error
103
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
104
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
105
-     * @throws \InvalidArgumentException
106
-     */
107
-    public function processShortcode($attributes = array())
108
-    {
109
-        // grab attributes and merge with defaults
110
-        $attributes = $this->getAttributes((array) $attributes);
111
-        $archive = is_archive();
112
-        $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
113
-        // don't display on archives unless 'display_on_archives' is true
114
-        if ($archive && ! $display_on_archives) {
115
-            return '';
116
-        }
77
+	/**
78
+	 * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
79
+	 *  [ESPRESSO_EVENT_ATTENDEES]
80
+	 *  - defaults to attendees for earliest active event, or earliest upcoming event.
81
+	 *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
82
+	 *  - attendees for specific event.
83
+	 *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
84
+	 *  - attendees for a specific datetime.
85
+	 *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
86
+	 *  - attendees for a specific ticket.
87
+	 *  [ESPRESSO_EVENT_ATTENDEES status=all]
88
+	 *  - specific registration status (use status id) or all for all attendees regardless of status.
89
+	 *  Note default is to only return approved attendees
90
+	 *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
91
+	 *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
92
+	 *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
93
+	 *  - default is to not display attendees list on archive pages.
94
+	 * Note: because of the relationship between event_id, ticket_id, and datetime_id:
95
+	 * If more than one of those params is included, then preference is given to the following:
96
+	 *  - event_id is used whenever its present and any others are ignored.
97
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
98
+	 *  - otherwise ticket_id is used if present.
99
+	 *
100
+	 * @param array $attributes
101
+	 * @return string
102
+	 * @throws EE_Error
103
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
104
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
105
+	 * @throws \InvalidArgumentException
106
+	 */
107
+	public function processShortcode($attributes = array())
108
+	{
109
+		// grab attributes and merge with defaults
110
+		$attributes = $this->getAttributes((array) $attributes);
111
+		$archive = is_archive();
112
+		$display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
113
+		// don't display on archives unless 'display_on_archives' is true
114
+		if ($archive && ! $display_on_archives) {
115
+			return '';
116
+		}
117 117
 
118
-        try {
119
-            $this->setBaseTemplateArguments($attributes);
120
-            $this->validateEntities($attributes);
121
-            $this->setBaseQueryParams();
122
-        } catch (EntityNotFoundException $e) {
123
-            if (WP_DEBUG) {
124
-                return '<div class="important-notice ee-error">'
125
-                       . $e->getMessage()
126
-                       . '</div>';
127
-            }
128
-            return '';
129
-        }
130
-        $this->setAdditionalQueryParams($attributes);
131
-        // get contacts!
132
-        $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
133
-        // all set let's load up the template and return.
134
-        return EEH_Template::locate_template(
135
-            'loop-espresso_event_attendees.php',
136
-            $this->template_args
137
-        );
138
-    }
118
+		try {
119
+			$this->setBaseTemplateArguments($attributes);
120
+			$this->validateEntities($attributes);
121
+			$this->setBaseQueryParams();
122
+		} catch (EntityNotFoundException $e) {
123
+			if (WP_DEBUG) {
124
+				return '<div class="important-notice ee-error">'
125
+					   . $e->getMessage()
126
+					   . '</div>';
127
+			}
128
+			return '';
129
+		}
130
+		$this->setAdditionalQueryParams($attributes);
131
+		// get contacts!
132
+		$this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
133
+		// all set let's load up the template and return.
134
+		return EEH_Template::locate_template(
135
+			'loop-espresso_event_attendees.php',
136
+			$this->template_args
137
+		);
138
+	}
139 139
 
140 140
 
141
-    /**
142
-     * merge incoming attributes with filtered defaults
143
-     *
144
-     * @param array $attributes
145
-     * @return array
146
-     */
147
-    private function getAttributes(array $attributes)
148
-    {
149
-        return (array) apply_filters(
150
-            'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
151
-            $attributes + array(
152
-                'event_id'            => null,
153
-                'datetime_id'         => null,
154
-                'ticket_id'           => null,
155
-                'status'              => EEM_Registration::status_id_approved,
156
-                'show_gravatar'       => false,
157
-                'display_on_archives' => false,
158
-            )
159
-        );
160
-    }
141
+	/**
142
+	 * merge incoming attributes with filtered defaults
143
+	 *
144
+	 * @param array $attributes
145
+	 * @return array
146
+	 */
147
+	private function getAttributes(array $attributes)
148
+	{
149
+		return (array) apply_filters(
150
+			'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
151
+			$attributes + array(
152
+				'event_id'            => null,
153
+				'datetime_id'         => null,
154
+				'ticket_id'           => null,
155
+				'status'              => EEM_Registration::status_id_approved,
156
+				'show_gravatar'       => false,
157
+				'display_on_archives' => false,
158
+			)
159
+		);
160
+	}
161 161
 
162 162
 
163
-    /**
164
-     * Set all the base template arguments from the incoming attributes.
165
-     * * Note: because of the relationship between event_id, ticket_id, and datetime_id:
166
-     * If more than one of those params is included, then preference is given to the following:
167
-     *  - event_id is used whenever its present and any others are ignored.
168
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
169
-     *  - otherwise ticket_id is used if present.
170
-     *
171
-     * @param array $attributes
172
-     * @throws EE_Error
173
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
174
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
175
-     * @throws \InvalidArgumentException
176
-     */
177
-    private function setBaseTemplateArguments(array $attributes)
178
-    {
179
-        $this->template_args['show_gravatar'] = $attributes['show_gravatar'];
180
-        $this->template_args['event'] = $this->getEvent($attributes);
181
-        $this->template_args['datetime'] = empty($attributes['event_id'])
182
-            ? $this->getDatetime($attributes)
183
-            : null;
184
-        $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id'])
185
-            ? $this->getTicket($attributes)
186
-            : null;
187
-    }
163
+	/**
164
+	 * Set all the base template arguments from the incoming attributes.
165
+	 * * Note: because of the relationship between event_id, ticket_id, and datetime_id:
166
+	 * If more than one of those params is included, then preference is given to the following:
167
+	 *  - event_id is used whenever its present and any others are ignored.
168
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
169
+	 *  - otherwise ticket_id is used if present.
170
+	 *
171
+	 * @param array $attributes
172
+	 * @throws EE_Error
173
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
174
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
175
+	 * @throws \InvalidArgumentException
176
+	 */
177
+	private function setBaseTemplateArguments(array $attributes)
178
+	{
179
+		$this->template_args['show_gravatar'] = $attributes['show_gravatar'];
180
+		$this->template_args['event'] = $this->getEvent($attributes);
181
+		$this->template_args['datetime'] = empty($attributes['event_id'])
182
+			? $this->getDatetime($attributes)
183
+			: null;
184
+		$this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id'])
185
+			? $this->getTicket($attributes)
186
+			: null;
187
+	}
188 188
 
189 189
 
190
-    /**
191
-     * Validates the presence of entities for the given attribute values.
192
-     *
193
-     * @param array $attributes
194
-     * @throws EntityNotFoundException
195
-     */
196
-    private function validateEntities(array $attributes)
197
-    {
198
-        if (! $this->template_args['event'] instanceof EE_Event
199
-            || (
200
-                empty($attributes['event_id'])
201
-                && $attributes['datetime_id']
202
-                && ! $this->template_args['datetime'] instanceof EE_Datetime
203
-            )
204
-            || (
205
-                empty($attributes['event_id'])
206
-                && empty($attributes['datetime_id'])
207
-                && $attributes['ticket_id']
208
-                && ! $this->template_args['ticket'] instanceof EE_Ticket
209
-            )
210
-        ) {
211
-            throw new EntityNotFoundException(
212
-                '',
213
-                '',
214
-                esc_html__(
215
-                    'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
216
-                    'event_espresso'
217
-                )
218
-            );
219
-        }
220
-    }
190
+	/**
191
+	 * Validates the presence of entities for the given attribute values.
192
+	 *
193
+	 * @param array $attributes
194
+	 * @throws EntityNotFoundException
195
+	 */
196
+	private function validateEntities(array $attributes)
197
+	{
198
+		if (! $this->template_args['event'] instanceof EE_Event
199
+			|| (
200
+				empty($attributes['event_id'])
201
+				&& $attributes['datetime_id']
202
+				&& ! $this->template_args['datetime'] instanceof EE_Datetime
203
+			)
204
+			|| (
205
+				empty($attributes['event_id'])
206
+				&& empty($attributes['datetime_id'])
207
+				&& $attributes['ticket_id']
208
+				&& ! $this->template_args['ticket'] instanceof EE_Ticket
209
+			)
210
+		) {
211
+			throw new EntityNotFoundException(
212
+				'',
213
+				'',
214
+				esc_html__(
215
+					'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
216
+					'event_espresso'
217
+				)
218
+			);
219
+		}
220
+	}
221 221
 
222 222
 
223
-    /**
224
-     * Sets the query params for the base query elements.
225
-     */
226
-    private function setBaseQueryParams()
227
-    {
228
-        switch (true) {
229
-            case $this->template_args['datetime'] instanceof EE_Datetime:
230
-                $this->query_params = array(
231
-                    0                          => array(
232
-                        'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID(),
233
-                    ),
234
-                    'default_where_conditions' => 'this_model_only',
235
-                );
236
-                break;
237
-            case $this->template_args['ticket'] instanceof EE_Ticket:
238
-                $this->query_params[0] = array(
239
-                    'Registration.TKT_ID' => $this->template_args['ticket']->ID(),
240
-                );
241
-                break;
242
-            case $this->template_args['event'] instanceof EE_Event:
243
-                $this->query_params[0] = array(
244
-                    'Registration.EVT_ID' => $this->template_args['event']->ID(),
245
-                );
246
-                break;
247
-        }
248
-    }
223
+	/**
224
+	 * Sets the query params for the base query elements.
225
+	 */
226
+	private function setBaseQueryParams()
227
+	{
228
+		switch (true) {
229
+			case $this->template_args['datetime'] instanceof EE_Datetime:
230
+				$this->query_params = array(
231
+					0                          => array(
232
+						'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID(),
233
+					),
234
+					'default_where_conditions' => 'this_model_only',
235
+				);
236
+				break;
237
+			case $this->template_args['ticket'] instanceof EE_Ticket:
238
+				$this->query_params[0] = array(
239
+					'Registration.TKT_ID' => $this->template_args['ticket']->ID(),
240
+				);
241
+				break;
242
+			case $this->template_args['event'] instanceof EE_Event:
243
+				$this->query_params[0] = array(
244
+					'Registration.EVT_ID' => $this->template_args['event']->ID(),
245
+				);
246
+				break;
247
+		}
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * @param array $attributes
253
-     * @return EE_Event|null
254
-     * @throws EE_Error
255
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
-     * @throws \InvalidArgumentException
258
-     */
259
-    private function getEvent(array $attributes)
260
-    {
261
-        switch (true) {
262
-            case ! empty($attributes['event_id']):
263
-                $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
264
-                break;
265
-            case ! empty($attributes['datetime_id']):
266
-                $event = EEM_Event::instance()->get_one(array(
267
-                    array(
268
-                        'Datetime.DTT_ID' => $attributes['datetime_id'],
269
-                    ),
270
-                ));
271
-                break;
272
-            case ! empty($attributes['ticket_id']):
273
-                $event = EEM_Event::instance()->get_one(array(
274
-                    array(
275
-                        'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'],
276
-                    ),
277
-                    'default_where_conditions' => 'none'
278
-                ));
279
-                break;
280
-            case is_espresso_event():
281
-                $event = EEH_Event_View::get_event();
282
-                break;
283
-            default:
284
-                // one last shot...
285
-                // try getting the earliest active event
286
-                $events = EEM_Event::instance()->get_active_events(array(
287
-                    'limit'    => 1,
288
-                    'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
289
-                ));
290
-                //  if none then get the next upcoming
291
-                $events = empty($events)
292
-                    ? EEM_Event::instance()->get_upcoming_events(array(
293
-                        'limit'    => 1,
294
-                        'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
295
-                    ))
296
-                    : $events;
297
-                $event = reset($events);
298
-        }
251
+	/**
252
+	 * @param array $attributes
253
+	 * @return EE_Event|null
254
+	 * @throws EE_Error
255
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
+	 * @throws \InvalidArgumentException
258
+	 */
259
+	private function getEvent(array $attributes)
260
+	{
261
+		switch (true) {
262
+			case ! empty($attributes['event_id']):
263
+				$event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
264
+				break;
265
+			case ! empty($attributes['datetime_id']):
266
+				$event = EEM_Event::instance()->get_one(array(
267
+					array(
268
+						'Datetime.DTT_ID' => $attributes['datetime_id'],
269
+					),
270
+				));
271
+				break;
272
+			case ! empty($attributes['ticket_id']):
273
+				$event = EEM_Event::instance()->get_one(array(
274
+					array(
275
+						'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'],
276
+					),
277
+					'default_where_conditions' => 'none'
278
+				));
279
+				break;
280
+			case is_espresso_event():
281
+				$event = EEH_Event_View::get_event();
282
+				break;
283
+			default:
284
+				// one last shot...
285
+				// try getting the earliest active event
286
+				$events = EEM_Event::instance()->get_active_events(array(
287
+					'limit'    => 1,
288
+					'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
289
+				));
290
+				//  if none then get the next upcoming
291
+				$events = empty($events)
292
+					? EEM_Event::instance()->get_upcoming_events(array(
293
+						'limit'    => 1,
294
+						'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
295
+					))
296
+					: $events;
297
+				$event = reset($events);
298
+		}
299 299
 
300
-        return $event instanceof EE_Event ? $event : null;
301
-    }
300
+		return $event instanceof EE_Event ? $event : null;
301
+	}
302 302
 
303 303
 
304
-    /**
305
-     * @param array $attributes
306
-     * @return EE_Datetime|null
307
-     * @throws EE_Error
308
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
309
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
310
-     * @throws \InvalidArgumentException
311
-     */
312
-    private function getDatetime(array $attributes)
313
-    {
314
-        if (! empty($attributes['datetime_id'])) {
315
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
316
-            if ($datetime instanceof EE_Datetime) {
317
-                return $datetime;
318
-            }
319
-        }
320
-        return null;
321
-    }
304
+	/**
305
+	 * @param array $attributes
306
+	 * @return EE_Datetime|null
307
+	 * @throws EE_Error
308
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
309
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
310
+	 * @throws \InvalidArgumentException
311
+	 */
312
+	private function getDatetime(array $attributes)
313
+	{
314
+		if (! empty($attributes['datetime_id'])) {
315
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
316
+			if ($datetime instanceof EE_Datetime) {
317
+				return $datetime;
318
+			}
319
+		}
320
+		return null;
321
+	}
322 322
 
323 323
 
324
-    /**
325
-     * @param array $attributes
326
-     * @return \EE_Base_Class|EE_Ticket|null
327
-     * @throws EE_Error
328
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
329
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
330
-     * @throws \InvalidArgumentException
331
-     */
332
-    private function getTicket(array $attributes)
333
-    {
334
-        if (! empty($attributes['ticket_id'])) {
335
-            $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
336
-            if ($ticket instanceof EE_Ticket) {
337
-                return $ticket;
338
-            }
339
-        }
340
-        return null;
341
-    }
324
+	/**
325
+	 * @param array $attributes
326
+	 * @return \EE_Base_Class|EE_Ticket|null
327
+	 * @throws EE_Error
328
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
329
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
330
+	 * @throws \InvalidArgumentException
331
+	 */
332
+	private function getTicket(array $attributes)
333
+	{
334
+		if (! empty($attributes['ticket_id'])) {
335
+			$ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
336
+			if ($ticket instanceof EE_Ticket) {
337
+				return $ticket;
338
+			}
339
+		}
340
+		return null;
341
+	}
342 342
 
343 343
 
344
-    /**
345
-     * @param array $attributes
346
-     * @throws EE_Error
347
-     */
348
-    private function setAdditionalQueryParams(array $attributes)
349
-    {
350
-        $reg_status_array = EEM_Registration::reg_status_array();
351
-        if ($attributes['status'] !== 'all' && isset($reg_status_array[ $attributes['status'] ])) {
352
-            $this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
353
-        }
354
-        $this->query_params['group_by'] = array('ATT_ID');
355
-        $this->query_params['order_by'] = (array) apply_filters(
356
-            'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
357
-            array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
358
-        );
359
-    }
344
+	/**
345
+	 * @param array $attributes
346
+	 * @throws EE_Error
347
+	 */
348
+	private function setAdditionalQueryParams(array $attributes)
349
+	{
350
+		$reg_status_array = EEM_Registration::reg_status_array();
351
+		if ($attributes['status'] !== 'all' && isset($reg_status_array[ $attributes['status'] ])) {
352
+			$this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
353
+		}
354
+		$this->query_params['group_by'] = array('ATT_ID');
355
+		$this->query_params['order_by'] = (array) apply_filters(
356
+			'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
357
+			array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
358
+		);
359
+	}
360 360
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    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
-                    ); ?>
52
+					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
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
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.4.0');
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
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.000');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.000');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.