@@ -38,103 +38,103 @@ |
||
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.76.rc.002'); |
|
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.76.rc.002'); |
|
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 | } |
@@ -17,50 +17,50 @@ |
||
17 | 17 | class WordpressHeartbeat |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var LoaderInterface $loader |
|
22 | - */ |
|
23 | - protected $loader; |
|
20 | + /** |
|
21 | + * @var LoaderInterface $loader |
|
22 | + */ |
|
23 | + protected $loader; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var RequestInterface $request |
|
27 | - */ |
|
28 | - protected $request; |
|
25 | + /** |
|
26 | + * @var RequestInterface $request |
|
27 | + */ |
|
28 | + protected $request; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * WordpressHeartbeat constructor. |
|
33 | - * |
|
34 | - * @param LoaderInterface $loader |
|
35 | - * @param RequestInterface $request |
|
36 | - */ |
|
37 | - public function __construct( |
|
38 | - LoaderInterface $loader, |
|
39 | - RequestInterface $request |
|
40 | - ) { |
|
41 | - $this->loader = $loader; |
|
42 | - $this->request = $request; |
|
43 | - do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this); |
|
44 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes')); |
|
45 | - } |
|
31 | + /** |
|
32 | + * WordpressHeartbeat constructor. |
|
33 | + * |
|
34 | + * @param LoaderInterface $loader |
|
35 | + * @param RequestInterface $request |
|
36 | + */ |
|
37 | + public function __construct( |
|
38 | + LoaderInterface $loader, |
|
39 | + RequestInterface $request |
|
40 | + ) { |
|
41 | + $this->loader = $loader; |
|
42 | + $this->request = $request; |
|
43 | + do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this); |
|
44 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes')); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * @since $VID:$ |
|
50 | - * @throws InvalidClassException |
|
51 | - */ |
|
52 | - public function resolveRoutes() |
|
53 | - { |
|
54 | - $screenID = $this->request->getRequestParam('screen_id'); |
|
55 | - $heartbeat_data = $this->request->getRequestParam('data', []); |
|
56 | - if ($screenID === 'espresso_events') { |
|
57 | - $this->loader->getShared( |
|
58 | - 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' |
|
59 | - ); |
|
60 | - } elseif ($screenID === 'front' && ! empty($heartbeat_data['espresso_thank_you_page'])) { |
|
61 | - $this->loader->getShared( |
|
62 | - 'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor' |
|
63 | - ); |
|
64 | - } |
|
65 | - } |
|
48 | + /** |
|
49 | + * @since $VID:$ |
|
50 | + * @throws InvalidClassException |
|
51 | + */ |
|
52 | + public function resolveRoutes() |
|
53 | + { |
|
54 | + $screenID = $this->request->getRequestParam('screen_id'); |
|
55 | + $heartbeat_data = $this->request->getRequestParam('data', []); |
|
56 | + if ($screenID === 'espresso_events') { |
|
57 | + $this->loader->getShared( |
|
58 | + 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' |
|
59 | + ); |
|
60 | + } elseif ($screenID === 'front' && ! empty($heartbeat_data['espresso_thank_you_page'])) { |
|
61 | + $this->loader->getShared( |
|
62 | + 'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor' |
|
63 | + ); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | } |
@@ -16,52 +16,52 @@ |
||
16 | 16 | class EventEditorHeartbeat |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var Domain $domain |
|
21 | - */ |
|
22 | - protected $domain; |
|
19 | + /** |
|
20 | + * @var Domain $domain |
|
21 | + */ |
|
22 | + protected $domain; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var EE_Environment_Config $environment |
|
26 | - */ |
|
27 | - protected $environment; |
|
24 | + /** |
|
25 | + * @var EE_Environment_Config $environment |
|
26 | + */ |
|
27 | + protected $environment; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * EventEditorHeartbeat constructor. |
|
32 | - * |
|
33 | - * @param Domain $domain |
|
34 | - * @param EE_Environment_Config $environment |
|
35 | - */ |
|
36 | - public function __construct(Domain $domain, EE_Environment_Config $environment) |
|
37 | - { |
|
38 | - $this->domain = $domain; |
|
39 | - $this->environment = $environment; |
|
40 | - if ($this->domain->isCaffeinated()) { |
|
41 | - add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2); |
|
42 | - } |
|
43 | - } |
|
30 | + /** |
|
31 | + * EventEditorHeartbeat constructor. |
|
32 | + * |
|
33 | + * @param Domain $domain |
|
34 | + * @param EE_Environment_Config $environment |
|
35 | + */ |
|
36 | + public function __construct(Domain $domain, EE_Environment_Config $environment) |
|
37 | + { |
|
38 | + $this->domain = $domain; |
|
39 | + $this->environment = $environment; |
|
40 | + if ($this->domain->isCaffeinated()) { |
|
41 | + add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
48 | - * accordingly. |
|
49 | - * |
|
50 | - * @param array $response The existing heartbeat response array. |
|
51 | - * @param array $data The incoming data package. |
|
52 | - * @return array possibly appended response. |
|
53 | - */ |
|
54 | - public function heartbeatResponse($response, $data) |
|
55 | - { |
|
56 | - /** |
|
57 | - * check whether count of tickets is approaching the potential |
|
58 | - * limits for the server. |
|
59 | - */ |
|
60 | - if (! empty($data['input_count'])) { |
|
61 | - $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check( |
|
62 | - $data['input_count'] |
|
63 | - ); |
|
64 | - } |
|
65 | - return $response; |
|
66 | - } |
|
46 | + /** |
|
47 | + * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
48 | + * accordingly. |
|
49 | + * |
|
50 | + * @param array $response The existing heartbeat response array. |
|
51 | + * @param array $data The incoming data package. |
|
52 | + * @return array possibly appended response. |
|
53 | + */ |
|
54 | + public function heartbeatResponse($response, $data) |
|
55 | + { |
|
56 | + /** |
|
57 | + * check whether count of tickets is approaching the potential |
|
58 | + * limits for the server. |
|
59 | + */ |
|
60 | + if (! empty($data['input_count'])) { |
|
61 | + $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check( |
|
62 | + $data['input_count'] |
|
63 | + ); |
|
64 | + } |
|
65 | + return $response; |
|
66 | + } |
|
67 | 67 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | * check whether count of tickets is approaching the potential |
58 | 58 | * limits for the server. |
59 | 59 | */ |
60 | - if (! empty($data['input_count'])) { |
|
60 | + if ( ! empty($data['input_count'])) { |
|
61 | 61 | $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check( |
62 | 62 | $data['input_count'] |
63 | 63 | ); |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | public function heartbeatResponse($response = array(), $data = array()) |
60 | 60 | { |
61 | 61 | // does this heartbeat contain our data ? |
62 | - if (! isset($data['espresso_thank_you_page'])) { |
|
62 | + if ( ! isset($data['espresso_thank_you_page'])) { |
|
63 | 63 | return $response; |
64 | 64 | } |
65 | 65 | // check for reg_url_link in the incoming heartbeat data |
66 | - if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) { |
|
66 | + if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) { |
|
67 | 67 | $response['espresso_thank_you_page'] = array( |
68 | 68 | 'errors' => ! empty($notices['errors']) |
69 | 69 | ? $notices['errors'] |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | private function initializeThankYouPageAndTransaction($response, $data) |
111 | 111 | { |
112 | - require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
112 | + require_once EE_MODULES.'thank_you_page/EED_Thank_You_Page.module.php'; |
|
113 | 113 | // set_definitions, instantiate the thank you page class, and get the ball rolling |
114 | 114 | EED_Thank_You_Page::set_definitions(); |
115 | 115 | $this->thank_you_page = EED_Thank_You_Page::instance(); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | // get TXN |
120 | 120 | $transaction = $this->thank_you_page->get_txn(); |
121 | 121 | // no TXN? then get out |
122 | - if (! $transaction instanceof EE_Transaction) { |
|
122 | + if ( ! $transaction instanceof EE_Transaction) { |
|
123 | 123 | $notices = EE_Error::get_notices(); |
124 | 124 | $response['espresso_thank_you_page'] = array( |
125 | 125 | 'errors' => ! empty($notices['errors']) |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | // then check for payments |
187 | 187 | $payments = $this->thank_you_page->get_txn_payments($since); |
188 | 188 | // has a payment been processed ? |
189 | - if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
189 | + if ( ! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
190 | 190 | if ($since) { |
191 | 191 | $response['espresso_thank_you_page'] = array( |
192 | 192 | 'new_payments' => $this->thank_you_page->get_new_payments($payments), |
@@ -21,206 +21,206 @@ |
||
21 | 21 | class ThankYouPageIpnMonitor |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var EED_Thank_You_Page $thank_you_page |
|
26 | - */ |
|
27 | - private $thank_you_page; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_Transaction $transaction |
|
31 | - */ |
|
32 | - private $transaction; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * EventEditorHeartbeat constructor. |
|
37 | - */ |
|
38 | - public function __construct() |
|
39 | - { |
|
40 | - add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3); |
|
41 | - add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * thank_you_page_IPN_monitor |
|
47 | - * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
48 | - * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
49 | - * it also calculates the IPN wait time since the Thank You page was first loaded |
|
50 | - * |
|
51 | - * @param array $response |
|
52 | - * @param array $data |
|
53 | - * @return array |
|
54 | - * @throws EE_Error |
|
55 | - * @throws InvalidDataTypeException |
|
56 | - * @throws InvalidInterfaceException |
|
57 | - * @throws InvalidArgumentException |
|
58 | - */ |
|
59 | - public function heartbeatResponse($response = array(), $data = array()) |
|
60 | - { |
|
61 | - // does this heartbeat contain our data ? |
|
62 | - if (! isset($data['espresso_thank_you_page'])) { |
|
63 | - return $response; |
|
64 | - } |
|
65 | - // check for reg_url_link in the incoming heartbeat data |
|
66 | - if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) { |
|
67 | - $response['espresso_thank_you_page'] = array( |
|
68 | - 'errors' => ! empty($notices['errors']) |
|
69 | - ? $notices['errors'] |
|
70 | - : __( |
|
71 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
72 | - 'event_espresso' |
|
73 | - ), |
|
74 | - ); |
|
75 | - return $response; |
|
76 | - } |
|
77 | - // kk heartbeat has our data |
|
78 | - $response = $this->initializeThankYouPageAndTransaction($response, $data); |
|
79 | - // if something went wrong... |
|
80 | - if (isset($response['espresso_thank_you_page']['errors'])) { |
|
81 | - return $response; |
|
82 | - } |
|
83 | - // grab transient of Transaction's status |
|
84 | - $txn_status = isset($data['espresso_thank_you_page']['txn_status']) |
|
85 | - ? $data['espresso_thank_you_page']['txn_status'] |
|
86 | - : null; |
|
87 | - $response = $this->getTransactionDetails($txn_status, $response, $data); |
|
88 | - // no payment data yet? |
|
89 | - if (isset($response['espresso_thank_you_page']['still_waiting'])) { |
|
90 | - return $response; |
|
91 | - } |
|
92 | - // TXN is happening so let's get the payments now |
|
93 | - // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
94 | - $since = isset($data['espresso_thank_you_page']['get_payments_since']) |
|
95 | - ? $data['espresso_thank_you_page']['get_payments_since'] |
|
96 | - : 0; |
|
97 | - return $this->paymentDetails($since); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param array $response |
|
103 | - * @param array $data |
|
104 | - * @return array |
|
105 | - * @throws EE_Error |
|
106 | - * @throws InvalidArgumentException |
|
107 | - * @throws InvalidDataTypeException |
|
108 | - * @throws InvalidInterfaceException |
|
109 | - */ |
|
110 | - private function initializeThankYouPageAndTransaction($response, $data) |
|
111 | - { |
|
112 | - require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
113 | - // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
114 | - EED_Thank_You_Page::set_definitions(); |
|
115 | - $this->thank_you_page = EED_Thank_You_Page::instance(); |
|
116 | - $this->thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']); |
|
117 | - $this->thank_you_page->init(); |
|
118 | - $response['espresso_thank_you_page'] = array(); |
|
119 | - // get TXN |
|
120 | - $transaction = $this->thank_you_page->get_txn(); |
|
121 | - // no TXN? then get out |
|
122 | - if (! $transaction instanceof EE_Transaction) { |
|
123 | - $notices = EE_Error::get_notices(); |
|
124 | - $response['espresso_thank_you_page'] = array( |
|
125 | - 'errors' => ! empty($notices['errors']) |
|
126 | - ? $notices['errors'] |
|
127 | - : sprintf( |
|
128 | - __( |
|
129 | - 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
130 | - 'event_espresso' |
|
131 | - ), |
|
132 | - __LINE__ |
|
133 | - ), |
|
134 | - ); |
|
135 | - return $response; |
|
136 | - } |
|
137 | - $this->transaction = $transaction; |
|
138 | - return $response; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param string $txn_status |
|
144 | - * @param array $response |
|
145 | - * @param array $data |
|
146 | - * @return array |
|
147 | - * @throws EE_Error |
|
148 | - */ |
|
149 | - private function getTransactionDetails($txn_status, $response, $data) |
|
150 | - { |
|
151 | - // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
152 | - if ($txn_status !== $this->transaction->status_ID()) { |
|
153 | - // switch between two possible basic outcomes |
|
154 | - switch ($this->transaction->status_ID()) { |
|
155 | - // TXN has been updated in some way |
|
156 | - case EEM_Transaction::overpaid_status_code: |
|
157 | - case EEM_Transaction::complete_status_code: |
|
158 | - case EEM_Transaction::incomplete_status_code: |
|
159 | - // send updated TXN results back to client, |
|
160 | - $response['espresso_thank_you_page'] = array( |
|
161 | - 'transaction_details' => $this->thank_you_page->get_transaction_details(), |
|
162 | - 'txn_status' => $this->transaction->status_ID(), |
|
163 | - ); |
|
164 | - return $response; |
|
165 | - // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
166 | - case EEM_Transaction::failed_status_code: |
|
167 | - default: |
|
168 | - // keep on waiting... |
|
169 | - return $this->updateServerWaitTime($data['espresso_thank_you_page']); |
|
170 | - } |
|
171 | - // or is the TXN still failed (never been updated) ??? |
|
172 | - } elseif ($this->transaction->failed()) { |
|
173 | - // keep on waiting... |
|
174 | - return $this->updateServerWaitTime($data['espresso_thank_you_page']); |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @param int $since |
|
181 | - * @return array |
|
182 | - * @throws EE_Error |
|
183 | - */ |
|
184 | - private function paymentDetails($since) |
|
185 | - { |
|
186 | - // then check for payments |
|
187 | - $payments = $this->thank_you_page->get_txn_payments($since); |
|
188 | - // has a payment been processed ? |
|
189 | - if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
190 | - if ($since) { |
|
191 | - $response['espresso_thank_you_page'] = array( |
|
192 | - 'new_payments' => $this->thank_you_page->get_new_payments($payments), |
|
193 | - 'transaction_details' => $this->thank_you_page->get_transaction_details(), |
|
194 | - 'txn_status' => $this->transaction->status_ID(), |
|
195 | - ); |
|
196 | - } else { |
|
197 | - $response['espresso_thank_you_page']['payment_details'] = $this->thank_you_page->get_payment_details( |
|
198 | - $payments |
|
199 | - ); |
|
200 | - } |
|
201 | - // reset time to check for payments |
|
202 | - $response['espresso_thank_you_page']['get_payments_since'] = time(); |
|
203 | - } else { |
|
204 | - $response['espresso_thank_you_page']['get_payments_since'] = $since; |
|
205 | - } |
|
206 | - return $response; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @param array $thank_you_page_data thank you page portion of the incoming JSON array |
|
212 | - * from the WP heartbeat data |
|
213 | - * @return array |
|
214 | - * @throws EE_Error |
|
215 | - */ |
|
216 | - private function updateServerWaitTime($thank_you_page_data) |
|
217 | - { |
|
218 | - $response['espresso_thank_you_page'] = array( |
|
219 | - 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
220 | - ? time() - $thank_you_page_data['initial_access'] |
|
221 | - : 0, |
|
222 | - 'txn_status' => $this->transaction->status_ID(), |
|
223 | - ); |
|
224 | - return $response; |
|
225 | - } |
|
24 | + /** |
|
25 | + * @var EED_Thank_You_Page $thank_you_page |
|
26 | + */ |
|
27 | + private $thank_you_page; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_Transaction $transaction |
|
31 | + */ |
|
32 | + private $transaction; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * EventEditorHeartbeat constructor. |
|
37 | + */ |
|
38 | + public function __construct() |
|
39 | + { |
|
40 | + add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3); |
|
41 | + add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * thank_you_page_IPN_monitor |
|
47 | + * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
48 | + * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
49 | + * it also calculates the IPN wait time since the Thank You page was first loaded |
|
50 | + * |
|
51 | + * @param array $response |
|
52 | + * @param array $data |
|
53 | + * @return array |
|
54 | + * @throws EE_Error |
|
55 | + * @throws InvalidDataTypeException |
|
56 | + * @throws InvalidInterfaceException |
|
57 | + * @throws InvalidArgumentException |
|
58 | + */ |
|
59 | + public function heartbeatResponse($response = array(), $data = array()) |
|
60 | + { |
|
61 | + // does this heartbeat contain our data ? |
|
62 | + if (! isset($data['espresso_thank_you_page'])) { |
|
63 | + return $response; |
|
64 | + } |
|
65 | + // check for reg_url_link in the incoming heartbeat data |
|
66 | + if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) { |
|
67 | + $response['espresso_thank_you_page'] = array( |
|
68 | + 'errors' => ! empty($notices['errors']) |
|
69 | + ? $notices['errors'] |
|
70 | + : __( |
|
71 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
72 | + 'event_espresso' |
|
73 | + ), |
|
74 | + ); |
|
75 | + return $response; |
|
76 | + } |
|
77 | + // kk heartbeat has our data |
|
78 | + $response = $this->initializeThankYouPageAndTransaction($response, $data); |
|
79 | + // if something went wrong... |
|
80 | + if (isset($response['espresso_thank_you_page']['errors'])) { |
|
81 | + return $response; |
|
82 | + } |
|
83 | + // grab transient of Transaction's status |
|
84 | + $txn_status = isset($data['espresso_thank_you_page']['txn_status']) |
|
85 | + ? $data['espresso_thank_you_page']['txn_status'] |
|
86 | + : null; |
|
87 | + $response = $this->getTransactionDetails($txn_status, $response, $data); |
|
88 | + // no payment data yet? |
|
89 | + if (isset($response['espresso_thank_you_page']['still_waiting'])) { |
|
90 | + return $response; |
|
91 | + } |
|
92 | + // TXN is happening so let's get the payments now |
|
93 | + // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
94 | + $since = isset($data['espresso_thank_you_page']['get_payments_since']) |
|
95 | + ? $data['espresso_thank_you_page']['get_payments_since'] |
|
96 | + : 0; |
|
97 | + return $this->paymentDetails($since); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param array $response |
|
103 | + * @param array $data |
|
104 | + * @return array |
|
105 | + * @throws EE_Error |
|
106 | + * @throws InvalidArgumentException |
|
107 | + * @throws InvalidDataTypeException |
|
108 | + * @throws InvalidInterfaceException |
|
109 | + */ |
|
110 | + private function initializeThankYouPageAndTransaction($response, $data) |
|
111 | + { |
|
112 | + require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
113 | + // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
114 | + EED_Thank_You_Page::set_definitions(); |
|
115 | + $this->thank_you_page = EED_Thank_You_Page::instance(); |
|
116 | + $this->thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']); |
|
117 | + $this->thank_you_page->init(); |
|
118 | + $response['espresso_thank_you_page'] = array(); |
|
119 | + // get TXN |
|
120 | + $transaction = $this->thank_you_page->get_txn(); |
|
121 | + // no TXN? then get out |
|
122 | + if (! $transaction instanceof EE_Transaction) { |
|
123 | + $notices = EE_Error::get_notices(); |
|
124 | + $response['espresso_thank_you_page'] = array( |
|
125 | + 'errors' => ! empty($notices['errors']) |
|
126 | + ? $notices['errors'] |
|
127 | + : sprintf( |
|
128 | + __( |
|
129 | + 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
130 | + 'event_espresso' |
|
131 | + ), |
|
132 | + __LINE__ |
|
133 | + ), |
|
134 | + ); |
|
135 | + return $response; |
|
136 | + } |
|
137 | + $this->transaction = $transaction; |
|
138 | + return $response; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param string $txn_status |
|
144 | + * @param array $response |
|
145 | + * @param array $data |
|
146 | + * @return array |
|
147 | + * @throws EE_Error |
|
148 | + */ |
|
149 | + private function getTransactionDetails($txn_status, $response, $data) |
|
150 | + { |
|
151 | + // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
152 | + if ($txn_status !== $this->transaction->status_ID()) { |
|
153 | + // switch between two possible basic outcomes |
|
154 | + switch ($this->transaction->status_ID()) { |
|
155 | + // TXN has been updated in some way |
|
156 | + case EEM_Transaction::overpaid_status_code: |
|
157 | + case EEM_Transaction::complete_status_code: |
|
158 | + case EEM_Transaction::incomplete_status_code: |
|
159 | + // send updated TXN results back to client, |
|
160 | + $response['espresso_thank_you_page'] = array( |
|
161 | + 'transaction_details' => $this->thank_you_page->get_transaction_details(), |
|
162 | + 'txn_status' => $this->transaction->status_ID(), |
|
163 | + ); |
|
164 | + return $response; |
|
165 | + // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
166 | + case EEM_Transaction::failed_status_code: |
|
167 | + default: |
|
168 | + // keep on waiting... |
|
169 | + return $this->updateServerWaitTime($data['espresso_thank_you_page']); |
|
170 | + } |
|
171 | + // or is the TXN still failed (never been updated) ??? |
|
172 | + } elseif ($this->transaction->failed()) { |
|
173 | + // keep on waiting... |
|
174 | + return $this->updateServerWaitTime($data['espresso_thank_you_page']); |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @param int $since |
|
181 | + * @return array |
|
182 | + * @throws EE_Error |
|
183 | + */ |
|
184 | + private function paymentDetails($since) |
|
185 | + { |
|
186 | + // then check for payments |
|
187 | + $payments = $this->thank_you_page->get_txn_payments($since); |
|
188 | + // has a payment been processed ? |
|
189 | + if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
190 | + if ($since) { |
|
191 | + $response['espresso_thank_you_page'] = array( |
|
192 | + 'new_payments' => $this->thank_you_page->get_new_payments($payments), |
|
193 | + 'transaction_details' => $this->thank_you_page->get_transaction_details(), |
|
194 | + 'txn_status' => $this->transaction->status_ID(), |
|
195 | + ); |
|
196 | + } else { |
|
197 | + $response['espresso_thank_you_page']['payment_details'] = $this->thank_you_page->get_payment_details( |
|
198 | + $payments |
|
199 | + ); |
|
200 | + } |
|
201 | + // reset time to check for payments |
|
202 | + $response['espresso_thank_you_page']['get_payments_since'] = time(); |
|
203 | + } else { |
|
204 | + $response['espresso_thank_you_page']['get_payments_since'] = $since; |
|
205 | + } |
|
206 | + return $response; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @param array $thank_you_page_data thank you page portion of the incoming JSON array |
|
212 | + * from the WP heartbeat data |
|
213 | + * @return array |
|
214 | + * @throws EE_Error |
|
215 | + */ |
|
216 | + private function updateServerWaitTime($thank_you_page_data) |
|
217 | + { |
|
218 | + $response['espresso_thank_you_page'] = array( |
|
219 | + 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
220 | + ? time() - $thank_you_page_data['initial_access'] |
|
221 | + : 0, |
|
222 | + 'txn_status' => $this->transaction->status_ID(), |
|
223 | + ); |
|
224 | + return $response; |
|
225 | + } |
|
226 | 226 | } |