@@ -19,139 +19,139 @@ |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - public function __construct() |
|
| 23 | - { |
|
| 24 | - parent::__construct(); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - protected function _init_props() |
|
| 29 | - { |
|
| 30 | - $this->label = esc_html__('Organization Shortcodes', 'event_espresso'); |
|
| 31 | - $this->description = esc_html__('All shortcodes specific to organization related data', 'event_espresso'); |
|
| 32 | - $this->_shortcodes = array( |
|
| 33 | - '[COMPANY]' => esc_html__('Event organization name', 'event_espresso'), |
|
| 34 | - '[CO_ADD1]' => esc_html__('Address 1 value for the organization', 'event_espresso'), |
|
| 35 | - '[CO_ADD2]' => esc_html__('Address 2 value for the organization', 'event_espresso'), |
|
| 36 | - '[CO_CITY]' => esc_html__('City the organization is in', 'event_espresso'), |
|
| 37 | - '[CO_STATE]' => esc_html__('State the organization is located in', 'event_espresso'), |
|
| 38 | - '[CO_ZIP]' => esc_html__('The zip code for the organization', 'event_espresso'), |
|
| 39 | - '[CO_LOGO]' => esc_html__('The logo image for the organization', 'event_espresso'), |
|
| 40 | - '[CO_EMAIL]' => esc_html__('The primary email address for the organization', 'event_espresso'), |
|
| 41 | - '[CO_PHONE]' => esc_html__('The phone number for the organization', 'event_espresso'), |
|
| 42 | - '[CO_LOGO_URL]' => esc_html__( |
|
| 43 | - 'Just the link to the image used as the logo for the organization', |
|
| 44 | - 'event_espresso' |
|
| 45 | - ), |
|
| 46 | - '[CO_FACEBOOK_URL]' => esc_html__('Link to organization Facebook page', 'event_espresso'), |
|
| 47 | - '[CO_TWITTER_URL]' => esc_html__('Link to organization Twitter page', 'event_espresso'), |
|
| 48 | - '[CO_PINTEREST_URL]' => esc_html__('Link to organization Pinterest page', 'event_espresso'), |
|
| 49 | - '[CO_GOOGLE_URL]' => esc_html__('Link to organization Google page', 'event_espresso'), |
|
| 50 | - '[CO_LINKEDIN_URL]' => esc_html__('Link to organization LinkedIn page', 'event_espresso'), |
|
| 51 | - '[CO_INSTAGRAM_URL]' => esc_html__('Link to organization Instagram page', 'event_espresso'), |
|
| 52 | - '[CO_TAX_NUMBER_*]' => sprintf( |
|
| 53 | - esc_html__( |
|
| 54 | - 'This is the shortcode used for displaying any tax number for the company. %1$sNote: This is a special dynamic shortcode.%2$s You can use the "prefix" parameter to indicate what the prefix for this tax number is. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: [CO_TAX_NUMBER_* prefix="GST: "] and that will output: GST: 12345t56. Also take note that if you have NO number in your settings, the prefix is not output either.', |
|
| 55 | - 'event_espresso' |
|
| 56 | - ), |
|
| 57 | - '<strong>', |
|
| 58 | - '</strong>' |
|
| 59 | - ), |
|
| 60 | - ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - protected function _parser($shortcode) |
|
| 65 | - { |
|
| 66 | - |
|
| 67 | - switch ($shortcode) { |
|
| 68 | - case '[COMPANY]': |
|
| 69 | - return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
| 70 | - break; |
|
| 71 | - |
|
| 72 | - case '[CO_ADD1]': |
|
| 73 | - return EE_Registry::instance()->CFG->organization->get_pretty('address_1'); |
|
| 74 | - break; |
|
| 75 | - |
|
| 76 | - case '[CO_ADD2]': |
|
| 77 | - return EE_Registry::instance()->CFG->organization->get_pretty('address_2'); |
|
| 78 | - break; |
|
| 79 | - |
|
| 80 | - case '[CO_CITY]': |
|
| 81 | - return EE_Registry::instance()->CFG->organization->get_pretty('city'); |
|
| 82 | - break; |
|
| 83 | - |
|
| 84 | - case '[CO_STATE]': |
|
| 85 | - $state = EE_Registry::instance()->load_model('State')->get_one_by_ID( |
|
| 86 | - EE_Registry::instance()->CFG->organization->STA_ID |
|
| 87 | - ); |
|
| 88 | - return $state instanceof EE_State ? $state->name() : ''; |
|
| 89 | - break; |
|
| 90 | - |
|
| 91 | - case '[CO_ZIP]': |
|
| 92 | - return EE_Registry::instance()->CFG->organization->get_pretty('zip'); |
|
| 93 | - break; |
|
| 94 | - |
|
| 95 | - case '[CO_EMAIL]': |
|
| 96 | - return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
| 97 | - break; |
|
| 98 | - |
|
| 99 | - case '[CO_PHONE]': |
|
| 100 | - return EE_Registry::instance()->CFG->organization->get_pretty('phone'); |
|
| 101 | - break; |
|
| 102 | - |
|
| 103 | - case '[CO_LOGO]': |
|
| 104 | - return '<img src="' |
|
| 105 | - . EE_Registry::instance()->CFG->organization->get_pretty( |
|
| 106 | - 'logo_url' |
|
| 107 | - ) . '" id="headerImage" />'; |
|
| 108 | - break; |
|
| 109 | - |
|
| 110 | - case '[CO_LOGO_URL]': |
|
| 111 | - return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
| 112 | - break; |
|
| 113 | - |
|
| 114 | - case '[CO_FACEBOOK_URL]': |
|
| 115 | - return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
| 116 | - break; |
|
| 117 | - |
|
| 118 | - case '[CO_TWITTER_URL]': |
|
| 119 | - return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
| 120 | - break; |
|
| 121 | - |
|
| 122 | - case '[CO_PINTEREST_URL]': |
|
| 123 | - return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
| 124 | - break; |
|
| 125 | - |
|
| 126 | - case '[CO_LINKEDIN_URL]': |
|
| 127 | - return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
| 128 | - break; |
|
| 129 | - |
|
| 130 | - case '[CO_GOOGLE_URL]': |
|
| 131 | - return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
| 132 | - break; |
|
| 133 | - |
|
| 134 | - case '[CO_INSTAGRAM_URL]': |
|
| 135 | - return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
| 136 | - break; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // also allow for parameter shortcode |
|
| 140 | - if (strpos($shortcode, '[CO_TAX_NUMBER_*') !== false) { |
|
| 141 | - // first see if there is any company tax number set and bail early if not |
|
| 142 | - $tax_number = EE_Registry::instance()->CFG->organization->vat; |
|
| 143 | - if (empty($tax_number)) { |
|
| 144 | - return ''; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // see if there are any attributes. |
|
| 148 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 149 | - |
|
| 150 | - // set custom attrs if present (or default) |
|
| 151 | - $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
| 152 | - return $prefix . $tax_number; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return ''; |
|
| 156 | - } |
|
| 22 | + public function __construct() |
|
| 23 | + { |
|
| 24 | + parent::__construct(); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + protected function _init_props() |
|
| 29 | + { |
|
| 30 | + $this->label = esc_html__('Organization Shortcodes', 'event_espresso'); |
|
| 31 | + $this->description = esc_html__('All shortcodes specific to organization related data', 'event_espresso'); |
|
| 32 | + $this->_shortcodes = array( |
|
| 33 | + '[COMPANY]' => esc_html__('Event organization name', 'event_espresso'), |
|
| 34 | + '[CO_ADD1]' => esc_html__('Address 1 value for the organization', 'event_espresso'), |
|
| 35 | + '[CO_ADD2]' => esc_html__('Address 2 value for the organization', 'event_espresso'), |
|
| 36 | + '[CO_CITY]' => esc_html__('City the organization is in', 'event_espresso'), |
|
| 37 | + '[CO_STATE]' => esc_html__('State the organization is located in', 'event_espresso'), |
|
| 38 | + '[CO_ZIP]' => esc_html__('The zip code for the organization', 'event_espresso'), |
|
| 39 | + '[CO_LOGO]' => esc_html__('The logo image for the organization', 'event_espresso'), |
|
| 40 | + '[CO_EMAIL]' => esc_html__('The primary email address for the organization', 'event_espresso'), |
|
| 41 | + '[CO_PHONE]' => esc_html__('The phone number for the organization', 'event_espresso'), |
|
| 42 | + '[CO_LOGO_URL]' => esc_html__( |
|
| 43 | + 'Just the link to the image used as the logo for the organization', |
|
| 44 | + 'event_espresso' |
|
| 45 | + ), |
|
| 46 | + '[CO_FACEBOOK_URL]' => esc_html__('Link to organization Facebook page', 'event_espresso'), |
|
| 47 | + '[CO_TWITTER_URL]' => esc_html__('Link to organization Twitter page', 'event_espresso'), |
|
| 48 | + '[CO_PINTEREST_URL]' => esc_html__('Link to organization Pinterest page', 'event_espresso'), |
|
| 49 | + '[CO_GOOGLE_URL]' => esc_html__('Link to organization Google page', 'event_espresso'), |
|
| 50 | + '[CO_LINKEDIN_URL]' => esc_html__('Link to organization LinkedIn page', 'event_espresso'), |
|
| 51 | + '[CO_INSTAGRAM_URL]' => esc_html__('Link to organization Instagram page', 'event_espresso'), |
|
| 52 | + '[CO_TAX_NUMBER_*]' => sprintf( |
|
| 53 | + esc_html__( |
|
| 54 | + 'This is the shortcode used for displaying any tax number for the company. %1$sNote: This is a special dynamic shortcode.%2$s You can use the "prefix" parameter to indicate what the prefix for this tax number is. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: [CO_TAX_NUMBER_* prefix="GST: "] and that will output: GST: 12345t56. Also take note that if you have NO number in your settings, the prefix is not output either.', |
|
| 55 | + 'event_espresso' |
|
| 56 | + ), |
|
| 57 | + '<strong>', |
|
| 58 | + '</strong>' |
|
| 59 | + ), |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + protected function _parser($shortcode) |
|
| 65 | + { |
|
| 66 | + |
|
| 67 | + switch ($shortcode) { |
|
| 68 | + case '[COMPANY]': |
|
| 69 | + return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
| 70 | + break; |
|
| 71 | + |
|
| 72 | + case '[CO_ADD1]': |
|
| 73 | + return EE_Registry::instance()->CFG->organization->get_pretty('address_1'); |
|
| 74 | + break; |
|
| 75 | + |
|
| 76 | + case '[CO_ADD2]': |
|
| 77 | + return EE_Registry::instance()->CFG->organization->get_pretty('address_2'); |
|
| 78 | + break; |
|
| 79 | + |
|
| 80 | + case '[CO_CITY]': |
|
| 81 | + return EE_Registry::instance()->CFG->organization->get_pretty('city'); |
|
| 82 | + break; |
|
| 83 | + |
|
| 84 | + case '[CO_STATE]': |
|
| 85 | + $state = EE_Registry::instance()->load_model('State')->get_one_by_ID( |
|
| 86 | + EE_Registry::instance()->CFG->organization->STA_ID |
|
| 87 | + ); |
|
| 88 | + return $state instanceof EE_State ? $state->name() : ''; |
|
| 89 | + break; |
|
| 90 | + |
|
| 91 | + case '[CO_ZIP]': |
|
| 92 | + return EE_Registry::instance()->CFG->organization->get_pretty('zip'); |
|
| 93 | + break; |
|
| 94 | + |
|
| 95 | + case '[CO_EMAIL]': |
|
| 96 | + return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
| 97 | + break; |
|
| 98 | + |
|
| 99 | + case '[CO_PHONE]': |
|
| 100 | + return EE_Registry::instance()->CFG->organization->get_pretty('phone'); |
|
| 101 | + break; |
|
| 102 | + |
|
| 103 | + case '[CO_LOGO]': |
|
| 104 | + return '<img src="' |
|
| 105 | + . EE_Registry::instance()->CFG->organization->get_pretty( |
|
| 106 | + 'logo_url' |
|
| 107 | + ) . '" id="headerImage" />'; |
|
| 108 | + break; |
|
| 109 | + |
|
| 110 | + case '[CO_LOGO_URL]': |
|
| 111 | + return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
| 112 | + break; |
|
| 113 | + |
|
| 114 | + case '[CO_FACEBOOK_URL]': |
|
| 115 | + return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
| 116 | + break; |
|
| 117 | + |
|
| 118 | + case '[CO_TWITTER_URL]': |
|
| 119 | + return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
| 120 | + break; |
|
| 121 | + |
|
| 122 | + case '[CO_PINTEREST_URL]': |
|
| 123 | + return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
| 124 | + break; |
|
| 125 | + |
|
| 126 | + case '[CO_LINKEDIN_URL]': |
|
| 127 | + return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
| 128 | + break; |
|
| 129 | + |
|
| 130 | + case '[CO_GOOGLE_URL]': |
|
| 131 | + return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
| 132 | + break; |
|
| 133 | + |
|
| 134 | + case '[CO_INSTAGRAM_URL]': |
|
| 135 | + return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
| 136 | + break; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // also allow for parameter shortcode |
|
| 140 | + if (strpos($shortcode, '[CO_TAX_NUMBER_*') !== false) { |
|
| 141 | + // first see if there is any company tax number set and bail early if not |
|
| 142 | + $tax_number = EE_Registry::instance()->CFG->organization->vat; |
|
| 143 | + if (empty($tax_number)) { |
|
| 144 | + return ''; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // see if there are any attributes. |
|
| 148 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
| 149 | + |
|
| 150 | + // set custom attrs if present (or default) |
|
| 151 | + $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
| 152 | + return $prefix . $tax_number; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return ''; |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -12,270 +12,270 @@ |
||
| 12 | 12 | class EEH_URL |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * _add_query_arg |
|
| 17 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 18 | - * |
|
| 19 | - * @access public |
|
| 20 | - * @param array $args |
|
| 21 | - * @param string $url |
|
| 22 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
| 26 | - { |
|
| 27 | - // check that an action exists and add nonce |
|
| 28 | - if (! $exclude_nonce) { |
|
| 29 | - if (isset($args['action']) && ! empty($args['action'])) { |
|
| 30 | - $args = array_merge( |
|
| 31 | - $args, |
|
| 32 | - array( |
|
| 33 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 34 | - ) |
|
| 35 | - ); |
|
| 36 | - } else { |
|
| 37 | - $args = array_merge( |
|
| 38 | - $args, |
|
| 39 | - array( |
|
| 40 | - 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
| 41 | - ) |
|
| 42 | - ); |
|
| 43 | - } |
|
| 44 | - } |
|
| 15 | + /** |
|
| 16 | + * _add_query_arg |
|
| 17 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 18 | + * |
|
| 19 | + * @access public |
|
| 20 | + * @param array $args |
|
| 21 | + * @param string $url |
|
| 22 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
| 26 | + { |
|
| 27 | + // check that an action exists and add nonce |
|
| 28 | + if (! $exclude_nonce) { |
|
| 29 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
| 30 | + $args = array_merge( |
|
| 31 | + $args, |
|
| 32 | + array( |
|
| 33 | + $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 34 | + ) |
|
| 35 | + ); |
|
| 36 | + } else { |
|
| 37 | + $args = array_merge( |
|
| 38 | + $args, |
|
| 39 | + array( |
|
| 40 | + 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
| 41 | + ) |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - // finally, let's always add a return address (if present) :) |
|
| 47 | - $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 48 | - ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 49 | - : $args; |
|
| 46 | + // finally, let's always add a return address (if present) :) |
|
| 47 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 48 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 49 | + : $args; |
|
| 50 | 50 | |
| 51 | - return add_query_arg($args, $url); |
|
| 52 | - } |
|
| 51 | + return add_query_arg($args, $url); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Returns whether not the remote file exists. |
|
| 57 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
| 58 | - * |
|
| 59 | - * @param string $url |
|
| 60 | - * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
| 61 | - * @return boolean |
|
| 62 | - */ |
|
| 63 | - public static function remote_file_exists($url, $args = array()) |
|
| 64 | - { |
|
| 65 | - $results = wp_remote_request( |
|
| 66 | - $url, |
|
| 67 | - array_merge( |
|
| 68 | - array( |
|
| 69 | - 'method' => 'GET', |
|
| 70 | - 'redirection' => 1, |
|
| 71 | - ), |
|
| 72 | - $args |
|
| 73 | - ) |
|
| 74 | - ); |
|
| 75 | - if (! $results instanceof WP_Error && |
|
| 76 | - isset($results['response']) && |
|
| 77 | - isset($results['response']['code']) && |
|
| 78 | - $results['response']['code'] == '200') { |
|
| 79 | - return true; |
|
| 80 | - } else { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - } |
|
| 55 | + /** |
|
| 56 | + * Returns whether not the remote file exists. |
|
| 57 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
| 58 | + * |
|
| 59 | + * @param string $url |
|
| 60 | + * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
| 61 | + * @return boolean |
|
| 62 | + */ |
|
| 63 | + public static function remote_file_exists($url, $args = array()) |
|
| 64 | + { |
|
| 65 | + $results = wp_remote_request( |
|
| 66 | + $url, |
|
| 67 | + array_merge( |
|
| 68 | + array( |
|
| 69 | + 'method' => 'GET', |
|
| 70 | + 'redirection' => 1, |
|
| 71 | + ), |
|
| 72 | + $args |
|
| 73 | + ) |
|
| 74 | + ); |
|
| 75 | + if (! $results instanceof WP_Error && |
|
| 76 | + isset($results['response']) && |
|
| 77 | + isset($results['response']['code']) && |
|
| 78 | + $results['response']['code'] == '200') { |
|
| 79 | + return true; |
|
| 80 | + } else { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * refactor_url |
|
| 88 | - * primarily used for removing the query string from a URL |
|
| 89 | - * |
|
| 90 | - * @param string $url |
|
| 91 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
| 92 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
| 96 | - { |
|
| 97 | - // break apart incoming URL |
|
| 98 | - $url_bits = parse_url($url); |
|
| 99 | - // HTTP or HTTPS ? |
|
| 100 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 101 | - // domain |
|
| 102 | - $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 103 | - // if only the base URL is requested, then return that now |
|
| 104 | - if ($base_url_only) { |
|
| 105 | - return $scheme . $host; |
|
| 106 | - } |
|
| 107 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 108 | - $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 109 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 110 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 111 | - $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 112 | - // if the query string is not required, then return what we have so far |
|
| 113 | - if ($remove_query) { |
|
| 114 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 115 | - } |
|
| 116 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 117 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 118 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 119 | - } |
|
| 86 | + /** |
|
| 87 | + * refactor_url |
|
| 88 | + * primarily used for removing the query string from a URL |
|
| 89 | + * |
|
| 90 | + * @param string $url |
|
| 91 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
| 92 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
| 96 | + { |
|
| 97 | + // break apart incoming URL |
|
| 98 | + $url_bits = parse_url($url); |
|
| 99 | + // HTTP or HTTPS ? |
|
| 100 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 101 | + // domain |
|
| 102 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 103 | + // if only the base URL is requested, then return that now |
|
| 104 | + if ($base_url_only) { |
|
| 105 | + return $scheme . $host; |
|
| 106 | + } |
|
| 107 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 108 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 109 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 110 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 111 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 112 | + // if the query string is not required, then return what we have so far |
|
| 113 | + if ($remove_query) { |
|
| 114 | + return $scheme . $user . $pass . $host . $port . $path; |
|
| 115 | + } |
|
| 116 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 117 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 118 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * get_query_string |
|
| 124 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
| 125 | - * |
|
| 126 | - * @param string $url |
|
| 127 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
| 128 | - * simply return the query string |
|
| 129 | - * @return string|array |
|
| 130 | - */ |
|
| 131 | - public static function get_query_string($url = '', $as_array = true) |
|
| 132 | - { |
|
| 133 | - // decode, then break apart incoming URL |
|
| 134 | - $url_bits = parse_url(html_entity_decode($url)); |
|
| 135 | - // grab query string from URL |
|
| 136 | - $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 137 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
| 138 | - if (! $as_array) { |
|
| 139 | - return $query; |
|
| 140 | - } |
|
| 141 | - // if no query string exists then just return an empty array now |
|
| 142 | - if (empty($query)) { |
|
| 143 | - return array(); |
|
| 144 | - } |
|
| 145 | - // empty array to hold results |
|
| 146 | - $query_params = array(); |
|
| 147 | - // now break apart the query string into separate params |
|
| 148 | - $query = explode('&', $query); |
|
| 149 | - // loop thru our query params |
|
| 150 | - foreach ($query as $query_args) { |
|
| 151 | - // break apart the key value pairs |
|
| 152 | - $query_args = explode('=', $query_args); |
|
| 153 | - // and add to our results array |
|
| 154 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 155 | - } |
|
| 156 | - return $query_params; |
|
| 157 | - } |
|
| 122 | + /** |
|
| 123 | + * get_query_string |
|
| 124 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
| 125 | + * |
|
| 126 | + * @param string $url |
|
| 127 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
| 128 | + * simply return the query string |
|
| 129 | + * @return string|array |
|
| 130 | + */ |
|
| 131 | + public static function get_query_string($url = '', $as_array = true) |
|
| 132 | + { |
|
| 133 | + // decode, then break apart incoming URL |
|
| 134 | + $url_bits = parse_url(html_entity_decode($url)); |
|
| 135 | + // grab query string from URL |
|
| 136 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 137 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
| 138 | + if (! $as_array) { |
|
| 139 | + return $query; |
|
| 140 | + } |
|
| 141 | + // if no query string exists then just return an empty array now |
|
| 142 | + if (empty($query)) { |
|
| 143 | + return array(); |
|
| 144 | + } |
|
| 145 | + // empty array to hold results |
|
| 146 | + $query_params = array(); |
|
| 147 | + // now break apart the query string into separate params |
|
| 148 | + $query = explode('&', $query); |
|
| 149 | + // loop thru our query params |
|
| 150 | + foreach ($query as $query_args) { |
|
| 151 | + // break apart the key value pairs |
|
| 152 | + $query_args = explode('=', $query_args); |
|
| 153 | + // and add to our results array |
|
| 154 | + $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 155 | + } |
|
| 156 | + return $query_params; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * prevent_prefetching |
|
| 162 | - * |
|
| 163 | - * @return void |
|
| 164 | - */ |
|
| 165 | - public static function prevent_prefetching() |
|
| 166 | - { |
|
| 167 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
| 168 | - // with the registration process |
|
| 169 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 170 | - } |
|
| 160 | + /** |
|
| 161 | + * prevent_prefetching |
|
| 162 | + * |
|
| 163 | + * @return void |
|
| 164 | + */ |
|
| 165 | + public static function prevent_prefetching() |
|
| 166 | + { |
|
| 167 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
| 168 | + // with the registration process |
|
| 169 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * This generates a unique site-specific string. |
|
| 175 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
| 176 | - * urls. |
|
| 177 | - * |
|
| 178 | - * @param string $prefix Use this to prefix the string with something. |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public static function generate_unique_token($prefix = '') |
|
| 182 | - { |
|
| 183 | - $token = md5(uniqid() . mt_rand()); |
|
| 184 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 185 | - } |
|
| 173 | + /** |
|
| 174 | + * This generates a unique site-specific string. |
|
| 175 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
| 176 | + * urls. |
|
| 177 | + * |
|
| 178 | + * @param string $prefix Use this to prefix the string with something. |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public static function generate_unique_token($prefix = '') |
|
| 182 | + { |
|
| 183 | + $token = md5(uniqid() . mt_rand()); |
|
| 184 | + return $prefix ? $prefix . '_' . $token : $token; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * filter_input_server_url |
|
| 190 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
| 191 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
| 192 | - * |
|
| 193 | - * @param string $server_variable |
|
| 194 | - * @return string |
|
| 195 | - */ |
|
| 196 | - public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
| 197 | - { |
|
| 198 | - $URL = ''; |
|
| 199 | - $server_variables = array( |
|
| 200 | - 'REQUEST_URI' => 1, |
|
| 201 | - 'HTTP_HOST' => 1, |
|
| 202 | - 'PHP_SELF' => 1, |
|
| 203 | - ); |
|
| 204 | - $server_variable = strtoupper($server_variable); |
|
| 205 | - // whitelist INPUT_SERVER var |
|
| 206 | - if (isset($server_variables[ $server_variable ])) { |
|
| 207 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 208 | - if (empty($URL)) { |
|
| 209 | - // fallback sanitization if the above fails |
|
| 210 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - return $URL; |
|
| 214 | - } |
|
| 188 | + /** |
|
| 189 | + * filter_input_server_url |
|
| 190 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
| 191 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
| 192 | + * |
|
| 193 | + * @param string $server_variable |
|
| 194 | + * @return string |
|
| 195 | + */ |
|
| 196 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
| 197 | + { |
|
| 198 | + $URL = ''; |
|
| 199 | + $server_variables = array( |
|
| 200 | + 'REQUEST_URI' => 1, |
|
| 201 | + 'HTTP_HOST' => 1, |
|
| 202 | + 'PHP_SELF' => 1, |
|
| 203 | + ); |
|
| 204 | + $server_variable = strtoupper($server_variable); |
|
| 205 | + // whitelist INPUT_SERVER var |
|
| 206 | + if (isset($server_variables[ $server_variable ])) { |
|
| 207 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 208 | + if (empty($URL)) { |
|
| 209 | + // fallback sanitization if the above fails |
|
| 210 | + $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + return $URL; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Gets the current page's full URL. |
|
| 219 | - * |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - public static function current_url() |
|
| 223 | - { |
|
| 224 | - $url = ''; |
|
| 225 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 226 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
| 227 | - $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 228 | - $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 229 | - } |
|
| 230 | - return $url; |
|
| 231 | - } |
|
| 217 | + /** |
|
| 218 | + * Gets the current page's full URL. |
|
| 219 | + * |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + public static function current_url() |
|
| 223 | + { |
|
| 224 | + $url = ''; |
|
| 225 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 226 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
| 227 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 228 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 229 | + } |
|
| 230 | + return $url; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
| 236 | - * |
|
| 237 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 238 | - * @since 4.9.46.rc.029 |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 241 | - public static function current_url_without_query_paramaters(array $query_parameters) |
|
| 242 | - { |
|
| 243 | - return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
| 244 | - } |
|
| 234 | + /** |
|
| 235 | + * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
| 236 | + * |
|
| 237 | + * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 238 | + * @since 4.9.46.rc.029 |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | + public static function current_url_without_query_paramaters(array $query_parameters) |
|
| 242 | + { |
|
| 243 | + return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * @param string $location |
|
| 249 | - * @param int $status |
|
| 250 | - * @param string $exit_notice |
|
| 251 | - */ |
|
| 252 | - public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
| 253 | - { |
|
| 254 | - EE_Error::get_notices(false, true); |
|
| 255 | - wp_safe_redirect($location, $status); |
|
| 256 | - exit($exit_notice); |
|
| 257 | - } |
|
| 247 | + /** |
|
| 248 | + * @param string $location |
|
| 249 | + * @param int $status |
|
| 250 | + * @param string $exit_notice |
|
| 251 | + */ |
|
| 252 | + public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
| 253 | + { |
|
| 254 | + EE_Error::get_notices(false, true); |
|
| 255 | + wp_safe_redirect($location, $status); |
|
| 256 | + exit($exit_notice); |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Slugifies text for usage in a URL. |
|
| 261 | - * |
|
| 262 | - * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
| 263 | - * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
| 264 | - * |
|
| 265 | - * @since 4.9.66.p |
|
| 266 | - * @param string $text |
|
| 267 | - * @param string $fallback |
|
| 268 | - * @return string which can be used in a URL |
|
| 269 | - */ |
|
| 270 | - public static function slugify($text, $fallback) |
|
| 271 | - { |
|
| 272 | - // url decode after sanitizing title to restore unicode characters, |
|
| 273 | - // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
| 274 | - return urldecode( |
|
| 275 | - sanitize_title( |
|
| 276 | - $text, |
|
| 277 | - $fallback |
|
| 278 | - ) |
|
| 279 | - ); |
|
| 280 | - } |
|
| 259 | + /** |
|
| 260 | + * Slugifies text for usage in a URL. |
|
| 261 | + * |
|
| 262 | + * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
| 263 | + * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
| 264 | + * |
|
| 265 | + * @since 4.9.66.p |
|
| 266 | + * @param string $text |
|
| 267 | + * @param string $fallback |
|
| 268 | + * @return string which can be used in a URL |
|
| 269 | + */ |
|
| 270 | + public static function slugify($text, $fallback) |
|
| 271 | + { |
|
| 272 | + // url decode after sanitizing title to restore unicode characters, |
|
| 273 | + // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
| 274 | + return urldecode( |
|
| 275 | + sanitize_title( |
|
| 276 | + $text, |
|
| 277 | + $fallback |
|
| 278 | + ) |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | 281 | } |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
| 26 | 26 | { |
| 27 | 27 | // check that an action exists and add nonce |
| 28 | - if (! $exclude_nonce) { |
|
| 28 | + if ( ! $exclude_nonce) { |
|
| 29 | 29 | if (isset($args['action']) && ! empty($args['action'])) { |
| 30 | 30 | $args = array_merge( |
| 31 | 31 | $args, |
| 32 | 32 | array( |
| 33 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 33 | + $args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce') |
|
| 34 | 34 | ) |
| 35 | 35 | ); |
| 36 | 36 | } else { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $args |
| 73 | 73 | ) |
| 74 | 74 | ); |
| 75 | - if (! $results instanceof WP_Error && |
|
| 75 | + if ( ! $results instanceof WP_Error && |
|
| 76 | 76 | isset($results['response']) && |
| 77 | 77 | isset($results['response']['code']) && |
| 78 | 78 | $results['response']['code'] == '200') { |
@@ -97,25 +97,25 @@ discard block |
||
| 97 | 97 | // break apart incoming URL |
| 98 | 98 | $url_bits = parse_url($url); |
| 99 | 99 | // HTTP or HTTPS ? |
| 100 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 100 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
| 101 | 101 | // domain |
| 102 | 102 | $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
| 103 | 103 | // if only the base URL is requested, then return that now |
| 104 | 104 | if ($base_url_only) { |
| 105 | - return $scheme . $host; |
|
| 105 | + return $scheme.$host; |
|
| 106 | 106 | } |
| 107 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 107 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
| 108 | 108 | $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
| 109 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 110 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 109 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
| 110 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
| 111 | 111 | $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
| 112 | 112 | // if the query string is not required, then return what we have so far |
| 113 | 113 | if ($remove_query) { |
| 114 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 114 | + return $scheme.$user.$pass.$host.$port.$path; |
|
| 115 | 115 | } |
| 116 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 117 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 118 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 116 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
| 117 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
| 118 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | // grab query string from URL |
| 136 | 136 | $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
| 137 | 137 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
| 138 | - if (! $as_array) { |
|
| 138 | + if ( ! $as_array) { |
|
| 139 | 139 | return $query; |
| 140 | 140 | } |
| 141 | 141 | // if no query string exists then just return an empty array now |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | // break apart the key value pairs |
| 152 | 152 | $query_args = explode('=', $query_args); |
| 153 | 153 | // and add to our results array |
| 154 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 154 | + $query_params[$query_args[0]] = $query_args[1]; |
|
| 155 | 155 | } |
| 156 | 156 | return $query_params; |
| 157 | 157 | } |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public static function generate_unique_token($prefix = '') |
| 182 | 182 | { |
| 183 | - $token = md5(uniqid() . mt_rand()); |
|
| 184 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 183 | + $token = md5(uniqid().mt_rand()); |
|
| 184 | + return $prefix ? $prefix.'_'.$token : $token; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | 'HTTP_HOST' => 1, |
| 202 | 202 | 'PHP_SELF' => 1, |
| 203 | 203 | ); |
| 204 | - $server_variable = strtoupper($server_variable); |
|
| 204 | + $server_variable = strtoupper($server_variable); |
|
| 205 | 205 | // whitelist INPUT_SERVER var |
| 206 | - if (isset($server_variables[ $server_variable ])) { |
|
| 206 | + if (isset($server_variables[$server_variable])) { |
|
| 207 | 207 | $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
| 208 | 208 | if (empty($URL)) { |
| 209 | 209 | // fallback sanitization if the above fails |
| 210 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
| 210 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | return $URL; |
@@ -29,358 +29,358 @@ |
||
| 29 | 29 | class EED_Batch extends EED_Module |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 34 | - * processes data only |
|
| 35 | - */ |
|
| 36 | - const batch_job = 'job'; |
|
| 37 | - /** |
|
| 38 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 39 | - * produces a file for download |
|
| 40 | - */ |
|
| 41 | - const batch_file_job = 'file'; |
|
| 42 | - /** |
|
| 43 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
| 44 | - * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
| 45 | - * at all |
|
| 46 | - */ |
|
| 47 | - const batch_not_job = 'none'; |
|
| 32 | + /** |
|
| 33 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 34 | + * processes data only |
|
| 35 | + */ |
|
| 36 | + const batch_job = 'job'; |
|
| 37 | + /** |
|
| 38 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 39 | + * produces a file for download |
|
| 40 | + */ |
|
| 41 | + const batch_file_job = 'file'; |
|
| 42 | + /** |
|
| 43 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
| 44 | + * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
| 45 | + * at all |
|
| 46 | + */ |
|
| 47 | + const batch_not_job = 'none'; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * |
|
| 51 | - * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
| 52 | - */ |
|
| 53 | - protected $_batch_request_type = null; |
|
| 49 | + /** |
|
| 50 | + * |
|
| 51 | + * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
| 52 | + */ |
|
| 53 | + protected $_batch_request_type = null; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Because we want to use the response in both the localized JS and in the body |
|
| 57 | - * we need to make this response available between method calls |
|
| 58 | - * |
|
| 59 | - * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 60 | - */ |
|
| 61 | - protected $_job_step_response = null; |
|
| 55 | + /** |
|
| 56 | + * Because we want to use the response in both the localized JS and in the body |
|
| 57 | + * we need to make this response available between method calls |
|
| 58 | + * |
|
| 59 | + * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 60 | + */ |
|
| 61 | + protected $_job_step_response = null; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var LoaderInterface |
|
| 65 | - */ |
|
| 66 | - protected $loader; |
|
| 63 | + /** |
|
| 64 | + * @var LoaderInterface |
|
| 65 | + */ |
|
| 66 | + protected $loader; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Gets the batch instance |
|
| 70 | - * |
|
| 71 | - * @return EED_Batch |
|
| 72 | - */ |
|
| 73 | - public static function instance() |
|
| 74 | - { |
|
| 75 | - return self::get_instance(); |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Gets the batch instance |
|
| 70 | + * |
|
| 71 | + * @return EED_Batch |
|
| 72 | + */ |
|
| 73 | + public static function instance() |
|
| 74 | + { |
|
| 75 | + return self::get_instance(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
| 80 | - * because it's an attack vector and there are currently no implementations |
|
| 81 | - */ |
|
| 82 | - public static function set_hooks() |
|
| 83 | - { |
|
| 84 | - // because this is a possibel attack vector, let's have this disabled until |
|
| 85 | - // we at least have a real use for it on the frontend |
|
| 86 | - if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
| 87 | - add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 88 | - add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
| 89 | - } |
|
| 90 | - } |
|
| 78 | + /** |
|
| 79 | + * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
| 80 | + * because it's an attack vector and there are currently no implementations |
|
| 81 | + */ |
|
| 82 | + public static function set_hooks() |
|
| 83 | + { |
|
| 84 | + // because this is a possibel attack vector, let's have this disabled until |
|
| 85 | + // we at least have a real use for it on the frontend |
|
| 86 | + if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
| 87 | + add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 88 | + add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Initializes some hooks for the admin in order to run batch jobs |
|
| 94 | - */ |
|
| 95 | - public static function set_hooks_admin() |
|
| 96 | - { |
|
| 97 | - add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
| 98 | - add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 92 | + /** |
|
| 93 | + * Initializes some hooks for the admin in order to run batch jobs |
|
| 94 | + */ |
|
| 95 | + public static function set_hooks_admin() |
|
| 96 | + { |
|
| 97 | + add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
| 98 | + add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 99 | 99 | |
| 100 | - // ajax |
|
| 101 | - add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 102 | - add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 103 | - add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 104 | - add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 105 | - } |
|
| 100 | + // ajax |
|
| 101 | + add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 102 | + add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 103 | + add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 104 | + add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @since 4.9.80.p |
|
| 109 | - * @return LoaderInterface |
|
| 110 | - * @throws InvalidArgumentException |
|
| 111 | - * @throws InvalidDataTypeException |
|
| 112 | - * @throws InvalidInterfaceException |
|
| 113 | - */ |
|
| 114 | - protected function getLoader() |
|
| 115 | - { |
|
| 116 | - if (!$this->loader instanceof LoaderInterface) { |
|
| 117 | - $this->loader = LoaderFactory::getLoader(); |
|
| 118 | - } |
|
| 119 | - return $this->loader; |
|
| 120 | - } |
|
| 107 | + /** |
|
| 108 | + * @since 4.9.80.p |
|
| 109 | + * @return LoaderInterface |
|
| 110 | + * @throws InvalidArgumentException |
|
| 111 | + * @throws InvalidDataTypeException |
|
| 112 | + * @throws InvalidInterfaceException |
|
| 113 | + */ |
|
| 114 | + protected function getLoader() |
|
| 115 | + { |
|
| 116 | + if (!$this->loader instanceof LoaderInterface) { |
|
| 117 | + $this->loader = LoaderFactory::getLoader(); |
|
| 118 | + } |
|
| 119 | + return $this->loader; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Enqueues batch scripts on the frontend or admin, and creates a job |
|
| 124 | - */ |
|
| 125 | - public function enqueue_scripts() |
|
| 126 | - { |
|
| 127 | - if (isset($_REQUEST['espresso_batch']) |
|
| 128 | - || |
|
| 129 | - ( |
|
| 130 | - isset($_REQUEST['page']) |
|
| 131 | - && $_REQUEST['page'] == 'espresso_batch' |
|
| 132 | - ) |
|
| 133 | - ) { |
|
| 134 | - if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
| 135 | - wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
|
| 136 | - } |
|
| 137 | - switch ($this->batch_request_type()) { |
|
| 138 | - case self::batch_job: |
|
| 139 | - $this->enqueue_scripts_styles_batch_create(); |
|
| 140 | - break; |
|
| 141 | - case self::batch_file_job: |
|
| 142 | - $this->enqueue_scripts_styles_batch_file_create(); |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 122 | + /** |
|
| 123 | + * Enqueues batch scripts on the frontend or admin, and creates a job |
|
| 124 | + */ |
|
| 125 | + public function enqueue_scripts() |
|
| 126 | + { |
|
| 127 | + if (isset($_REQUEST['espresso_batch']) |
|
| 128 | + || |
|
| 129 | + ( |
|
| 130 | + isset($_REQUEST['page']) |
|
| 131 | + && $_REQUEST['page'] == 'espresso_batch' |
|
| 132 | + ) |
|
| 133 | + ) { |
|
| 134 | + if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
| 135 | + wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
|
| 136 | + } |
|
| 137 | + switch ($this->batch_request_type()) { |
|
| 138 | + case self::batch_job: |
|
| 139 | + $this->enqueue_scripts_styles_batch_create(); |
|
| 140 | + break; |
|
| 141 | + case self::batch_file_job: |
|
| 142 | + $this->enqueue_scripts_styles_batch_file_create(); |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
| 150 | - */ |
|
| 151 | - public function enqueue_scripts_styles_batch_create() |
|
| 152 | - { |
|
| 153 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 154 | - wp_enqueue_script( |
|
| 155 | - 'batch_runner_init', |
|
| 156 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
| 157 | - array('batch_runner'), |
|
| 158 | - EVENT_ESPRESSO_VERSION, |
|
| 159 | - true |
|
| 160 | - ); |
|
| 161 | - wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 162 | - wp_localize_script( |
|
| 163 | - 'batch_runner_init', |
|
| 164 | - 'ee_job_i18n', |
|
| 165 | - array( |
|
| 166 | - 'return_url' => $_REQUEST['return_url'], |
|
| 167 | - ) |
|
| 168 | - ); |
|
| 169 | - } |
|
| 148 | + /** |
|
| 149 | + * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
| 150 | + */ |
|
| 151 | + public function enqueue_scripts_styles_batch_create() |
|
| 152 | + { |
|
| 153 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 154 | + wp_enqueue_script( |
|
| 155 | + 'batch_runner_init', |
|
| 156 | + BATCH_URL . 'assets/batch_runner_init.js', |
|
| 157 | + array('batch_runner'), |
|
| 158 | + EVENT_ESPRESSO_VERSION, |
|
| 159 | + true |
|
| 160 | + ); |
|
| 161 | + wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 162 | + wp_localize_script( |
|
| 163 | + 'batch_runner_init', |
|
| 164 | + 'ee_job_i18n', |
|
| 165 | + array( |
|
| 166 | + 'return_url' => $_REQUEST['return_url'], |
|
| 167 | + ) |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
| 173 | - */ |
|
| 174 | - public function enqueue_scripts_styles_batch_file_create() |
|
| 175 | - { |
|
| 176 | - // creates a job based on the request variable |
|
| 177 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 178 | - wp_enqueue_script( |
|
| 179 | - 'batch_file_runner_init', |
|
| 180 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 181 | - array('batch_runner'), |
|
| 182 | - EVENT_ESPRESSO_VERSION, |
|
| 183 | - true |
|
| 184 | - ); |
|
| 185 | - wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 186 | - wp_localize_script( |
|
| 187 | - 'batch_file_runner_init', |
|
| 188 | - 'ee_job_i18n', |
|
| 189 | - array( |
|
| 190 | - 'download_and_redirecting' => sprintf( |
|
| 191 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
| 192 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 193 | - '</a>' |
|
| 194 | - ), |
|
| 195 | - 'return_url' => $_REQUEST['return_url'], |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - } |
|
| 171 | + /** |
|
| 172 | + * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
| 173 | + */ |
|
| 174 | + public function enqueue_scripts_styles_batch_file_create() |
|
| 175 | + { |
|
| 176 | + // creates a job based on the request variable |
|
| 177 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 178 | + wp_enqueue_script( |
|
| 179 | + 'batch_file_runner_init', |
|
| 180 | + BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 181 | + array('batch_runner'), |
|
| 182 | + EVENT_ESPRESSO_VERSION, |
|
| 183 | + true |
|
| 184 | + ); |
|
| 185 | + wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 186 | + wp_localize_script( |
|
| 187 | + 'batch_file_runner_init', |
|
| 188 | + 'ee_job_i18n', |
|
| 189 | + array( |
|
| 190 | + 'download_and_redirecting' => sprintf( |
|
| 191 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
| 192 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 193 | + '</a>' |
|
| 194 | + ), |
|
| 195 | + 'return_url' => $_REQUEST['return_url'], |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * Enqueues scripts and styles common to any batch job, and creates |
|
| 202 | - * a job from the request data, and stores the response in the |
|
| 203 | - * $this->_job_step_response property |
|
| 204 | - * |
|
| 205 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 206 | - */ |
|
| 207 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
| 208 | - { |
|
| 209 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
| 210 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 211 | - 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
| 212 | - 'event_espresso' |
|
| 213 | - ); |
|
| 214 | - wp_register_script( |
|
| 215 | - 'progress_bar', |
|
| 216 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 217 | - array('jquery'), |
|
| 218 | - EVENT_ESPRESSO_VERSION, |
|
| 219 | - true |
|
| 220 | - ); |
|
| 221 | - wp_enqueue_style( |
|
| 222 | - 'progress_bar', |
|
| 223 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 224 | - array(), |
|
| 225 | - EVENT_ESPRESSO_VERSION |
|
| 226 | - ); |
|
| 227 | - wp_enqueue_script( |
|
| 228 | - 'batch_runner', |
|
| 229 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 230 | - array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
| 231 | - EVENT_ESPRESSO_VERSION, |
|
| 232 | - true |
|
| 233 | - ); |
|
| 234 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
| 235 | - $request_data = array_diff_key( |
|
| 236 | - $_REQUEST, |
|
| 237 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
| 238 | - ); |
|
| 239 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 240 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
| 241 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 242 | - // remember the response for later. We need it to display the page body |
|
| 243 | - $this->_job_step_response = $job_response; |
|
| 244 | - return $job_response; |
|
| 245 | - } |
|
| 200 | + /** |
|
| 201 | + * Enqueues scripts and styles common to any batch job, and creates |
|
| 202 | + * a job from the request data, and stores the response in the |
|
| 203 | + * $this->_job_step_response property |
|
| 204 | + * |
|
| 205 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 206 | + */ |
|
| 207 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
| 208 | + { |
|
| 209 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
| 210 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 211 | + 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
| 212 | + 'event_espresso' |
|
| 213 | + ); |
|
| 214 | + wp_register_script( |
|
| 215 | + 'progress_bar', |
|
| 216 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 217 | + array('jquery'), |
|
| 218 | + EVENT_ESPRESSO_VERSION, |
|
| 219 | + true |
|
| 220 | + ); |
|
| 221 | + wp_enqueue_style( |
|
| 222 | + 'progress_bar', |
|
| 223 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 224 | + array(), |
|
| 225 | + EVENT_ESPRESSO_VERSION |
|
| 226 | + ); |
|
| 227 | + wp_enqueue_script( |
|
| 228 | + 'batch_runner', |
|
| 229 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 230 | + array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
| 231 | + EVENT_ESPRESSO_VERSION, |
|
| 232 | + true |
|
| 233 | + ); |
|
| 234 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
| 235 | + $request_data = array_diff_key( |
|
| 236 | + $_REQUEST, |
|
| 237 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
| 238 | + ); |
|
| 239 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 240 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
| 241 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 242 | + // remember the response for later. We need it to display the page body |
|
| 243 | + $this->_job_step_response = $job_response; |
|
| 244 | + return $job_response; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
| 249 | - * |
|
| 250 | - * @param string $template |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public function override_template($template) |
|
| 254 | - { |
|
| 255 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
| 256 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 257 | - } |
|
| 258 | - return $template; |
|
| 259 | - } |
|
| 247 | + /** |
|
| 248 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
| 249 | + * |
|
| 250 | + * @param string $template |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + public function override_template($template) |
|
| 254 | + { |
|
| 255 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
| 256 | + return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 257 | + } |
|
| 258 | + return $template; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Adds an admin page which doesn't appear in the admin menu |
|
| 263 | - */ |
|
| 264 | - public function register_admin_pages() |
|
| 265 | - { |
|
| 266 | - add_submenu_page( |
|
| 267 | - '', // parent slug. we don't want this to actually appear in the menu |
|
| 268 | - __('Batch Job', 'event_espresso'), // page title |
|
| 269 | - 'n/a', // menu title |
|
| 270 | - 'read', // we want this page to actually be accessible to anyone, |
|
| 271 | - 'espresso_batch', // menu slug |
|
| 272 | - array(self::instance(), 'show_admin_page') |
|
| 273 | - ); |
|
| 274 | - } |
|
| 261 | + /** |
|
| 262 | + * Adds an admin page which doesn't appear in the admin menu |
|
| 263 | + */ |
|
| 264 | + public function register_admin_pages() |
|
| 265 | + { |
|
| 266 | + add_submenu_page( |
|
| 267 | + '', // parent slug. we don't want this to actually appear in the menu |
|
| 268 | + __('Batch Job', 'event_espresso'), // page title |
|
| 269 | + 'n/a', // menu title |
|
| 270 | + 'read', // we want this page to actually be accessible to anyone, |
|
| 271 | + 'espresso_batch', // menu slug |
|
| 272 | + array(self::instance(), 'show_admin_page') |
|
| 273 | + ); |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
| 278 | - * of creating the job and localizing some data |
|
| 279 | - */ |
|
| 280 | - public function show_admin_page() |
|
| 281 | - { |
|
| 282 | - echo EEH_Template::locate_template( |
|
| 283 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 284 | - array('batch_request_type' => $this->batch_request_type()) |
|
| 285 | - ); |
|
| 286 | - } |
|
| 276 | + /** |
|
| 277 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
| 278 | + * of creating the job and localizing some data |
|
| 279 | + */ |
|
| 280 | + public function show_admin_page() |
|
| 281 | + { |
|
| 282 | + echo EEH_Template::locate_template( |
|
| 283 | + EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 284 | + array('batch_request_type' => $this->batch_request_type()) |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Receives ajax calls for continuing a job |
|
| 290 | - */ |
|
| 291 | - public function batch_continue() |
|
| 292 | - { |
|
| 293 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 294 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 295 | - $response_obj = $batch_runner->continue_job($job_id); |
|
| 296 | - $this->_return_json($response_obj->to_array()); |
|
| 297 | - } |
|
| 288 | + /** |
|
| 289 | + * Receives ajax calls for continuing a job |
|
| 290 | + */ |
|
| 291 | + public function batch_continue() |
|
| 292 | + { |
|
| 293 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 294 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 295 | + $response_obj = $batch_runner->continue_job($job_id); |
|
| 296 | + $this->_return_json($response_obj->to_array()); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Receives the ajax call to cleanup a job |
|
| 301 | - * |
|
| 302 | - * @return type |
|
| 303 | - */ |
|
| 304 | - public function batch_cleanup() |
|
| 305 | - { |
|
| 306 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 307 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 308 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 309 | - $this->_return_json($response_obj->to_array()); |
|
| 310 | - } |
|
| 299 | + /** |
|
| 300 | + * Receives the ajax call to cleanup a job |
|
| 301 | + * |
|
| 302 | + * @return type |
|
| 303 | + */ |
|
| 304 | + public function batch_cleanup() |
|
| 305 | + { |
|
| 306 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 307 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 308 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 309 | + $this->_return_json($response_obj->to_array()); |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * Returns a json response |
|
| 315 | - * |
|
| 316 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
| 317 | - * |
|
| 318 | - * The returned json object is created from an array in the following format: |
|
| 319 | - * array( |
|
| 320 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 321 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 322 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
| 323 | - * args that might be included in here) |
|
| 324 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
| 325 | - * ) |
|
| 326 | - */ |
|
| 327 | - protected function _return_json($data) |
|
| 328 | - { |
|
| 329 | - $json = array( |
|
| 330 | - 'notices' => EE_Error::get_notices(), |
|
| 331 | - 'data' => $data, |
|
| 332 | - 'isEEajax' => true |
|
| 333 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 334 | - ); |
|
| 313 | + /** |
|
| 314 | + * Returns a json response |
|
| 315 | + * |
|
| 316 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
| 317 | + * |
|
| 318 | + * The returned json object is created from an array in the following format: |
|
| 319 | + * array( |
|
| 320 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 321 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 322 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
| 323 | + * args that might be included in here) |
|
| 324 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
| 325 | + * ) |
|
| 326 | + */ |
|
| 327 | + protected function _return_json($data) |
|
| 328 | + { |
|
| 329 | + $json = array( |
|
| 330 | + 'notices' => EE_Error::get_notices(), |
|
| 331 | + 'data' => $data, |
|
| 332 | + 'isEEajax' => true |
|
| 333 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 334 | + ); |
|
| 335 | 335 | |
| 336 | 336 | |
| 337 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 338 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 339 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 340 | - } |
|
| 341 | - echo wp_json_encode($json); |
|
| 342 | - exit(); |
|
| 343 | - } |
|
| 337 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 338 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 339 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 340 | + } |
|
| 341 | + echo wp_json_encode($json); |
|
| 342 | + exit(); |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - /** |
|
| 346 | - * Gets the job step response which was done during the enqueuing of scripts |
|
| 347 | - * |
|
| 348 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 349 | - */ |
|
| 350 | - public function job_step_response() |
|
| 351 | - { |
|
| 352 | - return $this->_job_step_response; |
|
| 353 | - } |
|
| 345 | + /** |
|
| 346 | + * Gets the job step response which was done during the enqueuing of scripts |
|
| 347 | + * |
|
| 348 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 349 | + */ |
|
| 350 | + public function job_step_response() |
|
| 351 | + { |
|
| 352 | + return $this->_job_step_response; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * Gets the batch request type indicated in the $_REQUEST |
|
| 357 | - * |
|
| 358 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
| 359 | - */ |
|
| 360 | - public function batch_request_type() |
|
| 361 | - { |
|
| 362 | - if ($this->_batch_request_type === null) { |
|
| 363 | - if (isset($_GET['batch'])) { |
|
| 364 | - if ($_GET['batch'] == self::batch_job) { |
|
| 365 | - $this->_batch_request_type = self::batch_job; |
|
| 366 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
| 367 | - $this->_batch_request_type = self::batch_file_job; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
| 371 | - if ($this->_batch_request_type === null) { |
|
| 372 | - $this->_batch_request_type = self::batch_not_job; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - return $this->_batch_request_type; |
|
| 376 | - } |
|
| 355 | + /** |
|
| 356 | + * Gets the batch request type indicated in the $_REQUEST |
|
| 357 | + * |
|
| 358 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
| 359 | + */ |
|
| 360 | + public function batch_request_type() |
|
| 361 | + { |
|
| 362 | + if ($this->_batch_request_type === null) { |
|
| 363 | + if (isset($_GET['batch'])) { |
|
| 364 | + if ($_GET['batch'] == self::batch_job) { |
|
| 365 | + $this->_batch_request_type = self::batch_job; |
|
| 366 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
| 367 | + $this->_batch_request_type = self::batch_file_job; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
| 371 | + if ($this->_batch_request_type === null) { |
|
| 372 | + $this->_batch_request_type = self::batch_not_job; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + return $this->_batch_request_type; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - /** |
|
| 379 | - * Unnecessary |
|
| 380 | - * |
|
| 381 | - * @param type $WP |
|
| 382 | - */ |
|
| 383 | - public function run($WP) |
|
| 384 | - { |
|
| 385 | - } |
|
| 378 | + /** |
|
| 379 | + * Unnecessary |
|
| 380 | + * |
|
| 381 | + * @param type $WP |
|
| 382 | + */ |
|
| 383 | + public function run($WP) |
|
| 384 | + { |
|
| 385 | + } |
|
| 386 | 386 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | protected function getLoader() |
| 115 | 115 | { |
| 116 | - if (!$this->loader instanceof LoaderInterface) { |
|
| 116 | + if ( ! $this->loader instanceof LoaderInterface) { |
|
| 117 | 117 | $this->loader = LoaderFactory::getLoader(); |
| 118 | 118 | } |
| 119 | 119 | return $this->loader; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | && $_REQUEST['page'] == 'espresso_batch' |
| 132 | 132 | ) |
| 133 | 133 | ) { |
| 134 | - if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
| 134 | + if ( ! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
| 135 | 135 | wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
| 136 | 136 | } |
| 137 | 137 | switch ($this->batch_request_type()) { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
| 154 | 154 | wp_enqueue_script( |
| 155 | 155 | 'batch_runner_init', |
| 156 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
| 156 | + BATCH_URL.'assets/batch_runner_init.js', |
|
| 157 | 157 | array('batch_runner'), |
| 158 | 158 | EVENT_ESPRESSO_VERSION, |
| 159 | 159 | true |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
| 178 | 178 | wp_enqueue_script( |
| 179 | 179 | 'batch_file_runner_init', |
| 180 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 180 | + BATCH_URL.'assets/batch_file_runner_init.js', |
|
| 181 | 181 | array('batch_runner'), |
| 182 | 182 | EVENT_ESPRESSO_VERSION, |
| 183 | 183 | true |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | array( |
| 190 | 190 | 'download_and_redirecting' => sprintf( |
| 191 | 191 | __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
| 192 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 192 | + '<a href="'.$_REQUEST['return_url'].'">', |
|
| 193 | 193 | '</a>' |
| 194 | 194 | ), |
| 195 | 195 | 'return_url' => $_REQUEST['return_url'], |
@@ -207,26 +207,26 @@ discard block |
||
| 207 | 207 | protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
| 208 | 208 | { |
| 209 | 209 | // just copy the bits of EE admin's eei18n that we need in the JS |
| 210 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 210 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
| 211 | 211 | 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
| 212 | 212 | 'event_espresso' |
| 213 | 213 | ); |
| 214 | 214 | wp_register_script( |
| 215 | 215 | 'progress_bar', |
| 216 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 216 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', |
|
| 217 | 217 | array('jquery'), |
| 218 | 218 | EVENT_ESPRESSO_VERSION, |
| 219 | 219 | true |
| 220 | 220 | ); |
| 221 | 221 | wp_enqueue_style( |
| 222 | 222 | 'progress_bar', |
| 223 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 223 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', |
|
| 224 | 224 | array(), |
| 225 | 225 | EVENT_ESPRESSO_VERSION |
| 226 | 226 | ); |
| 227 | 227 | wp_enqueue_script( |
| 228 | 228 | 'batch_runner', |
| 229 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 229 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', |
|
| 230 | 230 | array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
| 231 | 231 | EVENT_ESPRESSO_VERSION, |
| 232 | 232 | true |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | public function override_template($template) |
| 254 | 254 | { |
| 255 | 255 | if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
| 256 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 256 | + return EE_MODULES.'batch'.DS.'templates'.DS.'batch_frontend_wrapper.template.html'; |
|
| 257 | 257 | } |
| 258 | 258 | return $template; |
| 259 | 259 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | public function show_admin_page() |
| 281 | 281 | { |
| 282 | 282 | echo EEH_Template::locate_template( |
| 283 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 283 | + EE_MODULES.'batch'.DS.'templates'.DS.'batch_wrapper.template.html', |
|
| 284 | 284 | array('batch_request_type' => $this->batch_request_type()) |
| 285 | 285 | ); |
| 286 | 286 | } |
@@ -12,2893 +12,2893 @@ |
||
| 12 | 12 | class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @access protected |
|
| 17 | - * @var EE_Line_Item_Display $Line_Item_Display |
|
| 18 | - */ |
|
| 19 | - protected $line_item_display; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @access protected |
|
| 23 | - * @var boolean $handle_IPN_in_this_request |
|
| 24 | - */ |
|
| 25 | - protected $handle_IPN_in_this_request = false; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 30 | - * |
|
| 31 | - * @access public |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public static function set_hooks() |
|
| 35 | - { |
|
| 36 | - add_filter( |
|
| 37 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 38 | - array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
| 39 | - ); |
|
| 40 | - add_action( |
|
| 41 | - 'wp_ajax_switch_spco_billing_form', |
|
| 42 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 43 | - ); |
|
| 44 | - add_action( |
|
| 45 | - 'wp_ajax_nopriv_switch_spco_billing_form', |
|
| 46 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 47 | - ); |
|
| 48 | - add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
| 49 | - add_action( |
|
| 50 | - 'wp_ajax_nopriv_save_payer_details', |
|
| 51 | - array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
| 52 | - ); |
|
| 53 | - add_action( |
|
| 54 | - 'wp_ajax_get_transaction_details_for_gateways', |
|
| 55 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 56 | - ); |
|
| 57 | - add_action( |
|
| 58 | - 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
| 59 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 60 | - ); |
|
| 61 | - add_filter( |
|
| 62 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
| 63 | - array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
| 64 | - 10, |
|
| 65 | - 1 |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * ajax switch_spco_billing_form |
|
| 72 | - * |
|
| 73 | - * @throws \EE_Error |
|
| 74 | - */ |
|
| 75 | - public static function switch_spco_billing_form() |
|
| 76 | - { |
|
| 77 | - EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * ajax save_payer_details |
|
| 83 | - * |
|
| 84 | - * @throws \EE_Error |
|
| 85 | - */ |
|
| 86 | - public static function save_payer_details() |
|
| 87 | - { |
|
| 88 | - EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * ajax get_transaction_details |
|
| 94 | - * |
|
| 95 | - * @throws \EE_Error |
|
| 96 | - */ |
|
| 97 | - public static function get_transaction_details() |
|
| 98 | - { |
|
| 99 | - EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * bypass_recaptcha_for_load_payment_method |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @return array |
|
| 108 | - * @throws InvalidArgumentException |
|
| 109 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 110 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 111 | - */ |
|
| 112 | - public static function bypass_recaptcha_for_load_payment_method() |
|
| 113 | - { |
|
| 114 | - return array( |
|
| 115 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
| 116 | - 'step' => 'payment_options', |
|
| 117 | - 'action' => 'spco_billing_form', |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * class constructor |
|
| 124 | - * |
|
| 125 | - * @access public |
|
| 126 | - * @param EE_Checkout $checkout |
|
| 127 | - */ |
|
| 128 | - public function __construct(EE_Checkout $checkout) |
|
| 129 | - { |
|
| 130 | - $this->_slug = 'payment_options'; |
|
| 131 | - $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
| 132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
| 133 | - $this->checkout = $checkout; |
|
| 134 | - $this->_reset_success_message(); |
|
| 135 | - $this->set_instructions( |
|
| 136 | - esc_html__( |
|
| 137 | - 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
| 138 | - 'event_espresso' |
|
| 139 | - ) |
|
| 140 | - ); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return null |
|
| 146 | - */ |
|
| 147 | - public function line_item_display() |
|
| 148 | - { |
|
| 149 | - return $this->line_item_display; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param null $line_item_display |
|
| 155 | - */ |
|
| 156 | - public function set_line_item_display($line_item_display) |
|
| 157 | - { |
|
| 158 | - $this->line_item_display = $line_item_display; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return boolean |
|
| 164 | - */ |
|
| 165 | - public function handle_IPN_in_this_request() |
|
| 166 | - { |
|
| 167 | - return $this->handle_IPN_in_this_request; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param boolean $handle_IPN_in_this_request |
|
| 173 | - */ |
|
| 174 | - public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
| 175 | - { |
|
| 176 | - $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * translate_js_strings |
|
| 182 | - * |
|
| 183 | - * @return void |
|
| 184 | - */ |
|
| 185 | - public function translate_js_strings() |
|
| 186 | - { |
|
| 187 | - EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
| 188 | - 'Please select a method of payment in order to continue.', |
|
| 189 | - 'event_espresso' |
|
| 190 | - ); |
|
| 191 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
| 192 | - 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
| 193 | - 'event_espresso' |
|
| 194 | - ); |
|
| 195 | - EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
| 196 | - 'Forwarding to Secure Payment Provider.', |
|
| 197 | - 'event_espresso' |
|
| 198 | - ); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * enqueue_styles_and_scripts |
|
| 204 | - * |
|
| 205 | - * @return void |
|
| 206 | - * @throws EE_Error |
|
| 207 | - * @throws InvalidArgumentException |
|
| 208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 210 | - */ |
|
| 211 | - public function enqueue_styles_and_scripts() |
|
| 212 | - { |
|
| 213 | - $transaction = $this->checkout->transaction; |
|
| 214 | - // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
| 215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 216 | - return; |
|
| 217 | - } |
|
| 218 | - foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 219 | - $transaction, |
|
| 220 | - EEM_Payment_Method::scope_cart |
|
| 221 | - ) as $payment_method) { |
|
| 222 | - $type_obj = $payment_method->type_obj(); |
|
| 223 | - if ($type_obj instanceof EE_PMT_Base) { |
|
| 224 | - $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
| 225 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 226 | - $billing_form->enqueue_js(); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * initialize_reg_step |
|
| 235 | - * |
|
| 236 | - * @return bool |
|
| 237 | - * @throws EE_Error |
|
| 238 | - * @throws InvalidArgumentException |
|
| 239 | - * @throws ReflectionException |
|
| 240 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 241 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 242 | - */ |
|
| 243 | - public function initialize_reg_step() |
|
| 244 | - { |
|
| 245 | - // TODO: if /when we implement donations, then this will need overriding |
|
| 246 | - if (// don't need payment options for: |
|
| 247 | - // registrations made via the admin |
|
| 248 | - // completed transactions |
|
| 249 | - // overpaid transactions |
|
| 250 | - // $ 0.00 transactions(no payment required) |
|
| 251 | - ! $this->checkout->payment_required() |
|
| 252 | - // but do NOT remove if current action being called belongs to this reg step |
|
| 253 | - && ! is_callable(array($this, $this->checkout->action)) |
|
| 254 | - && ! $this->completed() |
|
| 255 | - ) { |
|
| 256 | - // and if so, then we no longer need the Payment Options step |
|
| 257 | - if ($this->is_current_step()) { |
|
| 258 | - $this->checkout->generate_reg_form = false; |
|
| 259 | - } |
|
| 260 | - $this->checkout->remove_reg_step($this->_slug); |
|
| 261 | - // DEBUG LOG |
|
| 262 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - // load EEM_Payment_Method |
|
| 266 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 267 | - // get all active payment methods |
|
| 268 | - $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 269 | - $this->checkout->transaction, |
|
| 270 | - EEM_Payment_Method::scope_cart |
|
| 271 | - ); |
|
| 272 | - return true; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @return EE_Form_Section_Proper |
|
| 278 | - * @throws EE_Error |
|
| 279 | - * @throws InvalidArgumentException |
|
| 280 | - * @throws ReflectionException |
|
| 281 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 282 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 283 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 284 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 285 | - */ |
|
| 286 | - public function generate_reg_form() |
|
| 287 | - { |
|
| 288 | - // reset in case someone changes their mind |
|
| 289 | - $this->_reset_selected_method_of_payment(); |
|
| 290 | - // set some defaults |
|
| 291 | - $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
| 292 | - $registrations_requiring_payment = array(); |
|
| 293 | - $registrations_for_free_events = array(); |
|
| 294 | - $registrations_requiring_pre_approval = array(); |
|
| 295 | - $sold_out_events = array(); |
|
| 296 | - $insufficient_spaces_available = array(); |
|
| 297 | - $no_payment_required = true; |
|
| 298 | - // loop thru registrations to gather info |
|
| 299 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 300 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 301 | - $registrations, |
|
| 302 | - $this->checkout->revisit |
|
| 303 | - ); |
|
| 304 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 305 | - /** @var $registration EE_Registration */ |
|
| 306 | - // has this registration lost it's space ? |
|
| 307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 308 | - if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
| 309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 310 | - } else { |
|
| 311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
| 312 | - } |
|
| 313 | - continue; |
|
| 314 | - } |
|
| 315 | - // event requires admin approval |
|
| 316 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
| 317 | - // add event to list of events with pre-approval reg status |
|
| 318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
| 319 | - do_action( |
|
| 320 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
| 321 | - $registration->event(), |
|
| 322 | - $this |
|
| 323 | - ); |
|
| 324 | - continue; |
|
| 325 | - } |
|
| 326 | - if ($this->checkout->revisit |
|
| 327 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 328 | - && ( |
|
| 329 | - $registration->event()->is_sold_out() |
|
| 330 | - || $registration->event()->is_sold_out(true) |
|
| 331 | - ) |
|
| 332 | - ) { |
|
| 333 | - // add event to list of events that are sold out |
|
| 334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 335 | - do_action( |
|
| 336 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
| 337 | - $registration->event(), |
|
| 338 | - $this |
|
| 339 | - ); |
|
| 340 | - continue; |
|
| 341 | - } |
|
| 342 | - // are they allowed to pay now and is there monies owing? |
|
| 343 | - if ($registration->owes_monies_and_can_pay()) { |
|
| 344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
| 345 | - do_action( |
|
| 346 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
| 347 | - $registration->event(), |
|
| 348 | - $this |
|
| 349 | - ); |
|
| 350 | - } elseif (! $this->checkout->revisit |
|
| 351 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 352 | - && $registration->ticket()->is_free() |
|
| 353 | - ) { |
|
| 354 | - $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $subsections = array(); |
|
| 358 | - // now decide which template to load |
|
| 359 | - if (! empty($sold_out_events)) { |
|
| 360 | - $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
| 361 | - } |
|
| 362 | - if (! empty($insufficient_spaces_available)) { |
|
| 363 | - $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
| 364 | - $insufficient_spaces_available |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
| 368 | - $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
| 369 | - $registrations_requiring_pre_approval |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - if (! empty($registrations_for_free_events)) { |
|
| 373 | - $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
| 374 | - } |
|
| 375 | - if (! empty($registrations_requiring_payment)) { |
|
| 376 | - if ($this->checkout->amount_owing > 0) { |
|
| 377 | - // autoload Line_Item_Display classes |
|
| 378 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 379 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 380 | - apply_filters( |
|
| 381 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 382 | - new EE_Line_Item_Filter_Collection() |
|
| 383 | - ), |
|
| 384 | - $this->checkout->cart->get_grand_total() |
|
| 385 | - ); |
|
| 386 | - /** @var EE_Line_Item $filtered_line_item_tree */ |
|
| 387 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 388 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 389 | - $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
| 390 | - $subsections['payment_options'] = $this->_display_payment_options( |
|
| 391 | - $this->line_item_display->display_line_item( |
|
| 392 | - $filtered_line_item_tree, |
|
| 393 | - array('registrations' => $registrations) |
|
| 394 | - ) |
|
| 395 | - ); |
|
| 396 | - $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
| 397 | - $this->_apply_registration_payments_to_amount_owing($registrations); |
|
| 398 | - } |
|
| 399 | - $no_payment_required = false; |
|
| 400 | - } else { |
|
| 401 | - $this->_hide_reg_step_submit_button_if_revisit(); |
|
| 402 | - } |
|
| 403 | - $this->_save_selected_method_of_payment(); |
|
| 404 | - |
|
| 405 | - $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
| 406 | - $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
| 407 | - |
|
| 408 | - return new EE_Form_Section_Proper( |
|
| 409 | - array( |
|
| 410 | - 'name' => $this->reg_form_name(), |
|
| 411 | - 'html_id' => $this->reg_form_name(), |
|
| 412 | - 'subsections' => $subsections, |
|
| 413 | - 'layout_strategy' => new EE_No_Layout(), |
|
| 414 | - ) |
|
| 415 | - ); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * add line item filters required for this reg step |
|
| 421 | - * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
| 422 | - * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 423 | - * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
| 424 | - * payment options reg step, can apply these filters via the following: apply_filters( |
|
| 425 | - * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
| 426 | - * filter collection by passing that instead of instantiating a new collection |
|
| 427 | - * |
|
| 428 | - * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
| 429 | - * @return EE_Line_Item_Filter_Collection |
|
| 430 | - * @throws EE_Error |
|
| 431 | - * @throws InvalidArgumentException |
|
| 432 | - * @throws ReflectionException |
|
| 433 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 434 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 435 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 436 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 437 | - */ |
|
| 438 | - public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
| 439 | - { |
|
| 440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 441 | - return $line_item_filter_collection; |
|
| 442 | - } |
|
| 443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 444 | - return $line_item_filter_collection; |
|
| 445 | - } |
|
| 446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 447 | - return $line_item_filter_collection; |
|
| 448 | - } |
|
| 449 | - $line_item_filter_collection->add( |
|
| 450 | - new EE_Billable_Line_Item_Filter( |
|
| 451 | - EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
| 452 | - EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 453 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 454 | - ) |
|
| 455 | - ) |
|
| 456 | - ) |
|
| 457 | - ); |
|
| 458 | - $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 459 | - return $line_item_filter_collection; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * remove_ejected_registrations |
|
| 465 | - * if a registrant has lost their potential space at an event due to lack of payment, |
|
| 466 | - * then this method removes them from the list of registrations being paid for during this request |
|
| 467 | - * |
|
| 468 | - * @param \EE_Registration[] $registrations |
|
| 469 | - * @return EE_Registration[] |
|
| 470 | - * @throws EE_Error |
|
| 471 | - * @throws InvalidArgumentException |
|
| 472 | - * @throws ReflectionException |
|
| 473 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 474 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 475 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 476 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 477 | - */ |
|
| 478 | - public static function remove_ejected_registrations(array $registrations) |
|
| 479 | - { |
|
| 480 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 481 | - $registrations, |
|
| 482 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
| 483 | - ); |
|
| 484 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 485 | - // has this registration lost it's space ? |
|
| 486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 487 | - unset($registrations[ $REG_ID ]); |
|
| 488 | - continue; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - return $registrations; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * find_registrations_that_lost_their_space |
|
| 497 | - * If a registrant chooses an offline payment method like Invoice, |
|
| 498 | - * then no space is reserved for them at the event until they fully pay fo that site |
|
| 499 | - * (unless the event's default reg status is set to APPROVED) |
|
| 500 | - * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
| 501 | - * then this method will determine which registrations have lost the ability to complete the reg process. |
|
| 502 | - * |
|
| 503 | - * @param \EE_Registration[] $registrations |
|
| 504 | - * @param bool $revisit |
|
| 505 | - * @return array |
|
| 506 | - * @throws EE_Error |
|
| 507 | - * @throws InvalidArgumentException |
|
| 508 | - * @throws ReflectionException |
|
| 509 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 510 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 511 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 512 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 513 | - */ |
|
| 514 | - public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
| 515 | - { |
|
| 516 | - // registrations per event |
|
| 517 | - $event_reg_count = array(); |
|
| 518 | - // spaces left per event |
|
| 519 | - $event_spaces_remaining = array(); |
|
| 520 | - // tickets left sorted by ID |
|
| 521 | - $tickets_remaining = array(); |
|
| 522 | - // registrations that have lost their space |
|
| 523 | - $ejected_registrations = array(); |
|
| 524 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 525 | - if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
| 526 | - || apply_filters( |
|
| 527 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
| 528 | - false, |
|
| 529 | - $registration, |
|
| 530 | - $revisit |
|
| 531 | - ) |
|
| 532 | - ) { |
|
| 533 | - continue; |
|
| 534 | - } |
|
| 535 | - $EVT_ID = $registration->event_ID(); |
|
| 536 | - $ticket = $registration->ticket(); |
|
| 537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
| 538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
| 539 | - } |
|
| 540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
| 541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
| 542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
| 543 | - } |
|
| 544 | - $event_reg_count[ $EVT_ID ]++; |
|
| 545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
| 546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - if ($revisit |
|
| 550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
| 551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
| 552 | - ) |
|
| 553 | - ) { |
|
| 554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
| 555 | - if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
| 556 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 557 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 558 | - // at this point, we should have enough details about the registrant to consider the registration |
|
| 559 | - // NOT incomplete |
|
| 560 | - $registration_processor->manually_update_registration_status( |
|
| 561 | - $registration, |
|
| 562 | - EEM_Registration::status_id_wait_list |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - return $ejected_registrations; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * _hide_reg_step_submit_button |
|
| 573 | - * removes the html for the reg step submit button |
|
| 574 | - * by replacing it with an empty string via filter callback |
|
| 575 | - * |
|
| 576 | - * @return void |
|
| 577 | - */ |
|
| 578 | - protected function _adjust_registration_status_if_event_old_sold() |
|
| 579 | - { |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * _hide_reg_step_submit_button |
|
| 585 | - * removes the html for the reg step submit button |
|
| 586 | - * by replacing it with an empty string via filter callback |
|
| 587 | - * |
|
| 588 | - * @return void |
|
| 589 | - */ |
|
| 590 | - protected function _hide_reg_step_submit_button_if_revisit() |
|
| 591 | - { |
|
| 592 | - if ($this->checkout->revisit) { |
|
| 593 | - add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * sold_out_events |
|
| 600 | - * displays notices regarding events that have sold out since hte registrant first signed up |
|
| 601 | - * |
|
| 602 | - * @param \EE_Event[] $sold_out_events_array |
|
| 603 | - * @return \EE_Form_Section_Proper |
|
| 604 | - * @throws \EE_Error |
|
| 605 | - */ |
|
| 606 | - private function _sold_out_events($sold_out_events_array = array()) |
|
| 607 | - { |
|
| 608 | - // set some defaults |
|
| 609 | - $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
| 610 | - $sold_out_events = ''; |
|
| 611 | - foreach ($sold_out_events_array as $sold_out_event) { |
|
| 612 | - $sold_out_events .= EEH_HTML::li( |
|
| 613 | - EEH_HTML::span( |
|
| 614 | - ' ' . $sold_out_event->name(), |
|
| 615 | - '', |
|
| 616 | - 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
| 617 | - ) |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - return new EE_Form_Section_Proper( |
|
| 621 | - array( |
|
| 622 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 623 | - array( |
|
| 624 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 625 | - . $this->_slug |
|
| 626 | - . DS |
|
| 627 | - . 'sold_out_events.template.php', |
|
| 628 | - 'template_args' => apply_filters( |
|
| 629 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 630 | - array( |
|
| 631 | - 'sold_out_events' => $sold_out_events, |
|
| 632 | - 'sold_out_events_msg' => apply_filters( |
|
| 633 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
| 634 | - sprintf( |
|
| 635 | - esc_html__( |
|
| 636 | - 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
| 637 | - 'event_espresso' |
|
| 638 | - ), |
|
| 639 | - '<strong>', |
|
| 640 | - '</strong>', |
|
| 641 | - '<br />' |
|
| 642 | - ) |
|
| 643 | - ), |
|
| 644 | - ) |
|
| 645 | - ), |
|
| 646 | - ) |
|
| 647 | - ), |
|
| 648 | - ) |
|
| 649 | - ); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * _insufficient_spaces_available |
|
| 655 | - * displays notices regarding events that do not have enough remaining spaces |
|
| 656 | - * to satisfy the current number of registrations looking to pay |
|
| 657 | - * |
|
| 658 | - * @param \EE_Event[] $insufficient_spaces_events_array |
|
| 659 | - * @return \EE_Form_Section_Proper |
|
| 660 | - * @throws \EE_Error |
|
| 661 | - */ |
|
| 662 | - private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
| 663 | - { |
|
| 664 | - // set some defaults |
|
| 665 | - $this->checkout->selected_method_of_payment = 'invoice'; |
|
| 666 | - $insufficient_space_events = ''; |
|
| 667 | - foreach ($insufficient_spaces_events_array as $event) { |
|
| 668 | - if ($event instanceof EE_Event) { |
|
| 669 | - $insufficient_space_events .= EEH_HTML::li( |
|
| 670 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 671 | - ); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - return new EE_Form_Section_Proper( |
|
| 675 | - array( |
|
| 676 | - 'subsections' => array( |
|
| 677 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
| 678 | - 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
| 679 | - ), |
|
| 680 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 681 | - array( |
|
| 682 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 683 | - . $this->_slug |
|
| 684 | - . DS |
|
| 685 | - . 'sold_out_events.template.php', |
|
| 686 | - 'template_args' => apply_filters( |
|
| 687 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
| 688 | - array( |
|
| 689 | - 'sold_out_events' => $insufficient_space_events, |
|
| 690 | - 'sold_out_events_msg' => apply_filters( |
|
| 691 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
| 692 | - esc_html__( |
|
| 693 | - 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 694 | - 'event_espresso' |
|
| 695 | - ) |
|
| 696 | - ), |
|
| 697 | - ) |
|
| 698 | - ), |
|
| 699 | - ) |
|
| 700 | - ), |
|
| 701 | - ) |
|
| 702 | - ); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * registrations_requiring_pre_approval |
|
| 708 | - * |
|
| 709 | - * @param array $registrations_requiring_pre_approval |
|
| 710 | - * @return EE_Form_Section_Proper |
|
| 711 | - * @throws EE_Error |
|
| 712 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 713 | - */ |
|
| 714 | - private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
| 715 | - { |
|
| 716 | - $events_requiring_pre_approval = ''; |
|
| 717 | - foreach ($registrations_requiring_pre_approval as $registration) { |
|
| 718 | - if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
| 719 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
| 720 | - EEH_HTML::span( |
|
| 721 | - '', |
|
| 722 | - '', |
|
| 723 | - 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
| 724 | - ) |
|
| 725 | - . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
| 726 | - ); |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - return new EE_Form_Section_Proper( |
|
| 730 | - array( |
|
| 731 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 732 | - array( |
|
| 733 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 734 | - . $this->_slug |
|
| 735 | - . DS |
|
| 736 | - . 'events_requiring_pre_approval.template.php', // layout_template |
|
| 737 | - 'template_args' => apply_filters( |
|
| 738 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 739 | - array( |
|
| 740 | - 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
| 741 | - 'events_requiring_pre_approval_msg' => apply_filters( |
|
| 742 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
| 743 | - esc_html__( |
|
| 744 | - 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
| 745 | - 'event_espresso' |
|
| 746 | - ) |
|
| 747 | - ), |
|
| 748 | - ) |
|
| 749 | - ), |
|
| 750 | - ) |
|
| 751 | - ), |
|
| 752 | - ) |
|
| 753 | - ); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * _no_payment_required |
|
| 759 | - * |
|
| 760 | - * @param \EE_Event[] $registrations_for_free_events |
|
| 761 | - * @return \EE_Form_Section_Proper |
|
| 762 | - * @throws \EE_Error |
|
| 763 | - */ |
|
| 764 | - private function _no_payment_required($registrations_for_free_events = array()) |
|
| 765 | - { |
|
| 766 | - // set some defaults |
|
| 767 | - $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
| 768 | - // generate no_payment_required form |
|
| 769 | - return new EE_Form_Section_Proper( |
|
| 770 | - array( |
|
| 771 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 772 | - array( |
|
| 773 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 774 | - . $this->_slug |
|
| 775 | - . DS |
|
| 776 | - . 'no_payment_required.template.php', // layout_template |
|
| 777 | - 'template_args' => apply_filters( |
|
| 778 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
| 779 | - array( |
|
| 780 | - 'revisit' => $this->checkout->revisit, |
|
| 781 | - 'registrations' => array(), |
|
| 782 | - 'ticket_count' => array(), |
|
| 783 | - 'registrations_for_free_events' => $registrations_for_free_events, |
|
| 784 | - 'no_payment_required_msg' => EEH_HTML::p( |
|
| 785 | - esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
| 786 | - ), |
|
| 787 | - ) |
|
| 788 | - ), |
|
| 789 | - ) |
|
| 790 | - ), |
|
| 791 | - ) |
|
| 792 | - ); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * _display_payment_options |
|
| 798 | - * |
|
| 799 | - * @param string $transaction_details |
|
| 800 | - * @return EE_Form_Section_Proper |
|
| 801 | - * @throws EE_Error |
|
| 802 | - * @throws InvalidArgumentException |
|
| 803 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 804 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 805 | - */ |
|
| 806 | - private function _display_payment_options($transaction_details = '') |
|
| 807 | - { |
|
| 808 | - // has method_of_payment been set by no-js user? |
|
| 809 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
| 810 | - // build payment options form |
|
| 811 | - return apply_filters( |
|
| 812 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
| 813 | - new EE_Form_Section_Proper( |
|
| 814 | - array( |
|
| 815 | - 'subsections' => array( |
|
| 816 | - 'before_payment_options' => apply_filters( |
|
| 817 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
| 818 | - new EE_Form_Section_Proper( |
|
| 819 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 820 | - ) |
|
| 821 | - ), |
|
| 822 | - 'payment_options' => $this->_setup_payment_options(), |
|
| 823 | - 'after_payment_options' => apply_filters( |
|
| 824 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
| 825 | - new EE_Form_Section_Proper( |
|
| 826 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 827 | - ) |
|
| 828 | - ), |
|
| 829 | - ), |
|
| 830 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 831 | - array( |
|
| 832 | - 'layout_template_file' => $this->_template, |
|
| 833 | - 'template_args' => apply_filters( |
|
| 834 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
| 835 | - array( |
|
| 836 | - 'reg_count' => $this->line_item_display->total_items(), |
|
| 837 | - 'transaction_details' => $transaction_details, |
|
| 838 | - 'available_payment_methods' => array(), |
|
| 839 | - ) |
|
| 840 | - ), |
|
| 841 | - ) |
|
| 842 | - ), |
|
| 843 | - ) |
|
| 844 | - ) |
|
| 845 | - ); |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * _extra_hidden_inputs |
|
| 851 | - * |
|
| 852 | - * @param bool $no_payment_required |
|
| 853 | - * @return \EE_Form_Section_Proper |
|
| 854 | - * @throws \EE_Error |
|
| 855 | - */ |
|
| 856 | - private function _extra_hidden_inputs($no_payment_required = true) |
|
| 857 | - { |
|
| 858 | - return new EE_Form_Section_Proper( |
|
| 859 | - array( |
|
| 860 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
| 861 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 862 | - 'subsections' => array( |
|
| 863 | - 'spco_no_payment_required' => new EE_Hidden_Input( |
|
| 864 | - array( |
|
| 865 | - 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
| 866 | - 'html_name' => 'spco_no_payment_required', |
|
| 867 | - 'html_id' => 'spco-no-payment-required-payment_options', |
|
| 868 | - 'default' => $no_payment_required, |
|
| 869 | - ) |
|
| 870 | - ), |
|
| 871 | - 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
| 872 | - array( |
|
| 873 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
| 874 | - 'html_name' => 'spco_transaction_id', |
|
| 875 | - 'html_id' => 'spco-transaction-id', |
|
| 876 | - 'default' => $this->checkout->transaction->ID(), |
|
| 877 | - ) |
|
| 878 | - ), |
|
| 879 | - ), |
|
| 880 | - ) |
|
| 881 | - ); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * _apply_registration_payments_to_amount_owing |
|
| 887 | - * |
|
| 888 | - * @access protected |
|
| 889 | - * @param array $registrations |
|
| 890 | - * @throws EE_Error |
|
| 891 | - */ |
|
| 892 | - protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
| 893 | - { |
|
| 894 | - $payments = array(); |
|
| 895 | - foreach ($registrations as $registration) { |
|
| 896 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 897 | - $payments += $registration->registration_payments(); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - if (! empty($payments)) { |
|
| 901 | - foreach ($payments as $payment) { |
|
| 902 | - if ($payment instanceof EE_Registration_Payment) { |
|
| 903 | - $this->checkout->amount_owing -= $payment->amount(); |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * _reset_selected_method_of_payment |
|
| 912 | - * |
|
| 913 | - * @access private |
|
| 914 | - * @param bool $force_reset |
|
| 915 | - * @return void |
|
| 916 | - * @throws InvalidArgumentException |
|
| 917 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 918 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 919 | - */ |
|
| 920 | - private function _reset_selected_method_of_payment($force_reset = false) |
|
| 921 | - { |
|
| 922 | - $reset_payment_method = $force_reset |
|
| 923 | - ? true |
|
| 924 | - : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
| 925 | - if ($reset_payment_method) { |
|
| 926 | - $this->checkout->selected_method_of_payment = null; |
|
| 927 | - $this->checkout->payment_method = null; |
|
| 928 | - $this->checkout->billing_form = null; |
|
| 929 | - $this->_save_selected_method_of_payment(); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * _save_selected_method_of_payment |
|
| 936 | - * stores the selected_method_of_payment in the session |
|
| 937 | - * so that it's available for all subsequent requests including AJAX |
|
| 938 | - * |
|
| 939 | - * @access private |
|
| 940 | - * @param string $selected_method_of_payment |
|
| 941 | - * @return void |
|
| 942 | - * @throws InvalidArgumentException |
|
| 943 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 944 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 945 | - */ |
|
| 946 | - private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
| 947 | - { |
|
| 948 | - $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
| 949 | - ? $selected_method_of_payment |
|
| 950 | - : $this->checkout->selected_method_of_payment; |
|
| 951 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 952 | - array('selected_method_of_payment' => $selected_method_of_payment) |
|
| 953 | - ); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * _setup_payment_options |
|
| 959 | - * |
|
| 960 | - * @return EE_Form_Section_Proper |
|
| 961 | - * @throws EE_Error |
|
| 962 | - * @throws InvalidArgumentException |
|
| 963 | - * @throws ReflectionException |
|
| 964 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 965 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 966 | - */ |
|
| 967 | - public function _setup_payment_options() |
|
| 968 | - { |
|
| 969 | - // load payment method classes |
|
| 970 | - $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
| 971 | - if (empty($this->checkout->available_payment_methods)) { |
|
| 972 | - EE_Error::add_error( |
|
| 973 | - apply_filters( |
|
| 974 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
| 975 | - sprintf( |
|
| 976 | - esc_html__( |
|
| 977 | - 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
| 978 | - 'event_espresso' |
|
| 979 | - ), |
|
| 980 | - '<br>', |
|
| 981 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 982 | - ) |
|
| 983 | - ), |
|
| 984 | - __FILE__, |
|
| 985 | - __FUNCTION__, |
|
| 986 | - __LINE__ |
|
| 987 | - ); |
|
| 988 | - } |
|
| 989 | - // switch up header depending on number of available payment methods |
|
| 990 | - $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
| 991 | - ? apply_filters( |
|
| 992 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 993 | - esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
| 994 | - ) |
|
| 995 | - : apply_filters( |
|
| 996 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 997 | - esc_html__('Method of Payment', 'event_espresso') |
|
| 998 | - ); |
|
| 999 | - $available_payment_methods = array( |
|
| 1000 | - // display the "Payment Method" header |
|
| 1001 | - 'payment_method_header' => new EE_Form_Section_HTML( |
|
| 1002 | - apply_filters( |
|
| 1003 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
| 1004 | - EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
| 1005 | - $payment_method_header |
|
| 1006 | - ) |
|
| 1007 | - ), |
|
| 1008 | - ); |
|
| 1009 | - // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
| 1010 | - $available_payment_method_options = array(); |
|
| 1011 | - $default_payment_method_option = array(); |
|
| 1012 | - // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
| 1013 | - $payment_methods_billing_info = array( |
|
| 1014 | - new EE_Form_Section_HTML( |
|
| 1015 | - EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
| 1016 | - ), |
|
| 1017 | - ); |
|
| 1018 | - // loop through payment methods |
|
| 1019 | - foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
| 1020 | - if ($payment_method instanceof EE_Payment_Method) { |
|
| 1021 | - $payment_method_button = EEH_HTML::img( |
|
| 1022 | - $payment_method->button_url(), |
|
| 1023 | - $payment_method->name(), |
|
| 1024 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
| 1025 | - 'spco-payment-method-btn-img' |
|
| 1026 | - ); |
|
| 1027 | - // check if any payment methods are set as default |
|
| 1028 | - // if payment method is already selected OR nothing is selected and this payment method should be |
|
| 1029 | - // open_by_default |
|
| 1030 | - if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
| 1031 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1032 | - ) { |
|
| 1033 | - $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
| 1034 | - $this->_save_selected_method_of_payment(); |
|
| 1035 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
| 1036 | - } else { |
|
| 1037 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
| 1038 | - } |
|
| 1039 | - $payment_methods_billing_info[ $payment_method->slug( |
|
| 1040 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
| 1041 | - $payment_method |
|
| 1042 | - ); |
|
| 1043 | - } |
|
| 1044 | - } |
|
| 1045 | - // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
| 1046 | - // of PMs |
|
| 1047 | - $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
| 1048 | - // now generate the actual form inputs |
|
| 1049 | - $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
| 1050 | - $available_payment_method_options |
|
| 1051 | - ); |
|
| 1052 | - $available_payment_methods += $payment_methods_billing_info; |
|
| 1053 | - // build the available payment methods form |
|
| 1054 | - return new EE_Form_Section_Proper( |
|
| 1055 | - array( |
|
| 1056 | - 'html_id' => 'spco-available-methods-of-payment-dv', |
|
| 1057 | - 'subsections' => $available_payment_methods, |
|
| 1058 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1059 | - ) |
|
| 1060 | - ); |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - |
|
| 1064 | - /** |
|
| 1065 | - * _get_available_payment_methods |
|
| 1066 | - * |
|
| 1067 | - * @return EE_Payment_Method[] |
|
| 1068 | - * @throws EE_Error |
|
| 1069 | - * @throws InvalidArgumentException |
|
| 1070 | - * @throws ReflectionException |
|
| 1071 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1072 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1073 | - */ |
|
| 1074 | - protected function _get_available_payment_methods() |
|
| 1075 | - { |
|
| 1076 | - if (! empty($this->checkout->available_payment_methods)) { |
|
| 1077 | - return $this->checkout->available_payment_methods; |
|
| 1078 | - } |
|
| 1079 | - $available_payment_methods = array(); |
|
| 1080 | - // load EEM_Payment_Method |
|
| 1081 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 1082 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 1083 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 1084 | - // get all active payment methods |
|
| 1085 | - $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
| 1086 | - $this->checkout->transaction, |
|
| 1087 | - EEM_Payment_Method::scope_cart |
|
| 1088 | - ); |
|
| 1089 | - foreach ($payment_methods as $payment_method) { |
|
| 1090 | - if ($payment_method instanceof EE_Payment_Method) { |
|
| 1091 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 1092 | - } |
|
| 1093 | - } |
|
| 1094 | - return $available_payment_methods; |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * _available_payment_method_inputs |
|
| 1100 | - * |
|
| 1101 | - * @access private |
|
| 1102 | - * @param array $available_payment_method_options |
|
| 1103 | - * @return \EE_Form_Section_Proper |
|
| 1104 | - */ |
|
| 1105 | - private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
| 1106 | - { |
|
| 1107 | - // generate inputs |
|
| 1108 | - return new EE_Form_Section_Proper( |
|
| 1109 | - array( |
|
| 1110 | - 'html_id' => 'ee-available-payment-method-inputs', |
|
| 1111 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1112 | - 'subsections' => array( |
|
| 1113 | - '' => new EE_Radio_Button_Input( |
|
| 1114 | - $available_payment_method_options, |
|
| 1115 | - array( |
|
| 1116 | - 'html_name' => 'selected_method_of_payment', |
|
| 1117 | - 'html_class' => 'spco-payment-method', |
|
| 1118 | - 'default' => $this->checkout->selected_method_of_payment, |
|
| 1119 | - 'label_size' => 11, |
|
| 1120 | - 'enforce_label_size' => true, |
|
| 1121 | - ) |
|
| 1122 | - ), |
|
| 1123 | - ), |
|
| 1124 | - ) |
|
| 1125 | - ); |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * _payment_method_billing_info |
|
| 1131 | - * |
|
| 1132 | - * @access private |
|
| 1133 | - * @param EE_Payment_Method $payment_method |
|
| 1134 | - * @return EE_Form_Section_Proper |
|
| 1135 | - * @throws EE_Error |
|
| 1136 | - * @throws InvalidArgumentException |
|
| 1137 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1138 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1139 | - */ |
|
| 1140 | - private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
| 1141 | - { |
|
| 1142 | - $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
| 1143 | - ? true |
|
| 1144 | - : false; |
|
| 1145 | - // generate the billing form for payment method |
|
| 1146 | - $billing_form = $currently_selected |
|
| 1147 | - ? $this->_get_billing_form_for_payment_method($payment_method) |
|
| 1148 | - : new EE_Form_Section_HTML(); |
|
| 1149 | - $this->checkout->billing_form = $currently_selected |
|
| 1150 | - ? $billing_form |
|
| 1151 | - : $this->checkout->billing_form; |
|
| 1152 | - // it's all in the details |
|
| 1153 | - $info_html = EEH_HTML::h3( |
|
| 1154 | - esc_html__('Important information regarding your payment', 'event_espresso'), |
|
| 1155 | - '', |
|
| 1156 | - 'spco-payment-method-hdr' |
|
| 1157 | - ); |
|
| 1158 | - // add some info regarding the step, either from what's saved in the admin, |
|
| 1159 | - // or a default string depending on whether the PM has a billing form or not |
|
| 1160 | - if ($payment_method->description()) { |
|
| 1161 | - $payment_method_info = $payment_method->description(); |
|
| 1162 | - } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1163 | - $payment_method_info = sprintf( |
|
| 1164 | - esc_html__( |
|
| 1165 | - 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
| 1166 | - 'event_espresso' |
|
| 1167 | - ), |
|
| 1168 | - $this->submit_button_text() |
|
| 1169 | - ); |
|
| 1170 | - } else { |
|
| 1171 | - $payment_method_info = sprintf( |
|
| 1172 | - esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
| 1173 | - $this->submit_button_text() |
|
| 1174 | - ); |
|
| 1175 | - } |
|
| 1176 | - $info_html .= EEH_HTML::div( |
|
| 1177 | - apply_filters( |
|
| 1178 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
| 1179 | - $payment_method_info |
|
| 1180 | - ), |
|
| 1181 | - '', |
|
| 1182 | - 'spco-payment-method-desc ee-attention' |
|
| 1183 | - ); |
|
| 1184 | - return new EE_Form_Section_Proper( |
|
| 1185 | - array( |
|
| 1186 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
| 1187 | - 'html_class' => 'spco-payment-method-info-dv', |
|
| 1188 | - // only display the selected or default PM |
|
| 1189 | - 'html_style' => $currently_selected ? '' : 'display:none;', |
|
| 1190 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1191 | - 'subsections' => array( |
|
| 1192 | - 'info' => new EE_Form_Section_HTML($info_html), |
|
| 1193 | - 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
| 1194 | - ), |
|
| 1195 | - ) |
|
| 1196 | - ); |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - |
|
| 1200 | - /** |
|
| 1201 | - * get_billing_form_html_for_payment_method |
|
| 1202 | - * |
|
| 1203 | - * @access public |
|
| 1204 | - * @return string |
|
| 1205 | - * @throws EE_Error |
|
| 1206 | - * @throws InvalidArgumentException |
|
| 1207 | - * @throws ReflectionException |
|
| 1208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1210 | - */ |
|
| 1211 | - public function get_billing_form_html_for_payment_method() |
|
| 1212 | - { |
|
| 1213 | - // how have they chosen to pay? |
|
| 1214 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1215 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1216 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1217 | - return false; |
|
| 1218 | - } |
|
| 1219 | - if (apply_filters( |
|
| 1220 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1221 | - false |
|
| 1222 | - )) { |
|
| 1223 | - EE_Error::add_success( |
|
| 1224 | - apply_filters( |
|
| 1225 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1226 | - sprintf( |
|
| 1227 | - esc_html__( |
|
| 1228 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1229 | - 'event_espresso' |
|
| 1230 | - ), |
|
| 1231 | - $this->checkout->payment_method->name() |
|
| 1232 | - ) |
|
| 1233 | - ) |
|
| 1234 | - ); |
|
| 1235 | - } |
|
| 1236 | - // now generate billing form for selected method of payment |
|
| 1237 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
| 1238 | - // fill form with attendee info if applicable |
|
| 1239 | - if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1240 | - && $this->checkout->transaction_has_primary_registrant() |
|
| 1241 | - ) { |
|
| 1242 | - $payment_method_billing_form->populate_from_attendee( |
|
| 1243 | - $this->checkout->transaction->primary_registration()->attendee() |
|
| 1244 | - ); |
|
| 1245 | - } |
|
| 1246 | - // and debug content |
|
| 1247 | - if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
| 1248 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1249 | - ) { |
|
| 1250 | - $payment_method_billing_form = |
|
| 1251 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1252 | - $payment_method_billing_form |
|
| 1253 | - ); |
|
| 1254 | - } |
|
| 1255 | - $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
| 1256 | - ? $payment_method_billing_form->get_html() |
|
| 1257 | - : ''; |
|
| 1258 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
| 1259 | - // localize validation rules for main form |
|
| 1260 | - $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
| 1261 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1262 | - return true; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - |
|
| 1266 | - /** |
|
| 1267 | - * _get_billing_form_for_payment_method |
|
| 1268 | - * |
|
| 1269 | - * @access private |
|
| 1270 | - * @param EE_Payment_Method $payment_method |
|
| 1271 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
| 1272 | - * @throws EE_Error |
|
| 1273 | - * @throws InvalidArgumentException |
|
| 1274 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1275 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1276 | - */ |
|
| 1277 | - private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
| 1278 | - { |
|
| 1279 | - $billing_form = $payment_method->type_obj()->billing_form( |
|
| 1280 | - $this->checkout->transaction, |
|
| 1281 | - array('amount_owing' => $this->checkout->amount_owing) |
|
| 1282 | - ); |
|
| 1283 | - if ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1284 | - if (apply_filters( |
|
| 1285 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1286 | - false |
|
| 1287 | - ) |
|
| 1288 | - && EE_Registry::instance()->REQ->is_set('payment_method') |
|
| 1289 | - ) { |
|
| 1290 | - EE_Error::add_success( |
|
| 1291 | - apply_filters( |
|
| 1292 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1293 | - sprintf( |
|
| 1294 | - esc_html__( |
|
| 1295 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1296 | - 'event_espresso' |
|
| 1297 | - ), |
|
| 1298 | - $payment_method->name() |
|
| 1299 | - ) |
|
| 1300 | - ) |
|
| 1301 | - ); |
|
| 1302 | - } |
|
| 1303 | - return apply_filters( |
|
| 1304 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 1305 | - $billing_form, |
|
| 1306 | - $payment_method |
|
| 1307 | - ); |
|
| 1308 | - } |
|
| 1309 | - // no actual billing form, so return empty HTML form section |
|
| 1310 | - return new EE_Form_Section_HTML(); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - |
|
| 1314 | - /** |
|
| 1315 | - * _get_selected_method_of_payment |
|
| 1316 | - * |
|
| 1317 | - * @access private |
|
| 1318 | - * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
| 1319 | - * is not found in the incoming request |
|
| 1320 | - * @param string $request_param |
|
| 1321 | - * @return NULL|string |
|
| 1322 | - * @throws EE_Error |
|
| 1323 | - * @throws InvalidArgumentException |
|
| 1324 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1325 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1326 | - */ |
|
| 1327 | - private function _get_selected_method_of_payment( |
|
| 1328 | - $required = false, |
|
| 1329 | - $request_param = 'selected_method_of_payment' |
|
| 1330 | - ) { |
|
| 1331 | - // is selected_method_of_payment set in the request ? |
|
| 1332 | - $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
| 1333 | - if ($selected_method_of_payment) { |
|
| 1334 | - // sanitize it |
|
| 1335 | - $selected_method_of_payment = is_array($selected_method_of_payment) |
|
| 1336 | - ? array_shift($selected_method_of_payment) |
|
| 1337 | - : $selected_method_of_payment; |
|
| 1338 | - $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
| 1339 | - // store it in the session so that it's available for all subsequent requests including AJAX |
|
| 1340 | - $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
| 1341 | - } else { |
|
| 1342 | - // or is is set in the session ? |
|
| 1343 | - $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
| 1344 | - 'selected_method_of_payment' |
|
| 1345 | - ); |
|
| 1346 | - } |
|
| 1347 | - // do ya really really gotta have it? |
|
| 1348 | - if (empty($selected_method_of_payment) && $required) { |
|
| 1349 | - EE_Error::add_error( |
|
| 1350 | - sprintf( |
|
| 1351 | - esc_html__( |
|
| 1352 | - 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
| 1353 | - 'event_espresso' |
|
| 1354 | - ), |
|
| 1355 | - '<br/>', |
|
| 1356 | - '<br/>', |
|
| 1357 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 1358 | - ), |
|
| 1359 | - __FILE__, |
|
| 1360 | - __FUNCTION__, |
|
| 1361 | - __LINE__ |
|
| 1362 | - ); |
|
| 1363 | - return null; |
|
| 1364 | - } |
|
| 1365 | - return $selected_method_of_payment; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - |
|
| 1370 | - |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - /********************************************************************************************************/ |
|
| 1374 | - /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
| 1375 | - /********************************************************************************************************/ |
|
| 1376 | - /** |
|
| 1377 | - * switch_payment_method |
|
| 1378 | - * |
|
| 1379 | - * @access public |
|
| 1380 | - * @return string |
|
| 1381 | - * @throws EE_Error |
|
| 1382 | - * @throws InvalidArgumentException |
|
| 1383 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1384 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1385 | - */ |
|
| 1386 | - public function switch_payment_method() |
|
| 1387 | - { |
|
| 1388 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1389 | - return false; |
|
| 1390 | - } |
|
| 1391 | - if (apply_filters( |
|
| 1392 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1393 | - false |
|
| 1394 | - )) { |
|
| 1395 | - EE_Error::add_success( |
|
| 1396 | - apply_filters( |
|
| 1397 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1398 | - sprintf( |
|
| 1399 | - esc_html__( |
|
| 1400 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1401 | - 'event_espresso' |
|
| 1402 | - ), |
|
| 1403 | - $this->checkout->payment_method->name() |
|
| 1404 | - ) |
|
| 1405 | - ) |
|
| 1406 | - ); |
|
| 1407 | - } |
|
| 1408 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1409 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1410 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1411 | - $this->checkout->payment_method |
|
| 1412 | - ); |
|
| 1413 | - } |
|
| 1414 | - // fill form with attendee info if applicable |
|
| 1415 | - if (apply_filters( |
|
| 1416 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 1417 | - ( |
|
| 1418 | - $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1419 | - && $this->checkout->transaction_has_primary_registrant() |
|
| 1420 | - ), |
|
| 1421 | - $this->checkout->billing_form, |
|
| 1422 | - $this->checkout->transaction |
|
| 1423 | - ) |
|
| 1424 | - ) { |
|
| 1425 | - $this->checkout->billing_form->populate_from_attendee( |
|
| 1426 | - $this->checkout->transaction->primary_registration()->attendee() |
|
| 1427 | - ); |
|
| 1428 | - } |
|
| 1429 | - // and debug content |
|
| 1430 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
| 1431 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1432 | - ) { |
|
| 1433 | - $this->checkout->billing_form = |
|
| 1434 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1435 | - $this->checkout->billing_form |
|
| 1436 | - ); |
|
| 1437 | - } |
|
| 1438 | - // get html and validation rules for form |
|
| 1439 | - if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
| 1440 | - $this->checkout->json_response->set_return_data( |
|
| 1441 | - array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
| 1442 | - ); |
|
| 1443 | - // localize validation rules for main form |
|
| 1444 | - $this->checkout->billing_form->localize_validation_rules(true); |
|
| 1445 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1446 | - } else { |
|
| 1447 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
| 1448 | - } |
|
| 1449 | - // prevents advancement to next step |
|
| 1450 | - $this->checkout->continue_reg = false; |
|
| 1451 | - return true; |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - |
|
| 1455 | - /** |
|
| 1456 | - * _verify_payment_method_is_set |
|
| 1457 | - * |
|
| 1458 | - * @return bool |
|
| 1459 | - * @throws EE_Error |
|
| 1460 | - * @throws InvalidArgumentException |
|
| 1461 | - * @throws ReflectionException |
|
| 1462 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1463 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1464 | - */ |
|
| 1465 | - protected function _verify_payment_method_is_set() |
|
| 1466 | - { |
|
| 1467 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1468 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1469 | - // how have they chosen to pay? |
|
| 1470 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1471 | - } else { |
|
| 1472 | - // choose your own adventure based on method_of_payment |
|
| 1473 | - switch ($this->checkout->selected_method_of_payment) { |
|
| 1474 | - case 'events_sold_out': |
|
| 1475 | - EE_Error::add_attention( |
|
| 1476 | - apply_filters( |
|
| 1477 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
| 1478 | - esc_html__( |
|
| 1479 | - 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
| 1480 | - 'event_espresso' |
|
| 1481 | - ) |
|
| 1482 | - ), |
|
| 1483 | - __FILE__, |
|
| 1484 | - __FUNCTION__, |
|
| 1485 | - __LINE__ |
|
| 1486 | - ); |
|
| 1487 | - return false; |
|
| 1488 | - break; |
|
| 1489 | - case 'payments_closed': |
|
| 1490 | - EE_Error::add_attention( |
|
| 1491 | - apply_filters( |
|
| 1492 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
| 1493 | - esc_html__( |
|
| 1494 | - 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
| 1495 | - 'event_espresso' |
|
| 1496 | - ) |
|
| 1497 | - ), |
|
| 1498 | - __FILE__, |
|
| 1499 | - __FUNCTION__, |
|
| 1500 | - __LINE__ |
|
| 1501 | - ); |
|
| 1502 | - return false; |
|
| 1503 | - break; |
|
| 1504 | - case 'no_payment_required': |
|
| 1505 | - EE_Error::add_attention( |
|
| 1506 | - apply_filters( |
|
| 1507 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
| 1508 | - esc_html__( |
|
| 1509 | - 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
| 1510 | - 'event_espresso' |
|
| 1511 | - ) |
|
| 1512 | - ), |
|
| 1513 | - __FILE__, |
|
| 1514 | - __FUNCTION__, |
|
| 1515 | - __LINE__ |
|
| 1516 | - ); |
|
| 1517 | - return false; |
|
| 1518 | - break; |
|
| 1519 | - default: |
|
| 1520 | - } |
|
| 1521 | - } |
|
| 1522 | - // verify payment method |
|
| 1523 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1524 | - // get payment method for selected method of payment |
|
| 1525 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1526 | - } |
|
| 1527 | - return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - |
|
| 1531 | - |
|
| 1532 | - /********************************************************************************************************/ |
|
| 1533 | - /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
| 1534 | - /********************************************************************************************************/ |
|
| 1535 | - /** |
|
| 1536 | - * save_payer_details_via_ajax |
|
| 1537 | - * |
|
| 1538 | - * @return void |
|
| 1539 | - * @throws EE_Error |
|
| 1540 | - * @throws InvalidArgumentException |
|
| 1541 | - * @throws ReflectionException |
|
| 1542 | - * @throws RuntimeException |
|
| 1543 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1544 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1545 | - */ |
|
| 1546 | - public function save_payer_details_via_ajax() |
|
| 1547 | - { |
|
| 1548 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1549 | - return; |
|
| 1550 | - } |
|
| 1551 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1552 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1553 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1554 | - $this->checkout->payment_method |
|
| 1555 | - ); |
|
| 1556 | - } |
|
| 1557 | - // generate primary attendee from payer info if applicable |
|
| 1558 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1559 | - $attendee = $this->_create_attendee_from_request_data(); |
|
| 1560 | - if ($attendee instanceof EE_Attendee) { |
|
| 1561 | - foreach ($this->checkout->transaction->registrations() as $registration) { |
|
| 1562 | - if ($registration->is_primary_registrant()) { |
|
| 1563 | - $this->checkout->primary_attendee_obj = $attendee; |
|
| 1564 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1565 | - $registration->set_attendee_id($attendee->ID()); |
|
| 1566 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1567 | - } |
|
| 1568 | - } |
|
| 1569 | - } |
|
| 1570 | - } |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - |
|
| 1574 | - /** |
|
| 1575 | - * create_attendee_from_request_data |
|
| 1576 | - * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
| 1577 | - * |
|
| 1578 | - * @return EE_Attendee |
|
| 1579 | - * @throws EE_Error |
|
| 1580 | - * @throws InvalidArgumentException |
|
| 1581 | - * @throws ReflectionException |
|
| 1582 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1583 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1584 | - */ |
|
| 1585 | - protected function _create_attendee_from_request_data() |
|
| 1586 | - { |
|
| 1587 | - // get State ID |
|
| 1588 | - $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
| 1589 | - if (! empty($STA_ID)) { |
|
| 1590 | - // can we get state object from name ? |
|
| 1591 | - EE_Registry::instance()->load_model('State'); |
|
| 1592 | - $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
| 1593 | - $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
| 1594 | - } |
|
| 1595 | - // get Country ISO |
|
| 1596 | - $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
| 1597 | - if (! empty($CNT_ISO)) { |
|
| 1598 | - // can we get country object from name ? |
|
| 1599 | - EE_Registry::instance()->load_model('Country'); |
|
| 1600 | - $country = EEM_Country::instance()->get_col( |
|
| 1601 | - array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
| 1602 | - 'CNT_ISO' |
|
| 1603 | - ); |
|
| 1604 | - $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
| 1605 | - } |
|
| 1606 | - // grab attendee data |
|
| 1607 | - $attendee_data = array( |
|
| 1608 | - 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
| 1609 | - 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
| 1610 | - 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
| 1611 | - 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
| 1612 | - 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
| 1613 | - 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
| 1614 | - 'STA_ID' => $STA_ID, |
|
| 1615 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1616 | - 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
| 1617 | - 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
| 1618 | - ); |
|
| 1619 | - // validate the email address since it is the most important piece of info |
|
| 1620 | - if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
| 1621 | - EE_Error::add_error( |
|
| 1622 | - esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
| 1623 | - __FILE__, |
|
| 1624 | - __FUNCTION__, |
|
| 1625 | - __LINE__ |
|
| 1626 | - ); |
|
| 1627 | - } |
|
| 1628 | - // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
| 1629 | - // AND email address |
|
| 1630 | - if (! empty($attendee_data['ATT_fname']) |
|
| 1631 | - && ! empty($attendee_data['ATT_lname']) |
|
| 1632 | - && ! empty($attendee_data['ATT_email']) |
|
| 1633 | - ) { |
|
| 1634 | - $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
| 1635 | - array( |
|
| 1636 | - 'ATT_fname' => $attendee_data['ATT_fname'], |
|
| 1637 | - 'ATT_lname' => $attendee_data['ATT_lname'], |
|
| 1638 | - 'ATT_email' => $attendee_data['ATT_email'], |
|
| 1639 | - ) |
|
| 1640 | - ); |
|
| 1641 | - if ($existing_attendee instanceof EE_Attendee) { |
|
| 1642 | - return $existing_attendee; |
|
| 1643 | - } |
|
| 1644 | - } |
|
| 1645 | - // no existing attendee? kk let's create a new one |
|
| 1646 | - // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
| 1647 | - // don't exist |
|
| 1648 | - $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
| 1649 | - ? $attendee_data['ATT_fname'] |
|
| 1650 | - : $attendee_data['ATT_email']; |
|
| 1651 | - $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
| 1652 | - ? $attendee_data['ATT_lname'] |
|
| 1653 | - : $attendee_data['ATT_email']; |
|
| 1654 | - return EE_Attendee::new_instance($attendee_data); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - |
|
| 1658 | - |
|
| 1659 | - /********************************************************************************************************/ |
|
| 1660 | - /**************************************** PROCESS REG STEP *****************************************/ |
|
| 1661 | - /********************************************************************************************************/ |
|
| 1662 | - /** |
|
| 1663 | - * process_reg_step |
|
| 1664 | - * |
|
| 1665 | - * @return bool |
|
| 1666 | - * @throws EE_Error |
|
| 1667 | - * @throws InvalidArgumentException |
|
| 1668 | - * @throws ReflectionException |
|
| 1669 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1670 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1671 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1672 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1673 | - */ |
|
| 1674 | - public function process_reg_step() |
|
| 1675 | - { |
|
| 1676 | - // how have they chosen to pay? |
|
| 1677 | - $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
| 1678 | - ? 'no_payment_required' |
|
| 1679 | - : $this->_get_selected_method_of_payment(true); |
|
| 1680 | - // choose your own adventure based on method_of_payment |
|
| 1681 | - switch ($this->checkout->selected_method_of_payment) { |
|
| 1682 | - case 'events_sold_out': |
|
| 1683 | - $this->checkout->redirect = true; |
|
| 1684 | - $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
| 1685 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1686 | - // mark this reg step as completed |
|
| 1687 | - $this->set_completed(); |
|
| 1688 | - return false; |
|
| 1689 | - break; |
|
| 1690 | - |
|
| 1691 | - case 'payments_closed': |
|
| 1692 | - if (apply_filters( |
|
| 1693 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
| 1694 | - false |
|
| 1695 | - )) { |
|
| 1696 | - EE_Error::add_success( |
|
| 1697 | - esc_html__('no payment required at this time.', 'event_espresso'), |
|
| 1698 | - __FILE__, |
|
| 1699 | - __FUNCTION__, |
|
| 1700 | - __LINE__ |
|
| 1701 | - ); |
|
| 1702 | - } |
|
| 1703 | - // mark this reg step as completed |
|
| 1704 | - $this->set_completed(); |
|
| 1705 | - return true; |
|
| 1706 | - break; |
|
| 1707 | - |
|
| 1708 | - case 'no_payment_required': |
|
| 1709 | - if (apply_filters( |
|
| 1710 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
| 1711 | - false |
|
| 1712 | - )) { |
|
| 1713 | - EE_Error::add_success( |
|
| 1714 | - esc_html__('no payment required.', 'event_espresso'), |
|
| 1715 | - __FILE__, |
|
| 1716 | - __FUNCTION__, |
|
| 1717 | - __LINE__ |
|
| 1718 | - ); |
|
| 1719 | - } |
|
| 1720 | - // mark this reg step as completed |
|
| 1721 | - $this->set_completed(); |
|
| 1722 | - return true; |
|
| 1723 | - break; |
|
| 1724 | - |
|
| 1725 | - default: |
|
| 1726 | - $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 1727 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 1728 | - ); |
|
| 1729 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 1730 | - $registrations, |
|
| 1731 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
| 1732 | - ); |
|
| 1733 | - // calculate difference between the two arrays |
|
| 1734 | - $registrations = array_diff($registrations, $ejected_registrations); |
|
| 1735 | - if (empty($registrations)) { |
|
| 1736 | - $this->_redirect_because_event_sold_out(); |
|
| 1737 | - return false; |
|
| 1738 | - } |
|
| 1739 | - $payment_successful = $this->_process_payment(); |
|
| 1740 | - if ($payment_successful) { |
|
| 1741 | - $this->checkout->continue_reg = true; |
|
| 1742 | - $this->_maybe_set_completed($this->checkout->payment_method); |
|
| 1743 | - } else { |
|
| 1744 | - $this->checkout->continue_reg = false; |
|
| 1745 | - } |
|
| 1746 | - return $payment_successful; |
|
| 1747 | - } |
|
| 1748 | - } |
|
| 1749 | - |
|
| 1750 | - |
|
| 1751 | - /** |
|
| 1752 | - * _redirect_because_event_sold_out |
|
| 1753 | - * |
|
| 1754 | - * @access protected |
|
| 1755 | - * @return void |
|
| 1756 | - */ |
|
| 1757 | - protected function _redirect_because_event_sold_out() |
|
| 1758 | - { |
|
| 1759 | - $this->checkout->continue_reg = false; |
|
| 1760 | - // set redirect URL |
|
| 1761 | - $this->checkout->redirect_url = add_query_arg( |
|
| 1762 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1763 | - $this->checkout->current_step->reg_step_url() |
|
| 1764 | - ); |
|
| 1765 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1766 | - } |
|
| 1767 | - |
|
| 1768 | - |
|
| 1769 | - /** |
|
| 1770 | - * _maybe_set_completed |
|
| 1771 | - * |
|
| 1772 | - * @access protected |
|
| 1773 | - * @param \EE_Payment_Method $payment_method |
|
| 1774 | - * @return void |
|
| 1775 | - * @throws \EE_Error |
|
| 1776 | - */ |
|
| 1777 | - protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
| 1778 | - { |
|
| 1779 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 1780 | - case EE_PMT_Base::offsite: |
|
| 1781 | - break; |
|
| 1782 | - case EE_PMT_Base::onsite: |
|
| 1783 | - case EE_PMT_Base::offline: |
|
| 1784 | - // mark this reg step as completed |
|
| 1785 | - $this->set_completed(); |
|
| 1786 | - break; |
|
| 1787 | - } |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - |
|
| 1791 | - /** |
|
| 1792 | - * update_reg_step |
|
| 1793 | - * this is the final step after a user revisits the site to retry a payment |
|
| 1794 | - * |
|
| 1795 | - * @return bool |
|
| 1796 | - * @throws EE_Error |
|
| 1797 | - * @throws InvalidArgumentException |
|
| 1798 | - * @throws ReflectionException |
|
| 1799 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1800 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1801 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1802 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1803 | - */ |
|
| 1804 | - public function update_reg_step() |
|
| 1805 | - { |
|
| 1806 | - $success = true; |
|
| 1807 | - // if payment required |
|
| 1808 | - if ($this->checkout->transaction->total() > 0) { |
|
| 1809 | - do_action( |
|
| 1810 | - 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
| 1811 | - $this->checkout->transaction |
|
| 1812 | - ); |
|
| 1813 | - // attempt payment via payment method |
|
| 1814 | - $success = $this->process_reg_step(); |
|
| 1815 | - } |
|
| 1816 | - if ($success && ! $this->checkout->redirect) { |
|
| 1817 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
| 1818 | - $this->checkout->transaction->ID() |
|
| 1819 | - ); |
|
| 1820 | - // set return URL |
|
| 1821 | - $this->checkout->redirect_url = add_query_arg( |
|
| 1822 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1823 | - $this->checkout->thank_you_page_url |
|
| 1824 | - ); |
|
| 1825 | - } |
|
| 1826 | - return $success; |
|
| 1827 | - } |
|
| 1828 | - |
|
| 1829 | - |
|
| 1830 | - /** |
|
| 1831 | - * _process_payment |
|
| 1832 | - * |
|
| 1833 | - * @access private |
|
| 1834 | - * @return bool |
|
| 1835 | - * @throws EE_Error |
|
| 1836 | - * @throws InvalidArgumentException |
|
| 1837 | - * @throws ReflectionException |
|
| 1838 | - * @throws RuntimeException |
|
| 1839 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1840 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1841 | - */ |
|
| 1842 | - private function _process_payment() |
|
| 1843 | - { |
|
| 1844 | - // basically confirm that the event hasn't sold out since they hit the page |
|
| 1845 | - if (! $this->_last_second_ticket_verifications()) { |
|
| 1846 | - return false; |
|
| 1847 | - } |
|
| 1848 | - // ya gotta make a choice man |
|
| 1849 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1850 | - $this->checkout->json_response->set_plz_select_method_of_payment( |
|
| 1851 | - esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
| 1852 | - ); |
|
| 1853 | - return false; |
|
| 1854 | - } |
|
| 1855 | - // get EE_Payment_Method object |
|
| 1856 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1857 | - return false; |
|
| 1858 | - } |
|
| 1859 | - // setup billing form |
|
| 1860 | - if ($this->checkout->payment_method->is_on_site()) { |
|
| 1861 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1862 | - $this->checkout->payment_method |
|
| 1863 | - ); |
|
| 1864 | - // bad billing form ? |
|
| 1865 | - if (! $this->_billing_form_is_valid()) { |
|
| 1866 | - return false; |
|
| 1867 | - } |
|
| 1868 | - } |
|
| 1869 | - // ensure primary registrant has been fully processed |
|
| 1870 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1871 | - return false; |
|
| 1872 | - } |
|
| 1873 | - // if session is close to expiring (under 10 minutes by default) |
|
| 1874 | - if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
| 1875 | - // add some time to session expiration so that payment can be completed |
|
| 1876 | - EE_Registry::instance()->SSN->extend_expiration(); |
|
| 1877 | - } |
|
| 1878 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1879 | - // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 1880 | - // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
| 1881 | - // for events with a default reg status of Approved |
|
| 1882 | - // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
| 1883 | - // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
| 1884 | - // ); |
|
| 1885 | - // attempt payment |
|
| 1886 | - $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
| 1887 | - // process results |
|
| 1888 | - $payment = $this->_validate_payment($payment); |
|
| 1889 | - $payment = $this->_post_payment_processing($payment); |
|
| 1890 | - // verify payment |
|
| 1891 | - if ($payment instanceof EE_Payment) { |
|
| 1892 | - // store that for later |
|
| 1893 | - $this->checkout->payment = $payment; |
|
| 1894 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
| 1895 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1896 | - $payment_status = $payment->status(); |
|
| 1897 | - if ($payment_status === EEM_Payment::status_id_approved |
|
| 1898 | - || $payment_status === EEM_Payment::status_id_pending |
|
| 1899 | - ) { |
|
| 1900 | - return true; |
|
| 1901 | - } else { |
|
| 1902 | - return false; |
|
| 1903 | - } |
|
| 1904 | - } elseif ($payment === true) { |
|
| 1905 | - // please note that offline payment methods will NOT make a payment, |
|
| 1906 | - // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
| 1907 | - $this->checkout->payment = $payment; |
|
| 1908 | - return true; |
|
| 1909 | - } |
|
| 1910 | - // where's my money? |
|
| 1911 | - return false; |
|
| 1912 | - } |
|
| 1913 | - |
|
| 1914 | - |
|
| 1915 | - /** |
|
| 1916 | - * _last_second_ticket_verifications |
|
| 1917 | - * |
|
| 1918 | - * @access public |
|
| 1919 | - * @return bool |
|
| 1920 | - * @throws EE_Error |
|
| 1921 | - */ |
|
| 1922 | - protected function _last_second_ticket_verifications() |
|
| 1923 | - { |
|
| 1924 | - // don't bother re-validating if not a return visit |
|
| 1925 | - if (! $this->checkout->revisit) { |
|
| 1926 | - return true; |
|
| 1927 | - } |
|
| 1928 | - $registrations = $this->checkout->transaction->registrations(); |
|
| 1929 | - if (empty($registrations)) { |
|
| 1930 | - return false; |
|
| 1931 | - } |
|
| 1932 | - foreach ($registrations as $registration) { |
|
| 1933 | - if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
| 1934 | - $event = $registration->event_obj(); |
|
| 1935 | - if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
| 1936 | - EE_Error::add_error( |
|
| 1937 | - apply_filters( |
|
| 1938 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
| 1939 | - sprintf( |
|
| 1940 | - esc_html__( |
|
| 1941 | - 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 1942 | - 'event_espresso' |
|
| 1943 | - ), |
|
| 1944 | - $event->name() |
|
| 1945 | - ) |
|
| 1946 | - ), |
|
| 1947 | - __FILE__, |
|
| 1948 | - __FUNCTION__, |
|
| 1949 | - __LINE__ |
|
| 1950 | - ); |
|
| 1951 | - return false; |
|
| 1952 | - } |
|
| 1953 | - } |
|
| 1954 | - } |
|
| 1955 | - return true; |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - |
|
| 1959 | - /** |
|
| 1960 | - * redirect_form |
|
| 1961 | - * |
|
| 1962 | - * @access public |
|
| 1963 | - * @return bool |
|
| 1964 | - * @throws EE_Error |
|
| 1965 | - * @throws InvalidArgumentException |
|
| 1966 | - * @throws ReflectionException |
|
| 1967 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1968 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1969 | - */ |
|
| 1970 | - public function redirect_form() |
|
| 1971 | - { |
|
| 1972 | - $payment_method_billing_info = $this->_payment_method_billing_info( |
|
| 1973 | - $this->_get_payment_method_for_selected_method_of_payment() |
|
| 1974 | - ); |
|
| 1975 | - $html = $payment_method_billing_info->get_html(); |
|
| 1976 | - $html .= $this->checkout->redirect_form; |
|
| 1977 | - EE_Registry::instance()->REQ->add_output($html); |
|
| 1978 | - return true; |
|
| 1979 | - } |
|
| 1980 | - |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * _billing_form_is_valid |
|
| 1984 | - * |
|
| 1985 | - * @access private |
|
| 1986 | - * @return bool |
|
| 1987 | - * @throws \EE_Error |
|
| 1988 | - */ |
|
| 1989 | - private function _billing_form_is_valid() |
|
| 1990 | - { |
|
| 1991 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1992 | - return true; |
|
| 1993 | - } |
|
| 1994 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
| 1995 | - if ($this->checkout->billing_form->was_submitted()) { |
|
| 1996 | - $this->checkout->billing_form->receive_form_submission(); |
|
| 1997 | - if ($this->checkout->billing_form->is_valid()) { |
|
| 1998 | - return true; |
|
| 1999 | - } |
|
| 2000 | - $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
| 2001 | - $error_strings = array(); |
|
| 2002 | - foreach ($validation_errors as $validation_error) { |
|
| 2003 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 2004 | - $form_section = $validation_error->get_form_section(); |
|
| 2005 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
| 2006 | - $label = $form_section->html_label_text(); |
|
| 2007 | - } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
| 2008 | - $label = $form_section->name(); |
|
| 2009 | - } else { |
|
| 2010 | - $label = esc_html__('Validation Error', 'event_espresso'); |
|
| 2011 | - } |
|
| 2012 | - $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
| 2013 | - } |
|
| 2014 | - } |
|
| 2015 | - EE_Error::add_error( |
|
| 2016 | - sprintf( |
|
| 2017 | - esc_html__( |
|
| 2018 | - 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
| 2019 | - 'event_espresso' |
|
| 2020 | - ), |
|
| 2021 | - '<br/>', |
|
| 2022 | - implode('<br/>', $error_strings) |
|
| 2023 | - ), |
|
| 2024 | - __FILE__, |
|
| 2025 | - __FUNCTION__, |
|
| 2026 | - __LINE__ |
|
| 2027 | - ); |
|
| 2028 | - } else { |
|
| 2029 | - EE_Error::add_error( |
|
| 2030 | - esc_html__( |
|
| 2031 | - 'The billing form was not submitted or something prevented it\'s submission.', |
|
| 2032 | - 'event_espresso' |
|
| 2033 | - ), |
|
| 2034 | - __FILE__, |
|
| 2035 | - __FUNCTION__, |
|
| 2036 | - __LINE__ |
|
| 2037 | - ); |
|
| 2038 | - } |
|
| 2039 | - } else { |
|
| 2040 | - EE_Error::add_error( |
|
| 2041 | - esc_html__( |
|
| 2042 | - 'The submitted billing form is invalid possibly due to a technical reason.', |
|
| 2043 | - 'event_espresso' |
|
| 2044 | - ), |
|
| 2045 | - __FILE__, |
|
| 2046 | - __FUNCTION__, |
|
| 2047 | - __LINE__ |
|
| 2048 | - ); |
|
| 2049 | - } |
|
| 2050 | - return false; |
|
| 2051 | - } |
|
| 2052 | - |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * _setup_primary_registrant_prior_to_payment |
|
| 2056 | - * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
| 2057 | - * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
| 2058 | - * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
| 2059 | - * yet) |
|
| 2060 | - * |
|
| 2061 | - * @access private |
|
| 2062 | - * @return bool |
|
| 2063 | - * @throws EE_Error |
|
| 2064 | - * @throws InvalidArgumentException |
|
| 2065 | - * @throws ReflectionException |
|
| 2066 | - * @throws RuntimeException |
|
| 2067 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2068 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2069 | - */ |
|
| 2070 | - private function _setup_primary_registrant_prior_to_payment() |
|
| 2071 | - { |
|
| 2072 | - // check if transaction has a primary registrant and that it has a related Attendee object |
|
| 2073 | - // if not, then we need to at least gather some primary registrant data before attempting payment |
|
| 2074 | - if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 2075 | - && ! $this->checkout->transaction_has_primary_registrant() |
|
| 2076 | - && ! $this->_capture_primary_registration_data_from_billing_form() |
|
| 2077 | - ) { |
|
| 2078 | - return false; |
|
| 2079 | - } |
|
| 2080 | - // because saving an object clears it's cache, we need to do the chevy shuffle |
|
| 2081 | - // grab the primary_registration object |
|
| 2082 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2083 | - // at this point we'll consider a TXN to not have been failed |
|
| 2084 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 2085 | - // save the TXN ( which clears cached copy of primary_registration) |
|
| 2086 | - $this->checkout->transaction->save(); |
|
| 2087 | - // grab TXN ID and save it to the primary_registration |
|
| 2088 | - $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
| 2089 | - // save what we have so far |
|
| 2090 | - $primary_registration->save(); |
|
| 2091 | - return true; |
|
| 2092 | - } |
|
| 2093 | - |
|
| 2094 | - |
|
| 2095 | - /** |
|
| 2096 | - * _capture_primary_registration_data_from_billing_form |
|
| 2097 | - * |
|
| 2098 | - * @access private |
|
| 2099 | - * @return bool |
|
| 2100 | - * @throws EE_Error |
|
| 2101 | - * @throws InvalidArgumentException |
|
| 2102 | - * @throws ReflectionException |
|
| 2103 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2104 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2105 | - */ |
|
| 2106 | - private function _capture_primary_registration_data_from_billing_form() |
|
| 2107 | - { |
|
| 2108 | - // convert billing form data into an attendee |
|
| 2109 | - $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
| 2110 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2111 | - EE_Error::add_error( |
|
| 2112 | - sprintf( |
|
| 2113 | - esc_html__( |
|
| 2114 | - 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2115 | - 'event_espresso' |
|
| 2116 | - ), |
|
| 2117 | - '<br/>', |
|
| 2118 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2119 | - ), |
|
| 2120 | - __FILE__, |
|
| 2121 | - __FUNCTION__, |
|
| 2122 | - __LINE__ |
|
| 2123 | - ); |
|
| 2124 | - return false; |
|
| 2125 | - } |
|
| 2126 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2127 | - if (! $primary_registration instanceof EE_Registration) { |
|
| 2128 | - EE_Error::add_error( |
|
| 2129 | - sprintf( |
|
| 2130 | - esc_html__( |
|
| 2131 | - 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2132 | - 'event_espresso' |
|
| 2133 | - ), |
|
| 2134 | - '<br/>', |
|
| 2135 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2136 | - ), |
|
| 2137 | - __FILE__, |
|
| 2138 | - __FUNCTION__, |
|
| 2139 | - __LINE__ |
|
| 2140 | - ); |
|
| 2141 | - return false; |
|
| 2142 | - } |
|
| 2143 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2144 | - instanceof |
|
| 2145 | - EE_Attendee |
|
| 2146 | - ) { |
|
| 2147 | - EE_Error::add_error( |
|
| 2148 | - sprintf( |
|
| 2149 | - esc_html__( |
|
| 2150 | - 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2151 | - 'event_espresso' |
|
| 2152 | - ), |
|
| 2153 | - '<br/>', |
|
| 2154 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2155 | - ), |
|
| 2156 | - __FILE__, |
|
| 2157 | - __FUNCTION__, |
|
| 2158 | - __LINE__ |
|
| 2159 | - ); |
|
| 2160 | - return false; |
|
| 2161 | - } |
|
| 2162 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 2163 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 2164 | - // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
| 2165 | - $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
| 2166 | - return true; |
|
| 2167 | - } |
|
| 2168 | - |
|
| 2169 | - |
|
| 2170 | - /** |
|
| 2171 | - * _get_payment_method_for_selected_method_of_payment |
|
| 2172 | - * retrieves a valid payment method |
|
| 2173 | - * |
|
| 2174 | - * @access public |
|
| 2175 | - * @return EE_Payment_Method |
|
| 2176 | - * @throws EE_Error |
|
| 2177 | - * @throws InvalidArgumentException |
|
| 2178 | - * @throws ReflectionException |
|
| 2179 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2180 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2181 | - */ |
|
| 2182 | - private function _get_payment_method_for_selected_method_of_payment() |
|
| 2183 | - { |
|
| 2184 | - if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
| 2185 | - $this->_redirect_because_event_sold_out(); |
|
| 2186 | - return null; |
|
| 2187 | - } |
|
| 2188 | - // get EE_Payment_Method object |
|
| 2189 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
| 2190 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
| 2191 | - } else { |
|
| 2192 | - // load EEM_Payment_Method |
|
| 2193 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 2194 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 2195 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 2196 | - $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
| 2197 | - } |
|
| 2198 | - // verify $payment_method |
|
| 2199 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
| 2200 | - // not a payment |
|
| 2201 | - EE_Error::add_error( |
|
| 2202 | - sprintf( |
|
| 2203 | - esc_html__( |
|
| 2204 | - 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2205 | - 'event_espresso' |
|
| 2206 | - ), |
|
| 2207 | - '<br/>', |
|
| 2208 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2209 | - ), |
|
| 2210 | - __FILE__, |
|
| 2211 | - __FUNCTION__, |
|
| 2212 | - __LINE__ |
|
| 2213 | - ); |
|
| 2214 | - return null; |
|
| 2215 | - } |
|
| 2216 | - // and verify it has a valid Payment_Method Type object |
|
| 2217 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2218 | - // not a payment |
|
| 2219 | - EE_Error::add_error( |
|
| 2220 | - sprintf( |
|
| 2221 | - esc_html__( |
|
| 2222 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2223 | - 'event_espresso' |
|
| 2224 | - ), |
|
| 2225 | - '<br/>', |
|
| 2226 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2227 | - ), |
|
| 2228 | - __FILE__, |
|
| 2229 | - __FUNCTION__, |
|
| 2230 | - __LINE__ |
|
| 2231 | - ); |
|
| 2232 | - return null; |
|
| 2233 | - } |
|
| 2234 | - return $payment_method; |
|
| 2235 | - } |
|
| 2236 | - |
|
| 2237 | - |
|
| 2238 | - /** |
|
| 2239 | - * _attempt_payment |
|
| 2240 | - * |
|
| 2241 | - * @access private |
|
| 2242 | - * @type EE_Payment_Method $payment_method |
|
| 2243 | - * @return mixed EE_Payment | boolean |
|
| 2244 | - * @throws EE_Error |
|
| 2245 | - * @throws InvalidArgumentException |
|
| 2246 | - * @throws ReflectionException |
|
| 2247 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2248 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2249 | - */ |
|
| 2250 | - private function _attempt_payment(EE_Payment_Method $payment_method) |
|
| 2251 | - { |
|
| 2252 | - $payment = null; |
|
| 2253 | - $this->checkout->transaction->save(); |
|
| 2254 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2255 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2256 | - return false; |
|
| 2257 | - } |
|
| 2258 | - try { |
|
| 2259 | - $payment_processor->set_revisit($this->checkout->revisit); |
|
| 2260 | - // generate payment object |
|
| 2261 | - $payment = $payment_processor->process_payment( |
|
| 2262 | - $payment_method, |
|
| 2263 | - $this->checkout->transaction, |
|
| 2264 | - $this->checkout->amount_owing, |
|
| 2265 | - $this->checkout->billing_form, |
|
| 2266 | - $this->_get_return_url($payment_method), |
|
| 2267 | - 'CART', |
|
| 2268 | - $this->checkout->admin_request, |
|
| 2269 | - true, |
|
| 2270 | - $this->reg_step_url() |
|
| 2271 | - ); |
|
| 2272 | - } catch (Exception $e) { |
|
| 2273 | - $this->_handle_payment_processor_exception($e); |
|
| 2274 | - } |
|
| 2275 | - return $payment; |
|
| 2276 | - } |
|
| 2277 | - |
|
| 2278 | - |
|
| 2279 | - /** |
|
| 2280 | - * _handle_payment_processor_exception |
|
| 2281 | - * |
|
| 2282 | - * @access protected |
|
| 2283 | - * @param \Exception $e |
|
| 2284 | - * @return void |
|
| 2285 | - * @throws EE_Error |
|
| 2286 | - * @throws InvalidArgumentException |
|
| 2287 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2288 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2289 | - */ |
|
| 2290 | - protected function _handle_payment_processor_exception(Exception $e) |
|
| 2291 | - { |
|
| 2292 | - EE_Error::add_error( |
|
| 2293 | - sprintf( |
|
| 2294 | - esc_html__( |
|
| 2295 | - 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
| 2296 | - 'event_espresso' |
|
| 2297 | - ), |
|
| 2298 | - '<br/>', |
|
| 2299 | - EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
| 2300 | - $e->getMessage(), |
|
| 2301 | - $e->getFile(), |
|
| 2302 | - $e->getLine() |
|
| 2303 | - ), |
|
| 2304 | - __FILE__, |
|
| 2305 | - __FUNCTION__, |
|
| 2306 | - __LINE__ |
|
| 2307 | - ); |
|
| 2308 | - } |
|
| 2309 | - |
|
| 2310 | - |
|
| 2311 | - /** |
|
| 2312 | - * _get_return_url |
|
| 2313 | - * |
|
| 2314 | - * @access protected |
|
| 2315 | - * @param \EE_Payment_Method $payment_method |
|
| 2316 | - * @return string |
|
| 2317 | - * @throws \EE_Error |
|
| 2318 | - */ |
|
| 2319 | - protected function _get_return_url(EE_Payment_Method $payment_method) |
|
| 2320 | - { |
|
| 2321 | - $return_url = ''; |
|
| 2322 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 2323 | - case EE_PMT_Base::offsite: |
|
| 2324 | - $return_url = add_query_arg( |
|
| 2325 | - array( |
|
| 2326 | - 'action' => 'process_gateway_response', |
|
| 2327 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2328 | - 'spco_txn' => $this->checkout->transaction->ID(), |
|
| 2329 | - ), |
|
| 2330 | - $this->reg_step_url() |
|
| 2331 | - ); |
|
| 2332 | - break; |
|
| 2333 | - case EE_PMT_Base::onsite: |
|
| 2334 | - case EE_PMT_Base::offline: |
|
| 2335 | - $return_url = $this->checkout->next_step->reg_step_url(); |
|
| 2336 | - break; |
|
| 2337 | - } |
|
| 2338 | - return $return_url; |
|
| 2339 | - } |
|
| 2340 | - |
|
| 2341 | - |
|
| 2342 | - /** |
|
| 2343 | - * _validate_payment |
|
| 2344 | - * |
|
| 2345 | - * @access private |
|
| 2346 | - * @param EE_Payment $payment |
|
| 2347 | - * @return EE_Payment|FALSE |
|
| 2348 | - * @throws EE_Error |
|
| 2349 | - * @throws InvalidArgumentException |
|
| 2350 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2351 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2352 | - */ |
|
| 2353 | - private function _validate_payment($payment = null) |
|
| 2354 | - { |
|
| 2355 | - if ($this->checkout->payment_method->is_off_line()) { |
|
| 2356 | - return true; |
|
| 2357 | - } |
|
| 2358 | - // verify payment object |
|
| 2359 | - if (! $payment instanceof EE_Payment) { |
|
| 2360 | - // not a payment |
|
| 2361 | - EE_Error::add_error( |
|
| 2362 | - sprintf( |
|
| 2363 | - esc_html__( |
|
| 2364 | - 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2365 | - 'event_espresso' |
|
| 2366 | - ), |
|
| 2367 | - '<br/>', |
|
| 2368 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2369 | - ), |
|
| 2370 | - __FILE__, |
|
| 2371 | - __FUNCTION__, |
|
| 2372 | - __LINE__ |
|
| 2373 | - ); |
|
| 2374 | - return false; |
|
| 2375 | - } |
|
| 2376 | - return $payment; |
|
| 2377 | - } |
|
| 2378 | - |
|
| 2379 | - |
|
| 2380 | - /** |
|
| 2381 | - * _post_payment_processing |
|
| 2382 | - * |
|
| 2383 | - * @access private |
|
| 2384 | - * @param EE_Payment|bool $payment |
|
| 2385 | - * @return bool |
|
| 2386 | - * @throws EE_Error |
|
| 2387 | - * @throws InvalidArgumentException |
|
| 2388 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2389 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2390 | - */ |
|
| 2391 | - private function _post_payment_processing($payment = null) |
|
| 2392 | - { |
|
| 2393 | - // Off-Line payment? |
|
| 2394 | - if ($payment === true) { |
|
| 2395 | - // $this->_setup_redirect_for_next_step(); |
|
| 2396 | - return true; |
|
| 2397 | - // On-Site payment? |
|
| 2398 | - } elseif ($this->checkout->payment_method->is_on_site()) { |
|
| 2399 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2400 | - // $this->_setup_redirect_for_next_step(); |
|
| 2401 | - $this->checkout->continue_reg = false; |
|
| 2402 | - } |
|
| 2403 | - // Off-Site payment? |
|
| 2404 | - } elseif ($this->checkout->payment_method->is_off_site()) { |
|
| 2405 | - // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
| 2406 | - if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
| 2407 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
| 2408 | - $this->checkout->redirect = true; |
|
| 2409 | - $this->checkout->redirect_form = $payment->redirect_form(); |
|
| 2410 | - $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
| 2411 | - // set JSON response |
|
| 2412 | - $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
| 2413 | - // and lastly, let's bump the payment status to pending |
|
| 2414 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
| 2415 | - $payment->save(); |
|
| 2416 | - } else { |
|
| 2417 | - // not a payment |
|
| 2418 | - $this->checkout->continue_reg = false; |
|
| 2419 | - EE_Error::add_error( |
|
| 2420 | - sprintf( |
|
| 2421 | - esc_html__( |
|
| 2422 | - 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
| 2423 | - 'event_espresso' |
|
| 2424 | - ), |
|
| 2425 | - '<br/>', |
|
| 2426 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2427 | - ), |
|
| 2428 | - __FILE__, |
|
| 2429 | - __FUNCTION__, |
|
| 2430 | - __LINE__ |
|
| 2431 | - ); |
|
| 2432 | - } |
|
| 2433 | - } else { |
|
| 2434 | - // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
| 2435 | - $this->checkout->continue_reg = false; |
|
| 2436 | - return false; |
|
| 2437 | - } |
|
| 2438 | - return $payment; |
|
| 2439 | - } |
|
| 2440 | - |
|
| 2441 | - |
|
| 2442 | - /** |
|
| 2443 | - * _process_payment_status |
|
| 2444 | - * |
|
| 2445 | - * @access private |
|
| 2446 | - * @type EE_Payment $payment |
|
| 2447 | - * @param string $payment_occurs |
|
| 2448 | - * @return bool |
|
| 2449 | - * @throws EE_Error |
|
| 2450 | - * @throws InvalidArgumentException |
|
| 2451 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2452 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2453 | - */ |
|
| 2454 | - private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
| 2455 | - { |
|
| 2456 | - // off-line payment? carry on |
|
| 2457 | - if ($payment_occurs === EE_PMT_Base::offline) { |
|
| 2458 | - return true; |
|
| 2459 | - } |
|
| 2460 | - // verify payment validity |
|
| 2461 | - if ($payment instanceof EE_Payment) { |
|
| 2462 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
| 2463 | - $msg = $payment->gateway_response(); |
|
| 2464 | - // check results |
|
| 2465 | - switch ($payment->status()) { |
|
| 2466 | - // good payment |
|
| 2467 | - case EEM_Payment::status_id_approved: |
|
| 2468 | - EE_Error::add_success( |
|
| 2469 | - esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
| 2470 | - __FILE__, |
|
| 2471 | - __FUNCTION__, |
|
| 2472 | - __LINE__ |
|
| 2473 | - ); |
|
| 2474 | - return true; |
|
| 2475 | - break; |
|
| 2476 | - // slow payment |
|
| 2477 | - case EEM_Payment::status_id_pending: |
|
| 2478 | - if (empty($msg)) { |
|
| 2479 | - $msg = esc_html__( |
|
| 2480 | - 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
| 2481 | - 'event_espresso' |
|
| 2482 | - ); |
|
| 2483 | - } |
|
| 2484 | - EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2485 | - return true; |
|
| 2486 | - break; |
|
| 2487 | - // don't wanna payment |
|
| 2488 | - case EEM_Payment::status_id_cancelled: |
|
| 2489 | - if (empty($msg)) { |
|
| 2490 | - $msg = _n( |
|
| 2491 | - 'Payment cancelled. Please try again.', |
|
| 2492 | - 'Payment cancelled. Please try again or select another method of payment.', |
|
| 2493 | - count($this->checkout->available_payment_methods), |
|
| 2494 | - 'event_espresso' |
|
| 2495 | - ); |
|
| 2496 | - } |
|
| 2497 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2498 | - return false; |
|
| 2499 | - break; |
|
| 2500 | - // not enough payment |
|
| 2501 | - case EEM_Payment::status_id_declined: |
|
| 2502 | - if (empty($msg)) { |
|
| 2503 | - $msg = _n( |
|
| 2504 | - 'We\'re sorry but your payment was declined. Please try again.', |
|
| 2505 | - 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
| 2506 | - count($this->checkout->available_payment_methods), |
|
| 2507 | - 'event_espresso' |
|
| 2508 | - ); |
|
| 2509 | - } |
|
| 2510 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2511 | - return false; |
|
| 2512 | - break; |
|
| 2513 | - // bad payment |
|
| 2514 | - case EEM_Payment::status_id_failed: |
|
| 2515 | - if (! empty($msg)) { |
|
| 2516 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2517 | - return false; |
|
| 2518 | - } |
|
| 2519 | - // default to error below |
|
| 2520 | - break; |
|
| 2521 | - } |
|
| 2522 | - } |
|
| 2523 | - // off-site payment gateway responses are too unreliable, so let's just assume that |
|
| 2524 | - // the payment processing is just running slower than the registrant's request |
|
| 2525 | - if ($payment_occurs === EE_PMT_Base::offsite) { |
|
| 2526 | - return true; |
|
| 2527 | - } |
|
| 2528 | - EE_Error::add_error( |
|
| 2529 | - sprintf( |
|
| 2530 | - esc_html__( |
|
| 2531 | - 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2532 | - 'event_espresso' |
|
| 2533 | - ), |
|
| 2534 | - '<br/>', |
|
| 2535 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2536 | - ), |
|
| 2537 | - __FILE__, |
|
| 2538 | - __FUNCTION__, |
|
| 2539 | - __LINE__ |
|
| 2540 | - ); |
|
| 2541 | - return false; |
|
| 2542 | - } |
|
| 2543 | - |
|
| 2544 | - |
|
| 2545 | - |
|
| 2546 | - |
|
| 2547 | - |
|
| 2548 | - |
|
| 2549 | - /********************************************************************************************************/ |
|
| 2550 | - /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
| 2551 | - /********************************************************************************************************/ |
|
| 2552 | - /** |
|
| 2553 | - * process_gateway_response |
|
| 2554 | - * this is the return point for Off-Site Payment Methods |
|
| 2555 | - * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
| 2556 | - * otherwise, it will load up the last payment made for the TXN. |
|
| 2557 | - * If the payment retrieved looks good, it will then either: |
|
| 2558 | - * complete the current step and allow advancement to the next reg step |
|
| 2559 | - * or present the payment options again |
|
| 2560 | - * |
|
| 2561 | - * @access private |
|
| 2562 | - * @return EE_Payment|FALSE |
|
| 2563 | - * @throws EE_Error |
|
| 2564 | - * @throws InvalidArgumentException |
|
| 2565 | - * @throws ReflectionException |
|
| 2566 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2567 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2568 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2569 | - */ |
|
| 2570 | - public function process_gateway_response() |
|
| 2571 | - { |
|
| 2572 | - $payment = null; |
|
| 2573 | - // how have they chosen to pay? |
|
| 2574 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 2575 | - // get EE_Payment_Method object |
|
| 2576 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2577 | - $this->checkout->continue_reg = false; |
|
| 2578 | - return false; |
|
| 2579 | - } |
|
| 2580 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
| 2581 | - return false; |
|
| 2582 | - } |
|
| 2583 | - $this->_validate_offsite_return(); |
|
| 2584 | - // DEBUG LOG |
|
| 2585 | - // $this->checkout->log( |
|
| 2586 | - // __CLASS__, |
|
| 2587 | - // __FUNCTION__, |
|
| 2588 | - // __LINE__, |
|
| 2589 | - // array( |
|
| 2590 | - // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2591 | - // 'payment_method' => $this->checkout->payment_method, |
|
| 2592 | - // ), |
|
| 2593 | - // true |
|
| 2594 | - // ); |
|
| 2595 | - // verify TXN |
|
| 2596 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 2597 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
| 2598 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2599 | - $this->checkout->continue_reg = false; |
|
| 2600 | - return false; |
|
| 2601 | - } |
|
| 2602 | - $payment = $this->_process_off_site_payment($gateway); |
|
| 2603 | - $payment = $this->_process_cancelled_payments($payment); |
|
| 2604 | - $payment = $this->_validate_payment($payment); |
|
| 2605 | - // if payment was not declined by the payment gateway or cancelled by the registrant |
|
| 2606 | - if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
| 2607 | - // $this->_setup_redirect_for_next_step(); |
|
| 2608 | - // store that for later |
|
| 2609 | - $this->checkout->payment = $payment; |
|
| 2610 | - // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
| 2611 | - // because we will complete this step during the IPN processing then |
|
| 2612 | - if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
| 2613 | - $this->set_completed(); |
|
| 2614 | - } |
|
| 2615 | - return true; |
|
| 2616 | - } |
|
| 2617 | - } |
|
| 2618 | - // DEBUG LOG |
|
| 2619 | - // $this->checkout->log( |
|
| 2620 | - // __CLASS__, |
|
| 2621 | - // __FUNCTION__, |
|
| 2622 | - // __LINE__, |
|
| 2623 | - // array('payment' => $payment) |
|
| 2624 | - // ); |
|
| 2625 | - $this->checkout->continue_reg = false; |
|
| 2626 | - return false; |
|
| 2627 | - } |
|
| 2628 | - |
|
| 2629 | - |
|
| 2630 | - /** |
|
| 2631 | - * _validate_return |
|
| 2632 | - * |
|
| 2633 | - * @access private |
|
| 2634 | - * @return void |
|
| 2635 | - * @throws EE_Error |
|
| 2636 | - * @throws InvalidArgumentException |
|
| 2637 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2638 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2639 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2640 | - */ |
|
| 2641 | - private function _validate_offsite_return() |
|
| 2642 | - { |
|
| 2643 | - $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
| 2644 | - if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
| 2645 | - // Houston... we might have a problem |
|
| 2646 | - $invalid_TXN = false; |
|
| 2647 | - // first gather some info |
|
| 2648 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2649 | - $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
| 2650 | - ? $valid_TXN->primary_registration() |
|
| 2651 | - : null; |
|
| 2652 | - // let's start by retrieving the cart for this TXN |
|
| 2653 | - $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
| 2654 | - if ($cart instanceof EE_Cart) { |
|
| 2655 | - // verify that the current cart has tickets |
|
| 2656 | - $tickets = $cart->get_tickets(); |
|
| 2657 | - if (empty($tickets)) { |
|
| 2658 | - $invalid_TXN = true; |
|
| 2659 | - } |
|
| 2660 | - } else { |
|
| 2661 | - $invalid_TXN = true; |
|
| 2662 | - } |
|
| 2663 | - $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
| 2664 | - ? $primary_registrant->session_ID() |
|
| 2665 | - : null; |
|
| 2666 | - // validate current Session ID and compare against valid TXN session ID |
|
| 2667 | - if ($invalid_TXN // if this is already true, then skip other checks |
|
| 2668 | - || EE_Session::instance()->id() === null |
|
| 2669 | - || ( |
|
| 2670 | - // WARNING !!! |
|
| 2671 | - // this could be PayPal sending back duplicate requests (ya they do that) |
|
| 2672 | - // or it **could** mean someone is simply registering AGAIN after having just done so |
|
| 2673 | - // so now we need to determine if this current TXN looks valid or not |
|
| 2674 | - // and whether this reg step has even been started ? |
|
| 2675 | - EE_Session::instance()->id() === $valid_TXN_SID |
|
| 2676 | - // really? you're half way through this reg step, but you never started it ? |
|
| 2677 | - && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
| 2678 | - ) |
|
| 2679 | - ) { |
|
| 2680 | - $invalid_TXN = true; |
|
| 2681 | - } |
|
| 2682 | - if ($invalid_TXN) { |
|
| 2683 | - // is the valid TXN completed ? |
|
| 2684 | - if ($valid_TXN instanceof EE_Transaction) { |
|
| 2685 | - // has this step even been started ? |
|
| 2686 | - $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
| 2687 | - if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
| 2688 | - // so it **looks** like this is a double request from PayPal |
|
| 2689 | - // so let's try to pick up where we left off |
|
| 2690 | - $this->checkout->transaction = $valid_TXN; |
|
| 2691 | - $this->checkout->refresh_all_entities(true); |
|
| 2692 | - return; |
|
| 2693 | - } |
|
| 2694 | - } |
|
| 2695 | - // you appear to be lost? |
|
| 2696 | - $this->_redirect_wayward_request($primary_registrant); |
|
| 2697 | - } |
|
| 2698 | - } |
|
| 2699 | - } |
|
| 2700 | - |
|
| 2701 | - |
|
| 2702 | - /** |
|
| 2703 | - * _redirect_wayward_request |
|
| 2704 | - * |
|
| 2705 | - * @access private |
|
| 2706 | - * @param \EE_Registration|null $primary_registrant |
|
| 2707 | - * @return bool |
|
| 2708 | - * @throws EE_Error |
|
| 2709 | - * @throws InvalidArgumentException |
|
| 2710 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2711 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2712 | - */ |
|
| 2713 | - private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
| 2714 | - { |
|
| 2715 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2716 | - // try redirecting based on the current TXN |
|
| 2717 | - $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
| 2718 | - ? $this->checkout->transaction->primary_registration() |
|
| 2719 | - : null; |
|
| 2720 | - } |
|
| 2721 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2722 | - EE_Error::add_error( |
|
| 2723 | - sprintf( |
|
| 2724 | - esc_html__( |
|
| 2725 | - 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2726 | - 'event_espresso' |
|
| 2727 | - ), |
|
| 2728 | - '<br/>', |
|
| 2729 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2730 | - ), |
|
| 2731 | - __FILE__, |
|
| 2732 | - __FUNCTION__, |
|
| 2733 | - __LINE__ |
|
| 2734 | - ); |
|
| 2735 | - return false; |
|
| 2736 | - } |
|
| 2737 | - // make sure transaction is not locked |
|
| 2738 | - $this->checkout->transaction->unlock(); |
|
| 2739 | - wp_safe_redirect( |
|
| 2740 | - add_query_arg( |
|
| 2741 | - array( |
|
| 2742 | - 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
| 2743 | - ), |
|
| 2744 | - $this->checkout->thank_you_page_url |
|
| 2745 | - ) |
|
| 2746 | - ); |
|
| 2747 | - exit(); |
|
| 2748 | - } |
|
| 2749 | - |
|
| 2750 | - |
|
| 2751 | - /** |
|
| 2752 | - * _process_off_site_payment |
|
| 2753 | - * |
|
| 2754 | - * @access private |
|
| 2755 | - * @param \EE_Offsite_Gateway $gateway |
|
| 2756 | - * @return EE_Payment |
|
| 2757 | - * @throws EE_Error |
|
| 2758 | - * @throws InvalidArgumentException |
|
| 2759 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2760 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2761 | - */ |
|
| 2762 | - private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
| 2763 | - { |
|
| 2764 | - try { |
|
| 2765 | - $request_data = \EE_Registry::instance()->REQ->params(); |
|
| 2766 | - // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
| 2767 | - $this->set_handle_IPN_in_this_request( |
|
| 2768 | - $gateway->handle_IPN_in_this_request($request_data, false) |
|
| 2769 | - ); |
|
| 2770 | - if ($this->handle_IPN_in_this_request()) { |
|
| 2771 | - // get payment details and process results |
|
| 2772 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 2773 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2774 | - $payment = $payment_processor->process_ipn( |
|
| 2775 | - $request_data, |
|
| 2776 | - $this->checkout->transaction, |
|
| 2777 | - $this->checkout->payment_method, |
|
| 2778 | - true, |
|
| 2779 | - false |
|
| 2780 | - ); |
|
| 2781 | - // $payment_source = 'process_ipn'; |
|
| 2782 | - } else { |
|
| 2783 | - $payment = $this->checkout->transaction->last_payment(); |
|
| 2784 | - // $payment_source = 'last_payment'; |
|
| 2785 | - } |
|
| 2786 | - } catch (Exception $e) { |
|
| 2787 | - // let's just eat the exception and try to move on using any previously set payment info |
|
| 2788 | - $payment = $this->checkout->transaction->last_payment(); |
|
| 2789 | - // $payment_source = 'last_payment after Exception'; |
|
| 2790 | - // but if we STILL don't have a payment object |
|
| 2791 | - if (! $payment instanceof EE_Payment) { |
|
| 2792 | - // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
| 2793 | - $this->_handle_payment_processor_exception($e); |
|
| 2794 | - } |
|
| 2795 | - } |
|
| 2796 | - // DEBUG LOG |
|
| 2797 | - // $this->checkout->log( |
|
| 2798 | - // __CLASS__, |
|
| 2799 | - // __FUNCTION__, |
|
| 2800 | - // __LINE__, |
|
| 2801 | - // array( |
|
| 2802 | - // 'process_ipn_payment' => $payment, |
|
| 2803 | - // 'payment_source' => $payment_source, |
|
| 2804 | - // ) |
|
| 2805 | - // ); |
|
| 2806 | - return $payment; |
|
| 2807 | - } |
|
| 2808 | - |
|
| 2809 | - |
|
| 2810 | - /** |
|
| 2811 | - * _process_cancelled_payments |
|
| 2812 | - * just makes sure that the payment status gets updated correctly |
|
| 2813 | - * so tha tan error isn't generated during payment validation |
|
| 2814 | - * |
|
| 2815 | - * @access private |
|
| 2816 | - * @param EE_Payment $payment |
|
| 2817 | - * @return EE_Payment | FALSE |
|
| 2818 | - * @throws \EE_Error |
|
| 2819 | - */ |
|
| 2820 | - private function _process_cancelled_payments($payment = null) |
|
| 2821 | - { |
|
| 2822 | - if ($payment instanceof EE_Payment |
|
| 2823 | - && isset($_REQUEST['ee_cancel_payment']) |
|
| 2824 | - && $payment->status() === EEM_Payment::status_id_failed |
|
| 2825 | - ) { |
|
| 2826 | - $payment->set_status(EEM_Payment::status_id_cancelled); |
|
| 2827 | - } |
|
| 2828 | - return $payment; |
|
| 2829 | - } |
|
| 2830 | - |
|
| 2831 | - |
|
| 2832 | - /** |
|
| 2833 | - * get_transaction_details_for_gateways |
|
| 2834 | - * |
|
| 2835 | - * @access public |
|
| 2836 | - * @return int |
|
| 2837 | - * @throws EE_Error |
|
| 2838 | - * @throws InvalidArgumentException |
|
| 2839 | - * @throws ReflectionException |
|
| 2840 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2841 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2842 | - */ |
|
| 2843 | - public function get_transaction_details_for_gateways() |
|
| 2844 | - { |
|
| 2845 | - $txn_details = array(); |
|
| 2846 | - // ya gotta make a choice man |
|
| 2847 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 2848 | - $txn_details = array( |
|
| 2849 | - 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
| 2850 | - ); |
|
| 2851 | - } |
|
| 2852 | - // get EE_Payment_Method object |
|
| 2853 | - if (empty($txn_details) |
|
| 2854 | - && |
|
| 2855 | - ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
| 2856 | - ) { |
|
| 2857 | - $txn_details = array( |
|
| 2858 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2859 | - 'error' => esc_html__( |
|
| 2860 | - 'A valid Payment Method could not be determined.', |
|
| 2861 | - 'event_espresso' |
|
| 2862 | - ), |
|
| 2863 | - ); |
|
| 2864 | - } |
|
| 2865 | - if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
| 2866 | - $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
| 2867 | - $txn_details = array( |
|
| 2868 | - 'TXN_ID' => $this->checkout->transaction->ID(), |
|
| 2869 | - 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
| 2870 | - 'TXN_total' => $this->checkout->transaction->total(), |
|
| 2871 | - 'TXN_paid' => $this->checkout->transaction->paid(), |
|
| 2872 | - 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
| 2873 | - 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
| 2874 | - 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
| 2875 | - 'payment_amount' => $this->checkout->amount_owing, |
|
| 2876 | - 'return_url' => $return_url, |
|
| 2877 | - 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
| 2878 | - 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
| 2879 | - array( |
|
| 2880 | - 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
| 2881 | - 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
| 2882 | - ) |
|
| 2883 | - ), |
|
| 2884 | - ); |
|
| 2885 | - } |
|
| 2886 | - echo wp_json_encode($txn_details); |
|
| 2887 | - exit(); |
|
| 2888 | - } |
|
| 2889 | - |
|
| 2890 | - |
|
| 2891 | - /** |
|
| 2892 | - * __sleep |
|
| 2893 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
| 2894 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
| 2895 | - * reg form, because if needed, it will be regenerated anyways |
|
| 2896 | - * |
|
| 2897 | - * @return array |
|
| 2898 | - */ |
|
| 2899 | - public function __sleep() |
|
| 2900 | - { |
|
| 2901 | - // remove the reg form and the checkout |
|
| 2902 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
| 2903 | - } |
|
| 15 | + /** |
|
| 16 | + * @access protected |
|
| 17 | + * @var EE_Line_Item_Display $Line_Item_Display |
|
| 18 | + */ |
|
| 19 | + protected $line_item_display; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @access protected |
|
| 23 | + * @var boolean $handle_IPN_in_this_request |
|
| 24 | + */ |
|
| 25 | + protected $handle_IPN_in_this_request = false; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 30 | + * |
|
| 31 | + * @access public |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public static function set_hooks() |
|
| 35 | + { |
|
| 36 | + add_filter( |
|
| 37 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 38 | + array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
| 39 | + ); |
|
| 40 | + add_action( |
|
| 41 | + 'wp_ajax_switch_spco_billing_form', |
|
| 42 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 43 | + ); |
|
| 44 | + add_action( |
|
| 45 | + 'wp_ajax_nopriv_switch_spco_billing_form', |
|
| 46 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 47 | + ); |
|
| 48 | + add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
| 49 | + add_action( |
|
| 50 | + 'wp_ajax_nopriv_save_payer_details', |
|
| 51 | + array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
| 52 | + ); |
|
| 53 | + add_action( |
|
| 54 | + 'wp_ajax_get_transaction_details_for_gateways', |
|
| 55 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 56 | + ); |
|
| 57 | + add_action( |
|
| 58 | + 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
| 59 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 60 | + ); |
|
| 61 | + add_filter( |
|
| 62 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
| 63 | + array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
| 64 | + 10, |
|
| 65 | + 1 |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * ajax switch_spco_billing_form |
|
| 72 | + * |
|
| 73 | + * @throws \EE_Error |
|
| 74 | + */ |
|
| 75 | + public static function switch_spco_billing_form() |
|
| 76 | + { |
|
| 77 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * ajax save_payer_details |
|
| 83 | + * |
|
| 84 | + * @throws \EE_Error |
|
| 85 | + */ |
|
| 86 | + public static function save_payer_details() |
|
| 87 | + { |
|
| 88 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * ajax get_transaction_details |
|
| 94 | + * |
|
| 95 | + * @throws \EE_Error |
|
| 96 | + */ |
|
| 97 | + public static function get_transaction_details() |
|
| 98 | + { |
|
| 99 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * bypass_recaptcha_for_load_payment_method |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @return array |
|
| 108 | + * @throws InvalidArgumentException |
|
| 109 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 110 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 111 | + */ |
|
| 112 | + public static function bypass_recaptcha_for_load_payment_method() |
|
| 113 | + { |
|
| 114 | + return array( |
|
| 115 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
| 116 | + 'step' => 'payment_options', |
|
| 117 | + 'action' => 'spco_billing_form', |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * class constructor |
|
| 124 | + * |
|
| 125 | + * @access public |
|
| 126 | + * @param EE_Checkout $checkout |
|
| 127 | + */ |
|
| 128 | + public function __construct(EE_Checkout $checkout) |
|
| 129 | + { |
|
| 130 | + $this->_slug = 'payment_options'; |
|
| 131 | + $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
| 132 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
| 133 | + $this->checkout = $checkout; |
|
| 134 | + $this->_reset_success_message(); |
|
| 135 | + $this->set_instructions( |
|
| 136 | + esc_html__( |
|
| 137 | + 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
| 138 | + 'event_espresso' |
|
| 139 | + ) |
|
| 140 | + ); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return null |
|
| 146 | + */ |
|
| 147 | + public function line_item_display() |
|
| 148 | + { |
|
| 149 | + return $this->line_item_display; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param null $line_item_display |
|
| 155 | + */ |
|
| 156 | + public function set_line_item_display($line_item_display) |
|
| 157 | + { |
|
| 158 | + $this->line_item_display = $line_item_display; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return boolean |
|
| 164 | + */ |
|
| 165 | + public function handle_IPN_in_this_request() |
|
| 166 | + { |
|
| 167 | + return $this->handle_IPN_in_this_request; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param boolean $handle_IPN_in_this_request |
|
| 173 | + */ |
|
| 174 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
| 175 | + { |
|
| 176 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * translate_js_strings |
|
| 182 | + * |
|
| 183 | + * @return void |
|
| 184 | + */ |
|
| 185 | + public function translate_js_strings() |
|
| 186 | + { |
|
| 187 | + EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
| 188 | + 'Please select a method of payment in order to continue.', |
|
| 189 | + 'event_espresso' |
|
| 190 | + ); |
|
| 191 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
| 192 | + 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
| 193 | + 'event_espresso' |
|
| 194 | + ); |
|
| 195 | + EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
| 196 | + 'Forwarding to Secure Payment Provider.', |
|
| 197 | + 'event_espresso' |
|
| 198 | + ); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * enqueue_styles_and_scripts |
|
| 204 | + * |
|
| 205 | + * @return void |
|
| 206 | + * @throws EE_Error |
|
| 207 | + * @throws InvalidArgumentException |
|
| 208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 210 | + */ |
|
| 211 | + public function enqueue_styles_and_scripts() |
|
| 212 | + { |
|
| 213 | + $transaction = $this->checkout->transaction; |
|
| 214 | + // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
| 215 | + if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 218 | + foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 219 | + $transaction, |
|
| 220 | + EEM_Payment_Method::scope_cart |
|
| 221 | + ) as $payment_method) { |
|
| 222 | + $type_obj = $payment_method->type_obj(); |
|
| 223 | + if ($type_obj instanceof EE_PMT_Base) { |
|
| 224 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
| 225 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 226 | + $billing_form->enqueue_js(); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * initialize_reg_step |
|
| 235 | + * |
|
| 236 | + * @return bool |
|
| 237 | + * @throws EE_Error |
|
| 238 | + * @throws InvalidArgumentException |
|
| 239 | + * @throws ReflectionException |
|
| 240 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 241 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 242 | + */ |
|
| 243 | + public function initialize_reg_step() |
|
| 244 | + { |
|
| 245 | + // TODO: if /when we implement donations, then this will need overriding |
|
| 246 | + if (// don't need payment options for: |
|
| 247 | + // registrations made via the admin |
|
| 248 | + // completed transactions |
|
| 249 | + // overpaid transactions |
|
| 250 | + // $ 0.00 transactions(no payment required) |
|
| 251 | + ! $this->checkout->payment_required() |
|
| 252 | + // but do NOT remove if current action being called belongs to this reg step |
|
| 253 | + && ! is_callable(array($this, $this->checkout->action)) |
|
| 254 | + && ! $this->completed() |
|
| 255 | + ) { |
|
| 256 | + // and if so, then we no longer need the Payment Options step |
|
| 257 | + if ($this->is_current_step()) { |
|
| 258 | + $this->checkout->generate_reg_form = false; |
|
| 259 | + } |
|
| 260 | + $this->checkout->remove_reg_step($this->_slug); |
|
| 261 | + // DEBUG LOG |
|
| 262 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + // load EEM_Payment_Method |
|
| 266 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 267 | + // get all active payment methods |
|
| 268 | + $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 269 | + $this->checkout->transaction, |
|
| 270 | + EEM_Payment_Method::scope_cart |
|
| 271 | + ); |
|
| 272 | + return true; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @return EE_Form_Section_Proper |
|
| 278 | + * @throws EE_Error |
|
| 279 | + * @throws InvalidArgumentException |
|
| 280 | + * @throws ReflectionException |
|
| 281 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 282 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 283 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 284 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 285 | + */ |
|
| 286 | + public function generate_reg_form() |
|
| 287 | + { |
|
| 288 | + // reset in case someone changes their mind |
|
| 289 | + $this->_reset_selected_method_of_payment(); |
|
| 290 | + // set some defaults |
|
| 291 | + $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
| 292 | + $registrations_requiring_payment = array(); |
|
| 293 | + $registrations_for_free_events = array(); |
|
| 294 | + $registrations_requiring_pre_approval = array(); |
|
| 295 | + $sold_out_events = array(); |
|
| 296 | + $insufficient_spaces_available = array(); |
|
| 297 | + $no_payment_required = true; |
|
| 298 | + // loop thru registrations to gather info |
|
| 299 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 300 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 301 | + $registrations, |
|
| 302 | + $this->checkout->revisit |
|
| 303 | + ); |
|
| 304 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 305 | + /** @var $registration EE_Registration */ |
|
| 306 | + // has this registration lost it's space ? |
|
| 307 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 308 | + if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
| 309 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 310 | + } else { |
|
| 311 | + $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
| 312 | + } |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | + // event requires admin approval |
|
| 316 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
| 317 | + // add event to list of events with pre-approval reg status |
|
| 318 | + $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
| 319 | + do_action( |
|
| 320 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
| 321 | + $registration->event(), |
|
| 322 | + $this |
|
| 323 | + ); |
|
| 324 | + continue; |
|
| 325 | + } |
|
| 326 | + if ($this->checkout->revisit |
|
| 327 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 328 | + && ( |
|
| 329 | + $registration->event()->is_sold_out() |
|
| 330 | + || $registration->event()->is_sold_out(true) |
|
| 331 | + ) |
|
| 332 | + ) { |
|
| 333 | + // add event to list of events that are sold out |
|
| 334 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 335 | + do_action( |
|
| 336 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
| 337 | + $registration->event(), |
|
| 338 | + $this |
|
| 339 | + ); |
|
| 340 | + continue; |
|
| 341 | + } |
|
| 342 | + // are they allowed to pay now and is there monies owing? |
|
| 343 | + if ($registration->owes_monies_and_can_pay()) { |
|
| 344 | + $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
| 345 | + do_action( |
|
| 346 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
| 347 | + $registration->event(), |
|
| 348 | + $this |
|
| 349 | + ); |
|
| 350 | + } elseif (! $this->checkout->revisit |
|
| 351 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 352 | + && $registration->ticket()->is_free() |
|
| 353 | + ) { |
|
| 354 | + $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $subsections = array(); |
|
| 358 | + // now decide which template to load |
|
| 359 | + if (! empty($sold_out_events)) { |
|
| 360 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
| 361 | + } |
|
| 362 | + if (! empty($insufficient_spaces_available)) { |
|
| 363 | + $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
| 364 | + $insufficient_spaces_available |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + if (! empty($registrations_requiring_pre_approval)) { |
|
| 368 | + $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
| 369 | + $registrations_requiring_pre_approval |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + if (! empty($registrations_for_free_events)) { |
|
| 373 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
| 374 | + } |
|
| 375 | + if (! empty($registrations_requiring_payment)) { |
|
| 376 | + if ($this->checkout->amount_owing > 0) { |
|
| 377 | + // autoload Line_Item_Display classes |
|
| 378 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 379 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 380 | + apply_filters( |
|
| 381 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 382 | + new EE_Line_Item_Filter_Collection() |
|
| 383 | + ), |
|
| 384 | + $this->checkout->cart->get_grand_total() |
|
| 385 | + ); |
|
| 386 | + /** @var EE_Line_Item $filtered_line_item_tree */ |
|
| 387 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 388 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 389 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
| 390 | + $subsections['payment_options'] = $this->_display_payment_options( |
|
| 391 | + $this->line_item_display->display_line_item( |
|
| 392 | + $filtered_line_item_tree, |
|
| 393 | + array('registrations' => $registrations) |
|
| 394 | + ) |
|
| 395 | + ); |
|
| 396 | + $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
| 397 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
| 398 | + } |
|
| 399 | + $no_payment_required = false; |
|
| 400 | + } else { |
|
| 401 | + $this->_hide_reg_step_submit_button_if_revisit(); |
|
| 402 | + } |
|
| 403 | + $this->_save_selected_method_of_payment(); |
|
| 404 | + |
|
| 405 | + $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
| 406 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
| 407 | + |
|
| 408 | + return new EE_Form_Section_Proper( |
|
| 409 | + array( |
|
| 410 | + 'name' => $this->reg_form_name(), |
|
| 411 | + 'html_id' => $this->reg_form_name(), |
|
| 412 | + 'subsections' => $subsections, |
|
| 413 | + 'layout_strategy' => new EE_No_Layout(), |
|
| 414 | + ) |
|
| 415 | + ); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * add line item filters required for this reg step |
|
| 421 | + * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
| 422 | + * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 423 | + * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
| 424 | + * payment options reg step, can apply these filters via the following: apply_filters( |
|
| 425 | + * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
| 426 | + * filter collection by passing that instead of instantiating a new collection |
|
| 427 | + * |
|
| 428 | + * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
| 429 | + * @return EE_Line_Item_Filter_Collection |
|
| 430 | + * @throws EE_Error |
|
| 431 | + * @throws InvalidArgumentException |
|
| 432 | + * @throws ReflectionException |
|
| 433 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 434 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 435 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 436 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 437 | + */ |
|
| 438 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
| 439 | + { |
|
| 440 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 441 | + return $line_item_filter_collection; |
|
| 442 | + } |
|
| 443 | + if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 444 | + return $line_item_filter_collection; |
|
| 445 | + } |
|
| 446 | + if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 447 | + return $line_item_filter_collection; |
|
| 448 | + } |
|
| 449 | + $line_item_filter_collection->add( |
|
| 450 | + new EE_Billable_Line_Item_Filter( |
|
| 451 | + EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
| 452 | + EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 453 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 454 | + ) |
|
| 455 | + ) |
|
| 456 | + ) |
|
| 457 | + ); |
|
| 458 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 459 | + return $line_item_filter_collection; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * remove_ejected_registrations |
|
| 465 | + * if a registrant has lost their potential space at an event due to lack of payment, |
|
| 466 | + * then this method removes them from the list of registrations being paid for during this request |
|
| 467 | + * |
|
| 468 | + * @param \EE_Registration[] $registrations |
|
| 469 | + * @return EE_Registration[] |
|
| 470 | + * @throws EE_Error |
|
| 471 | + * @throws InvalidArgumentException |
|
| 472 | + * @throws ReflectionException |
|
| 473 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 474 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 475 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 476 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 477 | + */ |
|
| 478 | + public static function remove_ejected_registrations(array $registrations) |
|
| 479 | + { |
|
| 480 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 481 | + $registrations, |
|
| 482 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
| 483 | + ); |
|
| 484 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 485 | + // has this registration lost it's space ? |
|
| 486 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 487 | + unset($registrations[ $REG_ID ]); |
|
| 488 | + continue; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + return $registrations; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * find_registrations_that_lost_their_space |
|
| 497 | + * If a registrant chooses an offline payment method like Invoice, |
|
| 498 | + * then no space is reserved for them at the event until they fully pay fo that site |
|
| 499 | + * (unless the event's default reg status is set to APPROVED) |
|
| 500 | + * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
| 501 | + * then this method will determine which registrations have lost the ability to complete the reg process. |
|
| 502 | + * |
|
| 503 | + * @param \EE_Registration[] $registrations |
|
| 504 | + * @param bool $revisit |
|
| 505 | + * @return array |
|
| 506 | + * @throws EE_Error |
|
| 507 | + * @throws InvalidArgumentException |
|
| 508 | + * @throws ReflectionException |
|
| 509 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 510 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 511 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 512 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 513 | + */ |
|
| 514 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
| 515 | + { |
|
| 516 | + // registrations per event |
|
| 517 | + $event_reg_count = array(); |
|
| 518 | + // spaces left per event |
|
| 519 | + $event_spaces_remaining = array(); |
|
| 520 | + // tickets left sorted by ID |
|
| 521 | + $tickets_remaining = array(); |
|
| 522 | + // registrations that have lost their space |
|
| 523 | + $ejected_registrations = array(); |
|
| 524 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 525 | + if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
| 526 | + || apply_filters( |
|
| 527 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
| 528 | + false, |
|
| 529 | + $registration, |
|
| 530 | + $revisit |
|
| 531 | + ) |
|
| 532 | + ) { |
|
| 533 | + continue; |
|
| 534 | + } |
|
| 535 | + $EVT_ID = $registration->event_ID(); |
|
| 536 | + $ticket = $registration->ticket(); |
|
| 537 | + if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
| 538 | + $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
| 539 | + } |
|
| 540 | + if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
| 541 | + if (! isset($event_reg_count[ $EVT_ID ])) { |
|
| 542 | + $event_reg_count[ $EVT_ID ] = 0; |
|
| 543 | + } |
|
| 544 | + $event_reg_count[ $EVT_ID ]++; |
|
| 545 | + if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
| 546 | + $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + if ($revisit |
|
| 550 | + && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
| 551 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
| 552 | + ) |
|
| 553 | + ) { |
|
| 554 | + $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
| 555 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
| 556 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 557 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 558 | + // at this point, we should have enough details about the registrant to consider the registration |
|
| 559 | + // NOT incomplete |
|
| 560 | + $registration_processor->manually_update_registration_status( |
|
| 561 | + $registration, |
|
| 562 | + EEM_Registration::status_id_wait_list |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + return $ejected_registrations; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * _hide_reg_step_submit_button |
|
| 573 | + * removes the html for the reg step submit button |
|
| 574 | + * by replacing it with an empty string via filter callback |
|
| 575 | + * |
|
| 576 | + * @return void |
|
| 577 | + */ |
|
| 578 | + protected function _adjust_registration_status_if_event_old_sold() |
|
| 579 | + { |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * _hide_reg_step_submit_button |
|
| 585 | + * removes the html for the reg step submit button |
|
| 586 | + * by replacing it with an empty string via filter callback |
|
| 587 | + * |
|
| 588 | + * @return void |
|
| 589 | + */ |
|
| 590 | + protected function _hide_reg_step_submit_button_if_revisit() |
|
| 591 | + { |
|
| 592 | + if ($this->checkout->revisit) { |
|
| 593 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * sold_out_events |
|
| 600 | + * displays notices regarding events that have sold out since hte registrant first signed up |
|
| 601 | + * |
|
| 602 | + * @param \EE_Event[] $sold_out_events_array |
|
| 603 | + * @return \EE_Form_Section_Proper |
|
| 604 | + * @throws \EE_Error |
|
| 605 | + */ |
|
| 606 | + private function _sold_out_events($sold_out_events_array = array()) |
|
| 607 | + { |
|
| 608 | + // set some defaults |
|
| 609 | + $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
| 610 | + $sold_out_events = ''; |
|
| 611 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
| 612 | + $sold_out_events .= EEH_HTML::li( |
|
| 613 | + EEH_HTML::span( |
|
| 614 | + ' ' . $sold_out_event->name(), |
|
| 615 | + '', |
|
| 616 | + 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
| 617 | + ) |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + return new EE_Form_Section_Proper( |
|
| 621 | + array( |
|
| 622 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 623 | + array( |
|
| 624 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 625 | + . $this->_slug |
|
| 626 | + . DS |
|
| 627 | + . 'sold_out_events.template.php', |
|
| 628 | + 'template_args' => apply_filters( |
|
| 629 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 630 | + array( |
|
| 631 | + 'sold_out_events' => $sold_out_events, |
|
| 632 | + 'sold_out_events_msg' => apply_filters( |
|
| 633 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
| 634 | + sprintf( |
|
| 635 | + esc_html__( |
|
| 636 | + 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
| 637 | + 'event_espresso' |
|
| 638 | + ), |
|
| 639 | + '<strong>', |
|
| 640 | + '</strong>', |
|
| 641 | + '<br />' |
|
| 642 | + ) |
|
| 643 | + ), |
|
| 644 | + ) |
|
| 645 | + ), |
|
| 646 | + ) |
|
| 647 | + ), |
|
| 648 | + ) |
|
| 649 | + ); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * _insufficient_spaces_available |
|
| 655 | + * displays notices regarding events that do not have enough remaining spaces |
|
| 656 | + * to satisfy the current number of registrations looking to pay |
|
| 657 | + * |
|
| 658 | + * @param \EE_Event[] $insufficient_spaces_events_array |
|
| 659 | + * @return \EE_Form_Section_Proper |
|
| 660 | + * @throws \EE_Error |
|
| 661 | + */ |
|
| 662 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
| 663 | + { |
|
| 664 | + // set some defaults |
|
| 665 | + $this->checkout->selected_method_of_payment = 'invoice'; |
|
| 666 | + $insufficient_space_events = ''; |
|
| 667 | + foreach ($insufficient_spaces_events_array as $event) { |
|
| 668 | + if ($event instanceof EE_Event) { |
|
| 669 | + $insufficient_space_events .= EEH_HTML::li( |
|
| 670 | + EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 671 | + ); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + return new EE_Form_Section_Proper( |
|
| 675 | + array( |
|
| 676 | + 'subsections' => array( |
|
| 677 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
| 678 | + 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
| 679 | + ), |
|
| 680 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 681 | + array( |
|
| 682 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 683 | + . $this->_slug |
|
| 684 | + . DS |
|
| 685 | + . 'sold_out_events.template.php', |
|
| 686 | + 'template_args' => apply_filters( |
|
| 687 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
| 688 | + array( |
|
| 689 | + 'sold_out_events' => $insufficient_space_events, |
|
| 690 | + 'sold_out_events_msg' => apply_filters( |
|
| 691 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
| 692 | + esc_html__( |
|
| 693 | + 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 694 | + 'event_espresso' |
|
| 695 | + ) |
|
| 696 | + ), |
|
| 697 | + ) |
|
| 698 | + ), |
|
| 699 | + ) |
|
| 700 | + ), |
|
| 701 | + ) |
|
| 702 | + ); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * registrations_requiring_pre_approval |
|
| 708 | + * |
|
| 709 | + * @param array $registrations_requiring_pre_approval |
|
| 710 | + * @return EE_Form_Section_Proper |
|
| 711 | + * @throws EE_Error |
|
| 712 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 713 | + */ |
|
| 714 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
| 715 | + { |
|
| 716 | + $events_requiring_pre_approval = ''; |
|
| 717 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
| 718 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
| 719 | + $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
| 720 | + EEH_HTML::span( |
|
| 721 | + '', |
|
| 722 | + '', |
|
| 723 | + 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
| 724 | + ) |
|
| 725 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
| 726 | + ); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + return new EE_Form_Section_Proper( |
|
| 730 | + array( |
|
| 731 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 732 | + array( |
|
| 733 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 734 | + . $this->_slug |
|
| 735 | + . DS |
|
| 736 | + . 'events_requiring_pre_approval.template.php', // layout_template |
|
| 737 | + 'template_args' => apply_filters( |
|
| 738 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 739 | + array( |
|
| 740 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
| 741 | + 'events_requiring_pre_approval_msg' => apply_filters( |
|
| 742 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
| 743 | + esc_html__( |
|
| 744 | + 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
| 745 | + 'event_espresso' |
|
| 746 | + ) |
|
| 747 | + ), |
|
| 748 | + ) |
|
| 749 | + ), |
|
| 750 | + ) |
|
| 751 | + ), |
|
| 752 | + ) |
|
| 753 | + ); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * _no_payment_required |
|
| 759 | + * |
|
| 760 | + * @param \EE_Event[] $registrations_for_free_events |
|
| 761 | + * @return \EE_Form_Section_Proper |
|
| 762 | + * @throws \EE_Error |
|
| 763 | + */ |
|
| 764 | + private function _no_payment_required($registrations_for_free_events = array()) |
|
| 765 | + { |
|
| 766 | + // set some defaults |
|
| 767 | + $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
| 768 | + // generate no_payment_required form |
|
| 769 | + return new EE_Form_Section_Proper( |
|
| 770 | + array( |
|
| 771 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 772 | + array( |
|
| 773 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 774 | + . $this->_slug |
|
| 775 | + . DS |
|
| 776 | + . 'no_payment_required.template.php', // layout_template |
|
| 777 | + 'template_args' => apply_filters( |
|
| 778 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
| 779 | + array( |
|
| 780 | + 'revisit' => $this->checkout->revisit, |
|
| 781 | + 'registrations' => array(), |
|
| 782 | + 'ticket_count' => array(), |
|
| 783 | + 'registrations_for_free_events' => $registrations_for_free_events, |
|
| 784 | + 'no_payment_required_msg' => EEH_HTML::p( |
|
| 785 | + esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
| 786 | + ), |
|
| 787 | + ) |
|
| 788 | + ), |
|
| 789 | + ) |
|
| 790 | + ), |
|
| 791 | + ) |
|
| 792 | + ); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * _display_payment_options |
|
| 798 | + * |
|
| 799 | + * @param string $transaction_details |
|
| 800 | + * @return EE_Form_Section_Proper |
|
| 801 | + * @throws EE_Error |
|
| 802 | + * @throws InvalidArgumentException |
|
| 803 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 804 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 805 | + */ |
|
| 806 | + private function _display_payment_options($transaction_details = '') |
|
| 807 | + { |
|
| 808 | + // has method_of_payment been set by no-js user? |
|
| 809 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
| 810 | + // build payment options form |
|
| 811 | + return apply_filters( |
|
| 812 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
| 813 | + new EE_Form_Section_Proper( |
|
| 814 | + array( |
|
| 815 | + 'subsections' => array( |
|
| 816 | + 'before_payment_options' => apply_filters( |
|
| 817 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
| 818 | + new EE_Form_Section_Proper( |
|
| 819 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 820 | + ) |
|
| 821 | + ), |
|
| 822 | + 'payment_options' => $this->_setup_payment_options(), |
|
| 823 | + 'after_payment_options' => apply_filters( |
|
| 824 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
| 825 | + new EE_Form_Section_Proper( |
|
| 826 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 827 | + ) |
|
| 828 | + ), |
|
| 829 | + ), |
|
| 830 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 831 | + array( |
|
| 832 | + 'layout_template_file' => $this->_template, |
|
| 833 | + 'template_args' => apply_filters( |
|
| 834 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
| 835 | + array( |
|
| 836 | + 'reg_count' => $this->line_item_display->total_items(), |
|
| 837 | + 'transaction_details' => $transaction_details, |
|
| 838 | + 'available_payment_methods' => array(), |
|
| 839 | + ) |
|
| 840 | + ), |
|
| 841 | + ) |
|
| 842 | + ), |
|
| 843 | + ) |
|
| 844 | + ) |
|
| 845 | + ); |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * _extra_hidden_inputs |
|
| 851 | + * |
|
| 852 | + * @param bool $no_payment_required |
|
| 853 | + * @return \EE_Form_Section_Proper |
|
| 854 | + * @throws \EE_Error |
|
| 855 | + */ |
|
| 856 | + private function _extra_hidden_inputs($no_payment_required = true) |
|
| 857 | + { |
|
| 858 | + return new EE_Form_Section_Proper( |
|
| 859 | + array( |
|
| 860 | + 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
| 861 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 862 | + 'subsections' => array( |
|
| 863 | + 'spco_no_payment_required' => new EE_Hidden_Input( |
|
| 864 | + array( |
|
| 865 | + 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
| 866 | + 'html_name' => 'spco_no_payment_required', |
|
| 867 | + 'html_id' => 'spco-no-payment-required-payment_options', |
|
| 868 | + 'default' => $no_payment_required, |
|
| 869 | + ) |
|
| 870 | + ), |
|
| 871 | + 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
| 872 | + array( |
|
| 873 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
| 874 | + 'html_name' => 'spco_transaction_id', |
|
| 875 | + 'html_id' => 'spco-transaction-id', |
|
| 876 | + 'default' => $this->checkout->transaction->ID(), |
|
| 877 | + ) |
|
| 878 | + ), |
|
| 879 | + ), |
|
| 880 | + ) |
|
| 881 | + ); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * _apply_registration_payments_to_amount_owing |
|
| 887 | + * |
|
| 888 | + * @access protected |
|
| 889 | + * @param array $registrations |
|
| 890 | + * @throws EE_Error |
|
| 891 | + */ |
|
| 892 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
| 893 | + { |
|
| 894 | + $payments = array(); |
|
| 895 | + foreach ($registrations as $registration) { |
|
| 896 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 897 | + $payments += $registration->registration_payments(); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + if (! empty($payments)) { |
|
| 901 | + foreach ($payments as $payment) { |
|
| 902 | + if ($payment instanceof EE_Registration_Payment) { |
|
| 903 | + $this->checkout->amount_owing -= $payment->amount(); |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * _reset_selected_method_of_payment |
|
| 912 | + * |
|
| 913 | + * @access private |
|
| 914 | + * @param bool $force_reset |
|
| 915 | + * @return void |
|
| 916 | + * @throws InvalidArgumentException |
|
| 917 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 918 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 919 | + */ |
|
| 920 | + private function _reset_selected_method_of_payment($force_reset = false) |
|
| 921 | + { |
|
| 922 | + $reset_payment_method = $force_reset |
|
| 923 | + ? true |
|
| 924 | + : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
| 925 | + if ($reset_payment_method) { |
|
| 926 | + $this->checkout->selected_method_of_payment = null; |
|
| 927 | + $this->checkout->payment_method = null; |
|
| 928 | + $this->checkout->billing_form = null; |
|
| 929 | + $this->_save_selected_method_of_payment(); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * _save_selected_method_of_payment |
|
| 936 | + * stores the selected_method_of_payment in the session |
|
| 937 | + * so that it's available for all subsequent requests including AJAX |
|
| 938 | + * |
|
| 939 | + * @access private |
|
| 940 | + * @param string $selected_method_of_payment |
|
| 941 | + * @return void |
|
| 942 | + * @throws InvalidArgumentException |
|
| 943 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 944 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 945 | + */ |
|
| 946 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
| 947 | + { |
|
| 948 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
| 949 | + ? $selected_method_of_payment |
|
| 950 | + : $this->checkout->selected_method_of_payment; |
|
| 951 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 952 | + array('selected_method_of_payment' => $selected_method_of_payment) |
|
| 953 | + ); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * _setup_payment_options |
|
| 959 | + * |
|
| 960 | + * @return EE_Form_Section_Proper |
|
| 961 | + * @throws EE_Error |
|
| 962 | + * @throws InvalidArgumentException |
|
| 963 | + * @throws ReflectionException |
|
| 964 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 965 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 966 | + */ |
|
| 967 | + public function _setup_payment_options() |
|
| 968 | + { |
|
| 969 | + // load payment method classes |
|
| 970 | + $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
| 971 | + if (empty($this->checkout->available_payment_methods)) { |
|
| 972 | + EE_Error::add_error( |
|
| 973 | + apply_filters( |
|
| 974 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
| 975 | + sprintf( |
|
| 976 | + esc_html__( |
|
| 977 | + 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
| 978 | + 'event_espresso' |
|
| 979 | + ), |
|
| 980 | + '<br>', |
|
| 981 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 982 | + ) |
|
| 983 | + ), |
|
| 984 | + __FILE__, |
|
| 985 | + __FUNCTION__, |
|
| 986 | + __LINE__ |
|
| 987 | + ); |
|
| 988 | + } |
|
| 989 | + // switch up header depending on number of available payment methods |
|
| 990 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
| 991 | + ? apply_filters( |
|
| 992 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 993 | + esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
| 994 | + ) |
|
| 995 | + : apply_filters( |
|
| 996 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 997 | + esc_html__('Method of Payment', 'event_espresso') |
|
| 998 | + ); |
|
| 999 | + $available_payment_methods = array( |
|
| 1000 | + // display the "Payment Method" header |
|
| 1001 | + 'payment_method_header' => new EE_Form_Section_HTML( |
|
| 1002 | + apply_filters( |
|
| 1003 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
| 1004 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
| 1005 | + $payment_method_header |
|
| 1006 | + ) |
|
| 1007 | + ), |
|
| 1008 | + ); |
|
| 1009 | + // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
| 1010 | + $available_payment_method_options = array(); |
|
| 1011 | + $default_payment_method_option = array(); |
|
| 1012 | + // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
| 1013 | + $payment_methods_billing_info = array( |
|
| 1014 | + new EE_Form_Section_HTML( |
|
| 1015 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
| 1016 | + ), |
|
| 1017 | + ); |
|
| 1018 | + // loop through payment methods |
|
| 1019 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
| 1020 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 1021 | + $payment_method_button = EEH_HTML::img( |
|
| 1022 | + $payment_method->button_url(), |
|
| 1023 | + $payment_method->name(), |
|
| 1024 | + 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
| 1025 | + 'spco-payment-method-btn-img' |
|
| 1026 | + ); |
|
| 1027 | + // check if any payment methods are set as default |
|
| 1028 | + // if payment method is already selected OR nothing is selected and this payment method should be |
|
| 1029 | + // open_by_default |
|
| 1030 | + if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
| 1031 | + || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1032 | + ) { |
|
| 1033 | + $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
| 1034 | + $this->_save_selected_method_of_payment(); |
|
| 1035 | + $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
| 1036 | + } else { |
|
| 1037 | + $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
| 1038 | + } |
|
| 1039 | + $payment_methods_billing_info[ $payment_method->slug( |
|
| 1040 | + ) . '-info' ] = $this->_payment_method_billing_info( |
|
| 1041 | + $payment_method |
|
| 1042 | + ); |
|
| 1043 | + } |
|
| 1044 | + } |
|
| 1045 | + // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
| 1046 | + // of PMs |
|
| 1047 | + $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
| 1048 | + // now generate the actual form inputs |
|
| 1049 | + $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
| 1050 | + $available_payment_method_options |
|
| 1051 | + ); |
|
| 1052 | + $available_payment_methods += $payment_methods_billing_info; |
|
| 1053 | + // build the available payment methods form |
|
| 1054 | + return new EE_Form_Section_Proper( |
|
| 1055 | + array( |
|
| 1056 | + 'html_id' => 'spco-available-methods-of-payment-dv', |
|
| 1057 | + 'subsections' => $available_payment_methods, |
|
| 1058 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1059 | + ) |
|
| 1060 | + ); |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + |
|
| 1064 | + /** |
|
| 1065 | + * _get_available_payment_methods |
|
| 1066 | + * |
|
| 1067 | + * @return EE_Payment_Method[] |
|
| 1068 | + * @throws EE_Error |
|
| 1069 | + * @throws InvalidArgumentException |
|
| 1070 | + * @throws ReflectionException |
|
| 1071 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1072 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1073 | + */ |
|
| 1074 | + protected function _get_available_payment_methods() |
|
| 1075 | + { |
|
| 1076 | + if (! empty($this->checkout->available_payment_methods)) { |
|
| 1077 | + return $this->checkout->available_payment_methods; |
|
| 1078 | + } |
|
| 1079 | + $available_payment_methods = array(); |
|
| 1080 | + // load EEM_Payment_Method |
|
| 1081 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 1082 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 1083 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 1084 | + // get all active payment methods |
|
| 1085 | + $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
| 1086 | + $this->checkout->transaction, |
|
| 1087 | + EEM_Payment_Method::scope_cart |
|
| 1088 | + ); |
|
| 1089 | + foreach ($payment_methods as $payment_method) { |
|
| 1090 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 1091 | + $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 1092 | + } |
|
| 1093 | + } |
|
| 1094 | + return $available_payment_methods; |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * _available_payment_method_inputs |
|
| 1100 | + * |
|
| 1101 | + * @access private |
|
| 1102 | + * @param array $available_payment_method_options |
|
| 1103 | + * @return \EE_Form_Section_Proper |
|
| 1104 | + */ |
|
| 1105 | + private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
| 1106 | + { |
|
| 1107 | + // generate inputs |
|
| 1108 | + return new EE_Form_Section_Proper( |
|
| 1109 | + array( |
|
| 1110 | + 'html_id' => 'ee-available-payment-method-inputs', |
|
| 1111 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1112 | + 'subsections' => array( |
|
| 1113 | + '' => new EE_Radio_Button_Input( |
|
| 1114 | + $available_payment_method_options, |
|
| 1115 | + array( |
|
| 1116 | + 'html_name' => 'selected_method_of_payment', |
|
| 1117 | + 'html_class' => 'spco-payment-method', |
|
| 1118 | + 'default' => $this->checkout->selected_method_of_payment, |
|
| 1119 | + 'label_size' => 11, |
|
| 1120 | + 'enforce_label_size' => true, |
|
| 1121 | + ) |
|
| 1122 | + ), |
|
| 1123 | + ), |
|
| 1124 | + ) |
|
| 1125 | + ); |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * _payment_method_billing_info |
|
| 1131 | + * |
|
| 1132 | + * @access private |
|
| 1133 | + * @param EE_Payment_Method $payment_method |
|
| 1134 | + * @return EE_Form_Section_Proper |
|
| 1135 | + * @throws EE_Error |
|
| 1136 | + * @throws InvalidArgumentException |
|
| 1137 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1138 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1139 | + */ |
|
| 1140 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
| 1141 | + { |
|
| 1142 | + $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
| 1143 | + ? true |
|
| 1144 | + : false; |
|
| 1145 | + // generate the billing form for payment method |
|
| 1146 | + $billing_form = $currently_selected |
|
| 1147 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
| 1148 | + : new EE_Form_Section_HTML(); |
|
| 1149 | + $this->checkout->billing_form = $currently_selected |
|
| 1150 | + ? $billing_form |
|
| 1151 | + : $this->checkout->billing_form; |
|
| 1152 | + // it's all in the details |
|
| 1153 | + $info_html = EEH_HTML::h3( |
|
| 1154 | + esc_html__('Important information regarding your payment', 'event_espresso'), |
|
| 1155 | + '', |
|
| 1156 | + 'spco-payment-method-hdr' |
|
| 1157 | + ); |
|
| 1158 | + // add some info regarding the step, either from what's saved in the admin, |
|
| 1159 | + // or a default string depending on whether the PM has a billing form or not |
|
| 1160 | + if ($payment_method->description()) { |
|
| 1161 | + $payment_method_info = $payment_method->description(); |
|
| 1162 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1163 | + $payment_method_info = sprintf( |
|
| 1164 | + esc_html__( |
|
| 1165 | + 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
| 1166 | + 'event_espresso' |
|
| 1167 | + ), |
|
| 1168 | + $this->submit_button_text() |
|
| 1169 | + ); |
|
| 1170 | + } else { |
|
| 1171 | + $payment_method_info = sprintf( |
|
| 1172 | + esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
| 1173 | + $this->submit_button_text() |
|
| 1174 | + ); |
|
| 1175 | + } |
|
| 1176 | + $info_html .= EEH_HTML::div( |
|
| 1177 | + apply_filters( |
|
| 1178 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
| 1179 | + $payment_method_info |
|
| 1180 | + ), |
|
| 1181 | + '', |
|
| 1182 | + 'spco-payment-method-desc ee-attention' |
|
| 1183 | + ); |
|
| 1184 | + return new EE_Form_Section_Proper( |
|
| 1185 | + array( |
|
| 1186 | + 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
| 1187 | + 'html_class' => 'spco-payment-method-info-dv', |
|
| 1188 | + // only display the selected or default PM |
|
| 1189 | + 'html_style' => $currently_selected ? '' : 'display:none;', |
|
| 1190 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1191 | + 'subsections' => array( |
|
| 1192 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
| 1193 | + 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
| 1194 | + ), |
|
| 1195 | + ) |
|
| 1196 | + ); |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + |
|
| 1200 | + /** |
|
| 1201 | + * get_billing_form_html_for_payment_method |
|
| 1202 | + * |
|
| 1203 | + * @access public |
|
| 1204 | + * @return string |
|
| 1205 | + * @throws EE_Error |
|
| 1206 | + * @throws InvalidArgumentException |
|
| 1207 | + * @throws ReflectionException |
|
| 1208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1210 | + */ |
|
| 1211 | + public function get_billing_form_html_for_payment_method() |
|
| 1212 | + { |
|
| 1213 | + // how have they chosen to pay? |
|
| 1214 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1215 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1216 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1217 | + return false; |
|
| 1218 | + } |
|
| 1219 | + if (apply_filters( |
|
| 1220 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1221 | + false |
|
| 1222 | + )) { |
|
| 1223 | + EE_Error::add_success( |
|
| 1224 | + apply_filters( |
|
| 1225 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1226 | + sprintf( |
|
| 1227 | + esc_html__( |
|
| 1228 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1229 | + 'event_espresso' |
|
| 1230 | + ), |
|
| 1231 | + $this->checkout->payment_method->name() |
|
| 1232 | + ) |
|
| 1233 | + ) |
|
| 1234 | + ); |
|
| 1235 | + } |
|
| 1236 | + // now generate billing form for selected method of payment |
|
| 1237 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
| 1238 | + // fill form with attendee info if applicable |
|
| 1239 | + if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1240 | + && $this->checkout->transaction_has_primary_registrant() |
|
| 1241 | + ) { |
|
| 1242 | + $payment_method_billing_form->populate_from_attendee( |
|
| 1243 | + $this->checkout->transaction->primary_registration()->attendee() |
|
| 1244 | + ); |
|
| 1245 | + } |
|
| 1246 | + // and debug content |
|
| 1247 | + if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
| 1248 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1249 | + ) { |
|
| 1250 | + $payment_method_billing_form = |
|
| 1251 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1252 | + $payment_method_billing_form |
|
| 1253 | + ); |
|
| 1254 | + } |
|
| 1255 | + $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
| 1256 | + ? $payment_method_billing_form->get_html() |
|
| 1257 | + : ''; |
|
| 1258 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
| 1259 | + // localize validation rules for main form |
|
| 1260 | + $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
| 1261 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1262 | + return true; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + |
|
| 1266 | + /** |
|
| 1267 | + * _get_billing_form_for_payment_method |
|
| 1268 | + * |
|
| 1269 | + * @access private |
|
| 1270 | + * @param EE_Payment_Method $payment_method |
|
| 1271 | + * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
| 1272 | + * @throws EE_Error |
|
| 1273 | + * @throws InvalidArgumentException |
|
| 1274 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1275 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1276 | + */ |
|
| 1277 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
| 1278 | + { |
|
| 1279 | + $billing_form = $payment_method->type_obj()->billing_form( |
|
| 1280 | + $this->checkout->transaction, |
|
| 1281 | + array('amount_owing' => $this->checkout->amount_owing) |
|
| 1282 | + ); |
|
| 1283 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1284 | + if (apply_filters( |
|
| 1285 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1286 | + false |
|
| 1287 | + ) |
|
| 1288 | + && EE_Registry::instance()->REQ->is_set('payment_method') |
|
| 1289 | + ) { |
|
| 1290 | + EE_Error::add_success( |
|
| 1291 | + apply_filters( |
|
| 1292 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1293 | + sprintf( |
|
| 1294 | + esc_html__( |
|
| 1295 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1296 | + 'event_espresso' |
|
| 1297 | + ), |
|
| 1298 | + $payment_method->name() |
|
| 1299 | + ) |
|
| 1300 | + ) |
|
| 1301 | + ); |
|
| 1302 | + } |
|
| 1303 | + return apply_filters( |
|
| 1304 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 1305 | + $billing_form, |
|
| 1306 | + $payment_method |
|
| 1307 | + ); |
|
| 1308 | + } |
|
| 1309 | + // no actual billing form, so return empty HTML form section |
|
| 1310 | + return new EE_Form_Section_HTML(); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + |
|
| 1314 | + /** |
|
| 1315 | + * _get_selected_method_of_payment |
|
| 1316 | + * |
|
| 1317 | + * @access private |
|
| 1318 | + * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
| 1319 | + * is not found in the incoming request |
|
| 1320 | + * @param string $request_param |
|
| 1321 | + * @return NULL|string |
|
| 1322 | + * @throws EE_Error |
|
| 1323 | + * @throws InvalidArgumentException |
|
| 1324 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1325 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1326 | + */ |
|
| 1327 | + private function _get_selected_method_of_payment( |
|
| 1328 | + $required = false, |
|
| 1329 | + $request_param = 'selected_method_of_payment' |
|
| 1330 | + ) { |
|
| 1331 | + // is selected_method_of_payment set in the request ? |
|
| 1332 | + $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
| 1333 | + if ($selected_method_of_payment) { |
|
| 1334 | + // sanitize it |
|
| 1335 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
| 1336 | + ? array_shift($selected_method_of_payment) |
|
| 1337 | + : $selected_method_of_payment; |
|
| 1338 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
| 1339 | + // store it in the session so that it's available for all subsequent requests including AJAX |
|
| 1340 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
| 1341 | + } else { |
|
| 1342 | + // or is is set in the session ? |
|
| 1343 | + $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
| 1344 | + 'selected_method_of_payment' |
|
| 1345 | + ); |
|
| 1346 | + } |
|
| 1347 | + // do ya really really gotta have it? |
|
| 1348 | + if (empty($selected_method_of_payment) && $required) { |
|
| 1349 | + EE_Error::add_error( |
|
| 1350 | + sprintf( |
|
| 1351 | + esc_html__( |
|
| 1352 | + 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
| 1353 | + 'event_espresso' |
|
| 1354 | + ), |
|
| 1355 | + '<br/>', |
|
| 1356 | + '<br/>', |
|
| 1357 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 1358 | + ), |
|
| 1359 | + __FILE__, |
|
| 1360 | + __FUNCTION__, |
|
| 1361 | + __LINE__ |
|
| 1362 | + ); |
|
| 1363 | + return null; |
|
| 1364 | + } |
|
| 1365 | + return $selected_method_of_payment; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + |
|
| 1370 | + |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + /********************************************************************************************************/ |
|
| 1374 | + /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
| 1375 | + /********************************************************************************************************/ |
|
| 1376 | + /** |
|
| 1377 | + * switch_payment_method |
|
| 1378 | + * |
|
| 1379 | + * @access public |
|
| 1380 | + * @return string |
|
| 1381 | + * @throws EE_Error |
|
| 1382 | + * @throws InvalidArgumentException |
|
| 1383 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1384 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1385 | + */ |
|
| 1386 | + public function switch_payment_method() |
|
| 1387 | + { |
|
| 1388 | + if (! $this->_verify_payment_method_is_set()) { |
|
| 1389 | + return false; |
|
| 1390 | + } |
|
| 1391 | + if (apply_filters( |
|
| 1392 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1393 | + false |
|
| 1394 | + )) { |
|
| 1395 | + EE_Error::add_success( |
|
| 1396 | + apply_filters( |
|
| 1397 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1398 | + sprintf( |
|
| 1399 | + esc_html__( |
|
| 1400 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1401 | + 'event_espresso' |
|
| 1402 | + ), |
|
| 1403 | + $this->checkout->payment_method->name() |
|
| 1404 | + ) |
|
| 1405 | + ) |
|
| 1406 | + ); |
|
| 1407 | + } |
|
| 1408 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1409 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1410 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1411 | + $this->checkout->payment_method |
|
| 1412 | + ); |
|
| 1413 | + } |
|
| 1414 | + // fill form with attendee info if applicable |
|
| 1415 | + if (apply_filters( |
|
| 1416 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 1417 | + ( |
|
| 1418 | + $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1419 | + && $this->checkout->transaction_has_primary_registrant() |
|
| 1420 | + ), |
|
| 1421 | + $this->checkout->billing_form, |
|
| 1422 | + $this->checkout->transaction |
|
| 1423 | + ) |
|
| 1424 | + ) { |
|
| 1425 | + $this->checkout->billing_form->populate_from_attendee( |
|
| 1426 | + $this->checkout->transaction->primary_registration()->attendee() |
|
| 1427 | + ); |
|
| 1428 | + } |
|
| 1429 | + // and debug content |
|
| 1430 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
| 1431 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1432 | + ) { |
|
| 1433 | + $this->checkout->billing_form = |
|
| 1434 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1435 | + $this->checkout->billing_form |
|
| 1436 | + ); |
|
| 1437 | + } |
|
| 1438 | + // get html and validation rules for form |
|
| 1439 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
| 1440 | + $this->checkout->json_response->set_return_data( |
|
| 1441 | + array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
| 1442 | + ); |
|
| 1443 | + // localize validation rules for main form |
|
| 1444 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
| 1445 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1446 | + } else { |
|
| 1447 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
| 1448 | + } |
|
| 1449 | + // prevents advancement to next step |
|
| 1450 | + $this->checkout->continue_reg = false; |
|
| 1451 | + return true; |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + |
|
| 1455 | + /** |
|
| 1456 | + * _verify_payment_method_is_set |
|
| 1457 | + * |
|
| 1458 | + * @return bool |
|
| 1459 | + * @throws EE_Error |
|
| 1460 | + * @throws InvalidArgumentException |
|
| 1461 | + * @throws ReflectionException |
|
| 1462 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1463 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1464 | + */ |
|
| 1465 | + protected function _verify_payment_method_is_set() |
|
| 1466 | + { |
|
| 1467 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1468 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1469 | + // how have they chosen to pay? |
|
| 1470 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1471 | + } else { |
|
| 1472 | + // choose your own adventure based on method_of_payment |
|
| 1473 | + switch ($this->checkout->selected_method_of_payment) { |
|
| 1474 | + case 'events_sold_out': |
|
| 1475 | + EE_Error::add_attention( |
|
| 1476 | + apply_filters( |
|
| 1477 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
| 1478 | + esc_html__( |
|
| 1479 | + 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
| 1480 | + 'event_espresso' |
|
| 1481 | + ) |
|
| 1482 | + ), |
|
| 1483 | + __FILE__, |
|
| 1484 | + __FUNCTION__, |
|
| 1485 | + __LINE__ |
|
| 1486 | + ); |
|
| 1487 | + return false; |
|
| 1488 | + break; |
|
| 1489 | + case 'payments_closed': |
|
| 1490 | + EE_Error::add_attention( |
|
| 1491 | + apply_filters( |
|
| 1492 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
| 1493 | + esc_html__( |
|
| 1494 | + 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
| 1495 | + 'event_espresso' |
|
| 1496 | + ) |
|
| 1497 | + ), |
|
| 1498 | + __FILE__, |
|
| 1499 | + __FUNCTION__, |
|
| 1500 | + __LINE__ |
|
| 1501 | + ); |
|
| 1502 | + return false; |
|
| 1503 | + break; |
|
| 1504 | + case 'no_payment_required': |
|
| 1505 | + EE_Error::add_attention( |
|
| 1506 | + apply_filters( |
|
| 1507 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
| 1508 | + esc_html__( |
|
| 1509 | + 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
| 1510 | + 'event_espresso' |
|
| 1511 | + ) |
|
| 1512 | + ), |
|
| 1513 | + __FILE__, |
|
| 1514 | + __FUNCTION__, |
|
| 1515 | + __LINE__ |
|
| 1516 | + ); |
|
| 1517 | + return false; |
|
| 1518 | + break; |
|
| 1519 | + default: |
|
| 1520 | + } |
|
| 1521 | + } |
|
| 1522 | + // verify payment method |
|
| 1523 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1524 | + // get payment method for selected method of payment |
|
| 1525 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1526 | + } |
|
| 1527 | + return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + |
|
| 1531 | + |
|
| 1532 | + /********************************************************************************************************/ |
|
| 1533 | + /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
| 1534 | + /********************************************************************************************************/ |
|
| 1535 | + /** |
|
| 1536 | + * save_payer_details_via_ajax |
|
| 1537 | + * |
|
| 1538 | + * @return void |
|
| 1539 | + * @throws EE_Error |
|
| 1540 | + * @throws InvalidArgumentException |
|
| 1541 | + * @throws ReflectionException |
|
| 1542 | + * @throws RuntimeException |
|
| 1543 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1544 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1545 | + */ |
|
| 1546 | + public function save_payer_details_via_ajax() |
|
| 1547 | + { |
|
| 1548 | + if (! $this->_verify_payment_method_is_set()) { |
|
| 1549 | + return; |
|
| 1550 | + } |
|
| 1551 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1552 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1553 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1554 | + $this->checkout->payment_method |
|
| 1555 | + ); |
|
| 1556 | + } |
|
| 1557 | + // generate primary attendee from payer info if applicable |
|
| 1558 | + if (! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1559 | + $attendee = $this->_create_attendee_from_request_data(); |
|
| 1560 | + if ($attendee instanceof EE_Attendee) { |
|
| 1561 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
| 1562 | + if ($registration->is_primary_registrant()) { |
|
| 1563 | + $this->checkout->primary_attendee_obj = $attendee; |
|
| 1564 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1565 | + $registration->set_attendee_id($attendee->ID()); |
|
| 1566 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1567 | + } |
|
| 1568 | + } |
|
| 1569 | + } |
|
| 1570 | + } |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + |
|
| 1574 | + /** |
|
| 1575 | + * create_attendee_from_request_data |
|
| 1576 | + * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
| 1577 | + * |
|
| 1578 | + * @return EE_Attendee |
|
| 1579 | + * @throws EE_Error |
|
| 1580 | + * @throws InvalidArgumentException |
|
| 1581 | + * @throws ReflectionException |
|
| 1582 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1583 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1584 | + */ |
|
| 1585 | + protected function _create_attendee_from_request_data() |
|
| 1586 | + { |
|
| 1587 | + // get State ID |
|
| 1588 | + $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
| 1589 | + if (! empty($STA_ID)) { |
|
| 1590 | + // can we get state object from name ? |
|
| 1591 | + EE_Registry::instance()->load_model('State'); |
|
| 1592 | + $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
| 1593 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
| 1594 | + } |
|
| 1595 | + // get Country ISO |
|
| 1596 | + $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
| 1597 | + if (! empty($CNT_ISO)) { |
|
| 1598 | + // can we get country object from name ? |
|
| 1599 | + EE_Registry::instance()->load_model('Country'); |
|
| 1600 | + $country = EEM_Country::instance()->get_col( |
|
| 1601 | + array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
| 1602 | + 'CNT_ISO' |
|
| 1603 | + ); |
|
| 1604 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
| 1605 | + } |
|
| 1606 | + // grab attendee data |
|
| 1607 | + $attendee_data = array( |
|
| 1608 | + 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
| 1609 | + 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
| 1610 | + 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
| 1611 | + 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
| 1612 | + 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
| 1613 | + 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
| 1614 | + 'STA_ID' => $STA_ID, |
|
| 1615 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1616 | + 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
| 1617 | + 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
| 1618 | + ); |
|
| 1619 | + // validate the email address since it is the most important piece of info |
|
| 1620 | + if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
| 1621 | + EE_Error::add_error( |
|
| 1622 | + esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
| 1623 | + __FILE__, |
|
| 1624 | + __FUNCTION__, |
|
| 1625 | + __LINE__ |
|
| 1626 | + ); |
|
| 1627 | + } |
|
| 1628 | + // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
| 1629 | + // AND email address |
|
| 1630 | + if (! empty($attendee_data['ATT_fname']) |
|
| 1631 | + && ! empty($attendee_data['ATT_lname']) |
|
| 1632 | + && ! empty($attendee_data['ATT_email']) |
|
| 1633 | + ) { |
|
| 1634 | + $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
| 1635 | + array( |
|
| 1636 | + 'ATT_fname' => $attendee_data['ATT_fname'], |
|
| 1637 | + 'ATT_lname' => $attendee_data['ATT_lname'], |
|
| 1638 | + 'ATT_email' => $attendee_data['ATT_email'], |
|
| 1639 | + ) |
|
| 1640 | + ); |
|
| 1641 | + if ($existing_attendee instanceof EE_Attendee) { |
|
| 1642 | + return $existing_attendee; |
|
| 1643 | + } |
|
| 1644 | + } |
|
| 1645 | + // no existing attendee? kk let's create a new one |
|
| 1646 | + // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
| 1647 | + // don't exist |
|
| 1648 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
| 1649 | + ? $attendee_data['ATT_fname'] |
|
| 1650 | + : $attendee_data['ATT_email']; |
|
| 1651 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
| 1652 | + ? $attendee_data['ATT_lname'] |
|
| 1653 | + : $attendee_data['ATT_email']; |
|
| 1654 | + return EE_Attendee::new_instance($attendee_data); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + |
|
| 1658 | + |
|
| 1659 | + /********************************************************************************************************/ |
|
| 1660 | + /**************************************** PROCESS REG STEP *****************************************/ |
|
| 1661 | + /********************************************************************************************************/ |
|
| 1662 | + /** |
|
| 1663 | + * process_reg_step |
|
| 1664 | + * |
|
| 1665 | + * @return bool |
|
| 1666 | + * @throws EE_Error |
|
| 1667 | + * @throws InvalidArgumentException |
|
| 1668 | + * @throws ReflectionException |
|
| 1669 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1670 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1671 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1672 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1673 | + */ |
|
| 1674 | + public function process_reg_step() |
|
| 1675 | + { |
|
| 1676 | + // how have they chosen to pay? |
|
| 1677 | + $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
| 1678 | + ? 'no_payment_required' |
|
| 1679 | + : $this->_get_selected_method_of_payment(true); |
|
| 1680 | + // choose your own adventure based on method_of_payment |
|
| 1681 | + switch ($this->checkout->selected_method_of_payment) { |
|
| 1682 | + case 'events_sold_out': |
|
| 1683 | + $this->checkout->redirect = true; |
|
| 1684 | + $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
| 1685 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1686 | + // mark this reg step as completed |
|
| 1687 | + $this->set_completed(); |
|
| 1688 | + return false; |
|
| 1689 | + break; |
|
| 1690 | + |
|
| 1691 | + case 'payments_closed': |
|
| 1692 | + if (apply_filters( |
|
| 1693 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
| 1694 | + false |
|
| 1695 | + )) { |
|
| 1696 | + EE_Error::add_success( |
|
| 1697 | + esc_html__('no payment required at this time.', 'event_espresso'), |
|
| 1698 | + __FILE__, |
|
| 1699 | + __FUNCTION__, |
|
| 1700 | + __LINE__ |
|
| 1701 | + ); |
|
| 1702 | + } |
|
| 1703 | + // mark this reg step as completed |
|
| 1704 | + $this->set_completed(); |
|
| 1705 | + return true; |
|
| 1706 | + break; |
|
| 1707 | + |
|
| 1708 | + case 'no_payment_required': |
|
| 1709 | + if (apply_filters( |
|
| 1710 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
| 1711 | + false |
|
| 1712 | + )) { |
|
| 1713 | + EE_Error::add_success( |
|
| 1714 | + esc_html__('no payment required.', 'event_espresso'), |
|
| 1715 | + __FILE__, |
|
| 1716 | + __FUNCTION__, |
|
| 1717 | + __LINE__ |
|
| 1718 | + ); |
|
| 1719 | + } |
|
| 1720 | + // mark this reg step as completed |
|
| 1721 | + $this->set_completed(); |
|
| 1722 | + return true; |
|
| 1723 | + break; |
|
| 1724 | + |
|
| 1725 | + default: |
|
| 1726 | + $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 1727 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 1728 | + ); |
|
| 1729 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 1730 | + $registrations, |
|
| 1731 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
| 1732 | + ); |
|
| 1733 | + // calculate difference between the two arrays |
|
| 1734 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
| 1735 | + if (empty($registrations)) { |
|
| 1736 | + $this->_redirect_because_event_sold_out(); |
|
| 1737 | + return false; |
|
| 1738 | + } |
|
| 1739 | + $payment_successful = $this->_process_payment(); |
|
| 1740 | + if ($payment_successful) { |
|
| 1741 | + $this->checkout->continue_reg = true; |
|
| 1742 | + $this->_maybe_set_completed($this->checkout->payment_method); |
|
| 1743 | + } else { |
|
| 1744 | + $this->checkout->continue_reg = false; |
|
| 1745 | + } |
|
| 1746 | + return $payment_successful; |
|
| 1747 | + } |
|
| 1748 | + } |
|
| 1749 | + |
|
| 1750 | + |
|
| 1751 | + /** |
|
| 1752 | + * _redirect_because_event_sold_out |
|
| 1753 | + * |
|
| 1754 | + * @access protected |
|
| 1755 | + * @return void |
|
| 1756 | + */ |
|
| 1757 | + protected function _redirect_because_event_sold_out() |
|
| 1758 | + { |
|
| 1759 | + $this->checkout->continue_reg = false; |
|
| 1760 | + // set redirect URL |
|
| 1761 | + $this->checkout->redirect_url = add_query_arg( |
|
| 1762 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1763 | + $this->checkout->current_step->reg_step_url() |
|
| 1764 | + ); |
|
| 1765 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1766 | + } |
|
| 1767 | + |
|
| 1768 | + |
|
| 1769 | + /** |
|
| 1770 | + * _maybe_set_completed |
|
| 1771 | + * |
|
| 1772 | + * @access protected |
|
| 1773 | + * @param \EE_Payment_Method $payment_method |
|
| 1774 | + * @return void |
|
| 1775 | + * @throws \EE_Error |
|
| 1776 | + */ |
|
| 1777 | + protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
| 1778 | + { |
|
| 1779 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 1780 | + case EE_PMT_Base::offsite: |
|
| 1781 | + break; |
|
| 1782 | + case EE_PMT_Base::onsite: |
|
| 1783 | + case EE_PMT_Base::offline: |
|
| 1784 | + // mark this reg step as completed |
|
| 1785 | + $this->set_completed(); |
|
| 1786 | + break; |
|
| 1787 | + } |
|
| 1788 | + } |
|
| 1789 | + |
|
| 1790 | + |
|
| 1791 | + /** |
|
| 1792 | + * update_reg_step |
|
| 1793 | + * this is the final step after a user revisits the site to retry a payment |
|
| 1794 | + * |
|
| 1795 | + * @return bool |
|
| 1796 | + * @throws EE_Error |
|
| 1797 | + * @throws InvalidArgumentException |
|
| 1798 | + * @throws ReflectionException |
|
| 1799 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1800 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1801 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1802 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1803 | + */ |
|
| 1804 | + public function update_reg_step() |
|
| 1805 | + { |
|
| 1806 | + $success = true; |
|
| 1807 | + // if payment required |
|
| 1808 | + if ($this->checkout->transaction->total() > 0) { |
|
| 1809 | + do_action( |
|
| 1810 | + 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
| 1811 | + $this->checkout->transaction |
|
| 1812 | + ); |
|
| 1813 | + // attempt payment via payment method |
|
| 1814 | + $success = $this->process_reg_step(); |
|
| 1815 | + } |
|
| 1816 | + if ($success && ! $this->checkout->redirect) { |
|
| 1817 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
| 1818 | + $this->checkout->transaction->ID() |
|
| 1819 | + ); |
|
| 1820 | + // set return URL |
|
| 1821 | + $this->checkout->redirect_url = add_query_arg( |
|
| 1822 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1823 | + $this->checkout->thank_you_page_url |
|
| 1824 | + ); |
|
| 1825 | + } |
|
| 1826 | + return $success; |
|
| 1827 | + } |
|
| 1828 | + |
|
| 1829 | + |
|
| 1830 | + /** |
|
| 1831 | + * _process_payment |
|
| 1832 | + * |
|
| 1833 | + * @access private |
|
| 1834 | + * @return bool |
|
| 1835 | + * @throws EE_Error |
|
| 1836 | + * @throws InvalidArgumentException |
|
| 1837 | + * @throws ReflectionException |
|
| 1838 | + * @throws RuntimeException |
|
| 1839 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1840 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1841 | + */ |
|
| 1842 | + private function _process_payment() |
|
| 1843 | + { |
|
| 1844 | + // basically confirm that the event hasn't sold out since they hit the page |
|
| 1845 | + if (! $this->_last_second_ticket_verifications()) { |
|
| 1846 | + return false; |
|
| 1847 | + } |
|
| 1848 | + // ya gotta make a choice man |
|
| 1849 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1850 | + $this->checkout->json_response->set_plz_select_method_of_payment( |
|
| 1851 | + esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
| 1852 | + ); |
|
| 1853 | + return false; |
|
| 1854 | + } |
|
| 1855 | + // get EE_Payment_Method object |
|
| 1856 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1857 | + return false; |
|
| 1858 | + } |
|
| 1859 | + // setup billing form |
|
| 1860 | + if ($this->checkout->payment_method->is_on_site()) { |
|
| 1861 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1862 | + $this->checkout->payment_method |
|
| 1863 | + ); |
|
| 1864 | + // bad billing form ? |
|
| 1865 | + if (! $this->_billing_form_is_valid()) { |
|
| 1866 | + return false; |
|
| 1867 | + } |
|
| 1868 | + } |
|
| 1869 | + // ensure primary registrant has been fully processed |
|
| 1870 | + if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1871 | + return false; |
|
| 1872 | + } |
|
| 1873 | + // if session is close to expiring (under 10 minutes by default) |
|
| 1874 | + if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
| 1875 | + // add some time to session expiration so that payment can be completed |
|
| 1876 | + EE_Registry::instance()->SSN->extend_expiration(); |
|
| 1877 | + } |
|
| 1878 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1879 | + // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 1880 | + // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
| 1881 | + // for events with a default reg status of Approved |
|
| 1882 | + // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
| 1883 | + // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
| 1884 | + // ); |
|
| 1885 | + // attempt payment |
|
| 1886 | + $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
| 1887 | + // process results |
|
| 1888 | + $payment = $this->_validate_payment($payment); |
|
| 1889 | + $payment = $this->_post_payment_processing($payment); |
|
| 1890 | + // verify payment |
|
| 1891 | + if ($payment instanceof EE_Payment) { |
|
| 1892 | + // store that for later |
|
| 1893 | + $this->checkout->payment = $payment; |
|
| 1894 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
| 1895 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1896 | + $payment_status = $payment->status(); |
|
| 1897 | + if ($payment_status === EEM_Payment::status_id_approved |
|
| 1898 | + || $payment_status === EEM_Payment::status_id_pending |
|
| 1899 | + ) { |
|
| 1900 | + return true; |
|
| 1901 | + } else { |
|
| 1902 | + return false; |
|
| 1903 | + } |
|
| 1904 | + } elseif ($payment === true) { |
|
| 1905 | + // please note that offline payment methods will NOT make a payment, |
|
| 1906 | + // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
| 1907 | + $this->checkout->payment = $payment; |
|
| 1908 | + return true; |
|
| 1909 | + } |
|
| 1910 | + // where's my money? |
|
| 1911 | + return false; |
|
| 1912 | + } |
|
| 1913 | + |
|
| 1914 | + |
|
| 1915 | + /** |
|
| 1916 | + * _last_second_ticket_verifications |
|
| 1917 | + * |
|
| 1918 | + * @access public |
|
| 1919 | + * @return bool |
|
| 1920 | + * @throws EE_Error |
|
| 1921 | + */ |
|
| 1922 | + protected function _last_second_ticket_verifications() |
|
| 1923 | + { |
|
| 1924 | + // don't bother re-validating if not a return visit |
|
| 1925 | + if (! $this->checkout->revisit) { |
|
| 1926 | + return true; |
|
| 1927 | + } |
|
| 1928 | + $registrations = $this->checkout->transaction->registrations(); |
|
| 1929 | + if (empty($registrations)) { |
|
| 1930 | + return false; |
|
| 1931 | + } |
|
| 1932 | + foreach ($registrations as $registration) { |
|
| 1933 | + if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
| 1934 | + $event = $registration->event_obj(); |
|
| 1935 | + if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
| 1936 | + EE_Error::add_error( |
|
| 1937 | + apply_filters( |
|
| 1938 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
| 1939 | + sprintf( |
|
| 1940 | + esc_html__( |
|
| 1941 | + 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 1942 | + 'event_espresso' |
|
| 1943 | + ), |
|
| 1944 | + $event->name() |
|
| 1945 | + ) |
|
| 1946 | + ), |
|
| 1947 | + __FILE__, |
|
| 1948 | + __FUNCTION__, |
|
| 1949 | + __LINE__ |
|
| 1950 | + ); |
|
| 1951 | + return false; |
|
| 1952 | + } |
|
| 1953 | + } |
|
| 1954 | + } |
|
| 1955 | + return true; |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + |
|
| 1959 | + /** |
|
| 1960 | + * redirect_form |
|
| 1961 | + * |
|
| 1962 | + * @access public |
|
| 1963 | + * @return bool |
|
| 1964 | + * @throws EE_Error |
|
| 1965 | + * @throws InvalidArgumentException |
|
| 1966 | + * @throws ReflectionException |
|
| 1967 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1968 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1969 | + */ |
|
| 1970 | + public function redirect_form() |
|
| 1971 | + { |
|
| 1972 | + $payment_method_billing_info = $this->_payment_method_billing_info( |
|
| 1973 | + $this->_get_payment_method_for_selected_method_of_payment() |
|
| 1974 | + ); |
|
| 1975 | + $html = $payment_method_billing_info->get_html(); |
|
| 1976 | + $html .= $this->checkout->redirect_form; |
|
| 1977 | + EE_Registry::instance()->REQ->add_output($html); |
|
| 1978 | + return true; |
|
| 1979 | + } |
|
| 1980 | + |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * _billing_form_is_valid |
|
| 1984 | + * |
|
| 1985 | + * @access private |
|
| 1986 | + * @return bool |
|
| 1987 | + * @throws \EE_Error |
|
| 1988 | + */ |
|
| 1989 | + private function _billing_form_is_valid() |
|
| 1990 | + { |
|
| 1991 | + if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1992 | + return true; |
|
| 1993 | + } |
|
| 1994 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
| 1995 | + if ($this->checkout->billing_form->was_submitted()) { |
|
| 1996 | + $this->checkout->billing_form->receive_form_submission(); |
|
| 1997 | + if ($this->checkout->billing_form->is_valid()) { |
|
| 1998 | + return true; |
|
| 1999 | + } |
|
| 2000 | + $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
| 2001 | + $error_strings = array(); |
|
| 2002 | + foreach ($validation_errors as $validation_error) { |
|
| 2003 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 2004 | + $form_section = $validation_error->get_form_section(); |
|
| 2005 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
| 2006 | + $label = $form_section->html_label_text(); |
|
| 2007 | + } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
| 2008 | + $label = $form_section->name(); |
|
| 2009 | + } else { |
|
| 2010 | + $label = esc_html__('Validation Error', 'event_espresso'); |
|
| 2011 | + } |
|
| 2012 | + $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
| 2013 | + } |
|
| 2014 | + } |
|
| 2015 | + EE_Error::add_error( |
|
| 2016 | + sprintf( |
|
| 2017 | + esc_html__( |
|
| 2018 | + 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
| 2019 | + 'event_espresso' |
|
| 2020 | + ), |
|
| 2021 | + '<br/>', |
|
| 2022 | + implode('<br/>', $error_strings) |
|
| 2023 | + ), |
|
| 2024 | + __FILE__, |
|
| 2025 | + __FUNCTION__, |
|
| 2026 | + __LINE__ |
|
| 2027 | + ); |
|
| 2028 | + } else { |
|
| 2029 | + EE_Error::add_error( |
|
| 2030 | + esc_html__( |
|
| 2031 | + 'The billing form was not submitted or something prevented it\'s submission.', |
|
| 2032 | + 'event_espresso' |
|
| 2033 | + ), |
|
| 2034 | + __FILE__, |
|
| 2035 | + __FUNCTION__, |
|
| 2036 | + __LINE__ |
|
| 2037 | + ); |
|
| 2038 | + } |
|
| 2039 | + } else { |
|
| 2040 | + EE_Error::add_error( |
|
| 2041 | + esc_html__( |
|
| 2042 | + 'The submitted billing form is invalid possibly due to a technical reason.', |
|
| 2043 | + 'event_espresso' |
|
| 2044 | + ), |
|
| 2045 | + __FILE__, |
|
| 2046 | + __FUNCTION__, |
|
| 2047 | + __LINE__ |
|
| 2048 | + ); |
|
| 2049 | + } |
|
| 2050 | + return false; |
|
| 2051 | + } |
|
| 2052 | + |
|
| 2053 | + |
|
| 2054 | + /** |
|
| 2055 | + * _setup_primary_registrant_prior_to_payment |
|
| 2056 | + * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
| 2057 | + * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
| 2058 | + * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
| 2059 | + * yet) |
|
| 2060 | + * |
|
| 2061 | + * @access private |
|
| 2062 | + * @return bool |
|
| 2063 | + * @throws EE_Error |
|
| 2064 | + * @throws InvalidArgumentException |
|
| 2065 | + * @throws ReflectionException |
|
| 2066 | + * @throws RuntimeException |
|
| 2067 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2068 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2069 | + */ |
|
| 2070 | + private function _setup_primary_registrant_prior_to_payment() |
|
| 2071 | + { |
|
| 2072 | + // check if transaction has a primary registrant and that it has a related Attendee object |
|
| 2073 | + // if not, then we need to at least gather some primary registrant data before attempting payment |
|
| 2074 | + if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 2075 | + && ! $this->checkout->transaction_has_primary_registrant() |
|
| 2076 | + && ! $this->_capture_primary_registration_data_from_billing_form() |
|
| 2077 | + ) { |
|
| 2078 | + return false; |
|
| 2079 | + } |
|
| 2080 | + // because saving an object clears it's cache, we need to do the chevy shuffle |
|
| 2081 | + // grab the primary_registration object |
|
| 2082 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2083 | + // at this point we'll consider a TXN to not have been failed |
|
| 2084 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 2085 | + // save the TXN ( which clears cached copy of primary_registration) |
|
| 2086 | + $this->checkout->transaction->save(); |
|
| 2087 | + // grab TXN ID and save it to the primary_registration |
|
| 2088 | + $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
| 2089 | + // save what we have so far |
|
| 2090 | + $primary_registration->save(); |
|
| 2091 | + return true; |
|
| 2092 | + } |
|
| 2093 | + |
|
| 2094 | + |
|
| 2095 | + /** |
|
| 2096 | + * _capture_primary_registration_data_from_billing_form |
|
| 2097 | + * |
|
| 2098 | + * @access private |
|
| 2099 | + * @return bool |
|
| 2100 | + * @throws EE_Error |
|
| 2101 | + * @throws InvalidArgumentException |
|
| 2102 | + * @throws ReflectionException |
|
| 2103 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2104 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2105 | + */ |
|
| 2106 | + private function _capture_primary_registration_data_from_billing_form() |
|
| 2107 | + { |
|
| 2108 | + // convert billing form data into an attendee |
|
| 2109 | + $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
| 2110 | + if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2111 | + EE_Error::add_error( |
|
| 2112 | + sprintf( |
|
| 2113 | + esc_html__( |
|
| 2114 | + 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2115 | + 'event_espresso' |
|
| 2116 | + ), |
|
| 2117 | + '<br/>', |
|
| 2118 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2119 | + ), |
|
| 2120 | + __FILE__, |
|
| 2121 | + __FUNCTION__, |
|
| 2122 | + __LINE__ |
|
| 2123 | + ); |
|
| 2124 | + return false; |
|
| 2125 | + } |
|
| 2126 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2127 | + if (! $primary_registration instanceof EE_Registration) { |
|
| 2128 | + EE_Error::add_error( |
|
| 2129 | + sprintf( |
|
| 2130 | + esc_html__( |
|
| 2131 | + 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2132 | + 'event_espresso' |
|
| 2133 | + ), |
|
| 2134 | + '<br/>', |
|
| 2135 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2136 | + ), |
|
| 2137 | + __FILE__, |
|
| 2138 | + __FUNCTION__, |
|
| 2139 | + __LINE__ |
|
| 2140 | + ); |
|
| 2141 | + return false; |
|
| 2142 | + } |
|
| 2143 | + if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2144 | + instanceof |
|
| 2145 | + EE_Attendee |
|
| 2146 | + ) { |
|
| 2147 | + EE_Error::add_error( |
|
| 2148 | + sprintf( |
|
| 2149 | + esc_html__( |
|
| 2150 | + 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2151 | + 'event_espresso' |
|
| 2152 | + ), |
|
| 2153 | + '<br/>', |
|
| 2154 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2155 | + ), |
|
| 2156 | + __FILE__, |
|
| 2157 | + __FUNCTION__, |
|
| 2158 | + __LINE__ |
|
| 2159 | + ); |
|
| 2160 | + return false; |
|
| 2161 | + } |
|
| 2162 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 2163 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 2164 | + // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
| 2165 | + $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
| 2166 | + return true; |
|
| 2167 | + } |
|
| 2168 | + |
|
| 2169 | + |
|
| 2170 | + /** |
|
| 2171 | + * _get_payment_method_for_selected_method_of_payment |
|
| 2172 | + * retrieves a valid payment method |
|
| 2173 | + * |
|
| 2174 | + * @access public |
|
| 2175 | + * @return EE_Payment_Method |
|
| 2176 | + * @throws EE_Error |
|
| 2177 | + * @throws InvalidArgumentException |
|
| 2178 | + * @throws ReflectionException |
|
| 2179 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2180 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2181 | + */ |
|
| 2182 | + private function _get_payment_method_for_selected_method_of_payment() |
|
| 2183 | + { |
|
| 2184 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
| 2185 | + $this->_redirect_because_event_sold_out(); |
|
| 2186 | + return null; |
|
| 2187 | + } |
|
| 2188 | + // get EE_Payment_Method object |
|
| 2189 | + if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
| 2190 | + $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
| 2191 | + } else { |
|
| 2192 | + // load EEM_Payment_Method |
|
| 2193 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 2194 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 2195 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 2196 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
| 2197 | + } |
|
| 2198 | + // verify $payment_method |
|
| 2199 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
| 2200 | + // not a payment |
|
| 2201 | + EE_Error::add_error( |
|
| 2202 | + sprintf( |
|
| 2203 | + esc_html__( |
|
| 2204 | + 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2205 | + 'event_espresso' |
|
| 2206 | + ), |
|
| 2207 | + '<br/>', |
|
| 2208 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2209 | + ), |
|
| 2210 | + __FILE__, |
|
| 2211 | + __FUNCTION__, |
|
| 2212 | + __LINE__ |
|
| 2213 | + ); |
|
| 2214 | + return null; |
|
| 2215 | + } |
|
| 2216 | + // and verify it has a valid Payment_Method Type object |
|
| 2217 | + if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2218 | + // not a payment |
|
| 2219 | + EE_Error::add_error( |
|
| 2220 | + sprintf( |
|
| 2221 | + esc_html__( |
|
| 2222 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2223 | + 'event_espresso' |
|
| 2224 | + ), |
|
| 2225 | + '<br/>', |
|
| 2226 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2227 | + ), |
|
| 2228 | + __FILE__, |
|
| 2229 | + __FUNCTION__, |
|
| 2230 | + __LINE__ |
|
| 2231 | + ); |
|
| 2232 | + return null; |
|
| 2233 | + } |
|
| 2234 | + return $payment_method; |
|
| 2235 | + } |
|
| 2236 | + |
|
| 2237 | + |
|
| 2238 | + /** |
|
| 2239 | + * _attempt_payment |
|
| 2240 | + * |
|
| 2241 | + * @access private |
|
| 2242 | + * @type EE_Payment_Method $payment_method |
|
| 2243 | + * @return mixed EE_Payment | boolean |
|
| 2244 | + * @throws EE_Error |
|
| 2245 | + * @throws InvalidArgumentException |
|
| 2246 | + * @throws ReflectionException |
|
| 2247 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2248 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2249 | + */ |
|
| 2250 | + private function _attempt_payment(EE_Payment_Method $payment_method) |
|
| 2251 | + { |
|
| 2252 | + $payment = null; |
|
| 2253 | + $this->checkout->transaction->save(); |
|
| 2254 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2255 | + if (! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2256 | + return false; |
|
| 2257 | + } |
|
| 2258 | + try { |
|
| 2259 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
| 2260 | + // generate payment object |
|
| 2261 | + $payment = $payment_processor->process_payment( |
|
| 2262 | + $payment_method, |
|
| 2263 | + $this->checkout->transaction, |
|
| 2264 | + $this->checkout->amount_owing, |
|
| 2265 | + $this->checkout->billing_form, |
|
| 2266 | + $this->_get_return_url($payment_method), |
|
| 2267 | + 'CART', |
|
| 2268 | + $this->checkout->admin_request, |
|
| 2269 | + true, |
|
| 2270 | + $this->reg_step_url() |
|
| 2271 | + ); |
|
| 2272 | + } catch (Exception $e) { |
|
| 2273 | + $this->_handle_payment_processor_exception($e); |
|
| 2274 | + } |
|
| 2275 | + return $payment; |
|
| 2276 | + } |
|
| 2277 | + |
|
| 2278 | + |
|
| 2279 | + /** |
|
| 2280 | + * _handle_payment_processor_exception |
|
| 2281 | + * |
|
| 2282 | + * @access protected |
|
| 2283 | + * @param \Exception $e |
|
| 2284 | + * @return void |
|
| 2285 | + * @throws EE_Error |
|
| 2286 | + * @throws InvalidArgumentException |
|
| 2287 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2288 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2289 | + */ |
|
| 2290 | + protected function _handle_payment_processor_exception(Exception $e) |
|
| 2291 | + { |
|
| 2292 | + EE_Error::add_error( |
|
| 2293 | + sprintf( |
|
| 2294 | + esc_html__( |
|
| 2295 | + 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
| 2296 | + 'event_espresso' |
|
| 2297 | + ), |
|
| 2298 | + '<br/>', |
|
| 2299 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
| 2300 | + $e->getMessage(), |
|
| 2301 | + $e->getFile(), |
|
| 2302 | + $e->getLine() |
|
| 2303 | + ), |
|
| 2304 | + __FILE__, |
|
| 2305 | + __FUNCTION__, |
|
| 2306 | + __LINE__ |
|
| 2307 | + ); |
|
| 2308 | + } |
|
| 2309 | + |
|
| 2310 | + |
|
| 2311 | + /** |
|
| 2312 | + * _get_return_url |
|
| 2313 | + * |
|
| 2314 | + * @access protected |
|
| 2315 | + * @param \EE_Payment_Method $payment_method |
|
| 2316 | + * @return string |
|
| 2317 | + * @throws \EE_Error |
|
| 2318 | + */ |
|
| 2319 | + protected function _get_return_url(EE_Payment_Method $payment_method) |
|
| 2320 | + { |
|
| 2321 | + $return_url = ''; |
|
| 2322 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 2323 | + case EE_PMT_Base::offsite: |
|
| 2324 | + $return_url = add_query_arg( |
|
| 2325 | + array( |
|
| 2326 | + 'action' => 'process_gateway_response', |
|
| 2327 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2328 | + 'spco_txn' => $this->checkout->transaction->ID(), |
|
| 2329 | + ), |
|
| 2330 | + $this->reg_step_url() |
|
| 2331 | + ); |
|
| 2332 | + break; |
|
| 2333 | + case EE_PMT_Base::onsite: |
|
| 2334 | + case EE_PMT_Base::offline: |
|
| 2335 | + $return_url = $this->checkout->next_step->reg_step_url(); |
|
| 2336 | + break; |
|
| 2337 | + } |
|
| 2338 | + return $return_url; |
|
| 2339 | + } |
|
| 2340 | + |
|
| 2341 | + |
|
| 2342 | + /** |
|
| 2343 | + * _validate_payment |
|
| 2344 | + * |
|
| 2345 | + * @access private |
|
| 2346 | + * @param EE_Payment $payment |
|
| 2347 | + * @return EE_Payment|FALSE |
|
| 2348 | + * @throws EE_Error |
|
| 2349 | + * @throws InvalidArgumentException |
|
| 2350 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2351 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2352 | + */ |
|
| 2353 | + private function _validate_payment($payment = null) |
|
| 2354 | + { |
|
| 2355 | + if ($this->checkout->payment_method->is_off_line()) { |
|
| 2356 | + return true; |
|
| 2357 | + } |
|
| 2358 | + // verify payment object |
|
| 2359 | + if (! $payment instanceof EE_Payment) { |
|
| 2360 | + // not a payment |
|
| 2361 | + EE_Error::add_error( |
|
| 2362 | + sprintf( |
|
| 2363 | + esc_html__( |
|
| 2364 | + 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2365 | + 'event_espresso' |
|
| 2366 | + ), |
|
| 2367 | + '<br/>', |
|
| 2368 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2369 | + ), |
|
| 2370 | + __FILE__, |
|
| 2371 | + __FUNCTION__, |
|
| 2372 | + __LINE__ |
|
| 2373 | + ); |
|
| 2374 | + return false; |
|
| 2375 | + } |
|
| 2376 | + return $payment; |
|
| 2377 | + } |
|
| 2378 | + |
|
| 2379 | + |
|
| 2380 | + /** |
|
| 2381 | + * _post_payment_processing |
|
| 2382 | + * |
|
| 2383 | + * @access private |
|
| 2384 | + * @param EE_Payment|bool $payment |
|
| 2385 | + * @return bool |
|
| 2386 | + * @throws EE_Error |
|
| 2387 | + * @throws InvalidArgumentException |
|
| 2388 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2389 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2390 | + */ |
|
| 2391 | + private function _post_payment_processing($payment = null) |
|
| 2392 | + { |
|
| 2393 | + // Off-Line payment? |
|
| 2394 | + if ($payment === true) { |
|
| 2395 | + // $this->_setup_redirect_for_next_step(); |
|
| 2396 | + return true; |
|
| 2397 | + // On-Site payment? |
|
| 2398 | + } elseif ($this->checkout->payment_method->is_on_site()) { |
|
| 2399 | + if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2400 | + // $this->_setup_redirect_for_next_step(); |
|
| 2401 | + $this->checkout->continue_reg = false; |
|
| 2402 | + } |
|
| 2403 | + // Off-Site payment? |
|
| 2404 | + } elseif ($this->checkout->payment_method->is_off_site()) { |
|
| 2405 | + // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
| 2406 | + if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
| 2407 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
| 2408 | + $this->checkout->redirect = true; |
|
| 2409 | + $this->checkout->redirect_form = $payment->redirect_form(); |
|
| 2410 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
| 2411 | + // set JSON response |
|
| 2412 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
| 2413 | + // and lastly, let's bump the payment status to pending |
|
| 2414 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
| 2415 | + $payment->save(); |
|
| 2416 | + } else { |
|
| 2417 | + // not a payment |
|
| 2418 | + $this->checkout->continue_reg = false; |
|
| 2419 | + EE_Error::add_error( |
|
| 2420 | + sprintf( |
|
| 2421 | + esc_html__( |
|
| 2422 | + 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
| 2423 | + 'event_espresso' |
|
| 2424 | + ), |
|
| 2425 | + '<br/>', |
|
| 2426 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2427 | + ), |
|
| 2428 | + __FILE__, |
|
| 2429 | + __FUNCTION__, |
|
| 2430 | + __LINE__ |
|
| 2431 | + ); |
|
| 2432 | + } |
|
| 2433 | + } else { |
|
| 2434 | + // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
| 2435 | + $this->checkout->continue_reg = false; |
|
| 2436 | + return false; |
|
| 2437 | + } |
|
| 2438 | + return $payment; |
|
| 2439 | + } |
|
| 2440 | + |
|
| 2441 | + |
|
| 2442 | + /** |
|
| 2443 | + * _process_payment_status |
|
| 2444 | + * |
|
| 2445 | + * @access private |
|
| 2446 | + * @type EE_Payment $payment |
|
| 2447 | + * @param string $payment_occurs |
|
| 2448 | + * @return bool |
|
| 2449 | + * @throws EE_Error |
|
| 2450 | + * @throws InvalidArgumentException |
|
| 2451 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2452 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2453 | + */ |
|
| 2454 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
| 2455 | + { |
|
| 2456 | + // off-line payment? carry on |
|
| 2457 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
| 2458 | + return true; |
|
| 2459 | + } |
|
| 2460 | + // verify payment validity |
|
| 2461 | + if ($payment instanceof EE_Payment) { |
|
| 2462 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
| 2463 | + $msg = $payment->gateway_response(); |
|
| 2464 | + // check results |
|
| 2465 | + switch ($payment->status()) { |
|
| 2466 | + // good payment |
|
| 2467 | + case EEM_Payment::status_id_approved: |
|
| 2468 | + EE_Error::add_success( |
|
| 2469 | + esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
| 2470 | + __FILE__, |
|
| 2471 | + __FUNCTION__, |
|
| 2472 | + __LINE__ |
|
| 2473 | + ); |
|
| 2474 | + return true; |
|
| 2475 | + break; |
|
| 2476 | + // slow payment |
|
| 2477 | + case EEM_Payment::status_id_pending: |
|
| 2478 | + if (empty($msg)) { |
|
| 2479 | + $msg = esc_html__( |
|
| 2480 | + 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
| 2481 | + 'event_espresso' |
|
| 2482 | + ); |
|
| 2483 | + } |
|
| 2484 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2485 | + return true; |
|
| 2486 | + break; |
|
| 2487 | + // don't wanna payment |
|
| 2488 | + case EEM_Payment::status_id_cancelled: |
|
| 2489 | + if (empty($msg)) { |
|
| 2490 | + $msg = _n( |
|
| 2491 | + 'Payment cancelled. Please try again.', |
|
| 2492 | + 'Payment cancelled. Please try again or select another method of payment.', |
|
| 2493 | + count($this->checkout->available_payment_methods), |
|
| 2494 | + 'event_espresso' |
|
| 2495 | + ); |
|
| 2496 | + } |
|
| 2497 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2498 | + return false; |
|
| 2499 | + break; |
|
| 2500 | + // not enough payment |
|
| 2501 | + case EEM_Payment::status_id_declined: |
|
| 2502 | + if (empty($msg)) { |
|
| 2503 | + $msg = _n( |
|
| 2504 | + 'We\'re sorry but your payment was declined. Please try again.', |
|
| 2505 | + 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
| 2506 | + count($this->checkout->available_payment_methods), |
|
| 2507 | + 'event_espresso' |
|
| 2508 | + ); |
|
| 2509 | + } |
|
| 2510 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2511 | + return false; |
|
| 2512 | + break; |
|
| 2513 | + // bad payment |
|
| 2514 | + case EEM_Payment::status_id_failed: |
|
| 2515 | + if (! empty($msg)) { |
|
| 2516 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2517 | + return false; |
|
| 2518 | + } |
|
| 2519 | + // default to error below |
|
| 2520 | + break; |
|
| 2521 | + } |
|
| 2522 | + } |
|
| 2523 | + // off-site payment gateway responses are too unreliable, so let's just assume that |
|
| 2524 | + // the payment processing is just running slower than the registrant's request |
|
| 2525 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
| 2526 | + return true; |
|
| 2527 | + } |
|
| 2528 | + EE_Error::add_error( |
|
| 2529 | + sprintf( |
|
| 2530 | + esc_html__( |
|
| 2531 | + 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2532 | + 'event_espresso' |
|
| 2533 | + ), |
|
| 2534 | + '<br/>', |
|
| 2535 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2536 | + ), |
|
| 2537 | + __FILE__, |
|
| 2538 | + __FUNCTION__, |
|
| 2539 | + __LINE__ |
|
| 2540 | + ); |
|
| 2541 | + return false; |
|
| 2542 | + } |
|
| 2543 | + |
|
| 2544 | + |
|
| 2545 | + |
|
| 2546 | + |
|
| 2547 | + |
|
| 2548 | + |
|
| 2549 | + /********************************************************************************************************/ |
|
| 2550 | + /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
| 2551 | + /********************************************************************************************************/ |
|
| 2552 | + /** |
|
| 2553 | + * process_gateway_response |
|
| 2554 | + * this is the return point for Off-Site Payment Methods |
|
| 2555 | + * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
| 2556 | + * otherwise, it will load up the last payment made for the TXN. |
|
| 2557 | + * If the payment retrieved looks good, it will then either: |
|
| 2558 | + * complete the current step and allow advancement to the next reg step |
|
| 2559 | + * or present the payment options again |
|
| 2560 | + * |
|
| 2561 | + * @access private |
|
| 2562 | + * @return EE_Payment|FALSE |
|
| 2563 | + * @throws EE_Error |
|
| 2564 | + * @throws InvalidArgumentException |
|
| 2565 | + * @throws ReflectionException |
|
| 2566 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2567 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2568 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2569 | + */ |
|
| 2570 | + public function process_gateway_response() |
|
| 2571 | + { |
|
| 2572 | + $payment = null; |
|
| 2573 | + // how have they chosen to pay? |
|
| 2574 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 2575 | + // get EE_Payment_Method object |
|
| 2576 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2577 | + $this->checkout->continue_reg = false; |
|
| 2578 | + return false; |
|
| 2579 | + } |
|
| 2580 | + if (! $this->checkout->payment_method->is_off_site()) { |
|
| 2581 | + return false; |
|
| 2582 | + } |
|
| 2583 | + $this->_validate_offsite_return(); |
|
| 2584 | + // DEBUG LOG |
|
| 2585 | + // $this->checkout->log( |
|
| 2586 | + // __CLASS__, |
|
| 2587 | + // __FUNCTION__, |
|
| 2588 | + // __LINE__, |
|
| 2589 | + // array( |
|
| 2590 | + // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2591 | + // 'payment_method' => $this->checkout->payment_method, |
|
| 2592 | + // ), |
|
| 2593 | + // true |
|
| 2594 | + // ); |
|
| 2595 | + // verify TXN |
|
| 2596 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 2597 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
| 2598 | + if (! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2599 | + $this->checkout->continue_reg = false; |
|
| 2600 | + return false; |
|
| 2601 | + } |
|
| 2602 | + $payment = $this->_process_off_site_payment($gateway); |
|
| 2603 | + $payment = $this->_process_cancelled_payments($payment); |
|
| 2604 | + $payment = $this->_validate_payment($payment); |
|
| 2605 | + // if payment was not declined by the payment gateway or cancelled by the registrant |
|
| 2606 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
| 2607 | + // $this->_setup_redirect_for_next_step(); |
|
| 2608 | + // store that for later |
|
| 2609 | + $this->checkout->payment = $payment; |
|
| 2610 | + // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
| 2611 | + // because we will complete this step during the IPN processing then |
|
| 2612 | + if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
| 2613 | + $this->set_completed(); |
|
| 2614 | + } |
|
| 2615 | + return true; |
|
| 2616 | + } |
|
| 2617 | + } |
|
| 2618 | + // DEBUG LOG |
|
| 2619 | + // $this->checkout->log( |
|
| 2620 | + // __CLASS__, |
|
| 2621 | + // __FUNCTION__, |
|
| 2622 | + // __LINE__, |
|
| 2623 | + // array('payment' => $payment) |
|
| 2624 | + // ); |
|
| 2625 | + $this->checkout->continue_reg = false; |
|
| 2626 | + return false; |
|
| 2627 | + } |
|
| 2628 | + |
|
| 2629 | + |
|
| 2630 | + /** |
|
| 2631 | + * _validate_return |
|
| 2632 | + * |
|
| 2633 | + * @access private |
|
| 2634 | + * @return void |
|
| 2635 | + * @throws EE_Error |
|
| 2636 | + * @throws InvalidArgumentException |
|
| 2637 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2638 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2639 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2640 | + */ |
|
| 2641 | + private function _validate_offsite_return() |
|
| 2642 | + { |
|
| 2643 | + $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
| 2644 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
| 2645 | + // Houston... we might have a problem |
|
| 2646 | + $invalid_TXN = false; |
|
| 2647 | + // first gather some info |
|
| 2648 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2649 | + $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
| 2650 | + ? $valid_TXN->primary_registration() |
|
| 2651 | + : null; |
|
| 2652 | + // let's start by retrieving the cart for this TXN |
|
| 2653 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
| 2654 | + if ($cart instanceof EE_Cart) { |
|
| 2655 | + // verify that the current cart has tickets |
|
| 2656 | + $tickets = $cart->get_tickets(); |
|
| 2657 | + if (empty($tickets)) { |
|
| 2658 | + $invalid_TXN = true; |
|
| 2659 | + } |
|
| 2660 | + } else { |
|
| 2661 | + $invalid_TXN = true; |
|
| 2662 | + } |
|
| 2663 | + $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
| 2664 | + ? $primary_registrant->session_ID() |
|
| 2665 | + : null; |
|
| 2666 | + // validate current Session ID and compare against valid TXN session ID |
|
| 2667 | + if ($invalid_TXN // if this is already true, then skip other checks |
|
| 2668 | + || EE_Session::instance()->id() === null |
|
| 2669 | + || ( |
|
| 2670 | + // WARNING !!! |
|
| 2671 | + // this could be PayPal sending back duplicate requests (ya they do that) |
|
| 2672 | + // or it **could** mean someone is simply registering AGAIN after having just done so |
|
| 2673 | + // so now we need to determine if this current TXN looks valid or not |
|
| 2674 | + // and whether this reg step has even been started ? |
|
| 2675 | + EE_Session::instance()->id() === $valid_TXN_SID |
|
| 2676 | + // really? you're half way through this reg step, but you never started it ? |
|
| 2677 | + && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
| 2678 | + ) |
|
| 2679 | + ) { |
|
| 2680 | + $invalid_TXN = true; |
|
| 2681 | + } |
|
| 2682 | + if ($invalid_TXN) { |
|
| 2683 | + // is the valid TXN completed ? |
|
| 2684 | + if ($valid_TXN instanceof EE_Transaction) { |
|
| 2685 | + // has this step even been started ? |
|
| 2686 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
| 2687 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
| 2688 | + // so it **looks** like this is a double request from PayPal |
|
| 2689 | + // so let's try to pick up where we left off |
|
| 2690 | + $this->checkout->transaction = $valid_TXN; |
|
| 2691 | + $this->checkout->refresh_all_entities(true); |
|
| 2692 | + return; |
|
| 2693 | + } |
|
| 2694 | + } |
|
| 2695 | + // you appear to be lost? |
|
| 2696 | + $this->_redirect_wayward_request($primary_registrant); |
|
| 2697 | + } |
|
| 2698 | + } |
|
| 2699 | + } |
|
| 2700 | + |
|
| 2701 | + |
|
| 2702 | + /** |
|
| 2703 | + * _redirect_wayward_request |
|
| 2704 | + * |
|
| 2705 | + * @access private |
|
| 2706 | + * @param \EE_Registration|null $primary_registrant |
|
| 2707 | + * @return bool |
|
| 2708 | + * @throws EE_Error |
|
| 2709 | + * @throws InvalidArgumentException |
|
| 2710 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2711 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2712 | + */ |
|
| 2713 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
| 2714 | + { |
|
| 2715 | + if (! $primary_registrant instanceof EE_Registration) { |
|
| 2716 | + // try redirecting based on the current TXN |
|
| 2717 | + $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
| 2718 | + ? $this->checkout->transaction->primary_registration() |
|
| 2719 | + : null; |
|
| 2720 | + } |
|
| 2721 | + if (! $primary_registrant instanceof EE_Registration) { |
|
| 2722 | + EE_Error::add_error( |
|
| 2723 | + sprintf( |
|
| 2724 | + esc_html__( |
|
| 2725 | + 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2726 | + 'event_espresso' |
|
| 2727 | + ), |
|
| 2728 | + '<br/>', |
|
| 2729 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2730 | + ), |
|
| 2731 | + __FILE__, |
|
| 2732 | + __FUNCTION__, |
|
| 2733 | + __LINE__ |
|
| 2734 | + ); |
|
| 2735 | + return false; |
|
| 2736 | + } |
|
| 2737 | + // make sure transaction is not locked |
|
| 2738 | + $this->checkout->transaction->unlock(); |
|
| 2739 | + wp_safe_redirect( |
|
| 2740 | + add_query_arg( |
|
| 2741 | + array( |
|
| 2742 | + 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
| 2743 | + ), |
|
| 2744 | + $this->checkout->thank_you_page_url |
|
| 2745 | + ) |
|
| 2746 | + ); |
|
| 2747 | + exit(); |
|
| 2748 | + } |
|
| 2749 | + |
|
| 2750 | + |
|
| 2751 | + /** |
|
| 2752 | + * _process_off_site_payment |
|
| 2753 | + * |
|
| 2754 | + * @access private |
|
| 2755 | + * @param \EE_Offsite_Gateway $gateway |
|
| 2756 | + * @return EE_Payment |
|
| 2757 | + * @throws EE_Error |
|
| 2758 | + * @throws InvalidArgumentException |
|
| 2759 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2760 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2761 | + */ |
|
| 2762 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
| 2763 | + { |
|
| 2764 | + try { |
|
| 2765 | + $request_data = \EE_Registry::instance()->REQ->params(); |
|
| 2766 | + // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
| 2767 | + $this->set_handle_IPN_in_this_request( |
|
| 2768 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
| 2769 | + ); |
|
| 2770 | + if ($this->handle_IPN_in_this_request()) { |
|
| 2771 | + // get payment details and process results |
|
| 2772 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 2773 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2774 | + $payment = $payment_processor->process_ipn( |
|
| 2775 | + $request_data, |
|
| 2776 | + $this->checkout->transaction, |
|
| 2777 | + $this->checkout->payment_method, |
|
| 2778 | + true, |
|
| 2779 | + false |
|
| 2780 | + ); |
|
| 2781 | + // $payment_source = 'process_ipn'; |
|
| 2782 | + } else { |
|
| 2783 | + $payment = $this->checkout->transaction->last_payment(); |
|
| 2784 | + // $payment_source = 'last_payment'; |
|
| 2785 | + } |
|
| 2786 | + } catch (Exception $e) { |
|
| 2787 | + // let's just eat the exception and try to move on using any previously set payment info |
|
| 2788 | + $payment = $this->checkout->transaction->last_payment(); |
|
| 2789 | + // $payment_source = 'last_payment after Exception'; |
|
| 2790 | + // but if we STILL don't have a payment object |
|
| 2791 | + if (! $payment instanceof EE_Payment) { |
|
| 2792 | + // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
| 2793 | + $this->_handle_payment_processor_exception($e); |
|
| 2794 | + } |
|
| 2795 | + } |
|
| 2796 | + // DEBUG LOG |
|
| 2797 | + // $this->checkout->log( |
|
| 2798 | + // __CLASS__, |
|
| 2799 | + // __FUNCTION__, |
|
| 2800 | + // __LINE__, |
|
| 2801 | + // array( |
|
| 2802 | + // 'process_ipn_payment' => $payment, |
|
| 2803 | + // 'payment_source' => $payment_source, |
|
| 2804 | + // ) |
|
| 2805 | + // ); |
|
| 2806 | + return $payment; |
|
| 2807 | + } |
|
| 2808 | + |
|
| 2809 | + |
|
| 2810 | + /** |
|
| 2811 | + * _process_cancelled_payments |
|
| 2812 | + * just makes sure that the payment status gets updated correctly |
|
| 2813 | + * so tha tan error isn't generated during payment validation |
|
| 2814 | + * |
|
| 2815 | + * @access private |
|
| 2816 | + * @param EE_Payment $payment |
|
| 2817 | + * @return EE_Payment | FALSE |
|
| 2818 | + * @throws \EE_Error |
|
| 2819 | + */ |
|
| 2820 | + private function _process_cancelled_payments($payment = null) |
|
| 2821 | + { |
|
| 2822 | + if ($payment instanceof EE_Payment |
|
| 2823 | + && isset($_REQUEST['ee_cancel_payment']) |
|
| 2824 | + && $payment->status() === EEM_Payment::status_id_failed |
|
| 2825 | + ) { |
|
| 2826 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
| 2827 | + } |
|
| 2828 | + return $payment; |
|
| 2829 | + } |
|
| 2830 | + |
|
| 2831 | + |
|
| 2832 | + /** |
|
| 2833 | + * get_transaction_details_for_gateways |
|
| 2834 | + * |
|
| 2835 | + * @access public |
|
| 2836 | + * @return int |
|
| 2837 | + * @throws EE_Error |
|
| 2838 | + * @throws InvalidArgumentException |
|
| 2839 | + * @throws ReflectionException |
|
| 2840 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2841 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2842 | + */ |
|
| 2843 | + public function get_transaction_details_for_gateways() |
|
| 2844 | + { |
|
| 2845 | + $txn_details = array(); |
|
| 2846 | + // ya gotta make a choice man |
|
| 2847 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 2848 | + $txn_details = array( |
|
| 2849 | + 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
| 2850 | + ); |
|
| 2851 | + } |
|
| 2852 | + // get EE_Payment_Method object |
|
| 2853 | + if (empty($txn_details) |
|
| 2854 | + && |
|
| 2855 | + ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
| 2856 | + ) { |
|
| 2857 | + $txn_details = array( |
|
| 2858 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2859 | + 'error' => esc_html__( |
|
| 2860 | + 'A valid Payment Method could not be determined.', |
|
| 2861 | + 'event_espresso' |
|
| 2862 | + ), |
|
| 2863 | + ); |
|
| 2864 | + } |
|
| 2865 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
| 2866 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
| 2867 | + $txn_details = array( |
|
| 2868 | + 'TXN_ID' => $this->checkout->transaction->ID(), |
|
| 2869 | + 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
| 2870 | + 'TXN_total' => $this->checkout->transaction->total(), |
|
| 2871 | + 'TXN_paid' => $this->checkout->transaction->paid(), |
|
| 2872 | + 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
| 2873 | + 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
| 2874 | + 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
| 2875 | + 'payment_amount' => $this->checkout->amount_owing, |
|
| 2876 | + 'return_url' => $return_url, |
|
| 2877 | + 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
| 2878 | + 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
| 2879 | + array( |
|
| 2880 | + 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
| 2881 | + 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
| 2882 | + ) |
|
| 2883 | + ), |
|
| 2884 | + ); |
|
| 2885 | + } |
|
| 2886 | + echo wp_json_encode($txn_details); |
|
| 2887 | + exit(); |
|
| 2888 | + } |
|
| 2889 | + |
|
| 2890 | + |
|
| 2891 | + /** |
|
| 2892 | + * __sleep |
|
| 2893 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
| 2894 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
| 2895 | + * reg form, because if needed, it will be regenerated anyways |
|
| 2896 | + * |
|
| 2897 | + * @return array |
|
| 2898 | + */ |
|
| 2899 | + public function __sleep() |
|
| 2900 | + { |
|
| 2901 | + // remove the reg form and the checkout |
|
| 2902 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
| 2903 | + } |
|
| 2904 | 2904 | } |
@@ -15,1388 +15,1388 @@ |
||
| 15 | 15 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * cached value for the the logical active status for the event |
|
| 20 | - * |
|
| 21 | - * @see get_active_status() |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $_active_status = ''; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 28 | - * |
|
| 29 | - * @var EE_Datetime |
|
| 30 | - */ |
|
| 31 | - protected $_Primary_Datetime; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
| 35 | - */ |
|
| 36 | - protected $available_spaces_calculator; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param array $props_n_values incoming values |
|
| 41 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 42 | - * used.) |
|
| 43 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 44 | - * date_format and the second value is the time format |
|
| 45 | - * @return EE_Event |
|
| 46 | - * @throws EE_Error |
|
| 47 | - */ |
|
| 48 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 49 | - { |
|
| 50 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 51 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param array $props_n_values incoming values from the database |
|
| 57 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 58 | - * the website will be used. |
|
| 59 | - * @return EE_Event |
|
| 60 | - * @throws EE_Error |
|
| 61 | - */ |
|
| 62 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 63 | - { |
|
| 64 | - return new self($props_n_values, true, $timezone); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return EventSpacesCalculator |
|
| 70 | - * @throws \EE_Error |
|
| 71 | - */ |
|
| 72 | - public function getAvailableSpacesCalculator() |
|
| 73 | - { |
|
| 74 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 75 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 76 | - } |
|
| 77 | - return $this->available_spaces_calculator; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 83 | - * |
|
| 84 | - * @param string $field_name |
|
| 85 | - * @param mixed $field_value |
|
| 86 | - * @param bool $use_default |
|
| 87 | - * @throws EE_Error |
|
| 88 | - */ |
|
| 89 | - public function set($field_name, $field_value, $use_default = false) |
|
| 90 | - { |
|
| 91 | - switch ($field_name) { |
|
| 92 | - case 'status': |
|
| 93 | - $this->set_status($field_value, $use_default); |
|
| 94 | - break; |
|
| 95 | - default: |
|
| 96 | - parent::set($field_name, $field_value, $use_default); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * set_status |
|
| 103 | - * Checks if event status is being changed to SOLD OUT |
|
| 104 | - * and updates event meta data with previous event status |
|
| 105 | - * so that we can revert things if/when the event is no longer sold out |
|
| 106 | - * |
|
| 107 | - * @access public |
|
| 108 | - * @param string $new_status |
|
| 109 | - * @param bool $use_default |
|
| 110 | - * @return void |
|
| 111 | - * @throws EE_Error |
|
| 112 | - */ |
|
| 113 | - public function set_status($new_status = null, $use_default = false) |
|
| 114 | - { |
|
| 115 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 116 | - if (empty($new_status) && ! $use_default) { |
|
| 117 | - return; |
|
| 118 | - } |
|
| 119 | - // get current Event status |
|
| 120 | - $old_status = $this->status(); |
|
| 121 | - // if status has changed |
|
| 122 | - if ($old_status !== $new_status) { |
|
| 123 | - // TO sold_out |
|
| 124 | - if ($new_status === EEM_Event::sold_out) { |
|
| 125 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
| 126 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
| 127 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 128 | - // OR FROM sold_out |
|
| 129 | - } elseif ($old_status === EEM_Event::sold_out) { |
|
| 130 | - $this->delete_post_meta('_previous_event_status'); |
|
| 131 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 132 | - } |
|
| 133 | - // clear out the active status so that it gets reset the next time it is requested |
|
| 134 | - $this->_active_status = null; |
|
| 135 | - // update status |
|
| 136 | - parent::set('status', $new_status, $use_default); |
|
| 137 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 138 | - return; |
|
| 139 | - } |
|
| 140 | - // even though the old value matches the new value, it's still good to |
|
| 141 | - // allow the parent set method to have a say |
|
| 142 | - parent::set('status', $new_status, $use_default); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Gets all the datetimes for this event |
|
| 148 | - * |
|
| 149 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 150 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 151 | - * @throws EE_Error |
|
| 152 | - */ |
|
| 153 | - public function datetimes($query_params = array()) |
|
| 154 | - { |
|
| 155 | - return $this->get_many_related('Datetime', $query_params); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 161 | - * |
|
| 162 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 163 | - * @throws EE_Error |
|
| 164 | - */ |
|
| 165 | - public function datetimes_in_chronological_order() |
|
| 166 | - { |
|
| 167 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 173 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 174 | - * after running our query, so that this timezone isn't set for EVERY query |
|
| 175 | - * on EEM_Datetime for the rest of the request, no? |
|
| 176 | - * |
|
| 177 | - * @param boolean $show_expired whether or not to include expired events |
|
| 178 | - * @param boolean $show_deleted whether or not to include deleted events |
|
| 179 | - * @param null $limit |
|
| 180 | - * @return EE_Datetime[] |
|
| 181 | - * @throws EE_Error |
|
| 182 | - */ |
|
| 183 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 184 | - { |
|
| 185 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 186 | - $this->ID(), |
|
| 187 | - $show_expired, |
|
| 188 | - $show_deleted, |
|
| 189 | - $limit |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
| 196 | - * |
|
| 197 | - * @return EE_Base_Class|EE_Datetime |
|
| 198 | - * @throws EE_Error |
|
| 199 | - */ |
|
| 200 | - public function first_datetime() |
|
| 201 | - { |
|
| 202 | - return $this->get_first_related('Datetime'); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Returns the 'primary' datetime for the event |
|
| 208 | - * |
|
| 209 | - * @param bool $try_to_exclude_expired |
|
| 210 | - * @param bool $try_to_exclude_deleted |
|
| 211 | - * @return EE_Datetime |
|
| 212 | - * @throws EE_Error |
|
| 213 | - */ |
|
| 214 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 215 | - { |
|
| 216 | - if (! empty($this->_Primary_Datetime)) { |
|
| 217 | - return $this->_Primary_Datetime; |
|
| 218 | - } |
|
| 219 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 220 | - $this->ID(), |
|
| 221 | - $try_to_exclude_expired, |
|
| 222 | - $try_to_exclude_deleted |
|
| 223 | - ); |
|
| 224 | - return $this->_Primary_Datetime; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Gets all the tickets available for purchase of this event |
|
| 230 | - * |
|
| 231 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 232 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 233 | - * @throws EE_Error |
|
| 234 | - */ |
|
| 235 | - public function tickets($query_params = array()) |
|
| 236 | - { |
|
| 237 | - // first get all datetimes |
|
| 238 | - $datetimes = $this->datetimes_ordered(); |
|
| 239 | - if (! $datetimes) { |
|
| 240 | - return array(); |
|
| 241 | - } |
|
| 242 | - $datetime_ids = array(); |
|
| 243 | - foreach ($datetimes as $datetime) { |
|
| 244 | - $datetime_ids[] = $datetime->ID(); |
|
| 245 | - } |
|
| 246 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 247 | - // if incoming $query_params has where conditions let's merge but not override existing. |
|
| 248 | - if (is_array($query_params) && isset($query_params[0])) { |
|
| 249 | - $where_params = array_merge($query_params[0], $where_params); |
|
| 250 | - unset($query_params[0]); |
|
| 251 | - } |
|
| 252 | - // now add $where_params to $query_params |
|
| 253 | - $query_params[0] = $where_params; |
|
| 254 | - return EEM_Ticket::instance()->get_all($query_params); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * get all unexpired untrashed tickets |
|
| 260 | - * |
|
| 261 | - * @return EE_Ticket[] |
|
| 262 | - * @throws EE_Error |
|
| 263 | - */ |
|
| 264 | - public function active_tickets() |
|
| 265 | - { |
|
| 266 | - return $this->tickets( |
|
| 267 | - array( |
|
| 268 | - array( |
|
| 269 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 270 | - 'TKT_deleted' => false, |
|
| 271 | - ), |
|
| 272 | - ) |
|
| 273 | - ); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @return bool |
|
| 279 | - * @throws EE_Error |
|
| 280 | - */ |
|
| 281 | - public function additional_limit() |
|
| 282 | - { |
|
| 283 | - return $this->get('EVT_additional_limit'); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @return bool |
|
| 289 | - * @throws EE_Error |
|
| 290 | - */ |
|
| 291 | - public function allow_overflow() |
|
| 292 | - { |
|
| 293 | - return $this->get('EVT_allow_overflow'); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @return bool |
|
| 299 | - * @throws EE_Error |
|
| 300 | - */ |
|
| 301 | - public function created() |
|
| 302 | - { |
|
| 303 | - return $this->get('EVT_created'); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @return bool |
|
| 309 | - * @throws EE_Error |
|
| 310 | - */ |
|
| 311 | - public function description() |
|
| 312 | - { |
|
| 313 | - return $this->get('EVT_desc'); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Runs do_shortcode and wpautop on the description |
|
| 319 | - * |
|
| 320 | - * @return string of html |
|
| 321 | - * @throws EE_Error |
|
| 322 | - */ |
|
| 323 | - public function description_filtered() |
|
| 324 | - { |
|
| 325 | - return $this->get_pretty('EVT_desc'); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * @return bool |
|
| 331 | - * @throws EE_Error |
|
| 332 | - */ |
|
| 333 | - public function display_description() |
|
| 334 | - { |
|
| 335 | - return $this->get('EVT_display_desc'); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @return bool |
|
| 341 | - * @throws EE_Error |
|
| 342 | - */ |
|
| 343 | - public function display_ticket_selector() |
|
| 344 | - { |
|
| 345 | - return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * @return bool |
|
| 351 | - * @throws EE_Error |
|
| 352 | - */ |
|
| 353 | - public function external_url() |
|
| 354 | - { |
|
| 355 | - return $this->get('EVT_external_URL'); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * @return bool |
|
| 361 | - * @throws EE_Error |
|
| 362 | - */ |
|
| 363 | - public function member_only() |
|
| 364 | - { |
|
| 365 | - return $this->get('EVT_member_only'); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @return bool |
|
| 371 | - * @throws EE_Error |
|
| 372 | - */ |
|
| 373 | - public function phone() |
|
| 374 | - { |
|
| 375 | - return $this->get('EVT_phone'); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * @return bool |
|
| 381 | - * @throws EE_Error |
|
| 382 | - */ |
|
| 383 | - public function modified() |
|
| 384 | - { |
|
| 385 | - return $this->get('EVT_modified'); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * @return bool |
|
| 391 | - * @throws EE_Error |
|
| 392 | - */ |
|
| 393 | - public function name() |
|
| 394 | - { |
|
| 395 | - return $this->get('EVT_name'); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * @return bool |
|
| 401 | - * @throws EE_Error |
|
| 402 | - */ |
|
| 403 | - public function order() |
|
| 404 | - { |
|
| 405 | - return $this->get('EVT_order'); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * @return bool|string |
|
| 411 | - * @throws EE_Error |
|
| 412 | - */ |
|
| 413 | - public function default_registration_status() |
|
| 414 | - { |
|
| 415 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 416 | - return ! empty($event_default_registration_status) |
|
| 417 | - ? $event_default_registration_status |
|
| 418 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * @param int $num_words |
|
| 424 | - * @param null $more |
|
| 425 | - * @param bool $not_full_desc |
|
| 426 | - * @return bool|string |
|
| 427 | - * @throws EE_Error |
|
| 428 | - */ |
|
| 429 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 430 | - { |
|
| 431 | - $short_desc = $this->get('EVT_short_desc'); |
|
| 432 | - if (! empty($short_desc) || $not_full_desc) { |
|
| 433 | - return $short_desc; |
|
| 434 | - } |
|
| 435 | - $full_desc = $this->get('EVT_desc'); |
|
| 436 | - return wp_trim_words($full_desc, $num_words, $more); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @return bool |
|
| 442 | - * @throws EE_Error |
|
| 443 | - */ |
|
| 444 | - public function slug() |
|
| 445 | - { |
|
| 446 | - return $this->get('EVT_slug'); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * @return bool |
|
| 452 | - * @throws EE_Error |
|
| 453 | - */ |
|
| 454 | - public function timezone_string() |
|
| 455 | - { |
|
| 456 | - return $this->get('EVT_timezone_string'); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @return bool |
|
| 462 | - * @throws EE_Error |
|
| 463 | - */ |
|
| 464 | - public function visible_on() |
|
| 465 | - { |
|
| 466 | - return $this->get('EVT_visible_on'); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * @return int |
|
| 472 | - * @throws EE_Error |
|
| 473 | - */ |
|
| 474 | - public function wp_user() |
|
| 475 | - { |
|
| 476 | - return $this->get('EVT_wp_user'); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * @return bool |
|
| 482 | - * @throws EE_Error |
|
| 483 | - */ |
|
| 484 | - public function donations() |
|
| 485 | - { |
|
| 486 | - return $this->get('EVT_donations'); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * @param $limit |
|
| 492 | - * @throws EE_Error |
|
| 493 | - */ |
|
| 494 | - public function set_additional_limit($limit) |
|
| 495 | - { |
|
| 496 | - $this->set('EVT_additional_limit', $limit); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * @param $created |
|
| 502 | - * @throws EE_Error |
|
| 503 | - */ |
|
| 504 | - public function set_created($created) |
|
| 505 | - { |
|
| 506 | - $this->set('EVT_created', $created); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * @param $desc |
|
| 512 | - * @throws EE_Error |
|
| 513 | - */ |
|
| 514 | - public function set_description($desc) |
|
| 515 | - { |
|
| 516 | - $this->set('EVT_desc', $desc); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * @param $display_desc |
|
| 522 | - * @throws EE_Error |
|
| 523 | - */ |
|
| 524 | - public function set_display_description($display_desc) |
|
| 525 | - { |
|
| 526 | - $this->set('EVT_display_desc', $display_desc); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * @param $display_ticket_selector |
|
| 532 | - * @throws EE_Error |
|
| 533 | - */ |
|
| 534 | - public function set_display_ticket_selector($display_ticket_selector) |
|
| 535 | - { |
|
| 536 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * @param $external_url |
|
| 542 | - * @throws EE_Error |
|
| 543 | - */ |
|
| 544 | - public function set_external_url($external_url) |
|
| 545 | - { |
|
| 546 | - $this->set('EVT_external_URL', $external_url); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * @param $member_only |
|
| 552 | - * @throws EE_Error |
|
| 553 | - */ |
|
| 554 | - public function set_member_only($member_only) |
|
| 555 | - { |
|
| 556 | - $this->set('EVT_member_only', $member_only); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * @param $event_phone |
|
| 562 | - * @throws EE_Error |
|
| 563 | - */ |
|
| 564 | - public function set_event_phone($event_phone) |
|
| 565 | - { |
|
| 566 | - $this->set('EVT_phone', $event_phone); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * @param $modified |
|
| 572 | - * @throws EE_Error |
|
| 573 | - */ |
|
| 574 | - public function set_modified($modified) |
|
| 575 | - { |
|
| 576 | - $this->set('EVT_modified', $modified); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * @param $name |
|
| 582 | - * @throws EE_Error |
|
| 583 | - */ |
|
| 584 | - public function set_name($name) |
|
| 585 | - { |
|
| 586 | - $this->set('EVT_name', $name); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * @param $order |
|
| 592 | - * @throws EE_Error |
|
| 593 | - */ |
|
| 594 | - public function set_order($order) |
|
| 595 | - { |
|
| 596 | - $this->set('EVT_order', $order); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * @param $short_desc |
|
| 602 | - * @throws EE_Error |
|
| 603 | - */ |
|
| 604 | - public function set_short_description($short_desc) |
|
| 605 | - { |
|
| 606 | - $this->set('EVT_short_desc', $short_desc); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * @param $slug |
|
| 612 | - * @throws EE_Error |
|
| 613 | - */ |
|
| 614 | - public function set_slug($slug) |
|
| 615 | - { |
|
| 616 | - $this->set('EVT_slug', $slug); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * @param $timezone_string |
|
| 622 | - * @throws EE_Error |
|
| 623 | - */ |
|
| 624 | - public function set_timezone_string($timezone_string) |
|
| 625 | - { |
|
| 626 | - $this->set('EVT_timezone_string', $timezone_string); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * @param $visible_on |
|
| 632 | - * @throws EE_Error |
|
| 633 | - */ |
|
| 634 | - public function set_visible_on($visible_on) |
|
| 635 | - { |
|
| 636 | - $this->set('EVT_visible_on', $visible_on); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * @param $wp_user |
|
| 642 | - * @throws EE_Error |
|
| 643 | - */ |
|
| 644 | - public function set_wp_user($wp_user) |
|
| 645 | - { |
|
| 646 | - $this->set('EVT_wp_user', $wp_user); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * @param $default_registration_status |
|
| 652 | - * @throws EE_Error |
|
| 653 | - */ |
|
| 654 | - public function set_default_registration_status($default_registration_status) |
|
| 655 | - { |
|
| 656 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * @param $donations |
|
| 662 | - * @throws EE_Error |
|
| 663 | - */ |
|
| 664 | - public function set_donations($donations) |
|
| 665 | - { |
|
| 666 | - $this->set('EVT_donations', $donations); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Adds a venue to this event |
|
| 672 | - * |
|
| 673 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 674 | - * @return EE_Base_Class|EE_Venue |
|
| 675 | - * @throws EE_Error |
|
| 676 | - */ |
|
| 677 | - public function add_venue($venue_id_or_obj) |
|
| 678 | - { |
|
| 679 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Removes a venue from the event |
|
| 685 | - * |
|
| 686 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 687 | - * @return EE_Base_Class|EE_Venue |
|
| 688 | - * @throws EE_Error |
|
| 689 | - */ |
|
| 690 | - public function remove_venue($venue_id_or_obj) |
|
| 691 | - { |
|
| 692 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
| 698 | - * |
|
| 699 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 700 | - * @return EE_Base_Class[]|EE_Venue[] |
|
| 701 | - * @throws EE_Error |
|
| 702 | - */ |
|
| 703 | - public function venues($query_params = array()) |
|
| 704 | - { |
|
| 705 | - return $this->get_many_related('Venue', $query_params); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * check if event id is present and if event is published |
|
| 711 | - * |
|
| 712 | - * @access public |
|
| 713 | - * @return boolean true yes, false no |
|
| 714 | - * @throws EE_Error |
|
| 715 | - */ |
|
| 716 | - private function _has_ID_and_is_published() |
|
| 717 | - { |
|
| 718 | - // first check if event id is present and not NULL, |
|
| 719 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 720 | - return |
|
| 721 | - $this->ID() && $this->ID() !== null |
|
| 722 | - && ( |
|
| 723 | - $this->status() === 'publish' |
|
| 724 | - || $this->status() === EEM_Event::sold_out |
|
| 725 | - || $this->status() === EEM_Event::postponed |
|
| 726 | - || $this->status() === EEM_Event::cancelled |
|
| 727 | - ); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - /** |
|
| 732 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 733 | - * |
|
| 734 | - * @access public |
|
| 735 | - * @return boolean true yes, false no |
|
| 736 | - * @throws EE_Error |
|
| 737 | - */ |
|
| 738 | - public function is_upcoming() |
|
| 739 | - { |
|
| 740 | - // check if event id is present and if this event is published |
|
| 741 | - if ($this->is_inactive()) { |
|
| 742 | - return false; |
|
| 743 | - } |
|
| 744 | - // set initial value |
|
| 745 | - $upcoming = false; |
|
| 746 | - // next let's get all datetimes and loop through them |
|
| 747 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 748 | - foreach ($datetimes as $datetime) { |
|
| 749 | - if ($datetime instanceof EE_Datetime) { |
|
| 750 | - // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 751 | - if ($datetime->is_expired()) { |
|
| 752 | - continue; |
|
| 753 | - } |
|
| 754 | - // if this dtt is active then we return false. |
|
| 755 | - if ($datetime->is_active()) { |
|
| 756 | - return false; |
|
| 757 | - } |
|
| 758 | - // otherwise let's check upcoming status |
|
| 759 | - $upcoming = $datetime->is_upcoming(); |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - return $upcoming; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * @return bool |
|
| 768 | - * @throws EE_Error |
|
| 769 | - */ |
|
| 770 | - public function is_active() |
|
| 771 | - { |
|
| 772 | - // check if event id is present and if this event is published |
|
| 773 | - if ($this->is_inactive()) { |
|
| 774 | - return false; |
|
| 775 | - } |
|
| 776 | - // set initial value |
|
| 777 | - $active = false; |
|
| 778 | - // next let's get all datetimes and loop through them |
|
| 779 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 780 | - foreach ($datetimes as $datetime) { |
|
| 781 | - if ($datetime instanceof EE_Datetime) { |
|
| 782 | - // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 783 | - if ($datetime->is_expired()) { |
|
| 784 | - continue; |
|
| 785 | - } |
|
| 786 | - // if this dtt is upcoming then we return false. |
|
| 787 | - if ($datetime->is_upcoming()) { |
|
| 788 | - return false; |
|
| 789 | - } |
|
| 790 | - // otherwise let's check active status |
|
| 791 | - $active = $datetime->is_active(); |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - return $active; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * @return bool |
|
| 800 | - * @throws EE_Error |
|
| 801 | - */ |
|
| 802 | - public function is_expired() |
|
| 803 | - { |
|
| 804 | - // check if event id is present and if this event is published |
|
| 805 | - if ($this->is_inactive()) { |
|
| 806 | - return false; |
|
| 807 | - } |
|
| 808 | - // set initial value |
|
| 809 | - $expired = false; |
|
| 810 | - // first let's get all datetimes and loop through them |
|
| 811 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 812 | - foreach ($datetimes as $datetime) { |
|
| 813 | - if ($datetime instanceof EE_Datetime) { |
|
| 814 | - // if this dtt is upcoming or active then we return false. |
|
| 815 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 816 | - return false; |
|
| 817 | - } |
|
| 818 | - // otherwise let's check active status |
|
| 819 | - $expired = $datetime->is_expired(); |
|
| 820 | - } |
|
| 821 | - } |
|
| 822 | - return $expired; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * @return bool |
|
| 828 | - * @throws EE_Error |
|
| 829 | - */ |
|
| 830 | - public function is_inactive() |
|
| 831 | - { |
|
| 832 | - // check if event id is present and if this event is published |
|
| 833 | - if ($this->_has_ID_and_is_published()) { |
|
| 834 | - return false; |
|
| 835 | - } |
|
| 836 | - return true; |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * calculate spaces remaining based on "saleable" tickets |
|
| 842 | - * |
|
| 843 | - * @param array $tickets |
|
| 844 | - * @param bool $filtered |
|
| 845 | - * @return int|float |
|
| 846 | - * @throws EE_Error |
|
| 847 | - * @throws DomainException |
|
| 848 | - * @throws UnexpectedEntityException |
|
| 849 | - */ |
|
| 850 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 851 | - { |
|
| 852 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 853 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 854 | - return $filtered |
|
| 855 | - ? apply_filters( |
|
| 856 | - 'FHEE_EE_Event__spaces_remaining', |
|
| 857 | - $spaces_remaining, |
|
| 858 | - $this, |
|
| 859 | - $tickets |
|
| 860 | - ) |
|
| 861 | - : $spaces_remaining; |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * perform_sold_out_status_check |
|
| 867 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
| 868 | - * available... if NOT, then the event status will get toggled to 'sold_out' |
|
| 869 | - * |
|
| 870 | - * @return bool return the ACTUAL sold out state. |
|
| 871 | - * @throws EE_Error |
|
| 872 | - * @throws DomainException |
|
| 873 | - * @throws UnexpectedEntityException |
|
| 874 | - */ |
|
| 875 | - public function perform_sold_out_status_check() |
|
| 876 | - { |
|
| 877 | - // get all tickets |
|
| 878 | - $tickets = $this->tickets( |
|
| 879 | - array( |
|
| 880 | - 'default_where_conditions' => 'none', |
|
| 881 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 882 | - ) |
|
| 883 | - ); |
|
| 884 | - $all_expired = true; |
|
| 885 | - foreach ($tickets as $ticket) { |
|
| 886 | - if (! $ticket->is_expired()) { |
|
| 887 | - $all_expired = false; |
|
| 888 | - break; |
|
| 889 | - } |
|
| 890 | - } |
|
| 891 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
| 892 | - if ($all_expired) { |
|
| 893 | - return true; |
|
| 894 | - } |
|
| 895 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 896 | - if ($spaces_remaining < 1) { |
|
| 897 | - if ($this->status() !== EEM_Event::post_status_private) { |
|
| 898 | - $this->set_status(EEM_Event::sold_out); |
|
| 899 | - $this->save(); |
|
| 900 | - } |
|
| 901 | - $sold_out = true; |
|
| 902 | - } else { |
|
| 903 | - $sold_out = false; |
|
| 904 | - // was event previously marked as sold out ? |
|
| 905 | - if ($this->status() === EEM_Event::sold_out) { |
|
| 906 | - // revert status to previous value, if it was set |
|
| 907 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 908 | - if ($previous_event_status) { |
|
| 909 | - $this->set_status($previous_event_status); |
|
| 910 | - $this->save(); |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 915 | - return $sold_out; |
|
| 916 | - } |
|
| 917 | - |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * This returns the total remaining spaces for sale on this event. |
|
| 921 | - * |
|
| 922 | - * @uses EE_Event::total_available_spaces() |
|
| 923 | - * @return float|int |
|
| 924 | - * @throws EE_Error |
|
| 925 | - * @throws DomainException |
|
| 926 | - * @throws UnexpectedEntityException |
|
| 927 | - */ |
|
| 928 | - public function spaces_remaining_for_sale() |
|
| 929 | - { |
|
| 930 | - return $this->total_available_spaces(true); |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * This returns the total spaces available for an event |
|
| 936 | - * while considering all the qtys on the tickets and the reg limits |
|
| 937 | - * on the datetimes attached to this event. |
|
| 938 | - * |
|
| 939 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 940 | - * If this is false, then we return the most tickets that could ever be sold |
|
| 941 | - * for this event with the datetime and tickets setup on the event under optimal |
|
| 942 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 943 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
| 944 | - * may appear to equal remaining tickets. However, the more tickets are |
|
| 945 | - * sold out, the more accurate the "live" total is. |
|
| 946 | - * @return float|int |
|
| 947 | - * @throws EE_Error |
|
| 948 | - * @throws DomainException |
|
| 949 | - * @throws UnexpectedEntityException |
|
| 950 | - */ |
|
| 951 | - public function total_available_spaces($consider_sold = false) |
|
| 952 | - { |
|
| 953 | - $spaces_available = $consider_sold |
|
| 954 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 955 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 956 | - return apply_filters( |
|
| 957 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 958 | - $spaces_available, |
|
| 959 | - $this, |
|
| 960 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 961 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 962 | - ); |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * Checks if the event is set to sold out |
|
| 968 | - * |
|
| 969 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 970 | - * actual status but also to flip the status if necessary to sold |
|
| 971 | - * out If false, we just check the existing status of the event |
|
| 972 | - * @return boolean |
|
| 973 | - * @throws EE_Error |
|
| 974 | - */ |
|
| 975 | - public function is_sold_out($actual = false) |
|
| 976 | - { |
|
| 977 | - if (! $actual) { |
|
| 978 | - return $this->status() === EEM_Event::sold_out; |
|
| 979 | - } |
|
| 980 | - return $this->perform_sold_out_status_check(); |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - /** |
|
| 985 | - * Checks if the event is marked as postponed |
|
| 986 | - * |
|
| 987 | - * @return boolean |
|
| 988 | - */ |
|
| 989 | - public function is_postponed() |
|
| 990 | - { |
|
| 991 | - return $this->status() === EEM_Event::postponed; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * Checks if the event is marked as cancelled |
|
| 997 | - * |
|
| 998 | - * @return boolean |
|
| 999 | - */ |
|
| 1000 | - public function is_cancelled() |
|
| 1001 | - { |
|
| 1002 | - return $this->status() === EEM_Event::cancelled; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 1008 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 1009 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 1010 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1011 | - * the event is considered expired. |
|
| 1012 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
| 1013 | - * status set on the EVENT when it is not published and thus is done |
|
| 1014 | - * |
|
| 1015 | - * @param bool $reset |
|
| 1016 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1017 | - * @throws EE_Error |
|
| 1018 | - */ |
|
| 1019 | - public function get_active_status($reset = false) |
|
| 1020 | - { |
|
| 1021 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1022 | - if (! empty($this->_active_status) && ! $reset) { |
|
| 1023 | - return $this->_active_status; |
|
| 1024 | - } |
|
| 1025 | - // first check if event id is present on this object |
|
| 1026 | - if (! $this->ID()) { |
|
| 1027 | - return false; |
|
| 1028 | - } |
|
| 1029 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1030 | - // if event is published: |
|
| 1031 | - if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
| 1032 | - // active? |
|
| 1033 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1034 | - EE_Datetime::active, |
|
| 1035 | - $where_params_for_event |
|
| 1036 | - ) > 0) { |
|
| 1037 | - $this->_active_status = EE_Datetime::active; |
|
| 1038 | - } else { |
|
| 1039 | - // upcoming? |
|
| 1040 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1041 | - EE_Datetime::upcoming, |
|
| 1042 | - $where_params_for_event |
|
| 1043 | - ) > 0) { |
|
| 1044 | - $this->_active_status = EE_Datetime::upcoming; |
|
| 1045 | - } else { |
|
| 1046 | - // expired? |
|
| 1047 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1048 | - EE_Datetime::expired, |
|
| 1049 | - $where_params_for_event |
|
| 1050 | - ) > 0 |
|
| 1051 | - ) { |
|
| 1052 | - $this->_active_status = EE_Datetime::expired; |
|
| 1053 | - } else { |
|
| 1054 | - // it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1055 | - // attached to the event. So in this case it will just be considered inactive. |
|
| 1056 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - } else { |
|
| 1061 | - // the event is not published, so let's just set it's active status according to its' post status |
|
| 1062 | - switch ($this->status()) { |
|
| 1063 | - case EEM_Event::sold_out: |
|
| 1064 | - $this->_active_status = EE_Datetime::sold_out; |
|
| 1065 | - break; |
|
| 1066 | - case EEM_Event::cancelled: |
|
| 1067 | - $this->_active_status = EE_Datetime::cancelled; |
|
| 1068 | - break; |
|
| 1069 | - case EEM_Event::postponed: |
|
| 1070 | - $this->_active_status = EE_Datetime::postponed; |
|
| 1071 | - break; |
|
| 1072 | - default: |
|
| 1073 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1074 | - } |
|
| 1075 | - } |
|
| 1076 | - return $this->_active_status; |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * pretty_active_status |
|
| 1082 | - * |
|
| 1083 | - * @access public |
|
| 1084 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1085 | - * @return mixed void|string |
|
| 1086 | - * @throws EE_Error |
|
| 1087 | - */ |
|
| 1088 | - public function pretty_active_status($echo = true) |
|
| 1089 | - { |
|
| 1090 | - $active_status = $this->get_active_status(); |
|
| 1091 | - $status = '<span class="ee-status event-active-status-' |
|
| 1092 | - . $active_status |
|
| 1093 | - . '">' |
|
| 1094 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1095 | - . '</span>'; |
|
| 1096 | - if ($echo) { |
|
| 1097 | - echo $status; |
|
| 1098 | - return ''; |
|
| 1099 | - } |
|
| 1100 | - return $status; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * @return bool|int |
|
| 1106 | - * @throws EE_Error |
|
| 1107 | - */ |
|
| 1108 | - public function get_number_of_tickets_sold() |
|
| 1109 | - { |
|
| 1110 | - $tkt_sold = 0; |
|
| 1111 | - if (! $this->ID()) { |
|
| 1112 | - return 0; |
|
| 1113 | - } |
|
| 1114 | - $datetimes = $this->datetimes(); |
|
| 1115 | - foreach ($datetimes as $datetime) { |
|
| 1116 | - if ($datetime instanceof EE_Datetime) { |
|
| 1117 | - $tkt_sold += $datetime->sold(); |
|
| 1118 | - } |
|
| 1119 | - } |
|
| 1120 | - return $tkt_sold; |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - |
|
| 1124 | - /** |
|
| 1125 | - * This just returns a count of all the registrations for this event |
|
| 1126 | - * |
|
| 1127 | - * @access public |
|
| 1128 | - * @return int |
|
| 1129 | - * @throws EE_Error |
|
| 1130 | - */ |
|
| 1131 | - public function get_count_of_all_registrations() |
|
| 1132 | - { |
|
| 1133 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * This returns the ticket with the earliest start time that is |
|
| 1139 | - * available for this event (across all datetimes attached to the event) |
|
| 1140 | - * |
|
| 1141 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1142 | - * @throws EE_Error |
|
| 1143 | - */ |
|
| 1144 | - public function get_ticket_with_earliest_start_time() |
|
| 1145 | - { |
|
| 1146 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1147 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1148 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * This returns the ticket with the latest end time that is available |
|
| 1154 | - * for this event (across all datetimes attached to the event) |
|
| 1155 | - * |
|
| 1156 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1157 | - * @throws EE_Error |
|
| 1158 | - */ |
|
| 1159 | - public function get_ticket_with_latest_end_time() |
|
| 1160 | - { |
|
| 1161 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1162 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1163 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1164 | - } |
|
| 1165 | - |
|
| 1166 | - |
|
| 1167 | - /** |
|
| 1168 | - * This returns the number of different ticket types currently on sale for this event. |
|
| 1169 | - * |
|
| 1170 | - * @return int |
|
| 1171 | - * @throws EE_Error |
|
| 1172 | - */ |
|
| 1173 | - public function countTicketsOnSale() |
|
| 1174 | - { |
|
| 1175 | - $where = array( |
|
| 1176 | - 'Datetime.EVT_ID' => $this->ID(), |
|
| 1177 | - 'TKT_start_date' => array('<', time()), |
|
| 1178 | - 'TKT_end_date' => array('>', time()), |
|
| 1179 | - ); |
|
| 1180 | - return EEM_Ticket::instance()->count(array($where)); |
|
| 1181 | - } |
|
| 1182 | - |
|
| 1183 | - |
|
| 1184 | - /** |
|
| 1185 | - * This returns whether there are any tickets on sale for this event. |
|
| 1186 | - * |
|
| 1187 | - * @return bool true = YES tickets on sale. |
|
| 1188 | - * @throws EE_Error |
|
| 1189 | - */ |
|
| 1190 | - public function tickets_on_sale() |
|
| 1191 | - { |
|
| 1192 | - return $this->countTicketsOnSale() > 0; |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1198 | - * to check for an external URL first |
|
| 1199 | - * |
|
| 1200 | - * @return string |
|
| 1201 | - * @throws EE_Error |
|
| 1202 | - */ |
|
| 1203 | - public function get_permalink() |
|
| 1204 | - { |
|
| 1205 | - if ($this->external_url()) { |
|
| 1206 | - return $this->external_url(); |
|
| 1207 | - } |
|
| 1208 | - return parent::get_permalink(); |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - |
|
| 1212 | - /** |
|
| 1213 | - * Gets the first term for 'espresso_event_categories' we can find |
|
| 1214 | - * |
|
| 1215 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1216 | - * @return EE_Base_Class|EE_Term|null |
|
| 1217 | - * @throws EE_Error |
|
| 1218 | - */ |
|
| 1219 | - public function first_event_category($query_params = array()) |
|
| 1220 | - { |
|
| 1221 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1222 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1223 | - return EEM_Term::instance()->get_one($query_params); |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - /** |
|
| 1228 | - * Gets all terms for 'espresso_event_categories' we can find |
|
| 1229 | - * |
|
| 1230 | - * @param array $query_params |
|
| 1231 | - * @return EE_Base_Class[]|EE_Term[] |
|
| 1232 | - * @throws EE_Error |
|
| 1233 | - */ |
|
| 1234 | - public function get_all_event_categories($query_params = array()) |
|
| 1235 | - { |
|
| 1236 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1237 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1238 | - return EEM_Term::instance()->get_all($query_params); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - /** |
|
| 1243 | - * Adds a question group to this event |
|
| 1244 | - * |
|
| 1245 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1246 | - * @param bool $for_primary if true, the question group will be added for the primary |
|
| 1247 | - * registrant, if false will be added for others. default: false |
|
| 1248 | - * @return EE_Base_Class|EE_Question_Group |
|
| 1249 | - * @throws EE_Error |
|
| 1250 | - * @throws InvalidArgumentException |
|
| 1251 | - * @throws InvalidDataTypeException |
|
| 1252 | - * @throws InvalidInterfaceException |
|
| 1253 | - * @throws ReflectionException |
|
| 1254 | - */ |
|
| 1255 | - public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1256 | - { |
|
| 1257 | - // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
| 1258 | - // That's in EE_HABTM_Relation::add_relation_to(). |
|
| 1259 | - return $this->_add_relation_to( |
|
| 1260 | - $question_group_id_or_obj, |
|
| 1261 | - 'Question_Group', |
|
| 1262 | - [ |
|
| 1263 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
| 1264 | - ] |
|
| 1265 | - ); |
|
| 1266 | - } |
|
| 1267 | - |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * Removes a question group from the event |
|
| 1271 | - * |
|
| 1272 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1273 | - * @param bool $for_primary if true, the question group will be removed from the primary |
|
| 1274 | - * registrant, if false will be removed from others. default: false |
|
| 1275 | - * @return EE_Base_Class|EE_Question_Group |
|
| 1276 | - * @throws EE_Error |
|
| 1277 | - * @throws InvalidArgumentException |
|
| 1278 | - * @throws ReflectionException |
|
| 1279 | - * @throws InvalidDataTypeException |
|
| 1280 | - * @throws InvalidInterfaceException |
|
| 1281 | - */ |
|
| 1282 | - public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1283 | - { |
|
| 1284 | - // If the question group is used for the other type (primary or additional) |
|
| 1285 | - // then just update it. If not, delete it outright. |
|
| 1286 | - $existing_relation = $this->get_first_related( |
|
| 1287 | - 'Event_Question_Group', |
|
| 1288 | - [ |
|
| 1289 | - [ |
|
| 1290 | - 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
| 1291 | - ] |
|
| 1292 | - ] |
|
| 1293 | - ); |
|
| 1294 | - $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
| 1295 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
| 1296 | - if ($existing_relation->get($other_field) === false) { |
|
| 1297 | - // Delete it. It's now no longer for primary or additional question groups. |
|
| 1298 | - return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
| 1299 | - } |
|
| 1300 | - // Just update it. They'll still use this question group for the other category |
|
| 1301 | - $existing_relation->save( |
|
| 1302 | - [ |
|
| 1303 | - $field_to_update => false |
|
| 1304 | - ] |
|
| 1305 | - ); |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1311 | - * |
|
| 1312 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1313 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1314 | - * @throws EE_Error |
|
| 1315 | - */ |
|
| 1316 | - public function question_groups($query_params = array()) |
|
| 1317 | - { |
|
| 1318 | - $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1319 | - return $this->get_many_related('Question_Group', $query_params); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - |
|
| 1323 | - /** |
|
| 1324 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1325 | - * |
|
| 1326 | - * @see EEI_Visual_Representation for comments |
|
| 1327 | - * @return string |
|
| 1328 | - */ |
|
| 1329 | - public function get_icon() |
|
| 1330 | - { |
|
| 1331 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - |
|
| 1335 | - /** |
|
| 1336 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1337 | - * |
|
| 1338 | - * @see EEI_Admin_Links for comments |
|
| 1339 | - * @return string |
|
| 1340 | - * @throws EE_Error |
|
| 1341 | - */ |
|
| 1342 | - public function get_admin_details_link() |
|
| 1343 | - { |
|
| 1344 | - return $this->get_admin_edit_link(); |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - |
|
| 1348 | - /** |
|
| 1349 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1350 | - * |
|
| 1351 | - * @see EEI_Admin_Links for comments |
|
| 1352 | - * @return string |
|
| 1353 | - * @throws EE_Error |
|
| 1354 | - */ |
|
| 1355 | - public function get_admin_edit_link() |
|
| 1356 | - { |
|
| 1357 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1358 | - array( |
|
| 1359 | - 'page' => 'espresso_events', |
|
| 1360 | - 'action' => 'edit', |
|
| 1361 | - 'post' => $this->ID(), |
|
| 1362 | - ), |
|
| 1363 | - admin_url('admin.php') |
|
| 1364 | - ); |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1370 | - * |
|
| 1371 | - * @see EEI_Admin_Links for comments |
|
| 1372 | - * @return string |
|
| 1373 | - */ |
|
| 1374 | - public function get_admin_settings_link() |
|
| 1375 | - { |
|
| 1376 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1377 | - array( |
|
| 1378 | - 'page' => 'espresso_events', |
|
| 1379 | - 'action' => 'default_event_settings', |
|
| 1380 | - ), |
|
| 1381 | - admin_url('admin.php') |
|
| 1382 | - ); |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - |
|
| 1386 | - /** |
|
| 1387 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1388 | - * |
|
| 1389 | - * @see EEI_Admin_Links for comments |
|
| 1390 | - * @return string |
|
| 1391 | - */ |
|
| 1392 | - public function get_admin_overview_link() |
|
| 1393 | - { |
|
| 1394 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1395 | - array( |
|
| 1396 | - 'page' => 'espresso_events', |
|
| 1397 | - 'action' => 'default', |
|
| 1398 | - ), |
|
| 1399 | - admin_url('admin.php') |
|
| 1400 | - ); |
|
| 1401 | - } |
|
| 18 | + /** |
|
| 19 | + * cached value for the the logical active status for the event |
|
| 20 | + * |
|
| 21 | + * @see get_active_status() |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $_active_status = ''; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 28 | + * |
|
| 29 | + * @var EE_Datetime |
|
| 30 | + */ |
|
| 31 | + protected $_Primary_Datetime; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
| 35 | + */ |
|
| 36 | + protected $available_spaces_calculator; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param array $props_n_values incoming values |
|
| 41 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 42 | + * used.) |
|
| 43 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 44 | + * date_format and the second value is the time format |
|
| 45 | + * @return EE_Event |
|
| 46 | + * @throws EE_Error |
|
| 47 | + */ |
|
| 48 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 49 | + { |
|
| 50 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 51 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param array $props_n_values incoming values from the database |
|
| 57 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 58 | + * the website will be used. |
|
| 59 | + * @return EE_Event |
|
| 60 | + * @throws EE_Error |
|
| 61 | + */ |
|
| 62 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 63 | + { |
|
| 64 | + return new self($props_n_values, true, $timezone); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return EventSpacesCalculator |
|
| 70 | + * @throws \EE_Error |
|
| 71 | + */ |
|
| 72 | + public function getAvailableSpacesCalculator() |
|
| 73 | + { |
|
| 74 | + if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 75 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 76 | + } |
|
| 77 | + return $this->available_spaces_calculator; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 83 | + * |
|
| 84 | + * @param string $field_name |
|
| 85 | + * @param mixed $field_value |
|
| 86 | + * @param bool $use_default |
|
| 87 | + * @throws EE_Error |
|
| 88 | + */ |
|
| 89 | + public function set($field_name, $field_value, $use_default = false) |
|
| 90 | + { |
|
| 91 | + switch ($field_name) { |
|
| 92 | + case 'status': |
|
| 93 | + $this->set_status($field_value, $use_default); |
|
| 94 | + break; |
|
| 95 | + default: |
|
| 96 | + parent::set($field_name, $field_value, $use_default); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * set_status |
|
| 103 | + * Checks if event status is being changed to SOLD OUT |
|
| 104 | + * and updates event meta data with previous event status |
|
| 105 | + * so that we can revert things if/when the event is no longer sold out |
|
| 106 | + * |
|
| 107 | + * @access public |
|
| 108 | + * @param string $new_status |
|
| 109 | + * @param bool $use_default |
|
| 110 | + * @return void |
|
| 111 | + * @throws EE_Error |
|
| 112 | + */ |
|
| 113 | + public function set_status($new_status = null, $use_default = false) |
|
| 114 | + { |
|
| 115 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 116 | + if (empty($new_status) && ! $use_default) { |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | + // get current Event status |
|
| 120 | + $old_status = $this->status(); |
|
| 121 | + // if status has changed |
|
| 122 | + if ($old_status !== $new_status) { |
|
| 123 | + // TO sold_out |
|
| 124 | + if ($new_status === EEM_Event::sold_out) { |
|
| 125 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
| 126 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
| 127 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 128 | + // OR FROM sold_out |
|
| 129 | + } elseif ($old_status === EEM_Event::sold_out) { |
|
| 130 | + $this->delete_post_meta('_previous_event_status'); |
|
| 131 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 132 | + } |
|
| 133 | + // clear out the active status so that it gets reset the next time it is requested |
|
| 134 | + $this->_active_status = null; |
|
| 135 | + // update status |
|
| 136 | + parent::set('status', $new_status, $use_default); |
|
| 137 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 138 | + return; |
|
| 139 | + } |
|
| 140 | + // even though the old value matches the new value, it's still good to |
|
| 141 | + // allow the parent set method to have a say |
|
| 142 | + parent::set('status', $new_status, $use_default); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Gets all the datetimes for this event |
|
| 148 | + * |
|
| 149 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 150 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 151 | + * @throws EE_Error |
|
| 152 | + */ |
|
| 153 | + public function datetimes($query_params = array()) |
|
| 154 | + { |
|
| 155 | + return $this->get_many_related('Datetime', $query_params); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 161 | + * |
|
| 162 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 163 | + * @throws EE_Error |
|
| 164 | + */ |
|
| 165 | + public function datetimes_in_chronological_order() |
|
| 166 | + { |
|
| 167 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 173 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 174 | + * after running our query, so that this timezone isn't set for EVERY query |
|
| 175 | + * on EEM_Datetime for the rest of the request, no? |
|
| 176 | + * |
|
| 177 | + * @param boolean $show_expired whether or not to include expired events |
|
| 178 | + * @param boolean $show_deleted whether or not to include deleted events |
|
| 179 | + * @param null $limit |
|
| 180 | + * @return EE_Datetime[] |
|
| 181 | + * @throws EE_Error |
|
| 182 | + */ |
|
| 183 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 184 | + { |
|
| 185 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 186 | + $this->ID(), |
|
| 187 | + $show_expired, |
|
| 188 | + $show_deleted, |
|
| 189 | + $limit |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
| 196 | + * |
|
| 197 | + * @return EE_Base_Class|EE_Datetime |
|
| 198 | + * @throws EE_Error |
|
| 199 | + */ |
|
| 200 | + public function first_datetime() |
|
| 201 | + { |
|
| 202 | + return $this->get_first_related('Datetime'); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Returns the 'primary' datetime for the event |
|
| 208 | + * |
|
| 209 | + * @param bool $try_to_exclude_expired |
|
| 210 | + * @param bool $try_to_exclude_deleted |
|
| 211 | + * @return EE_Datetime |
|
| 212 | + * @throws EE_Error |
|
| 213 | + */ |
|
| 214 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 215 | + { |
|
| 216 | + if (! empty($this->_Primary_Datetime)) { |
|
| 217 | + return $this->_Primary_Datetime; |
|
| 218 | + } |
|
| 219 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 220 | + $this->ID(), |
|
| 221 | + $try_to_exclude_expired, |
|
| 222 | + $try_to_exclude_deleted |
|
| 223 | + ); |
|
| 224 | + return $this->_Primary_Datetime; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Gets all the tickets available for purchase of this event |
|
| 230 | + * |
|
| 231 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 232 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 233 | + * @throws EE_Error |
|
| 234 | + */ |
|
| 235 | + public function tickets($query_params = array()) |
|
| 236 | + { |
|
| 237 | + // first get all datetimes |
|
| 238 | + $datetimes = $this->datetimes_ordered(); |
|
| 239 | + if (! $datetimes) { |
|
| 240 | + return array(); |
|
| 241 | + } |
|
| 242 | + $datetime_ids = array(); |
|
| 243 | + foreach ($datetimes as $datetime) { |
|
| 244 | + $datetime_ids[] = $datetime->ID(); |
|
| 245 | + } |
|
| 246 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 247 | + // if incoming $query_params has where conditions let's merge but not override existing. |
|
| 248 | + if (is_array($query_params) && isset($query_params[0])) { |
|
| 249 | + $where_params = array_merge($query_params[0], $where_params); |
|
| 250 | + unset($query_params[0]); |
|
| 251 | + } |
|
| 252 | + // now add $where_params to $query_params |
|
| 253 | + $query_params[0] = $where_params; |
|
| 254 | + return EEM_Ticket::instance()->get_all($query_params); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * get all unexpired untrashed tickets |
|
| 260 | + * |
|
| 261 | + * @return EE_Ticket[] |
|
| 262 | + * @throws EE_Error |
|
| 263 | + */ |
|
| 264 | + public function active_tickets() |
|
| 265 | + { |
|
| 266 | + return $this->tickets( |
|
| 267 | + array( |
|
| 268 | + array( |
|
| 269 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 270 | + 'TKT_deleted' => false, |
|
| 271 | + ), |
|
| 272 | + ) |
|
| 273 | + ); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @return bool |
|
| 279 | + * @throws EE_Error |
|
| 280 | + */ |
|
| 281 | + public function additional_limit() |
|
| 282 | + { |
|
| 283 | + return $this->get('EVT_additional_limit'); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @return bool |
|
| 289 | + * @throws EE_Error |
|
| 290 | + */ |
|
| 291 | + public function allow_overflow() |
|
| 292 | + { |
|
| 293 | + return $this->get('EVT_allow_overflow'); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @return bool |
|
| 299 | + * @throws EE_Error |
|
| 300 | + */ |
|
| 301 | + public function created() |
|
| 302 | + { |
|
| 303 | + return $this->get('EVT_created'); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @return bool |
|
| 309 | + * @throws EE_Error |
|
| 310 | + */ |
|
| 311 | + public function description() |
|
| 312 | + { |
|
| 313 | + return $this->get('EVT_desc'); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Runs do_shortcode and wpautop on the description |
|
| 319 | + * |
|
| 320 | + * @return string of html |
|
| 321 | + * @throws EE_Error |
|
| 322 | + */ |
|
| 323 | + public function description_filtered() |
|
| 324 | + { |
|
| 325 | + return $this->get_pretty('EVT_desc'); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * @return bool |
|
| 331 | + * @throws EE_Error |
|
| 332 | + */ |
|
| 333 | + public function display_description() |
|
| 334 | + { |
|
| 335 | + return $this->get('EVT_display_desc'); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @return bool |
|
| 341 | + * @throws EE_Error |
|
| 342 | + */ |
|
| 343 | + public function display_ticket_selector() |
|
| 344 | + { |
|
| 345 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * @return bool |
|
| 351 | + * @throws EE_Error |
|
| 352 | + */ |
|
| 353 | + public function external_url() |
|
| 354 | + { |
|
| 355 | + return $this->get('EVT_external_URL'); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * @return bool |
|
| 361 | + * @throws EE_Error |
|
| 362 | + */ |
|
| 363 | + public function member_only() |
|
| 364 | + { |
|
| 365 | + return $this->get('EVT_member_only'); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @return bool |
|
| 371 | + * @throws EE_Error |
|
| 372 | + */ |
|
| 373 | + public function phone() |
|
| 374 | + { |
|
| 375 | + return $this->get('EVT_phone'); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * @return bool |
|
| 381 | + * @throws EE_Error |
|
| 382 | + */ |
|
| 383 | + public function modified() |
|
| 384 | + { |
|
| 385 | + return $this->get('EVT_modified'); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * @return bool |
|
| 391 | + * @throws EE_Error |
|
| 392 | + */ |
|
| 393 | + public function name() |
|
| 394 | + { |
|
| 395 | + return $this->get('EVT_name'); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * @return bool |
|
| 401 | + * @throws EE_Error |
|
| 402 | + */ |
|
| 403 | + public function order() |
|
| 404 | + { |
|
| 405 | + return $this->get('EVT_order'); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * @return bool|string |
|
| 411 | + * @throws EE_Error |
|
| 412 | + */ |
|
| 413 | + public function default_registration_status() |
|
| 414 | + { |
|
| 415 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 416 | + return ! empty($event_default_registration_status) |
|
| 417 | + ? $event_default_registration_status |
|
| 418 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * @param int $num_words |
|
| 424 | + * @param null $more |
|
| 425 | + * @param bool $not_full_desc |
|
| 426 | + * @return bool|string |
|
| 427 | + * @throws EE_Error |
|
| 428 | + */ |
|
| 429 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 430 | + { |
|
| 431 | + $short_desc = $this->get('EVT_short_desc'); |
|
| 432 | + if (! empty($short_desc) || $not_full_desc) { |
|
| 433 | + return $short_desc; |
|
| 434 | + } |
|
| 435 | + $full_desc = $this->get('EVT_desc'); |
|
| 436 | + return wp_trim_words($full_desc, $num_words, $more); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @return bool |
|
| 442 | + * @throws EE_Error |
|
| 443 | + */ |
|
| 444 | + public function slug() |
|
| 445 | + { |
|
| 446 | + return $this->get('EVT_slug'); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * @return bool |
|
| 452 | + * @throws EE_Error |
|
| 453 | + */ |
|
| 454 | + public function timezone_string() |
|
| 455 | + { |
|
| 456 | + return $this->get('EVT_timezone_string'); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @return bool |
|
| 462 | + * @throws EE_Error |
|
| 463 | + */ |
|
| 464 | + public function visible_on() |
|
| 465 | + { |
|
| 466 | + return $this->get('EVT_visible_on'); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * @return int |
|
| 472 | + * @throws EE_Error |
|
| 473 | + */ |
|
| 474 | + public function wp_user() |
|
| 475 | + { |
|
| 476 | + return $this->get('EVT_wp_user'); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * @return bool |
|
| 482 | + * @throws EE_Error |
|
| 483 | + */ |
|
| 484 | + public function donations() |
|
| 485 | + { |
|
| 486 | + return $this->get('EVT_donations'); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @param $limit |
|
| 492 | + * @throws EE_Error |
|
| 493 | + */ |
|
| 494 | + public function set_additional_limit($limit) |
|
| 495 | + { |
|
| 496 | + $this->set('EVT_additional_limit', $limit); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * @param $created |
|
| 502 | + * @throws EE_Error |
|
| 503 | + */ |
|
| 504 | + public function set_created($created) |
|
| 505 | + { |
|
| 506 | + $this->set('EVT_created', $created); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * @param $desc |
|
| 512 | + * @throws EE_Error |
|
| 513 | + */ |
|
| 514 | + public function set_description($desc) |
|
| 515 | + { |
|
| 516 | + $this->set('EVT_desc', $desc); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * @param $display_desc |
|
| 522 | + * @throws EE_Error |
|
| 523 | + */ |
|
| 524 | + public function set_display_description($display_desc) |
|
| 525 | + { |
|
| 526 | + $this->set('EVT_display_desc', $display_desc); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * @param $display_ticket_selector |
|
| 532 | + * @throws EE_Error |
|
| 533 | + */ |
|
| 534 | + public function set_display_ticket_selector($display_ticket_selector) |
|
| 535 | + { |
|
| 536 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * @param $external_url |
|
| 542 | + * @throws EE_Error |
|
| 543 | + */ |
|
| 544 | + public function set_external_url($external_url) |
|
| 545 | + { |
|
| 546 | + $this->set('EVT_external_URL', $external_url); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * @param $member_only |
|
| 552 | + * @throws EE_Error |
|
| 553 | + */ |
|
| 554 | + public function set_member_only($member_only) |
|
| 555 | + { |
|
| 556 | + $this->set('EVT_member_only', $member_only); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * @param $event_phone |
|
| 562 | + * @throws EE_Error |
|
| 563 | + */ |
|
| 564 | + public function set_event_phone($event_phone) |
|
| 565 | + { |
|
| 566 | + $this->set('EVT_phone', $event_phone); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * @param $modified |
|
| 572 | + * @throws EE_Error |
|
| 573 | + */ |
|
| 574 | + public function set_modified($modified) |
|
| 575 | + { |
|
| 576 | + $this->set('EVT_modified', $modified); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * @param $name |
|
| 582 | + * @throws EE_Error |
|
| 583 | + */ |
|
| 584 | + public function set_name($name) |
|
| 585 | + { |
|
| 586 | + $this->set('EVT_name', $name); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * @param $order |
|
| 592 | + * @throws EE_Error |
|
| 593 | + */ |
|
| 594 | + public function set_order($order) |
|
| 595 | + { |
|
| 596 | + $this->set('EVT_order', $order); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * @param $short_desc |
|
| 602 | + * @throws EE_Error |
|
| 603 | + */ |
|
| 604 | + public function set_short_description($short_desc) |
|
| 605 | + { |
|
| 606 | + $this->set('EVT_short_desc', $short_desc); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * @param $slug |
|
| 612 | + * @throws EE_Error |
|
| 613 | + */ |
|
| 614 | + public function set_slug($slug) |
|
| 615 | + { |
|
| 616 | + $this->set('EVT_slug', $slug); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * @param $timezone_string |
|
| 622 | + * @throws EE_Error |
|
| 623 | + */ |
|
| 624 | + public function set_timezone_string($timezone_string) |
|
| 625 | + { |
|
| 626 | + $this->set('EVT_timezone_string', $timezone_string); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * @param $visible_on |
|
| 632 | + * @throws EE_Error |
|
| 633 | + */ |
|
| 634 | + public function set_visible_on($visible_on) |
|
| 635 | + { |
|
| 636 | + $this->set('EVT_visible_on', $visible_on); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * @param $wp_user |
|
| 642 | + * @throws EE_Error |
|
| 643 | + */ |
|
| 644 | + public function set_wp_user($wp_user) |
|
| 645 | + { |
|
| 646 | + $this->set('EVT_wp_user', $wp_user); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * @param $default_registration_status |
|
| 652 | + * @throws EE_Error |
|
| 653 | + */ |
|
| 654 | + public function set_default_registration_status($default_registration_status) |
|
| 655 | + { |
|
| 656 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * @param $donations |
|
| 662 | + * @throws EE_Error |
|
| 663 | + */ |
|
| 664 | + public function set_donations($donations) |
|
| 665 | + { |
|
| 666 | + $this->set('EVT_donations', $donations); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Adds a venue to this event |
|
| 672 | + * |
|
| 673 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 674 | + * @return EE_Base_Class|EE_Venue |
|
| 675 | + * @throws EE_Error |
|
| 676 | + */ |
|
| 677 | + public function add_venue($venue_id_or_obj) |
|
| 678 | + { |
|
| 679 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Removes a venue from the event |
|
| 685 | + * |
|
| 686 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 687 | + * @return EE_Base_Class|EE_Venue |
|
| 688 | + * @throws EE_Error |
|
| 689 | + */ |
|
| 690 | + public function remove_venue($venue_id_or_obj) |
|
| 691 | + { |
|
| 692 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
| 698 | + * |
|
| 699 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 700 | + * @return EE_Base_Class[]|EE_Venue[] |
|
| 701 | + * @throws EE_Error |
|
| 702 | + */ |
|
| 703 | + public function venues($query_params = array()) |
|
| 704 | + { |
|
| 705 | + return $this->get_many_related('Venue', $query_params); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * check if event id is present and if event is published |
|
| 711 | + * |
|
| 712 | + * @access public |
|
| 713 | + * @return boolean true yes, false no |
|
| 714 | + * @throws EE_Error |
|
| 715 | + */ |
|
| 716 | + private function _has_ID_and_is_published() |
|
| 717 | + { |
|
| 718 | + // first check if event id is present and not NULL, |
|
| 719 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 720 | + return |
|
| 721 | + $this->ID() && $this->ID() !== null |
|
| 722 | + && ( |
|
| 723 | + $this->status() === 'publish' |
|
| 724 | + || $this->status() === EEM_Event::sold_out |
|
| 725 | + || $this->status() === EEM_Event::postponed |
|
| 726 | + || $this->status() === EEM_Event::cancelled |
|
| 727 | + ); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 733 | + * |
|
| 734 | + * @access public |
|
| 735 | + * @return boolean true yes, false no |
|
| 736 | + * @throws EE_Error |
|
| 737 | + */ |
|
| 738 | + public function is_upcoming() |
|
| 739 | + { |
|
| 740 | + // check if event id is present and if this event is published |
|
| 741 | + if ($this->is_inactive()) { |
|
| 742 | + return false; |
|
| 743 | + } |
|
| 744 | + // set initial value |
|
| 745 | + $upcoming = false; |
|
| 746 | + // next let's get all datetimes and loop through them |
|
| 747 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 748 | + foreach ($datetimes as $datetime) { |
|
| 749 | + if ($datetime instanceof EE_Datetime) { |
|
| 750 | + // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 751 | + if ($datetime->is_expired()) { |
|
| 752 | + continue; |
|
| 753 | + } |
|
| 754 | + // if this dtt is active then we return false. |
|
| 755 | + if ($datetime->is_active()) { |
|
| 756 | + return false; |
|
| 757 | + } |
|
| 758 | + // otherwise let's check upcoming status |
|
| 759 | + $upcoming = $datetime->is_upcoming(); |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + return $upcoming; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * @return bool |
|
| 768 | + * @throws EE_Error |
|
| 769 | + */ |
|
| 770 | + public function is_active() |
|
| 771 | + { |
|
| 772 | + // check if event id is present and if this event is published |
|
| 773 | + if ($this->is_inactive()) { |
|
| 774 | + return false; |
|
| 775 | + } |
|
| 776 | + // set initial value |
|
| 777 | + $active = false; |
|
| 778 | + // next let's get all datetimes and loop through them |
|
| 779 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 780 | + foreach ($datetimes as $datetime) { |
|
| 781 | + if ($datetime instanceof EE_Datetime) { |
|
| 782 | + // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 783 | + if ($datetime->is_expired()) { |
|
| 784 | + continue; |
|
| 785 | + } |
|
| 786 | + // if this dtt is upcoming then we return false. |
|
| 787 | + if ($datetime->is_upcoming()) { |
|
| 788 | + return false; |
|
| 789 | + } |
|
| 790 | + // otherwise let's check active status |
|
| 791 | + $active = $datetime->is_active(); |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + return $active; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * @return bool |
|
| 800 | + * @throws EE_Error |
|
| 801 | + */ |
|
| 802 | + public function is_expired() |
|
| 803 | + { |
|
| 804 | + // check if event id is present and if this event is published |
|
| 805 | + if ($this->is_inactive()) { |
|
| 806 | + return false; |
|
| 807 | + } |
|
| 808 | + // set initial value |
|
| 809 | + $expired = false; |
|
| 810 | + // first let's get all datetimes and loop through them |
|
| 811 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 812 | + foreach ($datetimes as $datetime) { |
|
| 813 | + if ($datetime instanceof EE_Datetime) { |
|
| 814 | + // if this dtt is upcoming or active then we return false. |
|
| 815 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 816 | + return false; |
|
| 817 | + } |
|
| 818 | + // otherwise let's check active status |
|
| 819 | + $expired = $datetime->is_expired(); |
|
| 820 | + } |
|
| 821 | + } |
|
| 822 | + return $expired; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * @return bool |
|
| 828 | + * @throws EE_Error |
|
| 829 | + */ |
|
| 830 | + public function is_inactive() |
|
| 831 | + { |
|
| 832 | + // check if event id is present and if this event is published |
|
| 833 | + if ($this->_has_ID_and_is_published()) { |
|
| 834 | + return false; |
|
| 835 | + } |
|
| 836 | + return true; |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * calculate spaces remaining based on "saleable" tickets |
|
| 842 | + * |
|
| 843 | + * @param array $tickets |
|
| 844 | + * @param bool $filtered |
|
| 845 | + * @return int|float |
|
| 846 | + * @throws EE_Error |
|
| 847 | + * @throws DomainException |
|
| 848 | + * @throws UnexpectedEntityException |
|
| 849 | + */ |
|
| 850 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 851 | + { |
|
| 852 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 853 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 854 | + return $filtered |
|
| 855 | + ? apply_filters( |
|
| 856 | + 'FHEE_EE_Event__spaces_remaining', |
|
| 857 | + $spaces_remaining, |
|
| 858 | + $this, |
|
| 859 | + $tickets |
|
| 860 | + ) |
|
| 861 | + : $spaces_remaining; |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * perform_sold_out_status_check |
|
| 867 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
| 868 | + * available... if NOT, then the event status will get toggled to 'sold_out' |
|
| 869 | + * |
|
| 870 | + * @return bool return the ACTUAL sold out state. |
|
| 871 | + * @throws EE_Error |
|
| 872 | + * @throws DomainException |
|
| 873 | + * @throws UnexpectedEntityException |
|
| 874 | + */ |
|
| 875 | + public function perform_sold_out_status_check() |
|
| 876 | + { |
|
| 877 | + // get all tickets |
|
| 878 | + $tickets = $this->tickets( |
|
| 879 | + array( |
|
| 880 | + 'default_where_conditions' => 'none', |
|
| 881 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 882 | + ) |
|
| 883 | + ); |
|
| 884 | + $all_expired = true; |
|
| 885 | + foreach ($tickets as $ticket) { |
|
| 886 | + if (! $ticket->is_expired()) { |
|
| 887 | + $all_expired = false; |
|
| 888 | + break; |
|
| 889 | + } |
|
| 890 | + } |
|
| 891 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
| 892 | + if ($all_expired) { |
|
| 893 | + return true; |
|
| 894 | + } |
|
| 895 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 896 | + if ($spaces_remaining < 1) { |
|
| 897 | + if ($this->status() !== EEM_Event::post_status_private) { |
|
| 898 | + $this->set_status(EEM_Event::sold_out); |
|
| 899 | + $this->save(); |
|
| 900 | + } |
|
| 901 | + $sold_out = true; |
|
| 902 | + } else { |
|
| 903 | + $sold_out = false; |
|
| 904 | + // was event previously marked as sold out ? |
|
| 905 | + if ($this->status() === EEM_Event::sold_out) { |
|
| 906 | + // revert status to previous value, if it was set |
|
| 907 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 908 | + if ($previous_event_status) { |
|
| 909 | + $this->set_status($previous_event_status); |
|
| 910 | + $this->save(); |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 915 | + return $sold_out; |
|
| 916 | + } |
|
| 917 | + |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * This returns the total remaining spaces for sale on this event. |
|
| 921 | + * |
|
| 922 | + * @uses EE_Event::total_available_spaces() |
|
| 923 | + * @return float|int |
|
| 924 | + * @throws EE_Error |
|
| 925 | + * @throws DomainException |
|
| 926 | + * @throws UnexpectedEntityException |
|
| 927 | + */ |
|
| 928 | + public function spaces_remaining_for_sale() |
|
| 929 | + { |
|
| 930 | + return $this->total_available_spaces(true); |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * This returns the total spaces available for an event |
|
| 936 | + * while considering all the qtys on the tickets and the reg limits |
|
| 937 | + * on the datetimes attached to this event. |
|
| 938 | + * |
|
| 939 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 940 | + * If this is false, then we return the most tickets that could ever be sold |
|
| 941 | + * for this event with the datetime and tickets setup on the event under optimal |
|
| 942 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 943 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
| 944 | + * may appear to equal remaining tickets. However, the more tickets are |
|
| 945 | + * sold out, the more accurate the "live" total is. |
|
| 946 | + * @return float|int |
|
| 947 | + * @throws EE_Error |
|
| 948 | + * @throws DomainException |
|
| 949 | + * @throws UnexpectedEntityException |
|
| 950 | + */ |
|
| 951 | + public function total_available_spaces($consider_sold = false) |
|
| 952 | + { |
|
| 953 | + $spaces_available = $consider_sold |
|
| 954 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 955 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 956 | + return apply_filters( |
|
| 957 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 958 | + $spaces_available, |
|
| 959 | + $this, |
|
| 960 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 961 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 962 | + ); |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * Checks if the event is set to sold out |
|
| 968 | + * |
|
| 969 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 970 | + * actual status but also to flip the status if necessary to sold |
|
| 971 | + * out If false, we just check the existing status of the event |
|
| 972 | + * @return boolean |
|
| 973 | + * @throws EE_Error |
|
| 974 | + */ |
|
| 975 | + public function is_sold_out($actual = false) |
|
| 976 | + { |
|
| 977 | + if (! $actual) { |
|
| 978 | + return $this->status() === EEM_Event::sold_out; |
|
| 979 | + } |
|
| 980 | + return $this->perform_sold_out_status_check(); |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + /** |
|
| 985 | + * Checks if the event is marked as postponed |
|
| 986 | + * |
|
| 987 | + * @return boolean |
|
| 988 | + */ |
|
| 989 | + public function is_postponed() |
|
| 990 | + { |
|
| 991 | + return $this->status() === EEM_Event::postponed; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * Checks if the event is marked as cancelled |
|
| 997 | + * |
|
| 998 | + * @return boolean |
|
| 999 | + */ |
|
| 1000 | + public function is_cancelled() |
|
| 1001 | + { |
|
| 1002 | + return $this->status() === EEM_Event::cancelled; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 1008 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 1009 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 1010 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1011 | + * the event is considered expired. |
|
| 1012 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
| 1013 | + * status set on the EVENT when it is not published and thus is done |
|
| 1014 | + * |
|
| 1015 | + * @param bool $reset |
|
| 1016 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1017 | + * @throws EE_Error |
|
| 1018 | + */ |
|
| 1019 | + public function get_active_status($reset = false) |
|
| 1020 | + { |
|
| 1021 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1022 | + if (! empty($this->_active_status) && ! $reset) { |
|
| 1023 | + return $this->_active_status; |
|
| 1024 | + } |
|
| 1025 | + // first check if event id is present on this object |
|
| 1026 | + if (! $this->ID()) { |
|
| 1027 | + return false; |
|
| 1028 | + } |
|
| 1029 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1030 | + // if event is published: |
|
| 1031 | + if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
| 1032 | + // active? |
|
| 1033 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1034 | + EE_Datetime::active, |
|
| 1035 | + $where_params_for_event |
|
| 1036 | + ) > 0) { |
|
| 1037 | + $this->_active_status = EE_Datetime::active; |
|
| 1038 | + } else { |
|
| 1039 | + // upcoming? |
|
| 1040 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1041 | + EE_Datetime::upcoming, |
|
| 1042 | + $where_params_for_event |
|
| 1043 | + ) > 0) { |
|
| 1044 | + $this->_active_status = EE_Datetime::upcoming; |
|
| 1045 | + } else { |
|
| 1046 | + // expired? |
|
| 1047 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1048 | + EE_Datetime::expired, |
|
| 1049 | + $where_params_for_event |
|
| 1050 | + ) > 0 |
|
| 1051 | + ) { |
|
| 1052 | + $this->_active_status = EE_Datetime::expired; |
|
| 1053 | + } else { |
|
| 1054 | + // it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1055 | + // attached to the event. So in this case it will just be considered inactive. |
|
| 1056 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + } else { |
|
| 1061 | + // the event is not published, so let's just set it's active status according to its' post status |
|
| 1062 | + switch ($this->status()) { |
|
| 1063 | + case EEM_Event::sold_out: |
|
| 1064 | + $this->_active_status = EE_Datetime::sold_out; |
|
| 1065 | + break; |
|
| 1066 | + case EEM_Event::cancelled: |
|
| 1067 | + $this->_active_status = EE_Datetime::cancelled; |
|
| 1068 | + break; |
|
| 1069 | + case EEM_Event::postponed: |
|
| 1070 | + $this->_active_status = EE_Datetime::postponed; |
|
| 1071 | + break; |
|
| 1072 | + default: |
|
| 1073 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1074 | + } |
|
| 1075 | + } |
|
| 1076 | + return $this->_active_status; |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * pretty_active_status |
|
| 1082 | + * |
|
| 1083 | + * @access public |
|
| 1084 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1085 | + * @return mixed void|string |
|
| 1086 | + * @throws EE_Error |
|
| 1087 | + */ |
|
| 1088 | + public function pretty_active_status($echo = true) |
|
| 1089 | + { |
|
| 1090 | + $active_status = $this->get_active_status(); |
|
| 1091 | + $status = '<span class="ee-status event-active-status-' |
|
| 1092 | + . $active_status |
|
| 1093 | + . '">' |
|
| 1094 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1095 | + . '</span>'; |
|
| 1096 | + if ($echo) { |
|
| 1097 | + echo $status; |
|
| 1098 | + return ''; |
|
| 1099 | + } |
|
| 1100 | + return $status; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * @return bool|int |
|
| 1106 | + * @throws EE_Error |
|
| 1107 | + */ |
|
| 1108 | + public function get_number_of_tickets_sold() |
|
| 1109 | + { |
|
| 1110 | + $tkt_sold = 0; |
|
| 1111 | + if (! $this->ID()) { |
|
| 1112 | + return 0; |
|
| 1113 | + } |
|
| 1114 | + $datetimes = $this->datetimes(); |
|
| 1115 | + foreach ($datetimes as $datetime) { |
|
| 1116 | + if ($datetime instanceof EE_Datetime) { |
|
| 1117 | + $tkt_sold += $datetime->sold(); |
|
| 1118 | + } |
|
| 1119 | + } |
|
| 1120 | + return $tkt_sold; |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + |
|
| 1124 | + /** |
|
| 1125 | + * This just returns a count of all the registrations for this event |
|
| 1126 | + * |
|
| 1127 | + * @access public |
|
| 1128 | + * @return int |
|
| 1129 | + * @throws EE_Error |
|
| 1130 | + */ |
|
| 1131 | + public function get_count_of_all_registrations() |
|
| 1132 | + { |
|
| 1133 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * This returns the ticket with the earliest start time that is |
|
| 1139 | + * available for this event (across all datetimes attached to the event) |
|
| 1140 | + * |
|
| 1141 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1142 | + * @throws EE_Error |
|
| 1143 | + */ |
|
| 1144 | + public function get_ticket_with_earliest_start_time() |
|
| 1145 | + { |
|
| 1146 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1147 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1148 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * This returns the ticket with the latest end time that is available |
|
| 1154 | + * for this event (across all datetimes attached to the event) |
|
| 1155 | + * |
|
| 1156 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1157 | + * @throws EE_Error |
|
| 1158 | + */ |
|
| 1159 | + public function get_ticket_with_latest_end_time() |
|
| 1160 | + { |
|
| 1161 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1162 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1163 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1164 | + } |
|
| 1165 | + |
|
| 1166 | + |
|
| 1167 | + /** |
|
| 1168 | + * This returns the number of different ticket types currently on sale for this event. |
|
| 1169 | + * |
|
| 1170 | + * @return int |
|
| 1171 | + * @throws EE_Error |
|
| 1172 | + */ |
|
| 1173 | + public function countTicketsOnSale() |
|
| 1174 | + { |
|
| 1175 | + $where = array( |
|
| 1176 | + 'Datetime.EVT_ID' => $this->ID(), |
|
| 1177 | + 'TKT_start_date' => array('<', time()), |
|
| 1178 | + 'TKT_end_date' => array('>', time()), |
|
| 1179 | + ); |
|
| 1180 | + return EEM_Ticket::instance()->count(array($where)); |
|
| 1181 | + } |
|
| 1182 | + |
|
| 1183 | + |
|
| 1184 | + /** |
|
| 1185 | + * This returns whether there are any tickets on sale for this event. |
|
| 1186 | + * |
|
| 1187 | + * @return bool true = YES tickets on sale. |
|
| 1188 | + * @throws EE_Error |
|
| 1189 | + */ |
|
| 1190 | + public function tickets_on_sale() |
|
| 1191 | + { |
|
| 1192 | + return $this->countTicketsOnSale() > 0; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1198 | + * to check for an external URL first |
|
| 1199 | + * |
|
| 1200 | + * @return string |
|
| 1201 | + * @throws EE_Error |
|
| 1202 | + */ |
|
| 1203 | + public function get_permalink() |
|
| 1204 | + { |
|
| 1205 | + if ($this->external_url()) { |
|
| 1206 | + return $this->external_url(); |
|
| 1207 | + } |
|
| 1208 | + return parent::get_permalink(); |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + |
|
| 1212 | + /** |
|
| 1213 | + * Gets the first term for 'espresso_event_categories' we can find |
|
| 1214 | + * |
|
| 1215 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1216 | + * @return EE_Base_Class|EE_Term|null |
|
| 1217 | + * @throws EE_Error |
|
| 1218 | + */ |
|
| 1219 | + public function first_event_category($query_params = array()) |
|
| 1220 | + { |
|
| 1221 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1222 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1223 | + return EEM_Term::instance()->get_one($query_params); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * Gets all terms for 'espresso_event_categories' we can find |
|
| 1229 | + * |
|
| 1230 | + * @param array $query_params |
|
| 1231 | + * @return EE_Base_Class[]|EE_Term[] |
|
| 1232 | + * @throws EE_Error |
|
| 1233 | + */ |
|
| 1234 | + public function get_all_event_categories($query_params = array()) |
|
| 1235 | + { |
|
| 1236 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1237 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1238 | + return EEM_Term::instance()->get_all($query_params); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + /** |
|
| 1243 | + * Adds a question group to this event |
|
| 1244 | + * |
|
| 1245 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1246 | + * @param bool $for_primary if true, the question group will be added for the primary |
|
| 1247 | + * registrant, if false will be added for others. default: false |
|
| 1248 | + * @return EE_Base_Class|EE_Question_Group |
|
| 1249 | + * @throws EE_Error |
|
| 1250 | + * @throws InvalidArgumentException |
|
| 1251 | + * @throws InvalidDataTypeException |
|
| 1252 | + * @throws InvalidInterfaceException |
|
| 1253 | + * @throws ReflectionException |
|
| 1254 | + */ |
|
| 1255 | + public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1256 | + { |
|
| 1257 | + // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
| 1258 | + // That's in EE_HABTM_Relation::add_relation_to(). |
|
| 1259 | + return $this->_add_relation_to( |
|
| 1260 | + $question_group_id_or_obj, |
|
| 1261 | + 'Question_Group', |
|
| 1262 | + [ |
|
| 1263 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
| 1264 | + ] |
|
| 1265 | + ); |
|
| 1266 | + } |
|
| 1267 | + |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * Removes a question group from the event |
|
| 1271 | + * |
|
| 1272 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1273 | + * @param bool $for_primary if true, the question group will be removed from the primary |
|
| 1274 | + * registrant, if false will be removed from others. default: false |
|
| 1275 | + * @return EE_Base_Class|EE_Question_Group |
|
| 1276 | + * @throws EE_Error |
|
| 1277 | + * @throws InvalidArgumentException |
|
| 1278 | + * @throws ReflectionException |
|
| 1279 | + * @throws InvalidDataTypeException |
|
| 1280 | + * @throws InvalidInterfaceException |
|
| 1281 | + */ |
|
| 1282 | + public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1283 | + { |
|
| 1284 | + // If the question group is used for the other type (primary or additional) |
|
| 1285 | + // then just update it. If not, delete it outright. |
|
| 1286 | + $existing_relation = $this->get_first_related( |
|
| 1287 | + 'Event_Question_Group', |
|
| 1288 | + [ |
|
| 1289 | + [ |
|
| 1290 | + 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
| 1291 | + ] |
|
| 1292 | + ] |
|
| 1293 | + ); |
|
| 1294 | + $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
| 1295 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
| 1296 | + if ($existing_relation->get($other_field) === false) { |
|
| 1297 | + // Delete it. It's now no longer for primary or additional question groups. |
|
| 1298 | + return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
| 1299 | + } |
|
| 1300 | + // Just update it. They'll still use this question group for the other category |
|
| 1301 | + $existing_relation->save( |
|
| 1302 | + [ |
|
| 1303 | + $field_to_update => false |
|
| 1304 | + ] |
|
| 1305 | + ); |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1311 | + * |
|
| 1312 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1313 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1314 | + * @throws EE_Error |
|
| 1315 | + */ |
|
| 1316 | + public function question_groups($query_params = array()) |
|
| 1317 | + { |
|
| 1318 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1319 | + return $this->get_many_related('Question_Group', $query_params); |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + |
|
| 1323 | + /** |
|
| 1324 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1325 | + * |
|
| 1326 | + * @see EEI_Visual_Representation for comments |
|
| 1327 | + * @return string |
|
| 1328 | + */ |
|
| 1329 | + public function get_icon() |
|
| 1330 | + { |
|
| 1331 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + |
|
| 1335 | + /** |
|
| 1336 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1337 | + * |
|
| 1338 | + * @see EEI_Admin_Links for comments |
|
| 1339 | + * @return string |
|
| 1340 | + * @throws EE_Error |
|
| 1341 | + */ |
|
| 1342 | + public function get_admin_details_link() |
|
| 1343 | + { |
|
| 1344 | + return $this->get_admin_edit_link(); |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + |
|
| 1348 | + /** |
|
| 1349 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1350 | + * |
|
| 1351 | + * @see EEI_Admin_Links for comments |
|
| 1352 | + * @return string |
|
| 1353 | + * @throws EE_Error |
|
| 1354 | + */ |
|
| 1355 | + public function get_admin_edit_link() |
|
| 1356 | + { |
|
| 1357 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1358 | + array( |
|
| 1359 | + 'page' => 'espresso_events', |
|
| 1360 | + 'action' => 'edit', |
|
| 1361 | + 'post' => $this->ID(), |
|
| 1362 | + ), |
|
| 1363 | + admin_url('admin.php') |
|
| 1364 | + ); |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1370 | + * |
|
| 1371 | + * @see EEI_Admin_Links for comments |
|
| 1372 | + * @return string |
|
| 1373 | + */ |
|
| 1374 | + public function get_admin_settings_link() |
|
| 1375 | + { |
|
| 1376 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1377 | + array( |
|
| 1378 | + 'page' => 'espresso_events', |
|
| 1379 | + 'action' => 'default_event_settings', |
|
| 1380 | + ), |
|
| 1381 | + admin_url('admin.php') |
|
| 1382 | + ); |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + |
|
| 1386 | + /** |
|
| 1387 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1388 | + * |
|
| 1389 | + * @see EEI_Admin_Links for comments |
|
| 1390 | + * @return string |
|
| 1391 | + */ |
|
| 1392 | + public function get_admin_overview_link() |
|
| 1393 | + { |
|
| 1394 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1395 | + array( |
|
| 1396 | + 'page' => 'espresso_events', |
|
| 1397 | + 'action' => 'default', |
|
| 1398 | + ), |
|
| 1399 | + admin_url('admin.php') |
|
| 1400 | + ); |
|
| 1401 | + } |
|
| 1402 | 1402 | } |
@@ -18,184 +18,184 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class EE_Registration_Custom_Questions_Form extends EE_Form_Section_Proper |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * |
|
| 23 | - * @var EE_Registration |
|
| 24 | - */ |
|
| 25 | - protected $_registration = null; |
|
| 21 | + /** |
|
| 22 | + * |
|
| 23 | + * @var EE_Registration |
|
| 24 | + */ |
|
| 25 | + protected $_registration = null; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - * @param EE_Registration $reg |
|
| 30 | - * @param array $options |
|
| 31 | - */ |
|
| 32 | - public function __construct(EE_Registration $reg, $options = array()) |
|
| 33 | - { |
|
| 34 | - $this->_registration = $reg; |
|
| 35 | - if (! isset($options['layout_strategy'])) { |
|
| 36 | - $options['layout_strategy'] = new EE_Admin_Two_Column_Layout(); |
|
| 37 | - } |
|
| 38 | - if (! isset($options['html_id'])) { |
|
| 39 | - $options['html_id'] = 'reg-admin-attendee-questions-frm'; |
|
| 40 | - } |
|
| 41 | - $this->build_form_from_registration(); |
|
| 42 | - parent::__construct($options); |
|
| 43 | - } |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + * @param EE_Registration $reg |
|
| 30 | + * @param array $options |
|
| 31 | + */ |
|
| 32 | + public function __construct(EE_Registration $reg, $options = array()) |
|
| 33 | + { |
|
| 34 | + $this->_registration = $reg; |
|
| 35 | + if (! isset($options['layout_strategy'])) { |
|
| 36 | + $options['layout_strategy'] = new EE_Admin_Two_Column_Layout(); |
|
| 37 | + } |
|
| 38 | + if (! isset($options['html_id'])) { |
|
| 39 | + $options['html_id'] = 'reg-admin-attendee-questions-frm'; |
|
| 40 | + } |
|
| 41 | + $this->build_form_from_registration(); |
|
| 42 | + parent::__construct($options); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Gets the registration object this form is about |
|
| 48 | - * @return EE_Registration |
|
| 49 | - */ |
|
| 50 | - public function get_registration() |
|
| 51 | - { |
|
| 52 | - return $this->_registration; |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * Gets the registration object this form is about |
|
| 48 | + * @return EE_Registration |
|
| 49 | + */ |
|
| 50 | + public function get_registration() |
|
| 51 | + { |
|
| 52 | + return $this->_registration; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @since $VID:$ |
|
| 57 | - * @throws EE_Error |
|
| 58 | - * @throws InvalidArgumentException |
|
| 59 | - * @throws ReflectionException |
|
| 60 | - * @throws InvalidDataTypeException |
|
| 61 | - * @throws InvalidInterfaceException |
|
| 62 | - */ |
|
| 63 | - public function build_form_from_registration() |
|
| 64 | - { |
|
| 65 | - $reg = $this->get_registration(); |
|
| 66 | - if (! $reg instanceof EE_Registration) { |
|
| 67 | - throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso')); |
|
| 68 | - } |
|
| 69 | - // we want to get all their question groups |
|
| 70 | - $question_groups = EEM_Question_Group::instance()->get_all( |
|
| 71 | - [ |
|
| 72 | - [ |
|
| 73 | - 'Event_Question_Group.EVT_ID' => $reg->event_ID(), |
|
| 74 | - 'OR' => [ |
|
| 75 | - 'Question.QST_system*blank' => '', |
|
| 76 | - 'Question.QST_system*null' => ['IS_NULL'] |
|
| 77 | - ], |
|
| 78 | - 'Event_Question_Group.' |
|
| 79 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
| 80 | - $reg->is_primary_registrant() |
|
| 81 | - ) => true |
|
| 82 | - ], |
|
| 83 | - 'order_by' => ['QSG_order' => 'ASC'] |
|
| 84 | - ] |
|
| 85 | - ); |
|
| 86 | - // get each question groups questions |
|
| 87 | - foreach ($question_groups as $question_group) { |
|
| 88 | - if ($question_group instanceof EE_Question_Group) { |
|
| 89 | - $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group( |
|
| 90 | - $question_group, |
|
| 91 | - $reg |
|
| 92 | - ); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 55 | + /** |
|
| 56 | + * @since $VID:$ |
|
| 57 | + * @throws EE_Error |
|
| 58 | + * @throws InvalidArgumentException |
|
| 59 | + * @throws ReflectionException |
|
| 60 | + * @throws InvalidDataTypeException |
|
| 61 | + * @throws InvalidInterfaceException |
|
| 62 | + */ |
|
| 63 | + public function build_form_from_registration() |
|
| 64 | + { |
|
| 65 | + $reg = $this->get_registration(); |
|
| 66 | + if (! $reg instanceof EE_Registration) { |
|
| 67 | + throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso')); |
|
| 68 | + } |
|
| 69 | + // we want to get all their question groups |
|
| 70 | + $question_groups = EEM_Question_Group::instance()->get_all( |
|
| 71 | + [ |
|
| 72 | + [ |
|
| 73 | + 'Event_Question_Group.EVT_ID' => $reg->event_ID(), |
|
| 74 | + 'OR' => [ |
|
| 75 | + 'Question.QST_system*blank' => '', |
|
| 76 | + 'Question.QST_system*null' => ['IS_NULL'] |
|
| 77 | + ], |
|
| 78 | + 'Event_Question_Group.' |
|
| 79 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
| 80 | + $reg->is_primary_registrant() |
|
| 81 | + ) => true |
|
| 82 | + ], |
|
| 83 | + 'order_by' => ['QSG_order' => 'ASC'] |
|
| 84 | + ] |
|
| 85 | + ); |
|
| 86 | + // get each question groups questions |
|
| 87 | + foreach ($question_groups as $question_group) { |
|
| 88 | + if ($question_group instanceof EE_Question_Group) { |
|
| 89 | + $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group( |
|
| 90 | + $question_group, |
|
| 91 | + $reg |
|
| 92 | + ); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * |
|
| 101 | - * @param EE_Question_Group $question_group |
|
| 102 | - * @param EE_Registration $registration |
|
| 103 | - * @return \EE_Form_Section_Proper |
|
| 104 | - * @throws \EE_Error |
|
| 105 | - */ |
|
| 106 | - public function build_subform_from_question_group($question_group, $registration) |
|
| 107 | - { |
|
| 108 | - if (! $question_group instanceof EE_Question_Group || |
|
| 109 | - ! $registration instanceof EE_Registration) { |
|
| 110 | - throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso')); |
|
| 111 | - } |
|
| 112 | - $parts_of_subsection = array( |
|
| 113 | - 'title' => new EE_Form_Section_HTML( |
|
| 114 | - EEH_HTML::h5( |
|
| 115 | - $question_group->name(), |
|
| 116 | - $question_group->identifier(), |
|
| 117 | - 'espresso-question-group-title-h5 section-title' |
|
| 118 | - ) |
|
| 119 | - ) |
|
| 120 | - ); |
|
| 121 | - $questions = $question_group->questions( |
|
| 122 | - array( |
|
| 123 | - array( |
|
| 124 | - 'OR' => array( |
|
| 125 | - 'QST_system*blank' => '', |
|
| 126 | - 'QST_system*null' => array( 'IS_NULL' ) |
|
| 127 | - ) |
|
| 128 | - ) |
|
| 129 | - ) |
|
| 130 | - ); |
|
| 131 | - foreach ($questions as $question) { |
|
| 132 | - $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration); |
|
| 133 | - } |
|
| 134 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 135 | - 'ee_edit_registration', |
|
| 136 | - 'edit-reg-questions-mbox', |
|
| 137 | - $this->_registration->ID() |
|
| 138 | - )) { |
|
| 139 | - $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML( |
|
| 140 | - EEH_HTML::table( |
|
| 141 | - EEH_HTML::tr( |
|
| 142 | - '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '"> |
|
| 99 | + /** |
|
| 100 | + * |
|
| 101 | + * @param EE_Question_Group $question_group |
|
| 102 | + * @param EE_Registration $registration |
|
| 103 | + * @return \EE_Form_Section_Proper |
|
| 104 | + * @throws \EE_Error |
|
| 105 | + */ |
|
| 106 | + public function build_subform_from_question_group($question_group, $registration) |
|
| 107 | + { |
|
| 108 | + if (! $question_group instanceof EE_Question_Group || |
|
| 109 | + ! $registration instanceof EE_Registration) { |
|
| 110 | + throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso')); |
|
| 111 | + } |
|
| 112 | + $parts_of_subsection = array( |
|
| 113 | + 'title' => new EE_Form_Section_HTML( |
|
| 114 | + EEH_HTML::h5( |
|
| 115 | + $question_group->name(), |
|
| 116 | + $question_group->identifier(), |
|
| 117 | + 'espresso-question-group-title-h5 section-title' |
|
| 118 | + ) |
|
| 119 | + ) |
|
| 120 | + ); |
|
| 121 | + $questions = $question_group->questions( |
|
| 122 | + array( |
|
| 123 | + array( |
|
| 124 | + 'OR' => array( |
|
| 125 | + 'QST_system*blank' => '', |
|
| 126 | + 'QST_system*null' => array( 'IS_NULL' ) |
|
| 127 | + ) |
|
| 128 | + ) |
|
| 129 | + ) |
|
| 130 | + ); |
|
| 131 | + foreach ($questions as $question) { |
|
| 132 | + $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration); |
|
| 133 | + } |
|
| 134 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 135 | + 'ee_edit_registration', |
|
| 136 | + 'edit-reg-questions-mbox', |
|
| 137 | + $this->_registration->ID() |
|
| 138 | + )) { |
|
| 139 | + $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML( |
|
| 140 | + EEH_HTML::table( |
|
| 141 | + EEH_HTML::tr( |
|
| 142 | + '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '"> |
|
| 143 | 143 | <span class="reg-admin-edit-question-group-spn">' . __('edit the above question group', 'event_espresso') . '</span> |
| 144 | 144 | <div class="dashicons dashicons-edit"></div> |
| 145 | 145 | </a></td>' |
| 146 | - ) . |
|
| 147 | - EEH_HTML::no_row('', 2) |
|
| 148 | - ) |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - return new EE_Form_Section_Proper( |
|
| 152 | - array( |
|
| 153 | - 'subsections' => $parts_of_subsection, |
|
| 154 | - 'html_class' => 'question-group-questions', |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 157 | - } |
|
| 146 | + ) . |
|
| 147 | + EEH_HTML::no_row('', 2) |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + return new EE_Form_Section_Proper( |
|
| 152 | + array( |
|
| 153 | + 'subsections' => $parts_of_subsection, |
|
| 154 | + 'html_class' => 'question-group-questions', |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Overrides parent so if inputs were disabled, we leave those with their defaults |
|
| 161 | - * from the answers in the DB |
|
| 162 | - * @param array $req_data like $_POST |
|
| 163 | - * @return void |
|
| 164 | - */ |
|
| 165 | - protected function _normalize($req_data) |
|
| 166 | - { |
|
| 167 | - $this->_received_submission = true; |
|
| 168 | - $this->_validation_errors = array(); |
|
| 169 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 170 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 171 | - try { |
|
| 172 | - $subsection->_normalize($req_data); |
|
| 173 | - } catch (EE_Validation_Error $e) { |
|
| 174 | - $subsection->add_validation_error($e); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 159 | + /** |
|
| 160 | + * Overrides parent so if inputs were disabled, we leave those with their defaults |
|
| 161 | + * from the answers in the DB |
|
| 162 | + * @param array $req_data like $_POST |
|
| 163 | + * @return void |
|
| 164 | + */ |
|
| 165 | + protected function _normalize($req_data) |
|
| 166 | + { |
|
| 167 | + $this->_received_submission = true; |
|
| 168 | + $this->_validation_errors = array(); |
|
| 169 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 170 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 171 | + try { |
|
| 172 | + $subsection->_normalize($req_data); |
|
| 173 | + } catch (EE_Validation_Error $e) { |
|
| 174 | + $subsection->add_validation_error($e); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Performs validation on this form section and its subsections. For each subsection, |
|
| 184 | - * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls _validate on that subsection. |
|
| 185 | - * If you need to perform validation on the form as a whole (considering multiple) you would be best to override this _validate method, |
|
| 186 | - * calling parent::_validate() first. |
|
| 187 | - */ |
|
| 188 | - protected function _validate() |
|
| 189 | - { |
|
| 190 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 191 | - if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) { |
|
| 192 | - if (method_exists($this, '_validate_'.$subsection_name)) { |
|
| 193 | - call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection)); |
|
| 194 | - } |
|
| 195 | - $subsection->_validate(); |
|
| 196 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 197 | - $subsection->_received_submission = true; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 182 | + /** |
|
| 183 | + * Performs validation on this form section and its subsections. For each subsection, |
|
| 184 | + * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls _validate on that subsection. |
|
| 185 | + * If you need to perform validation on the form as a whole (considering multiple) you would be best to override this _validate method, |
|
| 186 | + * calling parent::_validate() first. |
|
| 187 | + */ |
|
| 188 | + protected function _validate() |
|
| 189 | + { |
|
| 190 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 191 | + if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) { |
|
| 192 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
| 193 | + call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection)); |
|
| 194 | + } |
|
| 195 | + $subsection->_validate(); |
|
| 196 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 197 | + $subsection->_received_submission = true; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | 201 | } |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | public function __construct(EE_Registration $reg, $options = array()) |
| 33 | 33 | { |
| 34 | 34 | $this->_registration = $reg; |
| 35 | - if (! isset($options['layout_strategy'])) { |
|
| 35 | + if ( ! isset($options['layout_strategy'])) { |
|
| 36 | 36 | $options['layout_strategy'] = new EE_Admin_Two_Column_Layout(); |
| 37 | 37 | } |
| 38 | - if (! isset($options['html_id'])) { |
|
| 38 | + if ( ! isset($options['html_id'])) { |
|
| 39 | 39 | $options['html_id'] = 'reg-admin-attendee-questions-frm'; |
| 40 | 40 | } |
| 41 | 41 | $this->build_form_from_registration(); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | public function build_form_from_registration() |
| 64 | 64 | { |
| 65 | 65 | $reg = $this->get_registration(); |
| 66 | - if (! $reg instanceof EE_Registration) { |
|
| 66 | + if ( ! $reg instanceof EE_Registration) { |
|
| 67 | 67 | throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso')); |
| 68 | 68 | } |
| 69 | 69 | // we want to get all their question groups |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | // get each question groups questions |
| 87 | 87 | foreach ($question_groups as $question_group) { |
| 88 | 88 | if ($question_group instanceof EE_Question_Group) { |
| 89 | - $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group( |
|
| 89 | + $this->_subsections[$question_group->ID()] = $this->build_subform_from_question_group( |
|
| 90 | 90 | $question_group, |
| 91 | 91 | $reg |
| 92 | 92 | ); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function build_subform_from_question_group($question_group, $registration) |
| 107 | 107 | { |
| 108 | - if (! $question_group instanceof EE_Question_Group || |
|
| 108 | + if ( ! $question_group instanceof EE_Question_Group || |
|
| 109 | 109 | ! $registration instanceof EE_Registration) { |
| 110 | 110 | throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso')); |
| 111 | 111 | } |
@@ -123,13 +123,13 @@ discard block |
||
| 123 | 123 | array( |
| 124 | 124 | 'OR' => array( |
| 125 | 125 | 'QST_system*blank' => '', |
| 126 | - 'QST_system*null' => array( 'IS_NULL' ) |
|
| 126 | + 'QST_system*null' => array('IS_NULL') |
|
| 127 | 127 | ) |
| 128 | 128 | ) |
| 129 | 129 | ) |
| 130 | 130 | ); |
| 131 | 131 | foreach ($questions as $question) { |
| 132 | - $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration); |
|
| 132 | + $parts_of_subsection[$question->ID()] = $question->generate_form_input($registration); |
|
| 133 | 133 | } |
| 134 | 134 | if (EE_Registry::instance()->CAP->current_user_can( |
| 135 | 135 | 'ee_edit_registration', |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML( |
| 140 | 140 | EEH_HTML::table( |
| 141 | 141 | EEH_HTML::tr( |
| 142 | - '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '"> |
|
| 143 | - <span class="reg-admin-edit-question-group-spn">' . __('edit the above question group', 'event_espresso') . '</span> |
|
| 142 | + '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="'.esc_attr__('click to edit question', 'event_espresso').'"> |
|
| 143 | + <span class="reg-admin-edit-question-group-spn">' . __('edit the above question group', 'event_espresso').'</span> |
|
| 144 | 144 | <div class="dashicons dashicons-edit"></div> |
| 145 | 145 | </a></td>' |
| 146 | - ) . |
|
| 146 | + ). |
|
| 147 | 147 | EEH_HTML::no_row('', 2) |
| 148 | 148 | ) |
| 149 | 149 | ); |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
| 191 | 191 | if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) { |
| 192 | 192 | if (method_exists($this, '_validate_'.$subsection_name)) { |
| 193 | - call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection)); |
|
| 193 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
| 194 | 194 | } |
| 195 | 195 | $subsection->_validate(); |
| 196 | 196 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |