@@ -27,1313 +27,1313 @@ |
||
| 27 | 27 | final class EE_System implements ResettableInterface |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 32 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 33 | - */ |
|
| 34 | - const req_type_normal = 0; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Indicates this is a brand new installation of EE so we should install |
|
| 38 | - * tables and default data etc |
|
| 39 | - */ |
|
| 40 | - const req_type_new_activation = 1; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 44 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 45 | - * and that default data is setup too |
|
| 46 | - */ |
|
| 47 | - const req_type_reactivation = 2; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * indicates that EE has been upgraded since its previous request. |
|
| 51 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 52 | - */ |
|
| 53 | - const req_type_upgrade = 3; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 57 | - */ |
|
| 58 | - const req_type_downgrade = 4; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @deprecated since version 4.6.0.dev.006 |
|
| 62 | - * Now whenever a new_activation is detected the request type is still just |
|
| 63 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 64 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 65 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 66 | - * (Specifically, when the migration manager indicates migrations are finished |
|
| 67 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 68 | - */ |
|
| 69 | - const req_type_activation_but_not_installed = 5; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 73 | - */ |
|
| 74 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_System $_instance |
|
| 78 | - */ |
|
| 79 | - private static $_instance; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var EE_Registry $registry |
|
| 83 | - */ |
|
| 84 | - private $registry; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @var LoaderInterface $loader |
|
| 88 | - */ |
|
| 89 | - private $loader; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var EE_Capabilities $capabilities |
|
| 93 | - */ |
|
| 94 | - private $capabilities; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var RequestInterface $request |
|
| 98 | - */ |
|
| 99 | - private $request; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
| 103 | - */ |
|
| 104 | - private $maintenance_mode; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 108 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 109 | - * |
|
| 110 | - * @var int $_req_type |
|
| 111 | - */ |
|
| 112 | - private $_req_type; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
| 116 | - * |
|
| 117 | - * @var boolean $_major_version_change |
|
| 118 | - */ |
|
| 119 | - private $_major_version_change = false; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * A Context DTO dedicated solely to identifying the current request type. |
|
| 123 | - * |
|
| 124 | - * @var RequestTypeContextCheckerInterface $request_type |
|
| 125 | - */ |
|
| 126 | - private $request_type; |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @singleton method used to instantiate class object |
|
| 131 | - * @param EE_Registry|null $registry |
|
| 132 | - * @param LoaderInterface|null $loader |
|
| 133 | - * @param RequestInterface|null $request |
|
| 134 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
| 135 | - * @return EE_System |
|
| 136 | - */ |
|
| 137 | - public static function instance( |
|
| 138 | - EE_Registry $registry = null, |
|
| 139 | - LoaderInterface $loader = null, |
|
| 140 | - RequestInterface $request = null, |
|
| 141 | - EE_Maintenance_Mode $maintenance_mode = null |
|
| 142 | - ) { |
|
| 143 | - // check if class object is instantiated |
|
| 144 | - if (! self::$_instance instanceof EE_System) { |
|
| 145 | - self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
| 146 | - } |
|
| 147 | - return self::$_instance; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * resets the instance and returns it |
|
| 153 | - * |
|
| 154 | - * @return EE_System |
|
| 155 | - */ |
|
| 156 | - public static function reset() |
|
| 157 | - { |
|
| 158 | - self::$_instance->_req_type = null; |
|
| 159 | - // make sure none of the old hooks are left hanging around |
|
| 160 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 161 | - // we need to reset the migration manager in order for it to detect DMSs properly |
|
| 162 | - EE_Data_Migration_Manager::reset(); |
|
| 163 | - self::instance()->detect_activations_or_upgrades(); |
|
| 164 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 165 | - return self::instance(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * sets hooks for running rest of system |
|
| 171 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 172 | - * starting EE Addons from any other point may lead to problems |
|
| 173 | - * |
|
| 174 | - * @param EE_Registry $registry |
|
| 175 | - * @param LoaderInterface $loader |
|
| 176 | - * @param RequestInterface $request |
|
| 177 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
| 178 | - */ |
|
| 179 | - private function __construct( |
|
| 180 | - EE_Registry $registry, |
|
| 181 | - LoaderInterface $loader, |
|
| 182 | - RequestInterface $request, |
|
| 183 | - EE_Maintenance_Mode $maintenance_mode |
|
| 184 | - ) { |
|
| 185 | - $this->registry = $registry; |
|
| 186 | - $this->loader = $loader; |
|
| 187 | - $this->request = $request; |
|
| 188 | - $this->maintenance_mode = $maintenance_mode; |
|
| 189 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
| 190 | - add_action( |
|
| 191 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 192 | - array($this, 'loadCapabilities'), |
|
| 193 | - 5 |
|
| 194 | - ); |
|
| 195 | - add_action( |
|
| 196 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 197 | - array($this, 'loadCommandBus'), |
|
| 198 | - 7 |
|
| 199 | - ); |
|
| 200 | - add_action( |
|
| 201 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 202 | - array($this, 'loadPluginApi'), |
|
| 203 | - 9 |
|
| 204 | - ); |
|
| 205 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 206 | - add_action( |
|
| 207 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 208 | - array($this, 'load_espresso_addons') |
|
| 209 | - ); |
|
| 210 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
| 211 | - // because the newly-activated addon didn't get a chance to run at all |
|
| 212 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 213 | - // detect whether install or upgrade |
|
| 214 | - add_action( |
|
| 215 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 216 | - array($this, 'detect_activations_or_upgrades'), |
|
| 217 | - 3 |
|
| 218 | - ); |
|
| 219 | - // load EE_Config, EE_Textdomain, etc |
|
| 220 | - add_action( |
|
| 221 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 222 | - array($this, 'load_core_configuration'), |
|
| 223 | - 5 |
|
| 224 | - ); |
|
| 225 | - // load specifications for matching routes to current request |
|
| 226 | - add_action( |
|
| 227 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 228 | - array($this, 'loadRouteMatchSpecifications') |
|
| 229 | - ); |
|
| 230 | - // load EE_Config, EE_Textdomain, etc |
|
| 231 | - add_action( |
|
| 232 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 233 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
| 234 | - 7 |
|
| 235 | - ); |
|
| 236 | - // you wanna get going? I wanna get going... let's get going! |
|
| 237 | - add_action( |
|
| 238 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 239 | - array($this, 'brew_espresso'), |
|
| 240 | - 9 |
|
| 241 | - ); |
|
| 242 | - // other housekeeping |
|
| 243 | - // exclude EE critical pages from wp_list_pages |
|
| 244 | - add_filter( |
|
| 245 | - 'wp_list_pages_excludes', |
|
| 246 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
| 247 | - 10 |
|
| 248 | - ); |
|
| 249 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 250 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 251 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * load and setup EE_Capabilities |
|
| 257 | - * |
|
| 258 | - * @return void |
|
| 259 | - * @throws EE_Error |
|
| 260 | - */ |
|
| 261 | - public function loadCapabilities() |
|
| 262 | - { |
|
| 263 | - $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
| 264 | - add_action( |
|
| 265 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 266 | - function () { |
|
| 267 | - LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
| 268 | - } |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * create and cache the CommandBus, and also add middleware |
|
| 275 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
| 276 | - * which is why we need to load the CommandBus after Caps are set up |
|
| 277 | - * |
|
| 278 | - * @return void |
|
| 279 | - * @throws EE_Error |
|
| 280 | - */ |
|
| 281 | - public function loadCommandBus() |
|
| 282 | - { |
|
| 283 | - $this->loader->getShared( |
|
| 284 | - 'CommandBusInterface', |
|
| 285 | - array( |
|
| 286 | - null, |
|
| 287 | - apply_filters( |
|
| 288 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 289 | - array( |
|
| 290 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
| 291 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
| 292 | - ) |
|
| 293 | - ), |
|
| 294 | - ) |
|
| 295 | - ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * @return void |
|
| 301 | - * @throws EE_Error |
|
| 302 | - */ |
|
| 303 | - public function loadPluginApi() |
|
| 304 | - { |
|
| 305 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 306 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 307 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 308 | - $this->loader->getShared('EE_Request_Handler'); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @param string $addon_name |
|
| 314 | - * @param string $version_constant |
|
| 315 | - * @param string $min_version_required |
|
| 316 | - * @param string $load_callback |
|
| 317 | - * @param string $plugin_file_constant |
|
| 318 | - * @return void |
|
| 319 | - */ |
|
| 320 | - private function deactivateIncompatibleAddon( |
|
| 321 | - $addon_name, |
|
| 322 | - $version_constant, |
|
| 323 | - $min_version_required, |
|
| 324 | - $load_callback, |
|
| 325 | - $plugin_file_constant |
|
| 326 | - ) { |
|
| 327 | - if (! defined($version_constant)) { |
|
| 328 | - return; |
|
| 329 | - } |
|
| 330 | - $addon_version = constant($version_constant); |
|
| 331 | - if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
| 332 | - remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
| 333 | - if (! function_exists('deactivate_plugins')) { |
|
| 334 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 335 | - } |
|
| 336 | - deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
| 337 | - unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
| 338 | - EE_Error::add_error( |
|
| 339 | - sprintf( |
|
| 340 | - esc_html__( |
|
| 341 | - 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
| 342 | - 'event_espresso' |
|
| 343 | - ), |
|
| 344 | - $addon_name, |
|
| 345 | - $min_version_required |
|
| 346 | - ), |
|
| 347 | - __FILE__, |
|
| 348 | - __FUNCTION__ . "({$addon_name})", |
|
| 349 | - __LINE__ |
|
| 350 | - ); |
|
| 351 | - EE_Error::get_notices(false, true); |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * load_espresso_addons |
|
| 358 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 359 | - * this is hooked into both: |
|
| 360 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 361 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 362 | - * and the WP 'activate_plugin' hook point |
|
| 363 | - * |
|
| 364 | - * @access public |
|
| 365 | - * @return void |
|
| 366 | - */ |
|
| 367 | - public function load_espresso_addons() |
|
| 368 | - { |
|
| 369 | - $this->deactivateIncompatibleAddon( |
|
| 370 | - 'Wait Lists', |
|
| 371 | - 'EE_WAIT_LISTS_VERSION', |
|
| 372 | - '1.0.0.beta.074', |
|
| 373 | - 'load_espresso_wait_lists', |
|
| 374 | - 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
| 375 | - ); |
|
| 376 | - $this->deactivateIncompatibleAddon( |
|
| 377 | - 'Automated Upcoming Event Notifications', |
|
| 378 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
| 379 | - '1.0.0.beta.091', |
|
| 380 | - 'load_espresso_automated_upcoming_event_notification', |
|
| 381 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
| 382 | - ); |
|
| 383 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 384 | - // if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 385 | - // We want it for mobile apps. Just include the entire plugin |
|
| 386 | - // also, don't load the basic auth when a plugin is getting activated, because |
|
| 387 | - // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 388 | - // and causes a fatal error |
|
| 389 | - if (($this->request->isWordPressApi() || $this->request->isApi()) |
|
| 390 | - && $this->request->getRequestParam('activate') !== 'true' |
|
| 391 | - && ! function_exists('json_basic_auth_handler') |
|
| 392 | - && ! function_exists('json_basic_auth_error') |
|
| 393 | - && ! in_array( |
|
| 394 | - $this->request->getRequestParam('action'), |
|
| 395 | - array('activate', 'activate-selected'), |
|
| 396 | - true |
|
| 397 | - ) |
|
| 398 | - ) { |
|
| 399 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 400 | - } |
|
| 401 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * detect_activations_or_upgrades |
|
| 407 | - * Checks for activation or upgrade of core first; |
|
| 408 | - * then also checks if any registered addons have been activated or upgraded |
|
| 409 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 410 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 411 | - * |
|
| 412 | - * @access public |
|
| 413 | - * @return void |
|
| 414 | - */ |
|
| 415 | - public function detect_activations_or_upgrades() |
|
| 416 | - { |
|
| 417 | - // first off: let's make sure to handle core |
|
| 418 | - $this->detect_if_activation_or_upgrade(); |
|
| 419 | - foreach ($this->registry->addons as $addon) { |
|
| 420 | - if ($addon instanceof EE_Addon) { |
|
| 421 | - // detect teh request type for that addon |
|
| 422 | - $addon->detect_activation_or_upgrade(); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * detect_if_activation_or_upgrade |
|
| 430 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 431 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 432 | - * |
|
| 433 | - * @access public |
|
| 434 | - * @return void |
|
| 435 | - */ |
|
| 436 | - public function detect_if_activation_or_upgrade() |
|
| 437 | - { |
|
| 438 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 439 | - // check if db has been updated, or if its a brand-new installation |
|
| 440 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 441 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
| 442 | - // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 443 | - switch ($request_type) { |
|
| 444 | - case EE_System::req_type_new_activation: |
|
| 445 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 446 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 447 | - break; |
|
| 448 | - case EE_System::req_type_reactivation: |
|
| 449 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 450 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 451 | - break; |
|
| 452 | - case EE_System::req_type_upgrade: |
|
| 453 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 454 | - // migrations may be required now that we've upgraded |
|
| 455 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 456 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 457 | - break; |
|
| 458 | - case EE_System::req_type_downgrade: |
|
| 459 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 460 | - // its possible migrations are no longer required |
|
| 461 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 462 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 463 | - break; |
|
| 464 | - case EE_System::req_type_normal: |
|
| 465 | - default: |
|
| 466 | - break; |
|
| 467 | - } |
|
| 468 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Updates the list of installed versions and sets hooks for |
|
| 474 | - * initializing the database later during the request |
|
| 475 | - * |
|
| 476 | - * @param array $espresso_db_update |
|
| 477 | - */ |
|
| 478 | - private function _handle_core_version_change($espresso_db_update) |
|
| 479 | - { |
|
| 480 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
| 481 | - // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 482 | - add_action( |
|
| 483 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 484 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 485 | - ); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 491 | - * information about what versions of EE have been installed and activated, |
|
| 492 | - * NOT necessarily the state of the database |
|
| 493 | - * |
|
| 494 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 495 | - * If not supplied, fetches it from the options table |
|
| 496 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 497 | - */ |
|
| 498 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 499 | - { |
|
| 500 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 501 | - if (! $espresso_db_update) { |
|
| 502 | - $espresso_db_update = get_option('espresso_db_update'); |
|
| 503 | - } |
|
| 504 | - // check that option is an array |
|
| 505 | - if (! is_array($espresso_db_update)) { |
|
| 506 | - // if option is FALSE, then it never existed |
|
| 507 | - if ($espresso_db_update === false) { |
|
| 508 | - // make $espresso_db_update an array and save option with autoload OFF |
|
| 509 | - $espresso_db_update = array(); |
|
| 510 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 511 | - } else { |
|
| 512 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 513 | - $espresso_db_update = array($espresso_db_update => array()); |
|
| 514 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 515 | - } |
|
| 516 | - } else { |
|
| 517 | - $corrected_db_update = array(); |
|
| 518 | - // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 519 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 520 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 521 | - // the key is an int, and the value IS NOT an array |
|
| 522 | - // so it must be numerically-indexed, where values are versions installed... |
|
| 523 | - // fix it! |
|
| 524 | - $version_string = $should_be_array; |
|
| 525 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
| 526 | - } else { |
|
| 527 | - // ok it checks out |
|
| 528 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - $espresso_db_update = $corrected_db_update; |
|
| 532 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 533 | - } |
|
| 534 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 535 | - return $espresso_db_update; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 541 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 542 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 543 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 544 | - * so that it will be done when migrations are finished |
|
| 545 | - * |
|
| 546 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 547 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 548 | - * This is a resource-intensive job |
|
| 549 | - * so we prefer to only do it when necessary |
|
| 550 | - * @return void |
|
| 551 | - * @throws EE_Error |
|
| 552 | - */ |
|
| 553 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 554 | - { |
|
| 555 | - $request_type = $this->detect_req_type(); |
|
| 556 | - // only initialize system if we're not in maintenance mode. |
|
| 557 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 558 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 559 | - $rewrite_rules = $this->loader->getShared( |
|
| 560 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 561 | - ); |
|
| 562 | - $rewrite_rules->flush(); |
|
| 563 | - if ($verify_schema) { |
|
| 564 | - EEH_Activation::initialize_db_and_folders(); |
|
| 565 | - } |
|
| 566 | - EEH_Activation::initialize_db_content(); |
|
| 567 | - EEH_Activation::system_initialization(); |
|
| 568 | - if ($initialize_addons_too) { |
|
| 569 | - $this->initialize_addons(); |
|
| 570 | - } |
|
| 571 | - } else { |
|
| 572 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 573 | - } |
|
| 574 | - if ($request_type === EE_System::req_type_new_activation |
|
| 575 | - || $request_type === EE_System::req_type_reactivation |
|
| 576 | - || ( |
|
| 577 | - $request_type === EE_System::req_type_upgrade |
|
| 578 | - && $this->is_major_version_change() |
|
| 579 | - ) |
|
| 580 | - ) { |
|
| 581 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Initializes the db for all registered addons |
|
| 588 | - * |
|
| 589 | - * @throws EE_Error |
|
| 590 | - */ |
|
| 591 | - public function initialize_addons() |
|
| 592 | - { |
|
| 593 | - // foreach registered addon, make sure its db is up-to-date too |
|
| 594 | - foreach ($this->registry->addons as $addon) { |
|
| 595 | - if ($addon instanceof EE_Addon) { |
|
| 596 | - $addon->initialize_db_if_no_migrations_required(); |
|
| 597 | - } |
|
| 598 | - } |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 604 | - * |
|
| 605 | - * @param array $version_history |
|
| 606 | - * @param string $current_version_to_add version to be added to the version history |
|
| 607 | - * @return boolean success as to whether or not this option was changed |
|
| 608 | - */ |
|
| 609 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 610 | - { |
|
| 611 | - if (! $version_history) { |
|
| 612 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 613 | - } |
|
| 614 | - if ($current_version_to_add === null) { |
|
| 615 | - $current_version_to_add = espresso_version(); |
|
| 616 | - } |
|
| 617 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
| 618 | - // re-save |
|
| 619 | - return update_option('espresso_db_update', $version_history); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * Detects if the current version indicated in the has existed in the list of |
|
| 625 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 626 | - * |
|
| 627 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 628 | - * If not supplied, fetches it from the options table. |
|
| 629 | - * Also, caches its result so later parts of the code can also know whether |
|
| 630 | - * there's been an update or not. This way we can add the current version to |
|
| 631 | - * espresso_db_update, but still know if this is a new install or not |
|
| 632 | - * @return int one of the constants on EE_System::req_type_ |
|
| 633 | - */ |
|
| 634 | - public function detect_req_type($espresso_db_update = null) |
|
| 635 | - { |
|
| 636 | - if ($this->_req_type === null) { |
|
| 637 | - $espresso_db_update = ! empty($espresso_db_update) |
|
| 638 | - ? $espresso_db_update |
|
| 639 | - : $this->fix_espresso_db_upgrade_option(); |
|
| 640 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
| 641 | - $espresso_db_update, |
|
| 642 | - 'ee_espresso_activation', |
|
| 643 | - espresso_version() |
|
| 644 | - ); |
|
| 645 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 646 | - $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
| 647 | - } |
|
| 648 | - return $this->_req_type; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 654 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 655 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 656 | - * |
|
| 657 | - * @param $activation_history |
|
| 658 | - * @return bool |
|
| 659 | - */ |
|
| 660 | - private function _detect_major_version_change($activation_history) |
|
| 661 | - { |
|
| 662 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 663 | - $previous_version_parts = explode('.', $previous_version); |
|
| 664 | - $current_version_parts = explode('.', espresso_version()); |
|
| 665 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 666 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 667 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 668 | - ); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Returns true if either the major or minor version of EE changed during this request. |
|
| 674 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 675 | - * |
|
| 676 | - * @return bool |
|
| 677 | - */ |
|
| 678 | - public function is_major_version_change() |
|
| 679 | - { |
|
| 680 | - return $this->_major_version_change; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 686 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 687 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 688 | - * just activated to (for core that will always be espresso_version()) |
|
| 689 | - * |
|
| 690 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 691 | - * ee plugin. for core that's 'espresso_db_update' |
|
| 692 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 693 | - * indicate that this plugin was just activated |
|
| 694 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 695 | - * espresso_version()) |
|
| 696 | - * @return int one of the constants on EE_System::req_type_* |
|
| 697 | - */ |
|
| 698 | - public static function detect_req_type_given_activation_history( |
|
| 699 | - $activation_history_for_addon, |
|
| 700 | - $activation_indicator_option_name, |
|
| 701 | - $version_to_upgrade_to |
|
| 702 | - ) { |
|
| 703 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 704 | - if ($activation_history_for_addon) { |
|
| 705 | - // it exists, so this isn't a completely new install |
|
| 706 | - // check if this version already in that list of previously installed versions |
|
| 707 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
| 708 | - // it a version we haven't seen before |
|
| 709 | - if ($version_is_higher === 1) { |
|
| 710 | - $req_type = EE_System::req_type_upgrade; |
|
| 711 | - } else { |
|
| 712 | - $req_type = EE_System::req_type_downgrade; |
|
| 713 | - } |
|
| 714 | - delete_option($activation_indicator_option_name); |
|
| 715 | - } else { |
|
| 716 | - // its not an update. maybe a reactivation? |
|
| 717 | - if (get_option($activation_indicator_option_name, false)) { |
|
| 718 | - if ($version_is_higher === -1) { |
|
| 719 | - $req_type = EE_System::req_type_downgrade; |
|
| 720 | - } elseif ($version_is_higher === 0) { |
|
| 721 | - // we've seen this version before, but it's an activation. must be a reactivation |
|
| 722 | - $req_type = EE_System::req_type_reactivation; |
|
| 723 | - } else {// $version_is_higher === 1 |
|
| 724 | - $req_type = EE_System::req_type_upgrade; |
|
| 725 | - } |
|
| 726 | - delete_option($activation_indicator_option_name); |
|
| 727 | - } else { |
|
| 728 | - // we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 729 | - if ($version_is_higher === -1) { |
|
| 730 | - $req_type = EE_System::req_type_downgrade; |
|
| 731 | - } elseif ($version_is_higher === 0) { |
|
| 732 | - // we've seen this version before and it's not an activation. its normal request |
|
| 733 | - $req_type = EE_System::req_type_normal; |
|
| 734 | - } else {// $version_is_higher === 1 |
|
| 735 | - $req_type = EE_System::req_type_upgrade; |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } else { |
|
| 740 | - // brand new install |
|
| 741 | - $req_type = EE_System::req_type_new_activation; |
|
| 742 | - delete_option($activation_indicator_option_name); |
|
| 743 | - } |
|
| 744 | - return $req_type; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 750 | - * the $activation_history_for_addon |
|
| 751 | - * |
|
| 752 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 753 | - * sometimes containing 'unknown-date' |
|
| 754 | - * @param string $version_to_upgrade_to (current version) |
|
| 755 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 756 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 757 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 758 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 759 | - */ |
|
| 760 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 761 | - { |
|
| 762 | - // find the most recently-activated version |
|
| 763 | - $most_recently_active_version = |
|
| 764 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 765 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Gets the most recently active version listed in the activation history, |
|
| 771 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 772 | - * |
|
| 773 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 774 | - * sometimes containing 'unknown-date' |
|
| 775 | - * @return string |
|
| 776 | - */ |
|
| 777 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 778 | - { |
|
| 779 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 780 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
| 781 | - if (is_array($activation_history)) { |
|
| 782 | - foreach ($activation_history as $version => $times_activated) { |
|
| 783 | - // check there is a record of when this version was activated. Otherwise, |
|
| 784 | - // mark it as unknown |
|
| 785 | - if (! $times_activated) { |
|
| 786 | - $times_activated = array('unknown-date'); |
|
| 787 | - } |
|
| 788 | - if (is_string($times_activated)) { |
|
| 789 | - $times_activated = array($times_activated); |
|
| 790 | - } |
|
| 791 | - foreach ($times_activated as $an_activation) { |
|
| 792 | - if ($an_activation !== 'unknown-date' |
|
| 793 | - && $an_activation |
|
| 794 | - > $most_recently_active_version_activation) { |
|
| 795 | - $most_recently_active_version = $version; |
|
| 796 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
| 797 | - ? '1970-01-01 00:00:00' |
|
| 798 | - : $an_activation; |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - return $most_recently_active_version; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * This redirects to the about EE page after activation |
|
| 809 | - * |
|
| 810 | - * @return void |
|
| 811 | - */ |
|
| 812 | - public function redirect_to_about_ee() |
|
| 813 | - { |
|
| 814 | - $notices = EE_Error::get_notices(false); |
|
| 815 | - // if current user is an admin and it's not an ajax or rest request |
|
| 816 | - if (! isset($notices['errors']) |
|
| 817 | - && $this->request->isAdmin() |
|
| 818 | - && apply_filters( |
|
| 819 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 820 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
| 821 | - ) |
|
| 822 | - ) { |
|
| 823 | - $query_params = array('page' => 'espresso_about'); |
|
| 824 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 825 | - $query_params['new_activation'] = true; |
|
| 826 | - } |
|
| 827 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 828 | - $query_params['reactivation'] = true; |
|
| 829 | - } |
|
| 830 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 831 | - wp_safe_redirect($url); |
|
| 832 | - exit(); |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * load_core_configuration |
|
| 839 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 840 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 841 | - * |
|
| 842 | - * @return void |
|
| 843 | - * @throws ReflectionException |
|
| 844 | - * @throws Exception |
|
| 845 | - */ |
|
| 846 | - public function load_core_configuration() |
|
| 847 | - { |
|
| 848 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 849 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
| 850 | - // load textdomain |
|
| 851 | - EE_Load_Textdomain::load_textdomain(); |
|
| 852 | - // load and setup EE_Config and EE_Network_Config |
|
| 853 | - $config = $this->loader->getShared('EE_Config'); |
|
| 854 | - $this->loader->getShared('EE_Network_Config'); |
|
| 855 | - // setup autoloaders |
|
| 856 | - // enable logging? |
|
| 857 | - if ($config->admin->use_full_logging) { |
|
| 858 | - $this->loader->getShared('EE_Log'); |
|
| 859 | - } |
|
| 860 | - // check for activation errors |
|
| 861 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 862 | - if ($activation_errors) { |
|
| 863 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 864 | - update_option('ee_plugin_activation_errors', false); |
|
| 865 | - } |
|
| 866 | - // get model names |
|
| 867 | - $this->_parse_model_names(); |
|
| 868 | - // load caf stuff a chance to play during the activation process too. |
|
| 869 | - $this->_maybe_brew_regular(); |
|
| 870 | - // configure custom post type definitions |
|
| 871 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
| 872 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
| 873 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 879 | - * |
|
| 880 | - * @return void |
|
| 881 | - * @throws ReflectionException |
|
| 882 | - */ |
|
| 883 | - private function _parse_model_names() |
|
| 884 | - { |
|
| 885 | - // get all the files in the EE_MODELS folder that end in .model.php |
|
| 886 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 887 | - $model_names = array(); |
|
| 888 | - $non_abstract_db_models = array(); |
|
| 889 | - foreach ($models as $model) { |
|
| 890 | - // get model classname |
|
| 891 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 892 | - $short_name = str_replace('EEM_', '', $classname); |
|
| 893 | - $reflectionClass = new ReflectionClass($classname); |
|
| 894 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 895 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
| 896 | - } |
|
| 897 | - $model_names[ $short_name ] = $classname; |
|
| 898 | - } |
|
| 899 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 900 | - $this->registry->non_abstract_db_models = apply_filters( |
|
| 901 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
| 902 | - $non_abstract_db_models |
|
| 903 | - ); |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 909 | - * that need to be setup before our EE_System launches. |
|
| 910 | - * |
|
| 911 | - * @return void |
|
| 912 | - * @throws DomainException |
|
| 913 | - * @throws InvalidArgumentException |
|
| 914 | - * @throws InvalidDataTypeException |
|
| 915 | - * @throws InvalidInterfaceException |
|
| 916 | - * @throws InvalidClassException |
|
| 917 | - * @throws InvalidFilePathException |
|
| 918 | - */ |
|
| 919 | - private function _maybe_brew_regular() |
|
| 920 | - { |
|
| 921 | - /** @var Domain $domain */ |
|
| 922 | - $domain = DomainFactory::getShared( |
|
| 923 | - new FullyQualifiedName( |
|
| 924 | - 'EventEspresso\core\domain\Domain' |
|
| 925 | - ), |
|
| 926 | - array( |
|
| 927 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
| 928 | - Version::fromString(espresso_version()), |
|
| 929 | - ) |
|
| 930 | - ); |
|
| 931 | - if ($domain->isCaffeinated()) { |
|
| 932 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - /** |
|
| 938 | - * @since 4.9.71.p |
|
| 939 | - * @throws Exception |
|
| 940 | - */ |
|
| 941 | - public function loadRouteMatchSpecifications() |
|
| 942 | - { |
|
| 943 | - try { |
|
| 944 | - $this->loader->getShared( |
|
| 945 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' |
|
| 946 | - ); |
|
| 947 | - } catch (Exception $exception) { |
|
| 948 | - new ExceptionStackTraceDisplay($exception); |
|
| 949 | - } |
|
| 950 | - do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * register_shortcodes_modules_and_widgets |
|
| 956 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
| 957 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 958 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 959 | - * |
|
| 960 | - * @access public |
|
| 961 | - * @return void |
|
| 962 | - * @throws Exception |
|
| 963 | - */ |
|
| 964 | - public function register_shortcodes_modules_and_widgets() |
|
| 965 | - { |
|
| 966 | - if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) { |
|
| 967 | - try { |
|
| 968 | - // load, register, and add shortcodes the new way |
|
| 969 | - $this->loader->getShared( |
|
| 970 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
| 971 | - array( |
|
| 972 | - // and the old way, but we'll put it under control of the new system |
|
| 973 | - EE_Config::getLegacyShortcodesManager(), |
|
| 974 | - ) |
|
| 975 | - ); |
|
| 976 | - } catch (Exception $exception) { |
|
| 977 | - new ExceptionStackTraceDisplay($exception); |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 981 | - // check for addons using old hook point |
|
| 982 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 983 | - $this->_incompatible_addon_error(); |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * _incompatible_addon_error |
|
| 990 | - * |
|
| 991 | - * @access public |
|
| 992 | - * @return void |
|
| 993 | - */ |
|
| 994 | - private function _incompatible_addon_error() |
|
| 995 | - { |
|
| 996 | - // get array of classes hooking into here |
|
| 997 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
| 998 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
| 999 | - ); |
|
| 1000 | - if (! empty($class_names)) { |
|
| 1001 | - $msg = __( |
|
| 1002 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 1003 | - 'event_espresso' |
|
| 1004 | - ); |
|
| 1005 | - $msg .= '<ul>'; |
|
| 1006 | - foreach ($class_names as $class_name) { |
|
| 1007 | - $msg .= '<li><b>Event Espresso - ' |
|
| 1008 | - . str_replace( |
|
| 1009 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
|
| 1010 | - '', |
|
| 1011 | - $class_name |
|
| 1012 | - ) . '</b></li>'; |
|
| 1013 | - } |
|
| 1014 | - $msg .= '</ul>'; |
|
| 1015 | - $msg .= __( |
|
| 1016 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 1017 | - 'event_espresso' |
|
| 1018 | - ); |
|
| 1019 | - // save list of incompatible addons to wp-options for later use |
|
| 1020 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 1021 | - if (is_admin()) { |
|
| 1022 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1023 | - } |
|
| 1024 | - } |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * brew_espresso |
|
| 1030 | - * begins the process of setting hooks for initializing EE in the correct order |
|
| 1031 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 1032 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 1033 | - * |
|
| 1034 | - * @return void |
|
| 1035 | - */ |
|
| 1036 | - public function brew_espresso() |
|
| 1037 | - { |
|
| 1038 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 1039 | - // load some final core systems |
|
| 1040 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 1041 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 1042 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 1043 | - add_action('init', array($this, 'load_controllers'), 7); |
|
| 1044 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 1045 | - add_action('init', array($this, 'initialize'), 10); |
|
| 1046 | - add_action('init', array($this, 'initialize_last'), 100); |
|
| 1047 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 1048 | - // pew pew pew |
|
| 1049 | - $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
| 1050 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 1051 | - } |
|
| 1052 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * set_hooks_for_core |
|
| 1058 | - * |
|
| 1059 | - * @access public |
|
| 1060 | - * @return void |
|
| 1061 | - * @throws EE_Error |
|
| 1062 | - */ |
|
| 1063 | - public function set_hooks_for_core() |
|
| 1064 | - { |
|
| 1065 | - $this->_deactivate_incompatible_addons(); |
|
| 1066 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 1067 | - $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
| 1068 | - // caps need to be initialized on every request so that capability maps are set. |
|
| 1069 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 1070 | - $this->registry->CAP->init_caps(); |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 1076 | - * deactivates any addons considered incompatible with the current version of EE |
|
| 1077 | - */ |
|
| 1078 | - private function _deactivate_incompatible_addons() |
|
| 1079 | - { |
|
| 1080 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 1081 | - if (! empty($incompatible_addons)) { |
|
| 1082 | - $active_plugins = get_option('active_plugins', array()); |
|
| 1083 | - foreach ($active_plugins as $active_plugin) { |
|
| 1084 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
| 1085 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 1086 | - unset($_GET['activate']); |
|
| 1087 | - espresso_deactivate_plugin($active_plugin); |
|
| 1088 | - } |
|
| 1089 | - } |
|
| 1090 | - } |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * perform_activations_upgrades_and_migrations |
|
| 1097 | - * |
|
| 1098 | - * @access public |
|
| 1099 | - * @return void |
|
| 1100 | - */ |
|
| 1101 | - public function perform_activations_upgrades_and_migrations() |
|
| 1102 | - { |
|
| 1103 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - |
|
| 1107 | - /** |
|
| 1108 | - * @return void |
|
| 1109 | - * @throws DomainException |
|
| 1110 | - */ |
|
| 1111 | - public function load_CPTs_and_session() |
|
| 1112 | - { |
|
| 1113 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 1114 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */ |
|
| 1115 | - $register_custom_taxonomies = $this->loader->getShared( |
|
| 1116 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
| 1117 | - ); |
|
| 1118 | - $register_custom_taxonomies->registerCustomTaxonomies(); |
|
| 1119 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ |
|
| 1120 | - $register_custom_post_types = $this->loader->getShared( |
|
| 1121 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
| 1122 | - ); |
|
| 1123 | - $register_custom_post_types->registerCustomPostTypes(); |
|
| 1124 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */ |
|
| 1125 | - $register_custom_taxonomy_terms = $this->loader->getShared( |
|
| 1126 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
| 1127 | - ); |
|
| 1128 | - $register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
| 1129 | - // load legacy Custom Post Types and Taxonomies |
|
| 1130 | - $this->loader->getShared('EE_Register_CPTs'); |
|
| 1131 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - |
|
| 1135 | - /** |
|
| 1136 | - * load_controllers |
|
| 1137 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 1138 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 1139 | - * time |
|
| 1140 | - * |
|
| 1141 | - * @access public |
|
| 1142 | - * @return void |
|
| 1143 | - */ |
|
| 1144 | - public function load_controllers() |
|
| 1145 | - { |
|
| 1146 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
| 1147 | - // let's get it started |
|
| 1148 | - if (! $this->maintenance_mode->level() |
|
| 1149 | - && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
| 1150 | - ) { |
|
| 1151 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 1152 | - $this->loader->getShared('EE_Front_Controller'); |
|
| 1153 | - } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
| 1154 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 1155 | - $this->loader->getShared('EE_Admin'); |
|
| 1156 | - } elseif ($this->request->isWordPressHeartbeat()) { |
|
| 1157 | - $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
| 1158 | - } |
|
| 1159 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - |
|
| 1163 | - /** |
|
| 1164 | - * core_loaded_and_ready |
|
| 1165 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1166 | - * |
|
| 1167 | - * @access public |
|
| 1168 | - * @return void |
|
| 1169 | - * @throws Exception |
|
| 1170 | - */ |
|
| 1171 | - public function core_loaded_and_ready() |
|
| 1172 | - { |
|
| 1173 | - if ($this->request->isAdmin() |
|
| 1174 | - || $this->request->isFrontend() |
|
| 1175 | - || $this->request->isIframe() |
|
| 1176 | - || $this->request->isWordPressApi() |
|
| 1177 | - ) { |
|
| 1178 | - try { |
|
| 1179 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
| 1180 | - $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
| 1181 | - if ($this->canLoadBlocks()) { |
|
| 1182 | - $this->loader->getShared( |
|
| 1183 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
| 1184 | - ); |
|
| 1185 | - } |
|
| 1186 | - } catch (Exception $exception) { |
|
| 1187 | - new ExceptionStackTraceDisplay($exception); |
|
| 1188 | - } |
|
| 1189 | - } |
|
| 1190 | - if ($this->request->isAdmin() |
|
| 1191 | - || $this->request->isEeAjax() |
|
| 1192 | - || $this->request->isFrontend() |
|
| 1193 | - ) { |
|
| 1194 | - $this->loader->getShared('EE_Session'); |
|
| 1195 | - } |
|
| 1196 | - // integrate WP_Query with the EE models |
|
| 1197 | - $this->loader->getShared('EE_CPT_Strategy'); |
|
| 1198 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1199 | - // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
| 1200 | - // builders require these even on the front-end |
|
| 1201 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
| 1202 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * initialize |
|
| 1208 | - * this is the best place to begin initializing client code |
|
| 1209 | - * |
|
| 1210 | - * @access public |
|
| 1211 | - * @return void |
|
| 1212 | - */ |
|
| 1213 | - public function initialize() |
|
| 1214 | - { |
|
| 1215 | - do_action('AHEE__EE_System__initialize'); |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - |
|
| 1219 | - /** |
|
| 1220 | - * initialize_last |
|
| 1221 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1222 | - * initialize has done so |
|
| 1223 | - * |
|
| 1224 | - * @access public |
|
| 1225 | - * @return void |
|
| 1226 | - */ |
|
| 1227 | - public function initialize_last() |
|
| 1228 | - { |
|
| 1229 | - do_action('AHEE__EE_System__initialize_last'); |
|
| 1230 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 1231 | - $rewrite_rules = $this->loader->getShared( |
|
| 1232 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 1233 | - ); |
|
| 1234 | - $rewrite_rules->flushRewriteRules(); |
|
| 1235 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
| 1236 | - if (($this->request->isAjax() || $this->request->isAdmin()) |
|
| 1237 | - && $this->maintenance_mode->models_can_query()) { |
|
| 1238 | - $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
| 1239 | - $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
| 1240 | - } |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - |
|
| 1244 | - /** |
|
| 1245 | - * @return void |
|
| 1246 | - * @throws EE_Error |
|
| 1247 | - */ |
|
| 1248 | - public function addEspressoToolbar() |
|
| 1249 | - { |
|
| 1250 | - $this->loader->getShared( |
|
| 1251 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
| 1252 | - array($this->registry->CAP) |
|
| 1253 | - ); |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - |
|
| 1257 | - /** |
|
| 1258 | - * do_not_cache |
|
| 1259 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 1260 | - * |
|
| 1261 | - * @access public |
|
| 1262 | - * @return void |
|
| 1263 | - */ |
|
| 1264 | - public static function do_not_cache() |
|
| 1265 | - { |
|
| 1266 | - // set no cache constants |
|
| 1267 | - if (! defined('DONOTCACHEPAGE')) { |
|
| 1268 | - define('DONOTCACHEPAGE', true); |
|
| 1269 | - } |
|
| 1270 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1271 | - define('DONOTCACHCEOBJECT', true); |
|
| 1272 | - } |
|
| 1273 | - if (! defined('DONOTCACHEDB')) { |
|
| 1274 | - define('DONOTCACHEDB', true); |
|
| 1275 | - } |
|
| 1276 | - // add no cache headers |
|
| 1277 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 1278 | - // plus a little extra for nginx and Google Chrome |
|
| 1279 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1280 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1281 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * extra_nocache_headers |
|
| 1287 | - * |
|
| 1288 | - * @access public |
|
| 1289 | - * @param $headers |
|
| 1290 | - * @return array |
|
| 1291 | - */ |
|
| 1292 | - public static function extra_nocache_headers($headers) |
|
| 1293 | - { |
|
| 1294 | - // for NGINX |
|
| 1295 | - $headers['X-Accel-Expires'] = 0; |
|
| 1296 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1297 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1298 | - return $headers; |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * nocache_headers |
|
| 1304 | - * |
|
| 1305 | - * @access public |
|
| 1306 | - * @return void |
|
| 1307 | - */ |
|
| 1308 | - public static function nocache_headers() |
|
| 1309 | - { |
|
| 1310 | - nocache_headers(); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - |
|
| 1314 | - /** |
|
| 1315 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1316 | - * never returned with the function. |
|
| 1317 | - * |
|
| 1318 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1319 | - * @return array |
|
| 1320 | - */ |
|
| 1321 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1322 | - { |
|
| 1323 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - |
|
| 1327 | - /** |
|
| 1328 | - * Return whether blocks can be registered/loaded or not. |
|
| 1329 | - * @return bool |
|
| 1330 | - */ |
|
| 1331 | - private function canLoadBlocks() |
|
| 1332 | - { |
|
| 1333 | - return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
| 1334 | - && function_exists('register_block_type') |
|
| 1335 | - // don't load blocks if in the Divi page builder editor context |
|
| 1336 | - // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
| 1337 | - && ! $this->request->getRequestParam('et_fb', false); |
|
| 1338 | - } |
|
| 30 | + /** |
|
| 31 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 32 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 33 | + */ |
|
| 34 | + const req_type_normal = 0; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Indicates this is a brand new installation of EE so we should install |
|
| 38 | + * tables and default data etc |
|
| 39 | + */ |
|
| 40 | + const req_type_new_activation = 1; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 44 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 45 | + * and that default data is setup too |
|
| 46 | + */ |
|
| 47 | + const req_type_reactivation = 2; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * indicates that EE has been upgraded since its previous request. |
|
| 51 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 52 | + */ |
|
| 53 | + const req_type_upgrade = 3; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 57 | + */ |
|
| 58 | + const req_type_downgrade = 4; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @deprecated since version 4.6.0.dev.006 |
|
| 62 | + * Now whenever a new_activation is detected the request type is still just |
|
| 63 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 64 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 65 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 66 | + * (Specifically, when the migration manager indicates migrations are finished |
|
| 67 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 68 | + */ |
|
| 69 | + const req_type_activation_but_not_installed = 5; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 73 | + */ |
|
| 74 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_System $_instance |
|
| 78 | + */ |
|
| 79 | + private static $_instance; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var EE_Registry $registry |
|
| 83 | + */ |
|
| 84 | + private $registry; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @var LoaderInterface $loader |
|
| 88 | + */ |
|
| 89 | + private $loader; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var EE_Capabilities $capabilities |
|
| 93 | + */ |
|
| 94 | + private $capabilities; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var RequestInterface $request |
|
| 98 | + */ |
|
| 99 | + private $request; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
| 103 | + */ |
|
| 104 | + private $maintenance_mode; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 108 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 109 | + * |
|
| 110 | + * @var int $_req_type |
|
| 111 | + */ |
|
| 112 | + private $_req_type; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
| 116 | + * |
|
| 117 | + * @var boolean $_major_version_change |
|
| 118 | + */ |
|
| 119 | + private $_major_version_change = false; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * A Context DTO dedicated solely to identifying the current request type. |
|
| 123 | + * |
|
| 124 | + * @var RequestTypeContextCheckerInterface $request_type |
|
| 125 | + */ |
|
| 126 | + private $request_type; |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @singleton method used to instantiate class object |
|
| 131 | + * @param EE_Registry|null $registry |
|
| 132 | + * @param LoaderInterface|null $loader |
|
| 133 | + * @param RequestInterface|null $request |
|
| 134 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
| 135 | + * @return EE_System |
|
| 136 | + */ |
|
| 137 | + public static function instance( |
|
| 138 | + EE_Registry $registry = null, |
|
| 139 | + LoaderInterface $loader = null, |
|
| 140 | + RequestInterface $request = null, |
|
| 141 | + EE_Maintenance_Mode $maintenance_mode = null |
|
| 142 | + ) { |
|
| 143 | + // check if class object is instantiated |
|
| 144 | + if (! self::$_instance instanceof EE_System) { |
|
| 145 | + self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
| 146 | + } |
|
| 147 | + return self::$_instance; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * resets the instance and returns it |
|
| 153 | + * |
|
| 154 | + * @return EE_System |
|
| 155 | + */ |
|
| 156 | + public static function reset() |
|
| 157 | + { |
|
| 158 | + self::$_instance->_req_type = null; |
|
| 159 | + // make sure none of the old hooks are left hanging around |
|
| 160 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 161 | + // we need to reset the migration manager in order for it to detect DMSs properly |
|
| 162 | + EE_Data_Migration_Manager::reset(); |
|
| 163 | + self::instance()->detect_activations_or_upgrades(); |
|
| 164 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 165 | + return self::instance(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * sets hooks for running rest of system |
|
| 171 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 172 | + * starting EE Addons from any other point may lead to problems |
|
| 173 | + * |
|
| 174 | + * @param EE_Registry $registry |
|
| 175 | + * @param LoaderInterface $loader |
|
| 176 | + * @param RequestInterface $request |
|
| 177 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
| 178 | + */ |
|
| 179 | + private function __construct( |
|
| 180 | + EE_Registry $registry, |
|
| 181 | + LoaderInterface $loader, |
|
| 182 | + RequestInterface $request, |
|
| 183 | + EE_Maintenance_Mode $maintenance_mode |
|
| 184 | + ) { |
|
| 185 | + $this->registry = $registry; |
|
| 186 | + $this->loader = $loader; |
|
| 187 | + $this->request = $request; |
|
| 188 | + $this->maintenance_mode = $maintenance_mode; |
|
| 189 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
| 190 | + add_action( |
|
| 191 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 192 | + array($this, 'loadCapabilities'), |
|
| 193 | + 5 |
|
| 194 | + ); |
|
| 195 | + add_action( |
|
| 196 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 197 | + array($this, 'loadCommandBus'), |
|
| 198 | + 7 |
|
| 199 | + ); |
|
| 200 | + add_action( |
|
| 201 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 202 | + array($this, 'loadPluginApi'), |
|
| 203 | + 9 |
|
| 204 | + ); |
|
| 205 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 206 | + add_action( |
|
| 207 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 208 | + array($this, 'load_espresso_addons') |
|
| 209 | + ); |
|
| 210 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
| 211 | + // because the newly-activated addon didn't get a chance to run at all |
|
| 212 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 213 | + // detect whether install or upgrade |
|
| 214 | + add_action( |
|
| 215 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 216 | + array($this, 'detect_activations_or_upgrades'), |
|
| 217 | + 3 |
|
| 218 | + ); |
|
| 219 | + // load EE_Config, EE_Textdomain, etc |
|
| 220 | + add_action( |
|
| 221 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 222 | + array($this, 'load_core_configuration'), |
|
| 223 | + 5 |
|
| 224 | + ); |
|
| 225 | + // load specifications for matching routes to current request |
|
| 226 | + add_action( |
|
| 227 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 228 | + array($this, 'loadRouteMatchSpecifications') |
|
| 229 | + ); |
|
| 230 | + // load EE_Config, EE_Textdomain, etc |
|
| 231 | + add_action( |
|
| 232 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 233 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
| 234 | + 7 |
|
| 235 | + ); |
|
| 236 | + // you wanna get going? I wanna get going... let's get going! |
|
| 237 | + add_action( |
|
| 238 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 239 | + array($this, 'brew_espresso'), |
|
| 240 | + 9 |
|
| 241 | + ); |
|
| 242 | + // other housekeeping |
|
| 243 | + // exclude EE critical pages from wp_list_pages |
|
| 244 | + add_filter( |
|
| 245 | + 'wp_list_pages_excludes', |
|
| 246 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
| 247 | + 10 |
|
| 248 | + ); |
|
| 249 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 250 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 251 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * load and setup EE_Capabilities |
|
| 257 | + * |
|
| 258 | + * @return void |
|
| 259 | + * @throws EE_Error |
|
| 260 | + */ |
|
| 261 | + public function loadCapabilities() |
|
| 262 | + { |
|
| 263 | + $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
| 264 | + add_action( |
|
| 265 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 266 | + function () { |
|
| 267 | + LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
| 268 | + } |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * create and cache the CommandBus, and also add middleware |
|
| 275 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
| 276 | + * which is why we need to load the CommandBus after Caps are set up |
|
| 277 | + * |
|
| 278 | + * @return void |
|
| 279 | + * @throws EE_Error |
|
| 280 | + */ |
|
| 281 | + public function loadCommandBus() |
|
| 282 | + { |
|
| 283 | + $this->loader->getShared( |
|
| 284 | + 'CommandBusInterface', |
|
| 285 | + array( |
|
| 286 | + null, |
|
| 287 | + apply_filters( |
|
| 288 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 289 | + array( |
|
| 290 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
| 291 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
| 292 | + ) |
|
| 293 | + ), |
|
| 294 | + ) |
|
| 295 | + ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * @return void |
|
| 301 | + * @throws EE_Error |
|
| 302 | + */ |
|
| 303 | + public function loadPluginApi() |
|
| 304 | + { |
|
| 305 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 306 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 307 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 308 | + $this->loader->getShared('EE_Request_Handler'); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @param string $addon_name |
|
| 314 | + * @param string $version_constant |
|
| 315 | + * @param string $min_version_required |
|
| 316 | + * @param string $load_callback |
|
| 317 | + * @param string $plugin_file_constant |
|
| 318 | + * @return void |
|
| 319 | + */ |
|
| 320 | + private function deactivateIncompatibleAddon( |
|
| 321 | + $addon_name, |
|
| 322 | + $version_constant, |
|
| 323 | + $min_version_required, |
|
| 324 | + $load_callback, |
|
| 325 | + $plugin_file_constant |
|
| 326 | + ) { |
|
| 327 | + if (! defined($version_constant)) { |
|
| 328 | + return; |
|
| 329 | + } |
|
| 330 | + $addon_version = constant($version_constant); |
|
| 331 | + if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
| 332 | + remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
| 333 | + if (! function_exists('deactivate_plugins')) { |
|
| 334 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 335 | + } |
|
| 336 | + deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
| 337 | + unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
| 338 | + EE_Error::add_error( |
|
| 339 | + sprintf( |
|
| 340 | + esc_html__( |
|
| 341 | + 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
| 342 | + 'event_espresso' |
|
| 343 | + ), |
|
| 344 | + $addon_name, |
|
| 345 | + $min_version_required |
|
| 346 | + ), |
|
| 347 | + __FILE__, |
|
| 348 | + __FUNCTION__ . "({$addon_name})", |
|
| 349 | + __LINE__ |
|
| 350 | + ); |
|
| 351 | + EE_Error::get_notices(false, true); |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * load_espresso_addons |
|
| 358 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 359 | + * this is hooked into both: |
|
| 360 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 361 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 362 | + * and the WP 'activate_plugin' hook point |
|
| 363 | + * |
|
| 364 | + * @access public |
|
| 365 | + * @return void |
|
| 366 | + */ |
|
| 367 | + public function load_espresso_addons() |
|
| 368 | + { |
|
| 369 | + $this->deactivateIncompatibleAddon( |
|
| 370 | + 'Wait Lists', |
|
| 371 | + 'EE_WAIT_LISTS_VERSION', |
|
| 372 | + '1.0.0.beta.074', |
|
| 373 | + 'load_espresso_wait_lists', |
|
| 374 | + 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
| 375 | + ); |
|
| 376 | + $this->deactivateIncompatibleAddon( |
|
| 377 | + 'Automated Upcoming Event Notifications', |
|
| 378 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
| 379 | + '1.0.0.beta.091', |
|
| 380 | + 'load_espresso_automated_upcoming_event_notification', |
|
| 381 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
| 382 | + ); |
|
| 383 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 384 | + // if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 385 | + // We want it for mobile apps. Just include the entire plugin |
|
| 386 | + // also, don't load the basic auth when a plugin is getting activated, because |
|
| 387 | + // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 388 | + // and causes a fatal error |
|
| 389 | + if (($this->request->isWordPressApi() || $this->request->isApi()) |
|
| 390 | + && $this->request->getRequestParam('activate') !== 'true' |
|
| 391 | + && ! function_exists('json_basic_auth_handler') |
|
| 392 | + && ! function_exists('json_basic_auth_error') |
|
| 393 | + && ! in_array( |
|
| 394 | + $this->request->getRequestParam('action'), |
|
| 395 | + array('activate', 'activate-selected'), |
|
| 396 | + true |
|
| 397 | + ) |
|
| 398 | + ) { |
|
| 399 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 400 | + } |
|
| 401 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * detect_activations_or_upgrades |
|
| 407 | + * Checks for activation or upgrade of core first; |
|
| 408 | + * then also checks if any registered addons have been activated or upgraded |
|
| 409 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 410 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 411 | + * |
|
| 412 | + * @access public |
|
| 413 | + * @return void |
|
| 414 | + */ |
|
| 415 | + public function detect_activations_or_upgrades() |
|
| 416 | + { |
|
| 417 | + // first off: let's make sure to handle core |
|
| 418 | + $this->detect_if_activation_or_upgrade(); |
|
| 419 | + foreach ($this->registry->addons as $addon) { |
|
| 420 | + if ($addon instanceof EE_Addon) { |
|
| 421 | + // detect teh request type for that addon |
|
| 422 | + $addon->detect_activation_or_upgrade(); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * detect_if_activation_or_upgrade |
|
| 430 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 431 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 432 | + * |
|
| 433 | + * @access public |
|
| 434 | + * @return void |
|
| 435 | + */ |
|
| 436 | + public function detect_if_activation_or_upgrade() |
|
| 437 | + { |
|
| 438 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 439 | + // check if db has been updated, or if its a brand-new installation |
|
| 440 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 441 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
| 442 | + // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 443 | + switch ($request_type) { |
|
| 444 | + case EE_System::req_type_new_activation: |
|
| 445 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 446 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 447 | + break; |
|
| 448 | + case EE_System::req_type_reactivation: |
|
| 449 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 450 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 451 | + break; |
|
| 452 | + case EE_System::req_type_upgrade: |
|
| 453 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 454 | + // migrations may be required now that we've upgraded |
|
| 455 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 456 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 457 | + break; |
|
| 458 | + case EE_System::req_type_downgrade: |
|
| 459 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 460 | + // its possible migrations are no longer required |
|
| 461 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 462 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 463 | + break; |
|
| 464 | + case EE_System::req_type_normal: |
|
| 465 | + default: |
|
| 466 | + break; |
|
| 467 | + } |
|
| 468 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Updates the list of installed versions and sets hooks for |
|
| 474 | + * initializing the database later during the request |
|
| 475 | + * |
|
| 476 | + * @param array $espresso_db_update |
|
| 477 | + */ |
|
| 478 | + private function _handle_core_version_change($espresso_db_update) |
|
| 479 | + { |
|
| 480 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
| 481 | + // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 482 | + add_action( |
|
| 483 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 484 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 485 | + ); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 491 | + * information about what versions of EE have been installed and activated, |
|
| 492 | + * NOT necessarily the state of the database |
|
| 493 | + * |
|
| 494 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 495 | + * If not supplied, fetches it from the options table |
|
| 496 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 497 | + */ |
|
| 498 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 499 | + { |
|
| 500 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 501 | + if (! $espresso_db_update) { |
|
| 502 | + $espresso_db_update = get_option('espresso_db_update'); |
|
| 503 | + } |
|
| 504 | + // check that option is an array |
|
| 505 | + if (! is_array($espresso_db_update)) { |
|
| 506 | + // if option is FALSE, then it never existed |
|
| 507 | + if ($espresso_db_update === false) { |
|
| 508 | + // make $espresso_db_update an array and save option with autoload OFF |
|
| 509 | + $espresso_db_update = array(); |
|
| 510 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 511 | + } else { |
|
| 512 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 513 | + $espresso_db_update = array($espresso_db_update => array()); |
|
| 514 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 515 | + } |
|
| 516 | + } else { |
|
| 517 | + $corrected_db_update = array(); |
|
| 518 | + // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 519 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 520 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 521 | + // the key is an int, and the value IS NOT an array |
|
| 522 | + // so it must be numerically-indexed, where values are versions installed... |
|
| 523 | + // fix it! |
|
| 524 | + $version_string = $should_be_array; |
|
| 525 | + $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
| 526 | + } else { |
|
| 527 | + // ok it checks out |
|
| 528 | + $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + $espresso_db_update = $corrected_db_update; |
|
| 532 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 533 | + } |
|
| 534 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 535 | + return $espresso_db_update; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 541 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 542 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 543 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 544 | + * so that it will be done when migrations are finished |
|
| 545 | + * |
|
| 546 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 547 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 548 | + * This is a resource-intensive job |
|
| 549 | + * so we prefer to only do it when necessary |
|
| 550 | + * @return void |
|
| 551 | + * @throws EE_Error |
|
| 552 | + */ |
|
| 553 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 554 | + { |
|
| 555 | + $request_type = $this->detect_req_type(); |
|
| 556 | + // only initialize system if we're not in maintenance mode. |
|
| 557 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 558 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 559 | + $rewrite_rules = $this->loader->getShared( |
|
| 560 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 561 | + ); |
|
| 562 | + $rewrite_rules->flush(); |
|
| 563 | + if ($verify_schema) { |
|
| 564 | + EEH_Activation::initialize_db_and_folders(); |
|
| 565 | + } |
|
| 566 | + EEH_Activation::initialize_db_content(); |
|
| 567 | + EEH_Activation::system_initialization(); |
|
| 568 | + if ($initialize_addons_too) { |
|
| 569 | + $this->initialize_addons(); |
|
| 570 | + } |
|
| 571 | + } else { |
|
| 572 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 573 | + } |
|
| 574 | + if ($request_type === EE_System::req_type_new_activation |
|
| 575 | + || $request_type === EE_System::req_type_reactivation |
|
| 576 | + || ( |
|
| 577 | + $request_type === EE_System::req_type_upgrade |
|
| 578 | + && $this->is_major_version_change() |
|
| 579 | + ) |
|
| 580 | + ) { |
|
| 581 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Initializes the db for all registered addons |
|
| 588 | + * |
|
| 589 | + * @throws EE_Error |
|
| 590 | + */ |
|
| 591 | + public function initialize_addons() |
|
| 592 | + { |
|
| 593 | + // foreach registered addon, make sure its db is up-to-date too |
|
| 594 | + foreach ($this->registry->addons as $addon) { |
|
| 595 | + if ($addon instanceof EE_Addon) { |
|
| 596 | + $addon->initialize_db_if_no_migrations_required(); |
|
| 597 | + } |
|
| 598 | + } |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 604 | + * |
|
| 605 | + * @param array $version_history |
|
| 606 | + * @param string $current_version_to_add version to be added to the version history |
|
| 607 | + * @return boolean success as to whether or not this option was changed |
|
| 608 | + */ |
|
| 609 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 610 | + { |
|
| 611 | + if (! $version_history) { |
|
| 612 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 613 | + } |
|
| 614 | + if ($current_version_to_add === null) { |
|
| 615 | + $current_version_to_add = espresso_version(); |
|
| 616 | + } |
|
| 617 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
| 618 | + // re-save |
|
| 619 | + return update_option('espresso_db_update', $version_history); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * Detects if the current version indicated in the has existed in the list of |
|
| 625 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 626 | + * |
|
| 627 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 628 | + * If not supplied, fetches it from the options table. |
|
| 629 | + * Also, caches its result so later parts of the code can also know whether |
|
| 630 | + * there's been an update or not. This way we can add the current version to |
|
| 631 | + * espresso_db_update, but still know if this is a new install or not |
|
| 632 | + * @return int one of the constants on EE_System::req_type_ |
|
| 633 | + */ |
|
| 634 | + public function detect_req_type($espresso_db_update = null) |
|
| 635 | + { |
|
| 636 | + if ($this->_req_type === null) { |
|
| 637 | + $espresso_db_update = ! empty($espresso_db_update) |
|
| 638 | + ? $espresso_db_update |
|
| 639 | + : $this->fix_espresso_db_upgrade_option(); |
|
| 640 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
| 641 | + $espresso_db_update, |
|
| 642 | + 'ee_espresso_activation', |
|
| 643 | + espresso_version() |
|
| 644 | + ); |
|
| 645 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 646 | + $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
| 647 | + } |
|
| 648 | + return $this->_req_type; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 654 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 655 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 656 | + * |
|
| 657 | + * @param $activation_history |
|
| 658 | + * @return bool |
|
| 659 | + */ |
|
| 660 | + private function _detect_major_version_change($activation_history) |
|
| 661 | + { |
|
| 662 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 663 | + $previous_version_parts = explode('.', $previous_version); |
|
| 664 | + $current_version_parts = explode('.', espresso_version()); |
|
| 665 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 666 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 667 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 668 | + ); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Returns true if either the major or minor version of EE changed during this request. |
|
| 674 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 675 | + * |
|
| 676 | + * @return bool |
|
| 677 | + */ |
|
| 678 | + public function is_major_version_change() |
|
| 679 | + { |
|
| 680 | + return $this->_major_version_change; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 686 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 687 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 688 | + * just activated to (for core that will always be espresso_version()) |
|
| 689 | + * |
|
| 690 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 691 | + * ee plugin. for core that's 'espresso_db_update' |
|
| 692 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 693 | + * indicate that this plugin was just activated |
|
| 694 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 695 | + * espresso_version()) |
|
| 696 | + * @return int one of the constants on EE_System::req_type_* |
|
| 697 | + */ |
|
| 698 | + public static function detect_req_type_given_activation_history( |
|
| 699 | + $activation_history_for_addon, |
|
| 700 | + $activation_indicator_option_name, |
|
| 701 | + $version_to_upgrade_to |
|
| 702 | + ) { |
|
| 703 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 704 | + if ($activation_history_for_addon) { |
|
| 705 | + // it exists, so this isn't a completely new install |
|
| 706 | + // check if this version already in that list of previously installed versions |
|
| 707 | + if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
| 708 | + // it a version we haven't seen before |
|
| 709 | + if ($version_is_higher === 1) { |
|
| 710 | + $req_type = EE_System::req_type_upgrade; |
|
| 711 | + } else { |
|
| 712 | + $req_type = EE_System::req_type_downgrade; |
|
| 713 | + } |
|
| 714 | + delete_option($activation_indicator_option_name); |
|
| 715 | + } else { |
|
| 716 | + // its not an update. maybe a reactivation? |
|
| 717 | + if (get_option($activation_indicator_option_name, false)) { |
|
| 718 | + if ($version_is_higher === -1) { |
|
| 719 | + $req_type = EE_System::req_type_downgrade; |
|
| 720 | + } elseif ($version_is_higher === 0) { |
|
| 721 | + // we've seen this version before, but it's an activation. must be a reactivation |
|
| 722 | + $req_type = EE_System::req_type_reactivation; |
|
| 723 | + } else {// $version_is_higher === 1 |
|
| 724 | + $req_type = EE_System::req_type_upgrade; |
|
| 725 | + } |
|
| 726 | + delete_option($activation_indicator_option_name); |
|
| 727 | + } else { |
|
| 728 | + // we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 729 | + if ($version_is_higher === -1) { |
|
| 730 | + $req_type = EE_System::req_type_downgrade; |
|
| 731 | + } elseif ($version_is_higher === 0) { |
|
| 732 | + // we've seen this version before and it's not an activation. its normal request |
|
| 733 | + $req_type = EE_System::req_type_normal; |
|
| 734 | + } else {// $version_is_higher === 1 |
|
| 735 | + $req_type = EE_System::req_type_upgrade; |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } else { |
|
| 740 | + // brand new install |
|
| 741 | + $req_type = EE_System::req_type_new_activation; |
|
| 742 | + delete_option($activation_indicator_option_name); |
|
| 743 | + } |
|
| 744 | + return $req_type; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 750 | + * the $activation_history_for_addon |
|
| 751 | + * |
|
| 752 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 753 | + * sometimes containing 'unknown-date' |
|
| 754 | + * @param string $version_to_upgrade_to (current version) |
|
| 755 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 756 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 757 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 758 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 759 | + */ |
|
| 760 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 761 | + { |
|
| 762 | + // find the most recently-activated version |
|
| 763 | + $most_recently_active_version = |
|
| 764 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 765 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Gets the most recently active version listed in the activation history, |
|
| 771 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 772 | + * |
|
| 773 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 774 | + * sometimes containing 'unknown-date' |
|
| 775 | + * @return string |
|
| 776 | + */ |
|
| 777 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 778 | + { |
|
| 779 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 780 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
| 781 | + if (is_array($activation_history)) { |
|
| 782 | + foreach ($activation_history as $version => $times_activated) { |
|
| 783 | + // check there is a record of when this version was activated. Otherwise, |
|
| 784 | + // mark it as unknown |
|
| 785 | + if (! $times_activated) { |
|
| 786 | + $times_activated = array('unknown-date'); |
|
| 787 | + } |
|
| 788 | + if (is_string($times_activated)) { |
|
| 789 | + $times_activated = array($times_activated); |
|
| 790 | + } |
|
| 791 | + foreach ($times_activated as $an_activation) { |
|
| 792 | + if ($an_activation !== 'unknown-date' |
|
| 793 | + && $an_activation |
|
| 794 | + > $most_recently_active_version_activation) { |
|
| 795 | + $most_recently_active_version = $version; |
|
| 796 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
| 797 | + ? '1970-01-01 00:00:00' |
|
| 798 | + : $an_activation; |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + return $most_recently_active_version; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * This redirects to the about EE page after activation |
|
| 809 | + * |
|
| 810 | + * @return void |
|
| 811 | + */ |
|
| 812 | + public function redirect_to_about_ee() |
|
| 813 | + { |
|
| 814 | + $notices = EE_Error::get_notices(false); |
|
| 815 | + // if current user is an admin and it's not an ajax or rest request |
|
| 816 | + if (! isset($notices['errors']) |
|
| 817 | + && $this->request->isAdmin() |
|
| 818 | + && apply_filters( |
|
| 819 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 820 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
| 821 | + ) |
|
| 822 | + ) { |
|
| 823 | + $query_params = array('page' => 'espresso_about'); |
|
| 824 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 825 | + $query_params['new_activation'] = true; |
|
| 826 | + } |
|
| 827 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 828 | + $query_params['reactivation'] = true; |
|
| 829 | + } |
|
| 830 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 831 | + wp_safe_redirect($url); |
|
| 832 | + exit(); |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * load_core_configuration |
|
| 839 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 840 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 841 | + * |
|
| 842 | + * @return void |
|
| 843 | + * @throws ReflectionException |
|
| 844 | + * @throws Exception |
|
| 845 | + */ |
|
| 846 | + public function load_core_configuration() |
|
| 847 | + { |
|
| 848 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 849 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
| 850 | + // load textdomain |
|
| 851 | + EE_Load_Textdomain::load_textdomain(); |
|
| 852 | + // load and setup EE_Config and EE_Network_Config |
|
| 853 | + $config = $this->loader->getShared('EE_Config'); |
|
| 854 | + $this->loader->getShared('EE_Network_Config'); |
|
| 855 | + // setup autoloaders |
|
| 856 | + // enable logging? |
|
| 857 | + if ($config->admin->use_full_logging) { |
|
| 858 | + $this->loader->getShared('EE_Log'); |
|
| 859 | + } |
|
| 860 | + // check for activation errors |
|
| 861 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 862 | + if ($activation_errors) { |
|
| 863 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 864 | + update_option('ee_plugin_activation_errors', false); |
|
| 865 | + } |
|
| 866 | + // get model names |
|
| 867 | + $this->_parse_model_names(); |
|
| 868 | + // load caf stuff a chance to play during the activation process too. |
|
| 869 | + $this->_maybe_brew_regular(); |
|
| 870 | + // configure custom post type definitions |
|
| 871 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
| 872 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
| 873 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 879 | + * |
|
| 880 | + * @return void |
|
| 881 | + * @throws ReflectionException |
|
| 882 | + */ |
|
| 883 | + private function _parse_model_names() |
|
| 884 | + { |
|
| 885 | + // get all the files in the EE_MODELS folder that end in .model.php |
|
| 886 | + $models = glob(EE_MODELS . '*.model.php'); |
|
| 887 | + $model_names = array(); |
|
| 888 | + $non_abstract_db_models = array(); |
|
| 889 | + foreach ($models as $model) { |
|
| 890 | + // get model classname |
|
| 891 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 892 | + $short_name = str_replace('EEM_', '', $classname); |
|
| 893 | + $reflectionClass = new ReflectionClass($classname); |
|
| 894 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 895 | + $non_abstract_db_models[ $short_name ] = $classname; |
|
| 896 | + } |
|
| 897 | + $model_names[ $short_name ] = $classname; |
|
| 898 | + } |
|
| 899 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 900 | + $this->registry->non_abstract_db_models = apply_filters( |
|
| 901 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
| 902 | + $non_abstract_db_models |
|
| 903 | + ); |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 909 | + * that need to be setup before our EE_System launches. |
|
| 910 | + * |
|
| 911 | + * @return void |
|
| 912 | + * @throws DomainException |
|
| 913 | + * @throws InvalidArgumentException |
|
| 914 | + * @throws InvalidDataTypeException |
|
| 915 | + * @throws InvalidInterfaceException |
|
| 916 | + * @throws InvalidClassException |
|
| 917 | + * @throws InvalidFilePathException |
|
| 918 | + */ |
|
| 919 | + private function _maybe_brew_regular() |
|
| 920 | + { |
|
| 921 | + /** @var Domain $domain */ |
|
| 922 | + $domain = DomainFactory::getShared( |
|
| 923 | + new FullyQualifiedName( |
|
| 924 | + 'EventEspresso\core\domain\Domain' |
|
| 925 | + ), |
|
| 926 | + array( |
|
| 927 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
| 928 | + Version::fromString(espresso_version()), |
|
| 929 | + ) |
|
| 930 | + ); |
|
| 931 | + if ($domain->isCaffeinated()) { |
|
| 932 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + /** |
|
| 938 | + * @since 4.9.71.p |
|
| 939 | + * @throws Exception |
|
| 940 | + */ |
|
| 941 | + public function loadRouteMatchSpecifications() |
|
| 942 | + { |
|
| 943 | + try { |
|
| 944 | + $this->loader->getShared( |
|
| 945 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' |
|
| 946 | + ); |
|
| 947 | + } catch (Exception $exception) { |
|
| 948 | + new ExceptionStackTraceDisplay($exception); |
|
| 949 | + } |
|
| 950 | + do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * register_shortcodes_modules_and_widgets |
|
| 956 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
| 957 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 958 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 959 | + * |
|
| 960 | + * @access public |
|
| 961 | + * @return void |
|
| 962 | + * @throws Exception |
|
| 963 | + */ |
|
| 964 | + public function register_shortcodes_modules_and_widgets() |
|
| 965 | + { |
|
| 966 | + if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) { |
|
| 967 | + try { |
|
| 968 | + // load, register, and add shortcodes the new way |
|
| 969 | + $this->loader->getShared( |
|
| 970 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
| 971 | + array( |
|
| 972 | + // and the old way, but we'll put it under control of the new system |
|
| 973 | + EE_Config::getLegacyShortcodesManager(), |
|
| 974 | + ) |
|
| 975 | + ); |
|
| 976 | + } catch (Exception $exception) { |
|
| 977 | + new ExceptionStackTraceDisplay($exception); |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 981 | + // check for addons using old hook point |
|
| 982 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 983 | + $this->_incompatible_addon_error(); |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * _incompatible_addon_error |
|
| 990 | + * |
|
| 991 | + * @access public |
|
| 992 | + * @return void |
|
| 993 | + */ |
|
| 994 | + private function _incompatible_addon_error() |
|
| 995 | + { |
|
| 996 | + // get array of classes hooking into here |
|
| 997 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
| 998 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
| 999 | + ); |
|
| 1000 | + if (! empty($class_names)) { |
|
| 1001 | + $msg = __( |
|
| 1002 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 1003 | + 'event_espresso' |
|
| 1004 | + ); |
|
| 1005 | + $msg .= '<ul>'; |
|
| 1006 | + foreach ($class_names as $class_name) { |
|
| 1007 | + $msg .= '<li><b>Event Espresso - ' |
|
| 1008 | + . str_replace( |
|
| 1009 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
|
| 1010 | + '', |
|
| 1011 | + $class_name |
|
| 1012 | + ) . '</b></li>'; |
|
| 1013 | + } |
|
| 1014 | + $msg .= '</ul>'; |
|
| 1015 | + $msg .= __( |
|
| 1016 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 1017 | + 'event_espresso' |
|
| 1018 | + ); |
|
| 1019 | + // save list of incompatible addons to wp-options for later use |
|
| 1020 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 1021 | + if (is_admin()) { |
|
| 1022 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1023 | + } |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * brew_espresso |
|
| 1030 | + * begins the process of setting hooks for initializing EE in the correct order |
|
| 1031 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 1032 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 1033 | + * |
|
| 1034 | + * @return void |
|
| 1035 | + */ |
|
| 1036 | + public function brew_espresso() |
|
| 1037 | + { |
|
| 1038 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 1039 | + // load some final core systems |
|
| 1040 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 1041 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 1042 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 1043 | + add_action('init', array($this, 'load_controllers'), 7); |
|
| 1044 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 1045 | + add_action('init', array($this, 'initialize'), 10); |
|
| 1046 | + add_action('init', array($this, 'initialize_last'), 100); |
|
| 1047 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 1048 | + // pew pew pew |
|
| 1049 | + $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
| 1050 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 1051 | + } |
|
| 1052 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * set_hooks_for_core |
|
| 1058 | + * |
|
| 1059 | + * @access public |
|
| 1060 | + * @return void |
|
| 1061 | + * @throws EE_Error |
|
| 1062 | + */ |
|
| 1063 | + public function set_hooks_for_core() |
|
| 1064 | + { |
|
| 1065 | + $this->_deactivate_incompatible_addons(); |
|
| 1066 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 1067 | + $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
| 1068 | + // caps need to be initialized on every request so that capability maps are set. |
|
| 1069 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 1070 | + $this->registry->CAP->init_caps(); |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 1076 | + * deactivates any addons considered incompatible with the current version of EE |
|
| 1077 | + */ |
|
| 1078 | + private function _deactivate_incompatible_addons() |
|
| 1079 | + { |
|
| 1080 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 1081 | + if (! empty($incompatible_addons)) { |
|
| 1082 | + $active_plugins = get_option('active_plugins', array()); |
|
| 1083 | + foreach ($active_plugins as $active_plugin) { |
|
| 1084 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
| 1085 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 1086 | + unset($_GET['activate']); |
|
| 1087 | + espresso_deactivate_plugin($active_plugin); |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | + } |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * perform_activations_upgrades_and_migrations |
|
| 1097 | + * |
|
| 1098 | + * @access public |
|
| 1099 | + * @return void |
|
| 1100 | + */ |
|
| 1101 | + public function perform_activations_upgrades_and_migrations() |
|
| 1102 | + { |
|
| 1103 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + |
|
| 1107 | + /** |
|
| 1108 | + * @return void |
|
| 1109 | + * @throws DomainException |
|
| 1110 | + */ |
|
| 1111 | + public function load_CPTs_and_session() |
|
| 1112 | + { |
|
| 1113 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 1114 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */ |
|
| 1115 | + $register_custom_taxonomies = $this->loader->getShared( |
|
| 1116 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
| 1117 | + ); |
|
| 1118 | + $register_custom_taxonomies->registerCustomTaxonomies(); |
|
| 1119 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ |
|
| 1120 | + $register_custom_post_types = $this->loader->getShared( |
|
| 1121 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
| 1122 | + ); |
|
| 1123 | + $register_custom_post_types->registerCustomPostTypes(); |
|
| 1124 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */ |
|
| 1125 | + $register_custom_taxonomy_terms = $this->loader->getShared( |
|
| 1126 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
| 1127 | + ); |
|
| 1128 | + $register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
| 1129 | + // load legacy Custom Post Types and Taxonomies |
|
| 1130 | + $this->loader->getShared('EE_Register_CPTs'); |
|
| 1131 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + |
|
| 1135 | + /** |
|
| 1136 | + * load_controllers |
|
| 1137 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 1138 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 1139 | + * time |
|
| 1140 | + * |
|
| 1141 | + * @access public |
|
| 1142 | + * @return void |
|
| 1143 | + */ |
|
| 1144 | + public function load_controllers() |
|
| 1145 | + { |
|
| 1146 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
| 1147 | + // let's get it started |
|
| 1148 | + if (! $this->maintenance_mode->level() |
|
| 1149 | + && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
| 1150 | + ) { |
|
| 1151 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 1152 | + $this->loader->getShared('EE_Front_Controller'); |
|
| 1153 | + } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
| 1154 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 1155 | + $this->loader->getShared('EE_Admin'); |
|
| 1156 | + } elseif ($this->request->isWordPressHeartbeat()) { |
|
| 1157 | + $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
| 1158 | + } |
|
| 1159 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * core_loaded_and_ready |
|
| 1165 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1166 | + * |
|
| 1167 | + * @access public |
|
| 1168 | + * @return void |
|
| 1169 | + * @throws Exception |
|
| 1170 | + */ |
|
| 1171 | + public function core_loaded_and_ready() |
|
| 1172 | + { |
|
| 1173 | + if ($this->request->isAdmin() |
|
| 1174 | + || $this->request->isFrontend() |
|
| 1175 | + || $this->request->isIframe() |
|
| 1176 | + || $this->request->isWordPressApi() |
|
| 1177 | + ) { |
|
| 1178 | + try { |
|
| 1179 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
| 1180 | + $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
| 1181 | + if ($this->canLoadBlocks()) { |
|
| 1182 | + $this->loader->getShared( |
|
| 1183 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
| 1184 | + ); |
|
| 1185 | + } |
|
| 1186 | + } catch (Exception $exception) { |
|
| 1187 | + new ExceptionStackTraceDisplay($exception); |
|
| 1188 | + } |
|
| 1189 | + } |
|
| 1190 | + if ($this->request->isAdmin() |
|
| 1191 | + || $this->request->isEeAjax() |
|
| 1192 | + || $this->request->isFrontend() |
|
| 1193 | + ) { |
|
| 1194 | + $this->loader->getShared('EE_Session'); |
|
| 1195 | + } |
|
| 1196 | + // integrate WP_Query with the EE models |
|
| 1197 | + $this->loader->getShared('EE_CPT_Strategy'); |
|
| 1198 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1199 | + // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
| 1200 | + // builders require these even on the front-end |
|
| 1201 | + require_once EE_PUBLIC . 'template_tags.php'; |
|
| 1202 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * initialize |
|
| 1208 | + * this is the best place to begin initializing client code |
|
| 1209 | + * |
|
| 1210 | + * @access public |
|
| 1211 | + * @return void |
|
| 1212 | + */ |
|
| 1213 | + public function initialize() |
|
| 1214 | + { |
|
| 1215 | + do_action('AHEE__EE_System__initialize'); |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + |
|
| 1219 | + /** |
|
| 1220 | + * initialize_last |
|
| 1221 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1222 | + * initialize has done so |
|
| 1223 | + * |
|
| 1224 | + * @access public |
|
| 1225 | + * @return void |
|
| 1226 | + */ |
|
| 1227 | + public function initialize_last() |
|
| 1228 | + { |
|
| 1229 | + do_action('AHEE__EE_System__initialize_last'); |
|
| 1230 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 1231 | + $rewrite_rules = $this->loader->getShared( |
|
| 1232 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 1233 | + ); |
|
| 1234 | + $rewrite_rules->flushRewriteRules(); |
|
| 1235 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
| 1236 | + if (($this->request->isAjax() || $this->request->isAdmin()) |
|
| 1237 | + && $this->maintenance_mode->models_can_query()) { |
|
| 1238 | + $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
| 1239 | + $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + |
|
| 1244 | + /** |
|
| 1245 | + * @return void |
|
| 1246 | + * @throws EE_Error |
|
| 1247 | + */ |
|
| 1248 | + public function addEspressoToolbar() |
|
| 1249 | + { |
|
| 1250 | + $this->loader->getShared( |
|
| 1251 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
| 1252 | + array($this->registry->CAP) |
|
| 1253 | + ); |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + |
|
| 1257 | + /** |
|
| 1258 | + * do_not_cache |
|
| 1259 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 1260 | + * |
|
| 1261 | + * @access public |
|
| 1262 | + * @return void |
|
| 1263 | + */ |
|
| 1264 | + public static function do_not_cache() |
|
| 1265 | + { |
|
| 1266 | + // set no cache constants |
|
| 1267 | + if (! defined('DONOTCACHEPAGE')) { |
|
| 1268 | + define('DONOTCACHEPAGE', true); |
|
| 1269 | + } |
|
| 1270 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1271 | + define('DONOTCACHCEOBJECT', true); |
|
| 1272 | + } |
|
| 1273 | + if (! defined('DONOTCACHEDB')) { |
|
| 1274 | + define('DONOTCACHEDB', true); |
|
| 1275 | + } |
|
| 1276 | + // add no cache headers |
|
| 1277 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 1278 | + // plus a little extra for nginx and Google Chrome |
|
| 1279 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1280 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1281 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * extra_nocache_headers |
|
| 1287 | + * |
|
| 1288 | + * @access public |
|
| 1289 | + * @param $headers |
|
| 1290 | + * @return array |
|
| 1291 | + */ |
|
| 1292 | + public static function extra_nocache_headers($headers) |
|
| 1293 | + { |
|
| 1294 | + // for NGINX |
|
| 1295 | + $headers['X-Accel-Expires'] = 0; |
|
| 1296 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1297 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1298 | + return $headers; |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * nocache_headers |
|
| 1304 | + * |
|
| 1305 | + * @access public |
|
| 1306 | + * @return void |
|
| 1307 | + */ |
|
| 1308 | + public static function nocache_headers() |
|
| 1309 | + { |
|
| 1310 | + nocache_headers(); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + |
|
| 1314 | + /** |
|
| 1315 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1316 | + * never returned with the function. |
|
| 1317 | + * |
|
| 1318 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1319 | + * @return array |
|
| 1320 | + */ |
|
| 1321 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1322 | + { |
|
| 1323 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1324 | + } |
|
| 1325 | + |
|
| 1326 | + |
|
| 1327 | + /** |
|
| 1328 | + * Return whether blocks can be registered/loaded or not. |
|
| 1329 | + * @return bool |
|
| 1330 | + */ |
|
| 1331 | + private function canLoadBlocks() |
|
| 1332 | + { |
|
| 1333 | + return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
| 1334 | + && function_exists('register_block_type') |
|
| 1335 | + // don't load blocks if in the Divi page builder editor context |
|
| 1336 | + // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
| 1337 | + && ! $this->request->getRequestParam('et_fb', false); |
|
| 1338 | + } |
|
| 1339 | 1339 | } |
@@ -31,557 +31,557 @@ |
||
| 31 | 31 | class CoreAssetManager extends AssetManager |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - // WordPress core / Third party JS asset handles |
|
| 35 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
| 34 | + // WordPress core / Third party JS asset handles |
|
| 35 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
| 36 | 36 | |
| 37 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
| 37 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
| 38 | 38 | |
| 39 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
| 39 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
| 40 | 40 | |
| 41 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
| 41 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
| 42 | 42 | |
| 43 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
| 43 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @since 4.9.71.p |
|
| 47 | - */ |
|
| 48 | - const JS_HANDLE_REACT = 'react'; |
|
| 45 | + /** |
|
| 46 | + * @since 4.9.71.p |
|
| 47 | + */ |
|
| 48 | + const JS_HANDLE_REACT = 'react'; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @since 4.9.71.p |
|
| 52 | - */ |
|
| 53 | - const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
| 50 | + /** |
|
| 51 | + * @since 4.9.71.p |
|
| 52 | + */ |
|
| 53 | + const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @since 4.9.71.p |
|
| 57 | - */ |
|
| 58 | - const JS_HANDLE_LODASH = 'lodash'; |
|
| 55 | + /** |
|
| 56 | + * @since 4.9.71.p |
|
| 57 | + */ |
|
| 58 | + const JS_HANDLE_LODASH = 'lodash'; |
|
| 59 | 59 | |
| 60 | - // EE JS assets handles |
|
| 61 | - const JS_HANDLE_MANIFEST = 'ee-manifest'; |
|
| 60 | + // EE JS assets handles |
|
| 61 | + const JS_HANDLE_MANIFEST = 'ee-manifest'; |
|
| 62 | 62 | |
| 63 | - const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
| 63 | + const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
| 64 | 64 | |
| 65 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
| 65 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
| 66 | 66 | |
| 67 | - const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores'; |
|
| 67 | + const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores'; |
|
| 68 | 68 | |
| 69 | - const JS_HANDLE_HELPERS = 'eventespresso-helpers'; |
|
| 69 | + const JS_HANDLE_HELPERS = 'eventespresso-helpers'; |
|
| 70 | 70 | |
| 71 | - const JS_HANDLE_MODEL = 'eventespresso-model'; |
|
| 71 | + const JS_HANDLE_MODEL = 'eventespresso-model'; |
|
| 72 | 72 | |
| 73 | - const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects'; |
|
| 73 | + const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects'; |
|
| 74 | 74 | |
| 75 | - const JS_HANDLE_HOCS = 'eventespresso-hocs'; |
|
| 75 | + const JS_HANDLE_HOCS = 'eventespresso-hocs'; |
|
| 76 | 76 | |
| 77 | - const JS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
| 78 | - |
|
| 79 | - const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs'; |
|
| 77 | + const JS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
| 78 | + |
|
| 79 | + const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs'; |
|
| 80 | 80 | |
| 81 | - const JS_HANDLE_VALIDATORS = 'eventespresso-validators'; |
|
| 81 | + const JS_HANDLE_VALIDATORS = 'eventespresso-validators'; |
|
| 82 | 82 | |
| 83 | - const JS_HANDLE_CORE = 'espresso_core'; |
|
| 83 | + const JS_HANDLE_CORE = 'espresso_core'; |
|
| 84 | 84 | |
| 85 | - const JS_HANDLE_I18N = 'eei18n'; |
|
| 86 | - |
|
| 87 | - const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
| 88 | - |
|
| 89 | - const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
| 90 | - |
|
| 91 | - // EE CSS assets handles |
|
| 92 | - const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
| 93 | - |
|
| 94 | - const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
| 95 | - |
|
| 96 | - const CSS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var EE_Currency_Config $currency_config |
|
| 100 | - */ |
|
| 101 | - protected $currency_config; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @var EE_Template_Config $template_config |
|
| 105 | - */ |
|
| 106 | - protected $template_config; |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * CoreAssetRegister constructor. |
|
| 111 | - * |
|
| 112 | - * @param AssetCollection $assets |
|
| 113 | - * @param EE_Currency_Config $currency_config |
|
| 114 | - * @param EE_Template_Config $template_config |
|
| 115 | - * @param DomainInterface $domain |
|
| 116 | - * @param Registry $registry |
|
| 117 | - */ |
|
| 118 | - public function __construct( |
|
| 119 | - AssetCollection $assets, |
|
| 120 | - EE_Currency_Config $currency_config, |
|
| 121 | - EE_Template_Config $template_config, |
|
| 122 | - DomainInterface $domain, |
|
| 123 | - Registry $registry |
|
| 124 | - ) { |
|
| 125 | - $this->currency_config = $currency_config; |
|
| 126 | - $this->template_config = $template_config; |
|
| 127 | - parent::__construct($domain, $assets, $registry); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @since 4.9.62.p |
|
| 133 | - * @throws DomainException |
|
| 134 | - * @throws DuplicateCollectionIdentifierException |
|
| 135 | - * @throws InvalidArgumentException |
|
| 136 | - * @throws InvalidDataTypeException |
|
| 137 | - * @throws InvalidEntityException |
|
| 138 | - * @throws InvalidInterfaceException |
|
| 139 | - */ |
|
| 140 | - public function addAssets() |
|
| 141 | - { |
|
| 142 | - $this->addJavascriptFiles(); |
|
| 143 | - $this->addStylesheetFiles(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @since 4.9.62.p |
|
| 149 | - * @throws DomainException |
|
| 150 | - * @throws DuplicateCollectionIdentifierException |
|
| 151 | - * @throws InvalidArgumentException |
|
| 152 | - * @throws InvalidDataTypeException |
|
| 153 | - * @throws InvalidEntityException |
|
| 154 | - * @throws InvalidInterfaceException |
|
| 155 | - */ |
|
| 156 | - public function addJavascriptFiles() |
|
| 157 | - { |
|
| 158 | - $this->loadCoreJs(); |
|
| 159 | - $this->loadJqueryValidate(); |
|
| 160 | - $this->loadAccountingJs(); |
|
| 161 | - add_action( |
|
| 162 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 163 | - array($this, 'loadQtipJs') |
|
| 164 | - ); |
|
| 165 | - $this->registerAdminAssets(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @since 4.9.62.p |
|
| 171 | - * @throws DuplicateCollectionIdentifierException |
|
| 172 | - * @throws InvalidDataTypeException |
|
| 173 | - * @throws InvalidEntityException |
|
| 174 | - */ |
|
| 175 | - public function addStylesheetFiles() |
|
| 176 | - { |
|
| 177 | - $this->loadCoreCss(); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * core default javascript |
|
| 183 | - * |
|
| 184 | - * @since 4.9.62.p |
|
| 185 | - * @throws DomainException |
|
| 186 | - * @throws DuplicateCollectionIdentifierException |
|
| 187 | - * @throws InvalidArgumentException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidEntityException |
|
| 190 | - * @throws InvalidInterfaceException |
|
| 191 | - */ |
|
| 192 | - private function loadCoreJs() |
|
| 193 | - { |
|
| 194 | - // conditionally load third-party libraries that WP core MIGHT have. |
|
| 195 | - $this->registerWpAssets(); |
|
| 196 | - |
|
| 197 | - $this->addJavascript( |
|
| 198 | - CoreAssetManager::JS_HANDLE_MANIFEST, |
|
| 199 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
| 200 | - ); |
|
| 201 | - |
|
| 202 | - $this->addJavascript( |
|
| 203 | - CoreAssetManager::JS_HANDLE_JS_CORE, |
|
| 204 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
| 205 | - array(CoreAssetManager::JS_HANDLE_MANIFEST) |
|
| 206 | - ) |
|
| 207 | - ->setHasInlineData(); |
|
| 208 | - |
|
| 209 | - $this->addJavascript( |
|
| 210 | - CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 211 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'), |
|
| 212 | - array( |
|
| 213 | - CoreAssetManager::JS_HANDLE_JS_CORE, |
|
| 214 | - CoreAssetManager::JS_HANDLE_REACT, |
|
| 215 | - CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
| 216 | - CoreAssetManager::JS_HANDLE_LODASH, |
|
| 217 | - ) |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - $this->addJavascript( |
|
| 221 | - CoreAssetManager::JS_HANDLE_VALIDATORS, |
|
| 222 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'validators') |
|
| 223 | - )->setRequiresTranslation(); |
|
| 224 | - |
|
| 225 | - $this->addJavascript( |
|
| 226 | - CoreAssetManager::JS_HANDLE_HELPERS, |
|
| 227 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers'), |
|
| 228 | - array( |
|
| 229 | - CoreAssetManager::JS_HANDLE_VALIDATORS |
|
| 230 | - ) |
|
| 231 | - )->setRequiresTranslation(); |
|
| 232 | - |
|
| 233 | - $this->addJavascript( |
|
| 234 | - CoreAssetManager::JS_HANDLE_MODEL, |
|
| 235 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'), |
|
| 236 | - array( |
|
| 237 | - CoreAssetManager::JS_HANDLE_HELPERS, |
|
| 238 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 239 | - ) |
|
| 240 | - )->setRequiresTranslation(); |
|
| 241 | - |
|
| 242 | - $this->addJavascript( |
|
| 243 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 244 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'), |
|
| 245 | - array( |
|
| 246 | - CoreAssetManager::JS_HANDLE_VALIDATORS, |
|
| 247 | - CoreAssetManager::JS_HANDLE_HELPERS, |
|
| 248 | - ) |
|
| 249 | - )->setRequiresTranslation(); |
|
| 250 | - |
|
| 251 | - $this->addJavascript( |
|
| 252 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 253 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'), |
|
| 254 | - array( |
|
| 255 | - CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 256 | - 'wp-data', |
|
| 257 | - 'wp-api-fetch', |
|
| 258 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 259 | - CoreAssetManager::JS_HANDLE_MODEL, |
|
| 260 | - ) |
|
| 261 | - ) |
|
| 262 | - ->setRequiresTranslation() |
|
| 263 | - ->setInlineDataCallback( |
|
| 264 | - function() { |
|
| 265 | - wp_add_inline_script( |
|
| 266 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 267 | - is_admin() |
|
| 268 | - ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )' |
|
| 269 | - : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )' |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - ); |
|
| 273 | - |
|
| 274 | - $this->addJavascript( |
|
| 275 | - CoreAssetManager::JS_HANDLE_HOCS, |
|
| 276 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocs'), |
|
| 277 | - array( |
|
| 278 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 279 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 280 | - 'wp-components', |
|
| 281 | - ) |
|
| 282 | - )->setRequiresTranslation(); |
|
| 283 | - |
|
| 284 | - $this->addJavascript( |
|
| 285 | - CoreAssetManager::JS_HANDLE_COMPONENTS, |
|
| 286 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'), |
|
| 287 | - array( |
|
| 288 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 289 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 290 | - 'wp-components', |
|
| 291 | - ) |
|
| 292 | - ) |
|
| 293 | - ->setRequiresTranslation(); |
|
| 294 | - |
|
| 295 | - $this->addJavascript( |
|
| 296 | - CoreAssetManager::JS_HANDLE_EDITOR_HOCS, |
|
| 297 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'editor-hocs'), |
|
| 298 | - array( |
|
| 299 | - CoreAssetManager::JS_HANDLE_COMPONENTS |
|
| 300 | - ) |
|
| 301 | - )->setRequiresTranslation(); |
|
| 302 | - |
|
| 303 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
| 304 | - $this->registry->addData( |
|
| 305 | - 'paths', |
|
| 306 | - array( |
|
| 307 | - 'base_rest_route' => rest_url(), |
|
| 308 | - 'rest_route' => rest_url('ee/v4.8.36/'), |
|
| 309 | - 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
| 310 | - 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
| 311 | - 'site_url' => site_url('/'), |
|
| 312 | - 'admin_url' => admin_url('/'), |
|
| 313 | - ) |
|
| 314 | - ); |
|
| 315 | - /** site formatting values **/ |
|
| 316 | - $this->registry->addData( |
|
| 317 | - 'site_formats', |
|
| 318 | - array( |
|
| 319 | - 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
| 320 | - ) |
|
| 321 | - ); |
|
| 322 | - /** currency data **/ |
|
| 323 | - $this->registry->addData( |
|
| 324 | - 'currency_config', |
|
| 325 | - $this->getCurrencySettings() |
|
| 326 | - ); |
|
| 327 | - /** site timezone */ |
|
| 328 | - $this->registry->addData( |
|
| 329 | - 'default_timezone', |
|
| 330 | - array( |
|
| 331 | - 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
| 332 | - 'string' => get_option('timezone_string'), |
|
| 333 | - 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
| 334 | - ) |
|
| 335 | - ); |
|
| 336 | - /** site locale (user locale if user logged in) */ |
|
| 337 | - $this->registry->addData( |
|
| 338 | - 'locale', |
|
| 339 | - array( |
|
| 340 | - 'user' => get_user_locale(), |
|
| 341 | - 'site' => get_locale() |
|
| 342 | - ) |
|
| 343 | - ); |
|
| 344 | - |
|
| 345 | - $this->addJavascript( |
|
| 346 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 347 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 348 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 349 | - ) |
|
| 350 | - ->setInlineDataCallback( |
|
| 351 | - function () { |
|
| 352 | - wp_localize_script( |
|
| 353 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 354 | - CoreAssetManager::JS_HANDLE_I18N, |
|
| 355 | - EE_Registry::$i18n_js_strings |
|
| 356 | - ); |
|
| 357 | - } |
|
| 358 | - ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Registers vendor files that are bundled with a later version WP but might not be for the current version of |
|
| 364 | - * WordPress in the running environment. |
|
| 365 | - * |
|
| 366 | - * @throws DuplicateCollectionIdentifierException |
|
| 367 | - * @throws InvalidDataTypeException |
|
| 368 | - * @throws InvalidEntityException |
|
| 369 | - * @throws DomainException |
|
| 370 | - * @since 4.9.71.p |
|
| 371 | - */ |
|
| 372 | - private function registerWpAssets() |
|
| 373 | - { |
|
| 374 | - global $wp_version; |
|
| 375 | - if (version_compare($wp_version, '5.0.beta', '>=')) { |
|
| 376 | - return; |
|
| 377 | - } |
|
| 378 | - $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT) |
|
| 379 | - ->setVersion('16.6.0'); |
|
| 380 | - $this->addVendorJavascript( |
|
| 381 | - CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
| 382 | - array(CoreAssetManager::JS_HANDLE_REACT) |
|
| 383 | - )->setVersion('16.6.0'); |
|
| 384 | - $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH) |
|
| 385 | - ->setInlineDataCallback( |
|
| 386 | - function() { |
|
| 387 | - wp_add_inline_script( |
|
| 388 | - CoreAssetManager::JS_HANDLE_LODASH, |
|
| 389 | - 'window.lodash = _.noConflict();' |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - ) |
|
| 393 | - ->setVersion('4.17.11'); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Returns configuration data for the accounting-js library. |
|
| 399 | - * @since 4.9.71.p |
|
| 400 | - * @return array |
|
| 401 | - */ |
|
| 402 | - private function getAccountingSettings() { |
|
| 403 | - return array( |
|
| 404 | - 'currency' => array( |
|
| 405 | - 'symbol' => $this->currency_config->sign, |
|
| 406 | - 'format' => array( |
|
| 407 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 408 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 409 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 410 | - ), |
|
| 411 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 412 | - 'thousand' => $this->currency_config->thsnds, |
|
| 413 | - 'precision' => $this->currency_config->dec_plc, |
|
| 414 | - ), |
|
| 415 | - 'number' => array( |
|
| 416 | - 'precision' => $this->currency_config->dec_plc, |
|
| 417 | - 'thousand' => $this->currency_config->thsnds, |
|
| 418 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 419 | - ), |
|
| 420 | - ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Returns configuration data for the js Currency VO. |
|
| 426 | - * @since 4.9.71.p |
|
| 427 | - * @return array |
|
| 428 | - */ |
|
| 429 | - private function getCurrencySettings() |
|
| 430 | - { |
|
| 431 | - return array( |
|
| 432 | - 'code' => $this->currency_config->code, |
|
| 433 | - 'singularLabel' => $this->currency_config->name, |
|
| 434 | - 'pluralLabel' => $this->currency_config->plural, |
|
| 435 | - 'sign' => $this->currency_config->sign, |
|
| 436 | - 'signB4' => $this->currency_config->sign_b4, |
|
| 437 | - 'decimalPlaces' => $this->currency_config->dec_plc, |
|
| 438 | - 'decimalMark' => $this->currency_config->dec_mrk, |
|
| 439 | - 'thousandsSeparator' => $this->currency_config->thsnds, |
|
| 440 | - ); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * @since 4.9.62.p |
|
| 446 | - * @throws DuplicateCollectionIdentifierException |
|
| 447 | - * @throws InvalidDataTypeException |
|
| 448 | - * @throws InvalidEntityException |
|
| 449 | - */ |
|
| 450 | - private function loadCoreCss() |
|
| 451 | - { |
|
| 452 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 453 | - $this->addStylesheet( |
|
| 454 | - CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
| 455 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 456 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 457 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 458 | - array('dashicons') |
|
| 459 | - ); |
|
| 460 | - //Load custom style sheet if available |
|
| 461 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 462 | - $this->addStylesheet( |
|
| 463 | - CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
| 464 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 465 | - array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
| 466 | - ); |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - $this->addStylesheet( |
|
| 470 | - CoreAssetManager::CSS_HANDLE_COMPONENTS, |
|
| 471 | - $this->registry->getCssUrl( |
|
| 472 | - $this->domain->assetNamespace(), |
|
| 473 | - 'components' |
|
| 474 | - ) |
|
| 475 | - ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * jQuery Validate for form validation |
|
| 481 | - * |
|
| 482 | - * @since 4.9.62.p |
|
| 483 | - * @throws DomainException |
|
| 484 | - * @throws DuplicateCollectionIdentifierException |
|
| 485 | - * @throws InvalidDataTypeException |
|
| 486 | - * @throws InvalidEntityException |
|
| 487 | - */ |
|
| 488 | - private function loadJqueryValidate() |
|
| 489 | - { |
|
| 490 | - $this->addJavascript( |
|
| 491 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
| 492 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 493 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 494 | - ) |
|
| 495 | - ->setVersion('1.15.0'); |
|
| 496 | - |
|
| 497 | - $this->addJavascript( |
|
| 498 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
| 499 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 500 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
| 501 | - ) |
|
| 502 | - ->setVersion('1.15.0'); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * accounting.js for performing client-side calculations |
|
| 508 | - * |
|
| 509 | - * @since 4.9.62.p |
|
| 510 | - * @throws DomainException |
|
| 511 | - * @throws DuplicateCollectionIdentifierException |
|
| 512 | - * @throws InvalidDataTypeException |
|
| 513 | - * @throws InvalidEntityException |
|
| 514 | - */ |
|
| 515 | - private function loadAccountingJs() |
|
| 516 | - { |
|
| 517 | - //accounting.js library |
|
| 518 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 519 | - $this->addJavascript( |
|
| 520 | - CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
| 521 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 522 | - array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
| 523 | - ) |
|
| 524 | - ->setVersion('0.3.2'); |
|
| 525 | - |
|
| 526 | - $this->addJavascript( |
|
| 527 | - CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
| 528 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 529 | - array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
| 530 | - ) |
|
| 531 | - ->setInlineDataCallback( |
|
| 532 | - function () { |
|
| 533 | - wp_localize_script( |
|
| 534 | - CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
| 535 | - 'EE_ACCOUNTING_CFG', |
|
| 536 | - $this->getAccountingSettings() |
|
| 537 | - ); |
|
| 538 | - } |
|
| 539 | - ) |
|
| 540 | - ->setVersion(); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * registers assets for cleaning your ears |
|
| 546 | - * |
|
| 547 | - * @param JavascriptAsset $script |
|
| 548 | - */ |
|
| 549 | - public function loadQtipJs(JavascriptAsset $script) |
|
| 550 | - { |
|
| 551 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 552 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 553 | - if ( |
|
| 554 | - $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
| 555 | - && apply_filters('FHEE_load_qtip', false) |
|
| 556 | - ) { |
|
| 557 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * assets that are used in the WordPress admin |
|
| 564 | - * |
|
| 565 | - * @since 4.9.62.p |
|
| 566 | - * @throws DuplicateCollectionIdentifierException |
|
| 567 | - * @throws InvalidDataTypeException |
|
| 568 | - * @throws InvalidEntityException |
|
| 569 | - */ |
|
| 570 | - private function registerAdminAssets() |
|
| 571 | - { |
|
| 572 | - $this->addJavascript( |
|
| 573 | - CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
| 574 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
| 575 | - array( |
|
| 576 | - CoreAssetManager::JS_HANDLE_JQUERY, |
|
| 577 | - CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 578 | - ) |
|
| 579 | - ) |
|
| 580 | - ->setRequiresTranslation(); |
|
| 581 | - |
|
| 582 | - $this->addStylesheet( |
|
| 583 | - CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
| 584 | - $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
| 585 | - ); |
|
| 586 | - } |
|
| 85 | + const JS_HANDLE_I18N = 'eei18n'; |
|
| 86 | + |
|
| 87 | + const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
| 88 | + |
|
| 89 | + const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
| 90 | + |
|
| 91 | + // EE CSS assets handles |
|
| 92 | + const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
| 93 | + |
|
| 94 | + const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
| 95 | + |
|
| 96 | + const CSS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @var EE_Currency_Config $currency_config |
|
| 100 | + */ |
|
| 101 | + protected $currency_config; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @var EE_Template_Config $template_config |
|
| 105 | + */ |
|
| 106 | + protected $template_config; |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * CoreAssetRegister constructor. |
|
| 111 | + * |
|
| 112 | + * @param AssetCollection $assets |
|
| 113 | + * @param EE_Currency_Config $currency_config |
|
| 114 | + * @param EE_Template_Config $template_config |
|
| 115 | + * @param DomainInterface $domain |
|
| 116 | + * @param Registry $registry |
|
| 117 | + */ |
|
| 118 | + public function __construct( |
|
| 119 | + AssetCollection $assets, |
|
| 120 | + EE_Currency_Config $currency_config, |
|
| 121 | + EE_Template_Config $template_config, |
|
| 122 | + DomainInterface $domain, |
|
| 123 | + Registry $registry |
|
| 124 | + ) { |
|
| 125 | + $this->currency_config = $currency_config; |
|
| 126 | + $this->template_config = $template_config; |
|
| 127 | + parent::__construct($domain, $assets, $registry); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @since 4.9.62.p |
|
| 133 | + * @throws DomainException |
|
| 134 | + * @throws DuplicateCollectionIdentifierException |
|
| 135 | + * @throws InvalidArgumentException |
|
| 136 | + * @throws InvalidDataTypeException |
|
| 137 | + * @throws InvalidEntityException |
|
| 138 | + * @throws InvalidInterfaceException |
|
| 139 | + */ |
|
| 140 | + public function addAssets() |
|
| 141 | + { |
|
| 142 | + $this->addJavascriptFiles(); |
|
| 143 | + $this->addStylesheetFiles(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @since 4.9.62.p |
|
| 149 | + * @throws DomainException |
|
| 150 | + * @throws DuplicateCollectionIdentifierException |
|
| 151 | + * @throws InvalidArgumentException |
|
| 152 | + * @throws InvalidDataTypeException |
|
| 153 | + * @throws InvalidEntityException |
|
| 154 | + * @throws InvalidInterfaceException |
|
| 155 | + */ |
|
| 156 | + public function addJavascriptFiles() |
|
| 157 | + { |
|
| 158 | + $this->loadCoreJs(); |
|
| 159 | + $this->loadJqueryValidate(); |
|
| 160 | + $this->loadAccountingJs(); |
|
| 161 | + add_action( |
|
| 162 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 163 | + array($this, 'loadQtipJs') |
|
| 164 | + ); |
|
| 165 | + $this->registerAdminAssets(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @since 4.9.62.p |
|
| 171 | + * @throws DuplicateCollectionIdentifierException |
|
| 172 | + * @throws InvalidDataTypeException |
|
| 173 | + * @throws InvalidEntityException |
|
| 174 | + */ |
|
| 175 | + public function addStylesheetFiles() |
|
| 176 | + { |
|
| 177 | + $this->loadCoreCss(); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * core default javascript |
|
| 183 | + * |
|
| 184 | + * @since 4.9.62.p |
|
| 185 | + * @throws DomainException |
|
| 186 | + * @throws DuplicateCollectionIdentifierException |
|
| 187 | + * @throws InvalidArgumentException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidEntityException |
|
| 190 | + * @throws InvalidInterfaceException |
|
| 191 | + */ |
|
| 192 | + private function loadCoreJs() |
|
| 193 | + { |
|
| 194 | + // conditionally load third-party libraries that WP core MIGHT have. |
|
| 195 | + $this->registerWpAssets(); |
|
| 196 | + |
|
| 197 | + $this->addJavascript( |
|
| 198 | + CoreAssetManager::JS_HANDLE_MANIFEST, |
|
| 199 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
| 200 | + ); |
|
| 201 | + |
|
| 202 | + $this->addJavascript( |
|
| 203 | + CoreAssetManager::JS_HANDLE_JS_CORE, |
|
| 204 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
| 205 | + array(CoreAssetManager::JS_HANDLE_MANIFEST) |
|
| 206 | + ) |
|
| 207 | + ->setHasInlineData(); |
|
| 208 | + |
|
| 209 | + $this->addJavascript( |
|
| 210 | + CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 211 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'), |
|
| 212 | + array( |
|
| 213 | + CoreAssetManager::JS_HANDLE_JS_CORE, |
|
| 214 | + CoreAssetManager::JS_HANDLE_REACT, |
|
| 215 | + CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
| 216 | + CoreAssetManager::JS_HANDLE_LODASH, |
|
| 217 | + ) |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + $this->addJavascript( |
|
| 221 | + CoreAssetManager::JS_HANDLE_VALIDATORS, |
|
| 222 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'validators') |
|
| 223 | + )->setRequiresTranslation(); |
|
| 224 | + |
|
| 225 | + $this->addJavascript( |
|
| 226 | + CoreAssetManager::JS_HANDLE_HELPERS, |
|
| 227 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers'), |
|
| 228 | + array( |
|
| 229 | + CoreAssetManager::JS_HANDLE_VALIDATORS |
|
| 230 | + ) |
|
| 231 | + )->setRequiresTranslation(); |
|
| 232 | + |
|
| 233 | + $this->addJavascript( |
|
| 234 | + CoreAssetManager::JS_HANDLE_MODEL, |
|
| 235 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'), |
|
| 236 | + array( |
|
| 237 | + CoreAssetManager::JS_HANDLE_HELPERS, |
|
| 238 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 239 | + ) |
|
| 240 | + )->setRequiresTranslation(); |
|
| 241 | + |
|
| 242 | + $this->addJavascript( |
|
| 243 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 244 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'), |
|
| 245 | + array( |
|
| 246 | + CoreAssetManager::JS_HANDLE_VALIDATORS, |
|
| 247 | + CoreAssetManager::JS_HANDLE_HELPERS, |
|
| 248 | + ) |
|
| 249 | + )->setRequiresTranslation(); |
|
| 250 | + |
|
| 251 | + $this->addJavascript( |
|
| 252 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 253 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'), |
|
| 254 | + array( |
|
| 255 | + CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 256 | + 'wp-data', |
|
| 257 | + 'wp-api-fetch', |
|
| 258 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 259 | + CoreAssetManager::JS_HANDLE_MODEL, |
|
| 260 | + ) |
|
| 261 | + ) |
|
| 262 | + ->setRequiresTranslation() |
|
| 263 | + ->setInlineDataCallback( |
|
| 264 | + function() { |
|
| 265 | + wp_add_inline_script( |
|
| 266 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 267 | + is_admin() |
|
| 268 | + ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )' |
|
| 269 | + : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )' |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + ); |
|
| 273 | + |
|
| 274 | + $this->addJavascript( |
|
| 275 | + CoreAssetManager::JS_HANDLE_HOCS, |
|
| 276 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocs'), |
|
| 277 | + array( |
|
| 278 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 279 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 280 | + 'wp-components', |
|
| 281 | + ) |
|
| 282 | + )->setRequiresTranslation(); |
|
| 283 | + |
|
| 284 | + $this->addJavascript( |
|
| 285 | + CoreAssetManager::JS_HANDLE_COMPONENTS, |
|
| 286 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'), |
|
| 287 | + array( |
|
| 288 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 289 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 290 | + 'wp-components', |
|
| 291 | + ) |
|
| 292 | + ) |
|
| 293 | + ->setRequiresTranslation(); |
|
| 294 | + |
|
| 295 | + $this->addJavascript( |
|
| 296 | + CoreAssetManager::JS_HANDLE_EDITOR_HOCS, |
|
| 297 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'editor-hocs'), |
|
| 298 | + array( |
|
| 299 | + CoreAssetManager::JS_HANDLE_COMPONENTS |
|
| 300 | + ) |
|
| 301 | + )->setRequiresTranslation(); |
|
| 302 | + |
|
| 303 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
| 304 | + $this->registry->addData( |
|
| 305 | + 'paths', |
|
| 306 | + array( |
|
| 307 | + 'base_rest_route' => rest_url(), |
|
| 308 | + 'rest_route' => rest_url('ee/v4.8.36/'), |
|
| 309 | + 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
| 310 | + 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
| 311 | + 'site_url' => site_url('/'), |
|
| 312 | + 'admin_url' => admin_url('/'), |
|
| 313 | + ) |
|
| 314 | + ); |
|
| 315 | + /** site formatting values **/ |
|
| 316 | + $this->registry->addData( |
|
| 317 | + 'site_formats', |
|
| 318 | + array( |
|
| 319 | + 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
| 320 | + ) |
|
| 321 | + ); |
|
| 322 | + /** currency data **/ |
|
| 323 | + $this->registry->addData( |
|
| 324 | + 'currency_config', |
|
| 325 | + $this->getCurrencySettings() |
|
| 326 | + ); |
|
| 327 | + /** site timezone */ |
|
| 328 | + $this->registry->addData( |
|
| 329 | + 'default_timezone', |
|
| 330 | + array( |
|
| 331 | + 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
| 332 | + 'string' => get_option('timezone_string'), |
|
| 333 | + 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
| 334 | + ) |
|
| 335 | + ); |
|
| 336 | + /** site locale (user locale if user logged in) */ |
|
| 337 | + $this->registry->addData( |
|
| 338 | + 'locale', |
|
| 339 | + array( |
|
| 340 | + 'user' => get_user_locale(), |
|
| 341 | + 'site' => get_locale() |
|
| 342 | + ) |
|
| 343 | + ); |
|
| 344 | + |
|
| 345 | + $this->addJavascript( |
|
| 346 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 347 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 348 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 349 | + ) |
|
| 350 | + ->setInlineDataCallback( |
|
| 351 | + function () { |
|
| 352 | + wp_localize_script( |
|
| 353 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 354 | + CoreAssetManager::JS_HANDLE_I18N, |
|
| 355 | + EE_Registry::$i18n_js_strings |
|
| 356 | + ); |
|
| 357 | + } |
|
| 358 | + ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Registers vendor files that are bundled with a later version WP but might not be for the current version of |
|
| 364 | + * WordPress in the running environment. |
|
| 365 | + * |
|
| 366 | + * @throws DuplicateCollectionIdentifierException |
|
| 367 | + * @throws InvalidDataTypeException |
|
| 368 | + * @throws InvalidEntityException |
|
| 369 | + * @throws DomainException |
|
| 370 | + * @since 4.9.71.p |
|
| 371 | + */ |
|
| 372 | + private function registerWpAssets() |
|
| 373 | + { |
|
| 374 | + global $wp_version; |
|
| 375 | + if (version_compare($wp_version, '5.0.beta', '>=')) { |
|
| 376 | + return; |
|
| 377 | + } |
|
| 378 | + $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT) |
|
| 379 | + ->setVersion('16.6.0'); |
|
| 380 | + $this->addVendorJavascript( |
|
| 381 | + CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
| 382 | + array(CoreAssetManager::JS_HANDLE_REACT) |
|
| 383 | + )->setVersion('16.6.0'); |
|
| 384 | + $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH) |
|
| 385 | + ->setInlineDataCallback( |
|
| 386 | + function() { |
|
| 387 | + wp_add_inline_script( |
|
| 388 | + CoreAssetManager::JS_HANDLE_LODASH, |
|
| 389 | + 'window.lodash = _.noConflict();' |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + ) |
|
| 393 | + ->setVersion('4.17.11'); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Returns configuration data for the accounting-js library. |
|
| 399 | + * @since 4.9.71.p |
|
| 400 | + * @return array |
|
| 401 | + */ |
|
| 402 | + private function getAccountingSettings() { |
|
| 403 | + return array( |
|
| 404 | + 'currency' => array( |
|
| 405 | + 'symbol' => $this->currency_config->sign, |
|
| 406 | + 'format' => array( |
|
| 407 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 408 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 409 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 410 | + ), |
|
| 411 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 412 | + 'thousand' => $this->currency_config->thsnds, |
|
| 413 | + 'precision' => $this->currency_config->dec_plc, |
|
| 414 | + ), |
|
| 415 | + 'number' => array( |
|
| 416 | + 'precision' => $this->currency_config->dec_plc, |
|
| 417 | + 'thousand' => $this->currency_config->thsnds, |
|
| 418 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 419 | + ), |
|
| 420 | + ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Returns configuration data for the js Currency VO. |
|
| 426 | + * @since 4.9.71.p |
|
| 427 | + * @return array |
|
| 428 | + */ |
|
| 429 | + private function getCurrencySettings() |
|
| 430 | + { |
|
| 431 | + return array( |
|
| 432 | + 'code' => $this->currency_config->code, |
|
| 433 | + 'singularLabel' => $this->currency_config->name, |
|
| 434 | + 'pluralLabel' => $this->currency_config->plural, |
|
| 435 | + 'sign' => $this->currency_config->sign, |
|
| 436 | + 'signB4' => $this->currency_config->sign_b4, |
|
| 437 | + 'decimalPlaces' => $this->currency_config->dec_plc, |
|
| 438 | + 'decimalMark' => $this->currency_config->dec_mrk, |
|
| 439 | + 'thousandsSeparator' => $this->currency_config->thsnds, |
|
| 440 | + ); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * @since 4.9.62.p |
|
| 446 | + * @throws DuplicateCollectionIdentifierException |
|
| 447 | + * @throws InvalidDataTypeException |
|
| 448 | + * @throws InvalidEntityException |
|
| 449 | + */ |
|
| 450 | + private function loadCoreCss() |
|
| 451 | + { |
|
| 452 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 453 | + $this->addStylesheet( |
|
| 454 | + CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
| 455 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 456 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 457 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 458 | + array('dashicons') |
|
| 459 | + ); |
|
| 460 | + //Load custom style sheet if available |
|
| 461 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 462 | + $this->addStylesheet( |
|
| 463 | + CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
| 464 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 465 | + array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
| 466 | + ); |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + $this->addStylesheet( |
|
| 470 | + CoreAssetManager::CSS_HANDLE_COMPONENTS, |
|
| 471 | + $this->registry->getCssUrl( |
|
| 472 | + $this->domain->assetNamespace(), |
|
| 473 | + 'components' |
|
| 474 | + ) |
|
| 475 | + ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * jQuery Validate for form validation |
|
| 481 | + * |
|
| 482 | + * @since 4.9.62.p |
|
| 483 | + * @throws DomainException |
|
| 484 | + * @throws DuplicateCollectionIdentifierException |
|
| 485 | + * @throws InvalidDataTypeException |
|
| 486 | + * @throws InvalidEntityException |
|
| 487 | + */ |
|
| 488 | + private function loadJqueryValidate() |
|
| 489 | + { |
|
| 490 | + $this->addJavascript( |
|
| 491 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
| 492 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 493 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 494 | + ) |
|
| 495 | + ->setVersion('1.15.0'); |
|
| 496 | + |
|
| 497 | + $this->addJavascript( |
|
| 498 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
| 499 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 500 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
| 501 | + ) |
|
| 502 | + ->setVersion('1.15.0'); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * accounting.js for performing client-side calculations |
|
| 508 | + * |
|
| 509 | + * @since 4.9.62.p |
|
| 510 | + * @throws DomainException |
|
| 511 | + * @throws DuplicateCollectionIdentifierException |
|
| 512 | + * @throws InvalidDataTypeException |
|
| 513 | + * @throws InvalidEntityException |
|
| 514 | + */ |
|
| 515 | + private function loadAccountingJs() |
|
| 516 | + { |
|
| 517 | + //accounting.js library |
|
| 518 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 519 | + $this->addJavascript( |
|
| 520 | + CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
| 521 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 522 | + array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
| 523 | + ) |
|
| 524 | + ->setVersion('0.3.2'); |
|
| 525 | + |
|
| 526 | + $this->addJavascript( |
|
| 527 | + CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
| 528 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 529 | + array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
| 530 | + ) |
|
| 531 | + ->setInlineDataCallback( |
|
| 532 | + function () { |
|
| 533 | + wp_localize_script( |
|
| 534 | + CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
| 535 | + 'EE_ACCOUNTING_CFG', |
|
| 536 | + $this->getAccountingSettings() |
|
| 537 | + ); |
|
| 538 | + } |
|
| 539 | + ) |
|
| 540 | + ->setVersion(); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * registers assets for cleaning your ears |
|
| 546 | + * |
|
| 547 | + * @param JavascriptAsset $script |
|
| 548 | + */ |
|
| 549 | + public function loadQtipJs(JavascriptAsset $script) |
|
| 550 | + { |
|
| 551 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 552 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 553 | + if ( |
|
| 554 | + $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
| 555 | + && apply_filters('FHEE_load_qtip', false) |
|
| 556 | + ) { |
|
| 557 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * assets that are used in the WordPress admin |
|
| 564 | + * |
|
| 565 | + * @since 4.9.62.p |
|
| 566 | + * @throws DuplicateCollectionIdentifierException |
|
| 567 | + * @throws InvalidDataTypeException |
|
| 568 | + * @throws InvalidEntityException |
|
| 569 | + */ |
|
| 570 | + private function registerAdminAssets() |
|
| 571 | + { |
|
| 572 | + $this->addJavascript( |
|
| 573 | + CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
| 574 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
| 575 | + array( |
|
| 576 | + CoreAssetManager::JS_HANDLE_JQUERY, |
|
| 577 | + CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 578 | + ) |
|
| 579 | + ) |
|
| 580 | + ->setRequiresTranslation(); |
|
| 581 | + |
|
| 582 | + $this->addStylesheet( |
|
| 583 | + CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
| 584 | + $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
| 585 | + ); |
|
| 586 | + } |
|
| 587 | 587 | } |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | <a id="display-additional-transaction-session-info" class="display-the-hidden smaller-text" |
| 16 | 16 | rel="additional-transaction-session-info"> |
| 17 | 17 | <span class="dashicons dashicons-plus-alt"></span><?php esc_html_e( |
| 18 | - 'view additional transaction session details', |
|
| 19 | - 'event_espresso' |
|
| 20 | - ); ?> |
|
| 18 | + 'view additional transaction session details', |
|
| 19 | + 'event_espresso' |
|
| 20 | + ); ?> |
|
| 21 | 21 | </a> |
| 22 | 22 | |
| 23 | 23 | <div id="additional-transaction-session-info-dv" class="hidden"> |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | <a id="hide-additional-transaction-session-info" class="hide-the-displayed hidden smaller-text" |
| 26 | 26 | rel="additional-transaction-session-info"> |
| 27 | 27 | <span class="dashicons dashicons-dismiss"></span><?php esc_html_e( |
| 28 | - 'hide additional transaction session details', |
|
| 29 | - 'event_espresso' |
|
| 30 | - ); ?> |
|
| 28 | + 'hide additional transaction session details', |
|
| 29 | + 'event_espresso' |
|
| 30 | + ); ?> |
|
| 31 | 31 | </a> |
| 32 | 32 | <br class="clear"/> |
| 33 | 33 | |
@@ -52,16 +52,16 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | |
| 54 | 54 | <?php if ($attendee instanceof EE_Attendee && ($grand_raw_total > 0 || $TXN_status !== EEM_Transaction::complete_status_code || ! empty($payments))) : |
| 55 | - $no_payment_text = $can_edit_payments |
|
| 56 | - ? esc_html__( |
|
| 57 | - 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
| 58 | - 'event_espresso' |
|
| 59 | - ) |
|
| 60 | - : esc_html__( |
|
| 61 | - 'No payments have been applied to this transaction yet.', |
|
| 62 | - 'event_espresso' |
|
| 63 | - ); |
|
| 64 | - ?> |
|
| 55 | + $no_payment_text = $can_edit_payments |
|
| 56 | + ? esc_html__( |
|
| 57 | + 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
| 58 | + 'event_espresso' |
|
| 59 | + ) |
|
| 60 | + : esc_html__( |
|
| 61 | + 'No payments have been applied to this transaction yet.', |
|
| 62 | + 'event_espresso' |
|
| 63 | + ); |
|
| 64 | + ?> |
|
| 65 | 65 | |
| 66 | 66 | <h3 class="admin-primary-mbox-h4 hdr-has-icon"> |
| 67 | 67 | <span class="ee-icon ee-icon-cash"></span><?php esc_html_e('Payment Details', 'event_espresso'); ?> |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | <?php if ($payments) : ?> |
| 89 | 89 | <?php $payment_total = 0; ?> |
| 90 | 90 | <?php foreach ($payments as $PAY_ID => $payment) : |
| 91 | - $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ]) |
|
| 92 | - ? wp_json_encode($existing_reg_payments[ $PAY_ID ]) |
|
| 93 | - : '{}'; |
|
| 94 | - ?> |
|
| 91 | + $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ]) |
|
| 92 | + ? wp_json_encode($existing_reg_payments[ $PAY_ID ]) |
|
| 93 | + : '{}'; |
|
| 94 | + ?> |
|
| 95 | 95 | <tr id="txn-admin-payment-tr-<?php echo $PAY_ID; ?>"> |
| 96 | 96 | <td> |
| 97 | 97 | <span id="payment-status-<?php echo $PAY_ID; ?>" |
@@ -136,16 +136,16 @@ discard block |
||
| 136 | 136 | </div> |
| 137 | 137 | <div id="payment-gateway-<?php echo $PAY_ID; ?>"> |
| 138 | 138 | <?php echo $payment->payment_method() |
| 139 | - ? $payment->payment_method()->admin_name() |
|
| 140 | - : esc_html__( |
|
| 141 | - "Unknown", |
|
| 142 | - 'event_espresso' |
|
| 143 | - ); ?> |
|
| 139 | + ? $payment->payment_method()->admin_name() |
|
| 140 | + : esc_html__( |
|
| 141 | + "Unknown", |
|
| 142 | + 'event_espresso' |
|
| 143 | + ); ?> |
|
| 144 | 144 | </div> |
| 145 | 145 | <div id="payment-gateway-id-<?php echo $PAY_ID; ?>" |
| 146 | 146 | class="hidden"><?php echo $payment->payment_method() |
| 147 | - ? $payment->payment_method()->ID() |
|
| 148 | - : 0; ?></div> |
|
| 147 | + ? $payment->payment_method()->ID() |
|
| 148 | + : 0; ?></div> |
|
| 149 | 149 | </td> |
| 150 | 150 | <td class=" jst-left"> |
| 151 | 151 | <div id="payment-response-<?php echo $PAY_ID; ?>"><?php echo $payment->gateway_response(); ?></div> |
@@ -162,29 +162,29 @@ discard block |
||
| 162 | 162 | </td> |
| 163 | 163 | <td class=" jst-rght"> |
| 164 | 164 | <?php $payment_class = $payment->amount() > 0 |
| 165 | - ? 'txn-admin-payment-status-' . $payment->STS_ID() |
|
| 166 | - : 'txn-admin-payment-status-PDC'; ?> |
|
| 165 | + ? 'txn-admin-payment-status-' . $payment->STS_ID() |
|
| 166 | + : 'txn-admin-payment-status-PDC'; ?> |
|
| 167 | 167 | <span class="<?php echo $payment_class; ?>"> |
| 168 | 168 | <div id="payment-amount-<?php echo $PAY_ID; ?>" style="display:inline;"> |
| 169 | 169 | <?php echo EEH_Template::format_currency( |
| 170 | - $payment->amount(), |
|
| 171 | - false, |
|
| 172 | - false |
|
| 173 | - ); ?></div> |
|
| 170 | + $payment->amount(), |
|
| 171 | + false, |
|
| 172 | + false |
|
| 173 | + ); ?></div> |
|
| 174 | 174 | </span> |
| 175 | 175 | </td> |
| 176 | 176 | </tr> |
| 177 | 177 | <?php |
| 178 | - $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; |
|
| 179 | - ?> |
|
| 178 | + $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; |
|
| 179 | + ?> |
|
| 180 | 180 | <?php endforeach; // $payment?> |
| 181 | 181 | <?php |
| 182 | - $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
|
| 183 | - $overpaid = $payment_total > $grand_raw_total |
|
| 184 | - ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', 'event_espresso') |
|
| 185 | - . '</span>' |
|
| 186 | - : ''; |
|
| 187 | - ?> |
|
| 182 | + $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
|
| 183 | + $overpaid = $payment_total > $grand_raw_total |
|
| 184 | + ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', 'event_espresso') |
|
| 185 | + . '</span>' |
|
| 186 | + : ''; |
|
| 187 | + ?> |
|
| 188 | 188 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
| 189 | 189 | <td class=" jst-rght" colspan="10"> |
| 190 | 190 | <span class="important-notice"><?php echo $no_payment_text; ?></span> |
@@ -195,20 +195,20 @@ discard block |
||
| 195 | 195 | <th class=" jst-rght" colspan="9"><span |
| 196 | 196 | id="payments-total-spn"> |
| 197 | 197 | <?php echo $overpaid |
| 198 | - . sprintf( |
|
| 199 | - esc_html__( |
|
| 200 | - 'Payments Total %s', |
|
| 201 | - 'event_espresso' |
|
| 202 | - ), |
|
| 203 | - '(' . EE_Registry::instance()->CFG->currency->code . ')' |
|
| 204 | - ); ?></span></th> |
|
| 198 | + . sprintf( |
|
| 199 | + esc_html__( |
|
| 200 | + 'Payments Total %s', |
|
| 201 | + 'event_espresso' |
|
| 202 | + ), |
|
| 203 | + '(' . EE_Registry::instance()->CFG->currency->code . ')' |
|
| 204 | + ); ?></span></th> |
|
| 205 | 205 | <th class=" jst-rght"><span |
| 206 | 206 | id="txn-admin-payment-total"> |
| 207 | 207 | <?php echo EEH_Template::format_currency( |
| 208 | - $payment_total, |
|
| 209 | - false, |
|
| 210 | - false |
|
| 211 | - ); ?></span></th> |
|
| 208 | + $payment_total, |
|
| 209 | + false, |
|
| 210 | + false |
|
| 211 | + ); ?></span></th> |
|
| 212 | 212 | </tr> |
| 213 | 213 | <?php else : ?> |
| 214 | 214 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | <th class=" jst-rght" colspan="9"><span |
| 221 | 221 | id="payments-total-spn"> |
| 222 | 222 | <?php echo esc_html__( |
| 223 | - 'Payments Total', |
|
| 224 | - 'event_espresso' |
|
| 225 | - ); ?></span></th> |
|
| 223 | + 'Payments Total', |
|
| 224 | + 'event_espresso' |
|
| 225 | + ); ?></span></th> |
|
| 226 | 226 | <th class=" jst-rght"><span id="txn-admin-payment-total"></span></th> |
| 227 | 227 | </tr> |
| 228 | 228 | <?php endif; // $payments |
| 229 | - ?> |
|
| 229 | + ?> |
|
| 230 | 230 | |
| 231 | 231 | <tr id="txn-admin-payment-empty-row-tr" class="hidden"> |
| 232 | 232 | <td> |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | |
| 292 | 292 | <ul id="txn-admin-payment-options-ul"> |
| 293 | 293 | <?php if ($can_edit_payments) : |
| 294 | - ?> |
|
| 294 | + ?> |
|
| 295 | 295 | <li> |
| 296 | 296 | <a id="display-txn-admin-apply-payment" class="button-primary no-icon no-hide" |
| 297 | 297 | rel="txn-admin-apply-payment"> <!--display-the-hidden --> |
@@ -308,9 +308,9 @@ discard block |
||
| 308 | 308 | <li> |
| 309 | 309 | <p> |
| 310 | 310 | <?php esc_html__( |
| 311 | - 'You do not have access to apply payments or refunds.', |
|
| 312 | - 'event_espresso' |
|
| 313 | - ); ?></p> |
|
| 311 | + 'You do not have access to apply payments or refunds.', |
|
| 312 | + 'event_espresso' |
|
| 313 | + ); ?></p> |
|
| 314 | 314 | </li> |
| 315 | 315 | <?php endif; ?> |
| 316 | 316 | </ul> |
@@ -328,23 +328,23 @@ discard block |
||
| 328 | 328 | style="display:none;"> |
| 329 | 329 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
| 330 | 330 | <?php |
| 331 | - echo sprintf( |
|
| 332 | - __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
| 333 | - '<span></span>', |
|
| 334 | - $txn_nmbr['value'] |
|
| 335 | - ); |
|
| 336 | - ?> |
|
| 331 | + echo sprintf( |
|
| 332 | + __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
| 333 | + '<span></span>', |
|
| 334 | + $txn_nmbr['value'] |
|
| 335 | + ); |
|
| 336 | + ?> |
|
| 337 | 337 | </h2> |
| 338 | 338 | |
| 339 | 339 | <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
| 340 | 340 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
| 341 | 341 | <?php |
| 342 | - echo sprintf( |
|
| 343 | - __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
| 344 | - '<span></span>', |
|
| 345 | - $txn_nmbr['value'] |
|
| 346 | - ); |
|
| 347 | - ?> |
|
| 342 | + echo sprintf( |
|
| 343 | + __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
| 344 | + '<span></span>', |
|
| 345 | + $txn_nmbr['value'] |
|
| 346 | + ); |
|
| 347 | + ?> |
|
| 348 | 348 | </h2> |
| 349 | 349 | |
| 350 | 350 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -378,55 +378,55 @@ discard block |
||
| 378 | 378 | <div class="txn-admin-apply-payment-date-dv admin-modal-dialog-row"> |
| 379 | 379 | <div class="validation-notice-dv"> |
| 380 | 380 | <?php esc_html_e( |
| 381 | - 'The following is a required field', |
|
| 382 | - 'event_espresso' |
|
| 383 | - ); ?></div> |
|
| 381 | + 'The following is a required field', |
|
| 382 | + 'event_espresso' |
|
| 383 | + ); ?></div> |
|
| 384 | 384 | <label for="txn-admin-payment-date-inp" class=""> |
| 385 | 385 | <?php esc_html_e( |
| 386 | - 'Payment Date', |
|
| 387 | - 'event_espresso' |
|
| 388 | - ); ?></label> |
|
| 386 | + 'Payment Date', |
|
| 387 | + 'event_espresso' |
|
| 388 | + ); ?></label> |
|
| 389 | 389 | <input name="txn_admin_payment[date]" id="txn-admin-payment-date-inp" |
| 390 | 390 | class="txn-admin-apply-payment-inp required" type="text" |
| 391 | 391 | value="<?php echo date('Y-m-d g:i a', current_time('timestamp')); ?>"/> |
| 392 | 392 | <p class="description"> |
| 393 | 393 | <?php esc_html_e( |
| 394 | - 'The date the payment was actually made on', |
|
| 395 | - 'event_espresso' |
|
| 396 | - ); ?></p> |
|
| 394 | + 'The date the payment was actually made on', |
|
| 395 | + 'event_espresso' |
|
| 396 | + ); ?></p> |
|
| 397 | 397 | </div> |
| 398 | 398 | |
| 399 | 399 | <div class="txn-admin-apply-payment-amount-dv admin-modal-dialog-row"> |
| 400 | 400 | <div class="validation-notice-dv"> |
| 401 | 401 | <?php esc_html_e( |
| 402 | - 'The following is a required field', |
|
| 403 | - 'event_espresso' |
|
| 404 | - ); ?></div> |
|
| 402 | + 'The following is a required field', |
|
| 403 | + 'event_espresso' |
|
| 404 | + ); ?></div> |
|
| 405 | 405 | <label for="txn-admin-payment-amount-inp" class=""> |
| 406 | 406 | <?php esc_html_e( |
| 407 | - 'Amount', |
|
| 408 | - 'event_espresso' |
|
| 409 | - ); ?></label> |
|
| 407 | + 'Amount', |
|
| 408 | + 'event_espresso' |
|
| 409 | + ); ?></label> |
|
| 410 | 410 | <input name="txn_admin_payment[amount]" id="txn-admin-payment-amount-inp" |
| 411 | 411 | class="txn-admin-apply-payment-inp required" type="text" value=""/> |
| 412 | 412 | <p class="description"> |
| 413 | 413 | <?php esc_html_e( |
| 414 | - 'The amount of the payment', |
|
| 415 | - 'event_espresso' |
|
| 416 | - ); ?></p> |
|
| 414 | + 'The amount of the payment', |
|
| 415 | + 'event_espresso' |
|
| 416 | + ); ?></p> |
|
| 417 | 417 | </div> |
| 418 | 418 | |
| 419 | 419 | <div class="txn-admin-apply-payment-method-dv admin-modal-dialog-row"> |
| 420 | 420 | <div class="validation-notice-dv"> |
| 421 | 421 | <?php esc_html_e( |
| 422 | - 'The following is a required field', |
|
| 423 | - 'event_espresso' |
|
| 424 | - ); ?></div> |
|
| 422 | + 'The following is a required field', |
|
| 423 | + 'event_espresso' |
|
| 424 | + ); ?></div> |
|
| 425 | 425 | <label for="txn-admin-payment-method-inp" class=""> |
| 426 | 426 | <?php esc_html_e( |
| 427 | - 'Method of Payment', |
|
| 428 | - 'event_espresso' |
|
| 429 | - ); ?></label> |
|
| 427 | + 'Method of Payment', |
|
| 428 | + 'event_espresso' |
|
| 429 | + ); ?></label> |
|
| 430 | 430 | <select name="txn_admin_payment[PMD_ID]" id="txn-admin-payment-method-slct" |
| 431 | 431 | class="txn-admin-apply-payment-slct required" type="text"> |
| 432 | 432 | <?php foreach ($payment_methods as $method) : ?> |
@@ -434,39 +434,39 @@ discard block |
||
| 434 | 434 | <option id="payment-method-opt-<?php echo $method->slug(); ?>" |
| 435 | 435 | value="<?php echo $method->ID(); ?>"<?php echo $selected; ?>> |
| 436 | 436 | <?php echo sanitize_key( |
| 437 | - $method->admin_desc() |
|
| 438 | - ) |
|
| 439 | - ? substr( |
|
| 440 | - $method->admin_desc(), |
|
| 441 | - 0, |
|
| 442 | - 128 |
|
| 443 | - ) |
|
| 444 | - : $method->admin_name(); ?> |
|
| 437 | + $method->admin_desc() |
|
| 438 | + ) |
|
| 439 | + ? substr( |
|
| 440 | + $method->admin_desc(), |
|
| 441 | + 0, |
|
| 442 | + 128 |
|
| 443 | + ) |
|
| 444 | + : $method->admin_name(); ?> |
|
| 445 | 445 | </option> |
| 446 | 446 | <?php endforeach; ?> |
| 447 | 447 | </select> |
| 448 | 448 | <p class="description"> |
| 449 | 449 | <?php esc_html_e( |
| 450 | - 'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
|
| 451 | - 'event_espresso' |
|
| 452 | - ); ?></p> |
|
| 450 | + 'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
|
| 451 | + 'event_espresso' |
|
| 452 | + ); ?></p> |
|
| 453 | 453 | </div> |
| 454 | 454 | |
| 455 | 455 | <div class="mop-PP mop-CC mop-CHQ mop"> |
| 456 | 456 | <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row"> |
| 457 | 457 | <label for="txn-admin-payment-txn-id-inp" class=""> |
| 458 | 458 | <?php esc_html_e( |
| 459 | - 'TXN ID / CHQ #', |
|
| 460 | - 'event_espresso' |
|
| 461 | - ); ?></label> |
|
| 459 | + 'TXN ID / CHQ #', |
|
| 460 | + 'event_espresso' |
|
| 461 | + ); ?></label> |
|
| 462 | 462 | <input name="txn_admin_payment[txn_id_chq_nmbr]" |
| 463 | 463 | id="txn-admin-payment-txn-id-chq-nmbr-inp" class="txn-admin-apply-payment-inp" |
| 464 | 464 | type="text" maxlength="100"/> |
| 465 | 465 | <p class="description"> |
| 466 | 466 | <?php esc_html_e( |
| 467 | - 'The Transaction ID sent back from the payment gateway, or the Cheque #', |
|
| 468 | - 'event_espresso' |
|
| 469 | - ); ?></p> |
|
| 467 | + 'The Transaction ID sent back from the payment gateway, or the Cheque #', |
|
| 468 | + 'event_espresso' |
|
| 469 | + ); ?></p> |
|
| 470 | 470 | </div> |
| 471 | 471 | </div> |
| 472 | 472 | |
@@ -479,9 +479,9 @@ discard block |
||
| 479 | 479 | type="text"/> |
| 480 | 480 | <p class="description"> |
| 481 | 481 | <?php esc_html_e( |
| 482 | - 'The gateway response string (optional)', |
|
| 483 | - 'event_espresso' |
|
| 484 | - ); ?></p> |
|
| 482 | + 'The gateway response string (optional)', |
|
| 483 | + 'event_espresso' |
|
| 484 | + ); ?></p> |
|
| 485 | 485 | </div> |
| 486 | 486 | </div> |
| 487 | 487 | |
@@ -489,9 +489,9 @@ discard block |
||
| 489 | 489 | <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row"> |
| 490 | 490 | <label for="txn-admin-payment-status-inp" class=""> |
| 491 | 491 | <?php esc_html_e( |
| 492 | - 'Payment Status', |
|
| 493 | - 'event_espresso' |
|
| 494 | - ); ?></label> |
|
| 492 | + 'Payment Status', |
|
| 493 | + 'event_espresso' |
|
| 494 | + ); ?></label> |
|
| 495 | 495 | <select name="txn_admin_payment[status]" id="txn-admin-payment-status-slct" |
| 496 | 496 | class="txn-admin-apply-payment-slct" type="text"> |
| 497 | 497 | <?php foreach ($payment_status as $STS_ID => $STS_code) : ?> |
@@ -504,52 +504,52 @@ discard block |
||
| 504 | 504 | </select> |
| 505 | 505 | <p class="description"> |
| 506 | 506 | <?php esc_html_e( |
| 507 | - 'Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
|
| 508 | - 'event_espresso' |
|
| 509 | - ); ?></p> |
|
| 507 | + 'Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
|
| 508 | + 'event_espresso' |
|
| 509 | + ); ?></p> |
|
| 510 | 510 | </div> |
| 511 | 511 | </div> |
| 512 | 512 | |
| 513 | 513 | <div class="txn-admin-apply-payment-po-nmbr-dv admin-modal-dialog-row"> |
| 514 | 514 | <label for="txn-admin-payment-po-nmbr-inp" class=""> |
| 515 | 515 | <?php esc_html_e( |
| 516 | - 'P.O. / S.O. #', |
|
| 517 | - 'event_espresso' |
|
| 518 | - ); ?></label> |
|
| 516 | + 'P.O. / S.O. #', |
|
| 517 | + 'event_espresso' |
|
| 518 | + ); ?></label> |
|
| 519 | 519 | <input name="txn_admin_payment[po_number]" id="txn-admin-payment-po-nmbr-inp" |
| 520 | 520 | class="txn-admin-apply-payment-inp" type="text" maxlength="100"/> |
| 521 | 521 | <p class="description"> |
| 522 | 522 | <?php esc_html_e( |
| 523 | - 'The Purchase or Sales Order Number if any (optional)', |
|
| 524 | - 'event_espresso' |
|
| 525 | - ); ?></p> |
|
| 523 | + 'The Purchase or Sales Order Number if any (optional)', |
|
| 524 | + 'event_espresso' |
|
| 525 | + ); ?></p> |
|
| 526 | 526 | </div> |
| 527 | 527 | |
| 528 | 528 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
| 529 | 529 | <label for="txn-admin-payment-accounting-inp" |
| 530 | 530 | class="last"> |
| 531 | 531 | <?php esc_html_e( |
| 532 | - 'Notes / Extra Accounting', |
|
| 533 | - 'event_espresso' |
|
| 534 | - ); ?></label> |
|
| 532 | + 'Notes / Extra Accounting', |
|
| 533 | + 'event_espresso' |
|
| 534 | + ); ?></label> |
|
| 535 | 535 | <input name="txn_admin_payment[accounting]" id="txn-admin-payment-accounting-inp" |
| 536 | 536 | class="txn-admin-apply-payment-inp" type="text" value="<?php echo $REG_code; ?>" |
| 537 | 537 | maxlength="100"/> <input type="hidden" id="txn-admin-reg-code-inp" |
| 538 | 538 | value="<?php echo $REG_code; ?>"/> |
| 539 | 539 | <p class="description"> |
| 540 | 540 | <?php esc_html_e( |
| 541 | - 'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
|
| 542 | - 'event_espresso' |
|
| 543 | - ); ?></p> |
|
| 541 | + 'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
|
| 542 | + 'event_espresso' |
|
| 543 | + ); ?></p> |
|
| 544 | 544 | </div> |
| 545 | 545 | |
| 546 | 546 | <div class="txn-admin-apply-payment-registrations-dv admin-modal-dialog-row"> |
| 547 | 547 | <label for="txn-admin-payment-registrations-inp" |
| 548 | 548 | class="last"> |
| 549 | 549 | <?php esc_html_e( |
| 550 | - 'Registrations to Apply Payment to:', |
|
| 551 | - 'event_espresso' |
|
| 552 | - ); ?></label> |
|
| 550 | + 'Registrations to Apply Payment to:', |
|
| 551 | + 'event_espresso' |
|
| 552 | + ); ?></label> |
|
| 553 | 553 | <label class="txn-admin-apply-payment-to-registrations-lbl"> |
| 554 | 554 | <input type="radio" value="1" id="txn-admin-apply-payment-to-all-registrations-inp" |
| 555 | 555 | name="txn_admin_payment[apply_to_all_registrations]" checked="checked"/> |
@@ -567,15 +567,15 @@ discard block |
||
| 567 | 567 | <label for="txn-admin-payment-reg-status-inp" |
| 568 | 568 | class="last"> |
| 569 | 569 | <?php esc_html_e( |
| 570 | - 'Change Registration Status?', |
|
| 571 | - 'event_espresso' |
|
| 572 | - ); ?></label> |
|
| 570 | + 'Change Registration Status?', |
|
| 571 | + 'event_espresso' |
|
| 572 | + ); ?></label> |
|
| 573 | 573 | <?php echo $status_change_select; ?> |
| 574 | 574 | <p class="description"> |
| 575 | 575 | <?php esc_html_e( |
| 576 | - 'If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
|
| 577 | - 'event_espresso' |
|
| 578 | - ); ?></p> |
|
| 576 | + 'If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
|
| 577 | + 'event_espresso' |
|
| 578 | + ); ?></p> |
|
| 579 | 579 | <br/> |
| 580 | 580 | </div> |
| 581 | 581 | |
@@ -596,14 +596,14 @@ discard block |
||
| 596 | 596 | <br class="clear-float"/> |
| 597 | 597 | <p class="description"> |
| 598 | 598 | <?php printf( |
| 599 | - esc_html__( |
|
| 600 | - 'By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', |
|
| 601 | - 'event_espresso' |
|
| 602 | - ), |
|
| 603 | - '<strong>', |
|
| 604 | - '</strong>', |
|
| 605 | - '<br />' |
|
| 606 | - ); ?></p> |
|
| 599 | + esc_html__( |
|
| 600 | + 'By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', |
|
| 601 | + 'event_espresso' |
|
| 602 | + ), |
|
| 603 | + '<strong>', |
|
| 604 | + '</strong>', |
|
| 605 | + '<br />' |
|
| 606 | + ); ?></p> |
|
| 607 | 607 | <label></label> |
| 608 | 608 | </div> |
| 609 | 609 | <div class="clear"></div> |
@@ -644,9 +644,9 @@ discard block |
||
| 644 | 644 | <li> |
| 645 | 645 | <span id="ee-ajax-processing-text" style="display:none;"> |
| 646 | 646 | <?php esc_html_e( |
| 647 | - 'Processing...', |
|
| 648 | - 'event_espresso' |
|
| 649 | - ); ?></span> |
|
| 647 | + 'Processing...', |
|
| 648 | + 'event_espresso' |
|
| 649 | + ); ?></span> |
|
| 650 | 650 | </li> |
| 651 | 651 | </ul> |
| 652 | 652 | |
@@ -661,9 +661,9 @@ discard block |
||
| 661 | 661 | style="display:none;"> |
| 662 | 662 | <span class="ee-icon ee-icon-cash-add"></span> |
| 663 | 663 | <?php echo esc_html__( |
| 664 | - 'Delete Payment/Refund for Transaction #', |
|
| 665 | - 'event_espresso' |
|
| 666 | - ) . $txn_nmbr['value']; ?> |
|
| 664 | + 'Delete Payment/Refund for Transaction #', |
|
| 665 | + 'event_espresso' |
|
| 666 | + ) . $txn_nmbr['value']; ?> |
|
| 667 | 667 | </h2> |
| 668 | 668 | |
| 669 | 669 | <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm" |
@@ -685,19 +685,19 @@ discard block |
||
| 685 | 685 | <label for="delete-txn-admin-payment-reg-status-inp" |
| 686 | 686 | class="last"> |
| 687 | 687 | <?php esc_html_e( |
| 688 | - 'Change Registration Status?', |
|
| 689 | - 'event_espresso' |
|
| 690 | - ); ?></label> |
|
| 688 | + 'Change Registration Status?', |
|
| 689 | + 'event_espresso' |
|
| 690 | + ); ?></label> |
|
| 691 | 691 | <?php echo $delete_status_change_select; ?> |
| 692 | 692 | <p class="description"> |
| 693 | 693 | <?php printf( |
| 694 | - esc_html__( |
|
| 695 | - 'If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', |
|
| 696 | - 'event_espresso' |
|
| 697 | - ), |
|
| 698 | - '<strong>', |
|
| 699 | - '</strong>' |
|
| 700 | - ); ?></p> |
|
| 694 | + esc_html__( |
|
| 695 | + 'If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', |
|
| 696 | + 'event_espresso' |
|
| 697 | + ), |
|
| 698 | + '<strong>', |
|
| 699 | + '</strong>' |
|
| 700 | + ); ?></p> |
|
| 701 | 701 | </div> |
| 702 | 702 | |
| 703 | 703 | <div class="ee-attention txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
@@ -706,9 +706,9 @@ discard block |
||
| 706 | 706 | <input type="checkbox" value="1" name="delete_txn_reg_status_change[send_notifications]"> |
| 707 | 707 | <p class="description"> |
| 708 | 708 | <?php esc_html_e( |
| 709 | - 'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', |
|
| 710 | - 'event_espresso' |
|
| 711 | - ); ?></p> |
|
| 709 | + 'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', |
|
| 710 | + 'event_espresso' |
|
| 711 | + ); ?></p> |
|
| 712 | 712 | </div> |
| 713 | 713 | <div class="clear"></div> |
| 714 | 714 | |
@@ -740,16 +740,16 @@ discard block |
||
| 740 | 740 | <?php endif; // $grand_raw_total > 0?> |
| 741 | 741 | |
| 742 | 742 | <?php |
| 743 | - if (WP_DEBUG) { |
|
| 744 | - $delivered_messages = get_option('EED_Messages__payment', array()); |
|
| 745 | - if (isset($delivered_messages[ $TXN_ID ])) { |
|
| 746 | - ?> |
|
| 743 | + if (WP_DEBUG) { |
|
| 744 | + $delivered_messages = get_option('EED_Messages__payment', array()); |
|
| 745 | + if (isset($delivered_messages[ $TXN_ID ])) { |
|
| 746 | + ?> |
|
| 747 | 747 | <h4 class="admin-primary-mbox-h4 hdr-has-icon"><span |
| 748 | 748 | class="dashicons dashicons-email-alt"></span> |
| 749 | 749 | <?php esc_html_e( |
| 750 | - 'Messages Sent to Primary Registrant', |
|
| 751 | - 'event_espresso' |
|
| 752 | - ); ?></h4> |
|
| 750 | + 'Messages Sent to Primary Registrant', |
|
| 751 | + 'event_espresso' |
|
| 752 | + ); ?></h4> |
|
| 753 | 753 | |
| 754 | 754 | <div class="admin-primary-mbox-tbl-wrap"> |
| 755 | 755 | <table class="admin-primary-mbox-tbl"> |
@@ -763,26 +763,26 @@ discard block |
||
| 763 | 763 | </thead> |
| 764 | 764 | <tbody> |
| 765 | 765 | <?php foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) : |
| 766 | - ?> |
|
| 766 | + ?> |
|
| 767 | 767 | <tr> |
| 768 | 768 | <td class="jst-left"> |
| 769 | 769 | <?php echo date( |
| 770 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 771 | - ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 772 | - ); ?></td> |
|
| 770 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
| 771 | + ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 772 | + ); ?></td> |
|
| 773 | 773 | <td class="jst-left"><?php echo isset($delivered_message['message_type']) |
| 774 | - ? $delivered_message['message_type'] : ''; ?></td> |
|
| 774 | + ? $delivered_message['message_type'] : ''; ?></td> |
|
| 775 | 775 | <td class="jst-left"><?php echo isset($delivered_message['pay_status']) |
| 776 | - ? $delivered_message['pay_status'] : ''; ?></td> |
|
| 776 | + ? $delivered_message['pay_status'] : ''; ?></td> |
|
| 777 | 777 | <td class="jst-left"><?php echo isset($delivered_message['txn_status']) |
| 778 | - ? $delivered_message['txn_status'] : ''; ?></td> |
|
| 778 | + ? $delivered_message['txn_status'] : ''; ?></td> |
|
| 779 | 779 | </tr> |
| 780 | 780 | <?php endforeach; // $delivered_messages?> |
| 781 | 781 | </tbody> |
| 782 | 782 | </table> |
| 783 | 783 | </div> |
| 784 | 784 | <?php |
| 785 | - } |
|
| 786 | - } |
|
| 787 | - ?> |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + ?> |
|
| 788 | 788 | </div> |
@@ -210,10 +210,13 @@ discard block |
||
| 210 | 210 | false |
| 211 | 211 | ); ?></span></th> |
| 212 | 212 | </tr> |
| 213 | - <?php else : ?> |
|
| 213 | + <?php else { |
|
| 214 | + : ?> |
|
| 214 | 215 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
| 215 | 216 | <td class=" jst-rght" colspan="10"> |
| 216 | - <span class="important-notice"><?php echo $no_payment_text; ?></span> |
|
| 217 | + <span class="important-notice"><?php echo $no_payment_text; |
|
| 218 | +} |
|
| 219 | +?></span> |
|
| 217 | 220 | </td> |
| 218 | 221 | </tr> |
| 219 | 222 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
@@ -304,13 +307,16 @@ discard block |
||
| 304 | 307 | <?php esc_html_e('Apply Refund', 'event_espresso'); ?> |
| 305 | 308 | </a> |
| 306 | 309 | </li> |
| 307 | - <?php else : ?> |
|
| 310 | + <?php else { |
|
| 311 | + : ?> |
|
| 308 | 312 | <li> |
| 309 | 313 | <p> |
| 310 | 314 | <?php esc_html__( |
| 311 | 315 | 'You do not have access to apply payments or refunds.', |
| 312 | 316 | 'event_espresso' |
| 313 | - ); ?></p> |
|
| 317 | + ); |
|
| 318 | +} |
|
| 319 | +?></p> |
|
| 314 | 320 | </li> |
| 315 | 321 | <?php endif; ?> |
| 316 | 322 | </ul> |
@@ -18,226 +18,226 @@ |
||
| 18 | 18 | class EE_Registration_CheckIn_List_Table extends EE_Admin_List_Table |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * EE_Registration_CheckIn_List_Table constructor. |
|
| 23 | - * |
|
| 24 | - * @param EE_Admin_Page $admin_page |
|
| 25 | - */ |
|
| 26 | - public function __construct($admin_page) |
|
| 27 | - { |
|
| 28 | - parent::__construct($admin_page); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @throws EE_Error |
|
| 34 | - */ |
|
| 35 | - protected function _setup_data() |
|
| 36 | - { |
|
| 37 | - $this->_data = $this->_get_checkins($this->_per_page); |
|
| 38 | - $this->_all_data_count = $this->_get_checkins($this->_per_page, true); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Sets up the properties for the list table. |
|
| 44 | - */ |
|
| 45 | - protected function _set_properties() |
|
| 46 | - { |
|
| 47 | - $this->_wp_list_args = array( |
|
| 48 | - 'singular' => __('check-in', 'event_espresso'), |
|
| 49 | - 'plural' => __('check-ins', 'event_espresso'), |
|
| 50 | - 'ajax' => true, |
|
| 51 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 52 | - ); |
|
| 53 | - |
|
| 54 | - $this->_columns = array( |
|
| 55 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 56 | - 'CHK_in' => __('Check-In', 'event_espresso'), |
|
| 57 | - 'CHK_timestamp' => __('Timestamp', 'event_espresso'), |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - $this->_sortable_columns = array( |
|
| 61 | - 'CHK_timestamp' => array('CHK_timestamp' => true), |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - $this->_primary_column = 'CHK_in'; |
|
| 65 | - |
|
| 66 | - $this->_hidden_columns = array(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - protected function _get_table_filters() |
|
| 74 | - { |
|
| 75 | - return []; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Returning an empty string to remove the search box for this view. |
|
| 81 | - * |
|
| 82 | - * @param string $text |
|
| 83 | - * @param string $input_id |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public function search_box($text, $input_id) |
|
| 87 | - { |
|
| 88 | - return ''; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @throws EE_Error |
|
| 94 | - */ |
|
| 95 | - protected function _add_view_counts() |
|
| 96 | - { |
|
| 97 | - $this->_views['all']['count'] = $this->_get_checkins(null, true); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param EE_Checkin $item |
|
| 103 | - * @return string |
|
| 104 | - * @throws EE_Error |
|
| 105 | - * @throws InvalidArgumentException |
|
| 106 | - * @throws ReflectionException |
|
| 107 | - * @throws InvalidDataTypeException |
|
| 108 | - * @throws InvalidInterfaceException |
|
| 109 | - */ |
|
| 110 | - public function column_cb($item) |
|
| 111 | - { |
|
| 112 | - return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param EE_Checkin $item |
|
| 118 | - * @return string |
|
| 119 | - * @throws EE_Error |
|
| 120 | - * @throws InvalidArgumentException |
|
| 121 | - * @throws InvalidDataTypeException |
|
| 122 | - * @throws InvalidInterfaceException |
|
| 123 | - * @throws ReflectionException |
|
| 124 | - */ |
|
| 125 | - public function column_CHK_in(EE_Checkin $item) |
|
| 126 | - { |
|
| 127 | - $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
| 128 | - return '<span class="' |
|
| 129 | - . $checkin_status_dashicon->cssClasses() |
|
| 130 | - . '"></span><span class="show-on-mobile-view-only">' |
|
| 131 | - . $item->get_datetime('CHK_timestamp') |
|
| 132 | - . '</span>'; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param EE_Checkin $item |
|
| 138 | - * @return string |
|
| 139 | - * @throws EE_Error |
|
| 140 | - * @throws InvalidArgumentException |
|
| 141 | - * @throws InvalidDataTypeException |
|
| 142 | - * @throws InvalidInterfaceException |
|
| 143 | - * @throws ReflectionException |
|
| 144 | - */ |
|
| 145 | - public function column_CHK_timestamp(EE_Checkin $item) |
|
| 146 | - { |
|
| 147 | - $actions = array(); |
|
| 148 | - $delete_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 149 | - array( |
|
| 150 | - 'action' => 'delete_checkin_row', |
|
| 151 | - 'DTT_ID' => $this->_req_data['DTT_ID'], |
|
| 152 | - '_REG_ID' => $this->_req_data['_REG_ID'], |
|
| 153 | - 'CHK_ID' => $item->ID(), |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 156 | - $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 157 | - 'ee_delete_checkins', |
|
| 158 | - 'espresso_registrations_delete_checkin_row' |
|
| 159 | - ) |
|
| 160 | - ? '<a href="' . $delete_url . '" title="' |
|
| 161 | - . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
| 162 | - . __('Delete', 'event_espresso') . '</a>' |
|
| 163 | - : ''; |
|
| 164 | - |
|
| 165 | - return sprintf( |
|
| 166 | - '%1$s %2$s', |
|
| 167 | - $item->get_datetime('CHK_timestamp', '', 'H:i:s a'), |
|
| 168 | - $this->row_actions($actions) |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * This retrieves all the Check-ins for the given parameters. |
|
| 175 | - * experimenting with having the query for the table values within the list table. |
|
| 176 | - * |
|
| 177 | - * @param int $per_page How many to retrieve per page |
|
| 178 | - * @param bool $count Whether to return a count or not |
|
| 179 | - * @return EE_Checkin[]|int |
|
| 180 | - * @throws EE_Error |
|
| 181 | - * @throws InvalidArgumentException |
|
| 182 | - * @throws InvalidDataTypeException |
|
| 183 | - * @throws InvalidInterfaceException |
|
| 184 | - */ |
|
| 185 | - protected function _get_checkins($per_page = 10, $count = false) |
|
| 186 | - { |
|
| 187 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : false; |
|
| 188 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
|
| 189 | - |
|
| 190 | - // if user does not have the capability for the checkins for this registration then get out! |
|
| 191 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 192 | - 'ee_read_checkin', |
|
| 193 | - 'espresso_registrations_registration_checkins', |
|
| 194 | - $REG_ID |
|
| 195 | - )) { |
|
| 196 | - return $count ? 0 : array(); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // if no reg id then get out cause need a reg id |
|
| 200 | - if (empty($REG_ID) || empty($DTT_ID)) { |
|
| 201 | - throw new EE_Error( |
|
| 202 | - __( |
|
| 203 | - 'This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // set orderby |
|
| 210 | - // note that with this table we're only providing the option to orderby the timestamp value. |
|
| 211 | - $orderby = 'CHK_timestamp'; |
|
| 212 | - |
|
| 213 | - $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 214 | - |
|
| 215 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 216 | - ? $this->_req_data['paged'] |
|
| 217 | - : 1; |
|
| 218 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 219 | - ? $this->_req_data['perpage'] |
|
| 220 | - : $per_page; |
|
| 221 | - $limit = null; |
|
| 222 | - if (! $count) { |
|
| 223 | - $offset = ($current_page - 1) * $per_page; |
|
| 224 | - $limit = array($offset, $per_page); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $_where = array( |
|
| 228 | - 'REG_ID' => $REG_ID, |
|
| 229 | - 'DTT_ID' => $DTT_ID, |
|
| 230 | - ); |
|
| 231 | - |
|
| 232 | - $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
| 233 | - |
|
| 234 | - // if no per_page value then we just want to return a count of all Check-ins |
|
| 235 | - if ($count) { |
|
| 236 | - return EEM_Checkin::instance()->count(array($_where)); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $count |
|
| 240 | - ? EEM_Checkin::instance()->count(array($_where)) |
|
| 241 | - : EEM_Checkin::instance()->get_all($query_params); |
|
| 242 | - } |
|
| 21 | + /** |
|
| 22 | + * EE_Registration_CheckIn_List_Table constructor. |
|
| 23 | + * |
|
| 24 | + * @param EE_Admin_Page $admin_page |
|
| 25 | + */ |
|
| 26 | + public function __construct($admin_page) |
|
| 27 | + { |
|
| 28 | + parent::__construct($admin_page); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @throws EE_Error |
|
| 34 | + */ |
|
| 35 | + protected function _setup_data() |
|
| 36 | + { |
|
| 37 | + $this->_data = $this->_get_checkins($this->_per_page); |
|
| 38 | + $this->_all_data_count = $this->_get_checkins($this->_per_page, true); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Sets up the properties for the list table. |
|
| 44 | + */ |
|
| 45 | + protected function _set_properties() |
|
| 46 | + { |
|
| 47 | + $this->_wp_list_args = array( |
|
| 48 | + 'singular' => __('check-in', 'event_espresso'), |
|
| 49 | + 'plural' => __('check-ins', 'event_espresso'), |
|
| 50 | + 'ajax' => true, |
|
| 51 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 52 | + ); |
|
| 53 | + |
|
| 54 | + $this->_columns = array( |
|
| 55 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 56 | + 'CHK_in' => __('Check-In', 'event_espresso'), |
|
| 57 | + 'CHK_timestamp' => __('Timestamp', 'event_espresso'), |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + $this->_sortable_columns = array( |
|
| 61 | + 'CHK_timestamp' => array('CHK_timestamp' => true), |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + $this->_primary_column = 'CHK_in'; |
|
| 65 | + |
|
| 66 | + $this->_hidden_columns = array(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + protected function _get_table_filters() |
|
| 74 | + { |
|
| 75 | + return []; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Returning an empty string to remove the search box for this view. |
|
| 81 | + * |
|
| 82 | + * @param string $text |
|
| 83 | + * @param string $input_id |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public function search_box($text, $input_id) |
|
| 87 | + { |
|
| 88 | + return ''; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @throws EE_Error |
|
| 94 | + */ |
|
| 95 | + protected function _add_view_counts() |
|
| 96 | + { |
|
| 97 | + $this->_views['all']['count'] = $this->_get_checkins(null, true); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param EE_Checkin $item |
|
| 103 | + * @return string |
|
| 104 | + * @throws EE_Error |
|
| 105 | + * @throws InvalidArgumentException |
|
| 106 | + * @throws ReflectionException |
|
| 107 | + * @throws InvalidDataTypeException |
|
| 108 | + * @throws InvalidInterfaceException |
|
| 109 | + */ |
|
| 110 | + public function column_cb($item) |
|
| 111 | + { |
|
| 112 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param EE_Checkin $item |
|
| 118 | + * @return string |
|
| 119 | + * @throws EE_Error |
|
| 120 | + * @throws InvalidArgumentException |
|
| 121 | + * @throws InvalidDataTypeException |
|
| 122 | + * @throws InvalidInterfaceException |
|
| 123 | + * @throws ReflectionException |
|
| 124 | + */ |
|
| 125 | + public function column_CHK_in(EE_Checkin $item) |
|
| 126 | + { |
|
| 127 | + $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
| 128 | + return '<span class="' |
|
| 129 | + . $checkin_status_dashicon->cssClasses() |
|
| 130 | + . '"></span><span class="show-on-mobile-view-only">' |
|
| 131 | + . $item->get_datetime('CHK_timestamp') |
|
| 132 | + . '</span>'; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param EE_Checkin $item |
|
| 138 | + * @return string |
|
| 139 | + * @throws EE_Error |
|
| 140 | + * @throws InvalidArgumentException |
|
| 141 | + * @throws InvalidDataTypeException |
|
| 142 | + * @throws InvalidInterfaceException |
|
| 143 | + * @throws ReflectionException |
|
| 144 | + */ |
|
| 145 | + public function column_CHK_timestamp(EE_Checkin $item) |
|
| 146 | + { |
|
| 147 | + $actions = array(); |
|
| 148 | + $delete_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 149 | + array( |
|
| 150 | + 'action' => 'delete_checkin_row', |
|
| 151 | + 'DTT_ID' => $this->_req_data['DTT_ID'], |
|
| 152 | + '_REG_ID' => $this->_req_data['_REG_ID'], |
|
| 153 | + 'CHK_ID' => $item->ID(), |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | + $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 157 | + 'ee_delete_checkins', |
|
| 158 | + 'espresso_registrations_delete_checkin_row' |
|
| 159 | + ) |
|
| 160 | + ? '<a href="' . $delete_url . '" title="' |
|
| 161 | + . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
| 162 | + . __('Delete', 'event_espresso') . '</a>' |
|
| 163 | + : ''; |
|
| 164 | + |
|
| 165 | + return sprintf( |
|
| 166 | + '%1$s %2$s', |
|
| 167 | + $item->get_datetime('CHK_timestamp', '', 'H:i:s a'), |
|
| 168 | + $this->row_actions($actions) |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * This retrieves all the Check-ins for the given parameters. |
|
| 175 | + * experimenting with having the query for the table values within the list table. |
|
| 176 | + * |
|
| 177 | + * @param int $per_page How many to retrieve per page |
|
| 178 | + * @param bool $count Whether to return a count or not |
|
| 179 | + * @return EE_Checkin[]|int |
|
| 180 | + * @throws EE_Error |
|
| 181 | + * @throws InvalidArgumentException |
|
| 182 | + * @throws InvalidDataTypeException |
|
| 183 | + * @throws InvalidInterfaceException |
|
| 184 | + */ |
|
| 185 | + protected function _get_checkins($per_page = 10, $count = false) |
|
| 186 | + { |
|
| 187 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : false; |
|
| 188 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
|
| 189 | + |
|
| 190 | + // if user does not have the capability for the checkins for this registration then get out! |
|
| 191 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 192 | + 'ee_read_checkin', |
|
| 193 | + 'espresso_registrations_registration_checkins', |
|
| 194 | + $REG_ID |
|
| 195 | + )) { |
|
| 196 | + return $count ? 0 : array(); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // if no reg id then get out cause need a reg id |
|
| 200 | + if (empty($REG_ID) || empty($DTT_ID)) { |
|
| 201 | + throw new EE_Error( |
|
| 202 | + __( |
|
| 203 | + 'This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // set orderby |
|
| 210 | + // note that with this table we're only providing the option to orderby the timestamp value. |
|
| 211 | + $orderby = 'CHK_timestamp'; |
|
| 212 | + |
|
| 213 | + $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 214 | + |
|
| 215 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 216 | + ? $this->_req_data['paged'] |
|
| 217 | + : 1; |
|
| 218 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 219 | + ? $this->_req_data['perpage'] |
|
| 220 | + : $per_page; |
|
| 221 | + $limit = null; |
|
| 222 | + if (! $count) { |
|
| 223 | + $offset = ($current_page - 1) * $per_page; |
|
| 224 | + $limit = array($offset, $per_page); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $_where = array( |
|
| 228 | + 'REG_ID' => $REG_ID, |
|
| 229 | + 'DTT_ID' => $DTT_ID, |
|
| 230 | + ); |
|
| 231 | + |
|
| 232 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
| 233 | + |
|
| 234 | + // if no per_page value then we just want to return a count of all Check-ins |
|
| 235 | + if ($count) { |
|
| 236 | + return EEM_Checkin::instance()->count(array($_where)); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $count |
|
| 240 | + ? EEM_Checkin::instance()->count(array($_where)) |
|
| 241 | + : EEM_Checkin::instance()->get_all($query_params); |
|
| 242 | + } |
|
| 243 | 243 | } |
@@ -11,606 +11,606 @@ |
||
| 11 | 11 | class EEG_Paypal_Pro extends EE_Onsite_Gateway |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var $_paypal_api_username string |
|
| 16 | - */ |
|
| 17 | - protected $_api_username = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var $_api_password string |
|
| 21 | - */ |
|
| 22 | - protected $_api_password = null; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var $_api_signature string |
|
| 26 | - */ |
|
| 27 | - protected $_api_signature = null; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
| 31 | - */ |
|
| 32 | - protected $_credit_card_types = null; |
|
| 33 | - |
|
| 34 | - protected $_currencies_supported = array( |
|
| 35 | - 'USD', |
|
| 36 | - 'GBP', |
|
| 37 | - 'CAD', |
|
| 38 | - 'AUD', |
|
| 39 | - 'BRL', |
|
| 40 | - 'CHF', |
|
| 41 | - 'CZK', |
|
| 42 | - 'DKK', |
|
| 43 | - 'EUR', |
|
| 44 | - 'HKD', |
|
| 45 | - 'HUF', |
|
| 46 | - 'ILS', |
|
| 47 | - 'JPY', |
|
| 48 | - 'MXN', |
|
| 49 | - 'MYR', |
|
| 50 | - 'NOK', |
|
| 51 | - 'NZD', |
|
| 52 | - 'PHP', |
|
| 53 | - 'PLN', |
|
| 54 | - 'SEK', |
|
| 55 | - 'SGD', |
|
| 56 | - 'THB', |
|
| 57 | - 'TRY', |
|
| 58 | - 'TWD', |
|
| 59 | - 'RUB', |
|
| 60 | - 'INR', |
|
| 61 | - ); |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param EEI_Payment $payment |
|
| 67 | - * @param array $billing_info { |
|
| 68 | - * @type string $credit_card |
|
| 69 | - * @type string $credit_card_type |
|
| 70 | - * @type string $exp_month always 2 characters |
|
| 71 | - * @type string $exp_year always 4 characters |
|
| 72 | - * @type string $cvv |
|
| 73 | - * } |
|
| 74 | - * @see parent::do_direct_payment for more info |
|
| 75 | - * @return EE_Payment|EEI_Payment |
|
| 76 | - * @throws EE_Error |
|
| 77 | - */ |
|
| 78 | - public function do_direct_payment($payment, $billing_info = null) |
|
| 79 | - { |
|
| 80 | - $transaction = $payment->transaction(); |
|
| 81 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 82 | - throw new EE_Error( |
|
| 83 | - esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - $primary_registrant = $transaction->primary_registration(); |
|
| 87 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
| 88 | - throw new EE_Error( |
|
| 89 | - esc_html__( |
|
| 90 | - 'No primary registration on transaction while paying with PayPal Pro.', |
|
| 91 | - 'event_espresso' |
|
| 92 | - ) |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - $attendee = $primary_registrant->attendee(); |
|
| 96 | - if (! $attendee instanceof EEI_Attendee) { |
|
| 97 | - throw new EE_Error( |
|
| 98 | - esc_html__( |
|
| 99 | - 'No attendee on primary registration while paying with PayPal Pro.', |
|
| 100 | - 'event_espresso' |
|
| 101 | - ) |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 105 | - $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 106 | - // charge for the full amount. Show itemized list |
|
| 107 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 108 | - $item_num = 1; |
|
| 109 | - $total_line_item = $transaction->total_line_item(); |
|
| 110 | - $order_items = array(); |
|
| 111 | - foreach ($total_line_item->get_items() as $line_item) { |
|
| 112 | - // ignore line items with a quantity of 0 |
|
| 113 | - if ($line_item->quantity() == 0) { |
|
| 114 | - continue; |
|
| 115 | - } |
|
| 116 | - // For percent items, whose unit_price is 0, use the total instead. |
|
| 117 | - if ($line_item->is_percent()) { |
|
| 118 | - $unit_price = $line_item->total(); |
|
| 119 | - $line_item_quantity = 1; |
|
| 120 | - } else { |
|
| 121 | - $unit_price = $line_item->unit_price(); |
|
| 122 | - $line_item_quantity = $line_item->quantity(); |
|
| 123 | - } |
|
| 124 | - $item = array( |
|
| 125 | - // Item Name. 127 char max. |
|
| 126 | - 'l_name' => substr( |
|
| 127 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 128 | - 0, |
|
| 129 | - 127 |
|
| 130 | - ), |
|
| 131 | - // Item description. 127 char max. |
|
| 132 | - 'l_desc' => substr( |
|
| 133 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 134 | - 0, |
|
| 135 | - 127 |
|
| 136 | - ), |
|
| 137 | - // Cost of individual item. |
|
| 138 | - 'l_amt' => $unit_price, |
|
| 139 | - // Item Number. 127 char max. |
|
| 140 | - 'l_number' => $item_num++, |
|
| 141 | - // Item quantity. Must be any positive integer. |
|
| 142 | - 'l_qty' => $line_item_quantity, |
|
| 143 | - // Item's sales tax amount. |
|
| 144 | - 'l_taxamt' => '', |
|
| 145 | - // eBay auction number of item. |
|
| 146 | - 'l_ebayitemnumber' => '', |
|
| 147 | - // eBay transaction ID of purchased item. |
|
| 148 | - 'l_ebayitemauctiontxnid' => '', |
|
| 149 | - // eBay order ID for the item. |
|
| 150 | - 'l_ebayitemorderid' => '', |
|
| 151 | - ); |
|
| 152 | - // add to array of all items |
|
| 153 | - array_push($order_items, $item); |
|
| 154 | - } |
|
| 155 | - $item_amount = $total_line_item->get_items_total(); |
|
| 156 | - $tax_amount = $total_line_item->get_total_tax(); |
|
| 157 | - } else { |
|
| 158 | - $order_items = array(); |
|
| 159 | - $item_amount = $payment->amount(); |
|
| 160 | - $tax_amount = 0; |
|
| 161 | - array_push($order_items, array( |
|
| 162 | - // Item Name. 127 char max. |
|
| 163 | - 'l_name' => substr( |
|
| 164 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 165 | - 0, |
|
| 166 | - 127 |
|
| 167 | - ), |
|
| 168 | - // Item description. 127 char max. |
|
| 169 | - 'l_desc' => substr( |
|
| 170 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 171 | - 0, |
|
| 172 | - 127 |
|
| 173 | - ), |
|
| 174 | - // Cost of individual item. |
|
| 175 | - 'l_amt' => $payment->amount(), |
|
| 176 | - // Item Number. 127 char max. |
|
| 177 | - 'l_number' => 1, |
|
| 178 | - // Item quantity. Must be any positive integer. |
|
| 179 | - 'l_qty' => 1, |
|
| 180 | - )); |
|
| 181 | - } |
|
| 182 | - // Populate data arrays with order data. |
|
| 183 | - $DPFields = array( |
|
| 184 | - // How you want to obtain payment ? |
|
| 185 | - // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
| 186 | - // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
| 187 | - 'paymentaction' => 'Sale', |
|
| 188 | - // Required. IP address of the payer's browser. |
|
| 189 | - 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
| 190 | - // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
| 191 | - 'returnfmfdetails' => '1', |
|
| 192 | - ); |
|
| 193 | - $CCDetails = array( |
|
| 194 | - // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
| 195 | - // If Maestro or Solo, the currency code must be GBP. |
|
| 196 | - // In addition, either start date or issue number must be specified. |
|
| 197 | - 'creditcardtype' => $billing_info['credit_card_type'], |
|
| 198 | - // Required. Credit card number. No spaces or punctuation. |
|
| 199 | - 'acct' => $billing_info['credit_card'], |
|
| 200 | - // Required. Credit card expiration date. Format is MMYYYY |
|
| 201 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
| 202 | - // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
| 203 | - 'cvv2' => $billing_info['cvv'], |
|
| 204 | - ); |
|
| 205 | - $PayerInfo = array( |
|
| 206 | - // Email address of payer. |
|
| 207 | - 'email' => $billing_info['email'], |
|
| 208 | - // Unique PayPal customer ID for payer. |
|
| 209 | - 'payerid' => '', |
|
| 210 | - // Status of payer. Values are verified or unverified |
|
| 211 | - 'payerstatus' => '', |
|
| 212 | - // Payer's business name. |
|
| 213 | - 'business' => '', |
|
| 214 | - ); |
|
| 215 | - $PayerName = array( |
|
| 216 | - // Payer's salutation. 20 char max. |
|
| 217 | - 'salutation' => '', |
|
| 218 | - // Payer's first name. 25 char max. |
|
| 219 | - 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
| 220 | - // Payer's middle name. 25 char max. |
|
| 221 | - 'middlename' => '', |
|
| 222 | - // Payer's last name. 25 char max. |
|
| 223 | - 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
| 224 | - // Payer's suffix. 12 char max. |
|
| 225 | - 'suffix' => '', |
|
| 226 | - ); |
|
| 227 | - $BillingAddress = array( |
|
| 228 | - // Required. First street address. |
|
| 229 | - 'street' => $billing_info['address'], |
|
| 230 | - // Second street address. |
|
| 231 | - 'street2' => $billing_info['address2'], |
|
| 232 | - // Required. Name of City. |
|
| 233 | - 'city' => $billing_info['city'], |
|
| 234 | - // Required. Name of State or Province. |
|
| 235 | - 'state' => substr($billing_info['state'], 0, 40), |
|
| 236 | - // Required. Country code. |
|
| 237 | - 'countrycode' => $billing_info['country'], |
|
| 238 | - // Required. Postal code of payer. |
|
| 239 | - 'zip' => $billing_info['zip'], |
|
| 240 | - ); |
|
| 241 | - // check if the registration info contains the needed fields for paypal pro |
|
| 242 | - // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
| 243 | - if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
| 244 | - $use_registration_address_info = true; |
|
| 245 | - } else { |
|
| 246 | - $use_registration_address_info = false; |
|
| 247 | - } |
|
| 248 | - // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
| 249 | - // If not, use the billing info again |
|
| 250 | - $ShippingAddress = array( |
|
| 251 | - 'shiptoname' => substr($use_registration_address_info |
|
| 252 | - ? $attendee->full_name() |
|
| 253 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
| 254 | - 'shiptostreet' => substr($use_registration_address_info |
|
| 255 | - ? $attendee->address() |
|
| 256 | - : $billing_info['address'], 0, 100), |
|
| 257 | - 'shiptostreet2' => substr($use_registration_address_info |
|
| 258 | - ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
| 259 | - 'shiptocity' => substr($use_registration_address_info |
|
| 260 | - ? $attendee->city() |
|
| 261 | - : $billing_info['city'], 0, 40), |
|
| 262 | - 'state' => substr($use_registration_address_info |
|
| 263 | - ? $attendee->state_name() |
|
| 264 | - : $billing_info['state'], 0, 40), |
|
| 265 | - 'shiptocountry' => $use_registration_address_info |
|
| 266 | - ? $attendee->country_ID() |
|
| 267 | - : $billing_info['country'], |
|
| 268 | - 'shiptozip' => substr($use_registration_address_info |
|
| 269 | - ? $attendee->zip() |
|
| 270 | - : $billing_info['zip'], 0, 20), |
|
| 271 | - 'shiptophonenum' => substr($use_registration_address_info |
|
| 272 | - ? $attendee->phone() |
|
| 273 | - : $billing_info['phone'], 0, 20), |
|
| 274 | - ); |
|
| 275 | - $PaymentDetails = array( |
|
| 276 | - // Required. Total amount of order, including shipping, handling, and tax. |
|
| 277 | - 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
| 278 | - // Required. Three-letter currency code. Default is USD. |
|
| 279 | - 'currencycode' => $payment->currency_code(), |
|
| 280 | - // Required if you include itemized cart details. (L_AMTn, etc.) |
|
| 281 | - // Subtotal of items not including S&H, or tax. |
|
| 282 | - 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
| 283 | - // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
| 284 | - 'shippingamt' => '', |
|
| 285 | - // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
| 286 | - 'handlingamt' => '', |
|
| 287 | - // Required if you specify itemized cart tax details. |
|
| 288 | - // Sum of tax for all items on the order. Total sales tax. |
|
| 289 | - 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
| 290 | - // Description of the order the customer is purchasing. 127 char max. |
|
| 291 | - 'desc' => $order_description, |
|
| 292 | - // Free-form field for your own use. 256 char max. |
|
| 293 | - 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
| 294 | - // Your own invoice or tracking number |
|
| 295 | - 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
| 296 | - // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
| 297 | - 'notifyurl' => '', |
|
| 298 | - 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
| 299 | - ); |
|
| 300 | - // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
| 301 | - $PayPalRequestData = array( |
|
| 302 | - 'DPFields' => $DPFields, |
|
| 303 | - 'CCDetails' => $CCDetails, |
|
| 304 | - 'PayerInfo' => $PayerInfo, |
|
| 305 | - 'PayerName' => $PayerName, |
|
| 306 | - 'BillingAddress' => $BillingAddress, |
|
| 307 | - 'ShippingAddress' => $ShippingAddress, |
|
| 308 | - 'PaymentDetails' => $PaymentDetails, |
|
| 309 | - 'OrderItems' => $order_items, |
|
| 310 | - ); |
|
| 311 | - $this->_log_clean_request($PayPalRequestData, $payment); |
|
| 312 | - try { |
|
| 313 | - $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
| 314 | - // remove PCI-sensitive data so it doesn't get stored |
|
| 315 | - $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
| 316 | - if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
| 317 | - $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
|
| 318 | - } elseif (isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
| 319 | - $message = $PayPalResult['L_LONGMESSAGE0']; |
|
| 320 | - } else { |
|
| 321 | - $message = $PayPalResult['ACK']; |
|
| 322 | - } |
|
| 323 | - if (empty($PayPalResult['RAWRESPONSE'])) { |
|
| 324 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 325 | - $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
| 326 | - $payment->set_details($PayPalResult); |
|
| 327 | - } else { |
|
| 328 | - if ($this->_APICallSuccessful($PayPalResult)) { |
|
| 329 | - $payment->set_status($this->_pay_model->approved_status()); |
|
| 330 | - } else { |
|
| 331 | - $payment->set_status($this->_pay_model->declined_status()); |
|
| 332 | - } |
|
| 333 | - // make sure we interpret the AMT as a float, not an international string |
|
| 334 | - // (where periods are thousand separators) |
|
| 335 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
| 336 | - $payment->set_gateway_response($message); |
|
| 337 | - $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
| 338 | - ? $PayPalResult['TRANSACTIONID'] |
|
| 339 | - : null); |
|
| 340 | - $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
| 341 | - ? $primary_registrant->reg_code() |
|
| 342 | - : ''; |
|
| 343 | - $payment->set_extra_accntng($primary_registration_code); |
|
| 344 | - $payment->set_details($PayPalResult); |
|
| 345 | - } |
|
| 346 | - } catch (Exception $e) { |
|
| 347 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 348 | - $payment->set_gateway_response($e->getMessage()); |
|
| 349 | - } |
|
| 350 | - // $payment->set_status( $this->_pay_model->declined_status() ); |
|
| 351 | - // $payment->set_gateway_response( '' ); |
|
| 352 | - return $payment; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
| 359 | - * |
|
| 360 | - * @param array $request |
|
| 361 | - * @param EEI_Payment $payment |
|
| 362 | - * @return void |
|
| 363 | - */ |
|
| 364 | - private function _log_clean_request($request, $payment) |
|
| 365 | - { |
|
| 366 | - $cleaned_request_data = $request; |
|
| 367 | - unset($cleaned_request_data['CCDetails']['acct']); |
|
| 368 | - unset($cleaned_request_data['CCDetails']['cvv2']); |
|
| 369 | - unset($cleaned_request_data['CCDetails']['expdate']); |
|
| 370 | - $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Cleans the response, logs it, and returns it |
|
| 377 | - * |
|
| 378 | - * @param array $response |
|
| 379 | - * @param EEI_Payment $payment |
|
| 380 | - * @return array cleaned |
|
| 381 | - */ |
|
| 382 | - private function _log_clean_response($response, $payment) |
|
| 383 | - { |
|
| 384 | - unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
| 385 | - unset($response['REQUESTDATA']['ACCT']); |
|
| 386 | - unset($response['REQUESTDATA']['EXPDATE']); |
|
| 387 | - unset($response['REQUESTDATA']['CVV2']); |
|
| 388 | - unset($response['RAWREQUEST']); |
|
| 389 | - $this->log(array('Paypal Response' => $response), $payment); |
|
| 390 | - return $response; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @param $DataArray |
|
| 397 | - * @return array |
|
| 398 | - */ |
|
| 399 | - private function prep_and_curl_request($DataArray) |
|
| 400 | - { |
|
| 401 | - // Create empty holders for each portion of the NVP string |
|
| 402 | - $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
| 403 | - $CCDetailsNVP = ''; |
|
| 404 | - $PayerInfoNVP = ''; |
|
| 405 | - $PayerNameNVP = ''; |
|
| 406 | - $BillingAddressNVP = ''; |
|
| 407 | - $ShippingAddressNVP = ''; |
|
| 408 | - $PaymentDetailsNVP = ''; |
|
| 409 | - $OrderItemsNVP = ''; |
|
| 410 | - $Secure3DNVP = ''; |
|
| 411 | - // DP Fields |
|
| 412 | - $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
| 413 | - foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
| 414 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
| 415 | - } |
|
| 416 | - // CC Details Fields |
|
| 417 | - $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
| 418 | - foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
| 419 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
| 420 | - } |
|
| 421 | - // PayerInfo Type Fields |
|
| 422 | - $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
| 423 | - foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
| 424 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
| 425 | - } |
|
| 426 | - // Payer Name Fields |
|
| 427 | - $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
| 428 | - foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
| 429 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
| 430 | - } |
|
| 431 | - // Address Fields (Billing) |
|
| 432 | - $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
| 433 | - foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
| 434 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
| 435 | - } |
|
| 436 | - // Payment Details Type Fields |
|
| 437 | - $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
| 438 | - foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
| 439 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
| 440 | - } |
|
| 441 | - // Payment Details Item Type Fields |
|
| 442 | - $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
| 443 | - $n = 0; |
|
| 444 | - foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
| 445 | - $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
| 446 | - foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
| 447 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
| 448 | - } |
|
| 449 | - $n++; |
|
| 450 | - } |
|
| 451 | - // Ship To Address Fields |
|
| 452 | - $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
| 453 | - foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
| 454 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
| 455 | - } |
|
| 456 | - // 3D Secure Fields |
|
| 457 | - $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
| 458 | - foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
| 459 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
| 460 | - } |
|
| 461 | - // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
| 462 | - $NVPRequest = 'USER=' |
|
| 463 | - . $this->_api_username |
|
| 464 | - . '&PWD=' |
|
| 465 | - . $this->_api_password |
|
| 466 | - . '&VERSION=64.0' |
|
| 467 | - . '&SIGNATURE=' |
|
| 468 | - . $this->_api_signature |
|
| 469 | - . $DPFieldsNVP |
|
| 470 | - . $CCDetailsNVP |
|
| 471 | - . $PayerInfoNVP |
|
| 472 | - . $PayerNameNVP |
|
| 473 | - . $BillingAddressNVP |
|
| 474 | - . $PaymentDetailsNVP |
|
| 475 | - . $OrderItemsNVP |
|
| 476 | - . $ShippingAddressNVP |
|
| 477 | - . $Secure3DNVP; |
|
| 478 | - $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
| 479 | - $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
| 480 | - $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
| 481 | - $Errors = $this->_GetErrors($NVPResponseArray); |
|
| 482 | - $NVPResponseArray['ERRORS'] = $Errors; |
|
| 483 | - $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
| 484 | - $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
| 485 | - $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
| 486 | - return $NVPResponseArray; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @param $Request |
|
| 493 | - * @return mixed |
|
| 494 | - */ |
|
| 495 | - private function _CURLRequest($Request) |
|
| 496 | - { |
|
| 497 | - $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
| 498 | - $curl = curl_init(); |
|
| 499 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
| 500 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
| 501 | - curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
| 502 | - curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
| 503 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
| 504 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
| 505 | - curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
| 506 | - // execute the curl POST |
|
| 507 | - $Response = curl_exec($curl); |
|
| 508 | - curl_close($curl); |
|
| 509 | - return $Response; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * @param $NVPString |
|
| 516 | - * @return array |
|
| 517 | - */ |
|
| 518 | - private function _NVPToArray($NVPString) |
|
| 519 | - { |
|
| 520 | - // prepare responses into array |
|
| 521 | - $proArray = array(); |
|
| 522 | - while (strlen($NVPString)) { |
|
| 523 | - // name |
|
| 524 | - $keypos = strpos($NVPString, '='); |
|
| 525 | - $keyval = substr($NVPString, 0, $keypos); |
|
| 526 | - // value |
|
| 527 | - $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
| 528 | - $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
| 529 | - // decoding the response |
|
| 530 | - $proArray[ $keyval ] = urldecode($valval); |
|
| 531 | - $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
| 532 | - } |
|
| 533 | - return $proArray; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @param array $PayPalResult |
|
| 540 | - * @return bool |
|
| 541 | - */ |
|
| 542 | - private function _APICallSuccessful($PayPalResult) |
|
| 543 | - { |
|
| 544 | - $approved = false; |
|
| 545 | - // check main response message from PayPal |
|
| 546 | - if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
| 547 | - $ack = strtoupper($PayPalResult['ACK']); |
|
| 548 | - $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
| 549 | - } |
|
| 550 | - return $approved; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * @param $DataArray |
|
| 557 | - * @return array |
|
| 558 | - */ |
|
| 559 | - private function _GetErrors($DataArray) |
|
| 560 | - { |
|
| 561 | - $Errors = array(); |
|
| 562 | - $n = 0; |
|
| 563 | - while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
| 564 | - $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
| 565 | - $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
| 566 | - ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
| 567 | - : ''; |
|
| 568 | - $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
| 569 | - ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
| 570 | - : ''; |
|
| 571 | - $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
| 572 | - ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
| 573 | - : ''; |
|
| 574 | - $CurrentItem = array( |
|
| 575 | - 'L_ERRORCODE' => $LErrorCode, |
|
| 576 | - 'L_SHORTMESSAGE' => $LShortMessage, |
|
| 577 | - 'L_LONGMESSAGE' => $LLongMessage, |
|
| 578 | - 'L_SEVERITYCODE' => $LSeverityCode, |
|
| 579 | - ); |
|
| 580 | - array_push($Errors, $CurrentItem); |
|
| 581 | - $n++; |
|
| 582 | - } |
|
| 583 | - return $Errors; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * nothing to see here... move along.... |
|
| 590 | - * |
|
| 591 | - * @access protected |
|
| 592 | - * @param $Errors |
|
| 593 | - * @return string |
|
| 594 | - */ |
|
| 595 | - private function _DisplayErrors($Errors) |
|
| 596 | - { |
|
| 597 | - $error = ''; |
|
| 598 | - foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
| 599 | - $CurrentError = $Errors[ $ErrorVar ]; |
|
| 600 | - foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
| 601 | - $CurrentVarName = ''; |
|
| 602 | - if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
| 603 | - $CurrentVarName = 'Error Code'; |
|
| 604 | - } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
| 605 | - $CurrentVarName = 'Short Message'; |
|
| 606 | - } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
| 607 | - $CurrentVarName = 'Long Message'; |
|
| 608 | - } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
| 609 | - $CurrentVarName = 'Severity Code'; |
|
| 610 | - } |
|
| 611 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - return $error; |
|
| 615 | - } |
|
| 14 | + /** |
|
| 15 | + * @var $_paypal_api_username string |
|
| 16 | + */ |
|
| 17 | + protected $_api_username = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var $_api_password string |
|
| 21 | + */ |
|
| 22 | + protected $_api_password = null; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var $_api_signature string |
|
| 26 | + */ |
|
| 27 | + protected $_api_signature = null; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
| 31 | + */ |
|
| 32 | + protected $_credit_card_types = null; |
|
| 33 | + |
|
| 34 | + protected $_currencies_supported = array( |
|
| 35 | + 'USD', |
|
| 36 | + 'GBP', |
|
| 37 | + 'CAD', |
|
| 38 | + 'AUD', |
|
| 39 | + 'BRL', |
|
| 40 | + 'CHF', |
|
| 41 | + 'CZK', |
|
| 42 | + 'DKK', |
|
| 43 | + 'EUR', |
|
| 44 | + 'HKD', |
|
| 45 | + 'HUF', |
|
| 46 | + 'ILS', |
|
| 47 | + 'JPY', |
|
| 48 | + 'MXN', |
|
| 49 | + 'MYR', |
|
| 50 | + 'NOK', |
|
| 51 | + 'NZD', |
|
| 52 | + 'PHP', |
|
| 53 | + 'PLN', |
|
| 54 | + 'SEK', |
|
| 55 | + 'SGD', |
|
| 56 | + 'THB', |
|
| 57 | + 'TRY', |
|
| 58 | + 'TWD', |
|
| 59 | + 'RUB', |
|
| 60 | + 'INR', |
|
| 61 | + ); |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param EEI_Payment $payment |
|
| 67 | + * @param array $billing_info { |
|
| 68 | + * @type string $credit_card |
|
| 69 | + * @type string $credit_card_type |
|
| 70 | + * @type string $exp_month always 2 characters |
|
| 71 | + * @type string $exp_year always 4 characters |
|
| 72 | + * @type string $cvv |
|
| 73 | + * } |
|
| 74 | + * @see parent::do_direct_payment for more info |
|
| 75 | + * @return EE_Payment|EEI_Payment |
|
| 76 | + * @throws EE_Error |
|
| 77 | + */ |
|
| 78 | + public function do_direct_payment($payment, $billing_info = null) |
|
| 79 | + { |
|
| 80 | + $transaction = $payment->transaction(); |
|
| 81 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 82 | + throw new EE_Error( |
|
| 83 | + esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + $primary_registrant = $transaction->primary_registration(); |
|
| 87 | + if (! $primary_registrant instanceof EEI_Registration) { |
|
| 88 | + throw new EE_Error( |
|
| 89 | + esc_html__( |
|
| 90 | + 'No primary registration on transaction while paying with PayPal Pro.', |
|
| 91 | + 'event_espresso' |
|
| 92 | + ) |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + $attendee = $primary_registrant->attendee(); |
|
| 96 | + if (! $attendee instanceof EEI_Attendee) { |
|
| 97 | + throw new EE_Error( |
|
| 98 | + esc_html__( |
|
| 99 | + 'No attendee on primary registration while paying with PayPal Pro.', |
|
| 100 | + 'event_espresso' |
|
| 101 | + ) |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 105 | + $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 106 | + // charge for the full amount. Show itemized list |
|
| 107 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 108 | + $item_num = 1; |
|
| 109 | + $total_line_item = $transaction->total_line_item(); |
|
| 110 | + $order_items = array(); |
|
| 111 | + foreach ($total_line_item->get_items() as $line_item) { |
|
| 112 | + // ignore line items with a quantity of 0 |
|
| 113 | + if ($line_item->quantity() == 0) { |
|
| 114 | + continue; |
|
| 115 | + } |
|
| 116 | + // For percent items, whose unit_price is 0, use the total instead. |
|
| 117 | + if ($line_item->is_percent()) { |
|
| 118 | + $unit_price = $line_item->total(); |
|
| 119 | + $line_item_quantity = 1; |
|
| 120 | + } else { |
|
| 121 | + $unit_price = $line_item->unit_price(); |
|
| 122 | + $line_item_quantity = $line_item->quantity(); |
|
| 123 | + } |
|
| 124 | + $item = array( |
|
| 125 | + // Item Name. 127 char max. |
|
| 126 | + 'l_name' => substr( |
|
| 127 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 128 | + 0, |
|
| 129 | + 127 |
|
| 130 | + ), |
|
| 131 | + // Item description. 127 char max. |
|
| 132 | + 'l_desc' => substr( |
|
| 133 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 134 | + 0, |
|
| 135 | + 127 |
|
| 136 | + ), |
|
| 137 | + // Cost of individual item. |
|
| 138 | + 'l_amt' => $unit_price, |
|
| 139 | + // Item Number. 127 char max. |
|
| 140 | + 'l_number' => $item_num++, |
|
| 141 | + // Item quantity. Must be any positive integer. |
|
| 142 | + 'l_qty' => $line_item_quantity, |
|
| 143 | + // Item's sales tax amount. |
|
| 144 | + 'l_taxamt' => '', |
|
| 145 | + // eBay auction number of item. |
|
| 146 | + 'l_ebayitemnumber' => '', |
|
| 147 | + // eBay transaction ID of purchased item. |
|
| 148 | + 'l_ebayitemauctiontxnid' => '', |
|
| 149 | + // eBay order ID for the item. |
|
| 150 | + 'l_ebayitemorderid' => '', |
|
| 151 | + ); |
|
| 152 | + // add to array of all items |
|
| 153 | + array_push($order_items, $item); |
|
| 154 | + } |
|
| 155 | + $item_amount = $total_line_item->get_items_total(); |
|
| 156 | + $tax_amount = $total_line_item->get_total_tax(); |
|
| 157 | + } else { |
|
| 158 | + $order_items = array(); |
|
| 159 | + $item_amount = $payment->amount(); |
|
| 160 | + $tax_amount = 0; |
|
| 161 | + array_push($order_items, array( |
|
| 162 | + // Item Name. 127 char max. |
|
| 163 | + 'l_name' => substr( |
|
| 164 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 165 | + 0, |
|
| 166 | + 127 |
|
| 167 | + ), |
|
| 168 | + // Item description. 127 char max. |
|
| 169 | + 'l_desc' => substr( |
|
| 170 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 171 | + 0, |
|
| 172 | + 127 |
|
| 173 | + ), |
|
| 174 | + // Cost of individual item. |
|
| 175 | + 'l_amt' => $payment->amount(), |
|
| 176 | + // Item Number. 127 char max. |
|
| 177 | + 'l_number' => 1, |
|
| 178 | + // Item quantity. Must be any positive integer. |
|
| 179 | + 'l_qty' => 1, |
|
| 180 | + )); |
|
| 181 | + } |
|
| 182 | + // Populate data arrays with order data. |
|
| 183 | + $DPFields = array( |
|
| 184 | + // How you want to obtain payment ? |
|
| 185 | + // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
| 186 | + // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
| 187 | + 'paymentaction' => 'Sale', |
|
| 188 | + // Required. IP address of the payer's browser. |
|
| 189 | + 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
| 190 | + // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
| 191 | + 'returnfmfdetails' => '1', |
|
| 192 | + ); |
|
| 193 | + $CCDetails = array( |
|
| 194 | + // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
| 195 | + // If Maestro or Solo, the currency code must be GBP. |
|
| 196 | + // In addition, either start date or issue number must be specified. |
|
| 197 | + 'creditcardtype' => $billing_info['credit_card_type'], |
|
| 198 | + // Required. Credit card number. No spaces or punctuation. |
|
| 199 | + 'acct' => $billing_info['credit_card'], |
|
| 200 | + // Required. Credit card expiration date. Format is MMYYYY |
|
| 201 | + 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
| 202 | + // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
| 203 | + 'cvv2' => $billing_info['cvv'], |
|
| 204 | + ); |
|
| 205 | + $PayerInfo = array( |
|
| 206 | + // Email address of payer. |
|
| 207 | + 'email' => $billing_info['email'], |
|
| 208 | + // Unique PayPal customer ID for payer. |
|
| 209 | + 'payerid' => '', |
|
| 210 | + // Status of payer. Values are verified or unverified |
|
| 211 | + 'payerstatus' => '', |
|
| 212 | + // Payer's business name. |
|
| 213 | + 'business' => '', |
|
| 214 | + ); |
|
| 215 | + $PayerName = array( |
|
| 216 | + // Payer's salutation. 20 char max. |
|
| 217 | + 'salutation' => '', |
|
| 218 | + // Payer's first name. 25 char max. |
|
| 219 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
| 220 | + // Payer's middle name. 25 char max. |
|
| 221 | + 'middlename' => '', |
|
| 222 | + // Payer's last name. 25 char max. |
|
| 223 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
| 224 | + // Payer's suffix. 12 char max. |
|
| 225 | + 'suffix' => '', |
|
| 226 | + ); |
|
| 227 | + $BillingAddress = array( |
|
| 228 | + // Required. First street address. |
|
| 229 | + 'street' => $billing_info['address'], |
|
| 230 | + // Second street address. |
|
| 231 | + 'street2' => $billing_info['address2'], |
|
| 232 | + // Required. Name of City. |
|
| 233 | + 'city' => $billing_info['city'], |
|
| 234 | + // Required. Name of State or Province. |
|
| 235 | + 'state' => substr($billing_info['state'], 0, 40), |
|
| 236 | + // Required. Country code. |
|
| 237 | + 'countrycode' => $billing_info['country'], |
|
| 238 | + // Required. Postal code of payer. |
|
| 239 | + 'zip' => $billing_info['zip'], |
|
| 240 | + ); |
|
| 241 | + // check if the registration info contains the needed fields for paypal pro |
|
| 242 | + // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
| 243 | + if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
| 244 | + $use_registration_address_info = true; |
|
| 245 | + } else { |
|
| 246 | + $use_registration_address_info = false; |
|
| 247 | + } |
|
| 248 | + // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
| 249 | + // If not, use the billing info again |
|
| 250 | + $ShippingAddress = array( |
|
| 251 | + 'shiptoname' => substr($use_registration_address_info |
|
| 252 | + ? $attendee->full_name() |
|
| 253 | + : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
| 254 | + 'shiptostreet' => substr($use_registration_address_info |
|
| 255 | + ? $attendee->address() |
|
| 256 | + : $billing_info['address'], 0, 100), |
|
| 257 | + 'shiptostreet2' => substr($use_registration_address_info |
|
| 258 | + ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
| 259 | + 'shiptocity' => substr($use_registration_address_info |
|
| 260 | + ? $attendee->city() |
|
| 261 | + : $billing_info['city'], 0, 40), |
|
| 262 | + 'state' => substr($use_registration_address_info |
|
| 263 | + ? $attendee->state_name() |
|
| 264 | + : $billing_info['state'], 0, 40), |
|
| 265 | + 'shiptocountry' => $use_registration_address_info |
|
| 266 | + ? $attendee->country_ID() |
|
| 267 | + : $billing_info['country'], |
|
| 268 | + 'shiptozip' => substr($use_registration_address_info |
|
| 269 | + ? $attendee->zip() |
|
| 270 | + : $billing_info['zip'], 0, 20), |
|
| 271 | + 'shiptophonenum' => substr($use_registration_address_info |
|
| 272 | + ? $attendee->phone() |
|
| 273 | + : $billing_info['phone'], 0, 20), |
|
| 274 | + ); |
|
| 275 | + $PaymentDetails = array( |
|
| 276 | + // Required. Total amount of order, including shipping, handling, and tax. |
|
| 277 | + 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
| 278 | + // Required. Three-letter currency code. Default is USD. |
|
| 279 | + 'currencycode' => $payment->currency_code(), |
|
| 280 | + // Required if you include itemized cart details. (L_AMTn, etc.) |
|
| 281 | + // Subtotal of items not including S&H, or tax. |
|
| 282 | + 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
| 283 | + // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
| 284 | + 'shippingamt' => '', |
|
| 285 | + // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
| 286 | + 'handlingamt' => '', |
|
| 287 | + // Required if you specify itemized cart tax details. |
|
| 288 | + // Sum of tax for all items on the order. Total sales tax. |
|
| 289 | + 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
| 290 | + // Description of the order the customer is purchasing. 127 char max. |
|
| 291 | + 'desc' => $order_description, |
|
| 292 | + // Free-form field for your own use. 256 char max. |
|
| 293 | + 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
| 294 | + // Your own invoice or tracking number |
|
| 295 | + 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
| 296 | + // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
| 297 | + 'notifyurl' => '', |
|
| 298 | + 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
| 299 | + ); |
|
| 300 | + // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
| 301 | + $PayPalRequestData = array( |
|
| 302 | + 'DPFields' => $DPFields, |
|
| 303 | + 'CCDetails' => $CCDetails, |
|
| 304 | + 'PayerInfo' => $PayerInfo, |
|
| 305 | + 'PayerName' => $PayerName, |
|
| 306 | + 'BillingAddress' => $BillingAddress, |
|
| 307 | + 'ShippingAddress' => $ShippingAddress, |
|
| 308 | + 'PaymentDetails' => $PaymentDetails, |
|
| 309 | + 'OrderItems' => $order_items, |
|
| 310 | + ); |
|
| 311 | + $this->_log_clean_request($PayPalRequestData, $payment); |
|
| 312 | + try { |
|
| 313 | + $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
| 314 | + // remove PCI-sensitive data so it doesn't get stored |
|
| 315 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
| 316 | + if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
| 317 | + $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
|
| 318 | + } elseif (isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
| 319 | + $message = $PayPalResult['L_LONGMESSAGE0']; |
|
| 320 | + } else { |
|
| 321 | + $message = $PayPalResult['ACK']; |
|
| 322 | + } |
|
| 323 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
| 324 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 325 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
| 326 | + $payment->set_details($PayPalResult); |
|
| 327 | + } else { |
|
| 328 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
| 329 | + $payment->set_status($this->_pay_model->approved_status()); |
|
| 330 | + } else { |
|
| 331 | + $payment->set_status($this->_pay_model->declined_status()); |
|
| 332 | + } |
|
| 333 | + // make sure we interpret the AMT as a float, not an international string |
|
| 334 | + // (where periods are thousand separators) |
|
| 335 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
| 336 | + $payment->set_gateway_response($message); |
|
| 337 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
| 338 | + ? $PayPalResult['TRANSACTIONID'] |
|
| 339 | + : null); |
|
| 340 | + $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
| 341 | + ? $primary_registrant->reg_code() |
|
| 342 | + : ''; |
|
| 343 | + $payment->set_extra_accntng($primary_registration_code); |
|
| 344 | + $payment->set_details($PayPalResult); |
|
| 345 | + } |
|
| 346 | + } catch (Exception $e) { |
|
| 347 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 348 | + $payment->set_gateway_response($e->getMessage()); |
|
| 349 | + } |
|
| 350 | + // $payment->set_status( $this->_pay_model->declined_status() ); |
|
| 351 | + // $payment->set_gateway_response( '' ); |
|
| 352 | + return $payment; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
| 359 | + * |
|
| 360 | + * @param array $request |
|
| 361 | + * @param EEI_Payment $payment |
|
| 362 | + * @return void |
|
| 363 | + */ |
|
| 364 | + private function _log_clean_request($request, $payment) |
|
| 365 | + { |
|
| 366 | + $cleaned_request_data = $request; |
|
| 367 | + unset($cleaned_request_data['CCDetails']['acct']); |
|
| 368 | + unset($cleaned_request_data['CCDetails']['cvv2']); |
|
| 369 | + unset($cleaned_request_data['CCDetails']['expdate']); |
|
| 370 | + $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Cleans the response, logs it, and returns it |
|
| 377 | + * |
|
| 378 | + * @param array $response |
|
| 379 | + * @param EEI_Payment $payment |
|
| 380 | + * @return array cleaned |
|
| 381 | + */ |
|
| 382 | + private function _log_clean_response($response, $payment) |
|
| 383 | + { |
|
| 384 | + unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
| 385 | + unset($response['REQUESTDATA']['ACCT']); |
|
| 386 | + unset($response['REQUESTDATA']['EXPDATE']); |
|
| 387 | + unset($response['REQUESTDATA']['CVV2']); |
|
| 388 | + unset($response['RAWREQUEST']); |
|
| 389 | + $this->log(array('Paypal Response' => $response), $payment); |
|
| 390 | + return $response; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @param $DataArray |
|
| 397 | + * @return array |
|
| 398 | + */ |
|
| 399 | + private function prep_and_curl_request($DataArray) |
|
| 400 | + { |
|
| 401 | + // Create empty holders for each portion of the NVP string |
|
| 402 | + $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
| 403 | + $CCDetailsNVP = ''; |
|
| 404 | + $PayerInfoNVP = ''; |
|
| 405 | + $PayerNameNVP = ''; |
|
| 406 | + $BillingAddressNVP = ''; |
|
| 407 | + $ShippingAddressNVP = ''; |
|
| 408 | + $PaymentDetailsNVP = ''; |
|
| 409 | + $OrderItemsNVP = ''; |
|
| 410 | + $Secure3DNVP = ''; |
|
| 411 | + // DP Fields |
|
| 412 | + $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
| 413 | + foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
| 414 | + $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
| 415 | + } |
|
| 416 | + // CC Details Fields |
|
| 417 | + $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
| 418 | + foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
| 419 | + $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
| 420 | + } |
|
| 421 | + // PayerInfo Type Fields |
|
| 422 | + $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
| 423 | + foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
| 424 | + $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
| 425 | + } |
|
| 426 | + // Payer Name Fields |
|
| 427 | + $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
| 428 | + foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
| 429 | + $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
| 430 | + } |
|
| 431 | + // Address Fields (Billing) |
|
| 432 | + $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
| 433 | + foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
| 434 | + $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
| 435 | + } |
|
| 436 | + // Payment Details Type Fields |
|
| 437 | + $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
| 438 | + foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
| 439 | + $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
| 440 | + } |
|
| 441 | + // Payment Details Item Type Fields |
|
| 442 | + $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
| 443 | + $n = 0; |
|
| 444 | + foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
| 445 | + $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
| 446 | + foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
| 447 | + $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
| 448 | + } |
|
| 449 | + $n++; |
|
| 450 | + } |
|
| 451 | + // Ship To Address Fields |
|
| 452 | + $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
| 453 | + foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
| 454 | + $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
| 455 | + } |
|
| 456 | + // 3D Secure Fields |
|
| 457 | + $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
| 458 | + foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
| 459 | + $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
| 460 | + } |
|
| 461 | + // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
| 462 | + $NVPRequest = 'USER=' |
|
| 463 | + . $this->_api_username |
|
| 464 | + . '&PWD=' |
|
| 465 | + . $this->_api_password |
|
| 466 | + . '&VERSION=64.0' |
|
| 467 | + . '&SIGNATURE=' |
|
| 468 | + . $this->_api_signature |
|
| 469 | + . $DPFieldsNVP |
|
| 470 | + . $CCDetailsNVP |
|
| 471 | + . $PayerInfoNVP |
|
| 472 | + . $PayerNameNVP |
|
| 473 | + . $BillingAddressNVP |
|
| 474 | + . $PaymentDetailsNVP |
|
| 475 | + . $OrderItemsNVP |
|
| 476 | + . $ShippingAddressNVP |
|
| 477 | + . $Secure3DNVP; |
|
| 478 | + $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
| 479 | + $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
| 480 | + $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
| 481 | + $Errors = $this->_GetErrors($NVPResponseArray); |
|
| 482 | + $NVPResponseArray['ERRORS'] = $Errors; |
|
| 483 | + $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
| 484 | + $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
| 485 | + $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
| 486 | + return $NVPResponseArray; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @param $Request |
|
| 493 | + * @return mixed |
|
| 494 | + */ |
|
| 495 | + private function _CURLRequest($Request) |
|
| 496 | + { |
|
| 497 | + $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
| 498 | + $curl = curl_init(); |
|
| 499 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
| 500 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
| 501 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
| 502 | + curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
| 503 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
| 504 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
| 505 | + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
| 506 | + // execute the curl POST |
|
| 507 | + $Response = curl_exec($curl); |
|
| 508 | + curl_close($curl); |
|
| 509 | + return $Response; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * @param $NVPString |
|
| 516 | + * @return array |
|
| 517 | + */ |
|
| 518 | + private function _NVPToArray($NVPString) |
|
| 519 | + { |
|
| 520 | + // prepare responses into array |
|
| 521 | + $proArray = array(); |
|
| 522 | + while (strlen($NVPString)) { |
|
| 523 | + // name |
|
| 524 | + $keypos = strpos($NVPString, '='); |
|
| 525 | + $keyval = substr($NVPString, 0, $keypos); |
|
| 526 | + // value |
|
| 527 | + $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
| 528 | + $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
| 529 | + // decoding the response |
|
| 530 | + $proArray[ $keyval ] = urldecode($valval); |
|
| 531 | + $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
| 532 | + } |
|
| 533 | + return $proArray; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @param array $PayPalResult |
|
| 540 | + * @return bool |
|
| 541 | + */ |
|
| 542 | + private function _APICallSuccessful($PayPalResult) |
|
| 543 | + { |
|
| 544 | + $approved = false; |
|
| 545 | + // check main response message from PayPal |
|
| 546 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
| 547 | + $ack = strtoupper($PayPalResult['ACK']); |
|
| 548 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
| 549 | + } |
|
| 550 | + return $approved; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * @param $DataArray |
|
| 557 | + * @return array |
|
| 558 | + */ |
|
| 559 | + private function _GetErrors($DataArray) |
|
| 560 | + { |
|
| 561 | + $Errors = array(); |
|
| 562 | + $n = 0; |
|
| 563 | + while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
| 564 | + $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
| 565 | + $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
| 566 | + ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
| 567 | + : ''; |
|
| 568 | + $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
| 569 | + ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
| 570 | + : ''; |
|
| 571 | + $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
| 572 | + ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
| 573 | + : ''; |
|
| 574 | + $CurrentItem = array( |
|
| 575 | + 'L_ERRORCODE' => $LErrorCode, |
|
| 576 | + 'L_SHORTMESSAGE' => $LShortMessage, |
|
| 577 | + 'L_LONGMESSAGE' => $LLongMessage, |
|
| 578 | + 'L_SEVERITYCODE' => $LSeverityCode, |
|
| 579 | + ); |
|
| 580 | + array_push($Errors, $CurrentItem); |
|
| 581 | + $n++; |
|
| 582 | + } |
|
| 583 | + return $Errors; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * nothing to see here... move along.... |
|
| 590 | + * |
|
| 591 | + * @access protected |
|
| 592 | + * @param $Errors |
|
| 593 | + * @return string |
|
| 594 | + */ |
|
| 595 | + private function _DisplayErrors($Errors) |
|
| 596 | + { |
|
| 597 | + $error = ''; |
|
| 598 | + foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
| 599 | + $CurrentError = $Errors[ $ErrorVar ]; |
|
| 600 | + foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
| 601 | + $CurrentVarName = ''; |
|
| 602 | + if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
| 603 | + $CurrentVarName = 'Error Code'; |
|
| 604 | + } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
| 605 | + $CurrentVarName = 'Short Message'; |
|
| 606 | + } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
| 607 | + $CurrentVarName = 'Long Message'; |
|
| 608 | + } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
| 609 | + $CurrentVarName = 'Severity Code'; |
|
| 610 | + } |
|
| 611 | + $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + return $error; |
|
| 615 | + } |
|
| 616 | 616 | } |
@@ -63,22 +63,22 @@ discard block |
||
| 63 | 63 | // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
| 64 | 64 | 'subsections'=>array( |
| 65 | 65 | 'credit_card'=>new EE_Credit_Card_Input( |
| 66 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
| 66 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
| 67 | 67 | ), |
| 68 | 68 | 'credit_card_type'=>new EE_Select_Input( |
| 69 | 69 | // the options are set dynamically |
| 70 | 70 | array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
| 71 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
| 71 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
| 72 | 72 | ), |
| 73 | 73 | 'exp_month'=>new EE_Credit_Card_Month_Input( |
| 74 | 74 | true, |
| 75 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
| 75 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso')) |
|
| 76 | 76 | ), |
| 77 | 77 | 'exp_year'=>new EE_Credit_Card_Year_Input( |
| 78 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
| 78 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso')) |
|
| 79 | 79 | ), |
| 80 | 80 | 'cvv'=>new EE_CVV_Input( |
| 81 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
| 81 | + array('required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso')) |
|
| 82 | 82 | ), |
| 83 | 83 | ) |
| 84 | 84 | ) |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | if ($this->_pm_instance->debug_mode()) { |
| 101 | 101 | $billing_form->add_subsections( |
| 102 | - array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
| 102 | + array('fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html()), |
|
| 103 | 103 | 'credit_card' |
| 104 | 104 | ); |
| 105 | 105 | $billing_form->add_subsections( |
| 106 | - array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
| 106 | + array('debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
| 107 | 107 | 'first_name' |
| 108 | 108 | ); |
| 109 | 109 | $billing_form->get_input('credit_card_type')->set_default('Visa'); |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | ] |
| 185 | 185 | ); |
| 186 | 186 | // If they existed, set the new ones instead |
| 187 | - if (!empty($old_extra_metas)) { |
|
| 187 | + if ( ! empty($old_extra_metas)) { |
|
| 188 | 188 | foreach ($old_extra_metas as $old_extra_meta) { |
| 189 | - $old_extra_meta->set('EXM_key', 'api_' . $old_extra_meta->get('EXM_key')); |
|
| 189 | + $old_extra_meta->set('EXM_key', 'api_'.$old_extra_meta->get('EXM_key')); |
|
| 190 | 190 | $old_extra_meta->save(); |
| 191 | 191 | } |
| 192 | 192 | } |
@@ -14,182 +14,182 @@ |
||
| 14 | 14 | class EE_PMT_Paypal_Pro extends EE_PMT_Base |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param EE_Payment_Method $pm_instance |
|
| 19 | - * @return EE_PMT_Paypal_Pro |
|
| 20 | - */ |
|
| 21 | - public function __construct($pm_instance = null) |
|
| 22 | - { |
|
| 23 | - require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php'); |
|
| 24 | - $this->_gateway = new EEG_Paypal_Pro(); |
|
| 25 | - $this->_pretty_name = __("Paypal Pro", 'event_espresso'); |
|
| 26 | - $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
| 27 | - $this->_requires_https = true; |
|
| 28 | - parent::__construct($pm_instance); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Gets the form for all the settings related to this payment method type |
|
| 34 | - * @return EE_Payment_Method_Form |
|
| 35 | - * @throws InvalidArgumentException |
|
| 36 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 37 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 38 | - */ |
|
| 39 | - public function generate_new_settings_form() |
|
| 40 | - { |
|
| 41 | - return new PayPalProSettingsForm(array(), $this->get_help_tab_link()); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Creates the billing form for this payment method type |
|
| 47 | - * @param \EE_Transaction $transaction |
|
| 48 | - * @throws \EE_Error |
|
| 49 | - * @return EE_Billing_Info_Form |
|
| 50 | - */ |
|
| 51 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
| 52 | - { |
|
| 53 | - $allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', true); |
|
| 54 | - // if allowed types is a string or empty array or null... |
|
| 55 | - if (empty($allowed_types)) { |
|
| 56 | - $allowed_types = array(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $billing_form = new EE_Billing_Attendee_Info_Form( |
|
| 60 | - $this->_pm_instance, |
|
| 61 | - array( |
|
| 62 | - 'name'=> 'Paypal_Pro_Billing_Form', |
|
| 63 | - // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
|
| 64 | - 'subsections'=>array( |
|
| 65 | - 'credit_card'=>new EE_Credit_Card_Input( |
|
| 66 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
| 67 | - ), |
|
| 68 | - 'credit_card_type'=>new EE_Select_Input( |
|
| 69 | - // the options are set dynamically |
|
| 70 | - array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
|
| 71 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
| 72 | - ), |
|
| 73 | - 'exp_month'=>new EE_Credit_Card_Month_Input( |
|
| 74 | - true, |
|
| 75 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
| 76 | - ), |
|
| 77 | - 'exp_year'=>new EE_Credit_Card_Year_Input( |
|
| 78 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
| 79 | - ), |
|
| 80 | - 'cvv'=>new EE_CVV_Input( |
|
| 81 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
| 82 | - ), |
|
| 83 | - ) |
|
| 84 | - ) |
|
| 85 | - ); |
|
| 86 | - return $this->apply_billing_form_debug_settings($billing_form); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * apply_billing_form_debug_settings |
|
| 93 | - * applies debug data to the form |
|
| 94 | - * |
|
| 95 | - * @param \EE_Billing_Info_Form $billing_form |
|
| 96 | - * @return \EE_Billing_Info_Form |
|
| 97 | - */ |
|
| 98 | - public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
| 99 | - { |
|
| 100 | - if ($this->_pm_instance->debug_mode()) { |
|
| 101 | - $billing_form->add_subsections( |
|
| 102 | - array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
| 103 | - 'credit_card' |
|
| 104 | - ); |
|
| 105 | - $billing_form->add_subsections( |
|
| 106 | - array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
| 107 | - 'first_name' |
|
| 108 | - ); |
|
| 109 | - $billing_form->get_input('credit_card_type')->set_default('Visa'); |
|
| 110 | - $billing_form->get_input('exp_year')->set_default(2018); |
|
| 111 | - $billing_form->get_input('cvv')->set_default('115'); |
|
| 112 | - } |
|
| 113 | - return $billing_form; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Returns an array of all the payment cards possibly supported by paypal pro. |
|
| 120 | - * Keys are their values, values are their pretty names. |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - public static function card_types_supported() |
|
| 124 | - { |
|
| 125 | - return array( |
|
| 126 | - 'Visa'=> __("Visa", 'event_espresso'), |
|
| 127 | - 'MasterCard'=> __("MasterCard", 'event_espresso'), |
|
| 128 | - 'Amex'=> __("American Express", 'event_espresso'), |
|
| 129 | - 'Discover'=> __("Discover", 'event_espresso') |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Adds the help tab |
|
| 137 | - * @see EE_PMT_Base::help_tabs_config() |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function help_tabs_config() |
|
| 141 | - { |
|
| 142 | - return array( |
|
| 143 | - $this->get_help_tab_name() => array( |
|
| 144 | - 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
| 145 | - 'filename' => 'payment_methods_overview_paypalpro' |
|
| 146 | - ), |
|
| 147 | - ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Overrides parent's _get_billing_values_from_form because we want to |
|
| 152 | - * get the country's 2-character ISO code, not the name like most gateways |
|
| 153 | - * @param EE_Billing_Info_Form $billing_form |
|
| 154 | - * @return array |
|
| 155 | - */ |
|
| 156 | - protected function _get_billing_values_from_form($billing_form) |
|
| 157 | - { |
|
| 158 | - $billing_values = parent::_get_billing_values_from_form($billing_form); |
|
| 159 | - $billing_values['country'] = $billing_form->get_input_value('country'); |
|
| 160 | - $billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type'); |
|
| 161 | - return $billing_values; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Override parent to account for a change in extra meta inputs in 4.9.75.p |
|
| 166 | - * @since 4.9.79.p |
|
| 167 | - * @param EE_Payment_Method $payment_method_instance |
|
| 168 | - * @throws EE_Error |
|
| 169 | - * @throws InvalidArgumentException |
|
| 170 | - * @throws ReflectionException |
|
| 171 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 172 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 173 | - */ |
|
| 174 | - public function set_instance($payment_method_instance) |
|
| 175 | - { |
|
| 176 | - // Check for the old extra meta inputs |
|
| 177 | - $old_extra_metas = EEM_Extra_Meta::instance()->get_all( |
|
| 178 | - [ |
|
| 179 | - [ |
|
| 180 | - 'EXM_type' => 'Payment_Method', |
|
| 181 | - 'OBJ_ID' => $payment_method_instance->ID(), |
|
| 182 | - 'EXM_key' => ['IN', ['username', 'password', 'signature']], |
|
| 183 | - ] |
|
| 184 | - ] |
|
| 185 | - ); |
|
| 186 | - // If they existed, set the new ones instead |
|
| 187 | - if (!empty($old_extra_metas)) { |
|
| 188 | - foreach ($old_extra_metas as $old_extra_meta) { |
|
| 189 | - $old_extra_meta->set('EXM_key', 'api_' . $old_extra_meta->get('EXM_key')); |
|
| 190 | - $old_extra_meta->save(); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - return parent::set_instance($payment_method_instance); |
|
| 194 | - } |
|
| 17 | + /** |
|
| 18 | + * @param EE_Payment_Method $pm_instance |
|
| 19 | + * @return EE_PMT_Paypal_Pro |
|
| 20 | + */ |
|
| 21 | + public function __construct($pm_instance = null) |
|
| 22 | + { |
|
| 23 | + require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php'); |
|
| 24 | + $this->_gateway = new EEG_Paypal_Pro(); |
|
| 25 | + $this->_pretty_name = __("Paypal Pro", 'event_espresso'); |
|
| 26 | + $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
| 27 | + $this->_requires_https = true; |
|
| 28 | + parent::__construct($pm_instance); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Gets the form for all the settings related to this payment method type |
|
| 34 | + * @return EE_Payment_Method_Form |
|
| 35 | + * @throws InvalidArgumentException |
|
| 36 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 37 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 38 | + */ |
|
| 39 | + public function generate_new_settings_form() |
|
| 40 | + { |
|
| 41 | + return new PayPalProSettingsForm(array(), $this->get_help_tab_link()); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Creates the billing form for this payment method type |
|
| 47 | + * @param \EE_Transaction $transaction |
|
| 48 | + * @throws \EE_Error |
|
| 49 | + * @return EE_Billing_Info_Form |
|
| 50 | + */ |
|
| 51 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
| 52 | + { |
|
| 53 | + $allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', true); |
|
| 54 | + // if allowed types is a string or empty array or null... |
|
| 55 | + if (empty($allowed_types)) { |
|
| 56 | + $allowed_types = array(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $billing_form = new EE_Billing_Attendee_Info_Form( |
|
| 60 | + $this->_pm_instance, |
|
| 61 | + array( |
|
| 62 | + 'name'=> 'Paypal_Pro_Billing_Form', |
|
| 63 | + // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
|
| 64 | + 'subsections'=>array( |
|
| 65 | + 'credit_card'=>new EE_Credit_Card_Input( |
|
| 66 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
| 67 | + ), |
|
| 68 | + 'credit_card_type'=>new EE_Select_Input( |
|
| 69 | + // the options are set dynamically |
|
| 70 | + array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
|
| 71 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
| 72 | + ), |
|
| 73 | + 'exp_month'=>new EE_Credit_Card_Month_Input( |
|
| 74 | + true, |
|
| 75 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
| 76 | + ), |
|
| 77 | + 'exp_year'=>new EE_Credit_Card_Year_Input( |
|
| 78 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
| 79 | + ), |
|
| 80 | + 'cvv'=>new EE_CVV_Input( |
|
| 81 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
| 82 | + ), |
|
| 83 | + ) |
|
| 84 | + ) |
|
| 85 | + ); |
|
| 86 | + return $this->apply_billing_form_debug_settings($billing_form); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * apply_billing_form_debug_settings |
|
| 93 | + * applies debug data to the form |
|
| 94 | + * |
|
| 95 | + * @param \EE_Billing_Info_Form $billing_form |
|
| 96 | + * @return \EE_Billing_Info_Form |
|
| 97 | + */ |
|
| 98 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
| 99 | + { |
|
| 100 | + if ($this->_pm_instance->debug_mode()) { |
|
| 101 | + $billing_form->add_subsections( |
|
| 102 | + array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
| 103 | + 'credit_card' |
|
| 104 | + ); |
|
| 105 | + $billing_form->add_subsections( |
|
| 106 | + array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
| 107 | + 'first_name' |
|
| 108 | + ); |
|
| 109 | + $billing_form->get_input('credit_card_type')->set_default('Visa'); |
|
| 110 | + $billing_form->get_input('exp_year')->set_default(2018); |
|
| 111 | + $billing_form->get_input('cvv')->set_default('115'); |
|
| 112 | + } |
|
| 113 | + return $billing_form; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Returns an array of all the payment cards possibly supported by paypal pro. |
|
| 120 | + * Keys are their values, values are their pretty names. |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + public static function card_types_supported() |
|
| 124 | + { |
|
| 125 | + return array( |
|
| 126 | + 'Visa'=> __("Visa", 'event_espresso'), |
|
| 127 | + 'MasterCard'=> __("MasterCard", 'event_espresso'), |
|
| 128 | + 'Amex'=> __("American Express", 'event_espresso'), |
|
| 129 | + 'Discover'=> __("Discover", 'event_espresso') |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Adds the help tab |
|
| 137 | + * @see EE_PMT_Base::help_tabs_config() |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function help_tabs_config() |
|
| 141 | + { |
|
| 142 | + return array( |
|
| 143 | + $this->get_help_tab_name() => array( |
|
| 144 | + 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
| 145 | + 'filename' => 'payment_methods_overview_paypalpro' |
|
| 146 | + ), |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Overrides parent's _get_billing_values_from_form because we want to |
|
| 152 | + * get the country's 2-character ISO code, not the name like most gateways |
|
| 153 | + * @param EE_Billing_Info_Form $billing_form |
|
| 154 | + * @return array |
|
| 155 | + */ |
|
| 156 | + protected function _get_billing_values_from_form($billing_form) |
|
| 157 | + { |
|
| 158 | + $billing_values = parent::_get_billing_values_from_form($billing_form); |
|
| 159 | + $billing_values['country'] = $billing_form->get_input_value('country'); |
|
| 160 | + $billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type'); |
|
| 161 | + return $billing_values; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Override parent to account for a change in extra meta inputs in 4.9.75.p |
|
| 166 | + * @since 4.9.79.p |
|
| 167 | + * @param EE_Payment_Method $payment_method_instance |
|
| 168 | + * @throws EE_Error |
|
| 169 | + * @throws InvalidArgumentException |
|
| 170 | + * @throws ReflectionException |
|
| 171 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 172 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 173 | + */ |
|
| 174 | + public function set_instance($payment_method_instance) |
|
| 175 | + { |
|
| 176 | + // Check for the old extra meta inputs |
|
| 177 | + $old_extra_metas = EEM_Extra_Meta::instance()->get_all( |
|
| 178 | + [ |
|
| 179 | + [ |
|
| 180 | + 'EXM_type' => 'Payment_Method', |
|
| 181 | + 'OBJ_ID' => $payment_method_instance->ID(), |
|
| 182 | + 'EXM_key' => ['IN', ['username', 'password', 'signature']], |
|
| 183 | + ] |
|
| 184 | + ] |
|
| 185 | + ); |
|
| 186 | + // If they existed, set the new ones instead |
|
| 187 | + if (!empty($old_extra_metas)) { |
|
| 188 | + foreach ($old_extra_metas as $old_extra_meta) { |
|
| 189 | + $old_extra_meta->set('EXM_key', 'api_' . $old_extra_meta->get('EXM_key')); |
|
| 190 | + $old_extra_meta->save(); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + return parent::set_instance($payment_method_instance); |
|
| 194 | + } |
|
| 195 | 195 | } |
@@ -21,2045 +21,2045 @@ |
||
| 21 | 21 | class EEH_Line_Item |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Adds a simple item (unrelated to any other model object) to the provided PARENT line item. |
|
| 26 | - * Does NOT automatically re-calculate the line item totals or update the related transaction. |
|
| 27 | - * You should call recalculate_total_including_taxes() on the grant total line item after this |
|
| 28 | - * to update the subtotals, and EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 29 | - * to keep the registration final prices in-sync with the transaction's total. |
|
| 30 | - * |
|
| 31 | - * @param EE_Line_Item $parent_line_item |
|
| 32 | - * @param string $name |
|
| 33 | - * @param float $unit_price |
|
| 34 | - * @param string $description |
|
| 35 | - * @param int $quantity |
|
| 36 | - * @param boolean $taxable |
|
| 37 | - * @param boolean $code if set to a value, ensures there is only one line item with that code |
|
| 38 | - * @return boolean success |
|
| 39 | - * @throws EE_Error |
|
| 40 | - * @throws InvalidArgumentException |
|
| 41 | - * @throws InvalidDataTypeException |
|
| 42 | - * @throws InvalidInterfaceException |
|
| 43 | - * @throws ReflectionException |
|
| 44 | - */ |
|
| 45 | - public static function add_unrelated_item( |
|
| 46 | - EE_Line_Item $parent_line_item, |
|
| 47 | - $name, |
|
| 48 | - $unit_price, |
|
| 49 | - $description = '', |
|
| 50 | - $quantity = 1, |
|
| 51 | - $taxable = false, |
|
| 52 | - $code = null |
|
| 53 | - ) { |
|
| 54 | - $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
| 55 | - $line_item = EE_Line_Item::new_instance(array( |
|
| 56 | - 'LIN_name' => $name, |
|
| 57 | - 'LIN_desc' => $description, |
|
| 58 | - 'LIN_unit_price' => $unit_price, |
|
| 59 | - 'LIN_quantity' => $quantity, |
|
| 60 | - 'LIN_percent' => null, |
|
| 61 | - 'LIN_is_taxable' => $taxable, |
|
| 62 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
| 63 | - 'LIN_total' => (float) $unit_price * (int) $quantity, |
|
| 64 | - 'LIN_type' => EEM_Line_Item::type_line_item, |
|
| 65 | - 'LIN_code' => $code, |
|
| 66 | - )); |
|
| 67 | - $line_item = apply_filters( |
|
| 68 | - 'FHEE__EEH_Line_Item__add_unrelated_item__line_item', |
|
| 69 | - $line_item, |
|
| 70 | - $parent_line_item |
|
| 71 | - ); |
|
| 72 | - return self::add_item($parent_line_item, $line_item); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Adds a simple item ( unrelated to any other model object) to the total line item, |
|
| 78 | - * in the correct spot in the line item tree. Automatically |
|
| 79 | - * re-calculates the line item totals and updates the related transaction. But |
|
| 80 | - * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
| 81 | - * should probably change because of this). |
|
| 82 | - * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 83 | - * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
| 84 | - * |
|
| 85 | - * @param EE_Line_Item $parent_line_item |
|
| 86 | - * @param string $name |
|
| 87 | - * @param float $percentage_amount |
|
| 88 | - * @param string $description |
|
| 89 | - * @param boolean $taxable |
|
| 90 | - * @return boolean success |
|
| 91 | - * @throws EE_Error |
|
| 92 | - */ |
|
| 93 | - public static function add_percentage_based_item( |
|
| 94 | - EE_Line_Item $parent_line_item, |
|
| 95 | - $name, |
|
| 96 | - $percentage_amount, |
|
| 97 | - $description = '', |
|
| 98 | - $taxable = false |
|
| 99 | - ) { |
|
| 100 | - $line_item = EE_Line_Item::new_instance(array( |
|
| 101 | - 'LIN_name' => $name, |
|
| 102 | - 'LIN_desc' => $description, |
|
| 103 | - 'LIN_unit_price' => 0, |
|
| 104 | - 'LIN_percent' => $percentage_amount, |
|
| 105 | - 'LIN_quantity' => 1, |
|
| 106 | - 'LIN_is_taxable' => $taxable, |
|
| 107 | - 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
| 108 | - 'LIN_type' => EEM_Line_Item::type_line_item, |
|
| 109 | - 'LIN_parent' => $parent_line_item->ID(), |
|
| 110 | - )); |
|
| 111 | - $line_item = apply_filters( |
|
| 112 | - 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
|
| 113 | - $line_item |
|
| 114 | - ); |
|
| 115 | - return $parent_line_item->add_child_line_item($line_item, false); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Returns the new line item created by adding a purchase of the ticket |
|
| 121 | - * ensures that ticket line item is saved, and that cart total has been recalculated. |
|
| 122 | - * If this ticket has already been purchased, just increments its count. |
|
| 123 | - * Automatically re-calculates the line item totals and updates the related transaction. But |
|
| 124 | - * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
| 125 | - * should probably change because of this). |
|
| 126 | - * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 127 | - * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
| 128 | - * |
|
| 129 | - * @param EE_Line_Item $total_line_item grand total line item of type EEM_Line_Item::type_total |
|
| 130 | - * @param EE_Ticket $ticket |
|
| 131 | - * @param int $qty |
|
| 132 | - * @return EE_Line_Item |
|
| 133 | - * @throws EE_Error |
|
| 134 | - * @throws InvalidArgumentException |
|
| 135 | - * @throws InvalidDataTypeException |
|
| 136 | - * @throws InvalidInterfaceException |
|
| 137 | - * @throws ReflectionException |
|
| 138 | - */ |
|
| 139 | - public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) |
|
| 140 | - { |
|
| 141 | - if (! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
| 142 | - throw new EE_Error( |
|
| 143 | - sprintf( |
|
| 144 | - esc_html__( |
|
| 145 | - 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', |
|
| 146 | - 'event_espresso' |
|
| 147 | - ), |
|
| 148 | - $ticket->ID(), |
|
| 149 | - $total_line_item->ID() |
|
| 150 | - ) |
|
| 151 | - ); |
|
| 152 | - } |
|
| 153 | - // either increment the qty for an existing ticket |
|
| 154 | - $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
| 155 | - // or add a new one |
|
| 156 | - if (! $line_item instanceof EE_Line_Item) { |
|
| 157 | - $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
| 158 | - } |
|
| 159 | - $total_line_item->recalculate_total_including_taxes(); |
|
| 160 | - return $line_item; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Returns the new line item created by adding a purchase of the ticket |
|
| 166 | - * |
|
| 167 | - * @param EE_Line_Item $total_line_item |
|
| 168 | - * @param EE_Ticket $ticket |
|
| 169 | - * @param int $qty |
|
| 170 | - * @return EE_Line_Item |
|
| 171 | - * @throws EE_Error |
|
| 172 | - * @throws InvalidArgumentException |
|
| 173 | - * @throws InvalidDataTypeException |
|
| 174 | - * @throws InvalidInterfaceException |
|
| 175 | - * @throws ReflectionException |
|
| 176 | - */ |
|
| 177 | - public static function increment_ticket_qty_if_already_in_cart( |
|
| 178 | - EE_Line_Item $total_line_item, |
|
| 179 | - EE_Ticket $ticket, |
|
| 180 | - $qty = 1 |
|
| 181 | - ) { |
|
| 182 | - $line_item = null; |
|
| 183 | - if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
| 184 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 185 | - foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
| 186 | - if ($ticket_line_item instanceof EE_Line_Item |
|
| 187 | - && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
|
| 188 | - ) { |
|
| 189 | - $line_item = $ticket_line_item; |
|
| 190 | - break; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - if ($line_item instanceof EE_Line_Item) { |
|
| 195 | - EEH_Line_Item::increment_quantity($line_item, $qty); |
|
| 196 | - return $line_item; |
|
| 197 | - } |
|
| 198 | - return null; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Increments the line item and all its children's quantity by $qty (but percent line items are unaffected). |
|
| 204 | - * Does NOT save or recalculate other line items totals |
|
| 205 | - * |
|
| 206 | - * @param EE_Line_Item $line_item |
|
| 207 | - * @param int $qty |
|
| 208 | - * @return void |
|
| 209 | - * @throws EE_Error |
|
| 210 | - * @throws InvalidArgumentException |
|
| 211 | - * @throws InvalidDataTypeException |
|
| 212 | - * @throws InvalidInterfaceException |
|
| 213 | - * @throws ReflectionException |
|
| 214 | - */ |
|
| 215 | - public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) |
|
| 216 | - { |
|
| 217 | - if (! $line_item->is_percent()) { |
|
| 218 | - $qty += $line_item->quantity(); |
|
| 219 | - $line_item->set_quantity($qty); |
|
| 220 | - $line_item->set_total($line_item->unit_price() * $qty); |
|
| 221 | - $line_item->save(); |
|
| 222 | - } |
|
| 223 | - foreach ($line_item->children() as $child) { |
|
| 224 | - if ($child->is_sub_line_item()) { |
|
| 225 | - EEH_Line_Item::update_quantity($child, $qty); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Decrements the line item and all its children's quantity by $qty (but percent line items are unaffected). |
|
| 233 | - * Does NOT save or recalculate other line items totals |
|
| 234 | - * |
|
| 235 | - * @param EE_Line_Item $line_item |
|
| 236 | - * @param int $qty |
|
| 237 | - * @return void |
|
| 238 | - * @throws EE_Error |
|
| 239 | - * @throws InvalidArgumentException |
|
| 240 | - * @throws InvalidDataTypeException |
|
| 241 | - * @throws InvalidInterfaceException |
|
| 242 | - * @throws ReflectionException |
|
| 243 | - */ |
|
| 244 | - public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) |
|
| 245 | - { |
|
| 246 | - if (! $line_item->is_percent()) { |
|
| 247 | - $qty = $line_item->quantity() - $qty; |
|
| 248 | - $qty = max($qty, 0); |
|
| 249 | - $line_item->set_quantity($qty); |
|
| 250 | - $line_item->set_total($line_item->unit_price() * $qty); |
|
| 251 | - $line_item->save(); |
|
| 252 | - } |
|
| 253 | - foreach ($line_item->children() as $child) { |
|
| 254 | - if ($child->is_sub_line_item()) { |
|
| 255 | - EEH_Line_Item::update_quantity($child, $qty); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Updates the line item and its children's quantities to the specified number. |
|
| 263 | - * Does NOT save them or recalculate totals. |
|
| 264 | - * |
|
| 265 | - * @param EE_Line_Item $line_item |
|
| 266 | - * @param int $new_quantity |
|
| 267 | - * @throws EE_Error |
|
| 268 | - * @throws InvalidArgumentException |
|
| 269 | - * @throws InvalidDataTypeException |
|
| 270 | - * @throws InvalidInterfaceException |
|
| 271 | - * @throws ReflectionException |
|
| 272 | - */ |
|
| 273 | - public static function update_quantity(EE_Line_Item $line_item, $new_quantity) |
|
| 274 | - { |
|
| 275 | - if (! $line_item->is_percent()) { |
|
| 276 | - $line_item->set_quantity($new_quantity); |
|
| 277 | - $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
| 278 | - $line_item->save(); |
|
| 279 | - } |
|
| 280 | - foreach ($line_item->children() as $child) { |
|
| 281 | - if ($child->is_sub_line_item()) { |
|
| 282 | - EEH_Line_Item::update_quantity($child, $new_quantity); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Returns the new line item created by adding a purchase of the ticket |
|
| 290 | - * |
|
| 291 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 292 | - * @param EE_Ticket $ticket |
|
| 293 | - * @param int $qty |
|
| 294 | - * @return EE_Line_Item |
|
| 295 | - * @throws EE_Error |
|
| 296 | - * @throws InvalidArgumentException |
|
| 297 | - * @throws InvalidDataTypeException |
|
| 298 | - * @throws InvalidInterfaceException |
|
| 299 | - * @throws ReflectionException |
|
| 300 | - */ |
|
| 301 | - public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) |
|
| 302 | - { |
|
| 303 | - $datetimes = $ticket->datetimes(); |
|
| 304 | - $first_datetime = reset($datetimes); |
|
| 305 | - $first_datetime_name = esc_html__('Event', 'event_espresso'); |
|
| 306 | - if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
| 307 | - $first_datetime_name = $first_datetime->event()->name(); |
|
| 308 | - } |
|
| 309 | - $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
| 310 | - // get event subtotal line |
|
| 311 | - $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
| 312 | - // add $ticket to cart |
|
| 313 | - $line_item = EE_Line_Item::new_instance(array( |
|
| 314 | - 'LIN_name' => $ticket->name(), |
|
| 315 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
| 316 | - 'LIN_unit_price' => $ticket->price(), |
|
| 317 | - 'LIN_quantity' => $qty, |
|
| 318 | - 'LIN_is_taxable' => $ticket->taxable(), |
|
| 319 | - 'LIN_order' => count($events_sub_total->children()), |
|
| 320 | - 'LIN_total' => $ticket->price() * $qty, |
|
| 321 | - 'LIN_type' => EEM_Line_Item::type_line_item, |
|
| 322 | - 'OBJ_ID' => $ticket->ID(), |
|
| 323 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 324 | - )); |
|
| 325 | - $line_item = apply_filters( |
|
| 326 | - 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
|
| 327 | - $line_item |
|
| 328 | - ); |
|
| 329 | - $events_sub_total->add_child_line_item($line_item); |
|
| 330 | - // now add the sub-line items |
|
| 331 | - $running_total_for_ticket = 0; |
|
| 332 | - foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
| 333 | - $sign = $price->is_discount() ? -1 : 1; |
|
| 334 | - $price_total = $price->is_percent() |
|
| 335 | - ? $running_total_for_ticket * $price->amount() / 100 |
|
| 336 | - : $price->amount() * $qty; |
|
| 337 | - $sub_line_item = EE_Line_Item::new_instance(array( |
|
| 338 | - 'LIN_name' => $price->name(), |
|
| 339 | - 'LIN_desc' => $price->desc(), |
|
| 340 | - 'LIN_quantity' => $price->is_percent() ? null : $qty, |
|
| 341 | - 'LIN_is_taxable' => false, |
|
| 342 | - 'LIN_order' => $price->order(), |
|
| 343 | - 'LIN_total' => $sign * $price_total, |
|
| 344 | - 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
|
| 345 | - 'OBJ_ID' => $price->ID(), |
|
| 346 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PRICE, |
|
| 347 | - )); |
|
| 348 | - $sub_line_item = apply_filters( |
|
| 349 | - 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
|
| 350 | - $sub_line_item |
|
| 351 | - ); |
|
| 352 | - if ($price->is_percent()) { |
|
| 353 | - $sub_line_item->set_percent($sign * $price->amount()); |
|
| 354 | - } else { |
|
| 355 | - $sub_line_item->set_unit_price($sign * $price->amount()); |
|
| 356 | - } |
|
| 357 | - $running_total_for_ticket += $price_total; |
|
| 358 | - $line_item->add_child_line_item($sub_line_item); |
|
| 359 | - } |
|
| 360 | - return $line_item; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Adds the specified item under the pre-tax-sub-total line item. Automatically |
|
| 366 | - * re-calculates the line item totals and updates the related transaction. But |
|
| 367 | - * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
| 368 | - * should probably change because of this). |
|
| 369 | - * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 370 | - * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
| 371 | - * |
|
| 372 | - * @param EE_Line_Item $total_line_item |
|
| 373 | - * @param EE_Line_Item $item to be added |
|
| 374 | - * @return boolean |
|
| 375 | - * @throws EE_Error |
|
| 376 | - * @throws InvalidArgumentException |
|
| 377 | - * @throws InvalidDataTypeException |
|
| 378 | - * @throws InvalidInterfaceException |
|
| 379 | - * @throws ReflectionException |
|
| 380 | - */ |
|
| 381 | - public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) |
|
| 382 | - { |
|
| 383 | - $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
| 384 | - if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
| 385 | - $success = $pre_tax_subtotal->add_child_line_item($item); |
|
| 386 | - } else { |
|
| 387 | - return false; |
|
| 388 | - } |
|
| 389 | - $total_line_item->recalculate_total_including_taxes(); |
|
| 390 | - return $success; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * cancels an existing ticket line item, |
|
| 396 | - * by decrementing it's quantity by 1 and adding a new "type_cancellation" sub-line-item. |
|
| 397 | - * ALL totals and subtotals will NEED TO BE UPDATED after performing this action |
|
| 398 | - * |
|
| 399 | - * @param EE_Line_Item $ticket_line_item |
|
| 400 | - * @param int $qty |
|
| 401 | - * @return bool success |
|
| 402 | - * @throws EE_Error |
|
| 403 | - * @throws InvalidArgumentException |
|
| 404 | - * @throws InvalidDataTypeException |
|
| 405 | - * @throws InvalidInterfaceException |
|
| 406 | - * @throws ReflectionException |
|
| 407 | - */ |
|
| 408 | - public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) |
|
| 409 | - { |
|
| 410 | - // validate incoming line_item |
|
| 411 | - if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
| 412 | - throw new EE_Error( |
|
| 413 | - sprintf( |
|
| 414 | - esc_html__( |
|
| 415 | - 'The supplied line item must have an Object Type of "Ticket", not %1$s.', |
|
| 416 | - 'event_espresso' |
|
| 417 | - ), |
|
| 418 | - $ticket_line_item->type() |
|
| 419 | - ) |
|
| 420 | - ); |
|
| 421 | - } |
|
| 422 | - if ($ticket_line_item->quantity() < $qty) { |
|
| 423 | - throw new EE_Error( |
|
| 424 | - sprintf( |
|
| 425 | - esc_html__( |
|
| 426 | - 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', |
|
| 427 | - 'event_espresso' |
|
| 428 | - ), |
|
| 429 | - $qty, |
|
| 430 | - $ticket_line_item->quantity() |
|
| 431 | - ) |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
|
| 435 | - $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
| 436 | - foreach ($ticket_line_item->children() as $child_line_item) { |
|
| 437 | - if ($child_line_item->is_sub_line_item() |
|
| 438 | - && ! $child_line_item->is_percent() |
|
| 439 | - && ! $child_line_item->is_cancellation() |
|
| 440 | - ) { |
|
| 441 | - $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - // get cancellation sub line item |
|
| 445 | - $cancellation_line_item = EEH_Line_Item::get_descendants_of_type( |
|
| 446 | - $ticket_line_item, |
|
| 447 | - EEM_Line_Item::type_cancellation |
|
| 448 | - ); |
|
| 449 | - $cancellation_line_item = reset($cancellation_line_item); |
|
| 450 | - // verify that this ticket was indeed previously cancelled |
|
| 451 | - if ($cancellation_line_item instanceof EE_Line_Item) { |
|
| 452 | - // increment cancelled quantity |
|
| 453 | - $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
| 454 | - } else { |
|
| 455 | - // create cancellation sub line item |
|
| 456 | - $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
| 457 | - 'LIN_name' => esc_html__('Cancellation', 'event_espresso'), |
|
| 458 | - 'LIN_desc' => sprintf( |
|
| 459 | - esc_html_x( |
|
| 460 | - 'Cancelled %1$s : %2$s', |
|
| 461 | - 'Cancelled Ticket Name : 2015-01-01 11:11', |
|
| 462 | - 'event_espresso' |
|
| 463 | - ), |
|
| 464 | - $ticket_line_item->name(), |
|
| 465 | - current_time(get_option('date_format') . ' ' . get_option('time_format')) |
|
| 466 | - ), |
|
| 467 | - 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
|
| 468 | - 'LIN_quantity' => $qty, |
|
| 469 | - 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
|
| 470 | - 'LIN_order' => count($ticket_line_item->children()), |
|
| 471 | - 'LIN_total' => 0, // $ticket_line_item->unit_price() |
|
| 472 | - 'LIN_type' => EEM_Line_Item::type_cancellation, |
|
| 473 | - )); |
|
| 474 | - $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
| 475 | - } |
|
| 476 | - if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
| 477 | - // decrement parent line item quantity |
|
| 478 | - $event_line_item = $ticket_line_item->parent(); |
|
| 479 | - if ($event_line_item instanceof EE_Line_Item |
|
| 480 | - && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
| 481 | - ) { |
|
| 482 | - $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
| 483 | - $event_line_item->save(); |
|
| 484 | - } |
|
| 485 | - EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
| 486 | - return true; |
|
| 487 | - } |
|
| 488 | - return false; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * reinstates (un-cancels?) a previously canceled ticket line item, |
|
| 494 | - * by incrementing it's quantity by 1, and decrementing it's "type_cancellation" sub-line-item. |
|
| 495 | - * ALL totals and subtotals will NEED TO BE UPDATED after performing this action |
|
| 496 | - * |
|
| 497 | - * @param EE_Line_Item $ticket_line_item |
|
| 498 | - * @param int $qty |
|
| 499 | - * @return bool success |
|
| 500 | - * @throws EE_Error |
|
| 501 | - * @throws InvalidArgumentException |
|
| 502 | - * @throws InvalidDataTypeException |
|
| 503 | - * @throws InvalidInterfaceException |
|
| 504 | - * @throws ReflectionException |
|
| 505 | - */ |
|
| 506 | - public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) |
|
| 507 | - { |
|
| 508 | - // validate incoming line_item |
|
| 509 | - if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
| 510 | - throw new EE_Error( |
|
| 511 | - sprintf( |
|
| 512 | - esc_html__( |
|
| 513 | - 'The supplied line item must have an Object Type of "Ticket", not %1$s.', |
|
| 514 | - 'event_espresso' |
|
| 515 | - ), |
|
| 516 | - $ticket_line_item->type() |
|
| 517 | - ) |
|
| 518 | - ); |
|
| 519 | - } |
|
| 520 | - // get cancellation sub line item |
|
| 521 | - $cancellation_line_item = EEH_Line_Item::get_descendants_of_type( |
|
| 522 | - $ticket_line_item, |
|
| 523 | - EEM_Line_Item::type_cancellation |
|
| 524 | - ); |
|
| 525 | - $cancellation_line_item = reset($cancellation_line_item); |
|
| 526 | - // verify that this ticket was indeed previously cancelled |
|
| 527 | - if (! $cancellation_line_item instanceof EE_Line_Item) { |
|
| 528 | - return false; |
|
| 529 | - } |
|
| 530 | - if ($cancellation_line_item->quantity() > $qty) { |
|
| 531 | - // decrement cancelled quantity |
|
| 532 | - $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
| 533 | - } elseif ($cancellation_line_item->quantity() === $qty) { |
|
| 534 | - // decrement cancelled quantity in case anyone still has the object kicking around |
|
| 535 | - $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
| 536 | - // delete because quantity will end up as 0 |
|
| 537 | - $cancellation_line_item->delete(); |
|
| 538 | - // and attempt to destroy the object, |
|
| 539 | - // even though PHP won't actually destroy it until it needs the memory |
|
| 540 | - unset($cancellation_line_item); |
|
| 541 | - } else { |
|
| 542 | - // what ?!?! negative quantity ?!?! |
|
| 543 | - throw new EE_Error( |
|
| 544 | - sprintf( |
|
| 545 | - esc_html__( |
|
| 546 | - 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
| 547 | - 'event_espresso' |
|
| 548 | - ), |
|
| 549 | - $qty, |
|
| 550 | - $cancellation_line_item->quantity() |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - // increment ticket quantity |
|
| 555 | - $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
| 556 | - if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
| 557 | - // increment parent line item quantity |
|
| 558 | - $event_line_item = $ticket_line_item->parent(); |
|
| 559 | - if ($event_line_item instanceof EE_Line_Item |
|
| 560 | - && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
| 561 | - ) { |
|
| 562 | - $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
| 563 | - } |
|
| 564 | - EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
| 565 | - return true; |
|
| 566 | - } |
|
| 567 | - return false; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * calls EEH_Line_Item::find_transaction_grand_total_for_line_item() |
|
| 573 | - * then EE_Line_Item::recalculate_total_including_taxes() on the result |
|
| 574 | - * |
|
| 575 | - * @param EE_Line_Item $line_item |
|
| 576 | - * @return float |
|
| 577 | - * @throws EE_Error |
|
| 578 | - * @throws InvalidArgumentException |
|
| 579 | - * @throws InvalidDataTypeException |
|
| 580 | - * @throws InvalidInterfaceException |
|
| 581 | - * @throws ReflectionException |
|
| 582 | - */ |
|
| 583 | - public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) |
|
| 584 | - { |
|
| 585 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
| 586 | - return $grand_total_line_item->recalculate_total_including_taxes(); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * Gets the line item which contains the subtotal of all the items |
|
| 592 | - * |
|
| 593 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 594 | - * @return EE_Line_Item |
|
| 595 | - * @throws EE_Error |
|
| 596 | - * @throws InvalidArgumentException |
|
| 597 | - * @throws InvalidDataTypeException |
|
| 598 | - * @throws InvalidInterfaceException |
|
| 599 | - * @throws ReflectionException |
|
| 600 | - */ |
|
| 601 | - public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) |
|
| 602 | - { |
|
| 603 | - $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
| 604 | - return $pre_tax_subtotal instanceof EE_Line_Item |
|
| 605 | - ? $pre_tax_subtotal |
|
| 606 | - : self::create_pre_tax_subtotal($total_line_item); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * Gets the line item for the taxes subtotal |
|
| 612 | - * |
|
| 613 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 614 | - * @return EE_Line_Item |
|
| 615 | - * @throws EE_Error |
|
| 616 | - * @throws InvalidArgumentException |
|
| 617 | - * @throws InvalidDataTypeException |
|
| 618 | - * @throws InvalidInterfaceException |
|
| 619 | - * @throws ReflectionException |
|
| 620 | - */ |
|
| 621 | - public static function get_taxes_subtotal(EE_Line_Item $total_line_item) |
|
| 622 | - { |
|
| 623 | - $taxes = $total_line_item->get_child_line_item('taxes'); |
|
| 624 | - return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * sets the TXN ID on an EE_Line_Item if passed a valid EE_Transaction object |
|
| 630 | - * |
|
| 631 | - * @param EE_Line_Item $line_item |
|
| 632 | - * @param EE_Transaction $transaction |
|
| 633 | - * @return void |
|
| 634 | - * @throws EE_Error |
|
| 635 | - * @throws InvalidArgumentException |
|
| 636 | - * @throws InvalidDataTypeException |
|
| 637 | - * @throws InvalidInterfaceException |
|
| 638 | - * @throws ReflectionException |
|
| 639 | - */ |
|
| 640 | - public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = null) |
|
| 641 | - { |
|
| 642 | - if ($transaction) { |
|
| 643 | - /** @type EEM_Transaction $EEM_Transaction */ |
|
| 644 | - $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
| 645 | - $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
| 646 | - $line_item->set_TXN_ID($TXN_ID); |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * Creates a new default total line item for the transaction, |
|
| 653 | - * and its tickets subtotal and taxes subtotal line items (and adds the |
|
| 654 | - * existing taxes as children of the taxes subtotal line item) |
|
| 655 | - * |
|
| 656 | - * @param EE_Transaction $transaction |
|
| 657 | - * @return EE_Line_Item of type total |
|
| 658 | - * @throws EE_Error |
|
| 659 | - * @throws InvalidArgumentException |
|
| 660 | - * @throws InvalidDataTypeException |
|
| 661 | - * @throws InvalidInterfaceException |
|
| 662 | - * @throws ReflectionException |
|
| 663 | - */ |
|
| 664 | - public static function create_total_line_item($transaction = null) |
|
| 665 | - { |
|
| 666 | - $total_line_item = EE_Line_Item::new_instance(array( |
|
| 667 | - 'LIN_code' => 'total', |
|
| 668 | - 'LIN_name' => esc_html__('Grand Total', 'event_espresso'), |
|
| 669 | - 'LIN_type' => EEM_Line_Item::type_total, |
|
| 670 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TRANSACTION, |
|
| 671 | - )); |
|
| 672 | - $total_line_item = apply_filters( |
|
| 673 | - 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
|
| 674 | - $total_line_item |
|
| 675 | - ); |
|
| 676 | - self::set_TXN_ID($total_line_item, $transaction); |
|
| 677 | - self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 678 | - self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 679 | - return $total_line_item; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Creates a default items subtotal line item |
|
| 685 | - * |
|
| 686 | - * @param EE_Line_Item $total_line_item |
|
| 687 | - * @param EE_Transaction $transaction |
|
| 688 | - * @return EE_Line_Item |
|
| 689 | - * @throws EE_Error |
|
| 690 | - * @throws InvalidArgumentException |
|
| 691 | - * @throws InvalidDataTypeException |
|
| 692 | - * @throws InvalidInterfaceException |
|
| 693 | - * @throws ReflectionException |
|
| 694 | - */ |
|
| 695 | - protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 696 | - { |
|
| 697 | - $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
| 698 | - 'LIN_code' => 'pre-tax-subtotal', |
|
| 699 | - 'LIN_name' => esc_html__('Pre-Tax Subtotal', 'event_espresso'), |
|
| 700 | - 'LIN_type' => EEM_Line_Item::type_sub_total, |
|
| 701 | - )); |
|
| 702 | - $pre_tax_line_item = apply_filters( |
|
| 703 | - 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
|
| 704 | - $pre_tax_line_item |
|
| 705 | - ); |
|
| 706 | - self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
| 707 | - $total_line_item->add_child_line_item($pre_tax_line_item); |
|
| 708 | - self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
| 709 | - return $pre_tax_line_item; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * Creates a line item for the taxes subtotal and finds all the tax prices |
|
| 715 | - * and applies taxes to it |
|
| 716 | - * |
|
| 717 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 718 | - * @param EE_Transaction $transaction |
|
| 719 | - * @return EE_Line_Item |
|
| 720 | - * @throws EE_Error |
|
| 721 | - * @throws InvalidArgumentException |
|
| 722 | - * @throws InvalidDataTypeException |
|
| 723 | - * @throws InvalidInterfaceException |
|
| 724 | - * @throws ReflectionException |
|
| 725 | - */ |
|
| 726 | - protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 727 | - { |
|
| 728 | - $tax_line_item = EE_Line_Item::new_instance(array( |
|
| 729 | - 'LIN_code' => 'taxes', |
|
| 730 | - 'LIN_name' => esc_html__('Taxes', 'event_espresso'), |
|
| 731 | - 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
|
| 732 | - 'LIN_order' => 1000,// this should always come last |
|
| 733 | - )); |
|
| 734 | - $tax_line_item = apply_filters( |
|
| 735 | - 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
|
| 736 | - $tax_line_item |
|
| 737 | - ); |
|
| 738 | - self::set_TXN_ID($tax_line_item, $transaction); |
|
| 739 | - $total_line_item->add_child_line_item($tax_line_item); |
|
| 740 | - // and lastly, add the actual taxes |
|
| 741 | - self::apply_taxes($total_line_item); |
|
| 742 | - return $tax_line_item; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Creates a default items subtotal line item |
|
| 748 | - * |
|
| 749 | - * @param EE_Line_Item $pre_tax_line_item |
|
| 750 | - * @param EE_Transaction $transaction |
|
| 751 | - * @param EE_Event $event |
|
| 752 | - * @return EE_Line_Item |
|
| 753 | - * @throws EE_Error |
|
| 754 | - * @throws InvalidArgumentException |
|
| 755 | - * @throws InvalidDataTypeException |
|
| 756 | - * @throws InvalidInterfaceException |
|
| 757 | - * @throws ReflectionException |
|
| 758 | - */ |
|
| 759 | - public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = null, $event = null) |
|
| 760 | - { |
|
| 761 | - $event_line_item = EE_Line_Item::new_instance(array( |
|
| 762 | - 'LIN_code' => self::get_event_code($event), |
|
| 763 | - 'LIN_name' => self::get_event_name($event), |
|
| 764 | - 'LIN_desc' => self::get_event_desc($event), |
|
| 765 | - 'LIN_type' => EEM_Line_Item::type_sub_total, |
|
| 766 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_EVENT, |
|
| 767 | - 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0, |
|
| 768 | - )); |
|
| 769 | - $event_line_item = apply_filters( |
|
| 770 | - 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
|
| 771 | - $event_line_item |
|
| 772 | - ); |
|
| 773 | - self::set_TXN_ID($event_line_item, $transaction); |
|
| 774 | - $pre_tax_line_item->add_child_line_item($event_line_item); |
|
| 775 | - return $event_line_item; |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Gets what the event ticket's code SHOULD be |
|
| 781 | - * |
|
| 782 | - * @param EE_Event $event |
|
| 783 | - * @return string |
|
| 784 | - * @throws EE_Error |
|
| 785 | - */ |
|
| 786 | - public static function get_event_code($event) |
|
| 787 | - { |
|
| 788 | - return 'event-' . ($event instanceof EE_Event ? $event->ID() : '0'); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * Gets the event name |
|
| 794 | - * |
|
| 795 | - * @param EE_Event $event |
|
| 796 | - * @return string |
|
| 797 | - * @throws EE_Error |
|
| 798 | - */ |
|
| 799 | - public static function get_event_name($event) |
|
| 800 | - { |
|
| 801 | - return $event instanceof EE_Event |
|
| 802 | - ? mb_substr($event->name(), 0, 245) |
|
| 803 | - : esc_html__('Event', 'event_espresso'); |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * Gets the event excerpt |
|
| 809 | - * |
|
| 810 | - * @param EE_Event $event |
|
| 811 | - * @return string |
|
| 812 | - * @throws EE_Error |
|
| 813 | - */ |
|
| 814 | - public static function get_event_desc($event) |
|
| 815 | - { |
|
| 816 | - return $event instanceof EE_Event ? $event->short_description() : ''; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Given the grand total line item and a ticket, finds the event sub-total |
|
| 822 | - * line item the ticket's purchase should be added onto |
|
| 823 | - * |
|
| 824 | - * @access public |
|
| 825 | - * @param EE_Line_Item $grand_total the grand total line item |
|
| 826 | - * @param EE_Ticket $ticket |
|
| 827 | - * @return EE_Line_Item |
|
| 828 | - * @throws EE_Error |
|
| 829 | - * @throws InvalidArgumentException |
|
| 830 | - * @throws InvalidDataTypeException |
|
| 831 | - * @throws InvalidInterfaceException |
|
| 832 | - * @throws ReflectionException |
|
| 833 | - */ |
|
| 834 | - public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) |
|
| 835 | - { |
|
| 836 | - $first_datetime = $ticket->first_datetime(); |
|
| 837 | - if (! $first_datetime instanceof EE_Datetime) { |
|
| 838 | - throw new EE_Error( |
|
| 839 | - sprintf( |
|
| 840 | - __('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), |
|
| 841 | - $ticket->ID() |
|
| 842 | - ) |
|
| 843 | - ); |
|
| 844 | - } |
|
| 845 | - $event = $first_datetime->event(); |
|
| 846 | - if (! $event instanceof EE_Event) { |
|
| 847 | - throw new EE_Error( |
|
| 848 | - sprintf( |
|
| 849 | - esc_html__( |
|
| 850 | - 'The supplied ticket (ID %d) has no event data associated with it.', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ), |
|
| 853 | - $ticket->ID() |
|
| 854 | - ) |
|
| 855 | - ); |
|
| 856 | - } |
|
| 857 | - $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
| 858 | - if (! $events_sub_total instanceof EE_Line_Item) { |
|
| 859 | - throw new EE_Error( |
|
| 860 | - sprintf( |
|
| 861 | - esc_html__( |
|
| 862 | - 'There is no events sub-total for ticket %s on total line item %d', |
|
| 863 | - 'event_espresso' |
|
| 864 | - ), |
|
| 865 | - $ticket->ID(), |
|
| 866 | - $grand_total->ID() |
|
| 867 | - ) |
|
| 868 | - ); |
|
| 869 | - } |
|
| 870 | - return $events_sub_total; |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * Gets the event line item |
|
| 876 | - * |
|
| 877 | - * @param EE_Line_Item $grand_total |
|
| 878 | - * @param EE_Event $event |
|
| 879 | - * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
|
| 880 | - * @throws EE_Error |
|
| 881 | - * @throws InvalidArgumentException |
|
| 882 | - * @throws InvalidDataTypeException |
|
| 883 | - * @throws InvalidInterfaceException |
|
| 884 | - * @throws ReflectionException |
|
| 885 | - */ |
|
| 886 | - public static function get_event_line_item(EE_Line_Item $grand_total, $event) |
|
| 887 | - { |
|
| 888 | - /** @type EE_Event $event */ |
|
| 889 | - $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
| 890 | - $event_line_item = null; |
|
| 891 | - $found = false; |
|
| 892 | - foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
| 893 | - // default event subtotal, we should only ever find this the first time this method is called |
|
| 894 | - if (! $event_line_item->OBJ_ID()) { |
|
| 895 | - // let's use this! but first... set the event details |
|
| 896 | - EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 897 | - $found = true; |
|
| 898 | - break; |
|
| 899 | - } |
|
| 900 | - if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
| 901 | - // found existing line item for this event in the cart, so break out of loop and use this one |
|
| 902 | - $found = true; |
|
| 903 | - break; |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - if (! $found) { |
|
| 907 | - // there is no event sub-total yet, so add it |
|
| 908 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
| 909 | - // create a new "event" subtotal below that |
|
| 910 | - $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
| 911 | - // and set the event details |
|
| 912 | - EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 913 | - } |
|
| 914 | - return $event_line_item; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - |
|
| 918 | - /** |
|
| 919 | - * Creates a default items subtotal line item |
|
| 920 | - * |
|
| 921 | - * @param EE_Line_Item $event_line_item |
|
| 922 | - * @param EE_Event $event |
|
| 923 | - * @param EE_Transaction $transaction |
|
| 924 | - * @return void |
|
| 925 | - * @throws EE_Error |
|
| 926 | - * @throws InvalidArgumentException |
|
| 927 | - * @throws InvalidDataTypeException |
|
| 928 | - * @throws InvalidInterfaceException |
|
| 929 | - * @throws ReflectionException |
|
| 930 | - */ |
|
| 931 | - public static function set_event_subtotal_details( |
|
| 932 | - EE_Line_Item $event_line_item, |
|
| 933 | - EE_Event $event, |
|
| 934 | - $transaction = null |
|
| 935 | - ) { |
|
| 936 | - if ($event instanceof EE_Event) { |
|
| 937 | - $event_line_item->set_code(self::get_event_code($event)); |
|
| 938 | - $event_line_item->set_name(self::get_event_name($event)); |
|
| 939 | - $event_line_item->set_desc(self::get_event_desc($event)); |
|
| 940 | - $event_line_item->set_OBJ_ID($event->ID()); |
|
| 941 | - } |
|
| 942 | - self::set_TXN_ID($event_line_item, $transaction); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * Finds what taxes should apply, adds them as tax line items under the taxes sub-total, |
|
| 948 | - * and recalculates the taxes sub-total and the grand total. Resets the taxes, so |
|
| 949 | - * any old taxes are removed |
|
| 950 | - * |
|
| 951 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 952 | - * @param bool $update_txn_status |
|
| 953 | - * @return bool |
|
| 954 | - * @throws EE_Error |
|
| 955 | - * @throws InvalidArgumentException |
|
| 956 | - * @throws InvalidDataTypeException |
|
| 957 | - * @throws InvalidInterfaceException |
|
| 958 | - * @throws ReflectionException |
|
| 959 | - * @throws RuntimeException |
|
| 960 | - */ |
|
| 961 | - public static function apply_taxes(EE_Line_Item $total_line_item, $update_txn_status = false) |
|
| 962 | - { |
|
| 963 | - /** @type EEM_Price $EEM_Price */ |
|
| 964 | - $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
| 965 | - // get array of taxes via Price Model |
|
| 966 | - $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
|
| 967 | - ksort($ordered_taxes); |
|
| 968 | - $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
| 969 | - // just to be safe, remove its old tax line items |
|
| 970 | - $deleted = $taxes_line_item->delete_children_line_items(); |
|
| 971 | - $updates = false; |
|
| 972 | - // loop thru taxes |
|
| 973 | - foreach ($ordered_taxes as $order => $taxes) { |
|
| 974 | - foreach ($taxes as $tax) { |
|
| 975 | - if ($tax instanceof EE_Price) { |
|
| 976 | - $tax_line_item = EE_Line_Item::new_instance( |
|
| 977 | - array( |
|
| 978 | - 'LIN_name' => $tax->name(), |
|
| 979 | - 'LIN_desc' => $tax->desc(), |
|
| 980 | - 'LIN_percent' => $tax->amount(), |
|
| 981 | - 'LIN_is_taxable' => false, |
|
| 982 | - 'LIN_order' => $order, |
|
| 983 | - 'LIN_total' => 0, |
|
| 984 | - 'LIN_type' => EEM_Line_Item::type_tax, |
|
| 985 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PRICE, |
|
| 986 | - 'OBJ_ID' => $tax->ID(), |
|
| 987 | - ) |
|
| 988 | - ); |
|
| 989 | - $tax_line_item = apply_filters( |
|
| 990 | - 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
|
| 991 | - $tax_line_item |
|
| 992 | - ); |
|
| 993 | - $updates = $taxes_line_item->add_child_line_item($tax_line_item) ? |
|
| 994 | - true : |
|
| 995 | - $updates; |
|
| 996 | - } |
|
| 997 | - } |
|
| 998 | - } |
|
| 999 | - // only recalculate totals if something changed |
|
| 1000 | - if ($deleted || $updates) { |
|
| 1001 | - $total_line_item->recalculate_total_including_taxes($update_txn_status); |
|
| 1002 | - return true; |
|
| 1003 | - } |
|
| 1004 | - return false; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - |
|
| 1008 | - /** |
|
| 1009 | - * Ensures that taxes have been applied to the order, if not applies them. |
|
| 1010 | - * Returns the total amount of tax |
|
| 1011 | - * |
|
| 1012 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 1013 | - * @return float |
|
| 1014 | - * @throws EE_Error |
|
| 1015 | - * @throws InvalidArgumentException |
|
| 1016 | - * @throws InvalidDataTypeException |
|
| 1017 | - * @throws InvalidInterfaceException |
|
| 1018 | - * @throws ReflectionException |
|
| 1019 | - */ |
|
| 1020 | - public static function ensure_taxes_applied($total_line_item) |
|
| 1021 | - { |
|
| 1022 | - $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 1023 | - if (! $taxes_subtotal->children()) { |
|
| 1024 | - self::apply_taxes($total_line_item); |
|
| 1025 | - } |
|
| 1026 | - return $taxes_subtotal->total(); |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * Deletes ALL children of the passed line item |
|
| 1032 | - * |
|
| 1033 | - * @param EE_Line_Item $parent_line_item |
|
| 1034 | - * @return bool |
|
| 1035 | - * @throws EE_Error |
|
| 1036 | - * @throws InvalidArgumentException |
|
| 1037 | - * @throws InvalidDataTypeException |
|
| 1038 | - * @throws InvalidInterfaceException |
|
| 1039 | - * @throws ReflectionException |
|
| 1040 | - */ |
|
| 1041 | - public static function delete_all_child_items(EE_Line_Item $parent_line_item) |
|
| 1042 | - { |
|
| 1043 | - $deleted = 0; |
|
| 1044 | - foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1045 | - if ($child_line_item instanceof EE_Line_Item) { |
|
| 1046 | - $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
| 1047 | - if ($child_line_item->ID()) { |
|
| 1048 | - $child_line_item->delete(); |
|
| 1049 | - unset($child_line_item); |
|
| 1050 | - } else { |
|
| 1051 | - $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
| 1052 | - } |
|
| 1053 | - $deleted++; |
|
| 1054 | - } |
|
| 1055 | - } |
|
| 1056 | - return $deleted; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * Deletes the line items as indicated by the line item code(s) provided, |
|
| 1062 | - * regardless of where they're found in the line item tree. Automatically |
|
| 1063 | - * re-calculates the line item totals and updates the related transaction. But |
|
| 1064 | - * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
| 1065 | - * should probably change because of this). |
|
| 1066 | - * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 1067 | - * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
| 1068 | - * |
|
| 1069 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 1070 | - * @param array|bool|string $line_item_codes |
|
| 1071 | - * @return int number of items successfully removed |
|
| 1072 | - * @throws EE_Error |
|
| 1073 | - */ |
|
| 1074 | - public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = false) |
|
| 1075 | - { |
|
| 1076 | - |
|
| 1077 | - if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
| 1078 | - EE_Error::doing_it_wrong( |
|
| 1079 | - 'EEH_Line_Item::delete_items', |
|
| 1080 | - esc_html__( |
|
| 1081 | - 'This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly', |
|
| 1082 | - 'event_espresso' |
|
| 1083 | - ), |
|
| 1084 | - '4.6.18' |
|
| 1085 | - ); |
|
| 1086 | - } |
|
| 1087 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1088 | - |
|
| 1089 | - // check if only a single line_item_id was passed |
|
| 1090 | - if (! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
| 1091 | - // place single line_item_id in an array to appear as multiple line_item_ids |
|
| 1092 | - $line_item_codes = array($line_item_codes); |
|
| 1093 | - } |
|
| 1094 | - $removals = 0; |
|
| 1095 | - // cycle thru line_item_ids |
|
| 1096 | - foreach ($line_item_codes as $line_item_id) { |
|
| 1097 | - $removals += $total_line_item->delete_child_line_item($line_item_id); |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - if ($removals > 0) { |
|
| 1101 | - $total_line_item->recalculate_taxes_and_tax_total(); |
|
| 1102 | - return $removals; |
|
| 1103 | - } else { |
|
| 1104 | - return false; |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - |
|
| 1109 | - /** |
|
| 1110 | - * Overwrites the previous tax by clearing out the old taxes, and creates a new |
|
| 1111 | - * tax and updates the total line item accordingly |
|
| 1112 | - * |
|
| 1113 | - * @param EE_Line_Item $total_line_item |
|
| 1114 | - * @param float $amount |
|
| 1115 | - * @param string $name |
|
| 1116 | - * @param string $description |
|
| 1117 | - * @param string $code |
|
| 1118 | - * @param boolean $add_to_existing_line_item |
|
| 1119 | - * if true, and a duplicate line item with the same code is found, |
|
| 1120 | - * $amount will be added onto it; otherwise will simply set the taxes to match $amount |
|
| 1121 | - * @return EE_Line_Item the new tax line item created |
|
| 1122 | - * @throws EE_Error |
|
| 1123 | - * @throws InvalidArgumentException |
|
| 1124 | - * @throws InvalidDataTypeException |
|
| 1125 | - * @throws InvalidInterfaceException |
|
| 1126 | - * @throws ReflectionException |
|
| 1127 | - */ |
|
| 1128 | - public static function set_total_tax_to( |
|
| 1129 | - EE_Line_Item $total_line_item, |
|
| 1130 | - $amount, |
|
| 1131 | - $name = null, |
|
| 1132 | - $description = null, |
|
| 1133 | - $code = null, |
|
| 1134 | - $add_to_existing_line_item = false |
|
| 1135 | - ) { |
|
| 1136 | - $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 1137 | - $taxable_total = $total_line_item->taxable_total(); |
|
| 1138 | - |
|
| 1139 | - if ($add_to_existing_line_item) { |
|
| 1140 | - $new_tax = $tax_subtotal->get_child_line_item($code); |
|
| 1141 | - EEM_Line_Item::instance()->delete( |
|
| 1142 | - array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
| 1143 | - ); |
|
| 1144 | - } else { |
|
| 1145 | - $new_tax = null; |
|
| 1146 | - $tax_subtotal->delete_children_line_items(); |
|
| 1147 | - } |
|
| 1148 | - if ($new_tax) { |
|
| 1149 | - $new_tax->set_total($new_tax->total() + $amount); |
|
| 1150 | - $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
| 1151 | - } else { |
|
| 1152 | - // no existing tax item. Create it |
|
| 1153 | - $new_tax = EE_Line_Item::new_instance(array( |
|
| 1154 | - 'TXN_ID' => $total_line_item->TXN_ID(), |
|
| 1155 | - 'LIN_name' => $name ? $name : esc_html__('Tax', 'event_espresso'), |
|
| 1156 | - 'LIN_desc' => $description ? $description : '', |
|
| 1157 | - 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
| 1158 | - 'LIN_total' => $amount, |
|
| 1159 | - 'LIN_parent' => $tax_subtotal->ID(), |
|
| 1160 | - 'LIN_type' => EEM_Line_Item::type_tax, |
|
| 1161 | - 'LIN_code' => $code, |
|
| 1162 | - )); |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - $new_tax = apply_filters( |
|
| 1166 | - 'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal', |
|
| 1167 | - $new_tax, |
|
| 1168 | - $total_line_item |
|
| 1169 | - ); |
|
| 1170 | - $new_tax->save(); |
|
| 1171 | - $tax_subtotal->set_total($new_tax->total()); |
|
| 1172 | - $tax_subtotal->save(); |
|
| 1173 | - $total_line_item->recalculate_total_including_taxes(); |
|
| 1174 | - return $new_tax; |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - |
|
| 1178 | - /** |
|
| 1179 | - * Makes all the line items which are children of $line_item taxable (or not). |
|
| 1180 | - * Does NOT save the line items |
|
| 1181 | - * |
|
| 1182 | - * @param EE_Line_Item $line_item |
|
| 1183 | - * @param boolean $taxable |
|
| 1184 | - * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
| 1185 | - * it will be whitelisted (ie, except from becoming taxable) |
|
| 1186 | - * @throws EE_Error |
|
| 1187 | - */ |
|
| 1188 | - public static function set_line_items_taxable( |
|
| 1189 | - EE_Line_Item $line_item, |
|
| 1190 | - $taxable = true, |
|
| 1191 | - $code_substring_for_whitelist = null |
|
| 1192 | - ) { |
|
| 1193 | - $whitelisted = false; |
|
| 1194 | - if ($code_substring_for_whitelist !== null) { |
|
| 1195 | - $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false; |
|
| 1196 | - } |
|
| 1197 | - if (! $whitelisted && $line_item->is_line_item()) { |
|
| 1198 | - $line_item->set_is_taxable($taxable); |
|
| 1199 | - } |
|
| 1200 | - foreach ($line_item->children() as $child_line_item) { |
|
| 1201 | - EEH_Line_Item::set_line_items_taxable( |
|
| 1202 | - $child_line_item, |
|
| 1203 | - $taxable, |
|
| 1204 | - $code_substring_for_whitelist |
|
| 1205 | - ); |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * Gets all descendants that are event subtotals |
|
| 1212 | - * |
|
| 1213 | - * @uses EEH_Line_Item::get_subtotals_of_object_type() |
|
| 1214 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1215 | - * @return EE_Line_Item[] |
|
| 1216 | - * @throws EE_Error |
|
| 1217 | - */ |
|
| 1218 | - public static function get_event_subtotals(EE_Line_Item $parent_line_item) |
|
| 1219 | - { |
|
| 1220 | - return self::get_subtotals_of_object_type($parent_line_item, EEM_Line_Item::OBJ_TYPE_EVENT); |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * Gets all descendants subtotals that match the supplied object type |
|
| 1226 | - * |
|
| 1227 | - * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
| 1228 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1229 | - * @param string $obj_type |
|
| 1230 | - * @return EE_Line_Item[] |
|
| 1231 | - * @throws EE_Error |
|
| 1232 | - */ |
|
| 1233 | - public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') |
|
| 1234 | - { |
|
| 1235 | - return self::_get_descendants_by_type_and_object_type( |
|
| 1236 | - $parent_line_item, |
|
| 1237 | - EEM_Line_Item::type_sub_total, |
|
| 1238 | - $obj_type |
|
| 1239 | - ); |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * Gets all descendants that are tickets |
|
| 1245 | - * |
|
| 1246 | - * @uses EEH_Line_Item::get_line_items_of_object_type() |
|
| 1247 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1248 | - * @return EE_Line_Item[] |
|
| 1249 | - * @throws EE_Error |
|
| 1250 | - */ |
|
| 1251 | - public static function get_ticket_line_items(EE_Line_Item $parent_line_item) |
|
| 1252 | - { |
|
| 1253 | - return self::get_line_items_of_object_type( |
|
| 1254 | - $parent_line_item, |
|
| 1255 | - EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1256 | - ); |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - |
|
| 1260 | - /** |
|
| 1261 | - * Gets all descendants subtotals that match the supplied object type |
|
| 1262 | - * |
|
| 1263 | - * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
| 1264 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1265 | - * @param string $obj_type |
|
| 1266 | - * @return EE_Line_Item[] |
|
| 1267 | - * @throws EE_Error |
|
| 1268 | - */ |
|
| 1269 | - public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') |
|
| 1270 | - { |
|
| 1271 | - return self::_get_descendants_by_type_and_object_type( |
|
| 1272 | - $parent_line_item, |
|
| 1273 | - EEM_Line_Item::type_line_item, |
|
| 1274 | - $obj_type |
|
| 1275 | - ); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * Gets all the descendants (ie, children or children of children etc) that are of the type 'tax' |
|
| 1281 | - * |
|
| 1282 | - * @uses EEH_Line_Item::get_descendants_of_type() |
|
| 1283 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1284 | - * @return EE_Line_Item[] |
|
| 1285 | - * @throws EE_Error |
|
| 1286 | - */ |
|
| 1287 | - public static function get_tax_descendants(EE_Line_Item $parent_line_item) |
|
| 1288 | - { |
|
| 1289 | - return EEH_Line_Item::get_descendants_of_type( |
|
| 1290 | - $parent_line_item, |
|
| 1291 | - EEM_Line_Item::type_tax |
|
| 1292 | - ); |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * Gets all the real items purchased which are children of this item |
|
| 1298 | - * |
|
| 1299 | - * @uses EEH_Line_Item::get_descendants_of_type() |
|
| 1300 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1301 | - * @return EE_Line_Item[] |
|
| 1302 | - * @throws EE_Error |
|
| 1303 | - */ |
|
| 1304 | - public static function get_line_item_descendants(EE_Line_Item $parent_line_item) |
|
| 1305 | - { |
|
| 1306 | - return EEH_Line_Item::get_descendants_of_type( |
|
| 1307 | - $parent_line_item, |
|
| 1308 | - EEM_Line_Item::type_line_item |
|
| 1309 | - ); |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - |
|
| 1313 | - /** |
|
| 1314 | - * Gets all descendants of supplied line item that match the supplied line item type |
|
| 1315 | - * |
|
| 1316 | - * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
| 1317 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1318 | - * @param string $line_item_type one of the EEM_Line_Item constants |
|
| 1319 | - * @return EE_Line_Item[] |
|
| 1320 | - * @throws EE_Error |
|
| 1321 | - */ |
|
| 1322 | - public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) |
|
| 1323 | - { |
|
| 1324 | - return self::_get_descendants_by_type_and_object_type( |
|
| 1325 | - $parent_line_item, |
|
| 1326 | - $line_item_type, |
|
| 1327 | - null |
|
| 1328 | - ); |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type |
|
| 1334 | - * as well |
|
| 1335 | - * |
|
| 1336 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1337 | - * @param string $line_item_type one of the EEM_Line_Item constants |
|
| 1338 | - * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when |
|
| 1339 | - * searching |
|
| 1340 | - * @return EE_Line_Item[] |
|
| 1341 | - * @throws EE_Error |
|
| 1342 | - */ |
|
| 1343 | - protected static function _get_descendants_by_type_and_object_type( |
|
| 1344 | - EE_Line_Item $parent_line_item, |
|
| 1345 | - $line_item_type, |
|
| 1346 | - $obj_type = null |
|
| 1347 | - ) { |
|
| 1348 | - $objects = array(); |
|
| 1349 | - foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1350 | - if ($child_line_item instanceof EE_Line_Item) { |
|
| 1351 | - if ($child_line_item->type() === $line_item_type |
|
| 1352 | - && ( |
|
| 1353 | - $child_line_item->OBJ_type() === $obj_type || $obj_type === null |
|
| 1354 | - ) |
|
| 1355 | - ) { |
|
| 1356 | - $objects[] = $child_line_item; |
|
| 1357 | - } else { |
|
| 1358 | - // go-through-all-its children looking for more matches |
|
| 1359 | - $objects = array_merge( |
|
| 1360 | - $objects, |
|
| 1361 | - self::_get_descendants_by_type_and_object_type( |
|
| 1362 | - $child_line_item, |
|
| 1363 | - $line_item_type, |
|
| 1364 | - $obj_type |
|
| 1365 | - ) |
|
| 1366 | - ); |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - } |
|
| 1370 | - return $objects; |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - |
|
| 1374 | - /** |
|
| 1375 | - * Gets all descendants subtotals that match the supplied object type |
|
| 1376 | - * |
|
| 1377 | - * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
| 1378 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1379 | - * @param string $OBJ_type object type (like Event) |
|
| 1380 | - * @param array $OBJ_IDs array of OBJ_IDs |
|
| 1381 | - * @return EE_Line_Item[] |
|
| 1382 | - * @throws EE_Error |
|
| 1383 | - */ |
|
| 1384 | - public static function get_line_items_by_object_type_and_IDs( |
|
| 1385 | - EE_Line_Item $parent_line_item, |
|
| 1386 | - $OBJ_type = '', |
|
| 1387 | - $OBJ_IDs = array() |
|
| 1388 | - ) { |
|
| 1389 | - return self::_get_descendants_by_object_type_and_object_ID( |
|
| 1390 | - $parent_line_item, |
|
| 1391 | - $OBJ_type, |
|
| 1392 | - $OBJ_IDs |
|
| 1393 | - ); |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type |
|
| 1399 | - * as well |
|
| 1400 | - * |
|
| 1401 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1402 | - * @param string $OBJ_type object type (like Event) |
|
| 1403 | - * @param array $OBJ_IDs array of OBJ_IDs |
|
| 1404 | - * @return EE_Line_Item[] |
|
| 1405 | - * @throws EE_Error |
|
| 1406 | - */ |
|
| 1407 | - protected static function _get_descendants_by_object_type_and_object_ID( |
|
| 1408 | - EE_Line_Item $parent_line_item, |
|
| 1409 | - $OBJ_type, |
|
| 1410 | - $OBJ_IDs |
|
| 1411 | - ) { |
|
| 1412 | - $objects = array(); |
|
| 1413 | - foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1414 | - if ($child_line_item instanceof EE_Line_Item) { |
|
| 1415 | - if ($child_line_item->OBJ_type() === $OBJ_type |
|
| 1416 | - && is_array($OBJ_IDs) |
|
| 1417 | - && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
| 1418 | - ) { |
|
| 1419 | - $objects[] = $child_line_item; |
|
| 1420 | - } else { |
|
| 1421 | - // go-through-all-its children looking for more matches |
|
| 1422 | - $objects = array_merge( |
|
| 1423 | - $objects, |
|
| 1424 | - self::_get_descendants_by_object_type_and_object_ID( |
|
| 1425 | - $child_line_item, |
|
| 1426 | - $OBJ_type, |
|
| 1427 | - $OBJ_IDs |
|
| 1428 | - ) |
|
| 1429 | - ); |
|
| 1430 | - } |
|
| 1431 | - } |
|
| 1432 | - } |
|
| 1433 | - return $objects; |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - |
|
| 1437 | - /** |
|
| 1438 | - * Uses a breadth-first-search in order to find the nearest descendant of |
|
| 1439 | - * the specified type and returns it, else NULL |
|
| 1440 | - * |
|
| 1441 | - * @uses EEH_Line_Item::_get_nearest_descendant() |
|
| 1442 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1443 | - * @param string $type like one of the EEM_Line_Item::type_* |
|
| 1444 | - * @return EE_Line_Item |
|
| 1445 | - * @throws EE_Error |
|
| 1446 | - * @throws InvalidArgumentException |
|
| 1447 | - * @throws InvalidDataTypeException |
|
| 1448 | - * @throws InvalidInterfaceException |
|
| 1449 | - * @throws ReflectionException |
|
| 1450 | - */ |
|
| 1451 | - public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) |
|
| 1452 | - { |
|
| 1453 | - return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
| 1454 | - } |
|
| 1455 | - |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * Uses a breadth-first-search in order to find the nearest descendant |
|
| 1459 | - * having the specified LIN_code and returns it, else NULL |
|
| 1460 | - * |
|
| 1461 | - * @uses EEH_Line_Item::_get_nearest_descendant() |
|
| 1462 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1463 | - * @param string $code any value used for LIN_code |
|
| 1464 | - * @return EE_Line_Item |
|
| 1465 | - * @throws EE_Error |
|
| 1466 | - * @throws InvalidArgumentException |
|
| 1467 | - * @throws InvalidDataTypeException |
|
| 1468 | - * @throws InvalidInterfaceException |
|
| 1469 | - * @throws ReflectionException |
|
| 1470 | - */ |
|
| 1471 | - public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) |
|
| 1472 | - { |
|
| 1473 | - return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - |
|
| 1477 | - /** |
|
| 1478 | - * Uses a breadth-first-search in order to find the nearest descendant |
|
| 1479 | - * having the specified LIN_code and returns it, else NULL |
|
| 1480 | - * |
|
| 1481 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1482 | - * @param string $search_field name of EE_Line_Item property |
|
| 1483 | - * @param string $value any value stored in $search_field |
|
| 1484 | - * @return EE_Line_Item |
|
| 1485 | - * @throws EE_Error |
|
| 1486 | - * @throws InvalidArgumentException |
|
| 1487 | - * @throws InvalidDataTypeException |
|
| 1488 | - * @throws InvalidInterfaceException |
|
| 1489 | - * @throws ReflectionException |
|
| 1490 | - */ |
|
| 1491 | - protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) |
|
| 1492 | - { |
|
| 1493 | - foreach ($parent_line_item->children() as $child) { |
|
| 1494 | - if ($child->get($search_field) == $value) { |
|
| 1495 | - return $child; |
|
| 1496 | - } |
|
| 1497 | - } |
|
| 1498 | - foreach ($parent_line_item->children() as $child) { |
|
| 1499 | - $descendant_found = self::_get_nearest_descendant( |
|
| 1500 | - $child, |
|
| 1501 | - $search_field, |
|
| 1502 | - $value |
|
| 1503 | - ); |
|
| 1504 | - if ($descendant_found) { |
|
| 1505 | - return $descendant_found; |
|
| 1506 | - } |
|
| 1507 | - } |
|
| 1508 | - return null; |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - |
|
| 1512 | - /** |
|
| 1513 | - * if passed line item has a TXN ID, uses that to jump directly to the grand total line item for the transaction, |
|
| 1514 | - * else recursively walks up the line item tree until a parent of type total is found, |
|
| 1515 | - * |
|
| 1516 | - * @param EE_Line_Item $line_item |
|
| 1517 | - * @return EE_Line_Item |
|
| 1518 | - * @throws EE_Error |
|
| 1519 | - */ |
|
| 1520 | - public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) |
|
| 1521 | - { |
|
| 1522 | - if ($line_item->TXN_ID()) { |
|
| 1523 | - $total_line_item = $line_item->transaction()->total_line_item(false); |
|
| 1524 | - if ($total_line_item instanceof EE_Line_Item) { |
|
| 1525 | - return $total_line_item; |
|
| 1526 | - } |
|
| 1527 | - } else { |
|
| 1528 | - $line_item_parent = $line_item->parent(); |
|
| 1529 | - if ($line_item_parent instanceof EE_Line_Item) { |
|
| 1530 | - if ($line_item_parent->is_total()) { |
|
| 1531 | - return $line_item_parent; |
|
| 1532 | - } |
|
| 1533 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
| 1534 | - } |
|
| 1535 | - } |
|
| 1536 | - throw new EE_Error( |
|
| 1537 | - sprintf( |
|
| 1538 | - esc_html__( |
|
| 1539 | - 'A valid grand total for line item %1$d was not found.', |
|
| 1540 | - 'event_espresso' |
|
| 1541 | - ), |
|
| 1542 | - $line_item->ID() |
|
| 1543 | - ) |
|
| 1544 | - ); |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - |
|
| 1548 | - /** |
|
| 1549 | - * Prints out a representation of the line item tree |
|
| 1550 | - * |
|
| 1551 | - * @param EE_Line_Item $line_item |
|
| 1552 | - * @param int $indentation |
|
| 1553 | - * @return void |
|
| 1554 | - * @throws EE_Error |
|
| 1555 | - */ |
|
| 1556 | - public static function visualize(EE_Line_Item $line_item, $indentation = 0) |
|
| 1557 | - { |
|
| 1558 | - echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 1559 | - if (! $indentation) { |
|
| 1560 | - echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 1561 | - } |
|
| 1562 | - for ($i = 0; $i < $indentation; $i++) { |
|
| 1563 | - echo '. '; |
|
| 1564 | - } |
|
| 1565 | - $breakdown = ''; |
|
| 1566 | - if ($line_item->is_line_item()) { |
|
| 1567 | - if ($line_item->is_percent()) { |
|
| 1568 | - $breakdown = "{$line_item->percent()}%"; |
|
| 1569 | - } else { |
|
| 1570 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
| 1571 | - } |
|
| 1572 | - } |
|
| 1573 | - echo $line_item->name(); |
|
| 1574 | - echo " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : "; |
|
| 1575 | - echo '$' . (string) $line_item->total(); |
|
| 1576 | - if ($breakdown) { |
|
| 1577 | - echo " ( {$breakdown} )"; |
|
| 1578 | - } |
|
| 1579 | - if ($line_item->is_taxable()) { |
|
| 1580 | - echo ' * taxable'; |
|
| 1581 | - } |
|
| 1582 | - if ($line_item->children()) { |
|
| 1583 | - foreach ($line_item->children() as $child) { |
|
| 1584 | - self::visualize($child, $indentation + 1); |
|
| 1585 | - } |
|
| 1586 | - } |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - /** |
|
| 1591 | - * Calculates the registration's final price, taking into account that they |
|
| 1592 | - * need to not only help pay for their OWN ticket, but also any transaction-wide surcharges and taxes, |
|
| 1593 | - * and receive a portion of any transaction-wide discounts. |
|
| 1594 | - * eg1, if I buy a $1 ticket and brent buys a $9 ticket, and we receive a $5 discount |
|
| 1595 | - * then I'll get 1/10 of that $5 discount, which is $0.50, and brent will get |
|
| 1596 | - * 9/10ths of that $5 discount, which is $4.50. So my final price should be $0.50 |
|
| 1597 | - * and brent's final price should be $5.50. |
|
| 1598 | - * In order to do this, we basically need to traverse the line item tree calculating |
|
| 1599 | - * the running totals (just as if we were recalculating the total), but when we identify |
|
| 1600 | - * regular line items, we need to keep track of their share of the grand total. |
|
| 1601 | - * Also, we need to keep track of the TAXABLE total for each ticket purchase, so |
|
| 1602 | - * we can know how to apply taxes to it. (Note: "taxable total" does not equal the "pretax total" |
|
| 1603 | - * when there are non-taxable items; otherwise they would be the same) |
|
| 1604 | - * |
|
| 1605 | - * @param EE_Line_Item $line_item |
|
| 1606 | - * @param array $billable_ticket_quantities array of EE_Ticket IDs and their corresponding quantity that |
|
| 1607 | - * can be included in price calculations at this moment |
|
| 1608 | - * @return array keys are line items for tickets IDs and values are their share of the running total, |
|
| 1609 | - * plus the key 'total', and 'taxable' which also has keys of all |
|
| 1610 | - * the ticket IDs. |
|
| 1611 | - * Eg array( |
|
| 1612 | - * 12 => 4.3 |
|
| 1613 | - * 23 => 8.0 |
|
| 1614 | - * 'total' => 16.6, |
|
| 1615 | - * 'taxable' => array( |
|
| 1616 | - * 12 => 10, |
|
| 1617 | - * 23 => 4 |
|
| 1618 | - * ). |
|
| 1619 | - * So to find which registrations have which final price, we need |
|
| 1620 | - * to find which line item is theirs, which can be done with |
|
| 1621 | - * `EEM_Line_Item::instance()->get_line_item_for_registration( |
|
| 1622 | - * $registration );` |
|
| 1623 | - * @throws EE_Error |
|
| 1624 | - * @throws InvalidArgumentException |
|
| 1625 | - * @throws InvalidDataTypeException |
|
| 1626 | - * @throws InvalidInterfaceException |
|
| 1627 | - * @throws ReflectionException |
|
| 1628 | - */ |
|
| 1629 | - public static function calculate_reg_final_prices_per_line_item( |
|
| 1630 | - EE_Line_Item $line_item, |
|
| 1631 | - $billable_ticket_quantities = array() |
|
| 1632 | - ) { |
|
| 1633 | - $running_totals = [ |
|
| 1634 | - 'total' => 0, |
|
| 1635 | - 'taxable' => ['total' => 0] |
|
| 1636 | - ]; |
|
| 1637 | - foreach ($line_item->children() as $child_line_item) { |
|
| 1638 | - switch ($child_line_item->type()) { |
|
| 1639 | - case EEM_Line_Item::type_sub_total: |
|
| 1640 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
| 1641 | - $child_line_item, |
|
| 1642 | - $billable_ticket_quantities |
|
| 1643 | - ); |
|
| 1644 | - // combine arrays but preserve numeric keys |
|
| 1645 | - $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
| 1646 | - $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
| 1647 | - $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
| 1648 | - break; |
|
| 1649 | - |
|
| 1650 | - case EEM_Line_Item::type_tax_sub_total: |
|
| 1651 | - // find how much the taxes percentage is |
|
| 1652 | - if ($child_line_item->percent() !== 0) { |
|
| 1653 | - $tax_percent_decimal = $child_line_item->percent() / 100; |
|
| 1654 | - } else { |
|
| 1655 | - $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
|
| 1656 | - } |
|
| 1657 | - // and apply to all the taxable totals, and add to the pretax totals |
|
| 1658 | - foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1659 | - // "total" and "taxable" array key is an exception |
|
| 1660 | - if ($line_item_id === 'taxable') { |
|
| 1661 | - continue; |
|
| 1662 | - } |
|
| 1663 | - $taxable_total = $running_totals['taxable'][ $line_item_id ]; |
|
| 1664 | - $running_totals[ $line_item_id ] += ($taxable_total * $tax_percent_decimal); |
|
| 1665 | - } |
|
| 1666 | - break; |
|
| 1667 | - |
|
| 1668 | - case EEM_Line_Item::type_line_item: |
|
| 1669 | - // ticket line items or ???? |
|
| 1670 | - if ($child_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
| 1671 | - // kk it's a ticket |
|
| 1672 | - if (isset($running_totals[ $child_line_item->ID() ])) { |
|
| 1673 | - // huh? that shouldn't happen. |
|
| 1674 | - $running_totals['total'] += $child_line_item->total(); |
|
| 1675 | - } else { |
|
| 1676 | - // its not in our running totals yet. great. |
|
| 1677 | - if ($child_line_item->is_taxable()) { |
|
| 1678 | - $taxable_amount = $child_line_item->unit_price(); |
|
| 1679 | - } else { |
|
| 1680 | - $taxable_amount = 0; |
|
| 1681 | - } |
|
| 1682 | - // are we only calculating totals for some tickets? |
|
| 1683 | - if (isset($billable_ticket_quantities[ $child_line_item->OBJ_ID() ])) { |
|
| 1684 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
| 1685 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
| 1686 | - ? $child_line_item->unit_price() |
|
| 1687 | - : 0; |
|
| 1688 | - $running_totals['taxable'][ $child_line_item->ID() ] = $quantity |
|
| 1689 | - ? $taxable_amount |
|
| 1690 | - : 0; |
|
| 1691 | - } else { |
|
| 1692 | - $quantity = $child_line_item->quantity(); |
|
| 1693 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
| 1694 | - $running_totals['taxable'][ $child_line_item->ID() ] = $taxable_amount; |
|
| 1695 | - } |
|
| 1696 | - $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
| 1697 | - $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
| 1698 | - } |
|
| 1699 | - } else { |
|
| 1700 | - // it's some other type of item added to the cart |
|
| 1701 | - // it should affect the running totals |
|
| 1702 | - // basically we want to convert it into a PERCENT modifier. Because |
|
| 1703 | - // more clearly affect all registration's final price equally |
|
| 1704 | - $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
| 1705 | - ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
| 1706 | - : 1; |
|
| 1707 | - foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1708 | - // the "taxable" array key is an exception |
|
| 1709 | - if ($line_item_id === 'taxable') { |
|
| 1710 | - continue; |
|
| 1711 | - } |
|
| 1712 | - // update the running totals |
|
| 1713 | - // yes this actually even works for the running grand total! |
|
| 1714 | - $running_totals[ $line_item_id ] = |
|
| 1715 | - $line_items_percent_of_running_total * $this_running_total; |
|
| 1716 | - |
|
| 1717 | - if ($child_line_item->is_taxable()) { |
|
| 1718 | - $running_totals['taxable'][ $line_item_id ] = |
|
| 1719 | - $line_items_percent_of_running_total * $running_totals['taxable'][ $line_item_id ]; |
|
| 1720 | - } |
|
| 1721 | - } |
|
| 1722 | - } |
|
| 1723 | - break; |
|
| 1724 | - } |
|
| 1725 | - } |
|
| 1726 | - return $running_totals; |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * @param EE_Line_Item $total_line_item |
|
| 1732 | - * @param EE_Line_Item $ticket_line_item |
|
| 1733 | - * @return float | null |
|
| 1734 | - * @throws EE_Error |
|
| 1735 | - * @throws InvalidArgumentException |
|
| 1736 | - * @throws InvalidDataTypeException |
|
| 1737 | - * @throws InvalidInterfaceException |
|
| 1738 | - * @throws OutOfRangeException |
|
| 1739 | - * @throws ReflectionException |
|
| 1740 | - */ |
|
| 1741 | - public static function calculate_final_price_for_ticket_line_item( |
|
| 1742 | - EE_Line_Item $total_line_item, |
|
| 1743 | - EE_Line_Item $ticket_line_item |
|
| 1744 | - ) { |
|
| 1745 | - static $final_prices_per_ticket_line_item = array(); |
|
| 1746 | - if (empty($final_prices_per_ticket_line_item)) { |
|
| 1747 | - $final_prices_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
| 1748 | - $total_line_item |
|
| 1749 | - ); |
|
| 1750 | - } |
|
| 1751 | - // ok now find this new registration's final price |
|
| 1752 | - if (isset($final_prices_per_ticket_line_item[ $ticket_line_item->ID() ])) { |
|
| 1753 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
| 1754 | - } |
|
| 1755 | - $message = sprintf( |
|
| 1756 | - esc_html__( |
|
| 1757 | - 'The final price for the ticket line item (ID:%1$d) could not be calculated.', |
|
| 1758 | - 'event_espresso' |
|
| 1759 | - ), |
|
| 1760 | - $ticket_line_item->ID() |
|
| 1761 | - ); |
|
| 1762 | - if (WP_DEBUG) { |
|
| 1763 | - $message .= '<br>' . print_r($final_prices_per_ticket_line_item, true); |
|
| 1764 | - throw new OutOfRangeException($message); |
|
| 1765 | - } |
|
| 1766 | - EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
| 1767 | - return null; |
|
| 1768 | - } |
|
| 1769 | - |
|
| 1770 | - |
|
| 1771 | - /** |
|
| 1772 | - * Creates a duplicate of the line item tree, except only includes billable items |
|
| 1773 | - * and the portion of line items attributed to billable things |
|
| 1774 | - * |
|
| 1775 | - * @param EE_Line_Item $line_item |
|
| 1776 | - * @param EE_Registration[] $registrations |
|
| 1777 | - * @return EE_Line_Item |
|
| 1778 | - * @throws EE_Error |
|
| 1779 | - * @throws InvalidArgumentException |
|
| 1780 | - * @throws InvalidDataTypeException |
|
| 1781 | - * @throws InvalidInterfaceException |
|
| 1782 | - * @throws ReflectionException |
|
| 1783 | - */ |
|
| 1784 | - public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) |
|
| 1785 | - { |
|
| 1786 | - $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
| 1787 | - foreach ($line_item->children() as $child_li) { |
|
| 1788 | - $copy_li->add_child_line_item( |
|
| 1789 | - EEH_Line_Item::billable_line_item_tree($child_li, $registrations) |
|
| 1790 | - ); |
|
| 1791 | - } |
|
| 1792 | - // if this is the grand total line item, make sure the totals all add up |
|
| 1793 | - // (we could have duplicated this logic AS we copied the line items, but |
|
| 1794 | - // it seems DRYer this way) |
|
| 1795 | - if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
| 1796 | - $copy_li->recalculate_total_including_taxes(); |
|
| 1797 | - } |
|
| 1798 | - return $copy_li; |
|
| 1799 | - } |
|
| 1800 | - |
|
| 1801 | - |
|
| 1802 | - /** |
|
| 1803 | - * Creates a new, unsaved line item from $line_item that factors in the |
|
| 1804 | - * number of billable registrations on $registrations. |
|
| 1805 | - * |
|
| 1806 | - * @param EE_Line_Item $line_item |
|
| 1807 | - * @param EE_Registration[] $registrations |
|
| 1808 | - * @return EE_Line_Item |
|
| 1809 | - * @throws EE_Error |
|
| 1810 | - * @throws InvalidArgumentException |
|
| 1811 | - * @throws InvalidDataTypeException |
|
| 1812 | - * @throws InvalidInterfaceException |
|
| 1813 | - * @throws ReflectionException |
|
| 1814 | - */ |
|
| 1815 | - public static function billable_line_item(EE_Line_Item $line_item, $registrations) |
|
| 1816 | - { |
|
| 1817 | - $new_li_fields = $line_item->model_field_array(); |
|
| 1818 | - if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1819 | - $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1820 | - ) { |
|
| 1821 | - $count = 0; |
|
| 1822 | - foreach ($registrations as $registration) { |
|
| 1823 | - if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
| 1824 | - in_array( |
|
| 1825 | - $registration->status_ID(), |
|
| 1826 | - EEM_Registration::reg_statuses_that_allow_payment(), |
|
| 1827 | - true |
|
| 1828 | - ) |
|
| 1829 | - ) { |
|
| 1830 | - $count++; |
|
| 1831 | - } |
|
| 1832 | - } |
|
| 1833 | - $new_li_fields['LIN_quantity'] = $count; |
|
| 1834 | - } |
|
| 1835 | - // don't set the total. We'll leave that up to the code that calculates it |
|
| 1836 | - unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
| 1837 | - return EE_Line_Item::new_instance($new_li_fields); |
|
| 1838 | - } |
|
| 1839 | - |
|
| 1840 | - |
|
| 1841 | - /** |
|
| 1842 | - * Returns a modified line item tree where all the subtotals which have a total of 0 |
|
| 1843 | - * are removed, and line items with a quantity of 0 |
|
| 1844 | - * |
|
| 1845 | - * @param EE_Line_Item $line_item |null |
|
| 1846 | - * @return EE_Line_Item|null |
|
| 1847 | - * @throws EE_Error |
|
| 1848 | - * @throws InvalidArgumentException |
|
| 1849 | - * @throws InvalidDataTypeException |
|
| 1850 | - * @throws InvalidInterfaceException |
|
| 1851 | - * @throws ReflectionException |
|
| 1852 | - */ |
|
| 1853 | - public static function non_empty_line_items(EE_Line_Item $line_item) |
|
| 1854 | - { |
|
| 1855 | - $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
| 1856 | - if ($copied_li === null) { |
|
| 1857 | - return null; |
|
| 1858 | - } |
|
| 1859 | - // if this is an event subtotal, we want to only include it if it |
|
| 1860 | - // has a non-zero total and at least one ticket line item child |
|
| 1861 | - $ticket_children = 0; |
|
| 1862 | - foreach ($line_item->children() as $child_li) { |
|
| 1863 | - $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
| 1864 | - if ($child_li_copy !== null) { |
|
| 1865 | - $copied_li->add_child_line_item($child_li_copy); |
|
| 1866 | - if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
| 1867 | - $child_li_copy->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1868 | - ) { |
|
| 1869 | - $ticket_children++; |
|
| 1870 | - } |
|
| 1871 | - } |
|
| 1872 | - } |
|
| 1873 | - // if this is an event subtotal with NO ticket children |
|
| 1874 | - // we basically want to ignore it |
|
| 1875 | - if ($ticket_children === 0 |
|
| 1876 | - && $line_item->type() === EEM_Line_Item::type_sub_total |
|
| 1877 | - && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
| 1878 | - && $line_item->total() === 0 |
|
| 1879 | - ) { |
|
| 1880 | - return null; |
|
| 1881 | - } |
|
| 1882 | - return $copied_li; |
|
| 1883 | - } |
|
| 1884 | - |
|
| 1885 | - |
|
| 1886 | - /** |
|
| 1887 | - * Creates a new, unsaved line item, but if it's a ticket line item |
|
| 1888 | - * with a total of 0, or a subtotal of 0, returns null instead |
|
| 1889 | - * |
|
| 1890 | - * @param EE_Line_Item $line_item |
|
| 1891 | - * @return EE_Line_Item |
|
| 1892 | - * @throws EE_Error |
|
| 1893 | - * @throws InvalidArgumentException |
|
| 1894 | - * @throws InvalidDataTypeException |
|
| 1895 | - * @throws InvalidInterfaceException |
|
| 1896 | - * @throws ReflectionException |
|
| 1897 | - */ |
|
| 1898 | - public static function non_empty_line_item(EE_Line_Item $line_item) |
|
| 1899 | - { |
|
| 1900 | - if ($line_item->type() === EEM_Line_Item::type_line_item |
|
| 1901 | - && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1902 | - && $line_item->quantity() === 0 |
|
| 1903 | - ) { |
|
| 1904 | - return null; |
|
| 1905 | - } |
|
| 1906 | - $new_li_fields = $line_item->model_field_array(); |
|
| 1907 | - // don't set the total. We'll leave that up to the code that calculates it |
|
| 1908 | - unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
| 1909 | - return EE_Line_Item::new_instance($new_li_fields); |
|
| 1910 | - } |
|
| 1911 | - |
|
| 1912 | - |
|
| 1913 | - /** |
|
| 1914 | - * Cycles through all of the ticket line items for the supplied total line item |
|
| 1915 | - * and ensures that the line item's "is_taxable" field matches that of its corresponding ticket |
|
| 1916 | - * |
|
| 1917 | - * @param EE_Line_Item $total_line_item |
|
| 1918 | - * @since 4.9.79.p |
|
| 1919 | - * @throws EE_Error |
|
| 1920 | - * @throws InvalidArgumentException |
|
| 1921 | - * @throws InvalidDataTypeException |
|
| 1922 | - * @throws InvalidInterfaceException |
|
| 1923 | - * @throws ReflectionException |
|
| 1924 | - */ |
|
| 1925 | - public static function resetIsTaxableForTickets(EE_Line_Item $total_line_item) |
|
| 1926 | - { |
|
| 1927 | - $ticket_line_items = self::get_ticket_line_items($total_line_item); |
|
| 1928 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 1929 | - if ($ticket_line_item instanceof EE_Line_Item |
|
| 1930 | - && $ticket_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1931 | - ) { |
|
| 1932 | - $ticket = $ticket_line_item->ticket(); |
|
| 1933 | - if ($ticket instanceof EE_Ticket && $ticket->taxable() !== $ticket_line_item->is_taxable()) { |
|
| 1934 | - $ticket_line_item->set_is_taxable($ticket->taxable()); |
|
| 1935 | - $ticket_line_item->save(); |
|
| 1936 | - } |
|
| 1937 | - } |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - |
|
| 1942 | - |
|
| 1943 | - /**************************************** @DEPRECATED METHODS *************************************** */ |
|
| 1944 | - /** |
|
| 1945 | - * @deprecated |
|
| 1946 | - * @param EE_Line_Item $total_line_item |
|
| 1947 | - * @return EE_Line_Item |
|
| 1948 | - * @throws EE_Error |
|
| 1949 | - * @throws InvalidArgumentException |
|
| 1950 | - * @throws InvalidDataTypeException |
|
| 1951 | - * @throws InvalidInterfaceException |
|
| 1952 | - * @throws ReflectionException |
|
| 1953 | - */ |
|
| 1954 | - public static function get_items_subtotal(EE_Line_Item $total_line_item) |
|
| 1955 | - { |
|
| 1956 | - EE_Error::doing_it_wrong( |
|
| 1957 | - 'EEH_Line_Item::get_items_subtotal()', |
|
| 1958 | - sprintf( |
|
| 1959 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 1960 | - 'EEH_Line_Item::get_pre_tax_subtotal()' |
|
| 1961 | - ), |
|
| 1962 | - '4.6.0' |
|
| 1963 | - ); |
|
| 1964 | - return self::get_pre_tax_subtotal($total_line_item); |
|
| 1965 | - } |
|
| 1966 | - |
|
| 1967 | - |
|
| 1968 | - /** |
|
| 1969 | - * @deprecated |
|
| 1970 | - * @param EE_Transaction $transaction |
|
| 1971 | - * @return EE_Line_Item |
|
| 1972 | - * @throws EE_Error |
|
| 1973 | - * @throws InvalidArgumentException |
|
| 1974 | - * @throws InvalidDataTypeException |
|
| 1975 | - * @throws InvalidInterfaceException |
|
| 1976 | - * @throws ReflectionException |
|
| 1977 | - */ |
|
| 1978 | - public static function create_default_total_line_item($transaction = null) |
|
| 1979 | - { |
|
| 1980 | - EE_Error::doing_it_wrong( |
|
| 1981 | - 'EEH_Line_Item::create_default_total_line_item()', |
|
| 1982 | - sprintf( |
|
| 1983 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 1984 | - 'EEH_Line_Item::create_total_line_item()' |
|
| 1985 | - ), |
|
| 1986 | - '4.6.0' |
|
| 1987 | - ); |
|
| 1988 | - return self::create_total_line_item($transaction); |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - |
|
| 1992 | - /** |
|
| 1993 | - * @deprecated |
|
| 1994 | - * @param EE_Line_Item $total_line_item |
|
| 1995 | - * @param EE_Transaction $transaction |
|
| 1996 | - * @return EE_Line_Item |
|
| 1997 | - * @throws EE_Error |
|
| 1998 | - * @throws InvalidArgumentException |
|
| 1999 | - * @throws InvalidDataTypeException |
|
| 2000 | - * @throws InvalidInterfaceException |
|
| 2001 | - * @throws ReflectionException |
|
| 2002 | - */ |
|
| 2003 | - public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 2004 | - { |
|
| 2005 | - EE_Error::doing_it_wrong( |
|
| 2006 | - 'EEH_Line_Item::create_default_tickets_subtotal()', |
|
| 2007 | - sprintf( |
|
| 2008 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 2009 | - 'EEH_Line_Item::create_pre_tax_subtotal()' |
|
| 2010 | - ), |
|
| 2011 | - '4.6.0' |
|
| 2012 | - ); |
|
| 2013 | - return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 2014 | - } |
|
| 2015 | - |
|
| 2016 | - |
|
| 2017 | - /** |
|
| 2018 | - * @deprecated |
|
| 2019 | - * @param EE_Line_Item $total_line_item |
|
| 2020 | - * @param EE_Transaction $transaction |
|
| 2021 | - * @return EE_Line_Item |
|
| 2022 | - * @throws EE_Error |
|
| 2023 | - * @throws InvalidArgumentException |
|
| 2024 | - * @throws InvalidDataTypeException |
|
| 2025 | - * @throws InvalidInterfaceException |
|
| 2026 | - * @throws ReflectionException |
|
| 2027 | - */ |
|
| 2028 | - public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 2029 | - { |
|
| 2030 | - EE_Error::doing_it_wrong( |
|
| 2031 | - 'EEH_Line_Item::create_default_taxes_subtotal()', |
|
| 2032 | - sprintf( |
|
| 2033 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 2034 | - 'EEH_Line_Item::create_taxes_subtotal()' |
|
| 2035 | - ), |
|
| 2036 | - '4.6.0' |
|
| 2037 | - ); |
|
| 2038 | - return self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 2039 | - } |
|
| 2040 | - |
|
| 2041 | - |
|
| 2042 | - /** |
|
| 2043 | - * @deprecated |
|
| 2044 | - * @param EE_Line_Item $total_line_item |
|
| 2045 | - * @param EE_Transaction $transaction |
|
| 2046 | - * @return EE_Line_Item |
|
| 2047 | - * @throws EE_Error |
|
| 2048 | - * @throws InvalidArgumentException |
|
| 2049 | - * @throws InvalidDataTypeException |
|
| 2050 | - * @throws InvalidInterfaceException |
|
| 2051 | - * @throws ReflectionException |
|
| 2052 | - */ |
|
| 2053 | - public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 2054 | - { |
|
| 2055 | - EE_Error::doing_it_wrong( |
|
| 2056 | - 'EEH_Line_Item::create_default_event_subtotal()', |
|
| 2057 | - sprintf( |
|
| 2058 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 2059 | - 'EEH_Line_Item::create_event_subtotal()' |
|
| 2060 | - ), |
|
| 2061 | - '4.6.0' |
|
| 2062 | - ); |
|
| 2063 | - return self::create_event_subtotal($total_line_item, $transaction); |
|
| 2064 | - } |
|
| 24 | + /** |
|
| 25 | + * Adds a simple item (unrelated to any other model object) to the provided PARENT line item. |
|
| 26 | + * Does NOT automatically re-calculate the line item totals or update the related transaction. |
|
| 27 | + * You should call recalculate_total_including_taxes() on the grant total line item after this |
|
| 28 | + * to update the subtotals, and EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 29 | + * to keep the registration final prices in-sync with the transaction's total. |
|
| 30 | + * |
|
| 31 | + * @param EE_Line_Item $parent_line_item |
|
| 32 | + * @param string $name |
|
| 33 | + * @param float $unit_price |
|
| 34 | + * @param string $description |
|
| 35 | + * @param int $quantity |
|
| 36 | + * @param boolean $taxable |
|
| 37 | + * @param boolean $code if set to a value, ensures there is only one line item with that code |
|
| 38 | + * @return boolean success |
|
| 39 | + * @throws EE_Error |
|
| 40 | + * @throws InvalidArgumentException |
|
| 41 | + * @throws InvalidDataTypeException |
|
| 42 | + * @throws InvalidInterfaceException |
|
| 43 | + * @throws ReflectionException |
|
| 44 | + */ |
|
| 45 | + public static function add_unrelated_item( |
|
| 46 | + EE_Line_Item $parent_line_item, |
|
| 47 | + $name, |
|
| 48 | + $unit_price, |
|
| 49 | + $description = '', |
|
| 50 | + $quantity = 1, |
|
| 51 | + $taxable = false, |
|
| 52 | + $code = null |
|
| 53 | + ) { |
|
| 54 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
| 55 | + $line_item = EE_Line_Item::new_instance(array( |
|
| 56 | + 'LIN_name' => $name, |
|
| 57 | + 'LIN_desc' => $description, |
|
| 58 | + 'LIN_unit_price' => $unit_price, |
|
| 59 | + 'LIN_quantity' => $quantity, |
|
| 60 | + 'LIN_percent' => null, |
|
| 61 | + 'LIN_is_taxable' => $taxable, |
|
| 62 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
| 63 | + 'LIN_total' => (float) $unit_price * (int) $quantity, |
|
| 64 | + 'LIN_type' => EEM_Line_Item::type_line_item, |
|
| 65 | + 'LIN_code' => $code, |
|
| 66 | + )); |
|
| 67 | + $line_item = apply_filters( |
|
| 68 | + 'FHEE__EEH_Line_Item__add_unrelated_item__line_item', |
|
| 69 | + $line_item, |
|
| 70 | + $parent_line_item |
|
| 71 | + ); |
|
| 72 | + return self::add_item($parent_line_item, $line_item); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Adds a simple item ( unrelated to any other model object) to the total line item, |
|
| 78 | + * in the correct spot in the line item tree. Automatically |
|
| 79 | + * re-calculates the line item totals and updates the related transaction. But |
|
| 80 | + * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
| 81 | + * should probably change because of this). |
|
| 82 | + * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 83 | + * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
| 84 | + * |
|
| 85 | + * @param EE_Line_Item $parent_line_item |
|
| 86 | + * @param string $name |
|
| 87 | + * @param float $percentage_amount |
|
| 88 | + * @param string $description |
|
| 89 | + * @param boolean $taxable |
|
| 90 | + * @return boolean success |
|
| 91 | + * @throws EE_Error |
|
| 92 | + */ |
|
| 93 | + public static function add_percentage_based_item( |
|
| 94 | + EE_Line_Item $parent_line_item, |
|
| 95 | + $name, |
|
| 96 | + $percentage_amount, |
|
| 97 | + $description = '', |
|
| 98 | + $taxable = false |
|
| 99 | + ) { |
|
| 100 | + $line_item = EE_Line_Item::new_instance(array( |
|
| 101 | + 'LIN_name' => $name, |
|
| 102 | + 'LIN_desc' => $description, |
|
| 103 | + 'LIN_unit_price' => 0, |
|
| 104 | + 'LIN_percent' => $percentage_amount, |
|
| 105 | + 'LIN_quantity' => 1, |
|
| 106 | + 'LIN_is_taxable' => $taxable, |
|
| 107 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
| 108 | + 'LIN_type' => EEM_Line_Item::type_line_item, |
|
| 109 | + 'LIN_parent' => $parent_line_item->ID(), |
|
| 110 | + )); |
|
| 111 | + $line_item = apply_filters( |
|
| 112 | + 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
|
| 113 | + $line_item |
|
| 114 | + ); |
|
| 115 | + return $parent_line_item->add_child_line_item($line_item, false); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Returns the new line item created by adding a purchase of the ticket |
|
| 121 | + * ensures that ticket line item is saved, and that cart total has been recalculated. |
|
| 122 | + * If this ticket has already been purchased, just increments its count. |
|
| 123 | + * Automatically re-calculates the line item totals and updates the related transaction. But |
|
| 124 | + * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
| 125 | + * should probably change because of this). |
|
| 126 | + * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 127 | + * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
| 128 | + * |
|
| 129 | + * @param EE_Line_Item $total_line_item grand total line item of type EEM_Line_Item::type_total |
|
| 130 | + * @param EE_Ticket $ticket |
|
| 131 | + * @param int $qty |
|
| 132 | + * @return EE_Line_Item |
|
| 133 | + * @throws EE_Error |
|
| 134 | + * @throws InvalidArgumentException |
|
| 135 | + * @throws InvalidDataTypeException |
|
| 136 | + * @throws InvalidInterfaceException |
|
| 137 | + * @throws ReflectionException |
|
| 138 | + */ |
|
| 139 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) |
|
| 140 | + { |
|
| 141 | + if (! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
| 142 | + throw new EE_Error( |
|
| 143 | + sprintf( |
|
| 144 | + esc_html__( |
|
| 145 | + 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', |
|
| 146 | + 'event_espresso' |
|
| 147 | + ), |
|
| 148 | + $ticket->ID(), |
|
| 149 | + $total_line_item->ID() |
|
| 150 | + ) |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | + // either increment the qty for an existing ticket |
|
| 154 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
| 155 | + // or add a new one |
|
| 156 | + if (! $line_item instanceof EE_Line_Item) { |
|
| 157 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
| 158 | + } |
|
| 159 | + $total_line_item->recalculate_total_including_taxes(); |
|
| 160 | + return $line_item; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Returns the new line item created by adding a purchase of the ticket |
|
| 166 | + * |
|
| 167 | + * @param EE_Line_Item $total_line_item |
|
| 168 | + * @param EE_Ticket $ticket |
|
| 169 | + * @param int $qty |
|
| 170 | + * @return EE_Line_Item |
|
| 171 | + * @throws EE_Error |
|
| 172 | + * @throws InvalidArgumentException |
|
| 173 | + * @throws InvalidDataTypeException |
|
| 174 | + * @throws InvalidInterfaceException |
|
| 175 | + * @throws ReflectionException |
|
| 176 | + */ |
|
| 177 | + public static function increment_ticket_qty_if_already_in_cart( |
|
| 178 | + EE_Line_Item $total_line_item, |
|
| 179 | + EE_Ticket $ticket, |
|
| 180 | + $qty = 1 |
|
| 181 | + ) { |
|
| 182 | + $line_item = null; |
|
| 183 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
| 184 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 185 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
| 186 | + if ($ticket_line_item instanceof EE_Line_Item |
|
| 187 | + && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
|
| 188 | + ) { |
|
| 189 | + $line_item = $ticket_line_item; |
|
| 190 | + break; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + if ($line_item instanceof EE_Line_Item) { |
|
| 195 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
| 196 | + return $line_item; |
|
| 197 | + } |
|
| 198 | + return null; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Increments the line item and all its children's quantity by $qty (but percent line items are unaffected). |
|
| 204 | + * Does NOT save or recalculate other line items totals |
|
| 205 | + * |
|
| 206 | + * @param EE_Line_Item $line_item |
|
| 207 | + * @param int $qty |
|
| 208 | + * @return void |
|
| 209 | + * @throws EE_Error |
|
| 210 | + * @throws InvalidArgumentException |
|
| 211 | + * @throws InvalidDataTypeException |
|
| 212 | + * @throws InvalidInterfaceException |
|
| 213 | + * @throws ReflectionException |
|
| 214 | + */ |
|
| 215 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) |
|
| 216 | + { |
|
| 217 | + if (! $line_item->is_percent()) { |
|
| 218 | + $qty += $line_item->quantity(); |
|
| 219 | + $line_item->set_quantity($qty); |
|
| 220 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
| 221 | + $line_item->save(); |
|
| 222 | + } |
|
| 223 | + foreach ($line_item->children() as $child) { |
|
| 224 | + if ($child->is_sub_line_item()) { |
|
| 225 | + EEH_Line_Item::update_quantity($child, $qty); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Decrements the line item and all its children's quantity by $qty (but percent line items are unaffected). |
|
| 233 | + * Does NOT save or recalculate other line items totals |
|
| 234 | + * |
|
| 235 | + * @param EE_Line_Item $line_item |
|
| 236 | + * @param int $qty |
|
| 237 | + * @return void |
|
| 238 | + * @throws EE_Error |
|
| 239 | + * @throws InvalidArgumentException |
|
| 240 | + * @throws InvalidDataTypeException |
|
| 241 | + * @throws InvalidInterfaceException |
|
| 242 | + * @throws ReflectionException |
|
| 243 | + */ |
|
| 244 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) |
|
| 245 | + { |
|
| 246 | + if (! $line_item->is_percent()) { |
|
| 247 | + $qty = $line_item->quantity() - $qty; |
|
| 248 | + $qty = max($qty, 0); |
|
| 249 | + $line_item->set_quantity($qty); |
|
| 250 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
| 251 | + $line_item->save(); |
|
| 252 | + } |
|
| 253 | + foreach ($line_item->children() as $child) { |
|
| 254 | + if ($child->is_sub_line_item()) { |
|
| 255 | + EEH_Line_Item::update_quantity($child, $qty); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Updates the line item and its children's quantities to the specified number. |
|
| 263 | + * Does NOT save them or recalculate totals. |
|
| 264 | + * |
|
| 265 | + * @param EE_Line_Item $line_item |
|
| 266 | + * @param int $new_quantity |
|
| 267 | + * @throws EE_Error |
|
| 268 | + * @throws InvalidArgumentException |
|
| 269 | + * @throws InvalidDataTypeException |
|
| 270 | + * @throws InvalidInterfaceException |
|
| 271 | + * @throws ReflectionException |
|
| 272 | + */ |
|
| 273 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) |
|
| 274 | + { |
|
| 275 | + if (! $line_item->is_percent()) { |
|
| 276 | + $line_item->set_quantity($new_quantity); |
|
| 277 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
| 278 | + $line_item->save(); |
|
| 279 | + } |
|
| 280 | + foreach ($line_item->children() as $child) { |
|
| 281 | + if ($child->is_sub_line_item()) { |
|
| 282 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Returns the new line item created by adding a purchase of the ticket |
|
| 290 | + * |
|
| 291 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 292 | + * @param EE_Ticket $ticket |
|
| 293 | + * @param int $qty |
|
| 294 | + * @return EE_Line_Item |
|
| 295 | + * @throws EE_Error |
|
| 296 | + * @throws InvalidArgumentException |
|
| 297 | + * @throws InvalidDataTypeException |
|
| 298 | + * @throws InvalidInterfaceException |
|
| 299 | + * @throws ReflectionException |
|
| 300 | + */ |
|
| 301 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) |
|
| 302 | + { |
|
| 303 | + $datetimes = $ticket->datetimes(); |
|
| 304 | + $first_datetime = reset($datetimes); |
|
| 305 | + $first_datetime_name = esc_html__('Event', 'event_espresso'); |
|
| 306 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
| 307 | + $first_datetime_name = $first_datetime->event()->name(); |
|
| 308 | + } |
|
| 309 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
| 310 | + // get event subtotal line |
|
| 311 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
| 312 | + // add $ticket to cart |
|
| 313 | + $line_item = EE_Line_Item::new_instance(array( |
|
| 314 | + 'LIN_name' => $ticket->name(), |
|
| 315 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
| 316 | + 'LIN_unit_price' => $ticket->price(), |
|
| 317 | + 'LIN_quantity' => $qty, |
|
| 318 | + 'LIN_is_taxable' => $ticket->taxable(), |
|
| 319 | + 'LIN_order' => count($events_sub_total->children()), |
|
| 320 | + 'LIN_total' => $ticket->price() * $qty, |
|
| 321 | + 'LIN_type' => EEM_Line_Item::type_line_item, |
|
| 322 | + 'OBJ_ID' => $ticket->ID(), |
|
| 323 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 324 | + )); |
|
| 325 | + $line_item = apply_filters( |
|
| 326 | + 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
|
| 327 | + $line_item |
|
| 328 | + ); |
|
| 329 | + $events_sub_total->add_child_line_item($line_item); |
|
| 330 | + // now add the sub-line items |
|
| 331 | + $running_total_for_ticket = 0; |
|
| 332 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
| 333 | + $sign = $price->is_discount() ? -1 : 1; |
|
| 334 | + $price_total = $price->is_percent() |
|
| 335 | + ? $running_total_for_ticket * $price->amount() / 100 |
|
| 336 | + : $price->amount() * $qty; |
|
| 337 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
| 338 | + 'LIN_name' => $price->name(), |
|
| 339 | + 'LIN_desc' => $price->desc(), |
|
| 340 | + 'LIN_quantity' => $price->is_percent() ? null : $qty, |
|
| 341 | + 'LIN_is_taxable' => false, |
|
| 342 | + 'LIN_order' => $price->order(), |
|
| 343 | + 'LIN_total' => $sign * $price_total, |
|
| 344 | + 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
|
| 345 | + 'OBJ_ID' => $price->ID(), |
|
| 346 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PRICE, |
|
| 347 | + )); |
|
| 348 | + $sub_line_item = apply_filters( |
|
| 349 | + 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
|
| 350 | + $sub_line_item |
|
| 351 | + ); |
|
| 352 | + if ($price->is_percent()) { |
|
| 353 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
| 354 | + } else { |
|
| 355 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
| 356 | + } |
|
| 357 | + $running_total_for_ticket += $price_total; |
|
| 358 | + $line_item->add_child_line_item($sub_line_item); |
|
| 359 | + } |
|
| 360 | + return $line_item; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Adds the specified item under the pre-tax-sub-total line item. Automatically |
|
| 366 | + * re-calculates the line item totals and updates the related transaction. But |
|
| 367 | + * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
| 368 | + * should probably change because of this). |
|
| 369 | + * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 370 | + * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
| 371 | + * |
|
| 372 | + * @param EE_Line_Item $total_line_item |
|
| 373 | + * @param EE_Line_Item $item to be added |
|
| 374 | + * @return boolean |
|
| 375 | + * @throws EE_Error |
|
| 376 | + * @throws InvalidArgumentException |
|
| 377 | + * @throws InvalidDataTypeException |
|
| 378 | + * @throws InvalidInterfaceException |
|
| 379 | + * @throws ReflectionException |
|
| 380 | + */ |
|
| 381 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) |
|
| 382 | + { |
|
| 383 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
| 384 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
| 385 | + $success = $pre_tax_subtotal->add_child_line_item($item); |
|
| 386 | + } else { |
|
| 387 | + return false; |
|
| 388 | + } |
|
| 389 | + $total_line_item->recalculate_total_including_taxes(); |
|
| 390 | + return $success; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * cancels an existing ticket line item, |
|
| 396 | + * by decrementing it's quantity by 1 and adding a new "type_cancellation" sub-line-item. |
|
| 397 | + * ALL totals and subtotals will NEED TO BE UPDATED after performing this action |
|
| 398 | + * |
|
| 399 | + * @param EE_Line_Item $ticket_line_item |
|
| 400 | + * @param int $qty |
|
| 401 | + * @return bool success |
|
| 402 | + * @throws EE_Error |
|
| 403 | + * @throws InvalidArgumentException |
|
| 404 | + * @throws InvalidDataTypeException |
|
| 405 | + * @throws InvalidInterfaceException |
|
| 406 | + * @throws ReflectionException |
|
| 407 | + */ |
|
| 408 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) |
|
| 409 | + { |
|
| 410 | + // validate incoming line_item |
|
| 411 | + if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
| 412 | + throw new EE_Error( |
|
| 413 | + sprintf( |
|
| 414 | + esc_html__( |
|
| 415 | + 'The supplied line item must have an Object Type of "Ticket", not %1$s.', |
|
| 416 | + 'event_espresso' |
|
| 417 | + ), |
|
| 418 | + $ticket_line_item->type() |
|
| 419 | + ) |
|
| 420 | + ); |
|
| 421 | + } |
|
| 422 | + if ($ticket_line_item->quantity() < $qty) { |
|
| 423 | + throw new EE_Error( |
|
| 424 | + sprintf( |
|
| 425 | + esc_html__( |
|
| 426 | + 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', |
|
| 427 | + 'event_espresso' |
|
| 428 | + ), |
|
| 429 | + $qty, |
|
| 430 | + $ticket_line_item->quantity() |
|
| 431 | + ) |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
|
| 435 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
| 436 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
| 437 | + if ($child_line_item->is_sub_line_item() |
|
| 438 | + && ! $child_line_item->is_percent() |
|
| 439 | + && ! $child_line_item->is_cancellation() |
|
| 440 | + ) { |
|
| 441 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + // get cancellation sub line item |
|
| 445 | + $cancellation_line_item = EEH_Line_Item::get_descendants_of_type( |
|
| 446 | + $ticket_line_item, |
|
| 447 | + EEM_Line_Item::type_cancellation |
|
| 448 | + ); |
|
| 449 | + $cancellation_line_item = reset($cancellation_line_item); |
|
| 450 | + // verify that this ticket was indeed previously cancelled |
|
| 451 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
| 452 | + // increment cancelled quantity |
|
| 453 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
| 454 | + } else { |
|
| 455 | + // create cancellation sub line item |
|
| 456 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
| 457 | + 'LIN_name' => esc_html__('Cancellation', 'event_espresso'), |
|
| 458 | + 'LIN_desc' => sprintf( |
|
| 459 | + esc_html_x( |
|
| 460 | + 'Cancelled %1$s : %2$s', |
|
| 461 | + 'Cancelled Ticket Name : 2015-01-01 11:11', |
|
| 462 | + 'event_espresso' |
|
| 463 | + ), |
|
| 464 | + $ticket_line_item->name(), |
|
| 465 | + current_time(get_option('date_format') . ' ' . get_option('time_format')) |
|
| 466 | + ), |
|
| 467 | + 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
|
| 468 | + 'LIN_quantity' => $qty, |
|
| 469 | + 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
|
| 470 | + 'LIN_order' => count($ticket_line_item->children()), |
|
| 471 | + 'LIN_total' => 0, // $ticket_line_item->unit_price() |
|
| 472 | + 'LIN_type' => EEM_Line_Item::type_cancellation, |
|
| 473 | + )); |
|
| 474 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
| 475 | + } |
|
| 476 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
| 477 | + // decrement parent line item quantity |
|
| 478 | + $event_line_item = $ticket_line_item->parent(); |
|
| 479 | + if ($event_line_item instanceof EE_Line_Item |
|
| 480 | + && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
| 481 | + ) { |
|
| 482 | + $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
| 483 | + $event_line_item->save(); |
|
| 484 | + } |
|
| 485 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
| 486 | + return true; |
|
| 487 | + } |
|
| 488 | + return false; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * reinstates (un-cancels?) a previously canceled ticket line item, |
|
| 494 | + * by incrementing it's quantity by 1, and decrementing it's "type_cancellation" sub-line-item. |
|
| 495 | + * ALL totals and subtotals will NEED TO BE UPDATED after performing this action |
|
| 496 | + * |
|
| 497 | + * @param EE_Line_Item $ticket_line_item |
|
| 498 | + * @param int $qty |
|
| 499 | + * @return bool success |
|
| 500 | + * @throws EE_Error |
|
| 501 | + * @throws InvalidArgumentException |
|
| 502 | + * @throws InvalidDataTypeException |
|
| 503 | + * @throws InvalidInterfaceException |
|
| 504 | + * @throws ReflectionException |
|
| 505 | + */ |
|
| 506 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) |
|
| 507 | + { |
|
| 508 | + // validate incoming line_item |
|
| 509 | + if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
| 510 | + throw new EE_Error( |
|
| 511 | + sprintf( |
|
| 512 | + esc_html__( |
|
| 513 | + 'The supplied line item must have an Object Type of "Ticket", not %1$s.', |
|
| 514 | + 'event_espresso' |
|
| 515 | + ), |
|
| 516 | + $ticket_line_item->type() |
|
| 517 | + ) |
|
| 518 | + ); |
|
| 519 | + } |
|
| 520 | + // get cancellation sub line item |
|
| 521 | + $cancellation_line_item = EEH_Line_Item::get_descendants_of_type( |
|
| 522 | + $ticket_line_item, |
|
| 523 | + EEM_Line_Item::type_cancellation |
|
| 524 | + ); |
|
| 525 | + $cancellation_line_item = reset($cancellation_line_item); |
|
| 526 | + // verify that this ticket was indeed previously cancelled |
|
| 527 | + if (! $cancellation_line_item instanceof EE_Line_Item) { |
|
| 528 | + return false; |
|
| 529 | + } |
|
| 530 | + if ($cancellation_line_item->quantity() > $qty) { |
|
| 531 | + // decrement cancelled quantity |
|
| 532 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
| 533 | + } elseif ($cancellation_line_item->quantity() === $qty) { |
|
| 534 | + // decrement cancelled quantity in case anyone still has the object kicking around |
|
| 535 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
| 536 | + // delete because quantity will end up as 0 |
|
| 537 | + $cancellation_line_item->delete(); |
|
| 538 | + // and attempt to destroy the object, |
|
| 539 | + // even though PHP won't actually destroy it until it needs the memory |
|
| 540 | + unset($cancellation_line_item); |
|
| 541 | + } else { |
|
| 542 | + // what ?!?! negative quantity ?!?! |
|
| 543 | + throw new EE_Error( |
|
| 544 | + sprintf( |
|
| 545 | + esc_html__( |
|
| 546 | + 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
| 547 | + 'event_espresso' |
|
| 548 | + ), |
|
| 549 | + $qty, |
|
| 550 | + $cancellation_line_item->quantity() |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + // increment ticket quantity |
|
| 555 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
| 556 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
| 557 | + // increment parent line item quantity |
|
| 558 | + $event_line_item = $ticket_line_item->parent(); |
|
| 559 | + if ($event_line_item instanceof EE_Line_Item |
|
| 560 | + && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
| 561 | + ) { |
|
| 562 | + $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
| 563 | + } |
|
| 564 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
| 565 | + return true; |
|
| 566 | + } |
|
| 567 | + return false; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * calls EEH_Line_Item::find_transaction_grand_total_for_line_item() |
|
| 573 | + * then EE_Line_Item::recalculate_total_including_taxes() on the result |
|
| 574 | + * |
|
| 575 | + * @param EE_Line_Item $line_item |
|
| 576 | + * @return float |
|
| 577 | + * @throws EE_Error |
|
| 578 | + * @throws InvalidArgumentException |
|
| 579 | + * @throws InvalidDataTypeException |
|
| 580 | + * @throws InvalidInterfaceException |
|
| 581 | + * @throws ReflectionException |
|
| 582 | + */ |
|
| 583 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) |
|
| 584 | + { |
|
| 585 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
| 586 | + return $grand_total_line_item->recalculate_total_including_taxes(); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * Gets the line item which contains the subtotal of all the items |
|
| 592 | + * |
|
| 593 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 594 | + * @return EE_Line_Item |
|
| 595 | + * @throws EE_Error |
|
| 596 | + * @throws InvalidArgumentException |
|
| 597 | + * @throws InvalidDataTypeException |
|
| 598 | + * @throws InvalidInterfaceException |
|
| 599 | + * @throws ReflectionException |
|
| 600 | + */ |
|
| 601 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) |
|
| 602 | + { |
|
| 603 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
| 604 | + return $pre_tax_subtotal instanceof EE_Line_Item |
|
| 605 | + ? $pre_tax_subtotal |
|
| 606 | + : self::create_pre_tax_subtotal($total_line_item); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * Gets the line item for the taxes subtotal |
|
| 612 | + * |
|
| 613 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 614 | + * @return EE_Line_Item |
|
| 615 | + * @throws EE_Error |
|
| 616 | + * @throws InvalidArgumentException |
|
| 617 | + * @throws InvalidDataTypeException |
|
| 618 | + * @throws InvalidInterfaceException |
|
| 619 | + * @throws ReflectionException |
|
| 620 | + */ |
|
| 621 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) |
|
| 622 | + { |
|
| 623 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
| 624 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * sets the TXN ID on an EE_Line_Item if passed a valid EE_Transaction object |
|
| 630 | + * |
|
| 631 | + * @param EE_Line_Item $line_item |
|
| 632 | + * @param EE_Transaction $transaction |
|
| 633 | + * @return void |
|
| 634 | + * @throws EE_Error |
|
| 635 | + * @throws InvalidArgumentException |
|
| 636 | + * @throws InvalidDataTypeException |
|
| 637 | + * @throws InvalidInterfaceException |
|
| 638 | + * @throws ReflectionException |
|
| 639 | + */ |
|
| 640 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = null) |
|
| 641 | + { |
|
| 642 | + if ($transaction) { |
|
| 643 | + /** @type EEM_Transaction $EEM_Transaction */ |
|
| 644 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
| 645 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
| 646 | + $line_item->set_TXN_ID($TXN_ID); |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * Creates a new default total line item for the transaction, |
|
| 653 | + * and its tickets subtotal and taxes subtotal line items (and adds the |
|
| 654 | + * existing taxes as children of the taxes subtotal line item) |
|
| 655 | + * |
|
| 656 | + * @param EE_Transaction $transaction |
|
| 657 | + * @return EE_Line_Item of type total |
|
| 658 | + * @throws EE_Error |
|
| 659 | + * @throws InvalidArgumentException |
|
| 660 | + * @throws InvalidDataTypeException |
|
| 661 | + * @throws InvalidInterfaceException |
|
| 662 | + * @throws ReflectionException |
|
| 663 | + */ |
|
| 664 | + public static function create_total_line_item($transaction = null) |
|
| 665 | + { |
|
| 666 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
| 667 | + 'LIN_code' => 'total', |
|
| 668 | + 'LIN_name' => esc_html__('Grand Total', 'event_espresso'), |
|
| 669 | + 'LIN_type' => EEM_Line_Item::type_total, |
|
| 670 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TRANSACTION, |
|
| 671 | + )); |
|
| 672 | + $total_line_item = apply_filters( |
|
| 673 | + 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
|
| 674 | + $total_line_item |
|
| 675 | + ); |
|
| 676 | + self::set_TXN_ID($total_line_item, $transaction); |
|
| 677 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 678 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 679 | + return $total_line_item; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Creates a default items subtotal line item |
|
| 685 | + * |
|
| 686 | + * @param EE_Line_Item $total_line_item |
|
| 687 | + * @param EE_Transaction $transaction |
|
| 688 | + * @return EE_Line_Item |
|
| 689 | + * @throws EE_Error |
|
| 690 | + * @throws InvalidArgumentException |
|
| 691 | + * @throws InvalidDataTypeException |
|
| 692 | + * @throws InvalidInterfaceException |
|
| 693 | + * @throws ReflectionException |
|
| 694 | + */ |
|
| 695 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 696 | + { |
|
| 697 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
| 698 | + 'LIN_code' => 'pre-tax-subtotal', |
|
| 699 | + 'LIN_name' => esc_html__('Pre-Tax Subtotal', 'event_espresso'), |
|
| 700 | + 'LIN_type' => EEM_Line_Item::type_sub_total, |
|
| 701 | + )); |
|
| 702 | + $pre_tax_line_item = apply_filters( |
|
| 703 | + 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
|
| 704 | + $pre_tax_line_item |
|
| 705 | + ); |
|
| 706 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
| 707 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
| 708 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
| 709 | + return $pre_tax_line_item; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * Creates a line item for the taxes subtotal and finds all the tax prices |
|
| 715 | + * and applies taxes to it |
|
| 716 | + * |
|
| 717 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 718 | + * @param EE_Transaction $transaction |
|
| 719 | + * @return EE_Line_Item |
|
| 720 | + * @throws EE_Error |
|
| 721 | + * @throws InvalidArgumentException |
|
| 722 | + * @throws InvalidDataTypeException |
|
| 723 | + * @throws InvalidInterfaceException |
|
| 724 | + * @throws ReflectionException |
|
| 725 | + */ |
|
| 726 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 727 | + { |
|
| 728 | + $tax_line_item = EE_Line_Item::new_instance(array( |
|
| 729 | + 'LIN_code' => 'taxes', |
|
| 730 | + 'LIN_name' => esc_html__('Taxes', 'event_espresso'), |
|
| 731 | + 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
|
| 732 | + 'LIN_order' => 1000,// this should always come last |
|
| 733 | + )); |
|
| 734 | + $tax_line_item = apply_filters( |
|
| 735 | + 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
|
| 736 | + $tax_line_item |
|
| 737 | + ); |
|
| 738 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
| 739 | + $total_line_item->add_child_line_item($tax_line_item); |
|
| 740 | + // and lastly, add the actual taxes |
|
| 741 | + self::apply_taxes($total_line_item); |
|
| 742 | + return $tax_line_item; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Creates a default items subtotal line item |
|
| 748 | + * |
|
| 749 | + * @param EE_Line_Item $pre_tax_line_item |
|
| 750 | + * @param EE_Transaction $transaction |
|
| 751 | + * @param EE_Event $event |
|
| 752 | + * @return EE_Line_Item |
|
| 753 | + * @throws EE_Error |
|
| 754 | + * @throws InvalidArgumentException |
|
| 755 | + * @throws InvalidDataTypeException |
|
| 756 | + * @throws InvalidInterfaceException |
|
| 757 | + * @throws ReflectionException |
|
| 758 | + */ |
|
| 759 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = null, $event = null) |
|
| 760 | + { |
|
| 761 | + $event_line_item = EE_Line_Item::new_instance(array( |
|
| 762 | + 'LIN_code' => self::get_event_code($event), |
|
| 763 | + 'LIN_name' => self::get_event_name($event), |
|
| 764 | + 'LIN_desc' => self::get_event_desc($event), |
|
| 765 | + 'LIN_type' => EEM_Line_Item::type_sub_total, |
|
| 766 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_EVENT, |
|
| 767 | + 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0, |
|
| 768 | + )); |
|
| 769 | + $event_line_item = apply_filters( |
|
| 770 | + 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
|
| 771 | + $event_line_item |
|
| 772 | + ); |
|
| 773 | + self::set_TXN_ID($event_line_item, $transaction); |
|
| 774 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
| 775 | + return $event_line_item; |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Gets what the event ticket's code SHOULD be |
|
| 781 | + * |
|
| 782 | + * @param EE_Event $event |
|
| 783 | + * @return string |
|
| 784 | + * @throws EE_Error |
|
| 785 | + */ |
|
| 786 | + public static function get_event_code($event) |
|
| 787 | + { |
|
| 788 | + return 'event-' . ($event instanceof EE_Event ? $event->ID() : '0'); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * Gets the event name |
|
| 794 | + * |
|
| 795 | + * @param EE_Event $event |
|
| 796 | + * @return string |
|
| 797 | + * @throws EE_Error |
|
| 798 | + */ |
|
| 799 | + public static function get_event_name($event) |
|
| 800 | + { |
|
| 801 | + return $event instanceof EE_Event |
|
| 802 | + ? mb_substr($event->name(), 0, 245) |
|
| 803 | + : esc_html__('Event', 'event_espresso'); |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * Gets the event excerpt |
|
| 809 | + * |
|
| 810 | + * @param EE_Event $event |
|
| 811 | + * @return string |
|
| 812 | + * @throws EE_Error |
|
| 813 | + */ |
|
| 814 | + public static function get_event_desc($event) |
|
| 815 | + { |
|
| 816 | + return $event instanceof EE_Event ? $event->short_description() : ''; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Given the grand total line item and a ticket, finds the event sub-total |
|
| 822 | + * line item the ticket's purchase should be added onto |
|
| 823 | + * |
|
| 824 | + * @access public |
|
| 825 | + * @param EE_Line_Item $grand_total the grand total line item |
|
| 826 | + * @param EE_Ticket $ticket |
|
| 827 | + * @return EE_Line_Item |
|
| 828 | + * @throws EE_Error |
|
| 829 | + * @throws InvalidArgumentException |
|
| 830 | + * @throws InvalidDataTypeException |
|
| 831 | + * @throws InvalidInterfaceException |
|
| 832 | + * @throws ReflectionException |
|
| 833 | + */ |
|
| 834 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) |
|
| 835 | + { |
|
| 836 | + $first_datetime = $ticket->first_datetime(); |
|
| 837 | + if (! $first_datetime instanceof EE_Datetime) { |
|
| 838 | + throw new EE_Error( |
|
| 839 | + sprintf( |
|
| 840 | + __('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), |
|
| 841 | + $ticket->ID() |
|
| 842 | + ) |
|
| 843 | + ); |
|
| 844 | + } |
|
| 845 | + $event = $first_datetime->event(); |
|
| 846 | + if (! $event instanceof EE_Event) { |
|
| 847 | + throw new EE_Error( |
|
| 848 | + sprintf( |
|
| 849 | + esc_html__( |
|
| 850 | + 'The supplied ticket (ID %d) has no event data associated with it.', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ), |
|
| 853 | + $ticket->ID() |
|
| 854 | + ) |
|
| 855 | + ); |
|
| 856 | + } |
|
| 857 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
| 858 | + if (! $events_sub_total instanceof EE_Line_Item) { |
|
| 859 | + throw new EE_Error( |
|
| 860 | + sprintf( |
|
| 861 | + esc_html__( |
|
| 862 | + 'There is no events sub-total for ticket %s on total line item %d', |
|
| 863 | + 'event_espresso' |
|
| 864 | + ), |
|
| 865 | + $ticket->ID(), |
|
| 866 | + $grand_total->ID() |
|
| 867 | + ) |
|
| 868 | + ); |
|
| 869 | + } |
|
| 870 | + return $events_sub_total; |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * Gets the event line item |
|
| 876 | + * |
|
| 877 | + * @param EE_Line_Item $grand_total |
|
| 878 | + * @param EE_Event $event |
|
| 879 | + * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
|
| 880 | + * @throws EE_Error |
|
| 881 | + * @throws InvalidArgumentException |
|
| 882 | + * @throws InvalidDataTypeException |
|
| 883 | + * @throws InvalidInterfaceException |
|
| 884 | + * @throws ReflectionException |
|
| 885 | + */ |
|
| 886 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) |
|
| 887 | + { |
|
| 888 | + /** @type EE_Event $event */ |
|
| 889 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
| 890 | + $event_line_item = null; |
|
| 891 | + $found = false; |
|
| 892 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
| 893 | + // default event subtotal, we should only ever find this the first time this method is called |
|
| 894 | + if (! $event_line_item->OBJ_ID()) { |
|
| 895 | + // let's use this! but first... set the event details |
|
| 896 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 897 | + $found = true; |
|
| 898 | + break; |
|
| 899 | + } |
|
| 900 | + if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
| 901 | + // found existing line item for this event in the cart, so break out of loop and use this one |
|
| 902 | + $found = true; |
|
| 903 | + break; |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + if (! $found) { |
|
| 907 | + // there is no event sub-total yet, so add it |
|
| 908 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
| 909 | + // create a new "event" subtotal below that |
|
| 910 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
| 911 | + // and set the event details |
|
| 912 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 913 | + } |
|
| 914 | + return $event_line_item; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + |
|
| 918 | + /** |
|
| 919 | + * Creates a default items subtotal line item |
|
| 920 | + * |
|
| 921 | + * @param EE_Line_Item $event_line_item |
|
| 922 | + * @param EE_Event $event |
|
| 923 | + * @param EE_Transaction $transaction |
|
| 924 | + * @return void |
|
| 925 | + * @throws EE_Error |
|
| 926 | + * @throws InvalidArgumentException |
|
| 927 | + * @throws InvalidDataTypeException |
|
| 928 | + * @throws InvalidInterfaceException |
|
| 929 | + * @throws ReflectionException |
|
| 930 | + */ |
|
| 931 | + public static function set_event_subtotal_details( |
|
| 932 | + EE_Line_Item $event_line_item, |
|
| 933 | + EE_Event $event, |
|
| 934 | + $transaction = null |
|
| 935 | + ) { |
|
| 936 | + if ($event instanceof EE_Event) { |
|
| 937 | + $event_line_item->set_code(self::get_event_code($event)); |
|
| 938 | + $event_line_item->set_name(self::get_event_name($event)); |
|
| 939 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
| 940 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
| 941 | + } |
|
| 942 | + self::set_TXN_ID($event_line_item, $transaction); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * Finds what taxes should apply, adds them as tax line items under the taxes sub-total, |
|
| 948 | + * and recalculates the taxes sub-total and the grand total. Resets the taxes, so |
|
| 949 | + * any old taxes are removed |
|
| 950 | + * |
|
| 951 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 952 | + * @param bool $update_txn_status |
|
| 953 | + * @return bool |
|
| 954 | + * @throws EE_Error |
|
| 955 | + * @throws InvalidArgumentException |
|
| 956 | + * @throws InvalidDataTypeException |
|
| 957 | + * @throws InvalidInterfaceException |
|
| 958 | + * @throws ReflectionException |
|
| 959 | + * @throws RuntimeException |
|
| 960 | + */ |
|
| 961 | + public static function apply_taxes(EE_Line_Item $total_line_item, $update_txn_status = false) |
|
| 962 | + { |
|
| 963 | + /** @type EEM_Price $EEM_Price */ |
|
| 964 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
| 965 | + // get array of taxes via Price Model |
|
| 966 | + $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
|
| 967 | + ksort($ordered_taxes); |
|
| 968 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
| 969 | + // just to be safe, remove its old tax line items |
|
| 970 | + $deleted = $taxes_line_item->delete_children_line_items(); |
|
| 971 | + $updates = false; |
|
| 972 | + // loop thru taxes |
|
| 973 | + foreach ($ordered_taxes as $order => $taxes) { |
|
| 974 | + foreach ($taxes as $tax) { |
|
| 975 | + if ($tax instanceof EE_Price) { |
|
| 976 | + $tax_line_item = EE_Line_Item::new_instance( |
|
| 977 | + array( |
|
| 978 | + 'LIN_name' => $tax->name(), |
|
| 979 | + 'LIN_desc' => $tax->desc(), |
|
| 980 | + 'LIN_percent' => $tax->amount(), |
|
| 981 | + 'LIN_is_taxable' => false, |
|
| 982 | + 'LIN_order' => $order, |
|
| 983 | + 'LIN_total' => 0, |
|
| 984 | + 'LIN_type' => EEM_Line_Item::type_tax, |
|
| 985 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PRICE, |
|
| 986 | + 'OBJ_ID' => $tax->ID(), |
|
| 987 | + ) |
|
| 988 | + ); |
|
| 989 | + $tax_line_item = apply_filters( |
|
| 990 | + 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
|
| 991 | + $tax_line_item |
|
| 992 | + ); |
|
| 993 | + $updates = $taxes_line_item->add_child_line_item($tax_line_item) ? |
|
| 994 | + true : |
|
| 995 | + $updates; |
|
| 996 | + } |
|
| 997 | + } |
|
| 998 | + } |
|
| 999 | + // only recalculate totals if something changed |
|
| 1000 | + if ($deleted || $updates) { |
|
| 1001 | + $total_line_item->recalculate_total_including_taxes($update_txn_status); |
|
| 1002 | + return true; |
|
| 1003 | + } |
|
| 1004 | + return false; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + |
|
| 1008 | + /** |
|
| 1009 | + * Ensures that taxes have been applied to the order, if not applies them. |
|
| 1010 | + * Returns the total amount of tax |
|
| 1011 | + * |
|
| 1012 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 1013 | + * @return float |
|
| 1014 | + * @throws EE_Error |
|
| 1015 | + * @throws InvalidArgumentException |
|
| 1016 | + * @throws InvalidDataTypeException |
|
| 1017 | + * @throws InvalidInterfaceException |
|
| 1018 | + * @throws ReflectionException |
|
| 1019 | + */ |
|
| 1020 | + public static function ensure_taxes_applied($total_line_item) |
|
| 1021 | + { |
|
| 1022 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 1023 | + if (! $taxes_subtotal->children()) { |
|
| 1024 | + self::apply_taxes($total_line_item); |
|
| 1025 | + } |
|
| 1026 | + return $taxes_subtotal->total(); |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * Deletes ALL children of the passed line item |
|
| 1032 | + * |
|
| 1033 | + * @param EE_Line_Item $parent_line_item |
|
| 1034 | + * @return bool |
|
| 1035 | + * @throws EE_Error |
|
| 1036 | + * @throws InvalidArgumentException |
|
| 1037 | + * @throws InvalidDataTypeException |
|
| 1038 | + * @throws InvalidInterfaceException |
|
| 1039 | + * @throws ReflectionException |
|
| 1040 | + */ |
|
| 1041 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) |
|
| 1042 | + { |
|
| 1043 | + $deleted = 0; |
|
| 1044 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1045 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1046 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
| 1047 | + if ($child_line_item->ID()) { |
|
| 1048 | + $child_line_item->delete(); |
|
| 1049 | + unset($child_line_item); |
|
| 1050 | + } else { |
|
| 1051 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
| 1052 | + } |
|
| 1053 | + $deleted++; |
|
| 1054 | + } |
|
| 1055 | + } |
|
| 1056 | + return $deleted; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * Deletes the line items as indicated by the line item code(s) provided, |
|
| 1062 | + * regardless of where they're found in the line item tree. Automatically |
|
| 1063 | + * re-calculates the line item totals and updates the related transaction. But |
|
| 1064 | + * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
| 1065 | + * should probably change because of this). |
|
| 1066 | + * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
| 1067 | + * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
| 1068 | + * |
|
| 1069 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
| 1070 | + * @param array|bool|string $line_item_codes |
|
| 1071 | + * @return int number of items successfully removed |
|
| 1072 | + * @throws EE_Error |
|
| 1073 | + */ |
|
| 1074 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = false) |
|
| 1075 | + { |
|
| 1076 | + |
|
| 1077 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
| 1078 | + EE_Error::doing_it_wrong( |
|
| 1079 | + 'EEH_Line_Item::delete_items', |
|
| 1080 | + esc_html__( |
|
| 1081 | + 'This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly', |
|
| 1082 | + 'event_espresso' |
|
| 1083 | + ), |
|
| 1084 | + '4.6.18' |
|
| 1085 | + ); |
|
| 1086 | + } |
|
| 1087 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1088 | + |
|
| 1089 | + // check if only a single line_item_id was passed |
|
| 1090 | + if (! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
| 1091 | + // place single line_item_id in an array to appear as multiple line_item_ids |
|
| 1092 | + $line_item_codes = array($line_item_codes); |
|
| 1093 | + } |
|
| 1094 | + $removals = 0; |
|
| 1095 | + // cycle thru line_item_ids |
|
| 1096 | + foreach ($line_item_codes as $line_item_id) { |
|
| 1097 | + $removals += $total_line_item->delete_child_line_item($line_item_id); |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + if ($removals > 0) { |
|
| 1101 | + $total_line_item->recalculate_taxes_and_tax_total(); |
|
| 1102 | + return $removals; |
|
| 1103 | + } else { |
|
| 1104 | + return false; |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + |
|
| 1109 | + /** |
|
| 1110 | + * Overwrites the previous tax by clearing out the old taxes, and creates a new |
|
| 1111 | + * tax and updates the total line item accordingly |
|
| 1112 | + * |
|
| 1113 | + * @param EE_Line_Item $total_line_item |
|
| 1114 | + * @param float $amount |
|
| 1115 | + * @param string $name |
|
| 1116 | + * @param string $description |
|
| 1117 | + * @param string $code |
|
| 1118 | + * @param boolean $add_to_existing_line_item |
|
| 1119 | + * if true, and a duplicate line item with the same code is found, |
|
| 1120 | + * $amount will be added onto it; otherwise will simply set the taxes to match $amount |
|
| 1121 | + * @return EE_Line_Item the new tax line item created |
|
| 1122 | + * @throws EE_Error |
|
| 1123 | + * @throws InvalidArgumentException |
|
| 1124 | + * @throws InvalidDataTypeException |
|
| 1125 | + * @throws InvalidInterfaceException |
|
| 1126 | + * @throws ReflectionException |
|
| 1127 | + */ |
|
| 1128 | + public static function set_total_tax_to( |
|
| 1129 | + EE_Line_Item $total_line_item, |
|
| 1130 | + $amount, |
|
| 1131 | + $name = null, |
|
| 1132 | + $description = null, |
|
| 1133 | + $code = null, |
|
| 1134 | + $add_to_existing_line_item = false |
|
| 1135 | + ) { |
|
| 1136 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 1137 | + $taxable_total = $total_line_item->taxable_total(); |
|
| 1138 | + |
|
| 1139 | + if ($add_to_existing_line_item) { |
|
| 1140 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
| 1141 | + EEM_Line_Item::instance()->delete( |
|
| 1142 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
| 1143 | + ); |
|
| 1144 | + } else { |
|
| 1145 | + $new_tax = null; |
|
| 1146 | + $tax_subtotal->delete_children_line_items(); |
|
| 1147 | + } |
|
| 1148 | + if ($new_tax) { |
|
| 1149 | + $new_tax->set_total($new_tax->total() + $amount); |
|
| 1150 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
| 1151 | + } else { |
|
| 1152 | + // no existing tax item. Create it |
|
| 1153 | + $new_tax = EE_Line_Item::new_instance(array( |
|
| 1154 | + 'TXN_ID' => $total_line_item->TXN_ID(), |
|
| 1155 | + 'LIN_name' => $name ? $name : esc_html__('Tax', 'event_espresso'), |
|
| 1156 | + 'LIN_desc' => $description ? $description : '', |
|
| 1157 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
| 1158 | + 'LIN_total' => $amount, |
|
| 1159 | + 'LIN_parent' => $tax_subtotal->ID(), |
|
| 1160 | + 'LIN_type' => EEM_Line_Item::type_tax, |
|
| 1161 | + 'LIN_code' => $code, |
|
| 1162 | + )); |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + $new_tax = apply_filters( |
|
| 1166 | + 'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal', |
|
| 1167 | + $new_tax, |
|
| 1168 | + $total_line_item |
|
| 1169 | + ); |
|
| 1170 | + $new_tax->save(); |
|
| 1171 | + $tax_subtotal->set_total($new_tax->total()); |
|
| 1172 | + $tax_subtotal->save(); |
|
| 1173 | + $total_line_item->recalculate_total_including_taxes(); |
|
| 1174 | + return $new_tax; |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + |
|
| 1178 | + /** |
|
| 1179 | + * Makes all the line items which are children of $line_item taxable (or not). |
|
| 1180 | + * Does NOT save the line items |
|
| 1181 | + * |
|
| 1182 | + * @param EE_Line_Item $line_item |
|
| 1183 | + * @param boolean $taxable |
|
| 1184 | + * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
| 1185 | + * it will be whitelisted (ie, except from becoming taxable) |
|
| 1186 | + * @throws EE_Error |
|
| 1187 | + */ |
|
| 1188 | + public static function set_line_items_taxable( |
|
| 1189 | + EE_Line_Item $line_item, |
|
| 1190 | + $taxable = true, |
|
| 1191 | + $code_substring_for_whitelist = null |
|
| 1192 | + ) { |
|
| 1193 | + $whitelisted = false; |
|
| 1194 | + if ($code_substring_for_whitelist !== null) { |
|
| 1195 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false; |
|
| 1196 | + } |
|
| 1197 | + if (! $whitelisted && $line_item->is_line_item()) { |
|
| 1198 | + $line_item->set_is_taxable($taxable); |
|
| 1199 | + } |
|
| 1200 | + foreach ($line_item->children() as $child_line_item) { |
|
| 1201 | + EEH_Line_Item::set_line_items_taxable( |
|
| 1202 | + $child_line_item, |
|
| 1203 | + $taxable, |
|
| 1204 | + $code_substring_for_whitelist |
|
| 1205 | + ); |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * Gets all descendants that are event subtotals |
|
| 1212 | + * |
|
| 1213 | + * @uses EEH_Line_Item::get_subtotals_of_object_type() |
|
| 1214 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1215 | + * @return EE_Line_Item[] |
|
| 1216 | + * @throws EE_Error |
|
| 1217 | + */ |
|
| 1218 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) |
|
| 1219 | + { |
|
| 1220 | + return self::get_subtotals_of_object_type($parent_line_item, EEM_Line_Item::OBJ_TYPE_EVENT); |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * Gets all descendants subtotals that match the supplied object type |
|
| 1226 | + * |
|
| 1227 | + * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
| 1228 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1229 | + * @param string $obj_type |
|
| 1230 | + * @return EE_Line_Item[] |
|
| 1231 | + * @throws EE_Error |
|
| 1232 | + */ |
|
| 1233 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') |
|
| 1234 | + { |
|
| 1235 | + return self::_get_descendants_by_type_and_object_type( |
|
| 1236 | + $parent_line_item, |
|
| 1237 | + EEM_Line_Item::type_sub_total, |
|
| 1238 | + $obj_type |
|
| 1239 | + ); |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * Gets all descendants that are tickets |
|
| 1245 | + * |
|
| 1246 | + * @uses EEH_Line_Item::get_line_items_of_object_type() |
|
| 1247 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1248 | + * @return EE_Line_Item[] |
|
| 1249 | + * @throws EE_Error |
|
| 1250 | + */ |
|
| 1251 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) |
|
| 1252 | + { |
|
| 1253 | + return self::get_line_items_of_object_type( |
|
| 1254 | + $parent_line_item, |
|
| 1255 | + EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1256 | + ); |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + |
|
| 1260 | + /** |
|
| 1261 | + * Gets all descendants subtotals that match the supplied object type |
|
| 1262 | + * |
|
| 1263 | + * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
| 1264 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1265 | + * @param string $obj_type |
|
| 1266 | + * @return EE_Line_Item[] |
|
| 1267 | + * @throws EE_Error |
|
| 1268 | + */ |
|
| 1269 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') |
|
| 1270 | + { |
|
| 1271 | + return self::_get_descendants_by_type_and_object_type( |
|
| 1272 | + $parent_line_item, |
|
| 1273 | + EEM_Line_Item::type_line_item, |
|
| 1274 | + $obj_type |
|
| 1275 | + ); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * Gets all the descendants (ie, children or children of children etc) that are of the type 'tax' |
|
| 1281 | + * |
|
| 1282 | + * @uses EEH_Line_Item::get_descendants_of_type() |
|
| 1283 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1284 | + * @return EE_Line_Item[] |
|
| 1285 | + * @throws EE_Error |
|
| 1286 | + */ |
|
| 1287 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) |
|
| 1288 | + { |
|
| 1289 | + return EEH_Line_Item::get_descendants_of_type( |
|
| 1290 | + $parent_line_item, |
|
| 1291 | + EEM_Line_Item::type_tax |
|
| 1292 | + ); |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * Gets all the real items purchased which are children of this item |
|
| 1298 | + * |
|
| 1299 | + * @uses EEH_Line_Item::get_descendants_of_type() |
|
| 1300 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1301 | + * @return EE_Line_Item[] |
|
| 1302 | + * @throws EE_Error |
|
| 1303 | + */ |
|
| 1304 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) |
|
| 1305 | + { |
|
| 1306 | + return EEH_Line_Item::get_descendants_of_type( |
|
| 1307 | + $parent_line_item, |
|
| 1308 | + EEM_Line_Item::type_line_item |
|
| 1309 | + ); |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + |
|
| 1313 | + /** |
|
| 1314 | + * Gets all descendants of supplied line item that match the supplied line item type |
|
| 1315 | + * |
|
| 1316 | + * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
| 1317 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1318 | + * @param string $line_item_type one of the EEM_Line_Item constants |
|
| 1319 | + * @return EE_Line_Item[] |
|
| 1320 | + * @throws EE_Error |
|
| 1321 | + */ |
|
| 1322 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) |
|
| 1323 | + { |
|
| 1324 | + return self::_get_descendants_by_type_and_object_type( |
|
| 1325 | + $parent_line_item, |
|
| 1326 | + $line_item_type, |
|
| 1327 | + null |
|
| 1328 | + ); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type |
|
| 1334 | + * as well |
|
| 1335 | + * |
|
| 1336 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1337 | + * @param string $line_item_type one of the EEM_Line_Item constants |
|
| 1338 | + * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when |
|
| 1339 | + * searching |
|
| 1340 | + * @return EE_Line_Item[] |
|
| 1341 | + * @throws EE_Error |
|
| 1342 | + */ |
|
| 1343 | + protected static function _get_descendants_by_type_and_object_type( |
|
| 1344 | + EE_Line_Item $parent_line_item, |
|
| 1345 | + $line_item_type, |
|
| 1346 | + $obj_type = null |
|
| 1347 | + ) { |
|
| 1348 | + $objects = array(); |
|
| 1349 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1350 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1351 | + if ($child_line_item->type() === $line_item_type |
|
| 1352 | + && ( |
|
| 1353 | + $child_line_item->OBJ_type() === $obj_type || $obj_type === null |
|
| 1354 | + ) |
|
| 1355 | + ) { |
|
| 1356 | + $objects[] = $child_line_item; |
|
| 1357 | + } else { |
|
| 1358 | + // go-through-all-its children looking for more matches |
|
| 1359 | + $objects = array_merge( |
|
| 1360 | + $objects, |
|
| 1361 | + self::_get_descendants_by_type_and_object_type( |
|
| 1362 | + $child_line_item, |
|
| 1363 | + $line_item_type, |
|
| 1364 | + $obj_type |
|
| 1365 | + ) |
|
| 1366 | + ); |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + } |
|
| 1370 | + return $objects; |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + |
|
| 1374 | + /** |
|
| 1375 | + * Gets all descendants subtotals that match the supplied object type |
|
| 1376 | + * |
|
| 1377 | + * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
| 1378 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1379 | + * @param string $OBJ_type object type (like Event) |
|
| 1380 | + * @param array $OBJ_IDs array of OBJ_IDs |
|
| 1381 | + * @return EE_Line_Item[] |
|
| 1382 | + * @throws EE_Error |
|
| 1383 | + */ |
|
| 1384 | + public static function get_line_items_by_object_type_and_IDs( |
|
| 1385 | + EE_Line_Item $parent_line_item, |
|
| 1386 | + $OBJ_type = '', |
|
| 1387 | + $OBJ_IDs = array() |
|
| 1388 | + ) { |
|
| 1389 | + return self::_get_descendants_by_object_type_and_object_ID( |
|
| 1390 | + $parent_line_item, |
|
| 1391 | + $OBJ_type, |
|
| 1392 | + $OBJ_IDs |
|
| 1393 | + ); |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type |
|
| 1399 | + * as well |
|
| 1400 | + * |
|
| 1401 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1402 | + * @param string $OBJ_type object type (like Event) |
|
| 1403 | + * @param array $OBJ_IDs array of OBJ_IDs |
|
| 1404 | + * @return EE_Line_Item[] |
|
| 1405 | + * @throws EE_Error |
|
| 1406 | + */ |
|
| 1407 | + protected static function _get_descendants_by_object_type_and_object_ID( |
|
| 1408 | + EE_Line_Item $parent_line_item, |
|
| 1409 | + $OBJ_type, |
|
| 1410 | + $OBJ_IDs |
|
| 1411 | + ) { |
|
| 1412 | + $objects = array(); |
|
| 1413 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1414 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1415 | + if ($child_line_item->OBJ_type() === $OBJ_type |
|
| 1416 | + && is_array($OBJ_IDs) |
|
| 1417 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
| 1418 | + ) { |
|
| 1419 | + $objects[] = $child_line_item; |
|
| 1420 | + } else { |
|
| 1421 | + // go-through-all-its children looking for more matches |
|
| 1422 | + $objects = array_merge( |
|
| 1423 | + $objects, |
|
| 1424 | + self::_get_descendants_by_object_type_and_object_ID( |
|
| 1425 | + $child_line_item, |
|
| 1426 | + $OBJ_type, |
|
| 1427 | + $OBJ_IDs |
|
| 1428 | + ) |
|
| 1429 | + ); |
|
| 1430 | + } |
|
| 1431 | + } |
|
| 1432 | + } |
|
| 1433 | + return $objects; |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + |
|
| 1437 | + /** |
|
| 1438 | + * Uses a breadth-first-search in order to find the nearest descendant of |
|
| 1439 | + * the specified type and returns it, else NULL |
|
| 1440 | + * |
|
| 1441 | + * @uses EEH_Line_Item::_get_nearest_descendant() |
|
| 1442 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1443 | + * @param string $type like one of the EEM_Line_Item::type_* |
|
| 1444 | + * @return EE_Line_Item |
|
| 1445 | + * @throws EE_Error |
|
| 1446 | + * @throws InvalidArgumentException |
|
| 1447 | + * @throws InvalidDataTypeException |
|
| 1448 | + * @throws InvalidInterfaceException |
|
| 1449 | + * @throws ReflectionException |
|
| 1450 | + */ |
|
| 1451 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) |
|
| 1452 | + { |
|
| 1453 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
| 1454 | + } |
|
| 1455 | + |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * Uses a breadth-first-search in order to find the nearest descendant |
|
| 1459 | + * having the specified LIN_code and returns it, else NULL |
|
| 1460 | + * |
|
| 1461 | + * @uses EEH_Line_Item::_get_nearest_descendant() |
|
| 1462 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1463 | + * @param string $code any value used for LIN_code |
|
| 1464 | + * @return EE_Line_Item |
|
| 1465 | + * @throws EE_Error |
|
| 1466 | + * @throws InvalidArgumentException |
|
| 1467 | + * @throws InvalidDataTypeException |
|
| 1468 | + * @throws InvalidInterfaceException |
|
| 1469 | + * @throws ReflectionException |
|
| 1470 | + */ |
|
| 1471 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) |
|
| 1472 | + { |
|
| 1473 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + |
|
| 1477 | + /** |
|
| 1478 | + * Uses a breadth-first-search in order to find the nearest descendant |
|
| 1479 | + * having the specified LIN_code and returns it, else NULL |
|
| 1480 | + * |
|
| 1481 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
| 1482 | + * @param string $search_field name of EE_Line_Item property |
|
| 1483 | + * @param string $value any value stored in $search_field |
|
| 1484 | + * @return EE_Line_Item |
|
| 1485 | + * @throws EE_Error |
|
| 1486 | + * @throws InvalidArgumentException |
|
| 1487 | + * @throws InvalidDataTypeException |
|
| 1488 | + * @throws InvalidInterfaceException |
|
| 1489 | + * @throws ReflectionException |
|
| 1490 | + */ |
|
| 1491 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) |
|
| 1492 | + { |
|
| 1493 | + foreach ($parent_line_item->children() as $child) { |
|
| 1494 | + if ($child->get($search_field) == $value) { |
|
| 1495 | + return $child; |
|
| 1496 | + } |
|
| 1497 | + } |
|
| 1498 | + foreach ($parent_line_item->children() as $child) { |
|
| 1499 | + $descendant_found = self::_get_nearest_descendant( |
|
| 1500 | + $child, |
|
| 1501 | + $search_field, |
|
| 1502 | + $value |
|
| 1503 | + ); |
|
| 1504 | + if ($descendant_found) { |
|
| 1505 | + return $descendant_found; |
|
| 1506 | + } |
|
| 1507 | + } |
|
| 1508 | + return null; |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + |
|
| 1512 | + /** |
|
| 1513 | + * if passed line item has a TXN ID, uses that to jump directly to the grand total line item for the transaction, |
|
| 1514 | + * else recursively walks up the line item tree until a parent of type total is found, |
|
| 1515 | + * |
|
| 1516 | + * @param EE_Line_Item $line_item |
|
| 1517 | + * @return EE_Line_Item |
|
| 1518 | + * @throws EE_Error |
|
| 1519 | + */ |
|
| 1520 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) |
|
| 1521 | + { |
|
| 1522 | + if ($line_item->TXN_ID()) { |
|
| 1523 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
| 1524 | + if ($total_line_item instanceof EE_Line_Item) { |
|
| 1525 | + return $total_line_item; |
|
| 1526 | + } |
|
| 1527 | + } else { |
|
| 1528 | + $line_item_parent = $line_item->parent(); |
|
| 1529 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
| 1530 | + if ($line_item_parent->is_total()) { |
|
| 1531 | + return $line_item_parent; |
|
| 1532 | + } |
|
| 1533 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
| 1534 | + } |
|
| 1535 | + } |
|
| 1536 | + throw new EE_Error( |
|
| 1537 | + sprintf( |
|
| 1538 | + esc_html__( |
|
| 1539 | + 'A valid grand total for line item %1$d was not found.', |
|
| 1540 | + 'event_espresso' |
|
| 1541 | + ), |
|
| 1542 | + $line_item->ID() |
|
| 1543 | + ) |
|
| 1544 | + ); |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + |
|
| 1548 | + /** |
|
| 1549 | + * Prints out a representation of the line item tree |
|
| 1550 | + * |
|
| 1551 | + * @param EE_Line_Item $line_item |
|
| 1552 | + * @param int $indentation |
|
| 1553 | + * @return void |
|
| 1554 | + * @throws EE_Error |
|
| 1555 | + */ |
|
| 1556 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) |
|
| 1557 | + { |
|
| 1558 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 1559 | + if (! $indentation) { |
|
| 1560 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 1561 | + } |
|
| 1562 | + for ($i = 0; $i < $indentation; $i++) { |
|
| 1563 | + echo '. '; |
|
| 1564 | + } |
|
| 1565 | + $breakdown = ''; |
|
| 1566 | + if ($line_item->is_line_item()) { |
|
| 1567 | + if ($line_item->is_percent()) { |
|
| 1568 | + $breakdown = "{$line_item->percent()}%"; |
|
| 1569 | + } else { |
|
| 1570 | + $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
| 1571 | + } |
|
| 1572 | + } |
|
| 1573 | + echo $line_item->name(); |
|
| 1574 | + echo " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : "; |
|
| 1575 | + echo '$' . (string) $line_item->total(); |
|
| 1576 | + if ($breakdown) { |
|
| 1577 | + echo " ( {$breakdown} )"; |
|
| 1578 | + } |
|
| 1579 | + if ($line_item->is_taxable()) { |
|
| 1580 | + echo ' * taxable'; |
|
| 1581 | + } |
|
| 1582 | + if ($line_item->children()) { |
|
| 1583 | + foreach ($line_item->children() as $child) { |
|
| 1584 | + self::visualize($child, $indentation + 1); |
|
| 1585 | + } |
|
| 1586 | + } |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + /** |
|
| 1591 | + * Calculates the registration's final price, taking into account that they |
|
| 1592 | + * need to not only help pay for their OWN ticket, but also any transaction-wide surcharges and taxes, |
|
| 1593 | + * and receive a portion of any transaction-wide discounts. |
|
| 1594 | + * eg1, if I buy a $1 ticket and brent buys a $9 ticket, and we receive a $5 discount |
|
| 1595 | + * then I'll get 1/10 of that $5 discount, which is $0.50, and brent will get |
|
| 1596 | + * 9/10ths of that $5 discount, which is $4.50. So my final price should be $0.50 |
|
| 1597 | + * and brent's final price should be $5.50. |
|
| 1598 | + * In order to do this, we basically need to traverse the line item tree calculating |
|
| 1599 | + * the running totals (just as if we were recalculating the total), but when we identify |
|
| 1600 | + * regular line items, we need to keep track of their share of the grand total. |
|
| 1601 | + * Also, we need to keep track of the TAXABLE total for each ticket purchase, so |
|
| 1602 | + * we can know how to apply taxes to it. (Note: "taxable total" does not equal the "pretax total" |
|
| 1603 | + * when there are non-taxable items; otherwise they would be the same) |
|
| 1604 | + * |
|
| 1605 | + * @param EE_Line_Item $line_item |
|
| 1606 | + * @param array $billable_ticket_quantities array of EE_Ticket IDs and their corresponding quantity that |
|
| 1607 | + * can be included in price calculations at this moment |
|
| 1608 | + * @return array keys are line items for tickets IDs and values are their share of the running total, |
|
| 1609 | + * plus the key 'total', and 'taxable' which also has keys of all |
|
| 1610 | + * the ticket IDs. |
|
| 1611 | + * Eg array( |
|
| 1612 | + * 12 => 4.3 |
|
| 1613 | + * 23 => 8.0 |
|
| 1614 | + * 'total' => 16.6, |
|
| 1615 | + * 'taxable' => array( |
|
| 1616 | + * 12 => 10, |
|
| 1617 | + * 23 => 4 |
|
| 1618 | + * ). |
|
| 1619 | + * So to find which registrations have which final price, we need |
|
| 1620 | + * to find which line item is theirs, which can be done with |
|
| 1621 | + * `EEM_Line_Item::instance()->get_line_item_for_registration( |
|
| 1622 | + * $registration );` |
|
| 1623 | + * @throws EE_Error |
|
| 1624 | + * @throws InvalidArgumentException |
|
| 1625 | + * @throws InvalidDataTypeException |
|
| 1626 | + * @throws InvalidInterfaceException |
|
| 1627 | + * @throws ReflectionException |
|
| 1628 | + */ |
|
| 1629 | + public static function calculate_reg_final_prices_per_line_item( |
|
| 1630 | + EE_Line_Item $line_item, |
|
| 1631 | + $billable_ticket_quantities = array() |
|
| 1632 | + ) { |
|
| 1633 | + $running_totals = [ |
|
| 1634 | + 'total' => 0, |
|
| 1635 | + 'taxable' => ['total' => 0] |
|
| 1636 | + ]; |
|
| 1637 | + foreach ($line_item->children() as $child_line_item) { |
|
| 1638 | + switch ($child_line_item->type()) { |
|
| 1639 | + case EEM_Line_Item::type_sub_total: |
|
| 1640 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
| 1641 | + $child_line_item, |
|
| 1642 | + $billable_ticket_quantities |
|
| 1643 | + ); |
|
| 1644 | + // combine arrays but preserve numeric keys |
|
| 1645 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
| 1646 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
| 1647 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
| 1648 | + break; |
|
| 1649 | + |
|
| 1650 | + case EEM_Line_Item::type_tax_sub_total: |
|
| 1651 | + // find how much the taxes percentage is |
|
| 1652 | + if ($child_line_item->percent() !== 0) { |
|
| 1653 | + $tax_percent_decimal = $child_line_item->percent() / 100; |
|
| 1654 | + } else { |
|
| 1655 | + $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
|
| 1656 | + } |
|
| 1657 | + // and apply to all the taxable totals, and add to the pretax totals |
|
| 1658 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1659 | + // "total" and "taxable" array key is an exception |
|
| 1660 | + if ($line_item_id === 'taxable') { |
|
| 1661 | + continue; |
|
| 1662 | + } |
|
| 1663 | + $taxable_total = $running_totals['taxable'][ $line_item_id ]; |
|
| 1664 | + $running_totals[ $line_item_id ] += ($taxable_total * $tax_percent_decimal); |
|
| 1665 | + } |
|
| 1666 | + break; |
|
| 1667 | + |
|
| 1668 | + case EEM_Line_Item::type_line_item: |
|
| 1669 | + // ticket line items or ???? |
|
| 1670 | + if ($child_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
| 1671 | + // kk it's a ticket |
|
| 1672 | + if (isset($running_totals[ $child_line_item->ID() ])) { |
|
| 1673 | + // huh? that shouldn't happen. |
|
| 1674 | + $running_totals['total'] += $child_line_item->total(); |
|
| 1675 | + } else { |
|
| 1676 | + // its not in our running totals yet. great. |
|
| 1677 | + if ($child_line_item->is_taxable()) { |
|
| 1678 | + $taxable_amount = $child_line_item->unit_price(); |
|
| 1679 | + } else { |
|
| 1680 | + $taxable_amount = 0; |
|
| 1681 | + } |
|
| 1682 | + // are we only calculating totals for some tickets? |
|
| 1683 | + if (isset($billable_ticket_quantities[ $child_line_item->OBJ_ID() ])) { |
|
| 1684 | + $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
| 1685 | + $running_totals[ $child_line_item->ID() ] = $quantity |
|
| 1686 | + ? $child_line_item->unit_price() |
|
| 1687 | + : 0; |
|
| 1688 | + $running_totals['taxable'][ $child_line_item->ID() ] = $quantity |
|
| 1689 | + ? $taxable_amount |
|
| 1690 | + : 0; |
|
| 1691 | + } else { |
|
| 1692 | + $quantity = $child_line_item->quantity(); |
|
| 1693 | + $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
| 1694 | + $running_totals['taxable'][ $child_line_item->ID() ] = $taxable_amount; |
|
| 1695 | + } |
|
| 1696 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
| 1697 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
| 1698 | + } |
|
| 1699 | + } else { |
|
| 1700 | + // it's some other type of item added to the cart |
|
| 1701 | + // it should affect the running totals |
|
| 1702 | + // basically we want to convert it into a PERCENT modifier. Because |
|
| 1703 | + // more clearly affect all registration's final price equally |
|
| 1704 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
| 1705 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
| 1706 | + : 1; |
|
| 1707 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1708 | + // the "taxable" array key is an exception |
|
| 1709 | + if ($line_item_id === 'taxable') { |
|
| 1710 | + continue; |
|
| 1711 | + } |
|
| 1712 | + // update the running totals |
|
| 1713 | + // yes this actually even works for the running grand total! |
|
| 1714 | + $running_totals[ $line_item_id ] = |
|
| 1715 | + $line_items_percent_of_running_total * $this_running_total; |
|
| 1716 | + |
|
| 1717 | + if ($child_line_item->is_taxable()) { |
|
| 1718 | + $running_totals['taxable'][ $line_item_id ] = |
|
| 1719 | + $line_items_percent_of_running_total * $running_totals['taxable'][ $line_item_id ]; |
|
| 1720 | + } |
|
| 1721 | + } |
|
| 1722 | + } |
|
| 1723 | + break; |
|
| 1724 | + } |
|
| 1725 | + } |
|
| 1726 | + return $running_totals; |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * @param EE_Line_Item $total_line_item |
|
| 1732 | + * @param EE_Line_Item $ticket_line_item |
|
| 1733 | + * @return float | null |
|
| 1734 | + * @throws EE_Error |
|
| 1735 | + * @throws InvalidArgumentException |
|
| 1736 | + * @throws InvalidDataTypeException |
|
| 1737 | + * @throws InvalidInterfaceException |
|
| 1738 | + * @throws OutOfRangeException |
|
| 1739 | + * @throws ReflectionException |
|
| 1740 | + */ |
|
| 1741 | + public static function calculate_final_price_for_ticket_line_item( |
|
| 1742 | + EE_Line_Item $total_line_item, |
|
| 1743 | + EE_Line_Item $ticket_line_item |
|
| 1744 | + ) { |
|
| 1745 | + static $final_prices_per_ticket_line_item = array(); |
|
| 1746 | + if (empty($final_prices_per_ticket_line_item)) { |
|
| 1747 | + $final_prices_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
| 1748 | + $total_line_item |
|
| 1749 | + ); |
|
| 1750 | + } |
|
| 1751 | + // ok now find this new registration's final price |
|
| 1752 | + if (isset($final_prices_per_ticket_line_item[ $ticket_line_item->ID() ])) { |
|
| 1753 | + return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
| 1754 | + } |
|
| 1755 | + $message = sprintf( |
|
| 1756 | + esc_html__( |
|
| 1757 | + 'The final price for the ticket line item (ID:%1$d) could not be calculated.', |
|
| 1758 | + 'event_espresso' |
|
| 1759 | + ), |
|
| 1760 | + $ticket_line_item->ID() |
|
| 1761 | + ); |
|
| 1762 | + if (WP_DEBUG) { |
|
| 1763 | + $message .= '<br>' . print_r($final_prices_per_ticket_line_item, true); |
|
| 1764 | + throw new OutOfRangeException($message); |
|
| 1765 | + } |
|
| 1766 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
| 1767 | + return null; |
|
| 1768 | + } |
|
| 1769 | + |
|
| 1770 | + |
|
| 1771 | + /** |
|
| 1772 | + * Creates a duplicate of the line item tree, except only includes billable items |
|
| 1773 | + * and the portion of line items attributed to billable things |
|
| 1774 | + * |
|
| 1775 | + * @param EE_Line_Item $line_item |
|
| 1776 | + * @param EE_Registration[] $registrations |
|
| 1777 | + * @return EE_Line_Item |
|
| 1778 | + * @throws EE_Error |
|
| 1779 | + * @throws InvalidArgumentException |
|
| 1780 | + * @throws InvalidDataTypeException |
|
| 1781 | + * @throws InvalidInterfaceException |
|
| 1782 | + * @throws ReflectionException |
|
| 1783 | + */ |
|
| 1784 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) |
|
| 1785 | + { |
|
| 1786 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
| 1787 | + foreach ($line_item->children() as $child_li) { |
|
| 1788 | + $copy_li->add_child_line_item( |
|
| 1789 | + EEH_Line_Item::billable_line_item_tree($child_li, $registrations) |
|
| 1790 | + ); |
|
| 1791 | + } |
|
| 1792 | + // if this is the grand total line item, make sure the totals all add up |
|
| 1793 | + // (we could have duplicated this logic AS we copied the line items, but |
|
| 1794 | + // it seems DRYer this way) |
|
| 1795 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
| 1796 | + $copy_li->recalculate_total_including_taxes(); |
|
| 1797 | + } |
|
| 1798 | + return $copy_li; |
|
| 1799 | + } |
|
| 1800 | + |
|
| 1801 | + |
|
| 1802 | + /** |
|
| 1803 | + * Creates a new, unsaved line item from $line_item that factors in the |
|
| 1804 | + * number of billable registrations on $registrations. |
|
| 1805 | + * |
|
| 1806 | + * @param EE_Line_Item $line_item |
|
| 1807 | + * @param EE_Registration[] $registrations |
|
| 1808 | + * @return EE_Line_Item |
|
| 1809 | + * @throws EE_Error |
|
| 1810 | + * @throws InvalidArgumentException |
|
| 1811 | + * @throws InvalidDataTypeException |
|
| 1812 | + * @throws InvalidInterfaceException |
|
| 1813 | + * @throws ReflectionException |
|
| 1814 | + */ |
|
| 1815 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) |
|
| 1816 | + { |
|
| 1817 | + $new_li_fields = $line_item->model_field_array(); |
|
| 1818 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1819 | + $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1820 | + ) { |
|
| 1821 | + $count = 0; |
|
| 1822 | + foreach ($registrations as $registration) { |
|
| 1823 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
| 1824 | + in_array( |
|
| 1825 | + $registration->status_ID(), |
|
| 1826 | + EEM_Registration::reg_statuses_that_allow_payment(), |
|
| 1827 | + true |
|
| 1828 | + ) |
|
| 1829 | + ) { |
|
| 1830 | + $count++; |
|
| 1831 | + } |
|
| 1832 | + } |
|
| 1833 | + $new_li_fields['LIN_quantity'] = $count; |
|
| 1834 | + } |
|
| 1835 | + // don't set the total. We'll leave that up to the code that calculates it |
|
| 1836 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
| 1837 | + return EE_Line_Item::new_instance($new_li_fields); |
|
| 1838 | + } |
|
| 1839 | + |
|
| 1840 | + |
|
| 1841 | + /** |
|
| 1842 | + * Returns a modified line item tree where all the subtotals which have a total of 0 |
|
| 1843 | + * are removed, and line items with a quantity of 0 |
|
| 1844 | + * |
|
| 1845 | + * @param EE_Line_Item $line_item |null |
|
| 1846 | + * @return EE_Line_Item|null |
|
| 1847 | + * @throws EE_Error |
|
| 1848 | + * @throws InvalidArgumentException |
|
| 1849 | + * @throws InvalidDataTypeException |
|
| 1850 | + * @throws InvalidInterfaceException |
|
| 1851 | + * @throws ReflectionException |
|
| 1852 | + */ |
|
| 1853 | + public static function non_empty_line_items(EE_Line_Item $line_item) |
|
| 1854 | + { |
|
| 1855 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
| 1856 | + if ($copied_li === null) { |
|
| 1857 | + return null; |
|
| 1858 | + } |
|
| 1859 | + // if this is an event subtotal, we want to only include it if it |
|
| 1860 | + // has a non-zero total and at least one ticket line item child |
|
| 1861 | + $ticket_children = 0; |
|
| 1862 | + foreach ($line_item->children() as $child_li) { |
|
| 1863 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
| 1864 | + if ($child_li_copy !== null) { |
|
| 1865 | + $copied_li->add_child_line_item($child_li_copy); |
|
| 1866 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
| 1867 | + $child_li_copy->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1868 | + ) { |
|
| 1869 | + $ticket_children++; |
|
| 1870 | + } |
|
| 1871 | + } |
|
| 1872 | + } |
|
| 1873 | + // if this is an event subtotal with NO ticket children |
|
| 1874 | + // we basically want to ignore it |
|
| 1875 | + if ($ticket_children === 0 |
|
| 1876 | + && $line_item->type() === EEM_Line_Item::type_sub_total |
|
| 1877 | + && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
| 1878 | + && $line_item->total() === 0 |
|
| 1879 | + ) { |
|
| 1880 | + return null; |
|
| 1881 | + } |
|
| 1882 | + return $copied_li; |
|
| 1883 | + } |
|
| 1884 | + |
|
| 1885 | + |
|
| 1886 | + /** |
|
| 1887 | + * Creates a new, unsaved line item, but if it's a ticket line item |
|
| 1888 | + * with a total of 0, or a subtotal of 0, returns null instead |
|
| 1889 | + * |
|
| 1890 | + * @param EE_Line_Item $line_item |
|
| 1891 | + * @return EE_Line_Item |
|
| 1892 | + * @throws EE_Error |
|
| 1893 | + * @throws InvalidArgumentException |
|
| 1894 | + * @throws InvalidDataTypeException |
|
| 1895 | + * @throws InvalidInterfaceException |
|
| 1896 | + * @throws ReflectionException |
|
| 1897 | + */ |
|
| 1898 | + public static function non_empty_line_item(EE_Line_Item $line_item) |
|
| 1899 | + { |
|
| 1900 | + if ($line_item->type() === EEM_Line_Item::type_line_item |
|
| 1901 | + && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1902 | + && $line_item->quantity() === 0 |
|
| 1903 | + ) { |
|
| 1904 | + return null; |
|
| 1905 | + } |
|
| 1906 | + $new_li_fields = $line_item->model_field_array(); |
|
| 1907 | + // don't set the total. We'll leave that up to the code that calculates it |
|
| 1908 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
| 1909 | + return EE_Line_Item::new_instance($new_li_fields); |
|
| 1910 | + } |
|
| 1911 | + |
|
| 1912 | + |
|
| 1913 | + /** |
|
| 1914 | + * Cycles through all of the ticket line items for the supplied total line item |
|
| 1915 | + * and ensures that the line item's "is_taxable" field matches that of its corresponding ticket |
|
| 1916 | + * |
|
| 1917 | + * @param EE_Line_Item $total_line_item |
|
| 1918 | + * @since 4.9.79.p |
|
| 1919 | + * @throws EE_Error |
|
| 1920 | + * @throws InvalidArgumentException |
|
| 1921 | + * @throws InvalidDataTypeException |
|
| 1922 | + * @throws InvalidInterfaceException |
|
| 1923 | + * @throws ReflectionException |
|
| 1924 | + */ |
|
| 1925 | + public static function resetIsTaxableForTickets(EE_Line_Item $total_line_item) |
|
| 1926 | + { |
|
| 1927 | + $ticket_line_items = self::get_ticket_line_items($total_line_item); |
|
| 1928 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 1929 | + if ($ticket_line_item instanceof EE_Line_Item |
|
| 1930 | + && $ticket_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
| 1931 | + ) { |
|
| 1932 | + $ticket = $ticket_line_item->ticket(); |
|
| 1933 | + if ($ticket instanceof EE_Ticket && $ticket->taxable() !== $ticket_line_item->is_taxable()) { |
|
| 1934 | + $ticket_line_item->set_is_taxable($ticket->taxable()); |
|
| 1935 | + $ticket_line_item->save(); |
|
| 1936 | + } |
|
| 1937 | + } |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + |
|
| 1942 | + |
|
| 1943 | + /**************************************** @DEPRECATED METHODS *************************************** */ |
|
| 1944 | + /** |
|
| 1945 | + * @deprecated |
|
| 1946 | + * @param EE_Line_Item $total_line_item |
|
| 1947 | + * @return EE_Line_Item |
|
| 1948 | + * @throws EE_Error |
|
| 1949 | + * @throws InvalidArgumentException |
|
| 1950 | + * @throws InvalidDataTypeException |
|
| 1951 | + * @throws InvalidInterfaceException |
|
| 1952 | + * @throws ReflectionException |
|
| 1953 | + */ |
|
| 1954 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) |
|
| 1955 | + { |
|
| 1956 | + EE_Error::doing_it_wrong( |
|
| 1957 | + 'EEH_Line_Item::get_items_subtotal()', |
|
| 1958 | + sprintf( |
|
| 1959 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 1960 | + 'EEH_Line_Item::get_pre_tax_subtotal()' |
|
| 1961 | + ), |
|
| 1962 | + '4.6.0' |
|
| 1963 | + ); |
|
| 1964 | + return self::get_pre_tax_subtotal($total_line_item); |
|
| 1965 | + } |
|
| 1966 | + |
|
| 1967 | + |
|
| 1968 | + /** |
|
| 1969 | + * @deprecated |
|
| 1970 | + * @param EE_Transaction $transaction |
|
| 1971 | + * @return EE_Line_Item |
|
| 1972 | + * @throws EE_Error |
|
| 1973 | + * @throws InvalidArgumentException |
|
| 1974 | + * @throws InvalidDataTypeException |
|
| 1975 | + * @throws InvalidInterfaceException |
|
| 1976 | + * @throws ReflectionException |
|
| 1977 | + */ |
|
| 1978 | + public static function create_default_total_line_item($transaction = null) |
|
| 1979 | + { |
|
| 1980 | + EE_Error::doing_it_wrong( |
|
| 1981 | + 'EEH_Line_Item::create_default_total_line_item()', |
|
| 1982 | + sprintf( |
|
| 1983 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 1984 | + 'EEH_Line_Item::create_total_line_item()' |
|
| 1985 | + ), |
|
| 1986 | + '4.6.0' |
|
| 1987 | + ); |
|
| 1988 | + return self::create_total_line_item($transaction); |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + |
|
| 1992 | + /** |
|
| 1993 | + * @deprecated |
|
| 1994 | + * @param EE_Line_Item $total_line_item |
|
| 1995 | + * @param EE_Transaction $transaction |
|
| 1996 | + * @return EE_Line_Item |
|
| 1997 | + * @throws EE_Error |
|
| 1998 | + * @throws InvalidArgumentException |
|
| 1999 | + * @throws InvalidDataTypeException |
|
| 2000 | + * @throws InvalidInterfaceException |
|
| 2001 | + * @throws ReflectionException |
|
| 2002 | + */ |
|
| 2003 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 2004 | + { |
|
| 2005 | + EE_Error::doing_it_wrong( |
|
| 2006 | + 'EEH_Line_Item::create_default_tickets_subtotal()', |
|
| 2007 | + sprintf( |
|
| 2008 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 2009 | + 'EEH_Line_Item::create_pre_tax_subtotal()' |
|
| 2010 | + ), |
|
| 2011 | + '4.6.0' |
|
| 2012 | + ); |
|
| 2013 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + |
|
| 2017 | + /** |
|
| 2018 | + * @deprecated |
|
| 2019 | + * @param EE_Line_Item $total_line_item |
|
| 2020 | + * @param EE_Transaction $transaction |
|
| 2021 | + * @return EE_Line_Item |
|
| 2022 | + * @throws EE_Error |
|
| 2023 | + * @throws InvalidArgumentException |
|
| 2024 | + * @throws InvalidDataTypeException |
|
| 2025 | + * @throws InvalidInterfaceException |
|
| 2026 | + * @throws ReflectionException |
|
| 2027 | + */ |
|
| 2028 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 2029 | + { |
|
| 2030 | + EE_Error::doing_it_wrong( |
|
| 2031 | + 'EEH_Line_Item::create_default_taxes_subtotal()', |
|
| 2032 | + sprintf( |
|
| 2033 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 2034 | + 'EEH_Line_Item::create_taxes_subtotal()' |
|
| 2035 | + ), |
|
| 2036 | + '4.6.0' |
|
| 2037 | + ); |
|
| 2038 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 2039 | + } |
|
| 2040 | + |
|
| 2041 | + |
|
| 2042 | + /** |
|
| 2043 | + * @deprecated |
|
| 2044 | + * @param EE_Line_Item $total_line_item |
|
| 2045 | + * @param EE_Transaction $transaction |
|
| 2046 | + * @return EE_Line_Item |
|
| 2047 | + * @throws EE_Error |
|
| 2048 | + * @throws InvalidArgumentException |
|
| 2049 | + * @throws InvalidDataTypeException |
|
| 2050 | + * @throws InvalidInterfaceException |
|
| 2051 | + * @throws ReflectionException |
|
| 2052 | + */ |
|
| 2053 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
| 2054 | + { |
|
| 2055 | + EE_Error::doing_it_wrong( |
|
| 2056 | + 'EEH_Line_Item::create_default_event_subtotal()', |
|
| 2057 | + sprintf( |
|
| 2058 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
| 2059 | + 'EEH_Line_Item::create_event_subtotal()' |
|
| 2060 | + ), |
|
| 2061 | + '4.6.0' |
|
| 2062 | + ); |
|
| 2063 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
| 2064 | + } |
|
| 2065 | 2065 | } |
@@ -13,2562 +13,2562 @@ |
||
| 13 | 13 | class Transactions_Admin_Page extends EE_Admin_Page |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var EE_Transaction |
|
| 18 | - */ |
|
| 19 | - private $_transaction; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var EE_Session |
|
| 23 | - */ |
|
| 24 | - private $_session; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var array $_txn_status |
|
| 28 | - */ |
|
| 29 | - private static $_txn_status; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array $_pay_status |
|
| 33 | - */ |
|
| 34 | - private static $_pay_status; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 38 | - */ |
|
| 39 | - protected $_existing_reg_payment_REG_IDs; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * _init_page_props |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - protected function _init_page_props() |
|
| 48 | - { |
|
| 49 | - $this->page_slug = TXN_PG_SLUG; |
|
| 50 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 51 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 52 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * _ajax_hooks |
|
| 58 | - * |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - protected function _ajax_hooks() |
|
| 62 | - { |
|
| 63 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 64 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 65 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * _define_page_props |
|
| 71 | - * |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - protected function _define_page_props() |
|
| 75 | - { |
|
| 76 | - $this->_admin_page_title = $this->page_label; |
|
| 77 | - $this->_labels = array( |
|
| 78 | - 'buttons' => array( |
|
| 79 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 80 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 81 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 82 | - ), |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * grab url requests and route them |
|
| 89 | - * |
|
| 90 | - * @access private |
|
| 91 | - * @return void |
|
| 92 | - * @throws EE_Error |
|
| 93 | - * @throws InvalidArgumentException |
|
| 94 | - * @throws InvalidDataTypeException |
|
| 95 | - * @throws InvalidInterfaceException |
|
| 96 | - */ |
|
| 97 | - public function _set_page_routes() |
|
| 98 | - { |
|
| 99 | - |
|
| 100 | - $this->_set_transaction_status_array(); |
|
| 101 | - |
|
| 102 | - $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 103 | - && ! is_array($this->_req_data['TXN_ID']) |
|
| 104 | - ? $this->_req_data['TXN_ID'] |
|
| 105 | - : 0; |
|
| 106 | - |
|
| 107 | - $this->_page_routes = array( |
|
| 108 | - |
|
| 109 | - 'default' => array( |
|
| 110 | - 'func' => '_transactions_overview_list_table', |
|
| 111 | - 'capability' => 'ee_read_transactions', |
|
| 112 | - ), |
|
| 113 | - |
|
| 114 | - 'view_transaction' => array( |
|
| 115 | - 'func' => '_transaction_details', |
|
| 116 | - 'capability' => 'ee_read_transaction', |
|
| 117 | - 'obj_id' => $txn_id, |
|
| 118 | - ), |
|
| 119 | - |
|
| 120 | - 'send_payment_reminder' => array( |
|
| 121 | - 'func' => '_send_payment_reminder', |
|
| 122 | - 'noheader' => true, |
|
| 123 | - 'capability' => 'ee_send_message', |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'espresso_apply_payment' => array( |
|
| 127 | - 'func' => 'apply_payments_or_refunds', |
|
| 128 | - 'noheader' => true, |
|
| 129 | - 'capability' => 'ee_edit_payments', |
|
| 130 | - ), |
|
| 131 | - |
|
| 132 | - 'espresso_apply_refund' => array( |
|
| 133 | - 'func' => 'apply_payments_or_refunds', |
|
| 134 | - 'noheader' => true, |
|
| 135 | - 'capability' => 'ee_edit_payments', |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'espresso_delete_payment' => array( |
|
| 139 | - 'func' => 'delete_payment', |
|
| 140 | - 'noheader' => true, |
|
| 141 | - 'capability' => 'ee_delete_payments', |
|
| 142 | - ), |
|
| 143 | - |
|
| 144 | - 'espresso_recalculate_line_items' => array( |
|
| 145 | - 'func' => 'recalculateLineItems', |
|
| 146 | - 'noheader' => true, |
|
| 147 | - 'capability' => 'ee_edit_payments', |
|
| 148 | - ), |
|
| 149 | - |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - protected function _set_page_config() |
|
| 155 | - { |
|
| 156 | - $this->_page_config = array( |
|
| 157 | - 'default' => array( |
|
| 158 | - 'nav' => array( |
|
| 159 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 160 | - 'order' => 10, |
|
| 161 | - ), |
|
| 162 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 163 | - 'help_tabs' => array( |
|
| 164 | - 'transactions_overview_help_tab' => array( |
|
| 165 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 166 | - 'filename' => 'transactions_overview', |
|
| 167 | - ), |
|
| 168 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 169 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 170 | - 'filename' => 'transactions_overview_table_column_headings', |
|
| 171 | - ), |
|
| 172 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 173 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 174 | - 'filename' => 'transactions_overview_views_filters_search', |
|
| 175 | - ), |
|
| 176 | - ), |
|
| 177 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 178 | - /** |
|
| 179 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 180 | - * may change in a later iteration so want to keep the code for then. |
|
| 181 | - */ |
|
| 182 | - // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 183 | - 'require_nonce' => false, |
|
| 184 | - ), |
|
| 185 | - 'view_transaction' => array( |
|
| 186 | - 'nav' => array( |
|
| 187 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 188 | - 'order' => 5, |
|
| 189 | - 'url' => isset($this->_req_data['TXN_ID']) |
|
| 190 | - ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 191 | - : $this->_admin_base_url, |
|
| 192 | - 'persistent' => false, |
|
| 193 | - ), |
|
| 194 | - 'help_tabs' => array( |
|
| 195 | - 'transactions_view_transaction_help_tab' => array( |
|
| 196 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 197 | - 'filename' => 'transactions_view_transaction', |
|
| 198 | - ), |
|
| 199 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 200 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 201 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 202 | - ), |
|
| 203 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 204 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 205 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 206 | - ), |
|
| 207 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 208 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 209 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 210 | - ), |
|
| 211 | - ), |
|
| 212 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 213 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 214 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 215 | - |
|
| 216 | - 'require_nonce' => false, |
|
| 217 | - ), |
|
| 218 | - ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * The below methods aren't used by this class currently |
|
| 224 | - */ |
|
| 225 | - protected function _add_screen_options() |
|
| 226 | - { |
|
| 227 | - // noop |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - protected function _add_feature_pointers() |
|
| 232 | - { |
|
| 233 | - // noop |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - public function admin_init() |
|
| 238 | - { |
|
| 239 | - // IF a registration was JUST added via the admin... |
|
| 240 | - if (isset( |
|
| 241 | - $this->_req_data['redirect_from'], |
|
| 242 | - $this->_req_data['EVT_ID'], |
|
| 243 | - $this->_req_data['event_name'] |
|
| 244 | - )) { |
|
| 245 | - // then set a cookie so that we can block any attempts to use |
|
| 246 | - // the back button as a way to enter another registration. |
|
| 247 | - setcookie( |
|
| 248 | - 'ee_registration_added', |
|
| 249 | - $this->_req_data['EVT_ID'], |
|
| 250 | - time() + WEEK_IN_SECONDS, |
|
| 251 | - '/' |
|
| 252 | - ); |
|
| 253 | - // and update the global |
|
| 254 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 255 | - } |
|
| 256 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 257 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 258 | - 'event_espresso' |
|
| 259 | - ); |
|
| 260 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 261 | - 'An error occurred! Please refresh the page and try again.', |
|
| 262 | - 'event_espresso' |
|
| 263 | - ); |
|
| 264 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 268 | - 'This transaction has been overpaid ! Payments Total', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - public function admin_notices() |
|
| 275 | - { |
|
| 276 | - // noop |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - public function admin_footer_scripts() |
|
| 281 | - { |
|
| 282 | - // noop |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * _set_transaction_status_array |
|
| 288 | - * sets list of transaction statuses |
|
| 289 | - * |
|
| 290 | - * @access private |
|
| 291 | - * @return void |
|
| 292 | - * @throws EE_Error |
|
| 293 | - * @throws InvalidArgumentException |
|
| 294 | - * @throws InvalidDataTypeException |
|
| 295 | - * @throws InvalidInterfaceException |
|
| 296 | - */ |
|
| 297 | - private function _set_transaction_status_array() |
|
| 298 | - { |
|
| 299 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * get_transaction_status_array |
|
| 305 | - * return the transaction status array for wp_list_table |
|
| 306 | - * |
|
| 307 | - * @access public |
|
| 308 | - * @return array |
|
| 309 | - */ |
|
| 310 | - public function get_transaction_status_array() |
|
| 311 | - { |
|
| 312 | - return self::$_txn_status; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * get list of payment statuses |
|
| 318 | - * |
|
| 319 | - * @access private |
|
| 320 | - * @return void |
|
| 321 | - * @throws EE_Error |
|
| 322 | - * @throws InvalidArgumentException |
|
| 323 | - * @throws InvalidDataTypeException |
|
| 324 | - * @throws InvalidInterfaceException |
|
| 325 | - */ |
|
| 326 | - private function _get_payment_status_array() |
|
| 327 | - { |
|
| 328 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 329 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * _add_screen_options_default |
|
| 335 | - * |
|
| 336 | - * @access protected |
|
| 337 | - * @return void |
|
| 338 | - * @throws InvalidArgumentException |
|
| 339 | - * @throws InvalidDataTypeException |
|
| 340 | - * @throws InvalidInterfaceException |
|
| 341 | - */ |
|
| 342 | - protected function _add_screen_options_default() |
|
| 343 | - { |
|
| 344 | - $this->_per_page_screen_option(); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * load_scripts_styles |
|
| 350 | - * |
|
| 351 | - * @access public |
|
| 352 | - * @return void |
|
| 353 | - */ |
|
| 354 | - public function load_scripts_styles() |
|
| 355 | - { |
|
| 356 | - // enqueue style |
|
| 357 | - wp_register_style( |
|
| 358 | - 'espresso_txn', |
|
| 359 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 360 | - array(), |
|
| 361 | - EVENT_ESPRESSO_VERSION |
|
| 362 | - ); |
|
| 363 | - wp_enqueue_style('espresso_txn'); |
|
| 364 | - // scripts |
|
| 365 | - wp_register_script( |
|
| 366 | - 'espresso_txn', |
|
| 367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 368 | - array( |
|
| 369 | - 'ee_admin_js', |
|
| 370 | - 'ee-datepicker', |
|
| 371 | - 'jquery-ui-datepicker', |
|
| 372 | - 'jquery-ui-draggable', |
|
| 373 | - 'ee-dialog', |
|
| 374 | - 'ee-accounting', |
|
| 375 | - 'ee-serialize-full-array', |
|
| 376 | - ), |
|
| 377 | - EVENT_ESPRESSO_VERSION, |
|
| 378 | - true |
|
| 379 | - ); |
|
| 380 | - wp_enqueue_script('espresso_txn'); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * load_scripts_styles_view_transaction |
|
| 386 | - * |
|
| 387 | - * @access public |
|
| 388 | - * @return void |
|
| 389 | - */ |
|
| 390 | - public function load_scripts_styles_view_transaction() |
|
| 391 | - { |
|
| 392 | - // styles |
|
| 393 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * load_scripts_styles_default |
|
| 399 | - * |
|
| 400 | - * @access public |
|
| 401 | - * @return void |
|
| 402 | - */ |
|
| 403 | - public function load_scripts_styles_default() |
|
| 404 | - { |
|
| 405 | - // styles |
|
| 406 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * _set_list_table_views_default |
|
| 412 | - * |
|
| 413 | - * @access protected |
|
| 414 | - * @return void |
|
| 415 | - */ |
|
| 416 | - protected function _set_list_table_views_default() |
|
| 417 | - { |
|
| 418 | - $this->_views = array( |
|
| 419 | - 'all' => array( |
|
| 420 | - 'slug' => 'all', |
|
| 421 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 422 | - 'count' => 0, |
|
| 423 | - ), |
|
| 424 | - 'abandoned' => array( |
|
| 425 | - 'slug' => 'abandoned', |
|
| 426 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 427 | - 'count' => 0, |
|
| 428 | - ), |
|
| 429 | - 'incomplete' => array( |
|
| 430 | - 'slug' => 'incomplete', |
|
| 431 | - 'label' => esc_html__('Incomplete Transactions', 'event_espresso'), |
|
| 432 | - 'count' => 0, |
|
| 433 | - ), |
|
| 434 | - ); |
|
| 435 | - if (/** |
|
| 436 | - * Filters whether a link to the "Failed Transactions" list table |
|
| 437 | - * appears on the Transactions Admin Page list table. |
|
| 438 | - * List display can be turned back on via the following: |
|
| 439 | - * add_filter( |
|
| 440 | - * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 441 | - * '__return_true' |
|
| 442 | - * ); |
|
| 443 | - * |
|
| 444 | - * @since 4.9.70.p |
|
| 445 | - * @param boolean $display_failed_txns_list |
|
| 446 | - * @param Transactions_Admin_Page $this |
|
| 447 | - */ |
|
| 448 | - apply_filters( |
|
| 449 | - 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 450 | - false, |
|
| 451 | - $this |
|
| 452 | - ) |
|
| 453 | - ) { |
|
| 454 | - $this->_views['failed'] = array( |
|
| 455 | - 'slug' => 'failed', |
|
| 456 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 457 | - 'count' => 0, |
|
| 458 | - ); |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * _set_transaction_object |
|
| 465 | - * This sets the _transaction property for the transaction details screen |
|
| 466 | - * |
|
| 467 | - * @access private |
|
| 468 | - * @return void |
|
| 469 | - * @throws EE_Error |
|
| 470 | - * @throws InvalidArgumentException |
|
| 471 | - * @throws RuntimeException |
|
| 472 | - * @throws InvalidDataTypeException |
|
| 473 | - * @throws InvalidInterfaceException |
|
| 474 | - * @throws ReflectionException |
|
| 475 | - */ |
|
| 476 | - private function _set_transaction_object() |
|
| 477 | - { |
|
| 478 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 479 | - return; |
|
| 480 | - } //get out we've already set the object |
|
| 481 | - |
|
| 482 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 483 | - ? absint($this->_req_data['TXN_ID']) |
|
| 484 | - : false; |
|
| 485 | - |
|
| 486 | - // get transaction object |
|
| 487 | - $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 488 | - $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 489 | - ? $this->_transaction->session_data() |
|
| 490 | - : null; |
|
| 491 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 492 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 496 | - $error_msg = sprintf( |
|
| 497 | - esc_html__( |
|
| 498 | - 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 499 | - 'event_espresso' |
|
| 500 | - ), |
|
| 501 | - $TXN_ID |
|
| 502 | - ); |
|
| 503 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * _transaction_legend_items |
|
| 510 | - * |
|
| 511 | - * @access protected |
|
| 512 | - * @return array |
|
| 513 | - * @throws EE_Error |
|
| 514 | - * @throws InvalidArgumentException |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - * @throws InvalidDataTypeException |
|
| 517 | - * @throws InvalidInterfaceException |
|
| 518 | - */ |
|
| 519 | - protected function _transaction_legend_items() |
|
| 520 | - { |
|
| 521 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 522 | - $items = array(); |
|
| 523 | - |
|
| 524 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 525 | - 'ee_read_global_messages', |
|
| 526 | - 'view_filtered_messages' |
|
| 527 | - )) { |
|
| 528 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 529 | - if (is_array($related_for_icon) |
|
| 530 | - && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 531 | - ) { |
|
| 532 | - $items['view_related_messages'] = array( |
|
| 533 | - 'class' => $related_for_icon['css_class'], |
|
| 534 | - 'desc' => $related_for_icon['label'], |
|
| 535 | - ); |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - $items = apply_filters( |
|
| 540 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 541 | - array_merge( |
|
| 542 | - $items, |
|
| 543 | - array( |
|
| 544 | - 'view_details' => array( |
|
| 545 | - 'class' => 'dashicons dashicons-cart', |
|
| 546 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 547 | - ), |
|
| 548 | - 'view_invoice' => array( |
|
| 549 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 550 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 551 | - ), |
|
| 552 | - 'view_receipt' => array( |
|
| 553 | - 'class' => 'dashicons dashicons-media-default', |
|
| 554 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 555 | - ), |
|
| 556 | - 'view_registration' => array( |
|
| 557 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 558 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 559 | - ), |
|
| 560 | - 'payment_overview_link' => array( |
|
| 561 | - 'class' => 'dashicons dashicons-money', |
|
| 562 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 563 | - ), |
|
| 564 | - ) |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - |
|
| 568 | - if (EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 569 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 570 | - 'ee_send_message', |
|
| 571 | - 'espresso_transactions_send_payment_reminder' |
|
| 572 | - ) |
|
| 573 | - ) { |
|
| 574 | - $items['send_payment_reminder'] = array( |
|
| 575 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 576 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 577 | - ); |
|
| 578 | - } else { |
|
| 579 | - $items['blank*'] = array( |
|
| 580 | - 'class' => '', |
|
| 581 | - 'desc' => '', |
|
| 582 | - ); |
|
| 583 | - } |
|
| 584 | - $more_items = apply_filters( |
|
| 585 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 586 | - array( |
|
| 587 | - 'overpaid' => array( |
|
| 588 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 589 | - 'desc' => EEH_Template::pretty_status( |
|
| 590 | - EEM_Transaction::overpaid_status_code, |
|
| 591 | - false, |
|
| 592 | - 'sentence' |
|
| 593 | - ), |
|
| 594 | - ), |
|
| 595 | - 'complete' => array( |
|
| 596 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 597 | - 'desc' => EEH_Template::pretty_status( |
|
| 598 | - EEM_Transaction::complete_status_code, |
|
| 599 | - false, |
|
| 600 | - 'sentence' |
|
| 601 | - ), |
|
| 602 | - ), |
|
| 603 | - 'incomplete' => array( |
|
| 604 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 605 | - 'desc' => EEH_Template::pretty_status( |
|
| 606 | - EEM_Transaction::incomplete_status_code, |
|
| 607 | - false, |
|
| 608 | - 'sentence' |
|
| 609 | - ), |
|
| 610 | - ), |
|
| 611 | - 'abandoned' => array( |
|
| 612 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 613 | - 'desc' => EEH_Template::pretty_status( |
|
| 614 | - EEM_Transaction::abandoned_status_code, |
|
| 615 | - false, |
|
| 616 | - 'sentence' |
|
| 617 | - ), |
|
| 618 | - ), |
|
| 619 | - 'failed' => array( |
|
| 620 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 621 | - 'desc' => EEH_Template::pretty_status( |
|
| 622 | - EEM_Transaction::failed_status_code, |
|
| 623 | - false, |
|
| 624 | - 'sentence' |
|
| 625 | - ), |
|
| 626 | - ), |
|
| 627 | - ) |
|
| 628 | - ); |
|
| 629 | - |
|
| 630 | - return array_merge($items, $more_items); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * _transactions_overview_list_table |
|
| 636 | - * |
|
| 637 | - * @access protected |
|
| 638 | - * @return void |
|
| 639 | - * @throws DomainException |
|
| 640 | - * @throws EE_Error |
|
| 641 | - * @throws InvalidArgumentException |
|
| 642 | - * @throws InvalidDataTypeException |
|
| 643 | - * @throws InvalidInterfaceException |
|
| 644 | - * @throws ReflectionException |
|
| 645 | - */ |
|
| 646 | - protected function _transactions_overview_list_table() |
|
| 647 | - { |
|
| 648 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 649 | - $event = isset($this->_req_data['EVT_ID']) |
|
| 650 | - ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 651 | - : null; |
|
| 652 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 653 | - ? sprintf( |
|
| 654 | - esc_html__( |
|
| 655 | - '%sViewing Transactions for the Event: %s%s', |
|
| 656 | - 'event_espresso' |
|
| 657 | - ), |
|
| 658 | - '<h3>', |
|
| 659 | - '<a href="' |
|
| 660 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 661 | - array('action' => 'edit', 'post' => $event->ID()), |
|
| 662 | - EVENTS_ADMIN_URL |
|
| 663 | - ) |
|
| 664 | - . '" title="' |
|
| 665 | - . esc_attr__( |
|
| 666 | - 'Click to Edit event', |
|
| 667 | - 'event_espresso' |
|
| 668 | - ) |
|
| 669 | - . '">' . $event->name() . '</a>', |
|
| 670 | - '</h3>' |
|
| 671 | - ) |
|
| 672 | - : ''; |
|
| 673 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 674 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * _transaction_details |
|
| 680 | - * generates HTML for the View Transaction Details Admin page |
|
| 681 | - * |
|
| 682 | - * @access protected |
|
| 683 | - * @return void |
|
| 684 | - * @throws DomainException |
|
| 685 | - * @throws EE_Error |
|
| 686 | - * @throws InvalidArgumentException |
|
| 687 | - * @throws InvalidDataTypeException |
|
| 688 | - * @throws InvalidInterfaceException |
|
| 689 | - * @throws RuntimeException |
|
| 690 | - * @throws ReflectionException |
|
| 691 | - */ |
|
| 692 | - protected function _transaction_details() |
|
| 693 | - { |
|
| 694 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 695 | - |
|
| 696 | - $this->_set_transaction_status_array(); |
|
| 697 | - |
|
| 698 | - $this->_template_args = array(); |
|
| 699 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 700 | - |
|
| 701 | - $this->_set_transaction_object(); |
|
| 702 | - |
|
| 703 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 704 | - return; |
|
| 705 | - } |
|
| 706 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 707 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 708 | - ? $primary_registration->attendee() |
|
| 709 | - : null; |
|
| 710 | - |
|
| 711 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 712 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 713 | - |
|
| 714 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 715 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 716 | - |
|
| 717 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 718 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 719 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 720 | - |
|
| 721 | - $this->_template_args['grand_total'] = $this->_transaction->total(); |
|
| 722 | - $this->_template_args['total_paid'] = $this->_transaction->paid(); |
|
| 723 | - |
|
| 724 | - $amount_due = $this->_transaction->total() - $this->_transaction->paid(); |
|
| 725 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 726 | - $amount_due, |
|
| 727 | - true |
|
| 728 | - ); |
|
| 729 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 730 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 731 | - . $this->_template_args['amount_due']; |
|
| 732 | - } else { |
|
| 733 | - $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 734 | - } |
|
| 735 | - $this->_template_args['amount_due_class'] = ''; |
|
| 736 | - |
|
| 737 | - if ($this->_transaction->paid() === $this->_transaction->total()) { |
|
| 738 | - // paid in full |
|
| 739 | - $this->_template_args['amount_due'] = false; |
|
| 740 | - } elseif ($this->_transaction->paid() > $this->_transaction->total()) { |
|
| 741 | - // overpaid |
|
| 742 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 743 | - } elseif ($this->_transaction->total() > (float) 0) { |
|
| 744 | - if ($this->_transaction->paid() > (float) 0) { |
|
| 745 | - // monies owing |
|
| 746 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 747 | - } elseif ($this->_transaction->paid() === (float) 0) { |
|
| 748 | - // no payments made yet |
|
| 749 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 750 | - } |
|
| 751 | - } elseif ($this->_transaction->total() === (float) 0) { |
|
| 752 | - // free event |
|
| 753 | - $this->_template_args['amount_due'] = false; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - $payment_method = $this->_transaction->payment_method(); |
|
| 757 | - |
|
| 758 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 759 | - ? $payment_method->admin_name() |
|
| 760 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 761 | - |
|
| 762 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 763 | - // link back to overview |
|
| 764 | - $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 765 | - ? $_SERVER['HTTP_REFERER'] |
|
| 766 | - : TXN_ADMIN_URL; |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - // next link |
|
| 770 | - $next_txn = $this->_transaction->next( |
|
| 771 | - null, |
|
| 772 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 773 | - 'TXN_ID' |
|
| 774 | - ); |
|
| 775 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 776 | - ? $this->_next_link( |
|
| 777 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 778 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 779 | - TXN_ADMIN_URL |
|
| 780 | - ), |
|
| 781 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 782 | - ) |
|
| 783 | - : ''; |
|
| 784 | - // previous link |
|
| 785 | - $previous_txn = $this->_transaction->previous( |
|
| 786 | - null, |
|
| 787 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 788 | - 'TXN_ID' |
|
| 789 | - ); |
|
| 790 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 791 | - ? $this->_previous_link( |
|
| 792 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 793 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 794 | - TXN_ADMIN_URL |
|
| 795 | - ), |
|
| 796 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 797 | - ) |
|
| 798 | - : ''; |
|
| 799 | - |
|
| 800 | - // were we just redirected here after adding a new registration ??? |
|
| 801 | - if (isset( |
|
| 802 | - $this->_req_data['redirect_from'], |
|
| 803 | - $this->_req_data['EVT_ID'], |
|
| 804 | - $this->_req_data['event_name'] |
|
| 805 | - )) { |
|
| 806 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 807 | - 'ee_edit_registrations', |
|
| 808 | - 'espresso_registrations_new_registration', |
|
| 809 | - $this->_req_data['EVT_ID'] |
|
| 810 | - )) { |
|
| 811 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 812 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 813 | - array( |
|
| 814 | - 'page' => 'espresso_registrations', |
|
| 815 | - 'action' => 'new_registration', |
|
| 816 | - 'return' => 'default', |
|
| 817 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 818 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 819 | - ), |
|
| 820 | - REG_ADMIN_URL |
|
| 821 | - ); |
|
| 822 | - $this->_admin_page_title .= '">'; |
|
| 823 | - |
|
| 824 | - $this->_admin_page_title .= sprintf( |
|
| 825 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 826 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 827 | - ); |
|
| 828 | - $this->_admin_page_title .= '</a>'; |
|
| 829 | - } |
|
| 830 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 831 | - } |
|
| 832 | - // grab messages at the last second |
|
| 833 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 834 | - // path to template |
|
| 835 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 836 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 837 | - $template_path, |
|
| 838 | - $this->_template_args, |
|
| 839 | - true |
|
| 840 | - ); |
|
| 841 | - |
|
| 842 | - // the details template wrapper |
|
| 843 | - $this->display_admin_page_with_sidebar(); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * _transaction_details_metaboxes |
|
| 849 | - * |
|
| 850 | - * @access protected |
|
| 851 | - * @return void |
|
| 852 | - * @throws EE_Error |
|
| 853 | - * @throws InvalidArgumentException |
|
| 854 | - * @throws InvalidDataTypeException |
|
| 855 | - * @throws InvalidInterfaceException |
|
| 856 | - * @throws RuntimeException |
|
| 857 | - * @throws ReflectionException |
|
| 858 | - */ |
|
| 859 | - protected function _transaction_details_metaboxes() |
|
| 860 | - { |
|
| 861 | - |
|
| 862 | - $this->_set_transaction_object(); |
|
| 863 | - |
|
| 864 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 865 | - return; |
|
| 866 | - } |
|
| 867 | - add_meta_box( |
|
| 868 | - 'edit-txn-details-mbox', |
|
| 869 | - esc_html__('Transaction Details', 'event_espresso'), |
|
| 870 | - array($this, 'txn_details_meta_box'), |
|
| 871 | - $this->_wp_page_slug, |
|
| 872 | - 'normal', |
|
| 873 | - 'high' |
|
| 874 | - ); |
|
| 875 | - add_meta_box( |
|
| 876 | - 'edit-txn-attendees-mbox', |
|
| 877 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 878 | - array($this, 'txn_attendees_meta_box'), |
|
| 879 | - $this->_wp_page_slug, |
|
| 880 | - 'normal', |
|
| 881 | - 'high', |
|
| 882 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 883 | - ); |
|
| 884 | - add_meta_box( |
|
| 885 | - 'edit-txn-registrant-mbox', |
|
| 886 | - esc_html__('Primary Contact', 'event_espresso'), |
|
| 887 | - array($this, 'txn_registrant_side_meta_box'), |
|
| 888 | - $this->_wp_page_slug, |
|
| 889 | - 'side', |
|
| 890 | - 'high' |
|
| 891 | - ); |
|
| 892 | - add_meta_box( |
|
| 893 | - 'edit-txn-billing-info-mbox', |
|
| 894 | - esc_html__('Billing Information', 'event_espresso'), |
|
| 895 | - array($this, 'txn_billing_info_side_meta_box'), |
|
| 896 | - $this->_wp_page_slug, |
|
| 897 | - 'side', |
|
| 898 | - 'high' |
|
| 899 | - ); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * Callback for transaction actions metabox. |
|
| 905 | - * |
|
| 906 | - * @param EE_Transaction|null $transaction |
|
| 907 | - * @return string |
|
| 908 | - * @throws DomainException |
|
| 909 | - * @throws EE_Error |
|
| 910 | - * @throws InvalidArgumentException |
|
| 911 | - * @throws InvalidDataTypeException |
|
| 912 | - * @throws InvalidInterfaceException |
|
| 913 | - * @throws ReflectionException |
|
| 914 | - * @throws RuntimeException |
|
| 915 | - */ |
|
| 916 | - public function getActionButtons(EE_Transaction $transaction = null) |
|
| 917 | - { |
|
| 918 | - $content = ''; |
|
| 919 | - $actions = array(); |
|
| 920 | - if (! $transaction instanceof EE_Transaction) { |
|
| 921 | - return $content; |
|
| 922 | - } |
|
| 923 | - /** @var EE_Registration $primary_registration */ |
|
| 924 | - $primary_registration = $transaction->primary_registration(); |
|
| 925 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 926 | - ? $primary_registration->attendee() |
|
| 927 | - : null; |
|
| 928 | - |
|
| 929 | - if ($attendee instanceof EE_Attendee |
|
| 930 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | - 'ee_send_message', |
|
| 932 | - 'espresso_transactions_send_payment_reminder' |
|
| 933 | - ) |
|
| 934 | - ) { |
|
| 935 | - $actions['payment_reminder'] = |
|
| 936 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 937 | - && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 938 | - && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code |
|
| 939 | - ? EEH_Template::get_button_or_link( |
|
| 940 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 941 | - array( |
|
| 942 | - 'action' => 'send_payment_reminder', |
|
| 943 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 944 | - 'redirect_to' => 'view_transaction', |
|
| 945 | - ), |
|
| 946 | - TXN_ADMIN_URL |
|
| 947 | - ), |
|
| 948 | - esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
| 949 | - 'button secondary-button', |
|
| 950 | - 'dashicons dashicons-email-alt' |
|
| 951 | - ) |
|
| 952 | - : ''; |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 956 | - 'ee_edit_payments', |
|
| 957 | - 'espresso_transactions_recalculate_line_items' |
|
| 958 | - ) |
|
| 959 | - ) { |
|
| 960 | - $actions['recalculate_line_items'] = EEH_Template::get_button_or_link( |
|
| 961 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 962 | - array( |
|
| 963 | - 'action' => 'espresso_recalculate_line_items', |
|
| 964 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 965 | - 'redirect_to' => 'view_transaction', |
|
| 966 | - ), |
|
| 967 | - TXN_ADMIN_URL |
|
| 968 | - ), |
|
| 969 | - esc_html__(' Recalculate Taxes and Total', 'event_espresso'), |
|
| 970 | - 'button secondary-button', |
|
| 971 | - 'dashicons dashicons-update' |
|
| 972 | - ); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - if ($primary_registration instanceof EE_Registration |
|
| 976 | - && EEH_MSG_Template::is_mt_active('receipt') |
|
| 977 | - ) { |
|
| 978 | - $actions['receipt'] = EEH_Template::get_button_or_link( |
|
| 979 | - $primary_registration->receipt_url(), |
|
| 980 | - esc_html__('View Receipt', 'event_espresso'), |
|
| 981 | - 'button secondary-button', |
|
| 982 | - 'dashicons dashicons-media-default' |
|
| 983 | - ); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - if ($primary_registration instanceof EE_Registration |
|
| 987 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
| 988 | - ) { |
|
| 989 | - $actions['invoice'] = EEH_Template::get_button_or_link( |
|
| 990 | - $primary_registration->invoice_url(), |
|
| 991 | - esc_html__('View Invoice', 'event_espresso'), |
|
| 992 | - 'button secondary-button', |
|
| 993 | - 'dashicons dashicons-media-spreadsheet' |
|
| 994 | - ); |
|
| 995 | - } |
|
| 996 | - $actions = array_filter( |
|
| 997 | - apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
| 998 | - ); |
|
| 999 | - if ($actions) { |
|
| 1000 | - $content = '<ul>'; |
|
| 1001 | - $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1002 | - $content .= '</uL>'; |
|
| 1003 | - } |
|
| 1004 | - return $content; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - |
|
| 1008 | - /** |
|
| 1009 | - * txn_details_meta_box |
|
| 1010 | - * generates HTML for the Transaction main meta box |
|
| 1011 | - * |
|
| 1012 | - * @return void |
|
| 1013 | - * @throws DomainException |
|
| 1014 | - * @throws EE_Error |
|
| 1015 | - * @throws InvalidArgumentException |
|
| 1016 | - * @throws InvalidDataTypeException |
|
| 1017 | - * @throws InvalidInterfaceException |
|
| 1018 | - * @throws RuntimeException |
|
| 1019 | - * @throws ReflectionException |
|
| 1020 | - */ |
|
| 1021 | - public function txn_details_meta_box() |
|
| 1022 | - { |
|
| 1023 | - $this->_set_transaction_object(); |
|
| 1024 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 1025 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1026 | - ? $this->_transaction->primary_registration()->attendee() |
|
| 1027 | - : null; |
|
| 1028 | - $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1029 | - 'ee_edit_payments', |
|
| 1030 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1031 | - ); |
|
| 1032 | - $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1033 | - 'ee_delete_payments', |
|
| 1034 | - 'delete_payment_from_registration_details' |
|
| 1035 | - ); |
|
| 1036 | - |
|
| 1037 | - // get line table |
|
| 1038 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1039 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
| 1040 | - 'admin_table', |
|
| 1041 | - 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 1042 | - ); |
|
| 1043 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 1044 | - $this->_transaction->total_line_item() |
|
| 1045 | - ); |
|
| 1046 | - $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code(); |
|
| 1047 | - |
|
| 1048 | - // process taxes |
|
| 1049 | - $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1050 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 1051 | - |
|
| 1052 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 1053 | - $this->_transaction->total(), |
|
| 1054 | - false, |
|
| 1055 | - false |
|
| 1056 | - ); |
|
| 1057 | - $this->_template_args['grand_raw_total'] = $this->_transaction->total(); |
|
| 1058 | - $this->_template_args['TXN_status'] = $this->_transaction->status_ID(); |
|
| 1059 | - |
|
| 1060 | - // process payment details |
|
| 1061 | - $payments = $this->_transaction->payments(); |
|
| 1062 | - if (! empty($payments)) { |
|
| 1063 | - $this->_template_args['payments'] = $payments; |
|
| 1064 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 1065 | - } else { |
|
| 1066 | - $this->_template_args['payments'] = false; |
|
| 1067 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 1071 | - $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 1072 | - array('action' => 'espresso_delete_payment'), |
|
| 1073 | - TXN_ADMIN_URL |
|
| 1074 | - ); |
|
| 1075 | - |
|
| 1076 | - if (isset($txn_details['invoice_number'])) { |
|
| 1077 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 1078 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 1079 | - 'Invoice Number', |
|
| 1080 | - 'event_espresso' |
|
| 1081 | - ); |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 1085 | - ->primary_registration() |
|
| 1086 | - ->session_ID(); |
|
| 1087 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 1088 | - 'Registration Session', |
|
| 1089 | - 'event_espresso' |
|
| 1090 | - ); |
|
| 1091 | - |
|
| 1092 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 1093 | - ? $this->_session['ip_address'] |
|
| 1094 | - : ''; |
|
| 1095 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 1096 | - 'Transaction placed from IP', |
|
| 1097 | - 'event_espresso' |
|
| 1098 | - ); |
|
| 1099 | - |
|
| 1100 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1101 | - ? $this->_session['user_agent'] |
|
| 1102 | - : ''; |
|
| 1103 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1104 | - 'Registrant User Agent', |
|
| 1105 | - 'event_espresso' |
|
| 1106 | - ); |
|
| 1107 | - |
|
| 1108 | - $reg_steps = '<ul>'; |
|
| 1109 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1110 | - if ($reg_step_status === true) { |
|
| 1111 | - $reg_steps .= '<li style="color:#70cc50">' |
|
| 1112 | - . sprintf( |
|
| 1113 | - esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1114 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1115 | - ) |
|
| 1116 | - . '</li>'; |
|
| 1117 | - } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1118 | - $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1119 | - . sprintf( |
|
| 1120 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1121 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1122 | - date( |
|
| 1123 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1124 | - $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1125 | - ) |
|
| 1126 | - ) |
|
| 1127 | - . '</li>'; |
|
| 1128 | - } else { |
|
| 1129 | - $reg_steps .= '<li style="color:#E76700">' |
|
| 1130 | - . sprintf( |
|
| 1131 | - esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1132 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1133 | - ) |
|
| 1134 | - . '</li>'; |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - $reg_steps .= '</ul>'; |
|
| 1138 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1139 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1140 | - 'Registration Step Progress', |
|
| 1141 | - 'event_espresso' |
|
| 1142 | - ); |
|
| 1143 | - |
|
| 1144 | - |
|
| 1145 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 1146 | - $this->_get_payment_methods($payments); |
|
| 1147 | - $this->_get_payment_status_array(); |
|
| 1148 | - $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
| 1149 | - |
|
| 1150 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1151 | - array( |
|
| 1152 | - 'action' => 'edit_transaction', |
|
| 1153 | - 'process' => 'transaction', |
|
| 1154 | - ), |
|
| 1155 | - TXN_ADMIN_URL |
|
| 1156 | - ); |
|
| 1157 | - $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
| 1158 | - array( |
|
| 1159 | - 'page' => 'espresso_transactions', |
|
| 1160 | - 'action' => 'espresso_apply_payment', |
|
| 1161 | - ), |
|
| 1162 | - WP_AJAX_URL |
|
| 1163 | - ); |
|
| 1164 | - $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
| 1165 | - array( |
|
| 1166 | - 'page' => 'espresso_transactions', |
|
| 1167 | - 'action' => 'espresso_delete_payment', |
|
| 1168 | - ), |
|
| 1169 | - WP_AJAX_URL |
|
| 1170 | - ); |
|
| 1171 | - |
|
| 1172 | - $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
| 1173 | - |
|
| 1174 | - // 'espresso_delete_payment_nonce' |
|
| 1175 | - |
|
| 1176 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1177 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * _get_registration_payment_IDs |
|
| 1183 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1184 | - * |
|
| 1185 | - * @access protected |
|
| 1186 | - * @param EE_Payment[] $payments |
|
| 1187 | - * @return array |
|
| 1188 | - * @throws EE_Error |
|
| 1189 | - * @throws InvalidArgumentException |
|
| 1190 | - * @throws InvalidDataTypeException |
|
| 1191 | - * @throws InvalidInterfaceException |
|
| 1192 | - * @throws ReflectionException |
|
| 1193 | - */ |
|
| 1194 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 1195 | - { |
|
| 1196 | - $existing_reg_payments = array(); |
|
| 1197 | - // get all reg payments for these payments |
|
| 1198 | - $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
| 1199 | - array( |
|
| 1200 | - array( |
|
| 1201 | - 'PAY_ID' => array( |
|
| 1202 | - 'IN', |
|
| 1203 | - array_keys($payments), |
|
| 1204 | - ), |
|
| 1205 | - ), |
|
| 1206 | - ) |
|
| 1207 | - ); |
|
| 1208 | - if (! empty($reg_payments)) { |
|
| 1209 | - foreach ($payments as $payment) { |
|
| 1210 | - if (! $payment instanceof EE_Payment) { |
|
| 1211 | - continue; |
|
| 1212 | - } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1213 | - $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1214 | - } |
|
| 1215 | - foreach ($reg_payments as $reg_payment) { |
|
| 1216 | - if ($reg_payment instanceof EE_Registration_Payment |
|
| 1217 | - && $reg_payment->payment_ID() === $payment->ID() |
|
| 1218 | - ) { |
|
| 1219 | - $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - return $existing_reg_payments; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * _get_registrations_to_apply_payment_to |
|
| 1231 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1232 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 1233 | - * |
|
| 1234 | - * @access protected |
|
| 1235 | - * @return void |
|
| 1236 | - * @throws EE_Error |
|
| 1237 | - * @throws InvalidArgumentException |
|
| 1238 | - * @throws InvalidDataTypeException |
|
| 1239 | - * @throws InvalidInterfaceException |
|
| 1240 | - * @throws ReflectionException |
|
| 1241 | - */ |
|
| 1242 | - protected function _get_registrations_to_apply_payment_to() |
|
| 1243 | - { |
|
| 1244 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1245 | - $query_params = array( |
|
| 1246 | - array( |
|
| 1247 | - 'STS_ID' => array( |
|
| 1248 | - 'IN', |
|
| 1249 | - array( |
|
| 1250 | - EEM_Registration::status_id_approved, |
|
| 1251 | - EEM_Registration::status_id_pending_payment, |
|
| 1252 | - EEM_Registration::status_id_not_approved, |
|
| 1253 | - ), |
|
| 1254 | - ), |
|
| 1255 | - ), |
|
| 1256 | - ); |
|
| 1257 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1258 | - '', |
|
| 1259 | - 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1260 | - '', |
|
| 1261 | - 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1262 | - ); |
|
| 1263 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1264 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1265 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1266 | - EEH_HTML::tr( |
|
| 1267 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1268 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1269 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1270 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1271 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1272 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1273 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1274 | - ) |
|
| 1275 | - ); |
|
| 1276 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1277 | - // get registrations for TXN |
|
| 1278 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 1279 | - $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1280 | - foreach ($registrations as $registration) { |
|
| 1281 | - if ($registration instanceof EE_Registration) { |
|
| 1282 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1283 | - ? $registration->attendee()->full_name() |
|
| 1284 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1285 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 1286 | - $taxable = $registration->ticket()->taxable() |
|
| 1287 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1288 | - : ''; |
|
| 1289 | - $checked = empty($existing_reg_payments) |
|
| 1290 | - || in_array($registration->ID(), $existing_reg_payments, true) |
|
| 1291 | - ? ' checked="checked"' |
|
| 1292 | - : ''; |
|
| 1293 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1294 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1295 | - EEH_HTML::td($registration->ID()) . |
|
| 1296 | - EEH_HTML::td($attendee_name) . |
|
| 1297 | - EEH_HTML::td( |
|
| 1298 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1299 | - ) . |
|
| 1300 | - EEH_HTML::td($registration->event_name()) . |
|
| 1301 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1302 | - EEH_HTML::td( |
|
| 1303 | - EEH_Template::format_currency($owing), |
|
| 1304 | - '', |
|
| 1305 | - 'txn-admin-payment-owing-td jst-cntr' |
|
| 1306 | - ) . |
|
| 1307 | - EEH_HTML::td( |
|
| 1308 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1309 | - . '" name="txn_admin_payment[registrations]"' |
|
| 1310 | - . $checked . $disabled . '>', |
|
| 1311 | - '', |
|
| 1312 | - 'jst-cntr' |
|
| 1313 | - ), |
|
| 1314 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1315 | - ); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1319 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1320 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1321 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1322 | - esc_html__( |
|
| 1323 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1324 | - 'event_espresso' |
|
| 1325 | - ), |
|
| 1326 | - '', |
|
| 1327 | - 'clear description' |
|
| 1328 | - ); |
|
| 1329 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1330 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * _get_reg_status_selection |
|
| 1336 | - * |
|
| 1337 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1338 | - * instead of events. |
|
| 1339 | - * @access protected |
|
| 1340 | - * @return void |
|
| 1341 | - * @throws EE_Error |
|
| 1342 | - */ |
|
| 1343 | - protected function _get_reg_status_selection() |
|
| 1344 | - { |
|
| 1345 | - // first get all possible statuses |
|
| 1346 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1347 | - // let's add a "don't change" option. |
|
| 1348 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1349 | - $status_array = array_merge($status_array, $statuses); |
|
| 1350 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1351 | - 'txn_reg_status_change[reg_status]', |
|
| 1352 | - $status_array, |
|
| 1353 | - 'NAN', |
|
| 1354 | - 'id="txn-admin-payment-reg-status-inp"', |
|
| 1355 | - 'txn-reg-status-change-reg-status' |
|
| 1356 | - ); |
|
| 1357 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1358 | - 'delete_txn_reg_status_change[reg_status]', |
|
| 1359 | - $status_array, |
|
| 1360 | - 'NAN', |
|
| 1361 | - 'delete-txn-admin-payment-reg-status-inp', |
|
| 1362 | - 'delete-txn-reg-status-change-reg-status' |
|
| 1363 | - ); |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - /** |
|
| 1368 | - * _get_payment_methods |
|
| 1369 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1370 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1371 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1372 | - * |
|
| 1373 | - * @access private |
|
| 1374 | - * @param EE_Payment[] to show on this page |
|
| 1375 | - * @return void |
|
| 1376 | - * @throws EE_Error |
|
| 1377 | - * @throws InvalidArgumentException |
|
| 1378 | - * @throws InvalidDataTypeException |
|
| 1379 | - * @throws InvalidInterfaceException |
|
| 1380 | - * @throws ReflectionException |
|
| 1381 | - */ |
|
| 1382 | - private function _get_payment_methods($payments = array()) |
|
| 1383 | - { |
|
| 1384 | - $payment_methods_of_payments = array(); |
|
| 1385 | - foreach ($payments as $payment) { |
|
| 1386 | - if ($payment instanceof EE_Payment) { |
|
| 1387 | - $payment_methods_of_payments[] = $payment->ID(); |
|
| 1388 | - } |
|
| 1389 | - } |
|
| 1390 | - if ($payment_methods_of_payments) { |
|
| 1391 | - $query_args = array( |
|
| 1392 | - array( |
|
| 1393 | - 'OR*payment_method_for_payment' => array( |
|
| 1394 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1395 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1396 | - ), |
|
| 1397 | - ), |
|
| 1398 | - ); |
|
| 1399 | - } else { |
|
| 1400 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1401 | - } |
|
| 1402 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * txn_attendees_meta_box |
|
| 1408 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1409 | - * |
|
| 1410 | - * @access public |
|
| 1411 | - * @param WP_Post $post |
|
| 1412 | - * @param array $metabox |
|
| 1413 | - * @return void |
|
| 1414 | - * @throws DomainException |
|
| 1415 | - * @throws EE_Error |
|
| 1416 | - * @throws InvalidArgumentException |
|
| 1417 | - * @throws InvalidDataTypeException |
|
| 1418 | - * @throws InvalidInterfaceException |
|
| 1419 | - * @throws ReflectionException |
|
| 1420 | - */ |
|
| 1421 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1422 | - { |
|
| 1423 | - |
|
| 1424 | - /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1425 | - extract($metabox['args']); |
|
| 1426 | - $this->_template_args['post'] = $post; |
|
| 1427 | - $this->_template_args['event_attendees'] = array(); |
|
| 1428 | - // process items in cart |
|
| 1429 | - $line_items = $this->_transaction->get_many_related( |
|
| 1430 | - 'Line_Item', |
|
| 1431 | - array(array('LIN_type' => 'line-item')) |
|
| 1432 | - ); |
|
| 1433 | - if (! empty($line_items)) { |
|
| 1434 | - foreach ($line_items as $item) { |
|
| 1435 | - if ($item instanceof EE_Line_Item) { |
|
| 1436 | - switch ($item->OBJ_type()) { |
|
| 1437 | - case 'Event': |
|
| 1438 | - break; |
|
| 1439 | - case 'Ticket': |
|
| 1440 | - $ticket = $item->ticket(); |
|
| 1441 | - // right now we're only handling tickets here. |
|
| 1442 | - // Cause its expected that only tickets will have attendees right? |
|
| 1443 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1444 | - break; |
|
| 1445 | - } |
|
| 1446 | - try { |
|
| 1447 | - $event_name = $ticket->get_event_name(); |
|
| 1448 | - } catch (Exception $e) { |
|
| 1449 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1450 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1451 | - } |
|
| 1452 | - $event_name .= ' - ' . $item->name(); |
|
| 1453 | - $ticket_price = EEH_Template::format_currency($item->unit_price()); |
|
| 1454 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1455 | - $registrations = $ticket->registrations( |
|
| 1456 | - array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1457 | - ); |
|
| 1458 | - foreach ($registrations as $registration) { |
|
| 1459 | - if (! $registration instanceof EE_Registration) { |
|
| 1460 | - break; |
|
| 1461 | - } |
|
| 1462 | - $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1463 | - = $registration->status_ID(); |
|
| 1464 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1465 | - = $registration->count(); |
|
| 1466 | - $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1467 | - = $event_name; |
|
| 1468 | - $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1469 | - = $ticket_price; |
|
| 1470 | - // attendee info |
|
| 1471 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1472 | - if ($attendee instanceof EE_Attendee) { |
|
| 1473 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1474 | - = $attendee->ID(); |
|
| 1475 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1476 | - = $attendee->full_name(); |
|
| 1477 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1478 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1479 | - . esc_html__( |
|
| 1480 | - ' Event', |
|
| 1481 | - 'event_espresso' |
|
| 1482 | - ) |
|
| 1483 | - . '">' . $attendee->email() . '</a>'; |
|
| 1484 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1485 | - = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1486 | - } else { |
|
| 1487 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1488 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1489 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1490 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - break; |
|
| 1494 | - } |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1499 | - array( |
|
| 1500 | - 'action' => 'edit_transaction', |
|
| 1501 | - 'process' => 'attendees', |
|
| 1502 | - ), |
|
| 1503 | - TXN_ADMIN_URL |
|
| 1504 | - ); |
|
| 1505 | - echo EEH_Template::display_template( |
|
| 1506 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1507 | - $this->_template_args, |
|
| 1508 | - true |
|
| 1509 | - ); |
|
| 1510 | - } else { |
|
| 1511 | - echo sprintf( |
|
| 1512 | - esc_html__( |
|
| 1513 | - '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1514 | - 'event_espresso' |
|
| 1515 | - ), |
|
| 1516 | - '<p class="important-notice">', |
|
| 1517 | - '</p>' |
|
| 1518 | - ); |
|
| 1519 | - } |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * txn_registrant_side_meta_box |
|
| 1525 | - * generates HTML for the Edit Transaction side meta box |
|
| 1526 | - * |
|
| 1527 | - * @access public |
|
| 1528 | - * @return void |
|
| 1529 | - * @throws DomainException |
|
| 1530 | - * @throws EE_Error |
|
| 1531 | - * @throws InvalidArgumentException |
|
| 1532 | - * @throws InvalidDataTypeException |
|
| 1533 | - * @throws InvalidInterfaceException |
|
| 1534 | - * @throws ReflectionException |
|
| 1535 | - */ |
|
| 1536 | - public function txn_registrant_side_meta_box() |
|
| 1537 | - { |
|
| 1538 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1539 | - ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1540 | - : null; |
|
| 1541 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1542 | - $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1543 | - 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1544 | - 'event_espresso' |
|
| 1545 | - ); |
|
| 1546 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1547 | - } |
|
| 1548 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1549 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1550 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1551 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1552 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1553 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1554 | - array( |
|
| 1555 | - 'action' => 'edit_attendee', |
|
| 1556 | - 'post' => $primary_att->ID(), |
|
| 1557 | - ), |
|
| 1558 | - REG_ADMIN_URL |
|
| 1559 | - ); |
|
| 1560 | - // get formatted address for registrant |
|
| 1561 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1562 | - echo EEH_Template::display_template( |
|
| 1563 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1564 | - $this->_template_args, |
|
| 1565 | - true |
|
| 1566 | - ); |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * txn_billing_info_side_meta_box |
|
| 1572 | - * generates HTML for the Edit Transaction side meta box |
|
| 1573 | - * |
|
| 1574 | - * @access public |
|
| 1575 | - * @return void |
|
| 1576 | - * @throws DomainException |
|
| 1577 | - * @throws EE_Error |
|
| 1578 | - */ |
|
| 1579 | - public function txn_billing_info_side_meta_box() |
|
| 1580 | - { |
|
| 1581 | - |
|
| 1582 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1583 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1584 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1585 | - TXN_ADMIN_URL |
|
| 1586 | - ); |
|
| 1587 | - |
|
| 1588 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1589 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - |
|
| 1593 | - /** |
|
| 1594 | - * apply_payments_or_refunds |
|
| 1595 | - * registers a payment or refund made towards a transaction |
|
| 1596 | - * |
|
| 1597 | - * @access public |
|
| 1598 | - * @return void |
|
| 1599 | - * @throws EE_Error |
|
| 1600 | - * @throws InvalidArgumentException |
|
| 1601 | - * @throws ReflectionException |
|
| 1602 | - * @throws RuntimeException |
|
| 1603 | - * @throws InvalidDataTypeException |
|
| 1604 | - * @throws InvalidInterfaceException |
|
| 1605 | - */ |
|
| 1606 | - public function apply_payments_or_refunds() |
|
| 1607 | - { |
|
| 1608 | - $json_response_data = array('return_data' => false); |
|
| 1609 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1610 | - $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1611 | - 'ee_edit_payments', |
|
| 1612 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1613 | - ); |
|
| 1614 | - if (! empty($valid_data) && $has_access) { |
|
| 1615 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1616 | - // save the new payment |
|
| 1617 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1618 | - // get the TXN for this payment |
|
| 1619 | - $transaction = $payment->transaction(); |
|
| 1620 | - // verify transaction |
|
| 1621 | - if ($transaction instanceof EE_Transaction) { |
|
| 1622 | - // calculate_total_payments_and_update_status |
|
| 1623 | - $this->_process_transaction_payments($transaction); |
|
| 1624 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1625 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1626 | - // apply payment to registrations (if applicable) |
|
| 1627 | - if (! empty($REG_IDs)) { |
|
| 1628 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1629 | - $this->_maybe_send_notifications(); |
|
| 1630 | - // now process status changes for the same registrations |
|
| 1631 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1632 | - } |
|
| 1633 | - $this->_maybe_send_notifications($payment); |
|
| 1634 | - // prepare to render page |
|
| 1635 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1636 | - do_action( |
|
| 1637 | - 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1638 | - $transaction, |
|
| 1639 | - $payment |
|
| 1640 | - ); |
|
| 1641 | - } else { |
|
| 1642 | - EE_Error::add_error( |
|
| 1643 | - esc_html__( |
|
| 1644 | - 'A valid Transaction for this payment could not be retrieved.', |
|
| 1645 | - 'event_espresso' |
|
| 1646 | - ), |
|
| 1647 | - __FILE__, |
|
| 1648 | - __FUNCTION__, |
|
| 1649 | - __LINE__ |
|
| 1650 | - ); |
|
| 1651 | - } |
|
| 1652 | - } elseif ($has_access) { |
|
| 1653 | - EE_Error::add_error( |
|
| 1654 | - esc_html__( |
|
| 1655 | - 'The payment form data could not be processed. Please try again.', |
|
| 1656 | - 'event_espresso' |
|
| 1657 | - ), |
|
| 1658 | - __FILE__, |
|
| 1659 | - __FUNCTION__, |
|
| 1660 | - __LINE__ |
|
| 1661 | - ); |
|
| 1662 | - } else { |
|
| 1663 | - EE_Error::add_error( |
|
| 1664 | - esc_html__( |
|
| 1665 | - 'You do not have access to apply payments or refunds to a registration.', |
|
| 1666 | - 'event_espresso' |
|
| 1667 | - ), |
|
| 1668 | - __FILE__, |
|
| 1669 | - __FUNCTION__, |
|
| 1670 | - __LINE__ |
|
| 1671 | - ); |
|
| 1672 | - } |
|
| 1673 | - $notices = EE_Error::get_notices( |
|
| 1674 | - false, |
|
| 1675 | - false, |
|
| 1676 | - false |
|
| 1677 | - ); |
|
| 1678 | - $this->_template_args = array( |
|
| 1679 | - 'data' => $json_response_data, |
|
| 1680 | - 'error' => $notices['errors'], |
|
| 1681 | - 'success' => $notices['success'], |
|
| 1682 | - ); |
|
| 1683 | - $this->_return_json(); |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * _validate_payment_request_data |
|
| 1689 | - * |
|
| 1690 | - * @return array |
|
| 1691 | - * @throws EE_Error |
|
| 1692 | - * @throws InvalidArgumentException |
|
| 1693 | - * @throws InvalidDataTypeException |
|
| 1694 | - * @throws InvalidInterfaceException |
|
| 1695 | - */ |
|
| 1696 | - protected function _validate_payment_request_data() |
|
| 1697 | - { |
|
| 1698 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1699 | - return array(); |
|
| 1700 | - } |
|
| 1701 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1702 | - try { |
|
| 1703 | - if ($payment_form->was_submitted()) { |
|
| 1704 | - $payment_form->receive_form_submission(); |
|
| 1705 | - if (! $payment_form->is_valid()) { |
|
| 1706 | - $submission_error_messages = array(); |
|
| 1707 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1708 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1709 | - $submission_error_messages[] = sprintf( |
|
| 1710 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1711 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1712 | - $validation_error->getMessage() |
|
| 1713 | - ); |
|
| 1714 | - } |
|
| 1715 | - } |
|
| 1716 | - EE_Error::add_error( |
|
| 1717 | - implode('<br />', $submission_error_messages), |
|
| 1718 | - __FILE__, |
|
| 1719 | - __FUNCTION__, |
|
| 1720 | - __LINE__ |
|
| 1721 | - ); |
|
| 1722 | - return array(); |
|
| 1723 | - } |
|
| 1724 | - } |
|
| 1725 | - } catch (EE_Error $e) { |
|
| 1726 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1727 | - return array(); |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - return $payment_form->valid_data(); |
|
| 1731 | - } |
|
| 1732 | - |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * _generate_payment_form_section |
|
| 1736 | - * |
|
| 1737 | - * @return EE_Form_Section_Proper |
|
| 1738 | - * @throws EE_Error |
|
| 1739 | - */ |
|
| 1740 | - protected function _generate_payment_form_section() |
|
| 1741 | - { |
|
| 1742 | - return new EE_Form_Section_Proper( |
|
| 1743 | - array( |
|
| 1744 | - 'name' => 'txn_admin_payment', |
|
| 1745 | - 'subsections' => array( |
|
| 1746 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1747 | - array( |
|
| 1748 | - 'default' => 0, |
|
| 1749 | - 'required' => false, |
|
| 1750 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1751 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1752 | - ) |
|
| 1753 | - ), |
|
| 1754 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1755 | - array( |
|
| 1756 | - 'default' => 0, |
|
| 1757 | - 'required' => true, |
|
| 1758 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1759 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1760 | - ) |
|
| 1761 | - ), |
|
| 1762 | - 'type' => new EE_Text_Input( |
|
| 1763 | - array( |
|
| 1764 | - 'default' => 1, |
|
| 1765 | - 'required' => true, |
|
| 1766 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1767 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1768 | - ) |
|
| 1769 | - ), |
|
| 1770 | - 'amount' => new EE_Text_Input( |
|
| 1771 | - array( |
|
| 1772 | - 'default' => 0, |
|
| 1773 | - 'required' => true, |
|
| 1774 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1775 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1776 | - ) |
|
| 1777 | - ), |
|
| 1778 | - 'status' => new EE_Text_Input( |
|
| 1779 | - array( |
|
| 1780 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1781 | - 'required' => true, |
|
| 1782 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1783 | - ) |
|
| 1784 | - ), |
|
| 1785 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1786 | - array( |
|
| 1787 | - 'default' => 2, |
|
| 1788 | - 'required' => true, |
|
| 1789 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1790 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1791 | - ) |
|
| 1792 | - ), |
|
| 1793 | - 'date' => new EE_Text_Input( |
|
| 1794 | - array( |
|
| 1795 | - 'default' => time(), |
|
| 1796 | - 'required' => true, |
|
| 1797 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1798 | - ) |
|
| 1799 | - ), |
|
| 1800 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1801 | - array( |
|
| 1802 | - 'default' => '', |
|
| 1803 | - 'required' => false, |
|
| 1804 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1805 | - 'validation_strategies' => array( |
|
| 1806 | - new EE_Max_Length_Validation_Strategy( |
|
| 1807 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1808 | - 100 |
|
| 1809 | - ), |
|
| 1810 | - ), |
|
| 1811 | - ) |
|
| 1812 | - ), |
|
| 1813 | - 'po_number' => new EE_Text_Input( |
|
| 1814 | - array( |
|
| 1815 | - 'default' => '', |
|
| 1816 | - 'required' => false, |
|
| 1817 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1818 | - 'validation_strategies' => array( |
|
| 1819 | - new EE_Max_Length_Validation_Strategy( |
|
| 1820 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1821 | - 100 |
|
| 1822 | - ), |
|
| 1823 | - ), |
|
| 1824 | - ) |
|
| 1825 | - ), |
|
| 1826 | - 'accounting' => new EE_Text_Input( |
|
| 1827 | - array( |
|
| 1828 | - 'default' => '', |
|
| 1829 | - 'required' => false, |
|
| 1830 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1831 | - 'validation_strategies' => array( |
|
| 1832 | - new EE_Max_Length_Validation_Strategy( |
|
| 1833 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1834 | - 100 |
|
| 1835 | - ), |
|
| 1836 | - ), |
|
| 1837 | - ) |
|
| 1838 | - ), |
|
| 1839 | - ), |
|
| 1840 | - ) |
|
| 1841 | - ); |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - |
|
| 1845 | - /** |
|
| 1846 | - * _create_payment_from_request_data |
|
| 1847 | - * |
|
| 1848 | - * @param array $valid_data |
|
| 1849 | - * @return EE_Payment |
|
| 1850 | - * @throws EE_Error |
|
| 1851 | - * @throws InvalidArgumentException |
|
| 1852 | - * @throws InvalidDataTypeException |
|
| 1853 | - * @throws InvalidInterfaceException |
|
| 1854 | - * @throws ReflectionException |
|
| 1855 | - */ |
|
| 1856 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1857 | - { |
|
| 1858 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1859 | - // get payment amount |
|
| 1860 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1861 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1862 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1863 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1864 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1865 | - $date = $valid_data['date'] |
|
| 1866 | - ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1867 | - : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1868 | - $payment = EE_Payment::new_instance( |
|
| 1869 | - array( |
|
| 1870 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1871 | - 'STS_ID' => $valid_data['status'], |
|
| 1872 | - 'PAY_timestamp' => $date, |
|
| 1873 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1874 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1875 | - 'PAY_amount' => $amount, |
|
| 1876 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1877 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1878 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1879 | - 'PAY_details' => $valid_data, |
|
| 1880 | - 'PAY_ID' => $PAY_ID, |
|
| 1881 | - ), |
|
| 1882 | - '', |
|
| 1883 | - array('Y-m-d', 'g:i a') |
|
| 1884 | - ); |
|
| 1885 | - |
|
| 1886 | - if (! $payment->save()) { |
|
| 1887 | - EE_Error::add_error( |
|
| 1888 | - sprintf( |
|
| 1889 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1890 | - $payment->ID() |
|
| 1891 | - ), |
|
| 1892 | - __FILE__, |
|
| 1893 | - __FUNCTION__, |
|
| 1894 | - __LINE__ |
|
| 1895 | - ); |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - return $payment; |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - /** |
|
| 1903 | - * _process_transaction_payments |
|
| 1904 | - * |
|
| 1905 | - * @param \EE_Transaction $transaction |
|
| 1906 | - * @return void |
|
| 1907 | - * @throws EE_Error |
|
| 1908 | - * @throws InvalidArgumentException |
|
| 1909 | - * @throws ReflectionException |
|
| 1910 | - * @throws InvalidDataTypeException |
|
| 1911 | - * @throws InvalidInterfaceException |
|
| 1912 | - */ |
|
| 1913 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1914 | - { |
|
| 1915 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1916 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1917 | - // update the transaction with this payment |
|
| 1918 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1919 | - EE_Error::add_success( |
|
| 1920 | - esc_html__( |
|
| 1921 | - 'The payment has been processed successfully.', |
|
| 1922 | - 'event_espresso' |
|
| 1923 | - ), |
|
| 1924 | - __FILE__, |
|
| 1925 | - __FUNCTION__, |
|
| 1926 | - __LINE__ |
|
| 1927 | - ); |
|
| 1928 | - } else { |
|
| 1929 | - EE_Error::add_error( |
|
| 1930 | - esc_html__( |
|
| 1931 | - 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1932 | - 'event_espresso' |
|
| 1933 | - ), |
|
| 1934 | - __FILE__, |
|
| 1935 | - __FUNCTION__, |
|
| 1936 | - __LINE__ |
|
| 1937 | - ); |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - |
|
| 1942 | - /** |
|
| 1943 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1944 | - * returns a list of registration IDs that the payment will apply to |
|
| 1945 | - * |
|
| 1946 | - * @param \EE_Payment $payment |
|
| 1947 | - * @return array |
|
| 1948 | - * @throws EE_Error |
|
| 1949 | - * @throws InvalidArgumentException |
|
| 1950 | - * @throws InvalidDataTypeException |
|
| 1951 | - * @throws InvalidInterfaceException |
|
| 1952 | - * @throws ReflectionException |
|
| 1953 | - */ |
|
| 1954 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1955 | - { |
|
| 1956 | - $REG_IDs = array(); |
|
| 1957 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1958 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1959 | - $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1960 | - } |
|
| 1961 | - // nothing specified ? then get all reg IDs |
|
| 1962 | - if (empty($REG_IDs)) { |
|
| 1963 | - $registrations = $payment->transaction()->registrations(); |
|
| 1964 | - $REG_IDs = ! empty($registrations) |
|
| 1965 | - ? array_keys($registrations) |
|
| 1966 | - : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1970 | - return array_map('intval', $REG_IDs); |
|
| 1971 | - } |
|
| 1972 | - |
|
| 1973 | - |
|
| 1974 | - /** |
|
| 1975 | - * @return array |
|
| 1976 | - */ |
|
| 1977 | - public function existing_reg_payment_REG_IDs() |
|
| 1978 | - { |
|
| 1979 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - |
|
| 1983 | - /** |
|
| 1984 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1985 | - */ |
|
| 1986 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1987 | - { |
|
| 1988 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - |
|
| 1992 | - /** |
|
| 1993 | - * _get_existing_reg_payment_REG_IDs |
|
| 1994 | - * returns a list of registration IDs that the payment is currently related to |
|
| 1995 | - * as recorded in the database |
|
| 1996 | - * |
|
| 1997 | - * @param \EE_Payment $payment |
|
| 1998 | - * @return array |
|
| 1999 | - * @throws EE_Error |
|
| 2000 | - * @throws InvalidArgumentException |
|
| 2001 | - * @throws InvalidDataTypeException |
|
| 2002 | - * @throws InvalidInterfaceException |
|
| 2003 | - * @throws ReflectionException |
|
| 2004 | - */ |
|
| 2005 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 2006 | - { |
|
| 2007 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 2008 | - // let's get any existing reg payment records for this payment |
|
| 2009 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 2010 | - // but we only want the REG IDs, so grab the array keys |
|
| 2011 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 2012 | - ? array_keys($existing_reg_payment_REG_IDs) |
|
| 2013 | - : array(); |
|
| 2014 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 2015 | - } |
|
| 2016 | - |
|
| 2017 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 2018 | - } |
|
| 2019 | - |
|
| 2020 | - |
|
| 2021 | - /** |
|
| 2022 | - * _remove_existing_registration_payments |
|
| 2023 | - * this calculates the difference between existing relations |
|
| 2024 | - * to the supplied payment and the new list registration IDs, |
|
| 2025 | - * removes any related registrations that no longer apply, |
|
| 2026 | - * and then updates the registration paid fields |
|
| 2027 | - * |
|
| 2028 | - * @param \EE_Payment $payment |
|
| 2029 | - * @param int $PAY_ID |
|
| 2030 | - * @return bool; |
|
| 2031 | - * @throws EE_Error |
|
| 2032 | - * @throws InvalidArgumentException |
|
| 2033 | - * @throws ReflectionException |
|
| 2034 | - * @throws InvalidDataTypeException |
|
| 2035 | - * @throws InvalidInterfaceException |
|
| 2036 | - */ |
|
| 2037 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 2038 | - { |
|
| 2039 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 2040 | - if (absint($PAY_ID) === 0) { |
|
| 2041 | - return false; |
|
| 2042 | - } |
|
| 2043 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2044 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 2045 | - return false; |
|
| 2046 | - } |
|
| 2047 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2048 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2049 | - |
|
| 2050 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 2051 | - $payment, |
|
| 2052 | - array( |
|
| 2053 | - array( |
|
| 2054 | - 'PAY_ID' => $payment->ID(), |
|
| 2055 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 2056 | - ), |
|
| 2057 | - ) |
|
| 2058 | - ); |
|
| 2059 | - } |
|
| 2060 | - |
|
| 2061 | - |
|
| 2062 | - /** |
|
| 2063 | - * _update_registration_payments |
|
| 2064 | - * this applies the payments to the selected registrations |
|
| 2065 | - * but only if they have not already been paid for |
|
| 2066 | - * |
|
| 2067 | - * @param EE_Transaction $transaction |
|
| 2068 | - * @param \EE_Payment $payment |
|
| 2069 | - * @param array $REG_IDs |
|
| 2070 | - * @return void |
|
| 2071 | - * @throws EE_Error |
|
| 2072 | - * @throws InvalidArgumentException |
|
| 2073 | - * @throws ReflectionException |
|
| 2074 | - * @throws RuntimeException |
|
| 2075 | - * @throws InvalidDataTypeException |
|
| 2076 | - * @throws InvalidInterfaceException |
|
| 2077 | - */ |
|
| 2078 | - protected function _update_registration_payments( |
|
| 2079 | - EE_Transaction $transaction, |
|
| 2080 | - EE_Payment $payment, |
|
| 2081 | - $REG_IDs = array() |
|
| 2082 | - ) { |
|
| 2083 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 2084 | - // so let's do that using our set of REG_IDs from the form |
|
| 2085 | - $registration_query_where_params = array( |
|
| 2086 | - 'REG_ID' => array('IN', $REG_IDs), |
|
| 2087 | - ); |
|
| 2088 | - // but add in some conditions regarding payment, |
|
| 2089 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 2090 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 2091 | - if (! $payment->is_a_refund()) { |
|
| 2092 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 2093 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 2094 | - } |
|
| 2095 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 2096 | - if (! empty($registrations)) { |
|
| 2097 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 2098 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2099 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 2100 | - } |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - |
|
| 2104 | - /** |
|
| 2105 | - * _process_registration_status_change |
|
| 2106 | - * This processes requested registration status changes for all the registrations |
|
| 2107 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 2108 | - * |
|
| 2109 | - * @param EE_Transaction $transaction |
|
| 2110 | - * @param array $REG_IDs |
|
| 2111 | - * @return bool |
|
| 2112 | - * @throws EE_Error |
|
| 2113 | - * @throws InvalidArgumentException |
|
| 2114 | - * @throws ReflectionException |
|
| 2115 | - * @throws InvalidDataTypeException |
|
| 2116 | - * @throws InvalidInterfaceException |
|
| 2117 | - */ |
|
| 2118 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 2119 | - { |
|
| 2120 | - // first if there is no change in status then we get out. |
|
| 2121 | - if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2122 | - || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 2123 | - ) { |
|
| 2124 | - // no error message, no change requested, just nothing to do man. |
|
| 2125 | - return false; |
|
| 2126 | - } |
|
| 2127 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 2128 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 2129 | - |
|
| 2130 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 2131 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 2132 | - $transaction, |
|
| 2133 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 2134 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 2135 | - ); |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - |
|
| 2139 | - /** |
|
| 2140 | - * _build_payment_json_response |
|
| 2141 | - * |
|
| 2142 | - * @access public |
|
| 2143 | - * @param \EE_Payment $payment |
|
| 2144 | - * @param array $REG_IDs |
|
| 2145 | - * @param bool | null $delete_txn_reg_status_change |
|
| 2146 | - * @return array |
|
| 2147 | - * @throws EE_Error |
|
| 2148 | - * @throws InvalidArgumentException |
|
| 2149 | - * @throws InvalidDataTypeException |
|
| 2150 | - * @throws InvalidInterfaceException |
|
| 2151 | - * @throws ReflectionException |
|
| 2152 | - */ |
|
| 2153 | - protected function _build_payment_json_response( |
|
| 2154 | - EE_Payment $payment, |
|
| 2155 | - $REG_IDs = array(), |
|
| 2156 | - $delete_txn_reg_status_change = null |
|
| 2157 | - ) { |
|
| 2158 | - // was the payment deleted ? |
|
| 2159 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 2160 | - return array( |
|
| 2161 | - 'PAY_ID' => $payment->ID(), |
|
| 2162 | - 'amount' => $payment->amount(), |
|
| 2163 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2164 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2165 | - 'pay_status' => $payment->STS_ID(), |
|
| 2166 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2167 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2168 | - ); |
|
| 2169 | - } else { |
|
| 2170 | - $this->_get_payment_status_array(); |
|
| 2171 | - |
|
| 2172 | - return array( |
|
| 2173 | - 'amount' => $payment->amount(), |
|
| 2174 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2175 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2176 | - 'pay_status' => $payment->STS_ID(), |
|
| 2177 | - 'PAY_ID' => $payment->ID(), |
|
| 2178 | - 'STS_ID' => $payment->STS_ID(), |
|
| 2179 | - 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2180 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2181 | - 'method' => strtoupper($payment->source()), |
|
| 2182 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2183 | - 'gateway' => $payment->payment_method() |
|
| 2184 | - ? $payment->payment_method()->admin_name() |
|
| 2185 | - : esc_html__('Unknown', 'event_espresso'), |
|
| 2186 | - 'gateway_response' => $payment->gateway_response(), |
|
| 2187 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2188 | - 'po_number' => $payment->po_number(), |
|
| 2189 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 2190 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2191 | - ); |
|
| 2192 | - } |
|
| 2193 | - } |
|
| 2194 | - |
|
| 2195 | - |
|
| 2196 | - /** |
|
| 2197 | - * delete_payment |
|
| 2198 | - * delete a payment or refund made towards a transaction |
|
| 2199 | - * |
|
| 2200 | - * @access public |
|
| 2201 | - * @return void |
|
| 2202 | - * @throws EE_Error |
|
| 2203 | - * @throws InvalidArgumentException |
|
| 2204 | - * @throws ReflectionException |
|
| 2205 | - * @throws InvalidDataTypeException |
|
| 2206 | - * @throws InvalidInterfaceException |
|
| 2207 | - */ |
|
| 2208 | - public function delete_payment() |
|
| 2209 | - { |
|
| 2210 | - $json_response_data = array('return_data' => false); |
|
| 2211 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2212 | - ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2213 | - : 0; |
|
| 2214 | - $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2215 | - 'ee_delete_payments', |
|
| 2216 | - 'delete_payment_from_registration_details' |
|
| 2217 | - ); |
|
| 2218 | - if ($PAY_ID && $can_delete) { |
|
| 2219 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2220 | - ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2221 | - : false; |
|
| 2222 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2223 | - if ($payment instanceof EE_Payment) { |
|
| 2224 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2225 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2226 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2227 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2228 | - $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2229 | - $payment, |
|
| 2230 | - $REG_IDs, |
|
| 2231 | - $delete_txn_reg_status_change |
|
| 2232 | - ); |
|
| 2233 | - if ($delete_txn_reg_status_change) { |
|
| 2234 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2235 | - // MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2236 | - // $_REQUEST global because that's how messages will be looking for it. |
|
| 2237 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2238 | - $this->_maybe_send_notifications(); |
|
| 2239 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2240 | - } |
|
| 2241 | - } |
|
| 2242 | - } else { |
|
| 2243 | - EE_Error::add_error( |
|
| 2244 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2245 | - __FILE__, |
|
| 2246 | - __FUNCTION__, |
|
| 2247 | - __LINE__ |
|
| 2248 | - ); |
|
| 2249 | - } |
|
| 2250 | - } elseif ($can_delete) { |
|
| 2251 | - EE_Error::add_error( |
|
| 2252 | - esc_html__( |
|
| 2253 | - 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2254 | - 'event_espresso' |
|
| 2255 | - ), |
|
| 2256 | - __FILE__, |
|
| 2257 | - __FUNCTION__, |
|
| 2258 | - __LINE__ |
|
| 2259 | - ); |
|
| 2260 | - } else { |
|
| 2261 | - EE_Error::add_error( |
|
| 2262 | - esc_html__( |
|
| 2263 | - 'You do not have access to delete a payment.', |
|
| 2264 | - 'event_espresso' |
|
| 2265 | - ), |
|
| 2266 | - __FILE__, |
|
| 2267 | - __FUNCTION__, |
|
| 2268 | - __LINE__ |
|
| 2269 | - ); |
|
| 2270 | - } |
|
| 2271 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 2272 | - $this->_template_args = array( |
|
| 2273 | - 'data' => $json_response_data, |
|
| 2274 | - 'success' => $notices['success'], |
|
| 2275 | - 'error' => $notices['errors'], |
|
| 2276 | - 'attention' => $notices['attention'], |
|
| 2277 | - ); |
|
| 2278 | - $this->_return_json(); |
|
| 2279 | - } |
|
| 2280 | - |
|
| 2281 | - |
|
| 2282 | - /** |
|
| 2283 | - * _registration_payment_data_array |
|
| 2284 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2285 | - * |
|
| 2286 | - * @access protected |
|
| 2287 | - * @param array $REG_IDs |
|
| 2288 | - * @return array |
|
| 2289 | - * @throws EE_Error |
|
| 2290 | - * @throws InvalidArgumentException |
|
| 2291 | - * @throws InvalidDataTypeException |
|
| 2292 | - * @throws InvalidInterfaceException |
|
| 2293 | - * @throws ReflectionException |
|
| 2294 | - */ |
|
| 2295 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 2296 | - { |
|
| 2297 | - $registration_payment_data = array(); |
|
| 2298 | - // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2299 | - if (! empty($REG_IDs)) { |
|
| 2300 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2301 | - foreach ($registrations as $registration) { |
|
| 2302 | - if ($registration instanceof EE_Registration) { |
|
| 2303 | - $registration_payment_data[ $registration->ID() ] = array( |
|
| 2304 | - 'paid' => $registration->pretty_paid(), |
|
| 2305 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2306 | - ); |
|
| 2307 | - } |
|
| 2308 | - } |
|
| 2309 | - } |
|
| 2310 | - |
|
| 2311 | - return $registration_payment_data; |
|
| 2312 | - } |
|
| 2313 | - |
|
| 2314 | - |
|
| 2315 | - /** |
|
| 2316 | - * _maybe_send_notifications |
|
| 2317 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2318 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 2319 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2320 | - * |
|
| 2321 | - * @access protected |
|
| 2322 | - * @param \EE_Payment | null $payment |
|
| 2323 | - */ |
|
| 2324 | - protected function _maybe_send_notifications($payment = null) |
|
| 2325 | - { |
|
| 2326 | - switch ($payment instanceof EE_Payment) { |
|
| 2327 | - // payment notifications |
|
| 2328 | - case true: |
|
| 2329 | - if (isset($this->_req_data['txn_payments']['send_notifications']) |
|
| 2330 | - && filter_var( |
|
| 2331 | - $this->_req_data['txn_payments']['send_notifications'], |
|
| 2332 | - FILTER_VALIDATE_BOOLEAN |
|
| 2333 | - ) |
|
| 2334 | - ) { |
|
| 2335 | - $this->_process_payment_notification($payment); |
|
| 2336 | - } |
|
| 2337 | - break; |
|
| 2338 | - // registration notifications |
|
| 2339 | - case false: |
|
| 2340 | - if (isset($this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2341 | - && filter_var( |
|
| 2342 | - $this->_req_data['txn_reg_status_change']['send_notifications'], |
|
| 2343 | - FILTER_VALIDATE_BOOLEAN |
|
| 2344 | - ) |
|
| 2345 | - ) { |
|
| 2346 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2347 | - } |
|
| 2348 | - break; |
|
| 2349 | - } |
|
| 2350 | - } |
|
| 2351 | - |
|
| 2352 | - |
|
| 2353 | - /** |
|
| 2354 | - * _send_payment_reminder |
|
| 2355 | - * generates HTML for the View Transaction Details Admin page |
|
| 2356 | - * |
|
| 2357 | - * @access protected |
|
| 2358 | - * @return void |
|
| 2359 | - * @throws EE_Error |
|
| 2360 | - * @throws InvalidArgumentException |
|
| 2361 | - * @throws InvalidDataTypeException |
|
| 2362 | - * @throws InvalidInterfaceException |
|
| 2363 | - */ |
|
| 2364 | - protected function _send_payment_reminder() |
|
| 2365 | - { |
|
| 2366 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2367 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2368 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2369 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2370 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2371 | - ) : array(); |
|
| 2372 | - do_action( |
|
| 2373 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2374 | - $transaction |
|
| 2375 | - ); |
|
| 2376 | - $this->_redirect_after_action( |
|
| 2377 | - false, |
|
| 2378 | - esc_html__('payment reminder', 'event_espresso'), |
|
| 2379 | - esc_html__('sent', 'event_espresso'), |
|
| 2380 | - $query_args, |
|
| 2381 | - true |
|
| 2382 | - ); |
|
| 2383 | - } |
|
| 2384 | - |
|
| 2385 | - |
|
| 2386 | - /** |
|
| 2387 | - * get_transactions |
|
| 2388 | - * get transactions for given parameters (used by list table) |
|
| 2389 | - * |
|
| 2390 | - * @param int $perpage how many transactions displayed per page |
|
| 2391 | - * @param boolean $count return the count or objects |
|
| 2392 | - * @param string $view |
|
| 2393 | - * @return mixed int = count || array of transaction objects |
|
| 2394 | - * @throws EE_Error |
|
| 2395 | - * @throws InvalidArgumentException |
|
| 2396 | - * @throws InvalidDataTypeException |
|
| 2397 | - * @throws InvalidInterfaceException |
|
| 2398 | - */ |
|
| 2399 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 2400 | - { |
|
| 2401 | - |
|
| 2402 | - $TXN = EEM_Transaction::instance(); |
|
| 2403 | - |
|
| 2404 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2405 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2406 | - : date( |
|
| 2407 | - 'm/d/Y', |
|
| 2408 | - strtotime('-10 year') |
|
| 2409 | - ); |
|
| 2410 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2411 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2412 | - : date('m/d/Y'); |
|
| 2413 | - |
|
| 2414 | - // make sure our timestamps start and end right at the boundaries for each day |
|
| 2415 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2416 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - // convert to timestamps |
|
| 2420 | - $start_date = strtotime($start_date); |
|
| 2421 | - $end_date = strtotime($end_date); |
|
| 2422 | - |
|
| 2423 | - // makes sure start date is the lowest value and vice versa |
|
| 2424 | - $start_date = min($start_date, $end_date); |
|
| 2425 | - $end_date = max($start_date, $end_date); |
|
| 2426 | - |
|
| 2427 | - // convert to correct format for query |
|
| 2428 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2429 | - 'TXN_timestamp', |
|
| 2430 | - date('Y-m-d H:i:s', $start_date), |
|
| 2431 | - 'Y-m-d H:i:s' |
|
| 2432 | - ); |
|
| 2433 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2434 | - 'TXN_timestamp', |
|
| 2435 | - date('Y-m-d H:i:s', $end_date), |
|
| 2436 | - 'Y-m-d H:i:s' |
|
| 2437 | - ); |
|
| 2438 | - |
|
| 2439 | - |
|
| 2440 | - // set orderby |
|
| 2441 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2442 | - |
|
| 2443 | - switch ($this->_req_data['orderby']) { |
|
| 2444 | - case 'TXN_ID': |
|
| 2445 | - $orderby = 'TXN_ID'; |
|
| 2446 | - break; |
|
| 2447 | - case 'ATT_fname': |
|
| 2448 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2449 | - break; |
|
| 2450 | - case 'event_name': |
|
| 2451 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 2452 | - break; |
|
| 2453 | - default: // 'TXN_timestamp' |
|
| 2454 | - $orderby = 'TXN_timestamp'; |
|
| 2455 | - } |
|
| 2456 | - |
|
| 2457 | - $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2458 | - $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2459 | - $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2460 | - $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2461 | - |
|
| 2462 | - $offset = ($current_page - 1) * $per_page; |
|
| 2463 | - $limit = array($offset, $per_page); |
|
| 2464 | - |
|
| 2465 | - $_where = array( |
|
| 2466 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2467 | - 'Registration.REG_count' => 1, |
|
| 2468 | - ); |
|
| 2469 | - |
|
| 2470 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 2471 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2472 | - } |
|
| 2473 | - |
|
| 2474 | - if (isset($this->_req_data['s'])) { |
|
| 2475 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2476 | - $_where['OR'] = array( |
|
| 2477 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2478 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2479 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2480 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2481 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2482 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2483 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2484 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2485 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2486 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2487 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2488 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2489 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2490 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2491 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2492 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2493 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2494 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2495 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2496 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2497 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2498 | - ); |
|
| 2499 | - } |
|
| 2500 | - |
|
| 2501 | - // failed transactions |
|
| 2502 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2503 | - || ($count && $view === 'failed'); |
|
| 2504 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2505 | - || ($count && $view === 'abandoned'); |
|
| 2506 | - $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2507 | - || ($count && $view === 'incomplete'); |
|
| 2508 | - |
|
| 2509 | - if ($failed) { |
|
| 2510 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2511 | - } elseif ($abandoned) { |
|
| 2512 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2513 | - } elseif ($incomplete) { |
|
| 2514 | - $_where['STS_ID'] = EEM_Transaction::incomplete_status_code; |
|
| 2515 | - } else { |
|
| 2516 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2517 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - $query_params = apply_filters( |
|
| 2521 | - 'FHEE__Transactions_Admin_Page___get_transactions_query_params', |
|
| 2522 | - array( |
|
| 2523 | - $_where, |
|
| 2524 | - 'order_by' => array($orderby => $sort), |
|
| 2525 | - 'limit' => $limit, |
|
| 2526 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2527 | - ), |
|
| 2528 | - $this->_req_data, |
|
| 2529 | - $view, |
|
| 2530 | - $count |
|
| 2531 | - ); |
|
| 2532 | - |
|
| 2533 | - $transactions = $count |
|
| 2534 | - ? $TXN->count(array($query_params[0]), 'TXN_ID', true) |
|
| 2535 | - : $TXN->get_all($query_params); |
|
| 2536 | - |
|
| 2537 | - return $transactions; |
|
| 2538 | - } |
|
| 2539 | - |
|
| 2540 | - |
|
| 2541 | - /** |
|
| 2542 | - * @since 4.9.79.p |
|
| 2543 | - * @throws EE_Error |
|
| 2544 | - * @throws InvalidArgumentException |
|
| 2545 | - * @throws InvalidDataTypeException |
|
| 2546 | - * @throws InvalidInterfaceException |
|
| 2547 | - * @throws ReflectionException |
|
| 2548 | - * @throws RuntimeException |
|
| 2549 | - */ |
|
| 2550 | - public function recalculateLineItems() |
|
| 2551 | - { |
|
| 2552 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2553 | - /** @var EE_Transaction $transaction */ |
|
| 2554 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2555 | - $total_line_item = $transaction->total_line_item(false); |
|
| 2556 | - $success = false; |
|
| 2557 | - if ($total_line_item instanceof EE_Line_Item) { |
|
| 2558 | - EEH_Line_Item::resetIsTaxableForTickets($total_line_item); |
|
| 2559 | - $success = EEH_Line_Item::apply_taxes($total_line_item, true); |
|
| 2560 | - } |
|
| 2561 | - $this->_redirect_after_action( |
|
| 2562 | - (bool) $success, |
|
| 2563 | - esc_html__('Transaction taxes and totals', 'event_espresso'), |
|
| 2564 | - esc_html__('recalculated', 'event_espresso'), |
|
| 2565 | - isset($this->_req_data['redirect_to']) |
|
| 2566 | - ? array( |
|
| 2567 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2568 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2569 | - ) |
|
| 2570 | - : array(), |
|
| 2571 | - true |
|
| 2572 | - ); |
|
| 2573 | - } |
|
| 16 | + /** |
|
| 17 | + * @var EE_Transaction |
|
| 18 | + */ |
|
| 19 | + private $_transaction; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var EE_Session |
|
| 23 | + */ |
|
| 24 | + private $_session; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var array $_txn_status |
|
| 28 | + */ |
|
| 29 | + private static $_txn_status; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array $_pay_status |
|
| 33 | + */ |
|
| 34 | + private static $_pay_status; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 38 | + */ |
|
| 39 | + protected $_existing_reg_payment_REG_IDs; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * _init_page_props |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + protected function _init_page_props() |
|
| 48 | + { |
|
| 49 | + $this->page_slug = TXN_PG_SLUG; |
|
| 50 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 51 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 52 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * _ajax_hooks |
|
| 58 | + * |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + protected function _ajax_hooks() |
|
| 62 | + { |
|
| 63 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 64 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 65 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * _define_page_props |
|
| 71 | + * |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + protected function _define_page_props() |
|
| 75 | + { |
|
| 76 | + $this->_admin_page_title = $this->page_label; |
|
| 77 | + $this->_labels = array( |
|
| 78 | + 'buttons' => array( |
|
| 79 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 80 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 81 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 82 | + ), |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * grab url requests and route them |
|
| 89 | + * |
|
| 90 | + * @access private |
|
| 91 | + * @return void |
|
| 92 | + * @throws EE_Error |
|
| 93 | + * @throws InvalidArgumentException |
|
| 94 | + * @throws InvalidDataTypeException |
|
| 95 | + * @throws InvalidInterfaceException |
|
| 96 | + */ |
|
| 97 | + public function _set_page_routes() |
|
| 98 | + { |
|
| 99 | + |
|
| 100 | + $this->_set_transaction_status_array(); |
|
| 101 | + |
|
| 102 | + $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 103 | + && ! is_array($this->_req_data['TXN_ID']) |
|
| 104 | + ? $this->_req_data['TXN_ID'] |
|
| 105 | + : 0; |
|
| 106 | + |
|
| 107 | + $this->_page_routes = array( |
|
| 108 | + |
|
| 109 | + 'default' => array( |
|
| 110 | + 'func' => '_transactions_overview_list_table', |
|
| 111 | + 'capability' => 'ee_read_transactions', |
|
| 112 | + ), |
|
| 113 | + |
|
| 114 | + 'view_transaction' => array( |
|
| 115 | + 'func' => '_transaction_details', |
|
| 116 | + 'capability' => 'ee_read_transaction', |
|
| 117 | + 'obj_id' => $txn_id, |
|
| 118 | + ), |
|
| 119 | + |
|
| 120 | + 'send_payment_reminder' => array( |
|
| 121 | + 'func' => '_send_payment_reminder', |
|
| 122 | + 'noheader' => true, |
|
| 123 | + 'capability' => 'ee_send_message', |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'espresso_apply_payment' => array( |
|
| 127 | + 'func' => 'apply_payments_or_refunds', |
|
| 128 | + 'noheader' => true, |
|
| 129 | + 'capability' => 'ee_edit_payments', |
|
| 130 | + ), |
|
| 131 | + |
|
| 132 | + 'espresso_apply_refund' => array( |
|
| 133 | + 'func' => 'apply_payments_or_refunds', |
|
| 134 | + 'noheader' => true, |
|
| 135 | + 'capability' => 'ee_edit_payments', |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'espresso_delete_payment' => array( |
|
| 139 | + 'func' => 'delete_payment', |
|
| 140 | + 'noheader' => true, |
|
| 141 | + 'capability' => 'ee_delete_payments', |
|
| 142 | + ), |
|
| 143 | + |
|
| 144 | + 'espresso_recalculate_line_items' => array( |
|
| 145 | + 'func' => 'recalculateLineItems', |
|
| 146 | + 'noheader' => true, |
|
| 147 | + 'capability' => 'ee_edit_payments', |
|
| 148 | + ), |
|
| 149 | + |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + protected function _set_page_config() |
|
| 155 | + { |
|
| 156 | + $this->_page_config = array( |
|
| 157 | + 'default' => array( |
|
| 158 | + 'nav' => array( |
|
| 159 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 160 | + 'order' => 10, |
|
| 161 | + ), |
|
| 162 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 163 | + 'help_tabs' => array( |
|
| 164 | + 'transactions_overview_help_tab' => array( |
|
| 165 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 166 | + 'filename' => 'transactions_overview', |
|
| 167 | + ), |
|
| 168 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 169 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 170 | + 'filename' => 'transactions_overview_table_column_headings', |
|
| 171 | + ), |
|
| 172 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 173 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 174 | + 'filename' => 'transactions_overview_views_filters_search', |
|
| 175 | + ), |
|
| 176 | + ), |
|
| 177 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 178 | + /** |
|
| 179 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 180 | + * may change in a later iteration so want to keep the code for then. |
|
| 181 | + */ |
|
| 182 | + // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 183 | + 'require_nonce' => false, |
|
| 184 | + ), |
|
| 185 | + 'view_transaction' => array( |
|
| 186 | + 'nav' => array( |
|
| 187 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 188 | + 'order' => 5, |
|
| 189 | + 'url' => isset($this->_req_data['TXN_ID']) |
|
| 190 | + ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 191 | + : $this->_admin_base_url, |
|
| 192 | + 'persistent' => false, |
|
| 193 | + ), |
|
| 194 | + 'help_tabs' => array( |
|
| 195 | + 'transactions_view_transaction_help_tab' => array( |
|
| 196 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 197 | + 'filename' => 'transactions_view_transaction', |
|
| 198 | + ), |
|
| 199 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 200 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 201 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 202 | + ), |
|
| 203 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 204 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 205 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 206 | + ), |
|
| 207 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 208 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 209 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 210 | + ), |
|
| 211 | + ), |
|
| 212 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 213 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 214 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 215 | + |
|
| 216 | + 'require_nonce' => false, |
|
| 217 | + ), |
|
| 218 | + ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * The below methods aren't used by this class currently |
|
| 224 | + */ |
|
| 225 | + protected function _add_screen_options() |
|
| 226 | + { |
|
| 227 | + // noop |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + protected function _add_feature_pointers() |
|
| 232 | + { |
|
| 233 | + // noop |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + public function admin_init() |
|
| 238 | + { |
|
| 239 | + // IF a registration was JUST added via the admin... |
|
| 240 | + if (isset( |
|
| 241 | + $this->_req_data['redirect_from'], |
|
| 242 | + $this->_req_data['EVT_ID'], |
|
| 243 | + $this->_req_data['event_name'] |
|
| 244 | + )) { |
|
| 245 | + // then set a cookie so that we can block any attempts to use |
|
| 246 | + // the back button as a way to enter another registration. |
|
| 247 | + setcookie( |
|
| 248 | + 'ee_registration_added', |
|
| 249 | + $this->_req_data['EVT_ID'], |
|
| 250 | + time() + WEEK_IN_SECONDS, |
|
| 251 | + '/' |
|
| 252 | + ); |
|
| 253 | + // and update the global |
|
| 254 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 255 | + } |
|
| 256 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 257 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 258 | + 'event_espresso' |
|
| 259 | + ); |
|
| 260 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 261 | + 'An error occurred! Please refresh the page and try again.', |
|
| 262 | + 'event_espresso' |
|
| 263 | + ); |
|
| 264 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 268 | + 'This transaction has been overpaid ! Payments Total', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + public function admin_notices() |
|
| 275 | + { |
|
| 276 | + // noop |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + public function admin_footer_scripts() |
|
| 281 | + { |
|
| 282 | + // noop |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * _set_transaction_status_array |
|
| 288 | + * sets list of transaction statuses |
|
| 289 | + * |
|
| 290 | + * @access private |
|
| 291 | + * @return void |
|
| 292 | + * @throws EE_Error |
|
| 293 | + * @throws InvalidArgumentException |
|
| 294 | + * @throws InvalidDataTypeException |
|
| 295 | + * @throws InvalidInterfaceException |
|
| 296 | + */ |
|
| 297 | + private function _set_transaction_status_array() |
|
| 298 | + { |
|
| 299 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * get_transaction_status_array |
|
| 305 | + * return the transaction status array for wp_list_table |
|
| 306 | + * |
|
| 307 | + * @access public |
|
| 308 | + * @return array |
|
| 309 | + */ |
|
| 310 | + public function get_transaction_status_array() |
|
| 311 | + { |
|
| 312 | + return self::$_txn_status; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * get list of payment statuses |
|
| 318 | + * |
|
| 319 | + * @access private |
|
| 320 | + * @return void |
|
| 321 | + * @throws EE_Error |
|
| 322 | + * @throws InvalidArgumentException |
|
| 323 | + * @throws InvalidDataTypeException |
|
| 324 | + * @throws InvalidInterfaceException |
|
| 325 | + */ |
|
| 326 | + private function _get_payment_status_array() |
|
| 327 | + { |
|
| 328 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 329 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * _add_screen_options_default |
|
| 335 | + * |
|
| 336 | + * @access protected |
|
| 337 | + * @return void |
|
| 338 | + * @throws InvalidArgumentException |
|
| 339 | + * @throws InvalidDataTypeException |
|
| 340 | + * @throws InvalidInterfaceException |
|
| 341 | + */ |
|
| 342 | + protected function _add_screen_options_default() |
|
| 343 | + { |
|
| 344 | + $this->_per_page_screen_option(); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * load_scripts_styles |
|
| 350 | + * |
|
| 351 | + * @access public |
|
| 352 | + * @return void |
|
| 353 | + */ |
|
| 354 | + public function load_scripts_styles() |
|
| 355 | + { |
|
| 356 | + // enqueue style |
|
| 357 | + wp_register_style( |
|
| 358 | + 'espresso_txn', |
|
| 359 | + TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 360 | + array(), |
|
| 361 | + EVENT_ESPRESSO_VERSION |
|
| 362 | + ); |
|
| 363 | + wp_enqueue_style('espresso_txn'); |
|
| 364 | + // scripts |
|
| 365 | + wp_register_script( |
|
| 366 | + 'espresso_txn', |
|
| 367 | + TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 368 | + array( |
|
| 369 | + 'ee_admin_js', |
|
| 370 | + 'ee-datepicker', |
|
| 371 | + 'jquery-ui-datepicker', |
|
| 372 | + 'jquery-ui-draggable', |
|
| 373 | + 'ee-dialog', |
|
| 374 | + 'ee-accounting', |
|
| 375 | + 'ee-serialize-full-array', |
|
| 376 | + ), |
|
| 377 | + EVENT_ESPRESSO_VERSION, |
|
| 378 | + true |
|
| 379 | + ); |
|
| 380 | + wp_enqueue_script('espresso_txn'); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * load_scripts_styles_view_transaction |
|
| 386 | + * |
|
| 387 | + * @access public |
|
| 388 | + * @return void |
|
| 389 | + */ |
|
| 390 | + public function load_scripts_styles_view_transaction() |
|
| 391 | + { |
|
| 392 | + // styles |
|
| 393 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * load_scripts_styles_default |
|
| 399 | + * |
|
| 400 | + * @access public |
|
| 401 | + * @return void |
|
| 402 | + */ |
|
| 403 | + public function load_scripts_styles_default() |
|
| 404 | + { |
|
| 405 | + // styles |
|
| 406 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * _set_list_table_views_default |
|
| 412 | + * |
|
| 413 | + * @access protected |
|
| 414 | + * @return void |
|
| 415 | + */ |
|
| 416 | + protected function _set_list_table_views_default() |
|
| 417 | + { |
|
| 418 | + $this->_views = array( |
|
| 419 | + 'all' => array( |
|
| 420 | + 'slug' => 'all', |
|
| 421 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 422 | + 'count' => 0, |
|
| 423 | + ), |
|
| 424 | + 'abandoned' => array( |
|
| 425 | + 'slug' => 'abandoned', |
|
| 426 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 427 | + 'count' => 0, |
|
| 428 | + ), |
|
| 429 | + 'incomplete' => array( |
|
| 430 | + 'slug' => 'incomplete', |
|
| 431 | + 'label' => esc_html__('Incomplete Transactions', 'event_espresso'), |
|
| 432 | + 'count' => 0, |
|
| 433 | + ), |
|
| 434 | + ); |
|
| 435 | + if (/** |
|
| 436 | + * Filters whether a link to the "Failed Transactions" list table |
|
| 437 | + * appears on the Transactions Admin Page list table. |
|
| 438 | + * List display can be turned back on via the following: |
|
| 439 | + * add_filter( |
|
| 440 | + * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 441 | + * '__return_true' |
|
| 442 | + * ); |
|
| 443 | + * |
|
| 444 | + * @since 4.9.70.p |
|
| 445 | + * @param boolean $display_failed_txns_list |
|
| 446 | + * @param Transactions_Admin_Page $this |
|
| 447 | + */ |
|
| 448 | + apply_filters( |
|
| 449 | + 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 450 | + false, |
|
| 451 | + $this |
|
| 452 | + ) |
|
| 453 | + ) { |
|
| 454 | + $this->_views['failed'] = array( |
|
| 455 | + 'slug' => 'failed', |
|
| 456 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 457 | + 'count' => 0, |
|
| 458 | + ); |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * _set_transaction_object |
|
| 465 | + * This sets the _transaction property for the transaction details screen |
|
| 466 | + * |
|
| 467 | + * @access private |
|
| 468 | + * @return void |
|
| 469 | + * @throws EE_Error |
|
| 470 | + * @throws InvalidArgumentException |
|
| 471 | + * @throws RuntimeException |
|
| 472 | + * @throws InvalidDataTypeException |
|
| 473 | + * @throws InvalidInterfaceException |
|
| 474 | + * @throws ReflectionException |
|
| 475 | + */ |
|
| 476 | + private function _set_transaction_object() |
|
| 477 | + { |
|
| 478 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 479 | + return; |
|
| 480 | + } //get out we've already set the object |
|
| 481 | + |
|
| 482 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 483 | + ? absint($this->_req_data['TXN_ID']) |
|
| 484 | + : false; |
|
| 485 | + |
|
| 486 | + // get transaction object |
|
| 487 | + $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 488 | + $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 489 | + ? $this->_transaction->session_data() |
|
| 490 | + : null; |
|
| 491 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 492 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 496 | + $error_msg = sprintf( |
|
| 497 | + esc_html__( |
|
| 498 | + 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 499 | + 'event_espresso' |
|
| 500 | + ), |
|
| 501 | + $TXN_ID |
|
| 502 | + ); |
|
| 503 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * _transaction_legend_items |
|
| 510 | + * |
|
| 511 | + * @access protected |
|
| 512 | + * @return array |
|
| 513 | + * @throws EE_Error |
|
| 514 | + * @throws InvalidArgumentException |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + * @throws InvalidDataTypeException |
|
| 517 | + * @throws InvalidInterfaceException |
|
| 518 | + */ |
|
| 519 | + protected function _transaction_legend_items() |
|
| 520 | + { |
|
| 521 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 522 | + $items = array(); |
|
| 523 | + |
|
| 524 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 525 | + 'ee_read_global_messages', |
|
| 526 | + 'view_filtered_messages' |
|
| 527 | + )) { |
|
| 528 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 529 | + if (is_array($related_for_icon) |
|
| 530 | + && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 531 | + ) { |
|
| 532 | + $items['view_related_messages'] = array( |
|
| 533 | + 'class' => $related_for_icon['css_class'], |
|
| 534 | + 'desc' => $related_for_icon['label'], |
|
| 535 | + ); |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + $items = apply_filters( |
|
| 540 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 541 | + array_merge( |
|
| 542 | + $items, |
|
| 543 | + array( |
|
| 544 | + 'view_details' => array( |
|
| 545 | + 'class' => 'dashicons dashicons-cart', |
|
| 546 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 547 | + ), |
|
| 548 | + 'view_invoice' => array( |
|
| 549 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 550 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 551 | + ), |
|
| 552 | + 'view_receipt' => array( |
|
| 553 | + 'class' => 'dashicons dashicons-media-default', |
|
| 554 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 555 | + ), |
|
| 556 | + 'view_registration' => array( |
|
| 557 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 558 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 559 | + ), |
|
| 560 | + 'payment_overview_link' => array( |
|
| 561 | + 'class' => 'dashicons dashicons-money', |
|
| 562 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 563 | + ), |
|
| 564 | + ) |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + |
|
| 568 | + if (EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 569 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 570 | + 'ee_send_message', |
|
| 571 | + 'espresso_transactions_send_payment_reminder' |
|
| 572 | + ) |
|
| 573 | + ) { |
|
| 574 | + $items['send_payment_reminder'] = array( |
|
| 575 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 576 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 577 | + ); |
|
| 578 | + } else { |
|
| 579 | + $items['blank*'] = array( |
|
| 580 | + 'class' => '', |
|
| 581 | + 'desc' => '', |
|
| 582 | + ); |
|
| 583 | + } |
|
| 584 | + $more_items = apply_filters( |
|
| 585 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 586 | + array( |
|
| 587 | + 'overpaid' => array( |
|
| 588 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 589 | + 'desc' => EEH_Template::pretty_status( |
|
| 590 | + EEM_Transaction::overpaid_status_code, |
|
| 591 | + false, |
|
| 592 | + 'sentence' |
|
| 593 | + ), |
|
| 594 | + ), |
|
| 595 | + 'complete' => array( |
|
| 596 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 597 | + 'desc' => EEH_Template::pretty_status( |
|
| 598 | + EEM_Transaction::complete_status_code, |
|
| 599 | + false, |
|
| 600 | + 'sentence' |
|
| 601 | + ), |
|
| 602 | + ), |
|
| 603 | + 'incomplete' => array( |
|
| 604 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 605 | + 'desc' => EEH_Template::pretty_status( |
|
| 606 | + EEM_Transaction::incomplete_status_code, |
|
| 607 | + false, |
|
| 608 | + 'sentence' |
|
| 609 | + ), |
|
| 610 | + ), |
|
| 611 | + 'abandoned' => array( |
|
| 612 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 613 | + 'desc' => EEH_Template::pretty_status( |
|
| 614 | + EEM_Transaction::abandoned_status_code, |
|
| 615 | + false, |
|
| 616 | + 'sentence' |
|
| 617 | + ), |
|
| 618 | + ), |
|
| 619 | + 'failed' => array( |
|
| 620 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 621 | + 'desc' => EEH_Template::pretty_status( |
|
| 622 | + EEM_Transaction::failed_status_code, |
|
| 623 | + false, |
|
| 624 | + 'sentence' |
|
| 625 | + ), |
|
| 626 | + ), |
|
| 627 | + ) |
|
| 628 | + ); |
|
| 629 | + |
|
| 630 | + return array_merge($items, $more_items); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * _transactions_overview_list_table |
|
| 636 | + * |
|
| 637 | + * @access protected |
|
| 638 | + * @return void |
|
| 639 | + * @throws DomainException |
|
| 640 | + * @throws EE_Error |
|
| 641 | + * @throws InvalidArgumentException |
|
| 642 | + * @throws InvalidDataTypeException |
|
| 643 | + * @throws InvalidInterfaceException |
|
| 644 | + * @throws ReflectionException |
|
| 645 | + */ |
|
| 646 | + protected function _transactions_overview_list_table() |
|
| 647 | + { |
|
| 648 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 649 | + $event = isset($this->_req_data['EVT_ID']) |
|
| 650 | + ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 651 | + : null; |
|
| 652 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 653 | + ? sprintf( |
|
| 654 | + esc_html__( |
|
| 655 | + '%sViewing Transactions for the Event: %s%s', |
|
| 656 | + 'event_espresso' |
|
| 657 | + ), |
|
| 658 | + '<h3>', |
|
| 659 | + '<a href="' |
|
| 660 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 661 | + array('action' => 'edit', 'post' => $event->ID()), |
|
| 662 | + EVENTS_ADMIN_URL |
|
| 663 | + ) |
|
| 664 | + . '" title="' |
|
| 665 | + . esc_attr__( |
|
| 666 | + 'Click to Edit event', |
|
| 667 | + 'event_espresso' |
|
| 668 | + ) |
|
| 669 | + . '">' . $event->name() . '</a>', |
|
| 670 | + '</h3>' |
|
| 671 | + ) |
|
| 672 | + : ''; |
|
| 673 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 674 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * _transaction_details |
|
| 680 | + * generates HTML for the View Transaction Details Admin page |
|
| 681 | + * |
|
| 682 | + * @access protected |
|
| 683 | + * @return void |
|
| 684 | + * @throws DomainException |
|
| 685 | + * @throws EE_Error |
|
| 686 | + * @throws InvalidArgumentException |
|
| 687 | + * @throws InvalidDataTypeException |
|
| 688 | + * @throws InvalidInterfaceException |
|
| 689 | + * @throws RuntimeException |
|
| 690 | + * @throws ReflectionException |
|
| 691 | + */ |
|
| 692 | + protected function _transaction_details() |
|
| 693 | + { |
|
| 694 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 695 | + |
|
| 696 | + $this->_set_transaction_status_array(); |
|
| 697 | + |
|
| 698 | + $this->_template_args = array(); |
|
| 699 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 700 | + |
|
| 701 | + $this->_set_transaction_object(); |
|
| 702 | + |
|
| 703 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 704 | + return; |
|
| 705 | + } |
|
| 706 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 707 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 708 | + ? $primary_registration->attendee() |
|
| 709 | + : null; |
|
| 710 | + |
|
| 711 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 712 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 713 | + |
|
| 714 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 715 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 716 | + |
|
| 717 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 718 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 719 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 720 | + |
|
| 721 | + $this->_template_args['grand_total'] = $this->_transaction->total(); |
|
| 722 | + $this->_template_args['total_paid'] = $this->_transaction->paid(); |
|
| 723 | + |
|
| 724 | + $amount_due = $this->_transaction->total() - $this->_transaction->paid(); |
|
| 725 | + $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 726 | + $amount_due, |
|
| 727 | + true |
|
| 728 | + ); |
|
| 729 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 730 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 731 | + . $this->_template_args['amount_due']; |
|
| 732 | + } else { |
|
| 733 | + $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 734 | + } |
|
| 735 | + $this->_template_args['amount_due_class'] = ''; |
|
| 736 | + |
|
| 737 | + if ($this->_transaction->paid() === $this->_transaction->total()) { |
|
| 738 | + // paid in full |
|
| 739 | + $this->_template_args['amount_due'] = false; |
|
| 740 | + } elseif ($this->_transaction->paid() > $this->_transaction->total()) { |
|
| 741 | + // overpaid |
|
| 742 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 743 | + } elseif ($this->_transaction->total() > (float) 0) { |
|
| 744 | + if ($this->_transaction->paid() > (float) 0) { |
|
| 745 | + // monies owing |
|
| 746 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 747 | + } elseif ($this->_transaction->paid() === (float) 0) { |
|
| 748 | + // no payments made yet |
|
| 749 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 750 | + } |
|
| 751 | + } elseif ($this->_transaction->total() === (float) 0) { |
|
| 752 | + // free event |
|
| 753 | + $this->_template_args['amount_due'] = false; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + $payment_method = $this->_transaction->payment_method(); |
|
| 757 | + |
|
| 758 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 759 | + ? $payment_method->admin_name() |
|
| 760 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 761 | + |
|
| 762 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 763 | + // link back to overview |
|
| 764 | + $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 765 | + ? $_SERVER['HTTP_REFERER'] |
|
| 766 | + : TXN_ADMIN_URL; |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + // next link |
|
| 770 | + $next_txn = $this->_transaction->next( |
|
| 771 | + null, |
|
| 772 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 773 | + 'TXN_ID' |
|
| 774 | + ); |
|
| 775 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 776 | + ? $this->_next_link( |
|
| 777 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 778 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 779 | + TXN_ADMIN_URL |
|
| 780 | + ), |
|
| 781 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 782 | + ) |
|
| 783 | + : ''; |
|
| 784 | + // previous link |
|
| 785 | + $previous_txn = $this->_transaction->previous( |
|
| 786 | + null, |
|
| 787 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 788 | + 'TXN_ID' |
|
| 789 | + ); |
|
| 790 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 791 | + ? $this->_previous_link( |
|
| 792 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 793 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 794 | + TXN_ADMIN_URL |
|
| 795 | + ), |
|
| 796 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 797 | + ) |
|
| 798 | + : ''; |
|
| 799 | + |
|
| 800 | + // were we just redirected here after adding a new registration ??? |
|
| 801 | + if (isset( |
|
| 802 | + $this->_req_data['redirect_from'], |
|
| 803 | + $this->_req_data['EVT_ID'], |
|
| 804 | + $this->_req_data['event_name'] |
|
| 805 | + )) { |
|
| 806 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 807 | + 'ee_edit_registrations', |
|
| 808 | + 'espresso_registrations_new_registration', |
|
| 809 | + $this->_req_data['EVT_ID'] |
|
| 810 | + )) { |
|
| 811 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 812 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 813 | + array( |
|
| 814 | + 'page' => 'espresso_registrations', |
|
| 815 | + 'action' => 'new_registration', |
|
| 816 | + 'return' => 'default', |
|
| 817 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 818 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 819 | + ), |
|
| 820 | + REG_ADMIN_URL |
|
| 821 | + ); |
|
| 822 | + $this->_admin_page_title .= '">'; |
|
| 823 | + |
|
| 824 | + $this->_admin_page_title .= sprintf( |
|
| 825 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 826 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 827 | + ); |
|
| 828 | + $this->_admin_page_title .= '</a>'; |
|
| 829 | + } |
|
| 830 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 831 | + } |
|
| 832 | + // grab messages at the last second |
|
| 833 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 834 | + // path to template |
|
| 835 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 836 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 837 | + $template_path, |
|
| 838 | + $this->_template_args, |
|
| 839 | + true |
|
| 840 | + ); |
|
| 841 | + |
|
| 842 | + // the details template wrapper |
|
| 843 | + $this->display_admin_page_with_sidebar(); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * _transaction_details_metaboxes |
|
| 849 | + * |
|
| 850 | + * @access protected |
|
| 851 | + * @return void |
|
| 852 | + * @throws EE_Error |
|
| 853 | + * @throws InvalidArgumentException |
|
| 854 | + * @throws InvalidDataTypeException |
|
| 855 | + * @throws InvalidInterfaceException |
|
| 856 | + * @throws RuntimeException |
|
| 857 | + * @throws ReflectionException |
|
| 858 | + */ |
|
| 859 | + protected function _transaction_details_metaboxes() |
|
| 860 | + { |
|
| 861 | + |
|
| 862 | + $this->_set_transaction_object(); |
|
| 863 | + |
|
| 864 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 865 | + return; |
|
| 866 | + } |
|
| 867 | + add_meta_box( |
|
| 868 | + 'edit-txn-details-mbox', |
|
| 869 | + esc_html__('Transaction Details', 'event_espresso'), |
|
| 870 | + array($this, 'txn_details_meta_box'), |
|
| 871 | + $this->_wp_page_slug, |
|
| 872 | + 'normal', |
|
| 873 | + 'high' |
|
| 874 | + ); |
|
| 875 | + add_meta_box( |
|
| 876 | + 'edit-txn-attendees-mbox', |
|
| 877 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 878 | + array($this, 'txn_attendees_meta_box'), |
|
| 879 | + $this->_wp_page_slug, |
|
| 880 | + 'normal', |
|
| 881 | + 'high', |
|
| 882 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 883 | + ); |
|
| 884 | + add_meta_box( |
|
| 885 | + 'edit-txn-registrant-mbox', |
|
| 886 | + esc_html__('Primary Contact', 'event_espresso'), |
|
| 887 | + array($this, 'txn_registrant_side_meta_box'), |
|
| 888 | + $this->_wp_page_slug, |
|
| 889 | + 'side', |
|
| 890 | + 'high' |
|
| 891 | + ); |
|
| 892 | + add_meta_box( |
|
| 893 | + 'edit-txn-billing-info-mbox', |
|
| 894 | + esc_html__('Billing Information', 'event_espresso'), |
|
| 895 | + array($this, 'txn_billing_info_side_meta_box'), |
|
| 896 | + $this->_wp_page_slug, |
|
| 897 | + 'side', |
|
| 898 | + 'high' |
|
| 899 | + ); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * Callback for transaction actions metabox. |
|
| 905 | + * |
|
| 906 | + * @param EE_Transaction|null $transaction |
|
| 907 | + * @return string |
|
| 908 | + * @throws DomainException |
|
| 909 | + * @throws EE_Error |
|
| 910 | + * @throws InvalidArgumentException |
|
| 911 | + * @throws InvalidDataTypeException |
|
| 912 | + * @throws InvalidInterfaceException |
|
| 913 | + * @throws ReflectionException |
|
| 914 | + * @throws RuntimeException |
|
| 915 | + */ |
|
| 916 | + public function getActionButtons(EE_Transaction $transaction = null) |
|
| 917 | + { |
|
| 918 | + $content = ''; |
|
| 919 | + $actions = array(); |
|
| 920 | + if (! $transaction instanceof EE_Transaction) { |
|
| 921 | + return $content; |
|
| 922 | + } |
|
| 923 | + /** @var EE_Registration $primary_registration */ |
|
| 924 | + $primary_registration = $transaction->primary_registration(); |
|
| 925 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 926 | + ? $primary_registration->attendee() |
|
| 927 | + : null; |
|
| 928 | + |
|
| 929 | + if ($attendee instanceof EE_Attendee |
|
| 930 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | + 'ee_send_message', |
|
| 932 | + 'espresso_transactions_send_payment_reminder' |
|
| 933 | + ) |
|
| 934 | + ) { |
|
| 935 | + $actions['payment_reminder'] = |
|
| 936 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 937 | + && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 938 | + && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code |
|
| 939 | + ? EEH_Template::get_button_or_link( |
|
| 940 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 941 | + array( |
|
| 942 | + 'action' => 'send_payment_reminder', |
|
| 943 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 944 | + 'redirect_to' => 'view_transaction', |
|
| 945 | + ), |
|
| 946 | + TXN_ADMIN_URL |
|
| 947 | + ), |
|
| 948 | + esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
| 949 | + 'button secondary-button', |
|
| 950 | + 'dashicons dashicons-email-alt' |
|
| 951 | + ) |
|
| 952 | + : ''; |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 956 | + 'ee_edit_payments', |
|
| 957 | + 'espresso_transactions_recalculate_line_items' |
|
| 958 | + ) |
|
| 959 | + ) { |
|
| 960 | + $actions['recalculate_line_items'] = EEH_Template::get_button_or_link( |
|
| 961 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 962 | + array( |
|
| 963 | + 'action' => 'espresso_recalculate_line_items', |
|
| 964 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 965 | + 'redirect_to' => 'view_transaction', |
|
| 966 | + ), |
|
| 967 | + TXN_ADMIN_URL |
|
| 968 | + ), |
|
| 969 | + esc_html__(' Recalculate Taxes and Total', 'event_espresso'), |
|
| 970 | + 'button secondary-button', |
|
| 971 | + 'dashicons dashicons-update' |
|
| 972 | + ); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + if ($primary_registration instanceof EE_Registration |
|
| 976 | + && EEH_MSG_Template::is_mt_active('receipt') |
|
| 977 | + ) { |
|
| 978 | + $actions['receipt'] = EEH_Template::get_button_or_link( |
|
| 979 | + $primary_registration->receipt_url(), |
|
| 980 | + esc_html__('View Receipt', 'event_espresso'), |
|
| 981 | + 'button secondary-button', |
|
| 982 | + 'dashicons dashicons-media-default' |
|
| 983 | + ); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + if ($primary_registration instanceof EE_Registration |
|
| 987 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
| 988 | + ) { |
|
| 989 | + $actions['invoice'] = EEH_Template::get_button_or_link( |
|
| 990 | + $primary_registration->invoice_url(), |
|
| 991 | + esc_html__('View Invoice', 'event_espresso'), |
|
| 992 | + 'button secondary-button', |
|
| 993 | + 'dashicons dashicons-media-spreadsheet' |
|
| 994 | + ); |
|
| 995 | + } |
|
| 996 | + $actions = array_filter( |
|
| 997 | + apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
| 998 | + ); |
|
| 999 | + if ($actions) { |
|
| 1000 | + $content = '<ul>'; |
|
| 1001 | + $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1002 | + $content .= '</uL>'; |
|
| 1003 | + } |
|
| 1004 | + return $content; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + |
|
| 1008 | + /** |
|
| 1009 | + * txn_details_meta_box |
|
| 1010 | + * generates HTML for the Transaction main meta box |
|
| 1011 | + * |
|
| 1012 | + * @return void |
|
| 1013 | + * @throws DomainException |
|
| 1014 | + * @throws EE_Error |
|
| 1015 | + * @throws InvalidArgumentException |
|
| 1016 | + * @throws InvalidDataTypeException |
|
| 1017 | + * @throws InvalidInterfaceException |
|
| 1018 | + * @throws RuntimeException |
|
| 1019 | + * @throws ReflectionException |
|
| 1020 | + */ |
|
| 1021 | + public function txn_details_meta_box() |
|
| 1022 | + { |
|
| 1023 | + $this->_set_transaction_object(); |
|
| 1024 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 1025 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1026 | + ? $this->_transaction->primary_registration()->attendee() |
|
| 1027 | + : null; |
|
| 1028 | + $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1029 | + 'ee_edit_payments', |
|
| 1030 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1031 | + ); |
|
| 1032 | + $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1033 | + 'ee_delete_payments', |
|
| 1034 | + 'delete_payment_from_registration_details' |
|
| 1035 | + ); |
|
| 1036 | + |
|
| 1037 | + // get line table |
|
| 1038 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1039 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
| 1040 | + 'admin_table', |
|
| 1041 | + 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 1042 | + ); |
|
| 1043 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 1044 | + $this->_transaction->total_line_item() |
|
| 1045 | + ); |
|
| 1046 | + $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code(); |
|
| 1047 | + |
|
| 1048 | + // process taxes |
|
| 1049 | + $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1050 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 1051 | + |
|
| 1052 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 1053 | + $this->_transaction->total(), |
|
| 1054 | + false, |
|
| 1055 | + false |
|
| 1056 | + ); |
|
| 1057 | + $this->_template_args['grand_raw_total'] = $this->_transaction->total(); |
|
| 1058 | + $this->_template_args['TXN_status'] = $this->_transaction->status_ID(); |
|
| 1059 | + |
|
| 1060 | + // process payment details |
|
| 1061 | + $payments = $this->_transaction->payments(); |
|
| 1062 | + if (! empty($payments)) { |
|
| 1063 | + $this->_template_args['payments'] = $payments; |
|
| 1064 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 1065 | + } else { |
|
| 1066 | + $this->_template_args['payments'] = false; |
|
| 1067 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 1071 | + $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 1072 | + array('action' => 'espresso_delete_payment'), |
|
| 1073 | + TXN_ADMIN_URL |
|
| 1074 | + ); |
|
| 1075 | + |
|
| 1076 | + if (isset($txn_details['invoice_number'])) { |
|
| 1077 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 1078 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 1079 | + 'Invoice Number', |
|
| 1080 | + 'event_espresso' |
|
| 1081 | + ); |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 1085 | + ->primary_registration() |
|
| 1086 | + ->session_ID(); |
|
| 1087 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 1088 | + 'Registration Session', |
|
| 1089 | + 'event_espresso' |
|
| 1090 | + ); |
|
| 1091 | + |
|
| 1092 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 1093 | + ? $this->_session['ip_address'] |
|
| 1094 | + : ''; |
|
| 1095 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 1096 | + 'Transaction placed from IP', |
|
| 1097 | + 'event_espresso' |
|
| 1098 | + ); |
|
| 1099 | + |
|
| 1100 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1101 | + ? $this->_session['user_agent'] |
|
| 1102 | + : ''; |
|
| 1103 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1104 | + 'Registrant User Agent', |
|
| 1105 | + 'event_espresso' |
|
| 1106 | + ); |
|
| 1107 | + |
|
| 1108 | + $reg_steps = '<ul>'; |
|
| 1109 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1110 | + if ($reg_step_status === true) { |
|
| 1111 | + $reg_steps .= '<li style="color:#70cc50">' |
|
| 1112 | + . sprintf( |
|
| 1113 | + esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1114 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1115 | + ) |
|
| 1116 | + . '</li>'; |
|
| 1117 | + } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1118 | + $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1119 | + . sprintf( |
|
| 1120 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1121 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1122 | + date( |
|
| 1123 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1124 | + $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1125 | + ) |
|
| 1126 | + ) |
|
| 1127 | + . '</li>'; |
|
| 1128 | + } else { |
|
| 1129 | + $reg_steps .= '<li style="color:#E76700">' |
|
| 1130 | + . sprintf( |
|
| 1131 | + esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1132 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1133 | + ) |
|
| 1134 | + . '</li>'; |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + $reg_steps .= '</ul>'; |
|
| 1138 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1139 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1140 | + 'Registration Step Progress', |
|
| 1141 | + 'event_espresso' |
|
| 1142 | + ); |
|
| 1143 | + |
|
| 1144 | + |
|
| 1145 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 1146 | + $this->_get_payment_methods($payments); |
|
| 1147 | + $this->_get_payment_status_array(); |
|
| 1148 | + $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
| 1149 | + |
|
| 1150 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1151 | + array( |
|
| 1152 | + 'action' => 'edit_transaction', |
|
| 1153 | + 'process' => 'transaction', |
|
| 1154 | + ), |
|
| 1155 | + TXN_ADMIN_URL |
|
| 1156 | + ); |
|
| 1157 | + $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
| 1158 | + array( |
|
| 1159 | + 'page' => 'espresso_transactions', |
|
| 1160 | + 'action' => 'espresso_apply_payment', |
|
| 1161 | + ), |
|
| 1162 | + WP_AJAX_URL |
|
| 1163 | + ); |
|
| 1164 | + $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
| 1165 | + array( |
|
| 1166 | + 'page' => 'espresso_transactions', |
|
| 1167 | + 'action' => 'espresso_delete_payment', |
|
| 1168 | + ), |
|
| 1169 | + WP_AJAX_URL |
|
| 1170 | + ); |
|
| 1171 | + |
|
| 1172 | + $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
| 1173 | + |
|
| 1174 | + // 'espresso_delete_payment_nonce' |
|
| 1175 | + |
|
| 1176 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1177 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * _get_registration_payment_IDs |
|
| 1183 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1184 | + * |
|
| 1185 | + * @access protected |
|
| 1186 | + * @param EE_Payment[] $payments |
|
| 1187 | + * @return array |
|
| 1188 | + * @throws EE_Error |
|
| 1189 | + * @throws InvalidArgumentException |
|
| 1190 | + * @throws InvalidDataTypeException |
|
| 1191 | + * @throws InvalidInterfaceException |
|
| 1192 | + * @throws ReflectionException |
|
| 1193 | + */ |
|
| 1194 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 1195 | + { |
|
| 1196 | + $existing_reg_payments = array(); |
|
| 1197 | + // get all reg payments for these payments |
|
| 1198 | + $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
| 1199 | + array( |
|
| 1200 | + array( |
|
| 1201 | + 'PAY_ID' => array( |
|
| 1202 | + 'IN', |
|
| 1203 | + array_keys($payments), |
|
| 1204 | + ), |
|
| 1205 | + ), |
|
| 1206 | + ) |
|
| 1207 | + ); |
|
| 1208 | + if (! empty($reg_payments)) { |
|
| 1209 | + foreach ($payments as $payment) { |
|
| 1210 | + if (! $payment instanceof EE_Payment) { |
|
| 1211 | + continue; |
|
| 1212 | + } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1213 | + $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1214 | + } |
|
| 1215 | + foreach ($reg_payments as $reg_payment) { |
|
| 1216 | + if ($reg_payment instanceof EE_Registration_Payment |
|
| 1217 | + && $reg_payment->payment_ID() === $payment->ID() |
|
| 1218 | + ) { |
|
| 1219 | + $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return $existing_reg_payments; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * _get_registrations_to_apply_payment_to |
|
| 1231 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1232 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 1233 | + * |
|
| 1234 | + * @access protected |
|
| 1235 | + * @return void |
|
| 1236 | + * @throws EE_Error |
|
| 1237 | + * @throws InvalidArgumentException |
|
| 1238 | + * @throws InvalidDataTypeException |
|
| 1239 | + * @throws InvalidInterfaceException |
|
| 1240 | + * @throws ReflectionException |
|
| 1241 | + */ |
|
| 1242 | + protected function _get_registrations_to_apply_payment_to() |
|
| 1243 | + { |
|
| 1244 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1245 | + $query_params = array( |
|
| 1246 | + array( |
|
| 1247 | + 'STS_ID' => array( |
|
| 1248 | + 'IN', |
|
| 1249 | + array( |
|
| 1250 | + EEM_Registration::status_id_approved, |
|
| 1251 | + EEM_Registration::status_id_pending_payment, |
|
| 1252 | + EEM_Registration::status_id_not_approved, |
|
| 1253 | + ), |
|
| 1254 | + ), |
|
| 1255 | + ), |
|
| 1256 | + ); |
|
| 1257 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1258 | + '', |
|
| 1259 | + 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1260 | + '', |
|
| 1261 | + 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1262 | + ); |
|
| 1263 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1264 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1265 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1266 | + EEH_HTML::tr( |
|
| 1267 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1268 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1269 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1270 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1271 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1272 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1273 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1274 | + ) |
|
| 1275 | + ); |
|
| 1276 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1277 | + // get registrations for TXN |
|
| 1278 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 1279 | + $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1280 | + foreach ($registrations as $registration) { |
|
| 1281 | + if ($registration instanceof EE_Registration) { |
|
| 1282 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1283 | + ? $registration->attendee()->full_name() |
|
| 1284 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1285 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 1286 | + $taxable = $registration->ticket()->taxable() |
|
| 1287 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1288 | + : ''; |
|
| 1289 | + $checked = empty($existing_reg_payments) |
|
| 1290 | + || in_array($registration->ID(), $existing_reg_payments, true) |
|
| 1291 | + ? ' checked="checked"' |
|
| 1292 | + : ''; |
|
| 1293 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1294 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1295 | + EEH_HTML::td($registration->ID()) . |
|
| 1296 | + EEH_HTML::td($attendee_name) . |
|
| 1297 | + EEH_HTML::td( |
|
| 1298 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1299 | + ) . |
|
| 1300 | + EEH_HTML::td($registration->event_name()) . |
|
| 1301 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1302 | + EEH_HTML::td( |
|
| 1303 | + EEH_Template::format_currency($owing), |
|
| 1304 | + '', |
|
| 1305 | + 'txn-admin-payment-owing-td jst-cntr' |
|
| 1306 | + ) . |
|
| 1307 | + EEH_HTML::td( |
|
| 1308 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 1309 | + . '" name="txn_admin_payment[registrations]"' |
|
| 1310 | + . $checked . $disabled . '>', |
|
| 1311 | + '', |
|
| 1312 | + 'jst-cntr' |
|
| 1313 | + ), |
|
| 1314 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 1315 | + ); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1319 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1320 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1321 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1322 | + esc_html__( |
|
| 1323 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1324 | + 'event_espresso' |
|
| 1325 | + ), |
|
| 1326 | + '', |
|
| 1327 | + 'clear description' |
|
| 1328 | + ); |
|
| 1329 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1330 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * _get_reg_status_selection |
|
| 1336 | + * |
|
| 1337 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1338 | + * instead of events. |
|
| 1339 | + * @access protected |
|
| 1340 | + * @return void |
|
| 1341 | + * @throws EE_Error |
|
| 1342 | + */ |
|
| 1343 | + protected function _get_reg_status_selection() |
|
| 1344 | + { |
|
| 1345 | + // first get all possible statuses |
|
| 1346 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1347 | + // let's add a "don't change" option. |
|
| 1348 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1349 | + $status_array = array_merge($status_array, $statuses); |
|
| 1350 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1351 | + 'txn_reg_status_change[reg_status]', |
|
| 1352 | + $status_array, |
|
| 1353 | + 'NAN', |
|
| 1354 | + 'id="txn-admin-payment-reg-status-inp"', |
|
| 1355 | + 'txn-reg-status-change-reg-status' |
|
| 1356 | + ); |
|
| 1357 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1358 | + 'delete_txn_reg_status_change[reg_status]', |
|
| 1359 | + $status_array, |
|
| 1360 | + 'NAN', |
|
| 1361 | + 'delete-txn-admin-payment-reg-status-inp', |
|
| 1362 | + 'delete-txn-reg-status-change-reg-status' |
|
| 1363 | + ); |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + /** |
|
| 1368 | + * _get_payment_methods |
|
| 1369 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1370 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1371 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1372 | + * |
|
| 1373 | + * @access private |
|
| 1374 | + * @param EE_Payment[] to show on this page |
|
| 1375 | + * @return void |
|
| 1376 | + * @throws EE_Error |
|
| 1377 | + * @throws InvalidArgumentException |
|
| 1378 | + * @throws InvalidDataTypeException |
|
| 1379 | + * @throws InvalidInterfaceException |
|
| 1380 | + * @throws ReflectionException |
|
| 1381 | + */ |
|
| 1382 | + private function _get_payment_methods($payments = array()) |
|
| 1383 | + { |
|
| 1384 | + $payment_methods_of_payments = array(); |
|
| 1385 | + foreach ($payments as $payment) { |
|
| 1386 | + if ($payment instanceof EE_Payment) { |
|
| 1387 | + $payment_methods_of_payments[] = $payment->ID(); |
|
| 1388 | + } |
|
| 1389 | + } |
|
| 1390 | + if ($payment_methods_of_payments) { |
|
| 1391 | + $query_args = array( |
|
| 1392 | + array( |
|
| 1393 | + 'OR*payment_method_for_payment' => array( |
|
| 1394 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1395 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1396 | + ), |
|
| 1397 | + ), |
|
| 1398 | + ); |
|
| 1399 | + } else { |
|
| 1400 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1401 | + } |
|
| 1402 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * txn_attendees_meta_box |
|
| 1408 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1409 | + * |
|
| 1410 | + * @access public |
|
| 1411 | + * @param WP_Post $post |
|
| 1412 | + * @param array $metabox |
|
| 1413 | + * @return void |
|
| 1414 | + * @throws DomainException |
|
| 1415 | + * @throws EE_Error |
|
| 1416 | + * @throws InvalidArgumentException |
|
| 1417 | + * @throws InvalidDataTypeException |
|
| 1418 | + * @throws InvalidInterfaceException |
|
| 1419 | + * @throws ReflectionException |
|
| 1420 | + */ |
|
| 1421 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1422 | + { |
|
| 1423 | + |
|
| 1424 | + /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1425 | + extract($metabox['args']); |
|
| 1426 | + $this->_template_args['post'] = $post; |
|
| 1427 | + $this->_template_args['event_attendees'] = array(); |
|
| 1428 | + // process items in cart |
|
| 1429 | + $line_items = $this->_transaction->get_many_related( |
|
| 1430 | + 'Line_Item', |
|
| 1431 | + array(array('LIN_type' => 'line-item')) |
|
| 1432 | + ); |
|
| 1433 | + if (! empty($line_items)) { |
|
| 1434 | + foreach ($line_items as $item) { |
|
| 1435 | + if ($item instanceof EE_Line_Item) { |
|
| 1436 | + switch ($item->OBJ_type()) { |
|
| 1437 | + case 'Event': |
|
| 1438 | + break; |
|
| 1439 | + case 'Ticket': |
|
| 1440 | + $ticket = $item->ticket(); |
|
| 1441 | + // right now we're only handling tickets here. |
|
| 1442 | + // Cause its expected that only tickets will have attendees right? |
|
| 1443 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1444 | + break; |
|
| 1445 | + } |
|
| 1446 | + try { |
|
| 1447 | + $event_name = $ticket->get_event_name(); |
|
| 1448 | + } catch (Exception $e) { |
|
| 1449 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1450 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1451 | + } |
|
| 1452 | + $event_name .= ' - ' . $item->name(); |
|
| 1453 | + $ticket_price = EEH_Template::format_currency($item->unit_price()); |
|
| 1454 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1455 | + $registrations = $ticket->registrations( |
|
| 1456 | + array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1457 | + ); |
|
| 1458 | + foreach ($registrations as $registration) { |
|
| 1459 | + if (! $registration instanceof EE_Registration) { |
|
| 1460 | + break; |
|
| 1461 | + } |
|
| 1462 | + $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1463 | + = $registration->status_ID(); |
|
| 1464 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1465 | + = $registration->count(); |
|
| 1466 | + $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1467 | + = $event_name; |
|
| 1468 | + $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1469 | + = $ticket_price; |
|
| 1470 | + // attendee info |
|
| 1471 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1472 | + if ($attendee instanceof EE_Attendee) { |
|
| 1473 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1474 | + = $attendee->ID(); |
|
| 1475 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1476 | + = $attendee->full_name(); |
|
| 1477 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1478 | + = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1479 | + . esc_html__( |
|
| 1480 | + ' Event', |
|
| 1481 | + 'event_espresso' |
|
| 1482 | + ) |
|
| 1483 | + . '">' . $attendee->email() . '</a>'; |
|
| 1484 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1485 | + = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1486 | + } else { |
|
| 1487 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1488 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1489 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1490 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1491 | + } |
|
| 1492 | + } |
|
| 1493 | + break; |
|
| 1494 | + } |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1499 | + array( |
|
| 1500 | + 'action' => 'edit_transaction', |
|
| 1501 | + 'process' => 'attendees', |
|
| 1502 | + ), |
|
| 1503 | + TXN_ADMIN_URL |
|
| 1504 | + ); |
|
| 1505 | + echo EEH_Template::display_template( |
|
| 1506 | + TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1507 | + $this->_template_args, |
|
| 1508 | + true |
|
| 1509 | + ); |
|
| 1510 | + } else { |
|
| 1511 | + echo sprintf( |
|
| 1512 | + esc_html__( |
|
| 1513 | + '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1514 | + 'event_espresso' |
|
| 1515 | + ), |
|
| 1516 | + '<p class="important-notice">', |
|
| 1517 | + '</p>' |
|
| 1518 | + ); |
|
| 1519 | + } |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * txn_registrant_side_meta_box |
|
| 1525 | + * generates HTML for the Edit Transaction side meta box |
|
| 1526 | + * |
|
| 1527 | + * @access public |
|
| 1528 | + * @return void |
|
| 1529 | + * @throws DomainException |
|
| 1530 | + * @throws EE_Error |
|
| 1531 | + * @throws InvalidArgumentException |
|
| 1532 | + * @throws InvalidDataTypeException |
|
| 1533 | + * @throws InvalidInterfaceException |
|
| 1534 | + * @throws ReflectionException |
|
| 1535 | + */ |
|
| 1536 | + public function txn_registrant_side_meta_box() |
|
| 1537 | + { |
|
| 1538 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1539 | + ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1540 | + : null; |
|
| 1541 | + if (! $primary_att instanceof EE_Attendee) { |
|
| 1542 | + $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1543 | + 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1544 | + 'event_espresso' |
|
| 1545 | + ); |
|
| 1546 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1547 | + } |
|
| 1548 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1549 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1550 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1551 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1552 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1553 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1554 | + array( |
|
| 1555 | + 'action' => 'edit_attendee', |
|
| 1556 | + 'post' => $primary_att->ID(), |
|
| 1557 | + ), |
|
| 1558 | + REG_ADMIN_URL |
|
| 1559 | + ); |
|
| 1560 | + // get formatted address for registrant |
|
| 1561 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1562 | + echo EEH_Template::display_template( |
|
| 1563 | + TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1564 | + $this->_template_args, |
|
| 1565 | + true |
|
| 1566 | + ); |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * txn_billing_info_side_meta_box |
|
| 1572 | + * generates HTML for the Edit Transaction side meta box |
|
| 1573 | + * |
|
| 1574 | + * @access public |
|
| 1575 | + * @return void |
|
| 1576 | + * @throws DomainException |
|
| 1577 | + * @throws EE_Error |
|
| 1578 | + */ |
|
| 1579 | + public function txn_billing_info_side_meta_box() |
|
| 1580 | + { |
|
| 1581 | + |
|
| 1582 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1583 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1584 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1585 | + TXN_ADMIN_URL |
|
| 1586 | + ); |
|
| 1587 | + |
|
| 1588 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1589 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + |
|
| 1593 | + /** |
|
| 1594 | + * apply_payments_or_refunds |
|
| 1595 | + * registers a payment or refund made towards a transaction |
|
| 1596 | + * |
|
| 1597 | + * @access public |
|
| 1598 | + * @return void |
|
| 1599 | + * @throws EE_Error |
|
| 1600 | + * @throws InvalidArgumentException |
|
| 1601 | + * @throws ReflectionException |
|
| 1602 | + * @throws RuntimeException |
|
| 1603 | + * @throws InvalidDataTypeException |
|
| 1604 | + * @throws InvalidInterfaceException |
|
| 1605 | + */ |
|
| 1606 | + public function apply_payments_or_refunds() |
|
| 1607 | + { |
|
| 1608 | + $json_response_data = array('return_data' => false); |
|
| 1609 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1610 | + $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1611 | + 'ee_edit_payments', |
|
| 1612 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1613 | + ); |
|
| 1614 | + if (! empty($valid_data) && $has_access) { |
|
| 1615 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1616 | + // save the new payment |
|
| 1617 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1618 | + // get the TXN for this payment |
|
| 1619 | + $transaction = $payment->transaction(); |
|
| 1620 | + // verify transaction |
|
| 1621 | + if ($transaction instanceof EE_Transaction) { |
|
| 1622 | + // calculate_total_payments_and_update_status |
|
| 1623 | + $this->_process_transaction_payments($transaction); |
|
| 1624 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1625 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1626 | + // apply payment to registrations (if applicable) |
|
| 1627 | + if (! empty($REG_IDs)) { |
|
| 1628 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1629 | + $this->_maybe_send_notifications(); |
|
| 1630 | + // now process status changes for the same registrations |
|
| 1631 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1632 | + } |
|
| 1633 | + $this->_maybe_send_notifications($payment); |
|
| 1634 | + // prepare to render page |
|
| 1635 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1636 | + do_action( |
|
| 1637 | + 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1638 | + $transaction, |
|
| 1639 | + $payment |
|
| 1640 | + ); |
|
| 1641 | + } else { |
|
| 1642 | + EE_Error::add_error( |
|
| 1643 | + esc_html__( |
|
| 1644 | + 'A valid Transaction for this payment could not be retrieved.', |
|
| 1645 | + 'event_espresso' |
|
| 1646 | + ), |
|
| 1647 | + __FILE__, |
|
| 1648 | + __FUNCTION__, |
|
| 1649 | + __LINE__ |
|
| 1650 | + ); |
|
| 1651 | + } |
|
| 1652 | + } elseif ($has_access) { |
|
| 1653 | + EE_Error::add_error( |
|
| 1654 | + esc_html__( |
|
| 1655 | + 'The payment form data could not be processed. Please try again.', |
|
| 1656 | + 'event_espresso' |
|
| 1657 | + ), |
|
| 1658 | + __FILE__, |
|
| 1659 | + __FUNCTION__, |
|
| 1660 | + __LINE__ |
|
| 1661 | + ); |
|
| 1662 | + } else { |
|
| 1663 | + EE_Error::add_error( |
|
| 1664 | + esc_html__( |
|
| 1665 | + 'You do not have access to apply payments or refunds to a registration.', |
|
| 1666 | + 'event_espresso' |
|
| 1667 | + ), |
|
| 1668 | + __FILE__, |
|
| 1669 | + __FUNCTION__, |
|
| 1670 | + __LINE__ |
|
| 1671 | + ); |
|
| 1672 | + } |
|
| 1673 | + $notices = EE_Error::get_notices( |
|
| 1674 | + false, |
|
| 1675 | + false, |
|
| 1676 | + false |
|
| 1677 | + ); |
|
| 1678 | + $this->_template_args = array( |
|
| 1679 | + 'data' => $json_response_data, |
|
| 1680 | + 'error' => $notices['errors'], |
|
| 1681 | + 'success' => $notices['success'], |
|
| 1682 | + ); |
|
| 1683 | + $this->_return_json(); |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * _validate_payment_request_data |
|
| 1689 | + * |
|
| 1690 | + * @return array |
|
| 1691 | + * @throws EE_Error |
|
| 1692 | + * @throws InvalidArgumentException |
|
| 1693 | + * @throws InvalidDataTypeException |
|
| 1694 | + * @throws InvalidInterfaceException |
|
| 1695 | + */ |
|
| 1696 | + protected function _validate_payment_request_data() |
|
| 1697 | + { |
|
| 1698 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1699 | + return array(); |
|
| 1700 | + } |
|
| 1701 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1702 | + try { |
|
| 1703 | + if ($payment_form->was_submitted()) { |
|
| 1704 | + $payment_form->receive_form_submission(); |
|
| 1705 | + if (! $payment_form->is_valid()) { |
|
| 1706 | + $submission_error_messages = array(); |
|
| 1707 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1708 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1709 | + $submission_error_messages[] = sprintf( |
|
| 1710 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1711 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1712 | + $validation_error->getMessage() |
|
| 1713 | + ); |
|
| 1714 | + } |
|
| 1715 | + } |
|
| 1716 | + EE_Error::add_error( |
|
| 1717 | + implode('<br />', $submission_error_messages), |
|
| 1718 | + __FILE__, |
|
| 1719 | + __FUNCTION__, |
|
| 1720 | + __LINE__ |
|
| 1721 | + ); |
|
| 1722 | + return array(); |
|
| 1723 | + } |
|
| 1724 | + } |
|
| 1725 | + } catch (EE_Error $e) { |
|
| 1726 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1727 | + return array(); |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + return $payment_form->valid_data(); |
|
| 1731 | + } |
|
| 1732 | + |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * _generate_payment_form_section |
|
| 1736 | + * |
|
| 1737 | + * @return EE_Form_Section_Proper |
|
| 1738 | + * @throws EE_Error |
|
| 1739 | + */ |
|
| 1740 | + protected function _generate_payment_form_section() |
|
| 1741 | + { |
|
| 1742 | + return new EE_Form_Section_Proper( |
|
| 1743 | + array( |
|
| 1744 | + 'name' => 'txn_admin_payment', |
|
| 1745 | + 'subsections' => array( |
|
| 1746 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1747 | + array( |
|
| 1748 | + 'default' => 0, |
|
| 1749 | + 'required' => false, |
|
| 1750 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1751 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1752 | + ) |
|
| 1753 | + ), |
|
| 1754 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1755 | + array( |
|
| 1756 | + 'default' => 0, |
|
| 1757 | + 'required' => true, |
|
| 1758 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1759 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1760 | + ) |
|
| 1761 | + ), |
|
| 1762 | + 'type' => new EE_Text_Input( |
|
| 1763 | + array( |
|
| 1764 | + 'default' => 1, |
|
| 1765 | + 'required' => true, |
|
| 1766 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1767 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1768 | + ) |
|
| 1769 | + ), |
|
| 1770 | + 'amount' => new EE_Text_Input( |
|
| 1771 | + array( |
|
| 1772 | + 'default' => 0, |
|
| 1773 | + 'required' => true, |
|
| 1774 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1775 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1776 | + ) |
|
| 1777 | + ), |
|
| 1778 | + 'status' => new EE_Text_Input( |
|
| 1779 | + array( |
|
| 1780 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1781 | + 'required' => true, |
|
| 1782 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1783 | + ) |
|
| 1784 | + ), |
|
| 1785 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1786 | + array( |
|
| 1787 | + 'default' => 2, |
|
| 1788 | + 'required' => true, |
|
| 1789 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1790 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1791 | + ) |
|
| 1792 | + ), |
|
| 1793 | + 'date' => new EE_Text_Input( |
|
| 1794 | + array( |
|
| 1795 | + 'default' => time(), |
|
| 1796 | + 'required' => true, |
|
| 1797 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1798 | + ) |
|
| 1799 | + ), |
|
| 1800 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1801 | + array( |
|
| 1802 | + 'default' => '', |
|
| 1803 | + 'required' => false, |
|
| 1804 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1805 | + 'validation_strategies' => array( |
|
| 1806 | + new EE_Max_Length_Validation_Strategy( |
|
| 1807 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1808 | + 100 |
|
| 1809 | + ), |
|
| 1810 | + ), |
|
| 1811 | + ) |
|
| 1812 | + ), |
|
| 1813 | + 'po_number' => new EE_Text_Input( |
|
| 1814 | + array( |
|
| 1815 | + 'default' => '', |
|
| 1816 | + 'required' => false, |
|
| 1817 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1818 | + 'validation_strategies' => array( |
|
| 1819 | + new EE_Max_Length_Validation_Strategy( |
|
| 1820 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1821 | + 100 |
|
| 1822 | + ), |
|
| 1823 | + ), |
|
| 1824 | + ) |
|
| 1825 | + ), |
|
| 1826 | + 'accounting' => new EE_Text_Input( |
|
| 1827 | + array( |
|
| 1828 | + 'default' => '', |
|
| 1829 | + 'required' => false, |
|
| 1830 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1831 | + 'validation_strategies' => array( |
|
| 1832 | + new EE_Max_Length_Validation_Strategy( |
|
| 1833 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1834 | + 100 |
|
| 1835 | + ), |
|
| 1836 | + ), |
|
| 1837 | + ) |
|
| 1838 | + ), |
|
| 1839 | + ), |
|
| 1840 | + ) |
|
| 1841 | + ); |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + |
|
| 1845 | + /** |
|
| 1846 | + * _create_payment_from_request_data |
|
| 1847 | + * |
|
| 1848 | + * @param array $valid_data |
|
| 1849 | + * @return EE_Payment |
|
| 1850 | + * @throws EE_Error |
|
| 1851 | + * @throws InvalidArgumentException |
|
| 1852 | + * @throws InvalidDataTypeException |
|
| 1853 | + * @throws InvalidInterfaceException |
|
| 1854 | + * @throws ReflectionException |
|
| 1855 | + */ |
|
| 1856 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1857 | + { |
|
| 1858 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1859 | + // get payment amount |
|
| 1860 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1861 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1862 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1863 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1864 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1865 | + $date = $valid_data['date'] |
|
| 1866 | + ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1867 | + : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1868 | + $payment = EE_Payment::new_instance( |
|
| 1869 | + array( |
|
| 1870 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1871 | + 'STS_ID' => $valid_data['status'], |
|
| 1872 | + 'PAY_timestamp' => $date, |
|
| 1873 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1874 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1875 | + 'PAY_amount' => $amount, |
|
| 1876 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1877 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1878 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1879 | + 'PAY_details' => $valid_data, |
|
| 1880 | + 'PAY_ID' => $PAY_ID, |
|
| 1881 | + ), |
|
| 1882 | + '', |
|
| 1883 | + array('Y-m-d', 'g:i a') |
|
| 1884 | + ); |
|
| 1885 | + |
|
| 1886 | + if (! $payment->save()) { |
|
| 1887 | + EE_Error::add_error( |
|
| 1888 | + sprintf( |
|
| 1889 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1890 | + $payment->ID() |
|
| 1891 | + ), |
|
| 1892 | + __FILE__, |
|
| 1893 | + __FUNCTION__, |
|
| 1894 | + __LINE__ |
|
| 1895 | + ); |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + return $payment; |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + /** |
|
| 1903 | + * _process_transaction_payments |
|
| 1904 | + * |
|
| 1905 | + * @param \EE_Transaction $transaction |
|
| 1906 | + * @return void |
|
| 1907 | + * @throws EE_Error |
|
| 1908 | + * @throws InvalidArgumentException |
|
| 1909 | + * @throws ReflectionException |
|
| 1910 | + * @throws InvalidDataTypeException |
|
| 1911 | + * @throws InvalidInterfaceException |
|
| 1912 | + */ |
|
| 1913 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1914 | + { |
|
| 1915 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1916 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1917 | + // update the transaction with this payment |
|
| 1918 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1919 | + EE_Error::add_success( |
|
| 1920 | + esc_html__( |
|
| 1921 | + 'The payment has been processed successfully.', |
|
| 1922 | + 'event_espresso' |
|
| 1923 | + ), |
|
| 1924 | + __FILE__, |
|
| 1925 | + __FUNCTION__, |
|
| 1926 | + __LINE__ |
|
| 1927 | + ); |
|
| 1928 | + } else { |
|
| 1929 | + EE_Error::add_error( |
|
| 1930 | + esc_html__( |
|
| 1931 | + 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1932 | + 'event_espresso' |
|
| 1933 | + ), |
|
| 1934 | + __FILE__, |
|
| 1935 | + __FUNCTION__, |
|
| 1936 | + __LINE__ |
|
| 1937 | + ); |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + |
|
| 1942 | + /** |
|
| 1943 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1944 | + * returns a list of registration IDs that the payment will apply to |
|
| 1945 | + * |
|
| 1946 | + * @param \EE_Payment $payment |
|
| 1947 | + * @return array |
|
| 1948 | + * @throws EE_Error |
|
| 1949 | + * @throws InvalidArgumentException |
|
| 1950 | + * @throws InvalidDataTypeException |
|
| 1951 | + * @throws InvalidInterfaceException |
|
| 1952 | + * @throws ReflectionException |
|
| 1953 | + */ |
|
| 1954 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1955 | + { |
|
| 1956 | + $REG_IDs = array(); |
|
| 1957 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1958 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1959 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1960 | + } |
|
| 1961 | + // nothing specified ? then get all reg IDs |
|
| 1962 | + if (empty($REG_IDs)) { |
|
| 1963 | + $registrations = $payment->transaction()->registrations(); |
|
| 1964 | + $REG_IDs = ! empty($registrations) |
|
| 1965 | + ? array_keys($registrations) |
|
| 1966 | + : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1970 | + return array_map('intval', $REG_IDs); |
|
| 1971 | + } |
|
| 1972 | + |
|
| 1973 | + |
|
| 1974 | + /** |
|
| 1975 | + * @return array |
|
| 1976 | + */ |
|
| 1977 | + public function existing_reg_payment_REG_IDs() |
|
| 1978 | + { |
|
| 1979 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + |
|
| 1983 | + /** |
|
| 1984 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1985 | + */ |
|
| 1986 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1987 | + { |
|
| 1988 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + |
|
| 1992 | + /** |
|
| 1993 | + * _get_existing_reg_payment_REG_IDs |
|
| 1994 | + * returns a list of registration IDs that the payment is currently related to |
|
| 1995 | + * as recorded in the database |
|
| 1996 | + * |
|
| 1997 | + * @param \EE_Payment $payment |
|
| 1998 | + * @return array |
|
| 1999 | + * @throws EE_Error |
|
| 2000 | + * @throws InvalidArgumentException |
|
| 2001 | + * @throws InvalidDataTypeException |
|
| 2002 | + * @throws InvalidInterfaceException |
|
| 2003 | + * @throws ReflectionException |
|
| 2004 | + */ |
|
| 2005 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 2006 | + { |
|
| 2007 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 2008 | + // let's get any existing reg payment records for this payment |
|
| 2009 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 2010 | + // but we only want the REG IDs, so grab the array keys |
|
| 2011 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 2012 | + ? array_keys($existing_reg_payment_REG_IDs) |
|
| 2013 | + : array(); |
|
| 2014 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 2015 | + } |
|
| 2016 | + |
|
| 2017 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 2018 | + } |
|
| 2019 | + |
|
| 2020 | + |
|
| 2021 | + /** |
|
| 2022 | + * _remove_existing_registration_payments |
|
| 2023 | + * this calculates the difference between existing relations |
|
| 2024 | + * to the supplied payment and the new list registration IDs, |
|
| 2025 | + * removes any related registrations that no longer apply, |
|
| 2026 | + * and then updates the registration paid fields |
|
| 2027 | + * |
|
| 2028 | + * @param \EE_Payment $payment |
|
| 2029 | + * @param int $PAY_ID |
|
| 2030 | + * @return bool; |
|
| 2031 | + * @throws EE_Error |
|
| 2032 | + * @throws InvalidArgumentException |
|
| 2033 | + * @throws ReflectionException |
|
| 2034 | + * @throws InvalidDataTypeException |
|
| 2035 | + * @throws InvalidInterfaceException |
|
| 2036 | + */ |
|
| 2037 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 2038 | + { |
|
| 2039 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 2040 | + if (absint($PAY_ID) === 0) { |
|
| 2041 | + return false; |
|
| 2042 | + } |
|
| 2043 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2044 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 2045 | + return false; |
|
| 2046 | + } |
|
| 2047 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2048 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2049 | + |
|
| 2050 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 2051 | + $payment, |
|
| 2052 | + array( |
|
| 2053 | + array( |
|
| 2054 | + 'PAY_ID' => $payment->ID(), |
|
| 2055 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 2056 | + ), |
|
| 2057 | + ) |
|
| 2058 | + ); |
|
| 2059 | + } |
|
| 2060 | + |
|
| 2061 | + |
|
| 2062 | + /** |
|
| 2063 | + * _update_registration_payments |
|
| 2064 | + * this applies the payments to the selected registrations |
|
| 2065 | + * but only if they have not already been paid for |
|
| 2066 | + * |
|
| 2067 | + * @param EE_Transaction $transaction |
|
| 2068 | + * @param \EE_Payment $payment |
|
| 2069 | + * @param array $REG_IDs |
|
| 2070 | + * @return void |
|
| 2071 | + * @throws EE_Error |
|
| 2072 | + * @throws InvalidArgumentException |
|
| 2073 | + * @throws ReflectionException |
|
| 2074 | + * @throws RuntimeException |
|
| 2075 | + * @throws InvalidDataTypeException |
|
| 2076 | + * @throws InvalidInterfaceException |
|
| 2077 | + */ |
|
| 2078 | + protected function _update_registration_payments( |
|
| 2079 | + EE_Transaction $transaction, |
|
| 2080 | + EE_Payment $payment, |
|
| 2081 | + $REG_IDs = array() |
|
| 2082 | + ) { |
|
| 2083 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 2084 | + // so let's do that using our set of REG_IDs from the form |
|
| 2085 | + $registration_query_where_params = array( |
|
| 2086 | + 'REG_ID' => array('IN', $REG_IDs), |
|
| 2087 | + ); |
|
| 2088 | + // but add in some conditions regarding payment, |
|
| 2089 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 2090 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 2091 | + if (! $payment->is_a_refund()) { |
|
| 2092 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 2093 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 2094 | + } |
|
| 2095 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 2096 | + if (! empty($registrations)) { |
|
| 2097 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 2098 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2099 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 2100 | + } |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + |
|
| 2104 | + /** |
|
| 2105 | + * _process_registration_status_change |
|
| 2106 | + * This processes requested registration status changes for all the registrations |
|
| 2107 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 2108 | + * |
|
| 2109 | + * @param EE_Transaction $transaction |
|
| 2110 | + * @param array $REG_IDs |
|
| 2111 | + * @return bool |
|
| 2112 | + * @throws EE_Error |
|
| 2113 | + * @throws InvalidArgumentException |
|
| 2114 | + * @throws ReflectionException |
|
| 2115 | + * @throws InvalidDataTypeException |
|
| 2116 | + * @throws InvalidInterfaceException |
|
| 2117 | + */ |
|
| 2118 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 2119 | + { |
|
| 2120 | + // first if there is no change in status then we get out. |
|
| 2121 | + if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2122 | + || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 2123 | + ) { |
|
| 2124 | + // no error message, no change requested, just nothing to do man. |
|
| 2125 | + return false; |
|
| 2126 | + } |
|
| 2127 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 2128 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 2129 | + |
|
| 2130 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 2131 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 2132 | + $transaction, |
|
| 2133 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 2134 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 2135 | + ); |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + |
|
| 2139 | + /** |
|
| 2140 | + * _build_payment_json_response |
|
| 2141 | + * |
|
| 2142 | + * @access public |
|
| 2143 | + * @param \EE_Payment $payment |
|
| 2144 | + * @param array $REG_IDs |
|
| 2145 | + * @param bool | null $delete_txn_reg_status_change |
|
| 2146 | + * @return array |
|
| 2147 | + * @throws EE_Error |
|
| 2148 | + * @throws InvalidArgumentException |
|
| 2149 | + * @throws InvalidDataTypeException |
|
| 2150 | + * @throws InvalidInterfaceException |
|
| 2151 | + * @throws ReflectionException |
|
| 2152 | + */ |
|
| 2153 | + protected function _build_payment_json_response( |
|
| 2154 | + EE_Payment $payment, |
|
| 2155 | + $REG_IDs = array(), |
|
| 2156 | + $delete_txn_reg_status_change = null |
|
| 2157 | + ) { |
|
| 2158 | + // was the payment deleted ? |
|
| 2159 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 2160 | + return array( |
|
| 2161 | + 'PAY_ID' => $payment->ID(), |
|
| 2162 | + 'amount' => $payment->amount(), |
|
| 2163 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2164 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2165 | + 'pay_status' => $payment->STS_ID(), |
|
| 2166 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2167 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2168 | + ); |
|
| 2169 | + } else { |
|
| 2170 | + $this->_get_payment_status_array(); |
|
| 2171 | + |
|
| 2172 | + return array( |
|
| 2173 | + 'amount' => $payment->amount(), |
|
| 2174 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2175 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2176 | + 'pay_status' => $payment->STS_ID(), |
|
| 2177 | + 'PAY_ID' => $payment->ID(), |
|
| 2178 | + 'STS_ID' => $payment->STS_ID(), |
|
| 2179 | + 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2180 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2181 | + 'method' => strtoupper($payment->source()), |
|
| 2182 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2183 | + 'gateway' => $payment->payment_method() |
|
| 2184 | + ? $payment->payment_method()->admin_name() |
|
| 2185 | + : esc_html__('Unknown', 'event_espresso'), |
|
| 2186 | + 'gateway_response' => $payment->gateway_response(), |
|
| 2187 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2188 | + 'po_number' => $payment->po_number(), |
|
| 2189 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 2190 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2191 | + ); |
|
| 2192 | + } |
|
| 2193 | + } |
|
| 2194 | + |
|
| 2195 | + |
|
| 2196 | + /** |
|
| 2197 | + * delete_payment |
|
| 2198 | + * delete a payment or refund made towards a transaction |
|
| 2199 | + * |
|
| 2200 | + * @access public |
|
| 2201 | + * @return void |
|
| 2202 | + * @throws EE_Error |
|
| 2203 | + * @throws InvalidArgumentException |
|
| 2204 | + * @throws ReflectionException |
|
| 2205 | + * @throws InvalidDataTypeException |
|
| 2206 | + * @throws InvalidInterfaceException |
|
| 2207 | + */ |
|
| 2208 | + public function delete_payment() |
|
| 2209 | + { |
|
| 2210 | + $json_response_data = array('return_data' => false); |
|
| 2211 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2212 | + ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2213 | + : 0; |
|
| 2214 | + $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2215 | + 'ee_delete_payments', |
|
| 2216 | + 'delete_payment_from_registration_details' |
|
| 2217 | + ); |
|
| 2218 | + if ($PAY_ID && $can_delete) { |
|
| 2219 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2220 | + ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2221 | + : false; |
|
| 2222 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2223 | + if ($payment instanceof EE_Payment) { |
|
| 2224 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2225 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2226 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2227 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2228 | + $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2229 | + $payment, |
|
| 2230 | + $REG_IDs, |
|
| 2231 | + $delete_txn_reg_status_change |
|
| 2232 | + ); |
|
| 2233 | + if ($delete_txn_reg_status_change) { |
|
| 2234 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2235 | + // MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2236 | + // $_REQUEST global because that's how messages will be looking for it. |
|
| 2237 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2238 | + $this->_maybe_send_notifications(); |
|
| 2239 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2240 | + } |
|
| 2241 | + } |
|
| 2242 | + } else { |
|
| 2243 | + EE_Error::add_error( |
|
| 2244 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2245 | + __FILE__, |
|
| 2246 | + __FUNCTION__, |
|
| 2247 | + __LINE__ |
|
| 2248 | + ); |
|
| 2249 | + } |
|
| 2250 | + } elseif ($can_delete) { |
|
| 2251 | + EE_Error::add_error( |
|
| 2252 | + esc_html__( |
|
| 2253 | + 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2254 | + 'event_espresso' |
|
| 2255 | + ), |
|
| 2256 | + __FILE__, |
|
| 2257 | + __FUNCTION__, |
|
| 2258 | + __LINE__ |
|
| 2259 | + ); |
|
| 2260 | + } else { |
|
| 2261 | + EE_Error::add_error( |
|
| 2262 | + esc_html__( |
|
| 2263 | + 'You do not have access to delete a payment.', |
|
| 2264 | + 'event_espresso' |
|
| 2265 | + ), |
|
| 2266 | + __FILE__, |
|
| 2267 | + __FUNCTION__, |
|
| 2268 | + __LINE__ |
|
| 2269 | + ); |
|
| 2270 | + } |
|
| 2271 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 2272 | + $this->_template_args = array( |
|
| 2273 | + 'data' => $json_response_data, |
|
| 2274 | + 'success' => $notices['success'], |
|
| 2275 | + 'error' => $notices['errors'], |
|
| 2276 | + 'attention' => $notices['attention'], |
|
| 2277 | + ); |
|
| 2278 | + $this->_return_json(); |
|
| 2279 | + } |
|
| 2280 | + |
|
| 2281 | + |
|
| 2282 | + /** |
|
| 2283 | + * _registration_payment_data_array |
|
| 2284 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2285 | + * |
|
| 2286 | + * @access protected |
|
| 2287 | + * @param array $REG_IDs |
|
| 2288 | + * @return array |
|
| 2289 | + * @throws EE_Error |
|
| 2290 | + * @throws InvalidArgumentException |
|
| 2291 | + * @throws InvalidDataTypeException |
|
| 2292 | + * @throws InvalidInterfaceException |
|
| 2293 | + * @throws ReflectionException |
|
| 2294 | + */ |
|
| 2295 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 2296 | + { |
|
| 2297 | + $registration_payment_data = array(); |
|
| 2298 | + // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2299 | + if (! empty($REG_IDs)) { |
|
| 2300 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2301 | + foreach ($registrations as $registration) { |
|
| 2302 | + if ($registration instanceof EE_Registration) { |
|
| 2303 | + $registration_payment_data[ $registration->ID() ] = array( |
|
| 2304 | + 'paid' => $registration->pretty_paid(), |
|
| 2305 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2306 | + ); |
|
| 2307 | + } |
|
| 2308 | + } |
|
| 2309 | + } |
|
| 2310 | + |
|
| 2311 | + return $registration_payment_data; |
|
| 2312 | + } |
|
| 2313 | + |
|
| 2314 | + |
|
| 2315 | + /** |
|
| 2316 | + * _maybe_send_notifications |
|
| 2317 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2318 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 2319 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2320 | + * |
|
| 2321 | + * @access protected |
|
| 2322 | + * @param \EE_Payment | null $payment |
|
| 2323 | + */ |
|
| 2324 | + protected function _maybe_send_notifications($payment = null) |
|
| 2325 | + { |
|
| 2326 | + switch ($payment instanceof EE_Payment) { |
|
| 2327 | + // payment notifications |
|
| 2328 | + case true: |
|
| 2329 | + if (isset($this->_req_data['txn_payments']['send_notifications']) |
|
| 2330 | + && filter_var( |
|
| 2331 | + $this->_req_data['txn_payments']['send_notifications'], |
|
| 2332 | + FILTER_VALIDATE_BOOLEAN |
|
| 2333 | + ) |
|
| 2334 | + ) { |
|
| 2335 | + $this->_process_payment_notification($payment); |
|
| 2336 | + } |
|
| 2337 | + break; |
|
| 2338 | + // registration notifications |
|
| 2339 | + case false: |
|
| 2340 | + if (isset($this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2341 | + && filter_var( |
|
| 2342 | + $this->_req_data['txn_reg_status_change']['send_notifications'], |
|
| 2343 | + FILTER_VALIDATE_BOOLEAN |
|
| 2344 | + ) |
|
| 2345 | + ) { |
|
| 2346 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2347 | + } |
|
| 2348 | + break; |
|
| 2349 | + } |
|
| 2350 | + } |
|
| 2351 | + |
|
| 2352 | + |
|
| 2353 | + /** |
|
| 2354 | + * _send_payment_reminder |
|
| 2355 | + * generates HTML for the View Transaction Details Admin page |
|
| 2356 | + * |
|
| 2357 | + * @access protected |
|
| 2358 | + * @return void |
|
| 2359 | + * @throws EE_Error |
|
| 2360 | + * @throws InvalidArgumentException |
|
| 2361 | + * @throws InvalidDataTypeException |
|
| 2362 | + * @throws InvalidInterfaceException |
|
| 2363 | + */ |
|
| 2364 | + protected function _send_payment_reminder() |
|
| 2365 | + { |
|
| 2366 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2367 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2368 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2369 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2370 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2371 | + ) : array(); |
|
| 2372 | + do_action( |
|
| 2373 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2374 | + $transaction |
|
| 2375 | + ); |
|
| 2376 | + $this->_redirect_after_action( |
|
| 2377 | + false, |
|
| 2378 | + esc_html__('payment reminder', 'event_espresso'), |
|
| 2379 | + esc_html__('sent', 'event_espresso'), |
|
| 2380 | + $query_args, |
|
| 2381 | + true |
|
| 2382 | + ); |
|
| 2383 | + } |
|
| 2384 | + |
|
| 2385 | + |
|
| 2386 | + /** |
|
| 2387 | + * get_transactions |
|
| 2388 | + * get transactions for given parameters (used by list table) |
|
| 2389 | + * |
|
| 2390 | + * @param int $perpage how many transactions displayed per page |
|
| 2391 | + * @param boolean $count return the count or objects |
|
| 2392 | + * @param string $view |
|
| 2393 | + * @return mixed int = count || array of transaction objects |
|
| 2394 | + * @throws EE_Error |
|
| 2395 | + * @throws InvalidArgumentException |
|
| 2396 | + * @throws InvalidDataTypeException |
|
| 2397 | + * @throws InvalidInterfaceException |
|
| 2398 | + */ |
|
| 2399 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 2400 | + { |
|
| 2401 | + |
|
| 2402 | + $TXN = EEM_Transaction::instance(); |
|
| 2403 | + |
|
| 2404 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2405 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2406 | + : date( |
|
| 2407 | + 'm/d/Y', |
|
| 2408 | + strtotime('-10 year') |
|
| 2409 | + ); |
|
| 2410 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2411 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2412 | + : date('m/d/Y'); |
|
| 2413 | + |
|
| 2414 | + // make sure our timestamps start and end right at the boundaries for each day |
|
| 2415 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2416 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + // convert to timestamps |
|
| 2420 | + $start_date = strtotime($start_date); |
|
| 2421 | + $end_date = strtotime($end_date); |
|
| 2422 | + |
|
| 2423 | + // makes sure start date is the lowest value and vice versa |
|
| 2424 | + $start_date = min($start_date, $end_date); |
|
| 2425 | + $end_date = max($start_date, $end_date); |
|
| 2426 | + |
|
| 2427 | + // convert to correct format for query |
|
| 2428 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2429 | + 'TXN_timestamp', |
|
| 2430 | + date('Y-m-d H:i:s', $start_date), |
|
| 2431 | + 'Y-m-d H:i:s' |
|
| 2432 | + ); |
|
| 2433 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2434 | + 'TXN_timestamp', |
|
| 2435 | + date('Y-m-d H:i:s', $end_date), |
|
| 2436 | + 'Y-m-d H:i:s' |
|
| 2437 | + ); |
|
| 2438 | + |
|
| 2439 | + |
|
| 2440 | + // set orderby |
|
| 2441 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2442 | + |
|
| 2443 | + switch ($this->_req_data['orderby']) { |
|
| 2444 | + case 'TXN_ID': |
|
| 2445 | + $orderby = 'TXN_ID'; |
|
| 2446 | + break; |
|
| 2447 | + case 'ATT_fname': |
|
| 2448 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2449 | + break; |
|
| 2450 | + case 'event_name': |
|
| 2451 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 2452 | + break; |
|
| 2453 | + default: // 'TXN_timestamp' |
|
| 2454 | + $orderby = 'TXN_timestamp'; |
|
| 2455 | + } |
|
| 2456 | + |
|
| 2457 | + $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2458 | + $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2459 | + $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2460 | + $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2461 | + |
|
| 2462 | + $offset = ($current_page - 1) * $per_page; |
|
| 2463 | + $limit = array($offset, $per_page); |
|
| 2464 | + |
|
| 2465 | + $_where = array( |
|
| 2466 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2467 | + 'Registration.REG_count' => 1, |
|
| 2468 | + ); |
|
| 2469 | + |
|
| 2470 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 2471 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2472 | + } |
|
| 2473 | + |
|
| 2474 | + if (isset($this->_req_data['s'])) { |
|
| 2475 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2476 | + $_where['OR'] = array( |
|
| 2477 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2478 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2479 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2480 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2481 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2482 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2483 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2484 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2485 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2486 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2487 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2488 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2489 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2490 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2491 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2492 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2493 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2494 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2495 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2496 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2497 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2498 | + ); |
|
| 2499 | + } |
|
| 2500 | + |
|
| 2501 | + // failed transactions |
|
| 2502 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2503 | + || ($count && $view === 'failed'); |
|
| 2504 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2505 | + || ($count && $view === 'abandoned'); |
|
| 2506 | + $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2507 | + || ($count && $view === 'incomplete'); |
|
| 2508 | + |
|
| 2509 | + if ($failed) { |
|
| 2510 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2511 | + } elseif ($abandoned) { |
|
| 2512 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2513 | + } elseif ($incomplete) { |
|
| 2514 | + $_where['STS_ID'] = EEM_Transaction::incomplete_status_code; |
|
| 2515 | + } else { |
|
| 2516 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2517 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2518 | + } |
|
| 2519 | + |
|
| 2520 | + $query_params = apply_filters( |
|
| 2521 | + 'FHEE__Transactions_Admin_Page___get_transactions_query_params', |
|
| 2522 | + array( |
|
| 2523 | + $_where, |
|
| 2524 | + 'order_by' => array($orderby => $sort), |
|
| 2525 | + 'limit' => $limit, |
|
| 2526 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2527 | + ), |
|
| 2528 | + $this->_req_data, |
|
| 2529 | + $view, |
|
| 2530 | + $count |
|
| 2531 | + ); |
|
| 2532 | + |
|
| 2533 | + $transactions = $count |
|
| 2534 | + ? $TXN->count(array($query_params[0]), 'TXN_ID', true) |
|
| 2535 | + : $TXN->get_all($query_params); |
|
| 2536 | + |
|
| 2537 | + return $transactions; |
|
| 2538 | + } |
|
| 2539 | + |
|
| 2540 | + |
|
| 2541 | + /** |
|
| 2542 | + * @since 4.9.79.p |
|
| 2543 | + * @throws EE_Error |
|
| 2544 | + * @throws InvalidArgumentException |
|
| 2545 | + * @throws InvalidDataTypeException |
|
| 2546 | + * @throws InvalidInterfaceException |
|
| 2547 | + * @throws ReflectionException |
|
| 2548 | + * @throws RuntimeException |
|
| 2549 | + */ |
|
| 2550 | + public function recalculateLineItems() |
|
| 2551 | + { |
|
| 2552 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2553 | + /** @var EE_Transaction $transaction */ |
|
| 2554 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2555 | + $total_line_item = $transaction->total_line_item(false); |
|
| 2556 | + $success = false; |
|
| 2557 | + if ($total_line_item instanceof EE_Line_Item) { |
|
| 2558 | + EEH_Line_Item::resetIsTaxableForTickets($total_line_item); |
|
| 2559 | + $success = EEH_Line_Item::apply_taxes($total_line_item, true); |
|
| 2560 | + } |
|
| 2561 | + $this->_redirect_after_action( |
|
| 2562 | + (bool) $success, |
|
| 2563 | + esc_html__('Transaction taxes and totals', 'event_espresso'), |
|
| 2564 | + esc_html__('recalculated', 'event_espresso'), |
|
| 2565 | + isset($this->_req_data['redirect_to']) |
|
| 2566 | + ? array( |
|
| 2567 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2568 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2569 | + ) |
|
| 2570 | + : array(), |
|
| 2571 | + true |
|
| 2572 | + ); |
|
| 2573 | + } |
|
| 2574 | 2574 | } |
@@ -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.80.rc.004'); |
|
| 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.80.rc.004'); |
|
| 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 | } |