@@ -37,138 +37,138 @@ |
||
| 37 | 37 | * @since 4.0 |
| 38 | 38 | */ |
| 39 | 39 | if (function_exists('espresso_version')) { |
| 40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 41 | - /** |
|
| 42 | - * espresso_duplicate_plugin_error |
|
| 43 | - * displays if more than one version of EE is activated at the same time. |
|
| 44 | - */ |
|
| 45 | - function espresso_duplicate_plugin_error() |
|
| 46 | - { |
|
| 47 | - ?> |
|
| 40 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 41 | + /** |
|
| 42 | + * espresso_duplicate_plugin_error |
|
| 43 | + * displays if more than one version of EE is activated at the same time. |
|
| 44 | + */ |
|
| 45 | + function espresso_duplicate_plugin_error() |
|
| 46 | + { |
|
| 47 | + ?> |
|
| 48 | 48 | <div class="error"> |
| 49 | 49 | <p> |
| 50 | 50 | <?php |
| 51 | - echo esc_html__( |
|
| 52 | - '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.', |
|
| 53 | - 'event_espresso' |
|
| 54 | - ); ?> |
|
| 51 | + echo esc_html__( |
|
| 52 | + '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.', |
|
| 53 | + 'event_espresso' |
|
| 54 | + ); ?> |
|
| 55 | 55 | </p> |
| 56 | 56 | </div> |
| 57 | 57 | <?php |
| 58 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 58 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | 62 | } else { |
| 63 | - define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
| 64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 65 | - /** |
|
| 66 | - * espresso_minimum_php_version_error |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - function espresso_minimum_php_version_error() |
|
| 71 | - { |
|
| 72 | - ?> |
|
| 63 | + define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
| 64 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 65 | + /** |
|
| 66 | + * espresso_minimum_php_version_error |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + function espresso_minimum_php_version_error() |
|
| 71 | + { |
|
| 72 | + ?> |
|
| 73 | 73 | <div class="error"> |
| 74 | 74 | <p> |
| 75 | 75 | <?php |
| 76 | - printf( |
|
| 77 | - esc_html__( |
|
| 78 | - '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.', |
|
| 79 | - 'event_espresso' |
|
| 80 | - ), |
|
| 81 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 82 | - PHP_VERSION, |
|
| 83 | - '<br/>', |
|
| 84 | - '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>' |
|
| 85 | - ); |
|
| 86 | - ?> |
|
| 76 | + printf( |
|
| 77 | + esc_html__( |
|
| 78 | + '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.', |
|
| 79 | + 'event_espresso' |
|
| 80 | + ), |
|
| 81 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 82 | + PHP_VERSION, |
|
| 83 | + '<br/>', |
|
| 84 | + '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>' |
|
| 85 | + ); |
|
| 86 | + ?> |
|
| 87 | 87 | </p> |
| 88 | 88 | </div> |
| 89 | 89 | <?php |
| 90 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 91 | - } |
|
| 90 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 94 | - } else { |
|
| 95 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 93 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 94 | + } else { |
|
| 95 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 96 | 96 | |
| 97 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
| 97 | + require_once __DIR__ . '/vendor/autoload.php'; |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * espresso_version |
|
| 101 | - * Returns the plugin version |
|
| 102 | - * |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - function espresso_version(): string |
|
| 106 | - { |
|
| 107 | - return apply_filters('FHEE__espresso__espresso_version', '5.0.23.rc.000'); |
|
| 108 | - } |
|
| 99 | + /** |
|
| 100 | + * espresso_version |
|
| 101 | + * Returns the plugin version |
|
| 102 | + * |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + function espresso_version(): string |
|
| 106 | + { |
|
| 107 | + return apply_filters('FHEE__espresso__espresso_version', '5.0.23.rc.000'); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * espresso_plugin_activation |
|
| 112 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 113 | - */ |
|
| 114 | - function espresso_plugin_activation() |
|
| 115 | - { |
|
| 116 | - update_option('ee_espresso_activation', true); |
|
| 117 | - update_option('event-espresso-core_allow_tracking', 'no'); |
|
| 118 | - update_option('event-espresso-core_tracking_notice', 'hide'); |
|
| 119 | - // Run WP GraphQL activation callback |
|
| 120 | - espressoLoadWpGraphQL(); |
|
| 121 | - graphql_activation_callback(); |
|
| 122 | - } |
|
| 110 | + /** |
|
| 111 | + * espresso_plugin_activation |
|
| 112 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 113 | + */ |
|
| 114 | + function espresso_plugin_activation() |
|
| 115 | + { |
|
| 116 | + update_option('ee_espresso_activation', true); |
|
| 117 | + update_option('event-espresso-core_allow_tracking', 'no'); |
|
| 118 | + update_option('event-espresso-core_tracking_notice', 'hide'); |
|
| 119 | + // Run WP GraphQL activation callback |
|
| 120 | + espressoLoadWpGraphQL(); |
|
| 121 | + graphql_activation_callback(); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 124 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * espresso_plugin_deactivation |
|
| 128 | - */ |
|
| 129 | - function espresso_plugin_deactivation() |
|
| 130 | - { |
|
| 131 | - // Run WP GraphQL deactivation callback |
|
| 132 | - espressoLoadWpGraphQL(); |
|
| 133 | - graphql_deactivation_callback(); |
|
| 134 | - delete_option('event-espresso-core_allow_tracking'); |
|
| 135 | - delete_option('event-espresso-core_tracking_notice'); |
|
| 136 | - } |
|
| 137 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
| 126 | + /** |
|
| 127 | + * espresso_plugin_deactivation |
|
| 128 | + */ |
|
| 129 | + function espresso_plugin_deactivation() |
|
| 130 | + { |
|
| 131 | + // Run WP GraphQL deactivation callback |
|
| 132 | + espressoLoadWpGraphQL(); |
|
| 133 | + graphql_deactivation_callback(); |
|
| 134 | + delete_option('event-espresso-core_allow_tracking'); |
|
| 135 | + delete_option('event-espresso-core_tracking_notice'); |
|
| 136 | + } |
|
| 137 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
| 138 | 138 | |
| 139 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 140 | - bootstrap_espresso(); |
|
| 141 | - } |
|
| 139 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 140 | + bootstrap_espresso(); |
|
| 141 | + } |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | if (! function_exists('espresso_deactivate_plugin')) { |
| 145 | - /** |
|
| 146 | - * deactivate_plugin |
|
| 147 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 148 | - * |
|
| 149 | - * @access public |
|
| 150 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 151 | - * @return void |
|
| 152 | - */ |
|
| 153 | - function espresso_deactivate_plugin(string $plugin_basename = '') |
|
| 154 | - { |
|
| 155 | - if (! function_exists('deactivate_plugins')) { |
|
| 156 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 157 | - } |
|
| 158 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 159 | - deactivate_plugins($plugin_basename); |
|
| 160 | - } |
|
| 145 | + /** |
|
| 146 | + * deactivate_plugin |
|
| 147 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 148 | + * |
|
| 149 | + * @access public |
|
| 150 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 151 | + * @return void |
|
| 152 | + */ |
|
| 153 | + function espresso_deactivate_plugin(string $plugin_basename = '') |
|
| 154 | + { |
|
| 155 | + if (! function_exists('deactivate_plugins')) { |
|
| 156 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 157 | + } |
|
| 158 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 159 | + deactivate_plugins($plugin_basename); |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
| 164 | 164 | if (! function_exists('espressoLoadWpGraphQL')) { |
| 165 | - function espressoLoadWpGraphQL() |
|
| 166 | - { |
|
| 167 | - if ( |
|
| 168 | - ! class_exists('WPGraphQL') |
|
| 169 | - && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php') |
|
| 170 | - ) { |
|
| 171 | - require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
| 172 | - } |
|
| 173 | - } |
|
| 165 | + function espressoLoadWpGraphQL() |
|
| 166 | + { |
|
| 167 | + if ( |
|
| 168 | + ! class_exists('WPGraphQL') |
|
| 169 | + && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php') |
|
| 170 | + ) { |
|
| 171 | + require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -19,1306 +19,1306 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Extend_Events_Admin_Page extends Events_Admin_Page |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Extend_Events_Admin_Page constructor. |
|
| 24 | - * |
|
| 25 | - * @param bool $routing |
|
| 26 | - * @throws ReflectionException |
|
| 27 | - */ |
|
| 28 | - public function __construct($routing = true) |
|
| 29 | - { |
|
| 30 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 31 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 32 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 33 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 34 | - } |
|
| 35 | - parent::__construct($routing); |
|
| 36 | - $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - protected function _set_page_config() |
|
| 41 | - { |
|
| 42 | - parent::_set_page_config(); |
|
| 43 | - |
|
| 44 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 45 | - // is there an evt_id in the request? |
|
| 46 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 47 | - $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
| 48 | - $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
| 49 | - $new_page_routes = [ |
|
| 50 | - 'duplicate_event' => [ |
|
| 51 | - 'func' => '_duplicate_event', |
|
| 52 | - 'capability' => 'ee_edit_event', |
|
| 53 | - 'obj_id' => $EVT_ID, |
|
| 54 | - 'noheader' => true, |
|
| 55 | - ], |
|
| 56 | - 'import_page' => [ |
|
| 57 | - 'func' => '_import_page', |
|
| 58 | - 'capability' => 'import', |
|
| 59 | - ], |
|
| 60 | - 'import' => [ |
|
| 61 | - 'func' => '_import_events', |
|
| 62 | - 'capability' => 'import', |
|
| 63 | - 'noheader' => true, |
|
| 64 | - ], |
|
| 65 | - 'import_events' => [ |
|
| 66 | - 'func' => '_import_events', |
|
| 67 | - 'capability' => 'import', |
|
| 68 | - 'noheader' => true, |
|
| 69 | - ], |
|
| 70 | - 'export_events' => [ |
|
| 71 | - 'func' => '_events_export', |
|
| 72 | - 'capability' => 'export', |
|
| 73 | - 'noheader' => true, |
|
| 74 | - ], |
|
| 75 | - 'export_categories' => [ |
|
| 76 | - 'func' => '_categories_export', |
|
| 77 | - 'capability' => 'export', |
|
| 78 | - 'noheader' => true, |
|
| 79 | - ], |
|
| 80 | - 'sample_export_file' => [ |
|
| 81 | - 'func' => '_sample_export_file', |
|
| 82 | - 'capability' => 'export', |
|
| 83 | - 'noheader' => true, |
|
| 84 | - ], |
|
| 85 | - 'update_template_settings' => [ |
|
| 86 | - 'func' => '_update_template_settings', |
|
| 87 | - 'capability' => 'manage_options', |
|
| 88 | - 'noheader' => true, |
|
| 89 | - ], |
|
| 90 | - 'ticket_list_table' => [ |
|
| 91 | - 'func' => '_tickets_overview_list_table', |
|
| 92 | - 'capability' => 'ee_read_default_tickets', |
|
| 93 | - ], |
|
| 94 | - ]; |
|
| 95 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 96 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 97 | - // don't load these meta boxes if using the advanced editor |
|
| 98 | - if ( |
|
| 99 | - ! $this->admin_config->useAdvancedEditor() |
|
| 100 | - || ! $this->feature->allowed('use_default_ticket_manager') |
|
| 101 | - ) { |
|
| 102 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 103 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 104 | - |
|
| 105 | - $legacy_editor_page_routes = [ |
|
| 106 | - 'trash_ticket' => [ |
|
| 107 | - 'func' => '_trash_or_restore_ticket', |
|
| 108 | - 'capability' => 'ee_delete_default_ticket', |
|
| 109 | - 'obj_id' => $TKT_ID, |
|
| 110 | - 'noheader' => true, |
|
| 111 | - 'args' => ['trash' => true], |
|
| 112 | - ], |
|
| 113 | - 'trash_tickets' => [ |
|
| 114 | - 'func' => '_trash_or_restore_ticket', |
|
| 115 | - 'capability' => 'ee_delete_default_tickets', |
|
| 116 | - 'noheader' => true, |
|
| 117 | - 'args' => ['trash' => true], |
|
| 118 | - ], |
|
| 119 | - 'restore_ticket' => [ |
|
| 120 | - 'func' => '_trash_or_restore_ticket', |
|
| 121 | - 'capability' => 'ee_delete_default_ticket', |
|
| 122 | - 'obj_id' => $TKT_ID, |
|
| 123 | - 'noheader' => true, |
|
| 124 | - ], |
|
| 125 | - 'restore_tickets' => [ |
|
| 126 | - 'func' => '_trash_or_restore_ticket', |
|
| 127 | - 'capability' => 'ee_delete_default_tickets', |
|
| 128 | - 'noheader' => true, |
|
| 129 | - ], |
|
| 130 | - 'delete_ticket' => [ |
|
| 131 | - 'func' => '_delete_ticket', |
|
| 132 | - 'capability' => 'ee_delete_default_ticket', |
|
| 133 | - 'obj_id' => $TKT_ID, |
|
| 134 | - 'noheader' => true, |
|
| 135 | - ], |
|
| 136 | - 'delete_tickets' => [ |
|
| 137 | - 'func' => '_delete_ticket', |
|
| 138 | - 'capability' => 'ee_delete_default_tickets', |
|
| 139 | - 'noheader' => true, |
|
| 140 | - ], |
|
| 141 | - ]; |
|
| 142 | - $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 146 | - // partial route/config override |
|
| 147 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 148 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 149 | - |
|
| 150 | - // add default tickets tab and template settings nav tabs (note union at end) |
|
| 151 | - $this->_page_config = [ |
|
| 152 | - 'ticket_list_table' => [ |
|
| 153 | - 'nav' => [ |
|
| 154 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 155 | - 'icon' => 'dashicons-tickets-alt', |
|
| 156 | - 'order' => 60, |
|
| 157 | - ], |
|
| 158 | - 'list_table' => 'Tickets_List_Table', |
|
| 159 | - 'require_nonce' => false, |
|
| 160 | - ], |
|
| 161 | - 'template_settings' => [ |
|
| 162 | - 'nav' => [ |
|
| 163 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 164 | - 'icon' => 'dashicons-layout', |
|
| 165 | - 'order' => 30, |
|
| 166 | - ], |
|
| 167 | - 'metaboxes' => array_merge( |
|
| 168 | - ['_publish_post_box'], |
|
| 169 | - $this->_default_espresso_metaboxes |
|
| 170 | - ), |
|
| 171 | - 'help_tabs' => [ |
|
| 172 | - 'general_settings_templates_help_tab' => [ |
|
| 173 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 174 | - 'filename' => 'general_settings_templates', |
|
| 175 | - ], |
|
| 176 | - ], |
|
| 177 | - 'require_nonce' => false, |
|
| 178 | - ], |
|
| 179 | - ] + $this->_page_config; |
|
| 180 | - |
|
| 181 | - // add filters and actions |
|
| 182 | - // modifying _views |
|
| 183 | - add_filter( |
|
| 184 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 185 | - [$this, 'add_additional_datetime_button'], |
|
| 186 | - 10, |
|
| 187 | - 2 |
|
| 188 | - ); |
|
| 189 | - add_filter( |
|
| 190 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 191 | - [$this, 'add_datetime_clone_button'], |
|
| 192 | - 10, |
|
| 193 | - 2 |
|
| 194 | - ); |
|
| 195 | - add_filter( |
|
| 196 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
| 197 | - [$this, 'datetime_timezones_template'], |
|
| 198 | - 10, |
|
| 199 | - 2 |
|
| 200 | - ); |
|
| 201 | - // filters for event list table |
|
| 202 | - add_filter( |
|
| 203 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 204 | - [$this, 'extra_list_table_actions'], |
|
| 205 | - 10, |
|
| 206 | - 2 |
|
| 207 | - ); |
|
| 208 | - // legend item |
|
| 209 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']); |
|
| 210 | - add_action('admin_init', [$this, 'admin_init']); |
|
| 211 | - // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
| 212 | - // add_filter('get_sample_permalink_html', [DuplicateEventButton::class, 'addButton'], 8, 2); |
|
| 213 | - DuplicateEventButton::addEventEditorPermalinkButton(8); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * admin_init |
|
| 219 | - */ |
|
| 220 | - public function admin_init() |
|
| 221 | - { |
|
| 222 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 223 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 224 | - 'event_espresso' |
|
| 225 | - ); |
|
| 226 | - EE_Registry::$i18n_js_strings['event_starts_on'] = esc_html__('Event Starts on', 'event_espresso'); |
|
| 227 | - EE_Registry::$i18n_js_strings['event_ends_on'] = esc_html__('Event Ends on', 'event_espresso'); |
|
| 228 | - EE_Registry::$i18n_js_strings['event_datetime_actions'] = esc_html__('Actions', 'event_espresso'); |
|
| 229 | - EE_Registry::$i18n_js_strings['event_clone_dt_msg'] = esc_html__( |
|
| 230 | - 'Clone this Event Date and Time', |
|
| 231 | - 'event_espresso' |
|
| 232 | - ); |
|
| 233 | - EE_Registry::$i18n_js_strings['remove_event_dt_msg'] = esc_html__( |
|
| 234 | - 'Remove this Event Time', |
|
| 235 | - 'event_espresso' |
|
| 236 | - ); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Add per page screen options to the default ticket list table view. |
|
| 242 | - * |
|
| 243 | - * @throws InvalidArgumentException |
|
| 244 | - * @throws InvalidDataTypeException |
|
| 245 | - * @throws InvalidInterfaceException |
|
| 246 | - */ |
|
| 247 | - protected function _add_screen_options_ticket_list_table() |
|
| 248 | - { |
|
| 249 | - $this->_per_page_screen_option(); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @param string $return the current html |
|
| 255 | - * @param int $id the post id for the page |
|
| 256 | - * @param string|null $new_title What the title is |
|
| 257 | - * @param string|null $new_slug what the slug is |
|
| 258 | - * @return string |
|
| 259 | - * @deprecated 5.0.0.p |
|
| 260 | - */ |
|
| 261 | - public function extra_permalink_field_buttons( |
|
| 262 | - string $return, |
|
| 263 | - int $id, |
|
| 264 | - ?string $new_title, |
|
| 265 | - ?string $new_slug |
|
| 266 | - ): string { |
|
| 267 | - $return = DuplicateEventButton::addButton($return, $id, $new_title, $new_slug); |
|
| 268 | - return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Set the list table views for the default ticket list table view. |
|
| 274 | - */ |
|
| 275 | - public function _set_list_table_views_ticket_list_table() |
|
| 276 | - { |
|
| 277 | - $this->_views = [ |
|
| 278 | - 'all' => [ |
|
| 279 | - 'slug' => 'all', |
|
| 280 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 281 | - 'count' => 0, |
|
| 282 | - 'bulk_action' => [ |
|
| 283 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 284 | - ], |
|
| 285 | - ], |
|
| 286 | - 'trashed' => [ |
|
| 287 | - 'slug' => 'trashed', |
|
| 288 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 289 | - 'count' => 0, |
|
| 290 | - 'bulk_action' => [ |
|
| 291 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 292 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 293 | - ], |
|
| 294 | - ], |
|
| 295 | - ]; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Enqueue scripts and styles for the event editor. |
|
| 301 | - */ |
|
| 302 | - public function load_scripts_styles_edit() |
|
| 303 | - { |
|
| 304 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 305 | - wp_register_script( |
|
| 306 | - 'ee-event-editor-heartbeat', |
|
| 307 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 308 | - ['ee_admin_js', 'heartbeat'], |
|
| 309 | - EVENT_ESPRESSO_VERSION, |
|
| 310 | - true |
|
| 311 | - ); |
|
| 312 | - wp_enqueue_script('ee-accounting'); |
|
| 313 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 314 | - } |
|
| 315 | - wp_enqueue_script('event_editor_js'); |
|
| 316 | - wp_register_style( |
|
| 317 | - 'event-editor-css', |
|
| 318 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 319 | - ['ee-admin-css'], |
|
| 320 | - EVENT_ESPRESSO_VERSION |
|
| 321 | - ); |
|
| 322 | - wp_enqueue_style('event-editor-css'); |
|
| 323 | - // styles |
|
| 324 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Sets the views for the default list table view. |
|
| 330 | - * |
|
| 331 | - * @throws EE_Error |
|
| 332 | - * @throws ReflectionException |
|
| 333 | - */ |
|
| 334 | - protected function _set_list_table_views_default() |
|
| 335 | - { |
|
| 336 | - parent::_set_list_table_views_default(); |
|
| 337 | - $new_views = [ |
|
| 338 | - 'today' => [ |
|
| 339 | - 'slug' => 'today', |
|
| 340 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
| 341 | - 'count' => $this->total_events_today(), |
|
| 342 | - 'bulk_action' => [ |
|
| 343 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 344 | - ], |
|
| 345 | - ], |
|
| 346 | - 'month' => [ |
|
| 347 | - 'slug' => 'month', |
|
| 348 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 349 | - 'count' => $this->total_events_this_month(), |
|
| 350 | - 'bulk_action' => [ |
|
| 351 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 352 | - ], |
|
| 353 | - ], |
|
| 354 | - ]; |
|
| 355 | - $this->_views = array_merge($this->_views, $new_views); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Returns the extra action links for the default list table view. |
|
| 361 | - * |
|
| 362 | - * @param array $action_links |
|
| 363 | - * @param EE_Event $event |
|
| 364 | - * @return array |
|
| 365 | - * @throws EE_Error |
|
| 366 | - * @throws ReflectionException |
|
| 367 | - */ |
|
| 368 | - public function extra_list_table_actions(array $action_links, EE_Event $event): array |
|
| 369 | - { |
|
| 370 | - if ( |
|
| 371 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 372 | - 'ee_read_registrations', |
|
| 373 | - 'espresso_registrations_reports', |
|
| 374 | - $event->ID() |
|
| 375 | - ) |
|
| 376 | - ) { |
|
| 377 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 378 | - [ |
|
| 379 | - 'action' => 'reports', |
|
| 380 | - 'EVT_ID' => $event->ID(), |
|
| 381 | - ], |
|
| 382 | - REG_ADMIN_URL |
|
| 383 | - ); |
|
| 384 | - |
|
| 385 | - $action_links[] = ' |
|
| 22 | + /** |
|
| 23 | + * Extend_Events_Admin_Page constructor. |
|
| 24 | + * |
|
| 25 | + * @param bool $routing |
|
| 26 | + * @throws ReflectionException |
|
| 27 | + */ |
|
| 28 | + public function __construct($routing = true) |
|
| 29 | + { |
|
| 30 | + if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 31 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 32 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 33 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 34 | + } |
|
| 35 | + parent::__construct($routing); |
|
| 36 | + $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + protected function _set_page_config() |
|
| 41 | + { |
|
| 42 | + parent::_set_page_config(); |
|
| 43 | + |
|
| 44 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 45 | + // is there an evt_id in the request? |
|
| 46 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 47 | + $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
| 48 | + $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
| 49 | + $new_page_routes = [ |
|
| 50 | + 'duplicate_event' => [ |
|
| 51 | + 'func' => '_duplicate_event', |
|
| 52 | + 'capability' => 'ee_edit_event', |
|
| 53 | + 'obj_id' => $EVT_ID, |
|
| 54 | + 'noheader' => true, |
|
| 55 | + ], |
|
| 56 | + 'import_page' => [ |
|
| 57 | + 'func' => '_import_page', |
|
| 58 | + 'capability' => 'import', |
|
| 59 | + ], |
|
| 60 | + 'import' => [ |
|
| 61 | + 'func' => '_import_events', |
|
| 62 | + 'capability' => 'import', |
|
| 63 | + 'noheader' => true, |
|
| 64 | + ], |
|
| 65 | + 'import_events' => [ |
|
| 66 | + 'func' => '_import_events', |
|
| 67 | + 'capability' => 'import', |
|
| 68 | + 'noheader' => true, |
|
| 69 | + ], |
|
| 70 | + 'export_events' => [ |
|
| 71 | + 'func' => '_events_export', |
|
| 72 | + 'capability' => 'export', |
|
| 73 | + 'noheader' => true, |
|
| 74 | + ], |
|
| 75 | + 'export_categories' => [ |
|
| 76 | + 'func' => '_categories_export', |
|
| 77 | + 'capability' => 'export', |
|
| 78 | + 'noheader' => true, |
|
| 79 | + ], |
|
| 80 | + 'sample_export_file' => [ |
|
| 81 | + 'func' => '_sample_export_file', |
|
| 82 | + 'capability' => 'export', |
|
| 83 | + 'noheader' => true, |
|
| 84 | + ], |
|
| 85 | + 'update_template_settings' => [ |
|
| 86 | + 'func' => '_update_template_settings', |
|
| 87 | + 'capability' => 'manage_options', |
|
| 88 | + 'noheader' => true, |
|
| 89 | + ], |
|
| 90 | + 'ticket_list_table' => [ |
|
| 91 | + 'func' => '_tickets_overview_list_table', |
|
| 92 | + 'capability' => 'ee_read_default_tickets', |
|
| 93 | + ], |
|
| 94 | + ]; |
|
| 95 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 96 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 97 | + // don't load these meta boxes if using the advanced editor |
|
| 98 | + if ( |
|
| 99 | + ! $this->admin_config->useAdvancedEditor() |
|
| 100 | + || ! $this->feature->allowed('use_default_ticket_manager') |
|
| 101 | + ) { |
|
| 102 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 103 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 104 | + |
|
| 105 | + $legacy_editor_page_routes = [ |
|
| 106 | + 'trash_ticket' => [ |
|
| 107 | + 'func' => '_trash_or_restore_ticket', |
|
| 108 | + 'capability' => 'ee_delete_default_ticket', |
|
| 109 | + 'obj_id' => $TKT_ID, |
|
| 110 | + 'noheader' => true, |
|
| 111 | + 'args' => ['trash' => true], |
|
| 112 | + ], |
|
| 113 | + 'trash_tickets' => [ |
|
| 114 | + 'func' => '_trash_or_restore_ticket', |
|
| 115 | + 'capability' => 'ee_delete_default_tickets', |
|
| 116 | + 'noheader' => true, |
|
| 117 | + 'args' => ['trash' => true], |
|
| 118 | + ], |
|
| 119 | + 'restore_ticket' => [ |
|
| 120 | + 'func' => '_trash_or_restore_ticket', |
|
| 121 | + 'capability' => 'ee_delete_default_ticket', |
|
| 122 | + 'obj_id' => $TKT_ID, |
|
| 123 | + 'noheader' => true, |
|
| 124 | + ], |
|
| 125 | + 'restore_tickets' => [ |
|
| 126 | + 'func' => '_trash_or_restore_ticket', |
|
| 127 | + 'capability' => 'ee_delete_default_tickets', |
|
| 128 | + 'noheader' => true, |
|
| 129 | + ], |
|
| 130 | + 'delete_ticket' => [ |
|
| 131 | + 'func' => '_delete_ticket', |
|
| 132 | + 'capability' => 'ee_delete_default_ticket', |
|
| 133 | + 'obj_id' => $TKT_ID, |
|
| 134 | + 'noheader' => true, |
|
| 135 | + ], |
|
| 136 | + 'delete_tickets' => [ |
|
| 137 | + 'func' => '_delete_ticket', |
|
| 138 | + 'capability' => 'ee_delete_default_tickets', |
|
| 139 | + 'noheader' => true, |
|
| 140 | + ], |
|
| 141 | + ]; |
|
| 142 | + $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 146 | + // partial route/config override |
|
| 147 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 148 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 149 | + |
|
| 150 | + // add default tickets tab and template settings nav tabs (note union at end) |
|
| 151 | + $this->_page_config = [ |
|
| 152 | + 'ticket_list_table' => [ |
|
| 153 | + 'nav' => [ |
|
| 154 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 155 | + 'icon' => 'dashicons-tickets-alt', |
|
| 156 | + 'order' => 60, |
|
| 157 | + ], |
|
| 158 | + 'list_table' => 'Tickets_List_Table', |
|
| 159 | + 'require_nonce' => false, |
|
| 160 | + ], |
|
| 161 | + 'template_settings' => [ |
|
| 162 | + 'nav' => [ |
|
| 163 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 164 | + 'icon' => 'dashicons-layout', |
|
| 165 | + 'order' => 30, |
|
| 166 | + ], |
|
| 167 | + 'metaboxes' => array_merge( |
|
| 168 | + ['_publish_post_box'], |
|
| 169 | + $this->_default_espresso_metaboxes |
|
| 170 | + ), |
|
| 171 | + 'help_tabs' => [ |
|
| 172 | + 'general_settings_templates_help_tab' => [ |
|
| 173 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 174 | + 'filename' => 'general_settings_templates', |
|
| 175 | + ], |
|
| 176 | + ], |
|
| 177 | + 'require_nonce' => false, |
|
| 178 | + ], |
|
| 179 | + ] + $this->_page_config; |
|
| 180 | + |
|
| 181 | + // add filters and actions |
|
| 182 | + // modifying _views |
|
| 183 | + add_filter( |
|
| 184 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 185 | + [$this, 'add_additional_datetime_button'], |
|
| 186 | + 10, |
|
| 187 | + 2 |
|
| 188 | + ); |
|
| 189 | + add_filter( |
|
| 190 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 191 | + [$this, 'add_datetime_clone_button'], |
|
| 192 | + 10, |
|
| 193 | + 2 |
|
| 194 | + ); |
|
| 195 | + add_filter( |
|
| 196 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
| 197 | + [$this, 'datetime_timezones_template'], |
|
| 198 | + 10, |
|
| 199 | + 2 |
|
| 200 | + ); |
|
| 201 | + // filters for event list table |
|
| 202 | + add_filter( |
|
| 203 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 204 | + [$this, 'extra_list_table_actions'], |
|
| 205 | + 10, |
|
| 206 | + 2 |
|
| 207 | + ); |
|
| 208 | + // legend item |
|
| 209 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']); |
|
| 210 | + add_action('admin_init', [$this, 'admin_init']); |
|
| 211 | + // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
| 212 | + // add_filter('get_sample_permalink_html', [DuplicateEventButton::class, 'addButton'], 8, 2); |
|
| 213 | + DuplicateEventButton::addEventEditorPermalinkButton(8); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * admin_init |
|
| 219 | + */ |
|
| 220 | + public function admin_init() |
|
| 221 | + { |
|
| 222 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 223 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 224 | + 'event_espresso' |
|
| 225 | + ); |
|
| 226 | + EE_Registry::$i18n_js_strings['event_starts_on'] = esc_html__('Event Starts on', 'event_espresso'); |
|
| 227 | + EE_Registry::$i18n_js_strings['event_ends_on'] = esc_html__('Event Ends on', 'event_espresso'); |
|
| 228 | + EE_Registry::$i18n_js_strings['event_datetime_actions'] = esc_html__('Actions', 'event_espresso'); |
|
| 229 | + EE_Registry::$i18n_js_strings['event_clone_dt_msg'] = esc_html__( |
|
| 230 | + 'Clone this Event Date and Time', |
|
| 231 | + 'event_espresso' |
|
| 232 | + ); |
|
| 233 | + EE_Registry::$i18n_js_strings['remove_event_dt_msg'] = esc_html__( |
|
| 234 | + 'Remove this Event Time', |
|
| 235 | + 'event_espresso' |
|
| 236 | + ); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Add per page screen options to the default ticket list table view. |
|
| 242 | + * |
|
| 243 | + * @throws InvalidArgumentException |
|
| 244 | + * @throws InvalidDataTypeException |
|
| 245 | + * @throws InvalidInterfaceException |
|
| 246 | + */ |
|
| 247 | + protected function _add_screen_options_ticket_list_table() |
|
| 248 | + { |
|
| 249 | + $this->_per_page_screen_option(); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @param string $return the current html |
|
| 255 | + * @param int $id the post id for the page |
|
| 256 | + * @param string|null $new_title What the title is |
|
| 257 | + * @param string|null $new_slug what the slug is |
|
| 258 | + * @return string |
|
| 259 | + * @deprecated 5.0.0.p |
|
| 260 | + */ |
|
| 261 | + public function extra_permalink_field_buttons( |
|
| 262 | + string $return, |
|
| 263 | + int $id, |
|
| 264 | + ?string $new_title, |
|
| 265 | + ?string $new_slug |
|
| 266 | + ): string { |
|
| 267 | + $return = DuplicateEventButton::addButton($return, $id, $new_title, $new_slug); |
|
| 268 | + return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Set the list table views for the default ticket list table view. |
|
| 274 | + */ |
|
| 275 | + public function _set_list_table_views_ticket_list_table() |
|
| 276 | + { |
|
| 277 | + $this->_views = [ |
|
| 278 | + 'all' => [ |
|
| 279 | + 'slug' => 'all', |
|
| 280 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 281 | + 'count' => 0, |
|
| 282 | + 'bulk_action' => [ |
|
| 283 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 284 | + ], |
|
| 285 | + ], |
|
| 286 | + 'trashed' => [ |
|
| 287 | + 'slug' => 'trashed', |
|
| 288 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 289 | + 'count' => 0, |
|
| 290 | + 'bulk_action' => [ |
|
| 291 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 292 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 293 | + ], |
|
| 294 | + ], |
|
| 295 | + ]; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Enqueue scripts and styles for the event editor. |
|
| 301 | + */ |
|
| 302 | + public function load_scripts_styles_edit() |
|
| 303 | + { |
|
| 304 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
| 305 | + wp_register_script( |
|
| 306 | + 'ee-event-editor-heartbeat', |
|
| 307 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 308 | + ['ee_admin_js', 'heartbeat'], |
|
| 309 | + EVENT_ESPRESSO_VERSION, |
|
| 310 | + true |
|
| 311 | + ); |
|
| 312 | + wp_enqueue_script('ee-accounting'); |
|
| 313 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 314 | + } |
|
| 315 | + wp_enqueue_script('event_editor_js'); |
|
| 316 | + wp_register_style( |
|
| 317 | + 'event-editor-css', |
|
| 318 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 319 | + ['ee-admin-css'], |
|
| 320 | + EVENT_ESPRESSO_VERSION |
|
| 321 | + ); |
|
| 322 | + wp_enqueue_style('event-editor-css'); |
|
| 323 | + // styles |
|
| 324 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Sets the views for the default list table view. |
|
| 330 | + * |
|
| 331 | + * @throws EE_Error |
|
| 332 | + * @throws ReflectionException |
|
| 333 | + */ |
|
| 334 | + protected function _set_list_table_views_default() |
|
| 335 | + { |
|
| 336 | + parent::_set_list_table_views_default(); |
|
| 337 | + $new_views = [ |
|
| 338 | + 'today' => [ |
|
| 339 | + 'slug' => 'today', |
|
| 340 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
| 341 | + 'count' => $this->total_events_today(), |
|
| 342 | + 'bulk_action' => [ |
|
| 343 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 344 | + ], |
|
| 345 | + ], |
|
| 346 | + 'month' => [ |
|
| 347 | + 'slug' => 'month', |
|
| 348 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 349 | + 'count' => $this->total_events_this_month(), |
|
| 350 | + 'bulk_action' => [ |
|
| 351 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 352 | + ], |
|
| 353 | + ], |
|
| 354 | + ]; |
|
| 355 | + $this->_views = array_merge($this->_views, $new_views); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Returns the extra action links for the default list table view. |
|
| 361 | + * |
|
| 362 | + * @param array $action_links |
|
| 363 | + * @param EE_Event $event |
|
| 364 | + * @return array |
|
| 365 | + * @throws EE_Error |
|
| 366 | + * @throws ReflectionException |
|
| 367 | + */ |
|
| 368 | + public function extra_list_table_actions(array $action_links, EE_Event $event): array |
|
| 369 | + { |
|
| 370 | + if ( |
|
| 371 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 372 | + 'ee_read_registrations', |
|
| 373 | + 'espresso_registrations_reports', |
|
| 374 | + $event->ID() |
|
| 375 | + ) |
|
| 376 | + ) { |
|
| 377 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 378 | + [ |
|
| 379 | + 'action' => 'reports', |
|
| 380 | + 'EVT_ID' => $event->ID(), |
|
| 381 | + ], |
|
| 382 | + REG_ADMIN_URL |
|
| 383 | + ); |
|
| 384 | + |
|
| 385 | + $action_links[] = ' |
|
| 386 | 386 | <a href="' . $reports_link . '" |
| 387 | 387 | aria-label="' . esc_attr__('View Report', 'event_espresso') . '" |
| 388 | 388 | class="ee-aria-tooltip button button--icon-only" |
| 389 | 389 | > |
| 390 | 390 | <span class="dashicons dashicons-chart-bar"></span> |
| 391 | 391 | </a>'; |
| 392 | - } |
|
| 393 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 394 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 395 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 396 | - 'see_notifications_for', |
|
| 397 | - null, |
|
| 398 | - ['EVT_ID' => $event->ID()] |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - return $action_links; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @param $items |
|
| 407 | - * @return mixed |
|
| 408 | - */ |
|
| 409 | - public function additional_legend_items($items) |
|
| 410 | - { |
|
| 411 | - if ( |
|
| 412 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 413 | - 'ee_read_registrations', |
|
| 414 | - 'espresso_registrations_reports' |
|
| 415 | - ) |
|
| 416 | - ) { |
|
| 417 | - $items['reports'] = [ |
|
| 418 | - 'class' => 'dashicons dashicons-chart-bar', |
|
| 419 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 420 | - ]; |
|
| 421 | - } |
|
| 422 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 423 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 424 | - // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset |
|
| 425 | - // (can only use numeric offsets when treating strings as arrays) |
|
| 426 | - if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) { |
|
| 427 | - $items['view_related_messages'] = [ |
|
| 428 | - 'class' => $related_for_icon['css_class'], |
|
| 429 | - 'desc' => $related_for_icon['label'], |
|
| 430 | - ]; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - return $items; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * This is the callback method for the duplicate event route |
|
| 439 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 440 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 441 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 442 | - * After duplication the redirect is to the new event edit page. |
|
| 443 | - * |
|
| 444 | - * @return void |
|
| 445 | - * @throws EE_Error If EE_Event is not available with given ID |
|
| 446 | - * @throws ReflectionException |
|
| 447 | - * @access protected |
|
| 448 | - */ |
|
| 449 | - protected function _duplicate_event() |
|
| 450 | - { |
|
| 451 | - // first make sure the ID for the event is in the request. |
|
| 452 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 453 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 454 | - if (! $EVT_ID) { |
|
| 455 | - EE_Error::add_error( |
|
| 456 | - esc_html__( |
|
| 457 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 458 | - 'event_espresso' |
|
| 459 | - ), |
|
| 460 | - __FILE__, |
|
| 461 | - __FUNCTION__, |
|
| 462 | - __LINE__ |
|
| 463 | - ); |
|
| 464 | - $this->_redirect_after_action(false, '', '', [], true); |
|
| 465 | - return; |
|
| 466 | - } |
|
| 467 | - // k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 468 | - $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 469 | - if (! $orig_event instanceof EE_Event) { |
|
| 470 | - throw new EE_Error( |
|
| 471 | - sprintf( |
|
| 472 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 473 | - $EVT_ID |
|
| 474 | - ) |
|
| 475 | - ); |
|
| 476 | - } |
|
| 477 | - // k now let's clone the $orig_event before getting relations |
|
| 478 | - $new_event = clone $orig_event; |
|
| 479 | - // original datetimes |
|
| 480 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 481 | - // other original relations |
|
| 482 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 483 | - // reset the ID and modify other details to make it clear this is a dupe |
|
| 484 | - $new_event->set('EVT_ID', 0); |
|
| 485 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 486 | - $new_event->set('EVT_name', $new_name); |
|
| 487 | - $new_event->set( |
|
| 488 | - 'EVT_slug', |
|
| 489 | - wp_unique_post_slug( |
|
| 490 | - sanitize_title($orig_event->name()), |
|
| 491 | - 0, |
|
| 492 | - 'publish', |
|
| 493 | - EspressoPostType::EVENTS, |
|
| 494 | - 0 |
|
| 495 | - ) |
|
| 496 | - ); |
|
| 497 | - $new_event->set('status', 'draft'); |
|
| 498 | - // duplicate discussion settings |
|
| 499 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 500 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 501 | - // save the new event |
|
| 502 | - $new_event->save(); |
|
| 503 | - // venues |
|
| 504 | - foreach ($orig_ven as $ven) { |
|
| 505 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
| 506 | - } |
|
| 507 | - $new_event->save(); |
|
| 508 | - // now we need to get the question group relations and handle that |
|
| 509 | - // first primary question groups |
|
| 510 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
| 511 | - 'Question_Group', |
|
| 512 | - [['Event_Question_Group.EQG_primary' => true]] |
|
| 513 | - ); |
|
| 514 | - if (! empty($orig_primary_qgs)) { |
|
| 515 | - foreach ($orig_primary_qgs as $obj) { |
|
| 516 | - if ($obj instanceof EE_Question_Group) { |
|
| 517 | - $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - // next additional attendee question groups |
|
| 522 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
| 523 | - 'Question_Group', |
|
| 524 | - [['Event_Question_Group.EQG_additional' => true]] |
|
| 525 | - ); |
|
| 526 | - if (! empty($orig_additional_qgs)) { |
|
| 527 | - foreach ($orig_additional_qgs as $obj) { |
|
| 528 | - if ($obj instanceof EE_Question_Group) { |
|
| 529 | - $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - $new_event->save(); |
|
| 535 | - |
|
| 536 | - // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 537 | - $cloned_tickets = []; |
|
| 538 | - foreach ($orig_datetimes as $orig_dtt) { |
|
| 539 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
| 540 | - continue; |
|
| 541 | - } |
|
| 542 | - $new_dtt = clone $orig_dtt; |
|
| 543 | - $orig_tickets = $orig_dtt->tickets(); |
|
| 544 | - // save new dtt then add to event |
|
| 545 | - $new_dtt->set('DTT_ID', 0); |
|
| 546 | - $new_dtt->set('DTT_sold', 0); |
|
| 547 | - $new_dtt->set_reserved(0); |
|
| 548 | - $new_dtt->save(); |
|
| 549 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 550 | - $new_event->save(); |
|
| 551 | - // now let's get the ticket relations setup. |
|
| 552 | - foreach ((array) $orig_tickets as $orig_ticket) { |
|
| 553 | - // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 554 | - if (! $orig_ticket instanceof EE_Ticket) { |
|
| 555 | - continue; |
|
| 556 | - } |
|
| 557 | - // is this ticket archived? If it is then let's skip |
|
| 558 | - if ($orig_ticket->get('TKT_deleted')) { |
|
| 559 | - continue; |
|
| 560 | - } |
|
| 561 | - // does this original ticket already exist in the clone_tickets cache? |
|
| 562 | - // If so we'll just use the new ticket from it. |
|
| 563 | - if (isset($cloned_tickets[ $orig_ticket->ID() ])) { |
|
| 564 | - $new_ticket = $cloned_tickets[ $orig_ticket->ID() ]; |
|
| 565 | - } else { |
|
| 566 | - $new_ticket = clone $orig_ticket; |
|
| 567 | - // get relations on the $orig_ticket that we need to set up. |
|
| 568 | - $orig_prices = $orig_ticket->prices(); |
|
| 569 | - $new_ticket->set('TKT_ID', 0); |
|
| 570 | - $new_ticket->set('TKT_sold', 0); |
|
| 571 | - $new_ticket->set('TKT_reserved', 0); |
|
| 572 | - // make sure new ticket has ID. |
|
| 573 | - $new_ticket->save(); |
|
| 574 | - // price relations on new ticket need to be setup. |
|
| 575 | - foreach ($orig_prices as $orig_price) { |
|
| 576 | - // don't clone default prices, just add a relation |
|
| 577 | - if ($orig_price->is_default()) { |
|
| 578 | - $new_ticket->_add_relation_to($orig_price, 'Price'); |
|
| 579 | - $new_ticket->save(); |
|
| 580 | - continue; |
|
| 581 | - } |
|
| 582 | - $new_price = clone $orig_price; |
|
| 583 | - $new_price->set('PRC_ID', 0); |
|
| 584 | - $new_price->save(); |
|
| 585 | - $new_ticket->_add_relation_to($new_price, 'Price'); |
|
| 586 | - } |
|
| 587 | - $new_ticket->save(); |
|
| 588 | - |
|
| 589 | - do_action( |
|
| 590 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
| 591 | - $orig_ticket, |
|
| 592 | - $new_ticket, |
|
| 593 | - $orig_prices, |
|
| 594 | - $orig_event, |
|
| 595 | - $orig_dtt, |
|
| 596 | - $new_dtt |
|
| 597 | - ); |
|
| 598 | - $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket; |
|
| 599 | - } |
|
| 600 | - // k now we can add the new ticket as a relation to the new datetime |
|
| 601 | - // and make sure it's added to our cached $cloned_tickets array |
|
| 602 | - // for use with later datetimes that have the same ticket. |
|
| 603 | - $new_dtt->_add_relation_to($new_ticket, 'Ticket'); |
|
| 604 | - } |
|
| 605 | - $new_dtt->save(); |
|
| 606 | - } |
|
| 607 | - // clone taxonomy information |
|
| 608 | - $taxonomies_to_clone_with = apply_filters( |
|
| 609 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 610 | - ['espresso_event_categories', 'espresso_event_type', 'post_tag'] |
|
| 611 | - ); |
|
| 612 | - // get terms for original event (notice) |
|
| 613 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 614 | - // loop through terms and add them to new event. |
|
| 615 | - foreach ($orig_terms as $term) { |
|
| 616 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - // duplicate other core WP_Post items for this event. |
|
| 620 | - // post thumbnail (feature image). |
|
| 621 | - $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
| 622 | - if ($feature_image_id) { |
|
| 623 | - update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // duplicate page_template setting |
|
| 627 | - $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
| 628 | - if ($page_template) { |
|
| 629 | - update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 633 | - // now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 634 | - if ($new_event->ID()) { |
|
| 635 | - $redirect_args = [ |
|
| 636 | - 'post' => $new_event->ID(), |
|
| 637 | - 'action' => 'edit', |
|
| 638 | - ]; |
|
| 639 | - EE_Error::add_success( |
|
| 640 | - esc_html__( |
|
| 641 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 642 | - 'event_espresso' |
|
| 643 | - ) |
|
| 644 | - ); |
|
| 645 | - } else { |
|
| 646 | - $redirect_args = [ |
|
| 647 | - 'action' => 'default', |
|
| 648 | - ]; |
|
| 649 | - EE_Error::add_error( |
|
| 650 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 651 | - __FILE__, |
|
| 652 | - __FUNCTION__, |
|
| 653 | - __LINE__ |
|
| 654 | - ); |
|
| 655 | - } |
|
| 656 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Generates output for the import page. |
|
| 662 | - * |
|
| 663 | - * @throws EE_Error |
|
| 664 | - */ |
|
| 665 | - protected function _import_page() |
|
| 666 | - { |
|
| 667 | - $title = esc_html__('Import', 'event_espresso'); |
|
| 668 | - $intro = esc_html__( |
|
| 669 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 670 | - 'event_espresso' |
|
| 671 | - ); |
|
| 672 | - |
|
| 673 | - $form_url = EVENTS_ADMIN_URL; |
|
| 674 | - $action = 'import_events'; |
|
| 675 | - $type = 'csv'; |
|
| 676 | - |
|
| 677 | - $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
| 678 | - $title, |
|
| 679 | - $intro, |
|
| 680 | - $form_url, |
|
| 681 | - $action, |
|
| 682 | - $type |
|
| 683 | - ); |
|
| 684 | - |
|
| 685 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 686 | - ['action' => 'sample_export_file'], |
|
| 687 | - $this->_admin_base_url |
|
| 688 | - ); |
|
| 689 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 690 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 691 | - $this->_template_args, |
|
| 692 | - true |
|
| 693 | - ); |
|
| 694 | - $this->display_admin_page_with_sidebar(); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * _import_events |
|
| 700 | - * This handles displaying the screen and running imports for importing events. |
|
| 701 | - * |
|
| 702 | - * @return void |
|
| 703 | - * @throws EE_Error |
|
| 704 | - */ |
|
| 705 | - protected function _import_events() |
|
| 706 | - { |
|
| 707 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 708 | - $success = EE_Import::instance()->import(); |
|
| 709 | - $this->_redirect_after_action( |
|
| 710 | - $success, |
|
| 711 | - esc_html__('Import File', 'event_espresso'), |
|
| 712 | - 'ran', |
|
| 713 | - ['action' => 'import_page'], |
|
| 714 | - true |
|
| 715 | - ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * _events_export |
|
| 721 | - * Will export all (or just the given event) to a Excel compatible file. |
|
| 722 | - * |
|
| 723 | - * @access protected |
|
| 724 | - * @return void |
|
| 725 | - */ |
|
| 726 | - protected function _events_export() |
|
| 727 | - { |
|
| 728 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 729 | - $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int'); |
|
| 730 | - $this->request->mergeRequestParams( |
|
| 731 | - [ |
|
| 732 | - 'export' => 'report', |
|
| 733 | - 'action' => 'all_event_data', |
|
| 734 | - 'EVT_ID' => $EVT_ID, |
|
| 735 | - ] |
|
| 736 | - ); |
|
| 737 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 738 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 739 | - $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
| 740 | - $EE_Export->export(); |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * handle category exports() |
|
| 747 | - * |
|
| 748 | - * @return void |
|
| 749 | - */ |
|
| 750 | - protected function _categories_export() |
|
| 751 | - { |
|
| 752 | - $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 753 | - $this->request->mergeRequestParams( |
|
| 754 | - [ |
|
| 755 | - 'export' => 'report', |
|
| 756 | - 'action' => 'categories', |
|
| 757 | - 'EVT_ID' => $EVT_ID, |
|
| 758 | - ] |
|
| 759 | - ); |
|
| 760 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 761 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 762 | - $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
| 763 | - $EE_Export->export(); |
|
| 764 | - } |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * Creates a sample CSV file for importing |
|
| 770 | - */ |
|
| 771 | - protected function _sample_export_file() |
|
| 772 | - { |
|
| 773 | - $EE_Export = EE_Export::instance(); |
|
| 774 | - if ($EE_Export instanceof EE_Export) { |
|
| 775 | - $EE_Export->export(); |
|
| 776 | - } |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - |
|
| 780 | - /************* Template Settings *************/ |
|
| 781 | - /** |
|
| 782 | - * Generates template settings page output |
|
| 783 | - * |
|
| 784 | - * @throws DomainException |
|
| 785 | - * @throws EE_Error |
|
| 786 | - * @throws InvalidArgumentException |
|
| 787 | - * @throws InvalidDataTypeException |
|
| 788 | - * @throws InvalidInterfaceException |
|
| 789 | - */ |
|
| 790 | - protected function _template_settings() |
|
| 791 | - { |
|
| 792 | - new TemplateCacheAdmin(EE_Registry::instance()->CFG->template_settings, $this->request); |
|
| 793 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 794 | - /** |
|
| 795 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 796 | - * from General_Settings_Admin_Page to here. |
|
| 797 | - */ |
|
| 798 | - $this->_template_args = apply_filters( |
|
| 799 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 800 | - $this->_template_args |
|
| 801 | - ); |
|
| 802 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 803 | - $this->_set_publish_post_box_vars(); |
|
| 804 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 805 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 806 | - $this->_template_args, |
|
| 807 | - true |
|
| 808 | - ); |
|
| 809 | - $this->display_admin_page_with_sidebar(); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * Handler for updating template settings. |
|
| 815 | - * |
|
| 816 | - * @throws EE_Error |
|
| 817 | - */ |
|
| 818 | - protected function _update_template_settings() |
|
| 819 | - { |
|
| 820 | - new TemplateCacheAdmin(EE_Registry::instance()->CFG->template_settings, $this->request); |
|
| 821 | - /** |
|
| 822 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 823 | - * from General_Settings_Admin_Page to here. |
|
| 824 | - */ |
|
| 825 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 826 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 827 | - EE_Registry::instance()->CFG->template_settings, |
|
| 828 | - $this->request->requestParams() |
|
| 829 | - ); |
|
| 830 | - // update custom post type slugs and detect if we need to flush rewrite rules |
|
| 831 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 832 | - |
|
| 833 | - $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug'); |
|
| 834 | - |
|
| 835 | - EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug |
|
| 836 | - ? EEH_URL::slugify($event_cpt_slug, 'events') |
|
| 837 | - : EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 838 | - |
|
| 839 | - $what = esc_html__('Template Settings', 'event_espresso'); |
|
| 840 | - $success = $this->_update_espresso_configuration( |
|
| 841 | - $what, |
|
| 842 | - EE_Registry::instance()->CFG->template_settings, |
|
| 843 | - __FILE__, |
|
| 844 | - __FUNCTION__, |
|
| 845 | - __LINE__ |
|
| 846 | - ); |
|
| 847 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) { |
|
| 848 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 849 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
| 850 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 851 | - ); |
|
| 852 | - $rewrite_rules->flush(); |
|
| 853 | - } |
|
| 854 | - do_action( |
|
| 855 | - 'AHEE__General_Settings_Admin_Page__update_template_settings__after_update', |
|
| 856 | - EE_Registry::instance()->CFG->template_settings, |
|
| 857 | - $this->request->requestParams(), |
|
| 858 | - $success |
|
| 859 | - ); |
|
| 860 | - $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - |
|
| 864 | - /** |
|
| 865 | - * _premium_event_editor_meta_boxes |
|
| 866 | - * add all metaboxes related to the event_editor |
|
| 867 | - * |
|
| 868 | - * @access protected |
|
| 869 | - * @return void |
|
| 870 | - * @throws EE_Error |
|
| 871 | - * @throws ReflectionException |
|
| 872 | - */ |
|
| 873 | - protected function _premium_event_editor_meta_boxes() |
|
| 874 | - { |
|
| 875 | - $this->verify_cpt_object(); |
|
| 876 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 877 | - if ( |
|
| 878 | - ! $this->admin_config->useAdvancedEditor() |
|
| 879 | - || ! $this->feature->allowed('use_reg_options_meta_box') |
|
| 880 | - ) { |
|
| 881 | - $this->addMetaBox( |
|
| 882 | - 'espresso_event_editor_event_options', |
|
| 883 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 884 | - [$this, 'registration_options_meta_box'], |
|
| 885 | - $this->page_slug, |
|
| 886 | - 'side', |
|
| 887 | - 'core' |
|
| 888 | - ); |
|
| 889 | - } |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - |
|
| 893 | - /** |
|
| 894 | - * override caf metabox |
|
| 895 | - * |
|
| 896 | - * @return void |
|
| 897 | - * @throws EE_Error |
|
| 898 | - * @throws ReflectionException |
|
| 899 | - */ |
|
| 900 | - public function registration_options_meta_box() |
|
| 901 | - { |
|
| 902 | - $yes_no_values = [ |
|
| 903 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 904 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 905 | - ]; |
|
| 906 | - |
|
| 907 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 908 | - [ |
|
| 909 | - RegStatus::CANCELLED, |
|
| 910 | - RegStatus::DECLINED, |
|
| 911 | - RegStatus::INCOMPLETE, |
|
| 912 | - RegStatus::WAIT_LIST, |
|
| 913 | - ], |
|
| 914 | - true |
|
| 915 | - ); |
|
| 916 | - |
|
| 917 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 918 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 919 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 920 | - |
|
| 921 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 922 | - 'default_reg_status', |
|
| 923 | - $default_reg_status_values, |
|
| 924 | - $this->_cpt_model_obj->default_registration_status(), |
|
| 925 | - '', |
|
| 926 | - 'ee-input-width--reg', |
|
| 927 | - false |
|
| 928 | - ); |
|
| 929 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 930 | - 'display_desc', |
|
| 931 | - $yes_no_values, |
|
| 932 | - $this->_cpt_model_obj->display_description() |
|
| 933 | - ); |
|
| 934 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 935 | - 'display_ticket_selector', |
|
| 936 | - $yes_no_values, |
|
| 937 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 938 | - '', |
|
| 939 | - 'ee-input-width--small', |
|
| 940 | - false |
|
| 941 | - ); |
|
| 942 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 943 | - 'EVT_default_registration_status', |
|
| 944 | - $default_reg_status_values, |
|
| 945 | - $this->_cpt_model_obj->default_registration_status(), |
|
| 946 | - '', |
|
| 947 | - 'ee-input-width--reg', |
|
| 948 | - false |
|
| 949 | - ); |
|
| 950 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 951 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 952 | - '', |
|
| 953 | - $template_args, |
|
| 954 | - $yes_no_values, |
|
| 955 | - $default_reg_status_values |
|
| 956 | - ); |
|
| 957 | - EEH_Template::display_template( |
|
| 958 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 959 | - $template_args |
|
| 960 | - ); |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * wp_list_table_mods for caf |
|
| 967 | - * ============================ |
|
| 968 | - */ |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * espresso_event_months_dropdown |
|
| 973 | - * |
|
| 974 | - * @deprecatd 5.0.0.p |
|
| 975 | - * @access public |
|
| 976 | - * @return string dropdown listing month/year selections for events. |
|
| 977 | - * @throws EE_Error |
|
| 978 | - */ |
|
| 979 | - public function espresso_event_months_dropdown(): string |
|
| 980 | - { |
|
| 981 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 982 | - // Note we need to include any other filters that are set! |
|
| 983 | - return EEH_Form_Fields::generate_event_months_dropdown( |
|
| 984 | - $this->request->getRequestParam('month_range', ''), |
|
| 985 | - $this->request->getRequestParam('status', ''), |
|
| 986 | - $this->request->getRequestParam('EVT_CAT', 0, 'int'), |
|
| 987 | - $this->request->getRequestParam('active_status', '') |
|
| 988 | - ); |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - /** |
|
| 993 | - * returns a list of "active" statuses on the event |
|
| 994 | - * |
|
| 995 | - * @deprecatd 5.0.0.p |
|
| 996 | - * @param string $current_value whatever the current active status is |
|
| 997 | - * @return string |
|
| 998 | - */ |
|
| 999 | - public function active_status_dropdown(string $current_value = ''): string |
|
| 1000 | - { |
|
| 1001 | - $select_name = 'active_status'; |
|
| 1002 | - $values = [ |
|
| 1003 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 1004 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
| 1005 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 1006 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 1007 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 1008 | - ]; |
|
| 1009 | - |
|
| 1010 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * returns a list of "venues" |
|
| 1016 | - * |
|
| 1017 | - * @deprecatd 5.0.0.p |
|
| 1018 | - * @param string $current_value whatever the current active status is |
|
| 1019 | - * @return string |
|
| 1020 | - * @throws EE_Error |
|
| 1021 | - * @throws ReflectionException |
|
| 1022 | - */ |
|
| 1023 | - protected function venuesDropdown(string $current_value = ''): string |
|
| 1024 | - { |
|
| 1025 | - $values = ['' => esc_html__('All Venues', 'event_espresso')]; |
|
| 1026 | - // populate the list of venues. |
|
| 1027 | - $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
|
| 1028 | - |
|
| 1029 | - foreach ($venues as $venue) { |
|
| 1030 | - $values[ $venue->ID() ] = $venue->name(); |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - return EEH_Form_Fields::select_input('venue', $values, $current_value); |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - |
|
| 1037 | - /** |
|
| 1038 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
| 1039 | - * |
|
| 1040 | - * @deprecatd 5.0.0.p |
|
| 1041 | - * @access public |
|
| 1042 | - * @return string html |
|
| 1043 | - * @throws EE_Error |
|
| 1044 | - * @throws ReflectionException |
|
| 1045 | - */ |
|
| 1046 | - public function category_dropdown(): string |
|
| 1047 | - { |
|
| 1048 | - return EEH_Form_Fields::generate_event_category_dropdown( |
|
| 1049 | - $this->request->getRequestParam('EVT_CAT', -1, 'int') |
|
| 1050 | - ); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * get total number of events today |
|
| 1056 | - * |
|
| 1057 | - * @access public |
|
| 1058 | - * @return int |
|
| 1059 | - * @throws EE_Error |
|
| 1060 | - * @throws InvalidArgumentException |
|
| 1061 | - * @throws InvalidDataTypeException |
|
| 1062 | - * @throws InvalidInterfaceException |
|
| 1063 | - * @throws ReflectionException |
|
| 1064 | - */ |
|
| 1065 | - public function total_events_today(): int |
|
| 1066 | - { |
|
| 1067 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1068 | - 'DTT_EVT_start', |
|
| 1069 | - date('Y-m-d') . ' 00:00:00', |
|
| 1070 | - 'Y-m-d H:i:s', |
|
| 1071 | - 'UTC' |
|
| 1072 | - ); |
|
| 1073 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1074 | - 'DTT_EVT_start', |
|
| 1075 | - date('Y-m-d') . ' 23:59:59', |
|
| 1076 | - 'Y-m-d H:i:s', |
|
| 1077 | - 'UTC' |
|
| 1078 | - ); |
|
| 1079 | - $where = [ |
|
| 1080 | - 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
| 1081 | - ]; |
|
| 1082 | - return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * get total number of events this month |
|
| 1088 | - * |
|
| 1089 | - * @access public |
|
| 1090 | - * @return int |
|
| 1091 | - * @throws EE_Error |
|
| 1092 | - * @throws InvalidArgumentException |
|
| 1093 | - * @throws InvalidDataTypeException |
|
| 1094 | - * @throws InvalidInterfaceException |
|
| 1095 | - * @throws ReflectionException |
|
| 1096 | - */ |
|
| 1097 | - public function total_events_this_month(): int |
|
| 1098 | - { |
|
| 1099 | - // Dates |
|
| 1100 | - $this_year_r = date('Y'); |
|
| 1101 | - $this_month_r = date('m'); |
|
| 1102 | - $days_this_month = date('t'); |
|
| 1103 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1104 | - 'DTT_EVT_start', |
|
| 1105 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1106 | - 'Y-m-d H:i:s', |
|
| 1107 | - 'UTC' |
|
| 1108 | - ); |
|
| 1109 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1110 | - 'DTT_EVT_start', |
|
| 1111 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1112 | - 'Y-m-d H:i:s', |
|
| 1113 | - 'UTC' |
|
| 1114 | - ); |
|
| 1115 | - $where = [ |
|
| 1116 | - 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
| 1117 | - ]; |
|
| 1118 | - return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - |
|
| 1122 | - /** DEFAULT TICKETS STUFF **/ |
|
| 1123 | - |
|
| 1124 | - /** |
|
| 1125 | - * Output default tickets list table view. |
|
| 1126 | - * |
|
| 1127 | - * @throws EE_Error |
|
| 1128 | - */ |
|
| 1129 | - public function _tickets_overview_list_table() |
|
| 1130 | - { |
|
| 1131 | - if ( |
|
| 1132 | - $this->admin_config->useAdvancedEditor() |
|
| 1133 | - && $this->feature->allowed('use_default_ticket_manager') |
|
| 1134 | - ) { |
|
| 1135 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1136 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1137 | - EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php', |
|
| 1138 | - [], |
|
| 1139 | - true |
|
| 1140 | - ); |
|
| 1141 | - $this->display_admin_page_with_no_sidebar(); |
|
| 1142 | - } else { |
|
| 1143 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1144 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * @param int $per_page |
|
| 1151 | - * @param bool $count |
|
| 1152 | - * @param bool $trashed |
|
| 1153 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1154 | - * @throws EE_Error |
|
| 1155 | - * @throws ReflectionException |
|
| 1156 | - */ |
|
| 1157 | - public function get_default_tickets(int $per_page = 10, bool $count = false, bool $trashed = false) |
|
| 1158 | - { |
|
| 1159 | - $orderby = $this->request->getRequestParam('orderby', 'TKT_name'); |
|
| 1160 | - $order = $this->request->getRequestParam('order', 'ASC'); |
|
| 1161 | - switch ($orderby) { |
|
| 1162 | - case 'TKT_name': |
|
| 1163 | - $orderby = ['TKT_name' => $order]; |
|
| 1164 | - break; |
|
| 1165 | - case 'TKT_price': |
|
| 1166 | - $orderby = ['TKT_price' => $order]; |
|
| 1167 | - break; |
|
| 1168 | - case 'TKT_uses': |
|
| 1169 | - $orderby = ['TKT_uses' => $order]; |
|
| 1170 | - break; |
|
| 1171 | - case 'TKT_min': |
|
| 1172 | - $orderby = ['TKT_min' => $order]; |
|
| 1173 | - break; |
|
| 1174 | - case 'TKT_max': |
|
| 1175 | - $orderby = ['TKT_max' => $order]; |
|
| 1176 | - break; |
|
| 1177 | - case 'TKT_qty': |
|
| 1178 | - $orderby = ['TKT_qty' => $order]; |
|
| 1179 | - break; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
| 1183 | - $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
| 1184 | - $offset = ($current_page - 1) * $per_page; |
|
| 1185 | - |
|
| 1186 | - $where = [ |
|
| 1187 | - 'TKT_is_default' => 1, |
|
| 1188 | - 'TKT_deleted' => $trashed, |
|
| 1189 | - ]; |
|
| 1190 | - |
|
| 1191 | - $search_term = $this->request->getRequestParam('s'); |
|
| 1192 | - if ($search_term) { |
|
| 1193 | - $search_term = '%' . $search_term . '%'; |
|
| 1194 | - $where['OR'] = [ |
|
| 1195 | - 'TKT_name' => ['LIKE', $search_term], |
|
| 1196 | - 'TKT_description' => ['LIKE', $search_term], |
|
| 1197 | - ]; |
|
| 1198 | - } |
|
| 1199 | - |
|
| 1200 | - return $count |
|
| 1201 | - ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where]) |
|
| 1202 | - : EEM_Ticket::instance()->get_all_deleted_and_undeleted( |
|
| 1203 | - [ |
|
| 1204 | - $where, |
|
| 1205 | - 'order_by' => $orderby, |
|
| 1206 | - 'limit' => [$offset, $per_page], |
|
| 1207 | - 'group_by' => 'TKT_ID', |
|
| 1208 | - ] |
|
| 1209 | - ); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - |
|
| 1213 | - /** |
|
| 1214 | - * @param bool $trash |
|
| 1215 | - * @throws EE_Error |
|
| 1216 | - * @throws InvalidArgumentException |
|
| 1217 | - * @throws InvalidDataTypeException |
|
| 1218 | - * @throws InvalidInterfaceException |
|
| 1219 | - * @throws ReflectionException |
|
| 1220 | - */ |
|
| 1221 | - protected function _trash_or_restore_ticket(bool $trash = false) |
|
| 1222 | - { |
|
| 1223 | - $success = 1; |
|
| 1224 | - $TKT = EEM_Ticket::instance(); |
|
| 1225 | - // checkboxes? |
|
| 1226 | - $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
| 1227 | - if (! empty($checkboxes)) { |
|
| 1228 | - // if array has more than one element then success message should be plural |
|
| 1229 | - $success = count($checkboxes) > 1 ? 2 : 1; |
|
| 1230 | - // cycle thru the boxes |
|
| 1231 | - foreach ($checkboxes as $TKT_ID => $value) { |
|
| 1232 | - if ($trash) { |
|
| 1233 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1234 | - $success = 0; |
|
| 1235 | - } |
|
| 1236 | - } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1237 | - $success = 0; |
|
| 1238 | - } |
|
| 1239 | - } |
|
| 1240 | - } else { |
|
| 1241 | - // grab single id and trash |
|
| 1242 | - $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
| 1243 | - if ($trash) { |
|
| 1244 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1245 | - $success = 0; |
|
| 1246 | - } |
|
| 1247 | - } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1248 | - $success = 0; |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1252 | - $query_args = [ |
|
| 1253 | - 'action' => 'ticket_list_table', |
|
| 1254 | - 'status' => $trash ? '' : 'trashed', |
|
| 1255 | - ]; |
|
| 1256 | - $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args); |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - |
|
| 1260 | - /** |
|
| 1261 | - * Handles trashing default ticket. |
|
| 1262 | - * |
|
| 1263 | - * @throws EE_Error |
|
| 1264 | - * @throws ReflectionException |
|
| 1265 | - */ |
|
| 1266 | - protected function _delete_ticket() |
|
| 1267 | - { |
|
| 1268 | - $success = 1; |
|
| 1269 | - // checkboxes? |
|
| 1270 | - $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
| 1271 | - if (! empty($checkboxes)) { |
|
| 1272 | - // if array has more than one element then success message should be plural |
|
| 1273 | - $success = count($checkboxes) > 1 ? 2 : 1; |
|
| 1274 | - // cycle thru the boxes |
|
| 1275 | - foreach ($checkboxes as $TKT_ID => $value) { |
|
| 1276 | - // delete |
|
| 1277 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1278 | - $success = 0; |
|
| 1279 | - } |
|
| 1280 | - } |
|
| 1281 | - } else { |
|
| 1282 | - // grab single id and trash |
|
| 1283 | - $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
| 1284 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1285 | - $success = 0; |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - $action_desc = 'deleted'; |
|
| 1289 | - $query_args = [ |
|
| 1290 | - 'action' => 'ticket_list_table', |
|
| 1291 | - 'status' => 'trashed', |
|
| 1292 | - ]; |
|
| 1293 | - // fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1294 | - if ( |
|
| 1295 | - EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1296 | - [['TKT_is_default' => 1]], |
|
| 1297 | - 'TKT_ID', |
|
| 1298 | - true |
|
| 1299 | - ) |
|
| 1300 | - ) { |
|
| 1301 | - $query_args = []; |
|
| 1302 | - } |
|
| 1303 | - $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args); |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * @param int $TKT_ID |
|
| 1309 | - * @return bool|int |
|
| 1310 | - * @throws EE_Error |
|
| 1311 | - * @throws ReflectionException |
|
| 1312 | - */ |
|
| 1313 | - protected function _delete_the_ticket(int $TKT_ID) |
|
| 1314 | - { |
|
| 1315 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1316 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1317 | - return false; |
|
| 1318 | - } |
|
| 1319 | - $ticket->_remove_relations('Datetime'); |
|
| 1320 | - // delete all related prices first |
|
| 1321 | - $ticket->delete_related_permanently('Price'); |
|
| 1322 | - return $ticket->delete_permanently(); |
|
| 1323 | - } |
|
| 392 | + } |
|
| 393 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 394 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 395 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 396 | + 'see_notifications_for', |
|
| 397 | + null, |
|
| 398 | + ['EVT_ID' => $event->ID()] |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + return $action_links; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @param $items |
|
| 407 | + * @return mixed |
|
| 408 | + */ |
|
| 409 | + public function additional_legend_items($items) |
|
| 410 | + { |
|
| 411 | + if ( |
|
| 412 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 413 | + 'ee_read_registrations', |
|
| 414 | + 'espresso_registrations_reports' |
|
| 415 | + ) |
|
| 416 | + ) { |
|
| 417 | + $items['reports'] = [ |
|
| 418 | + 'class' => 'dashicons dashicons-chart-bar', |
|
| 419 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 420 | + ]; |
|
| 421 | + } |
|
| 422 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 423 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 424 | + // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset |
|
| 425 | + // (can only use numeric offsets when treating strings as arrays) |
|
| 426 | + if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) { |
|
| 427 | + $items['view_related_messages'] = [ |
|
| 428 | + 'class' => $related_for_icon['css_class'], |
|
| 429 | + 'desc' => $related_for_icon['label'], |
|
| 430 | + ]; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + return $items; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * This is the callback method for the duplicate event route |
|
| 439 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 440 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 441 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 442 | + * After duplication the redirect is to the new event edit page. |
|
| 443 | + * |
|
| 444 | + * @return void |
|
| 445 | + * @throws EE_Error If EE_Event is not available with given ID |
|
| 446 | + * @throws ReflectionException |
|
| 447 | + * @access protected |
|
| 448 | + */ |
|
| 449 | + protected function _duplicate_event() |
|
| 450 | + { |
|
| 451 | + // first make sure the ID for the event is in the request. |
|
| 452 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 453 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 454 | + if (! $EVT_ID) { |
|
| 455 | + EE_Error::add_error( |
|
| 456 | + esc_html__( |
|
| 457 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 458 | + 'event_espresso' |
|
| 459 | + ), |
|
| 460 | + __FILE__, |
|
| 461 | + __FUNCTION__, |
|
| 462 | + __LINE__ |
|
| 463 | + ); |
|
| 464 | + $this->_redirect_after_action(false, '', '', [], true); |
|
| 465 | + return; |
|
| 466 | + } |
|
| 467 | + // k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 468 | + $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 469 | + if (! $orig_event instanceof EE_Event) { |
|
| 470 | + throw new EE_Error( |
|
| 471 | + sprintf( |
|
| 472 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 473 | + $EVT_ID |
|
| 474 | + ) |
|
| 475 | + ); |
|
| 476 | + } |
|
| 477 | + // k now let's clone the $orig_event before getting relations |
|
| 478 | + $new_event = clone $orig_event; |
|
| 479 | + // original datetimes |
|
| 480 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 481 | + // other original relations |
|
| 482 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 483 | + // reset the ID and modify other details to make it clear this is a dupe |
|
| 484 | + $new_event->set('EVT_ID', 0); |
|
| 485 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 486 | + $new_event->set('EVT_name', $new_name); |
|
| 487 | + $new_event->set( |
|
| 488 | + 'EVT_slug', |
|
| 489 | + wp_unique_post_slug( |
|
| 490 | + sanitize_title($orig_event->name()), |
|
| 491 | + 0, |
|
| 492 | + 'publish', |
|
| 493 | + EspressoPostType::EVENTS, |
|
| 494 | + 0 |
|
| 495 | + ) |
|
| 496 | + ); |
|
| 497 | + $new_event->set('status', 'draft'); |
|
| 498 | + // duplicate discussion settings |
|
| 499 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 500 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 501 | + // save the new event |
|
| 502 | + $new_event->save(); |
|
| 503 | + // venues |
|
| 504 | + foreach ($orig_ven as $ven) { |
|
| 505 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
| 506 | + } |
|
| 507 | + $new_event->save(); |
|
| 508 | + // now we need to get the question group relations and handle that |
|
| 509 | + // first primary question groups |
|
| 510 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
| 511 | + 'Question_Group', |
|
| 512 | + [['Event_Question_Group.EQG_primary' => true]] |
|
| 513 | + ); |
|
| 514 | + if (! empty($orig_primary_qgs)) { |
|
| 515 | + foreach ($orig_primary_qgs as $obj) { |
|
| 516 | + if ($obj instanceof EE_Question_Group) { |
|
| 517 | + $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + // next additional attendee question groups |
|
| 522 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
| 523 | + 'Question_Group', |
|
| 524 | + [['Event_Question_Group.EQG_additional' => true]] |
|
| 525 | + ); |
|
| 526 | + if (! empty($orig_additional_qgs)) { |
|
| 527 | + foreach ($orig_additional_qgs as $obj) { |
|
| 528 | + if ($obj instanceof EE_Question_Group) { |
|
| 529 | + $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + $new_event->save(); |
|
| 535 | + |
|
| 536 | + // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 537 | + $cloned_tickets = []; |
|
| 538 | + foreach ($orig_datetimes as $orig_dtt) { |
|
| 539 | + if (! $orig_dtt instanceof EE_Datetime) { |
|
| 540 | + continue; |
|
| 541 | + } |
|
| 542 | + $new_dtt = clone $orig_dtt; |
|
| 543 | + $orig_tickets = $orig_dtt->tickets(); |
|
| 544 | + // save new dtt then add to event |
|
| 545 | + $new_dtt->set('DTT_ID', 0); |
|
| 546 | + $new_dtt->set('DTT_sold', 0); |
|
| 547 | + $new_dtt->set_reserved(0); |
|
| 548 | + $new_dtt->save(); |
|
| 549 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 550 | + $new_event->save(); |
|
| 551 | + // now let's get the ticket relations setup. |
|
| 552 | + foreach ((array) $orig_tickets as $orig_ticket) { |
|
| 553 | + // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 554 | + if (! $orig_ticket instanceof EE_Ticket) { |
|
| 555 | + continue; |
|
| 556 | + } |
|
| 557 | + // is this ticket archived? If it is then let's skip |
|
| 558 | + if ($orig_ticket->get('TKT_deleted')) { |
|
| 559 | + continue; |
|
| 560 | + } |
|
| 561 | + // does this original ticket already exist in the clone_tickets cache? |
|
| 562 | + // If so we'll just use the new ticket from it. |
|
| 563 | + if (isset($cloned_tickets[ $orig_ticket->ID() ])) { |
|
| 564 | + $new_ticket = $cloned_tickets[ $orig_ticket->ID() ]; |
|
| 565 | + } else { |
|
| 566 | + $new_ticket = clone $orig_ticket; |
|
| 567 | + // get relations on the $orig_ticket that we need to set up. |
|
| 568 | + $orig_prices = $orig_ticket->prices(); |
|
| 569 | + $new_ticket->set('TKT_ID', 0); |
|
| 570 | + $new_ticket->set('TKT_sold', 0); |
|
| 571 | + $new_ticket->set('TKT_reserved', 0); |
|
| 572 | + // make sure new ticket has ID. |
|
| 573 | + $new_ticket->save(); |
|
| 574 | + // price relations on new ticket need to be setup. |
|
| 575 | + foreach ($orig_prices as $orig_price) { |
|
| 576 | + // don't clone default prices, just add a relation |
|
| 577 | + if ($orig_price->is_default()) { |
|
| 578 | + $new_ticket->_add_relation_to($orig_price, 'Price'); |
|
| 579 | + $new_ticket->save(); |
|
| 580 | + continue; |
|
| 581 | + } |
|
| 582 | + $new_price = clone $orig_price; |
|
| 583 | + $new_price->set('PRC_ID', 0); |
|
| 584 | + $new_price->save(); |
|
| 585 | + $new_ticket->_add_relation_to($new_price, 'Price'); |
|
| 586 | + } |
|
| 587 | + $new_ticket->save(); |
|
| 588 | + |
|
| 589 | + do_action( |
|
| 590 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
| 591 | + $orig_ticket, |
|
| 592 | + $new_ticket, |
|
| 593 | + $orig_prices, |
|
| 594 | + $orig_event, |
|
| 595 | + $orig_dtt, |
|
| 596 | + $new_dtt |
|
| 597 | + ); |
|
| 598 | + $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket; |
|
| 599 | + } |
|
| 600 | + // k now we can add the new ticket as a relation to the new datetime |
|
| 601 | + // and make sure it's added to our cached $cloned_tickets array |
|
| 602 | + // for use with later datetimes that have the same ticket. |
|
| 603 | + $new_dtt->_add_relation_to($new_ticket, 'Ticket'); |
|
| 604 | + } |
|
| 605 | + $new_dtt->save(); |
|
| 606 | + } |
|
| 607 | + // clone taxonomy information |
|
| 608 | + $taxonomies_to_clone_with = apply_filters( |
|
| 609 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 610 | + ['espresso_event_categories', 'espresso_event_type', 'post_tag'] |
|
| 611 | + ); |
|
| 612 | + // get terms for original event (notice) |
|
| 613 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 614 | + // loop through terms and add them to new event. |
|
| 615 | + foreach ($orig_terms as $term) { |
|
| 616 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + // duplicate other core WP_Post items for this event. |
|
| 620 | + // post thumbnail (feature image). |
|
| 621 | + $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
| 622 | + if ($feature_image_id) { |
|
| 623 | + update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // duplicate page_template setting |
|
| 627 | + $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
| 628 | + if ($page_template) { |
|
| 629 | + update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 633 | + // now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 634 | + if ($new_event->ID()) { |
|
| 635 | + $redirect_args = [ |
|
| 636 | + 'post' => $new_event->ID(), |
|
| 637 | + 'action' => 'edit', |
|
| 638 | + ]; |
|
| 639 | + EE_Error::add_success( |
|
| 640 | + esc_html__( |
|
| 641 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 642 | + 'event_espresso' |
|
| 643 | + ) |
|
| 644 | + ); |
|
| 645 | + } else { |
|
| 646 | + $redirect_args = [ |
|
| 647 | + 'action' => 'default', |
|
| 648 | + ]; |
|
| 649 | + EE_Error::add_error( |
|
| 650 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 651 | + __FILE__, |
|
| 652 | + __FUNCTION__, |
|
| 653 | + __LINE__ |
|
| 654 | + ); |
|
| 655 | + } |
|
| 656 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Generates output for the import page. |
|
| 662 | + * |
|
| 663 | + * @throws EE_Error |
|
| 664 | + */ |
|
| 665 | + protected function _import_page() |
|
| 666 | + { |
|
| 667 | + $title = esc_html__('Import', 'event_espresso'); |
|
| 668 | + $intro = esc_html__( |
|
| 669 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 670 | + 'event_espresso' |
|
| 671 | + ); |
|
| 672 | + |
|
| 673 | + $form_url = EVENTS_ADMIN_URL; |
|
| 674 | + $action = 'import_events'; |
|
| 675 | + $type = 'csv'; |
|
| 676 | + |
|
| 677 | + $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
| 678 | + $title, |
|
| 679 | + $intro, |
|
| 680 | + $form_url, |
|
| 681 | + $action, |
|
| 682 | + $type |
|
| 683 | + ); |
|
| 684 | + |
|
| 685 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 686 | + ['action' => 'sample_export_file'], |
|
| 687 | + $this->_admin_base_url |
|
| 688 | + ); |
|
| 689 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 690 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 691 | + $this->_template_args, |
|
| 692 | + true |
|
| 693 | + ); |
|
| 694 | + $this->display_admin_page_with_sidebar(); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * _import_events |
|
| 700 | + * This handles displaying the screen and running imports for importing events. |
|
| 701 | + * |
|
| 702 | + * @return void |
|
| 703 | + * @throws EE_Error |
|
| 704 | + */ |
|
| 705 | + protected function _import_events() |
|
| 706 | + { |
|
| 707 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 708 | + $success = EE_Import::instance()->import(); |
|
| 709 | + $this->_redirect_after_action( |
|
| 710 | + $success, |
|
| 711 | + esc_html__('Import File', 'event_espresso'), |
|
| 712 | + 'ran', |
|
| 713 | + ['action' => 'import_page'], |
|
| 714 | + true |
|
| 715 | + ); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * _events_export |
|
| 721 | + * Will export all (or just the given event) to a Excel compatible file. |
|
| 722 | + * |
|
| 723 | + * @access protected |
|
| 724 | + * @return void |
|
| 725 | + */ |
|
| 726 | + protected function _events_export() |
|
| 727 | + { |
|
| 728 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 729 | + $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int'); |
|
| 730 | + $this->request->mergeRequestParams( |
|
| 731 | + [ |
|
| 732 | + 'export' => 'report', |
|
| 733 | + 'action' => 'all_event_data', |
|
| 734 | + 'EVT_ID' => $EVT_ID, |
|
| 735 | + ] |
|
| 736 | + ); |
|
| 737 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 738 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 739 | + $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
| 740 | + $EE_Export->export(); |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * handle category exports() |
|
| 747 | + * |
|
| 748 | + * @return void |
|
| 749 | + */ |
|
| 750 | + protected function _categories_export() |
|
| 751 | + { |
|
| 752 | + $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 753 | + $this->request->mergeRequestParams( |
|
| 754 | + [ |
|
| 755 | + 'export' => 'report', |
|
| 756 | + 'action' => 'categories', |
|
| 757 | + 'EVT_ID' => $EVT_ID, |
|
| 758 | + ] |
|
| 759 | + ); |
|
| 760 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 761 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 762 | + $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
| 763 | + $EE_Export->export(); |
|
| 764 | + } |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * Creates a sample CSV file for importing |
|
| 770 | + */ |
|
| 771 | + protected function _sample_export_file() |
|
| 772 | + { |
|
| 773 | + $EE_Export = EE_Export::instance(); |
|
| 774 | + if ($EE_Export instanceof EE_Export) { |
|
| 775 | + $EE_Export->export(); |
|
| 776 | + } |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + |
|
| 780 | + /************* Template Settings *************/ |
|
| 781 | + /** |
|
| 782 | + * Generates template settings page output |
|
| 783 | + * |
|
| 784 | + * @throws DomainException |
|
| 785 | + * @throws EE_Error |
|
| 786 | + * @throws InvalidArgumentException |
|
| 787 | + * @throws InvalidDataTypeException |
|
| 788 | + * @throws InvalidInterfaceException |
|
| 789 | + */ |
|
| 790 | + protected function _template_settings() |
|
| 791 | + { |
|
| 792 | + new TemplateCacheAdmin(EE_Registry::instance()->CFG->template_settings, $this->request); |
|
| 793 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 794 | + /** |
|
| 795 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 796 | + * from General_Settings_Admin_Page to here. |
|
| 797 | + */ |
|
| 798 | + $this->_template_args = apply_filters( |
|
| 799 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 800 | + $this->_template_args |
|
| 801 | + ); |
|
| 802 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 803 | + $this->_set_publish_post_box_vars(); |
|
| 804 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 805 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 806 | + $this->_template_args, |
|
| 807 | + true |
|
| 808 | + ); |
|
| 809 | + $this->display_admin_page_with_sidebar(); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + |
|
| 813 | + /** |
|
| 814 | + * Handler for updating template settings. |
|
| 815 | + * |
|
| 816 | + * @throws EE_Error |
|
| 817 | + */ |
|
| 818 | + protected function _update_template_settings() |
|
| 819 | + { |
|
| 820 | + new TemplateCacheAdmin(EE_Registry::instance()->CFG->template_settings, $this->request); |
|
| 821 | + /** |
|
| 822 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 823 | + * from General_Settings_Admin_Page to here. |
|
| 824 | + */ |
|
| 825 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 826 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 827 | + EE_Registry::instance()->CFG->template_settings, |
|
| 828 | + $this->request->requestParams() |
|
| 829 | + ); |
|
| 830 | + // update custom post type slugs and detect if we need to flush rewrite rules |
|
| 831 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 832 | + |
|
| 833 | + $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug'); |
|
| 834 | + |
|
| 835 | + EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug |
|
| 836 | + ? EEH_URL::slugify($event_cpt_slug, 'events') |
|
| 837 | + : EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 838 | + |
|
| 839 | + $what = esc_html__('Template Settings', 'event_espresso'); |
|
| 840 | + $success = $this->_update_espresso_configuration( |
|
| 841 | + $what, |
|
| 842 | + EE_Registry::instance()->CFG->template_settings, |
|
| 843 | + __FILE__, |
|
| 844 | + __FUNCTION__, |
|
| 845 | + __LINE__ |
|
| 846 | + ); |
|
| 847 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) { |
|
| 848 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 849 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
| 850 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 851 | + ); |
|
| 852 | + $rewrite_rules->flush(); |
|
| 853 | + } |
|
| 854 | + do_action( |
|
| 855 | + 'AHEE__General_Settings_Admin_Page__update_template_settings__after_update', |
|
| 856 | + EE_Registry::instance()->CFG->template_settings, |
|
| 857 | + $this->request->requestParams(), |
|
| 858 | + $success |
|
| 859 | + ); |
|
| 860 | + $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + |
|
| 864 | + /** |
|
| 865 | + * _premium_event_editor_meta_boxes |
|
| 866 | + * add all metaboxes related to the event_editor |
|
| 867 | + * |
|
| 868 | + * @access protected |
|
| 869 | + * @return void |
|
| 870 | + * @throws EE_Error |
|
| 871 | + * @throws ReflectionException |
|
| 872 | + */ |
|
| 873 | + protected function _premium_event_editor_meta_boxes() |
|
| 874 | + { |
|
| 875 | + $this->verify_cpt_object(); |
|
| 876 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 877 | + if ( |
|
| 878 | + ! $this->admin_config->useAdvancedEditor() |
|
| 879 | + || ! $this->feature->allowed('use_reg_options_meta_box') |
|
| 880 | + ) { |
|
| 881 | + $this->addMetaBox( |
|
| 882 | + 'espresso_event_editor_event_options', |
|
| 883 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 884 | + [$this, 'registration_options_meta_box'], |
|
| 885 | + $this->page_slug, |
|
| 886 | + 'side', |
|
| 887 | + 'core' |
|
| 888 | + ); |
|
| 889 | + } |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + |
|
| 893 | + /** |
|
| 894 | + * override caf metabox |
|
| 895 | + * |
|
| 896 | + * @return void |
|
| 897 | + * @throws EE_Error |
|
| 898 | + * @throws ReflectionException |
|
| 899 | + */ |
|
| 900 | + public function registration_options_meta_box() |
|
| 901 | + { |
|
| 902 | + $yes_no_values = [ |
|
| 903 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 904 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 905 | + ]; |
|
| 906 | + |
|
| 907 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 908 | + [ |
|
| 909 | + RegStatus::CANCELLED, |
|
| 910 | + RegStatus::DECLINED, |
|
| 911 | + RegStatus::INCOMPLETE, |
|
| 912 | + RegStatus::WAIT_LIST, |
|
| 913 | + ], |
|
| 914 | + true |
|
| 915 | + ); |
|
| 916 | + |
|
| 917 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 918 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 919 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 920 | + |
|
| 921 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 922 | + 'default_reg_status', |
|
| 923 | + $default_reg_status_values, |
|
| 924 | + $this->_cpt_model_obj->default_registration_status(), |
|
| 925 | + '', |
|
| 926 | + 'ee-input-width--reg', |
|
| 927 | + false |
|
| 928 | + ); |
|
| 929 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 930 | + 'display_desc', |
|
| 931 | + $yes_no_values, |
|
| 932 | + $this->_cpt_model_obj->display_description() |
|
| 933 | + ); |
|
| 934 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 935 | + 'display_ticket_selector', |
|
| 936 | + $yes_no_values, |
|
| 937 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 938 | + '', |
|
| 939 | + 'ee-input-width--small', |
|
| 940 | + false |
|
| 941 | + ); |
|
| 942 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 943 | + 'EVT_default_registration_status', |
|
| 944 | + $default_reg_status_values, |
|
| 945 | + $this->_cpt_model_obj->default_registration_status(), |
|
| 946 | + '', |
|
| 947 | + 'ee-input-width--reg', |
|
| 948 | + false |
|
| 949 | + ); |
|
| 950 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 951 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 952 | + '', |
|
| 953 | + $template_args, |
|
| 954 | + $yes_no_values, |
|
| 955 | + $default_reg_status_values |
|
| 956 | + ); |
|
| 957 | + EEH_Template::display_template( |
|
| 958 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 959 | + $template_args |
|
| 960 | + ); |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * wp_list_table_mods for caf |
|
| 967 | + * ============================ |
|
| 968 | + */ |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * espresso_event_months_dropdown |
|
| 973 | + * |
|
| 974 | + * @deprecatd 5.0.0.p |
|
| 975 | + * @access public |
|
| 976 | + * @return string dropdown listing month/year selections for events. |
|
| 977 | + * @throws EE_Error |
|
| 978 | + */ |
|
| 979 | + public function espresso_event_months_dropdown(): string |
|
| 980 | + { |
|
| 981 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 982 | + // Note we need to include any other filters that are set! |
|
| 983 | + return EEH_Form_Fields::generate_event_months_dropdown( |
|
| 984 | + $this->request->getRequestParam('month_range', ''), |
|
| 985 | + $this->request->getRequestParam('status', ''), |
|
| 986 | + $this->request->getRequestParam('EVT_CAT', 0, 'int'), |
|
| 987 | + $this->request->getRequestParam('active_status', '') |
|
| 988 | + ); |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + /** |
|
| 993 | + * returns a list of "active" statuses on the event |
|
| 994 | + * |
|
| 995 | + * @deprecatd 5.0.0.p |
|
| 996 | + * @param string $current_value whatever the current active status is |
|
| 997 | + * @return string |
|
| 998 | + */ |
|
| 999 | + public function active_status_dropdown(string $current_value = ''): string |
|
| 1000 | + { |
|
| 1001 | + $select_name = 'active_status'; |
|
| 1002 | + $values = [ |
|
| 1003 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 1004 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
| 1005 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 1006 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 1007 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 1008 | + ]; |
|
| 1009 | + |
|
| 1010 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * returns a list of "venues" |
|
| 1016 | + * |
|
| 1017 | + * @deprecatd 5.0.0.p |
|
| 1018 | + * @param string $current_value whatever the current active status is |
|
| 1019 | + * @return string |
|
| 1020 | + * @throws EE_Error |
|
| 1021 | + * @throws ReflectionException |
|
| 1022 | + */ |
|
| 1023 | + protected function venuesDropdown(string $current_value = ''): string |
|
| 1024 | + { |
|
| 1025 | + $values = ['' => esc_html__('All Venues', 'event_espresso')]; |
|
| 1026 | + // populate the list of venues. |
|
| 1027 | + $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
|
| 1028 | + |
|
| 1029 | + foreach ($venues as $venue) { |
|
| 1030 | + $values[ $venue->ID() ] = $venue->name(); |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + return EEH_Form_Fields::select_input('venue', $values, $current_value); |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + |
|
| 1037 | + /** |
|
| 1038 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
| 1039 | + * |
|
| 1040 | + * @deprecatd 5.0.0.p |
|
| 1041 | + * @access public |
|
| 1042 | + * @return string html |
|
| 1043 | + * @throws EE_Error |
|
| 1044 | + * @throws ReflectionException |
|
| 1045 | + */ |
|
| 1046 | + public function category_dropdown(): string |
|
| 1047 | + { |
|
| 1048 | + return EEH_Form_Fields::generate_event_category_dropdown( |
|
| 1049 | + $this->request->getRequestParam('EVT_CAT', -1, 'int') |
|
| 1050 | + ); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * get total number of events today |
|
| 1056 | + * |
|
| 1057 | + * @access public |
|
| 1058 | + * @return int |
|
| 1059 | + * @throws EE_Error |
|
| 1060 | + * @throws InvalidArgumentException |
|
| 1061 | + * @throws InvalidDataTypeException |
|
| 1062 | + * @throws InvalidInterfaceException |
|
| 1063 | + * @throws ReflectionException |
|
| 1064 | + */ |
|
| 1065 | + public function total_events_today(): int |
|
| 1066 | + { |
|
| 1067 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1068 | + 'DTT_EVT_start', |
|
| 1069 | + date('Y-m-d') . ' 00:00:00', |
|
| 1070 | + 'Y-m-d H:i:s', |
|
| 1071 | + 'UTC' |
|
| 1072 | + ); |
|
| 1073 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1074 | + 'DTT_EVT_start', |
|
| 1075 | + date('Y-m-d') . ' 23:59:59', |
|
| 1076 | + 'Y-m-d H:i:s', |
|
| 1077 | + 'UTC' |
|
| 1078 | + ); |
|
| 1079 | + $where = [ |
|
| 1080 | + 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
| 1081 | + ]; |
|
| 1082 | + return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * get total number of events this month |
|
| 1088 | + * |
|
| 1089 | + * @access public |
|
| 1090 | + * @return int |
|
| 1091 | + * @throws EE_Error |
|
| 1092 | + * @throws InvalidArgumentException |
|
| 1093 | + * @throws InvalidDataTypeException |
|
| 1094 | + * @throws InvalidInterfaceException |
|
| 1095 | + * @throws ReflectionException |
|
| 1096 | + */ |
|
| 1097 | + public function total_events_this_month(): int |
|
| 1098 | + { |
|
| 1099 | + // Dates |
|
| 1100 | + $this_year_r = date('Y'); |
|
| 1101 | + $this_month_r = date('m'); |
|
| 1102 | + $days_this_month = date('t'); |
|
| 1103 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1104 | + 'DTT_EVT_start', |
|
| 1105 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1106 | + 'Y-m-d H:i:s', |
|
| 1107 | + 'UTC' |
|
| 1108 | + ); |
|
| 1109 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1110 | + 'DTT_EVT_start', |
|
| 1111 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1112 | + 'Y-m-d H:i:s', |
|
| 1113 | + 'UTC' |
|
| 1114 | + ); |
|
| 1115 | + $where = [ |
|
| 1116 | + 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
| 1117 | + ]; |
|
| 1118 | + return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + |
|
| 1122 | + /** DEFAULT TICKETS STUFF **/ |
|
| 1123 | + |
|
| 1124 | + /** |
|
| 1125 | + * Output default tickets list table view. |
|
| 1126 | + * |
|
| 1127 | + * @throws EE_Error |
|
| 1128 | + */ |
|
| 1129 | + public function _tickets_overview_list_table() |
|
| 1130 | + { |
|
| 1131 | + if ( |
|
| 1132 | + $this->admin_config->useAdvancedEditor() |
|
| 1133 | + && $this->feature->allowed('use_default_ticket_manager') |
|
| 1134 | + ) { |
|
| 1135 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1136 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1137 | + EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php', |
|
| 1138 | + [], |
|
| 1139 | + true |
|
| 1140 | + ); |
|
| 1141 | + $this->display_admin_page_with_no_sidebar(); |
|
| 1142 | + } else { |
|
| 1143 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1144 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * @param int $per_page |
|
| 1151 | + * @param bool $count |
|
| 1152 | + * @param bool $trashed |
|
| 1153 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1154 | + * @throws EE_Error |
|
| 1155 | + * @throws ReflectionException |
|
| 1156 | + */ |
|
| 1157 | + public function get_default_tickets(int $per_page = 10, bool $count = false, bool $trashed = false) |
|
| 1158 | + { |
|
| 1159 | + $orderby = $this->request->getRequestParam('orderby', 'TKT_name'); |
|
| 1160 | + $order = $this->request->getRequestParam('order', 'ASC'); |
|
| 1161 | + switch ($orderby) { |
|
| 1162 | + case 'TKT_name': |
|
| 1163 | + $orderby = ['TKT_name' => $order]; |
|
| 1164 | + break; |
|
| 1165 | + case 'TKT_price': |
|
| 1166 | + $orderby = ['TKT_price' => $order]; |
|
| 1167 | + break; |
|
| 1168 | + case 'TKT_uses': |
|
| 1169 | + $orderby = ['TKT_uses' => $order]; |
|
| 1170 | + break; |
|
| 1171 | + case 'TKT_min': |
|
| 1172 | + $orderby = ['TKT_min' => $order]; |
|
| 1173 | + break; |
|
| 1174 | + case 'TKT_max': |
|
| 1175 | + $orderby = ['TKT_max' => $order]; |
|
| 1176 | + break; |
|
| 1177 | + case 'TKT_qty': |
|
| 1178 | + $orderby = ['TKT_qty' => $order]; |
|
| 1179 | + break; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
| 1183 | + $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
| 1184 | + $offset = ($current_page - 1) * $per_page; |
|
| 1185 | + |
|
| 1186 | + $where = [ |
|
| 1187 | + 'TKT_is_default' => 1, |
|
| 1188 | + 'TKT_deleted' => $trashed, |
|
| 1189 | + ]; |
|
| 1190 | + |
|
| 1191 | + $search_term = $this->request->getRequestParam('s'); |
|
| 1192 | + if ($search_term) { |
|
| 1193 | + $search_term = '%' . $search_term . '%'; |
|
| 1194 | + $where['OR'] = [ |
|
| 1195 | + 'TKT_name' => ['LIKE', $search_term], |
|
| 1196 | + 'TKT_description' => ['LIKE', $search_term], |
|
| 1197 | + ]; |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + return $count |
|
| 1201 | + ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where]) |
|
| 1202 | + : EEM_Ticket::instance()->get_all_deleted_and_undeleted( |
|
| 1203 | + [ |
|
| 1204 | + $where, |
|
| 1205 | + 'order_by' => $orderby, |
|
| 1206 | + 'limit' => [$offset, $per_page], |
|
| 1207 | + 'group_by' => 'TKT_ID', |
|
| 1208 | + ] |
|
| 1209 | + ); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + |
|
| 1213 | + /** |
|
| 1214 | + * @param bool $trash |
|
| 1215 | + * @throws EE_Error |
|
| 1216 | + * @throws InvalidArgumentException |
|
| 1217 | + * @throws InvalidDataTypeException |
|
| 1218 | + * @throws InvalidInterfaceException |
|
| 1219 | + * @throws ReflectionException |
|
| 1220 | + */ |
|
| 1221 | + protected function _trash_or_restore_ticket(bool $trash = false) |
|
| 1222 | + { |
|
| 1223 | + $success = 1; |
|
| 1224 | + $TKT = EEM_Ticket::instance(); |
|
| 1225 | + // checkboxes? |
|
| 1226 | + $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
| 1227 | + if (! empty($checkboxes)) { |
|
| 1228 | + // if array has more than one element then success message should be plural |
|
| 1229 | + $success = count($checkboxes) > 1 ? 2 : 1; |
|
| 1230 | + // cycle thru the boxes |
|
| 1231 | + foreach ($checkboxes as $TKT_ID => $value) { |
|
| 1232 | + if ($trash) { |
|
| 1233 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1234 | + $success = 0; |
|
| 1235 | + } |
|
| 1236 | + } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1237 | + $success = 0; |
|
| 1238 | + } |
|
| 1239 | + } |
|
| 1240 | + } else { |
|
| 1241 | + // grab single id and trash |
|
| 1242 | + $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
| 1243 | + if ($trash) { |
|
| 1244 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1245 | + $success = 0; |
|
| 1246 | + } |
|
| 1247 | + } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1248 | + $success = 0; |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1252 | + $query_args = [ |
|
| 1253 | + 'action' => 'ticket_list_table', |
|
| 1254 | + 'status' => $trash ? '' : 'trashed', |
|
| 1255 | + ]; |
|
| 1256 | + $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args); |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + |
|
| 1260 | + /** |
|
| 1261 | + * Handles trashing default ticket. |
|
| 1262 | + * |
|
| 1263 | + * @throws EE_Error |
|
| 1264 | + * @throws ReflectionException |
|
| 1265 | + */ |
|
| 1266 | + protected function _delete_ticket() |
|
| 1267 | + { |
|
| 1268 | + $success = 1; |
|
| 1269 | + // checkboxes? |
|
| 1270 | + $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
| 1271 | + if (! empty($checkboxes)) { |
|
| 1272 | + // if array has more than one element then success message should be plural |
|
| 1273 | + $success = count($checkboxes) > 1 ? 2 : 1; |
|
| 1274 | + // cycle thru the boxes |
|
| 1275 | + foreach ($checkboxes as $TKT_ID => $value) { |
|
| 1276 | + // delete |
|
| 1277 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1278 | + $success = 0; |
|
| 1279 | + } |
|
| 1280 | + } |
|
| 1281 | + } else { |
|
| 1282 | + // grab single id and trash |
|
| 1283 | + $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
|
| 1284 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1285 | + $success = 0; |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + $action_desc = 'deleted'; |
|
| 1289 | + $query_args = [ |
|
| 1290 | + 'action' => 'ticket_list_table', |
|
| 1291 | + 'status' => 'trashed', |
|
| 1292 | + ]; |
|
| 1293 | + // fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1294 | + if ( |
|
| 1295 | + EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1296 | + [['TKT_is_default' => 1]], |
|
| 1297 | + 'TKT_ID', |
|
| 1298 | + true |
|
| 1299 | + ) |
|
| 1300 | + ) { |
|
| 1301 | + $query_args = []; |
|
| 1302 | + } |
|
| 1303 | + $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args); |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * @param int $TKT_ID |
|
| 1309 | + * @return bool|int |
|
| 1310 | + * @throws EE_Error |
|
| 1311 | + * @throws ReflectionException |
|
| 1312 | + */ |
|
| 1313 | + protected function _delete_the_ticket(int $TKT_ID) |
|
| 1314 | + { |
|
| 1315 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1316 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1317 | + return false; |
|
| 1318 | + } |
|
| 1319 | + $ticket->_remove_relations('Datetime'); |
|
| 1320 | + // delete all related prices first |
|
| 1321 | + $ticket->delete_related_permanently('Price'); |
|
| 1322 | + return $ticket->delete_permanently(); |
|
| 1323 | + } |
|
| 1324 | 1324 | } |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function __construct($routing = true) |
| 29 | 29 | { |
| 30 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 31 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 32 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 33 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 30 | + if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 31 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/'); |
|
| 32 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/'); |
|
| 33 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/'); |
|
| 34 | 34 | } |
| 35 | 35 | parent::__construct($routing); |
| 36 | 36 | $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | parent::_set_page_config(); |
| 43 | 43 | |
| 44 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 44 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events'; |
|
| 45 | 45 | // is there an evt_id in the request? |
| 46 | 46 | $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
| 47 | 47 | $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | 'noheader' => true, |
| 140 | 140 | ], |
| 141 | 141 | ]; |
| 142 | - $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes); |
|
| 142 | + $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | public function admin_init() |
| 221 | 221 | { |
| 222 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 222 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 223 | 223 | 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
| 224 | 224 | 'event_espresso' |
| 225 | 225 | ); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | 'Clone this Event Date and Time', |
| 231 | 231 | 'event_espresso' |
| 232 | 232 | ); |
| 233 | - EE_Registry::$i18n_js_strings['remove_event_dt_msg'] = esc_html__( |
|
| 233 | + EE_Registry::$i18n_js_strings['remove_event_dt_msg'] = esc_html__( |
|
| 234 | 234 | 'Remove this Event Time', |
| 235 | 235 | 'event_espresso' |
| 236 | 236 | ); |
@@ -301,10 +301,10 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | public function load_scripts_styles_edit() |
| 303 | 303 | { |
| 304 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 304 | + if ( ! $this->admin_config->useAdvancedEditor()) { |
|
| 305 | 305 | wp_register_script( |
| 306 | 306 | 'ee-event-editor-heartbeat', |
| 307 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 307 | + EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js', |
|
| 308 | 308 | ['ee_admin_js', 'heartbeat'], |
| 309 | 309 | EVENT_ESPRESSO_VERSION, |
| 310 | 310 | true |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | wp_enqueue_script('event_editor_js'); |
| 316 | 316 | wp_register_style( |
| 317 | 317 | 'event-editor-css', |
| 318 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 318 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 319 | 319 | ['ee-admin-css'], |
| 320 | 320 | EVENT_ESPRESSO_VERSION |
| 321 | 321 | ); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | protected function _set_list_table_views_default() |
| 335 | 335 | { |
| 336 | 336 | parent::_set_list_table_views_default(); |
| 337 | - $new_views = [ |
|
| 337 | + $new_views = [ |
|
| 338 | 338 | 'today' => [ |
| 339 | 339 | 'slug' => 'today', |
| 340 | 340 | 'label' => esc_html__('Today', 'event_espresso'), |
@@ -383,8 +383,8 @@ discard block |
||
| 383 | 383 | ); |
| 384 | 384 | |
| 385 | 385 | $action_links[] = ' |
| 386 | - <a href="' . $reports_link . '" |
|
| 387 | - aria-label="' . esc_attr__('View Report', 'event_espresso') . '" |
|
| 386 | + <a href="' . $reports_link.'" |
|
| 387 | + aria-label="' . esc_attr__('View Report', 'event_espresso').'" |
|
| 388 | 388 | class="ee-aria-tooltip button button--icon-only" |
| 389 | 389 | > |
| 390 | 390 | <span class="dashicons dashicons-chart-bar"></span> |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | // first make sure the ID for the event is in the request. |
| 452 | 452 | // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
| 453 | 453 | $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
| 454 | - if (! $EVT_ID) { |
|
| 454 | + if ( ! $EVT_ID) { |
|
| 455 | 455 | EE_Error::add_error( |
| 456 | 456 | esc_html__( |
| 457 | 457 | 'In order to duplicate an event an Event ID is required. None was given.', |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | } |
| 467 | 467 | // k we've got EVT_ID so let's use that to get the event we'll duplicate |
| 468 | 468 | $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
| 469 | - if (! $orig_event instanceof EE_Event) { |
|
| 469 | + if ( ! $orig_event instanceof EE_Event) { |
|
| 470 | 470 | throw new EE_Error( |
| 471 | 471 | sprintf( |
| 472 | 472 | esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | $orig_ven = $orig_event->get_many_related('Venue'); |
| 483 | 483 | // reset the ID and modify other details to make it clear this is a dupe |
| 484 | 484 | $new_event->set('EVT_ID', 0); |
| 485 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 485 | + $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 486 | 486 | $new_event->set('EVT_name', $new_name); |
| 487 | 487 | $new_event->set( |
| 488 | 488 | 'EVT_slug', |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | 'Question_Group', |
| 512 | 512 | [['Event_Question_Group.EQG_primary' => true]] |
| 513 | 513 | ); |
| 514 | - if (! empty($orig_primary_qgs)) { |
|
| 514 | + if ( ! empty($orig_primary_qgs)) { |
|
| 515 | 515 | foreach ($orig_primary_qgs as $obj) { |
| 516 | 516 | if ($obj instanceof EE_Question_Group) { |
| 517 | 517 | $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | 'Question_Group', |
| 524 | 524 | [['Event_Question_Group.EQG_additional' => true]] |
| 525 | 525 | ); |
| 526 | - if (! empty($orig_additional_qgs)) { |
|
| 526 | + if ( ! empty($orig_additional_qgs)) { |
|
| 527 | 527 | foreach ($orig_additional_qgs as $obj) { |
| 528 | 528 | if ($obj instanceof EE_Question_Group) { |
| 529 | 529 | $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
| 537 | 537 | $cloned_tickets = []; |
| 538 | 538 | foreach ($orig_datetimes as $orig_dtt) { |
| 539 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
| 539 | + if ( ! $orig_dtt instanceof EE_Datetime) { |
|
| 540 | 540 | continue; |
| 541 | 541 | } |
| 542 | 542 | $new_dtt = clone $orig_dtt; |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | // now let's get the ticket relations setup. |
| 552 | 552 | foreach ((array) $orig_tickets as $orig_ticket) { |
| 553 | 553 | // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
| 554 | - if (! $orig_ticket instanceof EE_Ticket) { |
|
| 554 | + if ( ! $orig_ticket instanceof EE_Ticket) { |
|
| 555 | 555 | continue; |
| 556 | 556 | } |
| 557 | 557 | // is this ticket archived? If it is then let's skip |
@@ -560,8 +560,8 @@ discard block |
||
| 560 | 560 | } |
| 561 | 561 | // does this original ticket already exist in the clone_tickets cache? |
| 562 | 562 | // If so we'll just use the new ticket from it. |
| 563 | - if (isset($cloned_tickets[ $orig_ticket->ID() ])) { |
|
| 564 | - $new_ticket = $cloned_tickets[ $orig_ticket->ID() ]; |
|
| 563 | + if (isset($cloned_tickets[$orig_ticket->ID()])) { |
|
| 564 | + $new_ticket = $cloned_tickets[$orig_ticket->ID()]; |
|
| 565 | 565 | } else { |
| 566 | 566 | $new_ticket = clone $orig_ticket; |
| 567 | 567 | // get relations on the $orig_ticket that we need to set up. |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | $orig_dtt, |
| 596 | 596 | $new_dtt |
| 597 | 597 | ); |
| 598 | - $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket; |
|
| 598 | + $cloned_tickets[$orig_ticket->ID()] = $new_ticket; |
|
| 599 | 599 | } |
| 600 | 600 | // k now we can add the new ticket as a relation to the new datetime |
| 601 | 601 | // and make sure it's added to our cached $cloned_tickets array |
@@ -682,12 +682,12 @@ discard block |
||
| 682 | 682 | $type |
| 683 | 683 | ); |
| 684 | 684 | |
| 685 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 685 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 686 | 686 | ['action' => 'sample_export_file'], |
| 687 | 687 | $this->_admin_base_url |
| 688 | 688 | ); |
| 689 | 689 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 690 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 690 | + EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php', |
|
| 691 | 691 | $this->_template_args, |
| 692 | 692 | true |
| 693 | 693 | ); |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | */ |
| 705 | 705 | protected function _import_events() |
| 706 | 706 | { |
| 707 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 707 | + require_once(EE_CLASSES.'EE_Import.class.php'); |
|
| 708 | 708 | $success = EE_Import::instance()->import(); |
| 709 | 709 | $this->_redirect_after_action( |
| 710 | 710 | $success, |
@@ -734,8 +734,8 @@ discard block |
||
| 734 | 734 | 'EVT_ID' => $EVT_ID, |
| 735 | 735 | ] |
| 736 | 736 | ); |
| 737 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 738 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 737 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 738 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 739 | 739 | $EE_Export = EE_Export::instance($this->request->requestParams()); |
| 740 | 740 | $EE_Export->export(); |
| 741 | 741 | } |
@@ -757,8 +757,8 @@ discard block |
||
| 757 | 757 | 'EVT_ID' => $EVT_ID, |
| 758 | 758 | ] |
| 759 | 759 | ); |
| 760 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 761 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 760 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 761 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 762 | 762 | $EE_Export = EE_Export::instance($this->request->requestParams()); |
| 763 | 763 | $EE_Export->export(); |
| 764 | 764 | } |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | $this->_set_add_edit_form_tags('update_template_settings'); |
| 803 | 803 | $this->_set_publish_post_box_vars(); |
| 804 | 804 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 805 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 805 | + EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php', |
|
| 806 | 806 | $this->_template_args, |
| 807 | 807 | true |
| 808 | 808 | ); |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | $template_args['_event'] = $this->_cpt_model_obj; |
| 919 | 919 | $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
| 920 | 920 | |
| 921 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 921 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 922 | 922 | 'default_reg_status', |
| 923 | 923 | $default_reg_status_values, |
| 924 | 924 | $this->_cpt_model_obj->default_registration_status(), |
@@ -926,12 +926,12 @@ discard block |
||
| 926 | 926 | 'ee-input-width--reg', |
| 927 | 927 | false |
| 928 | 928 | ); |
| 929 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 929 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 930 | 930 | 'display_desc', |
| 931 | 931 | $yes_no_values, |
| 932 | 932 | $this->_cpt_model_obj->display_description() |
| 933 | 933 | ); |
| 934 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 934 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 935 | 935 | 'display_ticket_selector', |
| 936 | 936 | $yes_no_values, |
| 937 | 937 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | $default_reg_status_values |
| 956 | 956 | ); |
| 957 | 957 | EEH_Template::display_template( |
| 958 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 958 | + EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 959 | 959 | $template_args |
| 960 | 960 | ); |
| 961 | 961 | } |
@@ -1027,7 +1027,7 @@ discard block |
||
| 1027 | 1027 | $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
| 1028 | 1028 | |
| 1029 | 1029 | foreach ($venues as $venue) { |
| 1030 | - $values[ $venue->ID() ] = $venue->name(); |
|
| 1030 | + $values[$venue->ID()] = $venue->name(); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | return EEH_Form_Fields::select_input('venue', $values, $current_value); |
@@ -1066,13 +1066,13 @@ discard block |
||
| 1066 | 1066 | { |
| 1067 | 1067 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
| 1068 | 1068 | 'DTT_EVT_start', |
| 1069 | - date('Y-m-d') . ' 00:00:00', |
|
| 1069 | + date('Y-m-d').' 00:00:00', |
|
| 1070 | 1070 | 'Y-m-d H:i:s', |
| 1071 | 1071 | 'UTC' |
| 1072 | 1072 | ); |
| 1073 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1073 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1074 | 1074 | 'DTT_EVT_start', |
| 1075 | - date('Y-m-d') . ' 23:59:59', |
|
| 1075 | + date('Y-m-d').' 23:59:59', |
|
| 1076 | 1076 | 'Y-m-d H:i:s', |
| 1077 | 1077 | 'UTC' |
| 1078 | 1078 | ); |
@@ -1102,17 +1102,17 @@ discard block |
||
| 1102 | 1102 | $days_this_month = date('t'); |
| 1103 | 1103 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
| 1104 | 1104 | 'DTT_EVT_start', |
| 1105 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1105 | + $this_year_r.'-'.$this_month_r.'-01 00:00:00', |
|
| 1106 | 1106 | 'Y-m-d H:i:s', |
| 1107 | 1107 | 'UTC' |
| 1108 | 1108 | ); |
| 1109 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1109 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1110 | 1110 | 'DTT_EVT_start', |
| 1111 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1111 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59', |
|
| 1112 | 1112 | 'Y-m-d H:i:s', |
| 1113 | 1113 | 'UTC' |
| 1114 | 1114 | ); |
| 1115 | - $where = [ |
|
| 1115 | + $where = [ |
|
| 1116 | 1116 | 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
| 1117 | 1117 | ]; |
| 1118 | 1118 | return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
@@ -1134,7 +1134,7 @@ discard block |
||
| 1134 | 1134 | ) { |
| 1135 | 1135 | // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
| 1136 | 1136 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 1137 | - EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php', |
|
| 1137 | + EVENTS_CAF_TEMPLATE_PATH.'default_tickets_moved_notice.template.php', |
|
| 1138 | 1138 | [], |
| 1139 | 1139 | true |
| 1140 | 1140 | ); |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | |
| 1191 | 1191 | $search_term = $this->request->getRequestParam('s'); |
| 1192 | 1192 | if ($search_term) { |
| 1193 | - $search_term = '%' . $search_term . '%'; |
|
| 1193 | + $search_term = '%'.$search_term.'%'; |
|
| 1194 | 1194 | $where['OR'] = [ |
| 1195 | 1195 | 'TKT_name' => ['LIKE', $search_term], |
| 1196 | 1196 | 'TKT_description' => ['LIKE', $search_term], |
@@ -1224,16 +1224,16 @@ discard block |
||
| 1224 | 1224 | $TKT = EEM_Ticket::instance(); |
| 1225 | 1225 | // checkboxes? |
| 1226 | 1226 | $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
| 1227 | - if (! empty($checkboxes)) { |
|
| 1227 | + if ( ! empty($checkboxes)) { |
|
| 1228 | 1228 | // if array has more than one element then success message should be plural |
| 1229 | 1229 | $success = count($checkboxes) > 1 ? 2 : 1; |
| 1230 | 1230 | // cycle thru the boxes |
| 1231 | 1231 | foreach ($checkboxes as $TKT_ID => $value) { |
| 1232 | 1232 | if ($trash) { |
| 1233 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1233 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1234 | 1234 | $success = 0; |
| 1235 | 1235 | } |
| 1236 | - } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1236 | + } elseif ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1237 | 1237 | $success = 0; |
| 1238 | 1238 | } |
| 1239 | 1239 | } |
@@ -1241,10 +1241,10 @@ discard block |
||
| 1241 | 1241 | // grab single id and trash |
| 1242 | 1242 | $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
| 1243 | 1243 | if ($trash) { |
| 1244 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1244 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1245 | 1245 | $success = 0; |
| 1246 | 1246 | } |
| 1247 | - } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1247 | + } elseif ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1248 | 1248 | $success = 0; |
| 1249 | 1249 | } |
| 1250 | 1250 | } |
@@ -1268,20 +1268,20 @@ discard block |
||
| 1268 | 1268 | $success = 1; |
| 1269 | 1269 | // checkboxes? |
| 1270 | 1270 | $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); |
| 1271 | - if (! empty($checkboxes)) { |
|
| 1271 | + if ( ! empty($checkboxes)) { |
|
| 1272 | 1272 | // if array has more than one element then success message should be plural |
| 1273 | 1273 | $success = count($checkboxes) > 1 ? 2 : 1; |
| 1274 | 1274 | // cycle thru the boxes |
| 1275 | 1275 | foreach ($checkboxes as $TKT_ID => $value) { |
| 1276 | 1276 | // delete |
| 1277 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1277 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1278 | 1278 | $success = 0; |
| 1279 | 1279 | } |
| 1280 | 1280 | } |
| 1281 | 1281 | } else { |
| 1282 | 1282 | // grab single id and trash |
| 1283 | 1283 | $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int'); |
| 1284 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1284 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1285 | 1285 | $success = 0; |
| 1286 | 1286 | } |
| 1287 | 1287 | } |
@@ -1313,7 +1313,7 @@ discard block |
||
| 1313 | 1313 | protected function _delete_the_ticket(int $TKT_ID) |
| 1314 | 1314 | { |
| 1315 | 1315 | $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
| 1316 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1316 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1317 | 1317 | return false; |
| 1318 | 1318 | } |
| 1319 | 1319 | $ticket->_remove_relations('Datetime'); |
@@ -21,212 +21,212 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Manager |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * List of PMs that can be replaced with PP Commerce. |
|
| 26 | - * ['payment method name' => 'settings option'] |
|
| 27 | - * |
|
| 28 | - * @var array $pms_can_hide |
|
| 29 | - */ |
|
| 30 | - protected static array $pms_can_hide = [ |
|
| 31 | - 'paypal_express' => 'api_username', |
|
| 32 | - 'paypal_pro' => 'api_username', |
|
| 33 | - 'aim' => 'login_id', |
|
| 34 | - ]; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Manager constructor. |
|
| 39 | - */ |
|
| 40 | - public function __construct() |
|
| 41 | - { |
|
| 42 | - if (DbStatus::isOffline()) { |
|
| 43 | - return; |
|
| 44 | - } |
|
| 45 | - $this->loadPaymentMethods(); |
|
| 46 | - if (is_admin()) { |
|
| 47 | - // Use only PayPal Commerce if it's a new setup. |
|
| 48 | - add_filter( |
|
| 49 | - 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
| 50 | - [__CLASS__, 'hidePaymentMethods'] |
|
| 51 | - ); |
|
| 52 | - // Payment methods related admin notices. |
|
| 53 | - add_action('admin_init', [__CLASS__, 'adminNotice']); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Load all payment methods that are in PaymentMethods folder. |
|
| 60 | - * |
|
| 61 | - * @return void |
|
| 62 | - */ |
|
| 63 | - protected function loadPaymentMethods() |
|
| 64 | - { |
|
| 65 | - // Scan the PaymentMethods folder. |
|
| 66 | - $pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR); |
|
| 67 | - // Filter the discovered PM list. |
|
| 68 | - $pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list); |
|
| 69 | - // Clean from duplicates. |
|
| 70 | - $pms_list = array_unique($pms_list); |
|
| 71 | - foreach ($pms_list as $pm_path) { |
|
| 72 | - $this->registerPaymentMethod($pm_path); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Looks for the main payment method file and loads it. |
|
| 79 | - * |
|
| 80 | - * @param string $pm_path path to the payment method folder |
|
| 81 | - * @param string $file_ext |
|
| 82 | - * @param string $pm_namespace |
|
| 83 | - * @return boolean |
|
| 84 | - */ |
|
| 85 | - public function registerPaymentMethod( |
|
| 86 | - string $pm_path, |
|
| 87 | - string $file_ext = '.php', |
|
| 88 | - string $pm_namespace = 'EventEspresso\PaymentMethods' |
|
| 89 | - ): bool { |
|
| 90 | - do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path); |
|
| 91 | - // Separators should match. |
|
| 92 | - $pm_path = str_replace('/\\', '/', $pm_path) . DS; |
|
| 93 | - // Sanitize PM name. |
|
| 94 | - $module_dir = basename($pm_path); |
|
| 95 | - // Get class name. |
|
| 96 | - $pm_class_name = str_replace(' ', '_', $module_dir); |
|
| 97 | - // Check if file exists. |
|
| 98 | - if (! is_readable($pm_path . $pm_class_name . $file_ext)) { |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - // Load the initial PM class. |
|
| 102 | - require_once($pm_path . DS . $pm_class_name . $file_ext); |
|
| 103 | - $pm_object = "$pm_namespace\\$pm_class_name"; |
|
| 104 | - if (! class_exists($pm_object)) { |
|
| 105 | - return false; |
|
| 106 | - } |
|
| 107 | - $payment_menthod = new $pm_object(); |
|
| 108 | - $payment_menthod->initialize(); |
|
| 109 | - return true; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Deactivate a few other PMs if it's a new setup. Use PP Commerce. |
|
| 115 | - * |
|
| 116 | - * @param array $pms_to_list |
|
| 117 | - * @return array |
|
| 118 | - * @throws EE_Error |
|
| 119 | - * @throws ReflectionException |
|
| 120 | - */ |
|
| 121 | - public static function hidePaymentMethods(array $pms_to_list): array |
|
| 122 | - { |
|
| 123 | - foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
|
| 124 | - // Can we deregister this PM ? |
|
| 125 | - if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) { |
|
| 126 | - unset($pms_to_list[ $pm_name ]); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - return $pms_to_list; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Deregisters the provided payment method if not used. |
|
| 135 | - * |
|
| 136 | - * @param string $pm_name |
|
| 137 | - * @param string $pm_option |
|
| 138 | - * @return bool |
|
| 139 | - * @throws EE_Error |
|
| 140 | - * @throws ReflectionException |
|
| 141 | - */ |
|
| 142 | - public static function pmCanBeHidden(string $pm_name, string $pm_option): bool |
|
| 143 | - { |
|
| 144 | - $pm_to_hide = EEM_Payment_Method::instance()->get_one_by_slug($pm_name); |
|
| 145 | - $pm_active = $pm_active_before = false; |
|
| 146 | - if ($pm_to_hide instanceof EE_Payment_Method) { |
|
| 147 | - $pm_active = $pm_to_hide->active(); |
|
| 148 | - // Payment method used before ? |
|
| 149 | - $option = $pm_to_hide->get_extra_meta($pm_option, true, false); |
|
| 150 | - $pm_active_before = ! empty($option); |
|
| 151 | - } |
|
| 152 | - // If PM not used before and not active, deregister it. |
|
| 153 | - if ( |
|
| 154 | - apply_filters( |
|
| 155 | - "FHEE__PaymentMethods__Manager__register_payment_methods__hide_$pm_name", |
|
| 156 | - ! $pm_active && ! $pm_active_before, |
|
| 157 | - $pm_name |
|
| 158 | - ) |
|
| 159 | - ) { |
|
| 160 | - return true; |
|
| 161 | - } |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Payment methods related admin notices. |
|
| 168 | - * |
|
| 169 | - * @return void |
|
| 170 | - */ |
|
| 171 | - public static function adminNotice() |
|
| 172 | - { |
|
| 173 | - // Is this an EE admin page ? |
|
| 174 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 175 | - $page_name = $request->getRequestParam('page'); |
|
| 176 | - // Only show the notice on core EE pages |
|
| 177 | - if (! str_contains($page_name, 'espresso')) { |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - // Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM. |
|
| 181 | - try { |
|
| 182 | - $pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout'); |
|
| 183 | - // Don't show notice if PayPal Commerce is active. |
|
| 184 | - if ($pp_commerce instanceof EE_Payment_Method && $pp_commerce->active()) { |
|
| 185 | - return; |
|
| 186 | - } |
|
| 187 | - foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
|
| 188 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_name); |
|
| 189 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->active()) { |
|
| 190 | - add_action('admin_notices', [__CLASS__, 'usePayPalCommerceNotice']); |
|
| 191 | - return; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } catch (EE_Error | ReflectionException $e) { |
|
| 195 | - // No handling needed right now. |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Recommend PayPal Commerce notice contents. |
|
| 202 | - * |
|
| 203 | - * @return void |
|
| 204 | - */ |
|
| 205 | - public static function usePayPalCommerceNotice() |
|
| 206 | - { |
|
| 207 | - echo '<div class="error"><p>' |
|
| 208 | - . sprintf( |
|
| 209 | - esc_html__( |
|
| 210 | - 'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.', |
|
| 211 | - 'event_espresso' |
|
| 212 | - ), |
|
| 213 | - '<strong>', |
|
| 214 | - '</strong>' |
|
| 215 | - ) |
|
| 216 | - . '</p></div>'; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @return bool |
|
| 222 | - * @since 5.0.20.p |
|
| 223 | - */ |
|
| 224 | - public static function verifySSL(): bool |
|
| 225 | - { |
|
| 226 | - static $verify_ssl = null; |
|
| 227 | - if ($verify_ssl === null) { |
|
| 228 | - $verify_ssl = (bool) apply_filters('FHEE__EventEspresso_PaymentMethods_Manager__verifySSL', true); |
|
| 229 | - } |
|
| 230 | - return (bool) $verify_ssl; |
|
| 231 | - } |
|
| 24 | + /** |
|
| 25 | + * List of PMs that can be replaced with PP Commerce. |
|
| 26 | + * ['payment method name' => 'settings option'] |
|
| 27 | + * |
|
| 28 | + * @var array $pms_can_hide |
|
| 29 | + */ |
|
| 30 | + protected static array $pms_can_hide = [ |
|
| 31 | + 'paypal_express' => 'api_username', |
|
| 32 | + 'paypal_pro' => 'api_username', |
|
| 33 | + 'aim' => 'login_id', |
|
| 34 | + ]; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Manager constructor. |
|
| 39 | + */ |
|
| 40 | + public function __construct() |
|
| 41 | + { |
|
| 42 | + if (DbStatus::isOffline()) { |
|
| 43 | + return; |
|
| 44 | + } |
|
| 45 | + $this->loadPaymentMethods(); |
|
| 46 | + if (is_admin()) { |
|
| 47 | + // Use only PayPal Commerce if it's a new setup. |
|
| 48 | + add_filter( |
|
| 49 | + 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
| 50 | + [__CLASS__, 'hidePaymentMethods'] |
|
| 51 | + ); |
|
| 52 | + // Payment methods related admin notices. |
|
| 53 | + add_action('admin_init', [__CLASS__, 'adminNotice']); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Load all payment methods that are in PaymentMethods folder. |
|
| 60 | + * |
|
| 61 | + * @return void |
|
| 62 | + */ |
|
| 63 | + protected function loadPaymentMethods() |
|
| 64 | + { |
|
| 65 | + // Scan the PaymentMethods folder. |
|
| 66 | + $pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR); |
|
| 67 | + // Filter the discovered PM list. |
|
| 68 | + $pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list); |
|
| 69 | + // Clean from duplicates. |
|
| 70 | + $pms_list = array_unique($pms_list); |
|
| 71 | + foreach ($pms_list as $pm_path) { |
|
| 72 | + $this->registerPaymentMethod($pm_path); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Looks for the main payment method file and loads it. |
|
| 79 | + * |
|
| 80 | + * @param string $pm_path path to the payment method folder |
|
| 81 | + * @param string $file_ext |
|
| 82 | + * @param string $pm_namespace |
|
| 83 | + * @return boolean |
|
| 84 | + */ |
|
| 85 | + public function registerPaymentMethod( |
|
| 86 | + string $pm_path, |
|
| 87 | + string $file_ext = '.php', |
|
| 88 | + string $pm_namespace = 'EventEspresso\PaymentMethods' |
|
| 89 | + ): bool { |
|
| 90 | + do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path); |
|
| 91 | + // Separators should match. |
|
| 92 | + $pm_path = str_replace('/\\', '/', $pm_path) . DS; |
|
| 93 | + // Sanitize PM name. |
|
| 94 | + $module_dir = basename($pm_path); |
|
| 95 | + // Get class name. |
|
| 96 | + $pm_class_name = str_replace(' ', '_', $module_dir); |
|
| 97 | + // Check if file exists. |
|
| 98 | + if (! is_readable($pm_path . $pm_class_name . $file_ext)) { |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + // Load the initial PM class. |
|
| 102 | + require_once($pm_path . DS . $pm_class_name . $file_ext); |
|
| 103 | + $pm_object = "$pm_namespace\\$pm_class_name"; |
|
| 104 | + if (! class_exists($pm_object)) { |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 107 | + $payment_menthod = new $pm_object(); |
|
| 108 | + $payment_menthod->initialize(); |
|
| 109 | + return true; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Deactivate a few other PMs if it's a new setup. Use PP Commerce. |
|
| 115 | + * |
|
| 116 | + * @param array $pms_to_list |
|
| 117 | + * @return array |
|
| 118 | + * @throws EE_Error |
|
| 119 | + * @throws ReflectionException |
|
| 120 | + */ |
|
| 121 | + public static function hidePaymentMethods(array $pms_to_list): array |
|
| 122 | + { |
|
| 123 | + foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
|
| 124 | + // Can we deregister this PM ? |
|
| 125 | + if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) { |
|
| 126 | + unset($pms_to_list[ $pm_name ]); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + return $pms_to_list; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Deregisters the provided payment method if not used. |
|
| 135 | + * |
|
| 136 | + * @param string $pm_name |
|
| 137 | + * @param string $pm_option |
|
| 138 | + * @return bool |
|
| 139 | + * @throws EE_Error |
|
| 140 | + * @throws ReflectionException |
|
| 141 | + */ |
|
| 142 | + public static function pmCanBeHidden(string $pm_name, string $pm_option): bool |
|
| 143 | + { |
|
| 144 | + $pm_to_hide = EEM_Payment_Method::instance()->get_one_by_slug($pm_name); |
|
| 145 | + $pm_active = $pm_active_before = false; |
|
| 146 | + if ($pm_to_hide instanceof EE_Payment_Method) { |
|
| 147 | + $pm_active = $pm_to_hide->active(); |
|
| 148 | + // Payment method used before ? |
|
| 149 | + $option = $pm_to_hide->get_extra_meta($pm_option, true, false); |
|
| 150 | + $pm_active_before = ! empty($option); |
|
| 151 | + } |
|
| 152 | + // If PM not used before and not active, deregister it. |
|
| 153 | + if ( |
|
| 154 | + apply_filters( |
|
| 155 | + "FHEE__PaymentMethods__Manager__register_payment_methods__hide_$pm_name", |
|
| 156 | + ! $pm_active && ! $pm_active_before, |
|
| 157 | + $pm_name |
|
| 158 | + ) |
|
| 159 | + ) { |
|
| 160 | + return true; |
|
| 161 | + } |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Payment methods related admin notices. |
|
| 168 | + * |
|
| 169 | + * @return void |
|
| 170 | + */ |
|
| 171 | + public static function adminNotice() |
|
| 172 | + { |
|
| 173 | + // Is this an EE admin page ? |
|
| 174 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 175 | + $page_name = $request->getRequestParam('page'); |
|
| 176 | + // Only show the notice on core EE pages |
|
| 177 | + if (! str_contains($page_name, 'espresso')) { |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + // Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM. |
|
| 181 | + try { |
|
| 182 | + $pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout'); |
|
| 183 | + // Don't show notice if PayPal Commerce is active. |
|
| 184 | + if ($pp_commerce instanceof EE_Payment_Method && $pp_commerce->active()) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 187 | + foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
|
| 188 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_name); |
|
| 189 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->active()) { |
|
| 190 | + add_action('admin_notices', [__CLASS__, 'usePayPalCommerceNotice']); |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } catch (EE_Error | ReflectionException $e) { |
|
| 195 | + // No handling needed right now. |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Recommend PayPal Commerce notice contents. |
|
| 202 | + * |
|
| 203 | + * @return void |
|
| 204 | + */ |
|
| 205 | + public static function usePayPalCommerceNotice() |
|
| 206 | + { |
|
| 207 | + echo '<div class="error"><p>' |
|
| 208 | + . sprintf( |
|
| 209 | + esc_html__( |
|
| 210 | + 'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.', |
|
| 211 | + 'event_espresso' |
|
| 212 | + ), |
|
| 213 | + '<strong>', |
|
| 214 | + '</strong>' |
|
| 215 | + ) |
|
| 216 | + . '</p></div>'; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @return bool |
|
| 222 | + * @since 5.0.20.p |
|
| 223 | + */ |
|
| 224 | + public static function verifySSL(): bool |
|
| 225 | + { |
|
| 226 | + static $verify_ssl = null; |
|
| 227 | + if ($verify_ssl === null) { |
|
| 228 | + $verify_ssl = (bool) apply_filters('FHEE__EventEspresso_PaymentMethods_Manager__verifySSL', true); |
|
| 229 | + } |
|
| 230 | + return (bool) $verify_ssl; |
|
| 231 | + } |
|
| 232 | 232 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | protected function loadPaymentMethods() |
| 64 | 64 | { |
| 65 | 65 | // Scan the PaymentMethods folder. |
| 66 | - $pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR); |
|
| 66 | + $pms_list = glob(EE_PLUGIN_DIR_PATH.'PaymentMethods/*', GLOB_ONLYDIR); |
|
| 67 | 67 | // Filter the discovered PM list. |
| 68 | 68 | $pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list); |
| 69 | 69 | // Clean from duplicates. |
@@ -89,19 +89,19 @@ discard block |
||
| 89 | 89 | ): bool { |
| 90 | 90 | do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path); |
| 91 | 91 | // Separators should match. |
| 92 | - $pm_path = str_replace('/\\', '/', $pm_path) . DS; |
|
| 92 | + $pm_path = str_replace('/\\', '/', $pm_path).DS; |
|
| 93 | 93 | // Sanitize PM name. |
| 94 | 94 | $module_dir = basename($pm_path); |
| 95 | 95 | // Get class name. |
| 96 | 96 | $pm_class_name = str_replace(' ', '_', $module_dir); |
| 97 | 97 | // Check if file exists. |
| 98 | - if (! is_readable($pm_path . $pm_class_name . $file_ext)) { |
|
| 98 | + if ( ! is_readable($pm_path.$pm_class_name.$file_ext)) { |
|
| 99 | 99 | return false; |
| 100 | 100 | } |
| 101 | 101 | // Load the initial PM class. |
| 102 | - require_once($pm_path . DS . $pm_class_name . $file_ext); |
|
| 102 | + require_once($pm_path.DS.$pm_class_name.$file_ext); |
|
| 103 | 103 | $pm_object = "$pm_namespace\\$pm_class_name"; |
| 104 | - if (! class_exists($pm_object)) { |
|
| 104 | + if ( ! class_exists($pm_object)) { |
|
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | $payment_menthod = new $pm_object(); |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | { |
| 123 | 123 | foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
| 124 | 124 | // Can we deregister this PM ? |
| 125 | - if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) { |
|
| 126 | - unset($pms_to_list[ $pm_name ]); |
|
| 125 | + if (isset($pms_to_list[$pm_name]) && self::pmCanBeHidden($pm_name, $pm_option)) { |
|
| 126 | + unset($pms_to_list[$pm_name]); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | return $pms_to_list; |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
| 175 | 175 | $page_name = $request->getRequestParam('page'); |
| 176 | 176 | // Only show the notice on core EE pages |
| 177 | - if (! str_contains($page_name, 'espresso')) { |
|
| 177 | + if ( ! str_contains($page_name, 'espresso')) { |
|
| 178 | 178 | return; |
| 179 | 179 | } |
| 180 | 180 | // Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM. |
@@ -16,188 +16,188 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class EE_PMT_PayPalCheckout extends EE_PMT_Base |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @param EE_Payment_Method|null $pm_instance |
|
| 21 | - * @throws ReflectionException |
|
| 22 | - * @throws EE_Error |
|
| 23 | - */ |
|
| 24 | - public function __construct($pm_instance = null) |
|
| 25 | - { |
|
| 26 | - $this->_template_path = dirname(__FILE__) . DS . 'templates' . DS; |
|
| 27 | - $this->_default_description = esc_html__('Please provide the following billing information.', 'event_espresso'); |
|
| 28 | - $this->_default_button_url = $this->file_url() . 'lib/default-cc-logo.png'; |
|
| 29 | - $this->_pretty_name = esc_html__('PayPal Commerce', 'event_espresso'); |
|
| 30 | - $this->_cache_billing_form = true; |
|
| 31 | - $this->_requires_https = true; |
|
| 19 | + /** |
|
| 20 | + * @param EE_Payment_Method|null $pm_instance |
|
| 21 | + * @throws ReflectionException |
|
| 22 | + * @throws EE_Error |
|
| 23 | + */ |
|
| 24 | + public function __construct($pm_instance = null) |
|
| 25 | + { |
|
| 26 | + $this->_template_path = dirname(__FILE__) . DS . 'templates' . DS; |
|
| 27 | + $this->_default_description = esc_html__('Please provide the following billing information.', 'event_espresso'); |
|
| 28 | + $this->_default_button_url = $this->file_url() . 'lib/default-cc-logo.png'; |
|
| 29 | + $this->_pretty_name = esc_html__('PayPal Commerce', 'event_espresso'); |
|
| 30 | + $this->_cache_billing_form = true; |
|
| 31 | + $this->_requires_https = true; |
|
| 32 | 32 | |
| 33 | - // Load gateway. |
|
| 34 | - require_once( |
|
| 35 | - EEP_PAYPAL_COMMERCE_PATH . 'EEG_PayPalCheckout.gateway.php' |
|
| 36 | - ); |
|
| 37 | - $this->_gateway = new EEG_PayPalCheckout(); |
|
| 33 | + // Load gateway. |
|
| 34 | + require_once( |
|
| 35 | + EEP_PAYPAL_COMMERCE_PATH . 'EEG_PayPalCheckout.gateway.php' |
|
| 36 | + ); |
|
| 37 | + $this->_gateway = new EEG_PayPalCheckout(); |
|
| 38 | 38 | |
| 39 | - // Display a refund message at transactions actions area. |
|
| 40 | - add_action( |
|
| 41 | - 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', |
|
| 42 | - [__CLASS__, 'refundNotice'], |
|
| 43 | - 10, |
|
| 44 | - 1 |
|
| 45 | - ); |
|
| 39 | + // Display a refund message at transactions actions area. |
|
| 40 | + add_action( |
|
| 41 | + 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', |
|
| 42 | + [__CLASS__, 'refundNotice'], |
|
| 43 | + 10, |
|
| 44 | + 1 |
|
| 45 | + ); |
|
| 46 | 46 | |
| 47 | - parent::__construct($pm_instance); |
|
| 48 | - } |
|
| 47 | + parent::__construct($pm_instance); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Generate a new payment method settings form. |
|
| 53 | - * |
|
| 54 | - * @return EE_Payment_Method_Form |
|
| 55 | - * @throws EE_Error |
|
| 56 | - * @throws ReflectionException |
|
| 57 | - */ |
|
| 58 | - public function generate_new_settings_form() |
|
| 59 | - { |
|
| 60 | - // Settings form. |
|
| 61 | - $settings_form = new SettingsForm($this, $this->_pm_instance); |
|
| 62 | - // Filter the form contents. |
|
| 63 | - return apply_filters( |
|
| 64 | - 'FHEE__EE_PMT_PayPalCheckout__generate_new_settings_form__form_filtering', |
|
| 65 | - $settings_form, |
|
| 66 | - $this, |
|
| 67 | - $this->_pm_instance |
|
| 68 | - ); |
|
| 69 | - } |
|
| 51 | + /** |
|
| 52 | + * Generate a new payment method settings form. |
|
| 53 | + * |
|
| 54 | + * @return EE_Payment_Method_Form |
|
| 55 | + * @throws EE_Error |
|
| 56 | + * @throws ReflectionException |
|
| 57 | + */ |
|
| 58 | + public function generate_new_settings_form() |
|
| 59 | + { |
|
| 60 | + // Settings form. |
|
| 61 | + $settings_form = new SettingsForm($this, $this->_pm_instance); |
|
| 62 | + // Filter the form contents. |
|
| 63 | + return apply_filters( |
|
| 64 | + 'FHEE__EE_PMT_PayPalCheckout__generate_new_settings_form__form_filtering', |
|
| 65 | + $settings_form, |
|
| 66 | + $this, |
|
| 67 | + $this->_pm_instance |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Creates a billing form for this payment method type. |
|
| 74 | - * |
|
| 75 | - * @param EE_Transaction|null $transaction |
|
| 76 | - * @param array|null $extra_args |
|
| 77 | - * @return EE_Billing_Info_Form|null |
|
| 78 | - * @throws EE_Error |
|
| 79 | - * @throws ReflectionException |
|
| 80 | - */ |
|
| 81 | - public function generate_new_billing_form(EE_Transaction $transaction = null, ?array $extra_args = []) |
|
| 82 | - { |
|
| 83 | - $request = LoaderFactory::getShared(Request::class); |
|
| 84 | - $request_params = $request->requestParams(); |
|
| 85 | - // Return the default billing form for the postbox if this is a WP admin transaction info page. |
|
| 86 | - if (! empty($request_params['page']) && $request_params['page'] === 'espresso_transactions') { |
|
| 87 | - $default_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, $extra_args); |
|
| 88 | - $default_form->add_subsections(['credit_card' => new EE_Credit_Card_Input()]); |
|
| 89 | - return $default_form; |
|
| 90 | - } |
|
| 91 | - // Just in case this is used on other admin pages. |
|
| 92 | - if (empty($transaction) && ! empty($request_params['TXN_ID'])) { |
|
| 93 | - $txn_instance = EEM_Transaction::instance()->get_one_by_ID($request_params['TXN_ID']); |
|
| 94 | - $transaction = $txn_instance instanceof EE_Transaction ? $txn_instance : null; |
|
| 95 | - } |
|
| 96 | - $options = array_merge( |
|
| 97 | - [ |
|
| 98 | - 'transaction' => $transaction, |
|
| 99 | - 'template_path' => $this->_template_path, |
|
| 100 | - ], |
|
| 101 | - $extra_args |
|
| 102 | - ); |
|
| 103 | - return LoaderFactory::getNew(BillingForm::class, [$this->_pm_instance, $options]); |
|
| 104 | - } |
|
| 72 | + /** |
|
| 73 | + * Creates a billing form for this payment method type. |
|
| 74 | + * |
|
| 75 | + * @param EE_Transaction|null $transaction |
|
| 76 | + * @param array|null $extra_args |
|
| 77 | + * @return EE_Billing_Info_Form|null |
|
| 78 | + * @throws EE_Error |
|
| 79 | + * @throws ReflectionException |
|
| 80 | + */ |
|
| 81 | + public function generate_new_billing_form(EE_Transaction $transaction = null, ?array $extra_args = []) |
|
| 82 | + { |
|
| 83 | + $request = LoaderFactory::getShared(Request::class); |
|
| 84 | + $request_params = $request->requestParams(); |
|
| 85 | + // Return the default billing form for the postbox if this is a WP admin transaction info page. |
|
| 86 | + if (! empty($request_params['page']) && $request_params['page'] === 'espresso_transactions') { |
|
| 87 | + $default_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, $extra_args); |
|
| 88 | + $default_form->add_subsections(['credit_card' => new EE_Credit_Card_Input()]); |
|
| 89 | + return $default_form; |
|
| 90 | + } |
|
| 91 | + // Just in case this is used on other admin pages. |
|
| 92 | + if (empty($transaction) && ! empty($request_params['TXN_ID'])) { |
|
| 93 | + $txn_instance = EEM_Transaction::instance()->get_one_by_ID($request_params['TXN_ID']); |
|
| 94 | + $transaction = $txn_instance instanceof EE_Transaction ? $txn_instance : null; |
|
| 95 | + } |
|
| 96 | + $options = array_merge( |
|
| 97 | + [ |
|
| 98 | + 'transaction' => $transaction, |
|
| 99 | + 'template_path' => $this->_template_path, |
|
| 100 | + ], |
|
| 101 | + $extra_args |
|
| 102 | + ); |
|
| 103 | + return LoaderFactory::getNew(BillingForm::class, [$this->_pm_instance, $options]); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Adds PM info to the help tab. |
|
| 109 | - * |
|
| 110 | - * @return array |
|
| 111 | - * @see EE_PMT_Base::help_tabs_config() |
|
| 112 | - */ |
|
| 113 | - public function help_tabs_config(): array |
|
| 114 | - { |
|
| 115 | - return [ |
|
| 116 | - $this->get_help_tab_name() => [ |
|
| 117 | - 'title' => esc_html__('PayPal Commerce settings', 'event_espresso'), |
|
| 118 | - 'filename' => 'pp-commerce-overview', |
|
| 119 | - ], |
|
| 120 | - ]; |
|
| 121 | - } |
|
| 107 | + /** |
|
| 108 | + * Adds PM info to the help tab. |
|
| 109 | + * |
|
| 110 | + * @return array |
|
| 111 | + * @see EE_PMT_Base::help_tabs_config() |
|
| 112 | + */ |
|
| 113 | + public function help_tabs_config(): array |
|
| 114 | + { |
|
| 115 | + return [ |
|
| 116 | + $this->get_help_tab_name() => [ |
|
| 117 | + 'title' => esc_html__('PayPal Commerce settings', 'event_espresso'), |
|
| 118 | + 'filename' => 'pp-commerce-overview', |
|
| 119 | + ], |
|
| 120 | + ]; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Adds a refund related message section. |
|
| 126 | - * |
|
| 127 | - * @param bool $can_edit_payments Flag that tells if user can edit payments. |
|
| 128 | - * @access public |
|
| 129 | - * @return void |
|
| 130 | - */ |
|
| 131 | - public static function refundNotice(bool $can_edit_payments) |
|
| 132 | - { |
|
| 133 | - if (! $can_edit_payments) { |
|
| 134 | - return; |
|
| 135 | - } |
|
| 136 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 137 | - $txn_id = $request->getRequestParam('TXN_ID', 0, DataType::INT); |
|
| 138 | - try { |
|
| 139 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($txn_id); |
|
| 140 | - if (! $transaction instanceof EE_Transaction) { |
|
| 141 | - return; |
|
| 142 | - } |
|
| 143 | - // Was this transaction paid using PayPal ? |
|
| 144 | - if (strpos((string) $transaction->payment_method(), 'PayPal Commerce') === false) { |
|
| 145 | - return; |
|
| 146 | - } |
|
| 147 | - // Try loading the template. |
|
| 148 | - EE_Registry::instance()->load_helper('Template'); |
|
| 149 | - } catch (EE_Error|ReflectionException $e) { |
|
| 150 | - // Just return, adding nothing. |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - $html = EEH_Template::locate_template( |
|
| 154 | - apply_filters( |
|
| 155 | - 'FHEEA__EE_PMT_PayPalCheckout__refundNotice', |
|
| 156 | - dirname(__FILE__) . DS . 'templates' . DS . 'apply-refund-notice.template.php' |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - echo $html; |
|
| 160 | - } |
|
| 124 | + /** |
|
| 125 | + * Adds a refund related message section. |
|
| 126 | + * |
|
| 127 | + * @param bool $can_edit_payments Flag that tells if user can edit payments. |
|
| 128 | + * @access public |
|
| 129 | + * @return void |
|
| 130 | + */ |
|
| 131 | + public static function refundNotice(bool $can_edit_payments) |
|
| 132 | + { |
|
| 133 | + if (! $can_edit_payments) { |
|
| 134 | + return; |
|
| 135 | + } |
|
| 136 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 137 | + $txn_id = $request->getRequestParam('TXN_ID', 0, DataType::INT); |
|
| 138 | + try { |
|
| 139 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($txn_id); |
|
| 140 | + if (! $transaction instanceof EE_Transaction) { |
|
| 141 | + return; |
|
| 142 | + } |
|
| 143 | + // Was this transaction paid using PayPal ? |
|
| 144 | + if (strpos((string) $transaction->payment_method(), 'PayPal Commerce') === false) { |
|
| 145 | + return; |
|
| 146 | + } |
|
| 147 | + // Try loading the template. |
|
| 148 | + EE_Registry::instance()->load_helper('Template'); |
|
| 149 | + } catch (EE_Error|ReflectionException $e) { |
|
| 150 | + // Just return, adding nothing. |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + $html = EEH_Template::locate_template( |
|
| 154 | + apply_filters( |
|
| 155 | + 'FHEEA__EE_PMT_PayPalCheckout__refundNotice', |
|
| 156 | + dirname(__FILE__) . DS . 'templates' . DS . 'apply-refund-notice.template.php' |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + echo $html; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * Override the parent. |
|
| 165 | - * |
|
| 166 | - * @param EE_Transaction $transaction |
|
| 167 | - * @param float|null $amount |
|
| 168 | - * @param EE_Billing_Info_Form|null $billing_info |
|
| 169 | - * @param string|null $return_url |
|
| 170 | - * @param string $fail_url |
|
| 171 | - * @param string $method |
|
| 172 | - * @param bool $by_admin |
|
| 173 | - * @return EE_Payment |
|
| 174 | - * @throws EE_Error |
|
| 175 | - * @throws ReflectionException |
|
| 176 | - */ |
|
| 177 | - public function process_payment( |
|
| 178 | - EE_Transaction $transaction, |
|
| 179 | - $amount = null, |
|
| 180 | - $billing_info = null, |
|
| 181 | - $return_url = null, |
|
| 182 | - $fail_url = '', |
|
| 183 | - $method = 'CART', |
|
| 184 | - $by_admin = false |
|
| 185 | - ): EE_Payment { |
|
| 186 | - // This payment should have been processed in the background, while the Order was created and charged. |
|
| 187 | - // So simply return the last payment. Unless it's somehow missing. |
|
| 188 | - $payment = $transaction->last_payment(); |
|
| 189 | - if (empty($payment) || $payment->status() === EEM_Payment::status_id_failed) { |
|
| 190 | - // Then we try processing the payment as usual. |
|
| 191 | - return parent::process_payment( |
|
| 192 | - $transaction, |
|
| 193 | - $amount, |
|
| 194 | - $billing_info, |
|
| 195 | - $return_url, |
|
| 196 | - $fail_url, |
|
| 197 | - $method, |
|
| 198 | - $by_admin |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - return $transaction->last_payment(); |
|
| 202 | - } |
|
| 163 | + /** |
|
| 164 | + * Override the parent. |
|
| 165 | + * |
|
| 166 | + * @param EE_Transaction $transaction |
|
| 167 | + * @param float|null $amount |
|
| 168 | + * @param EE_Billing_Info_Form|null $billing_info |
|
| 169 | + * @param string|null $return_url |
|
| 170 | + * @param string $fail_url |
|
| 171 | + * @param string $method |
|
| 172 | + * @param bool $by_admin |
|
| 173 | + * @return EE_Payment |
|
| 174 | + * @throws EE_Error |
|
| 175 | + * @throws ReflectionException |
|
| 176 | + */ |
|
| 177 | + public function process_payment( |
|
| 178 | + EE_Transaction $transaction, |
|
| 179 | + $amount = null, |
|
| 180 | + $billing_info = null, |
|
| 181 | + $return_url = null, |
|
| 182 | + $fail_url = '', |
|
| 183 | + $method = 'CART', |
|
| 184 | + $by_admin = false |
|
| 185 | + ): EE_Payment { |
|
| 186 | + // This payment should have been processed in the background, while the Order was created and charged. |
|
| 187 | + // So simply return the last payment. Unless it's somehow missing. |
|
| 188 | + $payment = $transaction->last_payment(); |
|
| 189 | + if (empty($payment) || $payment->status() === EEM_Payment::status_id_failed) { |
|
| 190 | + // Then we try processing the payment as usual. |
|
| 191 | + return parent::process_payment( |
|
| 192 | + $transaction, |
|
| 193 | + $amount, |
|
| 194 | + $billing_info, |
|
| 195 | + $return_url, |
|
| 196 | + $fail_url, |
|
| 197 | + $method, |
|
| 198 | + $by_admin |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + return $transaction->last_payment(); |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -39,536 +39,536 @@ |
||
| 39 | 39 | class BillingForm extends EE_Billing_Attendee_Info_Form |
| 40 | 40 | { |
| 41 | 41 | |
| 42 | - protected EE_Payment_Method $paypal_pmt; |
|
| 42 | + protected EE_Payment_Method $paypal_pmt; |
|
| 43 | 43 | |
| 44 | - protected ?EE_Transaction $transaction = null; |
|
| 44 | + protected ?EE_Transaction $transaction = null; |
|
| 45 | 45 | |
| 46 | - protected string $checkout_type; |
|
| 46 | + protected string $checkout_type; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Filepath to template files |
|
| 50 | - * |
|
| 51 | - * @var string $template_path |
|
| 52 | - */ |
|
| 53 | - protected string $template_path; |
|
| 48 | + /** |
|
| 49 | + * Filepath to template files |
|
| 50 | + * |
|
| 51 | + * @var string $template_path |
|
| 52 | + */ |
|
| 53 | + protected string $template_path; |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Class constructor. |
|
| 58 | - * |
|
| 59 | - * @param EE_Payment_Method $payment_method |
|
| 60 | - * @param array $options |
|
| 61 | - * @throws EE_Error |
|
| 62 | - * @throws ReflectionException |
|
| 63 | - */ |
|
| 64 | - public function __construct(EE_Payment_Method $payment_method, array $options) |
|
| 65 | - { |
|
| 66 | - $this->paypal_pmt = $payment_method; |
|
| 67 | - // Can't be too careful. |
|
| 68 | - $this->transaction = $options['transaction'] ?? null; |
|
| 69 | - $this->template_path = $options['template_path'] ?? ''; |
|
| 70 | - $this->checkout_type = $payment_method->get_extra_meta(Domain::META_KEY_CHECKOUT_TYPE, true, ''); |
|
| 71 | - $pm_slug = $payment_method->slug(); |
|
| 72 | - $parameters = array_replace_recursive( |
|
| 73 | - $options, |
|
| 74 | - [ |
|
| 75 | - 'name' => 'PayPalCommerceBillingForm', |
|
| 76 | - 'html_id' => 'pp-' . $pm_slug . '-billing-form', |
|
| 77 | - 'html_class' => 'pp_commerce_billing_form', |
|
| 78 | - 'subsections' => [ |
|
| 79 | - 'eea_paypal_commerce_token' => new EE_Hidden_Input( |
|
| 80 | - [ |
|
| 81 | - 'html_id' => 'eea-paypal-commerce-token', |
|
| 82 | - 'html_name' => 'EEA_paymentToken', |
|
| 83 | - 'default' => '', |
|
| 84 | - ] |
|
| 85 | - ), |
|
| 86 | - 'pp_order_nonce' => new EE_Hidden_Input( |
|
| 87 | - [ |
|
| 88 | - 'html_id' => 'eea-' . $pm_slug . '-order-nonce', |
|
| 89 | - 'html_name' => 'pp_order_nonce', |
|
| 90 | - 'default' => '', |
|
| 91 | - ] |
|
| 92 | - ), |
|
| 93 | - 'pp_order_id' => new EE_Hidden_Input( |
|
| 94 | - [ |
|
| 95 | - 'html_id' => 'eea-' . $pm_slug . '-order-id', |
|
| 96 | - 'html_name' => 'pp_order_id', |
|
| 97 | - 'default' => '', |
|
| 98 | - ] |
|
| 99 | - ), |
|
| 100 | - 'pp_order_status' => new EE_Hidden_Input( |
|
| 101 | - [ |
|
| 102 | - 'html_id' => 'eea-' . $pm_slug . '-order-status', |
|
| 103 | - 'html_name' => 'pp_order_status', |
|
| 104 | - 'default' => '', |
|
| 105 | - ] |
|
| 106 | - ), |
|
| 107 | - 'pp_order_amount' => new EE_Hidden_Input( |
|
| 108 | - [ |
|
| 109 | - 'html_id' => 'eea-' . $pm_slug . '-order-amount', |
|
| 110 | - 'html_name' => 'pp_order_amount', |
|
| 111 | - 'default' => '', |
|
| 112 | - ] |
|
| 113 | - ), |
|
| 114 | - ], |
|
| 115 | - ] |
|
| 116 | - ); |
|
| 117 | - // Add data tags to the PP script. |
|
| 118 | - add_filter('script_loader_tag', [$this, 'addDataTagsToScript'], 10, 2); |
|
| 119 | - parent::__construct($payment_method, $parameters); |
|
| 120 | - // Add and exclude other sections. |
|
| 121 | - $this->addPaymentSections(); |
|
| 122 | - // Additional actions and/or filters. |
|
| 123 | - $this->loadActionsAndFilters(); |
|
| 124 | - } |
|
| 56 | + /** |
|
| 57 | + * Class constructor. |
|
| 58 | + * |
|
| 59 | + * @param EE_Payment_Method $payment_method |
|
| 60 | + * @param array $options |
|
| 61 | + * @throws EE_Error |
|
| 62 | + * @throws ReflectionException |
|
| 63 | + */ |
|
| 64 | + public function __construct(EE_Payment_Method $payment_method, array $options) |
|
| 65 | + { |
|
| 66 | + $this->paypal_pmt = $payment_method; |
|
| 67 | + // Can't be too careful. |
|
| 68 | + $this->transaction = $options['transaction'] ?? null; |
|
| 69 | + $this->template_path = $options['template_path'] ?? ''; |
|
| 70 | + $this->checkout_type = $payment_method->get_extra_meta(Domain::META_KEY_CHECKOUT_TYPE, true, ''); |
|
| 71 | + $pm_slug = $payment_method->slug(); |
|
| 72 | + $parameters = array_replace_recursive( |
|
| 73 | + $options, |
|
| 74 | + [ |
|
| 75 | + 'name' => 'PayPalCommerceBillingForm', |
|
| 76 | + 'html_id' => 'pp-' . $pm_slug . '-billing-form', |
|
| 77 | + 'html_class' => 'pp_commerce_billing_form', |
|
| 78 | + 'subsections' => [ |
|
| 79 | + 'eea_paypal_commerce_token' => new EE_Hidden_Input( |
|
| 80 | + [ |
|
| 81 | + 'html_id' => 'eea-paypal-commerce-token', |
|
| 82 | + 'html_name' => 'EEA_paymentToken', |
|
| 83 | + 'default' => '', |
|
| 84 | + ] |
|
| 85 | + ), |
|
| 86 | + 'pp_order_nonce' => new EE_Hidden_Input( |
|
| 87 | + [ |
|
| 88 | + 'html_id' => 'eea-' . $pm_slug . '-order-nonce', |
|
| 89 | + 'html_name' => 'pp_order_nonce', |
|
| 90 | + 'default' => '', |
|
| 91 | + ] |
|
| 92 | + ), |
|
| 93 | + 'pp_order_id' => new EE_Hidden_Input( |
|
| 94 | + [ |
|
| 95 | + 'html_id' => 'eea-' . $pm_slug . '-order-id', |
|
| 96 | + 'html_name' => 'pp_order_id', |
|
| 97 | + 'default' => '', |
|
| 98 | + ] |
|
| 99 | + ), |
|
| 100 | + 'pp_order_status' => new EE_Hidden_Input( |
|
| 101 | + [ |
|
| 102 | + 'html_id' => 'eea-' . $pm_slug . '-order-status', |
|
| 103 | + 'html_name' => 'pp_order_status', |
|
| 104 | + 'default' => '', |
|
| 105 | + ] |
|
| 106 | + ), |
|
| 107 | + 'pp_order_amount' => new EE_Hidden_Input( |
|
| 108 | + [ |
|
| 109 | + 'html_id' => 'eea-' . $pm_slug . '-order-amount', |
|
| 110 | + 'html_name' => 'pp_order_amount', |
|
| 111 | + 'default' => '', |
|
| 112 | + ] |
|
| 113 | + ), |
|
| 114 | + ], |
|
| 115 | + ] |
|
| 116 | + ); |
|
| 117 | + // Add data tags to the PP script. |
|
| 118 | + add_filter('script_loader_tag', [$this, 'addDataTagsToScript'], 10, 2); |
|
| 119 | + parent::__construct($payment_method, $parameters); |
|
| 120 | + // Add and exclude other sections. |
|
| 121 | + $this->addPaymentSections(); |
|
| 122 | + // Additional actions and/or filters. |
|
| 123 | + $this->loadActionsAndFilters(); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Add PayPal payment sections. |
|
| 129 | - * |
|
| 130 | - * @return void |
|
| 131 | - * @throws EE_Error |
|
| 132 | - * @throws ReflectionException |
|
| 133 | - */ |
|
| 134 | - public function addPaymentSections(): void |
|
| 135 | - { |
|
| 136 | - // Exclude the default billing form fields. |
|
| 137 | - $this->exclude( |
|
| 138 | - [ |
|
| 139 | - 'first_name', |
|
| 140 | - 'last_name', |
|
| 141 | - 'email', |
|
| 142 | - ] |
|
| 143 | - ); |
|
| 144 | - // Add PayPal Hosted Fields. |
|
| 145 | - if ($this->checkout_type !== 'express_checkout') { |
|
| 146 | - $this->addAdvancedCardFields(); |
|
| 147 | - } |
|
| 148 | - // Add payment types separator, if both are enabled. |
|
| 149 | - if ($this->checkout_type === 'all') { |
|
| 150 | - $this->addTypesSeparator(); |
|
| 151 | - } |
|
| 152 | - // Add PayPal Buttons section. |
|
| 153 | - if ($this->checkout_type !== 'ppcp') { |
|
| 154 | - $this->add_subsections( |
|
| 155 | - [ |
|
| 156 | - 'paypal_commerce_pm_form' => $this->addPayPalCheckout(), |
|
| 157 | - ] |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - // Exclude the rest billing form fields if the payment type is express checkout. |
|
| 161 | - if ($this->checkout_type === 'express_checkout') { |
|
| 162 | - $this->exclude( |
|
| 163 | - [ |
|
| 164 | - 'address', |
|
| 165 | - 'address2', |
|
| 166 | - 'state', |
|
| 167 | - 'phone', |
|
| 168 | - 'city', |
|
| 169 | - 'country', |
|
| 170 | - 'zip', |
|
| 171 | - ] |
|
| 172 | - ); |
|
| 173 | - // Remove the Info subsection. |
|
| 174 | - add_filter('FHEE__EE_Form_Section_Proper___construct__options_array', [$this, 'excludeInfoSubsection']); |
|
| 175 | - } |
|
| 176 | - $this->add_subsections( |
|
| 177 | - [ |
|
| 178 | - 'debug_content' => $this->addDebugContent($this->paypal_pmt), |
|
| 179 | - ] |
|
| 180 | - ); |
|
| 181 | - } |
|
| 127 | + /** |
|
| 128 | + * Add PayPal payment sections. |
|
| 129 | + * |
|
| 130 | + * @return void |
|
| 131 | + * @throws EE_Error |
|
| 132 | + * @throws ReflectionException |
|
| 133 | + */ |
|
| 134 | + public function addPaymentSections(): void |
|
| 135 | + { |
|
| 136 | + // Exclude the default billing form fields. |
|
| 137 | + $this->exclude( |
|
| 138 | + [ |
|
| 139 | + 'first_name', |
|
| 140 | + 'last_name', |
|
| 141 | + 'email', |
|
| 142 | + ] |
|
| 143 | + ); |
|
| 144 | + // Add PayPal Hosted Fields. |
|
| 145 | + if ($this->checkout_type !== 'express_checkout') { |
|
| 146 | + $this->addAdvancedCardFields(); |
|
| 147 | + } |
|
| 148 | + // Add payment types separator, if both are enabled. |
|
| 149 | + if ($this->checkout_type === 'all') { |
|
| 150 | + $this->addTypesSeparator(); |
|
| 151 | + } |
|
| 152 | + // Add PayPal Buttons section. |
|
| 153 | + if ($this->checkout_type !== 'ppcp') { |
|
| 154 | + $this->add_subsections( |
|
| 155 | + [ |
|
| 156 | + 'paypal_commerce_pm_form' => $this->addPayPalCheckout(), |
|
| 157 | + ] |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + // Exclude the rest billing form fields if the payment type is express checkout. |
|
| 161 | + if ($this->checkout_type === 'express_checkout') { |
|
| 162 | + $this->exclude( |
|
| 163 | + [ |
|
| 164 | + 'address', |
|
| 165 | + 'address2', |
|
| 166 | + 'state', |
|
| 167 | + 'phone', |
|
| 168 | + 'city', |
|
| 169 | + 'country', |
|
| 170 | + 'zip', |
|
| 171 | + ] |
|
| 172 | + ); |
|
| 173 | + // Remove the Info subsection. |
|
| 174 | + add_filter('FHEE__EE_Form_Section_Proper___construct__options_array', [$this, 'excludeInfoSubsection']); |
|
| 175 | + } |
|
| 176 | + $this->add_subsections( |
|
| 177 | + [ |
|
| 178 | + 'debug_content' => $this->addDebugContent($this->paypal_pmt), |
|
| 179 | + ] |
|
| 180 | + ); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * Additional actions and/or filters. |
|
| 186 | - * |
|
| 187 | - * @return void |
|
| 188 | - */ |
|
| 189 | - public function loadActionsAndFilters(): void |
|
| 190 | - { |
|
| 191 | - add_filter( |
|
| 192 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 193 | - [__CLASS__, 'excludeBillingFormFields'], |
|
| 194 | - 10, |
|
| 195 | - 2 |
|
| 196 | - ); |
|
| 197 | - } |
|
| 184 | + /** |
|
| 185 | + * Additional actions and/or filters. |
|
| 186 | + * |
|
| 187 | + * @return void |
|
| 188 | + */ |
|
| 189 | + public function loadActionsAndFilters(): void |
|
| 190 | + { |
|
| 191 | + add_filter( |
|
| 192 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 193 | + [__CLASS__, 'excludeBillingFormFields'], |
|
| 194 | + 10, |
|
| 195 | + 2 |
|
| 196 | + ); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * Filter out billing form fields if pay button was used. |
|
| 202 | - * |
|
| 203 | - * @param EE_Billing_Info_Form $billing_form |
|
| 204 | - * @param EE_Payment_Method $payment_method |
|
| 205 | - * @return EE_Billing_Info_Form |
|
| 206 | - */ |
|
| 207 | - public static function excludeBillingFormFields( |
|
| 208 | - EE_Billing_Info_Form $billing_form, |
|
| 209 | - EE_Payment_Method $payment_method |
|
| 210 | - ): EE_Billing_Info_Form { |
|
| 211 | - $request = LoaderFactory::getShared(Request::class); |
|
| 212 | - $request_params = $request->requestParams(); |
|
| 213 | - // Only the PPC billing form. |
|
| 214 | - if (! $billing_form instanceof BillingForm) { |
|
| 215 | - return $billing_form; |
|
| 216 | - } |
|
| 217 | - // Make sure the billing form subsections have correct names. |
|
| 218 | - $inputs = $billing_form->inputs_in_subsections(); |
|
| 219 | - if (! empty($request_params['process_form_submission']) |
|
| 220 | - && $request_params['process_form_submission'] === '1' |
|
| 221 | - && ! empty($request_params['eep_ppc_skip_form_validation']) |
|
| 222 | - ) { |
|
| 223 | - // Hide card info fields. |
|
| 224 | - $billing_form->exclude( |
|
| 225 | - [ |
|
| 226 | - 'pp_name_on_card', |
|
| 227 | - 'address', |
|
| 228 | - 'address2', |
|
| 229 | - 'state', |
|
| 230 | - 'phone', |
|
| 231 | - 'city', |
|
| 232 | - 'country', |
|
| 233 | - 'zip', |
|
| 234 | - ] |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - return $billing_form; |
|
| 238 | - } |
|
| 200 | + /** |
|
| 201 | + * Filter out billing form fields if pay button was used. |
|
| 202 | + * |
|
| 203 | + * @param EE_Billing_Info_Form $billing_form |
|
| 204 | + * @param EE_Payment_Method $payment_method |
|
| 205 | + * @return EE_Billing_Info_Form |
|
| 206 | + */ |
|
| 207 | + public static function excludeBillingFormFields( |
|
| 208 | + EE_Billing_Info_Form $billing_form, |
|
| 209 | + EE_Payment_Method $payment_method |
|
| 210 | + ): EE_Billing_Info_Form { |
|
| 211 | + $request = LoaderFactory::getShared(Request::class); |
|
| 212 | + $request_params = $request->requestParams(); |
|
| 213 | + // Only the PPC billing form. |
|
| 214 | + if (! $billing_form instanceof BillingForm) { |
|
| 215 | + return $billing_form; |
|
| 216 | + } |
|
| 217 | + // Make sure the billing form subsections have correct names. |
|
| 218 | + $inputs = $billing_form->inputs_in_subsections(); |
|
| 219 | + if (! empty($request_params['process_form_submission']) |
|
| 220 | + && $request_params['process_form_submission'] === '1' |
|
| 221 | + && ! empty($request_params['eep_ppc_skip_form_validation']) |
|
| 222 | + ) { |
|
| 223 | + // Hide card info fields. |
|
| 224 | + $billing_form->exclude( |
|
| 225 | + [ |
|
| 226 | + 'pp_name_on_card', |
|
| 227 | + 'address', |
|
| 228 | + 'address2', |
|
| 229 | + 'state', |
|
| 230 | + 'phone', |
|
| 231 | + 'city', |
|
| 232 | + 'country', |
|
| 233 | + 'zip', |
|
| 234 | + ] |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + return $billing_form; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Add advanced card & debit card fields. |
|
| 243 | - * |
|
| 244 | - * @return void |
|
| 245 | - * @throws EE_Error|ReflectionException |
|
| 246 | - */ |
|
| 247 | - public function addAdvancedCardFields(): void |
|
| 248 | - { |
|
| 249 | - $pm_slug = $this->paypal_pmt->slug(); |
|
| 250 | - $this->add_subsections( |
|
| 251 | - [ |
|
| 252 | - 'pp_card_number' => new EE_Form_Section_HTML( |
|
| 253 | - EEH_HTML::label( |
|
| 254 | - esc_html__('Card Number', 'event_espresso'), |
|
| 255 | - "$pm_slug-card-number-lbl", |
|
| 256 | - "$pm_slug-card-fields", |
|
| 257 | - "", |
|
| 258 | - 'for="' . $pm_slug . '-card-number"' |
|
| 259 | - ) . |
|
| 260 | - EEH_HTML::p( |
|
| 261 | - "", |
|
| 262 | - "$pm_slug-card-number", |
|
| 263 | - "card_field $pm_slug-card-fields" |
|
| 264 | - ) |
|
| 265 | - ), |
|
| 266 | - 'pp_expiration_date' => new EE_Form_Section_HTML( |
|
| 267 | - EEH_HTML::label( |
|
| 268 | - esc_html__('Expiration Date', 'event_espresso'), |
|
| 269 | - "$pm_slug-expiration-date-lbl", |
|
| 270 | - "$pm_slug-card-fields", |
|
| 271 | - "", |
|
| 272 | - 'for="' . $pm_slug . '-expiration-date"' |
|
| 273 | - ) . |
|
| 274 | - EEH_HTML::p( |
|
| 275 | - "", |
|
| 276 | - "$pm_slug-expiration-date", |
|
| 277 | - "card_field $pm_slug-card-fields" |
|
| 278 | - ) |
|
| 279 | - ), |
|
| 280 | - 'pp_card_cvv' => new EE_Form_Section_HTML( |
|
| 281 | - EEH_HTML::label( |
|
| 282 | - esc_html__('CVV', 'event_espresso'), |
|
| 283 | - "$pm_slug-cvv-lbl", |
|
| 284 | - "$pm_slug-card-fields", |
|
| 285 | - "", |
|
| 286 | - 'for="' . $pm_slug . '-cvv"' |
|
| 287 | - ) . |
|
| 288 | - EEH_HTML::p( |
|
| 289 | - "", |
|
| 290 | - "$pm_slug-cvv", |
|
| 291 | - "card_field $pm_slug-card-fields" |
|
| 292 | - ) |
|
| 293 | - ), |
|
| 294 | - 'pp_name_on_card' => new EE_Text_Input( |
|
| 295 | - [ |
|
| 296 | - 'html_label_text' => esc_html__('Name On Card', 'event_espresso'), |
|
| 297 | - 'html_id' => $pm_slug . '-card-holder-name', |
|
| 298 | - 'html_name' => 'card-holder-name', |
|
| 299 | - 'html_class' => '', |
|
| 300 | - 'required' => true, |
|
| 301 | - ] |
|
| 302 | - ), |
|
| 303 | - ] |
|
| 304 | - ); |
|
| 305 | - // Add the submit button at the end. |
|
| 306 | - $this->add_subsections( |
|
| 307 | - [ |
|
| 308 | - 'pp_cc_submit' => new EE_Submit_Input( |
|
| 309 | - [ |
|
| 310 | - 'html_label_text' => esc_html__('Submit', 'event_espresso'), |
|
| 311 | - 'html_id' => $pm_slug, |
|
| 312 | - 'html_class' => 'eep-ppc-btn', |
|
| 313 | - ] |
|
| 314 | - ), |
|
| 315 | - ], |
|
| 316 | - 'phone', |
|
| 317 | - false |
|
| 318 | - ); |
|
| 319 | - } |
|
| 241 | + /** |
|
| 242 | + * Add advanced card & debit card fields. |
|
| 243 | + * |
|
| 244 | + * @return void |
|
| 245 | + * @throws EE_Error|ReflectionException |
|
| 246 | + */ |
|
| 247 | + public function addAdvancedCardFields(): void |
|
| 248 | + { |
|
| 249 | + $pm_slug = $this->paypal_pmt->slug(); |
|
| 250 | + $this->add_subsections( |
|
| 251 | + [ |
|
| 252 | + 'pp_card_number' => new EE_Form_Section_HTML( |
|
| 253 | + EEH_HTML::label( |
|
| 254 | + esc_html__('Card Number', 'event_espresso'), |
|
| 255 | + "$pm_slug-card-number-lbl", |
|
| 256 | + "$pm_slug-card-fields", |
|
| 257 | + "", |
|
| 258 | + 'for="' . $pm_slug . '-card-number"' |
|
| 259 | + ) . |
|
| 260 | + EEH_HTML::p( |
|
| 261 | + "", |
|
| 262 | + "$pm_slug-card-number", |
|
| 263 | + "card_field $pm_slug-card-fields" |
|
| 264 | + ) |
|
| 265 | + ), |
|
| 266 | + 'pp_expiration_date' => new EE_Form_Section_HTML( |
|
| 267 | + EEH_HTML::label( |
|
| 268 | + esc_html__('Expiration Date', 'event_espresso'), |
|
| 269 | + "$pm_slug-expiration-date-lbl", |
|
| 270 | + "$pm_slug-card-fields", |
|
| 271 | + "", |
|
| 272 | + 'for="' . $pm_slug . '-expiration-date"' |
|
| 273 | + ) . |
|
| 274 | + EEH_HTML::p( |
|
| 275 | + "", |
|
| 276 | + "$pm_slug-expiration-date", |
|
| 277 | + "card_field $pm_slug-card-fields" |
|
| 278 | + ) |
|
| 279 | + ), |
|
| 280 | + 'pp_card_cvv' => new EE_Form_Section_HTML( |
|
| 281 | + EEH_HTML::label( |
|
| 282 | + esc_html__('CVV', 'event_espresso'), |
|
| 283 | + "$pm_slug-cvv-lbl", |
|
| 284 | + "$pm_slug-card-fields", |
|
| 285 | + "", |
|
| 286 | + 'for="' . $pm_slug . '-cvv"' |
|
| 287 | + ) . |
|
| 288 | + EEH_HTML::p( |
|
| 289 | + "", |
|
| 290 | + "$pm_slug-cvv", |
|
| 291 | + "card_field $pm_slug-card-fields" |
|
| 292 | + ) |
|
| 293 | + ), |
|
| 294 | + 'pp_name_on_card' => new EE_Text_Input( |
|
| 295 | + [ |
|
| 296 | + 'html_label_text' => esc_html__('Name On Card', 'event_espresso'), |
|
| 297 | + 'html_id' => $pm_slug . '-card-holder-name', |
|
| 298 | + 'html_name' => 'card-holder-name', |
|
| 299 | + 'html_class' => '', |
|
| 300 | + 'required' => true, |
|
| 301 | + ] |
|
| 302 | + ), |
|
| 303 | + ] |
|
| 304 | + ); |
|
| 305 | + // Add the submit button at the end. |
|
| 306 | + $this->add_subsections( |
|
| 307 | + [ |
|
| 308 | + 'pp_cc_submit' => new EE_Submit_Input( |
|
| 309 | + [ |
|
| 310 | + 'html_label_text' => esc_html__('Submit', 'event_espresso'), |
|
| 311 | + 'html_id' => $pm_slug, |
|
| 312 | + 'html_class' => 'eep-ppc-btn', |
|
| 313 | + ] |
|
| 314 | + ), |
|
| 315 | + ], |
|
| 316 | + 'phone', |
|
| 317 | + false |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * Add advanced card & debit card fields. |
|
| 324 | - * |
|
| 325 | - * @return void |
|
| 326 | - * @throws EE_Error|ReflectionException |
|
| 327 | - */ |
|
| 328 | - public function addTypesSeparator(): void |
|
| 329 | - { |
|
| 330 | - $this->add_subsections( |
|
| 331 | - [ |
|
| 332 | - 'pp_payment_types_separator' => new EE_Form_Section_HTML( |
|
| 333 | - EEH_HTML::div( |
|
| 334 | - EEH_HTML::div( |
|
| 335 | - ' ', |
|
| 336 | - 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
| 337 | - 'eep-ppc-separator-line eep-left-floating' |
|
| 338 | - ) . |
|
| 339 | - EEH_HTML::div( |
|
| 340 | - esc_html__(' or ', 'event_espresso'), |
|
| 341 | - 'eep-' . $this->paypal_pmt->slug() . '-separator-text', |
|
| 342 | - 'eep-ppc-separator-text1 eep-mid-floating' |
|
| 343 | - ) . EEH_HTML::div( |
|
| 344 | - ' ', |
|
| 345 | - 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
| 346 | - 'eep-ppc-separator-line eep-right-floating' |
|
| 347 | - ), |
|
| 348 | - 'eep-ppc-separator-holder', |
|
| 349 | - 'eep-ppc-separator-holder' |
|
| 350 | - ) |
|
| 351 | - ), |
|
| 352 | - ] |
|
| 353 | - ); |
|
| 354 | - } |
|
| 322 | + /** |
|
| 323 | + * Add advanced card & debit card fields. |
|
| 324 | + * |
|
| 325 | + * @return void |
|
| 326 | + * @throws EE_Error|ReflectionException |
|
| 327 | + */ |
|
| 328 | + public function addTypesSeparator(): void |
|
| 329 | + { |
|
| 330 | + $this->add_subsections( |
|
| 331 | + [ |
|
| 332 | + 'pp_payment_types_separator' => new EE_Form_Section_HTML( |
|
| 333 | + EEH_HTML::div( |
|
| 334 | + EEH_HTML::div( |
|
| 335 | + ' ', |
|
| 336 | + 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
| 337 | + 'eep-ppc-separator-line eep-left-floating' |
|
| 338 | + ) . |
|
| 339 | + EEH_HTML::div( |
|
| 340 | + esc_html__(' or ', 'event_espresso'), |
|
| 341 | + 'eep-' . $this->paypal_pmt->slug() . '-separator-text', |
|
| 342 | + 'eep-ppc-separator-text1 eep-mid-floating' |
|
| 343 | + ) . EEH_HTML::div( |
|
| 344 | + ' ', |
|
| 345 | + 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
| 346 | + 'eep-ppc-separator-line eep-right-floating' |
|
| 347 | + ), |
|
| 348 | + 'eep-ppc-separator-holder', |
|
| 349 | + 'eep-ppc-separator-holder' |
|
| 350 | + ) |
|
| 351 | + ), |
|
| 352 | + ] |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * Exclude the info subsection from the PPC checkout form. |
|
| 359 | - * |
|
| 360 | - * @param array $options_array |
|
| 361 | - * @return array |
|
| 362 | - * @throws EE_Error |
|
| 363 | - * @throws ReflectionException |
|
| 364 | - */ |
|
| 365 | - public function excludeInfoSubsection(array $options_array): array |
|
| 366 | - { |
|
| 367 | - if ( |
|
| 368 | - ! empty($options_array['html_id']) |
|
| 369 | - && $options_array['html_id'] === 'spco-payment-method-info-' . $this->paypal_pmt->slug() |
|
| 370 | - ) { |
|
| 371 | - if (! empty($options_array['subsections']) && isset($options_array['subsections']['info'])) { |
|
| 372 | - unset($options_array['subsections']['info']); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - return $options_array; |
|
| 376 | - } |
|
| 357 | + /** |
|
| 358 | + * Exclude the info subsection from the PPC checkout form. |
|
| 359 | + * |
|
| 360 | + * @param array $options_array |
|
| 361 | + * @return array |
|
| 362 | + * @throws EE_Error |
|
| 363 | + * @throws ReflectionException |
|
| 364 | + */ |
|
| 365 | + public function excludeInfoSubsection(array $options_array): array |
|
| 366 | + { |
|
| 367 | + if ( |
|
| 368 | + ! empty($options_array['html_id']) |
|
| 369 | + && $options_array['html_id'] === 'spco-payment-method-info-' . $this->paypal_pmt->slug() |
|
| 370 | + ) { |
|
| 371 | + if (! empty($options_array['subsections']) && isset($options_array['subsections']['info'])) { |
|
| 372 | + unset($options_array['subsections']['info']); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + return $options_array; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Possibly adds debug content to PayPal commerce billing form. |
|
| 381 | - * |
|
| 382 | - * @param EE_Payment_Method $paypal_pm |
|
| 383 | - * @return EE_Form_Section_Base |
|
| 384 | - * @throws EE_Error|ReflectionException |
|
| 385 | - */ |
|
| 386 | - public function addDebugContent(EE_Payment_Method $paypal_pm): EE_Form_Section_Base |
|
| 387 | - { |
|
| 388 | - if ($paypal_pm->debug_mode()) { |
|
| 389 | - return new EE_Form_Section_Proper( |
|
| 390 | - [ |
|
| 391 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 392 | - [ |
|
| 393 | - 'layout_template_file' => $this->template_path . 'debugInfo.template.php', |
|
| 394 | - 'template_args' => [], |
|
| 395 | - ] |
|
| 396 | - ), |
|
| 397 | - ] |
|
| 398 | - ); |
|
| 399 | - } |
|
| 400 | - return new EE_Form_Section_HTML(); |
|
| 401 | - } |
|
| 379 | + /** |
|
| 380 | + * Possibly adds debug content to PayPal commerce billing form. |
|
| 381 | + * |
|
| 382 | + * @param EE_Payment_Method $paypal_pm |
|
| 383 | + * @return EE_Form_Section_Base |
|
| 384 | + * @throws EE_Error|ReflectionException |
|
| 385 | + */ |
|
| 386 | + public function addDebugContent(EE_Payment_Method $paypal_pm): EE_Form_Section_Base |
|
| 387 | + { |
|
| 388 | + if ($paypal_pm->debug_mode()) { |
|
| 389 | + return new EE_Form_Section_Proper( |
|
| 390 | + [ |
|
| 391 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 392 | + [ |
|
| 393 | + 'layout_template_file' => $this->template_path . 'debugInfo.template.php', |
|
| 394 | + 'template_args' => [], |
|
| 395 | + ] |
|
| 396 | + ), |
|
| 397 | + ] |
|
| 398 | + ); |
|
| 399 | + } |
|
| 400 | + return new EE_Form_Section_HTML(); |
|
| 401 | + } |
|
| 402 | 402 | |
| 403 | 403 | |
| 404 | - /** |
|
| 405 | - * Add PayPal checkout buttons. |
|
| 406 | - * |
|
| 407 | - * @return EE_Form_Section_Proper |
|
| 408 | - * @throws EE_Error |
|
| 409 | - * @throws ReflectionException |
|
| 410 | - * @throws Exception |
|
| 411 | - */ |
|
| 412 | - public function addPayPalCheckout(): EE_Form_Section_Proper |
|
| 413 | - { |
|
| 414 | - $template_args['pm_slug'] = $this->paypal_pmt->slug(); |
|
| 415 | - return new EE_Form_Section_Proper( |
|
| 416 | - [ |
|
| 417 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 418 | - [ |
|
| 419 | - 'layout_template_file' => $this->template_path . 'paymentButtons.template.php', |
|
| 420 | - 'template_args' => $template_args, |
|
| 421 | - ] |
|
| 422 | - ), |
|
| 423 | - ] |
|
| 424 | - ); |
|
| 425 | - } |
|
| 404 | + /** |
|
| 405 | + * Add PayPal checkout buttons. |
|
| 406 | + * |
|
| 407 | + * @return EE_Form_Section_Proper |
|
| 408 | + * @throws EE_Error |
|
| 409 | + * @throws ReflectionException |
|
| 410 | + * @throws Exception |
|
| 411 | + */ |
|
| 412 | + public function addPayPalCheckout(): EE_Form_Section_Proper |
|
| 413 | + { |
|
| 414 | + $template_args['pm_slug'] = $this->paypal_pmt->slug(); |
|
| 415 | + return new EE_Form_Section_Proper( |
|
| 416 | + [ |
|
| 417 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 418 | + [ |
|
| 419 | + 'layout_template_file' => $this->template_path . 'paymentButtons.template.php', |
|
| 420 | + 'template_args' => $template_args, |
|
| 421 | + ] |
|
| 422 | + ), |
|
| 423 | + ] |
|
| 424 | + ); |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | 427 | |
| 428 | - /** |
|
| 429 | - * Load scripts and localize data needed for this form. |
|
| 430 | - * |
|
| 431 | - * @param $tag |
|
| 432 | - * @param $handle |
|
| 433 | - * @return string |
|
| 434 | - * @throws EE_Error |
|
| 435 | - * @throws ReflectionException |
|
| 436 | - */ |
|
| 437 | - public function addDataTagsToScript($tag, $handle): string |
|
| 438 | - { |
|
| 439 | - if ($handle === 'eea_paypal_commerce_js_lib') { |
|
| 440 | - $bn_code = PayPalExtraMetaManager::getPmOption($this->_pm_instance, Domain::META_KEY_BN_CODE); |
|
| 441 | - $response = EED_PayPalCommerce::requestClientToken($this->paypal_pmt); |
|
| 442 | - if (empty($response['client_token'])) { |
|
| 443 | - return $tag; |
|
| 444 | - } |
|
| 445 | - $client_token = $response['client_token']; |
|
| 446 | - $attributes = " data-partner-attribution-id=\"$bn_code\" data-client-token=\"$client_token\""; |
|
| 447 | - $tag = str_replace('></script>', $attributes . '></script>', $tag); |
|
| 448 | - } |
|
| 449 | - return $tag; |
|
| 450 | - } |
|
| 428 | + /** |
|
| 429 | + * Load scripts and localize data needed for this form. |
|
| 430 | + * |
|
| 431 | + * @param $tag |
|
| 432 | + * @param $handle |
|
| 433 | + * @return string |
|
| 434 | + * @throws EE_Error |
|
| 435 | + * @throws ReflectionException |
|
| 436 | + */ |
|
| 437 | + public function addDataTagsToScript($tag, $handle): string |
|
| 438 | + { |
|
| 439 | + if ($handle === 'eea_paypal_commerce_js_lib') { |
|
| 440 | + $bn_code = PayPalExtraMetaManager::getPmOption($this->_pm_instance, Domain::META_KEY_BN_CODE); |
|
| 441 | + $response = EED_PayPalCommerce::requestClientToken($this->paypal_pmt); |
|
| 442 | + if (empty($response['client_token'])) { |
|
| 443 | + return $tag; |
|
| 444 | + } |
|
| 445 | + $client_token = $response['client_token']; |
|
| 446 | + $attributes = " data-partner-attribution-id=\"$bn_code\" data-client-token=\"$client_token\""; |
|
| 447 | + $tag = str_replace('></script>', $attributes . '></script>', $tag); |
|
| 448 | + } |
|
| 449 | + return $tag; |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | 452 | |
| 453 | - /** |
|
| 454 | - * Load scripts and localize data needed for this form. |
|
| 455 | - * |
|
| 456 | - * @return void |
|
| 457 | - * @throws EE_Error |
|
| 458 | - * @throws ReflectionException |
|
| 459 | - * @throws Exception |
|
| 460 | - */ |
|
| 461 | - public function enqueue_js(): void |
|
| 462 | - { |
|
| 463 | - $third_party = EED_PayPalCommerce::isThirdParty($this->_pm_instance); |
|
| 464 | - $currency = CurrencyManager::currencyCode(); |
|
| 465 | - $client_id_key = Domain::META_KEY_CLIENT_ID; |
|
| 466 | - // Scripts. |
|
| 467 | - $scripts_src = 'https://www.paypal.com/sdk/js?components=buttons,hosted-fields&intent=capture'; |
|
| 468 | - if ($third_party) { |
|
| 469 | - $client_id_key = Domain::META_KEY_PARTNER_CLIENT_ID; |
|
| 470 | - $merchant_id = PayPalExtraMetaManager::getPmOption( |
|
| 471 | - $this->_pm_instance, |
|
| 472 | - Domain::META_KEY_SELLER_MERCHANT_ID |
|
| 473 | - ); |
|
| 474 | - $scripts_src .= "&merchant-id=$merchant_id"; |
|
| 475 | - } |
|
| 476 | - $client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key); |
|
| 477 | - $scripts_src .= "&client-id=$client_id¤cy=$currency"; |
|
| 478 | - wp_enqueue_script('eea_paypal_commerce_js_lib', $scripts_src, [], null); |
|
| 479 | - wp_enqueue_script( |
|
| 480 | - 'eea_paypal_commerce_js', |
|
| 481 | - EEP_PAYPAL_COMMERCE_URL . 'assets/js/paypal-commerce-payments.js', |
|
| 482 | - ['eea_paypal_commerce_js_lib'], |
|
| 483 | - EVENT_ESPRESSO_VERSION, |
|
| 484 | - true |
|
| 485 | - ); |
|
| 486 | - // Styles. |
|
| 487 | - wp_enqueue_style( |
|
| 488 | - 'eea_paypal_checkout_form_styles', |
|
| 489 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-checkout.css', |
|
| 490 | - [], |
|
| 491 | - EVENT_ESPRESSO_VERSION |
|
| 492 | - ); |
|
| 493 | - // Localize the script with our transaction data. |
|
| 494 | - $parameters = $this->localizeParameters(); |
|
| 495 | - wp_localize_script('eea_paypal_commerce_js', 'eeaPPCommerceParameters', $parameters); |
|
| 496 | - parent::enqueue_js(); |
|
| 497 | - } |
|
| 453 | + /** |
|
| 454 | + * Load scripts and localize data needed for this form. |
|
| 455 | + * |
|
| 456 | + * @return void |
|
| 457 | + * @throws EE_Error |
|
| 458 | + * @throws ReflectionException |
|
| 459 | + * @throws Exception |
|
| 460 | + */ |
|
| 461 | + public function enqueue_js(): void |
|
| 462 | + { |
|
| 463 | + $third_party = EED_PayPalCommerce::isThirdParty($this->_pm_instance); |
|
| 464 | + $currency = CurrencyManager::currencyCode(); |
|
| 465 | + $client_id_key = Domain::META_KEY_CLIENT_ID; |
|
| 466 | + // Scripts. |
|
| 467 | + $scripts_src = 'https://www.paypal.com/sdk/js?components=buttons,hosted-fields&intent=capture'; |
|
| 468 | + if ($third_party) { |
|
| 469 | + $client_id_key = Domain::META_KEY_PARTNER_CLIENT_ID; |
|
| 470 | + $merchant_id = PayPalExtraMetaManager::getPmOption( |
|
| 471 | + $this->_pm_instance, |
|
| 472 | + Domain::META_KEY_SELLER_MERCHANT_ID |
|
| 473 | + ); |
|
| 474 | + $scripts_src .= "&merchant-id=$merchant_id"; |
|
| 475 | + } |
|
| 476 | + $client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key); |
|
| 477 | + $scripts_src .= "&client-id=$client_id¤cy=$currency"; |
|
| 478 | + wp_enqueue_script('eea_paypal_commerce_js_lib', $scripts_src, [], null); |
|
| 479 | + wp_enqueue_script( |
|
| 480 | + 'eea_paypal_commerce_js', |
|
| 481 | + EEP_PAYPAL_COMMERCE_URL . 'assets/js/paypal-commerce-payments.js', |
|
| 482 | + ['eea_paypal_commerce_js_lib'], |
|
| 483 | + EVENT_ESPRESSO_VERSION, |
|
| 484 | + true |
|
| 485 | + ); |
|
| 486 | + // Styles. |
|
| 487 | + wp_enqueue_style( |
|
| 488 | + 'eea_paypal_checkout_form_styles', |
|
| 489 | + EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-checkout.css', |
|
| 490 | + [], |
|
| 491 | + EVENT_ESPRESSO_VERSION |
|
| 492 | + ); |
|
| 493 | + // Localize the script with our transaction data. |
|
| 494 | + $parameters = $this->localizeParameters(); |
|
| 495 | + wp_localize_script('eea_paypal_commerce_js', 'eeaPPCommerceParameters', $parameters); |
|
| 496 | + parent::enqueue_js(); |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | 499 | |
| 500 | - /** |
|
| 501 | - * Form and return PayPal commerce parameters for script localization. |
|
| 502 | - * |
|
| 503 | - * @return array |
|
| 504 | - * @throws EE_Error |
|
| 505 | - * @throws ReflectionException |
|
| 506 | - * @throws Exception |
|
| 507 | - */ |
|
| 508 | - public function localizeParameters(): array |
|
| 509 | - { |
|
| 510 | - // Also tell the script about each instance of this PM. |
|
| 511 | - $pm_versions = []; |
|
| 512 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active( |
|
| 513 | - EEM_Payment_Method::scope_cart, |
|
| 514 | - [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
|
| 515 | - ); |
|
| 516 | - foreach ($active_payment_methods as $payment_method) { |
|
| 517 | - $pm_versions[ $payment_method->slug() ] = [ |
|
| 518 | - 'pm_slug' => $payment_method->slug(), |
|
| 519 | - ]; |
|
| 520 | - } |
|
| 521 | - // Convert money for a display format. |
|
| 522 | - $decimal_places = CurrencyManager::getDecimalPlaces(); |
|
| 523 | - $org_country = isset(EE_Registry::instance()->CFG->organization) |
|
| 524 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 525 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 526 | - : 'US'; |
|
| 527 | - $transaction_id = $this->transaction instanceof EE_Transaction ? $this->transaction->ID() : 0; |
|
| 528 | - $currency_code = CurrencyManager::currencyCode(); |
|
| 529 | - return [ |
|
| 530 | - 'pm_versions' => $pm_versions, |
|
| 531 | - 'payment_currency' => $currency_code, |
|
| 532 | - 'checkout_type' => $this->checkout_type, |
|
| 533 | - 'currency_sign' => EE_Registry::instance()->CFG->currency->sign, |
|
| 534 | - 'pp_order_nonce' => wp_create_nonce(Domain::CAPTURE_ORDER_NONCE_NAME), |
|
| 535 | - // The transaction ID is only used for logging errors. |
|
| 536 | - 'txn_id' => $transaction_id, |
|
| 537 | - 'org_country' => $org_country, |
|
| 538 | - 'decimal_places' => $decimal_places, |
|
| 539 | - 'site_name' => get_bloginfo('name'), |
|
| 540 | - 'active_states' => EED_PayPalCommerce::getActiveStates(), |
|
| 541 | - 'no_spco_error' => esc_html__( |
|
| 542 | - 'It appears the SDK script was not loaded properly! Please refresh the page and try again or contact support.', |
|
| 543 | - 'event_espresso' |
|
| 544 | - ), |
|
| 545 | - 'no_pm_error' => esc_html__( |
|
| 546 | - 'It appears that PayPal Commerce checkout JavaScript was not loaded properly! Please refresh the page and try again or contact support. PayPal Commerce payments can\'t be processed.', |
|
| 547 | - 'event_espresso' |
|
| 548 | - ), |
|
| 549 | - 'browser_not_supported' => esc_html__( |
|
| 550 | - 'It appears that this browser is not supported by PayPal scripts. We apologize, but PayPal payments won\'t work in this browser version.', |
|
| 551 | - 'event_espresso' |
|
| 552 | - ), |
|
| 553 | - 'get_token_error' => esc_html__( |
|
| 554 | - 'There was an error while trying to get the payment token. Please refresh the page and try again or contact support.', |
|
| 555 | - 'event_espresso' |
|
| 556 | - ), |
|
| 557 | - 'form_validation_notice' => esc_html__('Billing form information not valid.', 'event_espresso'), |
|
| 558 | - 'no_verification_token' => esc_html__('Missing the Verification token.', 'event_espresso'), |
|
| 559 | - 'error_response' => esc_html__('Error response received', 'event_espresso'), |
|
| 560 | - 'payment_error' => esc_html__( |
|
| 561 | - 'There was an error with this payment. See the logs for details.', |
|
| 562 | - 'event_espresso' |
|
| 563 | - ), |
|
| 564 | - 'no_order_id' => esc_html__('No Order ID found.', 'event_espresso'), |
|
| 565 | - 'general_pp_error' => esc_html__('PayPal form threw an error.', 'event_espresso'), |
|
| 566 | - 'hf_render_error' => esc_html__('Hosted fields could not be rendered!', 'event_espresso'), |
|
| 567 | - 'pm_capture_error' => esc_html__('Payment could not be captured!', 'event_espresso'), |
|
| 568 | - 'not_acdc_eligible' => esc_html__( |
|
| 569 | - 'This merchant is not eligible for Advanced Card Fields checkout type.', |
|
| 570 | - 'event_espresso' |
|
| 571 | - ), |
|
| 572 | - ]; |
|
| 573 | - } |
|
| 500 | + /** |
|
| 501 | + * Form and return PayPal commerce parameters for script localization. |
|
| 502 | + * |
|
| 503 | + * @return array |
|
| 504 | + * @throws EE_Error |
|
| 505 | + * @throws ReflectionException |
|
| 506 | + * @throws Exception |
|
| 507 | + */ |
|
| 508 | + public function localizeParameters(): array |
|
| 509 | + { |
|
| 510 | + // Also tell the script about each instance of this PM. |
|
| 511 | + $pm_versions = []; |
|
| 512 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active( |
|
| 513 | + EEM_Payment_Method::scope_cart, |
|
| 514 | + [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
|
| 515 | + ); |
|
| 516 | + foreach ($active_payment_methods as $payment_method) { |
|
| 517 | + $pm_versions[ $payment_method->slug() ] = [ |
|
| 518 | + 'pm_slug' => $payment_method->slug(), |
|
| 519 | + ]; |
|
| 520 | + } |
|
| 521 | + // Convert money for a display format. |
|
| 522 | + $decimal_places = CurrencyManager::getDecimalPlaces(); |
|
| 523 | + $org_country = isset(EE_Registry::instance()->CFG->organization) |
|
| 524 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 525 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 526 | + : 'US'; |
|
| 527 | + $transaction_id = $this->transaction instanceof EE_Transaction ? $this->transaction->ID() : 0; |
|
| 528 | + $currency_code = CurrencyManager::currencyCode(); |
|
| 529 | + return [ |
|
| 530 | + 'pm_versions' => $pm_versions, |
|
| 531 | + 'payment_currency' => $currency_code, |
|
| 532 | + 'checkout_type' => $this->checkout_type, |
|
| 533 | + 'currency_sign' => EE_Registry::instance()->CFG->currency->sign, |
|
| 534 | + 'pp_order_nonce' => wp_create_nonce(Domain::CAPTURE_ORDER_NONCE_NAME), |
|
| 535 | + // The transaction ID is only used for logging errors. |
|
| 536 | + 'txn_id' => $transaction_id, |
|
| 537 | + 'org_country' => $org_country, |
|
| 538 | + 'decimal_places' => $decimal_places, |
|
| 539 | + 'site_name' => get_bloginfo('name'), |
|
| 540 | + 'active_states' => EED_PayPalCommerce::getActiveStates(), |
|
| 541 | + 'no_spco_error' => esc_html__( |
|
| 542 | + 'It appears the SDK script was not loaded properly! Please refresh the page and try again or contact support.', |
|
| 543 | + 'event_espresso' |
|
| 544 | + ), |
|
| 545 | + 'no_pm_error' => esc_html__( |
|
| 546 | + 'It appears that PayPal Commerce checkout JavaScript was not loaded properly! Please refresh the page and try again or contact support. PayPal Commerce payments can\'t be processed.', |
|
| 547 | + 'event_espresso' |
|
| 548 | + ), |
|
| 549 | + 'browser_not_supported' => esc_html__( |
|
| 550 | + 'It appears that this browser is not supported by PayPal scripts. We apologize, but PayPal payments won\'t work in this browser version.', |
|
| 551 | + 'event_espresso' |
|
| 552 | + ), |
|
| 553 | + 'get_token_error' => esc_html__( |
|
| 554 | + 'There was an error while trying to get the payment token. Please refresh the page and try again or contact support.', |
|
| 555 | + 'event_espresso' |
|
| 556 | + ), |
|
| 557 | + 'form_validation_notice' => esc_html__('Billing form information not valid.', 'event_espresso'), |
|
| 558 | + 'no_verification_token' => esc_html__('Missing the Verification token.', 'event_espresso'), |
|
| 559 | + 'error_response' => esc_html__('Error response received', 'event_espresso'), |
|
| 560 | + 'payment_error' => esc_html__( |
|
| 561 | + 'There was an error with this payment. See the logs for details.', |
|
| 562 | + 'event_espresso' |
|
| 563 | + ), |
|
| 564 | + 'no_order_id' => esc_html__('No Order ID found.', 'event_espresso'), |
|
| 565 | + 'general_pp_error' => esc_html__('PayPal form threw an error.', 'event_espresso'), |
|
| 566 | + 'hf_render_error' => esc_html__('Hosted fields could not be rendered!', 'event_espresso'), |
|
| 567 | + 'pm_capture_error' => esc_html__('Payment could not be captured!', 'event_espresso'), |
|
| 568 | + 'not_acdc_eligible' => esc_html__( |
|
| 569 | + 'This merchant is not eligible for Advanced Card Fields checkout type.', |
|
| 570 | + 'event_espresso' |
|
| 571 | + ), |
|
| 572 | + ]; |
|
| 573 | + } |
|
| 574 | 574 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $options, |
| 74 | 74 | [ |
| 75 | 75 | 'name' => 'PayPalCommerceBillingForm', |
| 76 | - 'html_id' => 'pp-' . $pm_slug . '-billing-form', |
|
| 76 | + 'html_id' => 'pp-'.$pm_slug.'-billing-form', |
|
| 77 | 77 | 'html_class' => 'pp_commerce_billing_form', |
| 78 | 78 | 'subsections' => [ |
| 79 | 79 | 'eea_paypal_commerce_token' => new EE_Hidden_Input( |
@@ -85,28 +85,28 @@ discard block |
||
| 85 | 85 | ), |
| 86 | 86 | 'pp_order_nonce' => new EE_Hidden_Input( |
| 87 | 87 | [ |
| 88 | - 'html_id' => 'eea-' . $pm_slug . '-order-nonce', |
|
| 88 | + 'html_id' => 'eea-'.$pm_slug.'-order-nonce', |
|
| 89 | 89 | 'html_name' => 'pp_order_nonce', |
| 90 | 90 | 'default' => '', |
| 91 | 91 | ] |
| 92 | 92 | ), |
| 93 | 93 | 'pp_order_id' => new EE_Hidden_Input( |
| 94 | 94 | [ |
| 95 | - 'html_id' => 'eea-' . $pm_slug . '-order-id', |
|
| 95 | + 'html_id' => 'eea-'.$pm_slug.'-order-id', |
|
| 96 | 96 | 'html_name' => 'pp_order_id', |
| 97 | 97 | 'default' => '', |
| 98 | 98 | ] |
| 99 | 99 | ), |
| 100 | 100 | 'pp_order_status' => new EE_Hidden_Input( |
| 101 | 101 | [ |
| 102 | - 'html_id' => 'eea-' . $pm_slug . '-order-status', |
|
| 102 | + 'html_id' => 'eea-'.$pm_slug.'-order-status', |
|
| 103 | 103 | 'html_name' => 'pp_order_status', |
| 104 | 104 | 'default' => '', |
| 105 | 105 | ] |
| 106 | 106 | ), |
| 107 | 107 | 'pp_order_amount' => new EE_Hidden_Input( |
| 108 | 108 | [ |
| 109 | - 'html_id' => 'eea-' . $pm_slug . '-order-amount', |
|
| 109 | + 'html_id' => 'eea-'.$pm_slug.'-order-amount', |
|
| 110 | 110 | 'html_name' => 'pp_order_amount', |
| 111 | 111 | 'default' => '', |
| 112 | 112 | ] |
@@ -211,12 +211,12 @@ discard block |
||
| 211 | 211 | $request = LoaderFactory::getShared(Request::class); |
| 212 | 212 | $request_params = $request->requestParams(); |
| 213 | 213 | // Only the PPC billing form. |
| 214 | - if (! $billing_form instanceof BillingForm) { |
|
| 214 | + if ( ! $billing_form instanceof BillingForm) { |
|
| 215 | 215 | return $billing_form; |
| 216 | 216 | } |
| 217 | 217 | // Make sure the billing form subsections have correct names. |
| 218 | 218 | $inputs = $billing_form->inputs_in_subsections(); |
| 219 | - if (! empty($request_params['process_form_submission']) |
|
| 219 | + if ( ! empty($request_params['process_form_submission']) |
|
| 220 | 220 | && $request_params['process_form_submission'] === '1' |
| 221 | 221 | && ! empty($request_params['eep_ppc_skip_form_validation']) |
| 222 | 222 | ) { |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | "$pm_slug-card-number-lbl", |
| 256 | 256 | "$pm_slug-card-fields", |
| 257 | 257 | "", |
| 258 | - 'for="' . $pm_slug . '-card-number"' |
|
| 259 | - ) . |
|
| 258 | + 'for="'.$pm_slug.'-card-number"' |
|
| 259 | + ). |
|
| 260 | 260 | EEH_HTML::p( |
| 261 | 261 | "", |
| 262 | 262 | "$pm_slug-card-number", |
@@ -269,8 +269,8 @@ discard block |
||
| 269 | 269 | "$pm_slug-expiration-date-lbl", |
| 270 | 270 | "$pm_slug-card-fields", |
| 271 | 271 | "", |
| 272 | - 'for="' . $pm_slug . '-expiration-date"' |
|
| 273 | - ) . |
|
| 272 | + 'for="'.$pm_slug.'-expiration-date"' |
|
| 273 | + ). |
|
| 274 | 274 | EEH_HTML::p( |
| 275 | 275 | "", |
| 276 | 276 | "$pm_slug-expiration-date", |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | "$pm_slug-cvv-lbl", |
| 284 | 284 | "$pm_slug-card-fields", |
| 285 | 285 | "", |
| 286 | - 'for="' . $pm_slug . '-cvv"' |
|
| 287 | - ) . |
|
| 286 | + 'for="'.$pm_slug.'-cvv"' |
|
| 287 | + ). |
|
| 288 | 288 | EEH_HTML::p( |
| 289 | 289 | "", |
| 290 | 290 | "$pm_slug-cvv", |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | 'pp_name_on_card' => new EE_Text_Input( |
| 295 | 295 | [ |
| 296 | 296 | 'html_label_text' => esc_html__('Name On Card', 'event_espresso'), |
| 297 | - 'html_id' => $pm_slug . '-card-holder-name', |
|
| 297 | + 'html_id' => $pm_slug.'-card-holder-name', |
|
| 298 | 298 | 'html_name' => 'card-holder-name', |
| 299 | 299 | 'html_class' => '', |
| 300 | 300 | 'required' => true, |
@@ -333,16 +333,16 @@ discard block |
||
| 333 | 333 | EEH_HTML::div( |
| 334 | 334 | EEH_HTML::div( |
| 335 | 335 | ' ', |
| 336 | - 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
| 336 | + 'eep-'.$this->paypal_pmt->slug().'-payments-separator', |
|
| 337 | 337 | 'eep-ppc-separator-line eep-left-floating' |
| 338 | - ) . |
|
| 338 | + ). |
|
| 339 | 339 | EEH_HTML::div( |
| 340 | 340 | esc_html__(' or ', 'event_espresso'), |
| 341 | - 'eep-' . $this->paypal_pmt->slug() . '-separator-text', |
|
| 341 | + 'eep-'.$this->paypal_pmt->slug().'-separator-text', |
|
| 342 | 342 | 'eep-ppc-separator-text1 eep-mid-floating' |
| 343 | - ) . EEH_HTML::div( |
|
| 343 | + ).EEH_HTML::div( |
|
| 344 | 344 | ' ', |
| 345 | - 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
| 345 | + 'eep-'.$this->paypal_pmt->slug().'-payments-separator', |
|
| 346 | 346 | 'eep-ppc-separator-line eep-right-floating' |
| 347 | 347 | ), |
| 348 | 348 | 'eep-ppc-separator-holder', |
@@ -366,9 +366,9 @@ discard block |
||
| 366 | 366 | { |
| 367 | 367 | if ( |
| 368 | 368 | ! empty($options_array['html_id']) |
| 369 | - && $options_array['html_id'] === 'spco-payment-method-info-' . $this->paypal_pmt->slug() |
|
| 369 | + && $options_array['html_id'] === 'spco-payment-method-info-'.$this->paypal_pmt->slug() |
|
| 370 | 370 | ) { |
| 371 | - if (! empty($options_array['subsections']) && isset($options_array['subsections']['info'])) { |
|
| 371 | + if ( ! empty($options_array['subsections']) && isset($options_array['subsections']['info'])) { |
|
| 372 | 372 | unset($options_array['subsections']['info']); |
| 373 | 373 | } |
| 374 | 374 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | [ |
| 391 | 391 | 'layout_strategy' => new EE_Template_Layout( |
| 392 | 392 | [ |
| 393 | - 'layout_template_file' => $this->template_path . 'debugInfo.template.php', |
|
| 393 | + 'layout_template_file' => $this->template_path.'debugInfo.template.php', |
|
| 394 | 394 | 'template_args' => [], |
| 395 | 395 | ] |
| 396 | 396 | ), |
@@ -411,12 +411,12 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function addPayPalCheckout(): EE_Form_Section_Proper |
| 413 | 413 | { |
| 414 | - $template_args['pm_slug'] = $this->paypal_pmt->slug(); |
|
| 414 | + $template_args['pm_slug'] = $this->paypal_pmt->slug(); |
|
| 415 | 415 | return new EE_Form_Section_Proper( |
| 416 | 416 | [ |
| 417 | 417 | 'layout_strategy' => new EE_Template_Layout( |
| 418 | 418 | [ |
| 419 | - 'layout_template_file' => $this->template_path . 'paymentButtons.template.php', |
|
| 419 | + 'layout_template_file' => $this->template_path.'paymentButtons.template.php', |
|
| 420 | 420 | 'template_args' => $template_args, |
| 421 | 421 | ] |
| 422 | 422 | ), |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | } |
| 445 | 445 | $client_token = $response['client_token']; |
| 446 | 446 | $attributes = " data-partner-attribution-id=\"$bn_code\" data-client-token=\"$client_token\""; |
| 447 | - $tag = str_replace('></script>', $attributes . '></script>', $tag); |
|
| 447 | + $tag = str_replace('></script>', $attributes.'></script>', $tag); |
|
| 448 | 448 | } |
| 449 | 449 | return $tag; |
| 450 | 450 | } |
@@ -471,14 +471,14 @@ discard block |
||
| 471 | 471 | $this->_pm_instance, |
| 472 | 472 | Domain::META_KEY_SELLER_MERCHANT_ID |
| 473 | 473 | ); |
| 474 | - $scripts_src .= "&merchant-id=$merchant_id"; |
|
| 474 | + $scripts_src .= "&merchant-id=$merchant_id"; |
|
| 475 | 475 | } |
| 476 | - $client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key); |
|
| 476 | + $client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key); |
|
| 477 | 477 | $scripts_src .= "&client-id=$client_id¤cy=$currency"; |
| 478 | 478 | wp_enqueue_script('eea_paypal_commerce_js_lib', $scripts_src, [], null); |
| 479 | 479 | wp_enqueue_script( |
| 480 | 480 | 'eea_paypal_commerce_js', |
| 481 | - EEP_PAYPAL_COMMERCE_URL . 'assets/js/paypal-commerce-payments.js', |
|
| 481 | + EEP_PAYPAL_COMMERCE_URL.'assets/js/paypal-commerce-payments.js', |
|
| 482 | 482 | ['eea_paypal_commerce_js_lib'], |
| 483 | 483 | EVENT_ESPRESSO_VERSION, |
| 484 | 484 | true |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | // Styles. |
| 487 | 487 | wp_enqueue_style( |
| 488 | 488 | 'eea_paypal_checkout_form_styles', |
| 489 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-checkout.css', |
|
| 489 | + EEP_PAYPAL_COMMERCE_URL.'assets'.DS.'css'.DS.'eea-paypal-checkout.css', |
|
| 490 | 490 | [], |
| 491 | 491 | EVENT_ESPRESSO_VERSION |
| 492 | 492 | ); |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
| 515 | 515 | ); |
| 516 | 516 | foreach ($active_payment_methods as $payment_method) { |
| 517 | - $pm_versions[ $payment_method->slug() ] = [ |
|
| 517 | + $pm_versions[$payment_method->slug()] = [ |
|
| 518 | 518 | 'pm_slug' => $payment_method->slug(), |
| 519 | 519 | ]; |
| 520 | 520 | } |
@@ -24,225 +24,225 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class SettingsForm extends EE_Payment_Method_Form |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * Payment method. |
|
| 29 | - * |
|
| 30 | - * @var EE_PMT_Base|null |
|
| 31 | - */ |
|
| 32 | - protected $payment_method = null; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Payment method instance. |
|
| 36 | - * |
|
| 37 | - * @var EE_PMT_Base|null |
|
| 38 | - */ |
|
| 39 | - protected $pm_instance = null; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Class constructor. |
|
| 44 | - * |
|
| 45 | - * @param EE_PMT_PayPalCheckout $payment_method |
|
| 46 | - * @param EE_Payment_Method $pm_instance |
|
| 47 | - * @throws EE_Error |
|
| 48 | - * @throws ReflectionException |
|
| 49 | - */ |
|
| 50 | - public function __construct(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Method $pm_instance) |
|
| 51 | - { |
|
| 52 | - $form_parameters = []; |
|
| 53 | - $this->payment_method = $payment_method; |
|
| 54 | - $this->pm_instance = $pm_instance; |
|
| 55 | - // Allow Advanced Card Checkout if PPCP checkout type was possible and selected. |
|
| 56 | - $allowed_type = PayPalExtraMetaManager::getPmOption($pm_instance, Domain::META_KEY_ALLOWED_CHECKOUT_TYPE); |
|
| 57 | - $is_onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
| 58 | - if ($is_onboard && ($allowed_type === 'ppcp' || $allowed_type === 'all')) { |
|
| 59 | - $form_parameters = $this->addCheckoutTypeSelect($form_parameters); |
|
| 60 | - } |
|
| 61 | - // Build the PM form. |
|
| 62 | - parent::__construct($form_parameters); |
|
| 63 | - // Add a form for PayPal Onboard. |
|
| 64 | - $this->addOnboardingForm($payment_method, $pm_instance); |
|
| 65 | - // Add a form for PayPal Onboard. |
|
| 66 | - $this->addFeesNotice(); |
|
| 67 | - // Add the clear data button. |
|
| 68 | - $this->clearMetadataButton($pm_instance); |
|
| 69 | - // Disable inputs if needed. |
|
| 70 | - $this->toggleSubsections($pm_instance); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Adds an onboarding form as a subsection. |
|
| 76 | - * |
|
| 77 | - * @param EE_PMT_PayPalCheckout $payment_method |
|
| 78 | - * @param EE_Payment_Method $pm_instance |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public function addOnboardingForm(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Method $pm_instance): void |
|
| 82 | - { |
|
| 83 | - // Add the connect button before the app id field. |
|
| 84 | - try { |
|
| 85 | - $this->add_subsections( |
|
| 86 | - [ |
|
| 87 | - 'paypal_onboard' => new OnboardingForm($payment_method, $pm_instance), |
|
| 88 | - ], |
|
| 89 | - 'PMD_debug_mode', |
|
| 90 | - false |
|
| 91 | - ); |
|
| 92 | - } catch (EE_Error $e) { |
|
| 93 | - // Simply don't add the form. |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Add fees notice. |
|
| 100 | - * |
|
| 101 | - * @return void |
|
| 102 | - */ |
|
| 103 | - public function addFeesNotice(): void |
|
| 104 | - { |
|
| 105 | - if (defined('EE_PPC_USE_PAYMENT_FEES') && ! EE_PPC_USE_PAYMENT_FEES) { |
|
| 106 | - // We want to be able to disable fees. |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - try { |
|
| 110 | - $this->add_subsections( |
|
| 111 | - [ |
|
| 112 | - 'partner_fees_notice' => new EE_Form_Section_HTML( |
|
| 113 | - EEH_HTML::tr( |
|
| 114 | - EEH_HTML::th() |
|
| 115 | - . EEH_HTML::thx() |
|
| 116 | - . EEH_HTML::td( |
|
| 117 | - EEH_HTML::div( |
|
| 118 | - EEH_HTML::strong( |
|
| 119 | - esc_html__( |
|
| 120 | - 'PayPal Partner Commission Fees are based upon the status of your Support License:', |
|
| 121 | - 'event_espresso' |
|
| 122 | - ) |
|
| 123 | - ) |
|
| 124 | - . EEH_HTML::ul() |
|
| 125 | - . EEH_HTML::li( |
|
| 126 | - esc_html__('- Active licenses commission fees: 0%', 'event_espresso') |
|
| 127 | - ) |
|
| 128 | - . EEH_HTML::li( |
|
| 129 | - esc_html__('- Expired license commission fees: 3%', 'event_espresso') |
|
| 130 | - ) |
|
| 131 | - . EEH_HTML::ulx() |
|
| 132 | - . esc_html__( |
|
| 133 | - 'Keep your support license active for: lower fees, up-to-date software and have access to our support team. By connecting and processing payments you agree to these terms.', |
|
| 134 | - 'event_espresso' |
|
| 135 | - ), |
|
| 136 | - '', |
|
| 137 | - 'ee-status-outline ee-status-bg--info' |
|
| 138 | - ) |
|
| 139 | - ) |
|
| 140 | - ) |
|
| 141 | - ), |
|
| 142 | - ], |
|
| 143 | - 'paypal_onboard' |
|
| 144 | - ); |
|
| 145 | - } catch (EE_Error $e) { |
|
| 146 | - // Don't add this subsection then. |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Add a checkout type select. |
|
| 153 | - * |
|
| 154 | - * @param array $form_parameters |
|
| 155 | - * @return array |
|
| 156 | - * @throws EE_Error |
|
| 157 | - * @throws ReflectionException |
|
| 158 | - */ |
|
| 159 | - public function addCheckoutTypeSelect(array $form_parameters): array |
|
| 160 | - { |
|
| 161 | - $pm_slug = $this->pm_instance->slug(); |
|
| 162 | - $allowed_checkout_type = PayPalExtraMetaManager::getPmOption( |
|
| 163 | - $this->pm_instance, |
|
| 164 | - Domain::META_KEY_ALLOWED_CHECKOUT_TYPE |
|
| 165 | - ); |
|
| 166 | - // Section to be displayed if onboard. |
|
| 167 | - $form_parameters['extra_meta_inputs'] = [ |
|
| 168 | - Domain::META_KEY_CHECKOUT_TYPE => new EE_Select_Input( |
|
| 169 | - [ |
|
| 170 | - 'express_checkout' => esc_html__('Express Checkout', 'event_espresso'), |
|
| 171 | - 'ppcp' => esc_html__('Advanced Credit and Debit Card payments', 'event_espresso'), |
|
| 172 | - 'all' => esc_html__('Both, ACDC and Express Checkout', 'event_espresso'), |
|
| 173 | - ], |
|
| 174 | - [ |
|
| 175 | - 'html_name' => 'eep_checkout_type_option_' . $pm_slug, |
|
| 176 | - 'html_id' => 'eep_checkout_type_option_' . $pm_slug, |
|
| 177 | - 'html_class' => 'eep-checkout-type-option-' . $pm_slug, |
|
| 178 | - 'required' => true, |
|
| 179 | - 'default' => $allowed_checkout_type, |
|
| 180 | - ] |
|
| 181 | - ), |
|
| 182 | - ]; |
|
| 183 | - return $form_parameters; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Adds a button for clearing the PM metadata. |
|
| 189 | - * |
|
| 190 | - * @param EE_Payment_Method $pm_instance |
|
| 191 | - * @return void |
|
| 192 | - */ |
|
| 193 | - public function clearMetadataButton(EE_Payment_Method $pm_instance): void |
|
| 194 | - { |
|
| 195 | - try { |
|
| 196 | - $is_onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
| 197 | - if ($is_onboard) { |
|
| 198 | - return; |
|
| 199 | - } |
|
| 200 | - $button_text = sprintf( |
|
| 201 | - esc_html__('Clear %1$s metadata', 'event_espresso'), |
|
| 202 | - $pm_instance->admin_name() |
|
| 203 | - ); |
|
| 204 | - $this->add_subsections( |
|
| 205 | - [ |
|
| 206 | - 'clear_pm_metadata' => new EE_Form_Section_HTML( |
|
| 207 | - EEH_HTML::tr( |
|
| 208 | - EEH_HTML::th(esc_html__('Clear PM metadata ?', 'event_espresso')) . |
|
| 209 | - EEH_HTML::td( |
|
| 210 | - EEH_HTML::link( |
|
| 211 | - '', |
|
| 212 | - $button_text, |
|
| 213 | - $button_text, |
|
| 214 | - 'eea_clear_metadata_' . $pm_instance->slug(), |
|
| 215 | - 'espresso-button button button--secondary' |
|
| 216 | - ) |
|
| 217 | - ) |
|
| 218 | - ) |
|
| 219 | - ), |
|
| 220 | - ], |
|
| 221 | - 'PMD_order', |
|
| 222 | - false |
|
| 223 | - ); |
|
| 224 | - } catch (EE_Error $e) { |
|
| 225 | - // Don't add the button if there's some error. |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Toggles subsections depending on the OAuth status etc. |
|
| 232 | - * |
|
| 233 | - * @param EE_Payment_Method $pm_instance |
|
| 234 | - * @return void |
|
| 235 | - * @throws EE_Error |
|
| 236 | - */ |
|
| 237 | - private function toggleSubsections(EE_Payment_Method $pm_instance): void |
|
| 238 | - { |
|
| 239 | - $onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
| 240 | - // Don't allow changing the debug mode setting while connected. |
|
| 241 | - if ($onboard) { |
|
| 242 | - $debug_mode_input = $this->get_input('PMD_debug_mode', false); |
|
| 243 | - if (method_exists($debug_mode_input, 'isDisabled')) { |
|
| 244 | - $debug_mode_input->disable(); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 27 | + /** |
|
| 28 | + * Payment method. |
|
| 29 | + * |
|
| 30 | + * @var EE_PMT_Base|null |
|
| 31 | + */ |
|
| 32 | + protected $payment_method = null; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Payment method instance. |
|
| 36 | + * |
|
| 37 | + * @var EE_PMT_Base|null |
|
| 38 | + */ |
|
| 39 | + protected $pm_instance = null; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Class constructor. |
|
| 44 | + * |
|
| 45 | + * @param EE_PMT_PayPalCheckout $payment_method |
|
| 46 | + * @param EE_Payment_Method $pm_instance |
|
| 47 | + * @throws EE_Error |
|
| 48 | + * @throws ReflectionException |
|
| 49 | + */ |
|
| 50 | + public function __construct(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Method $pm_instance) |
|
| 51 | + { |
|
| 52 | + $form_parameters = []; |
|
| 53 | + $this->payment_method = $payment_method; |
|
| 54 | + $this->pm_instance = $pm_instance; |
|
| 55 | + // Allow Advanced Card Checkout if PPCP checkout type was possible and selected. |
|
| 56 | + $allowed_type = PayPalExtraMetaManager::getPmOption($pm_instance, Domain::META_KEY_ALLOWED_CHECKOUT_TYPE); |
|
| 57 | + $is_onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
| 58 | + if ($is_onboard && ($allowed_type === 'ppcp' || $allowed_type === 'all')) { |
|
| 59 | + $form_parameters = $this->addCheckoutTypeSelect($form_parameters); |
|
| 60 | + } |
|
| 61 | + // Build the PM form. |
|
| 62 | + parent::__construct($form_parameters); |
|
| 63 | + // Add a form for PayPal Onboard. |
|
| 64 | + $this->addOnboardingForm($payment_method, $pm_instance); |
|
| 65 | + // Add a form for PayPal Onboard. |
|
| 66 | + $this->addFeesNotice(); |
|
| 67 | + // Add the clear data button. |
|
| 68 | + $this->clearMetadataButton($pm_instance); |
|
| 69 | + // Disable inputs if needed. |
|
| 70 | + $this->toggleSubsections($pm_instance); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Adds an onboarding form as a subsection. |
|
| 76 | + * |
|
| 77 | + * @param EE_PMT_PayPalCheckout $payment_method |
|
| 78 | + * @param EE_Payment_Method $pm_instance |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public function addOnboardingForm(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Method $pm_instance): void |
|
| 82 | + { |
|
| 83 | + // Add the connect button before the app id field. |
|
| 84 | + try { |
|
| 85 | + $this->add_subsections( |
|
| 86 | + [ |
|
| 87 | + 'paypal_onboard' => new OnboardingForm($payment_method, $pm_instance), |
|
| 88 | + ], |
|
| 89 | + 'PMD_debug_mode', |
|
| 90 | + false |
|
| 91 | + ); |
|
| 92 | + } catch (EE_Error $e) { |
|
| 93 | + // Simply don't add the form. |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Add fees notice. |
|
| 100 | + * |
|
| 101 | + * @return void |
|
| 102 | + */ |
|
| 103 | + public function addFeesNotice(): void |
|
| 104 | + { |
|
| 105 | + if (defined('EE_PPC_USE_PAYMENT_FEES') && ! EE_PPC_USE_PAYMENT_FEES) { |
|
| 106 | + // We want to be able to disable fees. |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + try { |
|
| 110 | + $this->add_subsections( |
|
| 111 | + [ |
|
| 112 | + 'partner_fees_notice' => new EE_Form_Section_HTML( |
|
| 113 | + EEH_HTML::tr( |
|
| 114 | + EEH_HTML::th() |
|
| 115 | + . EEH_HTML::thx() |
|
| 116 | + . EEH_HTML::td( |
|
| 117 | + EEH_HTML::div( |
|
| 118 | + EEH_HTML::strong( |
|
| 119 | + esc_html__( |
|
| 120 | + 'PayPal Partner Commission Fees are based upon the status of your Support License:', |
|
| 121 | + 'event_espresso' |
|
| 122 | + ) |
|
| 123 | + ) |
|
| 124 | + . EEH_HTML::ul() |
|
| 125 | + . EEH_HTML::li( |
|
| 126 | + esc_html__('- Active licenses commission fees: 0%', 'event_espresso') |
|
| 127 | + ) |
|
| 128 | + . EEH_HTML::li( |
|
| 129 | + esc_html__('- Expired license commission fees: 3%', 'event_espresso') |
|
| 130 | + ) |
|
| 131 | + . EEH_HTML::ulx() |
|
| 132 | + . esc_html__( |
|
| 133 | + 'Keep your support license active for: lower fees, up-to-date software and have access to our support team. By connecting and processing payments you agree to these terms.', |
|
| 134 | + 'event_espresso' |
|
| 135 | + ), |
|
| 136 | + '', |
|
| 137 | + 'ee-status-outline ee-status-bg--info' |
|
| 138 | + ) |
|
| 139 | + ) |
|
| 140 | + ) |
|
| 141 | + ), |
|
| 142 | + ], |
|
| 143 | + 'paypal_onboard' |
|
| 144 | + ); |
|
| 145 | + } catch (EE_Error $e) { |
|
| 146 | + // Don't add this subsection then. |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Add a checkout type select. |
|
| 153 | + * |
|
| 154 | + * @param array $form_parameters |
|
| 155 | + * @return array |
|
| 156 | + * @throws EE_Error |
|
| 157 | + * @throws ReflectionException |
|
| 158 | + */ |
|
| 159 | + public function addCheckoutTypeSelect(array $form_parameters): array |
|
| 160 | + { |
|
| 161 | + $pm_slug = $this->pm_instance->slug(); |
|
| 162 | + $allowed_checkout_type = PayPalExtraMetaManager::getPmOption( |
|
| 163 | + $this->pm_instance, |
|
| 164 | + Domain::META_KEY_ALLOWED_CHECKOUT_TYPE |
|
| 165 | + ); |
|
| 166 | + // Section to be displayed if onboard. |
|
| 167 | + $form_parameters['extra_meta_inputs'] = [ |
|
| 168 | + Domain::META_KEY_CHECKOUT_TYPE => new EE_Select_Input( |
|
| 169 | + [ |
|
| 170 | + 'express_checkout' => esc_html__('Express Checkout', 'event_espresso'), |
|
| 171 | + 'ppcp' => esc_html__('Advanced Credit and Debit Card payments', 'event_espresso'), |
|
| 172 | + 'all' => esc_html__('Both, ACDC and Express Checkout', 'event_espresso'), |
|
| 173 | + ], |
|
| 174 | + [ |
|
| 175 | + 'html_name' => 'eep_checkout_type_option_' . $pm_slug, |
|
| 176 | + 'html_id' => 'eep_checkout_type_option_' . $pm_slug, |
|
| 177 | + 'html_class' => 'eep-checkout-type-option-' . $pm_slug, |
|
| 178 | + 'required' => true, |
|
| 179 | + 'default' => $allowed_checkout_type, |
|
| 180 | + ] |
|
| 181 | + ), |
|
| 182 | + ]; |
|
| 183 | + return $form_parameters; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Adds a button for clearing the PM metadata. |
|
| 189 | + * |
|
| 190 | + * @param EE_Payment_Method $pm_instance |
|
| 191 | + * @return void |
|
| 192 | + */ |
|
| 193 | + public function clearMetadataButton(EE_Payment_Method $pm_instance): void |
|
| 194 | + { |
|
| 195 | + try { |
|
| 196 | + $is_onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
| 197 | + if ($is_onboard) { |
|
| 198 | + return; |
|
| 199 | + } |
|
| 200 | + $button_text = sprintf( |
|
| 201 | + esc_html__('Clear %1$s metadata', 'event_espresso'), |
|
| 202 | + $pm_instance->admin_name() |
|
| 203 | + ); |
|
| 204 | + $this->add_subsections( |
|
| 205 | + [ |
|
| 206 | + 'clear_pm_metadata' => new EE_Form_Section_HTML( |
|
| 207 | + EEH_HTML::tr( |
|
| 208 | + EEH_HTML::th(esc_html__('Clear PM metadata ?', 'event_espresso')) . |
|
| 209 | + EEH_HTML::td( |
|
| 210 | + EEH_HTML::link( |
|
| 211 | + '', |
|
| 212 | + $button_text, |
|
| 213 | + $button_text, |
|
| 214 | + 'eea_clear_metadata_' . $pm_instance->slug(), |
|
| 215 | + 'espresso-button button button--secondary' |
|
| 216 | + ) |
|
| 217 | + ) |
|
| 218 | + ) |
|
| 219 | + ), |
|
| 220 | + ], |
|
| 221 | + 'PMD_order', |
|
| 222 | + false |
|
| 223 | + ); |
|
| 224 | + } catch (EE_Error $e) { |
|
| 225 | + // Don't add the button if there's some error. |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Toggles subsections depending on the OAuth status etc. |
|
| 232 | + * |
|
| 233 | + * @param EE_Payment_Method $pm_instance |
|
| 234 | + * @return void |
|
| 235 | + * @throws EE_Error |
|
| 236 | + */ |
|
| 237 | + private function toggleSubsections(EE_Payment_Method $pm_instance): void |
|
| 238 | + { |
|
| 239 | + $onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
| 240 | + // Don't allow changing the debug mode setting while connected. |
|
| 241 | + if ($onboard) { |
|
| 242 | + $debug_mode_input = $this->get_input('PMD_debug_mode', false); |
|
| 243 | + if (method_exists($debug_mode_input, 'isDisabled')) { |
|
| 244 | + $debug_mode_input->disable(); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | 248 | } |
@@ -13,297 +13,297 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class EEG_PayPalCheckout extends EE_Onsite_Gateway |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Currencies supported by this gateway. |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected $_currencies_supported = [ |
|
| 22 | - 'AUD', |
|
| 23 | - 'BRL', |
|
| 24 | - 'CAD', |
|
| 25 | - 'CNY', |
|
| 26 | - 'CZK', |
|
| 27 | - 'DKK', |
|
| 28 | - 'EUR', |
|
| 29 | - 'HKD', |
|
| 30 | - 'HUF', |
|
| 31 | - 'ILS', |
|
| 32 | - 'JPY', |
|
| 33 | - 'MYR', |
|
| 34 | - 'MXN', |
|
| 35 | - 'TWD', |
|
| 36 | - 'NZD', |
|
| 37 | - 'NOK', |
|
| 38 | - 'PHP', |
|
| 39 | - 'PLN', |
|
| 40 | - 'GBP', |
|
| 41 | - 'RUB', |
|
| 42 | - 'SGD', |
|
| 43 | - 'SEK', |
|
| 44 | - 'CHF', |
|
| 45 | - 'THB', |
|
| 46 | - 'USD', |
|
| 47 | - ]; |
|
| 16 | + /** |
|
| 17 | + * Currencies supported by this gateway. |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected $_currencies_supported = [ |
|
| 22 | + 'AUD', |
|
| 23 | + 'BRL', |
|
| 24 | + 'CAD', |
|
| 25 | + 'CNY', |
|
| 26 | + 'CZK', |
|
| 27 | + 'DKK', |
|
| 28 | + 'EUR', |
|
| 29 | + 'HKD', |
|
| 30 | + 'HUF', |
|
| 31 | + 'ILS', |
|
| 32 | + 'JPY', |
|
| 33 | + 'MYR', |
|
| 34 | + 'MXN', |
|
| 35 | + 'TWD', |
|
| 36 | + 'NZD', |
|
| 37 | + 'NOK', |
|
| 38 | + 'PHP', |
|
| 39 | + 'PLN', |
|
| 40 | + 'GBP', |
|
| 41 | + 'RUB', |
|
| 42 | + 'SGD', |
|
| 43 | + 'SEK', |
|
| 44 | + 'CHF', |
|
| 45 | + 'THB', |
|
| 46 | + 'USD', |
|
| 47 | + ]; |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Override the parent. |
|
| 52 | - * |
|
| 53 | - * @param EE_Payment|null $payment |
|
| 54 | - * @param array|null $billing_info |
|
| 55 | - * @return EE_Payment |
|
| 56 | - * @throws EE_Error |
|
| 57 | - * @throws ReflectionException |
|
| 58 | - */ |
|
| 59 | - public function do_direct_payment($payment, $billing_info = null) |
|
| 60 | - { |
|
| 61 | - // Normally we shouldn't be getting here because the payment should have been processed |
|
| 62 | - // along with the PP Order Charge. |
|
| 63 | - return $payment; |
|
| 64 | - } |
|
| 50 | + /** |
|
| 51 | + * Override the parent. |
|
| 52 | + * |
|
| 53 | + * @param EE_Payment|null $payment |
|
| 54 | + * @param array|null $billing_info |
|
| 55 | + * @return EE_Payment |
|
| 56 | + * @throws EE_Error |
|
| 57 | + * @throws ReflectionException |
|
| 58 | + */ |
|
| 59 | + public function do_direct_payment($payment, $billing_info = null) |
|
| 60 | + { |
|
| 61 | + // Normally we shouldn't be getting here because the payment should have been processed |
|
| 62 | + // along with the PP Order Charge. |
|
| 63 | + return $payment; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Validate the Order. |
|
| 69 | - * |
|
| 70 | - * @param $order |
|
| 71 | - * @param null $provided_order_id |
|
| 72 | - * @return array ['completed' => {boolean}, 'message' => {string}] |
|
| 73 | - */ |
|
| 74 | - public static function isOrderCompleted($order, $provided_order_id = null): array |
|
| 75 | - { |
|
| 76 | - $conclusion = [ |
|
| 77 | - 'completed' => false, |
|
| 78 | - 'message' => esc_html__('Could not validate this Order.', 'event_espresso'), |
|
| 79 | - ]; |
|
| 80 | - if (! empty($order) && ! empty($provided_order_id) && $order['id'] !== $provided_order_id) { |
|
| 81 | - $conclusion['message'] = esc_html__('Order ID mismatch.', 'event_espresso'); |
|
| 82 | - } |
|
| 83 | - if (! $order || ! is_array($order)) { |
|
| 84 | - $conclusion['message'] = esc_html__('The Order data is incorrectly formatted.', 'event_espresso'); |
|
| 85 | - } elseif (empty($order['status'])) { |
|
| 86 | - $conclusion['message'] = esc_html__( |
|
| 87 | - 'There was an error with this payment. The status of the Order could not be determined.', |
|
| 88 | - 'event_espresso' |
|
| 89 | - ); |
|
| 90 | - } elseif ($order['status'] !== 'COMPLETED') { |
|
| 91 | - $conclusion['message'] = esc_html__( |
|
| 92 | - 'There was an error with this payment. Order was not approved.', |
|
| 93 | - 'event_espresso' |
|
| 94 | - ); |
|
| 95 | - } elseif (empty($order['purchase_units'][0]['payments']['captures'][0]['status'])) { |
|
| 96 | - $conclusion['message'] = esc_html__( |
|
| 97 | - 'There was an error with this payment. The status of the Payment could not be determined.', |
|
| 98 | - 'event_espresso' |
|
| 99 | - ); |
|
| 100 | - } elseif ($order['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') { |
|
| 101 | - $conclusion['message'] = esc_html__( |
|
| 102 | - 'This payment was declined or failed validation. Please check the billing information you provided.', |
|
| 103 | - 'event_espresso' |
|
| 104 | - ); |
|
| 105 | - } else { |
|
| 106 | - // If we didn't fail on the above, the Order should be considered valid. |
|
| 107 | - $conclusion['completed'] = true; |
|
| 108 | - } |
|
| 109 | - return $conclusion; |
|
| 110 | - } |
|
| 67 | + /** |
|
| 68 | + * Validate the Order. |
|
| 69 | + * |
|
| 70 | + * @param $order |
|
| 71 | + * @param null $provided_order_id |
|
| 72 | + * @return array ['completed' => {boolean}, 'message' => {string}] |
|
| 73 | + */ |
|
| 74 | + public static function isOrderCompleted($order, $provided_order_id = null): array |
|
| 75 | + { |
|
| 76 | + $conclusion = [ |
|
| 77 | + 'completed' => false, |
|
| 78 | + 'message' => esc_html__('Could not validate this Order.', 'event_espresso'), |
|
| 79 | + ]; |
|
| 80 | + if (! empty($order) && ! empty($provided_order_id) && $order['id'] !== $provided_order_id) { |
|
| 81 | + $conclusion['message'] = esc_html__('Order ID mismatch.', 'event_espresso'); |
|
| 82 | + } |
|
| 83 | + if (! $order || ! is_array($order)) { |
|
| 84 | + $conclusion['message'] = esc_html__('The Order data is incorrectly formatted.', 'event_espresso'); |
|
| 85 | + } elseif (empty($order['status'])) { |
|
| 86 | + $conclusion['message'] = esc_html__( |
|
| 87 | + 'There was an error with this payment. The status of the Order could not be determined.', |
|
| 88 | + 'event_espresso' |
|
| 89 | + ); |
|
| 90 | + } elseif ($order['status'] !== 'COMPLETED') { |
|
| 91 | + $conclusion['message'] = esc_html__( |
|
| 92 | + 'There was an error with this payment. Order was not approved.', |
|
| 93 | + 'event_espresso' |
|
| 94 | + ); |
|
| 95 | + } elseif (empty($order['purchase_units'][0]['payments']['captures'][0]['status'])) { |
|
| 96 | + $conclusion['message'] = esc_html__( |
|
| 97 | + 'There was an error with this payment. The status of the Payment could not be determined.', |
|
| 98 | + 'event_espresso' |
|
| 99 | + ); |
|
| 100 | + } elseif ($order['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') { |
|
| 101 | + $conclusion['message'] = esc_html__( |
|
| 102 | + 'This payment was declined or failed validation. Please check the billing information you provided.', |
|
| 103 | + 'event_espresso' |
|
| 104 | + ); |
|
| 105 | + } else { |
|
| 106 | + // If we didn't fail on the above, the Order should be considered valid. |
|
| 107 | + $conclusion['completed'] = true; |
|
| 108 | + } |
|
| 109 | + return $conclusion; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Create an EE Payment. |
|
| 115 | - * |
|
| 116 | - * @param EE_Transaction $transaction |
|
| 117 | - * @param EE_Payment_Method $payment_method |
|
| 118 | - * @return EE_Payment |
|
| 119 | - * @throws EE_Error |
|
| 120 | - * @throws ReflectionException |
|
| 121 | - */ |
|
| 122 | - public static function createPayment(EE_Transaction $transaction, EE_Payment_Method $payment_method): EE_Payment |
|
| 123 | - { |
|
| 124 | - // No payment for this transaction was created at this point. |
|
| 125 | - $payment = EE_Payment::new_instance([ |
|
| 126 | - 'PAY_timestamp' => time(), |
|
| 127 | - 'TXN_ID' => $transaction->ID(), |
|
| 128 | - 'PMD_ID' => $payment_method->ID(), |
|
| 129 | - 'PAY_po_number' => null, |
|
| 130 | - 'PAY_extra_accntng' => null, |
|
| 131 | - 'PAY_details' => null, |
|
| 132 | - ]); |
|
| 133 | - $payment->save(); |
|
| 134 | - return $payment; |
|
| 135 | - } |
|
| 113 | + /** |
|
| 114 | + * Create an EE Payment. |
|
| 115 | + * |
|
| 116 | + * @param EE_Transaction $transaction |
|
| 117 | + * @param EE_Payment_Method $payment_method |
|
| 118 | + * @return EE_Payment |
|
| 119 | + * @throws EE_Error |
|
| 120 | + * @throws ReflectionException |
|
| 121 | + */ |
|
| 122 | + public static function createPayment(EE_Transaction $transaction, EE_Payment_Method $payment_method): EE_Payment |
|
| 123 | + { |
|
| 124 | + // No payment for this transaction was created at this point. |
|
| 125 | + $payment = EE_Payment::new_instance([ |
|
| 126 | + 'PAY_timestamp' => time(), |
|
| 127 | + 'TXN_ID' => $transaction->ID(), |
|
| 128 | + 'PMD_ID' => $payment_method->ID(), |
|
| 129 | + 'PAY_po_number' => null, |
|
| 130 | + 'PAY_extra_accntng' => null, |
|
| 131 | + 'PAY_details' => null, |
|
| 132 | + ]); |
|
| 133 | + $payment->save(); |
|
| 134 | + return $payment; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Set a payment error and log the data. |
|
| 140 | - * |
|
| 141 | - * @param EE_Payment $payment |
|
| 142 | - * @param string $status |
|
| 143 | - * @param array|string $response_data |
|
| 144 | - * @param string $update_message |
|
| 145 | - * @return EE_Payment |
|
| 146 | - * @throws EE_Error|ReflectionException |
|
| 147 | - */ |
|
| 148 | - public static function updatePaymentStatus( |
|
| 149 | - EE_Payment $payment, |
|
| 150 | - string $status, |
|
| 151 | - $response_data, |
|
| 152 | - string $update_message = '' |
|
| 153 | - ): EE_Payment { |
|
| 154 | - $paypal_pm = ! empty($payment->payment_method()) |
|
| 155 | - ? EEM_Payment_Method::instance()->get_one_by_slug($payment->payment_method()->name()) |
|
| 156 | - : null; |
|
| 157 | - // Is this a successful payment ? |
|
| 158 | - if ($status === EEM_Payment::status_id_approved) { |
|
| 159 | - $default_message = esc_html__('Successful payment.', 'event_espresso'); |
|
| 160 | - $amount = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0; |
|
| 161 | - // Don't set the amount if there is no info on that with this order. |
|
| 162 | - if (! empty($amount)) { |
|
| 163 | - $payment->set_amount((float) $amount); |
|
| 164 | - } |
|
| 165 | - $payment->set_txn_id_chq_nmbr( |
|
| 166 | - $order['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id'] |
|
| 167 | - ); |
|
| 168 | - } else { |
|
| 169 | - $default_message = sprintf( |
|
| 170 | - esc_html__( |
|
| 171 | - 'Your payment could not be processed successfully due to a technical issue.%1$sPlease try again or contact%2$s for assistance.', |
|
| 172 | - 'event_espresso' |
|
| 173 | - ), |
|
| 174 | - '<br/>', |
|
| 175 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 176 | - ); |
|
| 177 | - } |
|
| 178 | - $log_message = $update_message ?: $default_message; |
|
| 179 | - PayPalLogger::errorLog($log_message, $response_data, $paypal_pm, false, $payment->transaction()); |
|
| 180 | - $payment->set_status($status); |
|
| 181 | - $payment->set_details($log_message); |
|
| 182 | - $payment->set_gateway_response($log_message); |
|
| 183 | - $payment->save(); |
|
| 184 | - return $payment; |
|
| 185 | - } |
|
| 138 | + /** |
|
| 139 | + * Set a payment error and log the data. |
|
| 140 | + * |
|
| 141 | + * @param EE_Payment $payment |
|
| 142 | + * @param string $status |
|
| 143 | + * @param array|string $response_data |
|
| 144 | + * @param string $update_message |
|
| 145 | + * @return EE_Payment |
|
| 146 | + * @throws EE_Error|ReflectionException |
|
| 147 | + */ |
|
| 148 | + public static function updatePaymentStatus( |
|
| 149 | + EE_Payment $payment, |
|
| 150 | + string $status, |
|
| 151 | + $response_data, |
|
| 152 | + string $update_message = '' |
|
| 153 | + ): EE_Payment { |
|
| 154 | + $paypal_pm = ! empty($payment->payment_method()) |
|
| 155 | + ? EEM_Payment_Method::instance()->get_one_by_slug($payment->payment_method()->name()) |
|
| 156 | + : null; |
|
| 157 | + // Is this a successful payment ? |
|
| 158 | + if ($status === EEM_Payment::status_id_approved) { |
|
| 159 | + $default_message = esc_html__('Successful payment.', 'event_espresso'); |
|
| 160 | + $amount = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0; |
|
| 161 | + // Don't set the amount if there is no info on that with this order. |
|
| 162 | + if (! empty($amount)) { |
|
| 163 | + $payment->set_amount((float) $amount); |
|
| 164 | + } |
|
| 165 | + $payment->set_txn_id_chq_nmbr( |
|
| 166 | + $order['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id'] |
|
| 167 | + ); |
|
| 168 | + } else { |
|
| 169 | + $default_message = sprintf( |
|
| 170 | + esc_html__( |
|
| 171 | + 'Your payment could not be processed successfully due to a technical issue.%1$sPlease try again or contact%2$s for assistance.', |
|
| 172 | + 'event_espresso' |
|
| 173 | + ), |
|
| 174 | + '<br/>', |
|
| 175 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 176 | + ); |
|
| 177 | + } |
|
| 178 | + $log_message = $update_message ?: $default_message; |
|
| 179 | + PayPalLogger::errorLog($log_message, $response_data, $paypal_pm, false, $payment->transaction()); |
|
| 180 | + $payment->set_status($status); |
|
| 181 | + $payment->set_details($log_message); |
|
| 182 | + $payment->set_gateway_response($log_message); |
|
| 183 | + $payment->save(); |
|
| 184 | + return $payment; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Get PayPal order if already created for this transaction and saved. |
|
| 190 | - * |
|
| 191 | - * @param EE_Payment_Method $paypal_pm |
|
| 192 | - * @param int $TXN_ID |
|
| 193 | - * @return array |
|
| 194 | - */ |
|
| 195 | - public static function getPpOrder(EE_Payment_Method $paypal_pm, int $TXN_ID): array |
|
| 196 | - { |
|
| 197 | - try { |
|
| 198 | - $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
|
| 199 | - return $pp_orders[ $TXN_ID ] ?? []; |
|
| 200 | - } catch (Exception $exception) { |
|
| 201 | - return []; |
|
| 202 | - } |
|
| 203 | - } |
|
| 188 | + /** |
|
| 189 | + * Get PayPal order if already created for this transaction and saved. |
|
| 190 | + * |
|
| 191 | + * @param EE_Payment_Method $paypal_pm |
|
| 192 | + * @param int $TXN_ID |
|
| 193 | + * @return array |
|
| 194 | + */ |
|
| 195 | + public static function getPpOrder(EE_Payment_Method $paypal_pm, int $TXN_ID): array |
|
| 196 | + { |
|
| 197 | + try { |
|
| 198 | + $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
|
| 199 | + return $pp_orders[ $TXN_ID ] ?? []; |
|
| 200 | + } catch (Exception $exception) { |
|
| 201 | + return []; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Update PayPal order for this transaction. |
|
| 208 | - * |
|
| 209 | - * @param $order |
|
| 210 | - * @param EE_Payment_Method $paypal_pm |
|
| 211 | - * @param int $TXN_ID |
|
| 212 | - * @return bool |
|
| 213 | - */ |
|
| 214 | - public static function updatePpOrder($order, EE_Payment_Method $paypal_pm, int $TXN_ID): bool |
|
| 215 | - { |
|
| 216 | - try { |
|
| 217 | - $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
|
| 218 | - $pp_orders[ $TXN_ID ] = $order; |
|
| 219 | - return PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS, $pp_orders); |
|
| 220 | - } catch (Exception $exception) { |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 223 | - } |
|
| 206 | + /** |
|
| 207 | + * Update PayPal order for this transaction. |
|
| 208 | + * |
|
| 209 | + * @param $order |
|
| 210 | + * @param EE_Payment_Method $paypal_pm |
|
| 211 | + * @param int $TXN_ID |
|
| 212 | + * @return bool |
|
| 213 | + */ |
|
| 214 | + public static function updatePpOrder($order, EE_Payment_Method $paypal_pm, int $TXN_ID): bool |
|
| 215 | + { |
|
| 216 | + try { |
|
| 217 | + $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
|
| 218 | + $pp_orders[ $TXN_ID ] = $order; |
|
| 219 | + return PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS, $pp_orders); |
|
| 220 | + } catch (Exception $exception) { |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Delete PP Order associated with the provided transaction. |
|
| 228 | - * |
|
| 229 | - * @param EE_Payment_Method $paypal_pm |
|
| 230 | - * @param int $TXN_ID |
|
| 231 | - * @return bool |
|
| 232 | - */ |
|
| 233 | - public static function deletePpOrder(EE_Payment_Method $paypal_pm, int $TXN_ID): bool |
|
| 234 | - { |
|
| 235 | - try { |
|
| 236 | - $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
|
| 237 | - unset($pp_orders[ $TXN_ID ]); |
|
| 238 | - return PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS, $pp_orders); |
|
| 239 | - } catch (Exception $exception) { |
|
| 240 | - return false; |
|
| 241 | - } |
|
| 242 | - } |
|
| 226 | + /** |
|
| 227 | + * Delete PP Order associated with the provided transaction. |
|
| 228 | + * |
|
| 229 | + * @param EE_Payment_Method $paypal_pm |
|
| 230 | + * @param int $TXN_ID |
|
| 231 | + * @return bool |
|
| 232 | + */ |
|
| 233 | + public static function deletePpOrder(EE_Payment_Method $paypal_pm, int $TXN_ID): bool |
|
| 234 | + { |
|
| 235 | + try { |
|
| 236 | + $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
|
| 237 | + unset($pp_orders[ $TXN_ID ]); |
|
| 238 | + return PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS, $pp_orders); |
|
| 239 | + } catch (Exception $exception) { |
|
| 240 | + return false; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Save some transaction details, like billing information. |
|
| 247 | - * |
|
| 248 | - * @param EE_Payment $payment |
|
| 249 | - * @param EE_Transaction $transaction |
|
| 250 | - * @param array $order |
|
| 251 | - * @param array $billing_info |
|
| 252 | - * @return void |
|
| 253 | - * @throws EE_Error |
|
| 254 | - * @throws ReflectionException |
|
| 255 | - */ |
|
| 256 | - public static function saveBillingDetails( |
|
| 257 | - EE_Payment $payment, |
|
| 258 | - EE_Transaction $transaction, |
|
| 259 | - array $order, |
|
| 260 | - array $billing_info |
|
| 261 | - ): void { |
|
| 262 | - $primary_reg = $transaction->primary_registration(); |
|
| 263 | - $attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null; |
|
| 264 | - $payment_method = $transaction->payment_method(); |
|
| 265 | - $postmeta_name = $payment_method->type_obj() instanceof EE_PMT_Base |
|
| 266 | - ? 'billing_info_' . $payment_method->type_obj()->system_name() |
|
| 267 | - : ''; |
|
| 268 | - if (empty($order['payment_source']) || ! $attendee instanceof EE_Attendee) { |
|
| 269 | - // I guess we are done here then. Just save what we have. |
|
| 270 | - $payment->set_details($order); |
|
| 271 | - return; |
|
| 272 | - } |
|
| 273 | - // Do we have order information from the express checkout (PayPal button) ? |
|
| 274 | - $billing_info['first_name'] = $billing_info['first_name'] ?? $attendee->fname(); |
|
| 275 | - $billing_info['last_name'] = $billing_info['last_name'] ?? $attendee->lname(); |
|
| 276 | - $billing_info['email'] = $billing_info['email'] ?? $attendee->email(); |
|
| 277 | - if (! empty($billing_info['address'])) { |
|
| 278 | - $attendee->set_address($billing_info['address']); |
|
| 279 | - } |
|
| 280 | - if (! empty($billing_info['address_2'])) { |
|
| 281 | - $attendee->set_address2($billing_info['address_2']); |
|
| 282 | - } |
|
| 283 | - if (! empty($billing_info['city'])) { |
|
| 284 | - $attendee->set_city($billing_info['city']); |
|
| 285 | - } |
|
| 286 | - if (! empty($billing_info['state_id'])) { |
|
| 287 | - $attendee->set_state((int) $billing_info['state_id']); |
|
| 288 | - } |
|
| 289 | - if (! empty($billing_info['country'])) { |
|
| 290 | - $attendee->set_country($billing_info['country']); |
|
| 291 | - } |
|
| 292 | - if (! empty($billing_info['zip'])) { |
|
| 293 | - $attendee->set_zip($billing_info['zip']); |
|
| 294 | - } |
|
| 295 | - // Or card information from ACDC ? |
|
| 296 | - if (! empty($order['payment_source']['card'])) { |
|
| 297 | - $payer_card = $order['payment_source']['card']; |
|
| 298 | - if (! empty($payer_card['name'])) { |
|
| 299 | - $full_name = explode(' ', $payer_card['name']); |
|
| 300 | - // Don't need to save each field because others should be populated from the billing form. |
|
| 301 | - $billing_info['credit_card'] = $payer_card['last_digits'] ?? ''; |
|
| 302 | - $billing_info['first_name'] = $full_name[0] ?? $attendee->fname(); |
|
| 303 | - $billing_info['last_name'] = $full_name[1] ?? $attendee->lname(); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - update_post_meta($attendee->ID(), $postmeta_name, $billing_info); |
|
| 307 | - $attendee->save(); |
|
| 308 | - } |
|
| 245 | + /** |
|
| 246 | + * Save some transaction details, like billing information. |
|
| 247 | + * |
|
| 248 | + * @param EE_Payment $payment |
|
| 249 | + * @param EE_Transaction $transaction |
|
| 250 | + * @param array $order |
|
| 251 | + * @param array $billing_info |
|
| 252 | + * @return void |
|
| 253 | + * @throws EE_Error |
|
| 254 | + * @throws ReflectionException |
|
| 255 | + */ |
|
| 256 | + public static function saveBillingDetails( |
|
| 257 | + EE_Payment $payment, |
|
| 258 | + EE_Transaction $transaction, |
|
| 259 | + array $order, |
|
| 260 | + array $billing_info |
|
| 261 | + ): void { |
|
| 262 | + $primary_reg = $transaction->primary_registration(); |
|
| 263 | + $attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null; |
|
| 264 | + $payment_method = $transaction->payment_method(); |
|
| 265 | + $postmeta_name = $payment_method->type_obj() instanceof EE_PMT_Base |
|
| 266 | + ? 'billing_info_' . $payment_method->type_obj()->system_name() |
|
| 267 | + : ''; |
|
| 268 | + if (empty($order['payment_source']) || ! $attendee instanceof EE_Attendee) { |
|
| 269 | + // I guess we are done here then. Just save what we have. |
|
| 270 | + $payment->set_details($order); |
|
| 271 | + return; |
|
| 272 | + } |
|
| 273 | + // Do we have order information from the express checkout (PayPal button) ? |
|
| 274 | + $billing_info['first_name'] = $billing_info['first_name'] ?? $attendee->fname(); |
|
| 275 | + $billing_info['last_name'] = $billing_info['last_name'] ?? $attendee->lname(); |
|
| 276 | + $billing_info['email'] = $billing_info['email'] ?? $attendee->email(); |
|
| 277 | + if (! empty($billing_info['address'])) { |
|
| 278 | + $attendee->set_address($billing_info['address']); |
|
| 279 | + } |
|
| 280 | + if (! empty($billing_info['address_2'])) { |
|
| 281 | + $attendee->set_address2($billing_info['address_2']); |
|
| 282 | + } |
|
| 283 | + if (! empty($billing_info['city'])) { |
|
| 284 | + $attendee->set_city($billing_info['city']); |
|
| 285 | + } |
|
| 286 | + if (! empty($billing_info['state_id'])) { |
|
| 287 | + $attendee->set_state((int) $billing_info['state_id']); |
|
| 288 | + } |
|
| 289 | + if (! empty($billing_info['country'])) { |
|
| 290 | + $attendee->set_country($billing_info['country']); |
|
| 291 | + } |
|
| 292 | + if (! empty($billing_info['zip'])) { |
|
| 293 | + $attendee->set_zip($billing_info['zip']); |
|
| 294 | + } |
|
| 295 | + // Or card information from ACDC ? |
|
| 296 | + if (! empty($order['payment_source']['card'])) { |
|
| 297 | + $payer_card = $order['payment_source']['card']; |
|
| 298 | + if (! empty($payer_card['name'])) { |
|
| 299 | + $full_name = explode(' ', $payer_card['name']); |
|
| 300 | + // Don't need to save each field because others should be populated from the billing form. |
|
| 301 | + $billing_info['credit_card'] = $payer_card['last_digits'] ?? ''; |
|
| 302 | + $billing_info['first_name'] = $full_name[0] ?? $attendee->fname(); |
|
| 303 | + $billing_info['last_name'] = $full_name[1] ?? $attendee->lname(); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + update_post_meta($attendee->ID(), $postmeta_name, $billing_info); |
|
| 307 | + $attendee->save(); |
|
| 308 | + } |
|
| 309 | 309 | } |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | 'completed' => false, |
| 78 | 78 | 'message' => esc_html__('Could not validate this Order.', 'event_espresso'), |
| 79 | 79 | ]; |
| 80 | - if (! empty($order) && ! empty($provided_order_id) && $order['id'] !== $provided_order_id) { |
|
| 80 | + if ( ! empty($order) && ! empty($provided_order_id) && $order['id'] !== $provided_order_id) { |
|
| 81 | 81 | $conclusion['message'] = esc_html__('Order ID mismatch.', 'event_espresso'); |
| 82 | 82 | } |
| 83 | - if (! $order || ! is_array($order)) { |
|
| 83 | + if ( ! $order || ! is_array($order)) { |
|
| 84 | 84 | $conclusion['message'] = esc_html__('The Order data is incorrectly formatted.', 'event_espresso'); |
| 85 | 85 | } elseif (empty($order['status'])) { |
| 86 | 86 | $conclusion['message'] = esc_html__( |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $default_message = esc_html__('Successful payment.', 'event_espresso'); |
| 160 | 160 | $amount = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0; |
| 161 | 161 | // Don't set the amount if there is no info on that with this order. |
| 162 | - if (! empty($amount)) { |
|
| 162 | + if ( ! empty($amount)) { |
|
| 163 | 163 | $payment->set_amount((float) $amount); |
| 164 | 164 | } |
| 165 | 165 | $payment->set_txn_id_chq_nmbr( |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | { |
| 197 | 197 | try { |
| 198 | 198 | $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
| 199 | - return $pp_orders[ $TXN_ID ] ?? []; |
|
| 199 | + return $pp_orders[$TXN_ID] ?? []; |
|
| 200 | 200 | } catch (Exception $exception) { |
| 201 | 201 | return []; |
| 202 | 202 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | { |
| 216 | 216 | try { |
| 217 | 217 | $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
| 218 | - $pp_orders[ $TXN_ID ] = $order; |
|
| 218 | + $pp_orders[$TXN_ID] = $order; |
|
| 219 | 219 | return PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS, $pp_orders); |
| 220 | 220 | } catch (Exception $exception) { |
| 221 | 221 | return false; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | { |
| 235 | 235 | try { |
| 236 | 236 | $pp_orders = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS) ?? []; |
| 237 | - unset($pp_orders[ $TXN_ID ]); |
|
| 237 | + unset($pp_orders[$TXN_ID]); |
|
| 238 | 238 | return PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_PAYPAL_ORDERS, $pp_orders); |
| 239 | 239 | } catch (Exception $exception) { |
| 240 | 240 | return false; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | $attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null; |
| 264 | 264 | $payment_method = $transaction->payment_method(); |
| 265 | 265 | $postmeta_name = $payment_method->type_obj() instanceof EE_PMT_Base |
| 266 | - ? 'billing_info_' . $payment_method->type_obj()->system_name() |
|
| 266 | + ? 'billing_info_'.$payment_method->type_obj()->system_name() |
|
| 267 | 267 | : ''; |
| 268 | 268 | if (empty($order['payment_source']) || ! $attendee instanceof EE_Attendee) { |
| 269 | 269 | // I guess we are done here then. Just save what we have. |
@@ -274,28 +274,28 @@ discard block |
||
| 274 | 274 | $billing_info['first_name'] = $billing_info['first_name'] ?? $attendee->fname(); |
| 275 | 275 | $billing_info['last_name'] = $billing_info['last_name'] ?? $attendee->lname(); |
| 276 | 276 | $billing_info['email'] = $billing_info['email'] ?? $attendee->email(); |
| 277 | - if (! empty($billing_info['address'])) { |
|
| 277 | + if ( ! empty($billing_info['address'])) { |
|
| 278 | 278 | $attendee->set_address($billing_info['address']); |
| 279 | 279 | } |
| 280 | - if (! empty($billing_info['address_2'])) { |
|
| 280 | + if ( ! empty($billing_info['address_2'])) { |
|
| 281 | 281 | $attendee->set_address2($billing_info['address_2']); |
| 282 | 282 | } |
| 283 | - if (! empty($billing_info['city'])) { |
|
| 283 | + if ( ! empty($billing_info['city'])) { |
|
| 284 | 284 | $attendee->set_city($billing_info['city']); |
| 285 | 285 | } |
| 286 | - if (! empty($billing_info['state_id'])) { |
|
| 286 | + if ( ! empty($billing_info['state_id'])) { |
|
| 287 | 287 | $attendee->set_state((int) $billing_info['state_id']); |
| 288 | 288 | } |
| 289 | - if (! empty($billing_info['country'])) { |
|
| 289 | + if ( ! empty($billing_info['country'])) { |
|
| 290 | 290 | $attendee->set_country($billing_info['country']); |
| 291 | 291 | } |
| 292 | - if (! empty($billing_info['zip'])) { |
|
| 292 | + if ( ! empty($billing_info['zip'])) { |
|
| 293 | 293 | $attendee->set_zip($billing_info['zip']); |
| 294 | 294 | } |
| 295 | 295 | // Or card information from ACDC ? |
| 296 | - if (! empty($order['payment_source']['card'])) { |
|
| 296 | + if ( ! empty($order['payment_source']['card'])) { |
|
| 297 | 297 | $payer_card = $order['payment_source']['card']; |
| 298 | - if (! empty($payer_card['name'])) { |
|
| 298 | + if ( ! empty($payer_card['name'])) { |
|
| 299 | 299 | $full_name = explode(' ', $payer_card['name']); |
| 300 | 300 | // Don't need to save each field because others should be populated from the billing form. |
| 301 | 301 | $billing_info['credit_card'] = $payer_card['last_digits'] ?? ''; |
@@ -15,179 +15,179 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Domain |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Name of the extra meta key that stores this PM options as one meta. |
|
| 20 | - */ |
|
| 21 | - public const META_KEY_PAYPAL_DATA = 'paypal_data'; |
|
| 22 | - /** |
|
| 23 | - * Name of the extra meta key that stores this PM options as one meta. |
|
| 24 | - */ |
|
| 25 | - public const META_KEY_PAYPAL_DATA_SANDBOX = 'paypal_data_sandbox'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Name of the extra meta that stores whether the credentials were for the sandbox or live mode. |
|
| 29 | - */ |
|
| 30 | - public const META_KEY_SANDBOX_MODE = 'sandbox_mode'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Name of the extra meta that stores the Access Token that is used to auth in API requests to PayPal. |
|
| 34 | - */ |
|
| 35 | - public const META_KEY_ACCESS_TOKEN = 'access_token'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Name of the extra meta that stores the last request tracking ID. |
|
| 39 | - */ |
|
| 40 | - public const META_KEY_TRACKING_ID = 'tracking_id'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Name of the extra meta that stores the Event Espresso PayPal Account's merchant id. |
|
| 44 | - */ |
|
| 45 | - public const META_KEY_APP_ID = 'app_id'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Name of the extra meta that holds the seller client ID. |
|
| 49 | - */ |
|
| 50 | - public const META_KEY_CLIENT_ID = 'client_id'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Name of the extra meta that holds the seller secret. |
|
| 54 | - */ |
|
| 55 | - public const META_KEY_CLIENT_SECRET = 'client_secret'; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Name of the extra meta that stores the expiration date of the Access Token. |
|
| 59 | - */ |
|
| 60 | - public const META_KEY_TOKEN_EXPIRES_IN = 'expires_in'; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Name of the extra meta that holds the partner client ID. |
|
| 64 | - */ |
|
| 65 | - public const META_KEY_PARTNER_CLIENT_ID = 'partner_client_id'; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Name of the extra meta that holds the partner merchant ID. |
|
| 69 | - */ |
|
| 70 | - public const META_KEY_PARTNER_MERCHANT_ID = 'partner_merchant_id'; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Name of the extra meta that holds the seller merchant ID. |
|
| 74 | - */ |
|
| 75 | - public const META_KEY_SELLER_MERCHANT_ID = 'merchantIdInPayPal'; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Name of the extra meta that holds the onboarding URL. |
|
| 79 | - */ |
|
| 80 | - public const META_KEY_ONBOARDING_URL = 'onboarding_url'; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Name of the extra meta that holds the BN / request tracking code. |
|
| 84 | - */ |
|
| 85 | - public const META_KEY_BN_CODE = 'bn_code'; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Name of the extra meta that holds the last order details. |
|
| 89 | - */ |
|
| 90 | - public const META_KEY_LAST_ORDER = 'last_order_details'; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Name of the extra meta that holds the list of in progress orders. |
|
| 94 | - */ |
|
| 95 | - public const META_KEY_PAYPAL_ORDERS = 'paypal_orders_list'; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Name of the extra meta that stores the allowed PP checkout type selected by merchant while onboarding. |
|
| 99 | - */ |
|
| 100 | - public const META_KEY_ALLOWED_CHECKOUT_TYPE = 'allowed_checkout_type'; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Name of the extra meta that stores the merchant authorized scopes for our app to work within. |
|
| 104 | - */ |
|
| 105 | - public const META_KEY_AUTHORIZED_SCOPES = 'authorized_scopes'; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Name of the extra meta that stores the PP checkout type selected by merchant after onboarding. |
|
| 109 | - */ |
|
| 110 | - public const META_KEY_CHECKOUT_TYPE = 'checkout_type'; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Name of the PayPal API parameter that holds the auth code. |
|
| 114 | - */ |
|
| 115 | - public const API_KEY_AUTH_CODE = 'authCode'; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Name of the PayPal API parameter that holds the client token. |
|
| 119 | - */ |
|
| 120 | - public const API_KEY_CLIENT_TOKEN = 'client_token'; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Name of the extra meta that holds the seller payer ID. |
|
| 124 | - */ |
|
| 125 | - public const META_KEY_PAYER_ID = 'payer_id'; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Name of the PayPal API parameter that holds the client token expiration time. |
|
| 129 | - */ |
|
| 130 | - public const API_KEY_EXPIRES_IN = 'expires_in'; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Name of the PayPal API parameter that holds the list of oAuth integrations related to the merchant. |
|
| 134 | - */ |
|
| 135 | - public const API_PARAM_OAUTH_INTEGRATIONS = 'oauth_integrations'; |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Name of the PayPal API parameter that holds the list of third party permissions that were granted. |
|
| 139 | - */ |
|
| 140 | - public const API_PARAM_PERMISSIONS_GRANTED = 'oauth_third_party'; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Name of the PayPal API parameter that holds the bool of if the primary email was confirmed. |
|
| 144 | - */ |
|
| 145 | - public const API_PARAM_PRIM_EMAIL_CONFIRMED = 'primary_email_confirmed'; |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Name of the PayPal API parameter that holds the bool of if email was confirmed. |
|
| 149 | - */ |
|
| 150 | - public const API_PARAM_EMAIL_CONFIRMED = 'isEmailConfirmed'; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Name of the PayPal API parameter that holds the partner ID. |
|
| 154 | - */ |
|
| 155 | - public const API_PARAM_PARTNER_ID = 'merchantId'; |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Name of the PayPal API parameter that holds the merchant ID in the Track seller onboarding status request. |
|
| 159 | - */ |
|
| 160 | - public const API_PARAM_TRACK_MERCHANT_ID = 'merchant_id'; |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Name of the PayPal API parameter that holds the payments_receivable status. |
|
| 164 | - */ |
|
| 165 | - public const API_PARAM_PAYMENTS_RECEIVABLE = 'payments_receivable'; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Name of the nonce used in the capture order request. |
|
| 169 | - */ |
|
| 170 | - public const CAPTURE_ORDER_NONCE_NAME = 'eea_pp_commerce_capture_order_payment'; |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Name of the nonce used in the onboarding process. |
|
| 174 | - */ |
|
| 175 | - public const NONCE_NAME_ONBOARDING_RETURN = 'eea_pp_commerce_onboarding_return'; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Holds this payment method slug. |
|
| 179 | - */ |
|
| 180 | - public const PM_SLUG = 'paypalcheckout'; |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Returns the base PayPal API URL. |
|
| 185 | - * |
|
| 186 | - * @param EE_Payment_Method $payment_method |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public static function getPayPalApiUrl(EE_Payment_Method $payment_method): string |
|
| 190 | - { |
|
| 191 | - return $payment_method->debug_mode() ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com'; |
|
| 192 | - } |
|
| 18 | + /** |
|
| 19 | + * Name of the extra meta key that stores this PM options as one meta. |
|
| 20 | + */ |
|
| 21 | + public const META_KEY_PAYPAL_DATA = 'paypal_data'; |
|
| 22 | + /** |
|
| 23 | + * Name of the extra meta key that stores this PM options as one meta. |
|
| 24 | + */ |
|
| 25 | + public const META_KEY_PAYPAL_DATA_SANDBOX = 'paypal_data_sandbox'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Name of the extra meta that stores whether the credentials were for the sandbox or live mode. |
|
| 29 | + */ |
|
| 30 | + public const META_KEY_SANDBOX_MODE = 'sandbox_mode'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Name of the extra meta that stores the Access Token that is used to auth in API requests to PayPal. |
|
| 34 | + */ |
|
| 35 | + public const META_KEY_ACCESS_TOKEN = 'access_token'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Name of the extra meta that stores the last request tracking ID. |
|
| 39 | + */ |
|
| 40 | + public const META_KEY_TRACKING_ID = 'tracking_id'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Name of the extra meta that stores the Event Espresso PayPal Account's merchant id. |
|
| 44 | + */ |
|
| 45 | + public const META_KEY_APP_ID = 'app_id'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Name of the extra meta that holds the seller client ID. |
|
| 49 | + */ |
|
| 50 | + public const META_KEY_CLIENT_ID = 'client_id'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Name of the extra meta that holds the seller secret. |
|
| 54 | + */ |
|
| 55 | + public const META_KEY_CLIENT_SECRET = 'client_secret'; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Name of the extra meta that stores the expiration date of the Access Token. |
|
| 59 | + */ |
|
| 60 | + public const META_KEY_TOKEN_EXPIRES_IN = 'expires_in'; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Name of the extra meta that holds the partner client ID. |
|
| 64 | + */ |
|
| 65 | + public const META_KEY_PARTNER_CLIENT_ID = 'partner_client_id'; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Name of the extra meta that holds the partner merchant ID. |
|
| 69 | + */ |
|
| 70 | + public const META_KEY_PARTNER_MERCHANT_ID = 'partner_merchant_id'; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Name of the extra meta that holds the seller merchant ID. |
|
| 74 | + */ |
|
| 75 | + public const META_KEY_SELLER_MERCHANT_ID = 'merchantIdInPayPal'; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Name of the extra meta that holds the onboarding URL. |
|
| 79 | + */ |
|
| 80 | + public const META_KEY_ONBOARDING_URL = 'onboarding_url'; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Name of the extra meta that holds the BN / request tracking code. |
|
| 84 | + */ |
|
| 85 | + public const META_KEY_BN_CODE = 'bn_code'; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Name of the extra meta that holds the last order details. |
|
| 89 | + */ |
|
| 90 | + public const META_KEY_LAST_ORDER = 'last_order_details'; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Name of the extra meta that holds the list of in progress orders. |
|
| 94 | + */ |
|
| 95 | + public const META_KEY_PAYPAL_ORDERS = 'paypal_orders_list'; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Name of the extra meta that stores the allowed PP checkout type selected by merchant while onboarding. |
|
| 99 | + */ |
|
| 100 | + public const META_KEY_ALLOWED_CHECKOUT_TYPE = 'allowed_checkout_type'; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Name of the extra meta that stores the merchant authorized scopes for our app to work within. |
|
| 104 | + */ |
|
| 105 | + public const META_KEY_AUTHORIZED_SCOPES = 'authorized_scopes'; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Name of the extra meta that stores the PP checkout type selected by merchant after onboarding. |
|
| 109 | + */ |
|
| 110 | + public const META_KEY_CHECKOUT_TYPE = 'checkout_type'; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Name of the PayPal API parameter that holds the auth code. |
|
| 114 | + */ |
|
| 115 | + public const API_KEY_AUTH_CODE = 'authCode'; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Name of the PayPal API parameter that holds the client token. |
|
| 119 | + */ |
|
| 120 | + public const API_KEY_CLIENT_TOKEN = 'client_token'; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Name of the extra meta that holds the seller payer ID. |
|
| 124 | + */ |
|
| 125 | + public const META_KEY_PAYER_ID = 'payer_id'; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Name of the PayPal API parameter that holds the client token expiration time. |
|
| 129 | + */ |
|
| 130 | + public const API_KEY_EXPIRES_IN = 'expires_in'; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Name of the PayPal API parameter that holds the list of oAuth integrations related to the merchant. |
|
| 134 | + */ |
|
| 135 | + public const API_PARAM_OAUTH_INTEGRATIONS = 'oauth_integrations'; |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Name of the PayPal API parameter that holds the list of third party permissions that were granted. |
|
| 139 | + */ |
|
| 140 | + public const API_PARAM_PERMISSIONS_GRANTED = 'oauth_third_party'; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Name of the PayPal API parameter that holds the bool of if the primary email was confirmed. |
|
| 144 | + */ |
|
| 145 | + public const API_PARAM_PRIM_EMAIL_CONFIRMED = 'primary_email_confirmed'; |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Name of the PayPal API parameter that holds the bool of if email was confirmed. |
|
| 149 | + */ |
|
| 150 | + public const API_PARAM_EMAIL_CONFIRMED = 'isEmailConfirmed'; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Name of the PayPal API parameter that holds the partner ID. |
|
| 154 | + */ |
|
| 155 | + public const API_PARAM_PARTNER_ID = 'merchantId'; |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Name of the PayPal API parameter that holds the merchant ID in the Track seller onboarding status request. |
|
| 159 | + */ |
|
| 160 | + public const API_PARAM_TRACK_MERCHANT_ID = 'merchant_id'; |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Name of the PayPal API parameter that holds the payments_receivable status. |
|
| 164 | + */ |
|
| 165 | + public const API_PARAM_PAYMENTS_RECEIVABLE = 'payments_receivable'; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Name of the nonce used in the capture order request. |
|
| 169 | + */ |
|
| 170 | + public const CAPTURE_ORDER_NONCE_NAME = 'eea_pp_commerce_capture_order_payment'; |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Name of the nonce used in the onboarding process. |
|
| 174 | + */ |
|
| 175 | + public const NONCE_NAME_ONBOARDING_RETURN = 'eea_pp_commerce_onboarding_return'; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Holds this payment method slug. |
|
| 179 | + */ |
|
| 180 | + public const PM_SLUG = 'paypalcheckout'; |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Returns the base PayPal API URL. |
|
| 185 | + * |
|
| 186 | + * @param EE_Payment_Method $payment_method |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public static function getPayPalApiUrl(EE_Payment_Method $payment_method): string |
|
| 190 | + { |
|
| 191 | + return $payment_method->debug_mode() ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com'; |
|
| 192 | + } |
|
| 193 | 193 | } |
@@ -30,303 +30,303 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class CreateOrder extends OrdersApi |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * Line items total. |
|
| 35 | - * |
|
| 36 | - * @var float |
|
| 37 | - */ |
|
| 38 | - protected $items_total = 0; |
|
| 33 | + /** |
|
| 34 | + * Line items total. |
|
| 35 | + * |
|
| 36 | + * @var float |
|
| 37 | + */ |
|
| 38 | + protected $items_total = 0; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Promotions total. |
|
| 42 | - * |
|
| 43 | - * @var float |
|
| 44 | - */ |
|
| 45 | - protected $promos_total = 0; |
|
| 40 | + /** |
|
| 41 | + * Promotions total. |
|
| 42 | + * |
|
| 43 | + * @var float |
|
| 44 | + */ |
|
| 45 | + protected $promos_total = 0; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Tax total. |
|
| 49 | - * |
|
| 50 | - * @var float |
|
| 51 | - */ |
|
| 52 | - protected $tax_total = 0; |
|
| 47 | + /** |
|
| 48 | + * Tax total. |
|
| 49 | + * |
|
| 50 | + * @var float |
|
| 51 | + */ |
|
| 52 | + protected $tax_total = 0; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Currency. |
|
| 56 | - * |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected string $currency_code; |
|
| 54 | + /** |
|
| 55 | + * Currency. |
|
| 56 | + * |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected string $currency_code; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Billing info. |
|
| 63 | - * |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 66 | - protected array $billing_info; |
|
| 61 | + /** |
|
| 62 | + * Billing info. |
|
| 63 | + * |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | + protected array $billing_info; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Transaction this order is for. |
|
| 70 | - * |
|
| 71 | - * @var EE_Transaction |
|
| 72 | - */ |
|
| 73 | - protected EE_Transaction $transaction; |
|
| 68 | + /** |
|
| 69 | + * Transaction this order is for. |
|
| 70 | + * |
|
| 71 | + * @var EE_Transaction |
|
| 72 | + */ |
|
| 73 | + protected EE_Transaction $transaction; |
|
| 74 | 74 | |
| 75 | - private FeatureFlags $feature; |
|
| 75 | + private FeatureFlags $feature; |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * CreateOrder constructor. |
|
| 80 | - * |
|
| 81 | - * @param PayPalApi $api |
|
| 82 | - * @param EE_Transaction $transaction |
|
| 83 | - * @param array $billing_info |
|
| 84 | - * @param FeatureFlags $feature |
|
| 85 | - */ |
|
| 86 | - public function __construct(PayPalApi $api, EE_Transaction $transaction, array $billing_info, FeatureFlags $feature) |
|
| 87 | - { |
|
| 88 | - parent::__construct($api); |
|
| 89 | - $this->transaction = $transaction; |
|
| 90 | - $this->feature = $feature; |
|
| 91 | - $this->currency_code = CurrencyManager::currencyCode(); |
|
| 92 | - $this->sanitizeRequestParameters($billing_info); |
|
| 93 | - } |
|
| 78 | + /** |
|
| 79 | + * CreateOrder constructor. |
|
| 80 | + * |
|
| 81 | + * @param PayPalApi $api |
|
| 82 | + * @param EE_Transaction $transaction |
|
| 83 | + * @param array $billing_info |
|
| 84 | + * @param FeatureFlags $feature |
|
| 85 | + */ |
|
| 86 | + public function __construct(PayPalApi $api, EE_Transaction $transaction, array $billing_info, FeatureFlags $feature) |
|
| 87 | + { |
|
| 88 | + parent::__construct($api); |
|
| 89 | + $this->transaction = $transaction; |
|
| 90 | + $this->feature = $feature; |
|
| 91 | + $this->currency_code = CurrencyManager::currencyCode(); |
|
| 92 | + $this->sanitizeRequestParameters($billing_info); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Sanitize the array of billing form data. |
|
| 98 | - * |
|
| 99 | - * @param array $billing_info |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 102 | - public function sanitizeRequestParameters(array $billing_info): void |
|
| 103 | - { |
|
| 104 | - $email_validator = new Basic(); |
|
| 105 | - $sanitizer = new RequestSanitizer($email_validator); |
|
| 106 | - foreach ($billing_info as $item => $value) { |
|
| 107 | - $this->billing_info[ $item ] = $sanitizer->clean($value); |
|
| 108 | - } |
|
| 109 | - } |
|
| 96 | + /** |
|
| 97 | + * Sanitize the array of billing form data. |
|
| 98 | + * |
|
| 99 | + * @param array $billing_info |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | + public function sanitizeRequestParameters(array $billing_info): void |
|
| 103 | + { |
|
| 104 | + $email_validator = new Basic(); |
|
| 105 | + $sanitizer = new RequestSanitizer($email_validator); |
|
| 106 | + foreach ($billing_info as $item => $value) { |
|
| 107 | + $this->billing_info[ $item ] = $sanitizer->clean($value); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Create PayPal Order. |
|
| 114 | - * |
|
| 115 | - * @return array |
|
| 116 | - * @throws EE_Error |
|
| 117 | - * @throws ReflectionException |
|
| 118 | - */ |
|
| 119 | - public function create(): array |
|
| 120 | - { |
|
| 121 | - $order_parameters = $this->getParameters(); |
|
| 122 | - // Create Order request. |
|
| 123 | - $create_response = $this->api->sendRequest($order_parameters, $this->request_url); |
|
| 124 | - return $this->validateOrder($create_response, $order_parameters); |
|
| 125 | - } |
|
| 112 | + /** |
|
| 113 | + * Create PayPal Order. |
|
| 114 | + * |
|
| 115 | + * @return array |
|
| 116 | + * @throws EE_Error |
|
| 117 | + * @throws ReflectionException |
|
| 118 | + */ |
|
| 119 | + public function create(): array |
|
| 120 | + { |
|
| 121 | + $order_parameters = $this->getParameters(); |
|
| 122 | + // Create Order request. |
|
| 123 | + $create_response = $this->api->sendRequest($order_parameters, $this->request_url); |
|
| 124 | + return $this->validateOrder($create_response, $order_parameters); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Form order parameters. |
|
| 130 | - * |
|
| 131 | - * @return array |
|
| 132 | - * @throws EE_Error |
|
| 133 | - * @throws ReflectionException |
|
| 134 | - * @throws Exception |
|
| 135 | - */ |
|
| 136 | - protected function getParameters(): array |
|
| 137 | - { |
|
| 138 | - $registrant = $this->transaction->primary_registration(); |
|
| 139 | - $attendee = $registrant->attendee(); |
|
| 140 | - $event = $registrant->event(); |
|
| 141 | - $description = $event->name() ?: sprintf( |
|
| 142 | - esc_html__('Tickets for an event at %1$s', 'event_espresso'), |
|
| 143 | - get_bloginfo('name') |
|
| 144 | - ); |
|
| 145 | - $parameters = [ |
|
| 146 | - 'intent' => 'CAPTURE', |
|
| 147 | - 'purchase_units' => [ |
|
| 148 | - [ |
|
| 149 | - 'custom_id' => $this->transaction->ID(), |
|
| 150 | - 'description' => substr(wp_strip_all_tags($description), 0, 125), |
|
| 151 | - 'items' => $this->getLineItems(), |
|
| 152 | - 'amount' => [ |
|
| 153 | - 'value' => $this->transaction->remaining(), |
|
| 154 | - 'currency_code' => $this->currency_code, |
|
| 155 | - 'breakdown' => $this->getBreakdown(), |
|
| 156 | - ], |
|
| 157 | - ], |
|
| 158 | - ], |
|
| 159 | - 'application_context' => [ |
|
| 160 | - 'shipping_preference' => 'NO_SHIPPING', |
|
| 161 | - 'user_action' => 'PAY_NOW', |
|
| 162 | - ], |
|
| 163 | - 'payer' => [ |
|
| 164 | - 'email_address' => $attendee->email(), |
|
| 165 | - 'name' => [ |
|
| 166 | - 'given_name' => $attendee->fname(), |
|
| 167 | - 'surname' => $attendee->lname(), |
|
| 128 | + /** |
|
| 129 | + * Form order parameters. |
|
| 130 | + * |
|
| 131 | + * @return array |
|
| 132 | + * @throws EE_Error |
|
| 133 | + * @throws ReflectionException |
|
| 134 | + * @throws Exception |
|
| 135 | + */ |
|
| 136 | + protected function getParameters(): array |
|
| 137 | + { |
|
| 138 | + $registrant = $this->transaction->primary_registration(); |
|
| 139 | + $attendee = $registrant->attendee(); |
|
| 140 | + $event = $registrant->event(); |
|
| 141 | + $description = $event->name() ?: sprintf( |
|
| 142 | + esc_html__('Tickets for an event at %1$s', 'event_espresso'), |
|
| 143 | + get_bloginfo('name') |
|
| 144 | + ); |
|
| 145 | + $parameters = [ |
|
| 146 | + 'intent' => 'CAPTURE', |
|
| 147 | + 'purchase_units' => [ |
|
| 148 | + [ |
|
| 149 | + 'custom_id' => $this->transaction->ID(), |
|
| 150 | + 'description' => substr(wp_strip_all_tags($description), 0, 125), |
|
| 151 | + 'items' => $this->getLineItems(), |
|
| 152 | + 'amount' => [ |
|
| 153 | + 'value' => $this->transaction->remaining(), |
|
| 154 | + 'currency_code' => $this->currency_code, |
|
| 155 | + 'breakdown' => $this->getBreakdown(), |
|
| 156 | + ], |
|
| 157 | + ], |
|
| 158 | + ], |
|
| 159 | + 'application_context' => [ |
|
| 160 | + 'shipping_preference' => 'NO_SHIPPING', |
|
| 161 | + 'user_action' => 'PAY_NOW', |
|
| 162 | + ], |
|
| 163 | + 'payer' => [ |
|
| 164 | + 'email_address' => $attendee->email(), |
|
| 165 | + 'name' => [ |
|
| 166 | + 'given_name' => $attendee->fname(), |
|
| 167 | + 'surname' => $attendee->lname(), |
|
| 168 | 168 | |
| 169 | - ], |
|
| 170 | - ], |
|
| 171 | - ]; |
|
| 172 | - // Do we have the permissions for the fees ? |
|
| 173 | - $scopes = PayPalExtraMetaManager::getPmOption( |
|
| 174 | - $this->transaction->payment_method(), |
|
| 175 | - Domain::META_KEY_AUTHORIZED_SCOPES |
|
| 176 | - ); |
|
| 177 | - if ( |
|
| 178 | - ( |
|
| 179 | - (defined('EE_PPC_USE_PAYMENT_FEES') && EE_PPC_USE_PAYMENT_FEES) |
|
| 180 | - || (! defined('EE_PPC_USE_PAYMENT_FEES') |
|
| 181 | - && $this->feature->allowed(FeatureFlag::USE_PAYMENT_PROCESSOR_FEES) |
|
| 182 | - ) |
|
| 183 | - ) |
|
| 184 | - && ! empty($scopes) && in_array('partnerfee', $scopes) |
|
| 185 | - ) { |
|
| 186 | - $payment_fees = LoaderFactory::getShared(PartnerPaymentFees::class); |
|
| 187 | - $parameters['purchase_units'][0]['payment_instruction'] = [ |
|
| 188 | - 'platform_fees' => [ |
|
| 189 | - [ |
|
| 190 | - 'amount' => [ |
|
| 191 | - 'value' => (string) $payment_fees->getPartnerFee($this->transaction), |
|
| 192 | - 'currency_code' => $this->currency_code, |
|
| 193 | - ], |
|
| 194 | - ], |
|
| 195 | - ] |
|
| 196 | - ]; |
|
| 197 | - } |
|
| 198 | - return $parameters; |
|
| 199 | - } |
|
| 169 | + ], |
|
| 170 | + ], |
|
| 171 | + ]; |
|
| 172 | + // Do we have the permissions for the fees ? |
|
| 173 | + $scopes = PayPalExtraMetaManager::getPmOption( |
|
| 174 | + $this->transaction->payment_method(), |
|
| 175 | + Domain::META_KEY_AUTHORIZED_SCOPES |
|
| 176 | + ); |
|
| 177 | + if ( |
|
| 178 | + ( |
|
| 179 | + (defined('EE_PPC_USE_PAYMENT_FEES') && EE_PPC_USE_PAYMENT_FEES) |
|
| 180 | + || (! defined('EE_PPC_USE_PAYMENT_FEES') |
|
| 181 | + && $this->feature->allowed(FeatureFlag::USE_PAYMENT_PROCESSOR_FEES) |
|
| 182 | + ) |
|
| 183 | + ) |
|
| 184 | + && ! empty($scopes) && in_array('partnerfee', $scopes) |
|
| 185 | + ) { |
|
| 186 | + $payment_fees = LoaderFactory::getShared(PartnerPaymentFees::class); |
|
| 187 | + $parameters['purchase_units'][0]['payment_instruction'] = [ |
|
| 188 | + 'platform_fees' => [ |
|
| 189 | + [ |
|
| 190 | + 'amount' => [ |
|
| 191 | + 'value' => (string) $payment_fees->getPartnerFee($this->transaction), |
|
| 192 | + 'currency_code' => $this->currency_code, |
|
| 193 | + ], |
|
| 194 | + ], |
|
| 195 | + ] |
|
| 196 | + ]; |
|
| 197 | + } |
|
| 198 | + return $parameters; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Itemize the payment. List all the line items, discounts and taxes. |
|
| 204 | - * |
|
| 205 | - * @return array |
|
| 206 | - * @throws EE_Error|ReflectionException |
|
| 207 | - */ |
|
| 208 | - protected function getLineItems(): array |
|
| 209 | - { |
|
| 210 | - // Order line items. |
|
| 211 | - $line_items = []; |
|
| 212 | - $event_line_items = $this->transaction->items_purchased(); |
|
| 213 | - // List actual line items. |
|
| 214 | - foreach ($event_line_items as $line_item) { |
|
| 215 | - if ( |
|
| 216 | - $line_item instanceof EE_Line_Item |
|
| 217 | - && $line_item->OBJ_type() !== 'Promotion' |
|
| 218 | - && $line_item->quantity() > 0 |
|
| 219 | - ) { |
|
| 220 | - $item_money = $line_item->unit_price(); |
|
| 221 | - $li_description = $line_item->desc() ?? esc_html__('Event Ticket', 'event_espresso'); |
|
| 222 | - $line_items [] = [ |
|
| 223 | - 'name' => substr(wp_strip_all_tags($line_item->name()), 0, 126), |
|
| 224 | - 'quantity' => $line_item->quantity(), |
|
| 225 | - 'description' => substr(wp_strip_all_tags($li_description), 0, 125), |
|
| 226 | - 'unit_amount' => [ |
|
| 227 | - 'currency_code' => $this->currency_code, |
|
| 228 | - 'value' => $item_money, |
|
| 229 | - ], |
|
| 230 | - 'category' => 'DIGITAL_GOODS', |
|
| 231 | - ]; |
|
| 232 | - // Line item total. |
|
| 233 | - $this->items_total += $line_item->pretaxTotal(); |
|
| 234 | - } elseif ($line_item->OBJ_type() === 'Promotion' && $line_item->quantity() > 0) { |
|
| 235 | - // Promotions total. |
|
| 236 | - $this->promos_total += $line_item->total(); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - // Make sure we have an absolute number with only two decimal laces. |
|
| 240 | - $this->items_total = CurrencyManager::normalizeValue($this->items_total); |
|
| 241 | - $this->promos_total = CurrencyManager::normalizeValue($this->promos_total); |
|
| 242 | - // If this is a partial payment, apply the paid amount as a promo. |
|
| 243 | - if ($this->transaction->paid() > 0) { |
|
| 244 | - $this->promos_total += CurrencyManager::normalizeValue($this->transaction->paid()); |
|
| 245 | - } |
|
| 246 | - $this->countTaxTotal(); |
|
| 247 | - return $line_items; |
|
| 248 | - } |
|
| 202 | + /** |
|
| 203 | + * Itemize the payment. List all the line items, discounts and taxes. |
|
| 204 | + * |
|
| 205 | + * @return array |
|
| 206 | + * @throws EE_Error|ReflectionException |
|
| 207 | + */ |
|
| 208 | + protected function getLineItems(): array |
|
| 209 | + { |
|
| 210 | + // Order line items. |
|
| 211 | + $line_items = []; |
|
| 212 | + $event_line_items = $this->transaction->items_purchased(); |
|
| 213 | + // List actual line items. |
|
| 214 | + foreach ($event_line_items as $line_item) { |
|
| 215 | + if ( |
|
| 216 | + $line_item instanceof EE_Line_Item |
|
| 217 | + && $line_item->OBJ_type() !== 'Promotion' |
|
| 218 | + && $line_item->quantity() > 0 |
|
| 219 | + ) { |
|
| 220 | + $item_money = $line_item->unit_price(); |
|
| 221 | + $li_description = $line_item->desc() ?? esc_html__('Event Ticket', 'event_espresso'); |
|
| 222 | + $line_items [] = [ |
|
| 223 | + 'name' => substr(wp_strip_all_tags($line_item->name()), 0, 126), |
|
| 224 | + 'quantity' => $line_item->quantity(), |
|
| 225 | + 'description' => substr(wp_strip_all_tags($li_description), 0, 125), |
|
| 226 | + 'unit_amount' => [ |
|
| 227 | + 'currency_code' => $this->currency_code, |
|
| 228 | + 'value' => $item_money, |
|
| 229 | + ], |
|
| 230 | + 'category' => 'DIGITAL_GOODS', |
|
| 231 | + ]; |
|
| 232 | + // Line item total. |
|
| 233 | + $this->items_total += $line_item->pretaxTotal(); |
|
| 234 | + } elseif ($line_item->OBJ_type() === 'Promotion' && $line_item->quantity() > 0) { |
|
| 235 | + // Promotions total. |
|
| 236 | + $this->promos_total += $line_item->total(); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + // Make sure we have an absolute number with only two decimal laces. |
|
| 240 | + $this->items_total = CurrencyManager::normalizeValue($this->items_total); |
|
| 241 | + $this->promos_total = CurrencyManager::normalizeValue($this->promos_total); |
|
| 242 | + // If this is a partial payment, apply the paid amount as a promo. |
|
| 243 | + if ($this->transaction->paid() > 0) { |
|
| 244 | + $this->promos_total += CurrencyManager::normalizeValue($this->transaction->paid()); |
|
| 245 | + } |
|
| 246 | + $this->countTaxTotal(); |
|
| 247 | + return $line_items; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * Count the tax total. |
|
| 253 | - * |
|
| 254 | - * @return void |
|
| 255 | - * @throws EE_Error|ReflectionException |
|
| 256 | - */ |
|
| 257 | - protected function countTaxTotal(): void |
|
| 258 | - { |
|
| 259 | - // List taxes. |
|
| 260 | - $this->tax_total = 0; |
|
| 261 | - $tax_items = $this->transaction->tax_items(); |
|
| 262 | - foreach ($tax_items as $tax_item) { |
|
| 263 | - $this->tax_total += $tax_item->total(); |
|
| 264 | - } |
|
| 265 | - $this->tax_total = CurrencyManager::normalizeValue($this->tax_total); |
|
| 266 | - } |
|
| 251 | + /** |
|
| 252 | + * Count the tax total. |
|
| 253 | + * |
|
| 254 | + * @return void |
|
| 255 | + * @throws EE_Error|ReflectionException |
|
| 256 | + */ |
|
| 257 | + protected function countTaxTotal(): void |
|
| 258 | + { |
|
| 259 | + // List taxes. |
|
| 260 | + $this->tax_total = 0; |
|
| 261 | + $tax_items = $this->transaction->tax_items(); |
|
| 262 | + foreach ($tax_items as $tax_item) { |
|
| 263 | + $this->tax_total += $tax_item->total(); |
|
| 264 | + } |
|
| 265 | + $this->tax_total = CurrencyManager::normalizeValue($this->tax_total); |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Itemize the payment the breakdown list. |
|
| 271 | - * |
|
| 272 | - * @return array |
|
| 273 | - */ |
|
| 274 | - protected function getBreakdown(): array |
|
| 275 | - { |
|
| 276 | - $breakdown['item_total'] = [ |
|
| 277 | - 'currency_code' => $this->currency_code, |
|
| 278 | - 'value' => $this->items_total, |
|
| 279 | - ]; |
|
| 280 | - $breakdown['tax_total'] = [ |
|
| 281 | - 'currency_code' => $this->currency_code, |
|
| 282 | - 'value' => $this->tax_total, |
|
| 283 | - ]; |
|
| 284 | - $breakdown['discount'] = [ |
|
| 285 | - 'currency_code' => $this->currency_code, |
|
| 286 | - 'value' => abs($this->promos_total), |
|
| 287 | - ]; |
|
| 288 | - return $breakdown; |
|
| 289 | - } |
|
| 269 | + /** |
|
| 270 | + * Itemize the payment the breakdown list. |
|
| 271 | + * |
|
| 272 | + * @return array |
|
| 273 | + */ |
|
| 274 | + protected function getBreakdown(): array |
|
| 275 | + { |
|
| 276 | + $breakdown['item_total'] = [ |
|
| 277 | + 'currency_code' => $this->currency_code, |
|
| 278 | + 'value' => $this->items_total, |
|
| 279 | + ]; |
|
| 280 | + $breakdown['tax_total'] = [ |
|
| 281 | + 'currency_code' => $this->currency_code, |
|
| 282 | + 'value' => $this->tax_total, |
|
| 283 | + ]; |
|
| 284 | + $breakdown['discount'] = [ |
|
| 285 | + 'currency_code' => $this->currency_code, |
|
| 286 | + 'value' => abs($this->promos_total), |
|
| 287 | + ]; |
|
| 288 | + return $breakdown; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Makes sure that we have received an Order back from the API call. |
|
| 294 | - * |
|
| 295 | - * @param $response |
|
| 296 | - * @param $parameters |
|
| 297 | - * @return array |
|
| 298 | - * @throws EE_Error |
|
| 299 | - * @throws ReflectionException |
|
| 300 | - */ |
|
| 301 | - public function validateOrder($response, $parameters): array |
|
| 302 | - { |
|
| 303 | - $message = esc_html__('Validating Order Create:', 'event_espresso'); |
|
| 304 | - PayPalLogger::errorLog( |
|
| 305 | - $message, |
|
| 306 | - [$this->request_url, $response], |
|
| 307 | - $this->transaction->payment_method(), |
|
| 308 | - false, |
|
| 309 | - $this->transaction |
|
| 310 | - ); |
|
| 311 | - if (! empty($response['error'])) { |
|
| 312 | - return $response; |
|
| 313 | - } |
|
| 314 | - if (! isset($response['id'])) { |
|
| 315 | - $message = esc_html__('Unexpected response. Unable to find the order.', 'event_espresso'); |
|
| 316 | - try { |
|
| 317 | - PayPalLogger::errorLog( |
|
| 318 | - $message, |
|
| 319 | - [$this->request_url, $parameters, $response], |
|
| 320 | - $this->transaction->payment_method() |
|
| 321 | - ); |
|
| 322 | - } catch (EE_Error | ReflectionException $e) { |
|
| 323 | - // Just continue. |
|
| 324 | - } |
|
| 325 | - return [ |
|
| 326 | - 'error' => $response['error'] ?? 'missing_order', |
|
| 327 | - 'message' => $response['message'] ?? $message, |
|
| 328 | - ]; |
|
| 329 | - } |
|
| 330 | - return $response; |
|
| 331 | - } |
|
| 292 | + /** |
|
| 293 | + * Makes sure that we have received an Order back from the API call. |
|
| 294 | + * |
|
| 295 | + * @param $response |
|
| 296 | + * @param $parameters |
|
| 297 | + * @return array |
|
| 298 | + * @throws EE_Error |
|
| 299 | + * @throws ReflectionException |
|
| 300 | + */ |
|
| 301 | + public function validateOrder($response, $parameters): array |
|
| 302 | + { |
|
| 303 | + $message = esc_html__('Validating Order Create:', 'event_espresso'); |
|
| 304 | + PayPalLogger::errorLog( |
|
| 305 | + $message, |
|
| 306 | + [$this->request_url, $response], |
|
| 307 | + $this->transaction->payment_method(), |
|
| 308 | + false, |
|
| 309 | + $this->transaction |
|
| 310 | + ); |
|
| 311 | + if (! empty($response['error'])) { |
|
| 312 | + return $response; |
|
| 313 | + } |
|
| 314 | + if (! isset($response['id'])) { |
|
| 315 | + $message = esc_html__('Unexpected response. Unable to find the order.', 'event_espresso'); |
|
| 316 | + try { |
|
| 317 | + PayPalLogger::errorLog( |
|
| 318 | + $message, |
|
| 319 | + [$this->request_url, $parameters, $response], |
|
| 320 | + $this->transaction->payment_method() |
|
| 321 | + ); |
|
| 322 | + } catch (EE_Error | ReflectionException $e) { |
|
| 323 | + // Just continue. |
|
| 324 | + } |
|
| 325 | + return [ |
|
| 326 | + 'error' => $response['error'] ?? 'missing_order', |
|
| 327 | + 'message' => $response['message'] ?? $message, |
|
| 328 | + ]; |
|
| 329 | + } |
|
| 330 | + return $response; |
|
| 331 | + } |
|
| 332 | 332 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $email_validator = new Basic(); |
| 105 | 105 | $sanitizer = new RequestSanitizer($email_validator); |
| 106 | 106 | foreach ($billing_info as $item => $value) { |
| 107 | - $this->billing_info[ $item ] = $sanitizer->clean($value); |
|
| 107 | + $this->billing_info[$item] = $sanitizer->clean($value); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | esc_html__('Tickets for an event at %1$s', 'event_espresso'), |
| 143 | 143 | get_bloginfo('name') |
| 144 | 144 | ); |
| 145 | - $parameters = [ |
|
| 145 | + $parameters = [ |
|
| 146 | 146 | 'intent' => 'CAPTURE', |
| 147 | 147 | 'purchase_units' => [ |
| 148 | 148 | [ |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | if ( |
| 178 | 178 | ( |
| 179 | 179 | (defined('EE_PPC_USE_PAYMENT_FEES') && EE_PPC_USE_PAYMENT_FEES) |
| 180 | - || (! defined('EE_PPC_USE_PAYMENT_FEES') |
|
| 180 | + || ( ! defined('EE_PPC_USE_PAYMENT_FEES') |
|
| 181 | 181 | && $this->feature->allowed(FeatureFlag::USE_PAYMENT_PROCESSOR_FEES) |
| 182 | 182 | ) |
| 183 | 183 | ) |
@@ -277,11 +277,11 @@ discard block |
||
| 277 | 277 | 'currency_code' => $this->currency_code, |
| 278 | 278 | 'value' => $this->items_total, |
| 279 | 279 | ]; |
| 280 | - $breakdown['tax_total'] = [ |
|
| 280 | + $breakdown['tax_total'] = [ |
|
| 281 | 281 | 'currency_code' => $this->currency_code, |
| 282 | 282 | 'value' => $this->tax_total, |
| 283 | 283 | ]; |
| 284 | - $breakdown['discount'] = [ |
|
| 284 | + $breakdown['discount'] = [ |
|
| 285 | 285 | 'currency_code' => $this->currency_code, |
| 286 | 286 | 'value' => abs($this->promos_total), |
| 287 | 287 | ]; |
@@ -308,10 +308,10 @@ discard block |
||
| 308 | 308 | false, |
| 309 | 309 | $this->transaction |
| 310 | 310 | ); |
| 311 | - if (! empty($response['error'])) { |
|
| 311 | + if ( ! empty($response['error'])) { |
|
| 312 | 312 | return $response; |
| 313 | 313 | } |
| 314 | - if (! isset($response['id'])) { |
|
| 314 | + if ( ! isset($response['id'])) { |
|
| 315 | 315 | $message = esc_html__('Unexpected response. Unable to find the order.', 'event_espresso'); |
| 316 | 316 | try { |
| 317 | 317 | PayPalLogger::errorLog( |