Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
136:24 queued 121:17
created

EspressoTxnPage::initializeShortcode()   D

Complexity

Conditions 9
Paths 26

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 21
c 0
b 0
f 0
nc 26
nop 0
dl 0
loc 34
rs 4.909
1
<?php
2
namespace EventEspresso\core\domain\entities\shortcodes;
3
4
use EE_Offsite_Gateway;
5
use EE_Payment_Method;
6
use EE_Payment_Processor;
7
use EE_Registry;
8
use EE_Transaction;
9
use EEM_Payment_Method;
10
use EEM_Transaction;
11
use EventEspresso\core\services\shortcodes\EspressoShortcode;
12
13
defined('EVENT_ESPRESSO_VERSION') || exit;
14
15
16
17
/**
18
 * Class EspressoTxnPage
19
 * ESPRESSO_TXN_PAGE shortcode
20
 *
21
 * @package       Event Espresso
22
 * @author        Brent Christensen
23
 * @since         $VID:$
24
 */
25
class EspressoTxnPage extends EspressoShortcode
26
{
27
28
29
30
    /**
31
     * the actual shortcode tag that gets registered with WordPress
32
     *
33
     * @return string
34
     */
35
    public function getTag()
36
    {
37
        return 'ESPRESSO_TXN_PAGE';
38
    }
39
40
41
42
    /**
43
     * the time in seconds to cache the results of the processShortcode() method
44
     * 0 means the processShortcode() results will NOT be cached at all
45
     *
46
     * @return int
47
     */
48
    public function cacheExpiration()
49
    {
50
        return 0;
51
    }
52
53
54
    /**
55
     * a place for adding any initialization code that needs to run prior to wp_header().
56
     * this may be required for shortcodes that utilize a corresponding module,
57
     * and need to enqueue assets for that module
58
     *
59
     * @return void
60
     * @throws \Exception
61
     * @throws \EE_Error
62
     */
63
    public function initializeShortcode()
64
    {
65
        $transaction = null;
66
        if (EE_Registry::instance()->REQ->is_set('e_reg_url_link')) {
67
            /** @var EEM_Transaction $EEM_Transaction */
68
            $EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
69
            $transaction = $EEM_Transaction->get_transaction_from_reg_url_link();
70
        }
71
        if ($transaction instanceof EE_Transaction) {
72
            $payment_method = null;
73
            $payment_method_slug = EE_Registry::instance()->REQ->get('ee_payment_method', null);
74
            if ($payment_method_slug) {
75
                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($payment_method_slug);
76
            }
77
            if ($payment_method instanceof EE_Payment_Method && $payment_method->is_off_site()) {
78
                $gateway = $payment_method->type_obj()->get_gateway();
79
                if (
80
                    $gateway instanceof EE_Offsite_Gateway
81
                    && $gateway->handle_IPN_in_this_request(
82
                        \EE_Registry::instance()->REQ->params(),
83
                        true
84
                    )
85
                ) {
86
                    /** @type EE_Payment_Processor $payment_processor */
87
                    $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
88
                    $payment_processor->process_ipn($_REQUEST, $transaction, $payment_method);
89
                }
90
            }
91
            //allow gateways to add a filter to stop rendering the page
92
            if (apply_filters('FHEE__EES_Espresso_Txn_Page__run__exit', false)) {
93
                exit;
94
            }
95
        }
96
    }
97
98
99
100
    /**
101
     * callback that runs when the shortcode is encountered in post content.
102
     * IMPORTANT !!!
103
     * remember that shortcode content should be RETURNED and NOT echoed out
104
     *
105
     * @param array $attributes
106
     * @return string
107
     */
108
    public function processShortcode($attributes = array())
109
    {
110
        return esc_html__(
111
            'This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.',
112
            'event_espresso'
113
        );
114
    }
115
}
116
// End of file EspressoTxnPage.php
117
// Location: EventEspresso\core\domain\entities\shortcodes/EspressoTxnPage.php